xref: /titanic_54/usr/src/cmd/dladm/dladm.c (revision cd93090ec4fd8704271aee7cc8241a848bc78ffd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <locale.h>
317c478bd9Sstevel@tonic-gate #include <stdarg.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <fcntl.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <stropts.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <kstat.h>
387c478bd9Sstevel@tonic-gate #include <strings.h>
397c478bd9Sstevel@tonic-gate #include <getopt.h>
407c478bd9Sstevel@tonic-gate #include <unistd.h>
41*cd93090eSericheng #include <priv.h>
427c478bd9Sstevel@tonic-gate #include <libintl.h>
437c478bd9Sstevel@tonic-gate #include <libdlpi.h>
447c478bd9Sstevel@tonic-gate #include <libdladm.h>
457c478bd9Sstevel@tonic-gate #include <liblaadm.h>
467c478bd9Sstevel@tonic-gate #include <libmacadm.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	AGGR_DEV	"aggr0"
497c478bd9Sstevel@tonic-gate #define	MAXPORT		256
507c478bd9Sstevel@tonic-gate #define	DUMP_LACP_FORMAT	"    %-9s %-8s %-7s %-12s "	\
517c478bd9Sstevel@tonic-gate 	"%-5s %-4s %-4s %-9s %-7s\n"
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef struct pktsum_s {
547c478bd9Sstevel@tonic-gate 	uint64_t	ipackets;
557c478bd9Sstevel@tonic-gate 	uint64_t	opackets;
567c478bd9Sstevel@tonic-gate 	uint64_t	rbytes;
577c478bd9Sstevel@tonic-gate 	uint64_t	obytes;
587c478bd9Sstevel@tonic-gate 	uint32_t	ierrors;
597c478bd9Sstevel@tonic-gate 	uint32_t	oerrors;
607c478bd9Sstevel@tonic-gate } pktsum_t;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct show_link_state {
637c478bd9Sstevel@tonic-gate 	boolean_t	ls_firstonly;
647c478bd9Sstevel@tonic-gate 	boolean_t	ls_donefirst;
657c478bd9Sstevel@tonic-gate 	boolean_t	ls_stats;
667c478bd9Sstevel@tonic-gate 	pktsum_t	ls_prevstats;
677c478bd9Sstevel@tonic-gate 	boolean_t	ls_parseable;
687c478bd9Sstevel@tonic-gate } show_link_state_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct show_grp_state {
717c478bd9Sstevel@tonic-gate 	uint32_t	gs_key;
727c478bd9Sstevel@tonic-gate 	boolean_t	gs_lacp;
737c478bd9Sstevel@tonic-gate 	boolean_t	gs_found;
747c478bd9Sstevel@tonic-gate 	boolean_t	gs_stats;
757c478bd9Sstevel@tonic-gate 	boolean_t	gs_firstonly;
767c478bd9Sstevel@tonic-gate 	pktsum_t	gs_prevstats[MAXPORT];
777c478bd9Sstevel@tonic-gate 	boolean_t	gs_parseable;
787c478bd9Sstevel@tonic-gate } show_grp_state_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct show_mac_state {
817c478bd9Sstevel@tonic-gate 	boolean_t	ms_firstonly;
827c478bd9Sstevel@tonic-gate 	boolean_t	ms_donefirst;
837c478bd9Sstevel@tonic-gate 	pktsum_t	ms_prevstats;
847c478bd9Sstevel@tonic-gate 	boolean_t	ms_parseable;
857c478bd9Sstevel@tonic-gate } show_mac_state_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate typedef struct port_state {
887c478bd9Sstevel@tonic-gate 	char			*state_name;
897c478bd9Sstevel@tonic-gate 	aggr_port_state_t	state_num;
907c478bd9Sstevel@tonic-gate } port_state_t;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate static port_state_t port_states[] = {
937c478bd9Sstevel@tonic-gate 	{"standby", AGGR_PORT_STATE_STANDBY },
947c478bd9Sstevel@tonic-gate 	{"attached", AGGR_PORT_STATE_ATTACHED }
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	NPORTSTATES	(sizeof (port_states) / sizeof (port_state_t))
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate static void	do_show_link(int, char **);
1007c478bd9Sstevel@tonic-gate static void	do_create_aggr(int, char **);
1017c478bd9Sstevel@tonic-gate static void	do_delete_aggr(int, char **);
1027c478bd9Sstevel@tonic-gate static void	do_add_aggr(int, char **);
1037c478bd9Sstevel@tonic-gate static void	do_remove_aggr(int, char **);
1047c478bd9Sstevel@tonic-gate static void	do_modify_aggr(int, char **);
1057c478bd9Sstevel@tonic-gate static void	do_show_aggr(int, char **);
1067c478bd9Sstevel@tonic-gate static void	do_up_aggr(int, char **);
1077c478bd9Sstevel@tonic-gate static void	do_down_aggr(int, char **);
1087c478bd9Sstevel@tonic-gate static void	do_show_dev(int, char **);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate static void	link_stats(const char *, uint32_t);
1117c478bd9Sstevel@tonic-gate static void	aggr_stats(uint16_t, uint32_t);
1127c478bd9Sstevel@tonic-gate static void	dev_stats(const char *dev, uint32_t);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate static void	get_mac_stats(const char *, uint_t, pktsum_t *);
1157c478bd9Sstevel@tonic-gate static void	get_link_stats(const char *, pktsum_t *);
1167c478bd9Sstevel@tonic-gate static uint64_t	mac_ifspeed(const char *, uint_t);
1177c478bd9Sstevel@tonic-gate static char	*mac_link_state(const char *, uint_t);
1187c478bd9Sstevel@tonic-gate static char	*mac_link_duplex(const char *, uint_t);
1197c478bd9Sstevel@tonic-gate static void	stats_total(pktsum_t *, pktsum_t *, pktsum_t *);
1207c478bd9Sstevel@tonic-gate static void	stats_diff(pktsum_t *, pktsum_t *, pktsum_t *);
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate typedef struct	cmd {
1237c478bd9Sstevel@tonic-gate 	char	*c_name;
1247c478bd9Sstevel@tonic-gate 	void	(*c_fn)(int, char **);
1257c478bd9Sstevel@tonic-gate } cmd_t;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate static cmd_t	cmds[] = {
1287c478bd9Sstevel@tonic-gate 	{ "show-link", do_show_link },
129210db224Sericheng 	{ "show-dev", do_show_dev },
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	{ "create-aggr", do_create_aggr },
1327c478bd9Sstevel@tonic-gate 	{ "delete-aggr", do_delete_aggr },
1337c478bd9Sstevel@tonic-gate 	{ "add-aggr", do_add_aggr },
1347c478bd9Sstevel@tonic-gate 	{ "remove-aggr", do_remove_aggr },
1357c478bd9Sstevel@tonic-gate 	{ "modify-aggr", do_modify_aggr },
1367c478bd9Sstevel@tonic-gate 	{ "show-aggr", do_show_aggr },
1377c478bd9Sstevel@tonic-gate 	{ "up-aggr", do_up_aggr },
138210db224Sericheng 	{ "down-aggr", do_down_aggr }
1397c478bd9Sstevel@tonic-gate };
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate static const struct option longopts[] = {
1427c478bd9Sstevel@tonic-gate 	{"vlan-id",	required_argument,	0, 'v'},
1437c478bd9Sstevel@tonic-gate 	{"dev",		required_argument,	0, 'd'},
1447c478bd9Sstevel@tonic-gate 	{"policy",	required_argument,	0, 'P'},
1457c478bd9Sstevel@tonic-gate 	{"lacp-mode",	required_argument,	0, 'l'},
1467c478bd9Sstevel@tonic-gate 	{"lacp-timer",	required_argument,	0, 'T'},
1477c478bd9Sstevel@tonic-gate 	{"unicast",	required_argument,	0, 'u'},
1487c478bd9Sstevel@tonic-gate 	{"statistics",	no_argument,		0, 's'},
1497c478bd9Sstevel@tonic-gate 	{"interval",	required_argument,	0, 'i'},
1507c478bd9Sstevel@tonic-gate 	{"lacp",	no_argument,		0, 'L'},
1517c478bd9Sstevel@tonic-gate 	{"temporary",	no_argument,		0, 't'},
1527c478bd9Sstevel@tonic-gate 	{"root-dir",	required_argument,	0, 'r'},
1537c478bd9Sstevel@tonic-gate 	{"parseable",	no_argument,		0, 'p'},
1547c478bd9Sstevel@tonic-gate 	{ 0, 0, 0, 0 }
1557c478bd9Sstevel@tonic-gate };
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate static char *progname;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #define	PRINT_ERR_DIAG(s, diag, func) {					\
1607c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(s), progname, strerror(errno));	\
1617c478bd9Sstevel@tonic-gate 	if (diag != 0)							\
1627c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, " (%s)", func(diag));		\
1637c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "\n");					\
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate static void
1677c478bd9Sstevel@tonic-gate usage(void)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
170210db224Sericheng 	    "usage: dladm create-aggr [-t] [-R <root-dir>] [-P <policy>]\n"
1717c478bd9Sstevel@tonic-gate 	    "                    [-l <mode>] [-T <time>]\n"
1727c478bd9Sstevel@tonic-gate 	    "                    [-u <address>] -d <dev> ... <key>\n"
1737c478bd9Sstevel@tonic-gate 	    "             delete-aggr [-t] [-R <root-dir>] <key>\n"
1747c478bd9Sstevel@tonic-gate 	    "             add-aggr    [-t] [-R <root-dir>] -d <dev> ... <key>\n"
1757c478bd9Sstevel@tonic-gate 	    "             remove-aggr [-t] [-R <root-dir>] -d <dev> ... <key>\n"
1767c478bd9Sstevel@tonic-gate 	    "             modify-aggr [-t] [-R <root-dir>] [-P <policy>]\n"
1777c478bd9Sstevel@tonic-gate 	    "                    [-l <mode>] [-T <time>] [-u <address>] <key>\n"
1787c478bd9Sstevel@tonic-gate 	    "             show-aggr [-L] [-s] [-i <interval>] [-p] [<key>]\n"
1797c478bd9Sstevel@tonic-gate 	    "             show-dev [-s] [-i <interval>] [-p] [<dev>]\n"
1807c478bd9Sstevel@tonic-gate 	    "             show-link [-s] [-i <interval>] [-p] [<name>]\n"));
1817c478bd9Sstevel@tonic-gate 	exit(1);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate int
1857c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate 	int	i;
1887c478bd9Sstevel@tonic-gate 	cmd_t	*cmdp;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1917c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1927c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	progname = argv[0];
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (argc < 2)
1997c478bd9Sstevel@tonic-gate 		usage();
2007c478bd9Sstevel@tonic-gate 
201*cd93090eSericheng 	if (!priv_ineffect(PRIV_SYS_NET_CONFIG) ||
202*cd93090eSericheng 	    !priv_ineffect(PRIV_NET_RAWACCESS)) {
203*cd93090eSericheng 		(void) fprintf(stderr,
204*cd93090eSericheng 		    gettext("%s: insufficient privileges\n"), progname);
205*cd93090eSericheng 		exit(1);
206*cd93090eSericheng 	}
207*cd93090eSericheng 
2087c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (cmds) / sizeof (cmds[0]); i++) {
2097c478bd9Sstevel@tonic-gate 		cmdp = &cmds[i];
2107c478bd9Sstevel@tonic-gate 		if (strcmp(argv[1], cmdp->c_name) == 0) {
2117c478bd9Sstevel@tonic-gate 			cmdp->c_fn(argc - 1, &argv[1]);
2127c478bd9Sstevel@tonic-gate 			exit(0);
2137c478bd9Sstevel@tonic-gate 		}
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("%s: unknown subcommand '%s'\n"),
2177c478bd9Sstevel@tonic-gate 	    progname, argv[1]);
2187c478bd9Sstevel@tonic-gate 	usage();
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	return (0);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate static void
2257c478bd9Sstevel@tonic-gate do_create_aggr(int argc, char *argv[])
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	char			option;
2287c478bd9Sstevel@tonic-gate 	uint16_t		key;
2297c478bd9Sstevel@tonic-gate 	uint32_t		policy = AGGR_POLICY_L4;
2307c478bd9Sstevel@tonic-gate 	aggr_lacp_mode_t	lacp_mode = AGGR_LACP_OFF;
2317c478bd9Sstevel@tonic-gate 	aggr_lacp_timer_t	lacp_timer = AGGR_LACP_TIMER_SHORT;
2327c478bd9Sstevel@tonic-gate 	laadm_port_attr_db_t	port[MAXPORT];
2337c478bd9Sstevel@tonic-gate 	uint_t			nport = 0;
2347c478bd9Sstevel@tonic-gate 	uint8_t			mac_addr[ETHERADDRL];
2357c478bd9Sstevel@tonic-gate 	boolean_t		mac_addr_fixed = B_FALSE;
2367c478bd9Sstevel@tonic-gate 	boolean_t		P_arg = B_FALSE;
2377c478bd9Sstevel@tonic-gate 	boolean_t		l_arg = B_FALSE;
2387c478bd9Sstevel@tonic-gate 	boolean_t		t_arg = B_FALSE;
2397c478bd9Sstevel@tonic-gate 	boolean_t		u_arg = B_FALSE;
2407c478bd9Sstevel@tonic-gate 	boolean_t		T_arg = B_FALSE;
2417c478bd9Sstevel@tonic-gate 	char			*altroot = NULL;
2427c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
2437c478bd9Sstevel@tonic-gate 	laadm_diag_t		diag = 0;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	opterr = 0;
2467c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":d:l:P:R:tu:T:",
2477c478bd9Sstevel@tonic-gate 	    longopts, NULL)) != -1) {
2487c478bd9Sstevel@tonic-gate 		switch (option) {
2497c478bd9Sstevel@tonic-gate 		case 'd':
2507c478bd9Sstevel@tonic-gate 			if (nport >= MAXPORT) {
2517c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2527c478bd9Sstevel@tonic-gate 				    gettext("%s: too many <dev> arguments\n"),
2537c478bd9Sstevel@tonic-gate 				    progname);
2547c478bd9Sstevel@tonic-gate 				exit(1);
2557c478bd9Sstevel@tonic-gate 			}
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 			if (strlcpy(port[nport].lp_devname, optarg,
2587c478bd9Sstevel@tonic-gate 			    MAXNAMELEN) >= MAXNAMELEN) {
2597c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2607c478bd9Sstevel@tonic-gate 				    gettext("%s: device name too long\n"),
2617c478bd9Sstevel@tonic-gate 				    progname);
2627c478bd9Sstevel@tonic-gate 				exit(1);
2637c478bd9Sstevel@tonic-gate 			}
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 			port[nport].lp_port = 0;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 			nport++;
2687c478bd9Sstevel@tonic-gate 			break;
2697c478bd9Sstevel@tonic-gate 		case 'P':
2707c478bd9Sstevel@tonic-gate 			if (P_arg) {
2717c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
2727c478bd9Sstevel@tonic-gate 				    "%s: the option -P cannot be specified "
2737c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
2747c478bd9Sstevel@tonic-gate 				usage();
2757c478bd9Sstevel@tonic-gate 			}
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 			P_arg = B_TRUE;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_policy(optarg, &policy)) {
2807c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2817c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid policy '%s'\n"),
2827c478bd9Sstevel@tonic-gate 				    progname, optarg);
2837c478bd9Sstevel@tonic-gate 				exit(1);
2847c478bd9Sstevel@tonic-gate 			}
2857c478bd9Sstevel@tonic-gate 			break;
2867c478bd9Sstevel@tonic-gate 		case 'u':
2877c478bd9Sstevel@tonic-gate 			if (u_arg) {
2887c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
2897c478bd9Sstevel@tonic-gate 				    "%s: the option -u cannot be specified "
2907c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
2917c478bd9Sstevel@tonic-gate 				usage();
2927c478bd9Sstevel@tonic-gate 			}
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 			u_arg = B_TRUE;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_mac_addr(optarg, &mac_addr_fixed,
2977c478bd9Sstevel@tonic-gate 			    mac_addr)) {
2987c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2997c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid MAC address '%s'\n"),
3007c478bd9Sstevel@tonic-gate 				    progname, optarg);
3017c478bd9Sstevel@tonic-gate 				exit(1);
3027c478bd9Sstevel@tonic-gate 			}
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 			break;
3057c478bd9Sstevel@tonic-gate 		case 'l':
3067c478bd9Sstevel@tonic-gate 			if (l_arg) {
3077c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
3087c478bd9Sstevel@tonic-gate 				    "%s: the option -l cannot be specified "
3097c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
3107c478bd9Sstevel@tonic-gate 				usage();
3117c478bd9Sstevel@tonic-gate 			}
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 			l_arg = B_TRUE;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_lacp_mode(optarg, &lacp_mode)) {
3167c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3177c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid LACP mode '%s'\n"),
3187c478bd9Sstevel@tonic-gate 				    progname, optarg);
3197c478bd9Sstevel@tonic-gate 				exit(1);
3207c478bd9Sstevel@tonic-gate 			}
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 			break;
3237c478bd9Sstevel@tonic-gate 		case 'T':
3247c478bd9Sstevel@tonic-gate 			if (T_arg) {
3257c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
3267c478bd9Sstevel@tonic-gate 				    "%s: the option -T cannot be specified "
3277c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
3287c478bd9Sstevel@tonic-gate 				usage();
3297c478bd9Sstevel@tonic-gate 			}
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 			T_arg = B_TRUE;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_lacp_timer(optarg, &lacp_timer)) {
3347c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3357c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid LACP timer value"
3367c478bd9Sstevel@tonic-gate 				    " '%s'\n"),
3377c478bd9Sstevel@tonic-gate 				    progname, optarg);
3387c478bd9Sstevel@tonic-gate 				exit(1);
3397c478bd9Sstevel@tonic-gate 			}
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 			break;
3427c478bd9Sstevel@tonic-gate 		case 't':
3437c478bd9Sstevel@tonic-gate 			t_arg = B_TRUE;
3447c478bd9Sstevel@tonic-gate 			break;
3457c478bd9Sstevel@tonic-gate 		case 'R':
3467c478bd9Sstevel@tonic-gate 			altroot = optarg;
3477c478bd9Sstevel@tonic-gate 			break;
3487c478bd9Sstevel@tonic-gate 		case ':':
3497c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
3507c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
3517c478bd9Sstevel@tonic-gate 			    progname, optopt);
3527c478bd9Sstevel@tonic-gate 			exit(1);
3537c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
3547c478bd9Sstevel@tonic-gate 		case '?':
3557c478bd9Sstevel@tonic-gate 		default:
3567c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
3577c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
3587c478bd9Sstevel@tonic-gate 			    progname, optopt);
3597c478bd9Sstevel@tonic-gate 			exit(1);
3607c478bd9Sstevel@tonic-gate 		}
3617c478bd9Sstevel@tonic-gate 	}
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	if (nport == 0)
3647c478bd9Sstevel@tonic-gate 		usage();
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	/* get key value (required last argument) */
3677c478bd9Sstevel@tonic-gate 	if (optind != (argc-1))
3687c478bd9Sstevel@tonic-gate 		usage();
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	errno = 0;
3717c478bd9Sstevel@tonic-gate 	key = (int)strtol(argv[optind], &endp, 10);
3727c478bd9Sstevel@tonic-gate 	if (errno != 0 || key < 1 || *endp != '\0') {
3737c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3747c478bd9Sstevel@tonic-gate 		    gettext("%s: illegal key value '%d'\n"),
3757c478bd9Sstevel@tonic-gate 		    progname, key);
3767c478bd9Sstevel@tonic-gate 		exit(1);
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	if (laadm_create(key, nport, port, policy, mac_addr_fixed,
3807c478bd9Sstevel@tonic-gate 	    mac_addr, lacp_mode, lacp_timer, t_arg, altroot, &diag) < 0) {
3817c478bd9Sstevel@tonic-gate 		PRINT_ERR_DIAG("%s: create operation failed: %s", diag,
3827c478bd9Sstevel@tonic-gate 		    laadm_diag);
3837c478bd9Sstevel@tonic-gate 		exit(1);
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate static void
3887c478bd9Sstevel@tonic-gate do_delete_aggr(int argc, char *argv[])
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 	uint16_t		key;
3917c478bd9Sstevel@tonic-gate 	char			option;
3927c478bd9Sstevel@tonic-gate 	boolean_t		t_arg = B_FALSE;
3937c478bd9Sstevel@tonic-gate 	char			*altroot = NULL;
3947c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
3957c478bd9Sstevel@tonic-gate 	laadm_diag_t		diag = 0;
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	opterr = 0;
3987c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":R:t", longopts,
3997c478bd9Sstevel@tonic-gate 	    NULL)) != -1) {
4007c478bd9Sstevel@tonic-gate 		switch (option) {
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 		case 't':
4037c478bd9Sstevel@tonic-gate 			t_arg = B_TRUE;
4047c478bd9Sstevel@tonic-gate 			break;
4057c478bd9Sstevel@tonic-gate 		case 'R':
4067c478bd9Sstevel@tonic-gate 			altroot = optarg;
4077c478bd9Sstevel@tonic-gate 			break;
4087c478bd9Sstevel@tonic-gate 		case ':':
4097c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4107c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
4117c478bd9Sstevel@tonic-gate 			    progname, optopt);
4127c478bd9Sstevel@tonic-gate 			exit(1);
4137c478bd9Sstevel@tonic-gate 			break;
4147c478bd9Sstevel@tonic-gate 		case '?':
4157c478bd9Sstevel@tonic-gate 		default:
4167c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4177c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
4187c478bd9Sstevel@tonic-gate 			    progname, optopt);
4197c478bd9Sstevel@tonic-gate 			exit(1);
4207c478bd9Sstevel@tonic-gate 			break;
4217c478bd9Sstevel@tonic-gate 		}
4227c478bd9Sstevel@tonic-gate 	}
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	/* get key value (required last argument) */
4257c478bd9Sstevel@tonic-gate 	if (optind != (argc-1))
4267c478bd9Sstevel@tonic-gate 		usage();
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	errno = 0;
4297c478bd9Sstevel@tonic-gate 	key = (int)strtol(argv[optind], &endp, 10);
4307c478bd9Sstevel@tonic-gate 	if (errno != 0 || key < 1 || *endp != '\0') {
4317c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
4327c478bd9Sstevel@tonic-gate 		    gettext("%s: illegal key value '%d'\n"),
4337c478bd9Sstevel@tonic-gate 		    progname, key);
4347c478bd9Sstevel@tonic-gate 		exit(1);
4357c478bd9Sstevel@tonic-gate 	}
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	if (laadm_delete(key, t_arg, altroot, &diag) < 0) {
4387c478bd9Sstevel@tonic-gate 		PRINT_ERR_DIAG("%s: delete operation failed: %s", diag,
4397c478bd9Sstevel@tonic-gate 		    laadm_diag);
4407c478bd9Sstevel@tonic-gate 		exit(1);
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate static void
4457c478bd9Sstevel@tonic-gate do_add_aggr(int argc, char *argv[])
4467c478bd9Sstevel@tonic-gate {
4477c478bd9Sstevel@tonic-gate 	char			option;
4487c478bd9Sstevel@tonic-gate 	uint16_t		key;
4497c478bd9Sstevel@tonic-gate 	laadm_port_attr_db_t	port[MAXPORT];
4507c478bd9Sstevel@tonic-gate 	uint_t			nport = 0;
4517c478bd9Sstevel@tonic-gate 	boolean_t		t_arg = B_FALSE;
4527c478bd9Sstevel@tonic-gate 	char			*altroot = NULL;
4537c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
4547c478bd9Sstevel@tonic-gate 	laadm_diag_t		diag = 0;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	opterr = 0;
4577c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":d:R:t", longopts,
4587c478bd9Sstevel@tonic-gate 	    NULL)) != -1) {
4597c478bd9Sstevel@tonic-gate 		switch (option) {
4607c478bd9Sstevel@tonic-gate 		case 'd':
4617c478bd9Sstevel@tonic-gate 			if (nport >= MAXPORT) {
4627c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
4637c478bd9Sstevel@tonic-gate 				    gettext("%s: too many <dev> arguments\n"),
4647c478bd9Sstevel@tonic-gate 				    progname);
4657c478bd9Sstevel@tonic-gate 				exit(1);
4667c478bd9Sstevel@tonic-gate 			}
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 			if (strlcpy(port[nport].lp_devname, optarg,
4697c478bd9Sstevel@tonic-gate 			    MAXNAMELEN) >= MAXNAMELEN) {
4707c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
4717c478bd9Sstevel@tonic-gate 				    gettext("%s: device name too long\n"),
4727c478bd9Sstevel@tonic-gate 				    progname);
4737c478bd9Sstevel@tonic-gate 				exit(1);
4747c478bd9Sstevel@tonic-gate 			}
4757c478bd9Sstevel@tonic-gate 			port[nport].lp_port = 0;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 			nport++;
4787c478bd9Sstevel@tonic-gate 			break;
4797c478bd9Sstevel@tonic-gate 		case 't':
4807c478bd9Sstevel@tonic-gate 			t_arg = B_TRUE;
4817c478bd9Sstevel@tonic-gate 			break;
4827c478bd9Sstevel@tonic-gate 		case 'R':
4837c478bd9Sstevel@tonic-gate 			altroot = optarg;
4847c478bd9Sstevel@tonic-gate 			break;
4857c478bd9Sstevel@tonic-gate 		case ':':
4867c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4877c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
4887c478bd9Sstevel@tonic-gate 			    progname, optopt);
4897c478bd9Sstevel@tonic-gate 			exit(1);
4907c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
4917c478bd9Sstevel@tonic-gate 		case '?':
4927c478bd9Sstevel@tonic-gate 		default:
4937c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4947c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
4957c478bd9Sstevel@tonic-gate 			    progname, optopt);
4967c478bd9Sstevel@tonic-gate 			exit(1);
4977c478bd9Sstevel@tonic-gate 		}
4987c478bd9Sstevel@tonic-gate 	}
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	if (nport == 0)
5017c478bd9Sstevel@tonic-gate 		usage();
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	/* get key value (required last argument) */
5047c478bd9Sstevel@tonic-gate 	if (optind != (argc-1))
5057c478bd9Sstevel@tonic-gate 		usage();
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	errno = 0;
5087c478bd9Sstevel@tonic-gate 	key = (int)strtol(argv[optind], &endp, 10);
5097c478bd9Sstevel@tonic-gate 	if (errno != 0 || key < 1 || *endp != '\0') {
5107c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
5117c478bd9Sstevel@tonic-gate 		    gettext("%s: illegal key value '%d'\n"),
5127c478bd9Sstevel@tonic-gate 		    progname, key);
5137c478bd9Sstevel@tonic-gate 		exit(1);
5147c478bd9Sstevel@tonic-gate 	}
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	if (laadm_add(key, nport, port, t_arg, altroot, &diag) < 0) {
5177c478bd9Sstevel@tonic-gate 		PRINT_ERR_DIAG("%s: add operation failed: %s", diag,
5187c478bd9Sstevel@tonic-gate 		    laadm_diag);
5197c478bd9Sstevel@tonic-gate 		exit(1);
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate static void
5247c478bd9Sstevel@tonic-gate do_remove_aggr(int argc, char *argv[])
5257c478bd9Sstevel@tonic-gate {
5267c478bd9Sstevel@tonic-gate 	char			option;
5277c478bd9Sstevel@tonic-gate 	uint16_t		key;
5287c478bd9Sstevel@tonic-gate 	laadm_port_attr_db_t	port[MAXPORT];
5297c478bd9Sstevel@tonic-gate 	uint_t			nport = 0;
5307c478bd9Sstevel@tonic-gate 	boolean_t		t_arg = B_FALSE;
5317c478bd9Sstevel@tonic-gate 	char			*altroot = NULL;
5327c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
5337c478bd9Sstevel@tonic-gate 	laadm_diag_t		diag = 0;
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	opterr = 0;
5367c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":d:R:t",
5377c478bd9Sstevel@tonic-gate 	    longopts, NULL)) != -1) {
5387c478bd9Sstevel@tonic-gate 		switch (option) {
5397c478bd9Sstevel@tonic-gate 		case 'd':
5407c478bd9Sstevel@tonic-gate 			if (nport >= MAXPORT) {
5417c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
5427c478bd9Sstevel@tonic-gate 				    gettext("%s: too many <dev> arguments\n"),
5437c478bd9Sstevel@tonic-gate 				    progname);
5447c478bd9Sstevel@tonic-gate 				exit(1);
5457c478bd9Sstevel@tonic-gate 			}
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 			if (strlcpy(port[nport].lp_devname, optarg,
5487c478bd9Sstevel@tonic-gate 			    MAXNAMELEN) >= MAXNAMELEN) {
5497c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
5507c478bd9Sstevel@tonic-gate 				    gettext("%s: device name too long\n"),
5517c478bd9Sstevel@tonic-gate 				    progname);
5527c478bd9Sstevel@tonic-gate 				exit(1);
5537c478bd9Sstevel@tonic-gate 			}
5547c478bd9Sstevel@tonic-gate 			port[nport].lp_port = 0;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 			nport++;
5577c478bd9Sstevel@tonic-gate 			break;
5587c478bd9Sstevel@tonic-gate 		case 't':
5597c478bd9Sstevel@tonic-gate 			t_arg = B_TRUE;
5607c478bd9Sstevel@tonic-gate 			break;
5617c478bd9Sstevel@tonic-gate 		case 'R':
5627c478bd9Sstevel@tonic-gate 			altroot = optarg;
5637c478bd9Sstevel@tonic-gate 			break;
5647c478bd9Sstevel@tonic-gate 		case ':':
5657c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5667c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
5677c478bd9Sstevel@tonic-gate 			    progname, optopt);
5687c478bd9Sstevel@tonic-gate 			exit(1);
5697c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
5707c478bd9Sstevel@tonic-gate 		case '?':
5717c478bd9Sstevel@tonic-gate 		default:
5727c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5737c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
5747c478bd9Sstevel@tonic-gate 			    progname, optopt);
5757c478bd9Sstevel@tonic-gate 			exit(1);
5767c478bd9Sstevel@tonic-gate 		}
5777c478bd9Sstevel@tonic-gate 	}
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	if (nport == 0)
5807c478bd9Sstevel@tonic-gate 		usage();
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	/* get key value (required last argument) */
5837c478bd9Sstevel@tonic-gate 	if (optind != (argc-1))
5847c478bd9Sstevel@tonic-gate 		usage();
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	errno = 0;
5877c478bd9Sstevel@tonic-gate 	key = (int)strtol(argv[optind], &endp, 10);
5887c478bd9Sstevel@tonic-gate 	if (errno != 0 || key < 1 || *endp != '\0') {
5897c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
5907c478bd9Sstevel@tonic-gate 		    gettext("%s: illegal key value '%d'\n"),
5917c478bd9Sstevel@tonic-gate 		    progname, key);
5927c478bd9Sstevel@tonic-gate 		exit(1);
5937c478bd9Sstevel@tonic-gate 	}
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	if (laadm_remove(key, nport, port, t_arg, altroot, &diag) < 0) {
5967c478bd9Sstevel@tonic-gate 		PRINT_ERR_DIAG("%s: remove operation failed: %s", diag,
5977c478bd9Sstevel@tonic-gate 		    laadm_diag);
5987c478bd9Sstevel@tonic-gate 		exit(1);
5997c478bd9Sstevel@tonic-gate 	}
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate static void
6037c478bd9Sstevel@tonic-gate do_modify_aggr(int argc, char *argv[])
6047c478bd9Sstevel@tonic-gate {
6057c478bd9Sstevel@tonic-gate 	char			option;
6067c478bd9Sstevel@tonic-gate 	uint16_t		key;
6077c478bd9Sstevel@tonic-gate 	uint32_t		policy = AGGR_POLICY_L4;
6087c478bd9Sstevel@tonic-gate 	aggr_lacp_mode_t	lacp_mode = AGGR_LACP_OFF;
6097c478bd9Sstevel@tonic-gate 	aggr_lacp_timer_t	lacp_timer = AGGR_LACP_TIMER_SHORT;
6107c478bd9Sstevel@tonic-gate 	uint8_t			mac_addr[ETHERADDRL];
6117c478bd9Sstevel@tonic-gate 	boolean_t		mac_addr_fixed = B_FALSE;
6127c478bd9Sstevel@tonic-gate 	uint8_t			modify_mask = 0;
6137c478bd9Sstevel@tonic-gate 	boolean_t		t_arg = B_FALSE;
6147c478bd9Sstevel@tonic-gate 	char			*altroot = NULL;
6157c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
6167c478bd9Sstevel@tonic-gate 	laadm_diag_t		diag = 0;
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	opterr = 0;
6197c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":l:P:R:tu:T:", longopts,
6207c478bd9Sstevel@tonic-gate 	    NULL)) != -1) {
6217c478bd9Sstevel@tonic-gate 		switch (option) {
6227c478bd9Sstevel@tonic-gate 		case 'P':
6237c478bd9Sstevel@tonic-gate 			if (modify_mask & LAADM_MODIFY_POLICY) {
6247c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
6257c478bd9Sstevel@tonic-gate 				    "%s: the option -P cannot be specified "
6267c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
6277c478bd9Sstevel@tonic-gate 				usage();
6287c478bd9Sstevel@tonic-gate 			}
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 			modify_mask |= LAADM_MODIFY_POLICY;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_policy(optarg, &policy)) {
6337c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
6347c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid policy '%s'\n"),
6357c478bd9Sstevel@tonic-gate 				    progname, optarg);
6367c478bd9Sstevel@tonic-gate 				exit(1);
6377c478bd9Sstevel@tonic-gate 			}
6387c478bd9Sstevel@tonic-gate 			break;
6397c478bd9Sstevel@tonic-gate 		case 'u':
6407c478bd9Sstevel@tonic-gate 			if (modify_mask & LAADM_MODIFY_MAC) {
6417c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
6427c478bd9Sstevel@tonic-gate 				    "%s: the option -u cannot be specified "
6437c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
6447c478bd9Sstevel@tonic-gate 				usage();
6457c478bd9Sstevel@tonic-gate 			}
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 			modify_mask |= LAADM_MODIFY_MAC;
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_mac_addr(optarg, &mac_addr_fixed,
6507c478bd9Sstevel@tonic-gate 			    mac_addr)) {
6517c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
6527c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid MAC address '%s'\n"),
6537c478bd9Sstevel@tonic-gate 				    progname, optarg);
6547c478bd9Sstevel@tonic-gate 				exit(1);
6557c478bd9Sstevel@tonic-gate 			}
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 			break;
6587c478bd9Sstevel@tonic-gate 		case 'l':
6597c478bd9Sstevel@tonic-gate 			if (modify_mask & LAADM_MODIFY_LACP_MODE) {
6607c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
6617c478bd9Sstevel@tonic-gate 				    "%s: the option -l cannot be specified "
6627c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
6637c478bd9Sstevel@tonic-gate 				usage();
6647c478bd9Sstevel@tonic-gate 			}
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 			modify_mask |= LAADM_MODIFY_LACP_MODE;
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_lacp_mode(optarg, &lacp_mode)) {
6697c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
6707c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid LACP mode '%s'\n"),
6717c478bd9Sstevel@tonic-gate 				    progname, optarg);
6727c478bd9Sstevel@tonic-gate 				exit(1);
6737c478bd9Sstevel@tonic-gate 			}
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 			break;
6767c478bd9Sstevel@tonic-gate 		case 'T':
6777c478bd9Sstevel@tonic-gate 			if (modify_mask & LAADM_MODIFY_LACP_TIMER) {
6787c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
6797c478bd9Sstevel@tonic-gate 				    "%s: the option -T cannot be specified "
6807c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
6817c478bd9Sstevel@tonic-gate 				usage();
6827c478bd9Sstevel@tonic-gate 			}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 			modify_mask |= LAADM_MODIFY_LACP_TIMER;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 			if (!laadm_str_to_lacp_timer(optarg, &lacp_timer)) {
6877c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
6887c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid LACP timer value"
6897c478bd9Sstevel@tonic-gate 				    " '%s'\n"),
6907c478bd9Sstevel@tonic-gate 				    progname, optarg);
6917c478bd9Sstevel@tonic-gate 				exit(1);
6927c478bd9Sstevel@tonic-gate 			}
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 			break;
6957c478bd9Sstevel@tonic-gate 		case 't':
6967c478bd9Sstevel@tonic-gate 			t_arg = B_TRUE;
6977c478bd9Sstevel@tonic-gate 			break;
6987c478bd9Sstevel@tonic-gate 		case 'R':
6997c478bd9Sstevel@tonic-gate 			altroot = optarg;
7007c478bd9Sstevel@tonic-gate 			break;
7017c478bd9Sstevel@tonic-gate 		case ':':
7027c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
7037c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
7047c478bd9Sstevel@tonic-gate 			    progname, optopt);
7057c478bd9Sstevel@tonic-gate 			exit(1);
7067c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
7077c478bd9Sstevel@tonic-gate 		case '?':
7087c478bd9Sstevel@tonic-gate 		default:
7097c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
7107c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
7117c478bd9Sstevel@tonic-gate 			    progname, optopt);
7127c478bd9Sstevel@tonic-gate 			exit(1);
7137c478bd9Sstevel@tonic-gate 		}
7147c478bd9Sstevel@tonic-gate 	}
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	if (modify_mask == 0) {
7177c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: at least one of the "
7187c478bd9Sstevel@tonic-gate 		    "-PulT options must be specified\n"), progname);
7197c478bd9Sstevel@tonic-gate 		usage();
7207c478bd9Sstevel@tonic-gate 	}
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	/* get key value (required last argument) */
7237c478bd9Sstevel@tonic-gate 	if (optind != (argc-1))
7247c478bd9Sstevel@tonic-gate 		usage();
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 	errno = 0;
7277c478bd9Sstevel@tonic-gate 	key = (int)strtol(argv[optind], &endp, 10);
7287c478bd9Sstevel@tonic-gate 	if (errno != 0 || key < 1 || *endp != '\0') {
7297c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
7307c478bd9Sstevel@tonic-gate 		    gettext("%s: illegal key value '%d'\n"),
7317c478bd9Sstevel@tonic-gate 		    progname, key);
7327c478bd9Sstevel@tonic-gate 		exit(1);
7337c478bd9Sstevel@tonic-gate 	}
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	if (laadm_modify(key, modify_mask, policy, mac_addr_fixed, mac_addr,
7377c478bd9Sstevel@tonic-gate 	    lacp_mode, lacp_timer, t_arg, altroot, &diag) < 0) {
7387c478bd9Sstevel@tonic-gate 		PRINT_ERR_DIAG("%s: modify operation failed: %s", diag,
7397c478bd9Sstevel@tonic-gate 		    laadm_diag);
7407c478bd9Sstevel@tonic-gate 		exit(1);
7417c478bd9Sstevel@tonic-gate 	}
7427c478bd9Sstevel@tonic-gate }
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate static void
7457c478bd9Sstevel@tonic-gate do_up_aggr(int argc, char *argv[])
7467c478bd9Sstevel@tonic-gate {
7477c478bd9Sstevel@tonic-gate 	uint16_t	key = 0;
7487c478bd9Sstevel@tonic-gate 	char		*endp = NULL;
7497c478bd9Sstevel@tonic-gate 	laadm_diag_t	diag = 0;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 	/* get aggregation key (optional last argument) */
7527c478bd9Sstevel@tonic-gate 	if (argc == 2) {
7537c478bd9Sstevel@tonic-gate 		errno = 0;
7547c478bd9Sstevel@tonic-gate 		key = (int)strtol(argv[1], &endp, 10);
7557c478bd9Sstevel@tonic-gate 		if (errno != 0 || key < 1 || *endp != '\0') {
7567c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
7577c478bd9Sstevel@tonic-gate 			    gettext("%s: illegal key value '%d'\n"),
7587c478bd9Sstevel@tonic-gate 			    progname, key);
7597c478bd9Sstevel@tonic-gate 			exit(1);
7607c478bd9Sstevel@tonic-gate 		}
7617c478bd9Sstevel@tonic-gate 	} else if (argc > 2) {
7627c478bd9Sstevel@tonic-gate 		usage();
7637c478bd9Sstevel@tonic-gate 	}
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	if (laadm_up(key, NULL, &diag) < 0) {
7667c478bd9Sstevel@tonic-gate 		if (key != 0) {
7677c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
7687c478bd9Sstevel@tonic-gate 			    gettext("%s: could not bring up aggregation"
7697c478bd9Sstevel@tonic-gate 			    " '%u' : %s"), progname, key, strerror(errno));
7707c478bd9Sstevel@tonic-gate 			if (diag != 0)
7717c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, " (%s)",
7727c478bd9Sstevel@tonic-gate 				    laadm_diag(diag));
7737c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "\n");
7747c478bd9Sstevel@tonic-gate 		} else {
7757c478bd9Sstevel@tonic-gate 			PRINT_ERR_DIAG(
7767c478bd9Sstevel@tonic-gate 			    "%s: could not bring aggregations up: %s",
7777c478bd9Sstevel@tonic-gate 			    diag, laadm_diag);
7787c478bd9Sstevel@tonic-gate 		}
7797c478bd9Sstevel@tonic-gate 		exit(1);
7807c478bd9Sstevel@tonic-gate 	}
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate static void
7847c478bd9Sstevel@tonic-gate do_down_aggr(int argc, char *argv[])
7857c478bd9Sstevel@tonic-gate {
7867c478bd9Sstevel@tonic-gate 	uint16_t	key = 0;
7877c478bd9Sstevel@tonic-gate 	char		*endp = NULL;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	/* get aggregation key (optional last argument) */
7907c478bd9Sstevel@tonic-gate 	if (argc == 2) {
7917c478bd9Sstevel@tonic-gate 		errno = 0;
7927c478bd9Sstevel@tonic-gate 		key = (int)strtol(argv[1], &endp, 10);
7937c478bd9Sstevel@tonic-gate 		if (errno != 0 || key < 1 || *endp != '\0') {
7947c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
7957c478bd9Sstevel@tonic-gate 			    gettext("%s: illegal key value '%d'\n"),
7967c478bd9Sstevel@tonic-gate 			    progname, key);
7977c478bd9Sstevel@tonic-gate 			exit(1);
7987c478bd9Sstevel@tonic-gate 		}
7997c478bd9Sstevel@tonic-gate 	} else if (argc > 2) {
8007c478bd9Sstevel@tonic-gate 		usage();
8017c478bd9Sstevel@tonic-gate 	}
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 	if (laadm_down(key) < 0) {
8047c478bd9Sstevel@tonic-gate 		if (key != 0) {
8057c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
8067c478bd9Sstevel@tonic-gate 			    gettext("%s: could not bring aggregation"
8077c478bd9Sstevel@tonic-gate 			    " down '%u' : %s"),
8087c478bd9Sstevel@tonic-gate 			    progname, key, strerror(errno));
8097c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "\n");
8107c478bd9Sstevel@tonic-gate 		} else {
8117c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
8127c478bd9Sstevel@tonic-gate 			    gettext("%s: could not bring aggregations"
8137c478bd9Sstevel@tonic-gate 			    " down: %s"), progname, strerror(errno));
8147c478bd9Sstevel@tonic-gate 		}
8157c478bd9Sstevel@tonic-gate 		exit(1);
8167c478bd9Sstevel@tonic-gate 	}
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate #define	TYPE_WIDTH	10
820210db224Sericheng 
821210db224Sericheng static void
822210db224Sericheng print_link_parseable(const char *name, dladm_attr_t *dap, boolean_t legacy)
823210db224Sericheng {
824210db224Sericheng 	char		type[TYPE_WIDTH];
825210db224Sericheng 
826210db224Sericheng 	if (!legacy) {
827210db224Sericheng 		if (dap->da_vid != 0) {
828210db224Sericheng 			(void) snprintf(type, TYPE_WIDTH, "vlan %u",
829210db224Sericheng 			    dap->da_vid);
830210db224Sericheng 		} else {
831210db224Sericheng 			(void) snprintf(type, TYPE_WIDTH, "non-vlan");
832210db224Sericheng 		}
833210db224Sericheng 		if (strcmp(dap->da_dev, AGGR_DEV) == 0) {
834210db224Sericheng 			(void) printf("%s type=%s mtu=%d key=%u\n",
835210db224Sericheng 			    name, type, dap->da_max_sdu, dap->da_port);
836210db224Sericheng 		} else {
837210db224Sericheng 			(void) printf("%s type=%s mtu=%d device=%s\n",
838210db224Sericheng 			    name, type, dap->da_max_sdu, dap->da_dev);
839210db224Sericheng 		}
840210db224Sericheng 	} else {
841210db224Sericheng 		(void) printf("%s type=legacy mtu=%d device=%s\n",
842210db224Sericheng 		    name, dap->da_max_sdu, name);
843210db224Sericheng 	}
844210db224Sericheng }
845210db224Sericheng 
846210db224Sericheng static void
847210db224Sericheng print_link(const char *name, dladm_attr_t *dap, boolean_t legacy)
848210db224Sericheng {
849210db224Sericheng 	char		type[TYPE_WIDTH];
850210db224Sericheng 
851210db224Sericheng 	if (!legacy) {
852210db224Sericheng 		if (dap->da_vid != 0) {
853210db224Sericheng 			(void) snprintf(type, TYPE_WIDTH, gettext("vlan %u"),
854210db224Sericheng 			    dap->da_vid);
855210db224Sericheng 		} else {
856210db224Sericheng 			(void) snprintf(type, TYPE_WIDTH, gettext("non-vlan"));
857210db224Sericheng 		}
858210db224Sericheng 		if (strcmp(dap->da_dev, AGGR_DEV) == 0) {
859210db224Sericheng 			(void) printf(gettext("%-9s\ttype: %s\tmtu: %d"
860210db224Sericheng 			    "\taggregation: key %u\n"), name, type,
861210db224Sericheng 			    dap->da_max_sdu, dap->da_port);
862210db224Sericheng 		} else {
863210db224Sericheng 			(void) printf(gettext("%-9s\ttype: %s\tmtu: "
864210db224Sericheng 			    "%d\tdevice: %s\n"), name, type, dap->da_max_sdu,
865210db224Sericheng 			    dap->da_dev);
866210db224Sericheng 		}
867210db224Sericheng 	} else {
868210db224Sericheng 		(void) printf(gettext("%-9s\ttype: legacy\tmtu: "
869210db224Sericheng 		    "%d\tdevice: %s\n"), name, dap->da_max_sdu, name);
870210db224Sericheng 	}
871210db224Sericheng }
872210db224Sericheng 
873210db224Sericheng static int
874210db224Sericheng get_if_info(const char *name, dladm_attr_t *dlattrp, boolean_t *legacy)
875210db224Sericheng {
876210db224Sericheng 	int	err;
877210db224Sericheng 
878210db224Sericheng 	if ((err = dladm_info(name, dlattrp)) == 0) {
879210db224Sericheng 		*legacy = B_FALSE;
880210db224Sericheng 	} else if (err < 0 && errno == ENODEV) {
881210db224Sericheng 		int		fd;
882210db224Sericheng 		dlpi_if_attr_t	dia;
883210db224Sericheng 		dl_info_ack_t	dlia;
884210db224Sericheng 
885210db224Sericheng 		/*
886210db224Sericheng 		 * A return value of ENODEV means that the specified
887210db224Sericheng 		 * device is not gldv3.
888210db224Sericheng 		 */
889210db224Sericheng 		if ((fd = dlpi_if_open(name, &dia, B_FALSE)) != -1 &&
890210db224Sericheng 		    dlpi_info(fd, -1, &dlia, NULL, NULL, NULL, NULL,
891210db224Sericheng 		    NULL, NULL) != -1) {
892210db224Sericheng 			(void) dlpi_close(fd);
893210db224Sericheng 
894210db224Sericheng 			*legacy = B_TRUE;
895210db224Sericheng 			bzero(dlattrp, sizeof (*dlattrp));
896210db224Sericheng 			dlattrp->da_max_sdu = (uint_t)dlia.dl_max_sdu;
897210db224Sericheng 		} else {
898210db224Sericheng 			errno = ENOENT;
899210db224Sericheng 			return (-1);
900210db224Sericheng 		}
901210db224Sericheng 	} else {
902210db224Sericheng 		/*
903210db224Sericheng 		 * If the return value is not ENODEV, this means that
904210db224Sericheng 		 * user is either passing in a bogus interface name
905210db224Sericheng 		 * or a vlan interface name that doesn't exist yet.
906210db224Sericheng 		 */
907210db224Sericheng 		errno = ENOENT;
908210db224Sericheng 		return (-1);
909210db224Sericheng 	}
910210db224Sericheng 	return (0);
911210db224Sericheng }
9127c478bd9Sstevel@tonic-gate 
9137c478bd9Sstevel@tonic-gate /* ARGSUSED */
9147c478bd9Sstevel@tonic-gate static void
9157c478bd9Sstevel@tonic-gate show_link(void *arg, const char *name)
9167c478bd9Sstevel@tonic-gate {
9177c478bd9Sstevel@tonic-gate 	dladm_attr_t	dlattr;
918210db224Sericheng 	boolean_t	legacy = B_TRUE;
9197c478bd9Sstevel@tonic-gate 	show_link_state_t *state = (show_link_state_t *)arg;
9207c478bd9Sstevel@tonic-gate 
921210db224Sericheng 	if (get_if_info(name, &dlattr, &legacy) < 0) {
922210db224Sericheng 		(void) fprintf(stderr, gettext("%s: invalid device '%s'\n"),
9237c478bd9Sstevel@tonic-gate 		    progname, name);
9247c478bd9Sstevel@tonic-gate 		exit(1);
9257c478bd9Sstevel@tonic-gate 	}
9267c478bd9Sstevel@tonic-gate 
927210db224Sericheng 	if (state->ls_parseable) {
928210db224Sericheng 		print_link_parseable(name, &dlattr, legacy);
9297c478bd9Sstevel@tonic-gate 	} else {
930210db224Sericheng 		print_link(name, &dlattr, legacy);
9317c478bd9Sstevel@tonic-gate 	}
9327c478bd9Sstevel@tonic-gate }
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate static void
9357c478bd9Sstevel@tonic-gate show_link_stats(void *arg, const char *name)
9367c478bd9Sstevel@tonic-gate {
9377c478bd9Sstevel@tonic-gate 	show_link_state_t *state = (show_link_state_t *)arg;
9387c478bd9Sstevel@tonic-gate 	pktsum_t stats, diff_stats;
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	if (state->ls_firstonly) {
9417c478bd9Sstevel@tonic-gate 		if (state->ls_donefirst)
9427c478bd9Sstevel@tonic-gate 			return;
9437c478bd9Sstevel@tonic-gate 		state->ls_donefirst = B_TRUE;
9447c478bd9Sstevel@tonic-gate 	} else {
9457c478bd9Sstevel@tonic-gate 		bzero(&state->ls_prevstats, sizeof (state->ls_prevstats));
9467c478bd9Sstevel@tonic-gate 	}
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	get_link_stats(name, &stats);
9497c478bd9Sstevel@tonic-gate 	stats_diff(&diff_stats, &stats, &state->ls_prevstats);
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	(void) printf("%s", name);
9527c478bd9Sstevel@tonic-gate 	(void) printf("\t\t%-10llu", diff_stats.ipackets);
9537c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.rbytes);
9547c478bd9Sstevel@tonic-gate 	(void) printf("%-8u", diff_stats.ierrors);
9557c478bd9Sstevel@tonic-gate 	(void) printf("%-10llu", diff_stats.opackets);
9567c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.obytes);
9577c478bd9Sstevel@tonic-gate 	(void) printf("%-8u\n", diff_stats.oerrors);
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	state->ls_prevstats = stats;
9607c478bd9Sstevel@tonic-gate }
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate static void
9637c478bd9Sstevel@tonic-gate dump_grp(laadm_grp_attr_sys_t	*grp, boolean_t parseable)
9647c478bd9Sstevel@tonic-gate {
9657c478bd9Sstevel@tonic-gate 	char policy_str[LAADM_POLICY_STR_LEN];
9667c478bd9Sstevel@tonic-gate 	char addr_str[ETHERADDRL * 3];
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 	if (!parseable) {
9697c478bd9Sstevel@tonic-gate 		(void) printf(gettext("key: %d (0x%04x)"),
9707c478bd9Sstevel@tonic-gate 		    grp->lg_key, grp->lg_key);
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\tpolicy: %s"),
9737c478bd9Sstevel@tonic-gate 		    laadm_policy_to_str(grp->lg_policy, policy_str));
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\taddress: %s (%s)\n"),
9767c478bd9Sstevel@tonic-gate 		    laadm_mac_addr_to_str(grp->lg_mac, addr_str),
9777c478bd9Sstevel@tonic-gate 		    (grp->lg_mac_fixed) ? gettext("fixed") : gettext("auto"));
9787c478bd9Sstevel@tonic-gate 	} else {
9797c478bd9Sstevel@tonic-gate 		(void) printf("aggr key=%d", grp->lg_key);
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 		(void) printf(" policy=%s",
9827c478bd9Sstevel@tonic-gate 		    laadm_policy_to_str(grp->lg_policy, policy_str));
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 		(void) printf(" address=%s",
9857c478bd9Sstevel@tonic-gate 		    laadm_mac_addr_to_str(grp->lg_mac, addr_str));
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 		(void) printf(" address-type=%s\n",
9887c478bd9Sstevel@tonic-gate 		    (grp->lg_mac_fixed) ? "fixed" : "auto");
9897c478bd9Sstevel@tonic-gate 	}
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate static void
9937c478bd9Sstevel@tonic-gate dump_grp_lacp(laadm_grp_attr_sys_t *grp, boolean_t parseable)
9947c478bd9Sstevel@tonic-gate {
9957c478bd9Sstevel@tonic-gate 	const char *lacp_mode_str = laadm_lacp_mode_to_str(grp->lg_lacp_mode);
9967c478bd9Sstevel@tonic-gate 	const char *lacp_timer_str =
9977c478bd9Sstevel@tonic-gate 	    laadm_lacp_timer_to_str(grp->lg_lacp_timer);
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 	if (!parseable) {
10007c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\t\tLACP mode: %s"), lacp_mode_str);
10017c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\tLACP timer: %s\n"), lacp_timer_str);
10027c478bd9Sstevel@tonic-gate 	} else {
10037c478bd9Sstevel@tonic-gate 		(void) printf(" lacp-mode=%s", lacp_mode_str);
10047c478bd9Sstevel@tonic-gate 		(void) printf(" lacp-timer=%s\n", lacp_timer_str);
10057c478bd9Sstevel@tonic-gate 	}
10067c478bd9Sstevel@tonic-gate }
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate static void
10097c478bd9Sstevel@tonic-gate dump_grp_stats(laadm_grp_attr_sys_t *grp)
10107c478bd9Sstevel@tonic-gate {
10117c478bd9Sstevel@tonic-gate 	(void) printf("key: %d", grp->lg_key);
10127c478bd9Sstevel@tonic-gate 	(void) printf("\tipackets  rbytes      opackets	 obytes		 ");
10137c478bd9Sstevel@tonic-gate 	(void) printf("%%ipkts	%%opkts\n");
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate static void
10177c478bd9Sstevel@tonic-gate dump_ports_lacp_head(void)
10187c478bd9Sstevel@tonic-gate {
10197c478bd9Sstevel@tonic-gate 	(void) printf(DUMP_LACP_FORMAT, gettext("device"), gettext("activity"),
10207c478bd9Sstevel@tonic-gate 	    gettext("timeout"), gettext("aggregatable"), gettext("sync"),
10217c478bd9Sstevel@tonic-gate 	    gettext("coll"), gettext("dist"), gettext("defaulted"),
10227c478bd9Sstevel@tonic-gate 	    gettext("expired"));
10237c478bd9Sstevel@tonic-gate }
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate static void
10267c478bd9Sstevel@tonic-gate dump_ports_head(void)
10277c478bd9Sstevel@tonic-gate {
10287c478bd9Sstevel@tonic-gate 	(void) printf(gettext("	   device\taddress\t\t	speed\t\tduplex\tlink\t"
10297c478bd9Sstevel@tonic-gate 	    "state\n"));
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate static char *
10337c478bd9Sstevel@tonic-gate port_state_to_str(aggr_port_state_t state_num)
10347c478bd9Sstevel@tonic-gate {
10357c478bd9Sstevel@tonic-gate 	int			i;
10367c478bd9Sstevel@tonic-gate 	port_state_t		*state;
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 	for (i = 0; i < NPORTSTATES; i++) {
10397c478bd9Sstevel@tonic-gate 		state = &port_states[i];
10407c478bd9Sstevel@tonic-gate 		if (state->state_num == state_num)
10417c478bd9Sstevel@tonic-gate 			return (state->state_name);
10427c478bd9Sstevel@tonic-gate 	}
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 	return ("unknown");
10457c478bd9Sstevel@tonic-gate }
10467c478bd9Sstevel@tonic-gate 
10477c478bd9Sstevel@tonic-gate static void
10487c478bd9Sstevel@tonic-gate dump_port(laadm_port_attr_sys_t *port, boolean_t parseable)
10497c478bd9Sstevel@tonic-gate {
10507c478bd9Sstevel@tonic-gate 	char *dev = port->lp_devname;
10517c478bd9Sstevel@tonic-gate 	uint_t portnum = port->lp_port;
10527c478bd9Sstevel@tonic-gate 	char buf[ETHERADDRL * 3];
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	if (!parseable) {
10557c478bd9Sstevel@tonic-gate 		(void) printf("	   %-9s\t%s", dev, laadm_mac_addr_to_str(
10567c478bd9Sstevel@tonic-gate 		    port->lp_mac, buf));
10577c478bd9Sstevel@tonic-gate 		(void) printf("\t  %-5u Mbps", (int)(mac_ifspeed(dev, portnum) /
10587c478bd9Sstevel@tonic-gate 		    1000000ull));
10597c478bd9Sstevel@tonic-gate 		(void) printf("\t%s", mac_link_duplex(dev, portnum));
10607c478bd9Sstevel@tonic-gate 		(void) printf("\t%s", mac_link_state(dev, portnum));
10617c478bd9Sstevel@tonic-gate 		(void) printf("\t%s\n", port_state_to_str(port->lp_state));
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate 	} else {
10647c478bd9Sstevel@tonic-gate 		(void) printf(" device=%s address=%s", dev,
10657c478bd9Sstevel@tonic-gate 		    laadm_mac_addr_to_str(port->lp_mac, buf));
10667c478bd9Sstevel@tonic-gate 		(void) printf(" speed=%u", (int)(mac_ifspeed(dev, portnum) /
10677c478bd9Sstevel@tonic-gate 		    1000000ull));
10687c478bd9Sstevel@tonic-gate 		(void) printf(" duplex=%s", mac_link_duplex(dev, portnum));
10697c478bd9Sstevel@tonic-gate 		(void) printf(" link=%s", mac_link_state(dev, portnum));
10707c478bd9Sstevel@tonic-gate 		(void) printf(" port=%s", port_state_to_str(port->lp_state));
10717c478bd9Sstevel@tonic-gate 	}
10727c478bd9Sstevel@tonic-gate }
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate static void
10757c478bd9Sstevel@tonic-gate dump_port_lacp(laadm_port_attr_sys_t *port)
10767c478bd9Sstevel@tonic-gate {
10777c478bd9Sstevel@tonic-gate 	aggr_lacp_state_t *state = &port->lp_lacp_state;
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 	(void) printf(DUMP_LACP_FORMAT,
10807c478bd9Sstevel@tonic-gate 	    port->lp_devname, state->bit.activity ? "active" : "passive",
10817c478bd9Sstevel@tonic-gate 	    state->bit.timeout ? "short" : "long",
10827c478bd9Sstevel@tonic-gate 	    state->bit.aggregation ? "yes" : "no",
10837c478bd9Sstevel@tonic-gate 	    state->bit.sync ? "yes" : "no",
10847c478bd9Sstevel@tonic-gate 	    state->bit.collecting ? "yes" : "no",
10857c478bd9Sstevel@tonic-gate 	    state->bit.distributing ? "yes" : "no",
10867c478bd9Sstevel@tonic-gate 	    state->bit.defaulted ? "yes" : "no",
10877c478bd9Sstevel@tonic-gate 	    state->bit.expired ? "yes" : "no");
10887c478bd9Sstevel@tonic-gate }
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate static void
10917c478bd9Sstevel@tonic-gate dump_port_stat(int index, show_grp_state_t *state, pktsum_t *port_stats,
10927c478bd9Sstevel@tonic-gate     pktsum_t *tot_stats)
10937c478bd9Sstevel@tonic-gate {
10947c478bd9Sstevel@tonic-gate 	pktsum_t	diff_stats;
10957c478bd9Sstevel@tonic-gate 	pktsum_t	*old_stats = &state->gs_prevstats[index];
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	stats_diff(&diff_stats, port_stats, old_stats);
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate 	(void) printf("\t%-10llu", diff_stats.ipackets);
11007c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.rbytes);
11017c478bd9Sstevel@tonic-gate 	(void) printf("%-10llu", diff_stats.opackets);
11027c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.obytes);
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	if (tot_stats->ipackets == 0)
11057c478bd9Sstevel@tonic-gate 		(void) printf("\t-");
11067c478bd9Sstevel@tonic-gate 	else
11077c478bd9Sstevel@tonic-gate 		(void) printf("\t%-6.1f", (double)diff_stats.ipackets/
11087c478bd9Sstevel@tonic-gate 		    (double)tot_stats->ipackets * 100);
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate 	if (tot_stats->opackets == 0)
11117c478bd9Sstevel@tonic-gate 		(void) printf("\t-");
11127c478bd9Sstevel@tonic-gate 	else
11137c478bd9Sstevel@tonic-gate 		(void) printf("\t%-6.1f", (double)diff_stats.opackets/
11147c478bd9Sstevel@tonic-gate 		    (double)tot_stats->opackets * 100);
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate 	(void) printf("\n");
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 	*old_stats = *port_stats;
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate static int
11227c478bd9Sstevel@tonic-gate show_key(void *arg, laadm_grp_attr_sys_t *grp)
11237c478bd9Sstevel@tonic-gate {
11247c478bd9Sstevel@tonic-gate 	show_grp_state_t	*state = (show_grp_state_t *)arg;
11257c478bd9Sstevel@tonic-gate 	int			i;
11267c478bd9Sstevel@tonic-gate 	pktsum_t		pktsumtot, port_stat;
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 	if (state->gs_key != 0 && state->gs_key != grp->lg_key)
11297c478bd9Sstevel@tonic-gate 		return (0);
11307c478bd9Sstevel@tonic-gate 	if (state->gs_firstonly) {
11317c478bd9Sstevel@tonic-gate 		if (state->gs_found)
11327c478bd9Sstevel@tonic-gate 			return (0);
11337c478bd9Sstevel@tonic-gate 	} else {
11347c478bd9Sstevel@tonic-gate 		bzero(&state->gs_prevstats, sizeof (state->gs_prevstats));
11357c478bd9Sstevel@tonic-gate 	}
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 	state->gs_found = B_TRUE;
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	if (state->gs_stats) {
11407c478bd9Sstevel@tonic-gate 		/* show statistics */
11417c478bd9Sstevel@tonic-gate 		dump_grp_stats(grp);
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 		/* sum the ports statistics */
11447c478bd9Sstevel@tonic-gate 		bzero(&pktsumtot, sizeof (pktsumtot));
11457c478bd9Sstevel@tonic-gate 		for (i = 0; i < grp->lg_nports; i++) {
11467c478bd9Sstevel@tonic-gate 			get_mac_stats(grp->lg_ports[i].lp_devname,
11477c478bd9Sstevel@tonic-gate 			    grp->lg_ports[i].lp_port, &port_stat);
11487c478bd9Sstevel@tonic-gate 			stats_total(&pktsumtot, &port_stat,
11497c478bd9Sstevel@tonic-gate 			    &state->gs_prevstats[i]);
11507c478bd9Sstevel@tonic-gate 		}
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 		(void) printf("	   Total");
11537c478bd9Sstevel@tonic-gate 		(void) printf("\t%-10llu", pktsumtot.ipackets);
11547c478bd9Sstevel@tonic-gate 		(void) printf("%-12llu", pktsumtot.rbytes);
11557c478bd9Sstevel@tonic-gate 		(void) printf("%-10llu", pktsumtot.opackets);
11567c478bd9Sstevel@tonic-gate 		(void) printf("%-12llu\n", pktsumtot.obytes);
11577c478bd9Sstevel@tonic-gate 
11587c478bd9Sstevel@tonic-gate 		for (i = 0; i < grp->lg_nports; i++) {
11597c478bd9Sstevel@tonic-gate 			get_mac_stats(grp->lg_ports[i].lp_devname,
11607c478bd9Sstevel@tonic-gate 			    grp->lg_ports[i].lp_port, &port_stat);
11617c478bd9Sstevel@tonic-gate 			(void) printf("	   %s", grp->lg_ports[i].lp_devname);
11627c478bd9Sstevel@tonic-gate 			dump_port_stat(i, state, &port_stat, &pktsumtot);
11637c478bd9Sstevel@tonic-gate 		}
11647c478bd9Sstevel@tonic-gate 	} else if (state->gs_lacp) {
11657c478bd9Sstevel@tonic-gate 		/* show LACP info */
11667c478bd9Sstevel@tonic-gate 		dump_grp(grp, state->gs_parseable);
11677c478bd9Sstevel@tonic-gate 		dump_grp_lacp(grp, state->gs_parseable);
11687c478bd9Sstevel@tonic-gate 		dump_ports_lacp_head();
11697c478bd9Sstevel@tonic-gate 		for (i = 0; i < grp->lg_nports; i++)
11707c478bd9Sstevel@tonic-gate 			dump_port_lacp(&grp->lg_ports[i]);
11717c478bd9Sstevel@tonic-gate 	} else {
11727c478bd9Sstevel@tonic-gate 		dump_grp(grp, state->gs_parseable);
11737c478bd9Sstevel@tonic-gate 		if (!state->gs_parseable)
11747c478bd9Sstevel@tonic-gate 			dump_ports_head();
11757c478bd9Sstevel@tonic-gate 		for (i = 0; i < grp->lg_nports; i++) {
11767c478bd9Sstevel@tonic-gate 			if (state->gs_parseable)
11777c478bd9Sstevel@tonic-gate 				(void) printf("dev key=%d", grp->lg_key);
11787c478bd9Sstevel@tonic-gate 			dump_port(&grp->lg_ports[i], state->gs_parseable);
11797c478bd9Sstevel@tonic-gate 			if (state->gs_parseable)
11807c478bd9Sstevel@tonic-gate 				(void) printf("\n");
11817c478bd9Sstevel@tonic-gate 		}
11827c478bd9Sstevel@tonic-gate 	}
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	return (0);
11857c478bd9Sstevel@tonic-gate }
11867c478bd9Sstevel@tonic-gate 
11877c478bd9Sstevel@tonic-gate static int
11887c478bd9Sstevel@tonic-gate kstat_value(kstat_t *ksp, const char *name, uint8_t type, void *buf)
11897c478bd9Sstevel@tonic-gate {
11907c478bd9Sstevel@tonic-gate 	kstat_named_t	*knp;
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate 	if ((knp = kstat_data_lookup(ksp, (char *)name)) == NULL)
11937c478bd9Sstevel@tonic-gate 		return (-1);
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate 	if (knp->data_type != type)
11967c478bd9Sstevel@tonic-gate 		return (-1);
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate 	switch (type) {
11997c478bd9Sstevel@tonic-gate 	case KSTAT_DATA_UINT64:
12007c478bd9Sstevel@tonic-gate 		*(uint64_t *)buf = knp->value.ui64;
12017c478bd9Sstevel@tonic-gate 		break;
12027c478bd9Sstevel@tonic-gate 	case KSTAT_DATA_UINT32:
12037c478bd9Sstevel@tonic-gate 		*(uint32_t *)buf = knp->value.ui32;
12047c478bd9Sstevel@tonic-gate 		break;
12057c478bd9Sstevel@tonic-gate 	default:
12067c478bd9Sstevel@tonic-gate 		return (-1);
12077c478bd9Sstevel@tonic-gate 	}
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate 	return (0);
12107c478bd9Sstevel@tonic-gate }
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate static void
1213210db224Sericheng show_dev(void *arg, const char *dev)
12147c478bd9Sstevel@tonic-gate {
12157c478bd9Sstevel@tonic-gate 	show_mac_state_t *state = (show_mac_state_t *)arg;
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	(void) printf("%s", dev);
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 	if (!state->ms_parseable) {
12207c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\t\tlink: %s"),
1221210db224Sericheng 		    mac_link_state(dev, 0));
12227c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\tspeed: %-5u Mbps"),
1223210db224Sericheng 		    (unsigned int)(mac_ifspeed(dev, 0) / 1000000ull));
12247c478bd9Sstevel@tonic-gate 		(void) printf(gettext("\tduplex: %s\n"),
1225210db224Sericheng 		    mac_link_duplex(dev, 0));
12267c478bd9Sstevel@tonic-gate 	} else {
1227210db224Sericheng 		(void) printf(" link=%s", mac_link_state(dev, 0));
12287c478bd9Sstevel@tonic-gate 		(void) printf(" speed=%u",
1229210db224Sericheng 		    (unsigned int)(mac_ifspeed(dev, 0) / 1000000ull));
1230210db224Sericheng 		(void) printf(" duplex=%s\n", mac_link_duplex(dev, 0));
12317c478bd9Sstevel@tonic-gate 	}
12327c478bd9Sstevel@tonic-gate }
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12357c478bd9Sstevel@tonic-gate static void
1236210db224Sericheng show_dev_stats(void *arg, const char *dev)
12377c478bd9Sstevel@tonic-gate {
12387c478bd9Sstevel@tonic-gate 	show_mac_state_t *state = (show_mac_state_t *)arg;
12397c478bd9Sstevel@tonic-gate 	pktsum_t stats, diff_stats;
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	if (state->ms_firstonly) {
12427c478bd9Sstevel@tonic-gate 		if (state->ms_donefirst)
12437c478bd9Sstevel@tonic-gate 			return;
12447c478bd9Sstevel@tonic-gate 		state->ms_donefirst = B_TRUE;
12457c478bd9Sstevel@tonic-gate 	} else {
12467c478bd9Sstevel@tonic-gate 		bzero(&state->ms_prevstats, sizeof (state->ms_prevstats));
12477c478bd9Sstevel@tonic-gate 	}
12487c478bd9Sstevel@tonic-gate 
1249210db224Sericheng 	get_mac_stats(dev, 0, &stats);
12507c478bd9Sstevel@tonic-gate 	stats_diff(&diff_stats, &stats, &state->ms_prevstats);
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	(void) printf("%s", dev);
12537c478bd9Sstevel@tonic-gate 	(void) printf("\t\t%-10llu", diff_stats.ipackets);
12547c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.rbytes);
12557c478bd9Sstevel@tonic-gate 	(void) printf("%-8u", diff_stats.ierrors);
12567c478bd9Sstevel@tonic-gate 	(void) printf("%-10llu", diff_stats.opackets);
12577c478bd9Sstevel@tonic-gate 	(void) printf("%-12llu", diff_stats.obytes);
12587c478bd9Sstevel@tonic-gate 	(void) printf("%-8u\n", diff_stats.oerrors);
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate 	state->ms_prevstats = stats;
12617c478bd9Sstevel@tonic-gate }
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate static void
12647c478bd9Sstevel@tonic-gate do_show_link(int argc, char *argv[])
12657c478bd9Sstevel@tonic-gate {
12667c478bd9Sstevel@tonic-gate 	char		*name = NULL;
12677c478bd9Sstevel@tonic-gate 	int		option;
12687c478bd9Sstevel@tonic-gate 	boolean_t	s_arg = B_FALSE;
12697c478bd9Sstevel@tonic-gate 	boolean_t	i_arg = B_FALSE;
12707c478bd9Sstevel@tonic-gate 	uint32_t	interval = 0;
12717c478bd9Sstevel@tonic-gate 	show_link_state_t state;
12727c478bd9Sstevel@tonic-gate 	char		*endp = NULL;
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate 	state.ls_stats = B_FALSE;
12757c478bd9Sstevel@tonic-gate 	state.ls_parseable = B_FALSE;
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@tonic-gate 	opterr = 0;
12787c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":psi:",
12797c478bd9Sstevel@tonic-gate 	    longopts, NULL)) != -1) {
12807c478bd9Sstevel@tonic-gate 		switch (option) {
12817c478bd9Sstevel@tonic-gate 		case 'p':
12827c478bd9Sstevel@tonic-gate 			state.ls_parseable = B_TRUE;
12837c478bd9Sstevel@tonic-gate 			break;
12847c478bd9Sstevel@tonic-gate 		case 's':
12857c478bd9Sstevel@tonic-gate 			if (s_arg) {
12867c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
12877c478bd9Sstevel@tonic-gate 				    "%s: the option -s cannot be specified "
12887c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
12897c478bd9Sstevel@tonic-gate 				usage();
12907c478bd9Sstevel@tonic-gate 			}
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 			s_arg = B_TRUE;
12937c478bd9Sstevel@tonic-gate 			break;
12947c478bd9Sstevel@tonic-gate 		case 'i':
12957c478bd9Sstevel@tonic-gate 			if (i_arg) {
12967c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
12977c478bd9Sstevel@tonic-gate 				    "%s: the option -i cannot be specified "
12987c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
12997c478bd9Sstevel@tonic-gate 				usage();
13007c478bd9Sstevel@tonic-gate 			}
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 			i_arg = B_TRUE;
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate 			errno = 0;
13057c478bd9Sstevel@tonic-gate 			interval = (int)strtol(optarg, &endp, 10);
13067c478bd9Sstevel@tonic-gate 			if (errno != 0 || interval == 0 || *endp != '\0') {
13077c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
13087c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid interval value"
13097c478bd9Sstevel@tonic-gate 				    " '%d'\n"),
13107c478bd9Sstevel@tonic-gate 				    progname, interval);
13117c478bd9Sstevel@tonic-gate 				exit(1);
13127c478bd9Sstevel@tonic-gate 			}
13137c478bd9Sstevel@tonic-gate 			break;
13147c478bd9Sstevel@tonic-gate 		case ':':
13157c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
13167c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
13177c478bd9Sstevel@tonic-gate 			    progname, optopt);
13187c478bd9Sstevel@tonic-gate 			exit(1);
13197c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
13207c478bd9Sstevel@tonic-gate 		case '?':
13217c478bd9Sstevel@tonic-gate 		default:
13227c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
13237c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
13247c478bd9Sstevel@tonic-gate 			    progname, optopt);
13257c478bd9Sstevel@tonic-gate 			exit(1);
13267c478bd9Sstevel@tonic-gate 		}
13277c478bd9Sstevel@tonic-gate 	}
13287c478bd9Sstevel@tonic-gate 
13297c478bd9Sstevel@tonic-gate 	if (i_arg && !s_arg) {
13307c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: the option -i "
13317c478bd9Sstevel@tonic-gate 		    "can be used only with -s\n"), progname);
13327c478bd9Sstevel@tonic-gate 		usage();
13337c478bd9Sstevel@tonic-gate 	}
13347c478bd9Sstevel@tonic-gate 
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate 	/* get link name (optional last argument) */
13377c478bd9Sstevel@tonic-gate 	if (optind == (argc-1))
13387c478bd9Sstevel@tonic-gate 		name = argv[optind];
13397c478bd9Sstevel@tonic-gate 	else if (optind != argc)
13407c478bd9Sstevel@tonic-gate 		usage();
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 	if (s_arg) {
13437c478bd9Sstevel@tonic-gate 		link_stats(name, interval);
13447c478bd9Sstevel@tonic-gate 		return;
13457c478bd9Sstevel@tonic-gate 	}
13467c478bd9Sstevel@tonic-gate 
1347210db224Sericheng 	if (name == NULL) {
13487c478bd9Sstevel@tonic-gate 		(void) dladm_walk(show_link, &state);
1349210db224Sericheng 	} else {
13507c478bd9Sstevel@tonic-gate 		show_link(&state, name);
13517c478bd9Sstevel@tonic-gate 	}
1352210db224Sericheng }
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate static void
13557c478bd9Sstevel@tonic-gate do_show_aggr(int argc, char *argv[])
13567c478bd9Sstevel@tonic-gate {
13577c478bd9Sstevel@tonic-gate 	int			option;
13587c478bd9Sstevel@tonic-gate 	uint16_t		key = 0;
13597c478bd9Sstevel@tonic-gate 	boolean_t		L_arg = B_FALSE;
13607c478bd9Sstevel@tonic-gate 	boolean_t		s_arg = B_FALSE;
13617c478bd9Sstevel@tonic-gate 	boolean_t		i_arg = B_FALSE;
13627c478bd9Sstevel@tonic-gate 	show_grp_state_t	state;
13637c478bd9Sstevel@tonic-gate 	uint32_t		interval = 0;
13647c478bd9Sstevel@tonic-gate 	char			*endp = NULL;
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 	state.gs_stats = B_FALSE;
13677c478bd9Sstevel@tonic-gate 	state.gs_lacp = B_FALSE;
13687c478bd9Sstevel@tonic-gate 	state.gs_parseable = B_FALSE;
13697c478bd9Sstevel@tonic-gate 
13707c478bd9Sstevel@tonic-gate 	opterr = 0;
13717c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":Lpsi:",
13727c478bd9Sstevel@tonic-gate 	    longopts, NULL)) != -1) {
13737c478bd9Sstevel@tonic-gate 		switch (option) {
13747c478bd9Sstevel@tonic-gate 		case 'L':
13757c478bd9Sstevel@tonic-gate 			if (L_arg) {
13767c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
13777c478bd9Sstevel@tonic-gate 				    "%s: the option -L cannot be specified "
13787c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
13797c478bd9Sstevel@tonic-gate 				usage();
13807c478bd9Sstevel@tonic-gate 			}
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate 			if (s_arg || i_arg) {
13837c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
13847c478bd9Sstevel@tonic-gate 				    "%s: the option -L cannot be used with "
13857c478bd9Sstevel@tonic-gate 				    "any of -is\n"), progname);
13867c478bd9Sstevel@tonic-gate 				usage();
13877c478bd9Sstevel@tonic-gate 			}
13887c478bd9Sstevel@tonic-gate 
13897c478bd9Sstevel@tonic-gate 			L_arg = B_TRUE;
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate 			state.gs_lacp = B_TRUE;
13927c478bd9Sstevel@tonic-gate 			break;
13937c478bd9Sstevel@tonic-gate 		case 'p':
13947c478bd9Sstevel@tonic-gate 			state.gs_parseable = B_TRUE;
13957c478bd9Sstevel@tonic-gate 			break;
13967c478bd9Sstevel@tonic-gate 		case 's':
13977c478bd9Sstevel@tonic-gate 			if (s_arg) {
13987c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
13997c478bd9Sstevel@tonic-gate 				    "%s: the option -s cannot be specified "
14007c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
14017c478bd9Sstevel@tonic-gate 				usage();
14027c478bd9Sstevel@tonic-gate 			}
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 			if (L_arg) {
14057c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
14067c478bd9Sstevel@tonic-gate 				    "%s: the option -L cannot be used "
14077c478bd9Sstevel@tonic-gate 				    "with -k\n"), progname);
14087c478bd9Sstevel@tonic-gate 				usage();
14097c478bd9Sstevel@tonic-gate 			}
14107c478bd9Sstevel@tonic-gate 
14117c478bd9Sstevel@tonic-gate 			s_arg = B_TRUE;
14127c478bd9Sstevel@tonic-gate 			break;
14137c478bd9Sstevel@tonic-gate 		case 'i':
14147c478bd9Sstevel@tonic-gate 			if (i_arg) {
14157c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
14167c478bd9Sstevel@tonic-gate 				    "%s: the option -i cannot be specified "
14177c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
14187c478bd9Sstevel@tonic-gate 				usage();
14197c478bd9Sstevel@tonic-gate 			}
14207c478bd9Sstevel@tonic-gate 
14217c478bd9Sstevel@tonic-gate 			if (L_arg) {
14227c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
14237c478bd9Sstevel@tonic-gate 				    "%s: the option -i cannot be used "
14247c478bd9Sstevel@tonic-gate 				    "with -L\n"), progname);
14257c478bd9Sstevel@tonic-gate 				usage();
14267c478bd9Sstevel@tonic-gate 			}
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate 			i_arg = B_TRUE;
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 			errno = 0;
14317c478bd9Sstevel@tonic-gate 			interval = (int)strtol(optarg, &endp, 10);
14327c478bd9Sstevel@tonic-gate 			if (errno != 0 || interval == 0 || *endp != '\0') {
14337c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
14347c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid interval value"
14357c478bd9Sstevel@tonic-gate 				    " '%d'\n"),
14367c478bd9Sstevel@tonic-gate 				    progname, interval);
14377c478bd9Sstevel@tonic-gate 				exit(1);
14387c478bd9Sstevel@tonic-gate 			}
14397c478bd9Sstevel@tonic-gate 			break;
14407c478bd9Sstevel@tonic-gate 		case ':':
14417c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
14427c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
14437c478bd9Sstevel@tonic-gate 			    progname, optopt);
14447c478bd9Sstevel@tonic-gate 			exit(1);
14457c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
14467c478bd9Sstevel@tonic-gate 		case '?':
14477c478bd9Sstevel@tonic-gate 		default:
14487c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
14497c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
14507c478bd9Sstevel@tonic-gate 			    progname, optopt);
14517c478bd9Sstevel@tonic-gate 			exit(1);
14527c478bd9Sstevel@tonic-gate 		}
14537c478bd9Sstevel@tonic-gate 	}
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate 	if (i_arg && !s_arg) {
14567c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: the option -i "
14577c478bd9Sstevel@tonic-gate 		    "can be used only with -s\n"), progname);
14587c478bd9Sstevel@tonic-gate 		usage();
14597c478bd9Sstevel@tonic-gate 	}
14607c478bd9Sstevel@tonic-gate 
14617c478bd9Sstevel@tonic-gate 	/* get aggregation key (optional last argument) */
14627c478bd9Sstevel@tonic-gate 	if (optind == (argc-1)) {
14637c478bd9Sstevel@tonic-gate 		errno = 0;
14647c478bd9Sstevel@tonic-gate 		key = (int)strtol(argv[optind], &endp, 10);
14657c478bd9Sstevel@tonic-gate 		if (errno != 0 || key < 1 || *endp != '\0') {
14667c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
14677c478bd9Sstevel@tonic-gate 			    gettext("%s: illegal key value '%d'\n"),
14687c478bd9Sstevel@tonic-gate 			    progname, key);
14697c478bd9Sstevel@tonic-gate 			exit(1);
14707c478bd9Sstevel@tonic-gate 		}
14717c478bd9Sstevel@tonic-gate 	} else if (optind != argc) {
14727c478bd9Sstevel@tonic-gate 		usage();
14737c478bd9Sstevel@tonic-gate 	}
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate 	if (s_arg) {
14767c478bd9Sstevel@tonic-gate 		aggr_stats(key, interval);
14777c478bd9Sstevel@tonic-gate 		return;
14787c478bd9Sstevel@tonic-gate 	}
14797c478bd9Sstevel@tonic-gate 
14807c478bd9Sstevel@tonic-gate 	state.gs_key = key;
14817c478bd9Sstevel@tonic-gate 	state.gs_found = B_FALSE;
14827c478bd9Sstevel@tonic-gate 
14837c478bd9Sstevel@tonic-gate 	(void) laadm_walk_sys(show_key, &state);
14847c478bd9Sstevel@tonic-gate 
14857c478bd9Sstevel@tonic-gate 	if (key != 0 && !state.gs_found) {
14867c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
14877c478bd9Sstevel@tonic-gate 		    gettext("%s: non-existent aggregation key '%u'\n"),
14887c478bd9Sstevel@tonic-gate 		    progname, key);
14897c478bd9Sstevel@tonic-gate 		exit(1);
14907c478bd9Sstevel@tonic-gate 	}
14917c478bd9Sstevel@tonic-gate }
14927c478bd9Sstevel@tonic-gate 
14937c478bd9Sstevel@tonic-gate static void
14947c478bd9Sstevel@tonic-gate do_show_dev(int argc, char *argv[])
14957c478bd9Sstevel@tonic-gate {
14967c478bd9Sstevel@tonic-gate 	int		option;
14977c478bd9Sstevel@tonic-gate 	char		*dev = NULL;
14987c478bd9Sstevel@tonic-gate 	boolean_t	s_arg = B_FALSE;
14997c478bd9Sstevel@tonic-gate 	boolean_t	i_arg = B_FALSE;
15007c478bd9Sstevel@tonic-gate 	uint32_t	interval = 0;
15017c478bd9Sstevel@tonic-gate 	show_mac_state_t state;
15027c478bd9Sstevel@tonic-gate 	char		*endp = NULL;
15037c478bd9Sstevel@tonic-gate 
15047c478bd9Sstevel@tonic-gate 	state.ms_parseable = B_FALSE;
15057c478bd9Sstevel@tonic-gate 
15067c478bd9Sstevel@tonic-gate 	opterr = 0;
15077c478bd9Sstevel@tonic-gate 	while ((option = getopt_long(argc, argv, ":psi:",
15087c478bd9Sstevel@tonic-gate 	    longopts, NULL)) != -1) {
15097c478bd9Sstevel@tonic-gate 		switch (option) {
15107c478bd9Sstevel@tonic-gate 		case 'p':
15117c478bd9Sstevel@tonic-gate 			state.ms_parseable = B_TRUE;
15127c478bd9Sstevel@tonic-gate 			break;
15137c478bd9Sstevel@tonic-gate 		case 's':
15147c478bd9Sstevel@tonic-gate 			if (s_arg) {
15157c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
15167c478bd9Sstevel@tonic-gate 				    "%s: the option -s cannot be specified "
15177c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
15187c478bd9Sstevel@tonic-gate 				usage();
15197c478bd9Sstevel@tonic-gate 			}
15207c478bd9Sstevel@tonic-gate 
15217c478bd9Sstevel@tonic-gate 			s_arg = B_TRUE;
15227c478bd9Sstevel@tonic-gate 			break;
15237c478bd9Sstevel@tonic-gate 		case 'i':
15247c478bd9Sstevel@tonic-gate 			if (i_arg) {
15257c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
15267c478bd9Sstevel@tonic-gate 				    "%s: the option -i cannot be specified "
15277c478bd9Sstevel@tonic-gate 				    "more than once\n"), progname);
15287c478bd9Sstevel@tonic-gate 				usage();
15297c478bd9Sstevel@tonic-gate 			}
15307c478bd9Sstevel@tonic-gate 
15317c478bd9Sstevel@tonic-gate 			i_arg = B_TRUE;
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate 			errno = 0;
15347c478bd9Sstevel@tonic-gate 			interval = (int)strtol(optarg, &endp, 10);
15357c478bd9Sstevel@tonic-gate 			if (errno != 0 || interval == 0 || *endp != '\0') {
15367c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
15377c478bd9Sstevel@tonic-gate 				    gettext("%s: invalid interval value"
15387c478bd9Sstevel@tonic-gate 				    " '%d'\n"),
15397c478bd9Sstevel@tonic-gate 				    progname, interval);
15407c478bd9Sstevel@tonic-gate 				exit(1);
15417c478bd9Sstevel@tonic-gate 			}
15427c478bd9Sstevel@tonic-gate 			break;
15437c478bd9Sstevel@tonic-gate 		case ':':
15447c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
15457c478bd9Sstevel@tonic-gate 			    gettext("%s: option requires a value '-%c'\n"),
15467c478bd9Sstevel@tonic-gate 			    progname, optopt);
15477c478bd9Sstevel@tonic-gate 			exit(1);
15487c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
15497c478bd9Sstevel@tonic-gate 		case '?':
15507c478bd9Sstevel@tonic-gate 		default:
15517c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
15527c478bd9Sstevel@tonic-gate 			    gettext("%s: unrecognized option '-%c'\n"),
15537c478bd9Sstevel@tonic-gate 			    progname, optopt);
15547c478bd9Sstevel@tonic-gate 			exit(1);
15557c478bd9Sstevel@tonic-gate 		}
15567c478bd9Sstevel@tonic-gate 	}
15577c478bd9Sstevel@tonic-gate 
15587c478bd9Sstevel@tonic-gate 	if (i_arg && !s_arg) {
15597c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: the option -i "
15607c478bd9Sstevel@tonic-gate 		    "can be used only with -s\n"), progname);
15617c478bd9Sstevel@tonic-gate 		usage();
15627c478bd9Sstevel@tonic-gate 	}
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate 	/* get dev name (optional last argument) */
15657c478bd9Sstevel@tonic-gate 	if (optind == (argc-1))
15667c478bd9Sstevel@tonic-gate 		dev = argv[optind];
15677c478bd9Sstevel@tonic-gate 	else if (optind != argc)
15687c478bd9Sstevel@tonic-gate 		usage();
15697c478bd9Sstevel@tonic-gate 
1570*cd93090eSericheng 	if (dev != NULL) {
1571*cd93090eSericheng 		int		index;
1572*cd93090eSericheng 		char		drv[LIFNAMSIZ];
1573*cd93090eSericheng 		dladm_attr_t	dlattr;
1574*cd93090eSericheng 		boolean_t	legacy;
1575*cd93090eSericheng 
1576*cd93090eSericheng 		/*
1577*cd93090eSericheng 		 * Check for invalid devices.
1578*cd93090eSericheng 		 * aggregations and vlans are not considered devices.
1579*cd93090eSericheng 		 */
1580*cd93090eSericheng 		if (strncmp(dev, "aggr", 4) == 0 ||
1581*cd93090eSericheng 		    dlpi_if_parse(dev, drv, &index) < 0 ||
1582*cd93090eSericheng 		    index >= 1000 ||
1583*cd93090eSericheng 		    get_if_info(dev, &dlattr, &legacy) < 0) {
15847c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
1585*cd93090eSericheng 			    gettext("%s: invalid device '%s'\n"),
15867c478bd9Sstevel@tonic-gate 			    progname, dev);
15877c478bd9Sstevel@tonic-gate 			exit(1);
15887c478bd9Sstevel@tonic-gate 		}
1589*cd93090eSericheng 	}
15907c478bd9Sstevel@tonic-gate 
15917c478bd9Sstevel@tonic-gate 	if (s_arg) {
15927c478bd9Sstevel@tonic-gate 		dev_stats(dev, interval);
15937c478bd9Sstevel@tonic-gate 		return;
15947c478bd9Sstevel@tonic-gate 	}
15957c478bd9Sstevel@tonic-gate 
15967c478bd9Sstevel@tonic-gate 	if (dev == NULL)
15977c478bd9Sstevel@tonic-gate 		(void) macadm_walk(show_dev, &state, B_TRUE);
15987c478bd9Sstevel@tonic-gate 	else
1599210db224Sericheng 		show_dev(&state, dev);
16007c478bd9Sstevel@tonic-gate }
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate /* ARGSUSED */
16037c478bd9Sstevel@tonic-gate static void
16047c478bd9Sstevel@tonic-gate link_stats(const char *link, uint32_t interval)
16057c478bd9Sstevel@tonic-gate {
1606210db224Sericheng 	dladm_attr_t		dlattr;
1607210db224Sericheng 	boolean_t		legacy;
16087c478bd9Sstevel@tonic-gate 	show_link_state_t	state;
16097c478bd9Sstevel@tonic-gate 
1610210db224Sericheng 	if (link != NULL && get_if_info(link, &dlattr, &legacy) < 0) {
1611210db224Sericheng 		(void) fprintf(stderr, gettext("%s: invalid device '%s'\n"),
16127c478bd9Sstevel@tonic-gate 		    progname, link);
16137c478bd9Sstevel@tonic-gate 		exit(1);
16147c478bd9Sstevel@tonic-gate 	}
16157c478bd9Sstevel@tonic-gate 	bzero(&state, sizeof (state));
16167c478bd9Sstevel@tonic-gate 
16177c478bd9Sstevel@tonic-gate 	/*
16187c478bd9Sstevel@tonic-gate 	 * If an interval is specified, continuously show the stats
16197c478bd9Sstevel@tonic-gate 	 * only for the first MAC port.
16207c478bd9Sstevel@tonic-gate 	 */
16217c478bd9Sstevel@tonic-gate 	state.ls_firstonly = (interval != 0);
16227c478bd9Sstevel@tonic-gate 
16237c478bd9Sstevel@tonic-gate 	for (;;) {
16247c478bd9Sstevel@tonic-gate 		(void) printf("\t\tipackets  rbytes	 ierrors ");
16257c478bd9Sstevel@tonic-gate 		(void) printf("opackets	 obytes	     oerrors\n");
16267c478bd9Sstevel@tonic-gate 
16277c478bd9Sstevel@tonic-gate 		state.ls_donefirst = B_FALSE;
16287c478bd9Sstevel@tonic-gate 		if (link == NULL)
16297c478bd9Sstevel@tonic-gate 			(void) dladm_walk(show_link_stats, &state);
16307c478bd9Sstevel@tonic-gate 		else
16317c478bd9Sstevel@tonic-gate 			show_link_stats(&state, link);
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 		if (interval == 0)
16347c478bd9Sstevel@tonic-gate 			break;
16357c478bd9Sstevel@tonic-gate 
16367c478bd9Sstevel@tonic-gate 		(void) sleep(interval);
16377c478bd9Sstevel@tonic-gate 	}
16387c478bd9Sstevel@tonic-gate }
16397c478bd9Sstevel@tonic-gate 
16407c478bd9Sstevel@tonic-gate /* ARGSUSED */
16417c478bd9Sstevel@tonic-gate static void
16427c478bd9Sstevel@tonic-gate aggr_stats(uint16_t key, uint32_t interval)
16437c478bd9Sstevel@tonic-gate {
16447c478bd9Sstevel@tonic-gate 	show_grp_state_t state;
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate 	bzero(&state, sizeof (state));
16477c478bd9Sstevel@tonic-gate 	state.gs_stats = B_TRUE;
16487c478bd9Sstevel@tonic-gate 	state.gs_key = key;
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate 	/*
16517c478bd9Sstevel@tonic-gate 	 * If an interval is specified, continuously show the stats
16527c478bd9Sstevel@tonic-gate 	 * only for the first group.
16537c478bd9Sstevel@tonic-gate 	 */
16547c478bd9Sstevel@tonic-gate 	state.gs_firstonly = (interval != 0);
16557c478bd9Sstevel@tonic-gate 
16567c478bd9Sstevel@tonic-gate 	for (;;) {
16577c478bd9Sstevel@tonic-gate 		state.gs_found = B_FALSE;
16587c478bd9Sstevel@tonic-gate 		(void) laadm_walk_sys(show_key, &state);
16597c478bd9Sstevel@tonic-gate 		if (state.gs_key != 0 && !state.gs_found) {
16607c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
16617c478bd9Sstevel@tonic-gate 			    gettext("%s: non-existent aggregation key '%u'\n"),
16627c478bd9Sstevel@tonic-gate 			    progname, key);
16637c478bd9Sstevel@tonic-gate 			exit(1);
16647c478bd9Sstevel@tonic-gate 		}
16657c478bd9Sstevel@tonic-gate 
16667c478bd9Sstevel@tonic-gate 		if (interval == 0)
16677c478bd9Sstevel@tonic-gate 			break;
16687c478bd9Sstevel@tonic-gate 
16697c478bd9Sstevel@tonic-gate 		(void) sleep(interval);
16707c478bd9Sstevel@tonic-gate 	}
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate 
16737c478bd9Sstevel@tonic-gate /* ARGSUSED */
16747c478bd9Sstevel@tonic-gate static void
16757c478bd9Sstevel@tonic-gate dev_stats(const char *dev, uint32_t interval)
16767c478bd9Sstevel@tonic-gate {
16777c478bd9Sstevel@tonic-gate 	show_mac_state_t state;
16787c478bd9Sstevel@tonic-gate 
16797c478bd9Sstevel@tonic-gate 	bzero(&state, sizeof (state));
16807c478bd9Sstevel@tonic-gate 
16817c478bd9Sstevel@tonic-gate 	/*
16827c478bd9Sstevel@tonic-gate 	 * If an interval is specified, continuously show the stats
16837c478bd9Sstevel@tonic-gate 	 * only for the first MAC port.
16847c478bd9Sstevel@tonic-gate 	 */
16857c478bd9Sstevel@tonic-gate 	state.ms_firstonly = (interval != 0);
16867c478bd9Sstevel@tonic-gate 
16877c478bd9Sstevel@tonic-gate 	for (;;) {
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 		(void) printf("\t\tipackets  rbytes	 ierrors ");
16907c478bd9Sstevel@tonic-gate 		(void) printf("opackets	 obytes	     oerrors\n");
16917c478bd9Sstevel@tonic-gate 
16927c478bd9Sstevel@tonic-gate 		state.ms_donefirst = B_FALSE;
1693210db224Sericheng 		if (dev == NULL)
16947c478bd9Sstevel@tonic-gate 			(void) macadm_walk(show_dev_stats, &state, B_TRUE);
1695210db224Sericheng 		else
1696210db224Sericheng 			show_dev_stats(&state, dev);
16977c478bd9Sstevel@tonic-gate 
16987c478bd9Sstevel@tonic-gate 		if (interval == 0)
16997c478bd9Sstevel@tonic-gate 			break;
17007c478bd9Sstevel@tonic-gate 
17017c478bd9Sstevel@tonic-gate 		(void) sleep(interval);
17027c478bd9Sstevel@tonic-gate 	}
17037c478bd9Sstevel@tonic-gate }
17047c478bd9Sstevel@tonic-gate 
17057c478bd9Sstevel@tonic-gate /* accumulate stats (s1 += (s2 - s3)) */
17067c478bd9Sstevel@tonic-gate static void
17077c478bd9Sstevel@tonic-gate stats_total(pktsum_t *s1, pktsum_t *s2, pktsum_t *s3)
17087c478bd9Sstevel@tonic-gate {
17097c478bd9Sstevel@tonic-gate 	s1->ipackets += (s2->ipackets - s3->ipackets);
17107c478bd9Sstevel@tonic-gate 	s1->opackets += (s2->opackets - s3->opackets);
17117c478bd9Sstevel@tonic-gate 	s1->rbytes += (s2->rbytes - s3->rbytes);
17127c478bd9Sstevel@tonic-gate 	s1->obytes += (s2->obytes - s3->obytes);
17137c478bd9Sstevel@tonic-gate 	s1->ierrors += (s2->ierrors - s3->ierrors);
17147c478bd9Sstevel@tonic-gate 	s1->oerrors += (s2->oerrors - s3->oerrors);
17157c478bd9Sstevel@tonic-gate }
17167c478bd9Sstevel@tonic-gate 
17177c478bd9Sstevel@tonic-gate /* compute stats differences (s1 = s2 - s3) */
17187c478bd9Sstevel@tonic-gate static void
17197c478bd9Sstevel@tonic-gate stats_diff(pktsum_t *s1, pktsum_t *s2, pktsum_t *s3)
17207c478bd9Sstevel@tonic-gate {
17217c478bd9Sstevel@tonic-gate 	s1->ipackets = s2->ipackets - s3->ipackets;
17227c478bd9Sstevel@tonic-gate 	s1->opackets = s2->opackets - s3->opackets;
17237c478bd9Sstevel@tonic-gate 	s1->rbytes = s2->rbytes - s3->rbytes;
17247c478bd9Sstevel@tonic-gate 	s1->obytes = s2->obytes - s3->obytes;
17257c478bd9Sstevel@tonic-gate 	s1->ierrors = s2->ierrors - s3->ierrors;
17267c478bd9Sstevel@tonic-gate 	s1->oerrors = s2->oerrors - s3->oerrors;
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate 
1729*cd93090eSericheng /*
1730*cd93090eSericheng  * In the following routines, we do the first kstat_lookup()
1731*cd93090eSericheng  * assuming that the device is gldv3-based and that the kstat
1732*cd93090eSericheng  * name is of the format <driver_name><instance>/<port>. If the
1733*cd93090eSericheng  * lookup fails, we redo the kstat_lookup() using the kstat name
1734*cd93090eSericheng  * <driver_name><instance>. This second lookup is needed for
1735*cd93090eSericheng  * getting kstats from legacy devices. This can fail too if the
1736*cd93090eSericheng  * device is not attached or the device is legacy and doesn't
1737*cd93090eSericheng  * export the kstats we need.
1738*cd93090eSericheng  */
17397c478bd9Sstevel@tonic-gate static void
17407c478bd9Sstevel@tonic-gate get_stats(char *module, int instance, char *name, pktsum_t *stats)
17417c478bd9Sstevel@tonic-gate {
17427c478bd9Sstevel@tonic-gate 	kstat_ctl_t	*kcp;
17437c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
17447c478bd9Sstevel@tonic-gate 
17457c478bd9Sstevel@tonic-gate 	if ((kcp = kstat_open()) == NULL) {
17467c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
17477c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat open operation failed\n"),
17487c478bd9Sstevel@tonic-gate 		    progname);
17497c478bd9Sstevel@tonic-gate 		return;
17507c478bd9Sstevel@tonic-gate 	}
17517c478bd9Sstevel@tonic-gate 
1752*cd93090eSericheng 	if ((ksp = kstat_lookup(kcp, module, instance, name)) == NULL &&
1753*cd93090eSericheng 	    (module == NULL ||
1754*cd93090eSericheng 	    (ksp = kstat_lookup(kcp, NULL, -1, module)) == NULL)) {
17557c478bd9Sstevel@tonic-gate 		/*
17567c478bd9Sstevel@tonic-gate 		 * The kstat query could fail if the underlying MAC
17577c478bd9Sstevel@tonic-gate 		 * driver was already detached.
17587c478bd9Sstevel@tonic-gate 		 */
17597c478bd9Sstevel@tonic-gate 		(void) kstat_close(kcp);
17607c478bd9Sstevel@tonic-gate 		return;
17617c478bd9Sstevel@tonic-gate 	}
17627c478bd9Sstevel@tonic-gate 
17637c478bd9Sstevel@tonic-gate 	if (kstat_read(kcp, ksp, NULL) == -1)
17647c478bd9Sstevel@tonic-gate 		goto bail;
17657c478bd9Sstevel@tonic-gate 
17667c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "ipackets64", KSTAT_DATA_UINT64,
17677c478bd9Sstevel@tonic-gate 	    &stats->ipackets) < 0)
17687c478bd9Sstevel@tonic-gate 		goto bail;
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "opackets64", KSTAT_DATA_UINT64,
17717c478bd9Sstevel@tonic-gate 	    &stats->opackets) < 0)
17727c478bd9Sstevel@tonic-gate 		goto bail;
17737c478bd9Sstevel@tonic-gate 
17747c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "rbytes64", KSTAT_DATA_UINT64,
17757c478bd9Sstevel@tonic-gate 	    &stats->rbytes) < 0)
17767c478bd9Sstevel@tonic-gate 		goto bail;
17777c478bd9Sstevel@tonic-gate 
17787c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "obytes64", KSTAT_DATA_UINT64,
17797c478bd9Sstevel@tonic-gate 	    &stats->obytes) < 0)
17807c478bd9Sstevel@tonic-gate 		goto bail;
17817c478bd9Sstevel@tonic-gate 
17827c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "ierrors", KSTAT_DATA_UINT32,
17837c478bd9Sstevel@tonic-gate 	    &stats->ierrors) < 0)
17847c478bd9Sstevel@tonic-gate 		goto bail;
17857c478bd9Sstevel@tonic-gate 
17867c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "oerrors", KSTAT_DATA_UINT32,
17877c478bd9Sstevel@tonic-gate 	    &stats->oerrors) < 0)
17887c478bd9Sstevel@tonic-gate 		goto bail;
17897c478bd9Sstevel@tonic-gate 
17907c478bd9Sstevel@tonic-gate 	(void) kstat_close(kcp);
17917c478bd9Sstevel@tonic-gate 	return;
17927c478bd9Sstevel@tonic-gate 
17937c478bd9Sstevel@tonic-gate bail:
17947c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
17957c478bd9Sstevel@tonic-gate 	    gettext("%s: kstat operation failed\n"),
17967c478bd9Sstevel@tonic-gate 	    progname);
17977c478bd9Sstevel@tonic-gate 	(void) kstat_close(kcp);
17987c478bd9Sstevel@tonic-gate }
17997c478bd9Sstevel@tonic-gate 
18007c478bd9Sstevel@tonic-gate static void
18017c478bd9Sstevel@tonic-gate get_mac_stats(const char *dev, uint_t port, pktsum_t *stats)
18027c478bd9Sstevel@tonic-gate {
18037c478bd9Sstevel@tonic-gate 	char			name[MAXNAMELEN];
18047c478bd9Sstevel@tonic-gate 
18057c478bd9Sstevel@tonic-gate 	bzero(stats, sizeof (*stats));
18067c478bd9Sstevel@tonic-gate 
18077c478bd9Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN - 1, "%s/%u", dev, port);
18087c478bd9Sstevel@tonic-gate 	get_stats((char *)dev, 0, name, stats);
18097c478bd9Sstevel@tonic-gate }
18107c478bd9Sstevel@tonic-gate 
18117c478bd9Sstevel@tonic-gate static void
18127c478bd9Sstevel@tonic-gate get_link_stats(const char *link, pktsum_t *stats)
18137c478bd9Sstevel@tonic-gate {
18147c478bd9Sstevel@tonic-gate 	bzero(stats, sizeof (*stats));
18157c478bd9Sstevel@tonic-gate 	get_stats(NULL, -1, (char *)link, stats);
18167c478bd9Sstevel@tonic-gate }
18177c478bd9Sstevel@tonic-gate 
18187c478bd9Sstevel@tonic-gate static uint64_t
18197c478bd9Sstevel@tonic-gate mac_ifspeed(const char *dev, uint_t port)
18207c478bd9Sstevel@tonic-gate {
18217c478bd9Sstevel@tonic-gate 	char		name[MAXNAMELEN];
18227c478bd9Sstevel@tonic-gate 	kstat_ctl_t	*kcp;
18237c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
18247c478bd9Sstevel@tonic-gate 	uint64_t	ifspeed = 0;
18257c478bd9Sstevel@tonic-gate 
18267c478bd9Sstevel@tonic-gate 	if ((kcp = kstat_open()) == NULL) {
18277c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
18287c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat open operation failed\n"),
18297c478bd9Sstevel@tonic-gate 		    progname);
18307c478bd9Sstevel@tonic-gate 		return (0);
18317c478bd9Sstevel@tonic-gate 	}
18327c478bd9Sstevel@tonic-gate 
18337c478bd9Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN - 1, "%s/%u", dev, port);
1834*cd93090eSericheng 	if ((ksp = kstat_lookup(kcp, (char *)dev, -1, name)) == NULL &&
1835*cd93090eSericheng 	    (ksp = kstat_lookup(kcp, NULL, -1, (char *)dev)) == NULL) {
1836*cd93090eSericheng 
18377c478bd9Sstevel@tonic-gate 		/*
18387c478bd9Sstevel@tonic-gate 		 * The kstat query could fail if the underlying MAC
18397c478bd9Sstevel@tonic-gate 		 * driver was already detached.
18407c478bd9Sstevel@tonic-gate 		 */
18417c478bd9Sstevel@tonic-gate 		goto bail;
18427c478bd9Sstevel@tonic-gate 	}
18437c478bd9Sstevel@tonic-gate 
18447c478bd9Sstevel@tonic-gate 	if (kstat_read(kcp, ksp, NULL) == -1) {
18457c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
18467c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat read failed\n"),
18477c478bd9Sstevel@tonic-gate 		    progname);
18487c478bd9Sstevel@tonic-gate 		goto bail;
18497c478bd9Sstevel@tonic-gate 	}
18507c478bd9Sstevel@tonic-gate 
18517c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "ifspeed", KSTAT_DATA_UINT64, &ifspeed) < 0) {
18527c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
18537c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat value failed\n"),
18547c478bd9Sstevel@tonic-gate 		    progname);
18557c478bd9Sstevel@tonic-gate 		goto bail;
18567c478bd9Sstevel@tonic-gate 	}
18577c478bd9Sstevel@tonic-gate 
18587c478bd9Sstevel@tonic-gate bail:
18597c478bd9Sstevel@tonic-gate 	(void) kstat_close(kcp);
18607c478bd9Sstevel@tonic-gate 	return (ifspeed);
18617c478bd9Sstevel@tonic-gate }
18627c478bd9Sstevel@tonic-gate 
18637c478bd9Sstevel@tonic-gate static char *
18647c478bd9Sstevel@tonic-gate mac_link_state(const char *dev, uint_t port)
18657c478bd9Sstevel@tonic-gate {
18667c478bd9Sstevel@tonic-gate 	char		name[MAXNAMELEN];
18677c478bd9Sstevel@tonic-gate 	kstat_ctl_t	*kcp;
18687c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
18697c478bd9Sstevel@tonic-gate 	link_state_t	link_state;
18707c478bd9Sstevel@tonic-gate 	char		*state_str = "unknown";
18717c478bd9Sstevel@tonic-gate 
18727c478bd9Sstevel@tonic-gate 	if ((kcp = kstat_open()) == NULL) {
18737c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
18747c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat open operation failed\n"),
18757c478bd9Sstevel@tonic-gate 		    progname);
18767c478bd9Sstevel@tonic-gate 		return (state_str);
18777c478bd9Sstevel@tonic-gate 	}
18787c478bd9Sstevel@tonic-gate 
18797c478bd9Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN - 1, "%s/%u", dev, port);
1880*cd93090eSericheng 
1881*cd93090eSericheng 	if ((ksp = kstat_lookup(kcp, (char *)dev, -1, name)) == NULL &&
1882*cd93090eSericheng 	    (ksp = kstat_lookup(kcp, NULL, -1, (char *)dev)) == NULL) {
18837c478bd9Sstevel@tonic-gate 		/*
18847c478bd9Sstevel@tonic-gate 		 * The kstat query could fail if the underlying MAC
18857c478bd9Sstevel@tonic-gate 		 * driver was already detached.
18867c478bd9Sstevel@tonic-gate 		 */
18877c478bd9Sstevel@tonic-gate 		goto bail;
18887c478bd9Sstevel@tonic-gate 	}
18897c478bd9Sstevel@tonic-gate 
18907c478bd9Sstevel@tonic-gate 	if (kstat_read(kcp, ksp, NULL) == -1) {
18917c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
18927c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat read failed\n"),
18937c478bd9Sstevel@tonic-gate 		    progname);
18947c478bd9Sstevel@tonic-gate 		goto bail;
18957c478bd9Sstevel@tonic-gate 	}
18967c478bd9Sstevel@tonic-gate 
18977c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "link_state", KSTAT_DATA_UINT32,
18987c478bd9Sstevel@tonic-gate 	    &link_state) < 0) {
18997c478bd9Sstevel@tonic-gate 		goto bail;
19007c478bd9Sstevel@tonic-gate 	}
19017c478bd9Sstevel@tonic-gate 
19027c478bd9Sstevel@tonic-gate 	switch (link_state) {
19037c478bd9Sstevel@tonic-gate 	case LINK_STATE_UP:
19047c478bd9Sstevel@tonic-gate 		state_str = "up";
19057c478bd9Sstevel@tonic-gate 		break;
19067c478bd9Sstevel@tonic-gate 	case LINK_STATE_DOWN:
19077c478bd9Sstevel@tonic-gate 		state_str = "down";
19087c478bd9Sstevel@tonic-gate 		break;
19097c478bd9Sstevel@tonic-gate 	default:
19107c478bd9Sstevel@tonic-gate 		break;
19117c478bd9Sstevel@tonic-gate 	}
19127c478bd9Sstevel@tonic-gate 
19137c478bd9Sstevel@tonic-gate bail:
19147c478bd9Sstevel@tonic-gate 	(void) kstat_close(kcp);
19157c478bd9Sstevel@tonic-gate 	return (state_str);
19167c478bd9Sstevel@tonic-gate }
19177c478bd9Sstevel@tonic-gate 
19187c478bd9Sstevel@tonic-gate 
19197c478bd9Sstevel@tonic-gate static char *
19207c478bd9Sstevel@tonic-gate mac_link_duplex(const char *dev, uint_t port)
19217c478bd9Sstevel@tonic-gate {
19227c478bd9Sstevel@tonic-gate 	char		name[MAXNAMELEN];
19237c478bd9Sstevel@tonic-gate 	kstat_ctl_t	*kcp;
19247c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
19257c478bd9Sstevel@tonic-gate 	link_duplex_t	link_duplex;
19267c478bd9Sstevel@tonic-gate 	char		*duplex_str = "unknown";
19277c478bd9Sstevel@tonic-gate 
19287c478bd9Sstevel@tonic-gate 	if ((kcp = kstat_open()) == NULL) {
19297c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
19307c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat open operation failed\n"),
19317c478bd9Sstevel@tonic-gate 		    progname);
19327c478bd9Sstevel@tonic-gate 		return (duplex_str);
19337c478bd9Sstevel@tonic-gate 	}
19347c478bd9Sstevel@tonic-gate 
19357c478bd9Sstevel@tonic-gate 	(void) snprintf(name, MAXNAMELEN - 1, "%s/%u", dev, port);
1936*cd93090eSericheng 
1937*cd93090eSericheng 	if ((ksp = kstat_lookup(kcp, (char *)dev, -1, name)) == NULL &&
1938*cd93090eSericheng 	    (ksp = kstat_lookup(kcp, NULL, -1, (char *)dev)) == NULL) {
19397c478bd9Sstevel@tonic-gate 		/*
19407c478bd9Sstevel@tonic-gate 		 * The kstat query could fail if the underlying MAC
19417c478bd9Sstevel@tonic-gate 		 * driver was already detached.
19427c478bd9Sstevel@tonic-gate 		 */
19437c478bd9Sstevel@tonic-gate 		goto bail;
19447c478bd9Sstevel@tonic-gate 	}
19457c478bd9Sstevel@tonic-gate 
19467c478bd9Sstevel@tonic-gate 	if (kstat_read(kcp, ksp, NULL) == -1) {
19477c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
19487c478bd9Sstevel@tonic-gate 		    gettext("%s: kstat read failed\n"),
19497c478bd9Sstevel@tonic-gate 		    progname);
19507c478bd9Sstevel@tonic-gate 		goto bail;
19517c478bd9Sstevel@tonic-gate 	}
19527c478bd9Sstevel@tonic-gate 
19537c478bd9Sstevel@tonic-gate 	if (kstat_value(ksp, "link_duplex", KSTAT_DATA_UINT32,
19547c478bd9Sstevel@tonic-gate 	    &link_duplex) < 0) {
19557c478bd9Sstevel@tonic-gate 		goto bail;
19567c478bd9Sstevel@tonic-gate 	}
19577c478bd9Sstevel@tonic-gate 	switch (link_duplex) {
19587c478bd9Sstevel@tonic-gate 	case LINK_DUPLEX_FULL:
19597c478bd9Sstevel@tonic-gate 		duplex_str = "full";
19607c478bd9Sstevel@tonic-gate 		break;
19617c478bd9Sstevel@tonic-gate 	case LINK_DUPLEX_HALF:
19627c478bd9Sstevel@tonic-gate 		duplex_str = "half";
19637c478bd9Sstevel@tonic-gate 		break;
19647c478bd9Sstevel@tonic-gate 	default:
19657c478bd9Sstevel@tonic-gate 		break;
19667c478bd9Sstevel@tonic-gate 	}
19677c478bd9Sstevel@tonic-gate 
19687c478bd9Sstevel@tonic-gate bail:
19697c478bd9Sstevel@tonic-gate 	(void) kstat_close(kcp);
19707c478bd9Sstevel@tonic-gate 	return (duplex_str);
19717c478bd9Sstevel@tonic-gate }
1972