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