2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $FreeBSD: src/sbin/ifconfig/ifconfig.c,v 1.113.2.4 2006/02/09 10:48:43 yar Exp $
30 * $DragonFly: src/sbin/ifconfig/ifconfig.c,v 1.27 2006/05/05 14:53:41 sephe Exp $
33 #include <sys/param.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <sys/sysctl.h>
38 #include <sys/module.h>
39 #include <sys/linker.h>
41 #include <net/ethernet.h>
43 #include <net/if_var.h>
44 #include <net/if_dl.h>
45 #include <net/if_types.h>
46 #include <net/route.h>
49 #include <netinet/in.h>
50 #include <netinet/in_var.h>
51 #include <arpa/inet.h>
66 * This macro returns the size of a struct sockaddr when passed
67 * through a routing socket. Basically we round up sa_len to
68 * a multiple of sizeof(long), with a minimum of sizeof(long).
69 * The check for a NULL pointer is just a convenience, probably never used.
70 * The case sa_len == 0 should only apply to empty structures.
73 ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
75 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
78 * Since "struct ifreq" is composed of various union members, callers
79 * should pay special attention to interprete the value.
80 * (.e.g. little/big endian difference in the structure.)
95 int printkeys = 0; /* Print keying material for interfaces. */
96 int printname = 0; /* Print the name of the created interface. */
98 static int ifconfig(int argc, char *const *argv, const struct afswtch *afp);
99 static void status(const struct afswtch *afp, int addrcount,
100 struct sockaddr_dl *sdl, struct if_msghdr *ifm,
101 struct ifa_msghdr *ifam);
102 static void tunnel_status(int s);
103 static void usage(void);
105 static struct afswtch *af_getbyname(const char *name);
106 static struct afswtch *af_getbyfamily(int af);
107 static void af_other_status(int);
109 static struct option *opts = NULL;
112 opt_register(struct option *p)
124 /* XXX not right but close enough for now */
126 for (p = opts; p != NULL; p = p->next) {
127 strlcat(options, p->opt_usage, sizeof(options));
128 strlcat(options, " ", sizeof(options));
132 "usage: ifconfig %sinterface address_family [address [dest_address]]\n"
134 " ifconfig interface create\n"
135 " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n"
136 " ifconfig -l [-d] [-u] [address_family]\n"
137 " ifconfig %s[-d] [-m] [-u] [-v]\n",
138 options, options, options);
143 main(int argc, char *argv[])
145 int c, all, namesonly, downonly, uponly;
146 int need_nl = 0, count = 0;
147 const struct afswtch *afp = NULL;
148 int addrcount, ifindex;
149 struct if_msghdr *ifm, *nextifm;
150 struct ifa_msghdr *ifam;
151 struct sockaddr_dl *sdl;
152 char *buf, *lim, *next;
158 all = downonly = uponly = namesonly = verbose = 0;
160 /* Parse leading line options */
161 strlcpy(options, "adklmuv", sizeof(options));
162 for (p = opts; p != NULL; p = p->next)
163 strlcat(options, p->opt, sizeof(options));
164 while ((c = getopt(argc, argv, options)) != -1) {
166 case 'a': /* scan all interfaces */
169 case 'd': /* restrict scan to "down" interfaces */
175 case 'l': /* scan interface names only */
178 case 'm': /* show media choices in status */
181 case 'u': /* restrict scan to "up" interfaces */
188 for (p = opts; p != NULL; p = p->next)
189 if (p->opt[0] == c) {
201 /* -l cannot be used with -a or -m */
202 if (namesonly && (all || supmedia))
206 if (uponly && downonly)
209 /* no arguments is equivalent to '-a' */
210 if (!namesonly && argc < 1)
213 /* -a and -l allow an address family arg to limit the output */
214 if (all || namesonly) {
220 afp = af_getbyname(*argv);
223 if (afp->af_name != NULL)
225 /* leave with afp non-zero */
228 /* not listing, need an argument */
232 strncpy(name, *argv, sizeof(name));
235 /* check and maybe load support for this interface */
239 * NOTE: We must special-case the `create' command right
240 * here as we would otherwise fail when trying to find
243 if (argc > 0 && (strcmp(argv[0], "create") == 0 ||
244 strcmp(argv[0], "plumb") == 0)) {
250 ifindex = if_nametoindex(name);
252 errx(1, "interface %s does not exist", name);
255 /* Check for address family */
257 afp = af_getbyname(*argv);
266 mib[3] = 0; /* address family */
267 mib[4] = NET_RT_IFLIST;
268 mib[5] = ifindex; /* interface index */
270 /* if particular family specified, only ask about it */
274 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
275 errx(1, "iflist-sysctl-estimate");
276 if ((buf = malloc(needed)) == NULL)
278 if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
279 if (errno == ENOMEM && count++ < 10) {
280 warnx("Routing table grew, retrying");
285 errx(1, "actual retrieval of interface table");
292 ifm = (struct if_msghdr *)next;
294 if (ifm->ifm_type == RTM_IFINFO) {
296 if (ifm->ifm_data.ifi_datalen == 0)
297 ifm->ifm_data.ifi_datalen = sizeof(struct if_data);
298 sdl = (struct sockaddr_dl *)((char *)ifm + sizeof(struct if_msghdr) -
299 sizeof(struct if_data) + ifm->ifm_data.ifi_datalen);
301 sdl = (struct sockaddr_dl *)(ifm + 1);
303 flags = ifm->ifm_flags;
305 fprintf(stderr, "out of sync parsing NET_RT_IFLIST\n");
306 fprintf(stderr, "expected %d, got %d\n", RTM_IFINFO,
308 fprintf(stderr, "msglen = %d\n", ifm->ifm_msglen);
309 fprintf(stderr, "buf:%p, next:%p, lim:%p\n", buf, next,
314 next += ifm->ifm_msglen;
319 nextifm = (struct if_msghdr *)next;
321 if (nextifm->ifm_type != RTM_NEWADDR)
325 ifam = (struct ifa_msghdr *)nextifm;
328 next += nextifm->ifm_msglen;
330 memcpy(name, sdl->sdl_data,
331 sizeof(name) < sdl->sdl_nlen ?
332 sizeof(name)-1 : sdl->sdl_nlen);
333 name[sizeof(name) < sdl->sdl_nlen ?
334 sizeof(name)-1 : sdl->sdl_nlen] = '\0';
336 if (all || namesonly) {
338 if ((flags & IFF_UP) == 0)
339 continue; /* not up */
342 continue; /* not down */
344 if (afp == NULL || afp->af_af != AF_LINK ||
345 sdl->sdl_type == IFT_ETHER) {
356 ifconfig(argc, argv, afp);
358 status(afp, addrcount, sdl, ifm, ifam);
362 if (namesonly && need_nl > 0)
366 printf("%s\n", name);
371 static struct afswtch *afs = NULL;
374 af_register(struct afswtch *p)
380 static struct afswtch *
381 af_getbyname(const char *name)
385 for (afp = afs; afp != NULL; afp = afp->af_next)
386 if (strcmp(afp->af_name, name) == 0)
391 static struct afswtch *
392 af_getbyfamily(int af)
396 for (afp = afs; afp != NULL; afp = afp->af_next)
397 if (afp->af_af == af)
403 af_other_status(int s)
406 uint8_t afmask[howmany(AF_MAX, NBBY)];
408 memset(afmask, 0, sizeof(afmask));
409 for (afp = afs; afp != NULL; afp = afp->af_next) {
410 if (afp->af_other_status == NULL)
412 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
414 afp->af_other_status(s);
415 setbit(afmask, afp->af_af);
420 af_all_tunnel_status(int s)
423 uint8_t afmask[howmany(AF_MAX, NBBY)];
425 memset(afmask, 0, sizeof(afmask));
426 for (afp = afs; afp != NULL; afp = afp->af_next) {
427 if (afp->af_status_tunnel == NULL)
429 if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
431 afp->af_status_tunnel(s);
432 setbit(afmask, afp->af_af);
436 static struct cmd *cmds = NULL;
439 cmd_register(struct cmd *p)
445 static const struct cmd *
446 cmd_lookup(const char *name)
448 #define N(a) (sizeof(a)/sizeof(a[0]))
451 for (p = cmds; p != NULL; p = p->c_next)
452 if (strcmp(name, p->c_name) == 0)
459 callback_func *cb_func;
461 struct callback *cb_next;
463 static struct callback *callbacks = NULL;
466 callback_register(callback_func *func, void *arg)
470 cb = malloc(sizeof(struct callback));
472 errx(1, "unable to allocate memory for callback");
475 cb->cb_next = callbacks;
479 /* specially-handled commands */
480 static void setifaddr(const char *, int, int, const struct afswtch *);
481 static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr);
483 static void setifdstaddr(const char *, int, int, const struct afswtch *);
484 static const struct cmd setifdstaddr_cmd =
485 DEF_CMD("ifdstaddr", 0, setifdstaddr);
488 ifconfig(int argc, char *const *argv, const struct afswtch *afp)
494 afp = af_getbyname("inet");
495 ifr.ifr_addr.sa_family =
496 afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
497 AF_INET : afp->af_af;
498 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
500 if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
501 err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family);
506 p = cmd_lookup(*argv);
509 * Not a recognized command, choose between setting
510 * the interface address and the dst address.
512 p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
514 if (p->c_u.c_func || p->c_u.c_func2) {
515 if (p->c_parameter == NEXTARG) {
517 errx(1, "'%s' requires argument",
519 p->c_u.c_func(argv[1], 0, s, afp);
521 } else if (p->c_parameter == OPTARG) {
522 p->c_u.c_func(argv[1], 0, s, afp);
525 } else if (p->c_parameter == NEXTARG2) {
527 errx(1, "'%s' requires 2 arguments",
529 p->c_u.c_func2(argv[1], argv[2], s, afp);
530 argc -= 2, argv += 2;
532 p->c_u.c_func(*argv, p->c_parameter, s, afp);
538 * Do any post argument processing required by the address family.
540 if (afp->af_postproc != NULL)
541 afp->af_postproc(s, afp);
543 * Do deferred callbacks registered while processing
544 * command-line arguments.
546 for (cb = callbacks; cb != NULL; cb = cb->cb_next)
547 cb->cb_func(s, cb->cb_arg);
549 * Do deferred operations.
552 if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
553 warnx("interface %s cannot change %s addresses!",
560 strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
561 ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
563 if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
564 /* means no previous address for interface */
566 Perror("ioctl (SIOCDIFADDR)");
570 if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
571 warnx("interface %s cannot change %s addresses!",
576 if (newaddr && (setaddr || setmask)) {
577 strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
578 if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
579 Perror("ioctl (SIOCAIFADDR)");
588 setifaddr(const char *addr, int param, int s, const struct afswtch *afp)
590 if (afp->af_getaddr == NULL)
593 * Delay the ioctl to set the interface addr until flags are all set.
594 * The address interpretation may depend on the flags,
595 * and the flags may change when the address is set.
598 if (doalias == 0 && afp->af_af != AF_LINK)
600 afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR));
604 settunnel(const char *src, const char *dst, int s, const struct afswtch *afp)
606 struct addrinfo *srcres, *dstres;
609 if (afp->af_settunnel == NULL) {
610 warn("address family %s does not support tunnel setup",
615 if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
616 errx(1, "error in parsing address string: %s",
617 gai_strerror(ecode));
619 if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
620 errx(1, "error in parsing address string: %s",
621 gai_strerror(ecode));
623 if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
625 "source and destination address families do not match");
627 afp->af_settunnel(s, srcres, dstres);
629 freeaddrinfo(srcres);
630 freeaddrinfo(dstres);
635 deletetunnel(const char *vname, int param, int s, const struct afswtch *afp)
638 if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0)
639 err(1, "SIOCDIFPHYADDR");
643 setifnetmask(const char *addr, int dummy __unused, int s,
644 const struct afswtch *afp)
646 if (afp->af_getaddr != NULL) {
648 afp->af_getaddr(addr, MASK);
653 setifbroadaddr(const char *addr, int dummy __unused, int s,
654 const struct afswtch *afp)
656 if (afp->af_getaddr != NULL)
657 afp->af_getaddr(addr, DSTADDR);
661 setifipdst(const char *addr, int dummy __unused, int s,
662 const struct afswtch *afp)
664 const struct afswtch *inet;
666 inet = af_getbyname("inet");
669 inet->af_getaddr(addr, DSTADDR);
676 notealias(const char *addr, int param, int s, const struct afswtch *afp)
678 #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
679 if (setaddr && doalias == 0 && param < 0)
680 if (afp->af_addreq != NULL && afp->af_ridreq != NULL)
681 bcopy((caddr_t)rqtosa(af_addreq),
682 (caddr_t)rqtosa(af_ridreq),
683 rqtosa(af_addreq)->sa_len);
695 setifdstaddr(const char *addr, int param __unused, int s,
696 const struct afswtch *afp)
698 if (afp->af_getaddr != NULL)
699 afp->af_getaddr(addr, DSTADDR);
703 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
704 * of the ifreq structure, which may confuse other parts of ifconfig.
705 * Make a private copy so we can avoid that.
708 setifflags(const char *vname, int value, int s, const struct afswtch *afp)
712 bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq));
714 if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
715 Perror("ioctl (SIOCGIFFLAGS)");
718 strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name));
719 flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16);
726 my_ifr.ifr_flags = flags & 0xffff;
727 my_ifr.ifr_flagshigh = flags >> 16;
728 if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
733 setifcap(const char *vname, int value, int s, const struct afswtch *afp)
736 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
737 Perror("ioctl (SIOCGIFCAP)");
740 flags = ifr.ifr_curcap;
746 ifr.ifr_reqcap = flags;
747 if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
752 setifmetric(const char *val, int dummy __unused, int s,
753 const struct afswtch *afp)
755 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
756 ifr.ifr_metric = atoi(val);
757 if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
758 warn("ioctl (set metric)");
762 setifmtu(const char *val, int dummy __unused, int s,
763 const struct afswtch *afp)
765 strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
766 ifr.ifr_mtu = atoi(val);
767 if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
768 warn("ioctl (set mtu)");
772 setifname(const char *val, int dummy __unused, int s,
773 const struct afswtch *afp)
777 newname = strdup(val);
778 if (newname == NULL) {
779 warn("no memory to set ifname");
782 ifr.ifr_data = newname;
783 if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
784 warn("ioctl (set name)");
788 strlcpy(name, newname, sizeof(name));
792 * Even if we just created the interface, we don't need to print
793 * its name because we just nailed it down separately.
799 * Expand the compacted form of addresses as returned via the
800 * configuration read via sysctl().
803 rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
808 memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
809 for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
810 if ((rtinfo->rti_addrs & (1 << i)) == 0)
812 rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
818 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
819 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
820 "\20MULTICAST\21POLLING\22PPROMISC\23MONITOR\24STATICARP\25NEEDSGIANT"
823 "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING"
826 * Print the status of the interface. If an address family was
827 * specified, show only it; otherwise, show them all.
830 status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
831 struct if_msghdr *ifm, struct ifa_msghdr *ifam)
833 struct rt_addrinfo info;
839 afp = af_getbyname("inet");
843 ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
844 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
846 s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
848 err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
850 printf("%s: ", name);
851 printb("flags", flags, IFFBITS);
852 if (ifm->ifm_data.ifi_metric)
853 printf(" metric %ld", ifm->ifm_data.ifi_metric);
854 if (ifm->ifm_data.ifi_mtu)
855 printf(" mtu %ld", ifm->ifm_data.ifi_mtu);
858 if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
859 if (ifr.ifr_curcap != 0) {
860 printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
863 if (supmedia && ifr.ifr_reqcap != 0) {
864 printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS);
871 while (addrcount > 0) {
872 info.rti_addrs = ifam->ifam_addrs;
873 /* Expand the compacted addresses */
874 rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam,
878 const struct afswtch *p;
879 p = af_getbyfamily(info.rti_info[RTAX_IFA]->sa_family);
880 if (p != NULL && p->af_status != NULL)
881 p->af_status(s, &info);
882 } else if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family)
883 afp->af_status(s, &info);
885 ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen);
887 if (allfamilies || afp->af_af == AF_LINK) {
888 const struct afswtch *lafp;
891 * Hack; the link level address is received separately
892 * from the routing information so any address is not
893 * handled above. Cobble together an entry and invoke
894 * the status method specially.
896 lafp = af_getbyname("lladdr");
898 info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
899 lafp->af_status(s, &info);
904 else if (afp->af_other_status != NULL)
905 afp->af_other_status(s);
907 strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
908 if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
909 printf("%s", ifs.ascii);
918 af_all_tunnel_status(s);
922 Perror(const char *cmd)
927 errx(1, "%s: no such interface", cmd);
931 errx(1, "%s: permission denied", cmd);
940 * Print a value a la the %b format of the kernel's printf
943 printb(const char *s, unsigned v, const char *bits)
948 if (bits && *bits == 8)
949 printf("%s=%o", s, v);
951 printf("%s=%x", s, v);
955 while ((i = *bits++) != '\0') {
956 if (v & (1 << (i-1))) {
960 for (; (c = *bits) > 32; bits++)
963 for (; *bits > 32; bits++)
971 ifmaybeload(char *name)
973 struct module_stat mstat;
975 char ifkind[35], *cp, *dp;
977 /* turn interface and unit into module name */
978 strcpy(ifkind, "if_");
979 for (cp = name, dp = ifkind + 3;
980 (*cp != 0) && !isdigit(*cp); cp++, dp++)
984 /* scan files in kernel */
985 mstat.version = sizeof(struct module_stat);
986 for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
987 /* scan modules in file */
988 for (modid = kldfirstmod(fileid); modid > 0;
989 modid = modfnext(modid)) {
990 if (modstat(modid, &mstat) < 0)
992 /* strip bus name if present */
993 if ((cp = strchr(mstat.name, '/')) != NULL) {
998 /* already loaded? */
999 if (strncmp(name, cp, strlen(cp)) == 0 ||
1000 strncmp(ifkind, cp, strlen(cp)) == 0)
1005 /* not present, we should try to load it */
1009 static struct cmd basic_cmds[] = {
1010 DEF_CMD("up", IFF_UP, setifflags),
1011 DEF_CMD("down", -IFF_UP, setifflags),
1012 DEF_CMD("arp", -IFF_NOARP, setifflags),
1013 DEF_CMD("-arp", IFF_NOARP, setifflags),
1014 DEF_CMD("debug", IFF_DEBUG, setifflags),
1015 DEF_CMD("-debug", -IFF_DEBUG, setifflags),
1016 DEF_CMD("promisc", IFF_PPROMISC, setifflags),
1017 DEF_CMD("-promisc", -IFF_PPROMISC, setifflags),
1018 DEF_CMD("add", IFF_UP, notealias),
1019 DEF_CMD("alias", IFF_UP, notealias),
1020 DEF_CMD("-alias", -IFF_UP, notealias),
1021 DEF_CMD("delete", -IFF_UP, notealias),
1022 DEF_CMD("remove", -IFF_UP, notealias),
1024 #define EN_SWABIPS 0x1000
1025 DEF_CMD("swabips", EN_SWABIPS, setifflags),
1026 DEF_CMD("-swabips", -EN_SWABIPS, setifflags),
1028 DEF_CMD_ARG("netmask", setifnetmask),
1029 DEF_CMD_ARG("metric", setifmetric),
1030 DEF_CMD_ARG("broadcast", setifbroadaddr),
1032 DEF_CMD_ARG("ipdst", setifipdst),
1034 DEF_CMD_ARG2("tunnel", settunnel),
1035 DEF_CMD("-tunnel", 0, deletetunnel),
1036 DEF_CMD("deletetunnel", 0, deletetunnel),
1037 DEF_CMD("link0", IFF_LINK0, setifflags),
1038 DEF_CMD("-link0", -IFF_LINK0, setifflags),
1039 DEF_CMD("link1", IFF_LINK1, setifflags),
1040 DEF_CMD("-link1", -IFF_LINK1, setifflags),
1041 DEF_CMD("link2", IFF_LINK2, setifflags),
1042 DEF_CMD("-link2", -IFF_LINK2, setifflags),
1044 DEF_CMD("monitor", IFF_MONITOR, setifflags),
1045 DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
1046 DEF_CMD("staticarp", IFF_STATICARP, setifflags),
1047 DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
1049 DEF_CMD("polling", IFF_POLLING, setifflags),
1050 DEF_CMD("-polling", -IFF_POLLING, setifflags),
1051 DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap),
1052 DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap),
1053 DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap),
1054 DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap),
1055 DEF_CMD("netcons", IFCAP_NETCONS, setifcap),
1056 DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap),
1057 DEF_CMD("normal", -IFF_LINK0, setifflags),
1058 DEF_CMD("compress", IFF_LINK0, setifflags),
1059 DEF_CMD("noicmp", IFF_LINK1, setifflags),
1060 DEF_CMD_ARG("mtu", setifmtu),
1061 DEF_CMD_ARG("name", setifname),
1064 static __constructor void
1067 #define N(a) (sizeof(a) / sizeof(a[0]))
1070 for (i = 0; i < N(basic_cmds); i++)
1071 cmd_register(&basic_cmds[i]);