]> git.saurik.com Git - apple/network_cmds.git/blob - ifconfig.tproj/ifbridge.c
network_cmds-356.9.tar.gz
[apple/network_cmds.git] / ifconfig.tproj / ifbridge.c
1 /*-
2 * Copyright 2001 Wasabi Systems, Inc.
3 * All rights reserved.
4 *
5 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Wasabi Systems, Inc.
19 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #ifndef lint
37 static const char rcsid[] =
38 "$FreeBSD: src/sbin/ifconfig/ifbridge.c,v 1.11.2.1.2.1 2008/11/25 02:59:29 kensmith Exp $";
39 #endif /* not lint */
40
41 #include <sys/param.h>
42 #include <sys/ioctl.h>
43 #include <sys/socket.h>
44 #include <sys/sockio.h>
45
46 #include <stdlib.h>
47 #include <unistd.h>
48
49 #include <net/ethernet.h>
50 #include <net/if.h>
51 #include <net/if_bridgevar.h>
52 #include <net/route.h>
53
54 #include <ctype.h>
55 #include <stdio.h>
56 #include <string.h>
57 #include <stdlib.h>
58 #include <unistd.h>
59 #include <err.h>
60 #include <errno.h>
61
62 #include "ifconfig.h"
63
64 #define PV2ID(pv, epri, eaddr) do { \
65 epri = pv >> 48; \
66 eaddr[0] = pv >> 40; \
67 eaddr[1] = pv >> 32; \
68 eaddr[2] = pv >> 24; \
69 eaddr[3] = pv >> 16; \
70 eaddr[4] = pv >> 8; \
71 eaddr[5] = pv >> 0; \
72 } while (0)
73
74 static const char *stpstates[] = {
75 "disabled",
76 "listening",
77 "learning",
78 "forwarding",
79 "blocking",
80 "discarding"
81 };
82 #ifdef notdef
83 static const char *stpproto[] = {
84 "stp",
85 "-",
86 "rstp"
87 };
88 static const char *stproles[] = {
89 "disabled",
90 "root",
91 "designated",
92 "alternate",
93 "backup"
94 };
95 #endif
96
97 static int
98 get_val(const char *cp, u_long *valp)
99 {
100 char *endptr;
101 u_long val;
102
103 errno = 0;
104 val = strtoul(cp, &endptr, 0);
105 if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE)
106 return (-1);
107
108 *valp = val;
109 return (0);
110 }
111
112 static int
113 do_cmd(int sock, u_long op, void *arg, size_t argsize, int set)
114 {
115 struct ifdrv ifd;
116
117 memset(&ifd, 0, sizeof(ifd));
118
119 strlcpy(ifd.ifd_name, ifr.ifr_name, sizeof(ifd.ifd_name));
120 ifd.ifd_cmd = op;
121 ifd.ifd_len = argsize;
122 ifd.ifd_data = arg;
123
124 return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
125 }
126
127 static void
128 do_bridgeflag(int sock, const char *ifs, int flag, int set)
129 {
130 struct ifbreq req;
131
132 strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname));
133
134 if (do_cmd(sock, BRDGGIFFLGS, &req, sizeof(req), 0) < 0)
135 err(1, "unable to get bridge flags");
136
137 if (set)
138 req.ifbr_ifsflags |= flag;
139 else
140 req.ifbr_ifsflags &= ~flag;
141
142 if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
143 err(1, "unable to set bridge flags");
144 }
145
146 static void
147 bridge_interfaces(int s, const char *prefix)
148 {
149 struct ifbifconf bifc;
150 struct ifbreq *req;
151 char *inbuf = NULL, *ninbuf;
152 char *p, *pad;
153 int i, len = 8192;
154
155 pad = strdup(prefix);
156 if (pad == NULL)
157 err(1, "strdup");
158 /* replace the prefix with whitespace */
159 for (p = pad; *p != '\0'; p++) {
160 if(isprint(*p))
161 *p = ' ';
162 }
163
164 for (;;) {
165 ninbuf = realloc(inbuf, len);
166 if (ninbuf == NULL)
167 err(1, "unable to allocate interface buffer");
168 bifc.ifbic_len = len;
169 bifc.ifbic_buf = inbuf = ninbuf;
170 if (do_cmd(s, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0)
171 err(1, "unable to get interface list");
172 if ((bifc.ifbic_len + sizeof(*req)) < len)
173 break;
174 len *= 2;
175 }
176
177 for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
178 req = bifc.ifbic_req + i;
179 printf("%s%s ", prefix, req->ifbr_ifsname);
180 printb("flags", req->ifbr_ifsflags, IFBIFBITS);
181 printf("\n");
182
183 printf("%s", pad);
184 #ifdef notdef
185 printf("ifmaxaddr %u", req->ifbr_addrmax);
186 #endif
187 printf(" port %u priority %u", req->ifbr_portno,
188 req->ifbr_priority);
189 printf(" path cost %u", req->ifbr_path_cost);
190
191 if (req->ifbr_ifsflags & IFBIF_STP) {
192 #ifdef notdef
193 if (req->ifbr_proto <
194 sizeof(stpproto) / sizeof(stpproto[0]))
195 printf(" proto %s", stpproto[req->ifbr_proto]);
196 else
197 printf(" <unknown proto %d>",
198 req->ifbr_proto);
199
200 printf("\n%s", pad);
201 if (req->ifbr_role <
202 sizeof(stproles) / sizeof(stproles[0]))
203 printf("role %s", stproles[req->ifbr_role]);
204 else
205 printf("<unknown role %d>",
206 req->ifbr_role);
207 #endif
208 if (req->ifbr_state <
209 sizeof(stpstates) / sizeof(stpstates[0]))
210 printf(" state %s", stpstates[req->ifbr_state]);
211 else
212 printf(" <unknown state %d>",
213 req->ifbr_state);
214 }
215 printf("\n");
216 }
217
218 free(inbuf);
219 }
220
221 static void
222 bridge_addresses(int s, const char *prefix)
223 {
224 struct ifbaconf ifbac;
225 struct ifbareq *ifba;
226 char *inbuf = NULL, *ninbuf;
227 int i, len = 8192;
228 struct ether_addr ea;
229
230 for (;;) {
231 ninbuf = realloc(inbuf, len);
232 if (ninbuf == NULL)
233 err(1, "unable to allocate address buffer");
234 ifbac.ifbac_len = len;
235 ifbac.ifbac_buf = inbuf = ninbuf;
236 if (do_cmd(s, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
237 err(1, "unable to get address cache");
238 if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
239 break;
240 len *= 2;
241 }
242
243 for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
244 ifba = ifbac.ifbac_req + i;
245 memcpy(ea.octet, ifba->ifba_dst,
246 sizeof(ea.octet));
247 #ifdef notdef
248 printf("%s%s Vlan%d %s %lu ", prefix, ether_ntoa(&ea),
249 ifba->ifba_vlan, ifba->ifba_ifsname, ifba->ifba_expire);
250 #else
251 printf("%s%s %s %lu ", prefix, ether_ntoa(&ea),
252 ifba->ifba_ifsname, ifba->ifba_expire);
253 #endif
254 printb("flags", ifba->ifba_flags, IFBAFBITS);
255 printf("\n");
256 }
257
258 free(inbuf);
259 }
260
261 void
262 show_config(int sock, const char *prefix)
263 {
264 struct ifbrparam param;
265 u_int32_t ipfflags;
266 u_int16_t pri;
267 u_int8_t ht, fd, ma;
268
269 if (do_cmd(sock, BRDGGPRI, &param, sizeof(param), 0) < 0)
270 err(1, "unable to get bridge priority");
271 pri = param.ifbrp_prio;
272
273 if (do_cmd(sock, BRDGGHT, &param, sizeof(param), 0) < 0)
274 err(1, "unable to get hellotime");
275 ht = param.ifbrp_hellotime;
276
277 if (do_cmd(sock, BRDGGFD, &param, sizeof(param), 0) < 0)
278 err(1, "unable to get forward delay");
279 fd = param.ifbrp_fwddelay;
280
281 if (do_cmd(sock, BRDGGMA, &param, sizeof(param), 0) < 0)
282 err(1, "unable to get max age");
283 ma = param.ifbrp_maxage;
284
285 printf("%spriority %u hellotime %u fwddelay %u maxage %u\n",
286 prefix, pri, ht, fd, ma);
287
288 if (do_cmd(sock, BRDGGFILT, &param, sizeof(param), 0) < 0) {
289 /* err(1, "unable to get ipfilter status"); */
290 param.ifbrp_filter = 0;
291 }
292
293 ipfflags = param.ifbrp_filter;
294 printf("%sipfilter %s flags 0x%x\n", prefix,
295 (ipfflags & IFBF_FILT_USEIPF) ? "enabled" : "disabled",
296 ipfflags);
297 }
298
299 static void
300 bridge_status(int s)
301 {
302 #ifdef notdef
303 struct ifbropreq ifbp;
304 #endif
305 struct ifbrparam param;
306 #ifdef notdef
307 u_int16_t pri;
308 u_int8_t ht, fd, ma, hc, pro;
309 u_int8_t lladdr[ETHER_ADDR_LEN];
310 u_int16_t bprio;
311 #endif
312 u_int32_t csize, ctime;
313
314 if (do_cmd(s, BRDGGCACHE, &param, sizeof(param), 0) < 0)
315 return;
316 csize = param.ifbrp_csize;
317 if (do_cmd(s, BRDGGTO, &param, sizeof(param), 0) < 0)
318 return;
319 ctime = param.ifbrp_ctime;
320 #ifdef notdef
321 if (do_cmd(s, BRDGPARAM, &ifbp, sizeof(ifbp), 0) < 0)
322 return;
323 pri = ifbp.ifbop_priority;
324 pro = ifbp.ifbop_protocol;
325 ht = ifbp.ifbop_hellotime;
326 fd = ifbp.ifbop_fwddelay;
327 hc = ifbp.ifbop_holdcount;
328 ma = ifbp.ifbop_maxage;
329
330 PV2ID(ifbp.ifbop_bridgeid, bprio, lladdr);
331 printf("\tid %s priority %u hellotime %u fwddelay %u\n",
332 ether_ntoa((struct ether_addr *)lladdr), pri, ht, fd);
333 printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n",
334 ma, hc, stpproto[pro], csize, ctime);
335
336 PV2ID(ifbp.ifbop_designated_root, bprio, lladdr);
337 printf("\troot id %s priority %d ifcost %u port %u\n",
338 ether_ntoa((struct ether_addr *)lladdr), bprio,
339 ifbp.ifbop_root_path_cost, ifbp.ifbop_root_port & 0xfff);
340 #else
341 printf("\tConfiguration:\n");
342 show_config(s, "\t\t");
343 #endif
344
345 bridge_interfaces(s, "\tmember: ");
346
347 if (!all || verbose) {
348 printf("\tAddress cache (max cache: %u, timeout: %u):\n",
349 csize, ctime);
350 bridge_addresses(s, "\t\t");
351 }
352 return;
353
354 }
355
356 static void
357 setbridge_add(const char *val, int d, int s, const struct afswtch *afp)
358 {
359 struct ifbreq req;
360
361 memset(&req, 0, sizeof(req));
362 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
363 if (do_cmd(s, BRDGADD, &req, sizeof(req), 1) < 0)
364 err(1, "BRDGADD %s", val);
365 }
366
367 static void
368 setbridge_delete(const char *val, int d, int s, const struct afswtch *afp)
369 {
370 struct ifbreq req;
371
372 memset(&req, 0, sizeof(req));
373 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
374 if (do_cmd(s, BRDGDEL, &req, sizeof(req), 1) < 0)
375 err(1, "BRDGDEL %s", val);
376 }
377
378 static void
379 setbridge_discover(const char *val, int d, int s, const struct afswtch *afp)
380 {
381
382 do_bridgeflag(s, val, IFBIF_DISCOVER, 1);
383 }
384
385 static void
386 unsetbridge_discover(const char *val, int d, int s, const struct afswtch *afp)
387 {
388
389 do_bridgeflag(s, val, IFBIF_DISCOVER, 0);
390 }
391
392 static void
393 setbridge_learn(const char *val, int d, int s, const struct afswtch *afp)
394 {
395
396 do_bridgeflag(s, val, IFBIF_LEARNING, 1);
397 }
398
399 static void
400 unsetbridge_learn(const char *val, int d, int s, const struct afswtch *afp)
401 {
402
403 do_bridgeflag(s, val, IFBIF_LEARNING, 0);
404 }
405
406 #ifdef notdef
407 static void
408 setbridge_sticky(const char *val, int d, int s, const struct afswtch *afp)
409 {
410
411 do_bridgeflag(s, val, IFBIF_STICKY, 1);
412 }
413
414 static void
415 unsetbridge_sticky(const char *val, int d, int s, const struct afswtch *afp)
416 {
417
418 do_bridgeflag(s, val, IFBIF_STICKY, 0);
419 }
420
421 static void
422 setbridge_span(const char *val, int d, int s, const struct afswtch *afp)
423 {
424 struct ifbreq req;
425
426 memset(&req, 0, sizeof(req));
427 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
428 if (do_cmd(s, BRDGADDS, &req, sizeof(req), 1) < 0)
429 err(1, "BRDGADDS %s", val);
430 }
431
432 static void
433 unsetbridge_span(const char *val, int d, int s, const struct afswtch *afp)
434 {
435 struct ifbreq req;
436
437 memset(&req, 0, sizeof(req));
438 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
439 if (do_cmd(s, BRDGDELS, &req, sizeof(req), 1) < 0)
440 err(1, "BRDGDELS %s", val);
441 }
442 #endif
443
444 static void
445 setbridge_stp(const char *val, int d, int s, const struct afswtch *afp)
446 {
447
448 do_bridgeflag(s, val, IFBIF_STP, 1);
449 }
450
451 static void
452 unsetbridge_stp(const char *val, int d, int s, const struct afswtch *afp)
453 {
454
455 do_bridgeflag(s, val, IFBIF_STP, 0);
456 }
457
458 #ifdef notdef
459 static void
460 setbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
461 {
462 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 1);
463 }
464
465 static void
466 unsetbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
467 {
468 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 0);
469 }
470
471 static void
472 setbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
473 {
474 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 1);
475 }
476
477 static void
478 unsetbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
479 {
480 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 0);
481 }
482
483 static void
484 setbridge_ptp(const char *val, int d, int s, const struct afswtch *afp)
485 {
486 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 1);
487 }
488
489 static void
490 unsetbridge_ptp(const char *val, int d, int s, const struct afswtch *afp)
491 {
492 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 0);
493 }
494
495 static void
496 setbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp)
497 {
498 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 1);
499 }
500
501 static void
502 unsetbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp)
503 {
504 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 0);
505 }
506 #endif
507
508 static void
509 setbridge_flush(const char *val, int d, int s, const struct afswtch *afp)
510 {
511 struct ifbreq req;
512
513 memset(&req, 0, sizeof(req));
514 req.ifbr_ifsflags = IFBF_FLUSHDYN;
515 if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0)
516 err(1, "BRDGFLUSH");
517 }
518
519 static void
520 setbridge_flushall(const char *val, int d, int s, const struct afswtch *afp)
521 {
522 struct ifbreq req;
523
524 memset(&req, 0, sizeof(req));
525 req.ifbr_ifsflags = IFBF_FLUSHALL;
526 if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0)
527 err(1, "BRDGFLUSH");
528 }
529
530 static void
531 setbridge_static(const char *val, const char *mac, int s,
532 const struct afswtch *afp)
533 {
534 struct ifbareq req;
535 struct ether_addr *ea;
536
537 memset(&req, 0, sizeof(req));
538 strlcpy(req.ifba_ifsname, val, sizeof(req.ifba_ifsname));
539
540 ea = ether_aton(mac);
541 if (ea == NULL)
542 errx(1, "%s: invalid address: %s", val, mac);
543
544 memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
545 req.ifba_flags = IFBAF_STATIC;
546 #ifdef notdef
547 req.ifba_vlan = 1; /* XXX allow user to specify */
548 #endif
549
550 if (do_cmd(s, BRDGSADDR, &req, sizeof(req), 1) < 0)
551 err(1, "BRDGSADDR %s", val);
552 }
553
554 static void
555 setbridge_deladdr(const char *val, int d, int s, const struct afswtch *afp)
556 {
557 struct ifbareq req;
558 struct ether_addr *ea;
559
560 memset(&req, 0, sizeof(req));
561
562 ea = ether_aton(val);
563 if (ea == NULL)
564 errx(1, "invalid address: %s", val);
565
566 memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
567
568 if (do_cmd(s, BRDGDADDR, &req, sizeof(req), 1) < 0)
569 err(1, "BRDGDADDR %s", val);
570 }
571
572 static void
573 setbridge_addr(const char *val, int d, int s, const struct afswtch *afp)
574 {
575
576 bridge_addresses(s, "");
577 }
578
579 static void
580 setbridge_maxaddr(const char *arg, int d, int s, const struct afswtch *afp)
581 {
582 struct ifbrparam param;
583 u_long val;
584
585 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
586 errx(1, "invalid value: %s", arg);
587
588 param.ifbrp_csize = val & 0xffffffff;
589
590 if (do_cmd(s, BRDGSCACHE, &param, sizeof(param), 1) < 0)
591 err(1, "BRDGSCACHE %s", arg);
592 }
593
594 static void
595 setbridge_hellotime(const char *arg, int d, int s, const struct afswtch *afp)
596 {
597 struct ifbrparam param;
598 u_long val;
599
600 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
601 errx(1, "invalid value: %s", arg);
602
603 param.ifbrp_hellotime = val & 0xff;
604
605 if (do_cmd(s, BRDGSHT, &param, sizeof(param), 1) < 0)
606 err(1, "BRDGSHT %s", arg);
607 }
608
609 static void
610 setbridge_fwddelay(const char *arg, int d, int s, const struct afswtch *afp)
611 {
612 struct ifbrparam param;
613 u_long val;
614
615 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
616 errx(1, "invalid value: %s", arg);
617
618 param.ifbrp_fwddelay = val & 0xff;
619
620 if (do_cmd(s, BRDGSFD, &param, sizeof(param), 1) < 0)
621 err(1, "BRDGSFD %s", arg);
622 }
623
624 static void
625 setbridge_maxage(const char *arg, int d, int s, const struct afswtch *afp)
626 {
627 struct ifbrparam param;
628 u_long val;
629
630 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
631 errx(1, "invalid value: %s", arg);
632
633 param.ifbrp_maxage = val & 0xff;
634
635 if (do_cmd(s, BRDGSMA, &param, sizeof(param), 1) < 0)
636 err(1, "BRDGSMA %s", arg);
637 }
638
639 static void
640 setbridge_priority(const char *arg, int d, int s, const struct afswtch *afp)
641 {
642 struct ifbrparam param;
643 u_long val;
644
645 if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0)
646 errx(1, "invalid value: %s", arg);
647
648 param.ifbrp_prio = val & 0xffff;
649
650 if (do_cmd(s, BRDGSPRI, &param, sizeof(param), 1) < 0)
651 err(1, "BRDGSPRI %s", arg);
652 }
653
654 #ifdef notdef
655 static void
656 setbridge_protocol(const char *arg, int d, int s, const struct afswtch *afp)
657 {
658 struct ifbrparam param;
659
660 if (strcasecmp(arg, "stp") == 0) {
661 param.ifbrp_proto = 0;
662 } else if (strcasecmp(arg, "rstp") == 0) {
663 param.ifbrp_proto = 2;
664 } else {
665 errx(1, "unknown stp protocol");
666 }
667
668 if (do_cmd(s, BRDGSPROTO, &param, sizeof(param), 1) < 0)
669 err(1, "BRDGSPROTO %s", arg);
670 }
671 static void
672 setbridge_holdcount(const char *arg, int d, int s, const struct afswtch *afp)
673 {
674 struct ifbrparam param;
675 u_long val;
676
677 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
678 errx(1, "invalid value: %s", arg);
679
680 param.ifbrp_txhc = val & 0xff;
681
682 if (do_cmd(s, BRDGSTXHC, &param, sizeof(param), 1) < 0)
683 err(1, "BRDGSTXHC %s", arg);
684 }
685 #endif
686
687 static void
688 setbridge_ifpriority(const char *ifn, const char *pri, int s,
689 const struct afswtch *afp)
690 {
691 struct ifbreq req;
692 u_long val;
693
694 memset(&req, 0, sizeof(req));
695
696 if (get_val(pri, &val) < 0 || (val & ~0xff) != 0)
697 errx(1, "invalid value: %s", pri);
698
699 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
700 req.ifbr_priority = val & 0xff;
701
702 if (do_cmd(s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0)
703 err(1, "BRDGSIFPRIO %s", pri);
704 }
705
706 static void
707 setbridge_ifpathcost(const char *ifn, const char *cost, int s,
708 const struct afswtch *afp)
709 {
710 struct ifbreq req;
711 u_long val;
712
713 memset(&req, 0, sizeof(req));
714
715 if (get_val(cost, &val) < 0)
716 errx(1, "invalid value: %s", cost);
717
718 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
719 req.ifbr_path_cost = val;
720
721 if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
722 err(1, "BRDGSIFCOST %s", cost);
723 }
724
725 #ifdef notdef
726 static void
727 setbridge_ifmaxaddr(const char *ifn, const char *arg, int s,
728 const struct afswtch *afp)
729 {
730 struct ifbreq req;
731 u_long val;
732
733 memset(&req, 0, sizeof(req));
734
735 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
736 errx(1, "invalid value: %s", arg);
737
738 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
739 req.ifbr_addrmax = val & 0xffffffff;
740
741 if (do_cmd(s, BRDGSIFAMAX, &req, sizeof(req), 1) < 0)
742 err(1, "BRDGSIFAMAX %s", arg);
743 }
744 #endif
745
746 static void
747 setbridge_timeout(const char *arg, int d, int s, const struct afswtch *afp)
748 {
749 struct ifbrparam param;
750 u_long val;
751
752 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
753 errx(1, "invalid value: %s", arg);
754
755 param.ifbrp_ctime = val & 0xffffffff;
756
757 if (do_cmd(s, BRDGSTO, &param, sizeof(param), 1) < 0)
758 err(1, "BRDGSTO %s", arg);
759 }
760
761 #ifdef notdef
762 static void
763 setbridge_private(const char *val, int d, int s, const struct afswtch *afp)
764 {
765
766 do_bridgeflag(s, val, IFBIF_PRIVATE, 1);
767 }
768
769 static void
770 unsetbridge_private(const char *val, int d, int s, const struct afswtch *afp)
771 {
772
773 do_bridgeflag(s, val, IFBIF_PRIVATE, 0);
774 }
775 #endif
776
777 static struct cmd bridge_cmds[] = {
778 DEF_CMD_ARG("addm", setbridge_add),
779 DEF_CMD_ARG("deletem", setbridge_delete),
780 DEF_CMD_ARG("discover", setbridge_discover),
781 DEF_CMD_ARG("-discover", unsetbridge_discover),
782 DEF_CMD_ARG("learn", setbridge_learn),
783 DEF_CMD_ARG("-learn", unsetbridge_learn),
784 //DEF_CMD_ARG("sticky", setbridge_sticky),
785 //DEF_CMD_ARG("-sticky", unsetbridge_sticky),
786 //DEF_CMD_ARG("span", setbridge_span),
787 //DEF_CMD_ARG("-span", unsetbridge_span),
788 DEF_CMD_ARG("stp", setbridge_stp),
789 DEF_CMD_ARG("-stp", unsetbridge_stp),
790 //DEF_CMD_ARG("edge", setbridge_edge),
791 //DEF_CMD_ARG("-edge", unsetbridge_edge),
792 //DEF_CMD_ARG("autoedge", setbridge_autoedge),
793 //DEF_CMD_ARG("-autoedge", unsetbridge_autoedge),
794 //DEF_CMD_ARG("ptp", setbridge_ptp),
795 //DEF_CMD_ARG("-ptp", unsetbridge_ptp),
796 //DEF_CMD_ARG("autoptp", setbridge_autoptp),
797 //DEF_CMD_ARG("-autoptp", unsetbridge_autoptp),
798 DEF_CMD("flush", 0, setbridge_flush),
799 DEF_CMD("flushall", 0, setbridge_flushall),
800 DEF_CMD_ARG2("static", setbridge_static),
801 DEF_CMD_ARG("deladdr", setbridge_deladdr),
802 DEF_CMD("addr", 1, setbridge_addr),
803 DEF_CMD_ARG("maxaddr", setbridge_maxaddr),
804 DEF_CMD_ARG("hellotime", setbridge_hellotime),
805 DEF_CMD_ARG("fwddelay", setbridge_fwddelay),
806 DEF_CMD_ARG("maxage", setbridge_maxage),
807 DEF_CMD_ARG("priority", setbridge_priority),
808 //DEF_CMD_ARG("proto", setbridge_protocol),
809 //DEF_CMD_ARG("holdcnt", setbridge_holdcount),
810 DEF_CMD_ARG2("ifpriority", setbridge_ifpriority),
811 DEF_CMD_ARG2("ifpathcost", setbridge_ifpathcost),
812 //DEF_CMD_ARG2("ifmaxaddr", setbridge_ifmaxaddr),
813 DEF_CMD_ARG("timeout", setbridge_timeout),
814 //DEF_CMD_ARG("private", setbridge_private),
815 //DEF_CMD_ARG("-private", unsetbridge_private),
816 };
817 static struct afswtch af_bridge = {
818 .af_name = "af_bridge",
819 .af_af = AF_UNSPEC,
820 .af_other_status = bridge_status,
821 };
822
823 static __constructor void
824 bridge_ctor(void)
825 {
826 #define N(a) (sizeof(a) / sizeof(a[0]))
827 int i;
828
829 for (i = 0; i < N(bridge_cmds); i++)
830 cmd_register(&bridge_cmds[i]);
831 af_register(&af_bridge);
832 #undef N
833 }