/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2017 Joyent, Inc. * Copyright 2016 Nexenta Systems, Inc. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAXPORT 256 #define MAXVNIC 256 #define BUFLEN(lim, ptr) (((lim) > (ptr)) ? ((lim) - (ptr)) : 0) #define MAXLINELEN 1024 #define SMF_UPGRADE_FILE "/var/svc/profile/upgrade" #define SMF_UPGRADEDATALINK_FILE "/var/svc/profile/upgrade_datalink" #define SMF_DLADM_UPGRADE_MSG " # added by dladm(1M)" #define DLADM_DEFAULT_COL 80 /* * used by the wifi show-* commands to set up ofmt_field_t structures. */ #define WIFI_CMD_SCAN 0x00000001 #define WIFI_CMD_SHOW 0x00000002 #define WIFI_CMD_ALL (WIFI_CMD_SCAN | WIFI_CMD_SHOW) /* No larger than pktsum_t */ typedef struct brsum_s { uint64_t drops; uint64_t forward_dir; uint64_t forward_mb; uint64_t forward_unk; uint64_t recv; uint64_t sent; } brsum_t; /* No larger than pktsum_t */ typedef struct brlsum_s { uint32_t cfgbpdu; uint32_t tcnbpdu; uint32_t rstpbpdu; uint32_t txbpdu; uint64_t drops; uint64_t recv; uint64_t xmit; } brlsum_t; typedef struct show_state { boolean_t ls_firstonly; boolean_t ls_donefirst; pktsum_t ls_prevstats; uint32_t ls_flags; dladm_status_t ls_status; ofmt_handle_t ls_ofmt; boolean_t ls_parsable; boolean_t ls_mac; boolean_t ls_hwgrp; } show_state_t; typedef struct show_grp_state { pktsum_t gs_prevstats[MAXPORT]; uint32_t gs_flags; dladm_status_t gs_status; boolean_t gs_parsable; boolean_t gs_lacp; boolean_t gs_extended; boolean_t gs_stats; boolean_t gs_firstonly; boolean_t gs_donefirst; ofmt_handle_t gs_ofmt; } show_grp_state_t; typedef struct show_vnic_state { datalink_id_t vs_vnic_id; datalink_id_t vs_link_id; char vs_vnic[MAXLINKNAMELEN]; char vs_link[MAXLINKNAMELEN]; boolean_t vs_parsable; boolean_t vs_found; boolean_t vs_firstonly; boolean_t vs_donefirst; boolean_t vs_stats; boolean_t vs_printstats; pktsum_t vs_totalstats; pktsum_t vs_prevstats[MAXVNIC]; boolean_t vs_etherstub; dladm_status_t vs_status; uint32_t vs_flags; ofmt_handle_t vs_ofmt; char *vs_zonename; } show_vnic_state_t; typedef struct show_part_state { datalink_id_t ps_over_id; char ps_part[MAXLINKNAMELEN]; boolean_t ps_parsable; boolean_t ps_found; dladm_status_t ps_status; uint32_t ps_flags; ofmt_handle_t ps_ofmt; } show_part_state_t; typedef struct show_ib_state { datalink_id_t is_link_id; char is_link[MAXLINKNAMELEN]; boolean_t is_parsable; dladm_status_t is_status; uint32_t is_flags; ofmt_handle_t is_ofmt; } show_ib_state_t; typedef struct show_usage_state_s { boolean_t us_plot; boolean_t us_parsable; boolean_t us_printheader; boolean_t us_first; boolean_t us_showall; ofmt_handle_t us_ofmt; } show_usage_state_t; typedef struct show_overlay_request_s { boolean_t sor_failed; ofmt_handle_t sor_ofmt; } show_overlay_request_t; /* * callback functions for printing output and error diagnostics. */ static ofmt_cb_t print_default_cb, print_link_stats_cb, print_linkprop_cb; static ofmt_cb_t print_lacp_cb, print_phys_one_mac_cb; static ofmt_cb_t print_xaggr_cb, print_aggr_stats_cb; static ofmt_cb_t print_phys_one_hwgrp_cb, print_wlan_attr_cb; static ofmt_cb_t print_wifi_status_cb, print_link_attr_cb; static ofmt_cb_t print_overlay_cb, print_overlay_fma_cb, print_overlay_targ_cb; typedef void cmdfunc_t(int, char **, const char *); static cmdfunc_t do_show_link, do_show_wifi, do_show_phys; static cmdfunc_t do_create_aggr, do_delete_aggr, do_add_aggr, do_remove_aggr; static cmdfunc_t do_modify_aggr, do_show_aggr, do_up_aggr; static cmdfunc_t do_scan_wifi, do_connect_wifi, do_disconnect_wifi; static cmdfunc_t do_show_linkprop, do_set_linkprop, do_reset_linkprop; static cmdfunc_t do_create_secobj, do_delete_secobj, do_show_secobj; static cmdfunc_t do_init_linkprop, do_init_secobj; static cmdfunc_t do_create_vlan, do_delete_vlan, do_up_vlan, do_show_vlan; static cmdfunc_t do_rename_link, do_delete_phys, do_init_phys; static cmdfunc_t do_show_linkmap; static cmdfunc_t do_show_ether; static cmdfunc_t do_create_vnic, do_delete_vnic, do_show_vnic; static cmdfunc_t do_up_vnic; static cmdfunc_t do_create_part, do_delete_part, do_show_part, do_show_ib; static cmdfunc_t do_up_part; static cmdfunc_t do_create_etherstub, do_delete_etherstub, do_show_etherstub; static cmdfunc_t do_create_simnet, do_modify_simnet; static cmdfunc_t do_delete_simnet, do_show_simnet, do_up_simnet; static cmdfunc_t do_show_usage; static cmdfunc_t do_create_bridge, do_modify_bridge, do_delete_bridge; static cmdfunc_t do_add_bridge, do_remove_bridge, do_show_bridge; static cmdfunc_t do_create_iptun, do_modify_iptun, do_delete_iptun; static cmdfunc_t do_show_iptun, do_up_iptun, do_down_iptun; static cmdfunc_t do_create_overlay, do_delete_overlay, do_modify_overlay; static cmdfunc_t do_show_overlay; static void do_up_vnic_common(int, char **, const char *, boolean_t); static int show_part(dladm_handle_t, datalink_id_t, void *); static void altroot_cmd(char *, int, char **); static int show_linkprop_onelink(dladm_handle_t, datalink_id_t, void *); static void link_stats(datalink_id_t, uint_t, char *, show_state_t *); static void aggr_stats(datalink_id_t, show_grp_state_t *, uint_t); static void vnic_stats(show_vnic_state_t *, uint32_t); static int get_one_kstat(const char *, const char *, uint8_t, void *, boolean_t); static void get_mac_stats(const char *, pktsum_t *); static void get_link_stats(const char *, pktsum_t *); static uint64_t get_ifspeed(const char *, boolean_t); static const char *get_linkstate(const char *, boolean_t, char *); static const char *get_linkduplex(const char *, boolean_t, char *); static iptun_type_t iptun_gettypebyname(char *); static const char *iptun_gettypebyvalue(iptun_type_t); static dladm_status_t print_iptun(dladm_handle_t, datalink_id_t, show_state_t *); static int print_iptun_walker(dladm_handle_t, datalink_id_t, void *); static int show_etherprop(dladm_handle_t, datalink_id_t, void *); static void show_ether_xprop(void *, dladm_ether_info_t *); static boolean_t link_is_ether(const char *, datalink_id_t *); static boolean_t str2int(const char *, int *); static void die(const char *, ...); static void die_optdup(int); static void die_opterr(int, int, const char *); static void die_dlerr(dladm_status_t, const char *, ...); static void die_dlerrlist(dladm_status_t, dladm_errlist_t *, const char *, ...); static void warn(const char *, ...); static void warn_dlerr(dladm_status_t, const char *, ...); static void warn_dlerrlist(dladm_errlist_t *); typedef struct cmd { char *c_name; cmdfunc_t *c_fn; const char *c_usage; } cmd_t; static cmd_t cmds[] = { { "rename-link", do_rename_link, " rename-link [-z zonename] " }, { "show-link", do_show_link, " show-link [-pP] [-o ,..] [-s [-i ]] " "[]\n" }, { "create-aggr", do_create_aggr, " create-aggr [-t] [-P ] [-L ] [-T