/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (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 2005 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 #define AGGR_DEV "aggr0" #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)) static void do_show_link(int, char **); static void do_create_aggr(int, char **); static void do_delete_aggr(int, char **); static void do_add_aggr(int, char **); static void do_remove_aggr(int, char **); static void do_modify_aggr(int, char **); static void do_show_aggr(int, char **); static void do_up_aggr(int, char **); static void do_down_aggr(int, char **); static void do_show_dev(int, char **); static void link_stats(const char *, uint32_t); static void aggr_stats(uint16_t, uint32_t); static void dev_stats(const char *dev, uint32_t); static void get_mac_stats(const char *, uint_t, pktsum_t *); static void get_link_stats(const char *, pktsum_t *); static uint64_t mac_ifspeed(const char *, uint_t); static char *mac_link_state(const char *, uint_t); static char *mac_link_duplex(const char *, uint_t); static void stats_total(pktsum_t *, pktsum_t *, pktsum_t *); static void stats_diff(pktsum_t *, pktsum_t *, pktsum_t *); typedef struct cmd { char *c_name; void (*c_fn)(int, char **); } 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 } }; 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 char *progname; #define PRINT_ERR_DIAG(s, diag, func) { \ (void) fprintf(stderr, gettext(s), progname, strerror(errno)); \ if (diag != 0) \ (void) fprintf(stderr, " (%s)", func(diag)); \ (void) fprintf(stderr, "\n"); \ } static void usage(void) { (void) fprintf(stderr, gettext( "usage: dladm create-aggr [-t] [-R ] [-P ]\n" " [-l ] [-T