diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-10-07 15:10:20 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-01-10 09:53:31 +0100 |
commit | c40e45b75eb76d79a05c7fa85c1fa9b5c728a12f (patch) | |
tree | ad4f2519067709f00ab98b3c591186c26dc3a21f /freebsd/sbin/ifconfig/ifconfig.c | |
parent | userspace-header-gen.py: Simplify program ports (diff) | |
download | rtems-libbsd-c40e45b75eb76d79a05c7fa85c1fa9b5c728a12f.tar.bz2 |
Update to FreeBSD head 2016-08-23
Git mirror commit 9fe7c416e6abb28b1398fd3e5687099846800cfd.
Diffstat (limited to 'freebsd/sbin/ifconfig/ifconfig.c')
-rw-r--r-- | freebsd/sbin/ifconfig/ifconfig.c | 452 |
1 files changed, 336 insertions, 116 deletions
diff --git a/freebsd/sbin/ifconfig/ifconfig.c b/freebsd/sbin/ifconfig/ifconfig.c index 041e53d0..ad199be8 100644 --- a/freebsd/sbin/ifconfig/ifconfig.c +++ b/freebsd/sbin/ifconfig/ifconfig.c @@ -1,5 +1,9 @@ #include <machine/rtems-bsd-user-space.h> +#ifdef __rtems__ +#include "rtems-bsd-ifconfig-namespace.h" +#endif /* __rtems__ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -48,28 +52,19 @@ static const char rcsid[] = #define option getopt_option #include <getopt.h> #undef option -#define RTEMS_BSD_PROGRAM_NO_OPEN_WRAP -#define RTEMS_BSD_PROGRAM_NO_SOCKET_WRAP -#define RTEMS_BSD_PROGRAM_NO_CLOSE_WRAP -#define RTEMS_BSD_PROGRAM_NO_FOPEN_WRAP -#define RTEMS_BSD_PROGRAM_NO_FCLOSE_WRAP -#define RTEMS_BSD_PROGRAM_NO_MALLOC_WRAP -#define RTEMS_BSD_PROGRAM_NO_CALLOC_WRAP -#define RTEMS_BSD_PROGRAM_NO_REALLOC_WRAP -#define RTEMS_BSD_PROGRAM_NO_FREE_WRAP #include <machine/rtems-bsd-program.h> #include <machine/rtems-bsd-commands.h> #endif /* __rtems__ */ #include <rtems/bsd/sys/param.h> #include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/time.h> #include <sys/module.h> #include <sys/linker.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/time.h> #include <net/ethernet.h> #include <net/if.h> -#include <net/if_var.h> #include <net/if_dl.h> #include <net/if_types.h> #include <net/route.h> @@ -85,13 +80,18 @@ static const char rcsid[] = #include <err.h> #include <errno.h> #include <fcntl.h> +#ifdef JAIL #include <jail.h> +#endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "ifconfig.h" +#ifdef __rtems__ +#include "rtems-bsd-ifconfig-ifconfig-data.h" +#endif /* __rtems__ */ /* * Since "struct ifreq" is composed of various union members, callers @@ -110,10 +110,14 @@ int clearaddr; int newaddr = 1; int verbose; int noload; +int printifname = 0; int supmedia = 0; int printkeys = 0; /* Print keying material for interfaces. */ +/* Formatter Strings */ +char *f_inet, *f_inet6, *f_ether, *f_addr; + static int ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *afp); static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, @@ -125,8 +129,19 @@ static struct afswtch *af_getbyname(const char *name); static struct afswtch *af_getbyfamily(int af); static void af_other_status(int); +void printifnamemaybe(void); + static struct option *opts = NULL; +struct ifa_order_elt { + int if_order; + int af_orders[255]; + struct ifaddrs *ifa; + TAILQ_ENTRY(ifa_order_elt) link; +}; + +TAILQ_HEAD(ifa_queue, ifa_order_elt); + void opt_register(struct option *p) { @@ -148,8 +163,8 @@ usage(void) } fprintf(stderr, - "usage: ifconfig %sinterface address_family [address [dest_address]]\n" - " [parameters]\n" + "usage: ifconfig [-f type:format] %sinterface address_family\n" + " [address [dest_address]] [parameters]\n" " ifconfig interface create\n" " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" " ifconfig -l [-d] [-u] [address_family]\n" @@ -158,39 +173,241 @@ usage(void) exit(1); } +#define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) + +static int +calcorders(struct ifaddrs *ifa, struct ifa_queue *q) +{ + struct ifaddrs *prev; + struct ifa_order_elt *cur; + unsigned int ord, af, ifa_ord; + + prev = NULL; + cur = NULL; + ord = 0; + ifa_ord = 0; + + while (ifa != NULL) { + if (prev == NULL || + strcmp(ifa->ifa_name, prev->ifa_name) != 0) { + cur = calloc(1, sizeof(*cur)); + + if (cur == NULL) + return (-1); + + TAILQ_INSERT_TAIL(q, cur, link); + cur->if_order = ifa_ord ++; + cur->ifa = ifa; + ord = 0; + } + + if (ifa->ifa_addr) { + af = ifa->ifa_addr->sa_family; + + if (af < ORDERS_SIZE(cur->af_orders) && + cur->af_orders[af] == 0) + cur->af_orders[af] = ++ord; + } + prev = ifa; + ifa = ifa->ifa_next; + } + + return (0); +} + +static int +cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) +{ + struct ifa_order_elt *cur, *e1, *e2; + unsigned int af1, af2; + int ret; + + e1 = e2 = NULL; + + ret = strcmp(a->ifa_name, b->ifa_name); + if (ret != 0) { + TAILQ_FOREACH(cur, q, link) { + if (e1 && e2) + break; + + if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) + e1 = cur; + else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0) + e2 = cur; + } + + if (!e1 || !e2) + return (0); + else + return (e1->if_order - e2->if_order); + + } else if (a->ifa_addr != NULL && b->ifa_addr != NULL) { + TAILQ_FOREACH(cur, q, link) { + if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) { + e1 = cur; + break; + } + } + + if (!e1) + return (0); + + af1 = a->ifa_addr->sa_family; + af2 = b->ifa_addr->sa_family; + + if (af1 < ORDERS_SIZE(e1->af_orders) && + af2 < ORDERS_SIZE(e1->af_orders)) + return (e1->af_orders[af1] - e1->af_orders[af2]); + } + + return (0); +} + +static void freeformat(void) +{ + + if (f_inet != NULL) + free(f_inet); + if (f_inet6 != NULL) + free(f_inet6); + if (f_ether != NULL) + free(f_ether); + if (f_addr != NULL) + free(f_addr); +} + +static void setformat(char *input) +{ + char *formatstr, *category, *modifier; + + formatstr = strdup(input); + while ((category = strsep(&formatstr, ",")) != NULL) { + modifier = strchr(category, ':'); + if (modifier == NULL || modifier[1] == '\0') { + warnx("Skipping invalid format specification: %s\n", + category); + continue; + } + + /* Split the string on the separator, then seek past it */ + modifier[0] = '\0'; + modifier++; + + if (strcmp(category, "addr") == 0) + f_addr = strdup(modifier); + else if (strcmp(category, "ether") == 0) + f_ether = strdup(modifier); + else if (strcmp(category, "inet") == 0) + f_inet = strdup(modifier); + else if (strcmp(category, "inet6") == 0) + f_inet6 = strdup(modifier); + } + free(formatstr); +} + +#undef ORDERS_SIZE + +static struct ifaddrs * +sortifaddrs(struct ifaddrs *list, + int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), + struct ifa_queue *q) +{ + struct ifaddrs *right, *temp, *last, *result, *next, *tail; + + right = list; + temp = list; + last = list; + result = NULL; + next = NULL; + tail = NULL; + + if (!list || !list->ifa_next) + return (list); + + while (temp && temp->ifa_next) { + last = right; + right = right->ifa_next; + temp = temp->ifa_next->ifa_next; + } + + last->ifa_next = NULL; + + list = sortifaddrs(list, compare, q); + right = sortifaddrs(right, compare, q); + + while (list || right) { + + if (!right) { + next = list; + list = list->ifa_next; + } else if (!list) { + next = right; + right = right->ifa_next; + } else if (compare(list, right, q) <= 0) { + next = list; + list = list->ifa_next; + } else { + next = right; + right = right->ifa_next; + } + + if (!result) + result = next; + else + tail->ifa_next = next; + + tail = next; + } + + return (result); +} + +void printifnamemaybe() +{ + if (printifname) + printf("%s\n", name); +} + #ifdef __rtems__ static void ifconfig_ctor(void); -static void ifconfig_dtor(void); static int main(int argc, char *argv[]); -int rtems_bsd_command_ifconfig(int argc, char *argv[]) +static int +mainwrapper(int argc, char *argv[]) { - int exit_code; - - rtems_bsd_program_lock(); - ifconfig_ctor(); - bridge_ctor(); - carp_ctor(); clone_ctor(); gif_ctor(); gre_ctor(); group_ctor(); ifmedia_ctor(); - inet_ctor(); inet6_ctor(); + inet_ctor(); lagg_ctor(); link_ctor(); mac_ctor(); pfsync_ctor(); vlan_ctor(); - exit_code = rtems_bsd_program_call_main("ifconfig", main, argc, argv); + return main(argc, argv); +} + +RTEMS_LINKER_RWSET(bsd_prog_ifconfig, char); + +int +rtems_bsd_command_ifconfig(int argc, char *argv[]) +{ + int exit_code; + const void *data_begin; + size_t data_size; - clone_dtor(); - ifconfig_dtor(); + data_begin = RTEMS_LINKER_SET_BEGIN(bsd_prog_ifconfig); + data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_ifconfig); + rtems_bsd_program_lock(); + exit_code = rtems_bsd_program_call_main_with_data_restore("ifconfig", + mainwrapper, argc, argv, data_begin, data_size); rtems_bsd_program_unlock(); return exit_code; @@ -202,10 +419,12 @@ main(int argc, char *argv[]) int c, all, namesonly, downonly, uponly; const struct afswtch *afp = NULL; int ifindex; - struct ifaddrs *ifap, *ifa; + struct ifaddrs *ifap, *sifap, *ifa; struct ifreq paifr; const struct sockaddr_dl *sdl; - char options[1024], *cp, *namecp = NULL; + char options[1024], *cp, *envformat, *namecp = NULL; + struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q); + struct ifa_order_elt *cur, *tmp; const char *ifname; struct option *p; size_t iflen; @@ -220,12 +439,23 @@ main(int argc, char *argv[]) #endif /* __rtems__ */ all = downonly = uponly = namesonly = noload = verbose = 0; + f_inet = f_inet6 = f_ether = f_addr = NULL; + + envformat = getenv("IFCONFIG_FORMAT"); + if (envformat != NULL) + setformat(envformat); + + /* + * Ensure we print interface name when expected to, + * even if we terminate early due to error. + */ + atexit(printifnamemaybe); /* Parse leading line options */ #ifndef __rtems__ - strlcpy(options, "adklmnuv", sizeof(options)); + strlcpy(options, "f:adklmnuv", sizeof(options)); #else /* __rtems__ */ - strlcpy(options, "+adklmnuv", sizeof(options)); + strlcpy(options, "+f:adklmnuv", sizeof(options)); #endif /* __rtems__ */ for (p = opts; p != NULL; p = p->next) strlcat(options, p->opt, sizeof(options)); @@ -237,6 +467,11 @@ main(int argc, char *argv[]) case 'd': /* restrict scan to "down" interfaces */ downonly++; break; + case 'f': + if (optarg == NULL) + usage(); + setformat(optarg); + break; case 'k': printkeys++; break; @@ -325,6 +560,7 @@ main(int argc, char *argv[]) ifconfig(argc, argv, 1, NULL); exit(0); } +#ifdef JAIL /* * NOTE: We have to special-case the `-vnet' command * right here as we would otherwise fail when trying @@ -338,6 +574,7 @@ main(int argc, char *argv[]) ifconfig(argc, argv, 0, NULL); exit(0); } +#endif errx(1, "interface %s does not exist", ifname); } } @@ -351,11 +588,21 @@ main(int argc, char *argv[]) if (getifaddrs(&ifap) != 0) err(EXIT_FAILURE, "getifaddrs"); + cp = NULL; + + if (calcorders(ifap, &q) != 0) + err(EXIT_FAILURE, "calcorders"); + + sifap = sortifaddrs(ifap, cmpifaddrs, &q); + + TAILQ_FOREACH_SAFE(cur, &q, link, tmp) + free(cur); + ifindex = 0; - for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + for (ifa = sifap; ifa; ifa = ifa->ifa_next) { memset(&paifr, 0, sizeof(paifr)); - strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name)); + strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name)); if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) { memcpy(&paifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); @@ -399,7 +646,8 @@ main(int argc, char *argv[]) sdl->sdl_alen != ETHER_ADDR_LEN) continue; } else { - if (ifa->ifa_addr->sa_family != afp->af_af) + if (ifa->ifa_addr->sa_family + != afp->af_af) continue; } } @@ -421,6 +669,7 @@ main(int argc, char *argv[]) printf("\n"); freeifaddrs(ifap); + freeformat(); exit(0); } @@ -501,7 +750,6 @@ cmd_register(struct cmd *p) static const struct cmd * cmd_lookup(const char *name, int iscreate) { -#define N(a) (sizeof(a)/sizeof(a[0])) const struct cmd *p; for (p = cmds; p != NULL; p = p->c_next) @@ -515,7 +763,6 @@ cmd_lookup(const char *name, int iscreate) } } return NULL; -#undef N } struct callback { @@ -555,7 +802,7 @@ ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp) struct callback *cb; int s; - strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); + strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name); afp = NULL; if (uafp != NULL) afp = uafp; @@ -586,7 +833,7 @@ top: AF_LOCAL : afp->af_af; if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 && - (uafp != NULL || errno != EPROTONOSUPPORT || + (uafp != NULL || errno != EAFNOSUPPORT || (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)) err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family); @@ -676,7 +923,8 @@ top: } if (clearaddr) { int ret; - strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name); + strlcpy(((struct ifreq *)afp->af_ridreq)->ifr_name, name, + sizeof ifr.ifr_name); ret = ioctl(s, afp->af_difaddr, afp->af_ridreq); if (ret < 0) { if (errno == EADDRNOTAVAIL && (doalias >= 0)) { @@ -693,7 +941,8 @@ top: } } if (newaddr && (setaddr || setmask)) { - strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); + strlcpy(((struct ifreq *)afp->af_addreq)->ifr_name, name, + sizeof ifr.ifr_name); if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) Perror("ioctl (SIOCAIFADDR)"); } @@ -735,7 +984,7 @@ settunnel(const char *src, const char *dst, int s, const struct afswtch *afp) errx(1, "error in parsing address string: %s", gai_strerror(ecode)); - if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) + if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) errx(1, "error in parsing address string: %s", gai_strerror(ecode)); @@ -758,7 +1007,7 @@ deletetunnel(const char *vname, int param, int s, const struct afswtch *afp) err(1, "SIOCDIFPHYADDR"); } -#ifndef __rtems__ +#ifdef JAIL static void setifvnet(const char *jname, int dummy __unused, int s, const struct afswtch *afp) @@ -786,7 +1035,7 @@ setifrvnet(const char *jname, int dummy __unused, int s, if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0) err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name); } -#endif /* __rtems__ */ +#endif static void setifnetmask(const char *addr, int dummy __unused, int s, @@ -807,20 +1056,6 @@ setifbroadaddr(const char *addr, int dummy __unused, int s, } static void -setifipdst(const char *addr, int dummy __unused, int s, - const struct afswtch *afp) -{ - const struct afswtch *inet; - - inet = af_getbyname("inet"); - if (inet == NULL) - return; - inet->af_getaddr(addr, DSTADDR); - clearaddr = 0; - newaddr = 0; -} - -static void notealias(const char *addr, int param, int s, const struct afswtch *afp) { #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr)) @@ -903,20 +1138,20 @@ static void setifmetric(const char *val, int dummy __unused, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); ifr.ifr_metric = atoi(val); if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) - warn("ioctl (set metric)"); + err(1, "ioctl SIOCSIFMETRIC (set metric)"); } static void setifmtu(const char *val, int dummy __unused, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); ifr.ifr_mtu = atoi(val); if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0) - warn("ioctl (set mtu)"); + err(1, "ioctl SIOCSIFMTU (set mtu)"); } static void @@ -924,18 +1159,18 @@ setifname(const char *val, int dummy __unused, int s, const struct afswtch *afp) { char *newname; + + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); newname = strdup(val); - if (newname == NULL) { - warn("no memory to set ifname"); - return; - } + if (newname == NULL) + err(1, "no memory to set ifname"); ifr.ifr_data = newname; if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { - warn("ioctl (set name)"); free(newname); - return; + err(1, "ioctl SIOCSIFNAME (set name)"); } + printifname = 1; strlcpy(name, newname, sizeof(name)); free(newname); } @@ -947,6 +1182,8 @@ setifdescr(const char *val, int dummy __unused, int s, { char *newdescr; + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + ifr.ifr_buffer.length = strlen(val) + 1; if (ifr.ifr_buffer.length == 1) { ifr.ifr_buffer.buffer = newdescr = NULL; @@ -961,7 +1198,7 @@ setifdescr(const char *val, int dummy __unused, int s, } if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) - warn("ioctl (set descr)"); + err(1, "ioctl SIOCSIFDESCR (set descr)"); free(newdescr); } @@ -975,7 +1212,7 @@ unsetifdescr(const char *val, int value, int s, const struct afswtch *afp) } #define IFFBITS \ -"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ +"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \ "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ "\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP" @@ -1009,7 +1246,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_LOCAL : afp->af_af; } - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0); if (s < 0) @@ -1091,10 +1328,13 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, else if (afp->af_other_status != NULL) afp->af_other_status(s); - strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name); + strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name); if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) printf("%s", ifs.ascii); + if (verbose > 0) + sfp_status(s, &ifr, verbose); + close(s); return; } @@ -1155,6 +1395,21 @@ printb(const char *s, unsigned v, const char *bits) } void +print_vhid(const struct ifaddrs *ifa, const char *s) +{ + struct if_data *ifd; + + if (ifa->ifa_data == NULL) + return; + + ifd = ifa->ifa_data; + if (ifd->ifi_vhid == 0) + return; + + printf("vhid %d ", ifd->ifi_vhid); +} + +void ifmaybeload(const char *name) { #ifndef __rtems__ @@ -1177,9 +1432,8 @@ ifmaybeload(const char *name) } /* turn interface and unit into module name */ - strcpy(ifkind, "if_"); - strlcpy(ifkind + MOD_PREFIX_LEN, ifname, - sizeof(ifkind) - MOD_PREFIX_LEN); + strlcpy(ifkind, "if_", sizeof(ifkind)); + strlcat(ifkind, ifname, sizeof(ifkind)); /* scan files in kernel */ mstat.version = sizeof(struct module_stat); @@ -1196,8 +1450,8 @@ ifmaybeload(const char *name) cp = mstat.name; } /* already loaded? */ - if (strncmp(ifname, cp, strlen(ifname) + 1) == 0 || - strncmp(ifkind, cp, strlen(ifkind) + 1) == 0) + if (strcmp(ifname, cp) == 0 || + strcmp(ifkind, cp) == 0) return; } } @@ -1233,14 +1487,13 @@ static struct cmd basic_cmds[] = { DEF_CMD_ARG("netmask", setifnetmask), DEF_CMD_ARG("metric", setifmetric), DEF_CMD_ARG("broadcast", setifbroadaddr), - DEF_CMD_ARG("ipdst", setifipdst), DEF_CMD_ARG2("tunnel", settunnel), DEF_CMD("-tunnel", 0, deletetunnel), DEF_CMD("deletetunnel", 0, deletetunnel), -#ifndef __rtems__ +#ifdef JAIL DEF_CMD_ARG("vnet", setifvnet), DEF_CMD_ARG("-vnet", setifrvnet), -#endif /* __rtems__ */ +#endif DEF_CMD("link0", IFF_LINK0, setifflags), DEF_CMD("-link0", -IFF_LINK0, setifflags), DEF_CMD("link1", IFF_LINK1, setifflags), @@ -1288,48 +1541,15 @@ static struct cmd basic_cmds[] = { DEF_CMD_ARG("name", setifname), }; +#ifndef __rtems__ static __constructor void +#else /* __rtems__ */ +static void +#endif /* __rtems__ */ ifconfig_ctor(void) { -#ifdef __rtems__ - memset(&ifr, 0, sizeof(ifr)); - memset(&name, 0, sizeof(name)); - descr = NULL; - descrlen = 64; - setaddr = 0; - setmask = 0; - doalias = 0; - clearaddr = 0; - newaddr = 1; - verbose = 0; - noload = 0; - supmedia = 0; - printkeys = 0; - opts = NULL; - afs = NULL; - callbacks = NULL; - cmds = NULL; -#endif /* __rtems__ */ -#define N(a) (sizeof(a) / sizeof(a[0])) size_t i; - for (i = 0; i < N(basic_cmds); i++) + for (i = 0; i < nitems(basic_cmds); i++) cmd_register(&basic_cmds[i]); -#undef N -} -#ifdef __rtems__ -static void -ifconfig_dtor(void) -{ - struct callback *cb = callbacks; - - while (cb != NULL) { - struct callback *to_free = cb; - - cb = to_free->cb_next; - free(to_free); - } - - free(descr); } -#endif /* __rtems__ */ |