Page MenuHomeFreeBSD

D58560.id.diff
No OneTemporary

D58560.id.diff

This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -35,7 +35,7 @@
SRCS+= ifipsec.c # IPsec VTI
SRCS+= sfp.c # SFP/SFP+ information
-LIBADD+= ifconfig m util
+LIBADD+= ifconfig m util xo
CFLAGS+= -I${SRCTOP}/lib/libifconfig -I${OBJTOP}/lib/libifconfig
.if ${MK_WIRELESS_SUPPORT} != "no"
@@ -52,6 +52,8 @@
SRCS+= ifbridge.c # bridge support
SRCS+= iflagg.c # lagg support
+SRCS+= ifconfig_output.c # Console/print support
+
.if ${MK_INET6_SUPPORT} != "no"
CFLAGS+= -DINET6
.endif
diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -49,6 +49,7 @@
#include "ifconfig.h"
#include "ifconfig_netlink.h"
+#include "ifconfig_output.h"
#ifdef WITHOUT_NETLINK
static struct in_aliasreq in_addreq;
@@ -70,30 +71,8 @@
static struct in_pdata in_add, in_del;
#endif
-static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
extern char *f_inet, *f_addr;
-static void
-print_addr(struct sockaddr_in *sin)
-{
- int error, n_flags;
-
- 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);
-}
-
#ifdef WITHOUT_NETLINK
static void
in_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
@@ -104,13 +83,13 @@
if (sin == NULL)
return;
- print_addr(sin);
+ af_inet_print_addr(sin);
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = satosin(ifa->ifa_dstaddr);
if (sin == NULL)
sin = &null_sin;
- printf(" --> %s", inet_ntoa(sin->sin_addr));
+ af_inet_print_addr_pointtopoint(sin);
}
sin = satosin(ifa->ifa_netmask);
@@ -127,21 +106,21 @@
if (cidr == 0)
break;
}
- printf("/%d", cidr);
+ af_inet_print_cidr_mask(cidr);
} else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
- printf(" netmask %s", inet_ntoa(sin->sin_addr));
+ af_inet_print_netmask_str(sin->sin_addr);
else
- printf(" netmask 0x%lx", (unsigned long)ntohl(sin->sin_addr.s_addr));
+ af_inet_print_netmask(sin->sin_addr);
if (ifa->ifa_flags & IFF_BROADCAST) {
sin = satosin(ifa->ifa_broadaddr);
if (sin != NULL && sin->sin_addr.s_addr != 0)
- printf(" broadcast %s", inet_ntoa(sin->sin_addr));
+ af_inet_print_broadcast(sin);
}
print_vhid(ifa);
- putchar('\n');
+ ifconfig_print_newline();
}
#else
@@ -161,30 +140,30 @@
struct sockaddr_in *sin = satosin(ifa->ifa_local);
int plen = ifa->ifa_prefixlen;
- print_addr(sin);
+ af_inet_print_addr(sin);
if (link->ifi_flags & IFF_POINTOPOINT) {
struct sockaddr_in *dst = satosin(ifa->ifa_address);
- printf(" --> %s", inet_ntoa(dst->sin_addr));
+ af_inet_print_addr_pointtopoint(dst);
}
if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
- printf("/%d", plen);
+ af_inet_print_cidr_mask(plen);
} else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
- printf(" netmask %s", inet_ntoa(get_mask(plen)));
+ af_inet_print_netmask_str(get_mask(plen));
else
- printf(" netmask 0x%lx", (unsigned long)ntohl(get_mask(plen).s_addr));
+ af_inet_print_netmask(get_mask(plen));
if ((link->ifi_flags & IFF_BROADCAST) && plen != 0) {
struct sockaddr_in *brd = satosin(ifa->ifa_broadcast);
if (brd != NULL)
- printf(" broadcast %s", inet_ntoa(brd->sin_addr));
+ af_inet_print_broadcast(brd);
}
if (ifa->ifaf_vhid != 0)
- printf(" vhid %d", ifa->ifaf_vhid);
+ af_inet_print_vhid(ifa);
- putchar('\n');
+ ifconfig_print_newline();
}
#endif
@@ -227,7 +206,7 @@
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
if (errstr != NULL) {
*p = '/';
- errx(1, "%s: bad value (width %s)", s, errstr);
+ if_errx(1, "%s: bad value (width %s)", s, errstr);
}
min->sin_family = AF_INET;
min->sin_len = sizeof(*min);
@@ -244,7 +223,7 @@
else if ((np = getnetbyname(s)) != NULL)
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
else
- errx(1, "%s: bad value", s);
+ if_errx(1, "%s: bad value", s);
}
#else
@@ -278,7 +257,7 @@
else if ((np = getnetbyname(addr_str)) != NULL)
*ip = inet_makeaddr(np->n_net, INADDR_ANY);
else
- errx(1, "%s: bad value", addr_str);
+ if_errx(1, "%s: bad value", addr_str);
}
static void
@@ -302,7 +281,7 @@
if((p = strrchr(s, '/')) != NULL) {
const char *errstr;
/* address is `name/masklen' */
- int masklen;
+ int masklen = 0; // XXX had to be initialized?
*p = '\0';
if (!isdigit(*(p + 1)))
errstr = "invalid";
@@ -310,7 +289,7 @@
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
if (errstr != NULL) {
*p = '/';
- errx(1, "%s: bad value (width %s)", s, errstr);
+ if_errx(1, "%s: bad value (width %s)", s, errstr);
}
px->plen = masklen;
px->maskset = true;
@@ -371,7 +350,7 @@
}
if (e.error != 0) {
if (e.error_str != NULL)
- warnx("%s(): %s", __func__, e.error_str);
+ if_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -391,7 +370,7 @@
memset(&e, 0, sizeof(e));
snl_read_reply_code(ss, hdr->nlmsg_seq, &e);
if (e.error_str != NULL)
- warnx("%s(): %s", __func__, e.error_str);
+ if_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -432,7 +411,7 @@
struct snl_errmsg_data e = {};
snl_read_reply_code(ctx->io_ss, hdr->nlmsg_seq, &e);
if (e.error_str != NULL)
- warnx("%s(): %s", __func__, e.error_str);
+ if_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -442,7 +421,7 @@
err_nomask(int ifflags)
{
if ((ifflags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) {
- errx(1, "ERROR: setting interface address without mask is no longer supported.");
+ if_errx(1, "ERROR: setting interface address without mask is no longer supported.");
}
}
@@ -485,7 +464,7 @@
if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, NI_NUMERICHOST) != 0)
dst[0] = '\0';
- printf("\ttunnel inet %s --> %s\n", src, dst);
+ af_inet_print_tunnel_inet(src, dst);
}
static void
@@ -499,7 +478,7 @@
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len);
if (ioctl_ctx(ctx, SIOCSIFPHYADDR, &addreq) < 0)
- warn("SIOCSIFPHYADDR");
+ if_warn("SIOCSIFPHYADDR");
}
static void
diff --git a/sbin/ifconfig/af_inet6.h b/sbin/ifconfig/af_inet6.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/af_inet6.h
@@ -0,0 +1,2 @@
+/* Utility export for ifconfig_output.c */
+char *sec2str(time_t total);
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c
--- a/sbin/ifconfig/af_inet6.c
+++ b/sbin/ifconfig/af_inet6.c
@@ -53,6 +53,8 @@
#include "ifconfig.h"
#include "ifconfig_netlink.h"
+#include "ifconfig_output.h"
+#include "af_inet6.h"
#ifndef WITHOUT_NETLINK
struct in6_px {
@@ -83,7 +85,7 @@
#ifdef WITHOUT_NETLINK
static int prefix(void *, int);
#endif
-static char *sec2str(time_t);
+
static int explicit_prefix = 0;
extern char *f_inet6, *f_addr;
@@ -91,7 +93,7 @@
extern void setnd6defif(if_ctx *,const char *, int);
extern void nd6_status(if_ctx *);
-static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
+//static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
static void
setifprefixlen(if_ctx *ctx __netlink_unused, const char *addr, int dummy __unused)
@@ -105,7 +107,7 @@
int plen = strtol(addr, NULL, 10);
if ((plen < 0) || (plen > 128))
- errx(1, "%s: bad value", addr);
+ if_errx(1, "%s: bad value", addr);
in6_add.addr.plen = plen;
#endif
explicit_prefix = 1;
@@ -117,7 +119,7 @@
const struct afswtch *afp = ctx->afp;
if (afp->af_af != AF_INET6)
- err(1, "address flags can be set only for inet6 addresses");
+ if_err(1, "address flags can be set only for inet6 addresses");
#ifdef WITHOUT_NETLINK
if (flag < 0)
@@ -148,9 +150,9 @@
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
newval = (time_t)strtoul(val, &ep, 0);
if (val == ep)
- errx(1, "invalid %s", cmd);
+ if_errx(1, "invalid %s", cmd);
if (afp->af_af != AF_INET6)
- errx(1, "%s not allowed for the AF", cmd);
+ if_errx(1, "%s not allowed for the AF", cmd);
if (strcmp(cmd, "vltime") == 0) {
lifetime->ia6t_expire = now.tv_sec + newval;
lifetime->ia6t_vltime = newval;
@@ -182,16 +184,16 @@
struct in6_addr *in6;
if (afp->af_af != AF_INET6)
- errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
+ if_errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
#ifdef WITHOUT_NETLINK
in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
#else
in6 = &in6_add.addr.addr;
#endif
if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
- errx(EXIT_FAILURE, "interface index is already filled");
+ if_errx(EXIT_FAILURE, "interface index is already filled");
if (getifaddrs(&ifap) != 0)
- err(EXIT_FAILURE, "getifaddrs");
+ if_err(EXIT_FAILURE, "getifaddrs");
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family == AF_INET6 &&
strcmp(ifa->ifa_name, ctx->ifname) == 0) {
@@ -203,87 +205,13 @@
}
}
if (!lladdr)
- errx(EXIT_FAILURE, "could not determine link local address");
+ if_errx(EXIT_FAILURE, "could not determine link local address");
memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
freeifaddrs(ifap);
}
-static void
-print_addr(struct sockaddr_in6 *sin)
-{
- int error, n_flags;
-
- 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);
-}
-
-static void
-print_p2p(struct sockaddr_in6 *sin)
-{
- int error;
-
- error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
- sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
-
- if (error != 0)
- inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, sizeof(addr_buf));
- printf(" --> %s", addr_buf);
-}
-
-static void
-print_mask(int plen)
-{
- if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
- printf("/%d", plen);
- else
- printf(" prefixlen %d", plen);
-}
-
-static void
-print_flags(int flags6)
-{
- if ((flags6 & IN6_IFF_ANYCAST) != 0)
- printf(" anycast");
- if ((flags6 & IN6_IFF_TENTATIVE) != 0)
- printf(" tentative");
- if ((flags6 & IN6_IFF_DUPLICATED) != 0)
- printf(" duplicated");
- if ((flags6 & IN6_IFF_DETACHED) != 0)
- printf(" detached");
- if ((flags6 & IN6_IFF_DEPRECATED) != 0)
- printf(" deprecated");
- if ((flags6 & IN6_IFF_AUTOCONF) != 0)
- printf(" autoconf");
- if ((flags6 & IN6_IFF_TEMPORARY) != 0)
- printf(" temporary");
- if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
- printf(" prefer_source");
-
-}
-
-static void
-print_lifetime(const char *prepend, time_t px_time, struct timespec *now)
-{
- printf(" %s", prepend);
- if (px_time == 0)
- printf(" infty");
-
- printf(" %s", px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
-}
-
#ifdef WITHOUT_NETLINK
static void
in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
@@ -300,12 +228,12 @@
strlcpy(ifr6.ifr_name, ctx->ifname, sizeof(ifr6.ifr_name));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- warn("socket(AF_INET6,SOCK_DGRAM)");
+ if_warn("socket(AF_INET6,SOCK_DGRAM)");
return;
}
ifr6.ifr_addr = *sin;
if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
- warn("ioctl(SIOCGIFAFLAG_IN6)");
+ if_warn("ioctl(SIOCGIFAFLAG_IN6)");
close(s6);
return;
}
@@ -313,14 +241,14 @@
memset(&lifetime, 0, sizeof(lifetime));
ifr6.ifr_addr = *sin;
if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
- warn("ioctl(SIOCGIFALIFETIME_IN6)");
+ if_warn("ioctl(SIOCGIFALIFETIME_IN6)");
close(s6);
return;
}
lifetime = ifr6.ifr_ifru.ifru_lifetime;
close(s6);
- print_addr(sin);
+ af_inet6_print_addr(sin);
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = satosin6(ifa->ifa_dstaddr);
@@ -329,31 +257,30 @@
* address.
*/
if (sin != NULL && sin->sin6_family == AF_INET6)
- print_p2p(sin);
+ af_inet6_print_pointtopoint(sin);
}
sin = satosin6(ifa->ifa_netmask);
if (sin == NULL)
sin = &null_sin;
- print_mask(prefix(&sin->sin6_addr, sizeof(struct in6_addr)));
+ af_inet6_print_mask(prefix(&sin->sin6_addr, sizeof(struct in6_addr)));
- print_flags(flags6);
+ af_inet6_print_flags(flags6);
if ((satosin6(ifa->ifa_addr))->sin6_scope_id)
- printf(" scopeid 0x%x",
- (satosin6(ifa->ifa_addr))->sin6_scope_id);
+ af_inet6_print_scopeid((satosin6(ifa->ifa_addr))->sin6_scope_id);
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
- print_lifetime("pltime", lifetime.ia6t_preferred, &now);
- print_lifetime("vltime", lifetime.ia6t_expire, &now);
+ af_inet6_print_lifetime("pltime", lifetime.ia6t_preferred, &now);
+ af_inet6_print_lifetime("vltime", lifetime.ia6t_expire, &now);
}
print_vhid(ifa);
- putchar('\n');
+ ifconfig_print_newline();
}
#else
@@ -375,9 +302,9 @@
vl = (ci->ifa_valid == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_valid;
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
- print_lifetime("pltime",
+ af_inet6_print_lifetime("pltime",
pl + (ip6lifetime ? ci->tstamp / 1000 : now.tv_sec), &now);
- print_lifetime("vltime",
+ af_inet6_print_lifetime("vltime",
vl + (ip6lifetime ? ci->tstamp / 1000 : now.tv_sec), &now);
}
@@ -390,25 +317,25 @@
if (ifa->ifa_local == NULL) {
/* Non-P2P address */
scopeid = satosin6(ifa->ifa_address)->sin6_scope_id;
- print_addr(satosin6(ifa->ifa_address));
+ af_inet6_print_addr(satosin6(ifa->ifa_address));
} else {
scopeid = satosin6(ifa->ifa_local)->sin6_scope_id;
- print_addr(satosin6(ifa->ifa_local));
- print_p2p(satosin6(ifa->ifa_address));
+ af_inet6_print_addr(satosin6(ifa->ifa_local));
+ af_inet6_print_pointtopoint(satosin6(ifa->ifa_address));
}
- print_mask(plen);
- print_flags(ifa->ifaf_flags);
+ af_inet6_print_mask(plen);
+ af_inet6_print_flags(ifa->ifaf_flags);
if (scopeid != 0)
- printf(" scopeid 0x%x", scopeid);
+ af_inet6_print_scopeid(scopeid);
show_lifetime(ifa->ifa_cacheinfo);
if (ifa->ifaf_vhid != 0)
- printf(" vhid %d", ifa->ifaf_vhid);
+ af_inet6_print_vhid(ifa);
- putchar('\n');
+ ifconfig_print_newline();
}
static struct in6_px *sin6tab_nl[] = {
@@ -431,9 +358,9 @@
struct in6_px *px = sin6tab_nl[which];
if (which == MASK)
- errx(1, "netmask: invalid option for inet6");
+ if_errx(1, "netmask: invalid option for inet6");
if (which == BRDADDR)
- errx(1, "broadcast: invalid option for inet6");
+ if_errx(1, "broadcast: invalid option for inet6");
px->set = true;
px->plen = 128;
@@ -443,7 +370,7 @@
*p = '\0';
int plen = strtol(p + 1, NULL, 10);
if (plen < 0 || plen > 128)
- errx(1, "%s: bad value", p + 1);
+ if_errx(1, "%s: bad value", p + 1);
px->plen = plen;
explicit_prefix = 1;
}
@@ -455,7 +382,7 @@
int error = getaddrinfo(addr_str, NULL, &hints, &res);
if (error != 0) {
if (inet_pton(AF_INET6, addr_str, &px->addr) != 1)
- errx(1, "%s: bad value", addr_str);
+ if_errx(1, "%s: bad value", addr_str);
} else {
struct sockaddr_in6 *sin6;
@@ -525,7 +452,7 @@
int len = atoi(plen);
if ((len < 0) || (len > 128))
- errx(1, "%s: bad value", plen);
+ if_errx(1, "%s: bad value", plen);
sin->sin6_len = sizeof(*sin);
if (which != MASK)
sin->sin6_family = AF_INET6;
@@ -565,7 +492,7 @@
error = getaddrinfo(s, NULL, &hints, &res);
if (error != 0) {
if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
- errx(1, "%s: bad value", s);
+ if_errx(1, "%s: bad value", s);
} else {
bcopy(res->ai_addr, sin, res->ai_addrlen);
freeaddrinfo(res);
@@ -598,39 +525,6 @@
}
#endif
-static char *
-sec2str(time_t total)
-{
- static char result[256];
- int days, hours, mins, secs;
- int first = 1;
- char *p = result;
-
- if (0) {
- days = total / 3600 / 24;
- hours = (total / 3600) % 24;
- mins = (total / 60) % 60;
- secs = total % 60;
-
- if (days) {
- first = 0;
- p += sprintf(p, "%dd", days);
- }
- if (!first || hours) {
- first = 0;
- p += sprintf(p, "%dh", hours);
- }
- if (!first || mins) {
- first = 0;
- p += sprintf(p, "%dm", mins);
- }
- sprintf(p, "%ds", secs);
- } else
- sprintf(result, "%lu", (unsigned long)total);
-
- return(result);
-}
-
static void
in6_postproc(if_ctx *ctx, int newaddr __unused,
int ifflags __unused)
@@ -671,7 +565,7 @@
NI_NUMERICHOST) != 0)
dst[0] = '\0';
- printf("\ttunnel inet6 %s --> %s\n", src, dst);
+ af_inet6_print_tunnel(src, dst);
}
static void
@@ -685,7 +579,7 @@
dstres->ai_addr->sa_len);
if (ioctl_ctx(ctx, SIOCSIFPHYADDR_IN6, &in6_req) < 0)
- warn("SIOCSIFPHYADDR_IN6");
+ if_warn("SIOCSIFPHYADDR_IN6");
}
static void
@@ -728,8 +622,8 @@
DEF_CMD_ARG("pltime", setip6pltime),
DEF_CMD_ARG("vltime", setip6vltime),
DEF_CMD("eui64", 0, setip6eui64),
- DEF_CMD("stableaddr", ND6_IFF_STABLEADDR, setnd6flags),
- DEF_CMD("-stableaddr", -ND6_IFF_STABLEADDR, setnd6flags),
+ // DEF_CMD("stableaddr", ND6_IFF_STABLEADDR, setnd6flags),
+ //DEF_CMD("-stableaddr", -ND6_IFF_STABLEADDR, setnd6flags),
};
static struct afswtch af_inet6 = {
@@ -791,3 +685,36 @@
af_register(&af_inet6);
opt_register(&in6_Lopt);
}
+
+char *
+sec2str(time_t total)
+{
+ static char result[256];
+ int days, hours, mins, secs;
+ int first = 1;
+ char *p = result;
+
+ if (0) {
+ days = total / 3600 / 24;
+ hours = (total / 3600) % 24;
+ mins = (total / 60) % 60;
+ secs = total % 60;
+
+ if (days) {
+ first = 0;
+ p += sprintf(p, "%dd", days);
+ }
+ if (!first || hours) {
+ first = 0;
+ p += sprintf(p, "%dh", hours);
+ }
+ if (!first || mins) {
+ first = 0;
+ p += sprintf(p, "%dm", mins);
+ }
+ sprintf(p, "%ds", secs);
+ } else
+ sprintf(result, "%lu", (unsigned long)total);
+
+ return(result);
+}
diff --git a/sbin/ifconfig/af_link.c b/sbin/ifconfig/af_link.c
--- a/sbin/ifconfig/af_link.c
+++ b/sbin/ifconfig/af_link.c
@@ -47,64 +47,12 @@
#include "ifconfig.h"
#include "ifconfig_netlink.h"
+#include "ifconfig_output.h"
static struct ifreq link_ridreq;
extern char *f_ether;
-static void
-print_ether(const struct ether_addr *addr, const char *prefix)
-{
- char *ether_format = ether_ntoa(addr);
-
- if (f_ether != NULL) {
- if (strcmp(f_ether, "dash") == 0) {
- char *format_char;
-
- while ((format_char = strchr(ether_format, ':')) != NULL) {
- *format_char = '-';
- }
- } else if (strcmp(f_ether, "dotted") == 0) {
- /* Indices 0 and 1 is kept as is. */
- ether_format[ 2] = ether_format[ 3];
- ether_format[ 3] = ether_format[ 4];
- ether_format[ 4] = '.';
- ether_format[ 5] = ether_format[ 6];
- ether_format[ 6] = ether_format[ 7];
- ether_format[ 7] = ether_format[ 9];
- ether_format[ 8] = ether_format[10];
- ether_format[ 9] = '.';
- ether_format[10] = ether_format[12];
- ether_format[11] = ether_format[13];
- ether_format[12] = ether_format[15];
- ether_format[13] = ether_format[16];
- ether_format[14] = '\0';
- }
- }
- printf("\t%s %s\n", prefix, ether_format);
-}
-
-static void
-print_lladdr(struct sockaddr_dl *sdl)
-{
- if (match_ether(sdl)) {
- print_ether((struct ether_addr *)LLADDR(sdl), "ether");
- } else {
- int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
- printf("\tlladdr %s\n", link_ntoa(sdl) + n);
- }
-}
-
-static void
-print_pcp(if_ctx *ctx)
-{
- struct ifreq ifr = {};
-
- if (ioctl_ctx_ifr(ctx, SIOCGLANPCP, &ifr) == 0 &&
- ifr.ifr_lan_pcp != IFNET_PCP_NONE)
- printf("\tpcp %d\n", ifr.ifr_lan_pcp);
-}
-
#ifdef WITHOUT_NETLINK
static void
link_status(if_ctx *ctx, const struct ifaddrs *ifa)
@@ -119,7 +67,7 @@
if (sdl == NULL || sdl->sdl_alen == 0)
return;
- print_lladdr(sdl);
+ af_link_print_lladdr(sdl);
/*
* Best-effort (i.e. failures are silent) to get original
@@ -138,7 +86,7 @@
memcpy(&ifr.ifr_addr, ifa->ifa_addr, sizeof(ifa->ifa_addr->sa_len));
ifr.ifr_addr.sa_family = AF_LOCAL;
if ((sock_hw = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
- warn("socket(AF_LOCAL,SOCK_DGRAM)");
+ if_warn("socket(AF_LOCAL,SOCK_DGRAM)");
return;
}
rc = ioctl(sock_hw, SIOCGHWADDR, &ifr);
@@ -154,9 +102,9 @@
memcmp(ifr.ifr_addr.sa_data, LLADDR(sdl), sdl->sdl_alen) == 0)
goto pcp;
- print_ether((const struct ether_addr *)&ifr.ifr_addr.sa_data, "hwaddr");
+ af_link_print_ether((const struct ether_addr *)&ifr.ifr_addr.sa_data, "hwaddr");
pcp:
- print_pcp(ctx);
+ af_link_print_pcp(ctx);
}
#else
@@ -172,17 +120,17 @@
.sdl_alen = NLA_DATA_LEN(link->ifla_address),
};
memcpy(LLADDR(&sdl), NLA_DATA(link->ifla_address), sdl.sdl_alen);
- print_lladdr(&sdl);
+ af_link_print_lladdr(&sdl);
if (link->iflaf_orig_hwaddr != NULL) {
struct nlattr *hwaddr = link->iflaf_orig_hwaddr;
if (memcmp(NLA_DATA(hwaddr), NLA_DATA(link->ifla_address), sdl.sdl_alen))
- print_ether((struct ether_addr *)NLA_DATA(hwaddr), "hwaddr");
+ af_link_print_ether((struct ether_addr *)NLA_DATA(hwaddr), "hwaddr");
}
}
if (convert_iftype(link->ifi_type) == IFT_ETHER)
- print_pcp(ctx);
+ af_link_print_pcp(ctx);
}
#endif
@@ -194,7 +142,7 @@
struct sockaddr *sa = &link_ridreq.ifr_addr;
if (which != ADDR)
- errx(1, "can't set link-level netmask or broadcast");
+ if_errx(1, "can't set link-level netmask or broadcast");
if (!strcmp(addr, "random")) {
sdl.sdl_len = sizeof(sdl);
sdl.sdl_alen = ETHER_ADDR_LEN;
@@ -206,16 +154,16 @@
sdl.sdl_data[0] |= 0x02;
} else {
if ((temp = malloc(strlen(addr) + 2)) == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
temp[0] = ':';
strcpy(temp + 1, addr);
sdl.sdl_len = sizeof(sdl);
if (link_addr(temp, &sdl) == -1)
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
free(temp);
}
if (sdl.sdl_alen > sizeof(sa->sa_data))
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
sa->sa_family = AF_LINK;
sa->sa_len = sdl.sdl_alen;
bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen);
diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c
--- a/sbin/ifconfig/af_nd6.c
+++ b/sbin/ifconfig/af_nd6.c
@@ -50,6 +50,7 @@
#include <netinet6/nd6.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
#define MAX_SYSCTL_TRY 5
static const char *ND6BITS[] = {
@@ -80,7 +81,7 @@
strlcpy(nd.ifname, ctx->ifname, sizeof(nd.ifname));
error = ioctl_ctx(ctx, SIOCGIFINFO_IN6, &nd);
if (error) {
- warn("ioctl(SIOCGIFINFO_IN6)");
+ if_warn("ioctl(SIOCGIFINFO_IN6)");
return;
}
if (d < 0)
@@ -89,7 +90,7 @@
nd.ndi.flags |= d;
error = ioctl_ctx(ctx, SIOCSIFINFO_IN6, (caddr_t)&nd);
if (error)
- warn("ioctl(SIOCSIFINFO_IN6)");
+ if_warn("ioctl(SIOCSIFINFO_IN6)");
}
void
@@ -108,14 +109,14 @@
} else
return;
} else if ((ifindex = if_nametoindex(ndifreq.ifname)) == 0) {
- warn("if_nametoindex(%s)", ndifreq.ifname);
+ if_warn("if_nametoindex(%s)", ndifreq.ifname);
return;
}
ndifreq.ifindex = ifindex;
error = ioctl_ctx(ctx, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq);
if (error)
- warn("ioctl(SIOCSDEFIFACE_IN6)");
+ if_warn("ioctl(SIOCSDEFIFACE_IN6)");
}
static int
@@ -130,7 +131,7 @@
ifindex = if_nametoindex(ndifreq.ifname);
error = ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq);
if (error) {
- warn("ioctl(SIOCGDEFIFACE_IN6)");
+ if_warn("ioctl(SIOCGDEFIFACE_IN6)");
return (error);
}
return (ndifreq.ifindex == ifindex);
@@ -148,13 +149,13 @@
strlcpy(nd.ifname, ctx->ifname, sizeof(nd.ifname));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
if (errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
- warn("socket(AF_INET6, SOCK_DGRAM)");
+ if_warn("socket(AF_INET6, SOCK_DGRAM)");
return;
}
error = ioctl(s6, SIOCGIFINFO_IN6, &nd);
if (error) {
if (errno != EPFNOSUPPORT)
- warn("ioctl(SIOCGIFINFO_IN6)");
+ if_warn("ioctl(SIOCGIFINFO_IN6)");
close(s6);
return;
}
@@ -163,7 +164,8 @@
if (nd.ndi.flags == 0 && !isdefif)
return;
bits = (nd.ndi.flags | (isdefif << 15));
- printf("\tnd6 options=%x", bits);
- print_bits("options", &bits, 1, ND6BITS, nitems(ND6BITS));
- putchar('\n');
+ af_nd6_print_options(bits);
+ ifconfig_print_bits("nd6-options", "option", &bits, 1, ND6BITS,
+ nitems(ND6BITS));
+ ifconfig_print_newline();
}
diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c
--- a/sbin/ifconfig/carp.c
+++ b/sbin/ifconfig/carp.c
@@ -56,6 +56,7 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static const char *carp_states[] = { CARP_STATES };
@@ -84,24 +85,21 @@
for (size_t i = 0; i < carpr[0].carpr_count; i++) {
switch (carpr[i].carpr_version) {
case CARP_VERSION_CARP:
- printf("\tcarp: %s vhid %d advbase %d advskew %d",
- carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,
- carpr[i].carpr_advbase, carpr[i].carpr_advskew);
+ carp_print_summary(carp_states[carpr[i].carpr_state],
+ &carpr[i]);
if (ctx->args->printkeys && carpr[i].carpr_key[0] != '\0')
- printf(" key \"%s\"\n", carpr[i].carpr_key);
+ carp_print_key(&carpr[i]);
else
- printf("\n");
+ ifconfig_print_newline();
inet_ntop(AF_INET6, &carpr[i].carpr_addr6, addr_buf,
sizeof(addr_buf));
- printf("\t peer %s peer6 %s\n",
- inet_ntoa(carpr[i].carpr_addr), addr_buf);
+ carp_print_peer(&carpr[i], addr_buf);
break;
case CARP_VERSION_VRRPv3:
- printf("\tvrrp: %s vrid %d prio %d interval %d\n",
- carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,
- carpr[i].carpr_vrrp_prio, carpr[i].carpr_vrrp_adv_inter);
+ carp_print_vrrp3(carp_states[carpr[i].carpr_state],
+ &carpr[i]);
break;
}
}
@@ -115,11 +113,11 @@
carpr_vhid = atoi(val);
if (carpr_vhid <= 0 || carpr_vhid > CARP_MAXVHID)
- errx(1, "vhid must be greater than 0 and less than %u",
+ if_errx(1, "vhid must be greater than 0 and less than %u",
CARP_MAXVHID);
if (afp->af_setvhid == NULL)
- errx(1, "%s doesn't support carp(4)", afp->af_name);
+ if_errx(1, "%s doesn't support carp(4)", afp->af_name);
afp->af_setvhid(carpr_vhid);
callback_register(setcarp_callback, NULL);
}
@@ -158,10 +156,10 @@
if (ifconfig_carp_set_info(lifh, ctx->ifname, &carpr)) {
if (ifconfig_err_errtype(lifh) == OTHER)
- err(1, "%s: %s", __func__,
+ if_err(1, "%s: %s", __func__,
strerror(ifconfig_err_errno(lifh)));
else
- err(1, "%s: %d", __func__, ifconfig_err_errtype(lifh));
+ if_err(1, "%s: %d", __func__, ifconfig_err_errtype(lifh));
}
}
@@ -170,7 +168,7 @@
{
if (carpr_vhid == -1)
- errx(1, "passwd requires vhid");
+ if_errx(1, "passwd requires vhid");
carpr_key = val;
}
@@ -180,7 +178,7 @@
{
if (carpr_vhid == -1)
- errx(1, "advskew requires vhid");
+ if_errx(1, "advskew requires vhid");
carpr_advskew = atoi(val);
}
@@ -190,7 +188,7 @@
{
if (carpr_vhid == -1)
- errx(1, "advbase requires vhid");
+ if_errx(1, "advbase requires vhid");
carpr_advbase = atoi(val);
}
@@ -201,7 +199,7 @@
int i;
if (carpr_vhid == -1)
- errx(1, "state requires vhid");
+ if_errx(1, "state requires vhid");
for (i = 0; i <= CARP_MAXSTATE; i++)
if (strcasecmp(carp_states[i], val) == 0) {
@@ -209,7 +207,7 @@
return;
}
- errx(1, "unknown state");
+ if_errx(1, "unknown state");
}
static void
@@ -234,7 +232,7 @@
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(val, NULL, &hints, &res) != 0)
- errx(1, "Invalid IPv6 address %s", val);
+ if_errx(1, "Invalid IPv6 address %s", val);
memcpy(&carp_addr6, &(satosin6(res->ai_addr))->sin6_addr, sizeof(carp_addr6));
freeaddrinfo(res);
@@ -255,7 +253,7 @@
carpr_version = atoi(val);
if (carpr_version != CARP_VERSION_CARP && carpr_version != CARP_VERSION_VRRPv3)
- errx(1, "version must be %d or %d", CARP_VERSION_CARP,
+ if_errx(1, "version must be %d or %d", CARP_VERSION_CARP,
CARP_VERSION_VRRPv3);
}
@@ -271,7 +269,7 @@
carpr_vrrp_adv_inter = atoi(val);
if (carpr_vrrp_adv_inter == 0 || carpr_vrrp_adv_inter > VRRP_MAX_INTERVAL)
- errx(1, "vrrpinterval must be greater than 0 and less than %d", VRRP_MAX_INTERVAL);
+ if_errx(1, "vrrpinterval must be greater than 0 and less than %d", VRRP_MAX_INTERVAL);
}
static struct cmd carp_cmds[] = {
diff --git a/sbin/ifconfig/ifbridge.h b/sbin/ifconfig/ifbridge.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/ifbridge.h
@@ -0,0 +1,7 @@
+#pragma once
+
+const char *vlan_proto_name(uint16_t proto);
+
+extern const char *stpstates[];
+extern const char *stpproto[];
+extern const char *stproles[];
\ No newline at end of file
diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c
--- a/sbin/ifconfig/ifbridge.c
+++ b/sbin/ifconfig/ifbridge.c
@@ -58,15 +58,17 @@
#include <libifconfig.h>
+#include "ifbridge.h"
#include "ifconfig.h"
+#include "ifconfig_output.h"
static int parse_vlans(ifbvlan_set_t *set, const char *str);
static int get_val(const char *cp, u_long *valp);
static int get_vlan_id(const char *cp, ether_vlanid_t *valp);
-static const char *stpstates[] = { STP_STATES };
-static const char *stpproto[] = { STP_PROTOS };
-static const char *stproles[] = { STP_ROLES };
+const char *stpstates[] = { STP_STATES };
+const char *stpproto[] = { STP_PROTOS };
+const char *stproles[] = { STP_ROLES };
static int
get_val(const char *cp, u_long *valp)
@@ -118,7 +120,7 @@
strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname));
if (do_cmd(ctx, BRDGGIFFLGS, &req, sizeof(req), 0) < 0)
- err(1, "unable to get bridge flags");
+ if_err(1, "unable to get bridge flags");
if (set)
req.ifbr_ifsflags |= flag;
@@ -126,7 +128,7 @@
req.ifbr_ifsflags &= ~flag;
if (do_cmd(ctx, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
- err(1, "unable to set bridge flags");
+ if_err(1, "unable to set bridge flags");
}
static void
@@ -136,16 +138,15 @@
struct ifbareq *ifba;
char *inbuf = NULL, *ninbuf;
size_t len = 8192;
- struct ether_addr ea;
for (;;) {
ninbuf = realloc(inbuf, len);
if (ninbuf == NULL)
- err(1, "unable to allocate address buffer");
+ if_err(1, "unable to allocate address buffer");
ifbac.ifbac_len = len;
ifbac.ifbac_buf = inbuf = ninbuf;
if (do_cmd(ctx, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
- err(1, "unable to get address cache");
+ if_err(1, "unable to get address cache");
if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
break;
len *= 2;
@@ -153,48 +154,15 @@
for (unsigned long i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
ifba = ifbac.ifbac_req + i;
- memcpy(ea.octet, ifba->ifba_dst,
- sizeof(ea.octet));
- printf("%s%s Vlan%d %s %lu ", prefix, ether_ntoa(&ea),
- ifba->ifba_vlan, ifba->ifba_ifsname, ifba->ifba_expire);
- printb("flags", ifba->ifba_flags, IFBAFBITS);
- printf("\n");
+ ifbridge_print_vlan(prefix, ifba);
+ ifconfig_printb("flags", ifba->ifba_flags, IFBAFBITS);
+ ifconfig_print_newline();
}
free(inbuf);
}
-static void
-print_vlans(ifbvlan_set_t *vlans)
-{
- unsigned printed = 0;
-
- for (unsigned vlan = DOT1Q_VID_MIN; vlan <= DOT1Q_VID_MAX;) {
- unsigned last;
-
- if (!BRVLAN_TEST(vlans, vlan)) {
- ++vlan;
- continue;
- }
-
- last = vlan;
- while (last < DOT1Q_VID_MAX && BRVLAN_TEST(vlans, last + 1))
- ++last;
-
- if (printed == 0)
- printf(" tagged ");
- else
- printf(",");
-
- printf("%u", vlan);
- if (last != vlan)
- printf("-%u", last);
- ++printed;
- vlan = last + 1;
- }
-}
-
-static char const *
+char const *
vlan_proto_name(uint16_t proto)
{
switch (proto) {
@@ -213,80 +181,54 @@
bridge_status(if_ctx *ctx)
{
struct ifconfig_bridge_status *bridge;
- struct ifbropreq *params;
const char *pad, *prefix;
- uint8_t lladdr[ETHER_ADDR_LEN];
- uint16_t bprio;
if (ifconfig_bridge_get_bridge_status(lifh, ctx->ifname, &bridge) == -1)
return;
- params = bridge->params;
-
- PV2ID(params->ifbop_bridgeid, bprio, lladdr);
- printf("\tid %s priority %u hellotime %u fwddelay %u\n",
- ether_ntoa((struct ether_addr *)lladdr),
- params->ifbop_priority,
- params->ifbop_hellotime,
- params->ifbop_fwddelay);
- printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n",
- params->ifbop_maxage,
- params->ifbop_holdcount,
- stpproto[params->ifbop_protocol],
- bridge->cache_size,
- bridge->cache_lifetime);
- PV2ID(params->ifbop_designated_root, bprio, lladdr);
- printf("\troot id %s priority %d ifcost %u port %u\n",
- ether_ntoa((struct ether_addr *)lladdr),
- bprio,
- params->ifbop_root_path_cost,
- params->ifbop_root_port & 0xfff);
-
- printb("\tbridge flags", bridge->flags, IFBRFBITS);
+ ifbridge_print_summary(bridge);
+
+ ifconfig_printb("\tbridge flags", bridge->flags, IFBRFBITS);
if (bridge->defpvid)
- printf(" defuntagged=%u", (unsigned) bridge->defpvid);
- printf("\n");
+ ifbridge_print_defuntagged(bridge);
+ ifconfig_print_newline();
prefix = "\tmember: ";
pad = "\t ";
for (size_t i = 0; i < bridge->members_count; ++i) {
struct ifbreq *member = &bridge->members[i];
- printf("%s%s ", prefix, member->ifbr_ifsname);
- printb("flags", member->ifbr_ifsflags, IFBIFBITS);
- printf("\n%s", pad);
+ ifbridge_print_bridge_member(prefix, member);
+ ifconfig_printb("flags", member->ifbr_ifsflags, IFBIFBITS);
+ ifbridge_print_bridge_member_pad(pad);
if (member->ifbr_addrmax != 0)
- printf("ifmaxaddr %u ", member->ifbr_addrmax);
- printf("port %u priority %u path cost %u",
- member->ifbr_portno,
- member->ifbr_priority,
- member->ifbr_path_cost);
+ ifbridge_print_bridge_member_maxaddr(member);
+ ifbridge_print_bridge_member_stp(member);
if (member->ifbr_ifsflags & IFBIF_STP) {
uint8_t proto = member->ifbr_proto;
uint8_t role = member->ifbr_role;
uint8_t state = member->ifbr_state;
if (proto < nitems(stpproto))
- printf(" proto %s", stpproto[proto]);
+ ifbridge_print_bridge_member_proto(proto);
else
- printf(" <unknown proto %d>", proto);
- printf("\n%s", pad);
+ ifbridge_print_bridge_member_proto_unknown(proto);
+ ifbridge_print_bridge_member_pad(pad);
if (role < nitems(stproles))
- printf("role %s", stproles[role]);
+ ifbridge_print_bridge_member_role(role);
else
- printf("<unknown role %d>", role);
+ ifbridge_print_bridge_member_role_unknown(role);
if (state < nitems(stpstates))
- printf(" state %s", stpstates[state]);
+ ifbridge_print_bridge_member_state(state);
else
- printf(" <unknown state %d>", state);
+ ifbridge_print_bridge_member_state_unknown(state);
}
if (member->ifbr_vlanproto != 0)
- printf(" vlan protocol %s",
- vlan_proto_name(member->ifbr_vlanproto));
+ ifbridge_print_bridge_member_vlan_proto(member);
if (member->ifbr_pvid != 0)
- printf(" untagged %u", (unsigned)member->ifbr_pvid);
- print_vlans(&bridge->member_vlans[i]);
- printf("\n");
+ ifbridge_print_bridge_member_pvid(member);
+ ifbridge_print_vlans(&bridge->member_vlans[i]);
+ ifconfig_print_newline();
}
ifconfig_bridge_free_bridge_status(bridge);
@@ -303,7 +245,7 @@
memset(&vlreq, 0, sizeof(vlreq));
if (argc < 1)
- errx(1, "usage: addm <interface> [opts ...]");
+ if_errx(1, "usage: addm <interface> [opts ...]");
strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
--argc; ++argv;
@@ -311,22 +253,22 @@
while (argc) {
if (strcmp(argv[0], "untagged") == 0) {
if (argc < 2)
- errx(1, "usage: untagged <vlan id>");
+ if_errx(1, "usage: untagged <vlan id>");
if (get_vlan_id(argv[1], &req.ifbr_pvid) < 0)
- errx(1, "invalid VLAN identifier: %s", argv[1]);
+ if_errx(1, "invalid VLAN identifier: %s", argv[1]);
argc -= 2;
argv += 2;
} else if (strcmp(argv[0], "tagged") == 0) {
if (argc < 2)
- errx(1, "usage: tagged <vlan set>");
+ if_errx(1, "usage: tagged <vlan set>");
vlreq.bv_op = BRDG_VLAN_OP_SET;
strlcpy(vlreq.bv_ifname, req.ifbr_ifsname,
sizeof(vlreq.bv_ifname));
if (parse_vlans(&vlreq.bv_set, argv[1]) != 0)
- errx(1, "invalid vlan set: %s", argv[1]);
+ if_errx(1, "invalid vlan set: %s", argv[1]);
argc -= 2;
argv += 2;
@@ -336,16 +278,16 @@
}
if (do_cmd(ctx, BRDGADD, &req, sizeof(req), 1) < 0)
- err(1, "BRDGADD %s", req.ifbr_ifsname);
+ if_err(1, "BRDGADD %s", req.ifbr_ifsname);
if (req.ifbr_pvid != 0 &&
do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPVID %s %u", req.ifbr_ifsname,
+ if_err(1, "BRDGSIFPVID %s %u", req.ifbr_ifsname,
(unsigned)req.ifbr_pvid);
if (vlreq.bv_op != 0 &&
do_cmd(ctx, BRDGSIFVLANSET, &vlreq, sizeof(vlreq), 1) < 0)
- err(1, "BRDGSIFVLANSET %s", req.ifbr_ifsname);
+ if_err(1, "BRDGSIFVLANSET %s", req.ifbr_ifsname);
return (oargc - argc);
}
@@ -358,7 +300,7 @@
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
if (do_cmd(ctx, BRDGDEL, &req, sizeof(req), 1) < 0)
- err(1, "BRDGDEL %s", val);
+ if_err(1, "BRDGDEL %s", val);
}
static void
@@ -411,7 +353,7 @@
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
if (do_cmd(ctx, BRDGADDS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGADDS %s", val);
+ if_err(1, "BRDGADDS %s", val);
}
static void
@@ -422,7 +364,7 @@
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
if (do_cmd(ctx, BRDGDELS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGDELS %s", val);
+ if_err(1, "BRDGDELS %s", val);
}
static void
@@ -495,7 +437,7 @@
memset(&req, 0, sizeof(req));
req.ifbr_ifsflags = IFBF_FLUSHDYN;
if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0)
- err(1, "BRDGFLUSH");
+ if_err(1, "BRDGFLUSH");
}
static void
@@ -506,7 +448,7 @@
memset(&req, 0, sizeof(req));
req.ifbr_ifsflags = IFBF_FLUSHALL;
if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0)
- err(1, "BRDGFLUSH");
+ if_err(1, "BRDGFLUSH");
}
static int
@@ -517,7 +459,7 @@
int arg;
if (argc < 2)
- errx(1, "usage: static <interface> <address> [vlan <id>]");
+ if_errx(1, "usage: static <interface> <address> [vlan <id>]");
arg = 0;
memset(&req, 0, sizeof(req));
@@ -528,24 +470,24 @@
ea = ether_aton(argv[arg]);
if (ea == NULL)
- errx(1, "invalid address: %s", argv[arg]);
+ if_errx(1, "invalid address: %s", argv[arg]);
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
++arg;
req.ifba_vlan = 0;
if (argc > 2 && strcmp(argv[arg], "vlan") == 0) {
if (argc < 3)
- errx(1, "usage: static <interface> <address> "
+ if_errx(1, "usage: static <interface> <address> "
"[vlan <id>]");
++arg;
if (get_vlan_id(argv[arg], &req.ifba_vlan) < 0)
- errx(1, "invalid vlan id: %s", argv[arg]);
+ if_errx(1, "invalid vlan id: %s", argv[arg]);
++arg;
}
if (do_cmd(ctx, BRDGSADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSADDR");
+ if_err(1, "BRDGSADDR");
return arg;
}
@@ -557,30 +499,30 @@
int arg;
if (argc < 1)
- errx(1, "usage: deladdr <address> [vlan <id>]");
+ if_errx(1, "usage: deladdr <address> [vlan <id>]");
arg = 0;
memset(&req, 0, sizeof(req));
ea = ether_aton(argv[arg]);
if (ea == NULL)
- errx(1, "invalid address: %s", argv[arg]);
+ if_errx(1, "invalid address: %s", argv[arg]);
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
++arg;
req.ifba_vlan = 0;
if (argc >= 2 && strcmp(argv[arg], "vlan") == 0) {
if (argc < 3)
- errx(1, "usage: deladdr <address> [vlan <id>]");
+ if_errx(1, "usage: deladdr <address> [vlan <id>]");
++arg;
if (get_vlan_id(argv[arg], &req.ifba_vlan) < 0)
- errx(1, "invalid vlan id: %s", argv[arg]);
+ if_errx(1, "invalid vlan id: %s", argv[arg]);
++arg;
}
if (do_cmd(ctx, BRDGDADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGDADDR");
+ if_err(1, "BRDGDADDR");
return arg;
}
@@ -598,12 +540,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_csize = val & 0xffffffff;
if (do_cmd(ctx, BRDGSCACHE, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSCACHE %s", arg);
+ if_err(1, "BRDGSCACHE %s", arg);
}
static void
@@ -613,12 +555,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_hellotime = val & 0xff;
if (do_cmd(ctx, BRDGSHT, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSHT %s", arg);
+ if_err(1, "BRDGSHT %s", arg);
}
static void
@@ -628,12 +570,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_fwddelay = val & 0xff;
if (do_cmd(ctx, BRDGSFD, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSFD %s", arg);
+ if_err(1, "BRDGSFD %s", arg);
}
static void
@@ -643,12 +585,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_maxage = val & 0xff;
if (do_cmd(ctx, BRDGSMA, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSMA %s", arg);
+ if_err(1, "BRDGSMA %s", arg);
}
static void
@@ -658,12 +600,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_prio = val & 0xffff;
if (do_cmd(ctx, BRDGSPRI, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSPRI %s", arg);
+ if_err(1, "BRDGSPRI %s", arg);
}
static void
@@ -676,11 +618,11 @@
} else if (strcasecmp(arg, "rstp") == 0) {
param.ifbrp_proto = 2;
} else {
- errx(1, "unknown stp protocol");
+ if_errx(1, "unknown stp protocol");
}
if (do_cmd(ctx, BRDGSPROTO, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSPROTO %s", arg);
+ if_err(1, "BRDGSPROTO %s", arg);
}
static void
@@ -690,12 +632,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_txhc = val & 0xff;
if (do_cmd(ctx, BRDGSTXHC, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSTXHC %s", arg);
+ if_err(1, "BRDGSTXHC %s", arg);
}
static void
@@ -707,13 +649,13 @@
memset(&req, 0, sizeof(req));
if (get_val(pri, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", pri);
+ if_errx(1, "invalid value: %s", pri);
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
req.ifbr_priority = val & 0xff;
if (do_cmd(ctx, BRDGSIFPRIO, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPRIO %s", pri);
+ if_err(1, "BRDGSIFPRIO %s", pri);
}
static void
@@ -725,13 +667,13 @@
memset(&req, 0, sizeof(req));
if (get_val(cost, &val) < 0)
- errx(1, "invalid value: %s", cost);
+ if_errx(1, "invalid value: %s", cost);
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
req.ifbr_path_cost = val;
if (do_cmd(ctx, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFCOST %s", cost);
+ if_err(1, "BRDGSIFCOST %s", cost);
}
static void
@@ -743,10 +685,10 @@
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
if (get_vlan_id(vlanid, &req.ifbr_pvid) < 0)
- errx(1, "invalid VLAN identifier: %s", vlanid);
+ if_errx(1, "invalid VLAN identifier: %s", vlanid);
if (do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPVID %s", vlanid);
+ if_err(1, "BRDGSIFPVID %s", vlanid);
}
static void
@@ -760,7 +702,7 @@
req.ifbr_pvid = 0;
if (do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPVID");
+ if_err(1, "BRDGSIFPVID");
}
static void
@@ -772,13 +714,13 @@
memset(&req, 0, sizeof(req));
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
req.ifbr_addrmax = val & 0xffffffff;
if (do_cmd(ctx, BRDGSIFAMAX, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFAMAX %s", arg);
+ if_err(1, "BRDGSIFAMAX %s", arg);
}
static void
@@ -788,12 +730,12 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ if_errx(1, "invalid value: %s", arg);
param.ifbrp_ctime = val & 0xffffffff;
if (do_cmd(ctx, BRDGSTO, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSTO %s", arg);
+ if_err(1, "BRDGSTO %s", arg);
}
static void
@@ -874,13 +816,13 @@
memset(&req, 0, sizeof(req));
if (parse_vlans(&req.bv_set, vlans) != 0)
- errx(1, "invalid vlan set: %s", vlans);
+ if_errx(1, "invalid vlan set: %s", vlans);
strlcpy(req.bv_ifname, ifn, sizeof(req.bv_ifname));
req.bv_op = op;
if (do_cmd(ctx, BRDGSIFVLANSET, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFVLANSET %s", vlans);
+ if_err(1, "BRDGSIFVLANSET %s", vlans);
}
static void
@@ -907,12 +849,12 @@
struct ifbrparam req;
if (do_cmd(ctx, BRDGGFLAGS, &req, sizeof(req), 0) < 0)
- err(1, "BRDGGFLAGS");
+ if_err(1, "BRDGGFLAGS");
req.ifbrp_flags |= (uint32_t)newflags;
if (do_cmd(ctx, BRDGSFLAGS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSFLAGS");
+ if_err(1, "BRDGSFLAGS");
}
static void
@@ -921,12 +863,12 @@
struct ifbrparam req;
if (do_cmd(ctx, BRDGGFLAGS, &req, sizeof(req), 0) < 0)
- err(1, "BRDGGFLAGS");
+ if_err(1, "BRDGGFLAGS");
req.ifbrp_flags &= ~(uint32_t)newflags;
if (do_cmd(ctx, BRDGSFLAGS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSFLAGS");
+ if_err(1, "BRDGSFLAGS");
}
static void
@@ -936,10 +878,10 @@
memset(&req, 0, sizeof(req));
if (get_vlan_id(arg, &req.ifbrp_defpvid) < 0)
- errx(1, "invalid vlan id: %s", arg);
+ if_errx(1, "invalid vlan id: %s", arg);
if (do_cmd(ctx, BRDGSDEFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSDEFPVID");
+ if_err(1, "BRDGSDEFPVID");
}
static void
@@ -951,7 +893,7 @@
req.ifbrp_defpvid = 0;
if (do_cmd(ctx, BRDGSDEFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSDEFPVID");
+ if_err(1, "BRDGSDEFPVID");
}
static void
@@ -979,10 +921,10 @@
else if (strcmp(proto, "802.1ad") == 0)
req.ifbr_vlanproto = ETHERTYPE_QINQ;
else
- errx(1, "unrecognised VLAN protocol: %s", proto);
+ if_errx(1, "unrecognised VLAN protocol: %s", proto);
if (do_cmd(ctx, BRDGSIFVLANPROTO, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFVLANPROTO");
+ if_err(1, "BRDGSIFVLANPROTO");
}
static struct cmd bridge_cmds[] = {
diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c
--- a/sbin/ifconfig/ifclone.c
+++ b/sbin/ifconfig/ifclone.c
@@ -43,6 +43,7 @@
#include <unistd.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
typedef enum {
MT_PREFIX,
@@ -56,16 +57,16 @@
size_t cloners_count;
if (ifconfig_list_cloners(lifh, &cloners, &cloners_count) < 0)
- errc(1, ifconfig_err_errno(lifh), "unable to list cloners");
+ if_errc(1, ifconfig_err_errno(lifh), "unable to list cloners");
for (const char *name = cloners;
name < cloners + cloners_count * IFNAMSIZ;
name += IFNAMSIZ) {
if (name > cloners)
- putchar(' ');
- printf("%s", name);
+ ifconfig_print_space();
+ ifclone_print_cloners(name);
}
- putchar('\n');
+ ifconfig_print_newline();
free(cloners);
}
@@ -122,12 +123,12 @@
/* Warning to be removed in FreeBSD 17.0 */
if (sscanf(ctx->ifname, "ipfw%u", &u) == 1 ||
sscanf(ctx->ifname, "ipfwlog%u", &u) == 1) {
- warnx("ipfw(4) logging does not need interface creation "
+ if_warnx("ipfw(4) logging does not need interface creation "
"in FreeBSD 16.0");
return;
}
if (sscanf(ctx->ifname, "pflog%u", &u) == 1) {
- warnx("pflog(4) logging does not need interface creation "
+ if_warnx("pflog(4) logging does not need interface creation "
"in FreeBSD 16.0");
return;
}
@@ -171,7 +172,7 @@
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCIFDESTROY, &ifr) < 0)
- err(1, "SIOCIFDESTROY");
+ if_err(1, "SIOCIFDESTROY");
}
static struct cmd clone_cmds[] = {
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -251,6 +251,90 @@
const struct afswtch *afp; /* AF we're operating on */
};
+static const char *IFFBITS[] = {
+ "UP", /* 00:0x1 IFF_UP*/
+ "BROADCAST", /* 01:0x2 IFF_BROADCAST*/
+ "DEBUG", /* 02:0x4 IFF_DEBUG*/
+ "LOOPBACK", /* 03:0x8 IFF_LOOPBACK*/
+ "POINTOPOINT", /* 04:0x10 IFF_POINTOPOINT*/
+ "NEEDSEPOCH", /* 05:0x20 IFF_NEEDSEPOCH*/
+ "RUNNING", /* 06:0x40 IFF_DRV_RUNNING*/
+ "NOARP", /* 07:0x80 IFF_NOARP*/
+ "PROMISC", /* 08:0x100 IFF_PROMISC*/
+ "ALLMULTI", /* 09:0x200 IFF_ALLMULTI*/
+ "DRV_OACTIVE", /* 10:0x400 IFF_DRV_OACTIVE*/
+ "SIMPLEX", /* 11:0x800 IFF_SIMPLEX*/
+ "LINK0", /* 12:0x1000 IFF_LINK0*/
+ "LINK1", /* 13:0x2000 IFF_LINK1*/
+ "LINK2", /* 14:0x4000 IFF_LINK2*/
+ "MULTICAST", /* 15:0x8000 IFF_MULTICAST*/
+ "CANTCONFIG", /* 16:0x10000 IFF_CANTCONFIG*/
+ "PPROMISC", /* 17:0x20000 IFF_PPROMISC*/
+ "MONITOR", /* 18:0x40000 IFF_MONITOR*/
+ "STATICARP", /* 19:0x80000 IFF_STATICARP*/
+ "STICKYARP", /* 20:0x100000 IFF_STICKYARP*/
+ "DYING", /* 21:0x200000 IFF_DYING*/
+ "", /* 22:0x400000 */
+ "PALLMULTI", /* 23:0x800000 IFF_PALLMULTI*/
+ "LOWER_UP", /* 24:0x1000000 IFF_NETLINK_1*/
+};
+
+/* static const char *IFFBITS[] = { */
+/* [0] = "UP", */
+/* [1] = "BROADCAST", */
+/* [2] = "DEBUG", */
+/* [3] = "LOOPBACK", */
+/* [4] = "POINTOPOINT", */
+/* [6] = "RUNNING", */
+/* [7] = "NOARP", */
+/* [8] = "PROMISC", */
+/* [9] = "ALLMULTI", */
+/* [10] = "OACTIVE", */
+/* [11] = "SIMPLEX", */
+/* [12] = "LINK0", */
+/* [13] = "LINK1", */
+/* [14] = "LINK2", */
+/* [15] = "MULTICAST", */
+/* [17] = "PPROMISC", */
+/* [18] = "MONITOR", */
+/* [19] = "STATICARP", */
+/* [20] = "STICKYARP", */
+/* }; */
+
+static const char *IFCAPBITS[] = {
+ [0] = "RXCSUM",
+ [1] = "TXCSUM",
+ [2] = "NETCONS",
+ [3] = "VLAN_MTU",
+ [4] = "VLAN_HWTAGGING",
+ [5] = "JUMBO_MTU",
+ [6] = "POLLING",
+ [7] = "VLAN_HWCSUM",
+ [8] = "TSO4",
+ [9] = "TSO6",
+ [10] = "LRO",
+ [11] = "WOL_UCAST",
+ [12] = "WOL_MCAST",
+ [13] = "WOL_MAGIC",
+ [14] = "TOE4",
+ [15] = "TOE6",
+ [16] = "VLAN_HWFILTER",
+ [18] = "VLAN_HWTSO",
+ [19] = "LINKSTATE",
+ [20] = "NETMAP",
+ [21] = "RXCSUM_IPV6",
+ [22] = "TXCSUM_IPV6",
+ [23] = "HWSTATS",
+ [24] = "TXRTLMT",
+ [25] = "HWRXTSTMP",
+ [26] = "MEXTPG",
+ [27] = "TXTLS4",
+ [28] = "TXTLS6",
+ [29] = "VXLAN_HWCSUM",
+ [30] = "VXLAN_HWTSO",
+ [31] = "TXTLS_RTLMT",
+};
+
struct option {
const char *opt;
const char *opt_usage;
@@ -269,9 +353,6 @@
void setifcapnv(if_ctx *ctx, const char *vname, const char *arg);
void Perror(const char *cmd);
-void print_bits(const char *btype, uint32_t *v, const int v_count,
- const char **names, const int n_count);
-void printb(const char *s, unsigned value, const char *bits);
void ifmaybeload(struct ifconfig_args *args, const char *name);
@@ -290,8 +371,7 @@
void tunnel_status(if_ctx *ctx);
struct afswtch *af_getbyfamily(int af);
void af_other_status(if_ctx *ctx);
-void print_ifstatus(if_ctx *ctx);
-void print_metric(if_ctx *ctx);
+
ifType convert_iftype(ifType iftype);
/* Netlink-related functions */
@@ -306,8 +386,6 @@
*/
struct ifmediareq *ifmedia_getstate(if_ctx *ctx);
-void print_vhid(const struct ifaddrs *);
-
void ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr);
/* Helpers */
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -72,6 +72,7 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
ifconfig_handle_t *lifh;
@@ -87,8 +88,6 @@
int exit_code = 0;
-static char ifname_to_print[IFNAMSIZ]; /* Helper for printifnamemaybe() */
-
/* Formatter Strings */
char *f_inet, *f_inet6, *f_ether, *f_addr;
@@ -191,7 +190,7 @@
strlcpy(ctx->_ifname_storage_ioctl, name, sizeof(ctx->_ifname_storage_ioctl));
ctx->ifname = ctx->_ifname_storage_ioctl;
- strlcpy(ifname_to_print, name, sizeof(ifname_to_print));
+ strlcpy(ifconfig_ifname_to_print, name, sizeof(ifconfig_ifname_to_print));
}
static void
@@ -217,9 +216,9 @@
if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) {
switch (errno) {
case EEXIST:
- errx(1, "interface %s already exists", ifr->ifr_name);
+ if_errx(1, "interface %s already exists", ifr->ifr_name);
default:
- err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
+ if_err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
}
}
@@ -341,7 +340,7 @@
free(f_inet6);
f_inet6 = strdup(category);
} else {
- warnx("Skipping invalid format: %s\n",
+ if_warnx("Skipping invalid format: %s\n",
category);
}
continue;
@@ -425,13 +424,6 @@
}
#endif
-static void
-printifnamemaybe(void)
-{
- if (ifname_to_print[0] != '\0')
- printf("%s\n", ifname_to_print);
-}
-
static void
list_interfaces(if_ctx *ctx)
{
@@ -573,7 +565,7 @@
const struct afswtch *afp = af_getbyname(*argv);
if (afp == NULL) {
- warnx("Address family '%s' unknown.", *argv);
+ if_warnx("Address family '%s' unknown.", *argv);
usage();
}
if (afp->af_name != NULL)
@@ -632,9 +624,11 @@
.io_s = -1,
};
+ ac = ifconfig_parse_args(ac, av);
+
lifh = ifconfig_open();
if (lifh == NULL)
- err(EXIT_FAILURE, "ifconfig_open");
+ if_err(EXIT_FAILURE, "ifconfig_open");
envformat = getenv("IFCONFIG_FORMAT");
if (envformat != NULL)
@@ -644,10 +638,12 @@
* Ensure we print interface name when expected to,
* even if we terminate early due to error.
*/
- atexit(printifnamemaybe);
-
+ atexit(ifconfig_printifnamemaybe);
+ atexit(ifconfig_finish);
args_parse(args, ac, av);
+ ifconfig_open_container("ifconfig");
+
if (!args->all && !args->namesonly) {
/* not listing, need an argument */
args->ifname = args_pop(args);
@@ -713,7 +709,7 @@
*/
if ((args->argc > 0) && (args->ifname != NULL)) {
if (isnametoolong(args->ifname))
- warnx("%s: interface name too long, skipping", args->ifname);
+ if_warnx("%s: interface name too long, skipping", args->ifname);
else {
flags = getifflags(args->ifname, -1, false);
if (!(((flags & IFF_CANTCONFIG) != 0) ||
@@ -729,6 +725,7 @@
list_interfaces(&ctx);
done:
+ ifconfig_close_container("ifconfig");
freeformat();
ifconfig_close(lifh);
exit(exit_code);
@@ -786,12 +783,12 @@
struct ifconfig_args *args = ctx->args;
if (getifaddrs(&ifap) != 0)
- err(EXIT_FAILURE, "getifaddrs");
+ if_err(EXIT_FAILURE, "getifaddrs");
char *cp = NULL;
if (calcorders(ifap, &q) != 0)
- err(EXIT_FAILURE, "calcorders");
+ if_err(EXIT_FAILURE, "calcorders");
sifap = sortifaddrs(ifap, cmpifaddrs, &q);
@@ -818,7 +815,7 @@
if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
continue;
if (isnametoolong(ifa->ifa_name)) {
- warnx("%s: interface name too long, skipping",
+ if_warnx("%s: interface name too long, skipping",
ifa->ifa_name);
continue;
}
@@ -840,7 +837,7 @@
namecp = cp;
ifindex++;
if (ifindex > 1)
- printf(" ");
+ ifconfig_print_space();
fputs(cp, stdout);
continue;
}
@@ -852,7 +849,7 @@
status(ctx, sdl, ifa);
}
if (args->namesonly)
- printf("\n");
+ ifconfig_print_newline();
freeifaddrs(ifap);
}
#endif
@@ -1063,7 +1060,7 @@
int error;
if (afp->af_exec == NULL) {
- warnx("interface %s cannot change %s addresses!",
+ if_warnx("interface %s cannot change %s addresses!",
ctx->ifname, afp->af_name);
clearaddr = 0;
return;
@@ -1082,7 +1079,7 @@
addifaddr(if_ctx *ctx, const struct afswtch *afp)
{
if (afp->af_exec == NULL) {
- warnx("interface %s cannot change %s addresses!",
+ if_warnx("interface %s cannot change %s addresses!",
ctx->ifname, afp->af_name);
newaddr = 0;
return;
@@ -1134,7 +1131,7 @@
if (afp == NULL)
afp = af_getbyname("link");
if (afp == NULL) {
- warnx("Please specify an address_family.");
+ if_warnx("Please specify an address_family.");
usage();
}
@@ -1146,7 +1143,7 @@
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
(uafp != NULL || errno != EAFNOSUPPORT ||
(s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
- err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
+ if_err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
ctx->io_s = s;
ctx->afp = afp;
@@ -1270,7 +1267,7 @@
int ecode;
if (afp->af_settunnel == NULL) {
- warn("address family %s does not support tunnel setup",
+ if_warn("address family %s does not support tunnel setup",
afp->af_name);
return;
}
@@ -1299,7 +1296,7 @@
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCDIFPHYADDR, &ifr) < 0)
- err(1, "SIOCDIFPHYADDR");
+ if_err(1, "SIOCDIFPHYADDR");
}
#ifdef JAIL
@@ -1312,7 +1309,7 @@
if (ifr.ifr_jid < 0)
errx(1, "%s", jail_errmsg);
if (ioctl_ctx_ifr(ctx, SIOCSIFVNET, &ifr) < 0)
- err(1, "SIOCSIFVNET");
+ if_err(1, "SIOCSIFVNET");
}
static void
@@ -1322,9 +1319,9 @@
ifr.ifr_jid = jail_getid(jname);
if (ifr.ifr_jid < 0)
- errx(1, "%s", jail_errmsg);
+ if_errx(1, "%s", jail_errmsg);
if (ioctl_ctx_ifr(ctx, SIOCSIFRVNET, &ifr) < 0)
- err(1, "SIOCSIFRVNET(%d, %s)", ifr.ifr_jid, ifr.ifr_name);
+ if_err(1, "SIOCSIFRVNET(%d, %s)", ifr.ifr_jid, ifr.ifr_name);
}
#endif
@@ -1384,7 +1381,7 @@
(void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name));
if (us < 0) {
if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
- err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
+ if_err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
} else
s = us;
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
@@ -1490,7 +1487,7 @@
if (ioctl_ctx_ifr(ctx, SIOCGIFCAP, &ifr) < 0)
Perror("ioctl (SIOCGIFCAP)");
if ((ifr.ifr_curcap & IFCAP_NV) == 0) {
- warnx("IFCAP_NV not supported");
+ if_warnx("IFCAP_NV not supported");
return; /* Not exit() */
}
@@ -1532,7 +1529,7 @@
ifr.ifr_metric = atoi(val);
if (ioctl_ctx_ifr(ctx, SIOCSIFMETRIC, &ifr) < 0)
- err(1, "ioctl SIOCSIFMETRIC (set metric)");
+ if_err(1, "ioctl SIOCSIFMETRIC (set metric)");
}
static void
@@ -1542,7 +1539,7 @@
ifr.ifr_mtu = atoi(val);
if (ioctl_ctx_ifr(ctx, SIOCSIFMTU, &ifr) < 0)
- err(1, "ioctl SIOCSIFMTU (set mtu)");
+ if_err(1, "ioctl SIOCSIFMTU (set mtu)");
}
static void
@@ -1559,7 +1556,7 @@
errx(1, "value for pcp out of range");
ifr.ifr_lan_pcp = ul;
if (ioctl_ctx_ifr(ctx, SIOCSLANPCP, &ifr) == -1)
- err(1, "SIOCSLANPCP");
+ if_err(1, "SIOCSLANPCP");
}
static void
@@ -1569,7 +1566,7 @@
ifr.ifr_lan_pcp = IFNET_PCP_NONE;
if (ioctl_ctx_ifr(ctx, SIOCSLANPCP, &ifr) == -1)
- err(1, "SIOCSLANPCP");
+ if_err(1, "SIOCSLANPCP");
}
static void
@@ -1581,11 +1578,11 @@
ifr_set_name(&ifr, ctx->ifname);
newname = strdup(val);
if (newname == NULL)
- err(1, "no memory to set ifname");
+ if_err(1, "no memory to set ifname");
ifr.ifr_data = newname;
if (ioctl_ctx(ctx, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
free(newname);
- err(1, "ioctl SIOCSIFNAME (set name)");
+ if_err(1, "ioctl SIOCSIFNAME (set name)");
}
ifname_update(ctx, newname);
free(newname);
@@ -1605,13 +1602,13 @@
newdescr = strdup(val);
ifr.ifr_buffer.buffer = newdescr;
if (newdescr == NULL) {
- warn("no memory to set ifdescr");
+ if_warn("no memory to set ifdescr");
return;
}
}
if (ioctl_ctx_ifr(ctx, SIOCSIFDESCR, &ifr) < 0)
- err(1, "ioctl SIOCSIFDESCR (set descr)");
+ if_err(1, "ioctl SIOCSIFDESCR (set descr)");
free(newdescr);
}
@@ -1624,200 +1621,6 @@
#ifdef WITHOUT_NETLINK
-static const char *IFFBITS[] = {
- [0] = "UP",
- [1] = "BROADCAST",
- [2] = "DEBUG",
- [3] = "LOOPBACK",
- [4] = "POINTOPOINT",
- [6] = "RUNNING",
- [7] = "NOARP",
- [8] = "PROMISC",
- [9] = "ALLMULTI",
- [10] = "OACTIVE",
- [11] = "SIMPLEX",
- [12] = "LINK0",
- [13] = "LINK1",
- [14] = "LINK2",
- [15] = "MULTICAST",
- [17] = "PPROMISC",
- [18] = "MONITOR",
- [19] = "STATICARP",
- [20] = "STICKYARP",
-};
-
-static const char *IFCAPBITS[] = {
- [0] = "RXCSUM",
- [1] = "TXCSUM",
- [2] = "NETCONS",
- [3] = "VLAN_MTU",
- [4] = "VLAN_HWTAGGING",
- [5] = "JUMBO_MTU",
- [6] = "POLLING",
- [7] = "VLAN_HWCSUM",
- [8] = "TSO4",
- [9] = "TSO6",
- [10] = "LRO",
- [11] = "WOL_UCAST",
- [12] = "WOL_MCAST",
- [13] = "WOL_MAGIC",
- [14] = "TOE4",
- [15] = "TOE6",
- [16] = "VLAN_HWFILTER",
- [18] = "VLAN_HWTSO",
- [19] = "LINKSTATE",
- [20] = "NETMAP",
- [21] = "RXCSUM_IPV6",
- [22] = "TXCSUM_IPV6",
- [23] = "HWSTATS",
- [24] = "TXRTLMT",
- [25] = "HWRXTSTMP",
- [26] = "MEXTPG",
- [27] = "TXTLS4",
- [28] = "TXTLS6",
- [29] = "VXLAN_HWCSUM",
- [30] = "VXLAN_HWTSO",
- [31] = "TXTLS_RTLMT",
-};
-
-static void
-print_ifcap_nv(if_ctx *ctx)
-{
- struct ifreq ifr = {};
- nvlist_t *nvcap;
- const char *nvname;
- void *buf, *cookie;
- bool first, val;
- int type;
-
- buf = malloc(IFR_CAP_NV_MAXBUFSIZE);
- if (buf == NULL)
- Perror("malloc");
- ifr.ifr_cap_nv.buffer = buf;
- ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE;
- if (ioctl_ctx_ifr(ctx, SIOCGIFCAPNV, &ifr) != 0)
- Perror("ioctl (SIOCGIFCAPNV)");
- nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer,
- ifr.ifr_cap_nv.length, 0);
- if (nvcap == NULL)
- Perror("nvlist_unpack");
- printf("\toptions");
- cookie = NULL;
- for (first = true;; first = false) {
- nvname = nvlist_next(nvcap, &type, &cookie);
- if (nvname == NULL) {
- printf("\n");
- break;
- }
- if (type == NV_TYPE_BOOL) {
- val = nvlist_get_bool(nvcap, nvname);
- if (val) {
- printf("%c%s",
- first ? ' ' : ',', nvname);
- }
- }
- }
- if (ctx->args->supmedia) {
- printf("\tcapabilities");
- cookie = NULL;
- for (first = true;; first = false) {
- nvname = nvlist_next(nvcap, &type,
- &cookie);
- if (nvname == NULL) {
- printf("\n");
- break;
- }
- if (type == NV_TYPE_BOOL)
- printf("%c%s", first ? ' ' :
- ',', nvname);
- }
- }
- nvlist_destroy(nvcap);
- free(buf);
-
- if (ioctl_ctx(ctx, SIOCGIFCAP, (caddr_t)&ifr) != 0)
- Perror("ioctl (SIOCGIFCAP)");
-}
-
-static void
-print_ifcap(if_ctx *ctx)
-{
- struct ifreq ifr = {};
-
- if (ioctl_ctx_ifr(ctx, SIOCGIFCAP, &ifr) != 0)
- return;
-
- if ((ifr.ifr_curcap & IFCAP_NV) != 0)
- print_ifcap_nv(ctx);
- else {
- printf("\toptions=%x", ifr.ifr_curcap);
- print_bits("options", &ifr.ifr_curcap, 1, IFCAPBITS, nitems(IFCAPBITS));
- putchar('\n');
- if (ctx->args->supmedia && ifr.ifr_reqcap != 0) {
- printf("\tcapabilities=%x", ifr.ifr_reqcap);
- print_bits("capabilities", &ifr.ifr_reqcap, 1, IFCAPBITS, nitems(IFCAPBITS));
- putchar('\n');
- }
- }
-}
-#endif
-
-void
-print_ifstatus(if_ctx *ctx)
-{
- struct ifstat ifs;
-
- strlcpy(ifs.ifs_name, ctx->ifname, sizeof ifs.ifs_name);
- if (ioctl_ctx(ctx, SIOCGIFSTATUS, &ifs) == 0)
- printf("%s", ifs.ascii);
-}
-
-void
-print_metric(if_ctx *ctx)
-{
- struct ifreq ifr = {};
-
- if (ioctl_ctx_ifr(ctx, SIOCGIFMETRIC, &ifr) != -1)
- printf(" metric %d", ifr.ifr_metric);
-}
-
-#ifdef WITHOUT_NETLINK
-static void
-print_mtu(if_ctx *ctx)
-{
- struct ifreq ifr = {};
-
- if (ioctl_ctx_ifr(ctx, SIOCGIFMTU, &ifr) != -1)
- printf(" mtu %d", ifr.ifr_mtu);
-}
-
-static void
-print_description(if_ctx *ctx)
-{
- struct ifreq ifr = {};
-
- ifr_set_name(&ifr, ctx->ifname);
- for (;;) {
- if ((descr = reallocf(descr, descrlen)) != NULL) {
- ifr.ifr_buffer.buffer = descr;
- ifr.ifr_buffer.length = descrlen;
- if (ioctl_ctx(ctx, SIOCGIFDESCR, &ifr) == 0) {
- if (ifr.ifr_buffer.buffer == descr) {
- if (strlen(descr) > 0)
- printf("\tdescription: %s\n",
- descr);
- } else if (ifr.ifr_buffer.length > descrlen) {
- descrlen = ifr.ifr_buffer.length;
- continue;
- }
- }
- } else
- warn("unable to allocate memory for interface"
- "description");
- break;
- }
-}
-
/*
* Print the status of the interface. If an address family was
* specified, show only it; otherwise, show them all.
@@ -1839,19 +1642,20 @@
s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
if (s < 0)
- err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
+ if_err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
old_s = ctx->io_s;
ctx->io_s = s;
- printf("%s: flags=%x", ctx->ifname, ifa->ifa_flags);
- print_bits("flags", &ifa->ifa_flags, 1, IFFBITS, nitems(IFFBITS));
- print_metric(ctx);
- print_mtu(ctx);
- putchar('\n');
+ ifconfig_print_flags(ctx, ifa);
+ ifconfig_print_bits("flags", "flag", &ifa->ifa_flags, 1, IFFBITS,
+ nitems(IFFBITS));
+ ifconfig_print_metric(ctx);
+ ifconfig_print_mtu(ctx);
+ ifconfig_print_newline();
- print_description(ctx);
+ ifconfig_print_description(ctx);
- print_ifcap(ctx);
+ ifconfig_print_ifcap(ctx);
tunnel_status(ctx);
@@ -1890,7 +1694,7 @@
else if (args->afp->af_other_status != NULL)
args->afp->af_other_status(ctx);
- print_ifstatus(ctx);
+ ifconfig_print_ifstatus(ctx);
if (args->verbose > 0)
sfp_status(ctx);
@@ -1920,7 +1724,7 @@
break;
default:
- errc(1, error, "%s", cmd);
+ if_errc(1, error, "%s", cmd);
}
}
@@ -1930,75 +1734,6 @@
Perrorc(cmd, errno);
}
-void
-print_bits(const char *btype, uint32_t *v, const int v_count,
- const char **names, const int n_count)
-{
- int num = 0;
-
- for (int i = 0; i < v_count * 32; i++) {
- bool is_set = v[i / 32] & (1U << (i % 32));
- if (is_set) {
- if (num++ == 0)
- printf("<");
- if (num != 1)
- printf(",");
- if (i < n_count)
- printf("%s", names[i]);
- else
- printf("%s_%d", btype, i);
- }
- }
- if (num > 0)
- printf(">");
-}
-
-/*
- * Print a value a la the %b format of the kernel's printf
- */
-void
-printb(const char *s, unsigned v, const char *bits)
-{
- int i, any = 0;
- char c;
-
- if (bits && *bits == 8)
- printf("%s=%o", s, v);
- else
- printf("%s=%x", s, v);
- if (bits) {
- bits++;
- putchar('<');
- while ((i = *bits++) != '\0') {
- if (v & (1u << (i-1))) {
- if (any)
- putchar(',');
- any = 1;
- for (; (c = *bits) > 32; bits++)
- putchar(c);
- } else
- for (; *bits > 32; bits++)
- ;
- }
- putchar('>');
- }
-}
-
-void
-print_vhid(const struct ifaddrs *ifa)
-{
- 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(struct ifconfig_args *args, const char *name)
{
diff --git a/sbin/ifconfig/ifconfig_netlink.c b/sbin/ifconfig/ifconfig_netlink.c
--- a/sbin/ifconfig/ifconfig_netlink.c
+++ b/sbin/ifconfig/ifconfig_netlink.c
@@ -52,36 +52,10 @@
#include <net/if_dl.h>
#include <net/if_strings.h>
#include <net/if_types.h>
+
#include "ifconfig.h"
#include "ifconfig_netlink.h"
-
-static const char *IFFBITS[] = {
- "UP", /* 00:0x1 IFF_UP*/
- "BROADCAST", /* 01:0x2 IFF_BROADCAST*/
- "DEBUG", /* 02:0x4 IFF_DEBUG*/
- "LOOPBACK", /* 03:0x8 IFF_LOOPBACK*/
- "POINTOPOINT", /* 04:0x10 IFF_POINTOPOINT*/
- "NEEDSEPOCH", /* 05:0x20 IFF_NEEDSEPOCH*/
- "RUNNING", /* 06:0x40 IFF_DRV_RUNNING*/
- "NOARP", /* 07:0x80 IFF_NOARP*/
- "PROMISC", /* 08:0x100 IFF_PROMISC*/
- "ALLMULTI", /* 09:0x200 IFF_ALLMULTI*/
- "DRV_OACTIVE", /* 10:0x400 IFF_DRV_OACTIVE*/
- "SIMPLEX", /* 11:0x800 IFF_SIMPLEX*/
- "LINK0", /* 12:0x1000 IFF_LINK0*/
- "LINK1", /* 13:0x2000 IFF_LINK1*/
- "LINK2", /* 14:0x4000 IFF_LINK2*/
- "MULTICAST", /* 15:0x8000 IFF_MULTICAST*/
- "CANTCONFIG", /* 16:0x10000 IFF_CANTCONFIG*/
- "PPROMISC", /* 17:0x20000 IFF_PPROMISC*/
- "MONITOR", /* 18:0x40000 IFF_MONITOR*/
- "STATICARP", /* 19:0x80000 IFF_STATICARP*/
- "STICKYARP", /* 20:0x100000 IFF_STICKYARP*/
- "DYING", /* 21:0x200000 IFF_DYING*/
- "", /* 22:0x400000 */
- "PALLMULTI", /* 23:0x800000 IFF_PALLMULTI*/
- "LOWER_UP", /* 24:0x1000000 IFF_NETLINK_1*/
-};
+#include "ifconfig_output.h"
static void
nl_init_socket(struct snl_state *ss)
@@ -92,12 +66,12 @@
if (modfind("netlink") == -1 && errno == ENOENT) {
/* Try to load */
if (kldload("netlink") == -1)
- err(1, "netlink is not loaded and load attempt failed");
+ if_err(1, "netlink is not loaded and load attempt failed");
if (snl_init(ss, NETLINK_ROUTE))
return;
}
- err(1, "unable to open netlink socket");
+ if_err(1, "unable to open netlink socket");
}
int
@@ -342,28 +316,6 @@
}
}
-static void
-print_ifcaps(if_ctx *ctx, if_link_t *link)
-{
- uint32_t sz_u32 = roundup2(link->iflaf_caps.nla_bitset_size, 32) / 32;
-
- if (sz_u32 > 0) {
- uint32_t *caps = link->iflaf_caps.nla_bitset_value;
-
- printf("\toptions=%x", caps[0]);
- print_bits("IFCAPS", caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
- putchar('\n');
- }
-
- if (ctx->args->supmedia && sz_u32 > 0) {
- uint32_t *caps = link->iflaf_caps.nla_bitset_mask;
-
- printf("\tcapabilities=%x", caps[0]);
- print_bits("IFCAPS", caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
- putchar('\n');
- }
-}
-
static void
status_nl(if_ctx *ctx, struct iface *iface)
{
@@ -371,18 +323,21 @@
struct ifconfig_args *args = ctx->args;
char *drivername = NULL;
- printf("%s: ", link->ifla_ifname);
+ ifconfig_open_instance("interface");
- printf("flags=%x", link->ifi_flags);
- print_bits("IFF", &link->ifi_flags, 1, IFFBITS, nitems(IFFBITS));
+ ifconfig_netlink_print_ifname(link);
- print_metric(ctx);
- printf(" mtu %d\n", link->ifla_mtu);
+ ifconfig_netlink_print_flags(link);
+ ifconfig_print_bits("interface-flags", "flag", &link->ifi_flags, 1,
+ IFFBITS, nitems(IFFBITS));
+
+ ifconfig_print_metric(ctx);
+ ifconfig_netlink_print_mtu(link);
if (link->ifla_ifalias != NULL)
- printf("\tdescription: %s\n", link->ifla_ifalias);
+ ifconfig_netlink_print_ifalias(link);
- print_ifcaps(ctx, link);
+ ifconfig_netlink_print_ifcaps(ctx, link);
tunnel_status(ctx);
if (args->allfamilies | (args->afp != NULL && args->afp->af_af == AF_LINK)) {
@@ -394,7 +349,10 @@
sort_iface_ifaddrs(ctx->io_ss, iface);
+ ifconfig_open_container("addresses");
+
for (struct ifa *ifa = iface->ifa; ifa != NULL; ifa = ifa->next) {
+ ifconfig_open_instance("address");
if (args->allfamilies) {
const struct afswtch *p = af_getbyfamily(ifa->addr.ifa_family);
@@ -405,15 +363,19 @@
p->af_status(ctx, link, &ifa->addr);
}
+ ifconfig_close_instance("address");
}
+ ifconfig_close_container("addresses");
+
/* TODO: convert to netlink */
if (args->allfamilies)
af_other_status(ctx);
else if (args->afp->af_other_status != NULL)
args->afp->af_other_status(ctx);
- print_ifstatus(ctx);
+ ifconfig_print_ifstatus(ctx);
+
if (args->drivername || args->verbose) {
if (ifconfig_get_orig_name(lifh, link->ifla_ifname,
&drivername) != 0) {
@@ -427,11 +389,14 @@
exit_code = 1;
}
if (drivername != NULL)
- printf("\tdrivername: %s\n", drivername);
+ ifconfig_netlink_print_drivername(drivername);
free(drivername);
}
if (args->verbose > 0)
sfp_status(ctx);
+
+ ifconfig_close_instance("interface");
+
}
static int
@@ -440,7 +405,7 @@
int s = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (s < 0)
- err(1, "socket(family %u,SOCK_DGRAM)", AF_LOCAL);
+ if_err(1, "socket(family %u,SOCK_DGRAM)", AF_LOCAL);
return (s);
}
@@ -469,6 +434,8 @@
qsort(sorted_ifaces, ifmap->count, sizeof(void *), cmp_iface);
prepare_ifaddrs(&ss, ifmap);
+ ifconfig_open_list("interfaces");
+
for (uint32_t i = 0, num = 0; i < ifmap->count; i++) {
struct iface *iface = sorted_ifaces[i];
@@ -479,7 +446,7 @@
if (args->namesonly) {
if (num++ != 0)
- printf(" ");
+ ifconfig_print_space();
fputs(iface->link.ifla_ifname, stdout);
} else if (args->argc == 0)
status_nl(ctx, iface);
@@ -487,8 +454,9 @@
ifconfig_ioctl(ctx, 0, args->afp);
}
if (args->namesonly)
- printf("\n");
+ ifconfig_print_newline();
+ ifconfig_close_list("interfaces");
close(ctx->io_s);
snl_free(&ss);
}
diff --git a/sbin/ifconfig/ifconfig_output.h b/sbin/ifconfig/ifconfig_output.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/ifconfig_output.h
@@ -0,0 +1,382 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#pragma once
+
+#include <net/ieee8023ad_lacp.h>
+#include <net/if_lagg.h>
+#include <net/if_stf.h>
+#include <net/if_vlan_var.h>
+#include <net/if_vxlan.h>
+
+#include <libifconfig_sfp.h>
+
+#include "ifgeneve.h"
+#include "ifieee80211.h"
+
+static char
+ ifconfig_ifname_to_print[IFNAMSIZ]; /* Helper for
+ ifconfig_printifnamemaybe() */
+
+#define IFIEEE80211_MAXCOL 78
+static int ifieee80211_col;
+static char ifieee80211_spacer;
+
+void af_inet_print_addr(struct sockaddr_in *sin);
+char *af_inet6_sec2str(time_t);
+void af_inet6_print_addr(struct sockaddr_in6 *sin);
+void af_inet6_print_pointtopoint(struct sockaddr_in6 *sin);
+void af_inet6_print_mask(int plen);
+void af_inet6_print_flags(int flags6);
+void af_inet6_print_lifetime(const char *prepend, time_t px_time,
+ struct timespec *now);
+
+void af_link_print_ether(const struct ether_addr *addr, const char *prefix);
+void af_link_print_lladdr(struct sockaddr_dl *sdl);
+void af_link_print_pcp(if_ctx *ctx);
+void ifbridge_print_vlans(ifbvlan_set_t *vlans);
+void ifconfig_printifnamemaybe(void);
+int ifconfig_parse_args(int ac, char *av[]);
+void ifconfig_finish(void);
+void ifconfig_open_container(const char *name);
+void ifconfig_close_container(const char *name);
+void ifconfig_open_list(const char *name);
+void ifconfig_close_list(const char *name);
+void ifconfig_open_instance(const char *name);
+void ifconfig_close_instance(const char *name);
+void ifconfig_print_ifcap_nv(if_ctx *ctx);
+void ifconfig_print_ifcap(if_ctx *ctx);
+void ifconfig_print_ifstatus(if_ctx *ctx);
+void ifconfig_print_metric(if_ctx *ctx);
+void ifconfig_print_mtu(if_ctx *ctx);
+void ifconfig_print_description(if_ctx *ctx);
+void ifconfig_print_bits(const char *btype, const char *child, uint32_t *v,
+ const int v_count, const char **names, const int n_count);
+
+void ifconfig_printb(const char *s, unsigned v, const char *bits);
+void ifconfig_print_vhid(const struct ifaddrs *ifa);
+void ifconfig_netlink_print_ifcaps(if_ctx *ctx, if_link_t *link);
+void ifgroup_printgroup(const char *groupname);
+void ifieee80211_line_init(char c);
+void ifieee80211_line_break(void);
+void ifieee80211_line_check(const char *fmt, ...);
+void ifieee80211_print_chaninfo(const struct ieee80211_channel *c, int verb);
+void ifieee80211_print_channels(if_ctx *ctx,
+ const struct ieee80211req_chaninfo *chans, int allchans, int verb);
+
+void ifieee80211_print_txpow(const struct ieee80211_channel *c);
+void ifieee80211_print_txpow_verbose(const struct ieee80211_channel *c);
+void ifieee80211_print_regdomain(const struct ieee80211_regdomain *reg,
+ int verb);
+
+void ifieee80211_printcipher(int s, struct ieee80211req *ireq, int keylenop);
+void ifieee80211_printkey_index(uint16_t keyix, char *buf, size_t buflen);
+void ifieee80211_printkey(if_ctx *ctx, const struct ieee80211req_key *ik);
+void ifieee80211_printrate(const char *tag, int v, int defrate, int defmcs);
+void ifieee80211_print_string(const u_int8_t *buf, int len);
+void ifieee80211_printie(if_ctx *ctx, const char *tag, const uint8_t *ie,
+ size_t ielen, unsigned int maxlen);
+
+void ifieee80211_printwmeparam(if_ctx *ctx, const char *tag,
+ const u_int8_t *ie);
+
+void ifieee80211_printwmeinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printhecap(if_ctx *ctx, const char *tag, const uint8_t *ie);
+void ifieee80211_printheoper(if_ctx *ctx, const char *tag, const uint8_t *ie);
+void ifieee80211_printmuedcaparamset(if_ctx *ctx, const char *tag,
+ const uint8_t *ie);
+
+void ifieee80211_printsupopclass(if_ctx *ctx, const char *tag,
+ const u_int8_t *ie);
+
+void ifieee80211_printvhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printvhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printvhtpwrenv(if_ctx *ctx, const char *tag,
+ const u_int8_t *ie, size_t ielen);
+
+void ifieee80211_printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printathie(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printmeshconf(if_ctx *ctx, const char *tag, const uint8_t *ie);
+void ifieee80211_printbssload(if_ctx *ctx, const char *tag, const uint8_t *ie);
+void ifieee80211_printapchanrep(if_ctx *ctx, const char *tag,
+ const u_int8_t *ie, size_t ielen);
+
+void ifieee80211_printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen);
+
+void ifieee80211_printrsnxe(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen);
+
+void ifieee80211_printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie);
+void ifieee80211_printtdmaie(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen);
+
+void ifieee80211_printssid(const char *tag, const u_int8_t *ie, int maxlen);
+void ifieee80211_printrates(const char *tag, const u_int8_t *ie, size_t ielen);
+void ifieee80211_printcountry(const char *tag, const u_int8_t *ie);
+void ifieee80211_printexties(if_ctx *ctx, const u_int8_t *vp,
+ unsigned int maxcols);
+
+void ifieee80211_printies(if_ctx *ctx, const u_int8_t *vp, int ielen,
+ unsigned int maxcols);
+
+void ifieee80211_printmimo(const struct ieee80211_mimo_info *mi);
+void ifieee80211_printbssidname(const struct ether_addr *n);
+void ifieee80211_printpolicy(int policy);
+void ifmedia_print_media(ifmedia_t media, bool print_toptype);
+void ifmedia_print_media_ifconfig(ifmedia_t media);
+
+void ifconfig_print_space(void);
+void ifconfig_print_char(char c);
+void ifconfig_print_tab(void);
+void ifconfig_print_newline(void);
+
+void ifconfig_print_flags(if_ctx *ctx, const struct ifaddrs *ifa);
+void ifclone_print_cloners(const char *name);
+
+void af_inet_print_addr_pointtopoint(struct sockaddr_in *sin);
+void af_inet_print_cidr_mask(int cidr);
+void af_inet_print_netmask_str(struct in_addr addr);
+void af_inet_print_netmask(struct in_addr addr);
+void af_inet_print_broadcast(struct sockaddr_in *sin);
+void af_inet_print_vhid(if_addr_t *ifa);
+void af_inet_print_tunnel_inet(const char *src, const char *dst);
+
+void af_inet6_print_scopeid(uint32_t scopeid);
+void af_inet6_print_vhid(if_addr_t *ifa);
+void af_inet6_print_tunnel(const char *src, const char *dst);
+
+void af_nd6_print_options(uint32_t bits);
+
+void carp_print_summary(const char *state, struct ifconfig_carp *carpr);
+void carp_print_key(struct ifconfig_carp *carpr);
+void carp_print_peer(struct ifconfig_carp *carpr, const char *peer_addr);
+void carp_print_vrrp3(const char *state, struct ifconfig_carp *carpr);
+
+void iffib_print_fib(struct ifreq *ifr);
+void iffib_print_tunnelfib(struct ifreq *ifr);
+
+void ifgif_print_options(int opts);
+
+void ifgre_print_key(uint32_t opts);
+void ifgre_print_udpport(uint32_t port);
+void ifgre_print_options(uint32_t opts);
+
+void ifgroup_print_groups(void);
+void ifgroup_print_group(struct ifg_req *ifg);
+
+void ifipsec_print_reqid(uint32_t reqid);
+
+void iflagg_print_laggproto(const char *proto);
+void iflagg_print_lagghash(void);
+void iflagg_print_l2(const char *sep);
+void iflagg_print_l3(const char *sep);
+void iflagg_print_l4(const char *sep);
+void iflagg_print_options(void);
+void iflagg_print_flowid_shift(struct lagg_reqopts *ro);
+void iflagg_print_trr_limit(struct lagg_reqopts *ro);
+void iflagg_print_statistics(void);
+void iflagg_print_active_ports(struct lagg_reqopts *ro);
+void iflagg_print_flapping(struct lagg_reqopts *ro);
+void iflagg_print_lagg_id(struct lacp_opreq *lp);
+void iflagg_print_laggport(struct lagg_reqport *port);
+void iflagg_print_peer(struct lacp_opreq *lp);
+
+void ifmac_print_maclabel(const char *label_text);
+
+void ifmedia_print_media_header(void);
+void ifmedia_print_status(const char *status);
+void ifmedia_print_reason(struct ifdownreason *ifdr);
+void ifmedia_print_reason_vendor(struct ifdownreason *ifdr);
+void ifmedia_print_supmedia(void);
+
+void ifpfsync_print_syncdev(const char *syncdev);
+void ifpfsync_print_syncpeer(const char *syncpeer_str);
+void ifpfsync_print_maxupd(int maxupdates);
+void ifpfsync_print_defer(int flags);
+void ifpfsync_print_version(int version);
+void ifpfsync_print_syncok(int flags);
+
+void ifstf_print_v4net(struct stfv4args *param);
+void ifstf_print_tv4br(struct stfv4args *param);
+
+void ifvlan_print_vlan(struct vlanreq *vreq);
+void ifvlan_print_vlanproto(void);
+void ifvlan_print_8021q(const char *proto_8021Q);
+void ifvlan_print_8021d(const char *proto_8021ad);
+void ifvlan_print_otherproto(struct vlanreq *vreq);
+void ifvlan_print_vlanpcp(struct ifreq *ifr);
+void ifvlan_print_parent(struct vlanreq *vreq);
+
+void ifvxlan_print_vni(int vni);
+void ifvxlan_print_src(int ipv6, const char *src, const char *srcport);
+void ifvxlan_print_dst(int mc, int ipv6, const char *dst, const char *dstport);
+void ifvxlan_print_config(void);
+void ifvxlan_print_portrange(struct ifvxlancfg *cfg);
+void ifvxlan_print_ftable(void);
+void ifvxlan_print_threshold(struct ifvxlancfg *cfg);
+
+void ifconfig_netlink_print_ifname(if_link_t *link);
+void ifconfig_netlink_print_flags(if_link_t *link);
+void ifconfig_netlink_print_mtu(if_link_t *link);
+void ifconfig_netlink_print_ifalias(if_link_t *link);
+void ifconfig_netlink_print_drivername(const char *drivername);
+
+void ifgeneve_print_mode(void);
+void ifgeneve_print_proto_l3(void);
+void ifgeneve_print_proto_l2(void);
+void ifgeneve_print_config(void);
+void ifgeneve_print_config_vni_notconfigured(void);
+void ifgeneve_print_vni(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_src(int ipv6, const char *src,
+ struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_dst(int mc, int ipv6, const char *dst,
+ struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_mcastdev(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_portrange(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_ttl(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_ttl_inherit(void);
+void ifgeneve_print_dscp(void);
+void ifgeneve_print_df_inherit(void);
+void ifgeneve_print_df_set(void);
+void ifgeneve_print_df_unset(void);
+void ifgeneve_print_extctl(void);
+void ifgeneve_print_ftable_mode(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_ftable(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_ftable_nospace(struct nl_parsed_geneve *geneve_data);
+void ifgeneve_print_stats(struct nl_parsed_geneve *geneve_data);
+
+void ifbridge_print_vlan(const char *prefix, struct ifbareq *ifba);
+void ifbridge_print_summary(struct ifconfig_bridge_status *bridge);
+void ifbridge_print_defuntagged(struct ifconfig_bridge_status *bridge);
+void ifbridge_print_bridge_member(const char *prefix, struct ifbreq *member);
+void ifbridge_print_bridge_member_pad(const char *pad);
+void ifbridge_print_bridge_member_maxaddr(struct ifbreq *member);
+void ifbridge_print_bridge_member_stp(struct ifbreq *member);
+void ifbridge_print_bridge_member_proto(int proto);
+void ifbridge_print_bridge_member_proto_unknown(int proto);
+void ifbridge_print_bridge_member_role(int role);
+void ifbridge_print_bridge_member_role_unknown(int role);
+void ifbridge_print_bridge_member_state(int state);
+void ifbridge_print_bridge_member_state_unknown(int state);
+void ifbridge_print_bridge_member_vlan_proto(struct ifbreq *member);
+void ifbridge_print_bridge_member_pvid(struct ifbreq *member);
+
+void sfp_print_plugged(struct ifconfig_sfp_info *info,
+ struct ifconfig_sfp_info_strings *strings);
+void sfp_print_vendor(struct ifconfig_sfp_vendor_info *vendor_info);
+void sfp_print_verbose_compliance(struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_class(struct ifconfig_sfp_info *info,
+ struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_length(struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_tech(struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_media(struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_speed(struct ifconfig_sfp_info_strings *strings);
+void sfp_print_verbose_nombitrate(struct ifconfig_sfp_status *status);
+void sfp_print_verbose_voltage(struct ifconfig_sfp_status *status);
+void sfp_print_verbose_rxpower(size_t chan, uint16_t rx, uint16_t tx);
+void sfp_print_verbose_cmis_dump1(const void *buf, int len);
+void sfp_print_verbose_cmis_dump2(const void *buf, int len);
+void sfp_print_verbose_cmis_dump3(const void *buf, int len);
+void sfp_print_verbose_sff8436_dump1(const void *buf, int len);
+void sfp_print_verbose_sff8436_dump2(const void *buf, int len);
+void sfp_print_verbose_sff8472_dump1(const void *buf);
+
+void ifieee80211_print_drivercaps(struct ieee80211_devcaps_req *dc);
+void ifieee80211_print_cryptocaps(struct ieee80211_devcaps_req *dc);
+void ifieee80211_print_htcaps(struct ieee80211_devcaps_req *dc);
+void ifieee80211_print_vhtcaps(struct ieee80211_devcaps_req *dc);
+void ifieee80211_print_regdomain_addchans(const char *func);
+void ifieee80211_print_verbose_vht20_skip(uint32_t freq);
+void ifieee80211_print_verbose_vht40_skip(uint32_t freq);
+void ifieee80211_print_verbose_vht80_skip(uint32_t freq);
+void ifieee80211_print_verbose_vht160_skip(uint32_t freq);
+void ifieee80211_print_verbose_vht80p80_skip(uint32_t freq);
+void ifieee80211_print_verbose_ht20_skip(uint32_t freq);
+void ifieee80211_print_verbose_ht40_skip(uint32_t freq);
+void ifieee80211_print_verbose_freq_skip(uint32_t freq);
+void ifieee80211_print_verbose_checkchan_notavail(void);
+void ifieee80211_print_verbose_ecm_chan(uint32_t freq);
+void ifieee80211_print_verbose_indoor_chan_skip(uint32_t freq);
+void ifieee80211_print_verbose_outdoor_chan_skip(uint32_t freq);
+void ifieee80211_print_verbose_chansep_need(int freq, int separation, int need);
+void ifieee80211_print_verbose_chan_table_full(uint32_t freq);
+void ifieee80211_print_verbose_add_freq(struct ieee80211req_chaninfo *ci,
+ const struct ieee80211_channel *c);
+void ifieee80211_print_verbose_maxregpower(const struct ieee80211_channel *c);
+void ifieee80211_print_country_codes(void);
+void ifieee80211_print_country_code(const struct country *cp, int i);
+void ifieee80211_print_reg_domains(void);
+void ifieee80211_print_reg_domain(const struct regdomain *dp, int i);
+void ifieee80211_print_list_scan_hdr(void);
+void ifieee80211_print_list_scan_row(const struct ieee80211req_scan_result *sr,
+ const uint8_t *idp, int idlen);
+void ifieee80211_print_list_stations_hdr(void);
+void ifieee80211_print_list_stations_hdr2(void);
+void ifieee80211_print_list_stations_row(
+ const struct ieee80211req_sta_info *si);
+void ifieee80211_print_list_stations_row2(
+ const struct ieee80211req_sta_info *si);
+void ifieee80211_print_list_wme_aci_tag(const char *tag);
+void ifieee80211_print_list_wme_aci_cwmin(int val);
+void ifieee80211_print_list_wme_aci_cwmax(int val);
+void ifieee80211_print_list_wme_aci_aifs(int val);
+void ifieee80211_print_list_wme_aci_txoplimit(int val);
+void ifieee80211_print_list_wme_aci_acm_enabled(void);
+void ifieee80211_print_list_wme_aci_acm_disabled(void);
+void ifieee80211_print_list_wme_aci_ack_enabled(void);
+void ifieee80211_print_list_wme_aci_ack_disabled(void);
+void ifieee80211_print_list_mac_acl_loaded(void);
+void ifieee80211_print_list_mac_unknown_policy(unsigned int policy);
+void ifieee80211_print_list_mac_nacl(char c, struct ieee80211req_maclist *acl);
+void ifieee80211_print_list_mesh_hdr(void);
+void ifieee80211_print_list_mesh_row(const struct ieee80211req_mesh_route *rt);
+void ifieee80211_print_list_mesh_row2(const struct ieee80211req_mesh_route *rt);
+void ifieee80211_print_ieee80211_status_meshid(void);
+void ifieee80211_print_ieee80211_status_ssid(void);
+void ifieee80211_print_ieee80211_status_ssid_idx(int i);
+void ifieee80211_print_ieee80211_status_channel(
+ const struct ieee80211_channel *c);
+void ifieee80211_print_ieee80211_status_channel_undef(void);
+void ifieee80211_print_ieee80211_status_bssid(const uint8_t *bssid);
+void ifieee80211_print_ieee80211_status_stationname(void);
+
+void if_err(int eval, const char *fmt, ...) __attribute__((__noreturn__))
+__printflike(2, 3);
+void if_errc(int eval, int code, const char *fmt, ...)
+ __attribute__((__noreturn__)) __printflike(3, 4);
+void if_errx(int eval, const char *fmt, ...) __attribute__((__noreturn__))
+__printflike(2, 3);
+void if_warn(const char *fmt, ...) __printflike(1, 2);
+void if_warnc(int cond, int code, const char *fmt, ...) __printflike(3, 4);
+void if_warnx(const char *fmt, ...) __printflike(1, 2);
diff --git a/sbin/ifconfig/ifconfig_output.c b/sbin/ifconfig/ifconfig_output.c
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/ifconfig_output.c
@@ -0,0 +1,5595 @@
+#define _WANT_IFCAP_BIT_NAMES
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/nv.h>
+
+#include <net/ethernet.h>
+#include <net/ieee8023ad_lacp.h>
+#include <net/if.h>
+#include <net/if_bridgevar.h>
+#include <net/if_dl.h>
+#include <net/if_lagg.h>
+#include <net/if_media.h>
+#include <net/if_pfsync.h>
+#include <net/if_stf.h>
+#include <net/if_strings.h>
+#include <net/if_types.h>
+#include <net/if_vlan_var.h>
+#include <net/if_vxlan.h>
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+
+#include <arpa/inet.h>
+#include <ctype.h>
+#include <err.h>
+#include <ifaddrs.h>
+#include <langinfo.h>
+#include <libifconfig_sfp.h>
+#include <libutil.h>
+#include <locale.h>
+#include <netdb.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef WITHOUT_NETLINK
+#include <netlink/netlink.h>
+#include <netlink/netlink_route.h>
+#include <netlink/netlink_snl.h>
+#include <netlink/netlink_snl_route.h>
+#include <netlink/netlink_snl_route_compat.h>
+#include <netlink/netlink_snl_route_parsers.h>
+#endif
+
+#include "af_inet6.h"
+#include "ifbridge.h"
+#include "ifconfig.h"
+#include "ifconfig_output.h"
+#include "ifieee80211.h"
+#include "iflagg.h"
+
+#ifdef WITH_LIBXO
+#include <libxo/xo.h>
+#define IFCONFIG_XO_VERSION "1"
+#endif
+
+static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
+
+void
+af_inet_print_addr(struct sockaddr_in *sin)
+{
+ int error, n_flags;
+
+ 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));
+
+#ifdef WITH_LIBXO
+ xo_emit("\tinet {:inet-addr/%s}", addr_buf);
+#else
+ printf("\tinet %s", addr_buf);
+#endif
+}
+
+void
+af_inet6_print_addr(struct sockaddr_in6 *sin)
+{
+ int error, n_flags;
+
+ 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));
+#ifdef WITH_LIBXO
+ xo_emit("\tinet6 {:inet6-addr/%s}", addr_buf);
+#else
+ printf("\tinet6 %s", addr_buf);
+#endif
+}
+
+void
+af_inet6_print_pointtopoint(struct sockaddr_in6 *sin)
+{
+ int error;
+
+ error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
+ sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
+
+ if (error != 0)
+ inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
+ sizeof(addr_buf));
+#ifdef WITH_LIBXO
+ xo_emit(" --> {:dst-addr/%s}", addr_buf);
+#else
+ printf(" --> %s", addr_buf);
+#endif
+}
+
+void
+af_inet6_print_mask(int plen)
+{
+ if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
+#ifdef WITH_LIBXO
+ xo_emit("/{:prefixlen/%d}", plen);
+#else
+ printf("/%d", plen);
+#endif
+ else
+#ifdef WITH_LIBXO
+ xo_emit(" prefixlen {:prefixlen/%d}", plen);
+#else
+ printf(" prefixlen %d", plen);
+#endif
+}
+
+void
+af_inet6_print_flags(int flags6)
+{
+#ifdef WITH_LIBXO
+ xo_open_list("flags6");
+ if ((flags6 & IN6_IFF_ANYCAST) != 0)
+ xo_emit(" {P:/anycast}{le:flags6/%s}", "anycast");
+ if ((flags6 & IN6_IFF_TENTATIVE) != 0)
+ xo_emit(" {P:/tentative}{le:flags6/%s}", "tentative");
+ if ((flags6 & IN6_IFF_DUPLICATED) != 0)
+ xo_emit(" {P:/duplicated}{le:flags6/%s}", "duplicated");
+ if ((flags6 & IN6_IFF_DETACHED) != 0)
+ xo_emit(" {P:/detached}{le:flags6/%s}", "detached");
+ if ((flags6 & IN6_IFF_DEPRECATED) != 0)
+ xo_emit(" {P:/deprecated}{le:flags6/%s}", "deprecated");
+ if ((flags6 & IN6_IFF_AUTOCONF) != 0)
+ xo_emit(" {P:/autoconf}{le:flags6/%s}", "autoconf");
+ if ((flags6 & IN6_IFF_TEMPORARY) != 0)
+ xo_emit(" {P:/temporary}{le:flags6/%s}", "temporary");
+ if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
+ xo_emit(" {P:/prefer_source}{le:flags6/%s}", "prefer_source");
+ xo_close_list("flags6");
+#else
+ if ((flags6 & IN6_IFF_ANYCAST) != 0)
+ printf(" anycast");
+ if ((flags6 & IN6_IFF_TENTATIVE) != 0)
+ printf(" tentative");
+ if ((flags6 & IN6_IFF_DUPLICATED) != 0)
+ printf(" duplicated");
+ if ((flags6 & IN6_IFF_DETACHED) != 0)
+ printf(" detached");
+ if ((flags6 & IN6_IFF_DEPRECATED) != 0)
+ printf(" deprecated");
+ if ((flags6 & IN6_IFF_AUTOCONF) != 0)
+ printf(" autoconf");
+ if ((flags6 & IN6_IFF_TEMPORARY) != 0)
+ printf(" temporary");
+ if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
+ printf(" prefer_source");
+#endif
+}
+
+void
+af_inet6_print_lifetime(const char *prepend, time_t px_time,
+ struct timespec *now)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" {P:/%s}", prepend);
+ if (px_time == 0)
+ xo_emit(" {P:/infty}");
+
+ xo_emit(" {P:/%s}",
+ px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
+#else
+ printf(" %s", prepend);
+ if (px_time == 0)
+ printf(" infty");
+
+ printf(" %s",
+ px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
+#endif
+}
+
+void
+af_link_print_ether(const struct ether_addr *addr, const char *prefix)
+{
+ char *ether_format = ether_ntoa(addr);
+
+ if (f_ether != NULL) {
+ if (strcmp(f_ether, "dash") == 0) {
+ char *format_char;
+
+ while (
+ (format_char = strchr(ether_format, ':')) != NULL) {
+ *format_char = '-';
+ }
+ } else if (strcmp(f_ether, "dotted") == 0) {
+ /* Indices 0 and 1 is kept as is. */
+ ether_format[2] = ether_format[3];
+ ether_format[3] = ether_format[4];
+ ether_format[4] = '.';
+ ether_format[5] = ether_format[6];
+ ether_format[6] = ether_format[7];
+ ether_format[7] = ether_format[9];
+ ether_format[8] = ether_format[10];
+ ether_format[9] = '.';
+ ether_format[10] = ether_format[12];
+ ether_format[11] = ether_format[13];
+ ether_format[12] = ether_format[15];
+ ether_format[13] = ether_format[16];
+ ether_format[14] = '\0';
+ }
+ }
+#ifdef WITH_LIBXO
+ xo_open_container("link-address");
+ xo_emit("{P:\t}{:addr-type/%s} {:link-addr/%s}\n", prefix,
+ ether_format);
+ xo_close_container("link-address");
+#else
+ printf("\t%s %s\n", prefix, ether_format);
+#endif
+}
+
+void
+af_link_print_lladdr(struct sockaddr_dl *sdl)
+{
+ if (match_ether(sdl)) {
+ af_link_print_ether((struct ether_addr *)LLADDR(sdl), "ether");
+ } else {
+ int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
+#ifdef WITH_LIBXO
+ xo_open_container("link-address");
+ xo_emit("{P:\t}lladdr {:link-addr/%s}\n", link_ntoa(sdl) + n);
+ xo_close_container("link-address");
+#else
+ printf("\tlladdr %s\n", link_ntoa(sdl) + n);
+#endif
+ }
+}
+
+void
+af_link_print_pcp(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+
+ if (ioctl_ctx_ifr(ctx, SIOCGLANPCP, &ifr) == 0 &&
+ ifr.ifr_lan_pcp != IFNET_PCP_NONE)
+#ifdef WITH_LIBXO
+ xo_emit("\tpcp {:pcp/%d}\n", ifr.ifr_lan_pcp);
+#else
+ printf("\tpcp %d\n", ifr.ifr_lan_pcp);
+#endif
+}
+
+void
+ifbridge_print_vlans(ifbvlan_set_t *vlans)
+{
+ unsigned printed = 0;
+
+ for (unsigned vlan = DOT1Q_VID_MIN; vlan <= DOT1Q_VID_MAX;) {
+ unsigned last;
+
+ if (!BRVLAN_TEST(vlans, vlan)) {
+ ++vlan;
+ continue;
+ }
+
+ last = vlan;
+ while (last < DOT1Q_VID_MAX && BRVLAN_TEST(vlans, last + 1))
+ ++last;
+
+#ifdef WITH_LIBXO
+ if (printed == 0)
+ xo_emit("{P: tagged }");
+ else
+ xo_emit("{P:,}");
+
+ xo_open_list("vlan");
+ xo_open_container("vlan");
+ xo_emit("{:vlan-id/%d}", vlan);
+ if (last != vlan)
+ xo_emit("{P:-}{:vlan-end/%d}", last);
+ xo_close_container("vlan");
+ xo_close_list("vlan");
+ ++printed;
+ vlan = last + 1;
+#else
+ if (printed == 0)
+ printf(" tagged ");
+ else
+ printf(",");
+
+ printf("%u", vlan);
+ if (last != vlan)
+ printf("-%u", last);
+ ++printed;
+ vlan = last + 1;
+#endif
+ }
+}
+
+void
+ifconfig_printifnamemaybe(void)
+{
+ if (ifconfig_ifname_to_print[0] != '\0')
+#ifdef WITH_LIBXO
+ xo_emit("{:ifname-print/%s}\n", ifconfig_ifname_to_print);
+#else
+ printf("%s\n", ifconfig_ifname_to_print);
+#endif
+}
+
+int
+ifconfig_parse_args(int ac, char *av[] __unused)
+{
+#ifdef WITH_LIBXO
+ ac = xo_parse_args(ac, av);
+ if (ac < 0)
+ exit(EXIT_FAILURE);
+ xo_set_flags(NULL, XOF_PRETTY);
+
+ xo_set_version(IFCONFIG_XO_VERSION);
+#endif
+ return (ac);
+}
+
+void
+ifconfig_finish(void)
+{
+#ifdef WITH_LIBXO
+ xo_finish();
+#endif
+}
+
+void
+ifconfig_open_container(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_open_container(name);
+#endif
+}
+
+void
+ifconfig_close_container(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_close_container(name);
+#endif
+}
+
+void
+ifconfig_open_list(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_open_list(name);
+#endif
+}
+
+void
+ifconfig_close_list(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_close_list(name);
+#endif
+}
+
+void
+ifconfig_open_instance(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_open_instance(name);
+#endif
+}
+
+void
+ifconfig_close_instance(const char *name __unused)
+{
+#ifdef WITH_LIBXO
+ xo_close_instance(name);
+#endif
+}
+
+#ifdef WITHOUT_NETLINK
+void
+ifconfig_print_ifcap_nv(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+ nvlist_t *nvcap;
+ const char *nvname;
+ void *buf, *cookie;
+ bool first, val;
+ int type;
+
+ buf = malloc(IFR_CAP_NV_MAXBUFSIZE);
+ if (buf == NULL)
+ Perror("malloc");
+ ifr.ifr_cap_nv.buffer = buf;
+ ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE;
+ if (ioctl_ctx_ifr(ctx, SIOCGIFCAPNV, &ifr) != 0)
+ Perror("ioctl (SIOCGIFCAPNV)");
+ nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer, ifr.ifr_cap_nv.length, 0);
+ if (nvcap == NULL)
+ Perror("nvlist_unpack");
+#ifdef WITH_LIBXO
+ xo_emit("\toptions");
+#else
+ printf("\toptions");
+#endif
+ cookie = NULL;
+#ifdef WITH_LIBXO
+ xo_open_list("options");
+#endif
+ for (first = true;; first = false) {
+ nvname = nvlist_next(nvcap, &type, &cookie);
+ if (nvname == NULL) {
+ ifconfig_print_newline();
+ break;
+ }
+ if (type == NV_TYPE_BOOL) {
+ val = nvlist_get_bool(nvcap, nvname);
+ if (val) {
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%c%s}", first ? ' ' : ',', nvname);
+ xo_emit("{le:options/%s}", nvname);
+#else
+ printf("%c%s", first ? ' ' : ',', nvname);
+#endif
+ }
+ }
+ }
+#ifdef WITH_LIBXO
+ xo_close_list("options");
+#endif
+ if (ctx->args->supmedia) {
+#ifdef WITH_LIBXO
+ xo_emit("\tcapabilities");
+#else
+ printf("\tcapabilities");
+#endif
+ cookie = NULL;
+#ifdef WITH_LIBXO
+ xo_open_list("capabilities");
+#endif
+ for (first = true;; first = false) {
+ nvname = nvlist_next(nvcap, &type, &cookie);
+ if (nvname == NULL) {
+ ifconfig_print_newline();
+ break;
+ }
+ if (type == NV_TYPE_BOOL)
+#ifdef WITH_LIBXO
+ {
+ xo_emit("{P:/%c%s}", first ? ' ' : ',', nvname);
+ xo_emit("{le:capabilities/%s}", nvname);
+ }
+#else
+ printf("%c%s", first ? ' ' : ',', nvname);
+#endif
+ }
+#ifdef WITH_LIBXO
+ xo_close_list("capabilities");
+#endif
+ }
+ nvlist_destroy(nvcap);
+ free(buf);
+
+ if (ioctl_ctx(ctx, SIOCGIFCAP, (caddr_t)&ifr) != 0)
+ Perror("ioctl (SIOCGIFCAP)");
+}
+
+void
+ifconfig_print_ifcap(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+
+ if (ioctl_ctx_ifr(ctx, SIOCGIFCAP, &ifr) != 0)
+ return;
+
+ if ((ifr.ifr_curcap & IFCAP_NV) != 0)
+ ifconfig_print_ifcap_nv(ctx);
+ else {
+#ifdef WITH_LIBXO
+ xo_emit("\toptions={:ifcap-options-hex/%x}", ifr.ifr_curcap);
+ ifconfig_print_bits("options", "option", &ifr.ifr_curcap, 1,
+ IFCAPBITS, nitems(IFCAPBITS));
+
+ ifconfig_print_newline();
+
+ if (ctx->args->supmedia && ifr.ifr_reqcap != 0) {
+ xo_emit("\tcapabilities={:capab-hex/%x}",
+ ifr.ifr_reqcap);
+ ifconfig_print_bits("capabilities", "capability",
+ &ifr.ifr_reqcap, 1, IFCAPBITS, nitems(IFCAPBITS));
+ ifconfig_print_newline();
+ }
+#else
+ printf("\toptions=%x", ifr.ifr_curcap);
+ ifconfig_print_bits("options", "option", &ifr.ifr_curcap, 1,
+ IFCAPBITS, nitems(IFCAPBITS));
+ ifconfig_print_newline();
+ if (ctx->args->supmedia && ifr.ifr_reqcap != 0) {
+ printf("\tcapabilities=%x", ifr.ifr_reqcap);
+ ifconfig_print_bits("capabilities", "capability",
+ &ifr.ifr_reqcap, 1, IFCAPBITS, nitems(IFCAPBITS));
+ ifconfig_print_newline();
+ }
+#endif
+ }
+}
+#endif
+
+void
+ifconfig_print_ifstatus(if_ctx *ctx)
+{
+ struct ifstat ifs;
+
+ strlcpy(ifs.ifs_name, ctx->ifname, sizeof ifs.ifs_name);
+ if (ioctl_ctx(ctx, SIOCGIFSTATUS, &ifs) == 0)
+#ifdef WITH_LIBXO
+ {
+ char *p = ifs.ascii;
+
+ while (*p == '\t' || *p == ' ' || *p == '\n')
+ p++;
+ size_t len = strlen(p);
+ while (len > 0 &&
+ (p[len - 1] == '\n' || p[len - 1] == '\t' ||
+ p[len - 1] == ' '))
+ p[--len] = '\0';
+ xo_emit("{P:\t}{:if-status/%s}\n", p);
+ }
+#else
+ printf("%s", ifs.ascii);
+#endif
+}
+
+void
+ifconfig_print_metric(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+
+ if (ioctl_ctx_ifr(ctx, SIOCGIFMETRIC, &ifr) != -1)
+#ifdef WITH_LIBXO
+ xo_emit(" metric {:metric/%d}", ifr.ifr_metric);
+#else
+ printf(" metric %d", ifr.ifr_metric);
+#endif
+}
+
+#ifdef WITHOUT_NETLINK
+void
+ifconfig_print_mtu(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+
+ if (ioctl_ctx_ifr(ctx, SIOCGIFMTU, &ifr) != -1)
+#ifdef WITH_LIBXO
+ xo_emit(" mtu {:mtu/%d}", ifr.ifr_mtu);
+#else
+ printf(" mtu %d", ifr.ifr_mtu);
+#endif
+}
+
+void
+ifconfig_print_description(if_ctx *ctx)
+{
+ struct ifreq ifr = {};
+
+ ifr_set_name(&ifr, ctx->ifname);
+ for (;;) {
+ if ((descr = reallocf(descr, descrlen)) != NULL) {
+ ifr.ifr_buffer.buffer = descr;
+ ifr.ifr_buffer.length = descrlen;
+ if (ioctl_ctx(ctx, SIOCGIFDESCR, &ifr) == 0) {
+ if (ifr.ifr_buffer.buffer == descr) {
+ if (strlen(descr) > 0)
+#ifdef WITH_LIBXO
+ xo_emit(
+ "\tdescription: {:descr/%s}\n",
+ descr);
+#else
+ printf("\tdescription: %s\n",
+ descr);
+#endif
+ } else if (ifr.ifr_buffer.length > descrlen) {
+ descrlen = ifr.ifr_buffer.length;
+ continue;
+ }
+ }
+ } else
+ if_warn("unable to allocate memory for interface"
+ "description");
+ break;
+ }
+}
+#endif
+
+void
+ifconfig_print_bits(const char *btype, const char *child __unused, uint32_t *v,
+ const int v_count, const char **names, const int n_count)
+{
+ int num = 0;
+#ifdef WITH_LIBXO
+ char tag_fmt[64];
+
+ snprintf(tag_fmt, sizeof(tag_fmt), "{le:%s/%%s}", btype);
+ /*
+ * A JSON list of scalars has no element names, so for XML we emit
+ * a container with named children instead of repeated leaf elements.
+ */
+ if (xo_get_style(NULL) == XO_STYLE_XML) {
+ char child_fmt[64];
+
+ snprintf(child_fmt, sizeof(child_fmt), "{:%s/%%s}", child);
+ ifconfig_open_container(btype);
+ for (int i = 0; i < v_count * 32; i++) {
+ bool is_set = v[i / 32] & (1U << (i % 32));
+ if (is_set) {
+ if (i < n_count)
+ xo_emit(child_fmt, names[i]);
+ else {
+ char buf[64];
+
+ snprintf(buf, sizeof(buf), "%s_%d",
+ btype, i);
+ xo_emit(child_fmt, buf);
+ }
+ }
+ }
+ ifconfig_close_container(btype);
+ return;
+ }
+ xo_open_list(btype);
+ for (int i = 0; i < v_count * 32; i++) {
+ bool is_set = v[i / 32] & (1U << (i % 32));
+ if (is_set) {
+ if (num++ == 0)
+ xo_emit("{P:<}");
+ if (num != 1)
+ xo_emit("{P:,}");
+ if (i < n_count) {
+ xo_emit("{P:/%s}", names[i]);
+ xo_emit(tag_fmt, names[i]);
+ } else {
+ char buf[64];
+
+ snprintf(buf, sizeof(buf), "%s_%d", btype, i);
+ xo_emit("{P:/%s}", buf);
+ xo_emit(tag_fmt, buf);
+ }
+ }
+ }
+ if (num > 0)
+ xo_emit("{P:>}");
+ xo_close_list(btype);
+#else
+ for (int i = 0; i < v_count * 32; i++) {
+ bool is_set = v[i / 32] & (1U << (i % 32));
+ if (is_set) {
+ if (num++ == 0)
+ printf("<");
+ if (num != 1)
+ printf(",");
+ if (i < n_count)
+ printf("%s", names[i]);
+ else
+ printf("%s_%d", btype, i);
+ }
+ }
+ if (num > 0)
+ printf(">");
+#endif
+}
+
+/*
+ * Print a value a la the %b format of the kernel's printf
+ */
+void
+ifconfig_printb(const char *s, unsigned v, const char *bits)
+{
+ int i, any = 0;
+ char c;
+#ifdef WITH_LIBXO
+ if (bits && *bits == 8)
+ xo_emit("{P:/%s=%o}", s, v);
+ else
+ xo_emit("{P:/%s=%x}", s, v);
+ if (bits) {
+ bits++;
+ xo_emit("{P:<}");
+ while ((i = *bits++) != '\0') {
+ if (v & (1u << (i - 1))) {
+ if (any)
+ xo_emit("{P:,}");
+ any = 1;
+ for (; (c = *bits) > 32; bits++)
+ xo_emit("{P:/%c}", c);
+ } else
+ for (; *bits > 32; bits++)
+ ;
+ }
+ xo_emit("{P:>}");
+ }
+#else
+ if (bits && *bits == 8)
+ printf("%s=%o", s, v);
+ else
+ printf("%s=%x", s, v);
+ if (bits) {
+ bits++;
+ putchar('<');
+ while ((i = *bits++) != '\0') {
+ if (v & (1u << (i - 1))) {
+ if (any)
+ putchar(',');
+ any = 1;
+ for (; (c = *bits) > 32; bits++)
+ putchar(c);
+ } else
+ for (; *bits > 32; bits++)
+ ;
+ }
+ putchar('>');
+ }
+#endif
+}
+
+void
+ifconfig_print_vhid(const struct ifaddrs *ifa)
+{
+ struct if_data *ifd;
+
+ if (ifa->ifa_data == NULL)
+ return;
+
+ ifd = ifa->ifa_data;
+ if (ifd->ifi_vhid == 0)
+ return;
+#ifdef WITH_LIBXO
+ xo_emit(" vhid {:vhid/%d}", ifd->ifi_vhid);
+#else
+ printf(" vhid %d", ifd->ifi_vhid);
+#endif
+}
+
+void
+ifconfig_netlink_print_ifcaps(if_ctx *ctx, if_link_t *link)
+{
+ uint32_t sz_u32 = roundup2(link->iflaf_caps.nla_bitset_size, 32) / 32;
+#ifdef WITH_LIBXO
+ if (sz_u32 > 0) {
+ uint32_t *caps = link->iflaf_caps.nla_bitset_value;
+
+ xo_emit("\toptions={:options/%x}", caps[0]);
+ ifconfig_print_bits("interface-capabilities", "capability",
+ caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
+ ifconfig_print_newline();
+ }
+
+ if (ctx->args->supmedia && sz_u32 > 0) {
+ uint32_t *caps = link->iflaf_caps.nla_bitset_mask;
+
+ xo_emit("\tcapabilities={:capabilities/%x}", caps[0]);
+ ifconfig_print_bits("interface-capabilities", "capability",
+ caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
+ ifconfig_print_newline();
+ }
+#else
+ if (sz_u32 > 0) {
+ uint32_t *caps = link->iflaf_caps.nla_bitset_value;
+
+ printf("\toptions=%x", caps[0]);
+ ifconfig_print_bits("IFCAPS", "ifcap", caps, sz_u32,
+ ifcap_bit_names, nitems(ifcap_bit_names));
+ ifconfig_print_newline();
+ }
+
+ if (ctx->args->supmedia && sz_u32 > 0) {
+ uint32_t *caps = link->iflaf_caps.nla_bitset_mask;
+
+ printf("\tcapabilities=%x", caps[0]);
+ ifconfig_print_bits("IFCAPS", "ifcap", caps, sz_u32,
+ ifcap_bit_names, nitems(ifcap_bit_names));
+ ifconfig_print_newline();
+ }
+#endif
+}
+
+void
+ifgroup_printgroup(const char *groupname)
+{
+ struct ifgroupreq ifgr;
+ struct ifg_req *ifg;
+ unsigned int len;
+ int s;
+
+ s = socket(AF_LOCAL, SOCK_DGRAM, 0);
+ if (s == -1)
+ if_err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
+ bzero(&ifgr, sizeof(ifgr));
+ strlcpy(ifgr.ifgr_name, groupname, sizeof(ifgr.ifgr_name));
+ if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
+ if (errno == EINVAL || errno == ENOTTY || errno == ENOENT)
+ exit(exit_code);
+ else
+ if_err(1, "SIOCGIFGMEMB");
+ }
+
+ len = ifgr.ifgr_len;
+ if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
+ if_err(1, "printgroup");
+ if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
+ if_err(1, "SIOCGIFGMEMB");
+
+ for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req);
+ ifg++) {
+ len -= sizeof(struct ifg_req);
+#ifdef WITH_LIBXO
+ xo_emit("{:member-name/%s}\n", ifg->ifgrq_member);
+#else
+ printf("%s\n", ifg->ifgrq_member);
+#endif
+ }
+ free(ifgr.ifgr_groups);
+
+ exit(exit_code);
+}
+
+void
+ifieee80211_line_init(char c)
+{
+#ifdef WITH_LIBXO
+ ifieee80211_spacer = c;
+ if (c == '\t')
+ ifieee80211_col = 8;
+ else
+ ifieee80211_col = 1;
+#else
+ ifieee80211_spacer = c;
+ if (c == '\t')
+ ifieee80211_col = 8;
+ else
+ ifieee80211_col = 1;
+#endif
+}
+
+void
+ifieee80211_line_break(void)
+{
+#ifdef WITH_LIBXO
+ if (ifieee80211_spacer != '\t') {
+ xo_emit("{P:\n}");
+ ifieee80211_spacer = '\t';
+ }
+ ifieee80211_col = 8; /* 8-ifieee80211_col tab */
+#else
+ if (ifieee80211_spacer != '\t') {
+ ifconfig_print_newline();
+ ifieee80211_spacer = '\t';
+ }
+ ifieee80211_col = 8; /* 8-ifieee80211_col tab */
+#endif
+}
+
+void
+ifieee80211_line_check(const char *fmt, ...)
+{
+ char buf[80];
+ va_list ap;
+ int n;
+#ifdef WITH_LIBXO
+ va_start(ap, fmt);
+ n = vsnprintf(buf + 1, sizeof(buf) - 1, fmt, ap);
+ va_end(ap);
+ ifieee80211_col += 1 + n;
+ if (ifieee80211_col > IFIEEE80211_MAXCOL) {
+ ifieee80211_line_break();
+ ifieee80211_col += n;
+ }
+ buf[0] = ifieee80211_spacer;
+ xo_emit("{P:/%s}", buf);
+ ifieee80211_spacer = ' ';
+#else
+ va_start(ap, fmt);
+ n = vsnprintf(buf + 1, sizeof(buf) - 1, fmt, ap);
+ va_end(ap);
+ ifieee80211_col += 1 + n;
+ if (ifieee80211_col > IFIEEE80211_MAXCOL) {
+ ifieee80211_line_break();
+ ifieee80211_col += n;
+ }
+ buf[0] = ifieee80211_spacer;
+ printf("%s", buf);
+ ifieee80211_spacer = ' ';
+#endif
+}
+
+void
+ifieee80211_print_chaninfo(const struct ieee80211_channel *c, int verb)
+{
+ char buf[14];
+
+#ifdef WITH_LIBXO
+ if (verb)
+ xo_emit("{P:/Channel %3u : %u%c%c%c%c%c MHz%-14.14s}",
+ ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
+ IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
+ IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
+ IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
+ IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
+ IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
+ get_chaninfo(c, verb, buf, sizeof(buf)));
+ else
+ xo_emit("{P:/Channel %3u : %u%c MHz%-14.14s}",
+ ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
+ IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
+ get_chaninfo(c, verb, buf, sizeof(buf)));
+#else
+ if (verb)
+ printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
+ ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
+ IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
+ IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
+ IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
+ IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
+ IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
+ get_chaninfo(c, verb, buf, sizeof(buf)));
+ else
+ printf("Channel %3u : %u%c MHz%-14.14s",
+ ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
+ IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
+ get_chaninfo(c, verb, buf, sizeof(buf)));
+#endif
+}
+
+void
+ifieee80211_print_channels(if_ctx *ctx,
+ const struct ieee80211req_chaninfo *chans, int allchans, int verb)
+{
+ struct ieee80211req_chaninfo *achans;
+ uint8_t reported[IEEE80211_CHAN_BYTES];
+ const struct ieee80211_channel *c;
+ unsigned int i, half;
+
+ achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
+ if (achans == NULL)
+ if_errx(1, "no space for active channel list");
+ achans->ic_nchans = 0;
+ memset(reported, 0, sizeof(reported));
+ if (!allchans) {
+ struct ieee80211req_chanlist active;
+
+ if (get80211(ctx, IEEE80211_IOC_CHANLIST, &active,
+ sizeof(active)) < 0)
+ if_errx(1, "unable to get active channel list");
+ for (i = 0; i < chans->ic_nchans; i++) {
+ c = &chans->ic_chans[i];
+ if (!isset(active.ic_channels, c->ic_ieee))
+ continue;
+ /*
+ * Suppress compatible duplicates unless
+ * verbose. The kernel gives us it's
+ * complete channel list which has separate
+ * entries for 11g/11b and 11a/turbo.
+ */
+ if (isset(reported, c->ic_ieee) && !verb) {
+ /* XXX we assume duplicates are adjacent */
+ achans->ic_chans[achans->ic_nchans - 1] = *c;
+ } else {
+ achans->ic_chans[achans->ic_nchans++] = *c;
+ setbit(reported, c->ic_ieee);
+ }
+ }
+ } else {
+ for (i = 0; i < chans->ic_nchans; i++) {
+ c = &chans->ic_chans[i];
+ /* suppress duplicates as above */
+ if (isset(reported, c->ic_ieee) && !verb) {
+ /* XXX we assume duplicates are adjacent */
+ struct ieee80211_channel *a =
+ &achans->ic_chans[achans->ic_nchans - 1];
+ if (chanpref(c) > chanpref(a))
+ *a = *c;
+ } else {
+ achans->ic_chans[achans->ic_nchans++] = *c;
+ setbit(reported, c->ic_ieee);
+ }
+ }
+ }
+ half = achans->ic_nchans / 2;
+ if (achans->ic_nchans % 2)
+ half++;
+
+#ifdef WITH_LIBXO
+ for (i = 0; i < achans->ic_nchans / 2; i++) {
+ ifieee80211_print_chaninfo(&achans->ic_chans[i], verb);
+ ifieee80211_print_chaninfo(&achans->ic_chans[half + i], verb);
+ xo_emit("{P:\n}");
+ }
+ if (achans->ic_nchans % 2) {
+ ifieee80211_print_chaninfo(&achans->ic_chans[i], verb);
+ xo_emit("{P:\n}");
+ }
+#else
+ for (i = 0; i < achans->ic_nchans / 2; i++) {
+ ifieee80211_print_chaninfo(&achans->ic_chans[i], verb);
+ ifieee80211_print_chaninfo(&achans->ic_chans[half + i], verb);
+ ifconfig_print_newline();
+ }
+ if (achans->ic_nchans % 2) {
+ ifieee80211_print_chaninfo(&achans->ic_chans[i], verb);
+ printf("\n");
+ }
+#endif
+ free(achans);
+}
+
+void
+ifieee80211_print_txpow(const struct ieee80211_channel *c)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/Channel %3u : %u MHz %3.1f reg %2d }", c->ic_ieee,
+ c->ic_freq, c->ic_maxpower / 2., c->ic_maxregpower);
+#else
+ printf("Channel %3u : %u MHz %3.1f reg %2d ", c->ic_ieee, c->ic_freq,
+ c->ic_maxpower / 2., c->ic_maxregpower);
+#endif
+}
+
+void
+ifieee80211_print_txpow_verbose(const struct ieee80211_channel *c)
+{
+#ifdef WITH_LIBXO
+ ifieee80211_print_chaninfo(c, 1);
+ xo_emit("{P:/min %4.1f dBm max %3.1f dBm reg %2d dBm}",
+ c->ic_minpower / 2., c->ic_maxpower / 2., c->ic_maxregpower);
+ /* indicate where regulatory cap limits power use */
+ if (c->ic_maxpower > 2 * c->ic_maxregpower)
+ xo_emit("{P: <}");
+#else
+ ifieee80211_print_chaninfo(c, 1);
+ printf("min %4.1f dBm max %3.1f dBm reg %2d dBm", c->ic_minpower / 2.,
+ c->ic_maxpower / 2., c->ic_maxregpower);
+ /* indicate where regulatory cap limits power use */
+ if (c->ic_maxpower > 2 * c->ic_maxregpower)
+ printf(" <");
+#endif
+}
+
+void
+ifieee80211_print_regdomain(const struct ieee80211_regdomain *reg, int verb)
+{
+ if ((reg->regdomain != 0 && reg->regdomain != reg->country) || verb) {
+ const struct regdomain *rd =
+ lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
+ if (rd == NULL)
+ ifieee80211_line_check("regdomain %d", reg->regdomain);
+ else
+ ifieee80211_line_check("regdomain %s", rd->name);
+ }
+ if (reg->country != 0 || verb) {
+ const struct country *cc =
+ lib80211_country_findbycc(getregdata(), reg->country);
+ if (cc == NULL)
+ ifieee80211_line_check("country %d", reg->country);
+ else
+ ifieee80211_line_check("country %s", cc->isoname);
+ }
+ if (reg->location == 'I')
+ ifieee80211_line_check("indoor");
+ else if (reg->location == 'O')
+ ifieee80211_line_check("outdoor");
+ else if (verb)
+ ifieee80211_line_check("anywhere");
+ if (reg->ecm)
+ ifieee80211_line_check("ecm");
+ else if (verb)
+ ifieee80211_line_check("-ecm");
+}
+
+#if 0 /* XXX not interesting with WPA done in user space */
+void
+ifieee80211_printcipher(int s, struct ieee80211req *ireq, int keylenop)
+{
+#ifdef WITH_LIBXO
+ switch (ireq->i_val) {
+ case IEEE80211_CIPHER_WEP:
+ ireq->i_type = keylenop;
+ if (ioctl(s, SIOCG80211, ireq) != -1)
+ xo_emit("{P:/WEP-%s}",
+ ireq->i_len <= 5 ? "40" :
+ ireq->i_len <= 13 ? "104" : "128");
+ else
+ xo_emit("{P:WEP}");
+ break;
+ case IEEE80211_CIPHER_TKIP:
+ xo_emit("{P:TKIP}");
+ break;
+ case IEEE80211_CIPHER_AES_OCB:
+ xo_emit("{P:AES-OCB}");
+ break;
+ case IEEE80211_CIPHER_AES_CCM:
+ xo_emit("{P:AES-CCM}");
+ break;
+ case IEEE80211_CIPHER_AES_GCM_128:
+ xo_emit("{P:AES-GCM}");
+ break;
+ case IEEE80211_CIPHER_CKIP:
+ xo_emit("{P:CKIP}");
+ break;
+ case IEEE80211_CIPHER_NONE:
+ xo_emit("{P:NONE}");
+ break;
+ default:
+ xo_emit("{P:/UNKNOWN (0x%x)}", ireq->i_val);
+ break;
+ }
+#endif
+}
+#endif
+
+void
+ifieee80211_printkey_index(uint16_t keyix, char *buf, size_t buflen)
+{
+ buf[0] = '\0';
+ if (keyix == IEEE80211_KEYIX_NONE) {
+ snprintf(buf, buflen, "ucast");
+ } else {
+ snprintf(buf, buflen, "%u", keyix + 1);
+ }
+}
+
+void
+ifieee80211_printkey(if_ctx *ctx, const struct ieee80211req_key *ik)
+{
+ static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
+ u_int keylen = ik->ik_keylen;
+ int printcontents;
+ const int verbose = ctx->args->verbose;
+ const bool printkeys = ctx->args->printkeys;
+ char keyix[16];
+
+ printcontents = printkeys &&
+ (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
+ if (printcontents)
+ ifieee80211_line_break();
+ ifieee80211_printkey_index(ik->ik_keyix, keyix, sizeof(keyix));
+ switch (ik->ik_type) {
+ case IEEE80211_CIPHER_WEP:
+ /* compatibility */
+ ifieee80211_line_check("wepkey %s:%s", keyix,
+ keylen <= 5 ? "40-bit" :
+ keylen <= 13 ? "104-bit" :
+ "128-bit");
+ break;
+ case IEEE80211_CIPHER_TKIP:
+ if (keylen > 128 / 8)
+ keylen -= 128 / 8; /* ignore MIC for now */
+ ifieee80211_line_check("TKIP %s:%u-bit", keyix, 8 * keylen);
+ break;
+ case IEEE80211_CIPHER_AES_OCB:
+ ifieee80211_line_check("AES-OCB %s:%u-bit", keyix, 8 * keylen);
+ break;
+ case IEEE80211_CIPHER_AES_CCM:
+ ifieee80211_line_check("AES-CCM %s:%u-bit", keyix, 8 * keylen);
+ break;
+ case IEEE80211_CIPHER_AES_GCM_128:
+ ifieee80211_line_check("AES-GCM %s:%u-bit", keyix, 8 * keylen);
+ break;
+ case IEEE80211_CIPHER_CKIP:
+ ifieee80211_line_check("CKIP %s:%u-bit", keyix, 8 * keylen);
+ break;
+ case IEEE80211_CIPHER_NONE:
+ ifieee80211_line_check("NULL %s:%u-bit", keyix, 8 * keylen);
+ break;
+ default:
+ ifieee80211_line_check("UNKNOWN (0x%x) %s:%u-bit", ik->ik_type,
+ keyix, 8 * keylen);
+ break;
+ }
+ if (printcontents) {
+ u_int i;
+#ifdef WITH_LIBXO
+ xo_emit("{P: <}");
+ for (i = 0; i < keylen; i++)
+ xo_emit("{P:/%02x}", ik->ik_keydata[i]);
+ xo_emit("{P:>}");
+ if (ik->ik_type != IEEE80211_CIPHER_WEP &&
+ (ik->ik_keyrsc != 0 || verbose))
+ xo_emit("{P:/ rsc %ju}", (uintmax_t)ik->ik_keyrsc);
+ if (ik->ik_type != IEEE80211_CIPHER_WEP &&
+ (ik->ik_keytsc != 0 || verbose))
+ xo_emit("{P:/ tsc %ju}", (uintmax_t)ik->ik_keytsc);
+ if (ik->ik_flags != 0 && verbose) {
+ const char *sep = " ";
+
+ if (ik->ik_flags & IEEE80211_KEY_XMIT)
+ xo_emit("{P:/%stx}", sep), sep = "+";
+ if (ik->ik_flags & IEEE80211_KEY_RECV)
+ xo_emit("{P:/%srx}", sep), sep = "+";
+ if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
+ xo_emit("{P:/%sdef}", sep), sep = "+";
+ }
+ ifieee80211_line_break();
+#else
+ printf(" <");
+ for (i = 0; i < keylen; i++)
+ printf("%02x", ik->ik_keydata[i]);
+ printf(">");
+ if (ik->ik_type != IEEE80211_CIPHER_WEP &&
+ (ik->ik_keyrsc != 0 || verbose))
+ printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
+ if (ik->ik_type != IEEE80211_CIPHER_WEP &&
+ (ik->ik_keytsc != 0 || verbose))
+ printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
+ if (ik->ik_flags != 0 && verbose) {
+ const char *sep = " ";
+
+ if (ik->ik_flags & IEEE80211_KEY_XMIT)
+ printf("%stx", sep), sep = "+";
+ if (ik->ik_flags & IEEE80211_KEY_RECV)
+ printf("%srx", sep), sep = "+";
+ if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
+ printf("%sdef", sep), sep = "+";
+ }
+ ifieee80211_line_break();
+#endif
+ }
+}
+
+void
+ifieee80211_printrate(const char *tag, int v, int defrate, int defmcs)
+{
+ if ((v & IEEE80211_RATE_MCS) == 0) {
+ if (v != defrate) {
+ if (v & 1)
+ ifieee80211_line_check("%s %d.5", tag, v / 2);
+ else
+ ifieee80211_line_check("%s %d", tag, v / 2);
+ }
+ } else {
+ if (v != defmcs)
+ ifieee80211_line_check("%s %d", tag, v & ~0x80);
+ }
+}
+
+void
+ifieee80211_print_string(const u_int8_t *buf, int len)
+{
+ int i;
+ int hasspc;
+ int utf8;
+
+ i = 0;
+ hasspc = 0;
+
+ setlocale(LC_CTYPE, "");
+ utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
+
+ for (; i < len; i++) {
+ if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
+ break;
+ if (isspace(buf[i]))
+ hasspc++;
+ }
+#ifdef WITH_LIBXO
+ if (i == len || utf8) {
+ if (hasspc || len == 0 || buf[0] == '\0')
+ xo_emit("{P:/\"%.*s\"}", len, buf);
+ else
+ xo_emit("{P:/%.*s}", len, buf);
+ } else {
+ xo_emit("{P:0x}");
+ for (i = 0; i < len; i++)
+ xo_emit("{P:/%02x}", buf[i]);
+ }
+#else
+ if (i == len || utf8) {
+ if (hasspc || len == 0 || buf[0] == '\0')
+ printf("\"%.*s\"", len, buf);
+ else
+ printf("%.*s", len, buf);
+ } else {
+ printf("0x");
+ for (i = 0; i < len; i++)
+ printf("%02x", buf[i]);
+ }
+#endif
+}
+
+void
+ifieee80211_printie(if_ctx *ctx, const char *tag, const uint8_t *ie,
+ size_t ielen, unsigned int maxlen)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ maxlen -= strlen(tag) + 2;
+ if (2 * ielen > maxlen)
+ maxlen--;
+ xo_emit("{P:<}");
+ for (; ielen > 0; ie++, ielen--) {
+ if (maxlen-- <= 0)
+ break;
+ xo_emit("{P:/%02x}", *ie);
+ }
+ if (ielen != 0)
+ xo_emit("{P:-}");
+ xo_emit("{P:>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ maxlen -= strlen(tag) + 2;
+ if (2 * ielen > maxlen)
+ maxlen--;
+ printf("<");
+ for (; ielen > 0; ie++, ielen--) {
+ if (maxlen-- <= 0)
+ break;
+ printf("%02x", *ie);
+ }
+ if (ielen != 0)
+ printf("-");
+ printf(">");
+ }
+#endif
+}
+
+/*
+ * NB: The decoding routines assume a properly formatted ie
+ * which should be safe as the kernel only retains them
+ * if they parse ok.
+ */
+
+void
+ifieee80211_printwmeparam(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+ static const char *acnames[] = { "BE", "BK", "VO", "VI" };
+ const struct ieee80211_wme_param *wme =
+ (const struct ieee80211_wme_param *)ie;
+ int i;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (!ctx->args->verbose)
+ return;
+ xo_emit("{P:/<qosinfo 0x%x}", wme->param_qosInfo);
+ ie += offsetof(struct ieee80211_wme_param, params_acParams);
+ for (i = 0; i < WME_NUM_AC; i++) {
+ const struct ieee80211_wme_acparams *ac =
+ &wme->params_acParams[i];
+
+ xo_emit("{P:/ %s[%saifsn %u cwmin %u cwmax %u txop %u]}",
+ acnames[i],
+ _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_ACM) ?
+ "acm " :
+ "",
+ _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_AIFSN),
+ _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
+ WME_PARAM_LOGCWMIN),
+ _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
+ WME_PARAM_LOGCWMAX),
+ LE_READ_2(&ac->acp_txop));
+ }
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ if (!ctx->args->verbose)
+ return;
+ printf("<qosinfo 0x%x", wme->param_qosInfo);
+ ie += offsetof(struct ieee80211_wme_param, params_acParams);
+ for (i = 0; i < WME_NUM_AC; i++) {
+ const struct ieee80211_wme_acparams *ac =
+ &wme->params_acParams[i];
+
+ printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]", acnames[i],
+ _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_ACM) ?
+ "acm " :
+ "",
+ _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_AIFSN),
+ _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
+ WME_PARAM_LOGCWMIN),
+ _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
+ WME_PARAM_LOGCWMAX),
+ LE_READ_2(&ac->acp_txop));
+ }
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printwmeinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_wme_info *wme =
+ (const struct ieee80211_wme_info *)ie;
+ xo_emit("{P:/<version 0x%x info 0x%x>}", wme->wme_version,
+ wme->wme_info);
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_wme_info *wme =
+ (const struct ieee80211_wme_info *)ie;
+ printf("<version 0x%x info 0x%x>", wme->wme_version,
+ wme->wme_info);
+ }
+#endif
+}
+
+void
+ifieee80211_printhecap(if_ctx *ctx, const char *tag, const uint8_t *ie)
+{
+ const struct ieee80211_he_cap_elem *hecap;
+ const struct ieee80211_he_mcs_nss_supp *mcsnss;
+ unsigned int i;
+ uint8_t chw;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ if (ie[1] < 1 + sizeof(*hecap) + 4) {
+ xo_emit("{P:/<err: he_cap inval. length %#0x>}", ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ hecap = (const struct ieee80211_he_cap_elem *)(ie + 3);
+
+ /* XXX-BZ we need to somehow decode each field? */
+ xo_emit("{P:<mac_cap}");
+ for (i = 0; i < nitems(hecap->mac_cap_info); i++)
+ xo_emit("{P:/ %#04x}", hecap->mac_cap_info[i]);
+ xo_emit("{P: phy_cap}");
+ for (i = 0; i < nitems(hecap->phy_cap_info); i++)
+ xo_emit("{P:/ %#04x}", hecap->phy_cap_info[i]);
+
+ chw = hecap->phy_cap_info[0];
+ ie = (const uint8_t *)(const void *)(hecap + 1);
+ mcsnss = (const struct ieee80211_he_mcs_nss_supp *)ie;
+ /* Cannot use <= as < is a delimiter. */
+ xo_emit("{P:/ rx/tx_he_mcs map: loweq80 %#06x/%#06x}",
+ mcsnss->rx_mcs_80, mcsnss->tx_mcs_80);
+ ie += 2;
+ if ((chw & (1 << 2)) != 0) {
+ xo_emit("{P:/ 160 %#06x/%#06x}", mcsnss->rx_mcs_160,
+ mcsnss->tx_mcs_160);
+ ie += 2;
+ }
+ if ((chw & (1 << 3)) != 0) {
+ xo_emit("{P:/ 80+80 %#06x/%#06x}", mcsnss->rx_mcs_80p80,
+ mcsnss->tx_mcs_80p80);
+ ie += 2;
+ }
+ /* TODO: ppet = (struct ... *)ie; */
+
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ if (ie[1] < 1 + sizeof(*hecap) + 4) {
+ printf("<err: he_cap inval. length %#0x>", ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ hecap = (const struct ieee80211_he_cap_elem *)(ie + 3);
+
+ /* XXX-BZ we need to somehow decode each field? */
+ printf("<mac_cap");
+ for (i = 0; i < nitems(hecap->mac_cap_info); i++)
+ printf(" %#04x", hecap->mac_cap_info[i]);
+ printf(" phy_cap");
+ for (i = 0; i < nitems(hecap->phy_cap_info); i++)
+ printf(" %#04x", hecap->phy_cap_info[i]);
+
+ chw = hecap->phy_cap_info[0];
+ ie = (const uint8_t *)(const void *)(hecap + 1);
+ mcsnss = (const struct ieee80211_he_mcs_nss_supp *)ie;
+ /* Cannot use <= as < is a delimiter. */
+ printf(" rx/tx_he_mcs map: loweq80 %#06x/%#06x", mcsnss->rx_mcs_80,
+ mcsnss->tx_mcs_80);
+ ie += 2;
+ if ((chw & (1 << 2)) != 0) {
+ printf(" 160 %#06x/%#06x", mcsnss->rx_mcs_160,
+ mcsnss->tx_mcs_160);
+ ie += 2;
+ }
+ if ((chw & (1 << 3)) != 0) {
+ printf(" 80+80 %#06x/%#06x", mcsnss->rx_mcs_80p80,
+ mcsnss->tx_mcs_80p80);
+ ie += 2;
+ }
+ /* TODO: ppet = (struct ... *)ie; */
+
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printheoper(if_ctx *ctx, const char *tag, const uint8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_he_operation *heoper;
+ uint32_t params;
+
+ /* Check that the right size. */
+ if (ie[1] < 1 + sizeof(*heoper)) {
+ xo_emit("{P:/<err: he_oper inval. length %#0x>}",
+ ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ heoper = (const struct ieee80211_he_operation *)(ie + 3);
+
+ /* XXX-BZ we need to somehow decode each field? */
+ params = heoper->he_oper_params & 0x00ffffff;
+ xo_emit("{P:/<params %#08x}", params);
+ xo_emit("{P:/ bss_ifieee80211_col %#04x}",
+ (heoper->he_oper_params & 0xff000000) >> 24);
+ xo_emit("{P:/ mcs_nss %#06x}", heoper->he_mcs_nss_set);
+ if ((params & (1 << 14)) != 0) {
+ xo_emit("{P: vht_op 0-3}");
+ }
+ if ((params & (1 << 15)) != 0) {
+ xo_emit("{P: max_coh_bssid 0-1}");
+ }
+ if ((params & (1 << 17)) != 0) {
+ xo_emit("{P: 6ghz_op 0-5}");
+ }
+ xo_emit("{P:>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_he_operation *heoper;
+ uint32_t params;
+
+ /* Check that the right size. */
+ if (ie[1] < 1 + sizeof(*heoper)) {
+ printf("<err: he_oper inval. length %#0x>", ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ heoper = (const struct ieee80211_he_operation *)(ie + 3);
+
+ /* XXX-BZ we need to somehow decode each field? */
+ params = heoper->he_oper_params & 0x00ffffff;
+ printf("<params %#08x", params);
+ printf(" bss_ifieee80211_col %#04x",
+ (heoper->he_oper_params & 0xff000000) >> 24);
+ printf(" mcs_nss %#06x", heoper->he_mcs_nss_set);
+ if ((params & (1 << 14)) != 0) {
+ printf(" vht_op 0-3");
+ }
+ if ((params & (1 << 15)) != 0) {
+ printf(" max_coh_bssid 0-1");
+ }
+ if ((params & (1 << 17)) != 0) {
+ printf(" 6ghz_op 0-5");
+ }
+ printf(">");
+ }
+#endif
+}
+
+void
+ifieee80211_printmuedcaparamset(if_ctx *ctx, const char *tag, const uint8_t *ie)
+{
+ static const char *acnames[] = { "BE", "BK", "VO", "VI" };
+ const struct ieee80211_mu_edca_param_set *mu_edca;
+ int i;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ if (ie[1] != 1 + sizeof(*mu_edca)) {
+ xo_emit("{P:/<err: mu_edca inval. length %#04x>}", ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ mu_edca = (const struct ieee80211_mu_edca_param_set *)(ie + 3);
+
+ xo_emit("{P:/<qosinfo 0x%x}", mu_edca->mu_qos_info);
+ ie++;
+ for (i = 0; i < WME_NUM_AC; i++) {
+ const struct ieee80211_he_mu_edca_param_ac_rec *ac =
+ &mu_edca->param_ac_recs[i];
+
+ xo_emit("{P:/ %s[aifsn %u ecwmin %u ecwmax %u timer %u]}",
+ acnames[i], ac->aifsn,
+ _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMIN),
+ _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMAX),
+ ac->mu_edca_timer);
+ }
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ if (ie[1] != 1 + sizeof(*mu_edca)) {
+ printf("<err: mu_edca inval. length %#04x>", ie[1]);
+ return;
+ }
+ /* Skip Element ID, Length, EID Extension. */
+ mu_edca = (const struct ieee80211_mu_edca_param_set *)(ie + 3);
+
+ printf("<qosinfo 0x%x", mu_edca->mu_qos_info);
+ ie++;
+ for (i = 0; i < WME_NUM_AC; i++) {
+ const struct ieee80211_he_mu_edca_param_ac_rec *ac =
+ &mu_edca->param_ac_recs[i];
+
+ printf(" %s[aifsn %u ecwmin %u ecwmax %u timer %u]", acnames[i],
+ ac->aifsn,
+ _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMIN),
+ _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMAX),
+ ac->mu_edca_timer);
+ }
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printsupopclass(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+ uint8_t len, i;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ len = ie[1];
+ if (len < 2) {
+ xo_emit("{P:/<err: sup_op_class inval. length %#04x>}", ie[1]);
+ return;
+ }
+
+ ie += 2;
+ i = 0;
+ xo_emit("{P:/<cur op class %u}", *ie);
+ i++;
+ if (i < len && *(ie + i) != 130)
+ xo_emit("{P: op classes}");
+ while (i < len && *(ie + i) != 130) {
+ xo_emit("{P:/ %u}", *(ie + i));
+ i++;
+ }
+ if (i > 1 && i < len && *(ie + i) != 130) {
+ xo_emit("{P:/ parsing error at %#0x>}", i);
+ return;
+ }
+ /* Skip OneHundredAndThirty Delimiter. */
+ i++;
+ if (i < len && *(ie + i) != 0)
+ xo_emit("{P: ext seq}");
+ while (i < len && *(ie + i) != 0) {
+ xo_emit("{P:/ %u}", *(ie + i));
+ i++;
+ }
+ if (i > 1 && i < len && *(ie + i) != 0) {
+ xo_emit("{P:/ parsing error at %#0x>}", i);
+ return;
+ }
+ /* Skip Zero Delimiter. */
+ i++;
+ if ((i + 1) < len)
+ xo_emit("{P: duple seq}");
+ while ((i + 1) < len) {
+ xo_emit("{P:/ %u/%u}", *(ie + i), *(ie + i + 1));
+ i += 2;
+ }
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ /* Check that the right size. */
+ len = ie[1];
+ if (len < 2) {
+ printf("<err: sup_op_class inval. length %#04x>", ie[1]);
+ return;
+ }
+
+ ie += 2;
+ i = 0;
+ printf("<cur op class %u", *ie);
+ i++;
+ if (i < len && *(ie + i) != 130)
+ printf(" op classes");
+ while (i < len && *(ie + i) != 130) {
+ printf(" %u", *(ie + i));
+ i++;
+ }
+ if (i > 1 && i < len && *(ie + i) != 130) {
+ printf(" parsing error at %#0x>", i);
+ return;
+ }
+ /* Skip OneHundredAndThirty Delimiter. */
+ i++;
+ if (i < len && *(ie + i) != 0)
+ printf(" ext seq");
+ while (i < len && *(ie + i) != 0) {
+ printf(" %u", *(ie + i));
+ i++;
+ }
+ if (i > 1 && i < len && *(ie + i) != 0) {
+ printf(" parsing error at %#0x>", i);
+ return;
+ }
+ /* Skip Zero Delimiter. */
+ i++;
+ if ((i + 1) < len)
+ printf(" duple seq");
+ while ((i + 1) < len) {
+ printf(" %u/%u", *(ie + i), *(ie + i + 1));
+ i += 2;
+ }
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printvhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_vht_cap *vhtcap;
+ uint32_t vhtcap_info;
+
+ /* Check that the right size. */
+ if (ie[1] != sizeof(*vhtcap)) {
+ xo_emit("{P:<err: vht_cap inval. length>}");
+ return;
+ }
+ /* Skip Element ID and Length. */
+ vhtcap = (const struct ieee80211_vht_cap *)(ie + 2);
+
+ vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
+ xo_emit("{P:/<cap 0x%08x}", vhtcap_info);
+ xo_emit("{P:/ rx_mcs_map 0x%x}",
+ LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
+ xo_emit("{P:/ rx_highest %d}",
+ LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
+ xo_emit("{P:/ tx_mcs_map 0x%x}",
+ LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
+ xo_emit("{P:/ tx_highest %d}",
+ LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
+
+ xo_emit("{P:>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_vht_cap *vhtcap;
+ uint32_t vhtcap_info;
+
+ /* Check that the right size. */
+ if (ie[1] != sizeof(*vhtcap)) {
+ printf("<err: vht_cap inval. length>");
+ return;
+ }
+ /* Skip Element ID and Length. */
+ vhtcap = (const struct ieee80211_vht_cap *)(ie + 2);
+
+ vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
+ printf("<cap 0x%08x", vhtcap_info);
+ printf(" rx_mcs_map 0x%x",
+ LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
+ printf(" rx_highest %d",
+ LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
+ printf(" tx_mcs_map 0x%x",
+ LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
+ printf(" tx_highest %d",
+ LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
+
+ printf(">");
+ }
+#endif
+}
+
+void
+ifieee80211_printvhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_vht_operation *vhtinfo;
+
+ /* Check that the right size. */
+ if (ie[1] != sizeof(*vhtinfo)) {
+ xo_emit("{P:<err: vht_operation inval. length>}");
+ return;
+ }
+ /* Skip Element ID and Length. */
+ vhtinfo = (const struct ieee80211_vht_operation *)(ie + 2);
+
+ xo_emit(
+ "{P:/<chw %d freq0_idx %d freq1_idx %d basic_mcs_set 0x%04x>}",
+ vhtinfo->chan_width, vhtinfo->center_freq_seq0_idx,
+ vhtinfo->center_freq_seq1_idx,
+ LE_READ_2(&vhtinfo->basic_mcs_set));
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_vht_operation *vhtinfo;
+
+ /* Check that the right size. */
+ if (ie[1] != sizeof(*vhtinfo)) {
+ printf("<err: vht_operation inval. length>");
+ return;
+ }
+ /* Skip Element ID and Length. */
+ vhtinfo = (const struct ieee80211_vht_operation *)(ie + 2);
+
+ printf(
+ "<chw %d freq0_idx %d freq1_idx %d basic_mcs_set 0x%04x>",
+ vhtinfo->chan_width, vhtinfo->center_freq_seq0_idx,
+ vhtinfo->center_freq_seq1_idx,
+ LE_READ_2(&vhtinfo->basic_mcs_set));
+ }
+#endif
+}
+
+void
+ifieee80211_printvhtpwrenv(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen)
+{
+ static const char *txpwrmap[] = {
+ "20",
+ "40",
+ "80",
+ "160",
+ };
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
+ (const struct ieee80211_ie_vht_txpwrenv *)ie;
+ size_t i, n;
+ const char *sep = "";
+
+ /* Get count; trim at ielen */
+ n = (vhtpwr->tx_info & IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) +
+ 1;
+ /* Trim at ielen */
+ if (n + 3 > ielen)
+ n = ielen - 3;
+ xo_emit("{P:/<tx_info 0x%02x pwr:[}", vhtpwr->tx_info);
+ for (i = 0; i < n; i++) {
+ xo_emit("{P:/%s%s:%.2f}", sep, txpwrmap[i],
+ ((float)((int8_t)ie[i + 3])) / 2.0);
+ sep = " ";
+ }
+
+ xo_emit("{P:]>}");
+ }
+#else
+ printf("%s", tag);
+
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
+ (const struct ieee80211_ie_vht_txpwrenv *)ie;
+ size_t i, n;
+ const char *sep = "";
+
+ /* Get count; trim at ielen */
+ n = (vhtpwr->tx_info & IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) +
+ 1;
+ /* Trim at ielen */
+ if (n + 3 > ielen)
+ n = ielen - 3;
+ printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
+ for (i = 0; i < n; i++) {
+ printf("%s%s:%.2f", sep, txpwrmap[i],
+ ((float)((int8_t)ie[i + 3])) / 2.0);
+ sep = " ";
+ }
+
+ printf("]>");
+ }
+#endif
+}
+
+void
+ifieee80211_printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_htcap *htcap =
+ (const struct ieee80211_ie_htcap *)ie;
+ const char *sep;
+ int i, j;
+
+ xo_emit("{P:/<cap 0x%x param 0x%x}", LE_READ_2(&htcap->hc_cap),
+ htcap->hc_param);
+ xo_emit("{P: mcsset[}");
+ sep = "";
+ for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
+ if (isset(htcap->hc_mcsset, i)) {
+ for (j = i + 1; j < IEEE80211_HTRATE_MAXSIZE;
+ j++)
+ if (isclr(htcap->hc_mcsset, j))
+ break;
+ j--;
+ if (i == j)
+ xo_emit("{P:/%s%u}", sep, i);
+ else
+ xo_emit("{P:/%s%u-%u}", sep, i, j);
+ i += j - i;
+ sep = ",";
+ }
+ xo_emit("{P:/] extcap 0x%x txbf 0x%x antenna 0x%x>}",
+ LE_READ_2(&htcap->hc_extcap), LE_READ_4(&htcap->hc_txbf),
+ htcap->hc_antenna);
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_htcap *htcap =
+ (const struct ieee80211_ie_htcap *)ie;
+ const char *sep;
+ int i, j;
+
+ printf("<cap 0x%x param 0x%x", LE_READ_2(&htcap->hc_cap),
+ htcap->hc_param);
+ printf(" mcsset[");
+ sep = "";
+ for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
+ if (isset(htcap->hc_mcsset, i)) {
+ for (j = i + 1; j < IEEE80211_HTRATE_MAXSIZE;
+ j++)
+ if (isclr(htcap->hc_mcsset, j))
+ break;
+ j--;
+ if (i == j)
+ printf("%s%u", sep, i);
+ else
+ printf("%s%u-%u", sep, i, j);
+ i += j - i;
+ sep = ",";
+ }
+ printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
+ LE_READ_2(&htcap->hc_extcap), LE_READ_4(&htcap->hc_txbf),
+ htcap->hc_antenna);
+ }
+#endif
+}
+
+void
+ifieee80211_printhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_htinfo *htinfo =
+ (const struct ieee80211_ie_htinfo *)ie;
+ const char *sep;
+ int i, j;
+
+ xo_emit("{P:/<ctl %u, %x,%x,%x,%x}", htinfo->hi_ctrlchannel,
+ htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
+ LE_READ_2(&htinfo->hi_byte45));
+ xo_emit("{P: basicmcs[}");
+ sep = "";
+ for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
+ if (isset(htinfo->hi_basicmcsset, i)) {
+ for (j = i + 1; j < IEEE80211_HTRATE_MAXSIZE;
+ j++)
+ if (isclr(htinfo->hi_basicmcsset, j))
+ break;
+ j--;
+ if (i == j)
+ xo_emit("{P:/%s%u}", sep, i);
+ else
+ xo_emit("{P:/%s%u-%u}", sep, i, j);
+ i += j - i;
+ sep = ",";
+ }
+ xo_emit("{P:]>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ie_htinfo *htinfo =
+ (const struct ieee80211_ie_htinfo *)ie;
+ const char *sep;
+ int i, j;
+
+ printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
+ htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
+ LE_READ_2(&htinfo->hi_byte45));
+ printf(" basicmcs[");
+ sep = "";
+ for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
+ if (isset(htinfo->hi_basicmcsset, i)) {
+ for (j = i + 1; j < IEEE80211_HTRATE_MAXSIZE;
+ j++)
+ if (isclr(htinfo->hi_basicmcsset, j))
+ break;
+ j--;
+ if (i == j)
+ printf("%s%u", sep, i);
+ else
+ printf("%s%u-%u", sep, i, j);
+ i += j - i;
+ sep = ",";
+ }
+ printf("]>");
+ }
+#endif
+}
+
+void
+ifieee80211_printathie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ath_ie *ath =
+ (const struct ieee80211_ath_ie *)ie;
+
+ xo_emit("{P:<}");
+ if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
+ xo_emit("{P:DTURBO,}");
+ if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
+ xo_emit("{P:COMP,}");
+ if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
+ xo_emit("{P:FF,}");
+ if (ath->ath_capability & ATHEROS_CAP_XR)
+ xo_emit("{P:XR,}");
+ if (ath->ath_capability & ATHEROS_CAP_AR)
+ xo_emit("{P:AR,}");
+ if (ath->ath_capability & ATHEROS_CAP_BURST)
+ xo_emit("{P:BURST,}");
+ if (ath->ath_capability & ATHEROS_CAP_WME)
+ xo_emit("{P:WME,}");
+ if (ath->ath_capability & ATHEROS_CAP_BOOST)
+ xo_emit("{P:BOOST,}");
+ xo_emit("{P:/0x%x>}", LE_READ_2(ath->ath_defkeyix));
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ath_ie *ath =
+ (const struct ieee80211_ath_ie *)ie;
+
+ printf("<");
+ if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
+ printf("DTURBO,");
+ if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
+ printf("COMP,");
+ if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
+ printf("FF,");
+ if (ath->ath_capability & ATHEROS_CAP_XR)
+ printf("XR,");
+ if (ath->ath_capability & ATHEROS_CAP_AR)
+ printf("AR,");
+ if (ath->ath_capability & ATHEROS_CAP_BURST)
+ printf("BURST,");
+ if (ath->ath_capability & ATHEROS_CAP_WME)
+ printf("WME,");
+ if (ath->ath_capability & ATHEROS_CAP_BOOST)
+ printf("BOOST,");
+ printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
+ }
+#endif
+}
+
+void
+ifieee80211_printmeshconf(if_ctx *ctx, const char *tag, const uint8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_meshconf_ie *mconf =
+ (const struct ieee80211_meshconf_ie *)ie;
+ xo_emit("{P:<PATH:}");
+ if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
+ xo_emit("{P:HWMP}");
+ else
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: LINK:}");
+ if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
+ xo_emit("{P:AIRTIME}");
+ else
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: CONGESTION:}");
+ if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
+ xo_emit("{P:DISABLED}");
+ else
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: SYNC:}");
+ if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
+ xo_emit("{P:NEIGHOFF}");
+ else
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: AUTH:}");
+ if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
+ xo_emit("{P:DISABLED}");
+ else
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P:/ FORM:0x%x CAPS:0x%x>}", mconf->conf_form,
+ mconf->conf_cap);
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_meshconf_ie *mconf =
+ (const struct ieee80211_meshconf_ie *)ie;
+ printf("<PATH:");
+ if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
+ printf("HWMP");
+ else
+ printf("UNKNOWN");
+ printf(" LINK:");
+ if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
+ printf("AIRTIME");
+ else
+ printf("UNKNOWN");
+ printf(" CONGESTION:");
+ if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
+ printf("DISABLED");
+ else
+ printf("UNKNOWN");
+ printf(" SYNC:");
+ if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
+ printf("NEIGHOFF");
+ else
+ printf("UNKNOWN");
+ printf(" AUTH:");
+ if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
+ printf("DISABLED");
+ else
+ printf("UNKNOWN");
+ printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
+ mconf->conf_cap);
+ }
+#endif
+}
+
+void
+ifieee80211_printbssload(if_ctx *ctx, const char *tag, const uint8_t *ie)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_bss_load_ie *bssload =
+ (const struct ieee80211_bss_load_ie *)ie;
+ xo_emit("{P:/<sta count %d, chan load %d, aac %d>}",
+ LE_READ_2(&bssload->sta_count), bssload->chan_load,
+ bssload->aac);
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_bss_load_ie *bssload =
+ (const struct ieee80211_bss_load_ie *)ie;
+ printf("<sta count %d, chan load %d, aac %d>",
+ LE_READ_2(&bssload->sta_count), bssload->chan_load,
+ bssload->aac);
+ }
+#endif
+}
+
+void
+ifieee80211_printapchanrep(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ap_chan_report_ie *ap =
+ (const struct ieee80211_ap_chan_report_ie *)ie;
+ const char *sep = "";
+
+ xo_emit("{P:/<class %u, chan:[}", ap->i_class);
+
+ for (size_t i = 3; i < ielen; i++) {
+ xo_emit("{P:/%s%u}", sep, ie[i]);
+ sep = ",";
+ }
+ xo_emit("{P:]>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const struct ieee80211_ap_chan_report_ie *ap =
+ (const struct ieee80211_ap_chan_report_ie *)ie;
+ const char *sep = "";
+
+ printf("<class %u, chan:[", ap->i_class);
+
+ for (size_t i = 3; i < ielen; i++) {
+ printf("%s%u", sep, ie[i]);
+ sep = ",";
+ }
+ printf("]>");
+ }
+#endif
+}
+
+void
+ifieee80211_printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
+{
+ u_int8_t len = ie[1];
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const char *sep;
+ int n;
+
+ ie += 6, len -= 4; /* NB: len is payload only */
+
+ xo_emit("{P:/<v%u}", LE_READ_2(ie));
+ ie += 2, len -= 2;
+
+ xo_emit("{P:/ mc:%s}", wpa_cipher(ie));
+ ie += 4, len -= 4;
+
+ /* unicast ciphers */
+ n = LE_READ_2(ie);
+ ie += 2, len -= 2;
+ sep = " uc:";
+ for (; n > 0; n--) {
+ xo_emit("{P:/%s%s}", sep, wpa_cipher(ie));
+ ie += 4, len -= 4;
+ sep = "+";
+ }
+
+ /* key management algorithms */
+ n = LE_READ_2(ie);
+ ie += 2, len -= 2;
+ sep = " km:";
+ for (; n > 0; n--) {
+ xo_emit("{P:/%s%s}", sep, wpa_keymgmt(ie));
+ ie += 4, len -= 4;
+ sep = "+";
+ }
+
+ if (len > 2) /* optional capabilities */
+ xo_emit("{P:/, caps 0x%x}", LE_READ_2(ie));
+ xo_emit("{P:>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const char *sep;
+ int n;
+
+ ie += 6, len -= 4; /* NB: len is payload only */
+
+ printf("<v%u", LE_READ_2(ie));
+ ie += 2, len -= 2;
+
+ printf(" mc:%s", wpa_cipher(ie));
+ ie += 4, len -= 4;
+
+ /* unicast ciphers */
+ n = LE_READ_2(ie);
+ ie += 2, len -= 2;
+ sep = " uc:";
+ for (; n > 0; n--) {
+ printf("%s%s", sep, wpa_cipher(ie));
+ ie += 4, len -= 4;
+ sep = "+";
+ }
+
+ /* key management algorithms */
+ n = LE_READ_2(ie);
+ ie += 2, len -= 2;
+ sep = " km:";
+ for (; n > 0; n--) {
+ printf("%s%s", sep, wpa_keymgmt(ie));
+ ie += 4, len -= 4;
+ sep = "+";
+ }
+
+ if (len > 2) /* optional capabilities */
+ printf(", caps 0x%x", LE_READ_2(ie));
+ printf(">");
+ }
+#endif
+}
+
+void
+ifieee80211_printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose) {
+ const char *sep;
+ int n;
+
+ ie += 2, ielen -= 2;
+
+ xo_emit("{P:/<v%u}", LE_READ_2(ie));
+ ie += 2, ielen -= 2;
+
+ xo_emit("{P:/ mc:%s}", rsn_cipher(ie));
+ ie += 4, ielen -= 4;
+
+ /* unicast ciphers */
+ n = LE_READ_2(ie);
+ ie += 2, ielen -= 2;
+ sep = " uc:";
+ for (; n > 0; n--) {
+ xo_emit("{P:/%s%s}", sep, rsn_cipher(ie));
+ ie += 4, ielen -= 4;
+ sep = "+";
+ }
+
+ /* key management algorithms */
+ n = LE_READ_2(ie);
+ ie += 2, ielen -= 2;
+ sep = " km:";
+ for (; n > 0; n--) {
+ xo_emit("{P:/%s%s}", sep, rsn_keymgmt(ie));
+ ie += 4, ielen -= 4;
+ sep = "+";
+ }
+
+ if (ielen > 2) /* optional capabilities */
+ xo_emit("{P:/, caps 0x%x}", LE_READ_2(ie));
+ /* XXXPMKID */
+ xo_emit("{P:>}");
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose) {
+ const char *sep;
+ int n;
+
+ ie += 2, ielen -= 2;
+
+ printf("<v%u", LE_READ_2(ie));
+ ie += 2, ielen -= 2;
+
+ printf(" mc:%s", rsn_cipher(ie));
+ ie += 4, ielen -= 4;
+
+ /* unicast ciphers */
+ n = LE_READ_2(ie);
+ ie += 2, ielen -= 2;
+ sep = " uc:";
+ for (; n > 0; n--) {
+ printf("%s%s", sep, rsn_cipher(ie));
+ ie += 4, ielen -= 4;
+ sep = "+";
+ }
+
+ /* key management algorithms */
+ n = LE_READ_2(ie);
+ ie += 2, ielen -= 2;
+ sep = " km:";
+ for (; n > 0; n--) {
+ printf("%s%s", sep, rsn_keymgmt(ie));
+ ie += 4, ielen -= 4;
+ sep = "+";
+ }
+
+ if (ielen > 2) /* optional capabilities */
+ printf(", caps 0x%x", LE_READ_2(ie));
+ /* XXXPMKID */
+ printf(">");
+ }
+#endif
+}
+
+void
+ifieee80211_printrsnxe(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen)
+{
+ size_t n;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ ie += 2, ielen -= 2;
+
+ n = (*ie & 0x0f);
+ xo_emit("{P:/<%zu}", n + 1);
+
+ /* We do not yet know about more than n=1 (0). */
+ if (n != 0)
+ goto end;
+
+ if (*ie & 0x10)
+ xo_emit("{P: PTWTOPS}");
+ if (*ie & 0x20)
+ xo_emit("{P: SAE h-t-e}");
+
+end:
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ if (!ctx->args->verbose)
+ return;
+
+ ie += 2, ielen -= 2;
+
+ n = (*ie & 0x0f);
+ printf("<%zu", n + 1);
+
+ /* We do not yet know about more than n=1 (0). */
+ if (n != 0)
+ goto end;
+
+ if (*ie & 0x10)
+ printf(" PTWTOPS");
+ if (*ie & 0x20)
+ printf(" SAE h-t-e");
+
+end:
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printwpsie(if_ctx *ctx, const char *tag __unused,
+ const u_int8_t *ie)
+{
+ u_int8_t len = ie[1];
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+#endif
+ if (ctx->args->verbose) {
+ static const char *dev_pass_id[] = {
+ "D", /* Default (PIN) */
+ "U", /* User-specified */
+ "M", /* Machine-specified */
+ "K", /* Rekey */
+ "P", /* PushButton */
+ "R" /* Registrar-specified */
+ };
+ int n;
+ int f;
+
+ ie += 6, len -= 4; /* NB: len is payload only */
+
+ /* WPS IE in Beacon and Probe Resp frames have different fields
+ */
+#ifdef WITH_LIBXO
+ xo_emit("{P:<}");
+#else
+ printf("<");
+#endif
+ while (len) {
+ uint16_t tlv_type = BE_READ_2(ie);
+ uint16_t tlv_len = BE_READ_2(ie + 2);
+ uint16_t cfg_mthd;
+
+ /* some devices broadcast invalid WPS frames */
+ if (tlv_len > len) {
+#ifdef WITH_LIBXO
+ xo_emit("{P:/bad frame length tlv_type=0x%02x "
+ "tlv_len=%d len=%d}",
+ tlv_type, tlv_len, len);
+#else
+ printf("bad frame length tlv_type=0x%02x "
+ "tlv_len=%d len=%d",
+ tlv_type, tlv_len, len);
+#endif
+ break;
+ }
+
+ ie += 4, len -= 4;
+
+ switch (tlv_type) {
+ case IEEE80211_WPS_ATTR_VERSION:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/v:%d.%d}", *ie >> 4, *ie & 0xf);
+#else
+ printf("v:%d.%d", *ie >> 4, *ie & 0xf);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ ap_setup:%s}",
+ *ie ? "locked" : "unlocked");
+#else
+ printf(" ap_setup:%s",
+ *ie ? "locked" : "unlocked");
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_CONFIG_METHODS:
+ case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS:
+#ifdef WITH_LIBXO
+ if (tlv_type ==
+ IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
+ xo_emit("{P: sel_reg_cfg_mthd:}");
+ else
+ xo_emit("{P: cfg_mthd:}");
+#else
+ if (tlv_type ==
+ IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
+ printf(" sel_reg_cfg_mthd:");
+ else
+ printf(" cfg_mthd:");
+#endif
+ cfg_mthd = BE_READ_2(ie);
+ f = 0;
+ for (n = 15; n >= 0; n--) {
+ if (f) {
+#ifdef WITH_LIBXO
+ xo_emit("{P:,}");
+#else
+ printf(",");
+#endif
+ f = 0;
+ }
+ switch (cfg_mthd & (1 << n)) {
+ case 0:
+ break;
+ case IEEE80211_WPS_CONFIG_USBA:
+#ifdef WITH_LIBXO
+ xo_emit("{P:usba}");
+#else
+ printf("usba");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_ETHERNET:
+#ifdef WITH_LIBXO
+ xo_emit("{P:ethernet}");
+#else
+ printf("ethernet");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_LABEL:
+#ifdef WITH_LIBXO
+ xo_emit("{P:label}");
+#else
+ printf("label");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_DISPLAY:
+ if (!(cfg_mthd &
+ (IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
+ IEEE80211_WPS_CONFIG_PHY_DISPLAY))) {
+#ifdef WITH_LIBXO
+ xo_emit("{P:display}");
+#else
+ printf("display");
+#endif
+ f++;
+ }
+ break;
+ case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
+#ifdef WITH_LIBXO
+ xo_emit("{P:ext_nfc_tokenk}");
+#else
+ printf("ext_nfc_tokenk");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
+#ifdef WITH_LIBXO
+ xo_emit("{P:int_nfc_token}");
+#else
+ printf("int_nfc_token");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
+#ifdef WITH_LIBXO
+ xo_emit("{P:nfc_interface}");
+#else
+ printf("nfc_interface");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_PUSHBUTTON:
+ if (!(cfg_mthd &
+ (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON |
+ IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) {
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:push_button}");
+#else
+ printf("push_button");
+#endif
+ f++;
+ }
+ break;
+ case IEEE80211_WPS_CONFIG_KEYPAD:
+#ifdef WITH_LIBXO
+ xo_emit("{P:keypad}");
+#else
+ printf("keypad");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:virtual_push_button}");
+#else
+ printf("virtual_push_button");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:physical_push_button}");
+#else
+ printf("physical_push_button");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_P2PS:
+#ifdef WITH_LIBXO
+ xo_emit("{P:p2ps}");
+#else
+ printf("p2ps");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
+#ifdef WITH_LIBXO
+ xo_emit("{P:virtual_display}");
+#else
+ printf("virtual_display");
+#endif
+ f++;
+ break;
+ case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
+#ifdef WITH_LIBXO
+ xo_emit("{P:physical_display}");
+#else
+ printf("physical_display");
+#endif
+ f++;
+ break;
+ default:
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:/unknown_wps_config<%04x>}",
+ cfg_mthd & (1 << n));
+#else
+ printf(
+ "unknown_wps_config<%04x>",
+ cfg_mthd & (1 << n));
+#endif
+ f++;
+ break;
+ }
+ }
+ break;
+ case IEEE80211_WPS_ATTR_DEV_NAME:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ device_name:<%.*s>}", tlv_len,
+ ie);
+#else
+ printf(" device_name:<%.*s>", tlv_len, ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID:
+ n = LE_READ_2(ie);
+ if (n < (int)nitems(dev_pass_id))
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ dpi:%s}", dev_pass_id[n]);
+#else
+ printf(" dpi:%s", dev_pass_id[n]);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_MANUFACTURER:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ manufacturer:<%.*s>}", tlv_len,
+ ie);
+#else
+ printf(" manufacturer:<%.*s>", tlv_len, ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_MODEL_NAME:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ model_name:<%.*s>}", tlv_len, ie);
+#else
+ printf(" model_name:<%.*s>", tlv_len, ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_MODEL_NUMBER:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ model_number:<%.*s>}", tlv_len,
+ ie);
+#else
+ printf(" model_number:<%.*s>", tlv_len, ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
+#ifdef WITH_LIBXO
+ xo_emit("{P: prim_dev:}");
+ for (n = 0; n < tlv_len; n++)
+ xo_emit("{P:/%02x}", ie[n]);
+#else
+ printf(" prim_dev:");
+ for (n = 0; n < tlv_len; n++)
+ printf("%02x", ie[n]);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_RF_BANDS:
+#ifdef WITH_LIBXO
+ xo_emit("{P: rf:}");
+ f = 0;
+ for (n = 7; n >= 0; n--) {
+ if (f) {
+ xo_emit("{P:,}");
+ f = 0;
+ }
+ switch (*ie & (1 << n)) {
+ case 0:
+ break;
+ case IEEE80211_WPS_RF_BAND_24GHZ:
+ xo_emit("{P:2.4Ghz}");
+ f++;
+ break;
+ case IEEE80211_WPS_RF_BAND_50GHZ:
+ xo_emit("{P:5Ghz}");
+ f++;
+ break;
+ case IEEE80211_WPS_RF_BAND_600GHZ:
+ xo_emit("{P:60Ghz}");
+ f++;
+ break;
+ default:
+ xo_emit("{P:/unknown<%02x>}",
+ *ie & (1 << n));
+ f++;
+ break;
+ }
+ }
+#else
+ printf(" rf:");
+ f = 0;
+ for (n = 7; n >= 0; n--) {
+ if (f) {
+#ifdef WITH_LIBXO
+ xo_emit("{P:,}");
+#else
+ printf(",");
+#endif
+ f = 0;
+ }
+ switch (*ie & (1 << n)) {
+ case 0:
+ break;
+ case IEEE80211_WPS_RF_BAND_24GHZ:
+ printf("2.4Ghz");
+ f++;
+ break;
+ case IEEE80211_WPS_RF_BAND_50GHZ:
+ printf("5Ghz");
+ f++;
+ break;
+ case IEEE80211_WPS_RF_BAND_600GHZ:
+ printf("60Ghz");
+ f++;
+ break;
+ default:
+ printf("unknown<%02x>",
+ *ie & (1 << n));
+ f++;
+ break;
+ }
+ }
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ resp_type:0x%02x}", *ie);
+#else
+ printf(" resp_type:0x%02x", *ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ sel:%s}", *ie ? "T" : "F");
+#else
+ printf(" sel:%s", *ie ? "T" : "F");
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ serial_number:<%.*s>}", tlv_len,
+ ie);
+#else
+ printf(" serial_number:<%.*s>", tlv_len, ie);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_UUID_E:
+#ifdef WITH_LIBXO
+ xo_emit("{P: uuid-e:}");
+ for (n = 0; n < (tlv_len - 1); n++)
+ xo_emit("{P:/%02x-}", ie[n]);
+ xo_emit("{P:/%02x}", ie[n]);
+#else
+ printf(" uuid-e:");
+ for (n = 0; n < (tlv_len - 1); n++)
+ printf("%02x-", ie[n]);
+ printf("%02x", ie[n]);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_VENDOR_EXT:
+#ifdef WITH_LIBXO
+ xo_emit("{P: vendor:}");
+ for (n = 0; n < tlv_len; n++)
+ xo_emit("{P:/%02x}", ie[n]);
+#else
+ printf(" vendor:");
+ for (n = 0; n < tlv_len; n++)
+ printf("%02x", ie[n]);
+#endif
+ break;
+ case IEEE80211_WPS_ATTR_WPS_STATE:
+ switch (*ie) {
+ case IEEE80211_WPS_STATE_NOT_CONFIGURED:
+#ifdef WITH_LIBXO
+ xo_emit("{P: state:N}");
+#else
+ printf(" state:N");
+#endif
+ break;
+ case IEEE80211_WPS_STATE_CONFIGURED:
+#ifdef WITH_LIBXO
+ xo_emit("{P: state:C}");
+#else
+ printf(" state:C");
+#endif
+ break;
+ default:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ state:B<%02x>}", *ie);
+#else
+ printf(" state:B<%02x>", *ie);
+#endif
+ break;
+ }
+ break;
+ default:
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ unknown_wps_attr:0x%x}",
+ tlv_type);
+#else
+ printf(" unknown_wps_attr:0x%x", tlv_type);
+#endif
+ break;
+ }
+ ie += tlv_len, len -= tlv_len;
+ }
+#ifdef WITH_LIBXO
+ xo_emit("{P:>}");
+#else
+ printf(">");
+#endif
+ }
+}
+
+void
+ifieee80211_printtdmaie(if_ctx *ctx, const char *tag, const u_int8_t *ie,
+ size_t ielen)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ if (ctx->args->verbose &&
+ ielen >= sizeof(struct ieee80211_tdma_param)) {
+ const struct ieee80211_tdma_param *tdma =
+ (const struct ieee80211_tdma_param *)ie;
+
+ /* XXX tstamp */
+ xo_emit(
+ "{P:/<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>}",
+ tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
+ LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
+ tdma->tdma_inuse[0]);
+ }
+#else
+ printf("%s", tag);
+ if (ctx->args->verbose &&
+ ielen >= sizeof(struct ieee80211_tdma_param)) {
+ const struct ieee80211_tdma_param *tdma =
+ (const struct ieee80211_tdma_param *)ie;
+
+ /* XXX tstamp */
+ printf(
+ "<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
+ tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
+ LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
+ tdma->tdma_inuse[0]);
+ }
+#endif
+}
+
+void
+ifieee80211_printssid(const char *tag, const u_int8_t *ie, int maxlen)
+{
+ char ssid[2 * IEEE80211_NWID_LEN + 1];
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s<%.*s>}", tag, copy_essid(ssid, maxlen, ie + 2, ie[1]),
+ ssid);
+#else
+ printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie + 2, ie[1]), ssid);
+#endif
+}
+
+void
+ifieee80211_printrates(const char *tag, const u_int8_t *ie, size_t ielen)
+{
+ const char *sep;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+ sep = "<";
+ for (size_t i = 2; i < ielen; i++) {
+ xo_emit("{P:/%s%s%d}", sep,
+ ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
+ ie[i] & IEEE80211_RATE_VAL);
+ sep = ",";
+ }
+ xo_emit("{P:>}");
+#else
+ printf("%s", tag);
+ sep = "<";
+ for (size_t i = 2; i < ielen; i++) {
+ printf("%s%s%d", sep, ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
+ ie[i] & IEEE80211_RATE_VAL);
+ sep = ",";
+ }
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printcountry(const char *tag, const u_int8_t *ie)
+{
+ const struct ieee80211_country_ie *cie =
+ (const struct ieee80211_country_ie *)ie;
+ int i, nbands, schan, nchan;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s<%c%c%c}", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
+ nbands = (cie->len - 3) / sizeof(cie->band[0]);
+ for (i = 0; i < nbands; i++) {
+ schan = cie->band[i].schan;
+ nchan = cie->band[i].nchan;
+ if (nchan != 1)
+ xo_emit("{P:/ %u-%u,%u}", schan, schan + nchan - 1,
+ cie->band[i].maxtxpwr);
+ else
+ xo_emit("{P:/ %u,%u}", schan, cie->band[i].maxtxpwr);
+ }
+ xo_emit("{P:>}");
+#else
+ printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
+ nbands = (cie->len - 3) / sizeof(cie->band[0]);
+ for (i = 0; i < nbands; i++) {
+ schan = cie->band[i].schan;
+ nchan = cie->band[i].nchan;
+ if (nchan != 1)
+ printf(" %u-%u,%u", schan, schan + nchan - 1,
+ cie->band[i].maxtxpwr);
+ else
+ printf(" %u,%u", schan, cie->band[i].maxtxpwr);
+ }
+ printf(">");
+#endif
+}
+
+void
+ifieee80211_printexties(if_ctx *ctx, const u_int8_t *vp,
+ unsigned int maxifieee80211_cols)
+{
+ const int verbose = ctx->args->verbose;
+
+ if (vp[1] < 1)
+ return;
+
+ switch (vp[2]) {
+ case IEEE80211_ELEMID_EXT_HE_CAPA:
+ ifieee80211_printhecap(ctx, " HECAP", vp);
+ break;
+ case IEEE80211_ELEMID_EXT_HE_OPER:
+ ifieee80211_printheoper(ctx, " HEOPER", vp);
+ break;
+ case IEEE80211_ELEMID_EXT_MU_EDCA_PARAM_SET:
+ ifieee80211_printmuedcaparamset(ctx, " MU_EDCA_PARAM_SET", vp);
+ break;
+ default:
+ if (verbose)
+ ifieee80211_printie(ctx, iename(vp[0], vp), vp,
+ 2 + vp[1], maxifieee80211_cols);
+ break;
+ }
+}
+
+void
+ifieee80211_printies(if_ctx *ctx, const u_int8_t *vp, int ielen,
+ unsigned int maxifieee80211_cols)
+{
+ const int verbose = ctx->args->verbose;
+
+ while (ielen > 0) {
+ switch (vp[0]) {
+ case IEEE80211_ELEMID_SSID:
+ if (verbose)
+ ifieee80211_printssid(" SSID", vp,
+ maxifieee80211_cols);
+ break;
+ case IEEE80211_ELEMID_RATES:
+ case IEEE80211_ELEMID_XRATES:
+ if (verbose)
+ ifieee80211_printrates(vp[0] ==
+ IEEE80211_ELEMID_RATES ?
+ " RATES" :
+ " XRATES",
+ vp, 2 + vp[1]);
+ break;
+ case IEEE80211_ELEMID_DSPARMS:
+ if (verbose)
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ DSPARMS<%u>}", vp[2]);
+#else
+ printf(" DSPARMS<%u>", vp[2]);
+#endif
+ break;
+ case IEEE80211_ELEMID_COUNTRY:
+ if (verbose)
+ ifieee80211_printcountry(" COUNTRY", vp);
+ break;
+ case IEEE80211_ELEMID_ERP:
+ if (verbose)
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ ERP<0x%x>}", vp[2]);
+#else
+ printf(" ERP<0x%x>", vp[2]);
+#endif
+ break;
+ case IEEE80211_ELEMID_VENDOR:
+ if (iswpaoui(vp))
+ ifieee80211_printwpaie(ctx, " WPA", vp);
+ else if (iswmeinfo(vp))
+ ifieee80211_printwmeinfo(ctx, " WME", vp);
+ else if (iswmeparam(vp))
+ ifieee80211_printwmeparam(ctx, " WME", vp);
+ else if (isatherosoui(vp))
+ ifieee80211_printathie(ctx, " ATH", vp);
+ else if (iswpsoui(vp))
+ ifieee80211_printwpsie(ctx, " WPS", vp);
+ else if (istdmaoui(vp))
+ ifieee80211_printtdmaie(ctx, " TDMA", vp,
+ 2 + vp[1]);
+ else if (verbose)
+ ifieee80211_printie(ctx, " VEN", vp, 2 + vp[1],
+ maxifieee80211_cols);
+ break;
+ case IEEE80211_ELEMID_RSN:
+ ifieee80211_printrsnie(ctx, " RSN", vp, 2 + vp[1]);
+ break;
+ case IEEE80211_ELEMID_HTCAP:
+ ifieee80211_printhtcap(ctx, " HTCAP", vp);
+ break;
+ case IEEE80211_ELEMID_SUP_OP_CLASS:
+ ifieee80211_printsupopclass(ctx, " SUP_OP_CLASS", vp);
+ break;
+ case IEEE80211_ELEMID_HTINFO:
+ if (verbose)
+ ifieee80211_printhtinfo(ctx, " HTINFO", vp);
+ break;
+ case IEEE80211_ELEMID_MESHID:
+ if (verbose)
+ ifieee80211_printssid(" MESHID", vp,
+ maxifieee80211_cols);
+ break;
+ case IEEE80211_ELEMID_MESHCONF:
+ ifieee80211_printmeshconf(ctx, " MESHCONF", vp);
+ break;
+ case IEEE80211_ELEMID_VHT_CAP:
+ ifieee80211_printvhtcap(ctx, " VHTCAP", vp);
+ break;
+ case IEEE80211_ELEMID_VHT_OPMODE:
+ ifieee80211_printvhtinfo(ctx, " VHTOPMODE", vp);
+ break;
+ case IEEE80211_ELEMID_VHT_PWR_ENV:
+ ifieee80211_printvhtpwrenv(ctx, " VHTPWRENV", vp,
+ 2 + vp[1]);
+ break;
+ case IEEE80211_ELEMID_BSSLOAD:
+ ifieee80211_printbssload(ctx, " BSSLOAD", vp);
+ break;
+ case IEEE80211_ELEMID_APCHANREP:
+ ifieee80211_printapchanrep(ctx, " APCHANREP", vp,
+ 2 + vp[1]);
+ break;
+ case IEEE80211_ELEMID_RSN_EXT:
+ ifieee80211_printrsnxe(ctx, " RSNXE", vp, 2 + vp[1]);
+ break;
+ case IEEE80211_ELEMID_EXTFIELD:
+ ifieee80211_printexties(ctx, vp, maxifieee80211_cols);
+ break;
+ default:
+ if (verbose)
+ ifieee80211_printie(ctx, iename(vp[0], vp), vp,
+ 2 + vp[1], maxifieee80211_cols);
+ break;
+ }
+ ielen -= 2 + vp[1];
+ vp += 2 + vp[1];
+ }
+}
+
+void
+ifieee80211_printmimo(const struct ieee80211_mimo_info *mi)
+{
+ int i;
+ int r = 0;
+
+ for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
+ if (mi->ch[i].rssi[0] != 0) {
+ r = 1;
+ break;
+ }
+ }
+
+ /* NB: don't muddy display unless there's something to show */
+ if (r == 0)
+ return;
+#ifdef WITH_LIBXO
+ /* XXX TODO: ignore EVM; secondary channels for now */
+ xo_emit("{P:/ (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)}",
+ mi->ch[0].rssi[0] / 2.0, mi->ch[1].rssi[0] / 2.0,
+ mi->ch[2].rssi[0] / 2.0, mi->ch[3].rssi[0] / 2.0,
+ mi->ch[0].noise[0], mi->ch[1].noise[0], mi->ch[2].noise[0],
+ mi->ch[3].noise[0]);
+#else
+ /* XXX TODO: ignore EVM; secondary channels for now */
+ printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
+ mi->ch[0].rssi[0] / 2.0, mi->ch[1].rssi[0] / 2.0,
+ mi->ch[2].rssi[0] / 2.0, mi->ch[3].rssi[0] / 2.0,
+ mi->ch[0].noise[0], mi->ch[1].noise[0], mi->ch[2].noise[0],
+ mi->ch[3].noise[0]);
+#endif
+}
+
+void
+ifieee80211_printbssidname(const struct ether_addr *n)
+{
+ char name[MAXHOSTNAMELEN + 1];
+
+ if (ether_ntohost(name, n) != 0)
+ return;
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ (%s)}", name);
+#else
+ printf(" (%s)", name);
+#endif
+}
+
+void
+ifieee80211_printpolicy(int policy)
+{
+#ifdef WITH_LIBXO
+ switch (policy) {
+ case IEEE80211_MACCMD_POLICY_OPEN:
+ xo_emit("{P:policy: open\n}");
+ break;
+ case IEEE80211_MACCMD_POLICY_ALLOW:
+ xo_emit("{P:policy: allow\n}");
+ break;
+ case IEEE80211_MACCMD_POLICY_DENY:
+ xo_emit("{P:policy: deny\n}");
+ break;
+ case IEEE80211_MACCMD_POLICY_RADIUS:
+ xo_emit("{P:policy: radius\n}");
+ break;
+ default:
+ xo_emit("{P:/policy: unknown (%u)\n}", policy);
+ break;
+ }
+#else
+ switch (policy) {
+ case IEEE80211_MACCMD_POLICY_OPEN:
+ printf("policy: open\n");
+ break;
+ case IEEE80211_MACCMD_POLICY_ALLOW:
+ printf("policy: allow\n");
+ break;
+ case IEEE80211_MACCMD_POLICY_DENY:
+ printf("policy: deny\n");
+ break;
+ case IEEE80211_MACCMD_POLICY_RADIUS:
+ printf("policy: radius\n");
+ break;
+ default:
+ printf("policy: unknown (%u)\n", policy);
+ break;
+ }
+#endif
+}
+
+void
+ifmedia_print_media(ifmedia_t media, bool print_toptype)
+{
+ const char *val, **options;
+#ifdef WITH_LIBXO
+ xo_open_container("media");
+
+ val = ifconfig_media_get_type(media);
+ if (val == NULL) {
+ xo_emit("{P:<unknown type>}");
+ xo_close_container("media");
+ return;
+ } else if (print_toptype) {
+ xo_emit("{:type/%s}", val);
+ }
+
+ val = ifconfig_media_get_subtype(media);
+ if (val == NULL) {
+ xo_emit("{P:<unknown subtype>}");
+ xo_close_container("media");
+ return;
+ }
+
+ if (print_toptype)
+ xo_emit("{P: }");
+
+ xo_emit("{:subtype/%s}", val);
+
+ if (print_toptype) {
+ val = ifconfig_media_get_mode(media);
+ if (val != NULL && strcasecmp("autoselect", val) != 0)
+ xo_emit("{P: mode }{:mode/%s}", val);
+ }
+
+ options = ifconfig_media_get_options(media);
+ if (options != NULL && options[0] != NULL) {
+ xo_emit("{P: <}");
+ xo_open_list("option");
+ for (size_t i = 0; options[i] != NULL; ++i) {
+ if (i > 0)
+ xo_emit("{P:,}");
+ xo_emit("{P:/%s}", options[i]);
+ xo_emit("{le:option/%s}", options[i]);
+ }
+ xo_close_list("option");
+ xo_emit("{P:>}");
+ }
+ free(options);
+
+ if (print_toptype && IFM_INST(media) != 0)
+ xo_emit("{P: instance }{:instance/%d}", IFM_INST(media));
+
+ xo_close_container("media");
+#else
+ val = ifconfig_media_get_type(media);
+ if (val == NULL) {
+ printf("<unknown type>");
+ return;
+ } else if (print_toptype) {
+ printf("%s", val);
+ }
+
+ val = ifconfig_media_get_subtype(media);
+ if (val == NULL) {
+ printf("<unknown subtype>");
+ return;
+ }
+
+ if (print_toptype)
+ ifconfig_print_space();
+
+ printf("%s", val);
+
+ if (print_toptype) {
+ val = ifconfig_media_get_mode(media);
+ if (val != NULL && strcasecmp("autoselect", val) != 0)
+ printf(" mode %s", val);
+ }
+
+ options = ifconfig_media_get_options(media);
+ if (options != NULL && options[0] != NULL) {
+ printf(" <%s", options[0]);
+ for (size_t i = 1; options[i] != NULL; ++i)
+ printf(",%s", options[i]);
+ printf(">");
+ }
+ free(options);
+
+ if (print_toptype && IFM_INST(media) != 0)
+ printf(" instance %d", IFM_INST(media));
+#endif
+}
+
+void
+ifmedia_print_media_ifconfig(ifmedia_t media)
+{
+#ifdef WITH_LIBXO
+ const char *val, **options;
+
+ xo_open_container("media");
+
+ val = ifconfig_media_get_type(media);
+ if (val == NULL) {
+ xo_emit("{P:<unknown type>}");
+ xo_close_container("media");
+ return;
+ }
+
+ /*
+ * Don't print the top-level type; it's not like we can
+ * change it, or anything.
+ */
+
+ val = ifconfig_media_get_subtype(media);
+ if (val == NULL) {
+ xo_emit("{P:<unknown subtype>}");
+ xo_close_container("media");
+ return;
+ }
+
+ xo_emit("{P:media }{:subtype/%s}", val);
+
+ val = ifconfig_media_get_mode(media);
+ if (val != NULL)
+ xo_emit("{P: mode }{:mode/%s}", val);
+
+ options = ifconfig_media_get_options(media);
+ if (options != NULL && options[0] != NULL) {
+ xo_emit("{P: mediaopt }");
+ xo_open_list("option");
+ for (size_t i = 0; options[i] != NULL; ++i) {
+ if (i > 0)
+ xo_emit("{P:,}");
+ xo_emit("{P:/%s}", options[i]);
+ xo_emit("{le:option/%s}", options[i]);
+ }
+ xo_close_list("option");
+ }
+ free(options);
+
+ if (IFM_INST(media) != 0)
+ xo_emit("{P: instance }{:instance/%d}", IFM_INST(media));
+
+ xo_close_container("media");
+#else
+ const char *val, **options;
+
+ val = ifconfig_media_get_type(media);
+ if (val == NULL) {
+ printf("<unknown type>");
+ return;
+ }
+
+ /*
+ * Don't print the top-level type; it's not like we can
+ * change it, or anything.
+ */
+
+ val = ifconfig_media_get_subtype(media);
+ if (val == NULL) {
+ printf("<unknown subtype>");
+ return;
+ }
+
+ printf("media %s", val);
+
+ val = ifconfig_media_get_mode(media);
+ if (val != NULL)
+ printf(" mode %s", val);
+
+ options = ifconfig_media_get_options(media);
+ if (options != NULL && options[0] != NULL) {
+ printf(" mediaopt %s", options[0]);
+ for (size_t i = 1; options[i] != NULL; ++i)
+ printf(",%s", options[i]);
+ }
+ free(options);
+
+ if (IFM_INST(media) != 0)
+ printf(" instance %d", IFM_INST(media));
+#endif
+}
+
+void
+if_err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_err_v(eval, errno, fmt, ap);
+#else
+ verr(eval, fmt, ap);
+#endif
+ va_end(ap);
+}
+
+void
+if_errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_err_v(eval, code, fmt, ap);
+#else
+ verrc(eval, code, fmt, ap);
+#endif
+ va_end(ap);
+}
+
+void
+if_errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_err_v(eval, -1, fmt, ap);
+#else
+ verrx(eval, fmt, ap);
+#endif
+ va_end(ap);
+}
+
+void
+if_warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_warn_hcv(NULL, 1, errno, fmt, ap);
+#else
+ vwarn(fmt, ap);
+#endif
+ va_end(ap);
+}
+
+void
+if_warnc(int cond, int code, const char *fmt, ...)
+{
+ if (cond) {
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_warn_hcv(NULL, 1, code, fmt, ap);
+#else
+ vwarnc(code, fmt, ap);
+#endif
+ va_end(ap);
+ }
+}
+
+void
+if_warnx(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+#ifdef WITH_LIBXO
+ xo_emit_warn_hcv(NULL, 1, -1, fmt, ap);
+#else
+ vwarnx(fmt, ap);
+#endif
+ va_end(ap);
+}
+
+void
+ifconfig_print_space(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: }");
+#else
+ printf(" ");
+#endif
+}
+
+void
+ifconfig_print_char(char c)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%c}", c);
+#else
+ printf("%c", c);
+#endif
+}
+
+void
+ifconfig_print_tab(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\t");
+#else
+ printf("\t");
+#endif
+}
+
+void
+ifconfig_print_newline(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\n");
+#else
+ printf("\n");
+#endif
+}
+
+void
+ifconfig_print_flags(if_ctx *ctx, const struct ifaddrs *ifa)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{:ifname/%s}: flags={:flags-hex/%x}", ctx->ifname,
+ ifa->ifa_flags);
+#else
+ printf("%s: flags=%x", ctx->ifname, ifa->ifa_flags);
+#endif
+}
+
+void
+ifclone_print_cloners(const char *name)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{:cloner-name/%s}", name);
+#else
+ printf("%s", name);
+#endif
+}
+
+void
+af_inet_print_addr_pointtopoint(struct sockaddr_in *sin)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" --> {:dst-addr/%s}", inet_ntoa(sin->sin_addr));
+#else
+ printf(" --> %s", inet_ntoa(sin->sin_addr));
+#endif
+}
+
+void
+af_inet_print_cidr_mask(int cidr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("/{:prefixlen/%d}", cidr);
+#else
+ printf("/%d", cidr);
+#endif
+}
+
+void
+af_inet_print_netmask_str(struct in_addr addr)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" netmask {:netmask/%s}", inet_ntoa(addr));
+#else
+ printf(" netmask %s", inet_ntoa(addr));
+#endif
+}
+
+void
+af_inet_print_netmask(struct in_addr addr)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" netmask {:netmask/0x%lx}", (unsigned long)ntohl(addr.s_addr));
+#else
+ printf(" netmask 0x%lx", (unsigned long)ntohl(addr.s_addr));
+#endif
+}
+
+void
+af_inet_print_broadcast(struct sockaddr_in *sin)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" broadcast {:broadcast/%s}", inet_ntoa(sin->sin_addr));
+#else
+ printf(" broadcast %s", inet_ntoa(sin->sin_addr));
+#endif
+}
+
+void
+af_inet_print_vhid(if_addr_t *ifa)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" vhid {:vhid/%d}", ifa->ifaf_vhid);
+#else
+ printf(" vhid %d", ifa->ifaf_vhid);
+#endif
+}
+
+void
+af_inet_print_tunnel_inet(const char *src, const char *dst)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\ttunnel inet {:tunnel-src/%s} --> {:tunnel-dst/%s}\n", src,
+ dst);
+#else
+ printf("\ttunnel inet %s --> %s\n", src, dst);
+#endif
+}
+
+void
+af_inet6_print_scopeid(uint32_t scopeid)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" scopeid {:scopeid/0x%x}", scopeid);
+#else
+ printf(" scopeid 0x%x", scopeid);
+#endif
+}
+
+void
+af_inet6_print_vhid(if_addr_t *ifa)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" vhid {:vhid/%d}", ifa->ifaf_vhid);
+#else
+ printf(" vhid %d", ifa->ifaf_vhid);
+#endif
+}
+
+void
+af_inet6_print_tunnel(const char *src, const char *dst)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\ttunnel inet6 {:tunnel-src/%s} --> {:tunnel-dst/%s}\n", src,
+ dst);
+#else
+ printf("\ttunnel inet6 %s --> %s\n", src, dst);
+#endif
+}
+
+void
+af_nd6_print_options(uint32_t bits)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tnd6 options={:nd6-options-hex/%x}", bits);
+#else
+ printf("\tnd6 options=%x", bits);
+#endif
+}
+
+void
+carp_print_summary(const char *state, struct ifconfig_carp *carpr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tcarp: }{:carp-state/%s}{P: vhid }{:vhid/%d}"
+ "{P: advbase }{:advbase/%d}{P: advskew }{:advskew/%d}",
+ state, carpr->carpr_vhid, carpr->carpr_advbase,
+ carpr->carpr_advskew);
+#else
+ printf("\tcarp: %s vhid %d advbase %d advskew %d", state,
+ carpr->carpr_vhid, carpr->carpr_advbase, carpr->carpr_advskew);
+#endif
+}
+
+void
+carp_print_key(struct ifconfig_carp *carpr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: key \"}{:carp_key/%s}{P:\"}\n", carpr->carpr_key);
+#else
+ printf(" key \"%s\"\n", carpr->carpr_key);
+#endif
+}
+
+void
+carp_print_peer(struct ifconfig_carp *carpr, const char *peer_addr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t peer }{:carp_peer/%s}{P: peer6 }{:carp_peer6/%s}\n",
+ inet_ntoa(carpr->carpr_addr), peer_addr);
+#else
+ printf("\t peer %s peer6 %s\n", inet_ntoa(carpr->carpr_addr),
+ peer_addr);
+#endif
+}
+
+void
+carp_print_vrrp3(const char *state, struct ifconfig_carp *carpr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tvrrp: }{:vrrp_state/%s}{P: vrid }{:vrid/%d}"
+ "{P: prio }{:vrrp_prio/%d}{P: interval }{:vrrp_interval/%d}\n",
+ state, carpr->carpr_vhid, carpr->carpr_vrrp_prio,
+ carpr->carpr_vrrp_adv_inter);
+#else
+ printf("\tvrrp: %s vrid %d prio %d interval %d\n", state,
+ carpr->carpr_vhid, carpr->carpr_vrrp_prio,
+ carpr->carpr_vrrp_adv_inter);
+#endif
+}
+
+void
+iffib_print_fib(struct ifreq *ifr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tfib: {:fib-id/%u}\n", ifr->ifr_fib);
+#else
+ printf("\tfib: %u\n", ifr->ifr_fib);
+#endif
+}
+
+void
+iffib_print_tunnelfib(struct ifreq *ifr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\ttunnelfib: {:tunnelfib-id/%u}\n", ifr->ifr_fib);
+#else
+ printf("\ttunnelfib: %u\n", ifr->ifr_fib);
+#endif
+}
+
+void
+ifgif_print_options(int opts)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\toptions={:gif-options-hex/%x}", opts);
+#else
+ printf("\toptions=%x", opts);
+#endif
+}
+
+void
+ifgre_print_key(uint32_t opts)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tgrekey: 0x{:x} ({:u})\n", opts, opts);
+#else
+ printf("\tgrekey: 0x%x (%u)\n", opts, opts);
+#endif
+}
+
+void
+ifgre_print_udpport(uint32_t port)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tudpport: {:udpport/%u}\n", port);
+#else
+ printf("\tudpport: %u\n", port);
+#endif
+}
+
+void
+ifgre_print_options(uint32_t opts)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\toptions={:options/%x}", opts);
+#else
+ printf("\toptions=%x", opts);
+#endif
+}
+
+void
+ifgroup_print_groups(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tgroups:}");
+#else
+ printf("\tgroups:");
+#endif
+}
+
+void
+ifgroup_print_group(struct ifg_req *ifg)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" {:name/%s}", ifg->ifgrq_group);
+#else
+ printf(" %s", ifg->ifgrq_group);
+#endif
+}
+
+void
+ifipsec_print_reqid(uint32_t reqid)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\treqid: {:reqid/%u}\n", reqid);
+#else
+ printf("\treqid: %u\n", reqid);
+#endif
+}
+
+void
+iflagg_print_laggproto(const char *proto)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tlaggproto }{:lagg-proto/%s}", proto);
+#else
+ printf("\tlaggproto %s", proto);
+#endif
+}
+
+void
+iflagg_print_lagghash(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: lagghash }");
+#else
+ printf(" lagghash ");
+#endif
+}
+
+void
+iflagg_print_l2(const char *sep)
+{
+#ifdef WITH_LIBXO
+ if (sep[0] != '\0')
+ xo_emit("{P:,}");
+ xo_emit("{:lagg-hash-l2/%s}", "l2");
+#else
+ printf("%sl2", sep);
+#endif
+}
+
+void
+iflagg_print_l3(const char *sep)
+{
+#ifdef WITH_LIBXO
+ if (sep[0] != '\0')
+ xo_emit("{P:,}");
+ xo_emit("{:lagg-hash-l3/%s}", "l3");
+#else
+ printf("%sl3", sep);
+#endif
+}
+
+void
+iflagg_print_l4(const char *sep)
+{
+#ifdef WITH_LIBXO
+ if (sep[0] != '\0')
+ xo_emit("{P:,}");
+ xo_emit("{:lagg-hash-l4/%s}", "l4");
+#else
+ printf("%sl4", sep);
+#endif
+}
+
+void
+iflagg_print_options(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tlagg options:}\n");
+#else
+ printf("\tlagg options:\n");
+#endif
+}
+
+void
+iflagg_print_flowid_shift(struct lagg_reqopts *ro)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\tflowid_shift: }{:flowid-shift/%d}\n",
+ ro->ro_flowid_shift);
+#else
+ printf("\t\tflowid_shift: %d\n", ro->ro_flowid_shift);
+#endif
+}
+
+void
+iflagg_print_trr_limit(struct lagg_reqopts *ro)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\trr_limit: }{:rr-limit/%d}\n", ro->ro_bkt);
+#else
+ printf("\t\trr_limit: %d\n", ro->ro_bkt);
+#endif
+}
+
+void
+iflagg_print_statistics(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tlagg statistics:}\n");
+#else
+ printf("\tlagg statistics:\n");
+#endif
+}
+
+void
+iflagg_print_active_ports(struct lagg_reqopts *ro)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\tactive ports: }{:active-ports/%d}\n", ro->ro_active);
+#else
+ printf("\t\tactive ports: %d\n", ro->ro_active);
+#endif
+}
+
+void
+iflagg_print_flapping(struct lagg_reqopts *ro)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\tflapping: }{:flapping/%u}\n", ro->ro_flapping);
+#else
+ printf("\t\tflapping: %u\n", ro->ro_flapping);
+#endif
+}
+
+void
+iflagg_print_lagg_id(struct lacp_opreq *lp)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tlag id: }{:lag-id/%s}\n",
+ lacp_format_peer(lp, "\n\t\t "));
+#else
+ printf("\tlag id: %s\n", lacp_format_peer(lp, "\n\t\t "));
+#endif
+}
+
+void
+iflagg_print_laggport(struct lagg_reqport *port)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tlaggport: }{:name/%s} ", port->rp_portname);
+#else
+ printf("\tlaggport: %s ", port->rp_portname);
+#endif
+}
+
+void
+iflagg_print_peer(struct lacp_opreq *lp)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\t}{:lacp-peer/%s}\n", lacp_format_peer(lp, "\n\t\t "));
+#else
+ printf("\t\t%s\n", lacp_format_peer(lp, "\n\t\t "));
+#endif
+}
+
+void
+ifmac_print_maclabel(const char *label_text)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{T:}maclabel {:maclabel/%s}\n", label_text);
+#else
+ printf("\tmaclabel %s\n", label_text);
+#endif
+}
+
+void
+ifmedia_print_media_header(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tmedia: }");
+#else
+ printf("\tmedia: ");
+#endif
+}
+
+void
+ifmedia_print_status(const char *status)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tstatus: }{:status/%s}", status);
+#else
+ printf("\tstatus: %s", status);
+#endif
+}
+
+void
+ifmedia_print_reason(struct ifdownreason *ifdr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: (}{:reason-msg/%s}{P:)}", ifdr->ifdr_msg);
+#else
+ printf(" (%s)", ifdr->ifdr_msg);
+#endif
+}
+
+void
+ifmedia_print_reason_vendor(struct ifdownreason *ifdr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: (vendor code }{:vendor-code/%d}{P:)}", ifdr->ifdr_vendor);
+#else
+ printf(" (vendor code %d)", ifdr->ifdr_vendor);
+#endif
+}
+
+void
+ifmedia_print_supmedia(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tsupported media:}{P:\n}");
+#else
+ printf("\tsupported media:\n");
+#endif
+}
+
+void
+ifpfsync_print_syncdev(const char *syncdev)
+{
+#ifdef WITH_LIBXO
+ xo_emit("syncdev: {:syncdev/%s} ", syncdev);
+#else
+ printf("syncdev: %s ", syncdev);
+#endif
+}
+
+void
+ifpfsync_print_syncpeer(const char *syncpeer_str)
+{
+#ifdef WITH_LIBXO
+ xo_emit("syncpeer: {:syncpeer-str/%s} ", syncpeer_str);
+#else
+ printf("syncpeer: %s ", syncpeer_str);
+#endif
+}
+
+void
+ifpfsync_print_maxupd(int maxupdates)
+{
+#ifdef WITH_LIBXO
+ xo_emit("maxupd: {:maxupdates/%d} ", maxupdates);
+#else
+ printf("maxupd: %d ", maxupdates);
+#endif
+}
+
+void
+ifpfsync_print_defer(int flags)
+{
+#ifdef WITH_LIBXO
+ xo_emit("defer: {:defer-status/%s} ",
+ (flags & PFSYNCF_DEFER) ? "on" : "off");
+#else
+ printf("defer: %s ", (flags & PFSYNCF_DEFER) ? "on" : "off");
+#endif
+}
+
+void
+ifpfsync_print_version(int version)
+{
+#ifdef WITH_LIBXO
+ xo_emit("version: {:pfsync-version/%d}\n", version);
+#else
+ printf("version: %d\n", version);
+#endif
+}
+
+void
+ifpfsync_print_syncok(int flags)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tsyncok: {:syncok/%d}\n", (flags & PFSYNCF_OK) ? 1 : 0);
+#else
+ printf("\tsyncok: %d\n", (flags & PFSYNCF_OK) ? 1 : 0);
+#endif
+}
+
+void
+ifstf_print_v4net(struct stfv4args *param)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tv4net {:srcv4-addr/%s}/{:v4-prefixlen/%d} -> ",
+ inet_ntoa(param->srcv4_addr),
+ param->v4_prefixlen ? param->v4_prefixlen : 32);
+#else
+ printf("\tv4net %s/%d -> ", inet_ntoa(param->srcv4_addr),
+ param->v4_prefixlen ? param->v4_prefixlen : 32);
+#endif
+}
+
+void
+ifstf_print_tv4br(struct stfv4args *param)
+{
+#ifdef WITH_LIBXO
+ xo_emit("tv4br {:braddr/%s}\n", inet_ntoa(param->braddr));
+#else
+ printf("tv4br %s\n", inet_ntoa(param->braddr));
+#endif
+}
+
+void
+ifvlan_print_vlan(struct vlanreq *vreq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tvlan: }{:vlantag/%d}", vreq->vlr_tag);
+#else
+ printf("\tvlan: %d", vreq->vlr_tag);
+#endif
+}
+
+void
+ifvlan_print_vlanproto(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: vlanproto: }");
+#else
+ printf(" vlanproto: ");
+#endif
+}
+
+void
+ifvlan_print_8021q(const char *proto_8021Q)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{:vlan-protocol/%s}", proto_8021Q);
+#else
+ printf("%s", proto_8021Q);
+#endif
+}
+
+void
+ifvlan_print_8021d(const char *proto_8021ad)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{:vlan-protocol/%s}", proto_8021ad);
+#else
+ printf("%s", proto_8021ad);
+#endif
+}
+
+void
+ifvlan_print_otherproto(struct vlanreq *vreq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:0x}{:vlan-protocol/%04x}", vreq->vlr_proto);
+#else
+ printf("0x%04x", vreq->vlr_proto);
+#endif
+}
+
+void
+ifvlan_print_vlanpcp(struct ifreq *ifr)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: vlanpcp: }{:vlanpcp/%u}", ifr->ifr_vlan_pcp);
+#else
+ printf(" vlanpcp: %u", ifr->ifr_vlan_pcp);
+#endif
+}
+
+void
+ifvlan_print_parent(struct vlanreq *vreq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: parent interface: }{:parent-ifname/%s}",
+ vreq->vlr_parent[0] == '\0' ? "<none>" : vreq->vlr_parent);
+#else
+ printf(" parent interface: %s",
+ vreq->vlr_parent[0] == '\0' ? "<none>" : vreq->vlr_parent);
+#endif
+}
+
+void
+ifvxlan_print_vni(int vni)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tvxlan vni {:vni/%d}", vni);
+#else
+ printf("\tvxlan vni %d", vni);
+#endif
+}
+
+void
+ifvxlan_print_src(int ipv6, const char *src, const char *srcport)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" local {P:/%s}{:local-src/%s}{P:/%s}:{:local-src-port/%s}",
+ ipv6 ? "[" : "", src, ipv6 ? "]" : "", srcport);
+#else
+ printf(" local %s%s%s:%s", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
+ srcport);
+#endif
+}
+
+void
+ifvxlan_print_dst(int mc, int ipv6, const char *dst, const char *dstport)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ " {:peer-type/%s} {P:/%s}{:remote-dst/%s}{P:/%s}:{:remote-dst-port/%s}",
+ mc ? "group" : "remote", ipv6 ? "[" : "", dst, ipv6 ? "]" : "",
+ dstport);
+#else
+ printf(" %s %s%s%s:%s", mc ? "group" : "remote", ipv6 ? "[" : "", dst,
+ ipv6 ? "]" : "", dstport);
+#endif
+}
+
+void
+ifvxlan_print_config(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\t\tconfig: }");
+#else
+ printf("\n\t\tconfig: ");
+#endif
+}
+
+void
+ifvxlan_print_portrange(struct ifvxlancfg *cfg)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{:learning-status/%s}learning portrange {:port-min/%d}-{:port-max/%d} ttl {:ttl/%d}",
+ cfg->vxlc_learn ? "" : "no", cfg->vxlc_port_min, cfg->vxlc_port_max,
+ cfg->vxlc_ttl);
+#else
+ printf("%slearning portrange %d-%d ttl %d", cfg->vxlc_learn ? "" : "no",
+ cfg->vxlc_port_min, cfg->vxlc_port_max, cfg->vxlc_ttl);
+#endif
+}
+
+void
+ifvxlan_print_ftable(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\t\tftable: }");
+#else
+ printf("\n\t\tftable: ");
+#endif
+}
+
+void
+ifvxlan_print_threshold(struct ifvxlancfg *cfg)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "cnt {:ftable-cnt/%d} max {:ftable-max/%d} timeout {:ftable-timeout/%d}",
+ cfg->vxlc_ftable_cnt, cfg->vxlc_ftable_max,
+ cfg->vxlc_ftable_timeout);
+#else
+ printf("cnt %d max %d timeout %d", cfg->vxlc_ftable_cnt,
+ cfg->vxlc_ftable_max, cfg->vxlc_ftable_timeout);
+#endif
+}
+
+void
+ifconfig_netlink_print_ifname(if_link_t *link)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{:ifname/%s}: ", link->ifla_ifname);
+#else
+ printf("%s: ", link->ifla_ifname);
+#endif
+}
+
+void
+ifconfig_netlink_print_flags(if_link_t *link)
+{
+#ifdef WITH_LIBXO
+ xo_emit("flags={:flags-hex/%x}", link->ifi_flags);
+#else
+ printf("flags=%x", link->ifi_flags);
+#endif
+}
+
+void
+ifconfig_netlink_print_mtu(if_link_t *link)
+{
+#ifdef WITH_LIBXO
+ xo_emit(" mtu {:mtu/%d}\n", link->ifla_mtu);
+#else
+ printf(" mtu %d\n", link->ifla_mtu);
+#endif
+}
+
+void
+ifconfig_netlink_print_ifalias(if_link_t *link)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tdescription: {:descr/%s}\n", link->ifla_ifalias);
+#else
+ printf("\tdescription: %s\n", link->ifla_ifalias);
+#endif
+}
+
+void
+ifconfig_netlink_print_drivername(const char *drivername)
+{
+#ifdef WITH_LIBXO
+ xo_emit("\tdrivername: {:drivername/%s}\n", drivername);
+#else
+ printf("\tdrivername: %s\n", drivername);
+#endif
+}
+
+void
+ifgeneve_print_mode(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tgeneve mode: }");
+#else
+ printf("\tgeneve mode: ");
+#endif
+}
+
+void
+ifgeneve_print_proto_l3(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:l3}");
+#else
+ printf("l3");
+#endif
+}
+
+void
+ifgeneve_print_proto_l2(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:l2}");
+#else
+ printf("l2");
+#endif
+}
+
+void
+ifgeneve_print_config(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tgeneve config:\n}");
+#else
+ printf("\n\tgeneve config:\n");
+#endif
+}
+
+void
+ifgeneve_print_config_vni_notconfigured(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\t\tvirtual network identifier (vni): not configured\n}");
+#else
+ printf("\t\tvirtual network identifier (vni): not configured\n");
+#endif
+}
+
+void
+ifgeneve_print_vni(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/virtual network identifier (vni): %d}",
+ geneve_data->ifla_vni);
+#else
+ printf("\t\tvirtual network identifier (vni): %d",
+ geneve_data->ifla_vni);
+#endif
+}
+
+void
+ifgeneve_print_src(int ipv6, const char *src,
+ struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/local: %s%s%s:%u}", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
+ geneve_data->ifla_local_port);
+#else
+ printf("\n\t\tlocal: %s%s%s:%u", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
+ geneve_data->ifla_local_port);
+#endif
+}
+
+void
+ifgeneve_print_dst(int mc, int ipv6, const char *dst,
+ struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s: %s%s%s:%u}", mc ? "group" : "remote", ipv6 ? "[" : "",
+ dst, ipv6 ? "]" : "", geneve_data->ifla_local_port);
+#else
+ printf("\n\t\t%s: %s%s%s:%u", mc ? "group" : "remote", ipv6 ? "[" : "",
+ dst, ipv6 ? "]" : "", geneve_data->ifla_local_port);
+#endif
+}
+
+void
+ifgeneve_print_mcastdev(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ dev: %s}", geneve_data->ifla_mc_ifname);
+#else
+ printf(", dev: %s", geneve_data->ifla_mc_ifname);
+#endif
+}
+
+void
+ifgeneve_print_portrange(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/portrange: %u-%u}", geneve_data->ifla_port_range->low,
+ geneve_data->ifla_port_range->high);
+#else
+ printf("\n\t\tportrange: %u-%u", geneve_data->ifla_port_range->low,
+ geneve_data->ifla_port_range->high);
+#endif
+}
+
+void
+ifgeneve_print_ttl(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ ttl: %d}", geneve_data->ifla_ttl);
+#else
+ printf(", ttl: %d", geneve_data->ifla_ttl);
+#endif
+}
+
+void
+ifgeneve_print_ttl_inherit(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: ttl: inherit}");
+#else
+ printf(", ttl: inherit");
+#endif
+}
+
+void
+ifgeneve_print_dscp(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: dscp: inherit}");
+#else
+ printf(", dscp: inherit");
+#endif
+}
+
+void
+ifgeneve_print_df_inherit(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: df: inherit}");
+#else
+ printf(", df: inherit");
+#endif
+}
+
+void
+ifgeneve_print_df_set(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: df: set}");
+#else
+ printf(", df: set");
+#endif
+}
+
+void
+ifgeneve_print_df_unset(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: df: unset}");
+#else
+ printf(", df: unset");
+#endif
+}
+
+void
+ifgeneve_print_extctl(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: externally controlled}");
+#else
+ printf(", externally controlled");
+#endif
+}
+
+void
+ifgeneve_print_ftable_mode(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ftable mode: %slearning}",
+ geneve_data->ifla_ftable_learn ? "" : "no");
+#else
+ printf("\n\t\tftable mode: %slearning",
+ geneve_data->ifla_ftable_learn ? "" : "no");
+#endif
+}
+
+void
+ifgeneve_print_ftable(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ count: %d, max: %d, timeout: %d}",
+ geneve_data->ifla_ftable_count, geneve_data->ifla_ftable_max,
+ geneve_data->ifla_ftable_timeout);
+#else
+ printf(", count: %d, max: %d, timeout: %d",
+ geneve_data->ifla_ftable_count, geneve_data->ifla_ftable_max,
+ geneve_data->ifla_ftable_timeout);
+#endif
+}
+
+void
+ifgeneve_print_ftable_nospace(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ nospace: %u}", geneve_data->ifla_ftable_nospace);
+#else
+ printf(", nospace: %u", geneve_data->ifla_ftable_nospace);
+#endif
+}
+
+void
+ifgeneve_print_stats(struct nl_parsed_geneve *geneve_data)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/stats: tso %ju, txcsum %ju, rxcsum %ju}",
+ (uintmax_t)geneve_data->ifla_stats_tso,
+ (uintmax_t)geneve_data->ifla_stats_txcsum,
+ (uintmax_t)geneve_data->ifla_stats_rxcsum);
+#else
+ printf("\n\t\tstats: tso %ju, txcsum %ju, rxcsum %ju",
+ (uintmax_t)geneve_data->ifla_stats_tso,
+ (uintmax_t)geneve_data->ifla_stats_txcsum,
+ (uintmax_t)geneve_data->ifla_stats_rxcsum);
+#endif
+}
+
+void
+ifbridge_print_vlan(const char *prefix, struct ifbareq *ifba)
+{
+ struct ether_addr ea;
+
+#ifdef WITH_LIBXO
+ memcpy(ea.octet, ifba->ifba_dst, sizeof(ea.octet));
+ xo_emit(
+ "{:prefix/%s}{:mac-addr/%s}{P: Vlan}{:vlan/%d}{P: }{:port-name/%s}{P: }{:expire/%lu}{P: }",
+ prefix, ether_ntoa(&ea), ifba->ifba_vlan, ifba->ifba_ifsname,
+ ifba->ifba_expire);
+#else
+ memcpy(ea.octet, ifba->ifba_dst, sizeof(ea.octet));
+ printf("%s%s Vlan%d %s %lu ", prefix, ether_ntoa(&ea), ifba->ifba_vlan,
+ ifba->ifba_ifsname, ifba->ifba_expire);
+#endif
+}
+
+void
+ifbridge_print_summary(struct ifconfig_bridge_status *bridge)
+{
+ struct ifbropreq *params;
+ uint8_t lladdr[ETHER_ADDR_LEN];
+ uint16_t bprio;
+
+#ifdef WITH_LIBXO
+ params = bridge->params;
+
+ PV2ID(params->ifbop_bridgeid, bprio, lladdr);
+ xo_emit(
+ "{P:\tid }{:bridge-id/%s}{P: priority }{:bridge-priority/%u}{P: hellotime }{:hellotime/%u}{P: fwddelay }{:fwddelay/%u}\n",
+ ether_ntoa((struct ether_addr *)lladdr), params->ifbop_priority,
+ params->ifbop_hellotime, params->ifbop_fwddelay);
+ xo_emit(
+ "{P:\tmaxage }{:maxage/%u}{P: holdcnt }{:holdcnt/%u}{P: proto }{:stp-proto/%s}{P: maxaddr }{:maxaddr/%u}{P: timeout }{:timeout/%u}\n",
+ params->ifbop_maxage, params->ifbop_holdcount,
+ stpproto[params->ifbop_protocol], bridge->cache_size,
+ bridge->cache_lifetime);
+ PV2ID(params->ifbop_designated_root, bprio, lladdr);
+ xo_emit(
+ "{P:\troot id }{:root-id/%s}{P: priority }{:root-priority/%d}{P: ifcost }{:ifcost/%u}{P: port }{:root-port/%u}\n",
+ ether_ntoa((struct ether_addr *)lladdr), bprio,
+ params->ifbop_root_path_cost, params->ifbop_root_port & 0xfff);
+#else
+ params = bridge->params;
+
+ PV2ID(params->ifbop_bridgeid, bprio, lladdr);
+ printf("\tid %s priority %u hellotime %u fwddelay %u\n",
+ ether_ntoa((struct ether_addr *)lladdr), params->ifbop_priority,
+ params->ifbop_hellotime, params->ifbop_fwddelay);
+ printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n",
+ params->ifbop_maxage, params->ifbop_holdcount,
+ stpproto[params->ifbop_protocol], bridge->cache_size,
+ bridge->cache_lifetime);
+ PV2ID(params->ifbop_designated_root, bprio, lladdr);
+ printf("\troot id %s priority %d ifcost %u port %u\n",
+ ether_ntoa((struct ether_addr *)lladdr), bprio,
+ params->ifbop_root_path_cost, params->ifbop_root_port & 0xfff);
+#endif
+}
+
+void
+ifbridge_print_defuntagged(struct ifconfig_bridge_status *bridge)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: defuntagged=}{:defuntagged/%u}",
+ (unsigned)bridge->defpvid);
+#else
+ printf(" defuntagged=%u", (unsigned)bridge->defpvid);
+#endif
+}
+
+void
+ifbridge_print_bridge_member(const char *prefix, struct ifbreq *member)
+{
+#ifdef WITH_LIBXO
+ (void)prefix;
+ xo_emit("{P:\tmember: }{:member-name/%s}{P: }", member->ifbr_ifsname);
+#else
+ printf("%s%s ", prefix, member->ifbr_ifsname);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_pad(const char *pad)
+{
+#ifdef WITH_LIBXO
+ (void)pad;
+ xo_emit("\n{P:\t }");
+#else
+ printf("\n%s", pad);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_maxaddr(struct ifbreq *member)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:ifmaxaddr }{:ifmaxaddr/%u}{P: }", member->ifbr_addrmax);
+#else
+ printf("ifmaxaddr %u ", member->ifbr_addrmax);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_stp(struct ifbreq *member)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:port }{:port-number/%u}{P: priority }{:port-priority/%u}{P: path cost }{:path-cost/%u}",
+ member->ifbr_portno, member->ifbr_priority, member->ifbr_path_cost);
+#else
+ printf("port %u priority %u path cost %u", member->ifbr_portno,
+ member->ifbr_priority, member->ifbr_path_cost);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_proto(int proto)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: proto }{:stp-proto/%s}", stpproto[proto]);
+#else
+ printf(" proto %s", stpproto[proto]);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_proto_unknown(int proto)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: <unknown proto }{:unknown-proto/%d}{P:>}", proto);
+#else
+ printf(" <unknown proto %d>", proto);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_role(int role)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:role }{:stp-role/%s}", stproles[role]);
+#else
+ printf("role %s", stproles[role]);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_role_unknown(int role)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:<unknown role }{:unknown-role/%d}{P:>}", role);
+#else
+ printf("<unknown role %d>", role);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_state(int state)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: state }{:stp-state/%s}", stpstates[state]);
+#else
+ printf(" state %s", stpstates[state]);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_state_unknown(int state)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: <unknown state }{:unknown-state/%d}{P:>}", state);
+#else
+ printf(" <unknown state %d>", state);
+#endif
+}
+
+void
+ifbridge_print_bridge_member_vlan_proto(struct ifbreq *member)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: vlan protocol }{:vlan-proto/%s}",
+ vlan_proto_name(member->ifbr_vlanproto));
+#else
+ printf(" vlan protocol %s", vlan_proto_name(member->ifbr_vlanproto));
+#endif
+}
+
+void
+ifbridge_print_bridge_member_pvid(struct ifbreq *member)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: untagged }{:untagged/%u}", (unsigned)member->ifbr_pvid);
+#else
+ printf(" untagged %u", (unsigned)member->ifbr_pvid);
+#endif
+}
+
+void
+sfp_print_plugged(struct ifconfig_sfp_info *info,
+ struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:\tplugged: }{:sfp-id/%s}{P: }{:sfp-physical-spec/%s}{P: (}{:sfp-connector/%s}{P:)\n}",
+ ifconfig_sfp_id_display(info->sfp_id),
+ ifconfig_sfp_physical_spec(info, strings), strings->sfp_conn);
+#else
+ printf("\tplugged: %s %s (%s)\n", ifconfig_sfp_id_display(info->sfp_id),
+ ifconfig_sfp_physical_spec(info, strings), strings->sfp_conn);
+#endif
+}
+
+void
+sfp_print_vendor(struct ifconfig_sfp_vendor_info *vendor_info)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:\tvendor: }{:sfp-vendor/%s}{P: PN: }{:sfp-part-number/%s}{P: SN: }{:sfp-serial/%s}{P: DATE: }{:sfp-date/%s}{P:\n}",
+ vendor_info->name, vendor_info->pn, vendor_info->sn,
+ vendor_info->date);
+#else
+ printf("\tvendor: %s PN: %s SN: %s DATE: %s\n", vendor_info->name,
+ vendor_info->pn, vendor_info->sn, vendor_info->date);
+#endif
+}
+
+void
+sfp_print_verbose_compliance(struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tcompliance level: }{:sfp-revision/%s}{P:\n}",
+ strings->sfp_rev);
+#else
+ printf("\tcompliance level: %s\n", strings->sfp_rev);
+#endif
+}
+
+void
+sfp_print_verbose_class(struct ifconfig_sfp_info *info,
+ struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:Class: }{:sfp-class/%s}{P:\n}",
+ ifconfig_sfp_physical_spec(info, strings));
+#else
+ printf("Class: %s\n", ifconfig_sfp_physical_spec(info, strings));
+#endif
+}
+
+void
+sfp_print_verbose_length(struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:Length: }{:sfp-length/%s}{P:\n}", strings->sfp_fc_len);
+#else
+ printf("Length: %s\n", strings->sfp_fc_len);
+#endif
+}
+
+void
+sfp_print_verbose_tech(struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:Tech: }{:sfp-tech/%s}{P:\n}", strings->sfp_cab_tech);
+#else
+ printf("Tech: %s\n", strings->sfp_cab_tech);
+#endif
+}
+
+void
+sfp_print_verbose_media(struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:Media: }{:sfp-media/%s}{P:\n}", strings->sfp_fc_media);
+#else
+ printf("Media: %s\n", strings->sfp_fc_media);
+#endif
+}
+
+void
+sfp_print_verbose_speed(struct ifconfig_sfp_info_strings *strings)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:Speed: }{:sfp-speed/%s}{P:\n}", strings->sfp_fc_speed);
+#else
+ printf("Speed: %s\n", strings->sfp_fc_speed);
+#endif
+}
+
+void
+sfp_print_verbose_nombitrate(struct ifconfig_sfp_status *status)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\tnominal bitrate: }{:sfp-bitrate/%u}{P: Mbps\n}",
+ status->bitrate);
+#else
+ printf("\tnominal bitrate: %u Mbps\n", status->bitrate);
+#endif
+}
+
+void
+sfp_print_verbose_voltage(struct ifconfig_sfp_status *status)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:\tmodule temperature: }{:sfp-temperature/%.2f}{P: C voltage: }{:sfp-voltage/%.2f}{P: Volts\n}",
+ status->temp, status->voltage);
+#else
+ printf("\tmodule temperature: %.2f C voltage: %.2f Volts\n",
+ status->temp, status->voltage);
+#endif
+}
+
+void
+sfp_print_verbose_rxpower(size_t chan, uint16_t rx, uint16_t tx)
+{
+#ifdef WITH_LIBXO
+ xo_emit(
+ "{P:\tlane }{:sfp-lane/%zu}{P: RX power: }{:sfp-rx-power-mw/%.2f}{P: mW (}{:sfp-rx-power-dbm/%.2f}{P: dBm) TX bias: }{:sfp-tx-bias/%.2f}{P: mA\n}",
+ chan + 1, power_mW(rx), power_dBm(rx), bias_mA(tx));
+#else
+ printf("\tlane %zu: "
+ "RX power: %.2f mW (%.2f dBm) TX bias: %.2f mA\n",
+ chan + 1, power_mW(rx), power_dBm(rx), bias_mA(tx));
+#endif
+}
+
+static void
+sfp_print_hexdump(const uint8_t *bytes, int len, const char *tag __unused)
+{
+#ifdef WITH_LIBXO
+ int i;
+
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ for (i = 0; i < len; i++) {
+ if (i % 16 == 0)
+ xo_emit("{P:\t}");
+ else
+ xo_emit("{P: }");
+ xo_emit("{P:/%02x}", bytes[i]);
+ if (i % 16 == 15 || i == len - 1)
+ xo_emit("{P:\n}");
+ }
+ } else {
+ if (xo_get_style(NULL) == XO_STYLE_JSON) {
+ ifconfig_open_list(tag);
+ for (i = 0; i < len; i++)
+ xo_emit("{l:byte/%d}", bytes[i]);
+ ifconfig_close_list(tag);
+ } else {
+ ifconfig_open_container(tag);
+ for (i = 0; i < len; i++)
+ xo_emit("{:byte/%d}", bytes[i]);
+ ifconfig_close_container(tag);
+ }
+ }
+#else
+ hexdump(bytes, len, "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
+#endif
+}
+
+void
+sfp_print_verbose_cmis_dump1(const void *buf, int len)
+{
+ const uint8_t *bytes = buf;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tCMIS DUMP (Lower Memory 0..127):\n}");
+#else
+ printf("\n\tCMIS DUMP (Lower Memory 0..127):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-cmis-dump1");
+}
+
+void
+sfp_print_verbose_cmis_dump2(const void *buf, int len)
+{
+ const uint8_t *bytes = buf;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tCMIS DUMP (Page 00h 128..255):\n}");
+#else
+ printf("\n\tCMIS DUMP (Page 00h 128..255):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-cmis-dump2");
+}
+
+void
+sfp_print_verbose_cmis_dump3(const void *buf, int len)
+{
+ const uint8_t *bytes = buf;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tCMIS DUMP (Page 11h 128..255):\n}");
+#else
+ printf("\n\tCMIS DUMP (Page 11h 128..255):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-cmis-dump3");
+}
+
+void
+sfp_print_verbose_sff8436_dump1(const void *buf, int len)
+{
+ const uint8_t *bytes = buf;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tSFF8436 DUMP (0xA0 128..255 range):\n}");
+#else
+ printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-sff8436-dump1");
+}
+
+void
+sfp_print_verbose_sff8436_dump2(const void *buf, int len)
+{
+ const uint8_t *bytes = buf;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tSFF8436 DUMP (0xA0 0..81 range):\n}");
+#else
+ printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-sff8436-dump2");
+}
+
+void
+sfp_print_verbose_sff8472_dump1(const void *buf)
+{
+ const uint8_t *bytes = (const uint8_t *)buf + SFP_DUMP_START;
+ int len = SFP_DUMP_SIZE;
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tSFF8472 DUMP (0xA0 0..127 range):\n}");
+#else
+ printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
+#endif
+ sfp_print_hexdump(bytes, len, "sfp-sff8472-dump1");
+}
+
+void
+ifieee80211_print_drivercaps(struct ieee80211_devcaps_req *dc)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/drivercaps: 0x%x\n}", dc->dc_drivercaps);
+#else
+ printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
+#endif
+}
+
+void
+ifieee80211_print_cryptocaps(struct ieee80211_devcaps_req *dc)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/cryptocaps: 0x%x\n}", dc->dc_cryptocaps);
+#else
+ printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
+#endif
+}
+
+void
+ifieee80211_print_htcaps(struct ieee80211_devcaps_req *dc)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/htcaps : 0x%x\n}", dc->dc_htcaps);
+#else
+ printf("htcaps : 0x%x\n", dc->dc_htcaps);
+#endif
+}
+
+void
+ifieee80211_print_vhtcaps(struct ieee80211_devcaps_req *dc)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/vhtcaps : 0x%x\n}", dc->dc_vhtcaps);
+#else
+ printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
+#endif
+}
+
+void
+ifieee80211_print_regdomain_addchans(const char *func)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s:}", func);
+#else
+ printf("%s:", func);
+#endif
+}
+
+void
+ifieee80211_print_verbose_vht20_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not a VHT20 channel\n}", freq);
+#else
+ printf("%u: skip, not a VHT20 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_vht40_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not a VHT40 channel\n}", freq);
+#else
+ printf("%u: skip, not a VHT40 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_vht80_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not a VHT80 channel\n}", freq);
+#else
+ printf("%u: skip, not a VHT80 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_vht160_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not a VHT160 channel\n}", freq);
+#else
+ printf("%u: skip, not a VHT160 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_vht80p80_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not a VHT80+80 channel\n}", freq);
+#else
+ printf("%u: skip, not a VHT80+80 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_ht20_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not an HT20 channel\n}", freq);
+#else
+ printf("%u: skip, not an HT20 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_ht40_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, not an HT40 channel\n}", freq);
+#else
+ printf("%u: skip, not an HT40 channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_freq_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, }", freq);
+#else
+ printf("%u: skip, ", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_checkchan_notavail(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: not available\n}");
+#else
+ printf(" not available\n");
+#endif
+}
+
+void
+ifieee80211_print_verbose_ecm_chan(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, ECM channel\n}", freq);
+#else
+ printf("%u: skip, ECM channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_indoor_chan_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, indoor channel\n}", freq);
+#else
+ printf("%u: skip, indoor channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_outdoor_chan_skip(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, outdoor channel\n}", freq);
+#else
+ printf("%u: skip, outdoor channel\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_chansep_need(int freq, int separation, int need)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, only %u channel separation, need %d\n}", freq,
+ separation, need);
+#else
+ printf("%u: skip, only %u channel separation, need %d\n", freq,
+ separation, need);
+#endif
+}
+
+void
+ifieee80211_print_verbose_chan_table_full(uint32_t freq)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%u: skip, channel table full\n}", freq);
+#else
+ printf("%u: skip, channel table full\n", freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_add_freq(struct ieee80211req_chaninfo *ci,
+ const struct ieee80211_channel *c)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/[%3d] add freq %u }", ci->ic_nchans - 1, c->ic_freq);
+#else
+ printf("[%3d] add freq %u ", ci->ic_nchans - 1, c->ic_freq);
+#endif
+}
+
+void
+ifieee80211_print_verbose_maxregpower(const struct ieee80211_channel *c)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ power %u\n}", c->ic_maxregpower);
+#else
+ printf(" power %u\n", c->ic_maxregpower);
+#endif
+}
+
+void
+ifieee80211_print_country_codes(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\nCountry codes:\n}");
+#else
+ printf("\nCountry codes:\n");
+#endif
+}
+
+void
+ifieee80211_print_country_code(const struct country *cp, int i)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%2s %-15.15s%s}", cp->isoname, cp->name,
+ ((i + 1) % 4) == 0 ? "\n" : " ");
+#else
+ printf("%2s %-15.15s%s", cp->isoname, cp->name,
+ ((i + 1) % 4) == 0 ? "\n" : " ");
+#endif
+}
+
+void
+ifieee80211_print_reg_domains(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\nRegulatory domains:\n}");
+#else
+ printf("\nRegulatory domains:\n");
+#endif
+}
+
+void
+ifieee80211_print_reg_domain(const struct regdomain *dp, int i)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-15.15s%s}", dp->name, ((i + 1) % 4) == 0 ? "\n" : " ");
+#else
+ printf("%-15.15s%s", dp->name, ((i + 1) % 4) == 0 ? "\n" : " ");
+#endif
+}
+
+void
+ifieee80211_print_list_scan_hdr(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n}",
+ IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID", "BSSID",
+ "CHAN", "RATE", " S:N", "INT", "CAPS");
+#else
+ printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n",
+ IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID", "BSSID",
+ "CHAN", "RATE", " S:N", "INT", "CAPS");
+#endif
+}
+
+void
+ifieee80211_print_list_scan_row(const struct ieee80211req_scan_result *sr,
+ const uint8_t *idp, int idlen)
+{
+ char ssid[IEEE80211_NWID_LEN + 1];
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s}",
+ IEEE80211_NWID_LEN,
+ copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen), ssid,
+ ether_ntoa((const struct ether_addr *)sr->isr_bssid),
+ ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags),
+ getmaxrate(sr->isr_rates, sr->isr_nrates),
+ (sr->isr_rssi / 2) + sr->isr_noise, sr->isr_noise, sr->isr_intval,
+ getcaps(sr->isr_capinfo));
+#else
+ printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s", IEEE80211_NWID_LEN,
+ copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen), ssid,
+ ether_ntoa((const struct ether_addr *)sr->isr_bssid),
+ ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags),
+ getmaxrate(sr->isr_rates, sr->isr_nrates),
+ (sr->isr_rssi / 2) + sr->isr_noise, sr->isr_noise, sr->isr_intval,
+ getcaps(sr->isr_capinfo));
+#endif
+}
+
+void
+ifieee80211_print_list_stations_hdr(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n}", "ADDR",
+ "CHAN", "LOCAL", "PEER", "STATE", "RATE", "RSSI", "IDLE", "TXSEQ",
+ "RXSEQ");
+#else
+ printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n", "ADDR", "CHAN",
+ "LOCAL", "PEER", "STATE", "RATE", "RSSI", "IDLE", "TXSEQ", "RXSEQ");
+#endif
+}
+
+void
+ifieee80211_print_list_stations_hdr2(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n}", "ADDR",
+ "AID", "CHAN", "RATE", "RSSI", "IDLE", "TXSEQ", "RXSEQ", "CAPS",
+ "FLAG");
+#else
+ printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n", "ADDR",
+ "AID", "CHAN", "RATE", "RSSI", "IDLE", "TXSEQ", "RXSEQ", "CAPS",
+ "FLAG");
+#endif
+}
+
+void
+ifieee80211_print_list_stations_row(const struct ieee80211req_sta_info *si)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d}",
+ ether_ntoa((const struct ether_addr *)si->isi_macaddr),
+ ieee80211_mhz2ieee(si->isi_freq, si->isi_flags), si->isi_localid,
+ si->isi_peerid, mesh_linkstate_string(si->isi_peerstate),
+ si->isi_txmbps / 2, si->isi_rssi / 2., si->isi_inact, gettxseq(si),
+ getrxseq(si));
+#else
+ printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d",
+ ether_ntoa((const struct ether_addr *)si->isi_macaddr),
+ ieee80211_mhz2ieee(si->isi_freq, si->isi_flags), si->isi_localid,
+ si->isi_peerid, mesh_linkstate_string(si->isi_peerstate),
+ si->isi_txmbps / 2, si->isi_rssi / 2., si->isi_inact, gettxseq(si),
+ getrxseq(si));
+#endif
+}
+
+void
+ifieee80211_print_list_stations_row2(const struct ieee80211req_sta_info *si)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s}",
+ ether_ntoa((const struct ether_addr *)si->isi_macaddr),
+ IEEE80211_AID(si->isi_associd),
+ ieee80211_mhz2ieee(si->isi_freq, si->isi_flags), si->isi_txmbps / 2,
+ si->isi_rssi / 2., si->isi_inact, gettxseq(si), getrxseq(si),
+ getcaps(si->isi_capinfo), getflags(si->isi_state));
+#else
+ printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s",
+ ether_ntoa((const struct ether_addr *)si->isi_macaddr),
+ IEEE80211_AID(si->isi_associd),
+ ieee80211_mhz2ieee(si->isi_freq, si->isi_flags), si->isi_txmbps / 2,
+ si->isi_rssi / 2., si->isi_inact, gettxseq(si), getrxseq(si),
+ getcaps(si->isi_capinfo), getflags(si->isi_state));
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_tag(const char *tag)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s}", tag);
+#else
+ printf("\t%s", tag);
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_cwmin(int val)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ cwmin %2u}", val);
+#else
+ printf(" cwmin %2u", val);
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_cwmax(int val)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ cwmax %2u}", val);
+#else
+ printf(" cwmax %2u", val);
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_aifs(int val)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ aifs %2u}", val);
+#else
+ printf(" aifs %2u", val);
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_txoplimit(int val)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ txopLimit %3u}", val);
+#else
+ printf(" txopLimit %3u", val);
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_acm_enabled(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: acm}");
+#else
+ printf(" acm");
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_acm_disabled(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: -acm}");
+#else
+ printf(" -acm");
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_ack_enabled(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: ack}");
+#else
+ printf(" ack");
+#endif
+}
+
+void
+ifieee80211_print_list_wme_aci_ack_disabled(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: -ack}");
+#else
+ printf(" -ack");
+#endif
+}
+
+void
+ifieee80211_print_list_mac_acl_loaded(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:No acl policy loaded\n}");
+#else
+ printf("No acl policy loaded\n");
+#endif
+}
+
+void
+ifieee80211_print_list_mac_unknown_policy(unsigned int policy)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/policy: unknown (%u)\n}", policy);
+#else
+ printf("policy: unknown (%u)\n", policy);
+#endif
+}
+
+void
+ifieee80211_print_list_mac_nacl(char c, struct ieee80211req_maclist *acl)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%c%s\n}", c,
+ ether_ntoa((const struct ether_addr *)acl->ml_macaddr));
+#else
+ printf("%c%s\n", c,
+ ether_ntoa((const struct ether_addr *)acl->ml_macaddr));
+#endif
+}
+
+void
+ifieee80211_print_list_mesh_hdr(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%-17.17s %-17.17s %4s %4s %4s %6s %s\n}", "DEST",
+ "NEXT HOP", "HOPS", "METRIC", "LIFETIME", "MSEQ", "FLAGS");
+#else
+ printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n", "DEST", "NEXT HOP",
+ "HOPS", "METRIC", "LIFETIME", "MSEQ", "FLAGS");
+#endif
+}
+
+void
+ifieee80211_print_list_mesh_row(const struct ieee80211req_mesh_route *rt)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s }",
+ ether_ntoa((const struct ether_addr *)rt->imr_dest));
+#else
+ printf("%s ", ether_ntoa((const struct ether_addr *)rt->imr_dest));
+#endif
+}
+
+void
+ifieee80211_print_list_mesh_row2(const struct ieee80211req_mesh_route *rt)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/%s %4u %4u %6u %6u %c%c\n}",
+ ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
+ rt->imr_nhops, rt->imr_metric, rt->imr_lifetime, rt->imr_lastmseq,
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ? 'D' :
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ? 'V' :
+ '!',
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ? 'P' :
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ? 'G' :
+ ' ');
+#else
+ printf("%s %4u %4u %6u %6u %c%c\n",
+ ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
+ rt->imr_nhops, rt->imr_metric, rt->imr_lifetime, rt->imr_lastmseq,
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ? 'D' :
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ? 'V' :
+ '!',
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ? 'P' :
+ (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ? 'G' :
+ ' ');
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_meshid(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:meshid }");
+#else
+ printf("meshid ");
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_ssid(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:ssid }");
+#else
+ printf("ssid ");
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_ssid_idx(int i)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ %d:}", i + 1);
+#else
+ printf(" %d:", i + 1);
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_channel(const struct ieee80211_channel *c)
+{
+ char buf[14];
+
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ channel %d (%u MHz%s)}", c->ic_ieee, c->ic_freq,
+ get_chaninfo(c, 1, buf, sizeof(buf)));
+#else
+ printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
+ get_chaninfo(c, 1, buf, sizeof(buf)));
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_channel_undef(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P: channel UNDEF}");
+#else
+ printf(" channel UNDEF");
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_bssid(const uint8_t *bssid)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:/ bssid %s}", ether_ntoa((const struct ether_addr *)bssid));
+#else
+ printf(" bssid %s", ether_ntoa((const struct ether_addr *)bssid));
+#endif
+}
+
+void
+ifieee80211_print_ieee80211_status_stationname(void)
+{
+#ifdef WITH_LIBXO
+ xo_emit("{P:\n\tstationname }");
+#else
+ printf("\n\tstationname ");
+#endif
+}
diff --git a/sbin/ifconfig/iffib.c b/sbin/ifconfig/iffib.c
--- a/sbin/ifconfig/iffib.c
+++ b/sbin/ifconfig/iffib.c
@@ -42,6 +42,7 @@
#include <err.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static void
fib_status(if_ctx *ctx)
@@ -52,13 +53,13 @@
strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
if (ioctl_ctx(ctx, SIOCGIFFIB, (caddr_t)&ifr) == 0 &&
ifr.ifr_fib != RT_DEFAULT_FIB)
- printf("\tfib: %u\n", ifr.ifr_fib);
+ iffib_print_fib(&ifr);
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
if (ioctl_ctx(ctx, SIOCGTUNFIB, (caddr_t)&ifr) == 0 &&
ifr.ifr_fib != RT_DEFAULT_FIB)
- printf("\ttunnelfib: %u\n", ifr.ifr_fib);
+ iffib_print_tunnelfib(&ifr);
}
static void
@@ -70,11 +71,11 @@
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX)
- errx(1, "fib %s not valid", val);
+ if_errx(1, "fib %s not valid", val);
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSIFFIB, &ifr) < 0)
- err(1, "ioctl (SIOCSIFFIB)");
+ if_err(1, "ioctl (SIOCSIFFIB)");
}
static void
@@ -86,11 +87,11 @@
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX)
- errx(1, "fib %s not valid", val);
+ if_errx(1, "fib %s not valid", val);
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSTUNFIB, &ifr) < 0)
- err(1, "ioctl (SIOCSTUNFIB)");
+ if_err(1, "ioctl (SIOCSTUNFIB)");
}
static struct cmd fib_cmds[] = {
diff --git a/sbin/ifconfig/ifgeneve.h b/sbin/ifconfig/ifgeneve.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/ifgeneve.h
@@ -0,0 +1,68 @@
+#pragma once
+
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/nv.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <netdb.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_strings.h>
+#include <netinet/in.h>
+#include <net/if_geneve.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+
+#include <netlink/route/interface.h> // enum ifla_geneve_df
+
+static struct geneve_params gnvp = {
+ .ifla_proto = GENEVE_PROTO_ETHER,
+};
+
+struct nl_parsed_geneve {
+ /* essential */
+ uint32_t ifla_vni;
+ uint16_t ifla_proto;
+ struct sockaddr *ifla_local;
+ struct sockaddr *ifla_remote;
+ uint16_t ifla_local_port;
+ uint16_t ifla_remote_port;
+
+ /* optional */
+ struct ifla_geneve_port_range *ifla_port_range;
+ enum ifla_geneve_df ifla_df;
+ uint8_t ifla_ttl;
+ bool ifla_ttl_inherit;
+ bool ifla_dscp_inherit;
+ bool ifla_external;
+
+ /* l2 specific */
+ bool ifla_ftable_learn;
+ bool ifla_ftable_flush;
+ uint32_t ifla_ftable_max;
+ uint32_t ifla_ftable_timeout;
+ uint32_t ifla_ftable_count;
+ uint32_t ifla_ftable_nospace;
+ uint32_t ifla_ftable_lock_upgrade_failed;
+
+ /* multicast specific */
+ char *ifla_mc_ifname;
+ uint32_t ifla_mc_ifindex;
+
+ /* csum info */
+ uint64_t ifla_stats_txcsum;
+ uint64_t ifla_stats_tso;
+ uint64_t ifla_stats_rxcsum;
+};
diff --git a/sbin/ifconfig/ifgeneve.c b/sbin/ifconfig/ifgeneve.c
--- a/sbin/ifconfig/ifgeneve.c
+++ b/sbin/ifconfig/ifgeneve.c
@@ -26,6 +26,7 @@
* SUCH DAMAGE.
*/
+
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/nv.h>
@@ -49,49 +50,11 @@
#include <unistd.h>
#include <err.h>
#include <errno.h>
-
+
#include "ifconfig.h"
#include "ifconfig_netlink.h"
-
-struct nl_parsed_geneve {
- /* essential */
- uint32_t ifla_vni;
- uint16_t ifla_proto;
- struct sockaddr *ifla_local;
- struct sockaddr *ifla_remote;
- uint16_t ifla_local_port;
- uint16_t ifla_remote_port;
-
- /* optional */
- struct ifla_geneve_port_range *ifla_port_range;
- enum ifla_geneve_df ifla_df;
- uint8_t ifla_ttl;
- bool ifla_ttl_inherit;
- bool ifla_dscp_inherit;
- bool ifla_external;
-
- /* l2 specific */
- bool ifla_ftable_learn;
- bool ifla_ftable_flush;
- uint32_t ifla_ftable_max;
- uint32_t ifla_ftable_timeout;
- uint32_t ifla_ftable_count;
- uint32_t ifla_ftable_nospace;
- uint32_t ifla_ftable_lock_upgrade_failed;
-
- /* multicast specific */
- char *ifla_mc_ifname;
- uint32_t ifla_mc_ifindex;
-
- /* csum info */
- uint64_t ifla_stats_txcsum;
- uint64_t ifla_stats_tso;
- uint64_t ifla_stats_rxcsum;
-};
-
-static struct geneve_params gnvp = {
- .ifla_proto = GENEVE_PROTO_ETHER,
-};
+#include "ifconfig_output.h"
+#include "ifgeneve.h"
static int
get_proto(const char *cp, uint16_t *valp)
@@ -166,7 +129,7 @@
}
#endif
default:
- errx(1, "address family not supported");
+ if_errx(1, "address family not supported");
}
}
@@ -180,7 +143,7 @@
uint16_t val;
if (get_proto(arg, &val) < 0)
- errx(1, "invalid inner protocol: %s", arg);
+ if_errx(1, "invalid inner protocol: %s", arg);
gnvp.ifla_proto = val;
}
@@ -215,10 +178,10 @@
hdr = snl_finalize_msg(nw);
if (hdr == NULL || !snl_send_message(ctx->io_ss, hdr))
- err(1, "unable to send netlink message");
+ if_err(1, "unable to send netlink message");
if (!snl_read_reply_code(ctx->io_ss, hdr->nlmsg_seq, &errmsg))
- errx(errmsg.error, "%s", errmsg.error_str);
+ if_errx(errmsg.error, "%s", errmsg.error_str);
}
#define _OUT(_field) offsetof(struct nl_parsed_geneve, _field)
@@ -318,21 +281,21 @@
struct nla_geneve_info geneve_info = geneve_link.linkinfo;
struct nl_parsed_geneve geneve_data = geneve_info.data;
- printf("\tgeneve mode: ");
+ ifgeneve_print_mode();
switch (geneve_data.ifla_proto) {
case GENEVE_PROTO_INHERIT:
- printf("l3");
+ ifgeneve_print_proto_l3();
break;
case GENEVE_PROTO_ETHER:
default:
- printf("l2");
+ ifgeneve_print_proto_l2();
break;
}
- printf("\n\tgeneve config:\n");
+ ifgeneve_print_config();
/* Just report nothing if the network identity isn't set yet. */
if (geneve_data.ifla_vni >= GENEVE_VNI_MAX) {
- printf("\t\tvirtual network identifier (vni): not configured\n");
+ ifgeneve_print_config_vni_notconfigured();
return;
}
@@ -358,58 +321,46 @@
}
}
- printf("\t\tvirtual network identifier (vni): %d", geneve_data.ifla_vni);
+ ifgeneve_print_vni(&geneve_data);
if (src[0] != '\0')
- printf("\n\t\tlocal: %s%s%s:%u", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
- geneve_data.ifla_local_port);
+ ifgeneve_print_src(ipv6, src, &geneve_data);
if (dst[0] != '\0') {
- printf("\n\t\t%s: %s%s%s:%u", mc ? "group" : "remote", ipv6 ? "[" : "",
- dst, ipv6 ? "]" : "", geneve_data.ifla_local_port);
+ ifgeneve_print_dst(mc, ipv6, dst, &geneve_data);
if (mc)
- printf(", dev: %s", geneve_data.ifla_mc_ifname);
+ ifgeneve_print_mcastdev(&geneve_data);
}
if (ctx->args->verbose) {
- printf("\n\t\tportrange: %u-%u",
- geneve_data.ifla_port_range->low,
- geneve_data.ifla_port_range->high);
+ ifgeneve_print_portrange(&geneve_data);
if (geneve_data.ifla_ttl_inherit)
- printf(", ttl: inherit");
+ ifgeneve_print_ttl_inherit();
else
- printf(", ttl: %d", geneve_data.ifla_ttl);
+ ifgeneve_print_ttl(&geneve_data);
if (geneve_data.ifla_dscp_inherit)
- printf(", dscp: inherit");
+ ifgeneve_print_dscp();
if (geneve_data.ifla_df == IFLA_GENEVE_DF_INHERIT)
- printf(", df: inherit");
+ ifgeneve_print_df_inherit();
else if (geneve_data.ifla_df == IFLA_GENEVE_DF_SET)
- printf(", df: set");
+ ifgeneve_print_df_set();
else if (geneve_data.ifla_df == IFLA_GENEVE_DF_UNSET)
- printf(", df: unset");
+ ifgeneve_print_df_unset();
if (geneve_data.ifla_external)
- printf(", externally controlled");
+ ifgeneve_print_extctl();
if (geneve_data.ifla_proto == GENEVE_PROTO_ETHER) {
- printf("\n\t\tftable mode: %slearning",
- geneve_data.ifla_ftable_learn ? "" : "no");
- printf(", count: %d, max: %d, timeout: %d",
- geneve_data.ifla_ftable_count,
- geneve_data.ifla_ftable_max,
- geneve_data.ifla_ftable_timeout);
- printf(", nospace: %u",
- geneve_data.ifla_ftable_nospace);
+ ifgeneve_print_ftable_mode(&geneve_data);
+ ifgeneve_print_ftable(&geneve_data);
+ ifgeneve_print_ftable_nospace(&geneve_data);
}
- printf("\n\t\tstats: tso %ju, txcsum %ju, rxcsum %ju",
- (uintmax_t)geneve_data.ifla_stats_tso,
- (uintmax_t)geneve_data.ifla_stats_txcsum,
- (uintmax_t)geneve_data.ifla_stats_rxcsum);
+ ifgeneve_print_stats(&geneve_data);
}
- putchar('\n');
+ ifconfig_print_newline();
}
@@ -533,11 +484,11 @@
int error;
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing local address string: %s",
+ if_errx(1, "error in parsing local address string: %s",
gai_strerror(error));
if (!is_multicast(ai))
- errx(1, "group address must be multicast");
+ if_errx(1, "group address must be multicast");
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
@@ -563,7 +514,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid local port: %s", arg);
+ if_errx(1, "invalid local port: %s", arg);
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
@@ -587,7 +538,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid remote port: %s", arg);
+ if_errx(1, "invalid remote port: %s", arg);
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
@@ -611,11 +562,11 @@
u_long min, max;
if (get_val(arg1, &min) < 0 || min >= UINT16_MAX)
- errx(1, "invalid port range minimum: %s", arg1);
+ if_errx(1, "invalid port range minimum: %s", arg1);
if (get_val(arg2, &max) < 0 || max >= UINT16_MAX)
- errx(1, "invalid port range maximum: %s", arg2);
+ if_errx(1, "invalid port range maximum: %s", arg2);
if (max < min)
- errx(1, "invalid port range");
+ if_errx(1, "invalid port range");
const struct ifla_geneve_port_range port_range = {
.low = min,
@@ -645,7 +596,7 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid timeout value: %s", arg);
+ if_errx(1, "invalid timeout value: %s", arg);
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
@@ -669,7 +620,7 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid maxaddr value: %s", arg);
+ if_errx(1, "invalid maxaddr value: %s", arg);
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
@@ -723,7 +674,7 @@
} else if (!strcmp(arg, "inherit")) {
snl_add_msg_attr_bool(&nw, IFLA_GENEVE_TTL_INHERIT, true);
} else
- errx(1, "invalid TTL value: %s", arg);
+ if_errx(1, "invalid TTL value: %s", arg);
snl_end_attr_nested(&nw, off2);
snl_end_attr_nested(&nw, off);
@@ -739,7 +690,7 @@
enum ifla_geneve_df df;
if (get_df(arg, &df) < 0)
- errx(1, "invalid df value: %s", arg);
+ if_errx(1, "invalid df value: %s", arg);
geneve_nl_init(ctx, &nw, 0);
off = snl_add_msg_attr_nested(&nw, IFLA_LINKINFO);
diff --git a/sbin/ifconfig/ifgif.c b/sbin/ifconfig/ifgif.c
--- a/sbin/ifconfig/ifgif.c
+++ b/sbin/ifconfig/ifgif.c
@@ -47,6 +47,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static const char *GIFBITS[] = {
[0] = "NOCLAMP",
@@ -63,9 +64,10 @@
return;
if (opts == 0)
return;
- printf("\toptions=%x", opts);
- print_bits("options", &opts, 1, GIFBITS, nitems(GIFBITS));
- putchar('\n');
+ ifgif_print_options(opts);
+ ifconfig_print_bits("options", "option", &opts, 1, GIFBITS,
+ nitems(GIFBITS));
+ ifconfig_print_newline();
}
static void
@@ -75,7 +77,7 @@
struct ifreq ifr = { .ifr_data = (caddr_t)&opts };
if (ioctl_ctx_ifr(ctx, GIFGOPTS, &ifr) == -1) {
- warn("ioctl(GIFGOPTS)");
+ if_warn("ioctl(GIFGOPTS)");
return;
}
@@ -85,7 +87,7 @@
opts |= d;
if (ioctl_ctx(ctx, GIFSOPTS, &ifr) == -1) {
- warn("ioctl(GIFSOPTS)");
+ if_warn("ioctl(GIFSOPTS)");
return;
}
}
diff --git a/sbin/ifconfig/ifgre.c b/sbin/ifconfig/ifgre.c
--- a/sbin/ifconfig/ifgre.c
+++ b/sbin/ifconfig/ifgre.c
@@ -40,6 +40,7 @@
#include <err.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static const char *GREBITS[] = {
[0] = "ENABLE_CSUM",
@@ -55,7 +56,7 @@
if (ioctl_ctx_ifr(ctx, GREGKEY, &ifr) == 0)
if (opts != 0)
- printf("\tgrekey: 0x%x (%u)\n", opts, opts);
+ ifgre_print_key(opts);
opts = 0;
if (ioctl_ctx_ifr(ctx, GREGOPTS, &ifr) != 0 || opts == 0)
return;
@@ -63,10 +64,11 @@
port = 0;
ifr.ifr_data = (caddr_t)&port;
if (ioctl_ctx_ifr(ctx, GREGPORT, &ifr) == 0 && port != 0)
- printf("\tudpport: %u\n", port);
- printf("\toptions=%x", opts);
- print_bits("options", &opts, 1, GREBITS, nitems(GREBITS));
- putchar('\n');
+ ifgre_print_udpport(port);
+ ifgre_print_options(opts);
+ ifconfig_print_bits("options", "option", &opts, 1, GREBITS,
+ nitems(GREBITS));
+ ifconfig_print_newline();
}
static void
@@ -77,7 +79,7 @@
ifr.ifr_data = (caddr_t)&grekey;
if (ioctl_ctx_ifr(ctx, GRESKEY, &ifr) < 0)
- warn("ioctl (set grekey)");
+ if_warn("ioctl (set grekey)");
}
static void
@@ -87,7 +89,7 @@
struct ifreq ifr = { .ifr_data = (caddr_t)&udpport };
if (ioctl_ctx_ifr(ctx, GRESPORT, &ifr) < 0)
- warn("ioctl (set udpport)");
+ if_warn("ioctl (set udpport)");
}
static void
@@ -97,7 +99,7 @@
struct ifreq ifr = { .ifr_data = (caddr_t)&opts };
if (ioctl_ctx_ifr(ctx, GREGOPTS, &ifr) == -1) {
- warn("ioctl(GREGOPTS)");
+ if_warn("ioctl(GREGOPTS)");
return;
}
@@ -107,7 +109,7 @@
opts |= d;
if (ioctl_ctx(ctx, GRESOPTS, &ifr) == -1) {
- warn("ioctl(GIFSOPTS)");
+ if_warn("ioctl(GIFSOPTS)");
return;
}
}
diff --git a/sbin/ifconfig/ifgroup.c b/sbin/ifconfig/ifgroup.c
--- a/sbin/ifconfig/ifgroup.c
+++ b/sbin/ifconfig/ifgroup.c
@@ -41,6 +41,7 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static void
setifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
@@ -50,12 +51,12 @@
strlcpy(ifgr.ifgr_name, ctx->ifname, IFNAMSIZ);
if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
- errx(1, "setifgroup: group names may not end in a digit");
+ if_errx(1, "setifgroup: group names may not end in a digit");
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
- errx(1, "setifgroup: group name too long");
+ if_errx(1, "setifgroup: group name too long");
if (ioctl_ctx(ctx, SIOCAIFGROUP, (caddr_t)&ifgr) == -1 && errno != EEXIST)
- err(1," SIOCAIFGROUP");
+ if_err(1," SIOCAIFGROUP");
}
static void
@@ -66,12 +67,12 @@
strlcpy(ifgr.ifgr_name, ctx->ifname, IFNAMSIZ);
if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
- errx(1, "unsetifgroup: group names may not end in a digit");
+ if_errx(1, "unsetifgroup: group names may not end in a digit");
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
- errx(1, "unsetifgroup: group name too long");
+ if_errx(1, "unsetifgroup: group name too long");
if (ioctl_ctx(ctx, SIOCDIFGROUP, (caddr_t)&ifgr) == -1 && errno != ENOENT)
- err(1, "SIOCDIFGROUP");
+ if_err(1, "SIOCDIFGROUP");
}
static void
@@ -84,59 +85,26 @@
return;
cnt = 0;
+ ifconfig_open_list("groups");
for (size_t i = 0; i < ifgr.ifgr_len / sizeof(struct ifg_req); ++i) {
struct ifg_req *ifg = &ifgr.ifgr_groups[i];
if (strcmp(ifg->ifgrq_group, "all")) {
if (cnt == 0)
- printf("\tgroups:");
+ ifgroup_print_groups();
cnt++;
- printf(" %s", ifg->ifgrq_group);
+ ifconfig_open_instance("group");
+ ifgroup_print_group(ifg);
+ ifconfig_close_instance("group");
}
}
+ ifconfig_close_list("groups");
if (cnt)
- printf("\n");
+ ifconfig_print_newline();
free(ifgr.ifgr_groups);
}
-static void
-printgroup(const char *groupname)
-{
- struct ifgroupreq ifgr;
- struct ifg_req *ifg;
- unsigned int len;
- int s;
-
- s = socket(AF_LOCAL, SOCK_DGRAM, 0);
- if (s == -1)
- err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
- bzero(&ifgr, sizeof(ifgr));
- strlcpy(ifgr.ifgr_name, groupname, sizeof(ifgr.ifgr_name));
- if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
- if (errno == EINVAL || errno == ENOTTY ||
- errno == ENOENT)
- exit(exit_code);
- else
- err(1, "SIOCGIFGMEMB");
- }
-
- len = ifgr.ifgr_len;
- if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
- err(1, "printgroup");
- if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
- err(1, "SIOCGIFGMEMB");
-
- for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req);
- ifg++) {
- len -= sizeof(struct ifg_req);
- printf("%s\n", ifg->ifgrq_member);
- }
- free(ifgr.ifgr_groups);
-
- exit(exit_code);
-}
-
static struct cmd group_cmds[] = {
DEF_CMD_ARG("group", setifgroup),
DEF_CMD_ARG("-group", unsetifgroup),
@@ -151,7 +119,7 @@
static struct option group_gopt = {
.opt = "g:",
.opt_usage = "[-g groupname]",
- .cb = printgroup,
+ .cb = ifgroup_printgroup,
};
static __constructor void
diff --git a/sbin/ifconfig/ifieee80211.h b/sbin/ifconfig/ifieee80211.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/ifieee80211.h
@@ -0,0 +1,152 @@
+#pragma once
+
+#include <net/if_strings.h>
+
+#define WANT_NET80211 1
+#include <net80211/ieee80211_ioctl.h>
+#include <net80211/ieee80211_freebsd.h>
+#include <net80211/ieee80211_superg.h>
+#include <net80211/ieee80211_tdma.h>
+#include <net80211/ieee80211_mesh.h>
+#include <net80211/ieee80211_wps.h>
+
+#include <lib80211/lib80211_regdomain.h>
+#include <lib80211/lib80211_ioctl.h>
+
+#define LE_READ_2(p) \
+ ((u_int16_t) \
+ ((((const u_int8_t *)(p))[0] ) | \
+ (((const u_int8_t *)(p))[1] << 8)))
+
+#define LE_READ_4(p) \
+ ((u_int32_t) \
+ ((((const u_int8_t *)(p))[0] ) | \
+ (((const u_int8_t *)(p))[1] << 8) | \
+ (((const u_int8_t *)(p))[2] << 16) | \
+ (((const u_int8_t *)(p))[3] << 24)))
+
+#define BE_READ_2(p) \
+ ((u_int16_t) \
+ ((((const u_int8_t *)(p))[1] ) | \
+ (((const u_int8_t *)(p))[0] << 8)))
+
+
+/* Helper macros unified. */
+#ifndef _IEEE80211_MASKSHIFT
+#define _IEEE80211_MASKSHIFT(_v, _f) (((_v) & _f) >> _f##_S)
+#endif
+#ifndef _IEEE80211_SHIFTMASK
+#define _IEEE80211_SHIFTMASK(_v, _f) (((_v) << _f##_S) & _f)
+#endif
+
+#ifndef IEEE80211_FIXED_RATE_NONE
+#define IEEE80211_FIXED_RATE_NONE 0xff
+#endif
+
+/* XXX need these publicly defined or similar */
+#ifndef IEEE80211_NODE_AUTH
+#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
+#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
+#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
+#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
+#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
+#define IEEE80211_NODE_HT 0x000040 /* HT enabled */
+#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
+#define IEEE80211_NODE_WPS 0x000100 /* WPS association */
+#define IEEE80211_NODE_TSN 0x000200 /* TSN association */
+#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
+#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
+#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
+#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
+#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
+#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
+#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
+#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
+#define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
+#define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
+#define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */
+#define IEEE80211_NODE_LDPC 0x200000 /* LDPC enabled */
+#define IEEE80211_NODE_UAPSD 0x400000 /* UAPSD enabled */
+#endif
+
+/* XXX should also figure out where to put these for k/u-space sharing. */
+#ifndef IEEE80211_FVHT_VHT
+#define IEEE80211_FVHT_VHT 0x000000001 /* CONF: VHT supported */
+#define IEEE80211_FVHT_USEVHT40 0x000000002 /* CONF: Use VHT40 */
+#define IEEE80211_FVHT_USEVHT80 0x000000004 /* CONF: Use VHT80 */
+#define IEEE80211_FVHT_USEVHT80P80 0x000000008 /* CONF: Use VHT 80+80 */
+#define IEEE80211_FVHT_USEVHT160 0x000000010 /* CONF: Use VHT160 */
+#define IEEE80211_FVHT_STBC_TX 0x00000020 /* CONF: STBC tx enabled */
+#define IEEE80211_FVHT_STBC_RX 0x00000040 /* CONF: STBC rx enabled */
+#endif
+
+#define MAXCHAN 1536 /* max 1.5K channels */
+
+static const char *modename[IEEE80211_MODE_MAX] = {
+ [IEEE80211_MODE_AUTO] = "auto",
+ [IEEE80211_MODE_11A] = "11a",
+ [IEEE80211_MODE_11B] = "11b",
+ [IEEE80211_MODE_11G] = "11g",
+ [IEEE80211_MODE_FH] = "fh",
+ [IEEE80211_MODE_TURBO_A] = "turboA",
+ [IEEE80211_MODE_TURBO_G] = "turboG",
+ [IEEE80211_MODE_STURBO_A] = "sturbo",
+ [IEEE80211_MODE_11NA] = "11na",
+ [IEEE80211_MODE_11NG] = "11ng",
+ [IEEE80211_MODE_HALF] = "half",
+ [IEEE80211_MODE_QUARTER] = "quarter",
+ [IEEE80211_MODE_VHT_2GHZ] = "11acg",
+ [IEEE80211_MODE_VHT_5GHZ] = "11ac",
+};
+
+int get80211(if_ctx *ctx, int type, void *data, int len);
+const char *rsn_cipher(const u_int8_t *sel);
+const char *rsn_keymgmt(const u_int8_t *sel);
+const char *iename(uint8_t elemid, const u_int8_t *vp);
+int chanpref(const struct ieee80211_channel *c);
+void getchaninfo(if_ctx *ctx);
+const char * get_chaninfo(const struct ieee80211_channel *c, int precise, char buf[],
+ size_t bsize);
+
+int ieee80211_mhz2ieee(int freq, int flags);
+struct regdata *getregdata(void);
+int copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len);
+int iswpaoui(const u_int8_t *frm);
+int iswmeinfo(const u_int8_t *frm);
+int iswmeparam(const u_int8_t *frm);
+int isatherosoui(const u_int8_t *frm);
+int istdmaoui(const uint8_t *frm);
+int iswpsoui(const uint8_t *frm);
+
+int getmaxrate(const uint8_t rates[15], uint8_t nrates);
+const char *getcaps(int capinfo);
+const char *getflags(int flags);
+int gettxseq(const struct ieee80211req_sta_info *si);
+int getrxseq(const struct ieee80211req_sta_info *si);
+const char *mesh_linkstate_string(uint8_t state);
+
+static struct ieee80211req_chaninfo *chaninfo;
+static struct ieee80211_regdomain regdomain;
+
+static int gotregdomain = 0;
+
+static struct ieee80211_roamparams_req roamparams;
+
+static int gotroam = 0;
+
+static struct ieee80211_txparams_req txparams;
+
+static int gottxparams = 0;
+
+static struct ieee80211_channel curchan;
+
+static int gotcurchan = 0;
+
+static struct ifmediareq *global_ifmr;
+
+/* HT */
+static int htconf = 0;
+static int gothtconf = 0;
+
+const char * wpa_cipher(const u_int8_t *sel);
+const char * wpa_keymgmt(const u_int8_t *sel);
diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c
--- a/sbin/ifconfig/ifieee80211.c
+++ b/sbin/ifconfig/ifieee80211.c
@@ -93,115 +93,22 @@
#include <locale.h>
#include <langinfo.h>
-#include "ifconfig.h"
-
#include <lib80211/lib80211_regdomain.h>
#include <lib80211/lib80211_ioctl.h>
-#ifndef IEEE80211_FIXED_RATE_NONE
-#define IEEE80211_FIXED_RATE_NONE 0xff
-#endif
-
-/* XXX need these publicly defined or similar */
-#ifndef IEEE80211_NODE_AUTH
-#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
-#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
-#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
-#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
-#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
-#define IEEE80211_NODE_HT 0x000040 /* HT enabled */
-#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
-#define IEEE80211_NODE_WPS 0x000100 /* WPS association */
-#define IEEE80211_NODE_TSN 0x000200 /* TSN association */
-#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
-#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
-#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
-#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
-#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
-#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
-#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
-#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
-#define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
-#define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
-#define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */
-#define IEEE80211_NODE_LDPC 0x200000 /* LDPC enabled */
-#define IEEE80211_NODE_UAPSD 0x400000 /* UAPSD enabled */
-#endif
-
-/* XXX should also figure out where to put these for k/u-space sharing. */
-#ifndef IEEE80211_FVHT_VHT
-#define IEEE80211_FVHT_VHT 0x000000001 /* CONF: VHT supported */
-#define IEEE80211_FVHT_USEVHT40 0x000000002 /* CONF: Use VHT40 */
-#define IEEE80211_FVHT_USEVHT80 0x000000004 /* CONF: Use VHT80 */
-#define IEEE80211_FVHT_USEVHT80P80 0x000000008 /* CONF: Use VHT 80+80 */
-#define IEEE80211_FVHT_USEVHT160 0x000000010 /* CONF: Use VHT160 */
-#define IEEE80211_FVHT_STBC_TX 0x00000020 /* CONF: STBC tx enabled */
-#define IEEE80211_FVHT_STBC_RX 0x00000040 /* CONF: STBC rx enabled */
-#endif
-
-/* Helper macros unified. */
-#ifndef _IEEE80211_MASKSHIFT
-#define _IEEE80211_MASKSHIFT(_v, _f) (((_v) & _f) >> _f##_S)
-#endif
-#ifndef _IEEE80211_SHIFTMASK
-#define _IEEE80211_SHIFTMASK(_v, _f) (((_v) << _f##_S) & _f)
-#endif
-
-#define MAXCHAN 1536 /* max 1.5K channels */
-
-#define MAXCOL 78
-static int col;
-static char spacer;
-
-static void LINE_INIT(char c);
-static void LINE_BREAK(void);
-static void LINE_CHECK(const char *fmt, ...);
-
-static const char *modename[IEEE80211_MODE_MAX] = {
- [IEEE80211_MODE_AUTO] = "auto",
- [IEEE80211_MODE_11A] = "11a",
- [IEEE80211_MODE_11B] = "11b",
- [IEEE80211_MODE_11G] = "11g",
- [IEEE80211_MODE_FH] = "fh",
- [IEEE80211_MODE_TURBO_A] = "turboA",
- [IEEE80211_MODE_TURBO_G] = "turboG",
- [IEEE80211_MODE_STURBO_A] = "sturbo",
- [IEEE80211_MODE_11NA] = "11na",
- [IEEE80211_MODE_11NG] = "11ng",
- [IEEE80211_MODE_HALF] = "half",
- [IEEE80211_MODE_QUARTER] = "quarter",
- [IEEE80211_MODE_VHT_2GHZ] = "11acg",
- [IEEE80211_MODE_VHT_5GHZ] = "11ac",
-};
+#include "ifconfig.h"
+#include "ifieee80211.h"
+#include "ifconfig_output.h"
static void set80211(if_ctx *ctx, int type, int val, int len, void *data);
-static int get80211(if_ctx *ctx, int type, void *data, int len);
static int get80211len(if_ctx *ctx, int type, void *data, int len, int *plen);
static int get80211val(if_ctx *ctx, int type, int *val);
-static const char *get_string(const char *val, const char *sep,
- u_int8_t *buf, int *lenp);
-static void print_string(const u_int8_t *buf, int len);
-static void print_regdomain(const struct ieee80211_regdomain *, int);
-static void print_channels(if_ctx *, const struct ieee80211req_chaninfo *,
- int allchans, int verbose);
-static void regdomain_makechannels(if_ctx *, struct ieee80211_regdomain_req *,
- const struct ieee80211_devcaps_req *);
-static const char *mesh_linkstate_string(uint8_t state);
-static struct ieee80211req_chaninfo *chaninfo;
-static struct ieee80211_regdomain regdomain;
-static int gotregdomain = 0;
-static struct ieee80211_roamparams_req roamparams;
-static int gotroam = 0;
-static struct ieee80211_txparams_req txparams;
-static int gottxparams = 0;
-static struct ieee80211_channel curchan;
-static int gotcurchan = 0;
-static struct ifmediareq *global_ifmr;
+static const char *get_string(const char *val, const char *sep,
+ u_int8_t *buf, int *lenp);
-/* HT */
-static int htconf = 0;
-static int gothtconf = 0;
+static void regdomain_makechannels(if_ctx *, struct ieee80211_regdomain_req *,
+ const struct ieee80211_devcaps_req *);
static void
gethtconf(if_ctx *ctx)
@@ -209,7 +116,7 @@
if (gothtconf)
return;
if (get80211val(ctx, IEEE80211_IOC_HTCONF, &htconf) < 0)
- warn("unable to get HT configuration information");
+ if_warn("unable to get HT configuration information");
gothtconf = 1;
}
@@ -223,7 +130,7 @@
if (gotvhtconf)
return;
if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
- warn("unable to get VHT configuration information");
+ if_warn("unable to get VHT configuration information");
gotvhtconf = 1;
}
@@ -231,30 +138,30 @@
* Collect channel info from the kernel. We use this (mostly)
* to handle mapping between frequency and IEEE channel number.
*/
-static void
+void
getchaninfo(if_ctx *ctx)
{
if (chaninfo != NULL)
return;
chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
if (chaninfo == NULL)
- errx(1, "no space for channel list");
+ if_errx(1, "no space for channel list");
if (get80211(ctx, IEEE80211_IOC_CHANINFO, chaninfo,
IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
- err(1, "unable to get channel information");
+ if_err(1, "unable to get channel information");
global_ifmr = ifmedia_getstate(ctx);
gethtconf(ctx);
getvhtconf(ctx);
}
-static struct regdata *
+struct regdata *
getregdata(void)
{
static struct regdata *rdp = NULL;
if (rdp == NULL) {
rdp = lib80211_alloc_regdata();
if (rdp == NULL)
- errx(-1, "missing or corrupted regdomain database");
+ if_errx(-1, "missing or corrupted regdomain database");
}
return rdp;
}
@@ -366,7 +273,7 @@
return;
}
}
- errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
+ if_errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
}
static void
@@ -386,7 +293,7 @@
return;
}
}
- errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
+ if_errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
}
static const struct ieee80211_channel *
@@ -398,7 +305,7 @@
int val;
/* fall back to legacy ioctl */
if (get80211val(ctx, IEEE80211_IOC_CHANNEL, &val) < 0)
- err(-1, "cannot figure out current channel");
+ if_err(-1, "cannot figure out current channel");
getchaninfo(ctx);
mapchan(&curchan, val, 0);
}
@@ -445,7 +352,7 @@
return;
if (get80211(ctx, IEEE80211_IOC_ROAM,
&roamparams, sizeof(roamparams)) < 0)
- err(1, "unable to get roaming parameters");
+ if_err(1, "unable to get roaming parameters");
gotroam = 1;
}
@@ -463,7 +370,7 @@
return;
if (get80211(ctx, IEEE80211_IOC_TXPARAMS,
&txparams, sizeof(txparams)) < 0)
- err(1, "unable to get transmit parameters");
+ if_err(1, "unable to get transmit parameters");
gottxparams = 1;
}
@@ -481,7 +388,7 @@
return;
if (get80211(ctx, IEEE80211_IOC_REGDOMAIN,
&regdomain, sizeof(regdomain)) < 0)
- err(1, "unable to get regulatory domain info");
+ if_err(1, "unable to get regulatory domain info");
gotregdomain = 1;
}
@@ -490,7 +397,7 @@
{
if (get80211(ctx, IEEE80211_IOC_DEVCAPS, dc,
IEEE80211_DEVCAPS_SPACE(dc)) < 0)
- err(1, "unable to get device capabilities");
+ if_err(1, "unable to get device capabilities");
}
static void
@@ -511,7 +418,7 @@
*/
cc = lib80211_country_findbycc(rdp, rd->country);
if (cc == NULL)
- errx(1, "unknown ISO country code %d", rd->country);
+ if_errx(1, "unknown ISO country code %d", rd->country);
if (cc->rd->sku != rd->regdomain) {
const struct regdomain *rp;
/*
@@ -529,11 +436,11 @@
*/
rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
if (rp == NULL)
- errx(1, "country %s (%s) is not usable with "
+ if_errx(1, "country %s (%s) is not usable with "
"regdomain %d", cc->isoname, cc->name,
rd->regdomain);
else if (rp->cc != NULL && rp->cc != cc)
- errx(1, "country %s (%s) is not usable with "
+ if_errx(1, "country %s (%s) is not usable with "
"regdomain %s", cc->isoname, cc->name,
rp->name);
}
@@ -546,50 +453,50 @@
*/
dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
if (dc == NULL)
- errx(1, "no space for device capabilities");
+ if_errx(1, "no space for device capabilities");
dc->dc_chaninfo.ic_nchans = MAXCHAN;
getdevcaps(ctx, dc);
#if 0
if (verbose) {
- printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
- printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
- printf("htcaps : 0x%x\n", dc->dc_htcaps);
- printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
+ ifieee80211_print_drivercaps(dc);
+ ifieee80211_print_cryptocaps(dc);
+ ifieee80211_print_htcaps(dc);
+ ifieee80211_print_vhtcaps(dc);
#if 0
memcpy(chaninfo, &dc->dc_chaninfo,
IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
- print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
+ ifieee80211_print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
#endif
}
#endif
req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
if (req == NULL)
- errx(1, "no space for regdomain request");
+ if_errx(1, "no space for regdomain request");
req->rd = *rd;
regdomain_makechannels(ctx, req, dc);
if (ctx->args->verbose) {
- LINE_INIT(':');
- print_regdomain(rd, 1/*verbose*/);
- LINE_BREAK();
+ ifieee80211_line_init(':');
+ ifieee80211_print_regdomain(rd, 1/*verbose*/);
+ ifieee80211_line_break();
/* blech, reallocate channel list for new data */
if (chaninfo != NULL)
free(chaninfo);
chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
if (chaninfo == NULL)
- errx(1, "no space for channel list");
+ if_errx(1, "no space for channel list");
memcpy(chaninfo, &req->chaninfo,
IEEE80211_CHANINFO_SPACE(&req->chaninfo));
- print_channels(ctx, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
+ ifieee80211_print_channels(ctx, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
}
if (req->chaninfo.ic_nchans == 0)
- errx(1, "no channels calculated");
+ if_errx(1, "no channels calculated");
set80211(ctx, IEEE80211_IOC_REGDOMAIN, 0,
IEEE80211_REGDOMAIN_SPACE(req), req);
free(req);
free(dc);
}
-static int
+int
ieee80211_mhz2ieee(int freq, int flags)
{
struct ieee80211_channel chan;
@@ -711,7 +618,7 @@
flags |= IEEE80211_CHAN_STURBO;
break;
default:
- errx(-1, "%s: Invalid channel attribute %c\n",
+ if_errx(-1, "%s: Invalid channel attribute %c\n",
val, *cp);
}
}
@@ -748,7 +655,7 @@
flags |= IEEE80211_CHAN_HT40D;
break;
default:
- errx(-1, "%s: Invalid channel width\n", val);
+ if_errx(-1, "%s: Invalid channel width\n", val);
}
}
@@ -825,7 +732,7 @@
if (val[0] == '\0' || val == eptr || errno == ERANGE ||
/* channel may be suffixed with nothing, :flag, or /width */
(eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
- errx(1, "invalid channel specification%s",
+ if_errx(1, "invalid channel specification%s",
errno == ERANGE ? " (out of range)" : "");
flags = getchannelflags(val, v);
if (v > 255) { /* treat as frequency */
@@ -871,7 +778,7 @@
} else if (strcasecmp(val, "wpa") == 0) {
mode = IEEE80211_AUTH_WPA;
} else {
- errx(1, "unknown authmode");
+ if_errx(1, "unknown authmode");
}
set80211(ctx, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
@@ -893,7 +800,7 @@
} else if (strcasecmp(val, "psp-cam") == 0) {
mode = IEEE80211_POWERSAVE_PSP_CAM;
} else {
- errx(1, "unknown powersavemode");
+ if_errx(1, "unknown powersavemode");
}
set80211(ctx, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
@@ -928,7 +835,7 @@
} else if (strcasecmp(val, "mixed") == 0) {
mode = IEEE80211_WEP_MIXED;
} else {
- errx(1, "unknown wep mode");
+ if_errx(1, "unknown wep mode");
}
set80211(ctx, IEEE80211_IOC_WEP, mode, 0, NULL);
@@ -1036,7 +943,7 @@
} else if (strncasecmp(val, "rtscts", 3) == 0) {
mode = IEEE80211_PROTMODE_RTSCTS;
} else {
- errx(1, "unknown protection mode");
+ if_errx(1, "unknown protection mode");
}
set80211(ctx, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
@@ -1052,7 +959,7 @@
} else if (strncasecmp(val, "rts", 3) == 0) {
mode = IEEE80211_PROTMODE_RTSCTS;
} else {
- errx(1, "unknown protection mode");
+ if_errx(1, "unknown protection mode");
}
set80211(ctx, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
@@ -1066,7 +973,7 @@
txpow = (int) (2*v);
if (txpow != 2*v)
- errx(-1, "invalid tx power (must be .5 dBm units)");
+ if_errx(-1, "invalid tx power (must be .5 dBm units)");
set80211(ctx, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
}
@@ -1086,7 +993,7 @@
} else if (strcasecmp(val, "manual") == 0) {
mode = IEEE80211_ROAMING_MANUAL;
} else {
- errx(1, "unknown roaming mode");
+ if_errx(1, "unknown roaming mode");
}
set80211(ctx, IEEE80211_IOC_ROAMING, mode, 0, NULL);
}
@@ -1129,7 +1036,7 @@
temp = malloc(strlen(val) + 1);
if (temp == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
strcpy(temp, val);
memset(&chanlist, 0, sizeof(chanlist));
cp = temp;
@@ -1142,19 +1049,19 @@
switch (sscanf(cp, "%u-%u", &first, &last)) {
case 1:
if (first > IEEE80211_CHAN_MAX)
- errx(-1, "channel %u out of range, max %u",
+ if_errx(-1, "channel %u out of range, max %u",
first, IEEE80211_CHAN_MAX);
setbit(chanlist.ic_channels, first);
break;
case 2:
if (first > IEEE80211_CHAN_MAX)
- errx(-1, "channel %u out of range, max %u",
+ if_errx(-1, "channel %u out of range, max %u",
first, IEEE80211_CHAN_MAX);
if (last > IEEE80211_CHAN_MAX)
- errx(-1, "channel %u out of range, max %u",
+ if_errx(-1, "channel %u out of range, max %u",
last, IEEE80211_CHAN_MAX);
if (first > last)
- errx(-1, "void channel range, %u > %u",
+ if_errx(-1, "void channel range, %u > %u",
first, last);
for (f = first; f <= last; f++)
setbit(chanlist.ic_channels, f);
@@ -1182,14 +1089,14 @@
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
temp[0] = ':';
strcpy(temp + 1, val);
sdl.sdl_len = sizeof(sdl);
link_addr(temp, &sdl);
free(temp);
if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
set80211(ctx, IEEE80211_IOC_BSSID, 0,
IEEE80211_ADDR_LEN, LLADDR(&sdl));
} else {
@@ -1211,7 +1118,7 @@
return WME_AC_VI;
if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
return WME_AC_VO;
- errx(1, "unknown wme access class %s", ac);
+ if_errx(1, "unknown wme access class %s", ac);
}
static void
@@ -1309,14 +1216,14 @@
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
temp[0] = ':';
strcpy(temp + 1, val);
sdl.sdl_len = sizeof(sdl);
link_addr(temp, &sdl);
free(temp);
if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
set80211(ctx, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
}
@@ -1341,14 +1248,14 @@
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
temp[0] = ':';
strcpy(temp + 1, val);
sdl.sdl_len = sizeof(sdl);
link_addr(temp, &sdl);
free(temp);
if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
memset(&mlme, 0, sizeof(mlme));
mlme.im_op = IEEE80211_MLME_DEAUTH;
mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
@@ -1370,14 +1277,14 @@
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ if_errx(1, "malloc failed");
temp[0] = ':';
strcpy(temp + 1, val);
sdl.sdl_len = sizeof(sdl);
link_addr(temp, &sdl);
free(temp);
if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
- errx(1, "malformed link-level address");
+ if_errx(1, "malformed link-level address");
set80211(ctx, IEEE80211_IOC_MESH_RTCMD, req,
IEEE80211_ADDR_LEN, LLADDR(&sdl));
}
@@ -1542,7 +1449,7 @@
flags |= IEEE80211_CHAN_VHT;
break;
default:
- errx(-1, "%s: Invalid mode attribute %c\n",
+ if_errx(-1, "%s: Invalid mode attribute %c\n",
val, *cp);
}
}
@@ -1626,7 +1533,7 @@
rssi = (int) (2*v);
if (rssi != 2*v)
- errx(-1, "invalid rssi (must be .5 dBm units)");
+ if_errx(-1, "invalid rssi (must be .5 dBm units)");
flags = getmodeflags(val);
getroam(ctx);
if (flags == 0) { /* NB: no flags => current channel */
@@ -1645,7 +1552,7 @@
rate = (int) (2*v);
if (rate != 2*v)
- errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
+ if_errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
return rate; /* NB: returns 2x the specified value */
}
@@ -1787,7 +1694,7 @@
int ampdu;
if (get80211val(ctx, IEEE80211_IOC_AMPDU, &ampdu) < 0)
- errx(-1, "cannot set AMPDU setting");
+ if_errx(-1, "cannot set AMPDU setting");
if (d < 0) {
d = -d;
ampdu &= ~d;
@@ -1802,7 +1709,7 @@
int stbc;
if (get80211val(ctx, IEEE80211_IOC_STBC, &stbc) < 0)
- errx(-1, "cannot set STBC setting");
+ if_errx(-1, "cannot set STBC setting");
if (d < 0) {
d = -d;
stbc &= ~d;
@@ -1817,7 +1724,7 @@
int ldpc;
if (get80211val(ctx, IEEE80211_IOC_LDPC, &ldpc) < 0)
- errx(-1, "cannot set LDPC setting");
+ if_errx(-1, "cannot set LDPC setting");
if (d < 0) {
d = -d;
ldpc &= ~d;
@@ -1835,7 +1742,7 @@
static void
set80211ampdulimit(if_ctx *ctx, const char *val, int dummy __unused)
{
- int v;
+ int v = 0;
switch (atoi(val)) {
case 8:
@@ -1855,7 +1762,7 @@
v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
break;
default:
- errx(-1, "invalid A-MPDU limit %s", val);
+ if_errx(-1, "invalid A-MPDU limit %s", val);
}
set80211(ctx, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
}
@@ -1894,7 +1801,7 @@
v = IEEE80211_HTCAP_MPDUDENSITY_16;
break;
default:
- errx(-1, "invalid A-MPDU density %s", val);
+ if_errx(-1, "invalid A-MPDU density %s", val);
}
set80211(ctx, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
}
@@ -1905,7 +1812,7 @@
int amsdu;
if (get80211val(ctx, IEEE80211_IOC_AMSDU, &amsdu) < 0)
- err(-1, "cannot get AMSDU setting");
+ if_err(-1, "cannot get AMSDU setting");
if (d < 0) {
d = -d;
amsdu &= ~d;
@@ -1979,7 +1886,7 @@
set80211vhtconf(if_ctx *ctx, const char *val __unused, int d)
{
if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
- errx(-1, "cannot set VHT setting");
+ if_errx(-1, "cannot set VHT setting");
if (d < 0) {
d = -d;
vhtconf &= ~d;
@@ -2040,7 +1947,7 @@
set80211meshmetric(if_ctx *ctx, const char *val, int dummy __unused)
{
char v[12];
-
+
memcpy(v, val, sizeof(v));
set80211(ctx, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
}
@@ -2049,7 +1956,7 @@
set80211meshpath(if_ctx *ctx, const char *val, int dummy __unused)
{
char v[12];
-
+
memcpy(v, val, sizeof(v));
set80211(ctx, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
}
@@ -2163,11 +2070,11 @@
LIST_FOREACH(nb, bands, next) {
b = nb->band;
if (verbose) {
- printf("%s:", __func__);
- printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
- printb(" bandFlags", nb->flags | b->flags,
+ ifieee80211_print_regdomain_addchans(__func__);
+ ifconfig_printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
+ ifconfig_printb(" bandFlags", nb->flags | b->flags,
IEEE80211_CHAN_BITS);
- putchar('\n');
+ ifconfig_print_newline();
}
prev = NULL;
@@ -2189,36 +2096,31 @@
if ((chanFlags & IEEE80211_CHAN_VHT20) &&
(flags & IEEE80211_CHAN_VHT20) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT20 channel\n", freq);
+ ifieee80211_print_verbose_vht20_skip(freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT40) &&
(flags & IEEE80211_CHAN_VHT40) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT40 channel\n", freq);
+ ifieee80211_print_verbose_vht40_skip(freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT80) &&
(flags & IEEE80211_CHAN_VHT80) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT80 channel\n", freq);
+ ifieee80211_print_verbose_vht80_skip(freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT160) &&
(flags & IEEE80211_CHAN_VHT160) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT160 channel\n", freq);
+ ifieee80211_print_verbose_vht160_skip(freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT80P80) &&
(flags & IEEE80211_CHAN_VHT80P80) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT80+80 channel\n", freq);
+ ifieee80211_print_verbose_vht80p80_skip(freq);
continue;
}
flags &= ~IEEE80211_CHAN_VHT;
@@ -2236,15 +2138,13 @@
if ((chanFlags & IEEE80211_CHAN_HT20) &&
(flags & IEEE80211_CHAN_HT20) == 0) {
if (verbose)
- printf("%u: skip, not an "
- "HT20 channel\n", freq);
+ ifieee80211_print_verbose_ht20_skip(freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_HT40) &&
(flags & IEEE80211_CHAN_HT40) == 0) {
if (verbose)
- printf("%u: skip, not an "
- "HT40 channel\n", freq);
+ ifieee80211_print_verbose_ht40_skip(freq);
continue;
}
/* NB: HT attribute comes from caller */
@@ -2256,42 +2156,38 @@
*/
if (!checkchan(avail, freq, flags)) {
if (verbose) {
- printf("%u: skip, ", freq);
- printb("flags", flags,
+ ifieee80211_print_verbose_freq_skip(freq);
+ ifconfig_printb("flags", flags,
IEEE80211_CHAN_BITS);
- printf(" not available\n");
+ ifieee80211_print_verbose_checkchan_notavail();
}
continue;
}
if ((flags & REQ_ECM) && !reg->ecm) {
if (verbose)
- printf("%u: skip, ECM channel\n", freq);
+ ifieee80211_print_verbose_ecm_chan(freq);
continue;
}
if ((flags & REQ_INDOOR) && reg->location == 'O') {
if (verbose)
- printf("%u: skip, indoor channel\n",
- freq);
+ ifieee80211_print_verbose_indoor_chan_skip(freq);
continue;
}
if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
if (verbose)
- printf("%u: skip, outdoor channel\n",
- freq);
+ ifieee80211_print_verbose_outdoor_chan_skip(freq);
continue;
}
if ((flags & IEEE80211_CHAN_HT40) &&
prev != NULL && (freq - prev->ic_freq) < channelSep) {
if (verbose)
- printf("%u: skip, only %u channel "
- "separation, need %d\n", freq,
+ ifieee80211_print_verbose_chansep_need(freq,
freq - prev->ic_freq, channelSep);
continue;
}
if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
if (verbose)
- printf("%u: skip, channel table full\n",
- freq);
+ ifieee80211_print_verbose_chan_table_full(freq);
break;
}
c = &ci->ic_chans[ci->ic_nchans++];
@@ -2303,10 +2199,9 @@
else
c->ic_maxregpower = nb->maxPower;
if (verbose) {
- printf("[%3d] add freq %u ",
- ci->ic_nchans-1, c->ic_freq);
- printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
- printf(" power %u\n", c->ic_maxregpower);
+ ifieee80211_print_verbose_add_freq(ci, c);
+ ifconfig_printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
+ ifieee80211_print_verbose_maxregpower(c);
}
/* NB: kernel fills in other fields */
prev = c;
@@ -2337,13 +2232,13 @@
if (reg->regdomain == 0) {
cc = lib80211_country_findbycc(rdp, reg->country);
if (cc == NULL)
- errx(1, "internal error, country %d not found",
+ if_errx(1, "internal error, country %d not found",
reg->country);
rd = cc->rd;
} else
rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
if (rd == NULL)
- errx(1, "internal error, regdomain %d not found",
+ if_errx(1, "internal error, regdomain %d not found",
reg->regdomain);
if (rd->sku != SKU_DEBUG) {
/*
@@ -2462,19 +2357,18 @@
int i;
i = 0;
- printf("\nCountry codes:\n");
+ ifieee80211_print_country_codes();
LIST_FOREACH(cp, &rdp->countries, next) {
- printf("%2s %-15.15s%s", cp->isoname,
- cp->name, ((i+1)%4) == 0 ? "\n" : " ");
+ ifieee80211_print_country_code(cp, i);
i++;
}
i = 0;
- printf("\nRegulatory domains:\n");
+ ifieee80211_print_reg_domains();
LIST_FOREACH(dp, &rdp->domains, next) {
- printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
+ ifieee80211_print_reg_domain(dp, i);
i++;
}
- printf("\n");
+ ifconfig_print_newline();
}
static void
@@ -2485,7 +2379,7 @@
cc = lib80211_country_findbycc(rdp, rd->cc->code);
if (cc == NULL)
- errx(1, "internal error, ISO country code %d not "
+ if_errx(1, "internal error, ISO country code %d not "
"defined for regdomain %s", rd->cc->code, rd->name);
regdomain.country = cc->code;
regdomain.isocc[0] = cc->isoname[0];
@@ -2506,7 +2400,7 @@
if (eptr != val)
rd = lib80211_regdomain_findbysku(rdp, sku);
if (eptr == val || rd == NULL)
- errx(1, "unknown regdomain %s", val);
+ if_errx(1, "unknown regdomain %s", val);
}
getregdomain(ctx);
regdomain.regdomain = rd->sku;
@@ -2534,7 +2428,7 @@
if (eptr != val)
cc = lib80211_country_findbycc(rdp, code);
if (eptr == val || cc == NULL)
- errx(1, "unknown ISO country code %s", val);
+ if_errx(1, "unknown ISO country code %s", val);
}
getregdomain(ctx);
regdomain.regdomain = cc->rd->sku;
@@ -2560,47 +2454,7 @@
callback_register(setregdomain_cb, &regdomain);
}
-static void
-LINE_INIT(char c)
-{
- spacer = c;
- if (c == '\t')
- col = 8;
- else
- col = 1;
-}
-
-static void
-LINE_BREAK(void)
-{
- if (spacer != '\t') {
- printf("\n");
- spacer = '\t';
- }
- col = 8; /* 8-col tab */
-}
-
-static void
-LINE_CHECK(const char *fmt, ...)
-{
- char buf[80];
- va_list ap;
- int n;
-
- va_start(ap, fmt);
- n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
- va_end(ap);
- col += 1+n;
- if (col > MAXCOL) {
- LINE_BREAK();
- col += n;
- }
- buf[0] = spacer;
- printf("%s", buf);
- spacer = ' ';
-}
-
-static int
+int
getmaxrate(const uint8_t rates[15], uint8_t nrates)
{
int i, maxrate = -1;
@@ -2613,7 +2467,7 @@
return maxrate / 2;
}
-static const char *
+const char *
getcaps(int capinfo)
{
static char capstring[32];
@@ -2645,7 +2499,7 @@
return capstring;
}
-static const char *
+const char *
getflags(int flags)
{
static char flagstring[32];
@@ -2699,512 +2553,7 @@
return flagstring;
}
-static void
-printie(if_ctx *ctx, const char* tag, const uint8_t *ie, size_t ielen, unsigned int maxlen)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- maxlen -= strlen(tag)+2;
- if (2*ielen > maxlen)
- maxlen--;
- printf("<");
- for (; ielen > 0; ie++, ielen--) {
- if (maxlen-- <= 0)
- break;
- printf("%02x", *ie);
- }
- if (ielen != 0)
- printf("-");
- printf(">");
- }
-}
-
-#define LE_READ_2(p) \
- ((u_int16_t) \
- ((((const u_int8_t *)(p))[0] ) | \
- (((const u_int8_t *)(p))[1] << 8)))
-#define LE_READ_4(p) \
- ((u_int32_t) \
- ((((const u_int8_t *)(p))[0] ) | \
- (((const u_int8_t *)(p))[1] << 8) | \
- (((const u_int8_t *)(p))[2] << 16) | \
- (((const u_int8_t *)(p))[3] << 24)))
-
-/*
- * NB: The decoding routines assume a properly formatted ie
- * which should be safe as the kernel only retains them
- * if they parse ok.
- */
-
-static void
-printwmeparam(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- static const char *acnames[] = { "BE", "BK", "VO", "VI" };
- const struct ieee80211_wme_param *wme =
- (const struct ieee80211_wme_param *) ie;
- int i;
-
- printf("%s", tag);
- if (!ctx->args->verbose)
- return;
- printf("<qosinfo 0x%x", wme->param_qosInfo);
- ie += offsetof(struct ieee80211_wme_param, params_acParams);
- for (i = 0; i < WME_NUM_AC; i++) {
- const struct ieee80211_wme_acparams *ac =
- &wme->params_acParams[i];
-
- printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]", acnames[i],
- _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_ACM) ?
- "acm " : "",
- _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_AIFSN),
- _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
- WME_PARAM_LOGCWMIN),
- _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
- WME_PARAM_LOGCWMAX),
- LE_READ_2(&ac->acp_txop));
- }
- printf(">");
-}
-
-static void
-printwmeinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_wme_info *wme =
- (const struct ieee80211_wme_info *) ie;
- printf("<version 0x%x info 0x%x>",
- wme->wme_version, wme->wme_info);
- }
-}
-
-static void
-printhecap(if_ctx *ctx, const char *tag, const uint8_t *ie)
-{
- const struct ieee80211_he_cap_elem *hecap;
- const struct ieee80211_he_mcs_nss_supp *mcsnss;
- unsigned int i;
- uint8_t chw;
-
- printf("%s", tag);
- if (!ctx->args->verbose)
- return;
-
- /* Check that the right size. */
- if (ie[1] < 1 + sizeof(*hecap) + 4) {
- printf("<err: he_cap inval. length %#0x>", ie[1]);
- return;
- }
- /* Skip Element ID, Length, EID Extension. */
- hecap = (const struct ieee80211_he_cap_elem *)(ie + 3);
-
- /* XXX-BZ we need to somehow decode each field? */
- printf("<mac_cap");
- for (i = 0; i < nitems(hecap->mac_cap_info); i++)
- printf(" %#04x", hecap->mac_cap_info[i]);
- printf(" phy_cap");
- for (i = 0; i < nitems(hecap->phy_cap_info); i++)
- printf(" %#04x", hecap->phy_cap_info[i]);
-
- chw = hecap->phy_cap_info[0];
- ie = (const uint8_t *)(const void *)(hecap + 1);
- mcsnss = (const struct ieee80211_he_mcs_nss_supp *)ie;
- /* Cannot use <= as < is a delimiter. */
- printf(" rx/tx_he_mcs map: loweq80 %#06x/%#06x",
- mcsnss->rx_mcs_80, mcsnss->tx_mcs_80);
- ie += 2;
- if ((chw & (1<<2)) != 0) {
- printf(" 160 %#06x/%#06x",
- mcsnss->rx_mcs_160, mcsnss->tx_mcs_160);
- ie += 2;
- }
- if ((chw & (1<<3)) != 0) {
- printf(" 80+80 %#06x/%#06x",
- mcsnss->rx_mcs_80p80, mcsnss->tx_mcs_80p80);
- ie += 2;
- }
- /* TODO: ppet = (struct ... *)ie; */
-
- printf(">");
-}
-
-static void
-printheoper(if_ctx *ctx, const char *tag, const uint8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_he_operation *heoper;
- uint32_t params;
-
- /* Check that the right size. */
- if (ie[1] < 1 + sizeof(*heoper)) {
- printf("<err: he_oper inval. length %#0x>", ie[1]);
- return;
- }
- /* Skip Element ID, Length, EID Extension. */
- heoper = (const struct ieee80211_he_operation *)(ie + 3);
-
- /* XXX-BZ we need to somehow decode each field? */
- params = heoper->he_oper_params & 0x00ffffff;
- printf("<params %#08x", params);
- printf(" bss_col %#04x", (heoper->he_oper_params & 0xff000000) >> 24);
- printf(" mcs_nss %#06x", heoper->he_mcs_nss_set);
- if ((params & (1 << 14)) != 0) {
- printf(" vht_op 0-3");
- }
- if ((params & (1 << 15)) != 0) {
- printf(" max_coh_bssid 0-1");
- }
- if ((params & (1 << 17)) != 0) {
- printf(" 6ghz_op 0-5");
- }
- printf(">");
- }
-}
-
-static void
-printmuedcaparamset(if_ctx *ctx, const char *tag, const uint8_t *ie)
-{
- static const char *acnames[] = { "BE", "BK", "VO", "VI" };
- const struct ieee80211_mu_edca_param_set *mu_edca;
- int i;
-
- printf("%s", tag);
- if (!ctx->args->verbose)
- return;
-
- /* Check that the right size. */
- if (ie[1] != 1 + sizeof(*mu_edca)) {
- printf("<err: mu_edca inval. length %#04x>", ie[1]);
- return;
- }
- /* Skip Element ID, Length, EID Extension. */
- mu_edca = (const struct ieee80211_mu_edca_param_set *)(ie + 3);
-
- printf("<qosinfo 0x%x", mu_edca->mu_qos_info);
- ie++;
- for (i = 0; i < WME_NUM_AC; i++) {
- const struct ieee80211_he_mu_edca_param_ac_rec *ac =
- &mu_edca->param_ac_recs[i];
-
- printf(" %s[aifsn %u ecwmin %u ecwmax %u timer %u]", acnames[i],
- ac->aifsn,
- _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMIN),
- _IEEE80211_MASKSHIFT(ac->ecw_min_max, WME_PARAM_LOGCWMAX),
- ac->mu_edca_timer);
- }
- printf(">");
-}
-
-static void
-printsupopclass(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- uint8_t len, i;
-
- printf("%s", tag);
- if (!ctx->args->verbose)
- return;
-
- /* Check that the right size. */
- len = ie[1];
- if (len < 2) {
- printf("<err: sup_op_class inval. length %#04x>", ie[1]);
- return;
- }
-
- ie += 2;
- i = 0;
- printf("<cur op class %u", *ie);
- i++;
- if (i < len && *(ie + i) != 130)
- printf(" op classes");
- while (i < len && *(ie + i) != 130) {
- printf(" %u", *(ie + i));
- i++;
- }
- if (i > 1 && i < len && *(ie + i) != 130) {
- printf(" parsing error at %#0x>", i);
- return;
- }
- /* Skip OneHundredAndThirty Delimiter. */
- i++;
- if (i < len && *(ie + i) != 0)
- printf(" ext seq");
- while (i < len && *(ie + i) != 0) {
- printf(" %u", *(ie + i));
- i++;
- }
- if (i > 1 && i < len && *(ie + i) != 0) {
- printf(" parsing error at %#0x>", i);
- return;
- }
- /* Skip Zero Delimiter. */
- i++;
- if ((i + 1) < len)
- printf(" duple seq");
- while ((i + 1) < len) {
- printf(" %u/%u", *(ie + i), *(ie + i + 1));
- i += 2;
- }
- printf(">");
-}
-
-static void
-printvhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_vht_cap *vhtcap;
- uint32_t vhtcap_info;
-
- /* Check that the right size. */
- if (ie[1] != sizeof(*vhtcap)) {
- printf("<err: vht_cap inval. length>");
- return;
- }
- /* Skip Element ID and Length. */
- vhtcap = (const struct ieee80211_vht_cap *)(ie + 2);
-
- vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
- printf("<cap 0x%08x", vhtcap_info);
- printf(" rx_mcs_map 0x%x",
- LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
- printf(" rx_highest %d",
- LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
- printf(" tx_mcs_map 0x%x",
- LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
- printf(" tx_highest %d",
- LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
-
- printf(">");
- }
-}
-
-static void
-printvhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_vht_operation *vhtinfo;
-
- /* Check that the right size. */
- if (ie[1] != sizeof(*vhtinfo)) {
- printf("<err: vht_operation inval. length>");
- return;
- }
- /* Skip Element ID and Length. */
- vhtinfo = (const struct ieee80211_vht_operation *)(ie + 2);
-
- printf("<chw %d freq0_idx %d freq1_idx %d basic_mcs_set 0x%04x>",
- vhtinfo->chan_width,
- vhtinfo->center_freq_seq0_idx,
- vhtinfo->center_freq_seq1_idx,
- LE_READ_2(&vhtinfo->basic_mcs_set));
- }
-}
-
-static void
-printvhtpwrenv(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
-{
- printf("%s", tag);
- static const char *txpwrmap[] = {
- "20",
- "40",
- "80",
- "160",
- };
- if (ctx->args->verbose) {
- const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
- (const struct ieee80211_ie_vht_txpwrenv *) ie;
- size_t i, n;
- const char *sep = "";
-
- /* Get count; trim at ielen */
- n = (vhtpwr->tx_info &
- IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
- /* Trim at ielen */
- if (n + 3 > ielen)
- n = ielen - 3;
- printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
- for (i = 0; i < n; i++) {
- printf("%s%s:%.2f", sep, txpwrmap[i],
- ((float) ((int8_t) ie[i+3])) / 2.0);
- sep = " ";
- }
-
- printf("]>");
- }
-}
-
-static void
-printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_ie_htcap *htcap =
- (const struct ieee80211_ie_htcap *) ie;
- const char *sep;
- int i, j;
-
- printf("<cap 0x%x param 0x%x",
- LE_READ_2(&htcap->hc_cap), htcap->hc_param);
- printf(" mcsset[");
- sep = "";
- for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
- if (isset(htcap->hc_mcsset, i)) {
- for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
- if (isclr(htcap->hc_mcsset, j))
- break;
- j--;
- if (i == j)
- printf("%s%u", sep, i);
- else
- printf("%s%u-%u", sep, i, j);
- i += j-i;
- sep = ",";
- }
- printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
- LE_READ_2(&htcap->hc_extcap),
- LE_READ_4(&htcap->hc_txbf),
- htcap->hc_antenna);
- }
-}
-
-static void
-printhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_ie_htinfo *htinfo =
- (const struct ieee80211_ie_htinfo *) ie;
- const char *sep;
- int i, j;
-
- printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
- htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
- LE_READ_2(&htinfo->hi_byte45));
- printf(" basicmcs[");
- sep = "";
- for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
- if (isset(htinfo->hi_basicmcsset, i)) {
- for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
- if (isclr(htinfo->hi_basicmcsset, j))
- break;
- j--;
- if (i == j)
- printf("%s%u", sep, i);
- else
- printf("%s%u-%u", sep, i, j);
- i += j-i;
- sep = ",";
- }
- printf("]>");
- }
-}
-
-static void
-printathie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
-
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_ath_ie *ath =
- (const struct ieee80211_ath_ie *)ie;
-
- printf("<");
- if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
- printf("DTURBO,");
- if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
- printf("COMP,");
- if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
- printf("FF,");
- if (ath->ath_capability & ATHEROS_CAP_XR)
- printf("XR,");
- if (ath->ath_capability & ATHEROS_CAP_AR)
- printf("AR,");
- if (ath->ath_capability & ATHEROS_CAP_BURST)
- printf("BURST,");
- if (ath->ath_capability & ATHEROS_CAP_WME)
- printf("WME,");
- if (ath->ath_capability & ATHEROS_CAP_BOOST)
- printf("BOOST,");
- printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
- }
-}
-
-
-static void
-printmeshconf(if_ctx *ctx, const char *tag, const uint8_t *ie)
-{
-
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_meshconf_ie *mconf =
- (const struct ieee80211_meshconf_ie *)ie;
- printf("<PATH:");
- if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
- printf("HWMP");
- else
- printf("UNKNOWN");
- printf(" LINK:");
- if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
- printf("AIRTIME");
- else
- printf("UNKNOWN");
- printf(" CONGESTION:");
- if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
- printf("DISABLED");
- else
- printf("UNKNOWN");
- printf(" SYNC:");
- if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
- printf("NEIGHOFF");
- else
- printf("UNKNOWN");
- printf(" AUTH:");
- if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
- printf("DISABLED");
- else
- printf("UNKNOWN");
- printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
- mconf->conf_cap);
- }
-}
-
-static void
-printbssload(if_ctx *ctx, const char *tag, const uint8_t *ie)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_bss_load_ie *bssload =
- (const struct ieee80211_bss_load_ie *) ie;
- printf("<sta count %d, chan load %d, aac %d>",
- LE_READ_2(&bssload->sta_count),
- bssload->chan_load,
- bssload->aac);
- }
-}
-
-static void
-printapchanrep(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const struct ieee80211_ap_chan_report_ie *ap =
- (const struct ieee80211_ap_chan_report_ie *) ie;
- const char *sep = "";
-
- printf("<class %u, chan:[", ap->i_class);
-
- for (size_t i = 3; i < ielen; i++) {
- printf("%s%u", sep, ie[i]);
- sep = ",";
- }
- printf("]>");
- }
-}
-
-static const char *
+const char *
wpa_cipher(const u_int8_t *sel)
{
#define WPA_SEL(x) (((x)<<24)|WPA_OUI)
@@ -3226,7 +2575,7 @@
#undef WPA_SEL
}
-static const char *
+const char *
wpa_keymgmt(const u_int8_t *sel)
{
#define WPA_SEL(x) (((x)<<24)|WPA_OUI)
@@ -3244,51 +2593,7 @@
#undef WPA_SEL
}
-static void
-printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- u_int8_t len = ie[1];
-
- printf("%s", tag);
- if (ctx->args->verbose) {
- const char *sep;
- int n;
-
- ie += 6, len -= 4; /* NB: len is payload only */
-
- printf("<v%u", LE_READ_2(ie));
- ie += 2, len -= 2;
-
- printf(" mc:%s", wpa_cipher(ie));
- ie += 4, len -= 4;
-
- /* unicast ciphers */
- n = LE_READ_2(ie);
- ie += 2, len -= 2;
- sep = " uc:";
- for (; n > 0; n--) {
- printf("%s%s", sep, wpa_cipher(ie));
- ie += 4, len -= 4;
- sep = "+";
- }
-
- /* key management algorithms */
- n = LE_READ_2(ie);
- ie += 2, len -= 2;
- sep = " km:";
- for (; n > 0; n--) {
- printf("%s%s", sep, wpa_keymgmt(ie));
- ie += 4, len -= 4;
- sep = "+";
- }
-
- if (len > 2) /* optional capabilities */
- printf(", caps 0x%x", LE_READ_2(ie));
- printf(">");
- }
-}
-
-static const char *
+const char *
rsn_cipher(const u_int8_t *sel)
{
#define RSN_SEL(x) (((x)<<24)|RSN_OUI)
@@ -3318,7 +2623,7 @@
#undef WPA_SEL
}
-static const char *
+const char *
rsn_keymgmt(const u_int8_t *sel)
{
#define RSN_SEL(x) (((x)<<24)|RSN_OUI)
@@ -3340,334 +2645,13 @@
#undef RSN_SEL
}
-static void
-printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
-{
- printf("%s", tag);
- if (ctx->args->verbose) {
- const char *sep;
- int n;
-
- ie += 2, ielen -= 2;
-
- printf("<v%u", LE_READ_2(ie));
- ie += 2, ielen -= 2;
-
- printf(" mc:%s", rsn_cipher(ie));
- ie += 4, ielen -= 4;
-
- /* unicast ciphers */
- n = LE_READ_2(ie);
- ie += 2, ielen -= 2;
- sep = " uc:";
- for (; n > 0; n--) {
- printf("%s%s", sep, rsn_cipher(ie));
- ie += 4, ielen -= 4;
- sep = "+";
- }
-
- /* key management algorithms */
- n = LE_READ_2(ie);
- ie += 2, ielen -= 2;
- sep = " km:";
- for (; n > 0; n--) {
- printf("%s%s", sep, rsn_keymgmt(ie));
- ie += 4, ielen -= 4;
- sep = "+";
- }
-
- if (ielen > 2) /* optional capabilities */
- printf(", caps 0x%x", LE_READ_2(ie));
- /* XXXPMKID */
- printf(">");
- }
-}
-
-static void
-printrsnxe(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
-{
- size_t n;
-
- printf("%s", tag);
- if (!ctx->args->verbose)
- return;
-
- ie += 2, ielen -= 2;
-
- n = (*ie & 0x0f);
- printf("<%zu", n + 1);
-
- /* We do not yet know about more than n=1 (0). */
- if (n != 0)
- goto end;
-
- if (*ie & 0x10)
- printf(" PTWTOPS");
- if (*ie & 0x20)
- printf(" SAE h-t-e");
-
-end:
- printf(">");
-}
-
-#define BE_READ_2(p) \
- ((u_int16_t) \
- ((((const u_int8_t *)(p))[1] ) | \
- (((const u_int8_t *)(p))[0] << 8)))
-
-static void
-printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
-{
- u_int8_t len = ie[1];
-
- printf("%s", tag);
- if (ctx->args->verbose) {
- static const char *dev_pass_id[] = {
- "D", /* Default (PIN) */
- "U", /* User-specified */
- "M", /* Machine-specified */
- "K", /* Rekey */
- "P", /* PushButton */
- "R" /* Registrar-specified */
- };
- int n;
- int f;
-
- ie +=6, len -= 4; /* NB: len is payload only */
-
- /* WPS IE in Beacon and Probe Resp frames have different fields */
- printf("<");
- while (len) {
- uint16_t tlv_type = BE_READ_2(ie);
- uint16_t tlv_len = BE_READ_2(ie + 2);
- uint16_t cfg_mthd;
-
- /* some devices broadcast invalid WPS frames */
- if (tlv_len > len) {
- printf("bad frame length tlv_type=0x%02x "
- "tlv_len=%d len=%d", tlv_type, tlv_len,
- len);
- break;
- }
-
- ie += 4, len -= 4;
-
- switch (tlv_type) {
- case IEEE80211_WPS_ATTR_VERSION:
- printf("v:%d.%d", *ie >> 4, *ie & 0xf);
- break;
- case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
- printf(" ap_setup:%s", *ie ? "locked" :
- "unlocked");
- break;
- case IEEE80211_WPS_ATTR_CONFIG_METHODS:
- case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS:
- if (tlv_type == IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
- printf(" sel_reg_cfg_mthd:");
- else
- printf(" cfg_mthd:" );
- cfg_mthd = BE_READ_2(ie);
- f = 0;
- for (n = 15; n >= 0; n--) {
- if (f) {
- printf(",");
- f = 0;
- }
- switch (cfg_mthd & (1 << n)) {
- case 0:
- break;
- case IEEE80211_WPS_CONFIG_USBA:
- printf("usba");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_ETHERNET:
- printf("ethernet");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_LABEL:
- printf("label");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_DISPLAY:
- if (!(cfg_mthd &
- (IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
- IEEE80211_WPS_CONFIG_PHY_DISPLAY)))
- {
- printf("display");
- f++;
- }
- break;
- case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
- printf("ext_nfc_tokenk");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
- printf("int_nfc_token");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
- printf("nfc_interface");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_PUSHBUTTON:
- if (!(cfg_mthd &
- (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON |
- IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) {
- printf("push_button");
- f++;
- }
- break;
- case IEEE80211_WPS_CONFIG_KEYPAD:
- printf("keypad");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
- printf("virtual_push_button");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
- printf("physical_push_button");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_P2PS:
- printf("p2ps");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
- printf("virtual_display");
- f++;
- break;
- case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
- printf("physical_display");
- f++;
- break;
- default:
- printf("unknown_wps_config<%04x>",
- cfg_mthd & (1 << n));
- f++;
- break;
- }
- }
- break;
- case IEEE80211_WPS_ATTR_DEV_NAME:
- printf(" device_name:<%.*s>", tlv_len, ie);
- break;
- case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID:
- n = LE_READ_2(ie);
- if (n < (int)nitems(dev_pass_id))
- printf(" dpi:%s", dev_pass_id[n]);
- break;
- case IEEE80211_WPS_ATTR_MANUFACTURER:
- printf(" manufacturer:<%.*s>", tlv_len, ie);
- break;
- case IEEE80211_WPS_ATTR_MODEL_NAME:
- printf(" model_name:<%.*s>", tlv_len, ie);
- break;
- case IEEE80211_WPS_ATTR_MODEL_NUMBER:
- printf(" model_number:<%.*s>", tlv_len, ie);
- break;
- case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
- printf(" prim_dev:");
- for (n = 0; n < tlv_len; n++)
- printf("%02x", ie[n]);
- break;
- case IEEE80211_WPS_ATTR_RF_BANDS:
- printf(" rf:");
- f = 0;
- for (n = 7; n >= 0; n--) {
- if (f) {
- printf(",");
- f = 0;
- }
- switch (*ie & (1 << n)) {
- case 0:
- break;
- case IEEE80211_WPS_RF_BAND_24GHZ:
- printf("2.4Ghz");
- f++;
- break;
- case IEEE80211_WPS_RF_BAND_50GHZ:
- printf("5Ghz");
- f++;
- break;
- case IEEE80211_WPS_RF_BAND_600GHZ:
- printf("60Ghz");
- f++;
- break;
- default:
- printf("unknown<%02x>",
- *ie & (1 << n));
- f++;
- break;
- }
- }
- break;
- case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
- printf(" resp_type:0x%02x", *ie);
- break;
- case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
- printf(" sel:%s", *ie ? "T" : "F");
- break;
- case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
- printf(" serial_number:<%.*s>", tlv_len, ie);
- break;
- case IEEE80211_WPS_ATTR_UUID_E:
- printf(" uuid-e:");
- for (n = 0; n < (tlv_len - 1); n++)
- printf("%02x-", ie[n]);
- printf("%02x", ie[n]);
- break;
- case IEEE80211_WPS_ATTR_VENDOR_EXT:
- printf(" vendor:");
- for (n = 0; n < tlv_len; n++)
- printf("%02x", ie[n]);
- break;
- case IEEE80211_WPS_ATTR_WPS_STATE:
- switch (*ie) {
- case IEEE80211_WPS_STATE_NOT_CONFIGURED:
- printf(" state:N");
- break;
- case IEEE80211_WPS_STATE_CONFIGURED:
- printf(" state:C");
- break;
- default:
- printf(" state:B<%02x>", *ie);
- break;
- }
- break;
- default:
- printf(" unknown_wps_attr:0x%x", tlv_type);
- break;
- }
- ie += tlv_len, len -= tlv_len;
- }
- printf(">");
- }
-}
-
-static void
-printtdmaie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
-{
- printf("%s", tag);
- if (ctx->args->verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
- const struct ieee80211_tdma_param *tdma =
- (const struct ieee80211_tdma_param *) ie;
-
- /* XXX tstamp */
- printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
- tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
- LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
- tdma->tdma_inuse[0]);
- }
-}
-
/*
* Copy the ssid string contents into buf, truncating to fit. If the
* ssid is entirely printable then just copy intact. Otherwise convert
* to hexadecimal. If the result is truncated then replace the last
* three characters with "...".
*/
-static int
+int
copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
{
const u_int8_t *p;
@@ -3703,84 +2687,39 @@
return maxlen;
}
-static void
-printssid(const char *tag, const u_int8_t *ie, int maxlen)
-{
- char ssid[2*IEEE80211_NWID_LEN+1];
-
- printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
-}
-
-static void
-printrates(const char *tag, const u_int8_t *ie, size_t ielen)
-{
- const char *sep;
-
- printf("%s", tag);
- sep = "<";
- for (size_t i = 2; i < ielen; i++) {
- printf("%s%s%d", sep,
- ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
- ie[i] & IEEE80211_RATE_VAL);
- sep = ",";
- }
- printf(">");
-}
-
-static void
-printcountry(const char *tag, const u_int8_t *ie)
-{
- const struct ieee80211_country_ie *cie =
- (const struct ieee80211_country_ie *) ie;
- int i, nbands, schan, nchan;
-
- printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
- nbands = (cie->len - 3) / sizeof(cie->band[0]);
- for (i = 0; i < nbands; i++) {
- schan = cie->band[i].schan;
- nchan = cie->band[i].nchan;
- if (nchan != 1)
- printf(" %u-%u,%u", schan, schan + nchan-1,
- cie->band[i].maxtxpwr);
- else
- printf(" %u,%u", schan, cie->band[i].maxtxpwr);
- }
- printf(">");
-}
-
-static __inline int
+__inline int
iswpaoui(const u_int8_t *frm)
{
return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
}
-static __inline int
+__inline int
iswmeinfo(const u_int8_t *frm)
{
return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
frm[6] == WME_INFO_OUI_SUBTYPE;
}
-static __inline int
+__inline int
iswmeparam(const u_int8_t *frm)
{
return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
frm[6] == WME_PARAM_OUI_SUBTYPE;
}
-static __inline int
+__inline int
isatherosoui(const u_int8_t *frm)
{
return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
}
-static __inline int
+__inline int
istdmaoui(const uint8_t *frm)
{
return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
}
-static __inline int
+__inline int
iswpsoui(const uint8_t *frm)
{
return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
@@ -3801,7 +2740,7 @@
return (const char *) iename_buf;
}
-static const char *
+const char *
iename(uint8_t elemid, const u_int8_t *vp)
{
static char iename_buf[64];
@@ -3846,191 +2785,21 @@
return (const char *) iename_buf;
}
-static void
-printexties(if_ctx *ctx, const u_int8_t *vp, unsigned int maxcols)
-{
- const int verbose = ctx->args->verbose;
-
- if (vp[1] < 1)
- return;
-
- switch (vp[2]) {
- case IEEE80211_ELEMID_EXT_HE_CAPA:
- printhecap(ctx, " HECAP", vp);
- break;
- case IEEE80211_ELEMID_EXT_HE_OPER:
- printheoper(ctx, " HEOPER", vp);
- break;
- case IEEE80211_ELEMID_EXT_MU_EDCA_PARAM_SET:
- printmuedcaparamset(ctx, " MU_EDCA_PARAM_SET", vp);
- break;
- default:
- if (verbose)
- printie(ctx, iename(vp[0], vp), vp, 2+vp[1], maxcols);
- break;
- }
-}
-
-static void
-printies(if_ctx *ctx, const u_int8_t *vp, int ielen, unsigned int maxcols)
-{
- const int verbose = ctx->args->verbose;
-
- while (ielen > 0) {
- switch (vp[0]) {
- case IEEE80211_ELEMID_SSID:
- if (verbose)
- printssid(" SSID", vp, maxcols);
- break;
- case IEEE80211_ELEMID_RATES:
- case IEEE80211_ELEMID_XRATES:
- if (verbose)
- printrates(vp[0] == IEEE80211_ELEMID_RATES ?
- " RATES" : " XRATES", vp, 2+vp[1]);
- break;
- case IEEE80211_ELEMID_DSPARMS:
- if (verbose)
- printf(" DSPARMS<%u>", vp[2]);
- break;
- case IEEE80211_ELEMID_COUNTRY:
- if (verbose)
- printcountry(" COUNTRY", vp);
- break;
- case IEEE80211_ELEMID_ERP:
- if (verbose)
- printf(" ERP<0x%x>", vp[2]);
- break;
- case IEEE80211_ELEMID_VENDOR:
- if (iswpaoui(vp))
- printwpaie(ctx, " WPA", vp);
- else if (iswmeinfo(vp))
- printwmeinfo(ctx, " WME", vp);
- else if (iswmeparam(vp))
- printwmeparam(ctx, " WME", vp);
- else if (isatherosoui(vp))
- printathie(ctx, " ATH", vp);
- else if (iswpsoui(vp))
- printwpsie(ctx, " WPS", vp);
- else if (istdmaoui(vp))
- printtdmaie(ctx, " TDMA", vp, 2+vp[1]);
- else if (verbose)
- printie(ctx, " VEN", vp, 2+vp[1], maxcols);
- break;
- case IEEE80211_ELEMID_RSN:
- printrsnie(ctx, " RSN", vp, 2+vp[1]);
- break;
- case IEEE80211_ELEMID_HTCAP:
- printhtcap(ctx, " HTCAP", vp);
- break;
- case IEEE80211_ELEMID_SUP_OP_CLASS:
- printsupopclass(ctx, " SUP_OP_CLASS", vp);
- break;
- case IEEE80211_ELEMID_HTINFO:
- if (verbose)
- printhtinfo(ctx, " HTINFO", vp);
- break;
- case IEEE80211_ELEMID_MESHID:
- if (verbose)
- printssid(" MESHID", vp, maxcols);
- break;
- case IEEE80211_ELEMID_MESHCONF:
- printmeshconf(ctx, " MESHCONF", vp);
- break;
- case IEEE80211_ELEMID_VHT_CAP:
- printvhtcap(ctx, " VHTCAP", vp);
- break;
- case IEEE80211_ELEMID_VHT_OPMODE:
- printvhtinfo(ctx, " VHTOPMODE", vp);
- break;
- case IEEE80211_ELEMID_VHT_PWR_ENV:
- printvhtpwrenv(ctx, " VHTPWRENV", vp, 2+vp[1]);
- break;
- case IEEE80211_ELEMID_BSSLOAD:
- printbssload(ctx, " BSSLOAD", vp);
- break;
- case IEEE80211_ELEMID_APCHANREP:
- printapchanrep(ctx, " APCHANREP", vp, 2+vp[1]);
- break;
- case IEEE80211_ELEMID_RSN_EXT:
- printrsnxe(ctx, " RSNXE", vp, 2+vp[1]);
- break;
- case IEEE80211_ELEMID_EXTFIELD:
- printexties(ctx, vp, maxcols);
- break;
- default:
- if (verbose)
- printie(ctx, iename(vp[0], vp), vp, 2+vp[1], maxcols);
- break;
- }
- ielen -= 2+vp[1];
- vp += 2+vp[1];
- }
-}
-
-static void
-printmimo(const struct ieee80211_mimo_info *mi)
-{
- int i;
- int r = 0;
-
- for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
- if (mi->ch[i].rssi[0] != 0) {
- r = 1;
- break;
- }
- }
-
- /* NB: don't muddy display unless there's something to show */
- if (r == 0)
- return;
-
- /* XXX TODO: ignore EVM; secondary channels for now */
- printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
- mi->ch[0].rssi[0] / 2.0,
- mi->ch[1].rssi[0] / 2.0,
- mi->ch[2].rssi[0] / 2.0,
- mi->ch[3].rssi[0] / 2.0,
- mi->ch[0].noise[0],
- mi->ch[1].noise[0],
- mi->ch[2].noise[0],
- mi->ch[3].noise[0]);
-}
-
-static void
-printbssidname(const struct ether_addr *n)
-{
- char name[MAXHOSTNAMELEN + 1];
-
- if (ether_ntohost(name, n) != 0)
- return;
-
- printf(" (%s)", name);
-}
-
static void
list_scan(if_ctx *ctx)
{
uint8_t buf[24*1024];
- char ssid[IEEE80211_NWID_LEN+1];
const uint8_t *cp;
int len, idlen;
if (get80211len(ctx, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
- errx(1, "unable to get scan results");
+ if_errx(1, "unable to get scan results");
if (len < (int)sizeof(struct ieee80211req_scan_result))
return;
getchaninfo(ctx);
- printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
- , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID"
- , "BSSID"
- , "CHAN"
- , "RATE"
- , " S:N"
- , "INT"
- , "CAPS"
- );
+ ifieee80211_print_list_scan_hdr();
cp = buf;
do {
const struct ieee80211req_scan_result *sr;
@@ -4045,21 +2814,11 @@
idp = vp;
idlen = sr->isr_ssid_len;
}
- printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
- , IEEE80211_NWID_LEN
- , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen)
- , ssid
- , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
- , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
- , getmaxrate(sr->isr_rates, sr->isr_nrates)
- , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
- , sr->isr_intval
- , getcaps(sr->isr_capinfo)
- );
- printies(ctx, vp + sr->isr_ssid_len + sr->isr_meshid_len,
+ ifieee80211_print_list_scan_row(sr, idp, idlen);
+ ifieee80211_printies(ctx, vp + sr->isr_ssid_len + sr->isr_meshid_len,
sr->isr_ie_len, 24);
- printbssidname((const struct ether_addr *)sr->isr_bssid);
- printf("\n");
+ ifieee80211_printbssidname((const struct ether_addr *)sr->isr_bssid);
+ ifconfig_print_newline();
cp += sr->isr_len, len -= sr->isr_len;
} while (len >= (int)sizeof(struct ieee80211req_scan_result));
}
@@ -4124,7 +2883,7 @@
static enum ieee80211_opmode get80211opmode(if_ctx *ctx);
-static int
+int
gettxseq(const struct ieee80211req_sta_info *si)
{
int i, txseq;
@@ -4139,7 +2898,7 @@
return txseq;
}
-static int
+int
getrxseq(const struct ieee80211req_sta_info *si)
{
int rxseq;
@@ -4175,38 +2934,16 @@
u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
}
if (get80211len(ctx, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
- errx(1, "unable to get station information");
+ if_errx(1, "unable to get station information");
if (len < (int)sizeof(struct ieee80211req_sta_info))
return;
getchaninfo(ctx);
if (opmode == IEEE80211_M_MBSS)
- printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
- , "ADDR"
- , "CHAN"
- , "LOCAL"
- , "PEER"
- , "STATE"
- , "RATE"
- , "RSSI"
- , "IDLE"
- , "TXSEQ"
- , "RXSEQ"
- );
+ ifieee80211_print_list_stations_hdr();
else
- printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n"
- , "ADDR"
- , "AID"
- , "CHAN"
- , "RATE"
- , "RSSI"
- , "IDLE"
- , "TXSEQ"
- , "RXSEQ"
- , "CAPS"
- , "FLAG"
- );
+ ifieee80211_print_list_stations_hdr2();
cp = (const uint8_t *) u.req.info;
do {
const struct ieee80211req_sta_info *si;
@@ -4215,43 +2952,17 @@
if (si->isi_len < sizeof(*si))
break;
if (opmode == IEEE80211_M_MBSS)
- printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
- , ether_ntoa((const struct ether_addr*)
- si->isi_macaddr)
- , ieee80211_mhz2ieee(si->isi_freq,
- si->isi_flags)
- , si->isi_localid
- , si->isi_peerid
- , mesh_linkstate_string(si->isi_peerstate)
- , si->isi_txmbps/2
- , si->isi_rssi/2.
- , si->isi_inact
- , gettxseq(si)
- , getrxseq(si)
- );
+ ifieee80211_print_list_stations_row(si);
else
- printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s"
- , ether_ntoa((const struct ether_addr*)
- si->isi_macaddr)
- , IEEE80211_AID(si->isi_associd)
- , ieee80211_mhz2ieee(si->isi_freq,
- si->isi_flags)
- , si->isi_txmbps/2
- , si->isi_rssi/2.
- , si->isi_inact
- , gettxseq(si)
- , getrxseq(si)
- , getcaps(si->isi_capinfo)
- , getflags(si->isi_state)
- );
- printies(ctx, cp + si->isi_ie_off, si->isi_ie_len, 24);
- printmimo(&si->isi_mimo);
- printf("\n");
+ ifieee80211_print_list_stations_row2(si);
+ ifieee80211_printies(ctx, cp + si->isi_ie_off, si->isi_ie_len, 24);
+ ifieee80211_printmimo(&si->isi_mimo);
+ ifconfig_print_newline();
cp += si->isi_len, len -= si->isi_len;
} while (len >= (int)sizeof(struct ieee80211req_sta_info));
}
-static const char *
+const char *
mesh_linkstate_string(uint8_t state)
{
static const char *state_names[] = {
@@ -4271,7 +2982,7 @@
return state_names[state];
}
-static const char *
+const char *
get_chaninfo(const struct ieee80211_channel *c, int precise,
char buf[], size_t bsize)
{
@@ -4324,29 +3035,7 @@
return buf;
}
-static void
-print_chaninfo(const struct ieee80211_channel *c, int verb)
-{
- char buf[14];
-
- if (verb)
- printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
- ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
- IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
- IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
- IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
- IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
- IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
- get_chaninfo(c, verb, buf, sizeof(buf)));
- else
- printf("Channel %3u : %u%c MHz%-14.14s",
- ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
- IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
- get_chaninfo(c, verb, buf, sizeof(buf)));
-
-}
-
-static int
+int
chanpref(const struct ieee80211_channel *c)
{
@@ -4381,99 +3070,11 @@
return 0;
}
-static void
-print_channels(if_ctx *ctx, const struct ieee80211req_chaninfo *chans,
- int allchans, int verb)
-{
- struct ieee80211req_chaninfo *achans;
- uint8_t reported[IEEE80211_CHAN_BYTES];
- const struct ieee80211_channel *c;
- unsigned int i, half;
-
- achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
- if (achans == NULL)
- errx(1, "no space for active channel list");
- achans->ic_nchans = 0;
- memset(reported, 0, sizeof(reported));
- if (!allchans) {
- struct ieee80211req_chanlist active;
-
- if (get80211(ctx, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
- errx(1, "unable to get active channel list");
- for (i = 0; i < chans->ic_nchans; i++) {
- c = &chans->ic_chans[i];
- if (!isset(active.ic_channels, c->ic_ieee))
- continue;
- /*
- * Suppress compatible duplicates unless
- * verbose. The kernel gives us it's
- * complete channel list which has separate
- * entries for 11g/11b and 11a/turbo.
- */
- if (isset(reported, c->ic_ieee) && !verb) {
- /* XXX we assume duplicates are adjacent */
- achans->ic_chans[achans->ic_nchans-1] = *c;
- } else {
- achans->ic_chans[achans->ic_nchans++] = *c;
- setbit(reported, c->ic_ieee);
- }
- }
- } else {
- for (i = 0; i < chans->ic_nchans; i++) {
- c = &chans->ic_chans[i];
- /* suppress duplicates as above */
- if (isset(reported, c->ic_ieee) && !verb) {
- /* XXX we assume duplicates are adjacent */
- struct ieee80211_channel *a =
- &achans->ic_chans[achans->ic_nchans-1];
- if (chanpref(c) > chanpref(a))
- *a = *c;
- } else {
- achans->ic_chans[achans->ic_nchans++] = *c;
- setbit(reported, c->ic_ieee);
- }
- }
- }
- half = achans->ic_nchans / 2;
- if (achans->ic_nchans % 2)
- half++;
-
- for (i = 0; i < achans->ic_nchans / 2; i++) {
- print_chaninfo(&achans->ic_chans[i], verb);
- print_chaninfo(&achans->ic_chans[half+i], verb);
- printf("\n");
- }
- if (achans->ic_nchans % 2) {
- print_chaninfo(&achans->ic_chans[i], verb);
- printf("\n");
- }
- free(achans);
-}
-
static void
list_channels(if_ctx *ctx, int allchans)
{
getchaninfo(ctx);
- print_channels(ctx, chaninfo, allchans, ctx->args->verbose);
-}
-
-static void
-print_txpow(const struct ieee80211_channel *c)
-{
- printf("Channel %3u : %u MHz %3.1f reg %2d ",
- c->ic_ieee, c->ic_freq,
- c->ic_maxpower/2., c->ic_maxregpower);
-}
-
-static void
-print_txpow_verbose(const struct ieee80211_channel *c)
-{
- print_chaninfo(c, 1);
- printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
- c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
- /* indicate where regulatory cap limits power use */
- if (c->ic_maxpower > 2*c->ic_maxregpower)
- printf(" <");
+ ifieee80211_print_channels(ctx, chaninfo, allchans, ctx->args->verbose);
}
static void
@@ -4487,7 +3088,7 @@
getchaninfo(ctx);
achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
if (achans == NULL)
- errx(1, "no space for active channel list");
+ if_errx(1, "no space for active channel list");
achans->ic_nchans = 0;
memset(reported, 0, sizeof(reported));
for (i = 0; i < chaninfo->ic_nchans; i++) {
@@ -4511,18 +3112,18 @@
half++;
for (i = 0; i < achans->ic_nchans / 2; i++) {
- print_txpow(&achans->ic_chans[i]);
- print_txpow(&achans->ic_chans[half+i]);
- printf("\n");
+ ifieee80211_print_txpow(&achans->ic_chans[i]);
+ ifieee80211_print_txpow(&achans->ic_chans[half+i]);
+ ifconfig_print_newline();
}
if (achans->ic_nchans % 2) {
- print_txpow(&achans->ic_chans[i]);
- printf("\n");
+ ifieee80211_print_txpow(&achans->ic_chans[i]);
+ ifconfig_print_newline();
}
} else {
for (i = 0; i < achans->ic_nchans; i++) {
- print_txpow_verbose(&achans->ic_chans[i]);
- printf("\n");
+ ifieee80211_print_txpow_verbose(&achans->ic_chans[i]);
+ ifconfig_print_newline();
}
}
free(achans);
@@ -4544,27 +3145,27 @@
else
dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
if (dc == NULL)
- errx(1, "no space for device capabilities");
+ if_errx(1, "no space for device capabilities");
dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
getdevcaps(ctx, dc);
- printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
+ ifconfig_printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
if (dc->dc_cryptocaps != 0 || verbose) {
- putchar('\n');
- printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
+ ifconfig_print_newline();
+ ifconfig_printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
}
if (dc->dc_htcaps != 0 || verbose) {
- putchar('\n');
- printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
+ ifconfig_print_newline();
+ ifconfig_printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
}
if (dc->dc_vhtcaps != 0 || verbose) {
- putchar('\n');
- printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
+ ifconfig_print_newline();
+ ifconfig_printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
}
- putchar('\n');
+ ifconfig_print_newline();
if (verbose) {
chaninfo = &dc->dc_chaninfo; /* XXX */
- print_channels(ctx, &dc->dc_chaninfo, 1/*allchans*/, verbose);
+ ifieee80211_print_channels(ctx, &dc->dc_chaninfo, 1/*allchans*/, verbose);
}
free(dc);
}
@@ -4578,7 +3179,7 @@
ireq.i_type = param;
ireq.i_len = ac;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) {
- warn("cannot get WME parameter %d, ac %d%s",
+ if_warn("cannot get WME parameter %d, ac %d%s",
param, ac & IEEE80211_WMEPARAM_VAL,
ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
return -1;
@@ -4592,33 +3193,33 @@
{
int val;
- printf("\t%s", tag);
+ ifieee80211_print_list_wme_aci_tag(tag);
/* show WME BSS parameters */
if (get80211wme(ctx, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
- printf(" cwmin %2u", val);
+ ifieee80211_print_list_wme_aci_cwmin(val);
if (get80211wme(ctx, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
- printf(" cwmax %2u", val);
+ ifieee80211_print_list_wme_aci_cwmax(val);
if (get80211wme(ctx, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
- printf(" aifs %2u", val);
+ ifieee80211_print_list_wme_aci_aifs(val);
if (get80211wme(ctx, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
- printf(" txopLimit %3u", val);
+ ifieee80211_print_list_wme_aci_txoplimit(val);
if (get80211wme(ctx, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
if (val)
- printf(" acm");
+ ifieee80211_print_list_wme_aci_acm_enabled();
else if (ctx->args->verbose)
- printf(" -acm");
+ ifieee80211_print_list_wme_aci_acm_disabled();
}
/* !BSS only */
if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
if (get80211wme(ctx, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
if (!val)
- printf(" -ack");
+ ifieee80211_print_list_wme_aci_ack_disabled();
else if (ctx->args->verbose)
- printf(" ack");
+ ifieee80211_print_list_wme_aci_ack_enabled();
}
}
- printf("\n");
+ ifconfig_print_newline();
}
static void
@@ -4664,19 +3265,19 @@
mode == IEEE80211_MODE_VHT_2GHZ ||
mode == IEEE80211_MODE_VHT_5GHZ) {
if (rp->rssi & 1)
- LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
+ ifieee80211_line_check("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
modename[mode], rp->rssi/2,
rp->rate &~ IEEE80211_RATE_MCS);
else
- LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
+ ifieee80211_line_check("roam:%-7.7s rssi %4udBm MCS %2u ",
modename[mode], rp->rssi/2,
rp->rate &~ IEEE80211_RATE_MCS);
} else {
if (rp->rssi & 1)
- LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
+ ifieee80211_line_check("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
modename[mode], rp->rssi/2, rp->rate/2);
else
- LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
+ ifieee80211_line_check("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
modename[mode], rp->rssi/2, rp->rate/2);
}
}
@@ -4713,7 +3314,7 @@
mode == IEEE80211_MODE_VHT_2GHZ ||
mode == IEEE80211_MODE_VHT_5GHZ) {
if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
- LINE_CHECK("%-7.7s ucast NONE mgmt %2u %s "
+ ifieee80211_line_check("%-7.7s ucast NONE mgmt %2u %s "
"mcast %2u %s maxretry %u",
modename[mode],
get_rate_value(tp->mgmtrate),
@@ -4722,7 +3323,7 @@
get_mcs_mbs_rate_str(tp->mcastrate),
tp->maxretry);
else
- LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u %s "
+ ifieee80211_line_check("%-7.7s ucast %2u MCS mgmt %2u %s "
"mcast %2u %s maxretry %u",
modename[mode],
tp->ucastrate &~ IEEE80211_RATE_MCS,
@@ -4733,13 +3334,13 @@
tp->maxretry);
} else {
if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
- LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
+ ifieee80211_line_check("%-7.7s ucast NONE mgmt %2u Mb/s "
"mcast %2u Mb/s maxretry %u",
modename[mode],
tp->mgmtrate/2,
tp->mcastrate/2, tp->maxretry);
else
- LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
+ ifieee80211_line_check("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
"mcast %2u Mb/s maxretry %u",
modename[mode],
tp->ucastrate/2, tp->mgmtrate/2,
@@ -4748,28 +3349,6 @@
}
}
-static void
-printpolicy(int policy)
-{
- switch (policy) {
- case IEEE80211_MACCMD_POLICY_OPEN:
- printf("policy: open\n");
- break;
- case IEEE80211_MACCMD_POLICY_ALLOW:
- printf("policy: allow\n");
- break;
- case IEEE80211_MACCMD_POLICY_DENY:
- printf("policy: deny\n");
- break;
- case IEEE80211_MACCMD_POLICY_RADIUS:
- printf("policy: radius\n");
- break;
- default:
- printf("policy: unknown (%u)\n", policy);
- break;
- }
-}
-
static void
list_mac(if_ctx *ctx)
{
@@ -4784,10 +3363,10 @@
ireq.i_val = IEEE80211_MACCMD_POLICY;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) {
if (errno == EINVAL) {
- printf("No acl policy loaded\n");
+ ifieee80211_print_list_mac_acl_loaded();
return;
}
- err(1, "unable to get mac policy");
+ if_err(1, "unable to get mac policy");
}
policy = ireq.i_val;
if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
@@ -4799,82 +3378,50 @@
} else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
c = 'r'; /* NB: should never have entries */
} else {
- printf("policy: unknown (%u)\n", policy);
+ // XXX should this maybe be an err/errx? or warn/warnx?
+ ifieee80211_print_list_mac_unknown_policy(policy);
c = '?';
}
if (ctx->args->verbose || c == '?')
- printpolicy(policy);
+ ifieee80211_printpolicy(policy);
ireq.i_val = IEEE80211_MACCMD_LIST;
ireq.i_len = 0;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0)
- err(1, "unable to get mac acl list size");
+ if_err(1, "unable to get mac acl list size");
if (ireq.i_len == 0) { /* NB: no acls */
if (!(ctx->args->verbose || c == '?'))
- printpolicy(policy);
+ ifieee80211_printpolicy(policy);
return;
}
len = ireq.i_len;
data = malloc(len);
if (data == NULL)
- err(1, "out of memory for acl list");
+ if_err(1, "out of memory for acl list");
ireq.i_data = data;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0)
- err(1, "unable to get mac acl list");
+ if_err(1, "unable to get mac acl list");
nacls = len / sizeof(*acllist);
acllist = (struct ieee80211req_maclist *) data;
for (i = 0; i < nacls; i++)
- printf("%c%s\n", c, ether_ntoa(
- (const struct ether_addr *) acllist[i].ml_macaddr));
+ ifieee80211_print_list_mac_nacl(c, &acllist[i]);
free(data);
}
-static void
-print_regdomain(const struct ieee80211_regdomain *reg, int verb)
-{
- if ((reg->regdomain != 0 &&
- reg->regdomain != reg->country) || verb) {
- const struct regdomain *rd =
- lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
- if (rd == NULL)
- LINE_CHECK("regdomain %d", reg->regdomain);
- else
- LINE_CHECK("regdomain %s", rd->name);
- }
- if (reg->country != 0 || verb) {
- const struct country *cc =
- lib80211_country_findbycc(getregdata(), reg->country);
- if (cc == NULL)
- LINE_CHECK("country %d", reg->country);
- else
- LINE_CHECK("country %s", cc->isoname);
- }
- if (reg->location == 'I')
- LINE_CHECK("indoor");
- else if (reg->location == 'O')
- LINE_CHECK("outdoor");
- else if (verb)
- LINE_CHECK("anywhere");
- if (reg->ecm)
- LINE_CHECK("ecm");
- else if (verb)
- LINE_CHECK("-ecm");
-}
-
static void
list_regdomain(if_ctx *ctx, int channelsalso)
{
getregdomain(ctx);
if (channelsalso) {
getchaninfo(ctx);
- spacer = ':';
- print_regdomain(&regdomain, 1);
- LINE_BREAK();
- print_channels(ctx, chaninfo, 1/*allchans*/, 1/*verbose*/);
+ ifieee80211_spacer = ':';
+ ifieee80211_print_regdomain(&regdomain, 1);
+ ifieee80211_line_break();
+ ifieee80211_print_channels(ctx, chaninfo, 1/*allchans*/, 1/*verbose*/);
} else
- print_regdomain(&regdomain, ctx->args->verbose);
+ ifieee80211_print_regdomain(&regdomain, ctx->args->verbose);
}
static void
@@ -4890,33 +3437,14 @@
ireq.i_data = &routes;
ireq.i_len = sizeof(routes);
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0)
- err(1, "unable to get the Mesh routing table");
+ if_err(1, "unable to get the Mesh routing table");
- printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
- , "DEST"
- , "NEXT HOP"
- , "HOPS"
- , "METRIC"
- , "LIFETIME"
- , "MSEQ"
- , "FLAGS");
+ ifieee80211_print_list_mesh_hdr();
for (unsigned int i = 0; i < ireq.i_len / sizeof(*rt); i++) {
rt = &routes[i];
- printf("%s ",
- ether_ntoa((const struct ether_addr *)rt->imr_dest));
- printf("%s %4u %4u %6u %6u %c%c\n",
- ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
- rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
- rt->imr_lastmseq,
- (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
- 'D' :
- (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
- 'V' : '!',
- (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
- 'P' :
- (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
- 'G' :' ');
+ ifieee80211_print_list_mesh_row(rt);
+ ifieee80211_print_list_mesh_row2(rt);
}
}
@@ -4926,7 +3454,7 @@
int s = ctx->io_s;
#define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
- LINE_INIT('\t');
+ ifieee80211_line_init('\t');
if (iseq(arg, "sta"))
list_stations(ctx);
@@ -4957,8 +3485,8 @@
else if (iseq(arg, "mesh"))
list_mesh(ctx);
else
- errx(1, "Don't know how to list %s for %s", arg, ctx->ifname);
- LINE_BREAK();
+ if_errx(1, "Don't know how to list %s for %s", arg, ctx->ifname);
+ ifieee80211_line_break();
#undef iseq
}
@@ -4988,146 +3516,6 @@
return IEEE80211_M_STA;
}
-#if 0
-static void
-printcipher(int s, struct ieee80211req *ireq, int keylenop)
-{
- switch (ireq->i_val) {
- case IEEE80211_CIPHER_WEP:
- ireq->i_type = keylenop;
- if (ioctl(s, SIOCG80211, ireq) != -1)
- printf("WEP-%s",
- ireq->i_len <= 5 ? "40" :
- ireq->i_len <= 13 ? "104" : "128");
- else
- printf("WEP");
- break;
- case IEEE80211_CIPHER_TKIP:
- printf("TKIP");
- break;
- case IEEE80211_CIPHER_AES_OCB:
- printf("AES-OCB");
- break;
- case IEEE80211_CIPHER_AES_CCM:
- printf("AES-CCM");
- break;
- case IEEE80211_CIPHER_AES_GCM_128:
- printf("AES-GCM");
- break;
- case IEEE80211_CIPHER_CKIP:
- printf("CKIP");
- break;
- case IEEE80211_CIPHER_NONE:
- printf("NONE");
- break;
- default:
- printf("UNKNOWN (0x%x)", ireq->i_val);
- break;
- }
-}
-#endif
-
-static void
-printkey_index(uint16_t keyix, char *buf, size_t buflen)
-{
- buf[0] = '\0';
- if (keyix == IEEE80211_KEYIX_NONE) {
- snprintf(buf, buflen, "ucast");
- } else {
- snprintf(buf, buflen, "%u", keyix+1);
- }
-}
-
-static void
-printkey(if_ctx *ctx, const struct ieee80211req_key *ik)
-{
- static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
- u_int keylen = ik->ik_keylen;
- int printcontents;
- const int verbose = ctx->args->verbose;
- const bool printkeys = ctx->args->printkeys;
- char keyix[16];
-
- printcontents = printkeys &&
- (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
- if (printcontents)
- LINE_BREAK();
- printkey_index(ik->ik_keyix, keyix, sizeof(keyix));
- switch (ik->ik_type) {
- case IEEE80211_CIPHER_WEP:
- /* compatibility */
- LINE_CHECK("wepkey %s:%s", keyix,
- keylen <= 5 ? "40-bit" :
- keylen <= 13 ? "104-bit" : "128-bit");
- break;
- case IEEE80211_CIPHER_TKIP:
- if (keylen > 128/8)
- keylen -= 128/8; /* ignore MIC for now */
- LINE_CHECK("TKIP %s:%u-bit", keyix, 8*keylen);
- break;
- case IEEE80211_CIPHER_AES_OCB:
- LINE_CHECK("AES-OCB %s:%u-bit", keyix, 8*keylen);
- break;
- case IEEE80211_CIPHER_AES_CCM:
- LINE_CHECK("AES-CCM %s:%u-bit", keyix, 8*keylen);
- break;
- case IEEE80211_CIPHER_AES_GCM_128:
- LINE_CHECK("AES-GCM %s:%u-bit", keyix, 8*keylen);
- break;
- case IEEE80211_CIPHER_CKIP:
- LINE_CHECK("CKIP %s:%u-bit", keyix, 8*keylen);
- break;
- case IEEE80211_CIPHER_NONE:
- LINE_CHECK("NULL %s:%u-bit", keyix, 8*keylen);
- break;
- default:
- LINE_CHECK("UNKNOWN (0x%x) %s:%u-bit",
- ik->ik_type, keyix, 8*keylen);
- break;
- }
- if (printcontents) {
- u_int i;
-
- printf(" <");
- for (i = 0; i < keylen; i++)
- printf("%02x", ik->ik_keydata[i]);
- printf(">");
- if (ik->ik_type != IEEE80211_CIPHER_WEP &&
- (ik->ik_keyrsc != 0 || verbose))
- printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
- if (ik->ik_type != IEEE80211_CIPHER_WEP &&
- (ik->ik_keytsc != 0 || verbose))
- printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
- if (ik->ik_flags != 0 && verbose) {
- const char *sep = " ";
-
- if (ik->ik_flags & IEEE80211_KEY_XMIT)
- printf("%stx", sep), sep = "+";
- if (ik->ik_flags & IEEE80211_KEY_RECV)
- printf("%srx", sep), sep = "+";
- if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
- printf("%sdef", sep), sep = "+";
- }
- LINE_BREAK();
- }
-}
-
-static void
-printrate(const char *tag, int v, int defrate, int defmcs)
-{
- if ((v & IEEE80211_RATE_MCS) == 0) {
- if (v != defrate) {
- if (v & 1)
- LINE_CHECK("%s %d.5", tag, v/2);
- else
- LINE_CHECK("%s %d", tag, v/2);
- }
- } else {
- if (v != defmcs)
- LINE_CHECK("%s %d", tag, v &~ 0x80);
- }
-}
-
static int
getid(if_ctx *ctx, int ix, void *data, size_t len, int *plen, int mesh)
{
@@ -5189,46 +3577,44 @@
gothtconf = 0;
gotregdomain = 0;
- printf("\t");
+ ifconfig_print_tab();
if (opmode == IEEE80211_M_MBSS) {
- printf("meshid ");
+ ifieee80211_print_ieee80211_status_meshid();
getid(ctx, 0, data, sizeof(data), &len, 1);
- print_string(data, len);
+ ifieee80211_print_string(data, len);
} else {
if (get80211val(ctx, IEEE80211_IOC_NUMSSIDS, &num) < 0)
num = 0;
- printf("ssid ");
+ ifieee80211_print_ieee80211_status_ssid();
if (num > 1) {
for (i = 0; i < num; i++) {
if (getid(ctx, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
- printf(" %d:", i + 1);
- print_string(data, len);
+ ifieee80211_print_ieee80211_status_ssid_idx(i);
+ ifieee80211_print_string(data, len);
}
}
} else
- print_string(data, len);
+ ifieee80211_print_string(data, len);
}
c = getcurchan(ctx);
if (c->ic_freq != IEEE80211_CHAN_ANY) {
- char buf[14];
- printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
- get_chaninfo(c, 1, buf, sizeof(buf)));
+ ifieee80211_print_ieee80211_status_channel(c);
} else if (verbose)
- printf(" channel UNDEF");
+ ifieee80211_print_ieee80211_status_channel_undef();
if (get80211(ctx, IEEE80211_IOC_BSSID, bssid, IEEE80211_ADDR_LEN) >= 0 &&
(memcmp(bssid, zerobssid, sizeof(zerobssid)) != 0 || verbose)) {
- printf(" bssid %s", ether_ntoa((struct ether_addr *)bssid));
- printbssidname((struct ether_addr *)bssid);
+ ifieee80211_print_ieee80211_status_bssid(bssid);
+ ifieee80211_printbssidname((struct ether_addr *)bssid);
}
if (get80211len(ctx, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
- printf("\n\tstationname ");
- print_string(data, len);
+ ifieee80211_print_ieee80211_status_stationname();
+ ifieee80211_print_string(data, len);
}
- spacer = ' '; /* force first break */
- LINE_BREAK();
+ ifieee80211_spacer = ' '; /* force first break */
+ ifieee80211_line_break();
list_regdomain(ctx, 0);
@@ -5236,37 +3622,37 @@
if (get80211val(ctx, IEEE80211_IOC_AUTHMODE, &val) != -1) {
switch (val) {
case IEEE80211_AUTH_NONE:
- LINE_CHECK("authmode NONE");
+ ifieee80211_line_check("authmode NONE");
break;
case IEEE80211_AUTH_OPEN:
- LINE_CHECK("authmode OPEN");
+ ifieee80211_line_check("authmode OPEN");
break;
case IEEE80211_AUTH_SHARED:
- LINE_CHECK("authmode SHARED");
+ ifieee80211_line_check("authmode SHARED");
break;
case IEEE80211_AUTH_8021X:
- LINE_CHECK("authmode 802.1x");
+ ifieee80211_line_check("authmode 802.1x");
break;
case IEEE80211_AUTH_WPA:
if (get80211val(ctx, IEEE80211_IOC_WPA, &wpa) < 0)
wpa = 1; /* default to WPA1 */
switch (wpa) {
case 2:
- LINE_CHECK("authmode WPA2/802.11i");
+ ifieee80211_line_check("authmode WPA2/802.11i");
break;
case 3:
- LINE_CHECK("authmode WPA1+WPA2/802.11i");
+ ifieee80211_line_check("authmode WPA1+WPA2/802.11i");
break;
default:
- LINE_CHECK("authmode WPA");
+ ifieee80211_line_check("authmode WPA");
break;
}
break;
case IEEE80211_AUTH_AUTO:
- LINE_CHECK("authmode AUTO");
+ ifieee80211_line_check("authmode AUTO");
break;
default:
- LINE_CHECK("authmode UNKNOWN (0x%x)", val);
+ ifieee80211_line_check("authmode UNKNOWN (0x%x)", val);
break;
}
}
@@ -5274,21 +3660,21 @@
if (wpa || verbose) {
if (get80211val(ctx, IEEE80211_IOC_WPS, &val) != -1) {
if (val)
- LINE_CHECK("wps");
+ ifieee80211_line_check("wps");
else if (verbose)
- LINE_CHECK("-wps");
+ ifieee80211_line_check("-wps");
}
if (get80211val(ctx, IEEE80211_IOC_TSN, &val) != -1) {
if (val)
- LINE_CHECK("tsn");
+ ifieee80211_line_check("tsn");
else if (verbose)
- LINE_CHECK("-tsn");
+ ifieee80211_line_check("-tsn");
}
if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
if (val)
- LINE_CHECK("countermeasures");
+ ifieee80211_line_check("countermeasures");
else if (verbose)
- LINE_CHECK("-countermeasures");
+ ifieee80211_line_check("-countermeasures");
}
#if 0
/* XXX not interesting with WPA done in user space */
@@ -5298,22 +3684,22 @@
ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
if (ioctl(s, SIOCG80211, &ireq) != -1) {
- LINE_CHECK("mcastcipher ");
- printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
- spacer = ' ';
+ ifieee80211_line_check("mcastcipher ");
+ ifieee80211_printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
+ ifieee80211_spacer = ' ';
}
ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
if (ioctl(s, SIOCG80211, &ireq) != -1) {
- LINE_CHECK("ucastcipher ");
- printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
+ ifieee80211_line_check("ucastcipher ");
+ ifieee80211_printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
}
if (wpa & 2) {
ireq.i_type = IEEE80211_IOC_RSNCAPS;
if (ioctl(s, SIOCG80211, &ireq) != -1) {
- LINE_CHECK("RSN caps 0x%x", ireq.i_val);
- spacer = ' ';
+ ifieee80211_line_check("RSN caps 0x%x", ireq.i_val);
+ ifieee80211_spacer = ' ';
}
}
@@ -5328,16 +3714,16 @@
switch (wepmode) {
case IEEE80211_WEP_OFF:
- LINE_CHECK("privacy OFF");
+ ifieee80211_line_check("privacy OFF");
break;
case IEEE80211_WEP_ON:
- LINE_CHECK("privacy ON");
+ ifieee80211_line_check("privacy ON");
break;
case IEEE80211_WEP_MIXED:
- LINE_CHECK("privacy MIXED");
+ ifieee80211_line_check("privacy MIXED");
break;
default:
- LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
+ ifieee80211_line_check("privacy UNKNOWN (0x%x)", wepmode);
break;
}
@@ -5347,16 +3733,16 @@
*/
if (get80211val(ctx, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
- warn("WEP support, but no tx key!");
+ if_warn("WEP support, but no tx key!");
goto end;
}
if (val != -1)
- LINE_CHECK("deftxkey %d", val+1);
+ ifieee80211_line_check("deftxkey %d", val+1);
else if (wepmode != IEEE80211_WEP_OFF || verbose)
- LINE_CHECK("deftxkey UNDEF");
+ ifieee80211_line_check("deftxkey UNDEF");
if (get80211val(ctx, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
- warn("WEP support, but no NUMWEPKEYS support!");
+ if_warn("WEP support, but no NUMWEPKEYS support!");
goto end;
}
@@ -5366,13 +3752,13 @@
memset(&ik, 0, sizeof(ik));
ik.ik_keyix = i;
if (get80211(ctx, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
- warn("WEP support, but cannot get keys!");
+ if_warn("WEP support, but cannot get keys!");
goto end;
}
if (ik.ik_keylen != 0) {
if (verbose)
- LINE_BREAK();
- printkey(ctx, &ik);
+ ifieee80211_line_break();
+ ifieee80211_printkey(ctx, &ik);
}
}
if (opmode == IEEE80211_M_STA && wpa >= 2) {
@@ -5385,13 +3771,13 @@
error = get80211(ctx, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik));
if (error == 0 && ik.ik_keylen != 0) {
if (verbose)
- LINE_BREAK();
- printkey(ctx, &ik);
+ ifieee80211_line_break();
+ ifieee80211_printkey(ctx, &ik);
i++;
}
}
if (i > 0 && verbose)
- LINE_BREAK();
+ ifieee80211_line_break();
end:
;
}
@@ -5401,70 +3787,70 @@
if (val != IEEE80211_POWERSAVE_OFF || verbose) {
switch (val) {
case IEEE80211_POWERSAVE_OFF:
- LINE_CHECK("powersavemode OFF");
+ ifieee80211_line_check("powersavemode OFF");
break;
case IEEE80211_POWERSAVE_CAM:
- LINE_CHECK("powersavemode CAM");
+ ifieee80211_line_check("powersavemode CAM");
break;
case IEEE80211_POWERSAVE_PSP:
- LINE_CHECK("powersavemode PSP");
+ ifieee80211_line_check("powersavemode PSP");
break;
case IEEE80211_POWERSAVE_PSP_CAM:
- LINE_CHECK("powersavemode PSP-CAM");
+ ifieee80211_line_check("powersavemode PSP-CAM");
break;
}
if (get80211val(ctx, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
- LINE_CHECK("powersavesleep %d", val);
+ ifieee80211_line_check("powersavesleep %d", val);
}
}
if (get80211val(ctx, IEEE80211_IOC_TXPOWER, &val) != -1) {
if (val & 1)
- LINE_CHECK("txpower %d.5", val/2);
+ ifieee80211_line_check("txpower %d.5", val/2);
else
- LINE_CHECK("txpower %d", val/2);
+ ifieee80211_line_check("txpower %d", val/2);
}
if (verbose) {
if (get80211val(ctx, IEEE80211_IOC_TXPOWMAX, &val) != -1)
- LINE_CHECK("txpowmax %.1f", val/2.);
+ ifieee80211_line_check("txpowmax %.1f", val/2.);
}
if (get80211val(ctx, IEEE80211_IOC_DOTD, &val) != -1) {
if (val)
- LINE_CHECK("dotd");
+ ifieee80211_line_check("dotd");
else if (verbose)
- LINE_CHECK("-dotd");
+ ifieee80211_line_check("-dotd");
}
if (get80211val(ctx, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
if (val != IEEE80211_RTS_MAX || verbose)
- LINE_CHECK("rtsthreshold %d", val);
+ ifieee80211_line_check("rtsthreshold %d", val);
}
if (get80211val(ctx, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
if (val != IEEE80211_FRAG_MAX || verbose)
- LINE_CHECK("fragthreshold %d", val);
+ ifieee80211_line_check("fragthreshold %d", val);
}
if (opmode == IEEE80211_M_STA || verbose) {
if (get80211val(ctx, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
if (val != IEEE80211_HWBMISS_MAX || verbose)
- LINE_CHECK("bmiss %d", val);
+ ifieee80211_line_check("bmiss %d", val);
}
}
if (!verbose) {
gettxparams(ctx);
tp = &txparams.params[chan2mode(c)];
- printrate("ucastrate", tp->ucastrate,
+ ifieee80211_printrate("ucastrate", tp->ucastrate,
IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
- printrate("mcastrate", tp->mcastrate, 2*1,
+ ifieee80211_printrate("mcastrate", tp->mcastrate, 2*1,
IEEE80211_RATE_MCS|0);
- printrate("mgmtrate", tp->mgmtrate, 2*1,
+ ifieee80211_printrate("mgmtrate", tp->mgmtrate, 2*1,
IEEE80211_RATE_MCS|0);
if (tp->maxretry != 6) /* XXX */
- LINE_CHECK("maxretry %d", tp->maxretry);
+ ifieee80211_line_check("maxretry %d", tp->maxretry);
} else {
- LINE_BREAK();
+ ifieee80211_line_break();
list_txparams(ctx);
}
@@ -5473,58 +3859,58 @@
if (get80211val(ctx, IEEE80211_IOC_SCANVALID, &val) != -1) {
if (val != bgscaninterval || verbose)
- LINE_CHECK("scanvalid %u", val);
+ ifieee80211_line_check("scanvalid %u", val);
}
bgscan = 0;
if (get80211val(ctx, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
if (bgscan)
- LINE_CHECK("bgscan");
+ ifieee80211_line_check("bgscan");
else if (verbose)
- LINE_CHECK("-bgscan");
+ ifieee80211_line_check("-bgscan");
}
if (bgscan || verbose) {
if (bgscaninterval != -1)
- LINE_CHECK("bgscanintvl %u", bgscaninterval);
+ ifieee80211_line_check("bgscanintvl %u", bgscaninterval);
if (get80211val(ctx, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
- LINE_CHECK("bgscanidle %u", val);
+ ifieee80211_line_check("bgscanidle %u", val);
if (!verbose) {
getroam(ctx);
rp = &roamparams.params[chan2mode(c)];
if (rp->rssi & 1)
- LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
+ ifieee80211_line_check("roam:rssi %u.5", rp->rssi/2);
else
- LINE_CHECK("roam:rssi %u", rp->rssi/2);
- LINE_CHECK("roam:rate %s%u",
+ ifieee80211_line_check("roam:rssi %u", rp->rssi/2);
+ ifieee80211_line_check("roam:rate %s%u",
(rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
get_rate_value(rp->rate));
} else {
- LINE_BREAK();
+ ifieee80211_line_break();
list_roam(ctx);
- LINE_BREAK();
+ ifieee80211_line_break();
}
}
if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
if (get80211val(ctx, IEEE80211_IOC_PUREG, &val) != -1) {
if (val)
- LINE_CHECK("pureg");
+ ifieee80211_line_check("pureg");
else if (verbose)
- LINE_CHECK("-pureg");
+ ifieee80211_line_check("-pureg");
}
if (get80211val(ctx, IEEE80211_IOC_PROTMODE, &val) != -1) {
switch (val) {
case IEEE80211_PROTMODE_OFF:
- LINE_CHECK("protmode OFF");
+ ifieee80211_line_check("protmode OFF");
break;
case IEEE80211_PROTMODE_CTS:
- LINE_CHECK("protmode CTS");
+ ifieee80211_line_check("protmode CTS");
break;
case IEEE80211_PROTMODE_RTSCTS:
- LINE_CHECK("protmode RTSCTS");
+ ifieee80211_line_check("protmode RTSCTS");
break;
default:
- LINE_CHECK("protmode UNKNOWN (0x%x)", val);
+ ifieee80211_line_check("protmode UNKNOWN (0x%x)", val);
break;
}
}
@@ -5535,36 +3921,36 @@
switch (htconf & 3) {
case 0:
case 2:
- LINE_CHECK("-ht");
+ ifieee80211_line_check("-ht");
break;
case 1:
- LINE_CHECK("ht20");
+ ifieee80211_line_check("ht20");
break;
case 3:
if (verbose)
- LINE_CHECK("ht");
+ ifieee80211_line_check("ht");
break;
}
if (get80211val(ctx, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
if (!val)
- LINE_CHECK("-htcompat");
+ ifieee80211_line_check("-htcompat");
else if (verbose)
- LINE_CHECK("htcompat");
+ ifieee80211_line_check("htcompat");
}
if (get80211val(ctx, IEEE80211_IOC_AMPDU, &val) != -1) {
switch (val) {
case 0:
- LINE_CHECK("-ampdu");
+ ifieee80211_line_check("-ampdu");
break;
case 1:
- LINE_CHECK("ampdutx -ampdurx");
+ ifieee80211_line_check("ampdutx -ampdurx");
break;
case 2:
- LINE_CHECK("-ampdutx ampdurx");
+ ifieee80211_line_check("-ampdutx ampdurx");
break;
case 3:
if (verbose)
- LINE_CHECK("ampdu");
+ ifieee80211_line_check("ampdu");
break;
}
}
@@ -5572,16 +3958,16 @@
if (get80211val(ctx, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
switch (val) {
case IEEE80211_HTCAP_MAXRXAMPDU_8K:
- LINE_CHECK("ampdulimit 8k");
+ ifieee80211_line_check("ampdulimit 8k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_16K:
- LINE_CHECK("ampdulimit 16k");
+ ifieee80211_line_check("ampdulimit 16k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_32K:
- LINE_CHECK("ampdulimit 32k");
+ ifieee80211_line_check("ampdulimit 32k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_64K:
- LINE_CHECK("ampdulimit 64k");
+ ifieee80211_line_check("ampdulimit 64k");
break;
}
}
@@ -5590,126 +3976,126 @@
switch (val) {
case IEEE80211_HTCAP_MPDUDENSITY_NA:
if (verbose)
- LINE_CHECK("ampdudensity NA");
+ ifieee80211_line_check("ampdudensity NA");
break;
case IEEE80211_HTCAP_MPDUDENSITY_025:
- LINE_CHECK("ampdudensity .25");
+ ifieee80211_line_check("ampdudensity .25");
break;
case IEEE80211_HTCAP_MPDUDENSITY_05:
- LINE_CHECK("ampdudensity .5");
+ ifieee80211_line_check("ampdudensity .5");
break;
case IEEE80211_HTCAP_MPDUDENSITY_1:
- LINE_CHECK("ampdudensity 1");
+ ifieee80211_line_check("ampdudensity 1");
break;
case IEEE80211_HTCAP_MPDUDENSITY_2:
- LINE_CHECK("ampdudensity 2");
+ ifieee80211_line_check("ampdudensity 2");
break;
case IEEE80211_HTCAP_MPDUDENSITY_4:
- LINE_CHECK("ampdudensity 4");
+ ifieee80211_line_check("ampdudensity 4");
break;
case IEEE80211_HTCAP_MPDUDENSITY_8:
- LINE_CHECK("ampdudensity 8");
+ ifieee80211_line_check("ampdudensity 8");
break;
case IEEE80211_HTCAP_MPDUDENSITY_16:
- LINE_CHECK("ampdudensity 16");
+ ifieee80211_line_check("ampdudensity 16");
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_AMSDU, &val) != -1) {
switch (val) {
case 0:
- LINE_CHECK("-amsdu");
+ ifieee80211_line_check("-amsdu");
break;
case 1:
- LINE_CHECK("amsdutx -amsdurx");
+ ifieee80211_line_check("amsdutx -amsdurx");
break;
case 2:
- LINE_CHECK("-amsdutx amsdurx");
+ ifieee80211_line_check("-amsdutx amsdurx");
break;
case 3:
if (verbose)
- LINE_CHECK("amsdu");
+ ifieee80211_line_check("amsdu");
break;
}
}
/* XXX amsdu limit */
if (get80211val(ctx, IEEE80211_IOC_SHORTGI, &val) != -1) {
if (val)
- LINE_CHECK("shortgi");
+ ifieee80211_line_check("shortgi");
else if (verbose)
- LINE_CHECK("-shortgi");
+ ifieee80211_line_check("-shortgi");
}
if (get80211val(ctx, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
if (val == IEEE80211_PROTMODE_OFF)
- LINE_CHECK("htprotmode OFF");
+ ifieee80211_line_check("htprotmode OFF");
else if (val != IEEE80211_PROTMODE_RTSCTS)
- LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
+ ifieee80211_line_check("htprotmode UNKNOWN (0x%x)", val);
else if (verbose)
- LINE_CHECK("htprotmode RTSCTS");
+ ifieee80211_line_check("htprotmode RTSCTS");
}
if (get80211val(ctx, IEEE80211_IOC_PUREN, &val) != -1) {
if (val)
- LINE_CHECK("puren");
+ ifieee80211_line_check("puren");
else if (verbose)
- LINE_CHECK("-puren");
+ ifieee80211_line_check("-puren");
}
if (get80211val(ctx, IEEE80211_IOC_SMPS, &val) != -1) {
if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
- LINE_CHECK("smpsdyn");
+ ifieee80211_line_check("smpsdyn");
else if (val == IEEE80211_HTCAP_SMPS_ENA)
- LINE_CHECK("smps");
+ ifieee80211_line_check("smps");
else if (verbose)
- LINE_CHECK("-smps");
+ ifieee80211_line_check("-smps");
}
if (get80211val(ctx, IEEE80211_IOC_RIFS, &val) != -1) {
if (val)
- LINE_CHECK("rifs");
+ ifieee80211_line_check("rifs");
else if (verbose)
- LINE_CHECK("-rifs");
+ ifieee80211_line_check("-rifs");
}
/* XXX VHT STBC? */
if (get80211val(ctx, IEEE80211_IOC_STBC, &val) != -1) {
switch (val) {
case 0:
- LINE_CHECK("-stbc");
+ ifieee80211_line_check("-stbc");
break;
case 1:
- LINE_CHECK("stbctx -stbcrx");
+ ifieee80211_line_check("stbctx -stbcrx");
break;
case 2:
- LINE_CHECK("-stbctx stbcrx");
+ ifieee80211_line_check("-stbctx stbcrx");
break;
case 3:
if (verbose)
- LINE_CHECK("stbc");
+ ifieee80211_line_check("stbc");
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_LDPC, &val) != -1) {
switch (val) {
case 0:
- LINE_CHECK("-ldpc");
+ ifieee80211_line_check("-ldpc");
break;
case 1:
- LINE_CHECK("ldpctx -ldpcrx");
+ ifieee80211_line_check("ldpctx -ldpcrx");
break;
case 2:
- LINE_CHECK("-ldpctx ldpcrx");
+ ifieee80211_line_check("-ldpctx ldpcrx");
break;
case 3:
if (verbose)
- LINE_CHECK("ldpc");
+ ifieee80211_line_check("ldpc");
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_UAPSD, &val) != -1) {
switch (val) {
case 0:
- LINE_CHECK("-uapsd");
+ ifieee80211_line_check("-uapsd");
break;
case 1:
- LINE_CHECK("uapsd");
+ ifieee80211_line_check("uapsd");
break;
}
}
@@ -5718,111 +4104,111 @@
if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
getvhtconf(ctx);
if (vhtconf & IEEE80211_FVHT_VHT) {
- LINE_CHECK("vht");
+ ifieee80211_line_check("vht");
if (vhtconf & IEEE80211_FVHT_USEVHT40)
- LINE_CHECK("vht40");
+ ifieee80211_line_check("vht40");
else
- LINE_CHECK("-vht40");
+ ifieee80211_line_check("-vht40");
if (vhtconf & IEEE80211_FVHT_USEVHT80)
- LINE_CHECK("vht80");
+ ifieee80211_line_check("vht80");
else
- LINE_CHECK("-vht80");
+ ifieee80211_line_check("-vht80");
if (vhtconf & IEEE80211_FVHT_USEVHT160)
- LINE_CHECK("vht160");
+ ifieee80211_line_check("vht160");
else
- LINE_CHECK("-vht160");
+ ifieee80211_line_check("-vht160");
if (vhtconf & IEEE80211_FVHT_USEVHT80P80)
- LINE_CHECK("vht80p80");
+ ifieee80211_line_check("vht80p80");
else
- LINE_CHECK("-vht80p80");
+ ifieee80211_line_check("-vht80p80");
} else if (verbose)
- LINE_CHECK("-vht");
+ ifieee80211_line_check("-vht");
}
if (get80211val(ctx, IEEE80211_IOC_WME, &wme) != -1) {
if (wme)
- LINE_CHECK("wme");
+ ifieee80211_line_check("wme");
else if (verbose)
- LINE_CHECK("-wme");
+ ifieee80211_line_check("-wme");
} else
wme = 0;
if (get80211val(ctx, IEEE80211_IOC_BURST, &val) != -1) {
if (val)
- LINE_CHECK("burst");
+ ifieee80211_line_check("burst");
else if (verbose)
- LINE_CHECK("-burst");
+ ifieee80211_line_check("-burst");
}
if (get80211val(ctx, IEEE80211_IOC_FF, &val) != -1) {
if (val)
- LINE_CHECK("ff");
+ ifieee80211_line_check("ff");
else if (verbose)
- LINE_CHECK("-ff");
+ ifieee80211_line_check("-ff");
}
if (get80211val(ctx, IEEE80211_IOC_TURBOP, &val) != -1) {
if (val)
- LINE_CHECK("dturbo");
+ ifieee80211_line_check("dturbo");
else if (verbose)
- LINE_CHECK("-dturbo");
+ ifieee80211_line_check("-dturbo");
}
if (get80211val(ctx, IEEE80211_IOC_DWDS, &val) != -1) {
if (val)
- LINE_CHECK("dwds");
+ ifieee80211_line_check("dwds");
else if (verbose)
- LINE_CHECK("-dwds");
+ ifieee80211_line_check("-dwds");
}
if (opmode == IEEE80211_M_HOSTAP) {
if (get80211val(ctx, IEEE80211_IOC_HIDESSID, &val) != -1) {
if (val)
- LINE_CHECK("hidessid");
+ ifieee80211_line_check("hidessid");
else if (verbose)
- LINE_CHECK("-hidessid");
+ ifieee80211_line_check("-hidessid");
}
if (get80211val(ctx, IEEE80211_IOC_APBRIDGE, &val) != -1) {
if (!val)
- LINE_CHECK("-apbridge");
+ ifieee80211_line_check("-apbridge");
else if (verbose)
- LINE_CHECK("apbridge");
+ ifieee80211_line_check("apbridge");
}
if (get80211val(ctx, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
- LINE_CHECK("dtimperiod %u", val);
+ ifieee80211_line_check("dtimperiod %u", val);
if (get80211val(ctx, IEEE80211_IOC_DOTH, &val) != -1) {
if (!val)
- LINE_CHECK("-doth");
+ ifieee80211_line_check("-doth");
else if (verbose)
- LINE_CHECK("doth");
+ ifieee80211_line_check("doth");
}
if (get80211val(ctx, IEEE80211_IOC_DFS, &val) != -1) {
if (!val)
- LINE_CHECK("-dfs");
+ ifieee80211_line_check("-dfs");
else if (verbose)
- LINE_CHECK("dfs");
+ ifieee80211_line_check("dfs");
}
if (get80211val(ctx, IEEE80211_IOC_INACTIVITY, &val) != -1) {
if (!val)
- LINE_CHECK("-inact");
+ ifieee80211_line_check("-inact");
else if (verbose)
- LINE_CHECK("inact");
+ ifieee80211_line_check("inact");
}
} else {
if (get80211val(ctx, IEEE80211_IOC_ROAMING, &val) != -1) {
if (val != IEEE80211_ROAMING_AUTO || verbose) {
switch (val) {
case IEEE80211_ROAMING_DEVICE:
- LINE_CHECK("roaming DEVICE");
+ ifieee80211_line_check("roaming DEVICE");
break;
case IEEE80211_ROAMING_AUTO:
- LINE_CHECK("roaming AUTO");
+ ifieee80211_line_check("roaming AUTO");
break;
case IEEE80211_ROAMING_MANUAL:
- LINE_CHECK("roaming MANUAL");
+ ifieee80211_line_check("roaming MANUAL");
break;
default:
- LINE_CHECK("roaming UNKNOWN (0x%x)",
+ ifieee80211_line_check("roaming UNKNOWN (0x%x)",
val);
break;
}
@@ -5832,90 +4218,90 @@
if (opmode == IEEE80211_M_AHDEMO) {
if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
- LINE_CHECK("tdmaslot %u", val);
+ ifieee80211_line_check("tdmaslot %u", val);
if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
- LINE_CHECK("tdmaslotcnt %u", val);
+ ifieee80211_line_check("tdmaslotcnt %u", val);
if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
- LINE_CHECK("tdmaslotlen %u", val);
+ ifieee80211_line_check("tdmaslotlen %u", val);
if (get80211val(ctx, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
- LINE_CHECK("tdmabintval %u", val);
+ ifieee80211_line_check("tdmabintval %u", val);
} else if (get80211val(ctx, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
/* XXX default define not visible */
if (val != 100 || verbose)
- LINE_CHECK("bintval %u", val);
+ ifieee80211_line_check("bintval %u", val);
}
if (wme && verbose) {
- LINE_BREAK();
+ ifieee80211_line_break();
list_wme(ctx);
}
if (opmode == IEEE80211_M_MBSS) {
if (get80211val(ctx, IEEE80211_IOC_MESH_TTL, &val) != -1) {
- LINE_CHECK("meshttl %u", val);
+ ifieee80211_line_check("meshttl %u", val);
}
if (get80211val(ctx, IEEE80211_IOC_MESH_AP, &val) != -1) {
if (val)
- LINE_CHECK("meshpeering");
+ ifieee80211_line_check("meshpeering");
else
- LINE_CHECK("-meshpeering");
+ ifieee80211_line_check("-meshpeering");
}
if (get80211val(ctx, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
if (val)
- LINE_CHECK("meshforward");
+ ifieee80211_line_check("meshforward");
else
- LINE_CHECK("-meshforward");
+ ifieee80211_line_check("-meshforward");
}
if (get80211val(ctx, IEEE80211_IOC_MESH_GATE, &val) != -1) {
if (val)
- LINE_CHECK("meshgate");
+ ifieee80211_line_check("meshgate");
else
- LINE_CHECK("-meshgate");
+ ifieee80211_line_check("-meshgate");
}
if (get80211len(ctx, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
&len) != -1) {
data[len] = '\0';
- LINE_CHECK("meshmetric %s", data);
+ ifieee80211_line_check("meshmetric %s", data);
}
if (get80211len(ctx, IEEE80211_IOC_MESH_PR_PATH, data, 12,
&len) != -1) {
data[len] = '\0';
- LINE_CHECK("meshpath %s", data);
+ ifieee80211_line_check("meshpath %s", data);
}
if (get80211val(ctx, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
switch (val) {
case IEEE80211_HWMP_ROOTMODE_DISABLED:
- LINE_CHECK("hwmprootmode DISABLED");
+ ifieee80211_line_check("hwmprootmode DISABLED");
break;
case IEEE80211_HWMP_ROOTMODE_NORMAL:
- LINE_CHECK("hwmprootmode NORMAL");
+ ifieee80211_line_check("hwmprootmode NORMAL");
break;
case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
- LINE_CHECK("hwmprootmode PROACTIVE");
+ ifieee80211_line_check("hwmprootmode PROACTIVE");
break;
case IEEE80211_HWMP_ROOTMODE_RANN:
- LINE_CHECK("hwmprootmode RANN");
+ ifieee80211_line_check("hwmprootmode RANN");
break;
default:
- LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
+ ifieee80211_line_check("hwmprootmode UNKNOWN(%d)", val);
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
- LINE_CHECK("hwmpmaxhops %u", val);
+ ifieee80211_line_check("hwmpmaxhops %u", val);
}
}
- LINE_BREAK();
+ ifieee80211_line_break();
if (getdevicename(ctx, data, sizeof(data), &len) < 0)
return;
- LINE_CHECK("parent interface: %s", data);
+ ifieee80211_line_check("parent interface: %s", data);
- LINE_BREAK();
+ ifieee80211_line_break();
}
-static int
+int
get80211(if_ctx *ctx, int type, void *data, int len)
{
@@ -5943,7 +4329,7 @@
ret = lib80211_set80211(ctx->io_s, ctx->ifname, type, val, len, data);
if (ret < 0)
- err(1, "SIOCS80211");
+ if_err(1, "SIOCS80211");
}
static const char *
@@ -5967,19 +4353,19 @@
}
if (hexstr) {
if (!isxdigit((u_char)val[0])) {
- warnx("bad hexadecimal digits");
+ if_warnx("bad hexadecimal digits");
return NULL;
}
if (!isxdigit((u_char)val[1])) {
- warnx("odd count hexadecimal digits");
+ if_warnx("odd count hexadecimal digits");
return NULL;
}
}
if (p >= buf + len) {
if (hexstr)
- warnx("hexadecimal digits too long");
+ if_warnx("hexadecimal digits too long");
else
- warnx("string too long");
+ if_warnx("string too long");
return NULL;
}
if (hexstr) {
@@ -6002,37 +4388,6 @@
return val;
}
-static void
-print_string(const u_int8_t *buf, int len)
-{
- int i;
- int hasspc;
- int utf8;
-
- i = 0;
- hasspc = 0;
-
- setlocale(LC_CTYPE, "");
- utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
-
- for (; i < len; i++) {
- if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
- break;
- if (isspace(buf[i]))
- hasspc++;
- }
- if (i == len || utf8) {
- if (hasspc || len == 0 || buf[0] == '\0')
- printf("\"%.*s\"", len, buf);
- else
- printf("%.*s", len, buf);
- } else {
- printf("0x");
- for (i = 0; i < len; i++)
- printf("%02x", buf[i]);
- }
-}
-
static void
setdefregdomain(if_ctx *ctx)
{
@@ -6055,7 +4410,7 @@
/* Set FCC/US as default. */
rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
if (rd == NULL)
- errx(1, "FCC regdomain was not found");
+ if_errx(1, "FCC regdomain was not found");
regdomain.regdomain = rd->sku;
if (rd->cc != NULL)
@@ -6084,11 +4439,11 @@
static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
if (params.icp_parent[0] == '\0')
- errx(1, "must specify a parent device (wlandev) when creating "
+ if_errx(1, "must specify a parent device (wlandev) when creating "
"a wlan device");
if (params.icp_opmode == IEEE80211_M_WDS &&
memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
- errx(1, "no bssid specified for WDS (use wlanbssid)");
+ if_errx(1, "no bssid specified for WDS (use wlanbssid)");
ifr->ifr_data = (caddr_t) &params;
ifcreate_ioctl(ctx, ifr);
@@ -6108,7 +4463,7 @@
ea = ether_aton(arg);
if (ea == NULL)
- errx(1, "%s: cannot parse bssid", arg);
+ if_errx(1, "%s: cannot parse bssid", arg);
memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
}
@@ -6119,7 +4474,7 @@
ea = ether_aton(arg);
if (ea == NULL)
- errx(1, "%s: cannot parse address", arg);
+ if_errx(1, "%s: cannot parse address", arg);
memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
params.icp_flags |= IEEE80211_CLONE_MACADDR;
}
@@ -6146,7 +4501,7 @@
} else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
params.icp_opmode = IEEE80211_M_MBSS;
else
- errx(1, "Don't know to create %s for %s", arg, ctx->ifname);
+ if_errx(1, "Don't know to create %s for %s", arg, ctx->ifname);
#undef iseq
}
diff --git a/sbin/ifconfig/ifipsec.c b/sbin/ifconfig/ifipsec.c
--- a/sbin/ifconfig/ifipsec.c
+++ b/sbin/ifconfig/ifipsec.c
@@ -48,6 +48,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static void
ipsec_status(if_ctx *ctx)
@@ -57,7 +58,7 @@
if (ioctl_ctx_ifr(ctx, IPSECGREQID, &ifr) == -1)
return;
- printf("\treqid: %u\n", reqid);
+ ifipsec_print_reqid(reqid);
}
static void
@@ -69,11 +70,11 @@
v = strtoul(val, &ep, 0);
if (*ep != '\0') {
- warn("Invalid reqid value %s", val);
+ if_warn("Invalid reqid value %s", val);
return;
}
if (ioctl_ctx_ifr(ctx, IPSECSREQID, &ifr) == -1) {
- warn("ioctl(IPSECSREQID)");
+ if_warn("ioctl(IPSECSREQID)");
return;
}
}
diff --git a/sbin/ifconfig/iflagg.h b/sbin/ifconfig/iflagg.h
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/iflagg.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include <net/ieee8023ad_lacp.h>
+
+char *lacp_format_peer(struct lacp_opreq *req, const char *sep);
\ No newline at end of file
diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c
--- a/sbin/ifconfig/iflagg.c
+++ b/sbin/ifconfig/iflagg.c
@@ -26,6 +26,8 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
+#include "iflagg.h"
static struct iflaggparam params = {
.lagg_type = LAGG_TYPE_DEFAULT,
@@ -48,7 +50,7 @@
* Don't error at all if the port is already in the lagg.
*/
if (ioctl_ctx(ctx, SIOCSLAGGPORT, &rp) && errno != EEXIST) {
- warnx("%s %s: SIOCSLAGGPORT: %s",
+ if_warnx("%s %s: SIOCSLAGGPORT: %s",
ctx->ifname, val, strerror(errno));
exit_code = 1;
}
@@ -63,7 +65,7 @@
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
if (ioctl_ctx(ctx, SIOCSLAGGDELPORT, &rp))
- err(1, "SIOCSLAGGDELPORT");
+ if_err(1, "SIOCSLAGGDELPORT");
}
static void
@@ -82,11 +84,11 @@
}
}
if (ra.ra_proto == LAGG_PROTO_MAX)
- errx(1, "Invalid aggregation protocol: %s", val);
+ if_errx(1, "Invalid aggregation protocol: %s", val);
strlcpy(ra.ra_ifname, ctx->ifname, sizeof(ra.ra_ifname));
if (ioctl_ctx(ctx, SIOCSLAGG, &ra) != 0)
- err(1, "SIOCSLAGG");
+ if_err(1, "SIOCSLAGG");
}
static void
@@ -98,10 +100,10 @@
strlcpy(ro.ro_ifname, ctx->ifname, 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_errx(1, "Invalid flowid_shift option: %s", val);
if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0)
- err(1, "SIOCSLAGGOPTS");
+ if_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -113,10 +115,10 @@
ro.ro_opts = LAGG_OPT_RR_LIMIT;
ro.ro_bkt = (uint32_t)strtoul(val, NULL, 10);
if (ro.ro_bkt == 0)
- errx(1, "Invalid round-robin stride: %s", val);
+ if_errx(1, "Invalid round-robin stride: %s", val);
if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0)
- err(1, "SIOCSLAGGOPTS");
+ if_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -140,12 +142,12 @@
case -LAGG_OPT_LACP_FAST_TIMO:
break;
default:
- err(1, "Invalid lagg option");
+ if_err(1, "Invalid lagg option");
}
strlcpy(ro.ro_ifname, ctx->ifname, sizeof(ro.ro_ifname));
if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0)
- err(1, "SIOCSLAGGOPTS");
+ if_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -165,15 +167,15 @@
else if (strcmp(tok, "l4") == 0)
rf.rf_flags |= LAGG_F_HASHL4;
else
- errx(1, "Invalid lagghash option: %s", tok);
+ if_errx(1, "Invalid lagghash option: %s", tok);
}
free(str);
if (rf.rf_flags == 0)
- errx(1, "No lagghash options supplied");
+ if_errx(1, "No lagghash options supplied");
strlcpy(rf.rf_ifname, ctx->ifname, sizeof(rf.rf_ifname));
if (ioctl_ctx(ctx, SIOCSLAGGHASH, &rf))
- err(1, "SIOCSLAGGHASH");
+ if_err(1, "SIOCSLAGGHASH");
}
static char *
@@ -186,7 +188,7 @@
return (buf);
}
-static char *
+char *
lacp_format_peer(struct lacp_opreq *req, const char *sep)
{
char macbuf1[20];
@@ -232,53 +234,51 @@
break;
}
}
- printf("\tlaggproto %s", proto);
+ iflagg_print_laggproto(proto);
if (rf->rf_flags & LAGG_F_HASHMASK) {
const char *sep = "";
- printf(" lagghash ");
+ iflagg_print_lagghash();
if (rf->rf_flags & LAGG_F_HASHL2) {
- printf("%sl2", sep);
+ iflagg_print_l2(sep);
sep = ",";
}
if (rf->rf_flags & LAGG_F_HASHL3) {
- printf("%sl3", sep);
+ iflagg_print_l3(sep);
sep = ",";
}
if (rf->rf_flags & LAGG_F_HASHL4) {
- printf("%sl4", sep);
+ iflagg_print_l4(sep);
sep = ",";
}
}
- putchar('\n');
+ ifconfig_print_newline();
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);
+ iflagg_print_options();
+ ifconfig_printb("\t\tflags", ro->ro_opts, LAGG_OPT_BITS);
+ ifconfig_print_newline();
+ iflagg_print_flowid_shift(ro);
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);
+ iflagg_print_trr_limit(ro);
+ iflagg_print_statistics();
+ iflagg_print_active_ports(ro);
+ iflagg_print_flapping(ro);
if (ra->ra_proto == LAGG_PROTO_LACP) {
lp = &ra->ra_lacpreq;
- printf("\tlag id: %s\n",
- lacp_format_peer(lp, "\n\t\t "));
+ iflagg_print_lagg_id(lp);
}
}
for (size_t i = 0; i < (size_t)ra->ra_ports; ++i) {
lp = &ports[i].rp_lacpreq;
- printf("\tlaggport: %s ", ports[i].rp_portname);
- printb("flags", ports[i].rp_flags, LAGG_PORT_BITS);
+ iflagg_print_laggport(&ports[i]);
+ ifconfig_printb("flags", ports[i].rp_flags, LAGG_PORT_BITS);
if (verbose && ra->ra_proto == LAGG_PROTO_LACP)
- printb(" state", lp->actor_state, LACP_STATE_BITS);
- putchar('\n');
+ ifconfig_printb(" state", lp->actor_state, LACP_STATE_BITS);
+ ifconfig_print_newline();
if (verbose && ra->ra_proto == LAGG_PROTO_LACP)
- printf("\t\t%s\n",
- lacp_format_peer(lp, "\n\t\t "));
+ iflagg_print_peer(lp);
}
ifconfig_lagg_free_lagg_status(lagg);
@@ -295,7 +295,7 @@
return;
}
}
- errx(1, "invalid lagg type: %s", arg);
+ if_errx(1, "invalid lagg type: %s", arg);
}
static void
diff --git a/sbin/ifconfig/ifmac.c b/sbin/ifconfig/ifmac.c
--- a/sbin/ifconfig/ifmac.c
+++ b/sbin/ifconfig/ifmac.c
@@ -48,6 +48,7 @@
#include <string.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static void
maclabel_status(if_ctx *ctx)
@@ -70,7 +71,7 @@
goto mac_free;
if (strlen(label_text) != 0)
- printf("\tmaclabel %s\n", label_text);
+ ifmac_print_maclabel(label_text);
free(label_text);
mac_free:
diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c
--- a/sbin/ifconfig/ifmedia.c
+++ b/sbin/ifconfig/ifmedia.c
@@ -88,13 +88,12 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static void domediaopt(if_ctx *, const char *, bool);
static ifmedia_t get_media_subtype(ifmedia_t, const char *);
static ifmedia_t get_media_mode(ifmedia_t, const char *);
static ifmedia_t get_media_options(ifmedia_t, const char *);
-static void print_media(ifmedia_t, bool);
-static void print_media_ifconfig(ifmedia_t);
static void
media_status(if_ctx *ctx)
@@ -105,50 +104,50 @@
return;
if (ifmr->ifm_count == 0) {
- warnx("%s: no media types?", ctx->ifname);
+ if_warnx("%s: no media types?", ctx->ifname);
goto free;
}
- printf("\tmedia: ");
- print_media(ifmr->ifm_current, true);
+ ifmedia_print_media_header();
+ ifmedia_print_media(ifmr->ifm_current, true);
if (ifmr->ifm_active != ifmr->ifm_current) {
- putchar(' ');
- putchar('(');
- print_media(ifmr->ifm_active, false);
- putchar(')');
+ ifconfig_print_space();
+ ifconfig_print_char('(');
+ ifmedia_print_media(ifmr->ifm_active, false);
+ ifconfig_print_char(')');
}
- putchar('\n');
+ ifconfig_print_newline();
if (ifmr->ifm_status & IFM_AVALID) {
struct ifdownreason ifdr;
const char *status;
status = ifconfig_media_get_status(ifmr);
- printf("\tstatus: %s", status);
+ ifmedia_print_status(status);
if (strcmp(status, "no carrier") == 0 &&
ifconfig_media_get_downreason(lifh, ctx->ifname, &ifdr) == 0) {
switch (ifdr.ifdr_reason) {
case IFDR_REASON_MSG:
- printf(" (%s)", ifdr.ifdr_msg);
+ ifmedia_print_reason(&ifdr);
break;
case IFDR_REASON_VENDOR:
- printf(" (vendor code %d)",
- ifdr.ifdr_vendor);
+ ifmedia_print_reason_vendor(&ifdr);
break;
default:
break;
}
}
- putchar('\n');
+ ifconfig_print_newline();
}
if (ctx->args->supmedia) {
- printf("\tsupported media:\n");
+ ifmedia_print_supmedia();
for (int i = 0; i < ifmr->ifm_count; ++i) {
- printf("\t\t");
- print_media_ifconfig(ifmr->ifm_ulist[i]);
- putchar('\n');
+ ifconfig_print_tab();
+ ifconfig_print_tab();
+ ifmedia_print_media_ifconfig(ifmr->ifm_ulist[i]);
+ ifconfig_print_newline();
}
}
free:
@@ -164,11 +163,11 @@
return (ifmr);
if (ifconfig_media_get_mediareq(lifh, ctx->ifname, &ifmr) == -1)
- errc(1, ifconfig_err_errno(lifh),
+ if_errc(1, ifconfig_err_errno(lifh),
"%s: ifconfig_media_get_mediareq", ctx->ifname);
if (ifmr->ifm_count == 0)
- errx(1, "%s: no media types?", ctx->ifname);
+ if_errx(1, "%s: no media types?", ctx->ifname);
return (ifmr);
}
@@ -183,7 +182,7 @@
if (!did_it) {
ifr.ifr_media = ifmr->ifm_current;
if (ioctl_ctx_ifr(ctx, SIOCSIFMEDIA, &ifr) < 0)
- err(1, "SIOCSIFMEDIA (media)");
+ if_err(1, "SIOCSIFMEDIA (media)");
free(ifmr);
did_it = true;
}
@@ -260,7 +259,7 @@
inst = atoi(val);
if (inst < 0 || inst > (int)IFM_INST_MAX)
- errx(1, "invalid media instance: %s", val);
+ if_errx(1, "invalid media instance: %s", val);
ifmr->ifm_current = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
@@ -292,11 +291,11 @@
return (subtype);
switch (errno) {
case EINVAL:
- errx(EXIT_FAILURE, "unknown media type 0x%x", media);
+ if_errx(EXIT_FAILURE, "unknown media type 0x%x", media);
case ENOENT:
- errx(EXIT_FAILURE, "unknown media subtype: %s", val);
+ if_errx(EXIT_FAILURE, "unknown media subtype: %s", val);
default:
- err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
+ if_err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
}
/*NOTREACHED*/
}
@@ -311,11 +310,11 @@
return (mode);
switch (errno) {
case EINVAL:
- errx(EXIT_FAILURE, "unknown media type 0x%x", media);
+ if_errx(EXIT_FAILURE, "unknown media type 0x%x", media);
case ENOENT:
return (INVALID_IFMEDIA);
default:
- err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
+ if_err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
}
/*NOTREACHED*/
}
@@ -334,7 +333,7 @@
*/
opts = strdup(val);
if (opts == NULL)
- err(EXIT_FAILURE, "strdup");
+ if_err(EXIT_FAILURE, "strdup");
/*
* Split the comma-delimited list into separate strings.
@@ -348,7 +347,7 @@
}
optnames = calloc(nopts, sizeof(*optnames));
if (optnames == NULL)
- err(EXIT_FAILURE, "calloc");
+ if_err(EXIT_FAILURE, "calloc");
opt = opts;
for (size_t i = 0; i < nopts; ++i) {
optnames[i] = opt;
@@ -360,11 +359,11 @@
*/
options = ifconfig_media_lookup_options(media, optnames, nopts);
if (options == NULL)
- err(EXIT_FAILURE, "ifconfig_media_lookup_options");
+ if_err(EXIT_FAILURE, "ifconfig_media_lookup_options");
rval = 0;
for (size_t i = 0; i < nopts; ++i) {
if (options[i] == INVALID_IFMEDIA)
- errx(EXIT_FAILURE, "unknown option: %s", optnames[i]);
+ if_errx(EXIT_FAILURE, "unknown option: %s", optnames[i]);
rval |= options[i];
}
free(options);
@@ -373,89 +372,6 @@
return (rval);
}
-static void
-print_media(ifmedia_t media, bool print_toptype)
-{
- const char *val, **options;
-
- val = ifconfig_media_get_type(media);
- if (val == NULL) {
- printf("<unknown type>");
- return;
- } else if (print_toptype) {
- printf("%s", val);
- }
-
- val = ifconfig_media_get_subtype(media);
- if (val == NULL) {
- printf("<unknown subtype>");
- return;
- }
-
- if (print_toptype)
- putchar(' ');
-
- printf("%s", val);
-
- if (print_toptype) {
- val = ifconfig_media_get_mode(media);
- if (val != NULL && strcasecmp("autoselect", val) != 0)
- printf(" mode %s", val);
- }
-
- options = ifconfig_media_get_options(media);
- if (options != NULL && options[0] != NULL) {
- printf(" <%s", options[0]);
- for (size_t i = 1; options[i] != NULL; ++i)
- printf(",%s", options[i]);
- printf(">");
- }
- free(options);
-
- if (print_toptype && IFM_INST(media) != 0)
- printf(" instance %d", IFM_INST(media));
-}
-
-static void
-print_media_ifconfig(ifmedia_t media)
-{
- const char *val, **options;
-
- val = ifconfig_media_get_type(media);
- if (val == NULL) {
- printf("<unknown type>");
- return;
- }
-
- /*
- * Don't print the top-level type; it's not like we can
- * change it, or anything.
- */
-
- val = ifconfig_media_get_subtype(media);
- if (val == NULL) {
- printf("<unknown subtype>");
- return;
- }
-
- printf("media %s", val);
-
- val = ifconfig_media_get_mode(media);
- if (val != NULL)
- printf(" mode %s", val);
-
- options = ifconfig_media_get_options(media);
- if (options != NULL && options[0] != NULL) {
- printf(" mediaopt %s", options[0]);
- for (size_t i = 1; options[i] != NULL; ++i)
- printf(",%s", options[i]);
- }
- free(options);
-
- if (IFM_INST(media) != 0)
- printf(" instance %d", IFM_INST(media));
-}
-
/**********************************************************************
* ...until here.
**********************************************************************/
diff --git a/sbin/ifconfig/ifpfsync.c b/sbin/ifconfig/ifpfsync.c
--- a/sbin/ifconfig/ifpfsync.c
+++ b/sbin/ifconfig/ifpfsync.c
@@ -47,6 +47,7 @@
#include <unistd.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static int
pfsync_do_ioctl(if_ctx *ctx, uint cmd, nvlist_t **nvl)
@@ -173,10 +174,10 @@
nvlist_t *nvl = nvlist_create(0);
if (strlen(val) > IFNAMSIZ)
- errx(1, "interface name %s is too long", val);
+ if_errx(1, "interface name %s is too long", val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_string(nvl, "syncdev"))
nvlist_free_string(nvl, "syncdev");
@@ -184,7 +185,7 @@
nvlist_add_string(nvl, "syncdev", val);
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
}
static void
@@ -193,7 +194,7 @@
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_string(nvl, "syncdev"))
nvlist_free_string(nvl, "syncdev");
@@ -201,7 +202,7 @@
nvlist_add_string(nvl, "syncdev", "");
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
}
static void
@@ -214,10 +215,10 @@
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
if ((ecode = getaddrinfo(val, NULL, NULL, &peerres)) != 0)
- errx(1, "error in parsing address string: %s",
+ if_errx(1, "error in parsing address string: %s",
gai_strerror(ecode));
switch (peerres->ai_family) {
@@ -238,7 +239,7 @@
}
#endif
default:
- errx(1, "syncpeer address %s not supported", val);
+ if_errx(1, "syncpeer address %s not supported", val);
}
if (nvlist_exists_nvlist(nvl, "syncpeer"))
@@ -248,7 +249,7 @@
pfsync_sockaddr_to_syncpeer_nvlist(&addr));
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
freeaddrinfo(peerres);
@@ -263,7 +264,7 @@
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_nvlist(nvl, "syncpeer"))
nvlist_free_nvlist(nvl, "syncpeer");
@@ -272,7 +273,7 @@
pfsync_sockaddr_to_syncpeer_nvlist(&addr));
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -285,16 +286,16 @@
maxupdates = atoi(val);
if ((maxupdates < 0) || (maxupdates > 255))
- errx(1, "maxupd %s: out of range", val);
+ if_errx(1, "maxupd %s: out of range", val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
nvlist_free_number(nvl, "maxupdates");
nvlist_add_number(nvl, "maxupdates", maxupdates);
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -305,13 +306,13 @@
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
nvlist_free_number(nvl, "flags");
nvlist_add_number(nvl, "flags", d ? PFSYNCF_DEFER : 0);
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -326,13 +327,13 @@
version = atoi(val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ if_err(1, "SIOCGETPFSYNCNV");
nvlist_free_number(nvl, "version");
nvlist_add_number(nvl, "version", version);
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ if_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -374,10 +375,10 @@
nvlist_destroy(nvl);
- printf("\t");
+ ifconfig_print_tab();
if (syncdev[0] != '\0')
- printf("syncdev: %s ", syncdev);
+ ifpfsync_print_syncdev(syncdev);
if ((syncpeer.ss_family == AF_INET &&
((struct sockaddr_in *)&syncpeer)->sin_addr.s_addr !=
@@ -388,14 +389,14 @@
if ((error = getnameinfo(syncpeer_sa, syncpeer_sa->sa_len,
syncpeer_str, sizeof(syncpeer_str), NULL, 0,
NI_NUMERICHOST)) != 0)
- errx(1, "getnameinfo: %s", gai_strerror(error));
- printf("syncpeer: %s ", syncpeer_str);
+ if_errx(1, "getnameinfo: %s", gai_strerror(error));
+ ifpfsync_print_syncpeer(syncpeer_str);
}
- printf("maxupd: %d ", maxupdates);
- printf("defer: %s ", (flags & PFSYNCF_DEFER) ? "on" : "off");
- printf("version: %d\n", version);
- printf("\tsyncok: %d\n", (flags & PFSYNCF_OK) ? 1 : 0);
+ ifpfsync_print_maxupd(maxupdates);
+ ifpfsync_print_defer(flags);
+ ifpfsync_print_version(version);
+ ifpfsync_print_syncok(flags);
}
static struct cmd pfsync_cmds[] = {
diff --git a/sbin/ifconfig/ifstf.c b/sbin/ifconfig/ifstf.c
--- a/sbin/ifconfig/ifstf.c
+++ b/sbin/ifconfig/ifstf.c
@@ -52,6 +52,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static int
do_cmd(if_ctx *ctx, u_long op, void *arg, size_t argsize, int set)
@@ -74,9 +75,9 @@
if (do_cmd(ctx, STF6RD_GV4NET, &param, sizeof(param), 0) < 0)
return;
- printf("\tv4net %s/%d -> ", inet_ntoa(param.srcv4_addr),
- param.v4_prefixlen ? param.v4_prefixlen : 32);
- printf("tv4br %s\n", inet_ntoa(param.braddr));
+ ifstf_print_v4net(&param);
+ // XXX should this be \t4br instead of tv4br?
+ ifstf_print_tv4br(&param);
}
static void
@@ -91,11 +92,11 @@
sin.sin_family = AF_INET;
if (!inet_aton(val, &sin.sin_addr))
- errx(1, "%s: bad value", val);
+ if_errx(1, "%s: bad value", val);
req.braddr = sin.sin_addr;
if (do_cmd(ctx, STF6RD_SBR, &req, sizeof(req), 1) < 0)
- err(1, "STF6RD_SBR%s", val);
+ if_err(1, "STF6RD_SBR%s", val);
}
static void
@@ -113,21 +114,21 @@
p = strrchr(val, '/');
if (p == NULL)
- errx(2, "Wrong argument given");
+ if_errx(2, "Wrong argument given");
*p = '\0';
req.v4_prefixlen = (int)strtonum(p + 1, 0, 32, &errstr);
if (errstr != NULL || req.v4_prefixlen == 0) {
*p = '/';
- errx(1, "%s: bad value (prefix length %s)", val, errstr);
+ if_errx(1, "%s: bad value (prefix length %s)", val, errstr);
}
if (!inet_aton(val, &sin.sin_addr))
- errx(1, "%s: bad value", val);
+ if_errx(1, "%s: bad value", val);
memcpy(&req.srcv4_addr, &sin.sin_addr, sizeof(req.srcv4_addr));
if (do_cmd(ctx, STF6RD_SV4NET, &req, sizeof(req), 1) < 0)
- err(1, "STF6RD_SV4NET %s", val);
+ if_err(1, "STF6RD_SV4NET %s", val);
}
static struct cmd stf_cmds[] = {
diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c
--- a/sbin/ifconfig/ifvlan.c
+++ b/sbin/ifconfig/ifvlan.c
@@ -58,6 +58,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
#define NOTAG ((u_short) -1)
#define NOPROTO ((u_short) -1)
@@ -79,23 +80,22 @@
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
return;
- printf("\tvlan: %d", vreq.vlr_tag);
- printf(" vlanproto: ");
+ ifvlan_print_vlan(&vreq);
+ ifvlan_print_vlanproto();
switch (vreq.vlr_proto) {
case ETHERTYPE_VLAN:
- printf(proto_8021Q);
+ ifvlan_print_8021q(proto_8021Q);
break;
case ETHERTYPE_QINQ:
- printf(proto_8021ad);
+ ifvlan_print_8021d(proto_8021ad);
break;
default:
- printf("0x%04x", vreq.vlr_proto);
+ ifvlan_print_otherproto(&vreq);
}
if (ioctl_ctx_ifr(ctx, SIOCGVLANPCP, &ifr) != -1)
- printf(" vlanpcp: %u", ifr.ifr_vlan_pcp);
- printf(" parent interface: %s", vreq.vlr_parent[0] == '\0' ?
- "<none>" : vreq.vlr_parent);
- printf("\n");
+ ifvlan_print_vlanpcp(&ifr);
+ ifvlan_print_parent(&vreq);
+ ifconfig_print_newline();
}
static int
@@ -119,16 +119,16 @@
*/
*cp++ = '\0';
if ((*cp < '1') || (*cp > '9'))
- errx(1, "invalid vlan tag");
+ if_errx(1, "invalid vlan tag");
vid = *cp++ - '0';
while ((*cp >= '0') && (*cp <= '9')) {
vid = (vid * 10) + (*cp++ - '0');
if (vid >= 0xFFF)
- errx(1, "invalid vlan tag");
+ if_errx(1, "invalid vlan tag");
}
if (*cp != '\0')
- errx(1, "invalid vlan tag");
+ if_errx(1, "invalid vlan tag");
/*
* allow "devX.Y vlandev devX vlan Y" syntax
@@ -136,13 +136,13 @@
if (params.vlr_tag == NOTAG || params.vlr_tag == vid)
params.vlr_tag = vid;
else
- errx(1, "ambiguous vlan specification");
+ if_errx(1, "ambiguous vlan specification");
/* Restrict overriding interface name */
if (params.vlr_parent[0] == '\0' || !strcmp(params.vlr_parent, ifname))
strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
else
- errx(1, "ambiguous vlan specification");
+ if_errx(1, "ambiguous vlan specification");
}
static void
@@ -155,9 +155,9 @@
* One or both parameters were specified, make sure both.
*/
if (params.vlr_tag == NOTAG)
- errx(1, "must specify a tag for vlan create");
+ if_errx(1, "must specify a tag for vlan create");
if (params.vlr_parent[0] == '\0')
- errx(1, "must specify a parent device for vlan create");
+ if_errx(1, "must specify a parent device for vlan create");
if (params.vlr_proto == NOPROTO)
params.vlr_proto = ETHERTYPE_VLAN;
ifr->ifr_data = (caddr_t) &params;
@@ -169,7 +169,7 @@
vlan_cb(if_ctx *ctx __unused, void *arg __unused)
{
if ((params.vlr_tag != NOTAG) ^ (params.vlr_parent[0] != '\0'))
- errx(1, "both vlan and vlandev must be specified");
+ if_errx(1, "both vlan and vlandev must be specified");
}
static void
@@ -180,7 +180,7 @@
params.vlr_proto = ETHERTYPE_VLAN;
ifr->ifr_data = (caddr_t) &params;
if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1)
- err(1, "SIOCSETVLAN");
+ if_err(1, "SIOCSETVLAN");
}
}
@@ -194,11 +194,11 @@
ul = strtoul(val, &endp, 0);
if (*endp != '\0')
- errx(1, "invalid value for vlan");
+ if_errx(1, "invalid value for vlan");
params.vlr_tag = ul;
/* check if the value can be represented in vlr_tag */
if (params.vlr_tag != ul)
- errx(1, "value for vlan out of range");
+ if_errx(1, "value for vlan out of range");
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
/*
@@ -240,7 +240,7 @@
|| (strncasecmp(proto_qinq, val, strlen(proto_qinq)) == 0)) {
params.vlr_proto = ETHERTYPE_QINQ;
} else
- errx(1, "invalid value for vlanproto");
+ if_errx(1, "invalid value for vlanproto");
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
/*
@@ -266,12 +266,12 @@
ul = strtoul(val, &endp, 0);
if (*endp != '\0')
- errx(1, "invalid value for vlanpcp");
+ if_errx(1, "invalid value for vlanpcp");
if (ul > 7)
- errx(1, "value for vlanpcp out of range");
+ if_errx(1, "value for vlanpcp out of range");
ifr.ifr_vlan_pcp = ul;
if (ioctl_ctx_ifr(ctx, SIOCSVLANPCP, &ifr) == -1)
- err(1, "SIOCSVLANPCP");
+ if_err(1, "SIOCSVLANPCP");
}
static void
@@ -281,13 +281,13 @@
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
- err(1, "SIOCGETVLAN");
+ if_err(1, "SIOCGETVLAN");
bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
vreq.vlr_tag = 0;
if (ioctl_ctx(ctx, SIOCSETVLAN, (caddr_t)&ifr) == -1)
- err(1, "SIOCSETVLAN");
+ if_err(1, "SIOCSETVLAN");
}
static struct cmd vlan_cmds[] = {
diff --git a/sbin/ifconfig/ifvxlan.c b/sbin/ifconfig/ifvxlan.c
--- a/sbin/ifconfig/ifvxlan.c
+++ b/sbin/ifconfig/ifvxlan.c
@@ -49,6 +49,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
static struct ifvxlanparam params = {
.vxlp_vni = VXLAN_VNI_MAX,
@@ -130,24 +131,18 @@
mc = IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr);
}
- printf("\tvxlan vni %d", vni);
- printf(" local %s%s%s:%s", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
- srcport);
- printf(" %s %s%s%s:%s", mc ? "group" : "remote", ipv6 ? "[" : "",
- dst, ipv6 ? "]" : "", dstport);
+ ifvxlan_print_vni(vni);
+ ifvxlan_print_src(ipv6, src, srcport);
+ ifvxlan_print_dst(mc, ipv6, dst, dstport);
if (ctx->args->verbose) {
- printf("\n\t\tconfig: ");
- printf("%slearning portrange %d-%d ttl %d",
- cfg.vxlc_learn ? "" : "no", cfg.vxlc_port_min,
- cfg.vxlc_port_max, cfg.vxlc_ttl);
- printf("\n\t\tftable: ");
- printf("cnt %d max %d timeout %d",
- cfg.vxlc_ftable_cnt, cfg.vxlc_ftable_max,
- cfg.vxlc_ftable_timeout);
+ ifvxlan_print_config();
+ ifvxlan_print_portrange(&cfg);
+ ifvxlan_print_ftable();
+ ifvxlan_print_threshold(&cfg);
}
- putchar('\n');
+ ifconfig_print_newline();
}
#define _LOCAL_ADDR46 \
@@ -160,14 +155,14 @@
{
if ((params.vxlp_with & _LOCAL_ADDR46) == _LOCAL_ADDR46)
- errx(1, "cannot specify both local IPv4 and IPv6 addresses");
+ if_errx(1, "cannot specify both local IPv4 and IPv6 addresses");
if ((params.vxlp_with & _REMOTE_ADDR46) == _REMOTE_ADDR46)
- errx(1, "cannot specify both remote IPv4 and IPv6 addresses");
+ if_errx(1, "cannot specify both remote IPv4 and IPv6 addresses");
if ((params.vxlp_with & VXLAN_PARAM_WITH_LOCAL_ADDR4 &&
params.vxlp_with & VXLAN_PARAM_WITH_REMOTE_ADDR6) ||
(params.vxlp_with & VXLAN_PARAM_WITH_LOCAL_ADDR6 &&
params.vxlp_with & VXLAN_PARAM_WITH_REMOTE_ADDR4))
- errx(1, "cannot mix IPv4 and IPv6 addresses");
+ if_errx(1, "cannot mix IPv4 and IPv6 addresses");
}
#undef _LOCAL_ADDR46
@@ -190,7 +185,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val >= VXLAN_VNI_MAX)
- errx(1, "invalid network identifier: %s", arg);
+ if_errx(1, "invalid network identifier: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_VNI;
@@ -202,7 +197,7 @@
cmd.vxlcmd_vni = val;
if (do_cmd(ctx, VXLAN_CMD_SET_VNI, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_VNI");
+ if_err(1, "VXLAN_CMD_SET_VNI");
}
static void
@@ -218,7 +213,7 @@
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing local address string: %s",
+ if_errx(1, "error in parsing local address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -231,7 +226,7 @@
struct sockaddr_in *sin = satosin(sa);
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "local address cannot be multicast");
+ if_errx(1, "local address cannot be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -242,14 +237,14 @@
struct sockaddr_in6 *sin6 = satosin6(sa);
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "local address cannot be multicast");
+ if_errx(1, "local address cannot be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "local address %s not supported", addr);
+ if_errx(1, "local address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -266,7 +261,7 @@
}
if (do_cmd(ctx, VXLAN_CMD_SET_LOCAL_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_LOCAL_ADDR");
+ if_err(1, "VXLAN_CMD_SET_LOCAL_ADDR");
}
static void
@@ -282,7 +277,7 @@
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing remote address string: %s",
+ if_errx(1, "error in parsing remote address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -295,7 +290,7 @@
struct sockaddr_in *sin = satosin(sa);
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "remote address cannot be multicast");
+ if_errx(1, "remote address cannot be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -306,14 +301,14 @@
struct sockaddr_in6 *sin6 = satosin6(sa);
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "remote address cannot be multicast");
+ if_errx(1, "remote address cannot be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "remote address %s not supported", addr);
+ if_errx(1, "remote address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -330,7 +325,7 @@
}
if (do_cmd(ctx, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
+ if_err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
}
static void
@@ -346,7 +341,7 @@
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing group address string: %s",
+ if_errx(1, "error in parsing group address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -359,7 +354,7 @@
struct sockaddr_in *sin = satosin(sa);
if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "group address must be multicast");
+ if_errx(1, "group address must be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -370,14 +365,14 @@
struct sockaddr_in6 *sin6 = satosin6(sa);
if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "group address must be multicast");
+ if_errx(1, "group address must be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "group address %s not supported", addr);
+ if_errx(1, "group address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -394,7 +389,7 @@
}
if (do_cmd(ctx, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
+ if_err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
}
static void
@@ -404,7 +399,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid local port: %s", arg);
+ if_errx(1, "invalid local port: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_LOCAL_PORT;
@@ -416,7 +411,7 @@
cmd.vxlcmd_port = val;
if (do_cmd(ctx, VXLAN_CMD_SET_LOCAL_PORT, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_LOCAL_PORT");
+ if_err(1, "VXLAN_CMD_SET_LOCAL_PORT");
}
static void
@@ -426,7 +421,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid remote port: %s", arg);
+ if_errx(1, "invalid remote port: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_PORT;
@@ -438,7 +433,7 @@
cmd.vxlcmd_port = val;
if (do_cmd(ctx, VXLAN_CMD_SET_REMOTE_PORT, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_REMOTE_PORT");
+ if_err(1, "VXLAN_CMD_SET_REMOTE_PORT");
}
static void
@@ -448,11 +443,11 @@
u_long min, max;
if (get_val(arg1, &min) < 0 || min >= UINT16_MAX)
- errx(1, "invalid port range minimum: %s", arg1);
+ if_errx(1, "invalid port range minimum: %s", arg1);
if (get_val(arg2, &max) < 0 || max >= UINT16_MAX)
- errx(1, "invalid port range maximum: %s", arg2);
+ if_errx(1, "invalid port range maximum: %s", arg2);
if (max < min)
- errx(1, "invalid port range");
+ if_errx(1, "invalid port range");
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_PORT_RANGE;
@@ -466,7 +461,7 @@
cmd.vxlcmd_port_max = max;
if (do_cmd(ctx, VXLAN_CMD_SET_PORT_RANGE, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_PORT_RANGE");
+ if_err(1, "VXLAN_CMD_SET_PORT_RANGE");
}
static void
@@ -476,7 +471,7 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid timeout value: %s", arg);
+ if_errx(1, "invalid timeout value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_TIMEOUT;
@@ -488,7 +483,7 @@
cmd.vxlcmd_ftable_timeout = val & 0xFFFFFFFF;
if (do_cmd(ctx, VXLAN_CMD_SET_FTABLE_TIMEOUT, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_FTABLE_TIMEOUT");
+ if_err(1, "VXLAN_CMD_SET_FTABLE_TIMEOUT");
}
static void
@@ -498,7 +493,7 @@
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid maxaddr value: %s", arg);
+ if_errx(1, "invalid maxaddr value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_MAX;
@@ -510,7 +505,7 @@
cmd.vxlcmd_ftable_max = val & 0xFFFFFFFF;
if (do_cmd(ctx, VXLAN_CMD_SET_FTABLE_MAX, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_FTABLE_MAX");
+ if_err(1, "VXLAN_CMD_SET_FTABLE_MAX");
}
static void
@@ -529,7 +524,7 @@
strlcpy(cmd.vxlcmd_ifname, arg, sizeof(cmd.vxlcmd_ifname));
if (do_cmd(ctx, VXLAN_CMD_SET_MULTICAST_IF, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_MULTICAST_IF");
+ if_err(1, "VXLAN_CMD_SET_MULTICAST_IF");
}
static void
@@ -539,7 +534,7 @@
u_long val;
if (get_val(arg, &val) < 0 || val > 256)
- errx(1, "invalid TTL value: %s", arg);
+ if_errx(1, "invalid TTL value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_TTL;
@@ -551,7 +546,7 @@
cmd.vxlcmd_ttl = val;
if (do_cmd(ctx, VXLAN_CMD_SET_TTL, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_TTL");
+ if_err(1, "VXLAN_CMD_SET_TTL");
}
static void
@@ -570,7 +565,7 @@
cmd.vxlcmd_flags |= VXLAN_CMD_FLAG_LEARN;
if (do_cmd(ctx, VXLAN_CMD_SET_LEARN, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_LEARN");
+ if_err(1, "VXLAN_CMD_SET_LEARN");
}
static void
@@ -583,7 +578,7 @@
cmd.vxlcmd_flags |= VXLAN_CMD_FLAG_FLUSH_ALL;
if (do_cmd(ctx, VXLAN_CMD_FLUSH, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_FLUSH");
+ if_err(1, "VXLAN_CMD_FLUSH");
}
static struct cmd vxlan_cmds[] = {
diff --git a/sbin/ifconfig/sfp.c b/sbin/ifconfig/sfp.c
--- a/sbin/ifconfig/sfp.c
+++ b/sbin/ifconfig/sfp.c
@@ -44,12 +44,11 @@
#include <string.h>
#include <unistd.h>
-#include <libutil.h>
-
#include <libifconfig.h>
#include <libifconfig_sfp.h>
#include "ifconfig.h"
+#include "ifconfig_output.h"
void
sfp_status(if_ctx *ctx)
@@ -66,45 +65,37 @@
ifconfig_sfp_get_sfp_info_strings(&info, &strings);
- printf("\tplugged: %s %s (%s)\n",
- ifconfig_sfp_id_display(info.sfp_id),
- ifconfig_sfp_physical_spec(&info, &strings),
- strings.sfp_conn);
+ sfp_print_plugged(&info, &strings);
if (ifconfig_sfp_get_sfp_vendor_info(lifh, ctx->ifname, &vendor_info) == -1)
return;
- printf("\tvendor: %s PN: %s SN: %s DATE: %s\n",
- vendor_info.name, vendor_info.pn, vendor_info.sn, vendor_info.date);
+ sfp_print_vendor(&vendor_info);
if (ifconfig_sfp_id_is_cmis(info.sfp_id)) {
/* CMIS: no legacy compliance info to show */
} else if (ifconfig_sfp_id_is_qsfp(info.sfp_id)) {
if (verbose > 1)
- printf("\tcompliance level: %s\n", strings.sfp_rev);
+ sfp_print_verbose_compliance(&strings);
} else {
if (verbose > 5) {
- printf("Class: %s\n",
- ifconfig_sfp_physical_spec(&info, &strings));
- printf("Length: %s\n", strings.sfp_fc_len);
- printf("Tech: %s\n", strings.sfp_cab_tech);
- printf("Media: %s\n", strings.sfp_fc_media);
- printf("Speed: %s\n", strings.sfp_fc_speed);
+ sfp_print_verbose_class(&info, &strings);
+ sfp_print_verbose_length(&strings);
+ sfp_print_verbose_tech(&strings);
+ sfp_print_verbose_media(&strings);
+ sfp_print_verbose_speed(&strings);
}
}
if (ifconfig_sfp_get_sfp_status(lifh, ctx->ifname, &status) == 0) {
if (ifconfig_sfp_id_is_qsfp(info.sfp_id) && verbose > 1)
- printf("\tnominal bitrate: %u Mbps\n", status.bitrate);
- printf("\tmodule temperature: %.2f C voltage: %.2f Volts\n",
- status.temp, status.voltage);
+ sfp_print_verbose_nombitrate(&status);
+ sfp_print_verbose_voltage(&status);
channel_count = ifconfig_sfp_channel_count(&info);
for (size_t chan = 0; chan < channel_count; ++chan) {
uint16_t rx = status.channel[chan].rx;
uint16_t tx = status.channel[chan].tx;
- printf("\tlane %zu: "
- "RX power: %.2f mW (%.2f dBm) TX bias: %.2f mA\n",
- chan + 1, power_mW(rx), power_dBm(rx), bias_mA(tx));
+ sfp_print_verbose_rxpower(chan, rx, tx);
}
ifconfig_sfp_free_sfp_status(&status);
}
@@ -116,26 +107,17 @@
return;
if (ifconfig_sfp_id_is_cmis(info.sfp_id)) {
- printf("\n\tCMIS DUMP (Lower Memory 0..127):\n");
- hexdump(dump.data, 128,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
- printf("\n\tCMIS DUMP (Page 00h 128..255):\n");
- hexdump(dump.data + 128, 128,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
- printf("\n\tCMIS DUMP (Page 11h 128..255):\n");
- hexdump(dump.data + CMIS_DUMP_P11, 128,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
+ sfp_print_verbose_cmis_dump1(dump.data, 128);
+ sfp_print_verbose_cmis_dump2(dump.data + 128, 128);
+ sfp_print_verbose_cmis_dump3(dump.data + CMIS_DUMP_P11,
+ 128);
} else if (ifconfig_sfp_id_is_qsfp(info.sfp_id)) {
- printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
- hexdump(dump.data + QSFP_DUMP1_START, QSFP_DUMP1_SIZE,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
- printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
- hexdump(dump.data + QSFP_DUMP0_START, QSFP_DUMP0_SIZE,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
+ sfp_print_verbose_sff8436_dump1(
+ dump.data + QSFP_DUMP1_START, QSFP_DUMP1_SIZE);
+ sfp_print_verbose_sff8436_dump2(
+ dump.data + QSFP_DUMP0_START, QSFP_DUMP0_SIZE);
} else {
- printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
- hexdump(dump.data + SFP_DUMP_START, SFP_DUMP_SIZE,
- "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);
+ sfp_print_verbose_sff8472_dump1(dump.data);
}
}
}
diff --git a/sbin/ifconfig/tests/Makefile b/sbin/ifconfig/tests/Makefile
--- a/sbin/ifconfig/tests/Makefile
+++ b/sbin/ifconfig/tests/Makefile
@@ -1,6 +1,10 @@
+SUBDIR= with-libxo \
+ without-libxo
+
NETBSD_ATF_TESTS_SH= nonexistent_test
ATF_TESTS_SH+= ifconfig \
- inet6
+ inet6 \
+ libxo
TEST_METADATA+= execenv="jail"
TEST_METADATA+= execenv_jail_params="vnet allow.raw_sockets"
diff --git a/sbin/ifconfig/tests/Makefile.inc b/sbin/ifconfig/tests/Makefile.inc
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/tests/Makefile.inc
@@ -0,0 +1,94 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Stormshield
+#
+# Shared build definitions for the two ifconfig variants used by the libxo
+# output consistency test. They are built in separate subdirectories because
+# bsd.progs.mk cannot compile the same sources with different CFLAGS (the
+# object files would be shared between the two programs).
+
+.if !target(__<sbin_ifconfig_tests_makefile_inc>__)
+__<sbin_ifconfig_tests_makefile_inc>__: .NOTMAIN
+
+.include <src.opts.mk>
+.include <bsd.own.mk>
+
+PROG= ifconfig
+
+#
+# NB: The order here defines the order in which the constructors
+# are called. This in turn defines the default order in which
+# status is displayed. It must match sbin/ifconfig/Makefile.
+#
+SRCS= ../../ifconfig.c \
+ ../../af_link.c
+.if ${MK_INET_SUPPORT} != "no"
+SRCS+= ../../af_inet.c
+.endif
+.if ${MK_INET6_SUPPORT} != "no"
+SRCS+= ../../af_inet6.c \
+ ../../af_nd6.c \
+ ../../ifstf.c
+.endif
+SRCS+= ../../ifclone.c \
+ ../../ifmac.c \
+ ../../ifmedia.c \
+ ../../iffib.c \
+ ../../ifvlan.c \
+ ../../ifvxlan.c \
+ ../../ifgre.c \
+ ../../ifgif.c \
+ ../../ifipsec.c \
+ ../../sfp.c
+.if ${MK_WIRELESS_SUPPORT} != "no"
+SRCS+= ../../ifieee80211.c
+.endif
+SRCS+= ../../carp.c \
+ ../../ifgroup.c
+.if ${MK_PF} != "no"
+SRCS+= ../../ifpfsync.c
+.endif
+SRCS+= ../../ifbridge.c \
+ ../../iflagg.c \
+ ../../ifconfig_output.c
+.if ${MK_NETLINK_SUPPORT} != "no"
+SRCS+= ../../ifconfig_netlink.c \
+ ../../ifgeneve.c
+.endif
+
+CFLAGS+= -I${SRCTOP}/lib/libifconfig -I${OBJTOP}/lib/libifconfig
+.if ${MK_INET6_SUPPORT} != "no"
+CFLAGS+= -DINET6
+.endif
+.if ${MK_INET_SUPPORT} != "no"
+CFLAGS+= -DINET
+.endif
+.if ${MK_JAIL} != "no"
+CFLAGS+= -DJAIL
+.endif
+.if ${MK_NETLINK_SUPPORT} == "no"
+CFLAGS+= -DWITHOUT_NETLINK
+.endif
+CFLAGS+= -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings \
+ -Wnested-externs
+
+LIBADD+= ifconfig m util xo nv
+.if ${MK_WIRELESS_SUPPORT} != "no"
+LIBADD+= 80211
+.endif
+.if ${MK_JAIL} != "no"
+LIBADD+= jail
+.endif
+
+TESTSDIR= ${TESTSBASE}/sbin/ifconfig/${.CURDIR:T}
+BINDIR= ${TESTSDIR}
+PACKAGE= tests
+MAN=
+
+# The parent tests directory installs into ${TESTSBASE}/sbin/ifconfig, so the
+# per-variant binaries live right next to the libxo test script. Create the
+# install directory since manual "make install" does not run hierarchy(7).
+beforeinstall:
+ ${INSTALL} -d ${DESTDIR}${BINDIR}
+
+.endif
\ No newline at end of file
diff --git a/sbin/ifconfig/tests/libxo.sh b/sbin/ifconfig/tests/libxo.sh
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/tests/libxo.sh
@@ -0,0 +1,90 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Paige Thompson
+
+. $(atf_get_srcdir)/../../sys/common/vnet.subr
+
+atf_test_case "libxo_output_consistency" "cleanup"
+libxo_output_consistency_head()
+{
+ atf_set descr "ifconfig output must be identical with and without libxo"
+ atf_set require.user root
+}
+
+# Run the same command with both binaries and compare stdout and stderr.
+libxo_compare_cmd()
+{
+ local plain_out plain_err xo_out xo_err
+
+ plain_out=$(mktemp)
+ plain_err=$(mktemp)
+ xo_out=$(mktemp)
+ xo_err=$(mktemp)
+
+ atf_check -s exit:0 -o save:${plain_out} -e save:${plain_err} \
+ ${ifc_nolibxo} "$@"
+ atf_check -s exit:0 -o save:${xo_out} -e save:${xo_err} \
+ ${ifc_libxo} "$@"
+
+ atf_check -s exit:0 diff -u ${plain_out} ${xo_out}
+ atf_check -s exit:0 diff -u ${plain_err} ${xo_err}
+
+ rm -f ${plain_out} ${plain_err} ${xo_out} ${xo_err}
+}
+
+libxo_output_consistency_body()
+{
+ local iftype iface
+
+ vnet_init
+
+ ifc_libxo=$(atf_get_srcdir)/with-libxo/ifconfig
+ ifc_nolibxo=$(atf_get_srcdir)/without-libxo/ifconfig
+
+ # Create the interfaces used to exercise the bridge, lagg and vlan
+ # printing paths with explicit high unit numbers.
+ ${ifc_nolibxo} epair254 create >/dev/null 2>&1 || true
+ ${ifc_nolibxo} bridge254 create >/dev/null 2>&1 || true
+ ${ifc_nolibxo} lagg254 create >/dev/null 2>&1 || true
+
+ # Wire them up.
+ ${ifc_nolibxo} epair254a up >/dev/null 2>&1 || true
+ ${ifc_nolibxo} epair254b up >/dev/null 2>&1 || true
+ ${ifc_nolibxo} bridge254 addm epair254a >/dev/null 2>&1 || true
+ ${ifc_nolibxo} lagg254 laggproto failover laggport epair254b \
+ >/dev/null 2>&1 || true
+ ${ifc_nolibxo} vlan254 create vlan 42 vlandev epair254a \
+ >/dev/null 2>&1 || true
+
+ # Create every cloneable interface type the kernel supports, skipping
+ # the types created above and any that cannot be created (e.g. unloaded
+ # modules).
+ for iftype in $(${ifc_nolibxo} -C); do
+ case ${iftype} in
+ epair|bridge|lagg|vlan)
+ continue
+ ;;
+ esac
+ ${ifc_nolibxo} ${iftype} create >/dev/null 2>&1 || true
+ done
+
+ # Full listing, both summary and verbose.
+ libxo_compare_cmd
+ libxo_compare_cmd -v
+ libxo_compare_cmd -vv
+ libxo_compare_cmd -m
+
+ # Per-interface verbose output.
+ for iface in $(${ifc_nolibxo} -l); do
+ libxo_compare_cmd -vv ${iface}
+ done
+}
+libxo_output_consistency_cleanup()
+{
+ vnet_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case libxo_output_consistency
+}
diff --git a/sbin/ifconfig/tests/with-libxo/Makefile b/sbin/ifconfig/tests/with-libxo/Makefile
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/tests/with-libxo/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Paige Thompson
+
+CFLAGS+= -DWITH_LIBXO
+
+.include "../Makefile.inc"
+.include <bsd.prog.mk>
diff --git a/sbin/ifconfig/tests/without-libxo/Makefile b/sbin/ifconfig/tests/without-libxo/Makefile
new file mode 100644
--- /dev/null
+++ b/sbin/ifconfig/tests/without-libxo/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Paige Thompson
+
+.include "../Makefile.inc"
+.include <bsd.prog.mk>

File Metadata

Mime Type
text/plain
Expires
Wed, Aug 26, 7:31 PM (1 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37291331
Default Alt Text
D58560.id.diff (392 KB)

Event Timeline