No empty .Rs/.Re
[netbsd-mini2440.git] / sbin / brconfig / brconfig.c
blob694fe0c6716aea24470d2764c83bb744c3745ca3
1 /* $NetBSD: brconfig.c,v 1.11 2006/03/20 01:06:07 christos Exp $ */
3 /*
4 * Copyright 2001 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
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.
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.
39 * brconfig(8) --
41 * Configuration utility for the bridge(4) driver.
43 #include <sys/cdefs.h>
45 #ifndef lint
46 __RCSID("$NetBSD: brconfig.c,v 1.11 2006/03/20 01:06:07 christos Exp $");
47 #endif
50 #include <sys/param.h>
51 #include <sys/socket.h>
52 #include <sys/ioctl.h>
54 #include <net/if.h>
55 #include <net/if_ether.h>
56 #include <net/if_bridgevar.h>
58 #include <ctype.h>
59 #include <err.h>
60 #include <errno.h>
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64 #include <unistd.h>
65 #include <ifaddrs.h>
67 struct command {
68 const char *cmd_keyword;
69 int cmd_argcnt;
70 int cmd_flags;
71 void (*cmd_func)(const struct command *, int, const char *,
72 char **);
75 #define CMD_INVERT 0x01 /* "invert" the sense of the command */
77 void cmd_add(const struct command *, int, const char *, char **);
78 void cmd_delete(const struct command *, int, const char *, char **);
79 void cmd_up(const struct command *, int, const char *, char **);
80 void cmd_down(const struct command *, int, const char *, char **);
81 void cmd_discover(const struct command *, int, const char *, char **);
82 void cmd_learn(const struct command *, int, const char *, char **);
83 void cmd_flush(const struct command *, int, const char *, char **);
84 void cmd_flushall(const struct command *, int, const char *, char **);
85 void cmd_static(const struct command *, int, const char *, char **);
86 void cmd_deladdr(const struct command *, int, const char *, char **);
87 void cmd_addr(const struct command *, int, const char *, char **);
88 void cmd_maxaddr(const struct command *, int, const char *, char **);
89 void cmd_hellotime(const struct command *, int, const char *, char **);
90 void cmd_fwddelay(const struct command *, int, const char *, char **);
91 void cmd_maxage(const struct command *, int, const char *, char **);
92 void cmd_priority(const struct command *, int, const char *, char **);
93 void cmd_ifpriority(const struct command *, int, const char *, char **);
94 void cmd_ifpathcost(const struct command *, int, const char *, char **);
95 void cmd_timeout(const struct command *, int, const char *, char **);
96 void cmd_stp(const struct command *, int, const char *, char **);
97 void cmd_ipf(const struct command *, int, const char *, char **);
99 const struct command command_table[] = {
100 { "add", 1, 0, cmd_add },
101 { "delete", 1, 0, cmd_delete },
103 { "up", 0, 0, cmd_up },
104 { "down", 0, 0, cmd_down },
106 { "discover", 1, 0, cmd_discover },
107 { "-discover", 1, CMD_INVERT, cmd_discover },
109 { "learn", 1, 0, cmd_learn },
110 { "-learn", 1, CMD_INVERT, cmd_learn },
112 { "flush", 0, 0, cmd_flush },
113 { "flushall", 0, 0, cmd_flushall },
115 { "static", 2, 0, cmd_static },
116 { "deladdr", 1, 0, cmd_deladdr },
118 { "addr", 0, 0, cmd_addr },
119 { "maxaddr", 1, 0, cmd_maxaddr },
121 { "hellotime", 1, 0, cmd_hellotime },
122 { "fwddelay", 1, 0, cmd_fwddelay },
123 { "maxage", 1, 0, cmd_maxage },
124 { "priority", 1, 0, cmd_priority },
125 { "ifpriority", 2, 0, cmd_ifpriority },
126 { "ifpathcost", 2, 0, cmd_ifpathcost },
127 { "timeout", 1, 0, cmd_timeout },
128 { "stp", 1, 0, cmd_stp },
129 { "-stp", 1, CMD_INVERT, cmd_stp },
131 { "ipf", 0, 0, cmd_ipf },
132 { "-ipf", 0, CMD_INVERT, cmd_ipf },
134 { NULL, 0, 0, NULL },
137 void printall(int);
138 void status(int, const char *);
139 int is_bridge(const char *);
140 void show_config(int, const char *, const char *);
141 void show_interfaces(int, const char *, const char *);
142 void show_addresses(int, const char *, const char *);
143 int get_val(const char *, u_long *);
144 int do_cmd(int, const char *, u_long, void *, size_t, int);
145 void do_ifflag(int, const char *, int, int);
146 void do_bridgeflag(int, const char *, const char *, int, int);
148 void printb(const char *, u_int, const char *);
150 void usage(void);
152 int aflag;
154 struct ifreq g_ifr;
155 int g_ifr_updated;
158 main(int argc, char *argv[])
160 const struct command *cmd;
161 char *bridge;
162 int sock, ch;
164 if (argc < 2)
165 usage();
167 sock = socket(AF_INET, SOCK_DGRAM, 0);
168 if (sock < 0)
169 err(1, "socket");
171 while ((ch = getopt(argc, argv, "a")) != -1) {
172 switch (ch) {
173 case 'a':
174 aflag = 1;
175 break;
177 default:
178 usage();
182 argc -= optind;
183 argv += optind;
185 if (aflag) {
186 if (argc != 0)
187 usage();
188 printall(sock);
189 exit(0);
192 if (argc == 0)
193 usage();
195 bridge = argv[0];
197 if (is_bridge(bridge) == 0)
198 errx(1, "%s is not a bridge", bridge);
200 /* Get a copy of the interface flags. */
201 strlcpy(g_ifr.ifr_name, bridge, sizeof(g_ifr.ifr_name));
202 if (ioctl(sock, SIOCGIFFLAGS, &g_ifr) < 0)
203 err(1, "unable to get interface flags");
205 argc--;
206 argv++;
208 if (argc == 0) {
209 status(sock, bridge);
210 exit(0);
213 while (argc != 0) {
214 for (cmd = command_table; cmd->cmd_keyword != NULL; cmd++) {
215 if (strcmp(cmd->cmd_keyword, argv[0]) == 0)
216 break;
218 if (cmd->cmd_keyword == NULL)
219 errx(1, "unknown command: %s", argv[0]);
221 argc--;
222 argv++;
224 if (argc < cmd->cmd_argcnt)
225 errx(1, "command %s requires %d argument%s",
226 cmd->cmd_keyword, cmd->cmd_argcnt,
227 cmd->cmd_argcnt == 1 ? "" : "s");
229 (*cmd->cmd_func)(cmd, sock, bridge, argv);
231 argc -= cmd->cmd_argcnt;
232 argv += cmd->cmd_argcnt;
235 /* If the flags changed, update them. */
236 if (g_ifr_updated && ioctl(sock, SIOCSIFFLAGS, &g_ifr) < 0)
237 err(1, "unable to set interface flags");
239 exit (0);
242 void
243 usage(void)
245 static const char *usage_strings[] = {
246 "-a",
247 "<bridge>",
248 "<bridge> up|down",
249 "<bridge> addr",
250 "<bridge> add <interface>",
251 "<bridge> delete <interface>",
252 "<bridge> maxaddr <size>",
253 "<bridge> timeout <time>",
254 "<bridge> static <interface> <address>",
255 "<bridge> deladdr <address>",
256 "<bridge> flush",
257 "<bridge> flushall",
258 "<bridge> ipf|-ipf",
259 "<bridge> discover|-discover <interface>",
260 "<bridge> learn|-learn <interface>",
261 "<bridge> stp|-stp <interface>",
262 "<bridge> maxage <time>",
263 "<bridge> fwddelay <time>",
264 "<bridge> hellotime <time>",
265 "<bridge> priority <value>",
266 "<bridge> ifpriority <interface> <value>",
267 "<bridge> ifpathcost <interface> <value>",
268 NULL,
270 extern const char *__progname;
271 int i;
273 for (i = 0; usage_strings[i] != NULL; i++)
274 fprintf(stderr, "%s %s %s\n",
275 i == 0 ? "usage:" : " ",
276 __progname, usage_strings[i]);
278 exit(1);
282 is_bridge(const char *bridge)
285 if (strncmp(bridge, "bridge", 6) != 0 ||
286 isdigit((unsigned char)bridge[6]) == 0)
287 return (0);
289 return (1);
292 void
293 printb(const char *s, u_int v, const char *bits)
295 int i, any = 0;
296 char c;
298 if (bits && *bits == 8)
299 printf("%s=%o", s, v);
300 else
301 printf("%s=%x", s, v);
302 if (bits) {
303 bits++;
304 putchar('<');
305 while ((i = *bits++) != 0) {
306 if (v & (1 << (i-1))) {
307 if (any)
308 putchar(',');
309 any = 1;
310 for (; (c = *bits) > 32; bits++)
311 putchar(c);
312 } else
313 for (; *bits > 32; bits++)
316 putchar('>');
320 void
321 printall(int sock)
323 struct ifaddrs *ifap, *ifa;
324 char *p;
326 if (getifaddrs(&ifap) != 0)
327 err(1, "getifaddrs");
328 p = NULL;
329 for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
330 if (is_bridge(ifa->ifa_name) == 0)
331 continue;
332 if (p != NULL && strcmp(p, ifa->ifa_name) == 0)
333 continue;
334 p = ifa->ifa_name;
335 status(sock, ifa->ifa_name);
338 freeifaddrs(ifap);
341 void
342 status(int sock, const char *bridge)
344 struct ifreq ifr;
345 struct ifbrparam bp1, bp2;
347 memset(&ifr, 0, sizeof(ifr));
349 strlcpy(ifr.ifr_name, bridge, sizeof(ifr.ifr_name));
350 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
351 err(1, "unable to get flags");
353 printf("%s: ", bridge);
354 printb("flags", ifr.ifr_flags, IFFBITS);
355 printf("\n");
357 printf("\tConfiguration:\n");
358 show_config(sock, bridge, "\t\t");
360 printf("\tInterfaces:\n");
361 show_interfaces(sock, bridge, "\t\t");
363 if (do_cmd(sock, bridge, BRDGGCACHE, &bp1, sizeof(bp1), 0) < 0)
364 err(1, "unable to get address cache size");
365 if (do_cmd(sock, bridge, BRDGGTO, &bp2, sizeof(bp2), 0) < 0)
366 err(1, "unable to get address timeout");
368 printf("\tAddress cache (max cache: %u, timeout: %u):\n",
369 bp1.ifbrp_csize, bp2.ifbrp_ctime);
370 show_addresses(sock, bridge, "\t\t");
373 void
374 show_config(int sock, const char *bridge, const char *prefix)
376 struct ifbrparam param;
377 u_int32_t ipfflags;
378 u_int16_t pri;
379 u_int8_t ht, fd, ma;
381 if (do_cmd(sock, bridge, BRDGGPRI, &param, sizeof(param), 0) < 0)
382 err(1, "unable to get bridge priority");
383 pri = param.ifbrp_prio;
385 if (do_cmd(sock, bridge, BRDGGHT, &param, sizeof(param), 0) < 0)
386 err(1, "unable to get hellotime");
387 ht = param.ifbrp_hellotime;
389 if (do_cmd(sock, bridge, BRDGGFD, &param, sizeof(param), 0) < 0)
390 err(1, "unable to get forward delay");
391 fd = param.ifbrp_fwddelay;
393 if (do_cmd(sock, bridge, BRDGGMA, &param, sizeof(param), 0) < 0)
394 err(1, "unable to get max age");
395 ma = param.ifbrp_maxage;
397 printf("%spriority %u hellotime %u fwddelay %u maxage %u\n",
398 prefix, pri, ht, fd, ma);
400 if (do_cmd(sock, bridge, BRDGGFILT, &param, sizeof(param), 0) < 0) {
401 /* err(1, "unable to get ipfilter status"); */
402 param.ifbrp_filter = 0;
405 ipfflags = param.ifbrp_filter;
406 printf("%sipfilter %s flags 0x%x\n", prefix,
407 (ipfflags & IFBF_FILT_USEIPF) ? "enabled" : "disabled",
408 ipfflags);
411 void
412 show_interfaces(int sock, const char *bridge, const char *prefix)
414 static const char *stpstates[] = {
415 "disabled",
416 "listening",
417 "learning",
418 "forwarding",
419 "blocking",
421 struct ifbifconf bifc;
422 struct ifbreq *req;
423 char *inbuf = NULL, *ninbuf;
424 uint32_t i, len = 8192;
426 for (;;) {
427 ninbuf = realloc(inbuf, len);
428 if (ninbuf == NULL)
429 err(1, "unable to allocate interface buffer");
430 bifc.ifbic_len = len;
431 bifc.ifbic_buf = inbuf = ninbuf;
432 if (do_cmd(sock, bridge, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0)
433 err(1, "unable to get interface list");
434 if ((bifc.ifbic_len + sizeof(*req)) < len)
435 break;
436 len *= 2;
439 for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
440 req = bifc.ifbic_req + i;
441 printf("%s%s ", prefix, req->ifbr_ifsname);
442 printb("flags", req->ifbr_ifsflags, IFBIFBITS);
443 printf("\n");
444 printf("%s\t", prefix);
445 printf("port %u priority %u",
446 req->ifbr_portno, req->ifbr_priority);
447 if (req->ifbr_ifsflags & IFBIF_STP) {
448 printf(" path cost %u", req->ifbr_path_cost);
449 if (req->ifbr_state <
450 sizeof(stpstates) / sizeof(stpstates[0]))
451 printf(" %s", stpstates[req->ifbr_state]);
452 else
453 printf(" <unknown state %d>",
454 req->ifbr_state);
456 printf("\n");
459 free(inbuf);
462 void
463 show_addresses(int sock, const char *bridge, const char *prefix)
465 struct ifbaconf ifbac;
466 struct ifbareq *ifba;
467 char *inbuf = NULL, *ninbuf;
468 uint32_t i, len = 8192;
469 struct ether_addr ea;
471 for (;;) {
472 ninbuf = realloc(inbuf, len);
473 if (ninbuf == NULL)
474 err(1, "unable to allocate address buffer");
475 ifbac.ifbac_len = len;
476 ifbac.ifbac_buf = inbuf = ninbuf;
477 if (do_cmd(sock, bridge, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
478 err(1, "unable to get address cache");
479 if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
480 break;
481 len *= 2;
484 for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
485 ifba = ifbac.ifbac_req + i;
486 memcpy(ea.ether_addr_octet, ifba->ifba_dst,
487 sizeof(ea.ether_addr_octet));
488 printf("%s%s %s %lu ", prefix, ether_ntoa(&ea),
489 ifba->ifba_ifsname, ifba->ifba_expire);
490 printb("flags", ifba->ifba_flags, IFBAFBITS);
491 printf("\n");
494 free(inbuf);
498 get_val(const char *cp, u_long *valp)
500 char *endptr;
501 u_long val;
503 errno = 0;
504 val = strtoul(cp, &endptr, 0);
505 if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE)
506 return (-1);
508 *valp = val;
509 return (0);
513 do_cmd(int sock, const char *bridge, u_long op, void *arg, size_t argsize,
514 int set)
516 struct ifdrv ifd;
518 memset(&ifd, 0, sizeof(ifd));
520 strlcpy(ifd.ifd_name, bridge, sizeof(ifd.ifd_name));
521 ifd.ifd_cmd = op;
522 ifd.ifd_len = argsize;
523 ifd.ifd_data = arg;
525 return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
528 void
529 do_ifflag(int sock, const char *bridge, int flag, int set)
532 if (set)
533 g_ifr.ifr_flags |= flag;
534 else
535 g_ifr.ifr_flags &= ~flag;
537 g_ifr_updated = 1;
540 void
541 do_bridgeflag(int sock, const char *bridge, const char *ifs, int flag,
542 int set)
544 struct ifbreq req;
546 strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname));
548 if (do_cmd(sock, bridge, BRDGGIFFLGS, &req, sizeof(req), 0) < 0)
549 err(1, "unable to get bridge flags");
551 if (set)
552 req.ifbr_ifsflags |= flag;
553 else
554 req.ifbr_ifsflags &= ~flag;
556 if (do_cmd(sock, bridge, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
557 err(1, "unable to set bridge flags");
560 void
561 cmd_add(const struct command *cmd, int sock, const char *bridge,
562 char **argv)
564 struct ifbreq req;
566 memset(&req, 0, sizeof(req));
568 strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
569 if (do_cmd(sock, bridge, BRDGADD, &req, sizeof(req), 1) < 0)
570 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
573 void
574 cmd_delete(const struct command *cmd, int sock, const char *bridge,
575 char **argv)
577 struct ifbreq req;
579 memset(&req, 0, sizeof(req));
580 strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
581 if (do_cmd(sock, bridge, BRDGDEL, &req, sizeof(req), 1) < 0)
582 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
585 void
586 cmd_up(const struct command *cmd, int sock, const char *bridge,
587 char **argv)
590 do_ifflag(sock, bridge, IFF_UP, 1);
593 void
594 cmd_down(const struct command *cmd, int sock, const char *bridge,
595 char **argv)
598 do_ifflag(sock, bridge, IFF_UP, 0);
601 void
602 cmd_discover(const struct command *cmd, int sock, const char *bridge,
603 char **argv)
606 do_bridgeflag(sock, bridge, argv[0], IFBIF_DISCOVER,
607 (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
610 void
611 cmd_learn(const struct command *cmd, int sock, const char *bridge,
612 char **argv)
615 do_bridgeflag(sock, bridge, argv[0], IFBIF_LEARNING,
616 (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
619 void
620 cmd_stp(const struct command *cmd, int sock, const char *bridge,
621 char **argv)
624 do_bridgeflag(sock, bridge, argv[0], IFBIF_STP,
625 (cmd->cmd_flags & CMD_INVERT) ? 0 : 1);
628 void
629 cmd_flush(const struct command *cmd, int sock, const char *bridge,
630 char **argv)
632 struct ifbreq req;
634 memset(&req, 0, sizeof(req));
635 req.ifbr_ifsflags = IFBF_FLUSHDYN;
636 if (do_cmd(sock, bridge, BRDGFLUSH, &req, sizeof(req), 1) < 0)
637 err(1, "%s", cmd->cmd_keyword);
640 void
641 cmd_flushall(const struct command *cmd, int sock, const char *bridge,
642 char **argv)
644 struct ifbreq req;
646 memset(&req, 0, sizeof(req));
647 req.ifbr_ifsflags = IFBF_FLUSHALL;
648 if (do_cmd(sock, bridge, BRDGFLUSH, &req, sizeof(req), 1) < 0)
649 err(1, "%s", cmd->cmd_keyword);
652 void
653 cmd_static(const struct command *cmd, int sock, const char *bridge,
654 char **argv)
656 struct ifbareq req;
657 struct ether_addr *ea;
659 memset(&req, 0, sizeof(req));
660 strlcpy(req.ifba_ifsname, argv[0], sizeof(req.ifba_ifsname));
662 ea = ether_aton(argv[1]);
663 if (ea == NULL)
664 errx(1, "%s: invalid address: %s", cmd->cmd_keyword, argv[1]);
666 memcpy(req.ifba_dst, ea->ether_addr_octet, sizeof(req.ifba_dst));
667 req.ifba_flags = IFBAF_STATIC;
669 if (do_cmd(sock, bridge, BRDGSADDR, &req, sizeof(req), 1) < 0)
670 err(1, "%s %s %s", cmd->cmd_keyword, argv[0], argv[1]);
673 void
674 cmd_deladdr(const struct command *cmd, int sock, const char *bridge,
675 char **argv)
677 struct ifbareq req;
678 struct ether_addr *ea;
680 memset(&req, 0, sizeof(req));
682 ea = ether_aton(argv[0]);
683 if (ea == NULL)
684 errx(1, "%s: invalid address: %s", cmd->cmd_keyword, argv[0]);
686 memcpy(req.ifba_dst, ea->ether_addr_octet, sizeof(req.ifba_dst));
688 if (do_cmd(sock, bridge, BRDGDADDR, &req, sizeof(req), 1) < 0)
689 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
692 void
693 cmd_addr(const struct command *cmd, int sock, const char *bridge,
694 char **argv)
697 show_addresses(sock, bridge, "\t");
700 void
701 cmd_maxaddr(const struct command *cmd, int sock, const char *bridge,
702 char **argv)
704 struct ifbrparam param;
705 u_long val;
707 if (get_val(argv[0], &val) < 0 || (val & ~0xffffffff) != 0)
708 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
710 param.ifbrp_csize = val & 0xffffffff;
712 if (do_cmd(sock, bridge, BRDGSCACHE, &param, sizeof(param), 1) < 0)
713 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
716 void
717 cmd_hellotime(const struct command *cmd, int sock, const char *bridge,
718 char **argv)
720 struct ifbrparam param;
721 u_long val;
723 if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
724 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
726 param.ifbrp_hellotime = val & 0xff;
728 if (do_cmd(sock, bridge, BRDGSHT, &param, sizeof(param), 1) < 0)
729 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
732 void
733 cmd_fwddelay(const struct command *cmd, int sock, const char *bridge,
734 char **argv)
736 struct ifbrparam param;
737 u_long val;
739 if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
740 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
742 param.ifbrp_fwddelay = val & 0xff;
744 if (do_cmd(sock, bridge, BRDGSFD, &param, sizeof(param), 1) < 0)
745 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
748 void
749 cmd_maxage(const struct command *cmd, int sock, const char *bridge,
750 char **argv)
752 struct ifbrparam param;
753 u_long val;
755 if (get_val(argv[0], &val) < 0 || (val & ~0xff) != 0)
756 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
758 param.ifbrp_maxage = val & 0xff;
760 if (do_cmd(sock, bridge, BRDGSMA, &param, sizeof(param), 1) < 0)
761 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
764 void
765 cmd_priority(const struct command *cmd, int sock, const char *bridge,
766 char **argv)
768 struct ifbrparam param;
769 u_long val;
771 if (get_val(argv[0], &val) < 0 || (val & ~0xffff) != 0)
772 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
774 param.ifbrp_prio = val & 0xffff;
776 if (do_cmd(sock, bridge, BRDGSPRI, &param, sizeof(param), 1) < 0)
777 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
780 void
781 cmd_ifpriority(const struct command *cmd, int sock, const char *bridge,
782 char **argv)
784 struct ifbreq req;
785 u_long val;
787 memset(&req, 0, sizeof(req));
789 if (get_val(argv[1], &val) < 0 || (val & ~0xff) != 0)
790 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[1]);
792 strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
793 req.ifbr_priority = val & 0xff;
795 if (do_cmd(sock, bridge, BRDGSIFPRIO, &req, sizeof(req), 1) < 0)
796 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
799 void
800 cmd_ifpathcost(const struct command *cmd, int sock, const char *bridge,
801 char **argv)
803 struct ifbreq req;
804 u_long val;
806 memset(&req, 0, sizeof(req));
808 if (get_val(argv[1], &val) < 0 || (val & ~0xff) != 0)
809 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[1]);
811 strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
812 req.ifbr_path_cost = val & 0xffff;
814 if (do_cmd(sock, bridge, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
815 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
818 void
819 cmd_timeout(const struct command *cmd, int sock, const char *bridge,
820 char **argv)
822 struct ifbrparam param;
823 u_long val;
825 if (get_val(argv[0], &val) < 0 || (val & ~0xffffffff) != 0)
826 errx(1, "%s: invalid value: %s", cmd->cmd_keyword, argv[0]);
828 param.ifbrp_ctime = val & 0xffffffff;
830 if (do_cmd(sock, bridge, BRDGSTO, &param, sizeof(param), 1) < 0)
831 err(1, "%s %s", cmd->cmd_keyword, argv[0]);
834 void
835 cmd_ipf(const struct command *cmd, int sock, const char *bridge,
836 char **argv)
838 struct ifbrparam param;
840 if (do_cmd(sock, bridge, BRDGGFILT, &param, sizeof(param), 0) < 0)
841 err(1, "%s", cmd->cmd_keyword);
843 param.ifbrp_filter &= ~IFBF_FILT_USEIPF;
844 param.ifbrp_filter |= (cmd->cmd_flags & CMD_INVERT) ? 0 : IFBF_FILT_USEIPF;
845 if (do_cmd(sock, bridge, BRDGSFILT, &param, sizeof(param), 1) < 0)
846 err(1, "%s %x", cmd->cmd_keyword, param.ifbrp_filter);