2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char copyright[] =
34 "@(#) Copyright (c) 1983, 1993\n\
35 The Regents of the University of California. All rights reserved.\n";
37 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
39 static const char rcsid[] =
43 #include <sys/param.h>
44 #include <sys/ioctl.h>
45 #include <sys/module.h>
46 #include <sys/linker.h>
48 #include <sys/queue.h>
49 #include <sys/socket.h>
52 #include <net/ethernet.h>
54 #include <net/if_dl.h>
55 #include <net/if_types.h>
56 #include <net/route.h>
59 #include <netinet/in.h>
60 #include <netinet/in_var.h>
61 #include <arpa/inet.h>
79 #include <libifconfig.h>
83 ifconfig_handle_t *lifh;
86 * Since "struct ifreq" is composed of various union members, callers
87 * should pay special attention to interpret the value.
88 * (.e.g. little/big endian difference in the structure.)
103 struct ifconfig_args args;
105 int printkeys = 0; /* Print keying material for interfaces. */
108 /* Formatter Strings */
109 char *f_inet, *f_inet6, *f_ether, *f_addr;
111 static bool group_member(const char *ifname, const char *match,
112 const char *nomatch);
113 static int ifconfig(int argc, char *const *argv, int iscreate,
114 const struct afswtch *afp);
115 static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
116 struct ifaddrs *ifa);
117 static void tunnel_status(int s);
118 static _Noreturn void usage(void);
120 static int getifflags(const char *ifname, int us, bool err_ok);
122 static struct afswtch *af_getbyname(const char *name);
123 static struct afswtch *af_getbyfamily(int af);
124 static void af_other_status(int);
126 void printifnamemaybe(void);
128 static struct option *opts = NULL;
130 struct ifa_order_elt {
134 TAILQ_ENTRY(ifa_order_elt) link;
137 TAILQ_HEAD(ifa_queue, ifa_order_elt);
139 static struct module_map_entry {
145 .kldname = "if_tuntap",
149 .kldname = "if_tuntap",
153 .kldname = "if_tuntap",
161 * This mapping exists because there is a conflicting enc module
162 * in CAM. ifconfig's guessing behavior will attempt to match
163 * the ifname to a module as well as if_${ifname} and clash with
164 * CAM enc. This is an assertion of the correct module to load.
173 opt_register(struct option *p)
185 /* XXX not right but close enough for now */
187 for (p = opts; p != NULL; p = p->next) {
188 strlcat(options, p->opt_usage, sizeof(options));
189 strlcat(options, " ", sizeof(options));
193 "usage: ifconfig [-f type:format] %sinterface address_family\n"
194 " [address [dest_address]] [parameters]\n"
195 " ifconfig interface create\n"
196 " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n"
197 " ifconfig -l [-d] [-u] [address_family]\n"
198 " ifconfig %s[-d] [-m] [-u] [-v]\n",
199 options, options, options);
204 ioctl_ifcreate(int s, struct ifreq *ifr)
206 if (ioctl(s, SIOCIFCREATE2, ifr) < 0) {
209 errx(1, "interface %s already exists", ifr->ifr_name);
211 err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
217 calcorders(struct ifaddrs *ifa, struct ifa_queue *q)
219 struct ifaddrs *prev;
220 struct ifa_order_elt *cur;
221 unsigned int ord, af, ifa_ord;
228 while (ifa != NULL) {
230 strcmp(ifa->ifa_name, prev->ifa_name) != 0) {
231 cur = calloc(1, sizeof(*cur));
236 TAILQ_INSERT_TAIL(q, cur, link);
237 cur->if_order = ifa_ord ++;
243 af = ifa->ifa_addr->sa_family;
245 if (af < nitems(cur->af_orders) &&
246 cur->af_orders[af] == 0)
247 cur->af_orders[af] = ++ord;
257 cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q)
259 struct ifa_order_elt *cur, *e1, *e2;
260 unsigned int af1, af2;
265 ret = strcmp(a->ifa_name, b->ifa_name);
267 TAILQ_FOREACH(cur, q, link) {
271 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0)
273 else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0)
280 return (e1->if_order - e2->if_order);
282 } else if (a->ifa_addr != NULL && b->ifa_addr != NULL) {
283 TAILQ_FOREACH(cur, q, link) {
284 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) {
293 af1 = a->ifa_addr->sa_family;
294 af2 = b->ifa_addr->sa_family;
296 if (af1 < nitems(e1->af_orders) && af2 < nitems(e1->af_orders))
297 return (e1->af_orders[af1] - e1->af_orders[af2]);
303 static void freeformat(void)
316 static void setformat(char *input)
318 char *formatstr, *category, *modifier;
320 formatstr = strdup(input);
321 while ((category = strsep(&formatstr, ",")) != NULL) {
322 modifier = strchr(category, ':');
323 if (modifier == NULL || modifier[1] == '\0') {
324 warnx("Skipping invalid format specification: %s\n",
329 /* Split the string on the separator, then seek past it */
333 if (strcmp(category, "addr") == 0)
334 f_addr = strdup(modifier);
335 else if (strcmp(category, "ether") == 0)
336 f_ether = strdup(modifier);
337 else if (strcmp(category, "inet") == 0)
338 f_inet = strdup(modifier);
339 else if (strcmp(category, "inet6") == 0)
340 f_inet6 = strdup(modifier);
345 static struct ifaddrs *
346 sortifaddrs(struct ifaddrs *list,
347 int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *),
350 struct ifaddrs *right, *temp, *last, *result, *next, *tail;
359 if (!list || !list->ifa_next)
362 while (temp && temp->ifa_next) {
364 right = right->ifa_next;
365 temp = temp->ifa_next->ifa_next;
368 last->ifa_next = NULL;
370 list = sortifaddrs(list, compare, q);
371 right = sortifaddrs(right, compare, q);
373 while (list || right) {
377 list = list->ifa_next;
380 right = right->ifa_next;
381 } else if (compare(list, right, q) <= 0) {
383 list = list->ifa_next;
386 right = right->ifa_next;
392 tail->ifa_next = next;
400 void printifnamemaybe()
403 printf("%s\n", name);
406 static void list_interfaces(struct ifconfig_args *args);
409 main(int argc, char *argv[])
412 const struct afswtch *afp = NULL;
414 char options[1024], *envformat;
419 f_inet = f_inet6 = f_ether = f_addr = NULL;
421 lifh = ifconfig_open();
423 err(EXIT_FAILURE, "ifconfig_open");
425 envformat = getenv("IFCONFIG_FORMAT");
426 if (envformat != NULL)
427 setformat(envformat);
430 * Ensure we print interface name when expected to,
431 * even if we terminate early due to error.
433 atexit(printifnamemaybe);
435 /* Parse leading line options */
436 strlcpy(options, "G:adf:klmnuv", sizeof(options));
437 for (p = opts; p != NULL; p = p->next)
438 strlcat(options, p->opt, sizeof(options));
439 while ((c = getopt(argc, argv, options)) != -1) {
441 case 'a': /* scan all interfaces */
444 case 'd': /* restrict scan to "down" interfaces */
445 args.downonly = true;
453 if (optarg == NULL || args.all == 0)
455 args.nogroup = optarg;
458 args.printkeys = true;
460 case 'l': /* scan interface names only */
463 case 'm': /* show media choices in status */
464 args.supmedia = true;
466 case 'n': /* suppress module loading */
469 case 'u': /* restrict scan to "up" interfaces */
479 args.matchgroup = optarg;
484 for (p = opts; p != NULL; p = p->next)
485 if (p->opt[0] == c) {
497 /* Sync global variables */
498 printkeys = args.printkeys;
499 verbose = args.verbose;
501 /* -l cannot be used with -a or -m */
502 if (args.namesonly && (args.all || args.supmedia))
506 if (args.uponly && args.downonly)
509 /* no arguments is equivalent to '-a' */
510 if (!args.namesonly && argc < 1)
513 /* -a and -l allow an address family arg to limit the output */
514 if (args.all || args.namesonly) {
520 afp = af_getbyname(*argv);
522 warnx("Address family '%s' unknown.", *argv);
525 if (afp->af_name != NULL)
527 /* leave with afp non-zero */
530 /* not listing, need an argument */
537 /* check and maybe load support for this interface */
538 ifmaybeload(&args, args.ifname);
540 ifindex = if_nametoindex(args.ifname);
543 * NOTE: We must special-case the `create' command
544 * right here as we would otherwise fail when trying
545 * to find the interface.
547 if (argc > 0 && (strcmp(argv[0], "create") == 0 ||
548 strcmp(argv[0], "plumb") == 0)) {
549 iflen = strlcpy(name, args.ifname, sizeof(name));
550 if (iflen >= sizeof(name))
551 errx(1, "%s: cloning name too long",
553 ifconfig(argc, argv, 1, NULL);
558 * NOTE: We have to special-case the `-vnet' command
559 * right here as we would otherwise fail when trying
560 * to find the interface as it lives in another vnet.
562 if (argc > 0 && (strcmp(argv[0], "-vnet") == 0)) {
563 iflen = strlcpy(name, args.ifname, sizeof(name));
564 if (iflen >= sizeof(name))
565 errx(1, "%s: interface name too long",
567 ifconfig(argc, argv, 0, NULL);
571 errx(1, "interface %s does not exist", args.ifname);
574 * Do not allow use `create` command as hostname if
575 * address family is not specified.
577 if (argc > 0 && (strcmp(argv[0], "create") == 0 ||
578 strcmp(argv[0], "plumb") == 0)) {
580 errx(1, "interface %s already exists",
587 /* Check for address family */
589 afp = af_getbyname(*argv);
595 * Check for a requested configuration action on a single interface,
596 * which doesn't require building, sorting, and searching the entire
597 * system address list
599 if ((argc > 0) && (args.ifname != NULL)) {
600 iflen = strlcpy(name, args.ifname, sizeof(name));
601 if (iflen >= sizeof(name)) {
602 warnx("%s: interface name too long, skipping", args.ifname);
604 flags = getifflags(name, -1, false);
605 if (!(((flags & IFF_CANTCONFIG) != 0) ||
606 (args.downonly && (flags & IFF_UP) != 0) ||
607 (args.uponly && (flags & IFF_UP) == 0)))
608 ifconfig(argc, argv, 0, afp);
614 args.allfamilies = afp == NULL;
618 list_interfaces(&args);
622 ifconfig_close(lifh);
627 match_ether(const struct sockaddr_dl *sdl)
629 switch (sdl->sdl_type) {
633 if (sdl->sdl_alen == ETHER_ADDR_LEN)
641 match_afp(const struct afswtch *afp, int sa_family, const struct sockaddr_dl *sdl)
645 /* special case for "ether" address family */
646 if (!strcmp(afp->af_name, "ether")) {
647 if (sdl == NULL && !match_ether(sdl))
651 return (afp->af_af == sa_family);
655 match_if_flags(struct ifconfig_args *args, int if_flags)
657 if ((if_flags & IFF_CANTCONFIG) != 0)
659 if (args->downonly && (if_flags & IFF_UP) != 0)
661 if (args->uponly && (if_flags & IFF_UP) == 0)
667 list_interfaces(struct ifconfig_args *args)
669 struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q);
670 struct ifaddrs *ifap, *sifap, *ifa;
671 struct ifa_order_elt *cur, *tmp;
676 if (getifaddrs(&ifap) != 0)
677 err(EXIT_FAILURE, "getifaddrs");
681 if (calcorders(ifap, &q) != 0)
682 err(EXIT_FAILURE, "calcorders");
684 sifap = sortifaddrs(ifap, cmpifaddrs, &q);
686 TAILQ_FOREACH_SAFE(cur, &q, link, tmp)
690 for (ifa = sifap; ifa; ifa = ifa->ifa_next) {
691 struct ifreq paifr = {};
692 const struct sockaddr_dl *sdl;
694 strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
695 if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
696 memcpy(&paifr.ifr_addr, ifa->ifa_addr,
697 ifa->ifa_addr->sa_len);
700 if (args->ifname != NULL && strcmp(args->ifname, ifa->ifa_name) != 0)
702 if (ifa->ifa_addr->sa_family == AF_LINK)
703 sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
706 if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
708 iflen = strlcpy(name, ifa->ifa_name, sizeof(name));
709 if (iflen >= sizeof(name)) {
710 warnx("%s: interface name too long, skipping",
716 if (!match_if_flags(args, ifa->ifa_flags))
718 if (!group_member(ifa->ifa_name, args->matchgroup, args->nogroup))
721 * Are we just listing the interfaces?
723 if (args->namesonly) {
726 if (!match_afp(args->afp, ifa->ifa_addr->sa_family, sdl))
738 ifconfig(args->argc, args->argv, 0, args->afp);
740 status(args, sdl, ifa);
748 * Returns true if an interface should be listed because any its groups
749 * matches shell pattern "match" and none of groups matches pattern "nomatch".
750 * If any pattern is NULL, corresponding condition is skipped.
753 group_member(const char *ifname, const char *match, const char *nomatch)
755 static int sock = -1;
757 struct ifgroupreq ifgr;
760 bool matched, nomatched;
763 if (match == NULL && nomatch == NULL)
768 memset(&ifgr, 0, sizeof(ifgr));
769 strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ);
771 /* The socket is opened once. Let _exit() close it. */
773 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
775 errx(1, "%s: socket(AF_LOCAL,SOCK_DGRAM)", __func__);
778 /* Determine amount of memory for the list of groups. */
779 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) {
780 if (errno == EINVAL || errno == ENOTTY)
783 errx(1, "%s: SIOCGIFGROUP", __func__);
786 /* Obtain the list of groups. */
789 (struct ifg_req *)calloc(len / sizeof(*ifg), sizeof(*ifg));
791 if (ifgr.ifgr_groups == NULL)
792 errx(1, "%s: no memory", __func__);
793 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
794 errx(1, "%s: SIOCGIFGROUP", __func__);
796 /* Perform matching. */
799 for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(*ifg); ifg++) {
800 len -= sizeof(struct ifg_req);
802 matched |= !fnmatch(match, ifg->ifgrq_group, 0);
804 nomatched &= fnmatch(nomatch, ifg->ifgrq_group, 0);
806 free(ifgr.ifgr_groups);
808 if (match && !nomatch)
810 if (!match && nomatch)
812 return (matched && nomatched);
815 static struct afswtch *afs = NULL;
818 af_register(struct afswtch *p)
824 static struct afswtch *
825 af_getbyname(const char *name)
829 for (afp = afs; afp != NULL; afp = afp->af_next)
830 if (strcmp(afp->af_name, name) == 0)
835 static struct afswtch *
836 af_getbyfamily(int af)
840 for (afp = afs; afp != NULL; afp = afp->af_next)
841 if (afp->af_af == af)
847 af_other_status(int s)
850 uint8_t afmask[howmany(AF_MAX, NBBY)];
852 memset(afmask, 0, sizeof(afmask));
853 for (afp = afs; afp != NULL; afp = afp->af_next) {
854 if (afp->af_other_status == NULL)
856 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
858 afp->af_other_status(s);
859 setbit(afmask, afp->af_af);
864 af_all_tunnel_status(int s)
867 uint8_t afmask[howmany(AF_MAX, NBBY)];
869 memset(afmask, 0, sizeof(afmask));
870 for (afp = afs; afp != NULL; afp = afp->af_next) {
871 if (afp->af_status_tunnel == NULL)
873 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
875 afp->af_status_tunnel(s);
876 setbit(afmask, afp->af_af);
880 static struct cmd *cmds = NULL;
883 cmd_register(struct cmd *p)
889 static const struct cmd *
890 cmd_lookup(const char *name, int iscreate)
894 for (p = cmds; p != NULL; p = p->c_next)
895 if (strcmp(name, p->c_name) == 0) {
908 callback_func *cb_func;
910 struct callback *cb_next;
912 static struct callback *callbacks = NULL;
915 callback_register(callback_func *func, void *arg)
919 cb = malloc(sizeof(struct callback));
921 errx(1, "unable to allocate memory for callback");
924 cb->cb_next = callbacks;
928 /* specially-handled commands */
929 static void setifaddr(const char *, int, int, const struct afswtch *);
930 static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr);
932 static void setifdstaddr(const char *, int, int, const struct afswtch *);
933 static const struct cmd setifdstaddr_cmd =
934 DEF_CMD("ifdstaddr", 0, setifdstaddr);
937 ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp)
939 const struct afswtch *afp, *nafp;
944 strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
949 * This is the historical "accident" allowing users to configure IPv4
950 * addresses without the "inet" keyword which while a nice feature has
951 * proven to complicate other things. We cannot remove this but only
952 * make sure we will never have a similar implicit default for IPv6 or
953 * any other address familiy. We need a fallback though for
954 * ifconfig IF up/down etc. to work without INET support as people
955 * never used ifconfig IF link up/down, etc. either.
959 if (afp == NULL && feature_present("inet"))
960 afp = af_getbyname("inet");
964 afp = af_getbyname("link");
966 warnx("Please specify an address_family.");
970 ifr.ifr_addr.sa_family =
971 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
972 AF_LOCAL : afp->af_af;
974 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
975 (uafp != NULL || errno != EAFNOSUPPORT ||
976 (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
977 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
980 p = cmd_lookup(*argv, iscreate);
981 if (iscreate && p == NULL) {
983 * Push the clone create callback so the new
984 * device is created and can be used for any
985 * remaining arguments.
989 errx(1, "internal error, no callback");
990 callbacks = cb->cb_next;
991 cb->cb_func(s, cb->cb_arg);
994 * Handle any address family spec that
995 * immediately follows and potentially
996 * recreate the socket.
998 nafp = af_getbyname(*argv);
1008 * Look for a normal parameter.
1014 * Not a recognized command, choose between setting
1015 * the interface address and the dst address.
1017 p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
1019 if (p->c_parameter == NEXTARG && p->c_u.c_func) {
1020 if (argv[1] == NULL)
1021 errx(1, "'%s' requires argument",
1023 p->c_u.c_func(argv[1], 0, s, afp);
1025 } else if (p->c_parameter == OPTARG && p->c_u.c_func) {
1026 p->c_u.c_func(argv[1], 0, s, afp);
1027 if (argv[1] != NULL)
1029 } else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
1031 errx(1, "'%s' requires 2 arguments",
1033 p->c_u.c_func2(argv[1], argv[2], s, afp);
1034 argc -= 2, argv += 2;
1035 } else if (p->c_parameter == SPARAM && p->c_u.c_func3) {
1036 p->c_u.c_func3(*argv, p->c_sparameter, s, afp);
1037 } else if (p->c_u.c_func)
1038 p->c_u.c_func(*argv, p->c_parameter, s, afp);
1043 * Do any post argument processing required by the address family.
1045 if (afp->af_postproc != NULL)
1046 afp->af_postproc(s, afp, newaddr, getifflags(name, s, true));
1048 * Do deferred callbacks registered while processing
1049 * command-line arguments.
1051 for (cb = callbacks; cb != NULL; cb = cb->cb_next)
1052 cb->cb_func(s, cb->cb_arg);
1054 * Do deferred operations.
1057 if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
1058 warnx("interface %s cannot change %s addresses!",
1059 name, afp->af_name);
1065 strlcpy(((struct ifreq *)afp->af_ridreq)->ifr_name, name,
1066 sizeof ifr.ifr_name);
1067 ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
1069 if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
1070 /* means no previous address for interface */
1072 Perror("ioctl (SIOCDIFADDR)");
1076 if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
1077 warnx("interface %s cannot change %s addresses!",
1078 name, afp->af_name);
1082 if (newaddr && (setaddr || setmask)) {
1083 strlcpy(((struct ifreq *)afp->af_addreq)->ifr_name, name,
1084 sizeof ifr.ifr_name);
1085 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
1086 Perror("ioctl (SIOCAIFADDR)");
1095 setifaddr(const char *addr, int param, int s, const struct afswtch *afp)
1097 if (afp->af_getaddr == NULL)
1100 * Delay the ioctl to set the interface addr until flags are all set.
1101 * The address interpretation may depend on the flags,
1102 * and the flags may change when the address is set.
1105 if (doalias == 0 && afp->af_af != AF_LINK)
1107 afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR));
1111 settunnel(const char *src, const char *dst, int s, const struct afswtch *afp)
1113 struct addrinfo *srcres, *dstres;
1116 if (afp->af_settunnel == NULL) {
1117 warn("address family %s does not support tunnel setup",
1122 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
1123 errx(1, "error in parsing address string: %s",
1124 gai_strerror(ecode));
1126 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
1127 errx(1, "error in parsing address string: %s",
1128 gai_strerror(ecode));
1130 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
1132 "source and destination address families do not match");
1134 afp->af_settunnel(s, srcres, dstres);
1136 freeaddrinfo(srcres);
1137 freeaddrinfo(dstres);
1142 deletetunnel(const char *vname, int param, int s, const struct afswtch *afp)
1145 if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0)
1146 err(1, "SIOCDIFPHYADDR");
1151 setifvnet(const char *jname, int dummy __unused, int s,
1152 const struct afswtch *afp)
1154 struct ifreq my_ifr;
1156 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1157 my_ifr.ifr_jid = jail_getid(jname);
1158 if (my_ifr.ifr_jid < 0)
1159 errx(1, "%s", jail_errmsg);
1160 if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0)
1161 err(1, "SIOCSIFVNET");
1165 setifrvnet(const char *jname, int dummy __unused, int s,
1166 const struct afswtch *afp)
1168 struct ifreq my_ifr;
1170 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1171 my_ifr.ifr_jid = jail_getid(jname);
1172 if (my_ifr.ifr_jid < 0)
1173 errx(1, "%s", jail_errmsg);
1174 if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0)
1175 err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name);
1180 setifnetmask(const char *addr, int dummy __unused, int s,
1181 const struct afswtch *afp)
1183 if (afp->af_getaddr != NULL) {
1185 afp->af_getaddr(addr, MASK);
1190 setifbroadaddr(const char *addr, int dummy __unused, int s,
1191 const struct afswtch *afp)
1193 if (afp->af_getaddr != NULL)
1194 afp->af_getaddr(addr, DSTADDR);
1198 notealias(const char *addr, int param, int s, const struct afswtch *afp)
1200 #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
1201 if (setaddr && doalias == 0 && param < 0)
1202 if (afp->af_addreq != NULL && afp->af_ridreq != NULL)
1203 bcopy((caddr_t)rqtosa(af_addreq),
1204 (caddr_t)rqtosa(af_ridreq),
1205 rqtosa(af_addreq)->sa_len);
1217 setifdstaddr(const char *addr, int param __unused, int s,
1218 const struct afswtch *afp)
1220 if (afp->af_getaddr != NULL)
1221 afp->af_getaddr(addr, DSTADDR);
1225 getifflags(const char *ifname, int us, bool err_ok)
1227 struct ifreq my_ifr;
1230 memset(&my_ifr, 0, sizeof(my_ifr));
1231 (void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name));
1233 if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
1234 err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
1237 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
1239 Perror("ioctl (SIOCGIFFLAGS)");
1245 return ((my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16));
1249 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
1250 * of the ifreq structure, which may confuse other parts of ifconfig.
1251 * Make a private copy so we can avoid that.
1254 setifflags(const char *vname, int value, int s, const struct afswtch *afp)
1256 struct ifreq my_ifr;
1259 flags = getifflags(name, s, false);
1265 memset(&my_ifr, 0, sizeof(my_ifr));
1266 (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name));
1267 my_ifr.ifr_flags = flags & 0xffff;
1268 my_ifr.ifr_flagshigh = flags >> 16;
1269 if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
1274 setifcap(const char *vname, int value, int s, const struct afswtch *afp)
1278 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
1279 Perror("ioctl (SIOCGIFCAP)");
1282 flags = ifr.ifr_curcap;
1288 flags &= ifr.ifr_reqcap;
1289 /* Check for no change in capabilities. */
1290 if (ifr.ifr_curcap == flags)
1292 ifr.ifr_reqcap = flags;
1293 if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
1298 setifcapnv(const char *vname, const char *arg, int s, const struct afswtch *afp)
1306 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0)
1307 Perror("ioctl (SIOCGIFCAP)");
1308 if ((ifr.ifr_curcap & IFCAP_NV) == 0) {
1309 warnx("IFCAP_NV not supported");
1310 return; /* Not exit() */
1316 nvcap = nvlist_create(0);
1318 Perror("nvlist_create");
1319 while ((mopt = strsep(&marg, ",")) != NULL) {
1323 if (strcmp(mopt, "rxtls") == 0) {
1324 nvlist_add_bool(nvcap, "rxtls4", !neg);
1325 nvlist_add_bool(nvcap, "rxtls6", !neg);
1327 nvlist_add_bool(nvcap, mopt, !neg);
1330 buf = nvlist_pack(nvcap, &nvbuflen);
1332 errx(1, "nvlist_pack error");
1335 ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen;
1336 ifr.ifr_cap_nv.buffer = buf;
1337 if (ioctl(s, SIOCSIFCAPNV, (caddr_t)&ifr) < 0)
1340 nvlist_destroy(nvcap);
1345 setifmetric(const char *val, int dummy __unused, int s,
1346 const struct afswtch *afp)
1348 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1349 ifr.ifr_metric = atoi(val);
1350 if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
1351 err(1, "ioctl SIOCSIFMETRIC (set metric)");
1355 setifmtu(const char *val, int dummy __unused, int s,
1356 const struct afswtch *afp)
1358 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1359 ifr.ifr_mtu = atoi(val);
1360 if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
1361 err(1, "ioctl SIOCSIFMTU (set mtu)");
1365 setifpcp(const char *val, int arg __unused, int s, const struct afswtch *afp)
1370 ul = strtoul(val, &endp, 0);
1372 errx(1, "invalid value for pcp");
1374 errx(1, "value for pcp out of range");
1375 ifr.ifr_lan_pcp = ul;
1376 if (ioctl(s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1377 err(1, "SIOCSLANPCP");
1381 disableifpcp(const char *val, int arg __unused, int s,
1382 const struct afswtch *afp)
1385 ifr.ifr_lan_pcp = IFNET_PCP_NONE;
1386 if (ioctl(s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1387 err(1, "SIOCSLANPCP");
1391 setifname(const char *val, int dummy __unused, int s,
1392 const struct afswtch *afp)
1396 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1398 newname = strdup(val);
1399 if (newname == NULL)
1400 err(1, "no memory to set ifname");
1401 ifr.ifr_data = newname;
1402 if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
1404 err(1, "ioctl SIOCSIFNAME (set name)");
1407 strlcpy(name, newname, sizeof(name));
1413 setifdescr(const char *val, int dummy __unused, int s,
1414 const struct afswtch *afp)
1418 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1420 ifr.ifr_buffer.length = strlen(val) + 1;
1421 if (ifr.ifr_buffer.length == 1) {
1422 ifr.ifr_buffer.buffer = newdescr = NULL;
1423 ifr.ifr_buffer.length = 0;
1425 newdescr = strdup(val);
1426 ifr.ifr_buffer.buffer = newdescr;
1427 if (newdescr == NULL) {
1428 warn("no memory to set ifdescr");
1433 if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0)
1434 err(1, "ioctl SIOCSIFDESCR (set descr)");
1441 unsetifdescr(const char *val, int value, int s, const struct afswtch *afp)
1444 setifdescr("", 0, s, 0);
1448 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \
1449 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
1450 "\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP\25STICKYARP"
1453 "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \
1454 "\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \
1455 "\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \
1456 "\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT\32HWRXTSTMP\33NOMAP\34TXTLS4\35TXTLS6" \
1457 "\36VXLAN_HWCSUM\37VXLAN_HWTSO\40TXTLS_RTLMT"
1460 print_ifcap_nv(struct ifconfig_args *args, int s)
1468 buf = malloc(IFR_CAP_NV_MAXBUFSIZE);
1471 ifr.ifr_cap_nv.buffer = buf;
1472 ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE;
1473 if (ioctl(s, SIOCGIFCAPNV, (caddr_t)&ifr) != 0)
1474 Perror("ioctl (SIOCGIFCAPNV)");
1475 nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer,
1476 ifr.ifr_cap_nv.length, 0);
1478 Perror("nvlist_unpack");
1479 printf("\toptions");
1481 for (first = true;; first = false) {
1482 nvname = nvlist_next(nvcap, &type, &cookie);
1483 if (nvname == NULL) {
1487 if (type == NV_TYPE_BOOL) {
1488 val = nvlist_get_bool(nvcap, nvname);
1491 first ? ' ' : ',', nvname);
1495 if (args->supmedia) {
1496 printf("\tcapabilities");
1498 for (first = true;; first = false) {
1499 nvname = nvlist_next(nvcap, &type,
1501 if (nvname == NULL) {
1505 if (type == NV_TYPE_BOOL)
1506 printf("%c%s", first ? ' ' :
1510 nvlist_destroy(nvcap);
1513 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1514 Perror("ioctl (SIOCGIFCAP)");
1518 print_ifcap(struct ifconfig_args *args, int s)
1520 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1523 if ((ifr.ifr_curcap & IFCAP_NV) != 0)
1524 print_ifcap_nv(args, s);
1526 printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
1528 if (args->supmedia && ifr.ifr_reqcap != 0) {
1529 printb("\tcapabilities", ifr.ifr_reqcap,
1537 print_ifstatus(int s)
1541 strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
1542 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
1543 printf("%s", ifs.ascii);
1549 if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
1550 printf(" metric %d", ifr.ifr_metric);
1556 if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
1557 printf(" mtu %d", ifr.ifr_mtu);
1561 print_description(int s)
1564 if ((descr = reallocf(descr, descrlen)) != NULL) {
1565 ifr.ifr_buffer.buffer = descr;
1566 ifr.ifr_buffer.length = descrlen;
1567 if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) {
1568 if (ifr.ifr_buffer.buffer == descr) {
1569 if (strlen(descr) > 0)
1570 printf("\tdescription: %s\n",
1572 } else if (ifr.ifr_buffer.length > descrlen) {
1573 descrlen = ifr.ifr_buffer.length;
1578 warn("unable to allocate memory for interface"
1585 * Print the status of the interface. If an address family was
1586 * specified, show only it; otherwise, show them all.
1589 status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
1590 struct ifaddrs *ifa)
1592 struct ifaddrs *ift;
1594 bool allfamilies = args->afp == NULL;
1596 if (args->afp == NULL)
1597 ifr.ifr_addr.sa_family = AF_LOCAL;
1599 ifr.ifr_addr.sa_family =
1600 args->afp->af_af == AF_LINK ? AF_LOCAL : args->afp->af_af;
1601 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1603 s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
1605 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
1607 printf("%s: ", name);
1608 printb("flags", ifa->ifa_flags, IFFBITS);
1613 print_description(s);
1615 print_ifcap(args, s);
1619 for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
1620 if (ift->ifa_addr == NULL)
1622 if (strcmp(ifa->ifa_name, ift->ifa_name) != 0)
1625 const struct afswtch *p;
1626 p = af_getbyfamily(ift->ifa_addr->sa_family);
1627 if (p != NULL && p->af_status != NULL)
1628 p->af_status(s, ift);
1629 } else if (args->afp->af_af == ift->ifa_addr->sa_family)
1630 args->afp->af_status(s, ift);
1633 if (allfamilies || afp->af_af == AF_LINK) {
1634 const struct afswtch *lafp;
1637 * Hack; the link level address is received separately
1638 * from the routing information so any address is not
1639 * handled above. Cobble together an entry and invoke
1640 * the status method specially.
1642 lafp = af_getbyname("lladdr");
1644 info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
1645 lafp->af_status(s, &info);
1651 else if (args->afp->af_other_status != NULL)
1652 args->afp->af_other_status(s);
1655 if (args->verbose > 0)
1656 sfp_status(s, &ifr, args->verbose);
1663 tunnel_status(int s)
1665 af_all_tunnel_status(s);
1669 Perror(const char *cmd)
1674 errx(1, "%s: no such interface", cmd);
1678 errx(1, "%s: permission denied", cmd);
1687 * Print a value a la the %b format of the kernel's printf
1690 printb(const char *s, unsigned v, const char *bits)
1695 if (bits && *bits == 8)
1696 printf("%s=%o", s, v);
1698 printf("%s=%x", s, v);
1702 while ((i = *bits++) != '\0') {
1703 if (v & (1u << (i-1))) {
1707 for (; (c = *bits) > 32; bits++)
1710 for (; *bits > 32; bits++)
1718 print_vhid(const struct ifaddrs *ifa, const char *s)
1720 struct if_data *ifd;
1722 if (ifa->ifa_data == NULL)
1725 ifd = ifa->ifa_data;
1726 if (ifd->ifi_vhid == 0)
1729 printf(" vhid %d", ifd->ifi_vhid);
1733 ifmaybeload(struct ifconfig_args *args, const char *name)
1735 #define MOD_PREFIX_LEN 3 /* "if_" */
1736 struct module_stat mstat;
1737 int i, fileid, modid;
1738 char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
1740 struct module_map_entry *mme;
1743 /* loading suppressed by the user */
1747 /* trim the interface number off the end */
1748 strlcpy(ifname, name, sizeof(ifname));
1749 for (dp = ifname; *dp != 0; dp++)
1755 /* Either derive it from the map or guess otherwise */
1758 for (i = 0; i < nitems(module_map); ++i) {
1759 mme = &module_map[i];
1760 if (strcmp(mme->ifname, ifname) == 0) {
1761 strlcpy(ifkind, mme->kldname, sizeof(ifkind));
1767 /* We didn't have an alias for it... we'll guess. */
1769 /* turn interface and unit into module name */
1770 strlcpy(ifkind, "if_", sizeof(ifkind));
1771 strlcat(ifkind, ifname, sizeof(ifkind));
1774 /* scan files in kernel */
1775 mstat.version = sizeof(struct module_stat);
1776 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
1777 /* scan modules in file */
1778 for (modid = kldfirstmod(fileid); modid > 0;
1779 modid = modfnext(modid)) {
1780 if (modstat(modid, &mstat) < 0)
1782 /* strip bus name if present */
1783 if ((cp = strchr(mstat.name, '/')) != NULL) {
1789 * Is it already loaded? Don't compare with ifname if
1790 * we were specifically told which kld to use. Doing
1791 * so could lead to conflicts not trivially solved.
1793 if ((!found && strcmp(ifname, cp) == 0) ||
1794 strcmp(ifkind, cp) == 0)
1800 * Try to load the module. But ignore failures, because ifconfig can't
1801 * infer the names of all drivers (eg mlx4en(4)).
1803 (void) kldload(ifkind);
1806 static struct cmd basic_cmds[] = {
1807 DEF_CMD("up", IFF_UP, setifflags),
1808 DEF_CMD("down", -IFF_UP, setifflags),
1809 DEF_CMD("arp", -IFF_NOARP, setifflags),
1810 DEF_CMD("-arp", IFF_NOARP, setifflags),
1811 DEF_CMD("debug", IFF_DEBUG, setifflags),
1812 DEF_CMD("-debug", -IFF_DEBUG, setifflags),
1813 DEF_CMD_ARG("description", setifdescr),
1814 DEF_CMD_ARG("descr", setifdescr),
1815 DEF_CMD("-description", 0, unsetifdescr),
1816 DEF_CMD("-descr", 0, unsetifdescr),
1817 DEF_CMD("promisc", IFF_PPROMISC, setifflags),
1818 DEF_CMD("-promisc", -IFF_PPROMISC, setifflags),
1819 DEF_CMD("add", IFF_UP, notealias),
1820 DEF_CMD("alias", IFF_UP, notealias),
1821 DEF_CMD("-alias", -IFF_UP, notealias),
1822 DEF_CMD("delete", -IFF_UP, notealias),
1823 DEF_CMD("remove", -IFF_UP, notealias),
1825 #define EN_SWABIPS 0x1000
1826 DEF_CMD("swabips", EN_SWABIPS, setifflags),
1827 DEF_CMD("-swabips", -EN_SWABIPS, setifflags),
1829 DEF_CMD_ARG("netmask", setifnetmask),
1830 DEF_CMD_ARG("metric", setifmetric),
1831 DEF_CMD_ARG("broadcast", setifbroadaddr),
1832 DEF_CMD_ARG2("tunnel", settunnel),
1833 DEF_CMD("-tunnel", 0, deletetunnel),
1834 DEF_CMD("deletetunnel", 0, deletetunnel),
1836 DEF_CMD_ARG("vnet", setifvnet),
1837 DEF_CMD_ARG("-vnet", setifrvnet),
1839 DEF_CMD("link0", IFF_LINK0, setifflags),
1840 DEF_CMD("-link0", -IFF_LINK0, setifflags),
1841 DEF_CMD("link1", IFF_LINK1, setifflags),
1842 DEF_CMD("-link1", -IFF_LINK1, setifflags),
1843 DEF_CMD("link2", IFF_LINK2, setifflags),
1844 DEF_CMD("-link2", -IFF_LINK2, setifflags),
1845 DEF_CMD("monitor", IFF_MONITOR, setifflags),
1846 DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
1847 DEF_CMD("mextpg", IFCAP_MEXTPG, setifcap),
1848 DEF_CMD("-mextpg", -IFCAP_MEXTPG, setifcap),
1849 DEF_CMD("staticarp", IFF_STATICARP, setifflags),
1850 DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
1851 DEF_CMD("stickyarp", IFF_STICKYARP, setifflags),
1852 DEF_CMD("-stickyarp", -IFF_STICKYARP, setifflags),
1853 DEF_CMD("rxcsum6", IFCAP_RXCSUM_IPV6, setifcap),
1854 DEF_CMD("-rxcsum6", -IFCAP_RXCSUM_IPV6, setifcap),
1855 DEF_CMD("txcsum6", IFCAP_TXCSUM_IPV6, setifcap),
1856 DEF_CMD("-txcsum6", -IFCAP_TXCSUM_IPV6, setifcap),
1857 DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap),
1858 DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap),
1859 DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap),
1860 DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap),
1861 DEF_CMD("netcons", IFCAP_NETCONS, setifcap),
1862 DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap),
1863 DEF_CMD_ARG("pcp", setifpcp),
1864 DEF_CMD("-pcp", 0, disableifpcp),
1865 DEF_CMD("polling", IFCAP_POLLING, setifcap),
1866 DEF_CMD("-polling", -IFCAP_POLLING, setifcap),
1867 DEF_CMD("tso6", IFCAP_TSO6, setifcap),
1868 DEF_CMD("-tso6", -IFCAP_TSO6, setifcap),
1869 DEF_CMD("tso4", IFCAP_TSO4, setifcap),
1870 DEF_CMD("-tso4", -IFCAP_TSO4, setifcap),
1871 DEF_CMD("tso", IFCAP_TSO, setifcap),
1872 DEF_CMD("-tso", -IFCAP_TSO, setifcap),
1873 DEF_CMD("toe", IFCAP_TOE, setifcap),
1874 DEF_CMD("-toe", -IFCAP_TOE, setifcap),
1875 DEF_CMD("lro", IFCAP_LRO, setifcap),
1876 DEF_CMD("-lro", -IFCAP_LRO, setifcap),
1877 DEF_CMD("txtls", IFCAP_TXTLS, setifcap),
1878 DEF_CMD("-txtls", -IFCAP_TXTLS, setifcap),
1879 DEF_CMD_SARG("rxtls", IFCAP2_RXTLS4_NAME "," IFCAP2_RXTLS6_NAME,
1881 DEF_CMD_SARG("-rxtls", "-"IFCAP2_RXTLS4_NAME ",-" IFCAP2_RXTLS6_NAME,
1883 DEF_CMD("wol", IFCAP_WOL, setifcap),
1884 DEF_CMD("-wol", -IFCAP_WOL, setifcap),
1885 DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap),
1886 DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap),
1887 DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap),
1888 DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap),
1889 DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap),
1890 DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap),
1891 DEF_CMD("txrtlmt", IFCAP_TXRTLMT, setifcap),
1892 DEF_CMD("-txrtlmt", -IFCAP_TXRTLMT, setifcap),
1893 DEF_CMD("txtlsrtlmt", IFCAP_TXTLS_RTLMT, setifcap),
1894 DEF_CMD("-txtlsrtlmt", -IFCAP_TXTLS_RTLMT, setifcap),
1895 DEF_CMD("hwrxtstmp", IFCAP_HWRXTSTMP, setifcap),
1896 DEF_CMD("-hwrxtstmp", -IFCAP_HWRXTSTMP, setifcap),
1897 DEF_CMD("normal", -IFF_LINK0, setifflags),
1898 DEF_CMD("compress", IFF_LINK0, setifflags),
1899 DEF_CMD("noicmp", IFF_LINK1, setifflags),
1900 DEF_CMD_ARG("mtu", setifmtu),
1901 DEF_CMD_ARG("name", setifname),
1904 static __constructor void
1909 for (i = 0; i < nitems(basic_cmds); i++)
1910 cmd_register(&basic_cmds[i]);