summaryrefslogtreecommitdiffstats
path: root/freebsd/sbin/ifconfig
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-10-07 15:10:20 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-01-10 09:53:31 +0100
commitc40e45b75eb76d79a05c7fa85c1fa9b5c728a12f (patch)
treead4f2519067709f00ab98b3c591186c26dc3a21f /freebsd/sbin/ifconfig
parentuserspace-header-gen.py: Simplify program ports (diff)
downloadrtems-libbsd-c40e45b75eb76d79a05c7fa85c1fa9b5c728a12f.tar.bz2
Update to FreeBSD head 2016-08-23
Git mirror commit 9fe7c416e6abb28b1398fd3e5687099846800cfd.
Diffstat (limited to 'freebsd/sbin/ifconfig')
-rw-r--r--freebsd/sbin/ifconfig/af_inet.c75
-rw-r--r--freebsd/sbin/ifconfig/af_inet6.c170
-rw-r--r--freebsd/sbin/ifconfig/af_link.c30
-rw-r--r--freebsd/sbin/ifconfig/af_nd6.c22
-rw-r--r--freebsd/sbin/ifconfig/ifbridge.c33
-rw-r--r--freebsd/sbin/ifconfig/ifcarp.c10
-rw-r--r--freebsd/sbin/ifconfig/ifclone.c54
-rw-r--r--freebsd/sbin/ifconfig/ifconfig.c452
-rw-r--r--freebsd/sbin/ifconfig/ifconfig.h15
-rw-r--r--freebsd/sbin/ifconfig/ifgif.c25
-rw-r--r--freebsd/sbin/ifconfig/ifgre.c77
-rw-r--r--freebsd/sbin/ifconfig/ifgroup.c52
-rw-r--r--freebsd/sbin/ifconfig/ifieee80211.c26
-rw-r--r--freebsd/sbin/ifconfig/iflagg.c119
-rw-r--r--freebsd/sbin/ifconfig/ifmac.c18
-rw-r--r--freebsd/sbin/ifconfig/ifmedia.c190
-rw-r--r--freebsd/sbin/ifconfig/ifpfsync.c44
-rw-r--r--freebsd/sbin/ifconfig/ifvlan.c56
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet-data.h9
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet6-data.h13
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_link-data.h8
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_nd6-data.h4
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-data.h39
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifbridge-data.h9
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifclone-data.h7
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifconfig-data.h9
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgif-data.h6
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgre-data.h6
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgroup-data.h7
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-iflagg-data.h6
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmac-data.h6
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmedia-data.h29
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifpfsync-data.h6
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifvlan-data.h7
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-namespace.h76
-rw-r--r--freebsd/sbin/ifconfig/rtems-bsd-ifconfig-sfp-data.h15
-rw-r--r--freebsd/sbin/ifconfig/sfp.c935
37 files changed, 2202 insertions, 463 deletions
diff --git a/freebsd/sbin/ifconfig/af_inet.c b/freebsd/sbin/ifconfig/af_inet.c
index 1d713eec..d464df52 100644
--- a/freebsd/sbin/ifconfig/af_inet.c
+++ b/freebsd/sbin/ifconfig/af_inet.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.
@@ -34,7 +38,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
-#include <sys/types.h>
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
+#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
@@ -48,20 +55,25 @@ static const char rcsid[] =
#include <ifaddrs.h>
#include <netinet/in.h>
-#include <net/if_var.h> /* for struct ifaddr */
#include <netinet/in_var.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-af_inet-data.h"
+#endif /* __rtems__ */
static struct in_aliasreq in_addreq;
static struct ifreq in_ridreq;
+static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
+extern char *f_inet, *f_addr;
static void
in_status(int s __unused, const struct ifaddrs *ifa)
{
struct sockaddr_in *sin, null_sin;
+ int error, n_flags;
memset(&null_sin, 0, sizeof(null_sin));
@@ -69,25 +81,56 @@ in_status(int s __unused, const struct ifaddrs *ifa)
if (sin == NULL)
return;
- printf("\tinet %s ", inet_ntoa(sin->sin_addr));
+ if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
+ n_flags = 0;
+ else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
+ n_flags = NI_NOFQDN;
+ else
+ n_flags = NI_NUMERICHOST;
+
+ error = getnameinfo((struct sockaddr *)sin, sin->sin_len, addr_buf,
+ sizeof(addr_buf), NULL, 0, n_flags);
+
+ if (error)
+ inet_ntop(AF_INET, &sin->sin_addr, addr_buf, sizeof(addr_buf));
+
+ printf("\tinet %s", addr_buf);
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
if (sin == NULL)
sin = &null_sin;
- printf("--> %s ", inet_ntoa(sin->sin_addr));
+ printf(" --> %s ", inet_ntoa(sin->sin_addr));
}
sin = (struct sockaddr_in *)ifa->ifa_netmask;
if (sin == NULL)
sin = &null_sin;
- printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr));
+ if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
+ int cidr = 32;
+ unsigned long smask;
+
+ smask = ntohl(sin->sin_addr.s_addr);
+ while ((smask & 1) == 0) {
+ smask = smask >> 1;
+ cidr--;
+ if (cidr == 0)
+ break;
+ }
+ printf("/%d ", cidr);
+ } else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
+ printf(" netmask %s ", inet_ntoa(sin->sin_addr));
+ else
+ printf(" netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr));
if (ifa->ifa_flags & IFF_BROADCAST) {
sin = (struct sockaddr_in *)ifa->ifa_broadaddr;
if (sin != NULL && sin->sin_addr.s_addr != 0)
- printf("broadcast %s", inet_ntoa(sin->sin_addr));
+ printf("broadcast %s ", inet_ntoa(sin->sin_addr));
}
+
+ print_vhid(ifa, " ");
+
putchar('\n');
}
@@ -100,7 +143,6 @@ static struct sockaddr_in *sintab[] = {
static void
in_getaddr(const char *s, int which)
{
-#define MIN(a,b) ((a)<(b)?(a):(b))
struct sockaddr_in *sin = sintab[which];
struct hostent *hp;
struct netent *np;
@@ -117,7 +159,11 @@ in_getaddr(const char *s, int which)
int masklen;
struct sockaddr_in *min = sintab[MASK];
*p = '\0';
+#ifndef __rtems__
+ if (!isdigit(*(p + 1)))
+#else /* __rtems__ */
if (!isdigit((unsigned char)*(p + 1)))
+#endif /* __rtems__ */
errstr = "invalid";
else
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
@@ -134,14 +180,13 @@ in_getaddr(const char *s, int which)
if (inet_aton(s, &sin->sin_addr))
return;
- if ((hp = gethostbyname(s)) != 0)
+ if ((hp = gethostbyname(s)) != NULL)
bcopy(hp->h_addr, (char *)&sin->sin_addr,
MIN((size_t)hp->h_length, sizeof(sin->sin_addr)));
- else if ((np = getnetbyname(s)) != 0)
+ else if ((np = getnetbyname(s)) != NULL)
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
else
errx(1, "%s: bad value", s);
-#undef MIN
}
static void
@@ -153,7 +198,7 @@ in_status_tunnel(int s)
const struct sockaddr *sa = (const struct sockaddr *) &ifr.ifr_addr;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(s, SIOCGIFPSRCADDR, (caddr_t)&ifr) < 0)
return;
@@ -178,7 +223,7 @@ in_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
struct in_aliasreq addreq;
memset(&addreq, 0, sizeof(addreq));
- strncpy(addreq.ifra_name, name, IFNAMSIZ);
+ strlcpy(addreq.ifra_name, name, IFNAMSIZ);
memcpy(&addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len);
@@ -211,11 +256,5 @@ inet_ctor(void)
if (!feature_present("inet"))
return;
#endif
-
-#ifdef __rtems__
- memset(&in_addreq, 0, sizeof(in_addreq));
- memset(&in_ridreq, 0, sizeof(in_ridreq));
-#endif /* __rtems__ */
-
af_register(&af_inet);
}
diff --git a/freebsd/sbin/ifconfig/af_inet6.c b/freebsd/sbin/ifconfig/af_inet6.c
index 0e099ada..f743ee8f 100644
--- a/freebsd/sbin/ifconfig/af_inet6.c
+++ b/freebsd/sbin/ifconfig/af_inet6.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.
@@ -34,6 +38,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -45,12 +52,12 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <time.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <netinet/in.h>
-#include <net/if_var.h> /* for struct ifaddr */
#include <netinet/in_var.h>
#include <arpa/inet.h>
#include <netdb.h>
@@ -58,23 +65,26 @@ static const char rcsid[] =
#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-af_inet6-data.h"
+#endif /* __rtems__ */
static struct in6_ifreq in6_ridreq;
-static struct in6_aliasreq in6_addreq =
- { .ifra_flags = 0,
+static struct in6_aliasreq in6_addreq =
+ { .ifra_flags = 0,
.ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } };
static int ip6lifetime;
-static void in6_fillscopeid(struct sockaddr_in6 *sin6);
static int prefix(void *, int);
static char *sec2str(time_t);
static int explicit_prefix = 0;
+extern char *f_inet6, *f_addr;
extern void setnd6flags(const char *, int, int, const struct afswtch *);
extern void setnd6defif(const char *, int, int, const struct afswtch *);
extern void nd6_status(int);
-static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/
+static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
static void
setifprefixlen(const char *addr, int dummy __unused, int s,
@@ -102,20 +112,21 @@ static void
setip6lifetime(const char *cmd, const char *val, int s,
const struct afswtch *afp)
{
- time_t newval, t;
+ struct timespec now;
+ time_t newval;
char *ep;
- t = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
newval = (time_t)strtoul(val, &ep, 0);
if (val == ep)
errx(1, "invalid %s", cmd);
if (afp->af_af != AF_INET6)
errx(1, "%s not allowed for the AF", cmd);
if (strcmp(cmd, "vltime") == 0) {
- in6_addreq.ifra_lifetime.ia6t_expire = t + newval;
+ in6_addreq.ifra_lifetime.ia6t_expire = now.tv_sec + newval;
in6_addreq.ifra_lifetime.ia6t_vltime = newval;
} else if (strcmp(cmd, "pltime") == 0) {
- in6_addreq.ifra_lifetime.ia6t_preferred = t + newval;
+ in6_addreq.ifra_lifetime.ia6t_preferred = now.tv_sec + newval;
in6_addreq.ifra_lifetime.ia6t_pltime = newval;
}
}
@@ -169,18 +180,6 @@ setip6eui64(const char *cmd, int dummy __unused, int s,
}
static void
-in6_fillscopeid(struct sockaddr_in6 *sin6)
-{
-#if defined(__KAME__) && defined(KAME_SCOPEID)
- if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
- sin6->sin6_scope_id =
- ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
- sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
- }
-#endif
-}
-
-static void
in6_status(int s __unused, const struct ifaddrs *ifa)
{
struct sockaddr_in6 *sin, null_sin;
@@ -188,9 +187,10 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
int s6;
u_int32_t flags6;
struct in6_addrlifetime lifetime;
- time_t t = time(NULL);
- int error;
- u_int32_t scopeid;
+ struct timespec now;
+ int error, n_flags;
+
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
memset(&null_sin, 0, sizeof(null_sin));
@@ -198,7 +198,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if (sin == NULL)
return;
- strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
+ strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
warn("socket(AF_INET6,SOCK_DGRAM)");
return;
@@ -220,24 +220,19 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
lifetime = ifr6.ifr_ifru.ifru_lifetime;
close(s6);
- /* XXX: embedded link local addr check */
- if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
- *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
- u_short index;
-
- index = *(u_short *)&sin->sin6_addr.s6_addr[2];
- *(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
- if (sin->sin6_scope_id == 0)
- sin->sin6_scope_id = ntohs(index);
- }
- scopeid = sin->sin6_scope_id;
-
- error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
- sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
+ if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
+ n_flags = 0;
+ else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
+ n_flags = NI_NOFQDN;
+ else
+ n_flags = NI_NUMERICHOST;
+ error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
+ addr_buf, sizeof(addr_buf), NULL, 0,
+ n_flags);
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
sizeof(addr_buf));
- printf("\tinet6 %s ", addr_buf);
+ printf("\tinet6 %s", addr_buf);
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
@@ -248,17 +243,6 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if (sin != NULL && sin->sin6_family == AF_INET6) {
int error;
- /* XXX: embedded link local addr check */
- if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
- *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
- u_short index;
-
- index = *(u_short *)&sin->sin6_addr.s6_addr[2];
- *(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
- if (sin->sin6_scope_id == 0)
- sin->sin6_scope_id = ntohs(index);
- }
-
error = getnameinfo((struct sockaddr *)sin,
sin->sin6_len, addr_buf,
sizeof(addr_buf), NULL, 0,
@@ -266,15 +250,19 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
sizeof(addr_buf));
- printf("--> %s ", addr_buf);
+ printf(" --> %s ", addr_buf);
}
}
sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
if (sin == NULL)
sin = &null_sin;
- printf("prefixlen %d ", prefix(&sin->sin6_addr,
- sizeof(struct in6_addr)));
+ if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
+ printf("/%d ", prefix(&sin->sin6_addr,
+ sizeof(struct in6_addr)));
+ else
+ printf(" prefixlen %d ", prefix(&sin->sin6_addr,
+ sizeof(struct in6_addr)));
if ((flags6 & IN6_IFF_ANYCAST) != 0)
printf("anycast ");
@@ -293,25 +281,30 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
printf("prefer_source ");
- if (scopeid)
- printf("scopeid 0x%x ", scopeid);
+ if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
+ printf("scopeid 0x%x ",
+ ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
printf("pltime ");
if (lifetime.ia6t_preferred) {
- printf("%s ", lifetime.ia6t_preferred < t
- ? "0" : sec2str(lifetime.ia6t_preferred - t));
+ printf("%s ", lifetime.ia6t_preferred < now.tv_sec
+ ? "0" :
+ sec2str(lifetime.ia6t_preferred - now.tv_sec));
} else
printf("infty ");
printf("vltime ");
if (lifetime.ia6t_expire) {
- printf("%s ", lifetime.ia6t_expire < t
- ? "0" : sec2str(lifetime.ia6t_expire - t));
+ printf("%s ", lifetime.ia6t_expire < now.tv_sec
+ ? "0" :
+ sec2str(lifetime.ia6t_expire - now.tv_sec));
} else
printf("infty ");
}
+ print_vhid(ifa, " ");
+
putchar('\n');
}
@@ -389,25 +382,25 @@ done:
static int
prefix(void *val, int size)
{
- u_char *name = (u_char *)val;
- int byte, bit, plen = 0;
+ u_char *name = (u_char *)val;
+ int byte, bit, plen = 0;
- for (byte = 0; byte < size; byte++, plen += 8)
- if (name[byte] != 0xff)
- break;
+ for (byte = 0; byte < size; byte++, plen += 8)
+ if (name[byte] != 0xff)
+ break;
if (byte == size)
return (plen);
for (bit = 7; bit != 0; bit--, plen++)
- if (!(name[byte] & (1 << bit)))
- break;
- for (; bit != 0; bit--)
- if (name[byte] & (1 << bit))
- return(0);
- byte++;
- for (; byte < size; byte++)
- if (name[byte])
- return(0);
- return (plen);
+ if (!(name[byte] & (1 << bit)))
+ break;
+ for (; bit != 0; bit--)
+ if (name[byte] & (1 << bit))
+ return(0);
+ byte++;
+ for (; byte < size; byte++)
+ if (name[byte])
+ return(0);
+ return (plen);
}
static char *
@@ -464,13 +457,12 @@ in6_status_tunnel(int s)
const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr;
memset(&in6_ifr, 0, sizeof(in6_ifr));
- strncpy(in6_ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name));
if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0)
return;
if (sa->sa_family != AF_INET6)
return;
- in6_fillscopeid(&in6_ifr.ifr_addr);
if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0,
NI_NUMERICHOST) != 0)
src[0] = '\0';
@@ -479,7 +471,6 @@ in6_status_tunnel(int s)
return;
if (sa->sa_family != AF_INET6)
return;
- in6_fillscopeid(&in6_ifr.ifr_addr);
if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0,
NI_NUMERICHOST) != 0)
dst[0] = '\0';
@@ -493,7 +484,7 @@ in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
struct in6_aliasreq in6_addreq;
memset(&in6_addreq, 0, sizeof(in6_addreq));
- strncpy(in6_addreq.ifra_name, name, IFNAMSIZ);
+ strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name));
memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
dstres->ai_addr->sa_len);
@@ -527,6 +518,8 @@ static struct cmd inet6_cmds[] = {
DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags),
DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags),
+ DEF_CMD("no_dad", ND6_IFF_NO_DAD, setnd6flags),
+ DEF_CMD("-no_dad", -ND6_IFF_NO_DAD, setnd6flags),
DEF_CMD_ARG("pltime", setip6pltime),
DEF_CMD_ARG("vltime", setip6vltime),
DEF_CMD("eui64", 0, setip6eui64),
@@ -553,7 +546,11 @@ in6_Lopt_cb(const char *optarg __unused)
{
ip6lifetime++; /* print IPv6 address lifetime */
}
-static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
+static struct option in6_Lopt = {
+ .opt = "L",
+ .opt_usage = "[-L]",
+ .cb = in6_Lopt_cb
+};
#ifndef __rtems__
static __constructor void
@@ -562,16 +559,6 @@ void
#endif /* __rtems__ */
inet6_ctor(void)
{
-#ifdef __rtems__
- memset(&in6_ridreq, 0, sizeof(in6_ridreq));
- memset(&in6_addreq, 0, sizeof(in6_addreq));
- in6_addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
- in6_addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
- ip6lifetime = 0;
- explicit_prefix = 0;
- memset(&addr_buf, 0, sizeof(addr_buf));
-#endif /* __rtems__ */
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
#ifndef RESCUE
@@ -579,9 +566,8 @@ inet6_ctor(void)
return;
#endif
- for (i = 0; i < N(inet6_cmds); i++)
+ for (i = 0; i < nitems(inet6_cmds); i++)
cmd_register(&inet6_cmds[i]);
af_register(&af_inet6);
opt_register(&in6_Lopt);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/af_link.c b/freebsd/sbin/ifconfig/af_link.c
index ffd92e30..1c37496e 100644
--- a/freebsd/sbin/ifconfig/af_link.c
+++ b/freebsd/sbin/ifconfig/af_link.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.
@@ -34,6 +38,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -50,23 +57,35 @@ static const char rcsid[] =
#include <net/ethernet.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-af_link-data.h"
+#endif /* __rtems__ */
static struct ifreq link_ridreq;
+extern char *f_ether;
+
static void
link_status(int s __unused, const struct ifaddrs *ifa)
{
/* XXX no const 'cuz LLADDR is defined wrong */
struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+ char *ether_format, *format_char;
if (sdl != NULL && sdl->sdl_alen > 0) {
if ((sdl->sdl_type == IFT_ETHER ||
sdl->sdl_type == IFT_L2VLAN ||
sdl->sdl_type == IFT_BRIDGE) &&
- sdl->sdl_alen == ETHER_ADDR_LEN)
- printf("\tether %s\n",
- ether_ntoa((struct ether_addr *)LLADDR(sdl)));
- else {
+ sdl->sdl_alen == ETHER_ADDR_LEN) {
+ ether_format = ether_ntoa((struct ether_addr *)LLADDR(sdl));
+ if (f_ether != NULL && strcmp(f_ether, "dash") == 0) {
+ for (format_char = strchr(ether_format, ':');
+ format_char != NULL;
+ format_char = strchr(ether_format, ':'))
+ *format_char = '-';
+ }
+ printf("\tether %s\n", ether_format);
+ } else {
int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
printf("\tlladdr %s\n", link_ntoa(sdl) + n);
@@ -129,9 +148,6 @@ void
#endif /* __rtems__ */
link_ctor(void)
{
-#ifdef __rtems__
- memset(&link_ridreq, 0, sizeof(link_ridreq));
-#endif /* __rtems__ */
af_register(&af_link);
af_register(&af_ether);
af_register(&af_lladdr);
diff --git a/freebsd/sbin/ifconfig/af_nd6.c b/freebsd/sbin/ifconfig/af_nd6.c
index a1e930b0..ac302c65 100644
--- a/freebsd/sbin/ifconfig/af_nd6.c
+++ b/freebsd/sbin/ifconfig/af_nd6.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*
* Copyright (c) 2009 Hiroki Sato. All rights reserved.
*
@@ -30,6 +34,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -48,7 +55,6 @@ static const char rcsid[] =
#include <arpa/inet.h>
#include <netinet/in.h>
-#include <net/if_var.h>
#include <netinet/in_var.h>
#include <arpa/inet.h>
#include <netdb.h>
@@ -56,11 +62,15 @@ static const char rcsid[] =
#include <netinet6/nd6.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-af_nd6-data.h"
+#endif /* __rtems__ */
#define MAX_SYSCTL_TRY 5
#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \
"\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \
- "\007NO_RADR\010NO_PREFER_IFACE\020DEFAULTIF"
+ "\007NO_RADR\010NO_PREFER_IFACE\011IGNORELOOP\012NO_DAD" \
+ "\020DEFAULTIF"
static int isnd6defif(int);
void setnd6flags(const char *, int, int, const struct afswtch *);
@@ -76,7 +86,7 @@ setnd6flags(const char *dummyaddr __unused,
int error;
memset(&nd, 0, sizeof(nd));
- strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
+ strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
error = ioctl(s, SIOCGIFINFO_IN6, &nd);
if (error) {
warn("ioctl(SIOCGIFINFO_IN6)");
@@ -101,7 +111,7 @@ setnd6defif(const char *dummyaddr __unused,
int error;
memset(&ndifreq, 0, sizeof(ndifreq));
- strncpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
+ strlcpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
if (d < 0) {
if (isnd6defif(s)) {
@@ -128,7 +138,7 @@ isnd6defif(int s)
int error;
memset(&ndifreq, 0, sizeof(ndifreq));
- strncpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
+ strlcpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
ifindex = if_nametoindex(ndifreq.ifname);
error = ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq);
@@ -148,7 +158,7 @@ nd6_status(int s)
int isdefif;
memset(&nd, 0, sizeof(nd));
- strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
+ strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
if (errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
warn("socket(AF_INET6, SOCK_DGRAM)");
diff --git a/freebsd/sbin/ifconfig/ifbridge.c b/freebsd/sbin/ifconfig/ifbridge.c
index 9a4d868d..26412a02 100644
--- a/freebsd/sbin/ifconfig/ifbridge.c
+++ b/freebsd/sbin/ifconfig/ifbridge.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
* Copyright 2001 Wasabi Systems, Inc.
* All rights reserved.
@@ -40,6 +44,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -62,6 +69,9 @@ static const char rcsid[] =
#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifbridge-data.h"
+#endif /* __rtems__ */
#define PV2ID(pv, epri, eaddr) do { \
epri = pv >> 48; \
@@ -73,7 +83,7 @@ static const char rcsid[] =
eaddr[5] = pv >> 0; \
} while (0)
-static const char *const stpstates[] = {
+static const char *stpstates[] = {
"disabled",
"listening",
"learning",
@@ -81,12 +91,12 @@ static const char *const stpstates[] = {
"blocking",
"discarding"
};
-static const char *const stpproto[] = {
+static const char *stpproto[] = {
"stp",
"-",
"rstp"
};
-static const char *const stproles[] = {
+static const char *stproles[] = {
"disabled",
"root",
"designated",
@@ -157,7 +167,11 @@ bridge_interfaces(int s, const char *prefix)
err(1, "strdup");
/* replace the prefix with whitespace */
for (p = pad; *p != '\0'; p++) {
+#ifndef __rtems__
+ if(isprint(*p))
+#else /* __rtems__ */
if(isprint((unsigned char)*p))
+#endif /* __rtems__ */
*p = ' ';
}
@@ -187,22 +201,19 @@ bridge_interfaces(int s, const char *prefix)
printf(" path cost %u", req->ifbr_path_cost);
if (req->ifbr_ifsflags & IFBIF_STP) {
- if (req->ifbr_proto <
- sizeof(stpproto) / sizeof(stpproto[0]))
+ if (req->ifbr_proto < nitems(stpproto))
printf(" proto %s", stpproto[req->ifbr_proto]);
else
printf(" <unknown proto %d>",
req->ifbr_proto);
printf("\n%s", pad);
- if (req->ifbr_role <
- sizeof(stproles) / sizeof(stproles[0]))
+ if (req->ifbr_role < nitems(stproles))
printf("role %s", stproles[req->ifbr_role]);
else
printf("<unknown role %d>",
req->ifbr_role);
- if (req->ifbr_state <
- sizeof(stpstates) / sizeof(stpstates[0]))
+ if (req->ifbr_state < nitems(stpstates))
printf(" state %s", stpstates[req->ifbr_state]);
else
printf(" <unknown state %d>",
@@ -755,11 +766,9 @@ void
#endif /* __rtems__ */
bridge_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
int i;
- for (i = 0; i < N(bridge_cmds); i++)
+ for (i = 0; i < nitems(bridge_cmds); i++)
cmd_register(&bridge_cmds[i]);
af_register(&af_bridge);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifcarp.c b/freebsd/sbin/ifconfig/ifcarp.c
index d0f3616d..61e3fa36 100644
--- a/freebsd/sbin/ifconfig/ifcarp.c
+++ b/freebsd/sbin/ifconfig/ifcarp.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/* $FreeBSD$ */
/* from $OpenBSD: ifconfig.c,v 1.82 2003/10/19 05:43:35 mcbride Exp $ */
@@ -29,6 +33,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -51,6 +58,9 @@
#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifcarp-data.h"
+#endif /* __rtems__ */
static const char *const carp_states[] = { CARP_STATES };
diff --git a/freebsd/sbin/ifconfig/ifclone.c b/freebsd/sbin/ifconfig/ifclone.c
index 8fb9d6c3..6dcd344c 100644
--- a/freebsd/sbin/ifconfig/ifclone.c
+++ b/freebsd/sbin/ifconfig/ifclone.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.
@@ -35,20 +39,11 @@ static const char rcsid[] =
#endif /* not lint */
#ifdef __rtems__
-#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>
#endif /* __rtems__ */
-#include <sys/queue.h>
-#include <sys/types.h>
+#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
+#include <sys/queue.h>
#include <sys/socket.h>
#include <net/if.h>
@@ -59,6 +54,9 @@ static const char rcsid[] =
#include <unistd.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifclone-data.h"
+#endif /* __rtems__ */
static void
list_cloners(void)
@@ -84,10 +82,8 @@ list_cloners(void)
ifcr.ifcr_count = ifcr.ifcr_total;
ifcr.ifcr_buffer = buf;
- if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0) {
- free(buf);
+ if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
err(1, "SIOCIFGCLONERS for names");
- }
/*
* In case some disappeared in the mean time, clamp it down.
@@ -111,7 +107,11 @@ struct clone_defcb {
SLIST_ENTRY(clone_defcb) next;
};
+#ifndef __rtems__
static SLIST_HEAD(, clone_defcb) clone_defcbh =
+#else /* __rtems__ */
+static SLIST_HEAD(clone_defcb_list, clone_defcb) clone_defcbh =
+#endif /* __rtems__ */
SLIST_HEAD_INITIALIZER(clone_defcbh);
void
@@ -165,11 +165,12 @@ ifclonecreate(int s, void *arg)
}
/*
- * If we get a different name back than we put in, print it.
+ * If we get a different name back than we put in, update record and
+ * indicate it should be printed later.
*/
if (strncmp(name, ifr.ifr_name, sizeof(name)) != 0) {
strlcpy(name, ifr.ifr_name, sizeof(name));
- printf("%s\n", name);
+ printifname = 1;
}
}
@@ -182,7 +183,7 @@ DECL_CMD_FUNC(clone_create, arg, d)
static
DECL_CMD_FUNC(clone_destroy, arg, d)
{
- (void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
err(1, "SIOCIFDESTROY");
}
@@ -209,26 +210,9 @@ void
#endif /* __rtems__ */
clone_ctor(void)
{
-#ifdef __rtems__
- SLIST_INIT(&clone_defcbh);
-#endif /* __rtems__ */
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(clone_cmds); i++)
+ for (i = 0; i < nitems(clone_cmds); i++)
cmd_register(&clone_cmds[i]);
opt_register(&clone_Copt);
-#undef N
}
-#ifdef __rtems__
-void
-clone_dtor(void)
-{
- struct clone_defcb *dcp;
- struct clone_defcb *dcp_tmp;
-
- SLIST_FOREACH_SAFE(dcp, &clone_defcbh, next, dcp_tmp) {
- free(dcp);
- }
-}
-#endif /* __rtems__ */
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__ */
diff --git a/freebsd/sbin/ifconfig/ifconfig.h b/freebsd/sbin/ifconfig/ifconfig.h
index 074e810e..d9be9c7b 100644
--- a/freebsd/sbin/ifconfig/ifconfig.h
+++ b/freebsd/sbin/ifconfig/ifconfig.h
@@ -34,11 +34,7 @@
* $FreeBSD$
*/
-#ifndef __rtems__
#define __constructor __attribute__((constructor))
-#else /* __rtems__ */
-#define __constructor
-#endif /* __rtems__ */
struct afswtch;
struct cmd;
@@ -78,6 +74,7 @@ void callback_register(callback_func *, void *);
#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 0, NULL }
#define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL }
#define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1, NULL }
+#define DEF_CLONE_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 1, NULL }
struct ifaddrs;
struct addrinfo;
@@ -136,6 +133,7 @@ extern int supmedia;
extern int printkeys;
extern int newaddr;
extern int verbose;
+extern int printifname;
void setifcap(const char *, int value, int s, const struct afswtch *);
@@ -147,19 +145,23 @@ void ifmaybeload(const char *name);
typedef void clone_callback_func(int, struct ifreq *);
void clone_setdefcallback(const char *, clone_callback_func *);
+void sfp_status(int s, struct ifreq *ifr, int verbose);
+
/*
* XXX expose this so modules that neeed to know of any pending
* operations on ifmedia can avoid cmd line ordering confusion.
*/
struct ifmediareq *ifmedia_getstate(int s);
+
+void print_vhid(const struct ifaddrs *, const char *);
#ifdef __rtems__
-void atalk_ctor(void);
void bridge_ctor(void);
void carp_ctor(void);
void clone_ctor(void);
void gif_ctor(void);
void gre_ctor(void);
void group_ctor(void);
+void ieee80211_ctor(void);
void ifmedia_ctor(void);
void inet6_ctor(void);
void inet_ctor(void);
@@ -169,5 +171,6 @@ void mac_ctor(void);
void pfsync_ctor(void);
void vlan_ctor(void);
-void clone_dtor(void);
+/* Necessary for struct ifmedia_description */
+#include <if_media.h>
#endif /* __rtems__ */
diff --git a/freebsd/sbin/ifconfig/ifgif.c b/freebsd/sbin/ifconfig/ifgif.c
index e55933a5..c13a0506 100644
--- a/freebsd/sbin/ifconfig/ifgif.c
+++ b/freebsd/sbin/ifconfig/ifgif.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
* Copyright (c) 2009 Hiroki Sato. All rights reserved.
*
@@ -30,6 +34,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -52,8 +59,11 @@ static const char rcsid[] =
#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifgif-data.h"
+#endif /* __rtems__ */
-#define GIFBITS "\020\1ACCEPT_REV_ETHIP_VER\5SEND_REV_ETHIP_VER"
+#define GIFBITS "\020\2IGNORE_SOURCE"
static void gif_status(int);
@@ -72,8 +82,7 @@ gif_status(int s)
}
static void
-setgifopts(const char *val,
- int d, int s, const struct afswtch *afp)
+setgifopts(const char *val, int d, int s, const struct afswtch *afp)
{
int opts;
@@ -95,10 +104,8 @@ setgifopts(const char *val,
}
static struct cmd gif_cmds[] = {
- DEF_CMD("accept_rev_ethip_ver", GIF_ACCEPT_REVETHIP, setgifopts),
- DEF_CMD("-accept_rev_ethip_ver",-GIF_ACCEPT_REVETHIP, setgifopts),
- DEF_CMD("send_rev_ethip_ver", GIF_SEND_REVETHIP, setgifopts),
- DEF_CMD("-send_rev_ethip_ver", -GIF_SEND_REVETHIP, setgifopts),
+ DEF_CMD("ignore_source", GIF_IGNORE_SOURCE, setgifopts),
+ DEF_CMD("-ignore_source", -GIF_IGNORE_SOURCE, setgifopts),
};
static struct afswtch af_gif = {
@@ -114,11 +121,9 @@ void
#endif /* __rtems__ */
gif_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(gif_cmds); i++)
+ for (i = 0; i < nitems(gif_cmds); i++)
cmd_register(&gif_cmds[i]);
af_register(&af_gif);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifgre.c b/freebsd/sbin/ifconfig/ifgre.c
index 221371f6..6f72a89e 100644
--- a/freebsd/sbin/ifconfig/ifgre.c
+++ b/freebsd/sbin/ifconfig/ifgre.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
* Copyright (c) 2008 Andrew Thompson. All rights reserved.
*
@@ -25,61 +29,92 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sockio.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_gre.h>
-#include <net/route.h>
#include <ctype.h>
+#include <limits.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
+#include <string.h>
#include <err.h>
-#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifgre-data.h"
+#endif /* __rtems__ */
+
+#define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ"
static void gre_status(int s);
static void
gre_status(int s)
{
- int grekey = 0;
+ uint32_t opts = 0;
- ifr.ifr_data = (caddr_t)&grekey;
+ ifr.ifr_data = (caddr_t)&opts;
if (ioctl(s, GREGKEY, &ifr) == 0)
- if (grekey != 0)
- printf("\tgrekey: %d\n", grekey);
+ if (opts != 0)
+ printf("\tgrekey: 0x%x (%u)\n", opts, opts);
+ opts = 0;
+ if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
+ return;
+ printb("\toptions", opts, GREBITS);
+ putchar('\n');
}
static void
setifgrekey(const char *val, int dummy __unused, int s,
const struct afswtch *afp)
{
- uint32_t grekey = atol(val);
+ uint32_t grekey = strtol(val, NULL, 0);
- strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
ifr.ifr_data = (caddr_t)&grekey;
if (ioctl(s, GRESKEY, (caddr_t)&ifr) < 0)
warn("ioctl (set grekey)");
}
+static void
+setifgreopts(const char *val, int d, int s, const struct afswtch *afp)
+{
+ uint32_t opts;
+
+ ifr.ifr_data = (caddr_t)&opts;
+ if (ioctl(s, GREGOPTS, &ifr) == -1) {
+ warn("ioctl(GREGOPTS)");
+ return;
+ }
+
+ if (d < 0)
+ opts &= ~(-d);
+ else
+ opts |= d;
+
+ if (ioctl(s, GRESOPTS, &ifr) == -1) {
+ warn("ioctl(GIFSOPTS)");
+ return;
+ }
+}
+
+
static struct cmd gre_cmds[] = {
DEF_CMD_ARG("grekey", setifgrekey),
+ DEF_CMD("enable_csum", GRE_ENABLE_CSUM, setifgreopts),
+ DEF_CMD("-enable_csum",-GRE_ENABLE_CSUM,setifgreopts),
+ DEF_CMD("enable_seq", GRE_ENABLE_SEQ, setifgreopts),
+ DEF_CMD("-enable_seq",-GRE_ENABLE_SEQ, setifgreopts),
};
static struct afswtch af_gre = {
.af_name = "af_gre",
@@ -94,11 +129,9 @@ void
#endif /* __rtems__ */
gre_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(gre_cmds); i++)
+ for (i = 0; i < nitems(gre_cmds); i++)
cmd_register(&gre_cmds[i]);
af_register(&af_gre);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifgroup.c b/freebsd/sbin/ifconfig/ifgroup.c
index 444a1c22..0e19d4ae 100644
--- a/freebsd/sbin/ifconfig/ifgroup.c
+++ b/freebsd/sbin/ifconfig/ifgroup.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
* Copyright (c) 2006 Max Laier. All rights reserved.
*
@@ -31,18 +35,9 @@ static const char rcsid[] =
#endif /* not lint */
#ifdef __rtems__
-#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>
#endif /* __rtems__ */
-#include <sys/types.h>
+#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
@@ -56,6 +51,9 @@ static const char rcsid[] =
#include <unistd.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifgroup-data.h"
+#endif /* __rtems__ */
/* ARGSUSED */
static void
@@ -66,7 +64,12 @@ setifgroup(const char *group_name, int d, int s, const struct afswtch *rafp)
memset(&ifgr, 0, sizeof(ifgr));
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
- if (group_name[0] && isdigit((unsigned char)group_name[strlen(group_name) - 1]))
+#ifndef __rtems__
+ if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
+#else /* __rtems__ */
+ if (group_name[0] && isdigit(
+ (unsigned char)group_name[strlen(group_name) - 1]))
+#endif /* __rtems__ */
errx(1, "setifgroup: group names may not end in a digit");
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
@@ -84,7 +87,12 @@ unsetifgroup(const char *group_name, int d, int s, const struct afswtch *rafp)
memset(&ifgr, 0, sizeof(ifgr));
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
- if (group_name[0] && isdigit((unsigned char)group_name[strlen(group_name) - 1]))
+#ifndef __rtems__
+ if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
+#else /* __rtems__ */
+ if (group_name[0] && isdigit(
+ (unsigned char)group_name[strlen(group_name) - 1]))
+#endif /* __rtems__ */
errx(1, "unsetifgroup: group names may not end in a digit");
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
@@ -100,9 +108,6 @@ getifgroups(int s)
struct ifgroupreq ifgr;
struct ifg_req *ifg;
- if (!verbose)
- return;
-
memset(&ifgr, 0, sizeof(ifgr));
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
@@ -135,6 +140,8 @@ getifgroups(int s)
}
if (cnt)
printf("\n");
+
+ free(ifgr.ifgr_groups);
}
static void
@@ -151,7 +158,6 @@ printgroup(const char *groupname)
bzero(&ifgr, sizeof(ifgr));
strlcpy(ifgr.ifgr_name, groupname, sizeof(ifgr.ifgr_name));
if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
- close(s);
if (errno == EINVAL || errno == ENOTTY ||
errno == ENOENT)
exit(0);
@@ -160,15 +166,10 @@ printgroup(const char *groupname)
}
len = ifgr.ifgr_len;
- if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) {
- close(s);
+ if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
err(1, "printgroup");
- }
- if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
- free(ifgr.ifgr_groups);
- close(s);
+ if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
err(1, "SIOCGIFGMEMB");
- }
for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req);
ifg++) {
@@ -177,7 +178,6 @@ printgroup(const char *groupname)
cnt++;
}
free(ifgr.ifgr_groups);
- close(s);
exit(0);
}
@@ -200,12 +200,10 @@ void
#endif /* __rtems__ */
group_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
int i;
- for (i = 0; i < N(group_cmds); i++)
+ for (i = 0; i < nitems(group_cmds); i++)
cmd_register(&group_cmds[i]);
af_register(&af_group);
opt_register(&group_gopt);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifieee80211.c b/freebsd/sbin/ifconfig/ifieee80211.c
index 29b49a5b..ead27e2b 100644
--- a/freebsd/sbin/ifconfig/ifieee80211.c
+++ b/freebsd/sbin/ifconfig/ifieee80211.c
@@ -1,3 +1,9 @@
+#include <machine/rtems-bsd-user-space.h>
+
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*
* Copyright 2001 The Aerospace Corporation. All rights reserved.
*
@@ -64,6 +70,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -98,6 +107,9 @@
#include "ifconfig.h"
#include "regdomain.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifieee80211-data.h"
+#endif /* __rtems__ */
#ifndef IEEE80211_FIXED_RATE_NONE
#define IEEE80211_FIXED_RATE_NONE 0xff
@@ -207,12 +219,22 @@ getchaninfo(int s)
gethtconf(s);
}
+#ifdef __rtems__
+static struct regdata *getregdata_rdp = NULL;
+#endif /* __rtems__ */
static struct regdata *
getregdata(void)
{
+#ifndef __rtems__
static struct regdata *rdp = NULL;
+#else /* __rtems__ */
+ struct regdata *rdp = getregdata_rdp;
+#endif /* __rtems__ */
if (rdp == NULL) {
rdp = lib80211_alloc_regdata();
+#ifdef __rtems__
+ getregdata_rdp = rdp;
+#endif /* __rtems__ */
if (rdp == NULL)
errx(-1, "missing or corrupted regdomain database");
}
@@ -5269,7 +5291,11 @@ static struct afswtch af_ieee80211 = {
.af_other_status = ieee80211_status,
};
+#ifndef __rtems__
static __constructor void
+#else /* __rtems__ */
+void
+#endif /* __rtems__ */
ieee80211_ctor(void)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
diff --git a/freebsd/sbin/ifconfig/iflagg.c b/freebsd/sbin/ifconfig/iflagg.c
index 56970e57..78f81fdb 100644
--- a/freebsd/sbin/ifconfig/iflagg.c
+++ b/freebsd/sbin/ifconfig/iflagg.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
*/
@@ -8,6 +12,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -19,6 +26,7 @@ static const char rcsid[] =
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_lagg.h>
+#include <net/ieee8023ad_lacp.h>
#include <net/route.h>
#include <ctype.h>
@@ -30,6 +38,9 @@ static const char rcsid[] =
#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-iflagg-data.h"
+#endif /* __rtems__ */
char lacpbuf[120]; /* LACP peer '[(a,a,a),(p,p,p)]' */
@@ -70,7 +81,7 @@ setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
bzero(&ra, sizeof(ra));
ra.ra_proto = LAGG_PROTO_MAX;
- for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+ for (i = 0; i < nitems(lpr); i++) {
if (strcmp(val, lpr[i].lpr_name) == 0) {
ra.ra_proto = lpr[i].lpr_proto;
break;
@@ -85,6 +96,63 @@ setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
}
static void
+setlaggflowidshift(const char *val, int d, int s, const struct afswtch *afp)
+{
+ struct lagg_reqopts ro;
+
+ bzero(&ro, sizeof(ro));
+ ro.ro_opts = LAGG_OPT_FLOWIDSHIFT;
+ strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+ ro.ro_flowid_shift = (int)strtol(val, NULL, 10);
+ if (ro.ro_flowid_shift & ~LAGG_OPT_FLOWIDSHIFT_MASK)
+ errx(1, "Invalid flowid_shift option: %s", val);
+
+ if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
+ err(1, "SIOCSLAGGOPTS");
+}
+
+static void
+setlaggrr_limit(const char *val, int d, int s, const struct afswtch *afp)
+{
+ struct lagg_reqopts ro;
+
+ bzero(&ro, sizeof(ro));
+ strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+ ro.ro_bkt = (int)strtol(val, NULL, 10);
+
+ if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
+ err(1, "SIOCSLAGG");
+}
+
+static void
+setlaggsetopt(const char *val, int d, int s, const struct afswtch *afp)
+{
+ struct lagg_reqopts ro;
+
+ bzero(&ro, sizeof(ro));
+ ro.ro_opts = d;
+ switch (ro.ro_opts) {
+ case LAGG_OPT_USE_FLOWID:
+ case -LAGG_OPT_USE_FLOWID:
+ case LAGG_OPT_LACP_STRICT:
+ case -LAGG_OPT_LACP_STRICT:
+ case LAGG_OPT_LACP_TXTEST:
+ case -LAGG_OPT_LACP_TXTEST:
+ case LAGG_OPT_LACP_RXTEST:
+ case -LAGG_OPT_LACP_RXTEST:
+ case LAGG_OPT_LACP_TIMEOUT:
+ case -LAGG_OPT_LACP_TIMEOUT:
+ break;
+ default:
+ err(1, "Invalid lagg option");
+ }
+ strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+
+ if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
+ err(1, "SIOCSLAGGOPTS");
+}
+
+static void
setlagghash(const char *val, int d, int s, const struct afswtch *afp)
{
struct lagg_reqflags rf;
@@ -146,6 +214,7 @@ lagg_status(int s)
struct lagg_protos lpr[] = LAGG_PROTOS;
struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
struct lagg_reqall ra;
+ struct lagg_reqopts ro;
struct lagg_reqflags rf;
struct lacp_opreq *lp;
const char *proto = "<unknown>";
@@ -153,6 +222,7 @@ lagg_status(int s)
bzero(&rp, sizeof(rp));
bzero(&ra, sizeof(ra));
+ bzero(&ro, sizeof(ro));
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
@@ -164,6 +234,9 @@ lagg_status(int s)
ra.ra_size = sizeof(rpbuf);
ra.ra_port = rpbuf;
+ strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
+ ioctl(s, SIOCGLAGGOPTS, &ro);
+
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0)
rf.rf_flags = 0;
@@ -171,7 +244,7 @@ lagg_status(int s)
if (ioctl(s, SIOCGLAGG, &ra) == 0) {
lp = (struct lacp_opreq *)&ra.ra_lacpreq;
- for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+ for (i = 0; i < nitems(lpr); i++) {
if (ra.ra_proto == lpr[i].lpr_proto) {
proto = lpr[i].lpr_name;
break;
@@ -199,16 +272,29 @@ lagg_status(int s)
if (isport)
printf(" laggdev %s", rp.rp_ifname);
putchar('\n');
- if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
- printf("\tlag id: %s\n",
- lacp_format_peer(lp, "\n\t\t "));
+ if (verbose) {
+ printf("\tlagg options:\n");
+ printb("\t\tflags", ro.ro_opts, LAGG_OPT_BITS);
+ putchar('\n');
+ printf("\t\tflowid_shift: %d\n", ro.ro_flowid_shift);
+ if (ra.ra_proto == LAGG_PROTO_ROUNDROBIN)
+ printf("\t\trr_limit: %d\n", ro.ro_bkt);
+ printf("\tlagg statistics:\n");
+ printf("\t\tactive ports: %d\n", ro.ro_active);
+ printf("\t\tflapping: %u\n", ro.ro_flapping);
+ if (ra.ra_proto == LAGG_PROTO_LACP) {
+ printf("\tlag id: %s\n",
+ lacp_format_peer(lp, "\n\t\t "));
+ }
+ }
for (i = 0; i < ra.ra_ports; i++) {
lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
printf("\tlaggport: %s ", rpbuf[i].rp_portname);
printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
- printf(" state=%X", lp->actor_state);
+ printb(" state", lp->actor_state,
+ LACP_STATE_BITS);
putchar('\n');
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
printf("\t\t%s\n",
@@ -217,7 +303,7 @@ lagg_status(int s)
if (0 /* XXX */) {
printf("\tsupported aggregation protocols:\n");
- for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++)
+ for (i = 0; i < nitems(lpr); i++)
printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
}
}
@@ -228,6 +314,18 @@ static struct cmd lagg_cmds[] = {
DEF_CMD_ARG("-laggport", unsetlaggport),
DEF_CMD_ARG("laggproto", setlaggproto),
DEF_CMD_ARG("lagghash", setlagghash),
+ DEF_CMD("use_flowid", LAGG_OPT_USE_FLOWID, setlaggsetopt),
+ DEF_CMD("-use_flowid", -LAGG_OPT_USE_FLOWID, setlaggsetopt),
+ DEF_CMD("lacp_strict", LAGG_OPT_LACP_STRICT, setlaggsetopt),
+ DEF_CMD("-lacp_strict", -LAGG_OPT_LACP_STRICT, setlaggsetopt),
+ DEF_CMD("lacp_txtest", LAGG_OPT_LACP_TXTEST, setlaggsetopt),
+ DEF_CMD("-lacp_txtest", -LAGG_OPT_LACP_TXTEST, setlaggsetopt),
+ DEF_CMD("lacp_rxtest", LAGG_OPT_LACP_RXTEST, setlaggsetopt),
+ DEF_CMD("-lacp_rxtest", -LAGG_OPT_LACP_RXTEST, setlaggsetopt),
+ DEF_CMD("lacp_fast_timeout", LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
+ DEF_CMD("-lacp_fast_timeout", -LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
+ DEF_CMD_ARG("flowid_shift", setlaggflowidshift),
+ DEF_CMD_ARG("rr_limit", setlaggrr_limit),
};
static struct afswtch af_lagg = {
.af_name = "af_lagg",
@@ -242,14 +340,9 @@ void
#endif /* __rtems__ */
lagg_ctor(void)
{
-#ifdef __rtems__
- memset(&lacpbuf, 0, sizeof(lacpbuf));
-#endif /* __rtems__ */
-#define N(a) (sizeof(a) / sizeof(a[0]))
int i;
- for (i = 0; i < N(lagg_cmds); i++)
+ for (i = 0; i < nitems(lagg_cmds); i++)
cmd_register(&lagg_cmds[i]);
af_register(&af_lagg);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifmac.c b/freebsd/sbin/ifconfig/ifmac.c
index a64a0cbf..b9aa5eed 100644
--- a/freebsd/sbin/ifconfig/ifmac.c
+++ b/freebsd/sbin/ifconfig/ifmac.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*-
* Copyright (c) 2001 Networks Associates Technology, Inc.
* All rights reserved.
@@ -36,6 +40,9 @@
* $FreeBSD$
*/
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/mac.h>
@@ -50,6 +57,9 @@
#include <string.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifmac-data.h"
+#endif /* __rtems__ */
static void
maclabel_status(int s)
@@ -59,7 +69,7 @@ maclabel_status(int s)
char *label_text;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (mac_prepare_ifnet_label(&label) == -1)
return;
@@ -92,7 +102,7 @@ setifmaclabel(const char *val, int d, int s, const struct afswtch *rafp)
}
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_ifru.ifru_data = (void *)label;
error = ioctl(s, SIOCSIFMAC, &ifr);
@@ -117,11 +127,9 @@ void
#endif /* __rtems__ */
mac_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(mac_cmds); i++)
+ for (i = 0; i < nitems(mac_cmds); i++)
cmd_register(&mac_cmds[i]);
af_register(&af_mac);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifmedia.c b/freebsd/sbin/ifconfig/ifmedia.c
index ba029cb4..890ca8e3 100644
--- a/freebsd/sbin/ifconfig/ifmedia.c
+++ b/freebsd/sbin/ifconfig/ifmedia.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem Exp $ */
/* $FreeBSD$ */
@@ -64,6 +68,9 @@
* SUCH DAMAGE.
*/
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -86,19 +93,37 @@
#include <unistd.h>
#include "ifconfig.h"
+#ifdef __rtems__
+struct ifmedia_type_to_subtype {
+ struct {
+ struct ifmedia_description *desc;
+ int alias;
+ } subtypes[5];
+ struct {
+ struct ifmedia_description *desc;
+ int alias;
+ } options[4];
+ struct {
+ struct ifmedia_description *desc;
+ int alias;
+ } modes[3];
+};
+
+#include "rtems-bsd-ifconfig-ifmedia-data.h"
+#endif /* __rtems__ */
static void domediaopt(const char *, int, int);
static int get_media_subtype(int, const char *);
static int get_media_mode(int, const char *);
static int get_media_options(int, const char *);
-static int lookup_media_word(const struct ifmedia_description *, const char *);
+static int lookup_media_word(struct ifmedia_description *, const char *);
static void print_media_word(int, int);
static void print_media_word_ifconfig(int);
-static const struct ifmedia_description *get_toptype_desc(int);
-static const struct ifmedia_type_to_subtype *get_toptype_ttos(int);
-static const struct ifmedia_description *get_subtype_desc(int,
- const struct ifmedia_type_to_subtype *ttos);
+static struct ifmedia_description *get_toptype_desc(int);
+static struct ifmedia_type_to_subtype *get_toptype_ttos(int);
+static struct ifmedia_description *get_subtype_desc(int,
+ struct ifmedia_type_to_subtype *ttos);
#define IFM_OPMODE(x) \
((x) & (IFM_IEEE80211_ADHOC | IFM_IEEE80211_HOSTAP | \
@@ -111,11 +136,17 @@ media_status(int s)
{
struct ifmediareq ifmr;
int *media_list, i;
+ int xmedia = 1;
(void) memset(&ifmr, 0, sizeof(ifmr));
- (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
+ (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+ /*
+ * Check if interface supports extended media types.
+ */
+ if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
+ xmedia = 0;
+ if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
/*
* Interface doesn't support SIOC{G,S}IFMEDIA.
*/
@@ -132,9 +163,12 @@ media_status(int s)
err(1, "malloc");
ifmr.ifm_ulist = media_list;
- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
- free(media_list);
- err(1, "SIOCGIFMEDIA");
+ if (xmedia) {
+ if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
+ err(1, "SIOCGIFXMEDIA");
+ } else {
+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
+ err(1, "SIOCGIFMEDIA");
}
printf("\tmedia: ");
@@ -194,23 +228,29 @@ media_status(int s)
}
#ifdef __rtems__
-static struct ifmediareq *ifmr = NULL;
+static struct ifmediareq *ifmedia_getstate_ifmr = NULL;
#endif /* __rtems__ */
struct ifmediareq *
ifmedia_getstate(int s)
{
#ifndef __rtems__
static struct ifmediareq *ifmr = NULL;
+#else /* __rtems__ */
+ struct ifmediareq *ifmr = ifmedia_getstate_ifmr;
#endif /* __rtems__ */
int *mwords;
+ int xmedia = 1;
if (ifmr == NULL) {
ifmr = (struct ifmediareq *)malloc(sizeof(struct ifmediareq));
+#ifdef __rtems__
+ ifmedia_getstate_ifmr = ifmr;
+#endif /* __rtems__ */
if (ifmr == NULL)
err(1, "malloc");
(void) memset(ifmr, 0, sizeof(struct ifmediareq));
- (void) strncpy(ifmr->ifm_name, name,
+ (void) strlcpy(ifmr->ifm_name, name,
sizeof(ifmr->ifm_name));
ifmr->ifm_count = 0;
@@ -222,7 +262,10 @@ ifmedia_getstate(int s)
* the current media type and the top-level type.
*/
- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0) {
+ if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0) {
+ xmedia = 0;
+ }
+ if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0) {
err(1, "SIOCGIFMEDIA");
}
@@ -234,8 +277,13 @@ ifmedia_getstate(int s)
err(1, "malloc");
ifmr->ifm_ulist = mwords;
- if (ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0)
- err(1, "SIOCGIFMEDIA");
+ if (xmedia) {
+ if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0)
+ err(1, "SIOCGIFXMEDIA");
+ } else {
+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0)
+ err(1, "SIOCGIFMEDIA");
+ }
}
return ifmr;
@@ -281,7 +329,7 @@ setmedia(const char *val, int d, int s, const struct afswtch *afp)
*/
subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) |
IFM_TYPE(ifmr->ifm_ulist[0]) | subtype;
@@ -313,7 +361,7 @@ domediaopt(const char *val, int clear, int s)
options = get_media_options(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = ifmr->ifm_current;
if (clear)
ifr.ifr_media &= ~options;
@@ -340,7 +388,7 @@ setmediainst(const char *val, int d, int s, const struct afswtch *afp)
if (inst < 0 || inst > (int)IFM_INST_MAX)
errx(1, "invalid media instance: %s", val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
ifmr->ifm_current = ifr.ifr_media;
@@ -357,7 +405,7 @@ setmediamode(const char *val, int d, int s, const struct afswtch *afp)
mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
ifmr->ifm_current = ifr.ifr_media;
@@ -368,89 +416,91 @@ setmediamode(const char *val, int d, int s, const struct afswtch *afp)
* A good chunk of this is duplicated from sys/net/ifmedia.c
**********************************************************************/
-static const struct ifmedia_description ifm_type_descriptions[] =
+static struct ifmedia_description ifm_type_descriptions[] =
IFM_TYPE_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ethernet_descriptions[] =
+static struct ifmedia_description ifm_subtype_ethernet_descriptions[] =
IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ethernet_aliases[] =
+static struct ifmedia_description ifm_subtype_ethernet_aliases[] =
IFM_SUBTYPE_ETHERNET_ALIASES;
-static const struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] =
+static struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] =
IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_tokenring_descriptions[] =
+static struct ifmedia_description ifm_subtype_tokenring_descriptions[] =
IFM_SUBTYPE_TOKENRING_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_tokenring_aliases[] =
+static struct ifmedia_description ifm_subtype_tokenring_aliases[] =
IFM_SUBTYPE_TOKENRING_ALIASES;
-static const struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] =
+static struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] =
IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_fddi_descriptions[] =
+static struct ifmedia_description ifm_subtype_fddi_descriptions[] =
IFM_SUBTYPE_FDDI_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_fddi_aliases[] =
+static struct ifmedia_description ifm_subtype_fddi_aliases[] =
IFM_SUBTYPE_FDDI_ALIASES;
-static const struct ifmedia_description ifm_subtype_fddi_option_descriptions[] =
+static struct ifmedia_description ifm_subtype_fddi_option_descriptions[] =
IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ieee80211_descriptions[] =
+static struct ifmedia_description ifm_subtype_ieee80211_descriptions[] =
IFM_SUBTYPE_IEEE80211_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ieee80211_aliases[] =
+static struct ifmedia_description ifm_subtype_ieee80211_aliases[] =
IFM_SUBTYPE_IEEE80211_ALIASES;
-static const struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[] =
+static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[] =
IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[] =
+struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[] =
IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_ieee80211_mode_aliases[] =
+struct ifmedia_description ifm_subtype_ieee80211_mode_aliases[] =
IFM_SUBTYPE_IEEE80211_MODE_ALIASES;
-static const struct ifmedia_description ifm_subtype_atm_descriptions[] =
+static struct ifmedia_description ifm_subtype_atm_descriptions[] =
IFM_SUBTYPE_ATM_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_atm_aliases[] =
+static struct ifmedia_description ifm_subtype_atm_aliases[] =
IFM_SUBTYPE_ATM_ALIASES;
-static const struct ifmedia_description ifm_subtype_atm_option_descriptions[] =
+static struct ifmedia_description ifm_subtype_atm_option_descriptions[] =
IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_shared_descriptions[] =
+static struct ifmedia_description ifm_subtype_shared_descriptions[] =
IFM_SUBTYPE_SHARED_DESCRIPTIONS;
-static const struct ifmedia_description ifm_subtype_shared_aliases[] =
+static struct ifmedia_description ifm_subtype_shared_aliases[] =
IFM_SUBTYPE_SHARED_ALIASES;
-static const struct ifmedia_description ifm_shared_option_descriptions[] =
+static struct ifmedia_description ifm_shared_option_descriptions[] =
IFM_SHARED_OPTION_DESCRIPTIONS;
static struct ifmedia_description ifm_shared_option_aliases[] =
IFM_SHARED_OPTION_ALIASES;
+#ifndef __rtems__
struct ifmedia_type_to_subtype {
struct {
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
int alias;
} subtypes[5];
struct {
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
int alias;
} options[4];
struct {
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
int alias;
} modes[3];
};
+#endif /* __rtems__ */
/* must be in the same order as IFM_TYPE_DESCRIPTIONS */
-static const struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = {
+static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = {
{
{
{ &ifm_subtype_shared_descriptions[0], 0 },
@@ -548,8 +598,8 @@ static const struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = {
static int
get_media_subtype(int type, const char *val)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
int rval, i;
/* Find the top-level interface type. */
@@ -572,8 +622,8 @@ get_media_subtype(int type, const char *val)
static int
get_media_mode(int type, const char *val)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
int rval, i;
/* Find the top-level interface type. */
@@ -595,8 +645,8 @@ get_media_mode(int type, const char *val)
static int
get_media_options(int type, const char *val)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
char *optlist, *optptr;
int option = 0, i, rval = 0;
@@ -634,7 +684,7 @@ get_media_options(int type, const char *val)
}
static int
-lookup_media_word(const struct ifmedia_description *desc, const char *val)
+lookup_media_word(struct ifmedia_description *desc, const char *val)
{
for (; desc->ifmt_string != NULL; desc++)
@@ -644,9 +694,9 @@ lookup_media_word(const struct ifmedia_description *desc, const char *val)
return (-1);
}
-static const struct ifmedia_description *get_toptype_desc(int ifmw)
+static struct ifmedia_description *get_toptype_desc(int ifmw)
{
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++)
if (IFM_TYPE(ifmw) == desc->ifmt_word)
@@ -655,10 +705,10 @@ static const struct ifmedia_description *get_toptype_desc(int ifmw)
return desc;
}
-static const struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw)
+static struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
desc->ifmt_string != NULL; desc++, ttos++)
@@ -668,11 +718,11 @@ static const struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw)
return ttos;
}
-static const struct ifmedia_description *get_subtype_desc(int ifmw,
- const struct ifmedia_type_to_subtype *ttos)
+static struct ifmedia_description *get_subtype_desc(int ifmw,
+ struct ifmedia_type_to_subtype *ttos)
{
int i;
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
if (ttos->subtypes[i].alias)
@@ -687,11 +737,11 @@ static const struct ifmedia_description *get_subtype_desc(int ifmw,
return NULL;
}
-static const struct ifmedia_description *get_mode_desc(int ifmw,
- const struct ifmedia_type_to_subtype *ttos)
+static struct ifmedia_description *get_mode_desc(int ifmw,
+ struct ifmedia_type_to_subtype *ttos)
{
int i;
- const struct ifmedia_description *desc;
+ struct ifmedia_description *desc;
for (i = 0; ttos->modes[i].desc != NULL; i++) {
if (ttos->modes[i].alias)
@@ -709,8 +759,8 @@ static const struct ifmedia_description *get_mode_desc(int ifmw,
static void
print_media_word(int ifmw, int print_toptype)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
int seen_option = 0, i;
/* Find the top-level interface type. */
@@ -769,8 +819,8 @@ print_media_word(int ifmw, int print_toptype)
static void
print_media_word_ifconfig(int ifmw)
{
- const struct ifmedia_description *desc;
- const struct ifmedia_type_to_subtype *ttos;
+ struct ifmedia_description *desc;
+ struct ifmedia_type_to_subtype *ttos;
int seen_option = 0, i;
/* Find the top-level interface type. */
@@ -843,15 +893,9 @@ void
#endif /* __rtems__ */
ifmedia_ctor(void)
{
-#ifdef __rtems__
- did_it = 0;
- ifmr = NULL;
-#endif /* __rtems__ */
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(media_cmds); i++)
+ for (i = 0; i < nitems(media_cmds); i++)
cmd_register(&media_cmds[i]);
af_register(&af_media);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifpfsync.c b/freebsd/sbin/ifconfig/ifpfsync.c
index ad65e659..162219c8 100644
--- a/freebsd/sbin/ifconfig/ifpfsync.c
+++ b/freebsd/sbin/ifconfig/ifpfsync.c
@@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*
* Copyright (c) 2003 Ryan McBride. All rights reserved.
* Copyright (c) 2004 Max Laier. All rights reserved.
@@ -28,7 +32,10 @@
* $FreeBSD$
*/
-#include <sys/types.h>
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
+#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -47,6 +54,9 @@
#include <unistd.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifpfsync-data.h"
+#endif /* __rtems__ */
void setpfsync_syncdev(const char *, int, int, const struct afswtch *);
void unsetpfsync_syncdev(const char *, int, int, const struct afswtch *);
@@ -54,6 +64,7 @@ void setpfsync_syncpeer(const char *, int, int, const struct afswtch *);
void unsetpfsync_syncpeer(const char *, int, int, const struct afswtch *);
void setpfsync_syncpeer(const char *, int, int, const struct afswtch *);
void setpfsync_maxupd(const char *, int, int, const struct afswtch *);
+void setpfsync_defer(const char *, int, int, const struct afswtch *);
void pfsync_status(int);
void
@@ -164,6 +175,23 @@ setpfsync_maxupd(const char *val, int d, int s, const struct afswtch *rafp)
err(1, "SIOCSETPFSYNC");
}
+/* ARGSUSED */
+void
+setpfsync_defer(const char *val, int d, int s, const struct afswtch *rafp)
+{
+ struct pfsyncreq preq;
+
+ memset((char *)&preq, 0, sizeof(struct pfsyncreq));
+ ifr.ifr_data = (caddr_t)&preq;
+
+ if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
+ err(1, "SIOCGETPFSYNC");
+
+ preq.pfsyncr_defer = d;
+ if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSETPFSYNC");
+}
+
void
pfsync_status(int s)
{
@@ -185,8 +213,10 @@ pfsync_status(int s)
printf("syncpeer: %s ", inet_ntoa(preq.pfsyncr_syncpeer));
if (preq.pfsyncr_syncdev[0] != '\0' ||
- preq.pfsyncr_syncpeer.s_addr != INADDR_PFSYNC_GROUP)
- printf("maxupd: %d\n", preq.pfsyncr_maxupdates);
+ preq.pfsyncr_syncpeer.s_addr != INADDR_PFSYNC_GROUP) {
+ printf("maxupd: %d ", preq.pfsyncr_maxupdates);
+ printf("defer: %s\n", preq.pfsyncr_defer ? "on" : "off");
+ }
}
static struct cmd pfsync_cmds[] = {
@@ -196,7 +226,9 @@ static struct cmd pfsync_cmds[] = {
DEF_CMD("-syncif", 1, unsetpfsync_syncdev),
DEF_CMD_ARG("syncpeer", setpfsync_syncpeer),
DEF_CMD("-syncpeer", 1, unsetpfsync_syncpeer),
- DEF_CMD_ARG("maxupd", setpfsync_maxupd)
+ DEF_CMD_ARG("maxupd", setpfsync_maxupd),
+ DEF_CMD("defer", 1, setpfsync_defer),
+ DEF_CMD("-defer", 0, setpfsync_defer),
};
static struct afswtch af_pfsync = {
.af_name = "af_pfsync",
@@ -211,11 +243,9 @@ void
#endif /* __rtems__ */
pfsync_ctor(void)
{
-#define N(a) (sizeof(a) / sizeof(a[0]))
int i;
- for (i = 0; i < N(pfsync_cmds); i++)
+ for (i = 0; i < nitems(pfsync_cmds); i++)
cmd_register(&pfsync_cmds[i]);
af_register(&af_pfsync);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/ifvlan.c b/freebsd/sbin/ifconfig/ifvlan.c
index 9fc2971d..14350baf 100644
--- a/freebsd/sbin/ifconfig/ifvlan.c
+++ b/freebsd/sbin/ifconfig/ifvlan.c
@@ -1,8 +1,16 @@
#include <machine/rtems-bsd-user-space.h>
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
/*
- * Copyright (c) 1999
- * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ * Copyright (c) 1999 Bill Paul <wpaul@ctr.columbia.edu>
+ * Copyright (c) 2012 ADARA Networks, Inc.
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Robert N. M. Watson under
+ * contract to ADARA Networks, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,6 +40,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -42,7 +53,6 @@
#include <net/ethernet.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/if_vlan_var.h>
#include <net/route.h>
@@ -55,6 +65,9 @@
#include <errno.h>
#include "ifconfig.h"
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-ifvlan-data.h"
+#endif /* __rtems__ */
#ifndef lint
static const char rcsid[] =
@@ -81,10 +94,14 @@ vlan_status(int s)
{
struct vlanreq vreq;
- if (getvlan(s, &ifr, &vreq) != -1)
- printf("\tvlan: %d parent interface: %s\n",
- vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ?
- "<none>" : vreq.vlr_parent);
+ if (getvlan(s, &ifr, &vreq) == -1)
+ return;
+ printf("\tvlan: %d", vreq.vlr_tag);
+ if (ioctl(s, SIOCGVLANPCP, (caddr_t)&ifr) != -1)
+ printf(" vlanpcp: %u", ifr.ifr_vlan_pcp);
+ printf(" parent interface: %s", vreq.vlr_parent[0] == '\0' ?
+ "<none>" : vreq.vlr_parent);
+ printf("\n");
}
static void
@@ -152,6 +169,22 @@ DECL_CMD_FUNC(setvlandev, val, d)
}
static
+DECL_CMD_FUNC(setvlanpcp, val, d)
+{
+ u_long ul;
+ char *endp;
+
+ ul = strtoul(val, &endp, 0);
+ if (*endp != '\0')
+ errx(1, "invalid value for vlanpcp");
+ if (ul > 7)
+ errx(1, "value for vlanpcp out of range");
+ ifr.ifr_vlan_pcp = ul;
+ if (ioctl(s, SIOCSVLANPCP, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSVLANPCP");
+}
+
+static
DECL_CMD_FUNC(unsetvlandev, val, d)
{
struct vlanreq vreq;
@@ -172,6 +205,7 @@ DECL_CMD_FUNC(unsetvlandev, val, d)
static struct cmd vlan_cmds[] = {
DEF_CLONE_CMD_ARG("vlan", setvlantag),
DEF_CLONE_CMD_ARG("vlandev", setvlandev),
+ DEF_CMD_ARG("vlanpcp", setvlanpcp),
/* NB: non-clone cmds */
DEF_CMD_ARG("vlan", setvlantag),
DEF_CMD_ARG("vlandev", setvlandev),
@@ -201,17 +235,11 @@ void
#endif /* __rtems__ */
vlan_ctor(void)
{
-#ifdef __rtems__
- memset(&params, 0, sizeof(params));
- params.vlr_tag = NOTAG;
-#endif /* __rtems__ */
-#define N(a) (sizeof(a) / sizeof(a[0]))
size_t i;
- for (i = 0; i < N(vlan_cmds); i++)
+ for (i = 0; i < nitems(vlan_cmds); i++)
cmd_register(&vlan_cmds[i]);
af_register(&af_vlan);
callback_register(vlan_cb, NULL);
clone_setdefcallback("vlan", vlan_create);
-#undef N
}
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet-data.h
new file mode 100644
index 00000000..962974a0
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet-data.h
@@ -0,0 +1,9 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* af_inet.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct in_aliasreq in_addreq);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifreq in_ridreq);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_inet);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char addr_buf[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct sockaddr_in *sintab[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet6-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet6-data.h
new file mode 100644
index 00000000..6038db41
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_inet6-data.h
@@ -0,0 +1,13 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* af_inet6.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct in6_ifreq in6_ridreq);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct in6_aliasreq in6_addreq);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static int ip6lifetime);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static int explicit_prefix);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_inet6);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct option in6_Lopt);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char addr_buf[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct sockaddr_in6 *sin6tab[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd inet6_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_link-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_link-data.h
new file mode 100644
index 00000000..b5f77c05
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_link-data.h
@@ -0,0 +1,8 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* af_link.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifreq link_ridreq);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_link);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_ether);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_lladdr);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_nd6-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_nd6-data.h
new file mode 100644
index 00000000..5ad9960a
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-af_nd6-data.h
@@ -0,0 +1,4 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* af_nd6.c */
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-data.h
new file mode 100644
index 00000000..d5d6f294
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-data.h
@@ -0,0 +1,39 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+/* af_inet6.c */
+/* af_inet.c */
+/* af_link.c */
+/* af_nd6.c */
+/* ifbridge.c */
+/* ifclone.c */
+/* ifconfig.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int setaddr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern struct ifreq ifr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char name[16]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char *descr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern size_t descrlen);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int setmask);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int doalias);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int clearaddr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int newaddr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int verbose);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int noload);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int printifname);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int supmedia);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern int printkeys);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char *f_inet);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char *f_inet6);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char *f_ether);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char *f_addr);
+/* ifgif.c */
+/* ifgre.c */
+/* ifgroup.c */
+/* iflagg.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern char lacpbuf[120]);
+/* ifmac.c */
+/* ifmedia.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[8]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, extern struct ifmedia_description ifm_subtype_ieee80211_mode_aliases[2]);
+/* ifpfsync.c */
+/* ifvlan.c */
+/* sfp.c */
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifbridge-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifbridge-data.h
new file mode 100644
index 00000000..ba3ee5c6
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifbridge-data.h
@@ -0,0 +1,9 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifbridge.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_bridge);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char const *stpstates[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char const *stpproto[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char const *stproles[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd bridge_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifclone-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifclone-data.h
new file mode 100644
index 00000000..746e12c5
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifclone-data.h
@@ -0,0 +1,7 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifclone.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct clone_defcb_list clone_defcbh);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct option clone_Copt);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd clone_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifconfig-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifconfig-data.h
new file mode 100644
index 00000000..4ce74977
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifconfig-data.h
@@ -0,0 +1,9 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifconfig.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct option *opts);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch *afs);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd *cmds);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct callback *callbacks);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd basic_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgif-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgif-data.h
new file mode 100644
index 00000000..2364de3e
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgif-data.h
@@ -0,0 +1,6 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifgif.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_gif);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd gif_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgre-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgre-data.h
new file mode 100644
index 00000000..af37782d
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgre-data.h
@@ -0,0 +1,6 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifgre.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_gre);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd gre_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgroup-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgroup-data.h
new file mode 100644
index 00000000..3b306f50
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifgroup-data.h
@@ -0,0 +1,7 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifgroup.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_group);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct option group_gopt);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd group_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-iflagg-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-iflagg-data.h
new file mode 100644
index 00000000..64f05f94
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-iflagg-data.h
@@ -0,0 +1,6 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* iflagg.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_lagg);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd lagg_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmac-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmac-data.h
new file mode 100644
index 00000000..c7bc23f2
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmac-data.h
@@ -0,0 +1,6 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifmac.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_mac);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd mac_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmedia-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmedia-data.h
new file mode 100644
index 00000000..a14edd2b
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifmedia-data.h
@@ -0,0 +1,29 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifmedia.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmediareq *ifmedia_getstate_ifmr);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static int did_it);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_media);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_type_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ethernet_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ethernet_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ethernet_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_tokenring_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_tokenring_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_tokenring_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_fddi_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_fddi_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_fddi_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ieee80211_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ieee80211_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_atm_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_atm_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_atm_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_shared_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_subtype_shared_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_shared_option_descriptions[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_description ifm_shared_option_aliases[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd media_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifpfsync-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifpfsync-data.h
new file mode 100644
index 00000000..ad28104a
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifpfsync-data.h
@@ -0,0 +1,6 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifpfsync.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_pfsync);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd pfsync_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifvlan-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifvlan-data.h
new file mode 100644
index 00000000..0d8ffe8a
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-ifvlan-data.h
@@ -0,0 +1,7 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* ifvlan.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct vlanreq params);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct afswtch af_vlan);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct cmd vlan_cmds[]);
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-namespace.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-namespace.h
new file mode 100644
index 00000000..5bf653b8
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-namespace.h
@@ -0,0 +1,76 @@
+/* generated by userspace-header-gen.py */
+/* af_inet6.c */
+#define inet6_ctor _bsd_ifconfig_inet6_ctor
+/* af_inet.c */
+#define inet_ctor _bsd_ifconfig_inet_ctor
+/* af_link.c */
+#define link_ctor _bsd_ifconfig_link_ctor
+/* af_nd6.c */
+#define nd6_status _bsd_ifconfig_nd6_status
+#define setnd6defif _bsd_ifconfig_setnd6defif
+#define setnd6flags _bsd_ifconfig_setnd6flags
+/* ifbridge.c */
+#define bridge_ctor _bsd_ifconfig_bridge_ctor
+/* ifclone.c */
+#define clone_ctor _bsd_ifconfig_clone_ctor
+#define clone_setdefcallback _bsd_ifconfig_clone_setdefcallback
+/* ifconfig.c */
+#define setaddr _bsd_ifconfig_setaddr
+#define ifr _bsd_ifconfig_ifr
+#define name _bsd_ifconfig_name
+#define descr _bsd_ifconfig_descr
+#define descrlen _bsd_ifconfig_descrlen
+#define setmask _bsd_ifconfig_setmask
+#define doalias _bsd_ifconfig_doalias
+#define clearaddr _bsd_ifconfig_clearaddr
+#define newaddr _bsd_ifconfig_newaddr
+#define verbose _bsd_ifconfig_verbose
+#define noload _bsd_ifconfig_noload
+#define printifname _bsd_ifconfig_printifname
+#define supmedia _bsd_ifconfig_supmedia
+#define printkeys _bsd_ifconfig_printkeys
+#define f_inet _bsd_ifconfig_f_inet
+#define f_inet6 _bsd_ifconfig_f_inet6
+#define f_ether _bsd_ifconfig_f_ether
+#define f_addr _bsd_ifconfig_f_addr
+#define ifmaybeload _bsd_ifconfig_ifmaybeload
+#define print_vhid _bsd_ifconfig_print_vhid
+#define printb _bsd_ifconfig_printb
+#define Perror _bsd_ifconfig_Perror
+#define setifcap _bsd_ifconfig_setifcap
+#define callback_register _bsd_ifconfig_callback_register
+#define cmd_register _bsd_ifconfig_cmd_register
+#define af_register _bsd_ifconfig_af_register
+#define printifnamemaybe _bsd_ifconfig_printifnamemaybe
+#define opt_register _bsd_ifconfig_opt_register
+/* ifgif.c */
+#define gif_ctor _bsd_ifconfig_gif_ctor
+/* ifgre.c */
+#define gre_ctor _bsd_ifconfig_gre_ctor
+/* ifgroup.c */
+#define group_ctor _bsd_ifconfig_group_ctor
+/* iflagg.c */
+#define lacpbuf _bsd_ifconfig_lacpbuf
+#define lagg_ctor _bsd_ifconfig_lagg_ctor
+/* ifmac.c */
+#define mac_ctor _bsd_ifconfig_mac_ctor
+/* ifmedia.c */
+#define ifm_subtype_ieee80211_mode_descriptions _bsd_ifconfig_ifm_subtype_ieee80211_mode_descriptions
+#define ifm_subtype_ieee80211_mode_aliases _bsd_ifconfig_ifm_subtype_ieee80211_mode_aliases
+#define ifmedia_ctor _bsd_ifconfig_ifmedia_ctor
+#define ifmedia_getstate _bsd_ifconfig_ifmedia_getstate
+/* ifpfsync.c */
+#define pfsync_ctor _bsd_ifconfig_pfsync_ctor
+#define pfsync_status _bsd_ifconfig_pfsync_status
+#define setpfsync_defer _bsd_ifconfig_setpfsync_defer
+#define setpfsync_maxupd _bsd_ifconfig_setpfsync_maxupd
+#define unsetpfsync_syncpeer _bsd_ifconfig_unsetpfsync_syncpeer
+#define setpfsync_syncpeer _bsd_ifconfig_setpfsync_syncpeer
+#define unsetpfsync_syncdev _bsd_ifconfig_unsetpfsync_syncdev
+#define setpfsync_syncdev _bsd_ifconfig_setpfsync_syncdev
+/* ifvlan.c */
+#define vlan_ctor _bsd_ifconfig_vlan_ctor
+/* sfp.c */
+#define sfp_status _bsd_ifconfig_sfp_status
+#define find_zero_bit _bsd_ifconfig_find_zero_bit
+#define find_value _bsd_ifconfig_find_value
diff --git a/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-sfp-data.h b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-sfp-data.h
new file mode 100644
index 00000000..994d2279
--- /dev/null
+++ b/freebsd/sbin/ifconfig/rtems-bsd-ifconfig-sfp-data.h
@@ -0,0 +1,15 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-ifconfig-data.h"
+/* sfp.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static char const *sff_8024_id[23]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv conn[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv eth_10g[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv eth_compat[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv fc_len[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv cab_tech[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv fc_media[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv fc_speed[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv eth_1040g[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv eth_extended_comp[]);
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_ifconfig, static struct _nv rev_compl[]);
diff --git a/freebsd/sbin/ifconfig/sfp.c b/freebsd/sbin/ifconfig/sfp.c
new file mode 100644
index 00000000..55fb7c7e
--- /dev/null
+++ b/freebsd/sbin/ifconfig/sfp.c
@@ -0,0 +1,935 @@
+#include <machine/rtems-bsd-user-space.h>
+
+#ifdef __rtems__
+#include "rtems-bsd-ifconfig-namespace.h"
+#endif /* __rtems__ */
+
+/*-
+ * Copyright (c) 2014 Alexander V. Chernikov. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static const char rcsid[] =
+ "$FreeBSD$";
+#endif /* not lint */
+
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
+#include <sys/types.h>
+#include <rtems/bsd/sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/sff8436.h>
+#include <net/sff8472.h>
+
+#include <math.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "ifconfig.h"
+#ifdef __rtems__
+struct _nv {
+ int v;
+ const char *n;
+};
+
+#include "rtems-bsd-ifconfig-sfp-data.h"
+#endif /* __rtems__ */
+
+struct i2c_info {
+ int fd; /* fd to issue SIOCGI2C */
+ int error; /* Store first error */
+ int qsfp; /* True if transceiver is QSFP */
+ int do_diag; /* True if we need to request DDM */
+ struct ifreq *ifr; /* Pointer to pre-filled ifreq */
+};
+
+static int read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off,
+ uint8_t len, uint8_t *buf);
+static void dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off,
+ uint8_t len);
+
+#ifndef __rtems__
+struct _nv {
+ int v;
+ const char *n;
+};
+#endif /* __rtems__ */
+
+const char *find_value(struct _nv *x, int value);
+const char *find_zero_bit(struct _nv *x, int value, int sz);
+
+/* SFF-8472 Rev. 11.4 table 3.4: Connector values */
+static struct _nv conn[] = {
+ { 0x00, "Unknown" },
+ { 0x01, "SC" },
+ { 0x02, "Fibre Channel Style 1 copper" },
+ { 0x03, "Fibre Channel Style 2 copper" },
+ { 0x04, "BNC/TNC" },
+ { 0x05, "Fibre Channel coaxial" },
+ { 0x06, "FiberJack" },
+ { 0x07, "LC" },
+ { 0x08, "MT-RJ" },
+ { 0x09, "MU" },
+ { 0x0A, "SG" },
+ { 0x0B, "Optical pigtail" },
+ { 0x0C, "MPO Parallel Optic" },
+ { 0x20, "HSSDC II" },
+ { 0x21, "Copper pigtail" },
+ { 0x22, "RJ45" },
+ { 0x23, "No separate connector" }, /* SFF-8436 */
+ { 0, NULL }
+};
+
+/* SFF-8472 Rev. 11.4 table 3.5: Transceiver codes */
+/* 10G Ethernet/IB compliance codes, byte 3 */
+static struct _nv eth_10g[] = {
+ { 0x80, "10G Base-ER" },
+ { 0x40, "10G Base-LRM" },
+ { 0x20, "10G Base-LR" },
+ { 0x10, "10G Base-SR" },
+ { 0x08, "1X SX" },
+ { 0x04, "1X LX" },
+ { 0x02, "1X Copper Active" },
+ { 0x01, "1X Copper Passive" },
+ { 0, NULL }
+};
+
+/* Ethernet compliance codes, byte 6 */
+static struct _nv eth_compat[] = {
+ { 0x80, "BASE-PX" },
+ { 0x40, "BASE-BX10" },
+ { 0x20, "100BASE-FX" },
+ { 0x10, "100BASE-LX/LX10" },
+ { 0x08, "1000BASE-T" },
+ { 0x04, "1000BASE-CX" },
+ { 0x02, "1000BASE-LX" },
+ { 0x01, "1000BASE-SX" },
+ { 0, NULL }
+};
+
+/* FC link length, byte 7 */
+static struct _nv fc_len[] = {
+ { 0x80, "very long distance" },
+ { 0x40, "short distance" },
+ { 0x20, "intermediate distance" },
+ { 0x10, "long distance" },
+ { 0x08, "medium distance" },
+ { 0, NULL }
+};
+
+/* Channel/Cable technology, byte 7-8 */
+static struct _nv cab_tech[] = {
+ { 0x0400, "Shortwave laser (SA)" },
+ { 0x0200, "Longwave laser (LC)" },
+ { 0x0100, "Electrical inter-enclosure (EL)" },
+ { 0x80, "Electrical intra-enclosure (EL)" },
+ { 0x40, "Shortwave laser (SN)" },
+ { 0x20, "Shortwave laser (SL)" },
+ { 0x10, "Longwave laser (LL)" },
+ { 0x08, "Active Cable" },
+ { 0x04, "Passive Cable" },
+ { 0, NULL }
+};
+
+/* FC Transmission media, byte 9 */
+static struct _nv fc_media[] = {
+ { 0x80, "Twin Axial Pair" },
+ { 0x40, "Twisted Pair" },
+ { 0x20, "Miniature Coax" },
+ { 0x10, "Viao Coax" },
+ { 0x08, "Miltimode, 62.5um" },
+ { 0x04, "Multimode, 50um" },
+ { 0x02, "" },
+ { 0x01, "Single Mode" },
+ { 0, NULL }
+};
+
+/* FC Speed, byte 10 */
+static struct _nv fc_speed[] = {
+ { 0x80, "1200 MBytes/sec" },
+ { 0x40, "800 MBytes/sec" },
+ { 0x20, "1600 MBytes/sec" },
+ { 0x10, "400 MBytes/sec" },
+ { 0x08, "3200 MBytes/sec" },
+ { 0x04, "200 MBytes/sec" },
+ { 0x01, "100 MBytes/sec" },
+ { 0, NULL }
+};
+
+/* SFF-8436 Rev. 4.8 table 33: Specification compliance */
+
+/* 10/40G Ethernet compliance codes, byte 128 + 3 */
+static struct _nv eth_1040g[] = {
+ { 0x80, "Extended" },
+ { 0x40, "10GBASE-LRM" },
+ { 0x20, "10GBASE-LR" },
+ { 0x10, "10GBASE-SR" },
+ { 0x08, "40GBASE-CR4" },
+ { 0x04, "40GBASE-SR4" },
+ { 0x02, "40GBASE-LR4" },
+ { 0x01, "40G Active Cable" },
+ { 0, NULL }
+};
+#define SFF_8636_EXT_COMPLIANCE 0x80
+
+/* SFF-8024 Rev. 3.4 table 4.4: Extended Specification Compliance */
+static struct _nv eth_extended_comp[] = {
+ { 0xFF, "Reserved" },
+ { 0x1A, "2 lambda DWDM 100G" },
+ { 0x19, "100G ACC or 25GAUI C2M ACC" },
+ { 0x18, "100G AOC or 25GAUI C2M AOC" },
+ { 0x17, "100G CLR4" },
+ { 0x16, "10GBASE-T with SFI electrical interface" },
+ { 0x15, "G959.1 profile P1L1-2D2" },
+ { 0x14, "G959.1 profile P1S1-2D2" },
+ { 0x13, "G959.1 profile P1I1-2D1" },
+ { 0x12, "40G PSM4 Parallel SMF" },
+ { 0x11, "4 x 10GBASE-SR" },
+ { 0x10, "40GBASE-ER4" },
+ { 0x0F, "Reserved" },
+ { 0x0D, "25GBASE-CR CA-N" },
+ { 0x0C, "25GBASE-CR CA-S" },
+ { 0x0B, "100GBASE-CR4 or 25GBASE-CR CA-L" },
+ { 0x0A, "Reserved" },
+ { 0x09, "100G CWDM4 MSA without FEC" },
+ { 0x08, "100G ACC (Active Copper Cable)" },
+ { 0x07, "100G PSM4 Parallel SMF" },
+ { 0x06, "100G CWDM4 MSA with FEC" },
+ { 0x05, "100GBASE-SR10" },
+ { 0x04, "100GBASE-ER4" },
+ { 0x03, "100GBASE-LR4" },
+ { 0x02, "100GBASE-SR4" },
+ { 0x01, "100G AOC (Active Optical Cable) or 25GAUI C2M ACC" },
+ { 0x00, "Unspecified" }
+};
+
+/* SFF-8636 Rev. 2.5 table 6.3: Revision compliance */
+static struct _nv rev_compl[] = {
+ { 0x1, "SFF-8436 rev <=4.8" },
+ { 0x2, "SFF-8436 rev <=4.8" },
+ { 0x3, "SFF-8636 rev <=1.3" },
+ { 0x4, "SFF-8636 rev <=1.4" },
+ { 0x5, "SFF-8636 rev <=1.5" },
+ { 0x6, "SFF-8636 rev <=2.0" },
+ { 0x7, "SFF-8636 rev <=2.5" },
+ { 0x0, "Unspecified" }
+};
+
+const char *
+find_value(struct _nv *x, int value)
+{
+ for (; x->n != NULL; x++)
+ if (x->v == value)
+ return (x->n);
+ return (NULL);
+}
+
+const char *
+find_zero_bit(struct _nv *x, int value, int sz)
+{
+ int v, m;
+ const char *s;
+
+ v = 1;
+ for (v = 1, m = 1 << (8 * sz); v < m; v *= 2) {
+ if ((value & v) == 0)
+ continue;
+ if ((s = find_value(x, value & v)) != NULL) {
+ value &= ~v;
+ return (s);
+ }
+ }
+
+ return (NULL);
+}
+
+static void
+convert_sff_identifier(char *buf, size_t size, uint8_t value)
+{
+ const char *x;
+
+ x = NULL;
+ if (value <= SFF_8024_ID_LAST)
+ x = sff_8024_id[value];
+ else {
+ if (value > 0x80)
+ x = "Vendor specific";
+ else
+ x = "Reserved";
+ }
+
+ snprintf(buf, size, "%s", x);
+}
+
+static void
+convert_sff_connector(char *buf, size_t size, uint8_t value)
+{
+ const char *x;
+
+ if ((x = find_value(conn, value)) == NULL) {
+ if (value >= 0x0D && value <= 0x1F)
+ x = "Unallocated";
+ else if (value >= 0x24 && value <= 0x7F)
+ x = "Unallocated";
+ else
+ x = "Vendor specific";
+ }
+
+ snprintf(buf, size, "%s", x);
+}
+
+static void
+convert_sff_rev_compliance(char *buf, size_t size, uint8_t value)
+{
+ const char *x;
+
+ if (value > 0x07)
+ x = "Unallocated";
+ else
+ x = find_value(rev_compl, value);
+
+ snprintf(buf, size, "%s", x);
+}
+
+static void
+get_sfp_identifier(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t data;
+
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_ID, 1, &data);
+ convert_sff_identifier(buf, size, data);
+}
+
+static void
+get_sfp_connector(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t data;
+
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_CONNECTOR, 1, &data);
+ convert_sff_connector(buf, size, data);
+}
+
+static void
+get_qsfp_identifier(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t data;
+
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_ID, 1, &data);
+ convert_sff_identifier(buf, size, data);
+}
+
+static void
+get_qsfp_connector(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t data;
+
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_CONNECTOR, 1, &data);
+ convert_sff_connector(buf, size, data);
+}
+
+static void
+printf_sfp_transceiver_descr(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[12];
+ const char *tech_class, *tech_len, *tech_tech, *tech_media, *tech_speed;
+
+ tech_class = NULL;
+ tech_len = NULL;
+ tech_tech = NULL;
+ tech_media = NULL;
+ tech_speed = NULL;
+
+ /* Read bytes 3-10 at once */
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, &xbuf[3]);
+
+ /* Check 10G ethernet first */
+ tech_class = find_zero_bit(eth_10g, xbuf[3], 1);
+ if (tech_class == NULL) {
+ /* No match. Try 1G */
+ tech_class = find_zero_bit(eth_compat, xbuf[6], 1);
+ }
+
+ tech_len = find_zero_bit(fc_len, xbuf[7], 1);
+ tech_tech = find_zero_bit(cab_tech, xbuf[7] << 8 | xbuf[8], 2);
+ tech_media = find_zero_bit(fc_media, xbuf[9], 1);
+ tech_speed = find_zero_bit(fc_speed, xbuf[10], 1);
+
+ printf("Class: %s\n", tech_class);
+ printf("Length: %s\n", tech_len);
+ printf("Tech: %s\n", tech_tech);
+ printf("Media: %s\n", tech_media);
+ printf("Speed: %s\n", tech_speed);
+}
+
+static void
+get_sfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
+{
+ const char *tech_class;
+ uint8_t code;
+
+ unsigned char qbuf[8];
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, (uint8_t *)qbuf);
+
+ /* Check 10G Ethernet/IB first */
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 1, &code);
+ tech_class = find_zero_bit(eth_10g, code, 1);
+ if (tech_class == NULL) {
+ /* No match. Try Ethernet 1G */
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START + 3,
+ 1, (caddr_t)&code);
+ tech_class = find_zero_bit(eth_compat, code, 1);
+ }
+
+ if (tech_class == NULL)
+ tech_class = "Unknown";
+
+ snprintf(buf, size, "%s", tech_class);
+}
+
+static void
+get_qsfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
+{
+ const char *tech_class;
+ uint8_t code;
+
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_CODE_E1040100G, 1, &code);
+
+ /* Check for extended specification compliance */
+ if (code & SFF_8636_EXT_COMPLIANCE) {
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_OPTIONS_START, 1, &code);
+ tech_class = find_value(eth_extended_comp, code);
+ } else
+ /* Check 10/40G Ethernet class only */
+ tech_class = find_zero_bit(eth_1040g, code, 1);
+
+ if (tech_class == NULL)
+ tech_class = "Unknown";
+
+ snprintf(buf, size, "%s", tech_class);
+}
+
+/*
+ * Print SFF-8472/SFF-8436 string to supplied buffer.
+ * All (vendor-specific) strings are padded right with '0x20'.
+ */
+static void
+convert_sff_name(char *buf, size_t size, char *xbuf)
+{
+ char *p;
+
+ for (p = &xbuf[16]; *(p - 1) == 0x20; p--)
+ ;
+ *p = '\0';
+ snprintf(buf, size, "%s", xbuf);
+}
+
+static void
+convert_sff_date(char *buf, size_t size, char *xbuf)
+{
+
+ snprintf(buf, size, "20%c%c-%c%c-%c%c", xbuf[0], xbuf[1],
+ xbuf[2], xbuf[3], xbuf[4], xbuf[5]);
+}
+
+static void
+get_sfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_VENDOR_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_sfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_PN_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_sfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_SN_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_sfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[6];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ /* Date code, see Table 3.8 for description */
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_DATE_START, 6, (uint8_t *)xbuf);
+ convert_sff_date(buf, size, xbuf);
+}
+
+static void
+get_qsfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_VENDOR_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_qsfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_PN_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_qsfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[17];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_SN_START, 16, (uint8_t *)xbuf);
+ convert_sff_name(buf, size, xbuf);
+}
+
+static void
+get_qsfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[6];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_DATE_START, 6, (uint8_t *)xbuf);
+ convert_sff_date(buf, size, xbuf);
+}
+
+static void
+print_sfp_vendor(struct i2c_info *ii, char *buf, size_t size)
+{
+ char xbuf[80];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ if (ii->qsfp != 0) {
+ get_qsfp_vendor_name(ii, xbuf, 20);
+ get_qsfp_vendor_pn(ii, &xbuf[20], 20);
+ get_qsfp_vendor_sn(ii, &xbuf[40], 20);
+ get_qsfp_vendor_date(ii, &xbuf[60], 20);
+ } else {
+ get_sfp_vendor_name(ii, xbuf, 20);
+ get_sfp_vendor_pn(ii, &xbuf[20], 20);
+ get_sfp_vendor_sn(ii, &xbuf[40], 20);
+ get_sfp_vendor_date(ii, &xbuf[60], 20);
+ }
+
+ snprintf(buf, size, "vendor: %s PN: %s SN: %s DATE: %s",
+ xbuf, &xbuf[20], &xbuf[40], &xbuf[60]);
+}
+
+/*
+ * Converts internal templerature (SFF-8472, SFF-8436)
+ * 16-bit unsigned value to human-readable representation:
+ *
+ * Internally measured Module temperature are represented
+ * as a 16-bit signed twos complement value in increments of
+ * 1/256 degrees Celsius, yielding a total range of –128C to +128C
+ * that is considered valid between –40 and +125C.
+ *
+ */
+static void
+convert_sff_temp(char *buf, size_t size, uint8_t *xbuf)
+{
+ double d;
+
+ d = (double)xbuf[0];
+ d += (double)xbuf[1] / 256;
+
+ snprintf(buf, size, "%.2f C", d);
+}
+
+/*
+ * Retrieves supplied voltage (SFF-8472, SFF-8436).
+ * 16-bit usigned value, treated as range 0..+6.55 Volts
+ */
+static void
+convert_sff_voltage(char *buf, size_t size, uint8_t *xbuf)
+{
+ double d;
+
+ d = (double)((xbuf[0] << 8) | xbuf[1]);
+ snprintf(buf, size, "%.2f Volts", d / 10000);
+}
+
+/*
+ * Converts value in @xbuf to both milliwats and dBm
+ * human representation.
+ */
+static void
+convert_sff_power(struct i2c_info *ii, char *buf, size_t size, uint8_t *xbuf)
+{
+ uint16_t mW;
+ double dbm;
+
+ mW = (xbuf[0] << 8) + xbuf[1];
+
+ /* Convert mw to dbm */
+ dbm = 10.0 * log10(1.0 * mW / 10000);
+
+ /*
+ * Assume internally-calibrated data.
+ * This is always true for SFF-8346, and explicitly
+ * checked for SFF-8472.
+ */
+
+ /* Table 3.9, bit 5 is set, internally calibrated */
+ snprintf(buf, size, "%d.%02d mW (%.2f dBm)",
+ mW / 10000, (mW % 10000) / 100, dbm);
+}
+
+static void
+get_sfp_temp(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_DIAG, SFF_8472_TEMP, 2, xbuf);
+ convert_sff_temp(buf, size, xbuf);
+}
+
+static void
+get_sfp_voltage(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_DIAG, SFF_8472_VCC, 2, xbuf);
+ convert_sff_voltage(buf, size, xbuf);
+}
+
+static int
+get_qsfp_temp(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_TEMP, 2, xbuf);
+ if ((xbuf[0] == 0xFF && xbuf[1] == 0xFF) || (xbuf[0] == 0 && xbuf[1] == 0))
+ return (-1);
+ convert_sff_temp(buf, size, xbuf);
+ return (0);
+}
+
+static void
+get_qsfp_voltage(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_VCC, 2, xbuf);
+ convert_sff_voltage(buf, size, xbuf);
+}
+
+static void
+get_sfp_rx_power(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_DIAG, SFF_8472_RX_POWER, 2, xbuf);
+ convert_sff_power(ii, buf, size, xbuf);
+}
+
+static void
+get_sfp_tx_power(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8472_DIAG, SFF_8472_TX_POWER, 2, xbuf);
+ convert_sff_power(ii, buf, size, xbuf);
+}
+
+static void
+get_qsfp_rx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_RX_CH1_MSB + (chan-1)*2, 2, xbuf);
+ convert_sff_power(ii, buf, size, xbuf);
+}
+
+static void
+get_qsfp_tx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
+{
+ uint8_t xbuf[2];
+
+ memset(xbuf, 0, sizeof(xbuf));
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan-1)*2, 2, xbuf);
+ convert_sff_power(ii, buf, size, xbuf);
+}
+
+static void
+get_qsfp_rev_compliance(struct i2c_info *ii, char *buf, size_t size)
+{
+ uint8_t xbuf;
+
+ xbuf = 0;
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_STATUS, 1, &xbuf);
+ convert_sff_rev_compliance(buf, size, xbuf);
+}
+
+static uint32_t
+get_qsfp_br(struct i2c_info *ii)
+{
+ uint8_t xbuf;
+ uint32_t rate;
+
+ xbuf = 0;
+ read_i2c(ii, SFF_8436_BASE, SFF_8436_BITRATE, 1, &xbuf);
+ rate = xbuf * 100;
+ if (xbuf == 0xFF) {
+ read_i2c(ii, SFF_8436_BASE, SFF_8636_BITRATE, 1, &xbuf);
+ rate = xbuf * 250;
+ }
+
+ return (rate);
+}
+
+/*
+ * Reads i2c data from opened kernel socket.
+ */
+static int
+read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
+ uint8_t *buf)
+{
+ struct ifi2creq req;
+ int i, l;
+
+ if (ii->error != 0)
+ return (ii->error);
+
+ ii->ifr->ifr_data = (caddr_t)&req;
+
+ i = 0;
+ l = 0;
+ memset(&req, 0, sizeof(req));
+ req.dev_addr = addr;
+ req.offset = off;
+ req.len = len;
+
+ while (len > 0) {
+ l = MIN(sizeof(req.data), len);
+ req.len = l;
+ if (ioctl(ii->fd, SIOCGI2C, ii->ifr) != 0) {
+ ii->error = errno;
+ return (errno);
+ }
+
+ memcpy(&buf[i], req.data, l);
+ len -= l;
+ i += l;
+ req.offset += l;
+ }
+
+ return (0);
+}
+
+static void
+dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len)
+{
+ unsigned char buf[16];
+ int i, read;
+
+ while (len > 0) {
+ memset(buf, 0, sizeof(buf));
+ read = MIN(sizeof(buf), len);
+ read_i2c(ii, addr, off, read, buf);
+ if (ii->error != 0) {
+ fprintf(stderr, "Error reading i2c info\n");
+ return;
+ }
+
+ printf("\t");
+ for (i = 0; i < read; i++)
+ printf("%02X ", buf[i]);
+ printf("\n");
+ len -= read;
+ off += read;
+ }
+}
+
+static void
+print_qsfp_status(struct i2c_info *ii, int verbose)
+{
+ char buf[80], buf2[40], buf3[40];
+ uint32_t bitrate;
+ int i;
+
+ ii->qsfp = 1;
+
+ /* Transceiver type */
+ get_qsfp_identifier(ii, buf, sizeof(buf));
+ get_qsfp_transceiver_class(ii, buf2, sizeof(buf2));
+ get_qsfp_connector(ii, buf3, sizeof(buf3));
+ if (ii->error == 0)
+ printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
+ print_sfp_vendor(ii, buf, sizeof(buf));
+ if (ii->error == 0)
+ printf("\t%s\n", buf);
+
+ if (verbose > 1) {
+ get_qsfp_rev_compliance(ii, buf, sizeof(buf));
+ if (ii->error == 0)
+ printf("\tcompliance level: %s\n", buf);
+
+ bitrate = get_qsfp_br(ii);
+ if (ii->error == 0 && bitrate > 0)
+ printf("\tnominal bitrate: %u Mbps\n", bitrate);
+ }
+
+ /*
+ * The standards in this area are not clear when the
+ * additional measurements are present or not. Use a valid
+ * temperature reading as an indicator for the presence of
+ * voltage and TX/RX power measurements.
+ */
+ if (get_qsfp_temp(ii, buf, sizeof(buf)) == 0) {
+ get_qsfp_voltage(ii, buf2, sizeof(buf2));
+ printf("\tmodule temperature: %s voltage: %s\n", buf, buf2);
+ for (i = 1; i <= 4; i++) {
+ get_qsfp_rx_power(ii, buf, sizeof(buf), i);
+ get_qsfp_tx_power(ii, buf2, sizeof(buf2), i);
+ printf("\tlane %d: RX: %s TX: %s\n", i, buf, buf2);
+ }
+ }
+
+ if (verbose > 2) {
+ printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
+ dump_i2c_data(ii, SFF_8436_BASE, 128, 128);
+ printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
+ dump_i2c_data(ii, SFF_8436_BASE, 0, 82);
+ }
+}
+
+static void
+print_sfp_status(struct i2c_info *ii, int verbose)
+{
+ char buf[80], buf2[40], buf3[40];
+ uint8_t diag_type, flags;
+
+ /* Read diagnostic monitoring type */
+ read_i2c(ii, SFF_8472_BASE, SFF_8472_DIAG_TYPE, 1, (caddr_t)&diag_type);
+ if (ii->error != 0)
+ return;
+
+ /*
+ * Read monitoring data IFF it is supplied AND is
+ * internally calibrated
+ */
+ flags = SFF_8472_DDM_DONE | SFF_8472_DDM_INTERNAL;
+ if ((diag_type & flags) == flags)
+ ii->do_diag = 1;
+
+ /* Transceiver type */
+ get_sfp_identifier(ii, buf, sizeof(buf));
+ get_sfp_transceiver_class(ii, buf2, sizeof(buf2));
+ get_sfp_connector(ii, buf3, sizeof(buf3));
+ if (ii->error == 0)
+ printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
+ print_sfp_vendor(ii, buf, sizeof(buf));
+ if (ii->error == 0)
+ printf("\t%s\n", buf);
+
+ if (verbose > 5)
+ printf_sfp_transceiver_descr(ii, buf, sizeof(buf));
+ /*
+ * Request current measurements iff they are provided:
+ */
+ if (ii->do_diag != 0) {
+ get_sfp_temp(ii, buf, sizeof(buf));
+ get_sfp_voltage(ii, buf2, sizeof(buf2));
+ printf("\tmodule temperature: %s Voltage: %s\n", buf, buf2);
+ get_sfp_rx_power(ii, buf, sizeof(buf));
+ get_sfp_tx_power(ii, buf2, sizeof(buf2));
+ printf("\tRX: %s TX: %s\n", buf, buf2);
+ }
+
+ if (verbose > 2) {
+ printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
+ dump_i2c_data(ii, SFF_8472_BASE, 0, 128);
+ }
+}
+
+void
+sfp_status(int s, struct ifreq *ifr, int verbose)
+{
+ struct i2c_info ii;
+ uint8_t id_byte;
+
+ /* Prepare necessary into pass to i2c reader */
+ memset(&ii, 0, sizeof(ii));
+ ii.fd = s;
+ ii.ifr = ifr;
+
+ /*
+ * Try to read byte 0 from i2c:
+ * Both SFF-8472 and SFF-8436 use it as
+ * 'identification byte'.
+ * Stop reading status on zero as value -
+ * this might happen in case of empty transceiver slot.
+ */
+ id_byte = 0;
+ read_i2c(&ii, SFF_8472_BASE, SFF_8472_ID, 1, (caddr_t)&id_byte);
+ if (ii.error != 0 || id_byte == 0)
+ return;
+
+ switch (id_byte) {
+ case SFF_8024_ID_QSFP:
+ case SFF_8024_ID_QSFPPLUS:
+ case SFF_8024_ID_QSFP28:
+ print_qsfp_status(&ii, verbose);
+ break;
+ default:
+ print_sfp_status(&ii, verbose);
+ }
+}
+