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 void list_interfaces_ioctl(struct ifconfig_args *args);
112 static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
113 struct ifaddrs *ifa);
114 static _Noreturn void usage(void);
116 static int getifflags(const char *ifname, int us, bool err_ok);
118 static struct afswtch *af_getbyname(const char *name);
120 void printifnamemaybe(void);
122 static struct option *opts = NULL;
124 struct ifa_order_elt {
128 TAILQ_ENTRY(ifa_order_elt) link;
131 TAILQ_HEAD(ifa_queue, ifa_order_elt);
133 static struct module_map_entry {
139 .kldname = "if_tuntap",
143 .kldname = "if_tuntap",
147 .kldname = "if_tuntap",
155 * This mapping exists because there is a conflicting enc module
156 * in CAM. ifconfig's guessing behavior will attempt to match
157 * the ifname to a module as well as if_${ifname} and clash with
158 * CAM enc. This is an assertion of the correct module to load.
167 opt_register(struct option *p)
179 /* XXX not right but close enough for now */
181 for (p = opts; p != NULL; p = p->next) {
182 strlcat(options, p->opt_usage, sizeof(options));
183 strlcat(options, " ", sizeof(options));
187 "usage: ifconfig [-f type:format] %sinterface address_family\n"
188 " [address [dest_address]] [parameters]\n"
189 " ifconfig interface create\n"
190 " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n"
191 " ifconfig -l [-d] [-u] [address_family]\n"
192 " ifconfig %s[-d] [-m] [-u] [-v]\n",
193 options, options, options);
198 ioctl_ifcreate(int s, struct ifreq *ifr)
200 if (ioctl(s, SIOCIFCREATE2, ifr) < 0) {
203 errx(1, "interface %s already exists", ifr->ifr_name);
205 err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
211 calcorders(struct ifaddrs *ifa, struct ifa_queue *q)
213 struct ifaddrs *prev;
214 struct ifa_order_elt *cur;
215 unsigned int ord, af, ifa_ord;
222 while (ifa != NULL) {
224 strcmp(ifa->ifa_name, prev->ifa_name) != 0) {
225 cur = calloc(1, sizeof(*cur));
230 TAILQ_INSERT_TAIL(q, cur, link);
231 cur->if_order = ifa_ord ++;
237 af = ifa->ifa_addr->sa_family;
239 if (af < nitems(cur->af_orders) &&
240 cur->af_orders[af] == 0)
241 cur->af_orders[af] = ++ord;
251 cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q)
253 struct ifa_order_elt *cur, *e1, *e2;
254 unsigned int af1, af2;
259 ret = strcmp(a->ifa_name, b->ifa_name);
261 TAILQ_FOREACH(cur, q, link) {
265 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0)
267 else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0)
274 return (e1->if_order - e2->if_order);
276 } else if (a->ifa_addr != NULL && b->ifa_addr != NULL) {
277 TAILQ_FOREACH(cur, q, link) {
278 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) {
287 af1 = a->ifa_addr->sa_family;
288 af2 = b->ifa_addr->sa_family;
290 if (af1 < nitems(e1->af_orders) && af2 < nitems(e1->af_orders))
291 return (e1->af_orders[af1] - e1->af_orders[af2]);
297 static void freeformat(void)
310 static void setformat(char *input)
312 char *formatstr, *category, *modifier;
314 formatstr = strdup(input);
315 while ((category = strsep(&formatstr, ",")) != NULL) {
316 modifier = strchr(category, ':');
317 if (modifier == NULL || modifier[1] == '\0') {
318 warnx("Skipping invalid format specification: %s\n",
323 /* Split the string on the separator, then seek past it */
327 if (strcmp(category, "addr") == 0)
328 f_addr = strdup(modifier);
329 else if (strcmp(category, "ether") == 0)
330 f_ether = strdup(modifier);
331 else if (strcmp(category, "inet") == 0)
332 f_inet = strdup(modifier);
333 else if (strcmp(category, "inet6") == 0)
334 f_inet6 = strdup(modifier);
339 static struct ifaddrs *
340 sortifaddrs(struct ifaddrs *list,
341 int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *),
344 struct ifaddrs *right, *temp, *last, *result, *next, *tail;
353 if (!list || !list->ifa_next)
356 while (temp && temp->ifa_next) {
358 right = right->ifa_next;
359 temp = temp->ifa_next->ifa_next;
362 last->ifa_next = NULL;
364 list = sortifaddrs(list, compare, q);
365 right = sortifaddrs(right, compare, q);
367 while (list || right) {
371 list = list->ifa_next;
374 right = right->ifa_next;
375 } else if (compare(list, right, q) <= 0) {
377 list = list->ifa_next;
380 right = right->ifa_next;
386 tail->ifa_next = next;
394 void printifnamemaybe()
397 printf("%s\n", name);
401 list_interfaces(struct ifconfig_args *args)
403 #ifdef WITHOUT_NETLINK
404 list_interfaces_ioctl(args);
406 list_interfaces_nl(args);
411 args_peek(struct ifconfig_args *args)
414 return (args->argv[0]);
419 args_pop(struct ifconfig_args *args)
424 char *arg = args->argv[0];
433 args_parse(struct ifconfig_args *args, int argc, char *argv[])
439 /* Parse leading line options */
440 strlcpy(options, "G:adf:klmnuv", sizeof(options));
441 for (p = opts; p != NULL; p = p->next)
442 strlcat(options, p->opt, sizeof(options));
443 while ((c = getopt(argc, argv, options)) != -1) {
445 case 'a': /* scan all interfaces */
448 case 'd': /* restrict scan to "down" interfaces */
449 args->downonly = true;
457 if (optarg == NULL || args->all == 0)
459 args->nogroup = optarg;
462 args->printkeys = true;
464 case 'l': /* scan interface names only */
467 case 'm': /* show media choices in status */
468 args->supmedia = true;
470 case 'n': /* suppress module loading */
473 case 'u': /* restrict scan to "up" interfaces */
483 args->matchgroup = optarg;
488 for (p = opts; p != NULL; p = p->next)
489 if (p->opt[0] == c) {
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) {
519 const struct afswtch *afp = af_getbyname(*argv);
522 warnx("Address family '%s' unknown.", *argv);
525 if (afp->af_name != NULL)
527 /* leave with afp non-zero */
531 /* not listing, need an argument */
539 /* Sync global variables */
540 printkeys = args->printkeys;
541 verbose = args->verbose;
545 main(int ac, char *av[])
551 f_inet = f_inet6 = f_ether = f_addr = NULL;
553 lifh = ifconfig_open();
555 err(EXIT_FAILURE, "ifconfig_open");
557 envformat = getenv("IFCONFIG_FORMAT");
558 if (envformat != NULL)
559 setformat(envformat);
562 * Ensure we print interface name when expected to,
563 * even if we terminate early due to error.
565 atexit(printifnamemaybe);
567 args_parse(&args, ac, av);
569 if (!args.all && !args.namesonly) {
570 /* not listing, need an argument */
571 args.ifname = args_pop(&args);
573 /* check and maybe load support for this interface */
574 ifmaybeload(&args, args.ifname);
576 char *arg = args_peek(&args);
577 if (if_nametoindex(args.ifname) == 0) {
579 * NOTE: We must special-case the `create' command
580 * right here as we would otherwise fail when trying
581 * to find the interface.
583 if (arg != NULL && (strcmp(arg, "create") == 0 ||
584 strcmp(arg, "plumb") == 0)) {
585 iflen = strlcpy(name, args.ifname, sizeof(name));
586 if (iflen >= sizeof(name))
587 errx(1, "%s: cloning name too long",
589 ifconfig(args.argc, args.argv, 1, NULL);
594 * NOTE: We have to special-case the `-vnet' command
595 * right here as we would otherwise fail when trying
596 * to find the interface as it lives in another vnet.
598 if (arg != NULL && (strcmp(arg, "-vnet") == 0)) {
599 iflen = strlcpy(name, args.ifname, sizeof(name));
600 if (iflen >= sizeof(name))
601 errx(1, "%s: interface name too long",
603 ifconfig(args.argc, args.argv, 0, NULL);
607 errx(1, "interface %s does not exist", args.ifname);
610 * Do not allow use `create` command as hostname if
611 * address family is not specified.
613 if (arg != NULL && (strcmp(arg, "create") == 0 ||
614 strcmp(arg, "plumb") == 0)) {
616 errx(1, "interface %s already exists",
623 /* Check for address family */
625 args.afp = af_getbyname(args_peek(&args));
626 if (args.afp != NULL)
631 * Check for a requested configuration action on a single interface,
632 * which doesn't require building, sorting, and searching the entire
633 * system address list
635 if ((args.argc > 0) && (args.ifname != NULL)) {
636 iflen = strlcpy(name, args.ifname, sizeof(name));
637 if (iflen >= sizeof(name)) {
638 warnx("%s: interface name too long, skipping", args.ifname);
640 flags = getifflags(name, -1, false);
641 if (!(((flags & IFF_CANTCONFIG) != 0) ||
642 (args.downonly && (flags & IFF_UP) != 0) ||
643 (args.uponly && (flags & IFF_UP) == 0)))
644 ifconfig(args.argc, args.argv, 0, args.afp);
649 args.allfamilies = args.afp == NULL;
651 list_interfaces(&args);
655 ifconfig_close(lifh);
660 match_ether(const struct sockaddr_dl *sdl)
662 switch (sdl->sdl_type) {
666 if (sdl->sdl_alen == ETHER_ADDR_LEN)
674 match_afp(const struct afswtch *afp, int sa_family, const struct sockaddr_dl *sdl)
678 /* special case for "ether" address family */
679 if (!strcmp(afp->af_name, "ether")) {
680 if (sdl == NULL && !match_ether(sdl))
684 return (afp->af_af == sa_family);
688 match_if_flags(struct ifconfig_args *args, int if_flags)
690 if ((if_flags & IFF_CANTCONFIG) != 0)
692 if (args->downonly && (if_flags & IFF_UP) != 0)
694 if (args->uponly && (if_flags & IFF_UP) == 0)
699 #ifdef WITHOUT_NETLINK
701 list_interfaces_ioctl(struct ifconfig_args *args)
703 struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q);
704 struct ifaddrs *ifap, *sifap, *ifa;
705 struct ifa_order_elt *cur, *tmp;
710 if (getifaddrs(&ifap) != 0)
711 err(EXIT_FAILURE, "getifaddrs");
715 if (calcorders(ifap, &q) != 0)
716 err(EXIT_FAILURE, "calcorders");
718 sifap = sortifaddrs(ifap, cmpifaddrs, &q);
720 TAILQ_FOREACH_SAFE(cur, &q, link, tmp)
724 for (ifa = sifap; ifa; ifa = ifa->ifa_next) {
725 struct ifreq paifr = {};
726 const struct sockaddr_dl *sdl;
728 strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
729 if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
730 memcpy(&paifr.ifr_addr, ifa->ifa_addr,
731 ifa->ifa_addr->sa_len);
734 if (args->ifname != NULL && strcmp(args->ifname, ifa->ifa_name) != 0)
736 if (ifa->ifa_addr->sa_family == AF_LINK)
737 sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
740 if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
742 iflen = strlcpy(name, ifa->ifa_name, sizeof(name));
743 if (iflen >= sizeof(name)) {
744 warnx("%s: interface name too long, skipping",
750 if (!match_if_flags(args, ifa->ifa_flags))
752 if (!group_member(ifa->ifa_name, args->matchgroup, args->nogroup))
755 * Are we just listing the interfaces?
757 if (args->namesonly) {
760 if (!match_afp(args->afp, ifa->ifa_addr->sa_family, sdl))
772 ifconfig(args->argc, args->argv, 0, args->afp);
774 status(args, sdl, ifa);
783 * Returns true if an interface should be listed because any its groups
784 * matches shell pattern "match" and none of groups matches pattern "nomatch".
785 * If any pattern is NULL, corresponding condition is skipped.
788 group_member(const char *ifname, const char *match, const char *nomatch)
790 static int sock = -1;
792 struct ifgroupreq ifgr;
795 bool matched, nomatched;
798 if (match == NULL && nomatch == NULL)
803 memset(&ifgr, 0, sizeof(ifgr));
804 strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ);
806 /* The socket is opened once. Let _exit() close it. */
808 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
810 errx(1, "%s: socket(AF_LOCAL,SOCK_DGRAM)", __func__);
813 /* Determine amount of memory for the list of groups. */
814 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) {
815 if (errno == EINVAL || errno == ENOTTY)
818 errx(1, "%s: SIOCGIFGROUP", __func__);
821 /* Obtain the list of groups. */
824 (struct ifg_req *)calloc(len / sizeof(*ifg), sizeof(*ifg));
826 if (ifgr.ifgr_groups == NULL)
827 errx(1, "%s: no memory", __func__);
828 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
829 errx(1, "%s: SIOCGIFGROUP", __func__);
831 /* Perform matching. */
834 for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(*ifg); ifg++) {
835 len -= sizeof(struct ifg_req);
837 matched |= !fnmatch(match, ifg->ifgrq_group, 0);
839 nomatched &= fnmatch(nomatch, ifg->ifgrq_group, 0);
841 free(ifgr.ifgr_groups);
843 if (match && !nomatch)
845 if (!match && nomatch)
847 return (matched && nomatched);
850 static struct afswtch *afs = NULL;
853 af_register(struct afswtch *p)
859 static struct afswtch *
860 af_getbyname(const char *name)
864 for (afp = afs; afp != NULL; afp = afp->af_next)
865 if (strcmp(afp->af_name, name) == 0)
871 af_getbyfamily(int af)
875 for (afp = afs; afp != NULL; afp = afp->af_next)
876 if (afp->af_af == af)
882 af_other_status(int s)
885 uint8_t afmask[howmany(AF_MAX, NBBY)];
887 memset(afmask, 0, sizeof(afmask));
888 for (afp = afs; afp != NULL; afp = afp->af_next) {
889 if (afp->af_other_status == NULL)
891 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
893 afp->af_other_status(s);
894 setbit(afmask, afp->af_af);
899 af_all_tunnel_status(int s)
902 uint8_t afmask[howmany(AF_MAX, NBBY)];
904 memset(afmask, 0, sizeof(afmask));
905 for (afp = afs; afp != NULL; afp = afp->af_next) {
906 if (afp->af_status_tunnel == NULL)
908 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
910 afp->af_status_tunnel(s);
911 setbit(afmask, afp->af_af);
915 static struct cmd *cmds = NULL;
918 cmd_register(struct cmd *p)
924 static const struct cmd *
925 cmd_lookup(const char *name, int iscreate)
929 for (p = cmds; p != NULL; p = p->c_next)
930 if (strcmp(name, p->c_name) == 0) {
943 callback_func *cb_func;
945 struct callback *cb_next;
947 static struct callback *callbacks = NULL;
950 callback_register(callback_func *func, void *arg)
954 cb = malloc(sizeof(struct callback));
956 errx(1, "unable to allocate memory for callback");
959 cb->cb_next = callbacks;
963 /* specially-handled commands */
964 static void setifaddr(const char *, int, int, const struct afswtch *);
965 static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr);
967 static void setifdstaddr(const char *, int, int, const struct afswtch *);
968 static const struct cmd setifdstaddr_cmd =
969 DEF_CMD("ifdstaddr", 0, setifdstaddr);
972 ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp)
974 const struct afswtch *afp, *nafp;
979 strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
984 * This is the historical "accident" allowing users to configure IPv4
985 * addresses without the "inet" keyword which while a nice feature has
986 * proven to complicate other things. We cannot remove this but only
987 * make sure we will never have a similar implicit default for IPv6 or
988 * any other address familiy. We need a fallback though for
989 * ifconfig IF up/down etc. to work without INET support as people
990 * never used ifconfig IF link up/down, etc. either.
994 if (afp == NULL && feature_present("inet"))
995 afp = af_getbyname("inet");
999 afp = af_getbyname("link");
1001 warnx("Please specify an address_family.");
1005 ifr.ifr_addr.sa_family =
1006 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
1007 AF_LOCAL : afp->af_af;
1009 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
1010 (uafp != NULL || errno != EAFNOSUPPORT ||
1011 (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
1012 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
1015 p = cmd_lookup(*argv, iscreate);
1016 if (iscreate && p == NULL) {
1018 * Push the clone create callback so the new
1019 * device is created and can be used for any
1020 * remaining arguments.
1024 errx(1, "internal error, no callback");
1025 callbacks = cb->cb_next;
1026 cb->cb_func(s, cb->cb_arg);
1029 * Handle any address family spec that
1030 * immediately follows and potentially
1031 * recreate the socket.
1033 nafp = af_getbyname(*argv);
1043 * Look for a normal parameter.
1049 * Not a recognized command, choose between setting
1050 * the interface address and the dst address.
1052 p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
1054 if (p->c_parameter == NEXTARG && p->c_u.c_func) {
1055 if (argv[1] == NULL)
1056 errx(1, "'%s' requires argument",
1058 p->c_u.c_func(argv[1], 0, s, afp);
1060 } else if (p->c_parameter == OPTARG && p->c_u.c_func) {
1061 p->c_u.c_func(argv[1], 0, s, afp);
1062 if (argv[1] != NULL)
1064 } else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
1066 errx(1, "'%s' requires 2 arguments",
1068 p->c_u.c_func2(argv[1], argv[2], s, afp);
1069 argc -= 2, argv += 2;
1070 } else if (p->c_parameter == SPARAM && p->c_u.c_func3) {
1071 p->c_u.c_func3(*argv, p->c_sparameter, s, afp);
1072 } else if (p->c_u.c_func)
1073 p->c_u.c_func(*argv, p->c_parameter, s, afp);
1078 * Do any post argument processing required by the address family.
1080 if (afp->af_postproc != NULL)
1081 afp->af_postproc(s, afp, newaddr, getifflags(name, s, true));
1083 * Do deferred callbacks registered while processing
1084 * command-line arguments.
1086 for (cb = callbacks; cb != NULL; cb = cb->cb_next)
1087 cb->cb_func(s, cb->cb_arg);
1089 * Do deferred operations.
1092 if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
1093 warnx("interface %s cannot change %s addresses!",
1094 name, afp->af_name);
1100 strlcpy(((struct ifreq *)afp->af_ridreq)->ifr_name, name,
1101 sizeof ifr.ifr_name);
1102 ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
1104 if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
1105 /* means no previous address for interface */
1107 Perror("ioctl (SIOCDIFADDR)");
1111 if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
1112 warnx("interface %s cannot change %s addresses!",
1113 name, afp->af_name);
1117 if (newaddr && (setaddr || setmask)) {
1118 strlcpy(((struct ifreq *)afp->af_addreq)->ifr_name, name,
1119 sizeof ifr.ifr_name);
1120 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
1121 Perror("ioctl (SIOCAIFADDR)");
1130 setifaddr(const char *addr, int param, int s, const struct afswtch *afp)
1132 if (afp->af_getaddr == NULL)
1135 * Delay the ioctl to set the interface addr until flags are all set.
1136 * The address interpretation may depend on the flags,
1137 * and the flags may change when the address is set.
1140 if (doalias == 0 && afp->af_af != AF_LINK)
1142 afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR));
1146 settunnel(const char *src, const char *dst, int s, const struct afswtch *afp)
1148 struct addrinfo *srcres, *dstres;
1151 if (afp->af_settunnel == NULL) {
1152 warn("address family %s does not support tunnel setup",
1157 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
1158 errx(1, "error in parsing address string: %s",
1159 gai_strerror(ecode));
1161 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
1162 errx(1, "error in parsing address string: %s",
1163 gai_strerror(ecode));
1165 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
1167 "source and destination address families do not match");
1169 afp->af_settunnel(s, srcres, dstres);
1171 freeaddrinfo(srcres);
1172 freeaddrinfo(dstres);
1177 deletetunnel(const char *vname, int param, int s, const struct afswtch *afp)
1180 if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0)
1181 err(1, "SIOCDIFPHYADDR");
1186 setifvnet(const char *jname, int dummy __unused, int s,
1187 const struct afswtch *afp)
1189 struct ifreq my_ifr;
1191 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1192 my_ifr.ifr_jid = jail_getid(jname);
1193 if (my_ifr.ifr_jid < 0)
1194 errx(1, "%s", jail_errmsg);
1195 if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0)
1196 err(1, "SIOCSIFVNET");
1200 setifrvnet(const char *jname, int dummy __unused, int s,
1201 const struct afswtch *afp)
1203 struct ifreq my_ifr;
1205 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1206 my_ifr.ifr_jid = jail_getid(jname);
1207 if (my_ifr.ifr_jid < 0)
1208 errx(1, "%s", jail_errmsg);
1209 if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0)
1210 err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name);
1215 setifnetmask(const char *addr, int dummy __unused, int s,
1216 const struct afswtch *afp)
1218 if (afp->af_getaddr != NULL) {
1220 afp->af_getaddr(addr, MASK);
1225 setifbroadaddr(const char *addr, int dummy __unused, int s,
1226 const struct afswtch *afp)
1228 if (afp->af_getaddr != NULL)
1229 afp->af_getaddr(addr, DSTADDR);
1233 notealias(const char *addr, int param, int s, const struct afswtch *afp)
1235 #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
1236 if (setaddr && doalias == 0 && param < 0)
1237 if (afp->af_addreq != NULL && afp->af_ridreq != NULL)
1238 bcopy((caddr_t)rqtosa(af_addreq),
1239 (caddr_t)rqtosa(af_ridreq),
1240 rqtosa(af_addreq)->sa_len);
1252 setifdstaddr(const char *addr, int param __unused, int s,
1253 const struct afswtch *afp)
1255 if (afp->af_getaddr != NULL)
1256 afp->af_getaddr(addr, DSTADDR);
1260 getifflags(const char *ifname, int us, bool err_ok)
1262 struct ifreq my_ifr;
1265 memset(&my_ifr, 0, sizeof(my_ifr));
1266 (void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name));
1268 if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
1269 err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
1272 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
1274 Perror("ioctl (SIOCGIFFLAGS)");
1280 return ((my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16));
1284 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
1285 * of the ifreq structure, which may confuse other parts of ifconfig.
1286 * Make a private copy so we can avoid that.
1289 setifflags(const char *vname, int value, int s, const struct afswtch *afp)
1291 struct ifreq my_ifr;
1294 flags = getifflags(name, s, false);
1300 memset(&my_ifr, 0, sizeof(my_ifr));
1301 (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name));
1302 my_ifr.ifr_flags = flags & 0xffff;
1303 my_ifr.ifr_flagshigh = flags >> 16;
1304 if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
1309 setifcap(const char *vname, int value, int s, const struct afswtch *afp)
1313 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
1314 Perror("ioctl (SIOCGIFCAP)");
1317 flags = ifr.ifr_curcap;
1323 flags &= ifr.ifr_reqcap;
1324 /* Check for no change in capabilities. */
1325 if (ifr.ifr_curcap == flags)
1327 ifr.ifr_reqcap = flags;
1328 if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
1333 setifcapnv(const char *vname, const char *arg, int s, const struct afswtch *afp)
1341 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0)
1342 Perror("ioctl (SIOCGIFCAP)");
1343 if ((ifr.ifr_curcap & IFCAP_NV) == 0) {
1344 warnx("IFCAP_NV not supported");
1345 return; /* Not exit() */
1351 nvcap = nvlist_create(0);
1353 Perror("nvlist_create");
1354 while ((mopt = strsep(&marg, ",")) != NULL) {
1358 if (strcmp(mopt, "rxtls") == 0) {
1359 nvlist_add_bool(nvcap, "rxtls4", !neg);
1360 nvlist_add_bool(nvcap, "rxtls6", !neg);
1362 nvlist_add_bool(nvcap, mopt, !neg);
1365 buf = nvlist_pack(nvcap, &nvbuflen);
1367 errx(1, "nvlist_pack error");
1370 ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen;
1371 ifr.ifr_cap_nv.buffer = buf;
1372 if (ioctl(s, SIOCSIFCAPNV, (caddr_t)&ifr) < 0)
1375 nvlist_destroy(nvcap);
1380 setifmetric(const char *val, int dummy __unused, int s,
1381 const struct afswtch *afp)
1383 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1384 ifr.ifr_metric = atoi(val);
1385 if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
1386 err(1, "ioctl SIOCSIFMETRIC (set metric)");
1390 setifmtu(const char *val, int dummy __unused, int s,
1391 const struct afswtch *afp)
1393 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1394 ifr.ifr_mtu = atoi(val);
1395 if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
1396 err(1, "ioctl SIOCSIFMTU (set mtu)");
1400 setifpcp(const char *val, int arg __unused, int s, const struct afswtch *afp)
1405 ul = strtoul(val, &endp, 0);
1407 errx(1, "invalid value for pcp");
1409 errx(1, "value for pcp out of range");
1410 ifr.ifr_lan_pcp = ul;
1411 if (ioctl(s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1412 err(1, "SIOCSLANPCP");
1416 disableifpcp(const char *val, int arg __unused, int s,
1417 const struct afswtch *afp)
1420 ifr.ifr_lan_pcp = IFNET_PCP_NONE;
1421 if (ioctl(s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1422 err(1, "SIOCSLANPCP");
1426 setifname(const char *val, int dummy __unused, int s,
1427 const struct afswtch *afp)
1431 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1433 newname = strdup(val);
1434 if (newname == NULL)
1435 err(1, "no memory to set ifname");
1436 ifr.ifr_data = newname;
1437 if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
1439 err(1, "ioctl SIOCSIFNAME (set name)");
1442 strlcpy(name, newname, sizeof(name));
1448 setifdescr(const char *val, int dummy __unused, int s,
1449 const struct afswtch *afp)
1453 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1455 ifr.ifr_buffer.length = strlen(val) + 1;
1456 if (ifr.ifr_buffer.length == 1) {
1457 ifr.ifr_buffer.buffer = newdescr = NULL;
1458 ifr.ifr_buffer.length = 0;
1460 newdescr = strdup(val);
1461 ifr.ifr_buffer.buffer = newdescr;
1462 if (newdescr == NULL) {
1463 warn("no memory to set ifdescr");
1468 if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0)
1469 err(1, "ioctl SIOCSIFDESCR (set descr)");
1476 unsetifdescr(const char *val, int value, int s, const struct afswtch *afp)
1479 setifdescr("", 0, s, 0);
1483 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \
1484 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
1485 "\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP\25STICKYARP"
1488 "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \
1489 "\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \
1490 "\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \
1491 "\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT\32HWRXTSTMP\33NOMAP\34TXTLS4\35TXTLS6" \
1492 "\36VXLAN_HWCSUM\37VXLAN_HWTSO\40TXTLS_RTLMT"
1495 print_ifcap_nv(struct ifconfig_args *args, int s)
1503 buf = malloc(IFR_CAP_NV_MAXBUFSIZE);
1506 ifr.ifr_cap_nv.buffer = buf;
1507 ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE;
1508 if (ioctl(s, SIOCGIFCAPNV, (caddr_t)&ifr) != 0)
1509 Perror("ioctl (SIOCGIFCAPNV)");
1510 nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer,
1511 ifr.ifr_cap_nv.length, 0);
1513 Perror("nvlist_unpack");
1514 printf("\toptions");
1516 for (first = true;; first = false) {
1517 nvname = nvlist_next(nvcap, &type, &cookie);
1518 if (nvname == NULL) {
1522 if (type == NV_TYPE_BOOL) {
1523 val = nvlist_get_bool(nvcap, nvname);
1526 first ? ' ' : ',', nvname);
1530 if (args->supmedia) {
1531 printf("\tcapabilities");
1533 for (first = true;; first = false) {
1534 nvname = nvlist_next(nvcap, &type,
1536 if (nvname == NULL) {
1540 if (type == NV_TYPE_BOOL)
1541 printf("%c%s", first ? ' ' :
1545 nvlist_destroy(nvcap);
1548 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1549 Perror("ioctl (SIOCGIFCAP)");
1553 print_ifcap(struct ifconfig_args *args, int s)
1555 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1558 if ((ifr.ifr_curcap & IFCAP_NV) != 0)
1559 print_ifcap_nv(args, s);
1561 printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
1563 if (args->supmedia && ifr.ifr_reqcap != 0) {
1564 printb("\tcapabilities", ifr.ifr_reqcap,
1572 print_ifstatus(int s)
1576 strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
1577 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
1578 printf("%s", ifs.ascii);
1584 if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
1585 printf(" metric %d", ifr.ifr_metric);
1588 #ifdef WITHOUT_NETLINK
1592 if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
1593 printf(" mtu %d", ifr.ifr_mtu);
1597 print_description(int s)
1600 if ((descr = reallocf(descr, descrlen)) != NULL) {
1601 ifr.ifr_buffer.buffer = descr;
1602 ifr.ifr_buffer.length = descrlen;
1603 if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) {
1604 if (ifr.ifr_buffer.buffer == descr) {
1605 if (strlen(descr) > 0)
1606 printf("\tdescription: %s\n",
1608 } else if (ifr.ifr_buffer.length > descrlen) {
1609 descrlen = ifr.ifr_buffer.length;
1614 warn("unable to allocate memory for interface"
1621 * Print the status of the interface. If an address family was
1622 * specified, show only it; otherwise, show them all.
1625 status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
1626 struct ifaddrs *ifa)
1628 struct ifaddrs *ift;
1630 bool allfamilies = args->afp == NULL;
1632 if (args->afp == NULL)
1633 ifr.ifr_addr.sa_family = AF_LOCAL;
1635 ifr.ifr_addr.sa_family =
1636 args->afp->af_af == AF_LINK ? AF_LOCAL : args->afp->af_af;
1637 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1639 s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
1641 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
1643 printf("%s: ", name);
1644 printb("flags", ifa->ifa_flags, IFFBITS);
1649 print_description(s);
1651 print_ifcap(args, s);
1655 for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
1656 if (ift->ifa_addr == NULL)
1658 if (strcmp(ifa->ifa_name, ift->ifa_name) != 0)
1661 const struct afswtch *p;
1662 p = af_getbyfamily(ift->ifa_addr->sa_family);
1663 if (p != NULL && p->af_status != NULL)
1664 p->af_status(s, ift);
1665 } else if (args->afp->af_af == ift->ifa_addr->sa_family)
1666 args->afp->af_status(s, ift);
1669 if (allfamilies || afp->af_af == AF_LINK) {
1670 const struct afswtch *lafp;
1673 * Hack; the link level address is received separately
1674 * from the routing information so any address is not
1675 * handled above. Cobble together an entry and invoke
1676 * the status method specially.
1678 lafp = af_getbyname("lladdr");
1680 info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
1681 lafp->af_status(s, &info);
1687 else if (args->afp->af_other_status != NULL)
1688 args->afp->af_other_status(s);
1691 if (args->verbose > 0)
1692 sfp_status(s, &ifr, args->verbose);
1700 tunnel_status(int s)
1702 af_all_tunnel_status(s);
1706 Perror(const char *cmd)
1711 errx(1, "%s: no such interface", cmd);
1715 errx(1, "%s: permission denied", cmd);
1724 * Print a value a la the %b format of the kernel's printf
1727 printb(const char *s, unsigned v, const char *bits)
1732 if (bits && *bits == 8)
1733 printf("%s=%o", s, v);
1735 printf("%s=%x", s, v);
1739 while ((i = *bits++) != '\0') {
1740 if (v & (1u << (i-1))) {
1744 for (; (c = *bits) > 32; bits++)
1747 for (; *bits > 32; bits++)
1755 print_vhid(const struct ifaddrs *ifa, const char *s)
1757 struct if_data *ifd;
1759 if (ifa->ifa_data == NULL)
1762 ifd = ifa->ifa_data;
1763 if (ifd->ifi_vhid == 0)
1766 printf(" vhid %d", ifd->ifi_vhid);
1770 ifmaybeload(struct ifconfig_args *args, const char *name)
1772 #define MOD_PREFIX_LEN 3 /* "if_" */
1773 struct module_stat mstat;
1774 int i, fileid, modid;
1775 char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
1777 struct module_map_entry *mme;
1780 /* loading suppressed by the user */
1784 /* trim the interface number off the end */
1785 strlcpy(ifname, name, sizeof(ifname));
1786 dp = ifname + strlen(ifname) - 1;
1787 for (; dp > ifname; dp--) {
1794 /* Either derive it from the map or guess otherwise */
1797 for (i = 0; i < nitems(module_map); ++i) {
1798 mme = &module_map[i];
1799 if (strcmp(mme->ifname, ifname) == 0) {
1800 strlcpy(ifkind, mme->kldname, sizeof(ifkind));
1806 /* We didn't have an alias for it... we'll guess. */
1808 /* turn interface and unit into module name */
1809 strlcpy(ifkind, "if_", sizeof(ifkind));
1810 strlcat(ifkind, ifname, sizeof(ifkind));
1813 /* scan files in kernel */
1814 mstat.version = sizeof(struct module_stat);
1815 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
1816 /* scan modules in file */
1817 for (modid = kldfirstmod(fileid); modid > 0;
1818 modid = modfnext(modid)) {
1819 if (modstat(modid, &mstat) < 0)
1821 /* strip bus name if present */
1822 if ((cp = strchr(mstat.name, '/')) != NULL) {
1828 * Is it already loaded? Don't compare with ifname if
1829 * we were specifically told which kld to use. Doing
1830 * so could lead to conflicts not trivially solved.
1832 if ((!found && strcmp(ifname, cp) == 0) ||
1833 strcmp(ifkind, cp) == 0)
1839 * Try to load the module. But ignore failures, because ifconfig can't
1840 * infer the names of all drivers (eg mlx4en(4)).
1842 (void) kldload(ifkind);
1845 static struct cmd basic_cmds[] = {
1846 DEF_CMD("up", IFF_UP, setifflags),
1847 DEF_CMD("down", -IFF_UP, setifflags),
1848 DEF_CMD("arp", -IFF_NOARP, setifflags),
1849 DEF_CMD("-arp", IFF_NOARP, setifflags),
1850 DEF_CMD("debug", IFF_DEBUG, setifflags),
1851 DEF_CMD("-debug", -IFF_DEBUG, setifflags),
1852 DEF_CMD_ARG("description", setifdescr),
1853 DEF_CMD_ARG("descr", setifdescr),
1854 DEF_CMD("-description", 0, unsetifdescr),
1855 DEF_CMD("-descr", 0, unsetifdescr),
1856 DEF_CMD("promisc", IFF_PPROMISC, setifflags),
1857 DEF_CMD("-promisc", -IFF_PPROMISC, setifflags),
1858 DEF_CMD("add", IFF_UP, notealias),
1859 DEF_CMD("alias", IFF_UP, notealias),
1860 DEF_CMD("-alias", -IFF_UP, notealias),
1861 DEF_CMD("delete", -IFF_UP, notealias),
1862 DEF_CMD("remove", -IFF_UP, notealias),
1864 #define EN_SWABIPS 0x1000
1865 DEF_CMD("swabips", EN_SWABIPS, setifflags),
1866 DEF_CMD("-swabips", -EN_SWABIPS, setifflags),
1868 DEF_CMD_ARG("netmask", setifnetmask),
1869 DEF_CMD_ARG("metric", setifmetric),
1870 DEF_CMD_ARG("broadcast", setifbroadaddr),
1871 DEF_CMD_ARG2("tunnel", settunnel),
1872 DEF_CMD("-tunnel", 0, deletetunnel),
1873 DEF_CMD("deletetunnel", 0, deletetunnel),
1875 DEF_CMD_ARG("vnet", setifvnet),
1876 DEF_CMD_ARG("-vnet", setifrvnet),
1878 DEF_CMD("link0", IFF_LINK0, setifflags),
1879 DEF_CMD("-link0", -IFF_LINK0, setifflags),
1880 DEF_CMD("link1", IFF_LINK1, setifflags),
1881 DEF_CMD("-link1", -IFF_LINK1, setifflags),
1882 DEF_CMD("link2", IFF_LINK2, setifflags),
1883 DEF_CMD("-link2", -IFF_LINK2, setifflags),
1884 DEF_CMD("monitor", IFF_MONITOR, setifflags),
1885 DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
1886 DEF_CMD("mextpg", IFCAP_MEXTPG, setifcap),
1887 DEF_CMD("-mextpg", -IFCAP_MEXTPG, setifcap),
1888 DEF_CMD("staticarp", IFF_STATICARP, setifflags),
1889 DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
1890 DEF_CMD("stickyarp", IFF_STICKYARP, setifflags),
1891 DEF_CMD("-stickyarp", -IFF_STICKYARP, setifflags),
1892 DEF_CMD("rxcsum6", IFCAP_RXCSUM_IPV6, setifcap),
1893 DEF_CMD("-rxcsum6", -IFCAP_RXCSUM_IPV6, setifcap),
1894 DEF_CMD("txcsum6", IFCAP_TXCSUM_IPV6, setifcap),
1895 DEF_CMD("-txcsum6", -IFCAP_TXCSUM_IPV6, setifcap),
1896 DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap),
1897 DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap),
1898 DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap),
1899 DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap),
1900 DEF_CMD("netcons", IFCAP_NETCONS, setifcap),
1901 DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap),
1902 DEF_CMD_ARG("pcp", setifpcp),
1903 DEF_CMD("-pcp", 0, disableifpcp),
1904 DEF_CMD("polling", IFCAP_POLLING, setifcap),
1905 DEF_CMD("-polling", -IFCAP_POLLING, setifcap),
1906 DEF_CMD("tso6", IFCAP_TSO6, setifcap),
1907 DEF_CMD("-tso6", -IFCAP_TSO6, setifcap),
1908 DEF_CMD("tso4", IFCAP_TSO4, setifcap),
1909 DEF_CMD("-tso4", -IFCAP_TSO4, setifcap),
1910 DEF_CMD("tso", IFCAP_TSO, setifcap),
1911 DEF_CMD("-tso", -IFCAP_TSO, setifcap),
1912 DEF_CMD("toe", IFCAP_TOE, setifcap),
1913 DEF_CMD("-toe", -IFCAP_TOE, setifcap),
1914 DEF_CMD("lro", IFCAP_LRO, setifcap),
1915 DEF_CMD("-lro", -IFCAP_LRO, setifcap),
1916 DEF_CMD("txtls", IFCAP_TXTLS, setifcap),
1917 DEF_CMD("-txtls", -IFCAP_TXTLS, setifcap),
1918 DEF_CMD_SARG("rxtls", IFCAP2_RXTLS4_NAME "," IFCAP2_RXTLS6_NAME,
1920 DEF_CMD_SARG("-rxtls", "-"IFCAP2_RXTLS4_NAME ",-" IFCAP2_RXTLS6_NAME,
1922 DEF_CMD("wol", IFCAP_WOL, setifcap),
1923 DEF_CMD("-wol", -IFCAP_WOL, setifcap),
1924 DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap),
1925 DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap),
1926 DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap),
1927 DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap),
1928 DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap),
1929 DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap),
1930 DEF_CMD("txrtlmt", IFCAP_TXRTLMT, setifcap),
1931 DEF_CMD("-txrtlmt", -IFCAP_TXRTLMT, setifcap),
1932 DEF_CMD("txtlsrtlmt", IFCAP_TXTLS_RTLMT, setifcap),
1933 DEF_CMD("-txtlsrtlmt", -IFCAP_TXTLS_RTLMT, setifcap),
1934 DEF_CMD("hwrxtstmp", IFCAP_HWRXTSTMP, setifcap),
1935 DEF_CMD("-hwrxtstmp", -IFCAP_HWRXTSTMP, setifcap),
1936 DEF_CMD("normal", -IFF_LINK0, setifflags),
1937 DEF_CMD("compress", IFF_LINK0, setifflags),
1938 DEF_CMD("noicmp", IFF_LINK1, setifflags),
1939 DEF_CMD_ARG("mtu", setifmtu),
1940 DEF_CMD_ARG("name", setifname),
1943 static __constructor void
1948 for (i = 0; i < nitems(basic_cmds); i++)
1949 cmd_register(&basic_cmds[i]);