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