ifbridge.c revision 171678
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 37static const char rcsid[] = 38 "$FreeBSD: head/sbin/ifconfig/ifbridge.c 171678 2007-08-01 00:33:52Z thompsa $"; 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 74static const char *stpstates[] = { 75 "disabled", 76 "listening", 77 "learning", 78 "forwarding", 79 "blocking", 80 "discarding" 81}; 82static const char *stpproto[] = { 83 "stp", 84 "-", 85 "rstp" 86}; 87static const char *stproles[] = { 88 "disabled", 89 "root", 90 "designated", 91 "alternate", 92 "backup" 93}; 94 95static int 96get_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 110static int 111do_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 125static void 126do_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 144static void 145bridge_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 213static void 214bridge_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 Vlan%d %s %lu ", prefix, ether_ntoa(&ea), 240 ifba->ifba_vlan, ifba->ifba_ifsname, ifba->ifba_expire); 241 printb("flags", ifba->ifba_flags, IFBAFBITS); 242 printf("\n"); 243 } 244 245 free(inbuf); 246} 247 248static void 249bridge_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 291static void 292setbridge_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 302static void 303setbridge_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 313static void 314setbridge_discover(const char *val, int d, int s, const struct afswtch *afp) 315{ 316 317 do_bridgeflag(s, val, IFBIF_DISCOVER, 1); 318} 319 320static void 321unsetbridge_discover(const char *val, int d, int s, const struct afswtch *afp) 322{ 323 324 do_bridgeflag(s, val, IFBIF_DISCOVER, 0); 325} 326 327static void 328setbridge_learn(const char *val, int d, int s, const struct afswtch *afp) 329{ 330 331 do_bridgeflag(s, val, IFBIF_LEARNING, 1); 332} 333 334static void 335unsetbridge_learn(const char *val, int d, int s, const struct afswtch *afp) 336{ 337 338 do_bridgeflag(s, val, IFBIF_LEARNING, 0); 339} 340 341static void 342setbridge_sticky(const char *val, int d, int s, const struct afswtch *afp) 343{ 344 345 do_bridgeflag(s, val, IFBIF_STICKY, 1); 346} 347 348static void 349unsetbridge_sticky(const char *val, int d, int s, const struct afswtch *afp) 350{ 351 352 do_bridgeflag(s, val, IFBIF_STICKY, 0); 353} 354 355static void 356setbridge_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 366static void 367unsetbridge_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 377static void 378setbridge_stp(const char *val, int d, int s, const struct afswtch *afp) 379{ 380 381 do_bridgeflag(s, val, IFBIF_STP, 1); 382} 383 384static void 385unsetbridge_stp(const char *val, int d, int s, const struct afswtch *afp) 386{ 387 388 do_bridgeflag(s, val, IFBIF_STP, 0); 389} 390 391static void 392setbridge_edge(const char *val, int d, int s, const struct afswtch *afp) 393{ 394 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 1); 395} 396 397static void 398unsetbridge_edge(const char *val, int d, int s, const struct afswtch *afp) 399{ 400 do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 0); 401} 402 403static void 404setbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp) 405{ 406 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 1); 407} 408 409static void 410unsetbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp) 411{ 412 do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 0); 413} 414 415static void 416setbridge_ptp(const char *val, int d, int s, const struct afswtch *afp) 417{ 418 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 1); 419} 420 421static void 422unsetbridge_ptp(const char *val, int d, int s, const struct afswtch *afp) 423{ 424 do_bridgeflag(s, val, IFBIF_BSTP_PTP, 0); 425} 426 427static void 428setbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp) 429{ 430 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 1); 431} 432 433static void 434unsetbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp) 435{ 436 do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 0); 437} 438 439static void 440setbridge_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 450static void 451setbridge_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 461static void 462setbridge_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 req.ifba_vlan = 1; /* XXX allow user to specify */ 478 479 if (do_cmd(s, BRDGSADDR, &req, sizeof(req), 1) < 0) 480 err(1, "BRDGSADDR %s", val); 481} 482 483static void 484setbridge_deladdr(const char *val, int d, int s, const struct afswtch *afp) 485{ 486 struct ifbareq req; 487 struct ether_addr *ea; 488 489 memset(&req, 0, sizeof(req)); 490 491 ea = ether_aton(val); 492 if (ea == NULL) 493 errx(1, "invalid address: %s", val); 494 495 memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst)); 496 497 if (do_cmd(s, BRDGDADDR, &req, sizeof(req), 1) < 0) 498 err(1, "BRDGDADDR %s", val); 499} 500 501static void 502setbridge_addr(const char *val, int d, int s, const struct afswtch *afp) 503{ 504 505 bridge_addresses(s, ""); 506} 507 508static void 509setbridge_maxaddr(const char *arg, int d, int s, const struct afswtch *afp) 510{ 511 struct ifbrparam param; 512 u_long val; 513 514 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) 515 errx(1, "invalid value: %s", arg); 516 517 param.ifbrp_csize = val & 0xffffffff; 518 519 if (do_cmd(s, BRDGSCACHE, ¶m, sizeof(param), 1) < 0) 520 err(1, "BRDGSCACHE %s", arg); 521} 522 523static void 524setbridge_hellotime(const char *arg, int d, int s, const struct afswtch *afp) 525{ 526 struct ifbrparam param; 527 u_long val; 528 529 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 530 errx(1, "invalid value: %s", arg); 531 532 param.ifbrp_hellotime = val & 0xff; 533 534 if (do_cmd(s, BRDGSHT, ¶m, sizeof(param), 1) < 0) 535 err(1, "BRDGSHT %s", arg); 536} 537 538static void 539setbridge_fwddelay(const char *arg, int d, int s, const struct afswtch *afp) 540{ 541 struct ifbrparam param; 542 u_long val; 543 544 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 545 errx(1, "invalid value: %s", arg); 546 547 param.ifbrp_fwddelay = val & 0xff; 548 549 if (do_cmd(s, BRDGSFD, ¶m, sizeof(param), 1) < 0) 550 err(1, "BRDGSFD %s", arg); 551} 552 553static void 554setbridge_maxage(const char *arg, int d, int s, const struct afswtch *afp) 555{ 556 struct ifbrparam param; 557 u_long val; 558 559 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 560 errx(1, "invalid value: %s", arg); 561 562 param.ifbrp_maxage = val & 0xff; 563 564 if (do_cmd(s, BRDGSMA, ¶m, sizeof(param), 1) < 0) 565 err(1, "BRDGSMA %s", arg); 566} 567 568static void 569setbridge_priority(const char *arg, int d, int s, const struct afswtch *afp) 570{ 571 struct ifbrparam param; 572 u_long val; 573 574 if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0) 575 errx(1, "invalid value: %s", arg); 576 577 param.ifbrp_prio = val & 0xffff; 578 579 if (do_cmd(s, BRDGSPRI, ¶m, sizeof(param), 1) < 0) 580 err(1, "BRDGSPRI %s", arg); 581} 582 583static void 584setbridge_protocol(const char *arg, int d, int s, const struct afswtch *afp) 585{ 586 struct ifbrparam param; 587 588 if (strcasecmp(arg, "stp") == 0) { 589 param.ifbrp_proto = 0; 590 } else if (strcasecmp(arg, "rstp") == 0) { 591 param.ifbrp_proto = 2; 592 } else { 593 errx(1, "unknown stp protocol"); 594 } 595 596 if (do_cmd(s, BRDGSPROTO, ¶m, sizeof(param), 1) < 0) 597 err(1, "BRDGSPROTO %s", arg); 598} 599 600static void 601setbridge_holdcount(const char *arg, int d, int s, const struct afswtch *afp) 602{ 603 struct ifbrparam param; 604 u_long val; 605 606 if (get_val(arg, &val) < 0 || (val & ~0xff) != 0) 607 errx(1, "invalid value: %s", arg); 608 609 param.ifbrp_txhc = val & 0xff; 610 611 if (do_cmd(s, BRDGSTXHC, ¶m, sizeof(param), 1) < 0) 612 err(1, "BRDGSTXHC %s", arg); 613} 614 615static void 616setbridge_ifpriority(const char *ifn, const char *pri, int s, 617 const struct afswtch *afp) 618{ 619 struct ifbreq req; 620 u_long val; 621 622 memset(&req, 0, sizeof(req)); 623 624 if (get_val(pri, &val) < 0 || (val & ~0xff) != 0) 625 errx(1, "invalid value: %s", pri); 626 627 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); 628 req.ifbr_priority = val & 0xff; 629 630 if (do_cmd(s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0) 631 err(1, "BRDGSIFPRIO %s", pri); 632} 633 634static void 635setbridge_ifpathcost(const char *ifn, const char *cost, int s, 636 const struct afswtch *afp) 637{ 638 struct ifbreq req; 639 u_long val; 640 641 memset(&req, 0, sizeof(req)); 642 643 if (get_val(cost, &val) < 0) 644 errx(1, "invalid value: %s", cost); 645 646 strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); 647 req.ifbr_path_cost = val; 648 649 if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0) 650 err(1, "BRDGSIFCOST %s", cost); 651} 652 653static void 654setbridge_timeout(const char *arg, int d, int s, const struct afswtch *afp) 655{ 656 struct ifbrparam param; 657 u_long val; 658 659 if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) 660 errx(1, "invalid value: %s", arg); 661 662 param.ifbrp_ctime = val & 0xffffffff; 663 664 if (do_cmd(s, BRDGSTO, ¶m, sizeof(param), 1) < 0) 665 err(1, "BRDGSTO %s", arg); 666} 667 668static void 669setbridge_private(const char *val, int d, int s, const struct afswtch *afp) 670{ 671 672 do_bridgeflag(s, val, IFBIF_PRIVATE, 1); 673} 674 675static void 676unsetbridge_private(const char *val, int d, int s, const struct afswtch *afp) 677{ 678 679 do_bridgeflag(s, val, IFBIF_PRIVATE, 0); 680} 681 682static struct cmd bridge_cmds[] = { 683 DEF_CMD_ARG("addm", setbridge_add), 684 DEF_CMD_ARG("deletem", setbridge_delete), 685 DEF_CMD_ARG("discover", setbridge_discover), 686 DEF_CMD_ARG("-discover", unsetbridge_discover), 687 DEF_CMD_ARG("learn", setbridge_learn), 688 DEF_CMD_ARG("-learn", unsetbridge_learn), 689 DEF_CMD_ARG("sticky", setbridge_sticky), 690 DEF_CMD_ARG("-sticky", unsetbridge_sticky), 691 DEF_CMD_ARG("span", setbridge_span), 692 DEF_CMD_ARG("-span", unsetbridge_span), 693 DEF_CMD_ARG("stp", setbridge_stp), 694 DEF_CMD_ARG("-stp", unsetbridge_stp), 695 DEF_CMD_ARG("edge", setbridge_edge), 696 DEF_CMD_ARG("-edge", unsetbridge_edge), 697 DEF_CMD_ARG("autoedge", setbridge_autoedge), 698 DEF_CMD_ARG("-autoedge", unsetbridge_autoedge), 699 DEF_CMD_ARG("ptp", setbridge_ptp), 700 DEF_CMD_ARG("-ptp", unsetbridge_ptp), 701 DEF_CMD_ARG("autoptp", setbridge_autoptp), 702 DEF_CMD_ARG("-autoptp", unsetbridge_autoptp), 703 DEF_CMD("flush", 0, setbridge_flush), 704 DEF_CMD("flushall", 0, setbridge_flushall), 705 DEF_CMD_ARG2("static", setbridge_static), 706 DEF_CMD_ARG("deladdr", setbridge_deladdr), 707 DEF_CMD("addr", 1, setbridge_addr), 708 DEF_CMD_ARG("maxaddr", setbridge_maxaddr), 709 DEF_CMD_ARG("hellotime", setbridge_hellotime), 710 DEF_CMD_ARG("fwddelay", setbridge_fwddelay), 711 DEF_CMD_ARG("maxage", setbridge_maxage), 712 DEF_CMD_ARG("priority", setbridge_priority), 713 DEF_CMD_ARG("proto", setbridge_protocol), 714 DEF_CMD_ARG("holdcnt", setbridge_holdcount), 715 DEF_CMD_ARG2("ifpriority", setbridge_ifpriority), 716 DEF_CMD_ARG2("ifpathcost", setbridge_ifpathcost), 717 DEF_CMD_ARG("timeout", setbridge_timeout), 718 DEF_CMD_ARG("private", setbridge_private), 719 DEF_CMD_ARG("-private", unsetbridge_private), 720}; 721static struct afswtch af_bridge = { 722 .af_name = "af_bridge", 723 .af_af = AF_UNSPEC, 724 .af_other_status = bridge_status, 725}; 726 727static __constructor void 728bridge_ctor(void) 729{ 730#define N(a) (sizeof(a) / sizeof(a[0])) 731 int i; 732 733 for (i = 0; i < N(bridge_cmds); i++) 734 cmd_register(&bridge_cmds[i]); 735 af_register(&af_bridge); 736#undef N 737} 738