1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef lint 31 static const char copyright[] = 32 "@(#) Copyright (c) 1983, 1993\n\ 33 The Regents of the University of California. All rights reserved.\n"; 34 #endif /* not lint */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; 39 #endif 40 static const char rcsid[] = 41 "$FreeBSD$"; 42 #endif /* not lint */ 43 44 #include <sys/param.h> 45 #include <sys/ioctl.h> 46 #include <sys/module.h> 47 #include <sys/linker.h> 48 #include <sys/queue.h> 49 #include <sys/socket.h> 50 #include <sys/time.h> 51 52 #include <net/ethernet.h> 53 #include <net/if.h> 54 #include <net/if_dl.h> 55 #include <net/if_types.h> 56 #include <net/route.h> 57 58 /* IP */ 59 #include <netinet/in.h> 60 #include <netinet/in_var.h> 61 #include <arpa/inet.h> 62 #include <netdb.h> 63 64 #include <ifaddrs.h> 65 #include <ctype.h> 66 #include <err.h> 67 #include <errno.h> 68 #include <fcntl.h> 69 #ifdef JAIL 70 #include <jail.h> 71 #endif 72 #include <stdio.h> 73 #include <stdlib.h> 74 #include <string.h> 75 #include <unistd.h> 76 77 #include "ifconfig.h" 78 79 /* 80 * Since "struct ifreq" is composed of various union members, callers 81 * should pay special attention to interpret the value. 82 * (.e.g. little/big endian difference in the structure.) 83 */ 84 struct ifreq ifr; 85 86 char name[IFNAMSIZ]; 87 char *descr = NULL; 88 size_t descrlen = 64; 89 int setaddr; 90 int setmask; 91 int doalias; 92 int clearaddr; 93 int newaddr = 1; 94 int verbose; 95 int noload; 96 int printifname = 0; 97 98 int supmedia = 0; 99 int printkeys = 0; /* Print keying material for interfaces. */ 100 101 static int ifconfig(int argc, char *const *argv, int iscreate, 102 const struct afswtch *afp); 103 static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, 104 struct ifaddrs *ifa); 105 static void tunnel_status(int s); 106 static void usage(void); 107 108 static struct afswtch *af_getbyname(const char *name); 109 static struct afswtch *af_getbyfamily(int af); 110 static void af_other_status(int); 111 112 void printifnamemaybe(void); 113 114 static struct option *opts = NULL; 115 116 struct ifa_order_elt { 117 int if_order; 118 int af_orders[255]; 119 struct ifaddrs *ifa; 120 TAILQ_ENTRY(ifa_order_elt) link; 121 }; 122 123 TAILQ_HEAD(ifa_queue, ifa_order_elt); 124 125 void 126 opt_register(struct option *p) 127 { 128 p->next = opts; 129 opts = p; 130 } 131 132 static void 133 usage(void) 134 { 135 char options[1024]; 136 struct option *p; 137 138 /* XXX not right but close enough for now */ 139 options[0] = '\0'; 140 for (p = opts; p != NULL; p = p->next) { 141 strlcat(options, p->opt_usage, sizeof(options)); 142 strlcat(options, " ", sizeof(options)); 143 } 144 145 fprintf(stderr, 146 "usage: ifconfig %sinterface address_family [address [dest_address]]\n" 147 " [parameters]\n" 148 " ifconfig interface create\n" 149 " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" 150 " ifconfig -l [-d] [-u] [address_family]\n" 151 " ifconfig %s[-d] [-m] [-u] [-v]\n", 152 options, options, options); 153 exit(1); 154 } 155 156 #define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) 157 158 static int 159 calcorders(struct ifaddrs *ifa, struct ifa_queue *q) 160 { 161 struct ifaddrs *prev; 162 struct ifa_order_elt *cur; 163 unsigned int ord, af, ifa_ord; 164 165 prev = NULL; 166 cur = NULL; 167 ord = 0; 168 ifa_ord = 0; 169 170 while (ifa != NULL) { 171 if (prev == NULL || 172 strcmp(ifa->ifa_name, prev->ifa_name) != 0) { 173 cur = calloc(1, sizeof(*cur)); 174 175 if (cur == NULL) 176 return (-1); 177 178 TAILQ_INSERT_TAIL(q, cur, link); 179 cur->if_order = ifa_ord ++; 180 cur->ifa = ifa; 181 ord = 0; 182 } 183 184 if (ifa->ifa_addr) { 185 af = ifa->ifa_addr->sa_family; 186 187 if (af < ORDERS_SIZE(cur->af_orders) && 188 cur->af_orders[af] == 0) 189 cur->af_orders[af] = ++ord; 190 } 191 prev = ifa; 192 ifa = ifa->ifa_next; 193 } 194 195 return (0); 196 } 197 198 static int 199 cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) 200 { 201 struct ifa_order_elt *cur, *e1, *e2; 202 unsigned int af1, af2; 203 int ret; 204 205 e1 = e2 = NULL; 206 207 ret = strcmp(a->ifa_name, b->ifa_name); 208 if (ret != 0) { 209 TAILQ_FOREACH(cur, q, link) { 210 if (e1 && e2) 211 break; 212 213 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) 214 e1 = cur; 215 else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0) 216 e2 = cur; 217 } 218 219 if (!e1 || !e2) 220 return (0); 221 else 222 return (e1->if_order - e2->if_order); 223 224 } else if (a->ifa_addr != NULL && b->ifa_addr != NULL) { 225 TAILQ_FOREACH(cur, q, link) { 226 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) { 227 e1 = cur; 228 break; 229 } 230 } 231 232 if (!e1) 233 return (0); 234 235 af1 = a->ifa_addr->sa_family; 236 af2 = b->ifa_addr->sa_family; 237 238 if (af1 < ORDERS_SIZE(e1->af_orders) && 239 af2 < ORDERS_SIZE(e1->af_orders)) 240 return (e1->af_orders[af1] - e1->af_orders[af2]); 241 } 242 243 return (0); 244 } 245 246 #undef ORDERS_SIZE 247 248 static struct ifaddrs * 249 sortifaddrs(struct ifaddrs *list, 250 int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), 251 struct ifa_queue *q) 252 { 253 struct ifaddrs *right, *temp, *last, *result, *next, *tail; 254 255 right = list; 256 temp = list; 257 last = list; 258 result = NULL; 259 next = NULL; 260 tail = NULL; 261 262 if (!list || !list->ifa_next) 263 return (list); 264 265 while (temp && temp->ifa_next) { 266 last = right; 267 right = right->ifa_next; 268 temp = temp->ifa_next->ifa_next; 269 } 270 271 last->ifa_next = NULL; 272 273 list = sortifaddrs(list, compare, q); 274 right = sortifaddrs(right, compare, q); 275 276 while (list || right) { 277 278 if (!right) { 279 next = list; 280 list = list->ifa_next; 281 } else if (!list) { 282 next = right; 283 right = right->ifa_next; 284 } else if (compare(list, right, q) <= 0) { 285 next = list; 286 list = list->ifa_next; 287 } else { 288 next = right; 289 right = right->ifa_next; 290 } 291 292 if (!result) 293 result = next; 294 else 295 tail->ifa_next = next; 296 297 tail = next; 298 } 299 300 return (result); 301 } 302 303 void printifnamemaybe() 304 { 305 if (printifname) 306 printf("%s\n", name); 307 } 308 309 int 310 main(int argc, char *argv[]) 311 { 312 int c, all, namesonly, downonly, uponly; 313 const struct afswtch *afp = NULL; 314 int ifindex; 315 struct ifaddrs *ifap, *sifap, *ifa; 316 struct ifreq paifr; 317 const struct sockaddr_dl *sdl; 318 char options[1024], *cp, *namecp = NULL; 319 struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q); 320 struct ifa_order_elt *cur, *tmp; 321 const char *ifname; 322 struct option *p; 323 size_t iflen; 324 325 all = downonly = uponly = namesonly = noload = verbose = 0; 326 327 /* 328 * Ensure we print interface name when expected to, 329 * even if we terminate early due to error. 330 */ 331 atexit(printifnamemaybe); 332 333 /* Parse leading line options */ 334 strlcpy(options, "adklmnuv", sizeof(options)); 335 for (p = opts; p != NULL; p = p->next) 336 strlcat(options, p->opt, sizeof(options)); 337 while ((c = getopt(argc, argv, options)) != -1) { 338 switch (c) { 339 case 'a': /* scan all interfaces */ 340 all++; 341 break; 342 case 'd': /* restrict scan to "down" interfaces */ 343 downonly++; 344 break; 345 case 'k': 346 printkeys++; 347 break; 348 case 'l': /* scan interface names only */ 349 namesonly++; 350 break; 351 case 'm': /* show media choices in status */ 352 supmedia = 1; 353 break; 354 case 'n': /* suppress module loading */ 355 noload++; 356 break; 357 case 'u': /* restrict scan to "up" interfaces */ 358 uponly++; 359 break; 360 case 'v': 361 verbose++; 362 break; 363 default: 364 for (p = opts; p != NULL; p = p->next) 365 if (p->opt[0] == c) { 366 p->cb(optarg); 367 break; 368 } 369 if (p == NULL) 370 usage(); 371 break; 372 } 373 } 374 argc -= optind; 375 argv += optind; 376 377 /* -l cannot be used with -a or -m */ 378 if (namesonly && (all || supmedia)) 379 usage(); 380 381 /* nonsense.. */ 382 if (uponly && downonly) 383 usage(); 384 385 /* no arguments is equivalent to '-a' */ 386 if (!namesonly && argc < 1) 387 all = 1; 388 389 /* -a and -l allow an address family arg to limit the output */ 390 if (all || namesonly) { 391 if (argc > 1) 392 usage(); 393 394 ifname = NULL; 395 ifindex = 0; 396 if (argc == 1) { 397 afp = af_getbyname(*argv); 398 if (afp == NULL) { 399 warnx("Address family '%s' unknown.", *argv); 400 usage(); 401 } 402 if (afp->af_name != NULL) 403 argc--, argv++; 404 /* leave with afp non-zero */ 405 } 406 } else { 407 /* not listing, need an argument */ 408 if (argc < 1) 409 usage(); 410 411 ifname = *argv; 412 argc--, argv++; 413 414 /* check and maybe load support for this interface */ 415 ifmaybeload(ifname); 416 417 ifindex = if_nametoindex(ifname); 418 if (ifindex == 0) { 419 /* 420 * NOTE: We must special-case the `create' command 421 * right here as we would otherwise fail when trying 422 * to find the interface. 423 */ 424 if (argc > 0 && (strcmp(argv[0], "create") == 0 || 425 strcmp(argv[0], "plumb") == 0)) { 426 iflen = strlcpy(name, ifname, sizeof(name)); 427 if (iflen >= sizeof(name)) 428 errx(1, "%s: cloning name too long", 429 ifname); 430 ifconfig(argc, argv, 1, NULL); 431 exit(0); 432 } 433 #ifdef JAIL 434 /* 435 * NOTE: We have to special-case the `-vnet' command 436 * right here as we would otherwise fail when trying 437 * to find the interface as it lives in another vnet. 438 */ 439 if (argc > 0 && (strcmp(argv[0], "-vnet") == 0)) { 440 iflen = strlcpy(name, ifname, sizeof(name)); 441 if (iflen >= sizeof(name)) 442 errx(1, "%s: interface name too long", 443 ifname); 444 ifconfig(argc, argv, 0, NULL); 445 exit(0); 446 } 447 #endif 448 errx(1, "interface %s does not exist", ifname); 449 } 450 } 451 452 /* Check for address family */ 453 if (argc > 0) { 454 afp = af_getbyname(*argv); 455 if (afp != NULL) 456 argc--, argv++; 457 } 458 459 if (getifaddrs(&ifap) != 0) 460 err(EXIT_FAILURE, "getifaddrs"); 461 462 cp = NULL; 463 464 if (calcorders(ifap, &q) != 0) 465 err(EXIT_FAILURE, "calcorders"); 466 467 sifap = sortifaddrs(ifap, cmpifaddrs, &q); 468 469 TAILQ_FOREACH_SAFE(cur, &q, link, tmp) 470 free(cur); 471 472 ifindex = 0; 473 for (ifa = sifap; ifa; ifa = ifa->ifa_next) { 474 memset(&paifr, 0, sizeof(paifr)); 475 strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name)); 476 if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) { 477 memcpy(&paifr.ifr_addr, ifa->ifa_addr, 478 ifa->ifa_addr->sa_len); 479 } 480 481 if (ifname != NULL && strcmp(ifname, ifa->ifa_name) != 0) 482 continue; 483 if (ifa->ifa_addr->sa_family == AF_LINK) 484 sdl = (const struct sockaddr_dl *) ifa->ifa_addr; 485 else 486 sdl = NULL; 487 if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !namesonly) 488 continue; 489 iflen = strlcpy(name, ifa->ifa_name, sizeof(name)); 490 if (iflen >= sizeof(name)) { 491 warnx("%s: interface name too long, skipping", 492 ifa->ifa_name); 493 continue; 494 } 495 cp = ifa->ifa_name; 496 497 if ((ifa->ifa_flags & IFF_CANTCONFIG) != 0) 498 continue; 499 if (downonly && (ifa->ifa_flags & IFF_UP) != 0) 500 continue; 501 if (uponly && (ifa->ifa_flags & IFF_UP) == 0) 502 continue; 503 /* 504 * Are we just listing the interfaces? 505 */ 506 if (namesonly) { 507 if (namecp == cp) 508 continue; 509 if (afp != NULL) { 510 /* special case for "ether" address family */ 511 if (!strcmp(afp->af_name, "ether")) { 512 if (sdl == NULL || 513 (sdl->sdl_type != IFT_ETHER && 514 sdl->sdl_type != IFT_L2VLAN && 515 sdl->sdl_type != IFT_BRIDGE) || 516 sdl->sdl_alen != ETHER_ADDR_LEN) 517 continue; 518 } else { 519 if (ifa->ifa_addr->sa_family 520 != afp->af_af) 521 continue; 522 } 523 } 524 namecp = cp; 525 ifindex++; 526 if (ifindex > 1) 527 printf(" "); 528 fputs(name, stdout); 529 continue; 530 } 531 ifindex++; 532 533 if (argc > 0) 534 ifconfig(argc, argv, 0, afp); 535 else 536 status(afp, sdl, ifa); 537 } 538 if (namesonly) 539 printf("\n"); 540 freeifaddrs(ifap); 541 542 exit(0); 543 } 544 545 static struct afswtch *afs = NULL; 546 547 void 548 af_register(struct afswtch *p) 549 { 550 p->af_next = afs; 551 afs = p; 552 } 553 554 static struct afswtch * 555 af_getbyname(const char *name) 556 { 557 struct afswtch *afp; 558 559 for (afp = afs; afp != NULL; afp = afp->af_next) 560 if (strcmp(afp->af_name, name) == 0) 561 return afp; 562 return NULL; 563 } 564 565 static struct afswtch * 566 af_getbyfamily(int af) 567 { 568 struct afswtch *afp; 569 570 for (afp = afs; afp != NULL; afp = afp->af_next) 571 if (afp->af_af == af) 572 return afp; 573 return NULL; 574 } 575 576 static void 577 af_other_status(int s) 578 { 579 struct afswtch *afp; 580 uint8_t afmask[howmany(AF_MAX, NBBY)]; 581 582 memset(afmask, 0, sizeof(afmask)); 583 for (afp = afs; afp != NULL; afp = afp->af_next) { 584 if (afp->af_other_status == NULL) 585 continue; 586 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af)) 587 continue; 588 afp->af_other_status(s); 589 setbit(afmask, afp->af_af); 590 } 591 } 592 593 static void 594 af_all_tunnel_status(int s) 595 { 596 struct afswtch *afp; 597 uint8_t afmask[howmany(AF_MAX, NBBY)]; 598 599 memset(afmask, 0, sizeof(afmask)); 600 for (afp = afs; afp != NULL; afp = afp->af_next) { 601 if (afp->af_status_tunnel == NULL) 602 continue; 603 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af)) 604 continue; 605 afp->af_status_tunnel(s); 606 setbit(afmask, afp->af_af); 607 } 608 } 609 610 static struct cmd *cmds = NULL; 611 612 void 613 cmd_register(struct cmd *p) 614 { 615 p->c_next = cmds; 616 cmds = p; 617 } 618 619 static const struct cmd * 620 cmd_lookup(const char *name, int iscreate) 621 { 622 const struct cmd *p; 623 624 for (p = cmds; p != NULL; p = p->c_next) 625 if (strcmp(name, p->c_name) == 0) { 626 if (iscreate) { 627 if (p->c_iscloneop) 628 return p; 629 } else { 630 if (!p->c_iscloneop) 631 return p; 632 } 633 } 634 return NULL; 635 } 636 637 struct callback { 638 callback_func *cb_func; 639 void *cb_arg; 640 struct callback *cb_next; 641 }; 642 static struct callback *callbacks = NULL; 643 644 void 645 callback_register(callback_func *func, void *arg) 646 { 647 struct callback *cb; 648 649 cb = malloc(sizeof(struct callback)); 650 if (cb == NULL) 651 errx(1, "unable to allocate memory for callback"); 652 cb->cb_func = func; 653 cb->cb_arg = arg; 654 cb->cb_next = callbacks; 655 callbacks = cb; 656 } 657 658 /* specially-handled commands */ 659 static void setifaddr(const char *, int, int, const struct afswtch *); 660 static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr); 661 662 static void setifdstaddr(const char *, int, int, const struct afswtch *); 663 static const struct cmd setifdstaddr_cmd = 664 DEF_CMD("ifdstaddr", 0, setifdstaddr); 665 666 static int 667 ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp) 668 { 669 const struct afswtch *afp, *nafp; 670 const struct cmd *p; 671 struct callback *cb; 672 int s; 673 674 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); 675 afp = NULL; 676 if (uafp != NULL) 677 afp = uafp; 678 /* 679 * This is the historical "accident" allowing users to configure IPv4 680 * addresses without the "inet" keyword which while a nice feature has 681 * proven to complicate other things. We cannot remove this but only 682 * make sure we will never have a similar implicit default for IPv6 or 683 * any other address familiy. We need a fallback though for 684 * ifconfig IF up/down etc. to work without INET support as people 685 * never used ifconfig IF link up/down, etc. either. 686 */ 687 #ifndef RESCUE 688 #ifdef INET 689 if (afp == NULL && feature_present("inet")) 690 afp = af_getbyname("inet"); 691 #endif 692 #endif 693 if (afp == NULL) 694 afp = af_getbyname("link"); 695 if (afp == NULL) { 696 warnx("Please specify an address_family."); 697 usage(); 698 } 699 top: 700 ifr.ifr_addr.sa_family = 701 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ? 702 AF_LOCAL : afp->af_af; 703 704 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 && 705 (uafp != NULL || errno != EAFNOSUPPORT || 706 (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)) 707 err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family); 708 709 while (argc > 0) { 710 p = cmd_lookup(*argv, iscreate); 711 if (iscreate && p == NULL) { 712 /* 713 * Push the clone create callback so the new 714 * device is created and can be used for any 715 * remaining arguments. 716 */ 717 cb = callbacks; 718 if (cb == NULL) 719 errx(1, "internal error, no callback"); 720 callbacks = cb->cb_next; 721 cb->cb_func(s, cb->cb_arg); 722 iscreate = 0; 723 /* 724 * Handle any address family spec that 725 * immediately follows and potentially 726 * recreate the socket. 727 */ 728 nafp = af_getbyname(*argv); 729 if (nafp != NULL) { 730 argc--, argv++; 731 if (nafp != afp) { 732 close(s); 733 afp = nafp; 734 goto top; 735 } 736 } 737 /* 738 * Look for a normal parameter. 739 */ 740 continue; 741 } 742 if (p == NULL) { 743 /* 744 * Not a recognized command, choose between setting 745 * the interface address and the dst address. 746 */ 747 p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd); 748 } 749 if (p->c_u.c_func || p->c_u.c_func2) { 750 if (p->c_parameter == NEXTARG) { 751 if (argv[1] == NULL) 752 errx(1, "'%s' requires argument", 753 p->c_name); 754 p->c_u.c_func(argv[1], 0, s, afp); 755 argc--, argv++; 756 } else if (p->c_parameter == OPTARG) { 757 p->c_u.c_func(argv[1], 0, s, afp); 758 if (argv[1] != NULL) 759 argc--, argv++; 760 } else if (p->c_parameter == NEXTARG2) { 761 if (argc < 3) 762 errx(1, "'%s' requires 2 arguments", 763 p->c_name); 764 p->c_u.c_func2(argv[1], argv[2], s, afp); 765 argc -= 2, argv += 2; 766 } else 767 p->c_u.c_func(*argv, p->c_parameter, s, afp); 768 } 769 argc--, argv++; 770 } 771 772 /* 773 * Do any post argument processing required by the address family. 774 */ 775 if (afp->af_postproc != NULL) 776 afp->af_postproc(s, afp); 777 /* 778 * Do deferred callbacks registered while processing 779 * command-line arguments. 780 */ 781 for (cb = callbacks; cb != NULL; cb = cb->cb_next) 782 cb->cb_func(s, cb->cb_arg); 783 /* 784 * Do deferred operations. 785 */ 786 if (clearaddr) { 787 if (afp->af_ridreq == NULL || afp->af_difaddr == 0) { 788 warnx("interface %s cannot change %s addresses!", 789 name, afp->af_name); 790 clearaddr = 0; 791 } 792 } 793 if (clearaddr) { 794 int ret; 795 strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name); 796 ret = ioctl(s, afp->af_difaddr, afp->af_ridreq); 797 if (ret < 0) { 798 if (errno == EADDRNOTAVAIL && (doalias >= 0)) { 799 /* means no previous address for interface */ 800 } else 801 Perror("ioctl (SIOCDIFADDR)"); 802 } 803 } 804 if (newaddr) { 805 if (afp->af_addreq == NULL || afp->af_aifaddr == 0) { 806 warnx("interface %s cannot change %s addresses!", 807 name, afp->af_name); 808 newaddr = 0; 809 } 810 } 811 if (newaddr && (setaddr || setmask)) { 812 strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); 813 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) 814 Perror("ioctl (SIOCAIFADDR)"); 815 } 816 817 close(s); 818 return(0); 819 } 820 821 /*ARGSUSED*/ 822 static void 823 setifaddr(const char *addr, int param, int s, const struct afswtch *afp) 824 { 825 if (afp->af_getaddr == NULL) 826 return; 827 /* 828 * Delay the ioctl to set the interface addr until flags are all set. 829 * The address interpretation may depend on the flags, 830 * and the flags may change when the address is set. 831 */ 832 setaddr++; 833 if (doalias == 0 && afp->af_af != AF_LINK) 834 clearaddr = 1; 835 afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR)); 836 } 837 838 static void 839 settunnel(const char *src, const char *dst, int s, const struct afswtch *afp) 840 { 841 struct addrinfo *srcres, *dstres; 842 int ecode; 843 844 if (afp->af_settunnel == NULL) { 845 warn("address family %s does not support tunnel setup", 846 afp->af_name); 847 return; 848 } 849 850 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0) 851 errx(1, "error in parsing address string: %s", 852 gai_strerror(ecode)); 853 854 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) 855 errx(1, "error in parsing address string: %s", 856 gai_strerror(ecode)); 857 858 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family) 859 errx(1, 860 "source and destination address families do not match"); 861 862 afp->af_settunnel(s, srcres, dstres); 863 864 freeaddrinfo(srcres); 865 freeaddrinfo(dstres); 866 } 867 868 /* ARGSUSED */ 869 static void 870 deletetunnel(const char *vname, int param, int s, const struct afswtch *afp) 871 { 872 873 if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0) 874 err(1, "SIOCDIFPHYADDR"); 875 } 876 877 #ifdef JAIL 878 static void 879 setifvnet(const char *jname, int dummy __unused, int s, 880 const struct afswtch *afp) 881 { 882 struct ifreq my_ifr; 883 884 memcpy(&my_ifr, &ifr, sizeof(my_ifr)); 885 my_ifr.ifr_jid = jail_getid(jname); 886 if (my_ifr.ifr_jid < 0) 887 errx(1, "%s", jail_errmsg); 888 if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0) 889 err(1, "SIOCSIFVNET"); 890 } 891 892 static void 893 setifrvnet(const char *jname, int dummy __unused, int s, 894 const struct afswtch *afp) 895 { 896 struct ifreq my_ifr; 897 898 memcpy(&my_ifr, &ifr, sizeof(my_ifr)); 899 my_ifr.ifr_jid = jail_getid(jname); 900 if (my_ifr.ifr_jid < 0) 901 errx(1, "%s", jail_errmsg); 902 if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0) 903 err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name); 904 } 905 #endif 906 907 static void 908 setifnetmask(const char *addr, int dummy __unused, int s, 909 const struct afswtch *afp) 910 { 911 if (afp->af_getaddr != NULL) { 912 setmask++; 913 afp->af_getaddr(addr, MASK); 914 } 915 } 916 917 static void 918 setifbroadaddr(const char *addr, int dummy __unused, int s, 919 const struct afswtch *afp) 920 { 921 if (afp->af_getaddr != NULL) 922 afp->af_getaddr(addr, DSTADDR); 923 } 924 925 static void 926 notealias(const char *addr, int param, int s, const struct afswtch *afp) 927 { 928 #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr)) 929 if (setaddr && doalias == 0 && param < 0) 930 if (afp->af_addreq != NULL && afp->af_ridreq != NULL) 931 bcopy((caddr_t)rqtosa(af_addreq), 932 (caddr_t)rqtosa(af_ridreq), 933 rqtosa(af_addreq)->sa_len); 934 doalias = param; 935 if (param < 0) { 936 clearaddr = 1; 937 newaddr = 0; 938 } else 939 clearaddr = 0; 940 #undef rqtosa 941 } 942 943 /*ARGSUSED*/ 944 static void 945 setifdstaddr(const char *addr, int param __unused, int s, 946 const struct afswtch *afp) 947 { 948 if (afp->af_getaddr != NULL) 949 afp->af_getaddr(addr, DSTADDR); 950 } 951 952 /* 953 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion 954 * of the ifreq structure, which may confuse other parts of ifconfig. 955 * Make a private copy so we can avoid that. 956 */ 957 static void 958 setifflags(const char *vname, int value, int s, const struct afswtch *afp) 959 { 960 struct ifreq my_ifr; 961 int flags; 962 963 memset(&my_ifr, 0, sizeof(my_ifr)); 964 (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name)); 965 966 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { 967 Perror("ioctl (SIOCGIFFLAGS)"); 968 exit(1); 969 } 970 flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16); 971 972 if (value < 0) { 973 value = -value; 974 flags &= ~value; 975 } else 976 flags |= value; 977 my_ifr.ifr_flags = flags & 0xffff; 978 my_ifr.ifr_flagshigh = flags >> 16; 979 if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0) 980 Perror(vname); 981 } 982 983 void 984 setifcap(const char *vname, int value, int s, const struct afswtch *afp) 985 { 986 int flags; 987 988 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) { 989 Perror("ioctl (SIOCGIFCAP)"); 990 exit(1); 991 } 992 flags = ifr.ifr_curcap; 993 if (value < 0) { 994 value = -value; 995 flags &= ~value; 996 } else 997 flags |= value; 998 flags &= ifr.ifr_reqcap; 999 ifr.ifr_reqcap = flags; 1000 if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0) 1001 Perror(vname); 1002 } 1003 1004 static void 1005 setifmetric(const char *val, int dummy __unused, int s, 1006 const struct afswtch *afp) 1007 { 1008 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); 1009 ifr.ifr_metric = atoi(val); 1010 if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) 1011 err(1, "ioctl SIOCSIFMETRIC (set metric)"); 1012 } 1013 1014 static void 1015 setifmtu(const char *val, int dummy __unused, int s, 1016 const struct afswtch *afp) 1017 { 1018 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); 1019 ifr.ifr_mtu = atoi(val); 1020 if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0) 1021 err(1, "ioctl SIOCSIFMTU (set mtu)"); 1022 } 1023 1024 static void 1025 setifname(const char *val, int dummy __unused, int s, 1026 const struct afswtch *afp) 1027 { 1028 char *newname; 1029 1030 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1031 1032 newname = strdup(val); 1033 if (newname == NULL) 1034 err(1, "no memory to set ifname"); 1035 ifr.ifr_data = newname; 1036 if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { 1037 free(newname); 1038 err(1, "ioctl SIOCSIFNAME (set name)"); 1039 } 1040 printifname = 1; 1041 strlcpy(name, newname, sizeof(name)); 1042 free(newname); 1043 } 1044 1045 /* ARGSUSED */ 1046 static void 1047 setifdescr(const char *val, int dummy __unused, int s, 1048 const struct afswtch *afp) 1049 { 1050 char *newdescr; 1051 1052 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1053 1054 ifr.ifr_buffer.length = strlen(val) + 1; 1055 if (ifr.ifr_buffer.length == 1) { 1056 ifr.ifr_buffer.buffer = newdescr = NULL; 1057 ifr.ifr_buffer.length = 0; 1058 } else { 1059 newdescr = strdup(val); 1060 ifr.ifr_buffer.buffer = newdescr; 1061 if (newdescr == NULL) { 1062 warn("no memory to set ifdescr"); 1063 return; 1064 } 1065 } 1066 1067 if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) 1068 err(1, "ioctl SIOCSIFDESCR (set descr)"); 1069 1070 free(newdescr); 1071 } 1072 1073 /* ARGSUSED */ 1074 static void 1075 unsetifdescr(const char *val, int value, int s, const struct afswtch *afp) 1076 { 1077 1078 setifdescr("", 0, s, 0); 1079 } 1080 1081 #define IFFBITS \ 1082 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \ 1083 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ 1084 "\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP" 1085 1086 #define IFCAPBITS \ 1087 "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \ 1088 "\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \ 1089 "\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \ 1090 "\26RXCSUM_IPV6\27TXCSUM_IPV6" 1091 1092 /* 1093 * Print the status of the interface. If an address family was 1094 * specified, show only it; otherwise, show them all. 1095 */ 1096 static void 1097 status(const struct afswtch *afp, const struct sockaddr_dl *sdl, 1098 struct ifaddrs *ifa) 1099 { 1100 struct ifaddrs *ift; 1101 int allfamilies, s; 1102 struct ifstat ifs; 1103 1104 if (afp == NULL) { 1105 allfamilies = 1; 1106 ifr.ifr_addr.sa_family = AF_LOCAL; 1107 } else { 1108 allfamilies = 0; 1109 ifr.ifr_addr.sa_family = 1110 afp->af_af == AF_LINK ? AF_LOCAL : afp->af_af; 1111 } 1112 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1113 1114 s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0); 1115 if (s < 0) 1116 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family); 1117 1118 printf("%s: ", name); 1119 printb("flags", ifa->ifa_flags, IFFBITS); 1120 if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1) 1121 printf(" metric %d", ifr.ifr_metric); 1122 if (ioctl(s, SIOCGIFMTU, &ifr) != -1) 1123 printf(" mtu %d", ifr.ifr_mtu); 1124 putchar('\n'); 1125 1126 for (;;) { 1127 if ((descr = reallocf(descr, descrlen)) != NULL) { 1128 ifr.ifr_buffer.buffer = descr; 1129 ifr.ifr_buffer.length = descrlen; 1130 if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) { 1131 if (ifr.ifr_buffer.buffer == descr) { 1132 if (strlen(descr) > 0) 1133 printf("\tdescription: %s\n", 1134 descr); 1135 } else if (ifr.ifr_buffer.length > descrlen) { 1136 descrlen = ifr.ifr_buffer.length; 1137 continue; 1138 } 1139 } 1140 } else 1141 warn("unable to allocate memory for interface" 1142 "description"); 1143 break; 1144 } 1145 1146 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { 1147 if (ifr.ifr_curcap != 0) { 1148 printb("\toptions", ifr.ifr_curcap, IFCAPBITS); 1149 putchar('\n'); 1150 } 1151 if (supmedia && ifr.ifr_reqcap != 0) { 1152 printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS); 1153 putchar('\n'); 1154 } 1155 } 1156 1157 tunnel_status(s); 1158 1159 for (ift = ifa; ift != NULL; ift = ift->ifa_next) { 1160 if (ift->ifa_addr == NULL) 1161 continue; 1162 if (strcmp(ifa->ifa_name, ift->ifa_name) != 0) 1163 continue; 1164 if (allfamilies) { 1165 const struct afswtch *p; 1166 p = af_getbyfamily(ift->ifa_addr->sa_family); 1167 if (p != NULL && p->af_status != NULL) 1168 p->af_status(s, ift); 1169 } else if (afp->af_af == ift->ifa_addr->sa_family) 1170 afp->af_status(s, ift); 1171 } 1172 #if 0 1173 if (allfamilies || afp->af_af == AF_LINK) { 1174 const struct afswtch *lafp; 1175 1176 /* 1177 * Hack; the link level address is received separately 1178 * from the routing information so any address is not 1179 * handled above. Cobble together an entry and invoke 1180 * the status method specially. 1181 */ 1182 lafp = af_getbyname("lladdr"); 1183 if (lafp != NULL) { 1184 info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl; 1185 lafp->af_status(s, &info); 1186 } 1187 } 1188 #endif 1189 if (allfamilies) 1190 af_other_status(s); 1191 else if (afp->af_other_status != NULL) 1192 afp->af_other_status(s); 1193 1194 strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name); 1195 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) 1196 printf("%s", ifs.ascii); 1197 1198 if (verbose > 0) 1199 sfp_status(s, &ifr, verbose); 1200 1201 close(s); 1202 return; 1203 } 1204 1205 static void 1206 tunnel_status(int s) 1207 { 1208 af_all_tunnel_status(s); 1209 } 1210 1211 void 1212 Perror(const char *cmd) 1213 { 1214 switch (errno) { 1215 1216 case ENXIO: 1217 errx(1, "%s: no such interface", cmd); 1218 break; 1219 1220 case EPERM: 1221 errx(1, "%s: permission denied", cmd); 1222 break; 1223 1224 default: 1225 err(1, "%s", cmd); 1226 } 1227 } 1228 1229 /* 1230 * Print a value a la the %b format of the kernel's printf 1231 */ 1232 void 1233 printb(const char *s, unsigned v, const char *bits) 1234 { 1235 int i, any = 0; 1236 char c; 1237 1238 if (bits && *bits == 8) 1239 printf("%s=%o", s, v); 1240 else 1241 printf("%s=%x", s, v); 1242 bits++; 1243 if (bits) { 1244 putchar('<'); 1245 while ((i = *bits++) != '\0') { 1246 if (v & (1 << (i-1))) { 1247 if (any) 1248 putchar(','); 1249 any = 1; 1250 for (; (c = *bits) > 32; bits++) 1251 putchar(c); 1252 } else 1253 for (; *bits > 32; bits++) 1254 ; 1255 } 1256 putchar('>'); 1257 } 1258 } 1259 1260 void 1261 print_vhid(const struct ifaddrs *ifa, const char *s) 1262 { 1263 struct if_data *ifd; 1264 1265 if (ifa->ifa_data == NULL) 1266 return; 1267 1268 ifd = ifa->ifa_data; 1269 if (ifd->ifi_vhid == 0) 1270 return; 1271 1272 printf("vhid %d ", ifd->ifi_vhid); 1273 } 1274 1275 void 1276 ifmaybeload(const char *name) 1277 { 1278 #define MOD_PREFIX_LEN 3 /* "if_" */ 1279 struct module_stat mstat; 1280 int fileid, modid; 1281 char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp; 1282 const char *cp; 1283 1284 /* loading suppressed by the user */ 1285 if (noload) 1286 return; 1287 1288 /* trim the interface number off the end */ 1289 strlcpy(ifname, name, sizeof(ifname)); 1290 for (dp = ifname; *dp != 0; dp++) 1291 if (isdigit(*dp)) { 1292 *dp = 0; 1293 break; 1294 } 1295 1296 /* turn interface and unit into module name */ 1297 strlcpy(ifkind, "if_", sizeof(ifkind)); 1298 strlcat(ifkind, ifname, sizeof(ifkind)); 1299 1300 /* scan files in kernel */ 1301 mstat.version = sizeof(struct module_stat); 1302 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { 1303 /* scan modules in file */ 1304 for (modid = kldfirstmod(fileid); modid > 0; 1305 modid = modfnext(modid)) { 1306 if (modstat(modid, &mstat) < 0) 1307 continue; 1308 /* strip bus name if present */ 1309 if ((cp = strchr(mstat.name, '/')) != NULL) { 1310 cp++; 1311 } else { 1312 cp = mstat.name; 1313 } 1314 /* already loaded? */ 1315 if (strcmp(ifname, cp) == 0 || 1316 strcmp(ifkind, cp) == 0) 1317 return; 1318 } 1319 } 1320 1321 /* not present, we should try to load it */ 1322 kldload(ifkind); 1323 } 1324 1325 static struct cmd basic_cmds[] = { 1326 DEF_CMD("up", IFF_UP, setifflags), 1327 DEF_CMD("down", -IFF_UP, setifflags), 1328 DEF_CMD("arp", -IFF_NOARP, setifflags), 1329 DEF_CMD("-arp", IFF_NOARP, setifflags), 1330 DEF_CMD("debug", IFF_DEBUG, setifflags), 1331 DEF_CMD("-debug", -IFF_DEBUG, setifflags), 1332 DEF_CMD_ARG("description", setifdescr), 1333 DEF_CMD_ARG("descr", setifdescr), 1334 DEF_CMD("-description", 0, unsetifdescr), 1335 DEF_CMD("-descr", 0, unsetifdescr), 1336 DEF_CMD("promisc", IFF_PPROMISC, setifflags), 1337 DEF_CMD("-promisc", -IFF_PPROMISC, setifflags), 1338 DEF_CMD("add", IFF_UP, notealias), 1339 DEF_CMD("alias", IFF_UP, notealias), 1340 DEF_CMD("-alias", -IFF_UP, notealias), 1341 DEF_CMD("delete", -IFF_UP, notealias), 1342 DEF_CMD("remove", -IFF_UP, notealias), 1343 #ifdef notdef 1344 #define EN_SWABIPS 0x1000 1345 DEF_CMD("swabips", EN_SWABIPS, setifflags), 1346 DEF_CMD("-swabips", -EN_SWABIPS, setifflags), 1347 #endif 1348 DEF_CMD_ARG("netmask", setifnetmask), 1349 DEF_CMD_ARG("metric", setifmetric), 1350 DEF_CMD_ARG("broadcast", setifbroadaddr), 1351 DEF_CMD_ARG2("tunnel", settunnel), 1352 DEF_CMD("-tunnel", 0, deletetunnel), 1353 DEF_CMD("deletetunnel", 0, deletetunnel), 1354 #ifdef JAIL 1355 DEF_CMD_ARG("vnet", setifvnet), 1356 DEF_CMD_ARG("-vnet", setifrvnet), 1357 #endif 1358 DEF_CMD("link0", IFF_LINK0, setifflags), 1359 DEF_CMD("-link0", -IFF_LINK0, setifflags), 1360 DEF_CMD("link1", IFF_LINK1, setifflags), 1361 DEF_CMD("-link1", -IFF_LINK1, setifflags), 1362 DEF_CMD("link2", IFF_LINK2, setifflags), 1363 DEF_CMD("-link2", -IFF_LINK2, setifflags), 1364 DEF_CMD("monitor", IFF_MONITOR, setifflags), 1365 DEF_CMD("-monitor", -IFF_MONITOR, setifflags), 1366 DEF_CMD("staticarp", IFF_STATICARP, setifflags), 1367 DEF_CMD("-staticarp", -IFF_STATICARP, setifflags), 1368 DEF_CMD("rxcsum6", IFCAP_RXCSUM_IPV6, setifcap), 1369 DEF_CMD("-rxcsum6", -IFCAP_RXCSUM_IPV6, setifcap), 1370 DEF_CMD("txcsum6", IFCAP_TXCSUM_IPV6, setifcap), 1371 DEF_CMD("-txcsum6", -IFCAP_TXCSUM_IPV6, setifcap), 1372 DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap), 1373 DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap), 1374 DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap), 1375 DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap), 1376 DEF_CMD("netcons", IFCAP_NETCONS, setifcap), 1377 DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap), 1378 DEF_CMD("polling", IFCAP_POLLING, setifcap), 1379 DEF_CMD("-polling", -IFCAP_POLLING, setifcap), 1380 DEF_CMD("tso6", IFCAP_TSO6, setifcap), 1381 DEF_CMD("-tso6", -IFCAP_TSO6, setifcap), 1382 DEF_CMD("tso4", IFCAP_TSO4, setifcap), 1383 DEF_CMD("-tso4", -IFCAP_TSO4, setifcap), 1384 DEF_CMD("tso", IFCAP_TSO, setifcap), 1385 DEF_CMD("-tso", -IFCAP_TSO, setifcap), 1386 DEF_CMD("toe", IFCAP_TOE, setifcap), 1387 DEF_CMD("-toe", -IFCAP_TOE, setifcap), 1388 DEF_CMD("lro", IFCAP_LRO, setifcap), 1389 DEF_CMD("-lro", -IFCAP_LRO, setifcap), 1390 DEF_CMD("wol", IFCAP_WOL, setifcap), 1391 DEF_CMD("-wol", -IFCAP_WOL, setifcap), 1392 DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap), 1393 DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap), 1394 DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap), 1395 DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap), 1396 DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap), 1397 DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap), 1398 DEF_CMD("normal", -IFF_LINK0, setifflags), 1399 DEF_CMD("compress", IFF_LINK0, setifflags), 1400 DEF_CMD("noicmp", IFF_LINK1, setifflags), 1401 DEF_CMD_ARG("mtu", setifmtu), 1402 DEF_CMD_ARG("name", setifname), 1403 }; 1404 1405 static __constructor void 1406 ifconfig_ctor(void) 1407 { 1408 size_t i; 1409 1410 for (i = 0; i < nitems(basic_cmds); i++) 1411 cmd_register(&basic_cmds[i]); 1412 } 1413