ifconfig.c revision 102095
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 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35static const char copyright[] = 36"@(#) Copyright (c) 1983, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; 43#endif 44static const char rcsid[] = 45 "$FreeBSD: head/sbin/ifconfig/ifconfig.c 102095 2002-08-19 08:59:20Z sobomax $"; 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/ioctl.h> 50#include <sys/socket.h> 51#include <sys/sysctl.h> 52#include <sys/time.h> 53#include <sys/module.h> 54#include <sys/linker.h> 55 56#include <net/ethernet.h> 57#include <net/if.h> 58#include <net/if_var.h> 59#include <net/if_dl.h> 60#include <net/if_types.h> 61#include <net/route.h> 62 63/* IP */ 64#include <netinet/in.h> 65#include <netinet/in_var.h> 66#include <arpa/inet.h> 67#include <netdb.h> 68 69#ifdef INET6 70#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */ 71#endif 72 73#ifndef NO_IPX 74/* IPX */ 75#define IPXIP 76#define IPTUNNEL 77#include <netipx/ipx.h> 78#include <netipx/ipx_if.h> 79#endif 80 81/* Appletalk */ 82#include <netatalk/at.h> 83 84/* XNS */ 85#ifdef NS 86#define NSIP 87#include <netns/ns.h> 88#include <netns/ns_if.h> 89#endif 90 91/* OSI */ 92 93#include <ctype.h> 94#include <err.h> 95#include <errno.h> 96#include <fcntl.h> 97#include <stdio.h> 98#include <stdlib.h> 99#include <string.h> 100#include <unistd.h> 101#include <ifaddrs.h> 102 103#include "ifconfig.h" 104 105/* wrapper for KAME-special getnameinfo() */ 106#ifndef NI_WITHSCOPEID 107#define NI_WITHSCOPEID 0 108#endif 109 110struct ifreq ifr, ridreq; 111struct ifaliasreq addreq; 112#ifdef INET6 113struct in6_ifreq in6_ridreq; 114struct in6_aliasreq in6_addreq = 115 { { 0 }, 116 { 0 }, 117 { 0 }, 118 { 0 }, 119 0, 120 { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; 121#endif 122struct sockaddr_in netmask; 123struct netrange at_nr; /* AppleTalk net range */ 124 125char name[32]; 126int flags; 127int setaddr; 128int setipdst; 129int setmask; 130int doalias; 131int clearaddr; 132int newaddr = 1; 133#ifdef INET6 134static int ip6lifetime; 135#endif 136 137struct afswtch; 138 139int supmedia = 0; 140int listcloners = 0; 141 142#ifdef INET6 143char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ 144#endif 145 146void Perror(const char *cmd); 147void checkatrange(struct sockaddr_at *); 148int ifconfig(int argc, char *const *argv, const struct afswtch *afp); 149void notealias(const char *, int, int, const struct afswtch *afp); 150void list_cloners(void); 151void printb(const char *s, unsigned value, const char *bits); 152void rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *); 153void status(const struct afswtch *afp, int addrcount, 154 struct sockaddr_dl *sdl, struct if_msghdr *ifm, 155 struct ifa_msghdr *ifam); 156void tunnel_status(int s); 157void usage(void); 158void ifmaybeload(char *name); 159 160#ifdef INET6 161void in6_fillscopeid(struct sockaddr_in6 *sin6); 162int prefix(void *, int); 163static char *sec2str(time_t); 164int explicit_prefix = 0; 165#endif 166 167typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); 168typedef void c_func2(const char *arg, const char *arg2, int s, const struct afswtch *afp); 169c_func setatphase, setatrange; 170c_func setifaddr, setifbroadaddr, setifdstaddr, setifnetmask; 171c_func2 settunnel; 172c_func deletetunnel; 173#ifdef INET6 174c_func setifprefixlen; 175c_func setip6flags; 176c_func setip6pltime; 177c_func setip6vltime; 178c_func2 setip6lifetime; 179c_func setip6eui64; 180#endif 181c_func setifipdst; 182c_func setifflags, setifmetric, setifmtu, setifcap; 183c_func clone_destroy; 184 185 186void clone_create(void); 187 188 189#define NEXTARG 0xffffff 190#define NEXTARG2 0xfffffe 191 192const 193struct cmd { 194 const char *c_name; 195 int c_parameter; /* NEXTARG means next argv */ 196 void (*c_func)(const char *, int, int, const struct afswtch *afp); 197 void (*c_func2)(const char *, const char *, int, const struct afswtch *afp); 198} cmds[] = { 199 { "up", IFF_UP, setifflags } , 200 { "down", -IFF_UP, setifflags }, 201 { "arp", -IFF_NOARP, setifflags }, 202 { "-arp", IFF_NOARP, setifflags }, 203 { "debug", IFF_DEBUG, setifflags }, 204 { "-debug", -IFF_DEBUG, setifflags }, 205 { "add", IFF_UP, notealias }, 206 { "alias", IFF_UP, notealias }, 207 { "-alias", -IFF_UP, notealias }, 208 { "delete", -IFF_UP, notealias }, 209 { "remove", -IFF_UP, notealias }, 210#ifdef notdef 211#define EN_SWABIPS 0x1000 212 { "swabips", EN_SWABIPS, setifflags }, 213 { "-swabips", -EN_SWABIPS, setifflags }, 214#endif 215 { "netmask", NEXTARG, setifnetmask }, 216#ifdef INET6 217 { "prefixlen", NEXTARG, setifprefixlen }, 218 { "anycast", IN6_IFF_ANYCAST, setip6flags }, 219 { "tentative", IN6_IFF_TENTATIVE, setip6flags }, 220 { "-tentative", -IN6_IFF_TENTATIVE, setip6flags }, 221 { "deprecated", IN6_IFF_DEPRECATED, setip6flags }, 222 { "-deprecated", -IN6_IFF_DEPRECATED, setip6flags }, 223 { "autoconf", IN6_IFF_AUTOCONF, setip6flags }, 224 { "-autoconf", -IN6_IFF_AUTOCONF, setip6flags }, 225 { "pltime", NEXTARG, setip6pltime }, 226 { "vltime", NEXTARG, setip6vltime }, 227 { "eui64", 0, setip6eui64 }, 228#endif 229 { "range", NEXTARG, setatrange }, 230 { "phase", NEXTARG, setatphase }, 231 { "metric", NEXTARG, setifmetric }, 232 { "broadcast", NEXTARG, setifbroadaddr }, 233 { "ipdst", NEXTARG, setifipdst }, 234 { "tunnel", NEXTARG2, NULL, settunnel }, 235 { "deletetunnel", 0, deletetunnel }, 236 { "link0", IFF_LINK0, setifflags }, 237 { "-link0", -IFF_LINK0, setifflags }, 238 { "link1", IFF_LINK1, setifflags }, 239 { "-link1", -IFF_LINK1, setifflags }, 240 { "link2", IFF_LINK2, setifflags }, 241 { "-link2", -IFF_LINK2, setifflags }, 242#ifdef USE_IF_MEDIA 243 { "media", NEXTARG, setmedia }, 244 { "mediaopt", NEXTARG, setmediaopt }, 245 { "-mediaopt", NEXTARG, unsetmediaopt }, 246#endif 247#ifdef USE_VLANS 248 { "vlan", NEXTARG, setvlantag }, 249 { "vlandev", NEXTARG, setvlandev }, 250 { "-vlandev", NEXTARG, unsetvlandev }, 251#endif 252#if 0 253 /* XXX `create' special-cased below */ 254 {"create", 0, clone_create }, 255 {"plumb", 0, clone_create }, 256#endif 257 {"destroy", 0, clone_destroy }, 258 {"unplumb", 0, clone_destroy }, 259#ifdef USE_IEEE80211 260 { "ssid", NEXTARG, set80211ssid }, 261 { "nwid", NEXTARG, set80211ssid }, 262 { "stationname", NEXTARG, set80211stationname }, 263 { "station", NEXTARG, set80211stationname }, /* BSD/OS */ 264 { "channel", NEXTARG, set80211channel }, 265 { "authmode", NEXTARG, set80211authmode }, 266 { "powersavemode", NEXTARG, set80211powersavemode }, 267 { "powersave", 1, set80211powersave }, 268 { "-powersave", 0, set80211powersave }, 269 { "powersavesleep", NEXTARG, set80211powersavesleep }, 270 { "wepmode", NEXTARG, set80211wepmode }, 271 { "wep", 1, set80211wep }, 272 { "-wep", 0, set80211wep }, 273 { "weptxkey", NEXTARG, set80211weptxkey }, 274 { "wepkey", NEXTARG, set80211wepkey }, 275 { "nwkey", NEXTARG, set80211nwkey }, /* NetBSD */ 276 { "-nwkey", 0, set80211wep }, /* NetBSD */ 277#endif 278 { "rxcsum", IFCAP_RXCSUM, setifcap }, 279 { "-rxcsum", -IFCAP_RXCSUM, setifcap }, 280 { "txcsum", IFCAP_TXCSUM, setifcap }, 281 { "-txcsum", -IFCAP_TXCSUM, setifcap }, 282 { "netcons", IFCAP_NETCONS, setifcap }, 283 { "-netcons", -IFCAP_NETCONS, setifcap }, 284 { "normal", -IFF_LINK0, setifflags }, 285 { "compress", IFF_LINK0, setifflags }, 286 { "noicmp", IFF_LINK1, setifflags }, 287 { "mtu", NEXTARG, setifmtu }, 288 { 0, 0, setifaddr }, 289 { 0, 0, setifdstaddr }, 290}; 291 292/* 293 * XNS support liberally adapted from code written at the University of 294 * Maryland principally by James O'Toole and Chris Torek. 295 */ 296typedef void af_status(int, struct rt_addrinfo *); 297typedef void af_getaddr(const char *, int); 298typedef void af_getprefix(const char *, int); 299 300af_status in_status, at_status, link_status; 301af_getaddr in_getaddr, at_getaddr, link_getaddr; 302 303#ifndef NO_IPX 304af_status ipx_status; 305af_getaddr ipx_getaddr; 306#endif 307 308#ifdef INET6 309af_status in6_status; 310af_getaddr in6_getaddr; 311af_getprefix in6_getprefix; 312#endif /*INET6*/ 313#ifdef NS 314af_status xns_status; 315af_getaddr xns_getaddr; 316#endif 317 318/* Known address families */ 319const 320struct afswtch { 321 const char *af_name; 322 short af_af; 323 af_status *af_status; 324 af_getaddr *af_getaddr; 325 af_getprefix *af_getprefix; 326 u_long af_difaddr; 327 u_long af_aifaddr; 328 caddr_t af_ridreq; 329 caddr_t af_addreq; 330} afs[] = { 331#define C(x) ((caddr_t) &x) 332 { "inet", AF_INET, in_status, in_getaddr, NULL, 333 SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, 334#ifdef INET6 335 { "inet6", AF_INET6, in6_status, in6_getaddr, in6_getprefix, 336 SIOCDIFADDR_IN6, SIOCAIFADDR_IN6, 337 C(in6_ridreq), C(in6_addreq) }, 338#endif /*INET6*/ 339#ifndef NO_IPX 340 { "ipx", AF_IPX, ipx_status, ipx_getaddr, NULL, 341 SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, 342#endif 343 { "atalk", AF_APPLETALK, at_status, at_getaddr, NULL, 344 SIOCDIFADDR, SIOCAIFADDR, C(addreq), C(addreq) }, 345#ifdef NS 346 { "ns", AF_NS, xns_status, xns_getaddr, NULL, 347 SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, 348#endif 349 { "link", AF_LINK, link_status, link_getaddr, NULL, 350 0, SIOCSIFLLADDR, NULL, C(ridreq) }, 351 { "ether", AF_LINK, link_status, link_getaddr, NULL, 352 0, SIOCSIFLLADDR, NULL, C(ridreq) }, 353 { "lladdr", AF_LINK, link_status, link_getaddr, NULL, 354 0, SIOCSIFLLADDR, NULL, C(ridreq) }, 355#if 0 /* XXX conflicts with the media command */ 356#ifdef USE_IF_MEDIA 357 { "media", AF_UNSPEC, media_status, NULL, NULL, }, /* XXX not real!! */ 358#endif 359#ifdef USE_VLANS 360 { "vlan", AF_UNSPEC, vlan_status, NULL, NULL, }, /* XXX not real!! */ 361#endif 362#ifdef USE_IEEE80211 363 { "ieee80211", AF_UNSPEC, ieee80211_status, NULL, NULL, }, /* XXX not real!! */ 364#endif 365#endif 366 { 0, 0, 0, 0 } 367}; 368 369/* 370 * Expand the compacted form of addresses as returned via the 371 * configuration read via sysctl(). 372 */ 373 374#define ROUNDUP(a) \ 375 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 376#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 377 378void 379rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo) 380{ 381 struct sockaddr *sa; 382 int i; 383 384 memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info)); 385 for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) { 386 if ((rtinfo->rti_addrs & (1 << i)) == 0) 387 continue; 388 rtinfo->rti_info[i] = sa = (struct sockaddr *)cp; 389 ADVANCE(cp, sa); 390 } 391} 392 393 394void 395usage(void) 396{ 397#ifndef INET6 398 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 399 "usage: ifconfig interface address_family [address [dest_address]]", 400 " [parameters]", 401 " ifconfig -C", 402 " ifconfig interface create", 403 " ifconfig -a [-d] [-m] [-u] [address_family]", 404 " ifconfig -l [-d] [-u] [address_family]", 405 " ifconfig [-d] [-m] [-u]"); 406#else 407 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 408 "usage: ifconfig [-L] interface address_family [address [dest_address]]", 409 " [parameters]", 410 " ifconfig -C", 411 " ifconfig interface create", 412 " ifconfig -a [-L] [-d] [-m] [-u] [address_family]", 413 " ifconfig -l [-d] [-u] [address_family]", 414 " ifconfig [-L] [-d] [-m] [-u]"); 415#endif 416 exit(1); 417} 418 419int 420main(int argc, char *argv[]) 421{ 422 int c; 423 int all, namesonly, downonly, uponly; 424 int need_nl = 0; 425 const struct afswtch *afp = 0; 426 int addrcount, ifindex; 427 struct if_msghdr *ifm, *nextifm; 428 struct ifa_msghdr *ifam; 429 struct sockaddr_dl *sdl; 430 char *buf, *lim, *next; 431 size_t needed; 432 int mib[6]; 433 434 /* Parse leading line options */ 435 all = downonly = uponly = namesonly = 0; 436 while ((c = getopt(argc, argv, "adlmuC" 437#ifdef INET6 438 "L" 439#endif 440 )) != -1) { 441 switch (c) { 442 case 'a': /* scan all interfaces */ 443 all++; 444 break; 445 case 'd': /* restrict scan to "down" interfaces */ 446 downonly++; 447 break; 448 case 'l': /* scan interface names only */ 449 namesonly++; 450 break; 451 case 'm': /* show media choices in status */ 452 supmedia = 1; 453 break; 454 case 'u': /* restrict scan to "up" interfaces */ 455 uponly++; 456 break; 457 case 'C': 458 listcloners = 1; 459 break; 460#ifdef INET6 461 case 'L': 462 ip6lifetime++; /* print IPv6 address lifetime */ 463 break; 464#endif 465 default: 466 usage(); 467 break; 468 } 469 } 470 argc -= optind; 471 argv += optind; 472 473 if (listcloners) { 474 /* -C must be solitary */ 475 if (all || supmedia || uponly || downonly || namesonly || 476 argc > 0) 477 usage(); 478 479 list_cloners(); 480 exit(0); 481 } 482 483 /* -l cannot be used with -a or -m */ 484 if (namesonly && (all || supmedia)) 485 usage(); 486 487 /* nonsense.. */ 488 if (uponly && downonly) 489 usage(); 490 491 /* no arguments is equivalent to '-a' */ 492 if (!namesonly && argc < 1) 493 all = 1; 494 495 /* -a and -l allow an address family arg to limit the output */ 496 if (all || namesonly) { 497 if (argc > 1) 498 usage(); 499 500 ifindex = 0; 501 if (argc == 1) { 502 for (afp = afs; afp->af_name; afp++) 503 if (strcmp(afp->af_name, *argv) == 0) { 504 argc--, argv++; 505 break; 506 } 507 if (afp->af_name == NULL) 508 usage(); 509 /* leave with afp non-zero */ 510 } 511 } else { 512 /* not listing, need an argument */ 513 if (argc < 1) 514 usage(); 515 516 strncpy(name, *argv, sizeof(name)); 517 argc--, argv++; 518 519 /* check and maybe load support for this interface */ 520 ifmaybeload(name); 521 522 /* 523 * NOTE: We must special-case the `create' command right 524 * here as we would otherwise fail when trying to find 525 * the interface. 526 */ 527 if (argc > 0 && (strcmp(argv[0], "create") == 0 || 528 strcmp(argv[0], "plumb") == 0)) { 529 clone_create(); 530 argc--, argv++; 531 if (argc == 0) 532 exit(0); 533 } 534 ifindex = if_nametoindex(name); 535 if (ifindex == 0) 536 errx(1, "interface %s does not exist", name); 537 } 538 539 /* Check for address family */ 540 if (argc > 0) { 541 for (afp = afs; afp->af_name; afp++) 542 if (strcmp(afp->af_name, *argv) == 0) { 543 argc--, argv++; 544 break; 545 } 546 if (afp->af_name == NULL) 547 afp = NULL; /* not a family, NULL */ 548 } 549 550 mib[0] = CTL_NET; 551 mib[1] = PF_ROUTE; 552 mib[2] = 0; 553 mib[3] = 0; /* address family */ 554 mib[4] = NET_RT_IFLIST; 555 mib[5] = ifindex; /* interface index */ 556 557 /* if particular family specified, only ask about it */ 558 if (afp) 559 mib[3] = afp->af_af; 560 561 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) 562 errx(1, "iflist-sysctl-estimate"); 563 if ((buf = malloc(needed)) == NULL) 564 errx(1, "malloc"); 565 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) 566 errx(1, "actual retrieval of interface table"); 567 lim = buf + needed; 568 569 next = buf; 570 while (next < lim) { 571 572 ifm = (struct if_msghdr *)next; 573 574 if (ifm->ifm_type == RTM_IFINFO) { 575 sdl = (struct sockaddr_dl *)(ifm + 1); 576 flags = ifm->ifm_flags; 577 } else { 578 fprintf(stderr, "out of sync parsing NET_RT_IFLIST\n"); 579 fprintf(stderr, "expected %d, got %d\n", RTM_IFINFO, 580 ifm->ifm_type); 581 fprintf(stderr, "msglen = %d\n", ifm->ifm_msglen); 582 fprintf(stderr, "buf:%p, next:%p, lim:%p\n", buf, next, 583 lim); 584 exit (1); 585 } 586 587 next += ifm->ifm_msglen; 588 ifam = NULL; 589 addrcount = 0; 590 while (next < lim) { 591 592 nextifm = (struct if_msghdr *)next; 593 594 if (nextifm->ifm_type != RTM_NEWADDR) 595 break; 596 597 if (ifam == NULL) 598 ifam = (struct ifa_msghdr *)nextifm; 599 600 addrcount++; 601 next += nextifm->ifm_msglen; 602 } 603 strncpy(name, sdl->sdl_data, sdl->sdl_nlen); 604 name[sdl->sdl_nlen] = '\0'; 605 606 if (all || namesonly) { 607 if (uponly) 608 if ((flags & IFF_UP) == 0) 609 continue; /* not up */ 610 if (downonly) 611 if (flags & IFF_UP) 612 continue; /* not down */ 613 if (namesonly) { 614 if (afp == NULL || 615 afp->af_status != link_status || 616 sdl->sdl_type == IFT_ETHER) { 617 if (need_nl) 618 putchar(' '); 619 fputs(name, stdout); 620 need_nl++; 621 } 622 continue; 623 } 624 } 625 626 if (argc > 0) 627 ifconfig(argc, argv, afp); 628 else 629 status(afp, addrcount, sdl, ifm, ifam); 630 } 631 free(buf); 632 633 if (namesonly && need_nl > 0) 634 putchar('\n'); 635 636 exit (0); 637} 638 639int 640ifconfig(int argc, char *const *argv, const struct afswtch *afp) 641{ 642 int s; 643 644 if (afp == NULL) 645 afp = &afs[0]; 646 ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af; 647 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); 648 649 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0) 650 err(1, "socket"); 651 652 while (argc > 0) { 653 const struct cmd *p; 654 655 for (p = cmds; p->c_name; p++) 656 if (strcmp(*argv, p->c_name) == 0) 657 break; 658 if (p->c_name == 0 && setaddr) 659 p++; /* got src, do dst */ 660 if (p->c_func || p->c_func2) { 661 if (p->c_parameter == NEXTARG) { 662 if (argv[1] == NULL) 663 errx(1, "'%s' requires argument", 664 p->c_name); 665 (*p->c_func)(argv[1], 0, s, afp); 666 argc--, argv++; 667 } else if (p->c_parameter == NEXTARG2) { 668 if (argc < 3) 669 errx(1, "'%s' requires 2 arguments", 670 p->c_name); 671 (*p->c_func2)(argv[1], argv[2], s, afp); 672 argc -= 2, argv += 2; 673 } else 674 (*p->c_func)(*argv, p->c_parameter, s, afp); 675 } 676 argc--, argv++; 677 } 678#ifdef INET6 679 if (ifr.ifr_addr.sa_family == AF_INET6 && explicit_prefix == 0) { 680 /* Aggregatable address architecture defines all prefixes 681 are 64. So, it is convenient to set prefixlen to 64 if 682 it is not specified. */ 683 setifprefixlen("64", 0, s, afp); 684 /* in6_getprefix("64", MASK) if MASK is available here... */ 685 } 686#endif 687#ifndef NO_IPX 688 if (setipdst && ifr.ifr_addr.sa_family == AF_IPX) { 689 struct ipxip_req rq; 690 int size = sizeof(rq); 691 692 rq.rq_ipx = addreq.ifra_addr; 693 rq.rq_ip = addreq.ifra_dstaddr; 694 695 if (setsockopt(s, 0, SO_IPXIP_ROUTE, &rq, size) < 0) 696 Perror("Encapsulation Routing"); 697 } 698#endif 699 if (ifr.ifr_addr.sa_family == AF_APPLETALK) 700 checkatrange((struct sockaddr_at *) &addreq.ifra_addr); 701#ifdef NS 702 if (setipdst && ifr.ifr_addr.sa_family == AF_NS) { 703 struct nsip_req rq; 704 int size = sizeof(rq); 705 706 rq.rq_ns = addreq.ifra_addr; 707 rq.rq_ip = addreq.ifra_dstaddr; 708 709 if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0) 710 Perror("Encapsulation Routing"); 711 } 712#endif 713 if (clearaddr) { 714 if (afp->af_ridreq == NULL || afp->af_difaddr == 0) { 715 warnx("interface %s cannot change %s addresses!", 716 name, afp->af_name); 717 clearaddr = NULL; 718 } 719 } 720 if (clearaddr) { 721 int ret; 722 strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name); 723 if ((ret = ioctl(s, afp->af_difaddr, afp->af_ridreq)) < 0) { 724 if (errno == EADDRNOTAVAIL && (doalias >= 0)) { 725 /* means no previous address for interface */ 726 } else 727 Perror("ioctl (SIOCDIFADDR)"); 728 } 729 } 730 if (newaddr) { 731 if (afp->af_addreq == NULL || afp->af_aifaddr == 0) { 732 warnx("interface %s cannot change %s addresses!", 733 name, afp->af_name); 734 newaddr = 0; 735 } 736 } 737 if (newaddr && (setaddr || setmask)) { 738 strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); 739 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) 740 Perror("ioctl (SIOCAIFADDR)"); 741 } 742 close(s); 743 return(0); 744} 745#define RIDADDR 0 746#define ADDR 1 747#define MASK 2 748#define DSTADDR 3 749 750/*ARGSUSED*/ 751void 752setifaddr(const char *addr, int param, int s, const struct afswtch *afp) 753{ 754 if (*afp->af_getaddr == NULL) 755 return; 756 /* 757 * Delay the ioctl to set the interface addr until flags are all set. 758 * The address interpretation may depend on the flags, 759 * and the flags may change when the address is set. 760 */ 761 setaddr++; 762 if (doalias == 0 && afp->af_af != AF_LINK) 763 clearaddr = 1; 764 (*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR)); 765} 766 767void 768settunnel(const char *src, const char *dst, int s, const struct afswtch *afp) 769{ 770 struct addrinfo hints, *srcres, *dstres; 771 struct ifaliasreq addreq; 772 int ecode; 773#ifdef INET6 774 struct in6_aliasreq in6_addreq; 775#endif 776 777 memset(&hints, 0, sizeof(hints)); 778 hints.ai_family = afp->af_af; 779 780 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0) 781 errx(1, "error in parsing address string: %s", 782 gai_strerror(ecode)); 783 784 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) 785 errx(1, "error in parsing address string: %s", 786 gai_strerror(ecode)); 787 788 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family) 789 errx(1, 790 "source and destination address families do not match"); 791 792 switch (srcres->ai_addr->sa_family) { 793 case AF_INET: 794 memset(&addreq, 0, sizeof(addreq)); 795 strncpy(addreq.ifra_name, name, IFNAMSIZ); 796 memcpy(&addreq.ifra_addr, srcres->ai_addr, 797 srcres->ai_addr->sa_len); 798 memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, 799 dstres->ai_addr->sa_len); 800 801 if (ioctl(s, SIOCSIFPHYADDR, &addreq) < 0) 802 warn("SIOCSIFPHYADDR"); 803 break; 804 805#ifdef INET6 806 case AF_INET6: 807 memset(&in6_addreq, 0, sizeof(in6_addreq)); 808 strncpy(in6_addreq.ifra_name, name, IFNAMSIZ); 809 memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, 810 srcres->ai_addr->sa_len); 811 memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, 812 dstres->ai_addr->sa_len); 813 814 if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0) 815 warn("SIOCSIFPHYADDR_IN6"); 816 break; 817#endif /* INET6 */ 818 819 default: 820 warn("address family not supported"); 821 } 822 823 freeaddrinfo(srcres); 824 freeaddrinfo(dstres); 825} 826 827/* ARGSUSED */ 828void 829deletetunnel(const char *vname, int param, int s, const struct afswtch *afp) 830{ 831 832 if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0) 833 err(1, "SIOCDIFPHYADDR"); 834} 835 836void 837setifnetmask(const char *addr, int dummy __unused, int s, 838 const struct afswtch *afp) 839{ 840 if (*afp->af_getaddr == NULL) 841 return; 842 setmask++; 843 (*afp->af_getaddr)(addr, MASK); 844} 845 846#ifdef INET6 847void 848setifprefixlen(const char *addr, int dummy __unused, int s, 849 const struct afswtch *afp) 850{ 851 if (*afp->af_getprefix) 852 (*afp->af_getprefix)(addr, MASK); 853 explicit_prefix = 1; 854} 855 856void 857setip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused, 858 const struct afswtch *afp) 859{ 860 if (afp->af_af != AF_INET6) 861 err(1, "address flags can be set only for inet6 addresses"); 862 863 if (flag < 0) 864 in6_addreq.ifra_flags &= ~(-flag); 865 else 866 in6_addreq.ifra_flags |= flag; 867} 868 869void 870setip6pltime(const char *seconds, int dummy __unused, int s, 871 const struct afswtch *afp) 872{ 873 setip6lifetime("pltime", seconds, s, afp); 874} 875 876void 877setip6vltime(const char *seconds, int dummy __unused, int s, 878 const struct afswtch *afp) 879{ 880 setip6lifetime("vltime", seconds, s, afp); 881} 882 883void 884setip6lifetime(const char *cmd, const char *val, int s, 885 const struct afswtch *afp) 886{ 887 time_t newval, t; 888 char *ep; 889 890 t = time(NULL); 891 newval = (time_t)strtoul(val, &ep, 0); 892 if (val == ep) 893 errx(1, "invalid %s", cmd); 894 if (afp->af_af != AF_INET6) 895 errx(1, "%s not allowed for the AF", cmd); 896 if (strcmp(cmd, "vltime") == 0) { 897 in6_addreq.ifra_lifetime.ia6t_expire = t + newval; 898 in6_addreq.ifra_lifetime.ia6t_vltime = newval; 899 } else if (strcmp(cmd, "pltime") == 0) { 900 in6_addreq.ifra_lifetime.ia6t_preferred = t + newval; 901 in6_addreq.ifra_lifetime.ia6t_pltime = newval; 902 } 903} 904 905void 906setip6eui64(const char *cmd, int dummy __unused, int s, 907 const struct afswtch *afp) 908{ 909 struct ifaddrs *ifap, *ifa; 910 const struct sockaddr_in6 *sin6 = NULL; 911 const struct in6_addr *lladdr = NULL; 912 struct in6_addr *in6; 913 914 if (afp->af_af != AF_INET6) 915 errx(EXIT_FAILURE, "%s not allowed for the AF", cmd); 916 in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr; 917 if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) 918 errx(EXIT_FAILURE, "interface index is already filled"); 919 if (getifaddrs(&ifap) != 0) 920 err(EXIT_FAILURE, "getifaddrs"); 921 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 922 if (ifa->ifa_addr->sa_family == AF_INET6 && 923 strcmp(ifa->ifa_name, name) == 0) { 924 sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr; 925 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 926 lladdr = &sin6->sin6_addr; 927 break; 928 } 929 } 930 } 931 if (!lladdr) 932 errx(EXIT_FAILURE, "could not determine link local address"); 933 934 memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8); 935 936 freeifaddrs(ifap); 937} 938#endif 939 940void 941setifbroadaddr(const char *addr, int dummy __unused, int s, 942 const struct afswtch *afp) 943{ 944 if (*afp->af_getaddr == NULL) 945 return; 946 (*afp->af_getaddr)(addr, DSTADDR); 947} 948 949void 950setifipdst(const char *addr, int dummy __unused, int s, 951 const struct afswtch *afp) 952{ 953 in_getaddr(addr, DSTADDR); 954 setipdst++; 955 clearaddr = 0; 956 newaddr = 0; 957} 958#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr)) 959 960void 961notealias(const char *addr, int param, int s, const struct afswtch *afp) 962{ 963 if (setaddr && doalias == 0 && param < 0) 964 bcopy((caddr_t)rqtosa(af_addreq), 965 (caddr_t)rqtosa(af_ridreq), 966 rqtosa(af_addreq)->sa_len); 967 doalias = param; 968 if (param < 0) { 969 clearaddr = 1; 970 newaddr = 0; 971 } else 972 clearaddr = 0; 973} 974 975/*ARGSUSED*/ 976void 977setifdstaddr(const char *addr, int param __unused, int s, 978 const struct afswtch *afp) 979{ 980 if (*afp->af_getaddr == NULL) 981 return; 982 (*afp->af_getaddr)(addr, DSTADDR); 983} 984 985/* 986 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion 987 * of the ifreq structure, which may confuse other parts of ifconfig. 988 * Make a private copy so we can avoid that. 989 */ 990void 991setifflags(const char *vname, int value, int s, const struct afswtch *afp) 992{ 993 struct ifreq my_ifr; 994 995 bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq)); 996 997 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { 998 Perror("ioctl (SIOCGIFFLAGS)"); 999 exit(1); 1000 } 1001 strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name)); 1002 flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16); 1003 1004 if (value < 0) { 1005 value = -value; 1006 flags &= ~value; 1007 } else 1008 flags |= value; 1009 my_ifr.ifr_flags = flags & 0xffff; 1010 my_ifr.ifr_flagshigh = flags >> 16; 1011 if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0) 1012 Perror(vname); 1013} 1014 1015void 1016setifcap(const char *vname, int value, int s, const struct afswtch *afp) 1017{ 1018 1019 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) { 1020 Perror("ioctl (SIOCGIFCAP)"); 1021 exit(1); 1022 } 1023 flags = ifr.ifr_curcap; 1024 if (value < 0) { 1025 value = -value; 1026 flags &= ~value; 1027 } else 1028 flags |= value; 1029 ifr.ifr_reqcap = flags; 1030 if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0) 1031 Perror(vname); 1032} 1033 1034void 1035setifmetric(const char *val, int dummy __unused, int s, 1036 const struct afswtch *afp) 1037{ 1038 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); 1039 ifr.ifr_metric = atoi(val); 1040 if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) 1041 warn("ioctl (set metric)"); 1042} 1043 1044void 1045setifmtu(const char *val, int dummy __unused, int s, 1046 const struct afswtch *afp) 1047{ 1048 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); 1049 ifr.ifr_mtu = atoi(val); 1050 if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0) 1051 warn("ioctl (set mtu)"); 1052} 1053 1054#define IFFBITS \ 1055"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ 1056"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ 1057"\20MULTICAST" 1058 1059#define IFCAPBITS \ 1060"\003\1rxcsum\2txcsum\3netcons" 1061 1062/* 1063 * Print the status of the interface. If an address family was 1064 * specified, show it and it only; otherwise, show them all. 1065 */ 1066void 1067status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl, 1068 struct if_msghdr *ifm, struct ifa_msghdr *ifam) 1069{ 1070 const struct afswtch *p = NULL; 1071 struct rt_addrinfo info; 1072 int allfamilies, s; 1073 struct ifstat ifs; 1074 1075 if (afp == NULL) { 1076 allfamilies = 1; 1077 afp = &afs[0]; 1078 } else 1079 allfamilies = 0; 1080 1081 ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af; 1082 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1083 1084 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0) 1085 err(1, "socket"); 1086 1087 printf("%s: ", name); 1088 printb("flags", flags, IFFBITS); 1089 if (ifm->ifm_data.ifi_metric) 1090 printf(" metric %ld", ifm->ifm_data.ifi_metric); 1091 if (ifm->ifm_data.ifi_mtu) 1092 printf(" mtu %ld", ifm->ifm_data.ifi_mtu); 1093 putchar('\n'); 1094 1095 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { 1096 if (ifr.ifr_curcap != 0) { 1097 printb("\toptions", ifr.ifr_curcap, IFCAPBITS); 1098 putchar('\n'); 1099 } 1100 if (supmedia && ifr.ifr_reqcap != 0) { 1101 printf("\tcapability list:\n"); 1102 printb("\t\t", ifr.ifr_reqcap, IFCAPBITS); 1103 putchar('\n'); 1104 } 1105 } 1106 1107 tunnel_status(s); 1108 1109 while (addrcount > 0) { 1110 1111 info.rti_addrs = ifam->ifam_addrs; 1112 1113 /* Expand the compacted addresses */ 1114 rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam, 1115 &info); 1116 1117 if (!allfamilies) { 1118 if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family) { 1119 p = afp; 1120 (*p->af_status)(s, &info); 1121 } 1122 } else for (p = afs; p->af_name; p++) { 1123 if (p->af_af == info.rti_info[RTAX_IFA]->sa_family) 1124 (*p->af_status)(s, &info); 1125 } 1126 addrcount--; 1127 ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen); 1128 } 1129 if (allfamilies || afp->af_status == link_status) 1130 link_status(s, (struct rt_addrinfo *)sdl); 1131#ifdef USE_IF_MEDIA 1132 if (allfamilies || afp->af_status == media_status) 1133 media_status(s, NULL); 1134#endif 1135#ifdef USE_VLANS 1136 if (allfamilies || afp->af_status == vlan_status) 1137 vlan_status(s, NULL); 1138#endif 1139#ifdef USE_IEEE80211 1140 if (allfamilies || afp->af_status == ieee80211_status) 1141 ieee80211_status(s, NULL); 1142#endif 1143 strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name); 1144 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) 1145 printf("%s", ifs.ascii); 1146 1147 if (!allfamilies && !p && afp->af_status != media_status && 1148 afp->af_status != link_status 1149#ifdef USE_VLANS 1150 && afp->af_status != vlan_status 1151#endif 1152 ) 1153 warnx("%s has no %s interface address!", name, afp->af_name); 1154 1155 close(s); 1156 return; 1157} 1158 1159void 1160tunnel_status(int s) 1161{ 1162 char psrcaddr[NI_MAXHOST]; 1163 char pdstaddr[NI_MAXHOST]; 1164 u_long srccmd, dstcmd; 1165 struct ifreq *ifrp; 1166 const char *ver = ""; 1167#ifdef NI_WITHSCOPEID 1168 const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID; 1169#else 1170 const int niflag = NI_NUMERICHOST; 1171#endif 1172#ifdef INET6 1173 struct in6_ifreq in6_ifr; 1174 int s6; 1175#endif /* INET6 */ 1176 1177 psrcaddr[0] = pdstaddr[0] = '\0'; 1178 1179#ifdef INET6 1180 memset(&in6_ifr, 0, sizeof(in6_ifr)); 1181 strncpy(in6_ifr.ifr_name, name, IFNAMSIZ); 1182 s6 = socket(AF_INET6, SOCK_DGRAM, 0); 1183 if (s6 < 0) { 1184 srccmd = SIOCGIFPSRCADDR; 1185 dstcmd = SIOCGIFPDSTADDR; 1186 ifrp = 𝔦 1187 } else { 1188 close(s6); 1189 srccmd = SIOCGIFPSRCADDR_IN6; 1190 dstcmd = SIOCGIFPDSTADDR_IN6; 1191 ifrp = (struct ifreq *)&in6_ifr; 1192 } 1193#else /* INET6 */ 1194 srccmd = SIOCGIFPSRCADDR; 1195 dstcmd = SIOCGIFPDSTADDR; 1196 ifrp = 𝔦 1197#endif /* INET6 */ 1198 1199 if (ioctl(s, srccmd, (caddr_t)ifrp) < 0) 1200 return; 1201#ifdef INET6 1202 if (ifrp->ifr_addr.sa_family == AF_INET6) 1203 in6_fillscopeid((struct sockaddr_in6 *)&ifrp->ifr_addr); 1204#endif 1205 getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len, 1206 psrcaddr, sizeof(psrcaddr), 0, 0, niflag); 1207#ifdef INET6 1208 if (ifrp->ifr_addr.sa_family == AF_INET6) 1209 ver = "6"; 1210#endif 1211 1212 if (ioctl(s, dstcmd, (caddr_t)ifrp) < 0) 1213 return; 1214#ifdef INET6 1215 if (ifrp->ifr_addr.sa_family == AF_INET6) 1216 in6_fillscopeid((struct sockaddr_in6 *)&ifrp->ifr_addr); 1217#endif 1218 getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len, 1219 pdstaddr, sizeof(pdstaddr), 0, 0, niflag); 1220 1221 printf("\ttunnel inet%s %s --> %s\n", ver, 1222 psrcaddr, pdstaddr); 1223} 1224 1225void 1226in_status(int s __unused, struct rt_addrinfo * info) 1227{ 1228 struct sockaddr_in *sin, null_sin; 1229 1230 memset(&null_sin, 0, sizeof(null_sin)); 1231 1232 sin = (struct sockaddr_in *)info->rti_info[RTAX_IFA]; 1233 printf("\tinet %s ", inet_ntoa(sin->sin_addr)); 1234 1235 if (flags & IFF_POINTOPOINT) { 1236 /* note RTAX_BRD overlap with IFF_BROADCAST */ 1237 sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD]; 1238 if (!sin) 1239 sin = &null_sin; 1240 printf("--> %s ", inet_ntoa(sin->sin_addr)); 1241 } 1242 1243 sin = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK]; 1244 if (!sin) 1245 sin = &null_sin; 1246 printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr)); 1247 1248 if (flags & IFF_BROADCAST) { 1249 /* note RTAX_BRD overlap with IFF_POINTOPOINT */ 1250 sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD]; 1251 if (sin && sin->sin_addr.s_addr != 0) 1252 printf("broadcast %s", inet_ntoa(sin->sin_addr)); 1253 } 1254 putchar('\n'); 1255} 1256 1257#ifdef INET6 1258void 1259in6_fillscopeid(struct sockaddr_in6 *sin6) 1260{ 1261#if defined(__KAME__) && defined(KAME_SCOPEID) 1262 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 1263 sin6->sin6_scope_id = 1264 ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); 1265 sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0; 1266 } 1267#endif 1268} 1269 1270void 1271in6_status(int s __unused, struct rt_addrinfo * info) 1272{ 1273 struct sockaddr_in6 *sin, null_sin; 1274 struct in6_ifreq ifr6; 1275 int s6; 1276 u_int32_t flags6; 1277 struct in6_addrlifetime lifetime; 1278 time_t t = time(NULL); 1279 int error; 1280 u_int32_t scopeid; 1281 1282 memset(&null_sin, 0, sizeof(null_sin)); 1283 1284 sin = (struct sockaddr_in6 *)info->rti_info[RTAX_IFA]; 1285 strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); 1286 if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 1287 perror("ifconfig: socket"); 1288 return; 1289 } 1290 ifr6.ifr_addr = *sin; 1291 if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) { 1292 perror("ifconfig: ioctl(SIOCGIFAFLAG_IN6)"); 1293 close(s6); 1294 return; 1295 } 1296 flags6 = ifr6.ifr_ifru.ifru_flags6; 1297 memset(&lifetime, 0, sizeof(lifetime)); 1298 ifr6.ifr_addr = *sin; 1299 if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { 1300 perror("ifconfig: ioctl(SIOCGIFALIFETIME_IN6)"); 1301 close(s6); 1302 return; 1303 } 1304 lifetime = ifr6.ifr_ifru.ifru_lifetime; 1305 close(s6); 1306 1307 /* XXX: embedded link local addr check */ 1308 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && 1309 *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { 1310 u_short index; 1311 1312 index = *(u_short *)&sin->sin6_addr.s6_addr[2]; 1313 *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; 1314 if (sin->sin6_scope_id == 0) 1315 sin->sin6_scope_id = ntohs(index); 1316 } 1317 scopeid = sin->sin6_scope_id; 1318 1319 error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf, 1320 sizeof(addr_buf), NULL, 0, 1321 NI_NUMERICHOST|NI_WITHSCOPEID); 1322 if (error != 0) 1323 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 1324 sizeof(addr_buf)); 1325 printf("\tinet6 %s ", addr_buf); 1326 1327 if (flags & IFF_POINTOPOINT) { 1328 /* note RTAX_BRD overlap with IFF_BROADCAST */ 1329 sin = (struct sockaddr_in6 *)info->rti_info[RTAX_BRD]; 1330 /* 1331 * some of the interfaces do not have valid destination 1332 * address. 1333 */ 1334 if (sin && sin->sin6_family == AF_INET6) { 1335 int error; 1336 1337 /* XXX: embedded link local addr check */ 1338 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && 1339 *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { 1340 u_short index; 1341 1342 index = *(u_short *)&sin->sin6_addr.s6_addr[2]; 1343 *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; 1344 if (sin->sin6_scope_id == 0) 1345 sin->sin6_scope_id = ntohs(index); 1346 } 1347 1348 error = getnameinfo((struct sockaddr *)sin, 1349 sin->sin6_len, addr_buf, 1350 sizeof(addr_buf), NULL, 0, 1351 NI_NUMERICHOST|NI_WITHSCOPEID); 1352 if (error != 0) 1353 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 1354 sizeof(addr_buf)); 1355 printf("--> %s ", addr_buf); 1356 } 1357 } 1358 1359 sin = (struct sockaddr_in6 *)info->rti_info[RTAX_NETMASK]; 1360 if (!sin) 1361 sin = &null_sin; 1362 printf("prefixlen %d ", prefix(&sin->sin6_addr, 1363 sizeof(struct in6_addr))); 1364 1365 if ((flags6 & IN6_IFF_ANYCAST) != 0) 1366 printf("anycast "); 1367 if ((flags6 & IN6_IFF_TENTATIVE) != 0) 1368 printf("tentative "); 1369 if ((flags6 & IN6_IFF_DUPLICATED) != 0) 1370 printf("duplicated "); 1371 if ((flags6 & IN6_IFF_DETACHED) != 0) 1372 printf("detached "); 1373 if ((flags6 & IN6_IFF_DEPRECATED) != 0) 1374 printf("deprecated "); 1375 if ((flags6 & IN6_IFF_AUTOCONF) != 0) 1376 printf("autoconf "); 1377 if ((flags6 & IN6_IFF_TEMPORARY) != 0) 1378 printf("temporary "); 1379 1380 if (scopeid) 1381 printf("scopeid 0x%x ", scopeid); 1382 1383 if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 1384 printf("pltime "); 1385 if (lifetime.ia6t_preferred) { 1386 printf("%s ", lifetime.ia6t_preferred < t 1387 ? "0" : sec2str(lifetime.ia6t_preferred - t)); 1388 } else 1389 printf("infty "); 1390 1391 printf("vltime "); 1392 if (lifetime.ia6t_expire) { 1393 printf("%s ", lifetime.ia6t_expire < t 1394 ? "0" : sec2str(lifetime.ia6t_expire - t)); 1395 } else 1396 printf("infty "); 1397 } 1398 1399 putchar('\n'); 1400} 1401#endif /*INET6*/ 1402 1403#ifndef NO_IPX 1404void 1405ipx_status(int s __unused, struct rt_addrinfo * info) 1406{ 1407 struct sockaddr_ipx *sipx, null_sipx; 1408 1409 memset(&null_sipx, 0, sizeof(null_sipx)); 1410 1411 sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_IFA]; 1412 printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr)); 1413 1414 if (flags & IFF_POINTOPOINT) { 1415 sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_BRD]; 1416 if (!sipx) 1417 sipx = &null_sipx; 1418 printf("--> %s ", ipx_ntoa(sipx->sipx_addr)); 1419 } 1420 putchar('\n'); 1421} 1422#endif 1423 1424void 1425at_status(int s __unused, struct rt_addrinfo * info) 1426{ 1427 struct sockaddr_at *sat, null_sat; 1428 struct netrange *nr; 1429 1430 memset(&null_sat, 0, sizeof(null_sat)); 1431 1432 sat = (struct sockaddr_at *)info->rti_info[RTAX_IFA]; 1433 nr = &sat->sat_range.r_netrange; 1434 printf("\tatalk %d.%d range %d-%d phase %d", 1435 ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node, 1436 ntohs(nr->nr_firstnet), ntohs(nr->nr_lastnet), nr->nr_phase); 1437 if (flags & IFF_POINTOPOINT) { 1438 /* note RTAX_BRD overlap with IFF_BROADCAST */ 1439 sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD]; 1440 if (!sat) 1441 sat = &null_sat; 1442 printf("--> %d.%d", 1443 ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node); 1444 } 1445 if (flags & IFF_BROADCAST) { 1446 /* note RTAX_BRD overlap with IFF_POINTOPOINT */ 1447 sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD]; 1448 if (sat) 1449 printf(" broadcast %d.%d", 1450 ntohs(sat->sat_addr.s_net), 1451 sat->sat_addr.s_node); 1452 } 1453 1454 putchar('\n'); 1455} 1456 1457#ifdef NS 1458void 1459xns_status(int s __unused, struct rt_addrinfo * info) 1460{ 1461 struct sockaddr_ns *sns, null_sns; 1462 1463 memset(&null_sns, 0, sizeof(null_sns)); 1464 1465 sns = (struct sockaddr_ns *)info->rti_info[RTAX_IFA]; 1466 printf("\tns %s ", ns_ntoa(sns->sns_addr)); 1467 1468 if (flags & IFF_POINTOPOINT) { 1469 sns = (struct sockaddr_ns *)info->rti_info[RTAX_BRD]; 1470 if (!sns) 1471 sns = &null_sns; 1472 printf("--> %s ", ns_ntoa(sns->sns_addr)); 1473 } 1474 1475 putchar('\n'); 1476 close(s); 1477} 1478#endif 1479 1480 1481void 1482link_status(int s __unused, struct rt_addrinfo *info) 1483{ 1484 int n; 1485 struct sockaddr_dl *sdl = (struct sockaddr_dl *)info; 1486 1487 if ((n = sdl->sdl_alen) > 0) { 1488 if (sdl->sdl_type == IFT_ETHER && 1489 sdl->sdl_alen == ETHER_ADDR_LEN) 1490 printf("\tether %s\n", 1491 ether_ntoa((struct ether_addr *)LLADDR(sdl))); 1492 else 1493 printf("\tlladdr %s\n", link_ntoa(sdl) + n + 1); 1494 } 1495} 1496 1497void 1498Perror(const char *cmd) 1499{ 1500 switch (errno) { 1501 1502 case ENXIO: 1503 errx(1, "%s: no such interface", cmd); 1504 break; 1505 1506 case EPERM: 1507 errx(1, "%s: permission denied", cmd); 1508 break; 1509 1510 default: 1511 err(1, "%s", cmd); 1512 } 1513} 1514 1515#define SIN(x) ((struct sockaddr_in *) &(x)) 1516struct sockaddr_in *sintab[] = { 1517SIN(ridreq.ifr_addr), SIN(addreq.ifra_addr), 1518SIN(addreq.ifra_mask), SIN(addreq.ifra_broadaddr)}; 1519 1520void 1521in_getaddr(const char *s, int which) 1522{ 1523 struct sockaddr_in *sin = sintab[which]; 1524 struct hostent *hp; 1525 struct netent *np; 1526 1527 sin->sin_len = sizeof(*sin); 1528 if (which != MASK) 1529 sin->sin_family = AF_INET; 1530 1531 if (which == ADDR) { 1532 char *p = NULL; 1533 1534 if((p = strrchr(s, '/')) != NULL) { 1535 /* address is `name/masklen' */ 1536 int masklen; 1537 int ret; 1538 struct sockaddr_in *min = sintab[MASK]; 1539 *p = '\0'; 1540 ret = sscanf(p+1, "%u", &masklen); 1541 if(ret != 1 || (masklen < 0 || masklen > 32)) { 1542 *p = '/'; 1543 errx(1, "%s: bad value", s); 1544 } 1545 min->sin_len = sizeof(*min); 1546 min->sin_addr.s_addr = htonl(~((1LL << (32 - masklen)) - 1) & 1547 0xffffffff); 1548 } 1549 } 1550 1551 if (inet_aton(s, &sin->sin_addr)) 1552 return; 1553 if ((hp = gethostbyname(s)) != 0) 1554 bcopy(hp->h_addr, (char *)&sin->sin_addr, 1555 MIN(hp->h_length, sizeof(sin->sin_addr))); 1556 else if ((np = getnetbyname(s)) != 0) 1557 sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY); 1558 else 1559 errx(1, "%s: bad value", s); 1560} 1561 1562#ifdef INET6 1563#define SIN6(x) ((struct sockaddr_in6 *) &(x)) 1564struct sockaddr_in6 *sin6tab[] = { 1565SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), 1566SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr)}; 1567 1568void 1569in6_getaddr(const char *s, int which) 1570{ 1571 struct sockaddr_in6 *sin = sin6tab[which]; 1572 struct addrinfo hints, *res; 1573 int error = -1; 1574 1575 newaddr &= 1; 1576 1577 sin->sin6_len = sizeof(*sin); 1578 if (which != MASK) 1579 sin->sin6_family = AF_INET6; 1580 1581 if (which == ADDR) { 1582 char *p = NULL; 1583 if((p = strrchr(s, '/')) != NULL) { 1584 *p = '\0'; 1585 in6_getprefix(p + 1, MASK); 1586 explicit_prefix = 1; 1587 } 1588 } 1589 1590 if (sin->sin6_family == AF_INET6) { 1591 bzero(&hints, sizeof(struct addrinfo)); 1592 hints.ai_family = AF_INET6; 1593 error = getaddrinfo(s, NULL, &hints, &res); 1594 } 1595 if (error != 0) { 1596 if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1) 1597 errx(1, "%s: bad value", s); 1598 } else 1599 bcopy(res->ai_addr, sin, res->ai_addrlen); 1600} 1601 1602void 1603in6_getprefix(const char *plen, int which) 1604{ 1605 struct sockaddr_in6 *sin = sin6tab[which]; 1606 u_char *cp; 1607 int len = atoi(plen); 1608 1609 if ((len < 0) || (len > 128)) 1610 errx(1, "%s: bad value", plen); 1611 sin->sin6_len = sizeof(*sin); 1612 if (which != MASK) 1613 sin->sin6_family = AF_INET6; 1614 if ((len == 0) || (len == 128)) { 1615 memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr)); 1616 return; 1617 } 1618 memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr)); 1619 for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8) 1620 *cp++ = 0xff; 1621 *cp = 0xff << (8 - len); 1622} 1623#endif 1624 1625/* 1626 * Print a value a la the %b format of the kernel's printf 1627 */ 1628void 1629printb(const char *s, unsigned v, const char *bits) 1630{ 1631 int i, any = 0; 1632 char c; 1633 1634 if (bits && *bits == 8) 1635 printf("%s=%o", s, v); 1636 else 1637 printf("%s=%x", s, v); 1638 bits++; 1639 if (bits) { 1640 putchar('<'); 1641 while ((i = *bits++) != '\0') { 1642 if (v & (1 << (i-1))) { 1643 if (any) 1644 putchar(','); 1645 any = 1; 1646 for (; (c = *bits) > 32; bits++) 1647 putchar(c); 1648 } else 1649 for (; *bits > 32; bits++) 1650 ; 1651 } 1652 putchar('>'); 1653 } 1654} 1655 1656#ifndef NO_IPX 1657#define SIPX(x) ((struct sockaddr_ipx *) &(x)) 1658struct sockaddr_ipx *sipxtab[] = { 1659SIPX(ridreq.ifr_addr), SIPX(addreq.ifra_addr), 1660SIPX(addreq.ifra_mask), SIPX(addreq.ifra_broadaddr)}; 1661 1662void 1663ipx_getaddr(const char *addr, int which) 1664{ 1665 struct sockaddr_ipx *sipx = sipxtab[which]; 1666 1667 sipx->sipx_family = AF_IPX; 1668 sipx->sipx_len = sizeof(*sipx); 1669 sipx->sipx_addr = ipx_addr(addr); 1670 if (which == MASK) 1671 printf("Attempt to set IPX netmask will be ineffectual\n"); 1672} 1673#endif 1674 1675void 1676at_getaddr(const char *addr, int which) 1677{ 1678 struct sockaddr_at *sat = (struct sockaddr_at *) &addreq.ifra_addr; 1679 u_int net, node; 1680 1681 sat->sat_family = AF_APPLETALK; 1682 sat->sat_len = sizeof(*sat); 1683 if (which == MASK) 1684 errx(1, "AppleTalk does not use netmasks"); 1685 if (sscanf(addr, "%u.%u", &net, &node) != 2 1686 || net > 0xffff || node > 0xfe) 1687 errx(1, "%s: illegal address", addr); 1688 sat->sat_addr.s_net = htons(net); 1689 sat->sat_addr.s_node = node; 1690} 1691 1692void 1693link_getaddr(const char *addr, int which) 1694{ 1695 char *temp; 1696 struct sockaddr_dl sdl; 1697 struct sockaddr *sa = &ridreq.ifr_addr; 1698 1699 if (which != ADDR) 1700 errx(1, "can't set link-level netmask or broadcast"); 1701 if ((temp = malloc(strlen(addr) + 1)) == NULL) 1702 errx(1, "malloc failed"); 1703 temp[0] = ':'; 1704 strcpy(temp + 1, addr); 1705 sdl.sdl_len = sizeof(sdl); 1706 link_addr(temp, &sdl); 1707 free(temp); 1708 if (sdl.sdl_alen > sizeof(sa->sa_data)) 1709 errx(1, "malformed link-level address"); 1710 sa->sa_family = AF_LINK; 1711 sa->sa_len = sdl.sdl_alen; 1712 bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen); 1713} 1714 1715/* XXX FIXME -- should use strtoul for better parsing. */ 1716void 1717setatrange(const char *range, int dummy __unused, int s, 1718 const struct afswtch *afp) 1719{ 1720 u_short first = 123, last = 123; 1721 1722 if (sscanf(range, "%hu-%hu", &first, &last) != 2 1723 || first == 0 || first > 0xffff 1724 || last == 0 || last > 0xffff || first > last) 1725 errx(1, "%s: illegal net range: %u-%u", range, first, last); 1726 at_nr.nr_firstnet = htons(first); 1727 at_nr.nr_lastnet = htons(last); 1728} 1729 1730void 1731setatphase(const char *phase, int dummy __unused, int s, 1732 const struct afswtch *afp) 1733{ 1734 if (!strcmp(phase, "1")) 1735 at_nr.nr_phase = 1; 1736 else if (!strcmp(phase, "2")) 1737 at_nr.nr_phase = 2; 1738 else 1739 errx(1, "%s: illegal phase", phase); 1740} 1741 1742void 1743checkatrange(struct sockaddr_at *sat) 1744{ 1745 if (at_nr.nr_phase == 0) 1746 at_nr.nr_phase = 2; /* Default phase 2 */ 1747 if (at_nr.nr_firstnet == 0) 1748 at_nr.nr_firstnet = /* Default range of one */ 1749 at_nr.nr_lastnet = sat->sat_addr.s_net; 1750printf("\tatalk %d.%d range %d-%d phase %d\n", 1751 ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node, 1752 ntohs(at_nr.nr_firstnet), ntohs(at_nr.nr_lastnet), at_nr.nr_phase); 1753 if ((u_short) ntohs(at_nr.nr_firstnet) > 1754 (u_short) ntohs(sat->sat_addr.s_net) 1755 || (u_short) ntohs(at_nr.nr_lastnet) < 1756 (u_short) ntohs(sat->sat_addr.s_net)) 1757 errx(1, "AppleTalk address is not in range"); 1758 sat->sat_range.r_netrange = at_nr; 1759} 1760 1761#ifdef NS 1762#define SNS(x) ((struct sockaddr_ns *) &(x)) 1763struct sockaddr_ns *snstab[] = { 1764SNS(ridreq.ifr_addr), SNS(addreq.ifra_addr), 1765SNS(addreq.ifra_mask), SNS(addreq.ifra_broadaddr)}; 1766 1767void 1768xns_getaddr(const char *addr, int which) 1769{ 1770 struct sockaddr_ns *sns = snstab[which]; 1771 1772 sns->sns_family = AF_NS; 1773 sns->sns_len = sizeof(*sns); 1774 sns->sns_addr = ns_addr(addr); 1775 if (which == MASK) 1776 printf("Attempt to set XNS netmask will be ineffectual\n"); 1777} 1778#endif 1779 1780#ifdef INET6 1781int 1782prefix(void *val, int size) 1783{ 1784 u_char *name = (u_char *)val; 1785 int byte, bit, plen = 0; 1786 1787 for (byte = 0; byte < size; byte++, plen += 8) 1788 if (name[byte] != 0xff) 1789 break; 1790 if (byte == size) 1791 return (plen); 1792 for (bit = 7; bit != 0; bit--, plen++) 1793 if (!(name[byte] & (1 << bit))) 1794 break; 1795 for (; bit != 0; bit--) 1796 if (name[byte] & (1 << bit)) 1797 return(0); 1798 byte++; 1799 for (; byte < size; byte++) 1800 if (name[byte]) 1801 return(0); 1802 return (plen); 1803} 1804 1805static char * 1806sec2str(time_t total) 1807{ 1808 static char result[256]; 1809 int days, hours, mins, secs; 1810 int first = 1; 1811 char *p = result; 1812 1813 if (0) { 1814 days = total / 3600 / 24; 1815 hours = (total / 3600) % 24; 1816 mins = (total / 60) % 60; 1817 secs = total % 60; 1818 1819 if (days) { 1820 first = 0; 1821 p += sprintf(p, "%dd", days); 1822 } 1823 if (!first || hours) { 1824 first = 0; 1825 p += sprintf(p, "%dh", hours); 1826 } 1827 if (!first || mins) { 1828 first = 0; 1829 p += sprintf(p, "%dm", mins); 1830 } 1831 sprintf(p, "%ds", secs); 1832 } else 1833 sprintf(result, "%lu", (unsigned long)total); 1834 1835 return(result); 1836} 1837#endif /*INET6*/ 1838 1839void 1840ifmaybeload(char *name) 1841{ 1842 struct module_stat mstat; 1843 int fileid, modid; 1844 char ifkind[35], *cp, *dp; 1845 1846 /* turn interface and unit into module name */ 1847 strcpy(ifkind, "if_"); 1848 for (cp = name, dp = ifkind + 3; 1849 (*cp != 0) && !isdigit(*cp); cp++, dp++) 1850 *dp = *cp; 1851 *dp = 0; 1852 1853 /* scan files in kernel */ 1854 mstat.version = sizeof(struct module_stat); 1855 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { 1856 /* scan modules in file */ 1857 for (modid = kldfirstmod(fileid); modid > 0; 1858 modid = modfnext(modid)) { 1859 if (modstat(modid, &mstat) < 0) 1860 continue; 1861 /* strip bus name if present */ 1862 if ((cp = strchr(mstat.name, '/')) != NULL) { 1863 cp++; 1864 } else { 1865 cp = mstat.name; 1866 } 1867 /* already loaded? */ 1868 if (!strcmp(ifkind, cp)) 1869 return; 1870 } 1871 } 1872 1873 /* not present, we should try to load it */ 1874 kldload(ifkind); 1875} 1876 1877void 1878list_cloners(void) 1879{ 1880 struct if_clonereq ifcr; 1881 char *cp, *buf; 1882 int idx; 1883 int s; 1884 1885 s = socket(AF_INET, SOCK_DGRAM, 0); 1886 if (s == -1) 1887 err(1, "socket"); 1888 1889 memset(&ifcr, 0, sizeof(ifcr)); 1890 1891 if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0) 1892 err(1, "SIOCIFGCLONERS for count"); 1893 1894 buf = malloc(ifcr.ifcr_total * IFNAMSIZ); 1895 if (buf == NULL) 1896 err(1, "unable to allocate cloner name buffer"); 1897 1898 ifcr.ifcr_count = ifcr.ifcr_total; 1899 ifcr.ifcr_buffer = buf; 1900 1901 if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0) 1902 err(1, "SIOCIFGCLONERS for names"); 1903 1904 /* 1905 * In case some disappeared in the mean time, clamp it down. 1906 */ 1907 if (ifcr.ifcr_count > ifcr.ifcr_total) 1908 ifcr.ifcr_count = ifcr.ifcr_total; 1909 1910 for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) { 1911 if (idx > 0) 1912 putchar(' '); 1913 printf("%s", cp); 1914 } 1915 1916 putchar('\n'); 1917 free(buf); 1918} 1919 1920void 1921clone_create(void) 1922{ 1923 int s; 1924 1925 s = socket(AF_INET, SOCK_DGRAM, 0); 1926 if (s == -1) 1927 err(1, "socket"); 1928 1929 memset(&ifr, 0, sizeof(ifr)); 1930 (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1931 if (ioctl(s, SIOCIFCREATE, &ifr) < 0) 1932 err(1, "SIOCIFCREATE"); 1933 1934 if (strcmp(name, ifr.ifr_name) != 0) { 1935 printf("%s\n", ifr.ifr_name); 1936 strlcpy(name, ifr.ifr_name, sizeof(name)); 1937 } 1938 1939 close(s); 1940} 1941 1942void 1943clone_destroy(const char *val, int d, int s, const struct afswtch *rafp) 1944{ 1945 1946 (void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 1947 if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) 1948 err(1, "SIOCIFDESTROY"); 1949} 1950