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$"; 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 static const char *stpproto[] = { 83 "stp", 84 "-", 85 "rstp" 86 }; 87 static const char *stproles[] = { 88 "disabled", 89 "root", 90 "designated", 91 "alternate", 92 "backup" 93 }; 94 95 static int 96 get_val(const char *cp, u_long *valp) 97 { 98 char *endptr; 99 u_long val; 100 101 errno = 0; 102 val = strtoul(cp, &endptr, 0); 103 if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE) 104 return (-1); 105 106 *valp = val; 107 return (0); 108 } 109 110 static int 111 do_cmd(int sock, u_long op, void *arg, size_t argsize, int set) 112 { 113 struct ifdrv ifd; 114 115 memset(&ifd, 0, sizeof(ifd)); 116 117 strlcpy(ifd.ifd_name, ifr.ifr_name, sizeof(ifd.ifd_name)); 118 ifd.ifd_cmd = op; 119 ifd.ifd_len = argsize; 120 ifd.ifd_data = arg; 121 122 return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd)); 123 } 124 125 static void 126 do_bridgeflag(int sock, const char *ifs, int flag, int set) 127 { 128 struct ifbreq req; 129 130 strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname)); 131 132 if (do_cmd(sock, BRDGGIFFLGS, &req, sizeof(req), 0) < 0) 133 err(1, "unable to get bridge flags"); 134 135 if (set) 136 req.ifbr_ifsflags |= flag; 137 else 138 req.ifbr_ifsflags &= ~flag; 139 140 if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0) 141 err(1, "unable to set bridge flags"); 142 } 143 144 static void 145 bridge_interfaces(int s, const char *prefix) 146 { 147 struct ifbifconf bifc; 148 struct ifbreq *req; 149 char *inbuf = NULL, *ninbuf; 150 char *p, *pad; 151 int i, len = 8192; 152 153 pad = strdup(prefix); 154 if (pad == NULL) 155 err(1, "strdup"); 156 /* replace the prefix with whitespace */ 157 for (p = pad; *p != '\0'; p++) { 158 if(isprint(*p)) 159 *p = ' '; 160 } 161 162 for (;;) { 163 ninbuf = realloc(inbuf, len); 164 if (ninbuf == NULL) 165 err(1, "unable to allocate interface buffer"); 166 bifc.ifbic_len = len; 167 bifc.ifbic_buf = inbuf = ninbuf; 168 if (do_cmd(s, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0) 169 err(1, "unable to get interface list"); 170 if ((bifc.ifbic_len + sizeof(*req)) < len) 171 break; 172 len *= 2; 173 } 174 175 for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) { 176 req = bifc.ifbic_req + i; 177 printf("%s%s ", prefix, req->ifbr_ifsname); 178 printb("flags", req->ifbr_ifsflags, IFBIFBITS); 179 printf("\n"); 180 181 if (req->ifbr_ifsflags & IFBIF_STP) { 182 printf("%s", pad); 183 printf("port %u priority %u", 184 req->ifbr_portno, req->ifbr_priority); 185 printf(" path cost %u", req->ifbr_path_cost); 186 if (req->ifbr_proto < 187 sizeof(stpproto) / sizeof(stpproto[0])) 188 printf(" proto %s", stpproto[req->ifbr_proto]); 189 else 190 printf(" <unknown proto %d>", 191 req->ifbr_proto); 192 193 printf("\n%s", pad); 194 if (req->ifbr_role < 195 sizeof(stproles) / sizeof(stproles[0])) 196 printf("role %s", stproles[req->ifbr_role]); 197 else 198 printf("<unknown role %d>", 199 req->ifbr_role); 200 if (req->ifbr_state < 201 sizeof(stpstates) / sizeof(stpstates[0])) 202 printf(" state %s", stpstates[req->ifbr_state]); 203 else 204 printf(" <unknown state %d>", 205 req->ifbr_state); 206 printf("\n"); 207 } 208 } 209 210 free(inbuf); 211 } 212 213 static void 214 bridge_addresses(int s, const char *prefix) 215 { 216 struct ifbaconf ifbac; 217 struct ifbareq *ifba; 218 char *inbuf = NULL, *ninbuf; 219 int i, len = 8192; 220 struct ether_addr ea; 221 222 for (;;) { 223 ninbuf = realloc(inbuf, len); 224 if (ninbuf == NULL) 225 err(1, "unable to allocate address buffer"); 226 ifbac.ifbac_len = len; 227 ifbac.ifbac_buf = inbuf = ninbuf; 228 if (do_cmd(s, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0) 229 err(1, "unable to get address cache"); 230 if ((ifbac.ifbac_len + sizeof(*ifba)) < len) 231 break; 232 len *= 2; 233 } 234 235 for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) { 236 ifba = ifbac.ifbac_req + i; 237 memcpy(ea.octet, ifba->ifba_dst, 238 sizeof(ea.octet)); 239 printf("%s%s %s %lu ", prefix, ether_ntoa(&ea), 240 ifba->ifba_ifsname, ifba->ifba_expire); 241 printb("flags", ifba->ifba_flags, IFBAFBITS); 242 printf("\n"); 243 } 244 245 free(inbuf); 246 } 247 248 static void 249 bridge_status(int s) 250 { 251 struct ifbropreq ifbp; 252 struct ifbrparam param; 253 u_int16_t pri; 254 u_int8_t ht, fd, ma, hc, pro; 255 u_int8_t lladdr[ETHER_ADDR_LEN]; 256 u_int16_t bprio; 257 u_int32_t csize, ctime; 258 259 if (do_cmd(s, BRDGGCACHE, ¶m, sizeof(param), 0) < 0) 260 return; 261 csize = param.ifbrp_csize; 262 if (do_cmd(s, BRDGGTO, ¶m, sizeof(param), 0) < 0) 263 return; 264 ctime = param.ifbrp_ctime; 265 if (do_cmd(s, BRDGPARAM, &ifbp, sizeof(ifbp), 0) < 0) 266 return; 267 pri = ifbp.ifbop_priority; 268 pro = ifbp.ifbop_protocol; 269 ht = ifbp.ifbop_hellotime; 270 fd = ifbp.ifbop_fwddelay; 271 hc = ifbp.ifbop_holdcount; 272 ma = ifbp.ifbop_maxage; 273 274 PV2ID(ifbp.ifbop_bridgeid, bprio, lladdr); 275 printf("\tid %s priority %u hellotime %u fwddelay %u\n", 276 ether_ntoa((struct ether_addr *)lladdr), pri, ht, fd); 277 printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n", 278 ma, hc, stpproto[pro], csize, ctime); 279 280 PV2ID(ifbp.ifbop_designated_root, bprio, lladdr); 281 printf("\troot id %s priority %d ifcost %u port %u\n", 282 ether_ntoa((struct ether_addr *)lladdr), bprio, 283 ifbp.ifbop_root_path_cost, ifbp.ifbop_root_port & 0xfff); 284 285 bridge_interfaces(s, "\tmember: "); 286 287 return; 288 289 } 290 291 static void 292 setbridge_add(const char *val, int d, int s, const struct afswtch *afp) 293 { 294 struct ifbreq req; 295 296 memset(&req, 0, sizeof(req)); 297 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); 298 if (do_cmd(s, BRDGADD, &req, sizeof(req), 1) < 0) 299 err(1, "BRDGADD %s", val); 300 } 301 302 static void 303 setbridge_delete(const char *val, int d, int s, const struct afswtch *afp) 304 { 305 struct ifbreq req; 306 307 memset(&req, 0, sizeof(req)); 308 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); 309 if (do_cmd(s, BRDGDEL, &req, sizeof(req), 1) < 0) 310 err(1, "BRDGDEL %s", val); 311 } 312 313 static void 314 setbridge_discover(const char *val, int d, int s, const struct afswtch *afp) 315 { 316 317 do_bridgeflag(s, val, IFBIF_DISCOVER, 1); 318 } 319 320 static void 321 unsetbridge_discover(const char *val, int d, int s, const struct afswtch *afp) 322 { 323 324 do_bridgeflag(s, val, IFBIF_DISCOVER, 0); 325 } 326 327 static void 328 setbridge_learn(const char *val, int d, int s, const struct afswtch *afp) 329 { 330 331 do_bridgeflag(s, val, IFBIF_LEARNING, 1); 332 } 333 334 static void 335 unsetbridge_learn(const char *val, int d, int s, const struct afswtch *afp) 336 { 337 338 do_bridgeflag(s, val, IFBIF_LEARNING, 0); 339 } 340 341 static void 342 setbridge_sticky(const char *val, int d, int s, const struct afswtch *afp) 343 { 344 345 do_bridgeflag(s, val, IFBIF_STICKY, 1); 346 } 347 348 static void 349 unsetbridge_sticky(const char *val, int d, int s, const struct afswtch *afp) 350 { 351 352 do_bridgeflag(s, val, IFBIF_STICKY, 0); 353 } 354 355 static void 356 setbridge_span(const char *val, int d, int s, const struct afswtch *afp) 357 { 358 struct ifbreq req; 359 360 memset(&req, 0, sizeof(req)); 361 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); 362 if (do_cmd(s, BRDGADDS, &req, sizeof(req), 1) < 0) 363 err(1, "BRDGADDS %s", val); 364 } 365 366 static void 367 unsetbridge_span(const char *val, int d, int s, const struct afswtch *afp) 368 { 369 struct ifbreq req; 370 371 memset(&req, 0, sizeof(req)); 372 strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); 373 if (do_cmd(s, BRDGDELS, &req, sizeof(req), 1) < 0) 374 err(1, "BRDGDELS %s", val); 375 } 376 377 static void 378 setbridge_stp(const char *val, int d, int s, const struct afswtch *afp) 379 { 380 381 do_bridgeflag(s, val, IFBIF_STP, 1); 382 } 383 384 static void 385 unsetbridge_stp(const char *val, int d, int s, const struct afswtch *afp) 386 { 387 388 do_bridgeflag(s, val, IFBIF_STP, 0); 389 } 390 391 static void 392 setbridge_edge(const char *val, int d, int s, const struct afswtch *afp) 393 { 394 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 1); 395 } 396 397 static void 398 unsetbridge_edge(const char *val, int d, int s, const struct afswtch *afp) 399 { 400 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 0); 401 } 402 403 static void 404 setbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp) 405 { 406 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 1); 407 } 408 409 static void 410 unsetbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp) 411 { 412 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 0); 413 } 414 415 static void 416 setbridge_ptp(const char *val, int d, int s, const struct afswtch *afp) 417 { 418 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 1); 419 } 420 421 static void 422 unsetbridge_ptp(const char *val, int d, int s, const struct afswtch *afp) 423 { 424 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 0); 425 } 426 427 static void 428 setbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp) 429 { 430 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 1); 431 } 432 433 static void 434 unsetbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp) 435 { 436 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 0); 437 } 438 439 static void 440 setbridge_flush(const char *val, int d, int s, const struct afswtch *afp) 441 { 442 struct ifbreq req; 443 444 memset(&req, 0, sizeof(req)); 445 req.ifbr_ifsflags = IFBF_FLUSHDYN; 446 if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0) 447 err(1, "BRDGFLUSH"); 448 } 449 450 static void 451 setbridge_flushall(const char *val, int d, int s, const struct afswtch *afp) 452 { 453 struct ifbreq req; 454 455 memset(&req, 0, sizeof(req)); 456 req.ifbr_ifsflags = IFBF_FLUSHALL; 457 if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0) 458 err(1, "BRDGFLUSH"); 459 } 460 461 static void 462 setbridge_static(const char *val, const char *mac, int s, 463 const struct afswtch *afp) 464 { 465 struct ifbareq req; 466 struct ether_addr *ea; 467 468 memset(&req, 0, sizeof(req)); 469 strlcpy(req.ifba_ifsname, val, sizeof(req.ifba_ifsname)); 470 471 ea = ether_aton(mac); 472 if (ea == NULL) 473 errx(1, "%s: invalid address: %s", val, mac); 474 475 memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst)); 476 req.ifba_flags = IFBAF_STATIC; 477 478 if (do_cmd(s, BRDGSADDR, &req, sizeof(req), 1) < 0) 479 err(1, "BRDGSADDR %s", val); 480 } 481 482 static void 483 setbridge_deladdr(const char *val, int d, int s, const struct afswtch *afp) 484 { 485 struct ifbareq req; 486 struct ether_addr *ea; 487 488 memset(&req, 0, sizeof(req)); 489 490 ea = ether_aton(val); 491 if (ea == NULL) 492 errx(1, "invalid address: %s", val); 493 494 memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst)); 495 496 if (do_cmd(s, BRDGDADDR, &req, sizeof(req), 1) < 0) 497 err(1, "BRDGDADDR %s", val); 498 } 499 500 static void 501 setbridge_addr(const char *val, int d, int s, const struct afswtch *afp) 502 { 503 504 bridge_addresses(s, ""); 505 } 506 507 static void 508 setbridge_maxaddr(const char *arg, int d, int s, const struct afswtch *afp) 509 { 510 struct ifbrparam param; 511 u_long val; 512 513 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) 514 errx(1, "invalid value: %s", arg); 515 516 param.ifbrp_csize = val & 0xffffffff; 517 518 if (do_cmd(s, BRDGSCACHE, ¶m, sizeof(param), 1) < 0) 519 err(1, "BRDGSCACHE %s", arg); 520 } 521 522 static void 523 setbridge_hellotime(const char *arg, int d, int s, const struct afswtch *afp) 524 { 525 struct ifbrparam param; 526 u_long val; 527 528 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 529 errx(1, "invalid value: %s", arg); 530 531 param.ifbrp_hellotime = val & 0xff; 532 533 if (do_cmd(s, BRDGSHT, ¶m, sizeof(param), 1) < 0) 534 err(1, "BRDGSHT %s", arg); 535 } 536 537 static void 538 setbridge_fwddelay(const char *arg, int d, int s, const struct afswtch *afp) 539 { 540 struct ifbrparam param; 541 u_long val; 542 543 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 544 errx(1, "invalid value: %s", arg); 545 546 param.ifbrp_fwddelay = val & 0xff; 547 548 if (do_cmd(s, BRDGSFD, ¶m, sizeof(param), 1) < 0) 549 err(1, "BRDGSFD %s", arg); 550 } 551 552 static void 553 setbridge_maxage(const char *arg, int d, int s, const struct afswtch *afp) 554 { 555 struct ifbrparam param; 556 u_long val; 557 558 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 559 errx(1, "invalid value: %s", arg); 560 561 param.ifbrp_maxage = val & 0xff; 562 563 if (do_cmd(s, BRDGSMA, ¶m, sizeof(param), 1) < 0) 564 err(1, "BRDGSMA %s", arg); 565 } 566 567 static void 568 setbridge_priority(const char *arg, int d, int s, const struct afswtch *afp) 569 { 570 struct ifbrparam param; 571 u_long val; 572 573 if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0) 574 errx(1, "invalid value: %s", arg); 575 576 param.ifbrp_prio = val & 0xffff; 577 578 if (do_cmd(s, BRDGSPRI, ¶m, sizeof(param), 1) < 0) 579 err(1, "BRDGSPRI %s", arg); 580 } 581 582 static void 583 setbridge_protocol(const char *arg, int d, int s, const struct afswtch *afp) 584 { 585 struct ifbrparam param; 586 587 if (strcasecmp(arg, "stp") == 0) { 588 param.ifbrp_proto = 0; 589 } else if (strcasecmp(arg, "rstp") == 0) { 590 param.ifbrp_proto = 2; 591 } else { 592 errx(1, "unknown stp protocol"); 593 } 594 595 if (do_cmd(s, BRDGSPROTO, ¶m, sizeof(param), 1) < 0) 596 err(1, "BRDGSPROTO %s", arg); 597 } 598 599 static void 600 setbridge_holdcount(const char *arg, int d, int s, const struct afswtch *afp) 601 { 602 struct ifbrparam param; 603 u_long val; 604 605 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 606 errx(1, "invalid value: %s", arg); 607 608 param.ifbrp_txhc = val & 0xff; 609 610 if (do_cmd(s, BRDGSTXHC, ¶m, sizeof(param), 1) < 0) 611 err(1, "BRDGSTXHC %s", arg); 612 } 613 614 static void 615 setbridge_ifpriority(const char *ifn, const char *pri, int s, 616 const struct afswtch *afp) 617 { 618 struct ifbreq req; 619 u_long val; 620 621 memset(&req, 0, sizeof(req)); 622 623 if (get_val(pri, &val) < 0 || (val & ~0xff) != 0) 624 errx(1, "invalid value: %s", pri); 625 626 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); 627 req.ifbr_priority = val & 0xff; 628 629 if (do_cmd(s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0) 630 err(1, "BRDGSIFPRIO %s", pri); 631 } 632 633 static void 634 setbridge_ifpathcost(const char *ifn, const char *cost, int s, 635 const struct afswtch *afp) 636 { 637 struct ifbreq req; 638 u_long val; 639 640 memset(&req, 0, sizeof(req)); 641 642 if (get_val(cost, &val) < 0) 643 errx(1, "invalid value: %s", cost); 644 645 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); 646 req.ifbr_path_cost = val; 647 648 if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0) 649 err(1, "BRDGSIFCOST %s", cost); 650 } 651 652 static void 653 setbridge_timeout(const char *arg, int d, int s, const struct afswtch *afp) 654 { 655 struct ifbrparam param; 656 u_long val; 657 658 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) 659 errx(1, "invalid value: %s", arg); 660 661 param.ifbrp_ctime = val & 0xffffffff; 662 663 if (do_cmd(s, BRDGSTO, ¶m, sizeof(param), 1) < 0) 664 err(1, "BRDGSTO %s", arg); 665 } 666 667 static struct cmd bridge_cmds[] = { 668 DEF_CMD_ARG("addm", setbridge_add), 669 DEF_CMD_ARG("deletem", setbridge_delete), 670 DEF_CMD_ARG("discover", setbridge_discover), 671 DEF_CMD_ARG("-discover", unsetbridge_discover), 672 DEF_CMD_ARG("learn", setbridge_learn), 673 DEF_CMD_ARG("-learn", unsetbridge_learn), 674 DEF_CMD_ARG("sticky", setbridge_sticky), 675 DEF_CMD_ARG("-sticky", unsetbridge_sticky), 676 DEF_CMD_ARG("span", setbridge_span), 677 DEF_CMD_ARG("-span", unsetbridge_span), 678 DEF_CMD_ARG("stp", setbridge_stp), 679 DEF_CMD_ARG("-stp", unsetbridge_stp), 680 DEF_CMD_ARG("edge", setbridge_edge), 681 DEF_CMD_ARG("-edge", unsetbridge_edge), 682 DEF_CMD_ARG("autoedge", setbridge_autoedge), 683 DEF_CMD_ARG("-autoedge", unsetbridge_autoedge), 684 DEF_CMD_ARG("ptp", setbridge_ptp), 685 DEF_CMD_ARG("-ptp", unsetbridge_ptp), 686 DEF_CMD_ARG("autoptp", setbridge_autoptp), 687 DEF_CMD_ARG("-autoptp", unsetbridge_autoptp), 688 DEF_CMD("flush", 0, setbridge_flush), 689 DEF_CMD("flushall", 0, setbridge_flushall), 690 DEF_CMD_ARG2("static", setbridge_static), 691 DEF_CMD_ARG("deladdr", setbridge_deladdr), 692 DEF_CMD("addr", 1, setbridge_addr), 693 DEF_CMD_ARG("maxaddr", setbridge_maxaddr), 694 DEF_CMD_ARG("hellotime", setbridge_hellotime), 695 DEF_CMD_ARG("fwddelay", setbridge_fwddelay), 696 DEF_CMD_ARG("maxage", setbridge_maxage), 697 DEF_CMD_ARG("priority", setbridge_priority), 698 DEF_CMD_ARG("proto", setbridge_protocol), 699 DEF_CMD_ARG("holdcnt", setbridge_holdcount), 700 DEF_CMD_ARG2("ifpriority", setbridge_ifpriority), 701 DEF_CMD_ARG2("ifpathcost", setbridge_ifpathcost), 702 DEF_CMD_ARG("timeout", setbridge_timeout), 703 }; 704 static struct afswtch af_bridge = { 705 .af_name = "af_bridge", 706 .af_af = AF_UNSPEC, 707 .af_other_status = bridge_status, 708 }; 709 710 static __constructor void 711 bridge_ctor(void) 712 { 713 #define N(a) (sizeof(a) / sizeof(a[0])) 714 int i; 715 716 for (i = 0; i < N(bridge_cmds); i++) 717 cmd_register(&bridge_cmds[i]); 718 af_register(&af_bridge); 719 #undef N 720 } 721