/* * 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 2007 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 #define AGGR_DRV "aggr" #define MAXPORT 256 #define DUMP_LACP_FORMAT " %-9s %-8s %-7s %-12s " \ "%-5s %-4s %-4s %-9s %-7s\n" 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_link_state { boolean_t ls_firstonly; boolean_t ls_donefirst; boolean_t ls_stats; pktsum_t ls_prevstats; boolean_t ls_parseable; } show_link_state_t; typedef struct show_grp_state { uint32_t gs_key; boolean_t gs_lacp; boolean_t gs_found; boolean_t gs_stats; boolean_t gs_firstonly; pktsum_t gs_prevstats[MAXPORT]; boolean_t gs_parseable; } show_grp_state_t; typedef struct show_mac_state { boolean_t ms_firstonly; boolean_t ms_donefirst; pktsum_t ms_prevstats; boolean_t ms_parseable; } show_mac_state_t; typedef struct port_state { char *state_name; aggr_port_state_t state_num; } port_state_t; static port_state_t port_states[] = { {"standby", AGGR_PORT_STATE_STANDBY }, {"attached", AGGR_PORT_STATE_ATTACHED } }; #define NPORTSTATES (sizeof (port_states) / sizeof (port_state_t)) typedef void cmdfunc_t(int, char **); static cmdfunc_t do_show_link, do_show_dev, do_show_wifi; 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, do_down_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 void show_linkprop_onelink(void *, const char *); static void link_stats(const char *, uint_t); static void aggr_stats(uint32_t, uint_t); static void dev_stats(const char *dev, uint32_t); static void get_mac_stats(const char *, pktsum_t *); static void get_link_stats(const char *, pktsum_t *); static uint64_t mac_ifspeed(const char *); static char *mac_link_state(const char *); static char *mac_link_duplex(const char *); static void stats_total(pktsum_t *, pktsum_t *, pktsum_t *); static void stats_diff(pktsum_t *, pktsum_t *, pktsum_t *); 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_laerr(laadm_diag_t, const char *, ...); static void die_wlerr(wladm_status_t, const char *, ...); static void die_dlerr(dladm_status_t, const char *, ...); static void warn(const char *, ...); static void warn_wlerr(wladm_status_t, 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 }, { "down-aggr", do_down_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 } }; static const struct option longopts[] = { {"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' }, {"statistics", no_argument, 0, 's' }, {"interval", required_argument, 0, 'i' }, {"lacp", no_argument, 0, 'L' }, {"temporary", no_argument, 0, 't' }, {"root-dir", required_argument, 0, 'r' }, {"parseable", no_argument, 0, 'p' }, { 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 [-p] [-s [-i ]] []\n" "\tshow-dev [-p] [-s [-i ]] []\n" "\n" "\tcreate-aggr [-t] [-R ] [-P ] [-l ]\n" "\t [-T