/* * 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 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" #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 AGGR_DRV "aggr" #define MAXPORT 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)" typedef struct pktsum_s { uint64_t ipackets; uint64_t opackets; uint64_t rbytes; uint64_t obytes; uint32_t ierrors; uint32_t oerrors; } pktsum_t; typedef struct show_state { boolean_t ls_firstonly; boolean_t ls_donefirst; pktsum_t ls_prevstats; boolean_t ls_parseable; uint32_t ls_flags; dladm_status_t ls_status; } show_state_t; typedef struct show_grp_state { boolean_t gs_lacp; boolean_t gs_extended; boolean_t gs_stats; boolean_t gs_firstonly; boolean_t gs_donefirst; pktsum_t gs_prevstats[MAXPORT]; boolean_t gs_parseable; uint32_t gs_flags; dladm_status_t gs_status; } show_grp_state_t; typedef void cmdfunc_t(int, char **); static cmdfunc_t do_show_link, do_show_dev, 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 void altroot_cmd(char *, int, char **); static int show_linkprop_onelink(datalink_id_t, void *); static void link_stats(datalink_id_t, uint_t); static void aggr_stats(datalink_id_t, show_grp_state_t *, uint_t); static void dev_stats(const char *dev, 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 void stats_total(pktsum_t *, pktsum_t *, pktsum_t *); static void stats_diff(pktsum_t *, pktsum_t *, pktsum_t *); static const char *get_linkstate(const char *, boolean_t, char *); static const char *get_linkduplex(const char *, boolean_t, char *); static boolean_t str2int(const char *, int *); static void die(const char *, ...); static void die_optdup(int); static void die_opterr(int, int); static void die_dlerr(dladm_status_t, const char *, ...); static void warn(const char *, ...); static void warn_dlerr(dladm_status_t, const char *, ...); typedef struct cmd { char *c_name; cmdfunc_t *c_fn; } cmd_t; static cmd_t cmds[] = { { "show-link", do_show_link }, { "show-dev", do_show_dev }, { "create-aggr", do_create_aggr }, { "delete-aggr", do_delete_aggr }, { "add-aggr", do_add_aggr }, { "remove-aggr", do_remove_aggr }, { "modify-aggr", do_modify_aggr }, { "show-aggr", do_show_aggr }, { "up-aggr", do_up_aggr }, { "scan-wifi", do_scan_wifi }, { "connect-wifi", do_connect_wifi }, { "disconnect-wifi", do_disconnect_wifi }, { "show-wifi", do_show_wifi }, { "show-linkprop", do_show_linkprop }, { "set-linkprop", do_set_linkprop }, { "reset-linkprop", do_reset_linkprop }, { "create-secobj", do_create_secobj }, { "delete-secobj", do_delete_secobj }, { "show-secobj", do_show_secobj }, { "init-linkprop", do_init_linkprop }, { "init-secobj", do_init_secobj }, { "create-vlan", do_create_vlan }, { "delete-vlan", do_delete_vlan }, { "show-vlan", do_show_vlan }, { "up-vlan", do_up_vlan }, { "rename-link", do_rename_link }, { "delete-phys", do_delete_phys }, { "show-phys", do_show_phys }, { "init-phys", do_init_phys }, { "show-linkmap", do_show_linkmap } }; static const struct option lopts[] = { {"vlan-id", required_argument, 0, 'v'}, {"dev", required_argument, 0, 'd'}, {"policy", required_argument, 0, 'P'}, {"lacp-mode", required_argument, 0, 'L'}, {"lacp-timer", required_argument, 0, 'T'}, {"unicast", required_argument, 0, 'u'}, {"temporary", no_argument, 0, 't'}, {"root-dir", required_argument, 0, 'R'}, {"link", required_argument, 0, 'l'}, {"forcible", no_argument, 0, 'f'}, { 0, 0, 0, 0 } }; static const struct option show_lopts[] = { {"statistics", no_argument, 0, 's'}, {"interval", required_argument, 0, 'i'}, {"parseable", no_argument, 0, 'p'}, {"extended", no_argument, 0, 'x'}, {"persistent", no_argument, 0, 'P'}, {"lacp", no_argument, 0, 'L'}, { 0, 0, 0, 0 } }; static const struct option prop_longopts[] = { {"temporary", no_argument, 0, 't' }, {"root-dir", required_argument, 0, 'R' }, {"prop", required_argument, 0, 'p' }, {"parseable", no_argument, 0, 'c' }, {"persistent", no_argument, 0, 'P' }, { 0, 0, 0, 0 } }; static const struct option wifi_longopts[] = { {"parseable", no_argument, 0, 'p' }, {"output", required_argument, 0, 'o' }, {"essid", required_argument, 0, 'e' }, {"bsstype", required_argument, 0, 'b' }, {"mode", required_argument, 0, 'm' }, {"key", required_argument, 0, 'k' }, {"sec", required_argument, 0, 's' }, {"auth", required_argument, 0, 'a' }, {"create-ibss", required_argument, 0, 'c' }, {"timeout", required_argument, 0, 'T' }, {"all-links", no_argument, 0, 'a' }, {"temporary", no_argument, 0, 't' }, {"root-dir", required_argument, 0, 'R' }, {"persistent", no_argument, 0, 'P' }, {"file", required_argument, 0, 'f' }, { 0, 0, 0, 0 } }; static char *progname; static sig_atomic_t signalled; static void usage(void) { (void) fprintf(stderr, gettext("usage: dladm ...\n" "\tshow-link [-pP] [-s [-i ]] []\n" "\trename-link [-R ] \n" "\n" "\tdelete-phys \n" "\tshow-phys [-pP] []\n" "\tshow-dev [-p] [-s [-i ]] []\n" "\n" "\tcreate-aggr [-t] [-R ] [-P ] [-L ]\n" "\t [-T