Home | History | Annotate | Line # | Download | only in brconfig
brconfig.c revision 1.1.2.1
      1 /*	$NetBSD: brconfig.c,v 1.1.2.1 2003/06/30 03:13:19 grant Exp $	*/
      2 
      3 /*
      4  * Copyright 2001 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * brconfig(8) --
     40  *
     41  *	Configuration utility for the bridge(4) driver.
     42  */
     43 
     44 #include <sys/param.h>
     45 #include <sys/socket.h>
     46 #include <sys/ioctl.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_ether.h>
     50 #include <net/if_bridgevar.h>
     51 
     52 #include <ctype.h>
     53 #include <err.h>
     54 #include <errno.h>
     55 #include <stdio.h>
     56 #include <stdlib.h>
     57 #include <string.h>
     58 #include <unistd.h>
     59 #include <ifaddrs.h>
     60 
     61 struct command {
     62 	const char *cmd_keyword;
     63 	int	cmd_argcnt;
     64 	int	cmd_flags;
     65 	void	(*cmd_func)(const struct command *, int, const char *,
     66 		    char **);
     67 };
     68 
     69 #define	CMD_INVERT	0x01	/* "invert" the sense of the command */
     70 
     71 void	cmd_add(const struct command *, int, const char *, char **);
     72 void	cmd_delete(const struct command *, int, const char *, char **);
     73 void	cmd_up(const struct command *, int, const char *, char **);
     74 void	cmd_down(const struct command *, int, const char *, char **);
     75 void	cmd_discover(const struct command *, int, const char *, char **);
     76 void	cmd_learn(const struct command *, int, const char *, char **);
     77 void	cmd_flush(const struct command *, int, const char *, char **);
     78 void	cmd_flushall(const struct command *, int, const char *, char **);
     79 void	cmd_static(const struct command *, int, const char *, char **);
     80 void	cmd_deladdr(const struct command *, int, const char *, char **);
     81 void	cmd_addr(const struct command *, int, const char *, char **);
     82 void	cmd_maxaddr(const struct command *, int, const char *, char **);
     83 void	cmd_hellotime(const struct command *, int, const char *, char **);
     84 void	cmd_fwddelay(const struct command *, int, const char *, char **);
     85 void	cmd_maxage(const struct command *, int, const char *, char **);
     86 void	cmd_priority(const struct command *, int, const char *, char **);
     87 void	cmd_ifpriority(const struct command *, int, const char *, char **);
     88 void	cmd_ifpathcost(const struct command *, int, const char *, char **);
     89 void	cmd_timeout(const struct command *, int, const char *, char **);
     90 void	cmd_stp(const struct command *, int, const char *, char **);
     91 
     92 const struct command command_table[] = {
     93 	{ "add",		1,	0,		cmd_add },
     94 	{ "delete",		1,	0,		cmd_delete },
     95 
     96 	{ "up",			0,	0,		cmd_up },
     97 	{ "down",		0,	0,		cmd_down },
     98 
     99 	{ "discover",		1,	0,		cmd_discover },
    100 	{ "-discover",		1,	CMD_INVERT,	cmd_discover },
    101 
    102 	{ "learn",		1,	0,		cmd_learn },
    103 	{ "-learn",		1,	CMD_INVERT,	cmd_learn },
    104 
    105 	{ "flush",		0,	0,		cmd_flush },
    106 	{ "flushall",		0,	0,		cmd_flushall },
    107 
    108 	{ "static",		2,	0,		cmd_static },
    109 	{ "deladdr",		1,	0,		cmd_deladdr },
    110 
    111 	{ "addr",		0,	0,		cmd_addr },
    112 	{ "maxaddr",		1,	0,		cmd_maxaddr },
    113 
    114 	{ "hellotime",		1,	0,		cmd_hellotime },
    115 	{ "fwddelay",		1,	0,		cmd_fwddelay },
    116 	{ "maxage",		1,	0,		cmd_maxage },
    117 	{ "priority",		1,	0,		cmd_priority },
    118 	{ "ifpriority",		2,	0,		cmd_ifpriority },
    119 	{ "ifpathcost",		2,	0,		cmd_ifpathcost },
    120 	{ "timeout",		1,	0,		cmd_timeout },
    121 	{ "stp",		1,	0,		cmd_stp },
    122 	{ "-stp",		1,	CMD_INVERT,	cmd_stp },
    123 
    124 	{ NULL,			0,	0,		NULL },
    125 };
    126 
    127 void	printall(int);
    128 void	status(int, const char *);
    129 int	is_bridge(const char *);
    130 void	show_config(int, const char *, const char *);
    131 void	show_interfaces(int, const char *, const char *);
    132 void	show_addresses(int, const char *, const char *);
    133 int	get_val(const char *, u_long *);
    134 int	do_cmd(int, const char *, u_long, void *, size_t, int);
    135 void	do_ifflag(int, const char *, int, int);
    136 void	do_bridgeflag(int, const char *, const char *, int, int);
    137 
    138 void	printb(const char *, u_int, const char *);
    139 
    140 int	main(int, char *[]);
    141 void	usage(void);
    142 
    143 int	aflag;
    144 
    145 struct ifreq g_ifr;
    146 int	g_ifr_updated;
    147 
    148 #define	IFFBITS \
    149 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
    150 \11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST"
    151 
    152 int
    153 main(int argc, char *argv[])
    154 {
    155 	const struct command *cmd;
    156 	char *bridge;
    157 	int sock, ch;
    158 
    159 	if (argc < 2)
    160 		usage();
    161 
    162 	sock = socket(AF_INET, SOCK_DGRAM, 0);
    163 	if (sock < 0)
    164 		err(1, "socket");
    165 
    166 	while ((ch = getopt(argc, argv, "a")) != -1) {
    167 		switch (ch) {
    168 		case 'a':
    169 			aflag = 1;
    170 			break;
    171 
    172 		default:
    173 			usage();
    174 		}
    175 	}
    176 
    177 	argc -= optind;
    178 	argv += optind;
    179 
    180 	if (aflag) {
    181 		if (argc != 0)
    182 			usage();
    183 		printall(sock);
    184 		exit(0);
    185 	}
    186 
    187 	if (argc == 0)
    188 		usage();
    189 
    190 	bridge = argv[0];
    191 
    192 	if (is_bridge(bridge) == 0)
    193 		errx(1, "%s is not a bridge", bridge);
    194 
    195 	/* Get a copy of the interface flags. */
    196 	strlcpy(g_ifr.ifr_name, bridge, sizeof(g_ifr.ifr_name));
    197 	if (ioctl(sock, SIOCGIFFLAGS, &g_ifr) < 0)
    198 		err(1, "unable to get interface flags");
    199 
    200 	argc--;
    201 	argv++;
    202 
    203 	if (argc == 0) {
    204 		status(sock, bridge);
    205 		exit(0);
    206 	}
    207 
    208 	while (argc != 0) {
    209 		for (cmd = command_table; cmd->cmd_keyword != NULL; cmd++) {
    210 			if (strcmp(cmd->cmd_keyword, argv[0]) == 0)
    211 				break;
    212 		}
    213 		if (cmd->cmd_keyword == NULL)
    214 			errx(1, "unknown command: %s", argv[0]);
    215 
    216 		argc--;
    217 		argv++;
    218 
    219 		if (argc < cmd->cmd_argcnt)
    220 			errx(1, "command %s requires %d argument%s",
    221 			    cmd->cmd_keyword, cmd->cmd_argcnt,
    222 			    cmd->cmd_argcnt == 1 ? "" : "s");
    223 
    224 		(*cmd->cmd_func)(cmd, sock, bridge, argv);
    225 
    226 		argc -= cmd->cmd_argcnt;
    227 		argv += cmd->cmd_argcnt;
    228 	}
    229 
    230 	/* If the flags changed, update them. */
    231 	if (g_ifr_updated && ioctl(sock, SIOCSIFFLAGS, &g_ifr) < 0)
    232 		err(1, "unable to set interface flags");
    233 
    234 	exit (0);
    235 }
    236 
    237 void
    238 usage(void)
    239 {
    240 	static const char *usage_strings[] = {
    241 		"-a",
    242 		"<bridge>",
    243 		"<bridge> up|down",
    244 		"<bridge> addr",
    245 		"<bridge> add <interface>",
    246 		"<bridge> delete <interface>",
    247 		"<bridge> maxaddr <size>",
    248 		"<bridge> timeout <time>",
    249 		"<bridge> static <interface> <address>",
    250 		"<bridge> deladdr <address>",
    251 		"<bridge> flush",
    252 		"<bridge> flushall",
    253 		"<bridge> discover|-discover <interface>",
    254 		"<bridge> learn|-learn <interface>",
    255 		"<bridge> stp|-stp <interface>",
    256 		"<bridge> maxage <time>",
    257 		"<bridge> fwddelay <time>",
    258 		"<bridge> hellotime <time>",
    259 		"<bridge> priority <value>",
    260 		"<bridge> ifpriority <interface> <value>",
    261 		"<bridge> ifpathcost <interface> <value>",
    262 		NULL,
    263 	};
    264 	extern const char *__progname;
    265 	int i;
    266 
    267 	for (i = 0; usage_strings[i] != NULL; i++)
    268 		fprintf(stderr, "%s %s %s\n",
    269 		    i == 0 ? "usage:" : "      ",
    270 		    __progname, usage_strings[i]);
    271 
    272 	exit(1);
    273 }
    274 
    275 int
    276 is_bridge(const char *bridge)
    277 {
    278 
    279 	if (strncmp(bridge, "bridge", 6) != 0 ||
    280 	    isdigit(bridge[6]) == 0)
    281 		return (0);
    282 
    283 	return (1);
    284 }
    285 
    286 void
    287 printb(const char *s, u_int v, const char *bits)
    288 {
    289 	int i, any = 0;
    290 	char c;
    291 
    292 	if (bits && *bits == 8)
    293 		printf("%s=%o", s, v);
    294 	else
    295 		printf("%s=%x", s, v);
    296 	bits++;
    297 	if (bits) {
    298 		putchar('<');
    299 		while ((i = *bits++) != 0) {
    300 			if (v & (1 << (i-1))) {
    301 				if (any)
    302 					putchar(',');
    303 				any = 1;
    304 				for (; (c = *bits) > 32; bits++)
    305 					putchar(c);
    306 			} else
    307 				for (; *bits > 32; bits++)
    308 					;
    309 		}
    310 		putchar('>');
    311 	}
    312 }
    313 
    314 void
    315 printall(int sock)
    316 {
    317 	struct ifaddrs *ifap, *ifa;
    318 	char *p;
    319 
    320 	if (getifaddrs(&ifap) != 0)
    321 		err(1, "getifaddrs");
    322 	p = NULL;
    323 	for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
    324 		if (is_bridge(ifa->ifa_name) == 0)
    325 			continue;
    326 		if (p != NULL && strcmp(p, ifa->ifa_name) == 0)
    327 			continue;
    328 		p = ifa->ifa_name;
    329 		status(sock, ifa->ifa_name);
    330 	}
    331 
    332 	freeifaddrs(ifap);
    333 }
    334 
    335 void
    336 status(int sock, const char *bridge)
    337 {
    338 	struct ifreq ifr;
    339 	struct ifbrparam bp1, bp2;
    340 
    341 	memset(&ifr, 0, sizeof(ifr));
    342 
    343 	strlcpy(ifr.ifr_name, bridge, sizeof(ifr.ifr_name));
    344 	if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
    345 		err(1, "unable to get flags");
    346 
    347 	printf("%s: ", bridge);
    348 	printb("flags", ifr.ifr_flags, IFFBITS);
    349 	printf("\n");
    350 
    351 	printf("\tConfiguration:\n");
    352 	show_config(sock, bridge, "\t\t");
    353 
    354 	printf("\tInterfaces:\n");
    355 	show_interfaces(sock, bridge, "\t\t");
    356 
    357 	if (do_cmd(sock, bridge, BRDGGCACHE, &bp1, sizeof(bp1), 0) < 0)
    358 		err(1, "unable to get address cache size");
    359 	if (do_cmd(sock, bridge, BRDGGTO, &bp2, sizeof(bp2), 0) < 0)
    360 		err(1, "unable to get address timeout");
    361 
    362 	printf("\tAddress cache (max cache: %u, timeout: %u):\n",
    363 	    bp1.ifbrp_csize, bp2.ifbrp_ctime);
    364 	show_addresses(sock, bridge, "\t\t");
    365 }
    366 
    367 void
    368 show_config(int sock, const char *bridge, const char *prefix)
    369 {
    370 	struct ifbrparam param;
    371 	u_int16_t pri;
    372 	u_int8_t ht, fd, ma;
    373 
    374 	if (do_cmd(sock, bridge, BRDGGPRI, &param, sizeof(param), 0) < 0)
    375 		err(1, "unable to get bridge priority");
    376 	pri = param.ifbrp_prio;
    377 
    378 	if (do_cmd(sock, bridge, BRDGGHT, &param, sizeof(param), 0) < 0)
    379 		err(1, "unable to get hellotime");
    380 	ht = param.ifbrp_hellotime;
    381 
    382 	if (do_cmd(sock, bridge, BRDGGFD, &param, sizeof(param), 0) < 0)
    383 		err(1, "unable to get forward delay");
    384 	fd = param.ifbrp_fwddelay;
    385 
    386 	if (do_cmd(sock, bridge, BRDGGMA, &param, sizeof(param), 0) < 0)
    387 		err(1, "unable to get max age");
    388 	ma = param.ifbrp_maxage;
    389 
    390 	printf("%spriority %u hellotime %u fwddelay %u maxage %u\n",
    391 	    prefix, pri, ht, fd, ma);
    392 }
    393 
    394 void
    395 show_interfaces(int sock, const char *bridge, const char *prefix)
    396 {
    397 	static const char *stpstates[] = {
    398 		"disabled",
    399 		"listening",
    400 		"learning",
    401 		"forwarding",
    402 		"blocking",
    403 	};
    404 	struct ifbifconf bifc;
    405 	struct ifbreq *req;
    406 	char *inbuf = NULL;
    407 	int i, len = 8192;
    408 
    409 	for (;;) {
    410 		bifc.ifbic_len = len;
    411 		bifc.ifbic_buf = inbuf = realloc(inbuf, len);
    412 		if (inbuf == NULL)
    413 			err(1, "unabel to allocate interface buffer");
    414 		if (do_cmd(sock, bridge, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0)
    415 			err(1, "unable to get interface list");
    416 		if ((bifc.ifbic_len + sizeof(*req)) < len)
    417 			break;
    418 		len *= 2;
    419 	}
    420 
    421 	for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
    422 		req = bifc.ifbic_req + i;
    423 		printf("%s%s ", prefix, req->ifbr_ifsname);
    424 		printb("flags", req->ifbr_ifsflags, IFBIFBITS);
    425 		printf("\n");
    426 		printf("%s\t", prefix);
    427 		printf("port %u priority %u",
    428 		    req->ifbr_portno, req->ifbr_priority);
    429 		if (req->ifbr_ifsflags & IFBIF_STP) {
    430 			printf(" path cost %u", req->ifbr_path_cost);
    431 			if (req->ifbr_state <
    432 			    sizeof(stpstates) / sizeof(stpstates[0]))
    433 				printf(" %s", stpstates[req->ifbr_state]);
    434 			else
    435 				printf(" <unknown state %d>",
    436 				    req->ifbr_state);
    437 		}
    438 		printf("\n");
    439 	}
    440 
    441 	free(inbuf);
    442 }
    443 
    444 void
    445 show_addresses(int sock, const char *bridge, const char *prefix)
    446 {
    447 	struct ifbaconf ifbac;
    448 	struct ifbareq *ifba;
    449 	char *inbuf = NULL;
    450 	int i, len = 8192;
    451 	struct ether_addr ea;
    452 
    453 	for (;;) {
    454 		ifbac.ifbac_len = len;
    455 		ifbac.ifbac_buf = inbuf = realloc(inbuf, len);
    456 		if (inbuf == NULL)
    457 			err(1, "unable to allocate address buffer");
    458 		if (do_cmd(sock, bridge, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
    459 			err(1, "unable to get address cache");
    460 		if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
    461 			break;
    462 		len *= 2;
    463 	}
    464 
    465 	for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
    466 		ifba = ifbac.ifbac_req + i;
    467 		memcpy(ea.ether_addr_octet, ifba->ifba_dst,
    468 		    sizeof(ea.ether_addr_octet));
    469 		printf("%s%s %s %lu ", prefix, ether_ntoa(&ea),
    470 		    ifba->ifba_ifsname, ifba->ifba_expire);
    471 		printb("flags", ifba->ifba_flags, IFBAFBITS);
    472 		printf("\n");
    473 	}
    474 
    475 	free(inbuf);
    476 }
    477 
    478 int
    479 get_val(const char *cp, u_long *valp)
    480 {
    481 	char *endptr;
    482 	u_long val;
    483 
    484 	errno = 0;
    485 	val = strtoul(cp, &endptr, 0);
    486 	if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE)
    487 		return (-1);
    488 
    489 	*valp = val;
    490 	return (0);
    491 }
    492 
    493 int
    494 do_cmd(int sock, const char *bridge, u_long op, void *arg, size_t argsize,
    495     int set)
    496 {
    497 	struct ifdrv ifd;
    498 
    499 	memset(&ifd, 0, sizeof(ifd));
    500 
    501 	strlcpy(ifd.ifd_name, bridge, sizeof(ifd.ifd_name));
    502 	ifd.ifd_cmd = op;
    503 	ifd.ifd_len = argsize;
    504 	ifd.ifd_data = arg;
    505 
    506 	return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
    507 }
    508 
    509 void
    510 do_ifflag(int sock, const char *bridge, int flag, int set)
    511 {
    512 
    513 	if (set)
    514 		g_ifr.ifr_flags |= flag;
    515 	else
    516 		g_ifr.ifr_flags &= ~flag;
    517 
    518 	g_ifr_updated = 1;
    519 }
    520 
    521 void
    522 do_bridgeflag(int sock, const char *bridge, const char *ifs, int flag,
    523     int set)
    524 {
    525 	struct ifbreq req;
    526 
    527 	strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname));
    528 
    529 	if (do_cmd(sock, bridge, BRDGGIFFLGS, &req, sizeof(req), 0) < 0)
    530 		err(1, "unable to get bridge flags");
    531 
    532 	if (set)
    533 		req.ifbr_ifsflags |= flag;
    534 	else
    535 		req.ifbr_ifsflags &= ~flag;
    536 
    537 	if (do_cmd(sock, bridge, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
    538 		err(1, "unable to set bridge flags");
    539 }
    540 
    541 void
    542 cmd_add(const struct command *cmd, int sock, const char *bridge,
    543     char **argv)
    544 {
    545 	struct ifbreq req;
    546 
    547 	memset(&req, 0, sizeof(req));
    548 
    549 	strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
    550 	if (do_cmd(sock, bridge, BRDGADD, &req, sizeof(req), 1) < 0)
    551 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    552 }
    553 
    554 void
    555 cmd_delete(const struct command *cmd, int sock, const char *bridge,
    556     char **argv)
    557 {
    558 	struct ifbreq req;
    559 
    560 	memset(&req, 0, sizeof(req));
    561 	strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
    562 	if (do_cmd(sock, bridge, BRDGDEL, &req, sizeof(req), 1) < 0)
    563 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    564 }
    565 
    566 void
    567 cmd_up(const struct command *cmd, int sock, const char *bridge,
    568     char **argv)
    569 {
    570 
    571 	do_ifflag(sock, bridge, IFF_UP, 1);
    572 }
    573 
    574 void
    575 cmd_down(const struct command *cmd, int sock, const char *bridge,
    576     char **argv)
    577 {
    578 
    579 	do_ifflag(sock, bridge, IFF_UP, 0);
    580 }
    581 
    582 void
    583 cmd_discover(const struct command *cmd, int sock, const char *bridge,
    584     char **argv)
    585 {
    586 
    587 	do_bridgeflag(sock, bridge, argv[0], IFBIF_DISCOVER,
    588 	    (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
    589 }
    590 
    591 void
    592 cmd_learn(const struct command *cmd, int sock, const char *bridge,
    593     char **argv)
    594 {
    595 
    596 	do_bridgeflag(sock, bridge, argv[0], IFBIF_LEARNING,
    597 	    (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
    598 }
    599 
    600 void
    601 cmd_stp(const struct command *cmd, int sock, const char *bridge,
    602     char **argv)
    603 {
    604 
    605 	do_bridgeflag(sock, bridge, argv[0], IFBIF_STP,
    606 	    (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
    607 }
    608 
    609 void
    610 cmd_flush(const struct command *cmd, int sock, const char *bridge,
    611     char **argv)
    612 {
    613 	struct ifbreq req;
    614 
    615 	memset(&req, 0, sizeof(req));
    616 	req.ifbr_ifsflags = IFBF_FLUSHDYN;
    617 	if (do_cmd(sock, bridge, BRDGFLUSH, &req, sizeof(req), 1) < 0)
    618 		err(1, "%s", cmd->cmd_keyword);
    619 }
    620 
    621 void
    622 cmd_flushall(const struct command *cmd, int sock, const char *bridge,
    623     char **argv)
    624 {
    625 	struct ifbreq req;
    626 
    627 	memset(&req, 0, sizeof(req));
    628 	req.ifbr_ifsflags = IFBF_FLUSHALL;
    629 	if (do_cmd(sock, bridge, BRDGFLUSH, &req, sizeof(req), 1) < 0)
    630 		err(1, "%s", cmd->cmd_keyword);
    631 }
    632 
    633 void
    634 cmd_static(const struct command *cmd, int sock, const char *bridge,
    635     char **argv)
    636 {
    637 	struct ifbareq req;
    638 	struct ether_addr *ea;
    639 
    640 	memset(&req, 0, sizeof(req));
    641 	strlcpy(req.ifba_ifsname, argv[0], sizeof(req.ifba_ifsname));
    642 
    643 	ea = ether_aton(argv[1]);
    644 	if (ea == NULL)
    645 		errx(1, "%s: invalid address: %s", cmd->cmd_keyword, argv[1]);
    646 
    647 	memcpy(req.ifba_dst, ea->ether_addr_octet, sizeof(req.ifba_dst));
    648 	req.ifba_flags = IFBAF_STATIC;
    649 
    650 	if (do_cmd(sock, bridge, BRDGSADDR, &req, sizeof(req), 1) < 0)
    651 		err(1, "%s %s %s", cmd->cmd_keyword, argv[0], argv[1]);
    652 }
    653 
    654 void
    655 cmd_deladdr(const struct command *cmd, int sock, const char *bridge,
    656     char **argv)
    657 {
    658 	struct ifbareq req;
    659 	struct ether_addr *ea;
    660 
    661 	memset(&req, 0, sizeof(req));
    662 
    663 	ea = ether_aton(argv[0]);
    664 	if (ea == NULL)
    665 		errx(1, "%s: invalid address: %s", cmd->cmd_keyword, argv[0]);
    666 
    667 	memcpy(req.ifba_dst, ea->ether_addr_octet, sizeof(req.ifba_dst));
    668 
    669 	if (do_cmd(sock, bridge, BRDGDADDR, &req, sizeof(req), 1) < 0)
    670 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    671 }
    672 
    673 void
    674 cmd_addr(const struct command *cmd, int sock, const char *bridge,
    675     char **argv)
    676 {
    677 
    678 	show_addresses(sock, bridge, "\t");
    679 }
    680 
    681 void
    682 cmd_maxaddr(const struct command *cmd, int sock, const char *bridge,
    683     char **argv)
    684 {
    685 	struct ifbrparam param;
    686 	u_long val;
    687 
    688 	if (get_val(argv[0], &val) < 0 || (val & ~0xffffffff) != 0)
    689 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    690 
    691 	param.ifbrp_csize = val & 0xffffffff;
    692 
    693 	if (do_cmd(sock, bridge, BRDGSCACHE, &param, sizeof(param), 1) < 0)
    694 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    695 }
    696 
    697 void
    698 cmd_hellotime(const struct command *cmd, int sock, const char *bridge,
    699     char **argv)
    700 {
    701 	struct ifbrparam param;
    702 	u_long val;
    703 
    704 	if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
    705 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    706 
    707 	param.ifbrp_hellotime = val & 0xff;
    708 
    709 	if (do_cmd(sock, bridge, BRDGSHT, &param, sizeof(param), 1) < 0)
    710 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    711 }
    712 
    713 void
    714 cmd_fwddelay(const struct command *cmd, int sock, const char *bridge,
    715     char **argv)
    716 {
    717 	struct ifbrparam param;
    718 	u_long val;
    719 
    720 	if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
    721 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    722 
    723 	param.ifbrp_fwddelay = val & 0xff;
    724 
    725 	if (do_cmd(sock, bridge, BRDGSFD, &param, sizeof(param), 1) < 0)
    726 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    727 }
    728 
    729 void
    730 cmd_maxage(const struct command *cmd, int sock, const char *bridge,
    731     char **argv)
    732 {
    733 	struct ifbrparam param;
    734 	u_long val;
    735 
    736 	if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
    737 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    738 
    739 	param.ifbrp_maxage = val & 0xff;
    740 
    741 	if (do_cmd(sock, bridge, BRDGSMA, &param, sizeof(param), 1) < 0)
    742 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    743 }
    744 
    745 void
    746 cmd_priority(const struct command *cmd, int sock, const char *bridge,
    747     char **argv)
    748 {
    749 	struct ifbrparam param;
    750 	u_long val;
    751 
    752 	if (get_val(argv[0], &val) < 0 || (val & ~0xffff) != 0)
    753 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    754 
    755 	param.ifbrp_prio = val & 0xffff;
    756 
    757 	if (do_cmd(sock, bridge, BRDGSPRI, &param, sizeof(param), 1) < 0)
    758 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    759 }
    760 
    761 void
    762 cmd_ifpriority(const struct command *cmd, int sock, const char *bridge,
    763     char **argv)
    764 {
    765 	struct ifbreq req;
    766 	u_long val;
    767 
    768 	memset(&req, 0, sizeof(req));
    769 
    770 	if (get_val(argv[1], &val) < 0 || (val & ~0xff) != 0)
    771 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[1]);
    772 
    773 	strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
    774 	req.ifbr_priority = val & 0xff;
    775 
    776 	if (do_cmd(sock, bridge, BRDGSIFPRIO, &req, sizeof(req), 1) < 0)
    777 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    778 }
    779 
    780 void
    781 cmd_ifpathcost(const struct command *cmd, int sock, const char *bridge,
    782     char **argv)
    783 {
    784 	struct ifbreq req;
    785 	u_long val;
    786 
    787 	memset(&req, 0, sizeof(req));
    788 
    789 	if (get_val(argv[1], &val) < 0 || (val & ~0xff) != 0)
    790 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[1]);
    791 
    792 	strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
    793 	req.ifbr_path_cost = val & 0xffff;
    794 
    795 	if (do_cmd(sock, bridge, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
    796 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    797 }
    798 
    799 void
    800 cmd_timeout(const struct command *cmd, int sock, const char *bridge,
    801     char **argv)
    802 {
    803 	struct ifbrparam param;
    804 	u_long val;
    805 
    806 	if (get_val(argv[0], &val) < 0 || (val & ~0xffffffff) != 0)
    807 		errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
    808 
    809 	param.ifbrp_ctime = val & 0xffffffff;
    810 
    811 	if (do_cmd(sock, bridge, BRDGSTO, &param, sizeof(param), 1) < 0)
    812 		err(1, "%s %s", cmd->cmd_keyword, argv[0]);
    813 }
    814