1 /* $NetBSD: brconfig.c,v 1.11 2006/03/20 01:06:07 christos Exp $ */
4 * Copyright 2001 Wasabi Systems, Inc.
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
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
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.
41 * Configuration utility for the bridge(4) driver.
43 #include <sys/cdefs.h>
46 __RCSID("$NetBSD: brconfig.c,v 1.11 2006/03/20 01:06:07 christos Exp $");
50 #include <sys/param.h>
51 #include <sys/socket.h>
52 #include <sys/ioctl.h>
55 #include <net/if_ether.h>
56 #include <net/if_bridgevar.h>
68 const char *cmd_keyword
;
71 void (*cmd_func
)(const struct command
*, int, const 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
},
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 *);
158 main(int argc
, char *argv
[])
160 const struct command
*cmd
;
167 sock
= socket(AF_INET
, SOCK_DGRAM
, 0);
171 while ((ch
= getopt(argc
, argv
, "a")) != -1) {
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");
209 status(sock
, bridge
);
214 for (cmd
= command_table
; cmd
->cmd_keyword
!= NULL
; cmd
++) {
215 if (strcmp(cmd
->cmd_keyword
, argv
[0]) == 0)
218 if (cmd
->cmd_keyword
== NULL
)
219 errx(1, "unknown command: %s", argv
[0]);
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");
245 static const char *usage_strings
[] = {
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>",
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>",
270 extern const char *__progname
;
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
]);
282 is_bridge(const char *bridge
)
285 if (strncmp(bridge
, "bridge", 6) != 0 ||
286 isdigit((unsigned char)bridge
[6]) == 0)
293 printb(const char *s
, u_int v
, const char *bits
)
298 if (bits
&& *bits
== 8)
299 printf("%s=%o", s
, v
);
301 printf("%s=%x", s
, v
);
305 while ((i
= *bits
++) != 0) {
306 if (v
& (1 << (i
-1))) {
310 for (; (c
= *bits
) > 32; bits
++)
313 for (; *bits
> 32; bits
++)
323 struct ifaddrs
*ifap
, *ifa
;
326 if (getifaddrs(&ifap
) != 0)
327 err(1, "getifaddrs");
329 for (ifa
= ifap
; ifa
!= NULL
; ifa
= ifa
->ifa_next
) {
330 if (is_bridge(ifa
->ifa_name
) == 0)
332 if (p
!= NULL
&& strcmp(p
, ifa
->ifa_name
) == 0)
335 status(sock
, ifa
->ifa_name
);
342 status(int sock
, const char *bridge
)
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
);
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");
374 show_config(int sock
, const char *bridge
, const char *prefix
)
376 struct ifbrparam param
;
381 if (do_cmd(sock
, bridge
, BRDGGPRI
, ¶m
, sizeof(param
), 0) < 0)
382 err(1, "unable to get bridge priority");
383 pri
= param
.ifbrp_prio
;
385 if (do_cmd(sock
, bridge
, BRDGGHT
, ¶m
, sizeof(param
), 0) < 0)
386 err(1, "unable to get hellotime");
387 ht
= param
.ifbrp_hellotime
;
389 if (do_cmd(sock
, bridge
, BRDGGFD
, ¶m
, sizeof(param
), 0) < 0)
390 err(1, "unable to get forward delay");
391 fd
= param
.ifbrp_fwddelay
;
393 if (do_cmd(sock
, bridge
, BRDGGMA
, ¶m
, 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
, ¶m
, 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",
412 show_interfaces(int sock
, const char *bridge
, const char *prefix
)
414 static const char *stpstates
[] = {
421 struct ifbifconf bifc
;
423 char *inbuf
= NULL
, *ninbuf
;
424 uint32_t i
, len
= 8192;
427 ninbuf
= realloc(inbuf
, len
);
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
)
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
);
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
]);
453 printf(" <unknown state %d>",
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
;
472 ninbuf
= realloc(inbuf
, len
);
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
)
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
);
498 get_val(const char *cp
, u_long
*valp
)
504 val
= strtoul(cp
, &endptr
, 0);
505 if (cp
[0] == '\0' || endptr
[0] != '\0' || errno
== ERANGE
)
513 do_cmd(int sock
, const char *bridge
, u_long op
, void *arg
, size_t argsize
,
518 memset(&ifd
, 0, sizeof(ifd
));
520 strlcpy(ifd
.ifd_name
, bridge
, sizeof(ifd
.ifd_name
));
522 ifd
.ifd_len
= argsize
;
525 return (ioctl(sock
, set
? SIOCSDRVSPEC
: SIOCGDRVSPEC
, &ifd
));
529 do_ifflag(int sock
, const char *bridge
, int flag
, int set
)
533 g_ifr
.ifr_flags
|= flag
;
535 g_ifr
.ifr_flags
&= ~flag
;
541 do_bridgeflag(int sock
, const char *bridge
, const char *ifs
, int flag
,
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");
552 req
.ifbr_ifsflags
|= flag
;
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");
561 cmd_add(const struct command
*cmd
, int sock
, const char *bridge
,
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]);
574 cmd_delete(const struct command
*cmd
, int sock
, const char *bridge
,
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]);
586 cmd_up(const struct command
*cmd
, int sock
, const char *bridge
,
590 do_ifflag(sock
, bridge
, IFF_UP
, 1);
594 cmd_down(const struct command
*cmd
, int sock
, const char *bridge
,
598 do_ifflag(sock
, bridge
, IFF_UP
, 0);
602 cmd_discover(const struct command
*cmd
, int sock
, const char *bridge
,
606 do_bridgeflag(sock
, bridge
, argv
[0], IFBIF_DISCOVER
,
607 (cmd
->cmd_flags
& CMD_INVERT
) ? 0 : 1);
611 cmd_learn(const struct command
*cmd
, int sock
, const char *bridge
,
615 do_bridgeflag(sock
, bridge
, argv
[0], IFBIF_LEARNING
,
616 (cmd
->cmd_flags
& CMD_INVERT
) ? 0 : 1);
620 cmd_stp(const struct command
*cmd
, int sock
, const char *bridge
,
624 do_bridgeflag(sock
, bridge
, argv
[0], IFBIF_STP
,
625 (cmd
->cmd_flags
& CMD_INVERT
) ? 0 : 1);
629 cmd_flush(const struct command
*cmd
, int sock
, const char *bridge
,
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
);
641 cmd_flushall(const struct command
*cmd
, int sock
, const char *bridge
,
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
);
653 cmd_static(const struct command
*cmd
, int sock
, const char *bridge
,
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]);
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]);
674 cmd_deladdr(const struct command
*cmd
, int sock
, const char *bridge
,
678 struct ether_addr
*ea
;
680 memset(&req
, 0, sizeof(req
));
682 ea
= ether_aton(argv
[0]);
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]);
693 cmd_addr(const struct command
*cmd
, int sock
, const char *bridge
,
697 show_addresses(sock
, bridge
, "\t");
701 cmd_maxaddr(const struct command
*cmd
, int sock
, const char *bridge
,
704 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
713 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
717 cmd_hellotime(const struct command
*cmd
, int sock
, const char *bridge
,
720 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
729 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
733 cmd_fwddelay(const struct command
*cmd
, int sock
, const char *bridge
,
736 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
745 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
749 cmd_maxage(const struct command
*cmd
, int sock
, const char *bridge
,
752 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
761 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
765 cmd_priority(const struct command
*cmd
, int sock
, const char *bridge
,
768 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
777 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
781 cmd_ifpriority(const struct command
*cmd
, int sock
, const char *bridge
,
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]);
800 cmd_ifpathcost(const struct command
*cmd
, int sock
, const char *bridge
,
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]);
819 cmd_timeout(const struct command
*cmd
, int sock
, const char *bridge
,
822 struct ifbrparam param
;
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
, ¶m
, sizeof(param
), 1) < 0)
831 err(1, "%s %s", cmd
->cmd_keyword
, argv
[0]);
835 cmd_ipf(const struct command
*cmd
, int sock
, const char *bridge
,
838 struct ifbrparam param
;
840 if (do_cmd(sock
, bridge
, BRDGGFILT
, ¶m
, 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
, ¶m
, sizeof(param
), 1) < 0)
846 err(1, "%s %x", cmd
->cmd_keyword
, param
.ifbrp_filter
);