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>
48 #include <sys/module.h>
49 #include <sys/linker.h>
51 #include <sys/queue.h>
52 #include <sys/socket.h>
55 #include <net/ethernet.h>
57 #include <net/if_dl.h>
58 #include <net/if_types.h>
59 #include <net/route.h>
62 #include <netinet/in.h>
63 #include <netinet/in_var.h>
64 #include <arpa/inet.h>
82 #include <libifconfig.h>
86 ifconfig_handle_t *lifh;
89 * Since "struct ifreq" is composed of various union members, callers
90 * should pay special attention to interpret the value.
91 * (.e.g. little/big endian difference in the structure.)
96 #ifdef WITHOUT_NETLINK
97 static char *descr = NULL;
98 static size_t descrlen = 64;
103 static int clearaddr;
106 struct ifconfig_args global_args;
110 static char ifname_to_print[IFNAMSIZ]; /* Helper for printifnamemaybe() */
112 /* Formatter Strings */
113 char *f_inet, *f_inet6, *f_ether, *f_addr;
115 #ifdef WITHOUT_NETLINK
116 static void list_interfaces_ioctl(struct ifconfig_args *args);
117 static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
118 struct ifaddrs *ifa);
120 static _Noreturn void usage(void);
121 static void Perrorc(const char *cmd, int error);
123 static int getifflags(const char *ifname, int us, bool err_ok);
125 static struct afswtch *af_getbyname(const char *name);
127 static struct option *opts = NULL;
129 struct ifa_order_elt {
133 TAILQ_ENTRY(ifa_order_elt) link;
136 TAILQ_HEAD(ifa_queue, ifa_order_elt);
138 static struct module_map_entry {
144 .kldname = "if_tuntap",
148 .kldname = "if_tuntap",
152 .kldname = "if_tuntap",
160 * This mapping exists because there is a conflicting enc module
161 * in CAM. ifconfig's guessing behavior will attempt to match
162 * the ifname to a module as well as if_${ifname} and clash with
163 * CAM enc. This is an assertion of the correct module to load.
172 opt_register(struct option *p)
184 /* XXX not right but close enough for now */
186 for (p = opts; p != NULL; p = p->next) {
187 strlcat(options, p->opt_usage, sizeof(options));
188 strlcat(options, " ", sizeof(options));
192 "usage: ifconfig [-j jail] [-f type:format] %sinterface address_family\n"
193 " [address [dest_address]] [parameters]\n"
194 " ifconfig [-j jail] interface create\n"
195 " ifconfig [-j jail] -a %s[-d] [-m] [-u] [-v] [address_family]\n"
196 " ifconfig [-j jail] -l [-d] [-u] [address_family]\n"
197 " ifconfig [-j jail] %s[-d] [-m] [-u] [-v]\n",
198 options, options, options);
203 ifname_update(if_ctx *ctx, const char *name)
205 strlcpy(ctx->_ifname_storage_ioctl, name, sizeof(ctx->_ifname_storage_ioctl));
206 ctx->ifname = ctx->_ifname_storage_ioctl;
208 strlcpy(ifname_to_print, name, sizeof(ifname_to_print));
212 ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr)
214 char ifname_orig[IFNAMSIZ];
216 strlcpy(ifname_orig, ifr->ifr_name, sizeof(ifname_orig));
218 if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) {
221 errx(1, "interface %s already exists", ifr->ifr_name);
223 err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
227 if (strncmp(ifname_orig, ifr->ifr_name, sizeof(ifname_orig)) != 0)
228 ifname_update(ctx, ifr->ifr_name);
231 #ifdef WITHOUT_NETLINK
233 calcorders(struct ifaddrs *ifa, struct ifa_queue *q)
235 struct ifaddrs *prev;
236 struct ifa_order_elt *cur;
237 unsigned int ord, af, ifa_ord;
244 while (ifa != NULL) {
246 strcmp(ifa->ifa_name, prev->ifa_name) != 0) {
247 cur = calloc(1, sizeof(*cur));
252 TAILQ_INSERT_TAIL(q, cur, link);
253 cur->if_order = ifa_ord ++;
259 af = ifa->ifa_addr->sa_family;
261 if (af < nitems(cur->af_orders) &&
262 cur->af_orders[af] == 0)
263 cur->af_orders[af] = ++ord;
273 cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q)
275 struct ifa_order_elt *cur, *e1, *e2;
276 unsigned int af1, af2;
281 ret = strcmp(a->ifa_name, b->ifa_name);
283 TAILQ_FOREACH(cur, q, link) {
287 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0)
289 else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0)
296 return (e1->if_order - e2->if_order);
298 } else if (a->ifa_addr != NULL && b->ifa_addr != NULL) {
299 TAILQ_FOREACH(cur, q, link) {
300 if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) {
309 af1 = a->ifa_addr->sa_family;
310 af2 = b->ifa_addr->sa_family;
312 if (af1 < nitems(e1->af_orders) && af2 < nitems(e1->af_orders))
313 return (e1->af_orders[af1] - e1->af_orders[af2]);
320 static void freeformat(void)
333 static void setformat(char *input)
335 char *formatstr, *category, *modifier;
337 formatstr = strdup(input);
338 while ((category = strsep(&formatstr, ",")) != NULL) {
339 modifier = strchr(category, ':');
340 if (modifier == NULL || modifier[1] == '\0') {
341 warnx("Skipping invalid format specification: %s\n",
346 /* Split the string on the separator, then seek past it */
350 if (strcmp(category, "addr") == 0)
351 f_addr = strdup(modifier);
352 else if (strcmp(category, "ether") == 0)
353 f_ether = strdup(modifier);
354 else if (strcmp(category, "inet") == 0)
355 f_inet = strdup(modifier);
356 else if (strcmp(category, "inet6") == 0)
357 f_inet6 = strdup(modifier);
362 #ifdef WITHOUT_NETLINK
363 static struct ifaddrs *
364 sortifaddrs(struct ifaddrs *list,
365 int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *),
368 struct ifaddrs *right, *temp, *last, *result, *next, *tail;
377 if (!list || !list->ifa_next)
380 while (temp && temp->ifa_next) {
382 right = right->ifa_next;
383 temp = temp->ifa_next->ifa_next;
386 last->ifa_next = NULL;
388 list = sortifaddrs(list, compare, q);
389 right = sortifaddrs(right, compare, q);
391 while (list || right) {
395 list = list->ifa_next;
398 right = right->ifa_next;
399 } else if (compare(list, right, q) <= 0) {
401 list = list->ifa_next;
404 right = right->ifa_next;
410 tail->ifa_next = next;
420 printifnamemaybe(void)
422 if (ifname_to_print[0] != '\0')
423 printf("%s\n", ifname_to_print);
427 list_interfaces(struct ifconfig_args *args)
429 #ifdef WITHOUT_NETLINK
430 list_interfaces_ioctl(args);
432 list_interfaces_nl(args);
437 args_peek(struct ifconfig_args *args)
440 return (args->argv[0]);
445 args_pop(struct ifconfig_args *args)
450 char *arg = args->argv[0];
459 args_parse(struct ifconfig_args *args, int argc, char *argv[])
465 /* Parse leading line options */
466 strlcpy(options, "G:adf:j:klmnuv", sizeof(options));
467 for (p = opts; p != NULL; p = p->next)
468 strlcat(options, p->opt, sizeof(options));
469 while ((c = getopt(argc, argv, options)) != -1) {
471 case 'a': /* scan all interfaces */
474 case 'd': /* restrict scan to "down" interfaces */
475 args->downonly = true;
483 if (optarg == NULL || args->all == 0)
485 args->nogroup = optarg;
491 args->jail_name = optarg;
493 Perror("not built with jail support");
497 args->printkeys = true;
499 case 'l': /* scan interface names only */
502 case 'm': /* show media choices in status */
503 args->supmedia = true;
505 case 'n': /* suppress module loading */
508 case 'u': /* restrict scan to "up" interfaces */
518 args->matchgroup = optarg;
523 for (p = opts; p != NULL; p = p->next)
524 if (p->opt[0] == c) {
536 /* -l cannot be used with -a or -m */
537 if (args->namesonly && (args->all || args->supmedia))
541 if (args->uponly && args->downonly)
544 /* no arguments is equivalent to '-a' */
545 if (!args->namesonly && argc < 1)
548 /* -a and -l allow an address family arg to limit the output */
549 if (args->all || args->namesonly) {
554 const struct afswtch *afp = af_getbyname(*argv);
557 warnx("Address family '%s' unknown.", *argv);
560 if (afp->af_name != NULL)
562 /* leave with afp non-zero */
566 /* not listing, need an argument */
576 ifconfig_wrapper(struct ifconfig_args *args, int iscreate,
577 const struct afswtch *uafp)
579 #ifdef WITHOUT_NETLINK
580 struct ifconfig_context ctx = {
585 return (ifconfig(&ctx, iscreate, uafp));
587 return (ifconfig_wrapper_nl(args, iscreate, uafp));
592 isargcreate(const char *arg)
597 if (strcmp(arg, "create") == 0 || strcmp(arg, "plumb") == 0)
604 main(int ac, char *av[])
612 struct ifconfig_args *args = &global_args;
614 f_inet = f_inet6 = f_ether = f_addr = NULL;
616 lifh = ifconfig_open();
618 err(EXIT_FAILURE, "ifconfig_open");
620 envformat = getenv("IFCONFIG_FORMAT");
621 if (envformat != NULL)
622 setformat(envformat);
625 * Ensure we print interface name when expected to,
626 * even if we terminate early due to error.
628 atexit(printifnamemaybe);
630 args_parse(args, ac, av);
633 if (args->jail_name) {
634 jid = jail_getid(args->jail_name);
636 Perror("jail not found");
637 if (jail_attach(jid) != 0)
638 Perror("cannot attach to jail");
642 if (!args->all && !args->namesonly) {
643 /* not listing, need an argument */
644 args->ifname = args_pop(args);
646 /* check and maybe load support for this interface */
647 ifmaybeload(args, args->ifname);
649 char *arg = args_peek(args);
650 if (if_nametoindex(args->ifname) == 0) {
652 * NOTE: We must special-case the `create' command
653 * right here as we would otherwise fail when trying
654 * to find the interface.
656 if (isargcreate(arg)) {
657 iflen = strlcpy(name, args->ifname, sizeof(name));
658 if (iflen >= sizeof(name))
659 errx(1, "%s: cloning name too long",
661 ifconfig_wrapper(args, 1, NULL);
666 * NOTE: We have to special-case the `-vnet' command
667 * right here as we would otherwise fail when trying
668 * to find the interface as it lives in another vnet.
670 if (arg != NULL && (strcmp(arg, "-vnet") == 0)) {
671 iflen = strlcpy(name, args->ifname, sizeof(name));
672 if (iflen >= sizeof(name))
673 errx(1, "%s: interface name too long",
675 ifconfig_wrapper(args, 0, NULL);
679 errx(1, "interface %s does not exist", args->ifname);
682 * Do not allow use `create` command as hostname if
683 * address family is not specified.
685 if (isargcreate(arg)) {
687 errx(1, "interface %s already exists",
694 /* Check for address family */
695 if (args->argc > 0) {
696 args->afp = af_getbyname(args_peek(args));
697 if (args->afp != NULL)
702 * Check for a requested configuration action on a single interface,
703 * which doesn't require building, sorting, and searching the entire
704 * system address list
706 if ((args->argc > 0) && (args->ifname != NULL)) {
707 iflen = strlcpy(name, args->ifname, sizeof(name));
708 if (iflen >= sizeof(name)) {
709 warnx("%s: interface name too long, skipping", args->ifname);
711 flags = getifflags(name, -1, false);
712 if (!(((flags & IFF_CANTCONFIG) != 0) ||
713 (args->downonly && (flags & IFF_UP) != 0) ||
714 (args->uponly && (flags & IFF_UP) == 0)))
715 ifconfig_wrapper(args, 0, args->afp);
720 args->allfamilies = args->afp == NULL;
722 list_interfaces(args);
726 ifconfig_close(lifh);
731 match_ether(const struct sockaddr_dl *sdl)
733 switch (sdl->sdl_type) {
737 if (sdl->sdl_alen == ETHER_ADDR_LEN)
745 match_if_flags(struct ifconfig_args *args, int if_flags)
747 if ((if_flags & IFF_CANTCONFIG) != 0)
749 if (args->downonly && (if_flags & IFF_UP) != 0)
751 if (args->uponly && (if_flags & IFF_UP) == 0)
756 #ifdef WITHOUT_NETLINK
758 match_afp(const struct afswtch *afp, int sa_family, const struct sockaddr_dl *sdl)
762 /* special case for "ether" address family */
763 if (!strcmp(afp->af_name, "ether")) {
764 if (sdl == NULL && !match_ether(sdl))
768 return (afp->af_af == sa_family);
772 list_interfaces_ioctl(struct ifconfig_args *args)
774 struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q);
775 struct ifaddrs *ifap, *sifap, *ifa;
776 struct ifa_order_elt *cur, *tmp;
781 if (getifaddrs(&ifap) != 0)
782 err(EXIT_FAILURE, "getifaddrs");
786 if (calcorders(ifap, &q) != 0)
787 err(EXIT_FAILURE, "calcorders");
789 sifap = sortifaddrs(ifap, cmpifaddrs, &q);
791 TAILQ_FOREACH_SAFE(cur, &q, link, tmp)
795 for (ifa = sifap; ifa; ifa = ifa->ifa_next) {
796 struct ifreq paifr = {};
797 const struct sockaddr_dl *sdl;
799 strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
800 if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
801 memcpy(&paifr.ifr_addr, ifa->ifa_addr,
802 ifa->ifa_addr->sa_len);
805 if (args->ifname != NULL && strcmp(args->ifname, ifa->ifa_name) != 0)
807 if (ifa->ifa_addr->sa_family == AF_LINK)
808 sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
811 if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
813 iflen = strlcpy(name, ifa->ifa_name, sizeof(name));
814 if (iflen >= sizeof(name)) {
815 warnx("%s: interface name too long, skipping",
821 if (!match_if_flags(args, ifa->ifa_flags))
823 if (!group_member(ifa->ifa_name, args->matchgroup, args->nogroup))
826 * Are we just listing the interfaces?
828 if (args->namesonly) {
831 if (!match_afp(args->afp, ifa->ifa_addr->sa_family, sdl))
843 ifconfig_wrapper(args, 0, args->afp);
845 status(args, sdl, ifa);
854 * Returns true if an interface should be listed because any its groups
855 * matches shell pattern "match" and none of groups matches pattern "nomatch".
856 * If any pattern is NULL, corresponding condition is skipped.
859 group_member(const char *ifname, const char *match, const char *nomatch)
861 static int sock = -1;
863 struct ifgroupreq ifgr;
866 bool matched, nomatched;
869 if (match == NULL && nomatch == NULL)
874 memset(&ifgr, 0, sizeof(ifgr));
875 strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ);
877 /* The socket is opened once. Let _exit() close it. */
879 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
881 errx(1, "%s: socket(AF_LOCAL,SOCK_DGRAM)", __func__);
884 /* Determine amount of memory for the list of groups. */
885 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) {
886 if (errno == EINVAL || errno == ENOTTY)
889 errx(1, "%s: SIOCGIFGROUP", __func__);
892 /* Obtain the list of groups. */
895 (struct ifg_req *)calloc(len / sizeof(*ifg), sizeof(*ifg));
897 if (ifgr.ifgr_groups == NULL)
898 errx(1, "%s: no memory", __func__);
899 if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
900 errx(1, "%s: SIOCGIFGROUP", __func__);
902 /* Perform matching. */
905 for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(*ifg); ifg++) {
906 len -= sizeof(struct ifg_req);
908 matched |= !fnmatch(match, ifg->ifgrq_group, 0);
910 nomatched &= fnmatch(nomatch, ifg->ifgrq_group, 0);
912 free(ifgr.ifgr_groups);
914 if (match && !nomatch)
916 if (!match && nomatch)
918 return (matched && nomatched);
921 static struct afswtch *afs = NULL;
924 af_register(struct afswtch *p)
930 static struct afswtch *
931 af_getbyname(const char *name)
935 for (afp = afs; afp != NULL; afp = afp->af_next)
936 if (strcmp(afp->af_name, name) == 0)
942 af_getbyfamily(int af)
946 for (afp = afs; afp != NULL; afp = afp->af_next)
947 if (afp->af_af == af)
953 af_other_status(if_ctx *ctx)
956 uint8_t afmask[howmany(AF_MAX, NBBY)];
958 memset(afmask, 0, sizeof(afmask));
959 for (afp = afs; afp != NULL; afp = afp->af_next) {
960 if (afp->af_other_status == NULL)
962 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
964 afp->af_other_status(ctx);
965 setbit(afmask, afp->af_af);
970 af_all_tunnel_status(int s)
973 uint8_t afmask[howmany(AF_MAX, NBBY)];
975 memset(afmask, 0, sizeof(afmask));
976 for (afp = afs; afp != NULL; afp = afp->af_next) {
977 if (afp->af_status_tunnel == NULL)
979 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
981 afp->af_status_tunnel(s);
982 setbit(afmask, afp->af_af);
986 static struct cmd *cmds = NULL;
989 cmd_register(struct cmd *p)
995 static const struct cmd *
996 cmd_lookup(const char *name, int iscreate)
1000 for (p = cmds; p != NULL; p = p->c_next)
1001 if (strcmp(name, p->c_name) == 0) {
1006 if (!p->c_iscloneop)
1014 callback_func *cb_func;
1016 struct callback *cb_next;
1018 static struct callback *callbacks = NULL;
1021 callback_register(callback_func *func, void *arg)
1023 struct callback *cb;
1025 cb = malloc(sizeof(struct callback));
1027 errx(1, "unable to allocate memory for callback");
1030 cb->cb_next = callbacks;
1034 /* specially-handled commands */
1035 static void setifaddr(if_ctx *ctx, const char *addr, int param);
1036 static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr);
1038 static void setifdstaddr(if_ctx *ctx, const char *addr, int param __unused);
1039 static const struct cmd setifdstaddr_cmd =
1040 DEF_CMD("ifdstaddr", 0, setifdstaddr);
1043 af_exec_ioctl(if_ctx *ctx, unsigned long action, void *data)
1045 struct ifreq *req = (struct ifreq *)data;
1047 strlcpy(req->ifr_name, name, sizeof(req->ifr_name));
1048 if (ioctl_ctx(ctx, action, req) == 0)
1054 delifaddr(if_ctx *ctx, const struct afswtch *afp)
1058 if (afp->af_exec == NULL) {
1059 warnx("interface %s cannot change %s addresses!",
1060 name, afp->af_name);
1065 error = afp->af_exec(ctx, afp->af_difaddr, afp->af_ridreq);
1067 if (error == EADDRNOTAVAIL && (doalias >= 0)) {
1068 /* means no previous address for interface */
1070 Perrorc("ioctl (SIOCDIFADDR)", error);
1075 addifaddr(if_ctx *ctx, const struct afswtch *afp)
1077 if (afp->af_exec == NULL) {
1078 warnx("interface %s cannot change %s addresses!",
1079 name, afp->af_name);
1084 if (setaddr || setmask) {
1085 int error = afp->af_exec(ctx, afp->af_aifaddr, afp->af_addreq);
1087 Perrorc("ioctl (SIOCAIFADDR)", error);
1092 ifconfig(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
1094 const struct afswtch *afp, *nafp;
1095 const struct cmd *p;
1096 struct callback *cb;
1098 int argc = orig_ctx->args->argc;
1099 char *const *argv = orig_ctx->args->argv;
1100 struct ifconfig_context _ctx = {
1101 .args = orig_ctx->args,
1102 .io_ss = orig_ctx->io_ss,
1104 struct ifconfig_context *ctx = &_ctx;
1106 strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
1111 * This is the historical "accident" allowing users to configure IPv4
1112 * addresses without the "inet" keyword which while a nice feature has
1113 * proven to complicate other things. We cannot remove this but only
1114 * make sure we will never have a similar implicit default for IPv6 or
1115 * any other address familiy. We need a fallback though for
1116 * ifconfig IF up/down etc. to work without INET support as people
1117 * never used ifconfig IF link up/down, etc. either.
1121 if (afp == NULL && feature_present("inet"))
1122 afp = af_getbyname("inet");
1126 afp = af_getbyname("link");
1128 warnx("Please specify an address_family.");
1133 ifr.ifr_addr.sa_family =
1134 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
1135 AF_LOCAL : afp->af_af;
1137 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
1138 (uafp != NULL || errno != EAFNOSUPPORT ||
1139 (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
1140 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
1146 p = cmd_lookup(*argv, iscreate);
1147 if (iscreate && p == NULL) {
1149 * Push the clone create callback so the new
1150 * device is created and can be used for any
1151 * remaining arguments.
1155 errx(1, "internal error, no callback");
1156 callbacks = cb->cb_next;
1157 cb->cb_func(ctx, cb->cb_arg);
1160 * Handle any address family spec that
1161 * immediately follows and potentially
1162 * recreate the socket.
1164 nafp = af_getbyname(*argv);
1174 * Look for a normal parameter.
1180 * Not a recognized command, choose between setting
1181 * the interface address and the dst address.
1183 p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
1185 if (p->c_parameter == NEXTARG && p->c_u.c_func) {
1186 if (argv[1] == NULL)
1187 errx(1, "'%s' requires argument",
1189 p->c_u.c_func(ctx, argv[1], 0);
1191 } else if (p->c_parameter == OPTARG && p->c_u.c_func) {
1192 p->c_u.c_func(ctx, argv[1], 0);
1193 if (argv[1] != NULL)
1195 } else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
1197 errx(1, "'%s' requires 2 arguments",
1199 p->c_u.c_func2(ctx, argv[1], argv[2]);
1200 argc -= 2, argv += 2;
1201 } else if (p->c_parameter == SPARAM && p->c_u.c_func3) {
1202 p->c_u.c_func3(ctx, *argv, p->c_sparameter);
1203 } else if (p->c_u.c_func)
1204 p->c_u.c_func(ctx, *argv, p->c_parameter);
1209 * Do any post argument processing required by the address family.
1211 if (afp->af_postproc != NULL)
1212 afp->af_postproc(ctx, newaddr, getifflags(name, s, true));
1214 * Do deferred callbacks registered while processing
1215 * command-line arguments.
1217 for (cb = callbacks; cb != NULL; cb = cb->cb_next)
1218 cb->cb_func(ctx, cb->cb_arg);
1220 * Do deferred operations.
1223 delifaddr(ctx, afp);
1225 addifaddr(ctx, afp);
1232 setifaddr(if_ctx *ctx, const char *addr, int param)
1234 const struct afswtch *afp = ctx->afp;
1236 if (afp->af_getaddr == NULL)
1239 * Delay the ioctl to set the interface addr until flags are all set.
1240 * The address interpretation may depend on the flags,
1241 * and the flags may change when the address is set.
1244 if (doalias == 0 && afp->af_af != AF_LINK)
1246 afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR));
1250 settunnel(if_ctx *ctx, const char *src, const char *dst)
1252 const struct afswtch *afp = ctx->afp;
1253 struct addrinfo *srcres, *dstres;
1256 if (afp->af_settunnel == NULL) {
1257 warn("address family %s does not support tunnel setup",
1262 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
1263 errx(1, "error in parsing address string: %s",
1264 gai_strerror(ecode));
1266 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
1267 errx(1, "error in parsing address string: %s",
1268 gai_strerror(ecode));
1270 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
1272 "source and destination address families do not match");
1274 afp->af_settunnel(ctx->io_s, srcres, dstres);
1276 freeaddrinfo(srcres);
1277 freeaddrinfo(dstres);
1281 deletetunnel(if_ctx *ctx, const char *vname, int param)
1284 if (ioctl(ctx->io_s, SIOCDIFPHYADDR, &ifr) < 0)
1285 err(1, "SIOCDIFPHYADDR");
1290 setifvnet(if_ctx *ctx, const char *jname, int dummy __unused)
1292 struct ifreq my_ifr;
1294 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1295 my_ifr.ifr_jid = jail_getid(jname);
1296 if (my_ifr.ifr_jid < 0)
1297 errx(1, "%s", jail_errmsg);
1298 if (ioctl(ctx->io_s, SIOCSIFVNET, &my_ifr) < 0)
1299 err(1, "SIOCSIFVNET");
1303 setifrvnet(if_ctx *ctx, const char *jname, int dummy __unused)
1305 struct ifreq my_ifr;
1307 memcpy(&my_ifr, &ifr, sizeof(my_ifr));
1308 my_ifr.ifr_jid = jail_getid(jname);
1309 if (my_ifr.ifr_jid < 0)
1310 errx(1, "%s", jail_errmsg);
1311 if (ioctl(ctx->io_s, SIOCSIFRVNET, &my_ifr) < 0)
1312 err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name);
1317 setifnetmask(if_ctx *ctx, const char *addr, int dummy __unused)
1319 const struct afswtch *afp = ctx->afp;
1321 if (afp->af_getaddr != NULL) {
1323 afp->af_getaddr(addr, MASK);
1328 setifbroadaddr(if_ctx *ctx, const char *addr, int dummy __unused)
1330 const struct afswtch *afp = ctx->afp;
1332 if (afp->af_getaddr != NULL)
1333 afp->af_getaddr(addr, BRDADDR);
1337 notealias(if_ctx *ctx, const char *addr, int param)
1339 const struct afswtch *afp = ctx->afp;
1341 if (setaddr && doalias == 0 && param < 0) {
1342 if (afp->af_copyaddr != NULL)
1343 afp->af_copyaddr(ctx, RIDADDR, ADDR);
1354 setifdstaddr(if_ctx *ctx, const char *addr, int param __unused)
1356 const struct afswtch *afp = ctx->afp;
1358 if (afp->af_getaddr != NULL)
1359 afp->af_getaddr(addr, DSTADDR);
1363 getifflags(const char *ifname, int us, bool err_ok)
1365 struct ifreq my_ifr;
1368 memset(&my_ifr, 0, sizeof(my_ifr));
1369 (void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name));
1371 if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
1372 err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
1375 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
1377 Perror("ioctl (SIOCGIFFLAGS)");
1383 return ((my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16));
1387 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
1388 * of the ifreq structure, which may confuse other parts of ifconfig.
1389 * Make a private copy so we can avoid that.
1392 setifflags(if_ctx *ctx, const char *vname, int value)
1394 struct ifreq my_ifr;
1397 flags = getifflags(name, ctx->io_s, false);
1403 memset(&my_ifr, 0, sizeof(my_ifr));
1404 (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name));
1405 my_ifr.ifr_flags = flags & 0xffff;
1406 my_ifr.ifr_flagshigh = flags >> 16;
1407 if (ioctl(ctx->io_s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
1412 setifcap(if_ctx *ctx, const char *vname, int value)
1416 if (ioctl(ctx->io_s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
1417 Perror("ioctl (SIOCGIFCAP)");
1420 flags = ifr.ifr_curcap;
1426 flags &= ifr.ifr_reqcap;
1427 /* Check for no change in capabilities. */
1428 if (ifr.ifr_curcap == flags)
1430 ifr.ifr_reqcap = flags;
1431 if (ioctl(ctx->io_s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
1436 setifcapnv(if_ctx *ctx, const char *vname, const char *arg)
1444 if (ioctl(ctx->io_s, SIOCGIFCAP, (caddr_t)&ifr) < 0)
1445 Perror("ioctl (SIOCGIFCAP)");
1446 if ((ifr.ifr_curcap & IFCAP_NV) == 0) {
1447 warnx("IFCAP_NV not supported");
1448 return; /* Not exit() */
1454 nvcap = nvlist_create(0);
1456 Perror("nvlist_create");
1457 while ((mopt = strsep(&marg, ",")) != NULL) {
1461 if (strcmp(mopt, "rxtls") == 0) {
1462 nvlist_add_bool(nvcap, "rxtls4", !neg);
1463 nvlist_add_bool(nvcap, "rxtls6", !neg);
1465 nvlist_add_bool(nvcap, mopt, !neg);
1468 buf = nvlist_pack(nvcap, &nvbuflen);
1470 errx(1, "nvlist_pack error");
1473 ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen;
1474 ifr.ifr_cap_nv.buffer = buf;
1475 if (ioctl(ctx->io_s, SIOCSIFCAPNV, (caddr_t)&ifr) < 0)
1478 nvlist_destroy(nvcap);
1483 setifmetric(if_ctx *ctx, const char *val, int dummy __unused)
1485 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1486 ifr.ifr_metric = atoi(val);
1487 if (ioctl(ctx->io_s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
1488 err(1, "ioctl SIOCSIFMETRIC (set metric)");
1492 setifmtu(if_ctx *ctx, const char *val, int dummy __unused)
1494 strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
1495 ifr.ifr_mtu = atoi(val);
1496 if (ioctl(ctx->io_s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
1497 err(1, "ioctl SIOCSIFMTU (set mtu)");
1501 setifpcp(if_ctx *ctx, const char *val, int arg __unused)
1506 ul = strtoul(val, &endp, 0);
1508 errx(1, "invalid value for pcp");
1510 errx(1, "value for pcp out of range");
1511 ifr.ifr_lan_pcp = ul;
1512 if (ioctl(ctx->io_s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1513 err(1, "SIOCSLANPCP");
1517 disableifpcp(if_ctx *ctx, const char *val, int arg __unused)
1520 ifr.ifr_lan_pcp = IFNET_PCP_NONE;
1521 if (ioctl(ctx->io_s, SIOCSLANPCP, (caddr_t)&ifr) == -1)
1522 err(1, "SIOCSLANPCP");
1526 setifname(if_ctx *ctx, const char *val, int dummy __unused)
1530 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1532 newname = strdup(val);
1533 if (newname == NULL)
1534 err(1, "no memory to set ifname");
1535 ifr.ifr_data = newname;
1536 if (ioctl(ctx->io_s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
1538 err(1, "ioctl SIOCSIFNAME (set name)");
1540 ifname_update(ctx, newname);
1545 setifdescr(if_ctx *ctx, const char *val, int dummy __unused)
1549 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1551 ifr.ifr_buffer.length = strlen(val) + 1;
1552 if (ifr.ifr_buffer.length == 1) {
1553 ifr.ifr_buffer.buffer = newdescr = NULL;
1554 ifr.ifr_buffer.length = 0;
1556 newdescr = strdup(val);
1557 ifr.ifr_buffer.buffer = newdescr;
1558 if (newdescr == NULL) {
1559 warn("no memory to set ifdescr");
1564 if (ioctl(ctx->io_s, SIOCSIFDESCR, (caddr_t)&ifr) < 0)
1565 err(1, "ioctl SIOCSIFDESCR (set descr)");
1571 unsetifdescr(if_ctx *ctx, const char *val, int value)
1573 setifdescr(ctx, "", 0);
1577 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \
1578 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
1579 "\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP\25STICKYARP"
1582 "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \
1583 "\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \
1584 "\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \
1585 "\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT\32HWRXTSTMP\33NOMAP\34TXTLS4\35TXTLS6" \
1586 "\36VXLAN_HWCSUM\37VXLAN_HWTSO\40TXTLS_RTLMT"
1589 print_ifcap_nv(struct ifconfig_args *args, int s)
1597 buf = malloc(IFR_CAP_NV_MAXBUFSIZE);
1600 ifr.ifr_cap_nv.buffer = buf;
1601 ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE;
1602 if (ioctl(s, SIOCGIFCAPNV, (caddr_t)&ifr) != 0)
1603 Perror("ioctl (SIOCGIFCAPNV)");
1604 nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer,
1605 ifr.ifr_cap_nv.length, 0);
1607 Perror("nvlist_unpack");
1608 printf("\toptions");
1610 for (first = true;; first = false) {
1611 nvname = nvlist_next(nvcap, &type, &cookie);
1612 if (nvname == NULL) {
1616 if (type == NV_TYPE_BOOL) {
1617 val = nvlist_get_bool(nvcap, nvname);
1620 first ? ' ' : ',', nvname);
1624 if (args->supmedia) {
1625 printf("\tcapabilities");
1627 for (first = true;; first = false) {
1628 nvname = nvlist_next(nvcap, &type,
1630 if (nvname == NULL) {
1634 if (type == NV_TYPE_BOOL)
1635 printf("%c%s", first ? ' ' :
1639 nvlist_destroy(nvcap);
1642 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1643 Perror("ioctl (SIOCGIFCAP)");
1647 print_ifcap(struct ifconfig_args *args, int s)
1649 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0)
1652 if ((ifr.ifr_curcap & IFCAP_NV) != 0)
1653 print_ifcap_nv(args, s);
1655 printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
1657 if (args->supmedia && ifr.ifr_reqcap != 0) {
1658 printb("\tcapabilities", ifr.ifr_reqcap,
1666 print_ifstatus(int s)
1670 strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
1671 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
1672 printf("%s", ifs.ascii);
1678 if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
1679 printf(" metric %d", ifr.ifr_metric);
1682 #ifdef WITHOUT_NETLINK
1686 if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
1687 printf(" mtu %d", ifr.ifr_mtu);
1691 print_description(int s)
1694 if ((descr = reallocf(descr, descrlen)) != NULL) {
1695 ifr.ifr_buffer.buffer = descr;
1696 ifr.ifr_buffer.length = descrlen;
1697 if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) {
1698 if (ifr.ifr_buffer.buffer == descr) {
1699 if (strlen(descr) > 0)
1700 printf("\tdescription: %s\n",
1702 } else if (ifr.ifr_buffer.length > descrlen) {
1703 descrlen = ifr.ifr_buffer.length;
1708 warn("unable to allocate memory for interface"
1715 * Print the status of the interface. If an address family was
1716 * specified, show only it; otherwise, show them all.
1719 status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
1720 struct ifaddrs *ifa)
1722 struct ifaddrs *ift;
1724 bool allfamilies = args->afp == NULL;
1726 if (args->afp == NULL)
1727 ifr.ifr_addr.sa_family = AF_LOCAL;
1729 ifr.ifr_addr.sa_family =
1730 args->afp->af_af == AF_LINK ? AF_LOCAL : args->afp->af_af;
1731 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
1733 s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
1735 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
1737 struct ifconfig_context _ctx = { .io_s = s }, *ctx;
1740 printf("%s: ", name);
1741 printb("flags", ifa->ifa_flags, IFFBITS);
1746 print_description(s);
1748 print_ifcap(args, s);
1752 for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
1753 if (ift->ifa_addr == NULL)
1755 if (strcmp(ifa->ifa_name, ift->ifa_name) != 0)
1758 const struct afswtch *p;
1759 p = af_getbyfamily(ift->ifa_addr->sa_family);
1760 if (p != NULL && p->af_status != NULL)
1761 p->af_status(ctx, ift);
1762 } else if (args->afp->af_af == ift->ifa_addr->sa_family)
1763 args->afp->af_status(ctx, ift);
1766 if (allfamilies || afp->af_af == AF_LINK) {
1767 const struct afswtch *lafp;
1770 * Hack; the link level address is received separately
1771 * from the routing information so any address is not
1772 * handled above. Cobble together an entry and invoke
1773 * the status method specially.
1775 lafp = af_getbyname("lladdr");
1777 info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
1778 lafp->af_status(s, &info);
1783 af_other_status(ctx);
1784 else if (args->afp->af_other_status != NULL)
1785 args->afp->af_other_status(ctx);
1788 if (args->verbose > 0)
1797 tunnel_status(int s)
1799 af_all_tunnel_status(s);
1803 Perrorc(const char *cmd, int error)
1808 errx(1, "%s: no such interface", cmd);
1812 errx(1, "%s: permission denied", cmd);
1816 errc(1, error, "%s", cmd);
1821 Perror(const char *cmd)
1823 Perrorc(cmd, errno);
1827 * Print a value a la the %b format of the kernel's printf
1830 printb(const char *s, unsigned v, const char *bits)
1835 if (bits && *bits == 8)
1836 printf("%s=%o", s, v);
1838 printf("%s=%x", s, v);
1842 while ((i = *bits++) != '\0') {
1843 if (v & (1u << (i-1))) {
1847 for (; (c = *bits) > 32; bits++)
1850 for (; *bits > 32; bits++)
1858 print_vhid(const struct ifaddrs *ifa, const char *s)
1860 struct if_data *ifd;
1862 if (ifa->ifa_data == NULL)
1865 ifd = ifa->ifa_data;
1866 if (ifd->ifi_vhid == 0)
1869 printf(" vhid %d", ifd->ifi_vhid);
1873 ifmaybeload(struct ifconfig_args *args, const char *name)
1875 #define MOD_PREFIX_LEN 3 /* "if_" */
1876 struct module_stat mstat;
1878 char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
1880 struct module_map_entry *mme;
1883 /* loading suppressed by the user */
1887 /* trim the interface number off the end */
1888 strlcpy(ifname, name, sizeof(ifname));
1889 dp = ifname + strlen(ifname) - 1;
1890 for (; dp > ifname; dp--) {
1897 /* Either derive it from the map or guess otherwise */
1900 for (unsigned i = 0; i < nitems(module_map); ++i) {
1901 mme = &module_map[i];
1902 if (strcmp(mme->ifname, ifname) == 0) {
1903 strlcpy(ifkind, mme->kldname, sizeof(ifkind));
1909 /* We didn't have an alias for it... we'll guess. */
1911 /* turn interface and unit into module name */
1912 strlcpy(ifkind, "if_", sizeof(ifkind));
1913 strlcat(ifkind, ifname, sizeof(ifkind));
1916 /* scan files in kernel */
1917 mstat.version = sizeof(struct module_stat);
1918 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
1919 /* scan modules in file */
1920 for (modid = kldfirstmod(fileid); modid > 0;
1921 modid = modfnext(modid)) {
1922 if (modstat(modid, &mstat) < 0)
1924 /* strip bus name if present */
1925 if ((cp = strchr(mstat.name, '/')) != NULL) {
1931 * Is it already loaded? Don't compare with ifname if
1932 * we were specifically told which kld to use. Doing
1933 * so could lead to conflicts not trivially solved.
1935 if ((!found && strcmp(ifname, cp) == 0) ||
1936 strcmp(ifkind, cp) == 0)
1942 * Try to load the module. But ignore failures, because ifconfig can't
1943 * infer the names of all drivers (eg mlx4en(4)).
1945 (void) kldload(ifkind);
1948 static struct cmd basic_cmds[] = {
1949 DEF_CMD("up", IFF_UP, setifflags),
1950 DEF_CMD("down", -IFF_UP, setifflags),
1951 DEF_CMD("arp", -IFF_NOARP, setifflags),
1952 DEF_CMD("-arp", IFF_NOARP, setifflags),
1953 DEF_CMD("debug", IFF_DEBUG, setifflags),
1954 DEF_CMD("-debug", -IFF_DEBUG, setifflags),
1955 DEF_CMD_ARG("description", setifdescr),
1956 DEF_CMD_ARG("descr", setifdescr),
1957 DEF_CMD("-description", 0, unsetifdescr),
1958 DEF_CMD("-descr", 0, unsetifdescr),
1959 DEF_CMD("promisc", IFF_PPROMISC, setifflags),
1960 DEF_CMD("-promisc", -IFF_PPROMISC, setifflags),
1961 DEF_CMD("add", IFF_UP, notealias),
1962 DEF_CMD("alias", IFF_UP, notealias),
1963 DEF_CMD("-alias", -IFF_UP, notealias),
1964 DEF_CMD("delete", -IFF_UP, notealias),
1965 DEF_CMD("remove", -IFF_UP, notealias),
1967 #define EN_SWABIPS 0x1000
1968 DEF_CMD("swabips", EN_SWABIPS, setifflags),
1969 DEF_CMD("-swabips", -EN_SWABIPS, setifflags),
1971 DEF_CMD_ARG("netmask", setifnetmask),
1972 DEF_CMD_ARG("metric", setifmetric),
1973 DEF_CMD_ARG("broadcast", setifbroadaddr),
1974 DEF_CMD_ARG2("tunnel", settunnel),
1975 DEF_CMD("-tunnel", 0, deletetunnel),
1976 DEF_CMD("deletetunnel", 0, deletetunnel),
1978 DEF_CMD_ARG("vnet", setifvnet),
1979 DEF_CMD_ARG("-vnet", setifrvnet),
1981 DEF_CMD("link0", IFF_LINK0, setifflags),
1982 DEF_CMD("-link0", -IFF_LINK0, setifflags),
1983 DEF_CMD("link1", IFF_LINK1, setifflags),
1984 DEF_CMD("-link1", -IFF_LINK1, setifflags),
1985 DEF_CMD("link2", IFF_LINK2, setifflags),
1986 DEF_CMD("-link2", -IFF_LINK2, setifflags),
1987 DEF_CMD("monitor", IFF_MONITOR, setifflags),
1988 DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
1989 DEF_CMD("mextpg", IFCAP_MEXTPG, setifcap),
1990 DEF_CMD("-mextpg", -IFCAP_MEXTPG, setifcap),
1991 DEF_CMD("staticarp", IFF_STATICARP, setifflags),
1992 DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
1993 DEF_CMD("stickyarp", IFF_STICKYARP, setifflags),
1994 DEF_CMD("-stickyarp", -IFF_STICKYARP, setifflags),
1995 DEF_CMD("rxcsum6", IFCAP_RXCSUM_IPV6, setifcap),
1996 DEF_CMD("-rxcsum6", -IFCAP_RXCSUM_IPV6, setifcap),
1997 DEF_CMD("txcsum6", IFCAP_TXCSUM_IPV6, setifcap),
1998 DEF_CMD("-txcsum6", -IFCAP_TXCSUM_IPV6, setifcap),
1999 DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap),
2000 DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap),
2001 DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap),
2002 DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap),
2003 DEF_CMD("netcons", IFCAP_NETCONS, setifcap),
2004 DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap),
2005 DEF_CMD_ARG("pcp", setifpcp),
2006 DEF_CMD("-pcp", 0, disableifpcp),
2007 DEF_CMD("polling", IFCAP_POLLING, setifcap),
2008 DEF_CMD("-polling", -IFCAP_POLLING, setifcap),
2009 DEF_CMD("tso6", IFCAP_TSO6, setifcap),
2010 DEF_CMD("-tso6", -IFCAP_TSO6, setifcap),
2011 DEF_CMD("tso4", IFCAP_TSO4, setifcap),
2012 DEF_CMD("-tso4", -IFCAP_TSO4, setifcap),
2013 DEF_CMD("tso", IFCAP_TSO, setifcap),
2014 DEF_CMD("-tso", -IFCAP_TSO, setifcap),
2015 DEF_CMD("toe", IFCAP_TOE, setifcap),
2016 DEF_CMD("-toe", -IFCAP_TOE, setifcap),
2017 DEF_CMD("lro", IFCAP_LRO, setifcap),
2018 DEF_CMD("-lro", -IFCAP_LRO, setifcap),
2019 DEF_CMD("txtls", IFCAP_TXTLS, setifcap),
2020 DEF_CMD("-txtls", -IFCAP_TXTLS, setifcap),
2021 DEF_CMD_SARG("rxtls", IFCAP2_RXTLS4_NAME "," IFCAP2_RXTLS6_NAME,
2023 DEF_CMD_SARG("-rxtls", "-"IFCAP2_RXTLS4_NAME ",-" IFCAP2_RXTLS6_NAME,
2025 DEF_CMD("wol", IFCAP_WOL, setifcap),
2026 DEF_CMD("-wol", -IFCAP_WOL, setifcap),
2027 DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap),
2028 DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap),
2029 DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap),
2030 DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap),
2031 DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap),
2032 DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap),
2033 DEF_CMD("txrtlmt", IFCAP_TXRTLMT, setifcap),
2034 DEF_CMD("-txrtlmt", -IFCAP_TXRTLMT, setifcap),
2035 DEF_CMD("txtlsrtlmt", IFCAP_TXTLS_RTLMT, setifcap),
2036 DEF_CMD("-txtlsrtlmt", -IFCAP_TXTLS_RTLMT, setifcap),
2037 DEF_CMD("hwrxtstmp", IFCAP_HWRXTSTMP, setifcap),
2038 DEF_CMD("-hwrxtstmp", -IFCAP_HWRXTSTMP, setifcap),
2039 DEF_CMD("normal", -IFF_LINK0, setifflags),
2040 DEF_CMD("compress", IFF_LINK0, setifflags),
2041 DEF_CMD("noicmp", IFF_LINK1, setifflags),
2042 DEF_CMD_ARG("mtu", setifmtu),
2043 DEF_CMD_ARG("name", setifname),
2046 static __constructor void
2051 for (i = 0; i < nitems(basic_cmds); i++)
2052 cmd_register(&basic_cmds[i]);