Skip to content

Instantly share code, notes, and snippets.

@paigeadelethompson
Last active July 30, 2026 13:37
Show Gist options
  • Select an option

  • Save paigeadelethompson/5dd1b998d599ed7d147fd37a6aa90b2e to your computer and use it in GitHub Desktop.

Select an option

Save paigeadelethompson/5dd1b998d599ed7d147fd37a6aa90b2e to your computer and use it in GitHub Desktop.
diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
index 2553e61b5e9..ce778ad4848 100644
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -35,7 +35,7 @@ SRCS+= ifgif.c # GIF reversed header workaround
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"
diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
index 4fd74d481b3..9aed309788b 100644
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -47,6 +47,8 @@
#include <arpa/inet.h>
#include <netdb.h>
+#include <libxo/xo.h>
+
#include "ifconfig.h"
#include "ifconfig_netlink.h"
@@ -91,7 +93,7 @@ print_addr(struct sockaddr_in *sin)
if (error)
inet_ntop(AF_INET, &sin->sin_addr, addr_buf, sizeof(addr_buf));
- printf("\tinet %s", addr_buf);
+ xo_emit("\tinet {:inet-addr/%s}", addr_buf);
}
#ifdef WITHOUT_NETLINK
@@ -110,7 +112,7 @@ in_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
sin = satosin(ifa->ifa_dstaddr);
if (sin == NULL)
sin = &null_sin;
- printf(" --> %s", inet_ntoa(sin->sin_addr));
+ xo_emit(" --> {:dst-addr/%s}", inet_ntoa(sin->sin_addr));
}
sin = satosin(ifa->ifa_netmask);
@@ -127,21 +129,21 @@ in_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
if (cidr == 0)
break;
}
- printf("/%d", cidr);
+ xo_emit("/{:prefixlen/%d}", cidr);
} else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
- printf(" netmask %s", inet_ntoa(sin->sin_addr));
+ xo_emit(" netmask {:netmask/%s}", inet_ntoa(sin->sin_addr));
else
- printf(" netmask 0x%lx", (unsigned long)ntohl(sin->sin_addr.s_addr));
+ xo_emit(" netmask {:netmask/0x%lx}", (unsigned long)ntohl(sin->sin_addr.s_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));
+ xo_emit(" broadcast {:broadcast/%s}", inet_ntoa(sin->sin_addr));
}
print_vhid(ifa);
- putchar('\n');
+ xo_emit("\n");
}
#else
@@ -166,25 +168,25 @@ in_status_nl(if_ctx *ctx __unused, if_link_t *link, if_addr_t *ifa)
if (link->ifi_flags & IFF_POINTOPOINT) {
struct sockaddr_in *dst = satosin(ifa->ifa_address);
- printf(" --> %s", inet_ntoa(dst->sin_addr));
+ xo_emit(" --> {:dst-addr/%s}", inet_ntoa(dst->sin_addr));
}
if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
- printf("/%d", plen);
+ xo_emit("/{:prefixlen/%d}", plen);
} else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
- printf(" netmask %s", inet_ntoa(get_mask(plen)));
+ xo_emit(" netmask {:netmask/%s}", inet_ntoa(get_mask(plen)));
else
- printf(" netmask 0x%lx", (unsigned long)ntohl(get_mask(plen).s_addr));
+ xo_emit(" netmask {:netmask/0x%lx}", (unsigned long)ntohl(get_mask(plen).s_addr));
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));
+ xo_emit(" broadcast {:broadcast/%s}", inet_ntoa(brd->sin_addr));
}
if (ifa->ifaf_vhid != 0)
- printf(" vhid %d", ifa->ifaf_vhid);
+ xo_emit(" vhid {:vhid/%d}", ifa->ifaf_vhid);
- putchar('\n');
+ xo_emit("\n");
}
#endif
@@ -227,7 +229,7 @@ in_getaddr(const char *s, int which)
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
if (errstr != NULL) {
*p = '/';
- errx(1, "%s: bad value (width %s)", s, errstr);
+ xo_errx(1, "%s: bad value (width %s)", s, errstr);
}
min->sin_family = AF_INET;
min->sin_len = sizeof(*min);
@@ -244,7 +246,7 @@ in_getaddr(const char *s, int which)
else if ((np = getnetbyname(s)) != NULL)
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
else
- errx(1, "%s: bad value", s);
+ xo_errx(1, "%s: bad value", s);
}
#else
@@ -278,7 +280,7 @@ in_getip(const char *addr_str, struct in_addr *ip)
else if ((np = getnetbyname(addr_str)) != NULL)
*ip = inet_makeaddr(np->n_net, INADDR_ANY);
else
- errx(1, "%s: bad value", addr_str);
+ xo_errx(1, "%s: bad value", addr_str);
}
static void
@@ -310,7 +312,7 @@ in_getaddr(const char *s, int which)
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
if (errstr != NULL) {
*p = '/';
- errx(1, "%s: bad value (width %s)", s, errstr);
+ xo_errx(1, "%s: bad value (width %s)", s, errstr);
}
px->plen = masklen;
px->maskset = true;
@@ -371,7 +373,7 @@ in_delete_first_nl(if_ctx *ctx)
}
if (e.error != 0) {
if (e.error_str != NULL)
- warnx("%s(): %s", __func__, e.error_str);
+ xo_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -391,7 +393,7 @@ in_delete_first_nl(if_ctx *ctx)
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);
+ xo_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -432,7 +434,7 @@ in_exec_nl(if_ctx *ctx, unsigned long action, void *data)
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);
+ xo_warnx("%s(): %s", __func__, e.error_str);
return (e.error);
}
@@ -442,7 +444,7 @@ static void
err_nomask(int ifflags)
{
if ((ifflags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) {
- errx(1, "ERROR: setting interface address without mask is no longer supported.");
+ xo_errx(1, "ERROR: setting interface address without mask is no longer supported.");
}
}
@@ -485,7 +487,7 @@ in_status_tunnel(if_ctx *ctx)
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);
+ xo_emit("\ttunnel inet {:tunnel-src/%s} --> {:tunnel-dst/%s}\n", src, dst);
}
static void
@@ -499,7 +501,7 @@ in_set_tunnel(if_ctx *ctx, struct addrinfo *srcres, struct addrinfo *dstres)
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len);
if (ioctl_ctx(ctx, SIOCSIFPHYADDR, &addreq) < 0)
- warn("SIOCSIFPHYADDR");
+ xo_warn("SIOCSIFPHYADDR");
}
static void
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c
index e0f34f0c4d8..f1b6d48c4e2 100644
--- a/sbin/ifconfig/af_inet6.c
+++ b/sbin/ifconfig/af_inet6.c
@@ -51,6 +51,8 @@
#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */
+#include <libxo/xo.h>
+
#include "ifconfig.h"
#include "ifconfig_netlink.h"
@@ -105,7 +107,7 @@ setifprefixlen(if_ctx *ctx __netlink_unused, const char *addr, int dummy __unuse
int plen = strtol(addr, NULL, 10);
if ((plen < 0) || (plen > 128))
- errx(1, "%s: bad value", addr);
+ xo_errx(1, "%s: bad value", addr);
in6_add.addr.plen = plen;
#endif
explicit_prefix = 1;
@@ -117,7 +119,7 @@ setip6flags(if_ctx *ctx, const char *dummyaddr __unused, int flag)
const struct afswtch *afp = ctx->afp;
if (afp->af_af != AF_INET6)
- err(1, "address flags can be set only for inet6 addresses");
+ xo_err(1, "address flags can be set only for inet6 addresses");
#ifdef WITHOUT_NETLINK
if (flag < 0)
@@ -148,9 +150,9 @@ setip6lifetime(if_ctx *ctx, const char *cmd, const char *val)
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
newval = (time_t)strtoul(val, &ep, 0);
if (val == ep)
- errx(1, "invalid %s", cmd);
+ xo_errx(1, "invalid %s", cmd);
if (afp->af_af != AF_INET6)
- errx(1, "%s not allowed for the AF", cmd);
+ xo_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 @@ setip6eui64(if_ctx *ctx, const char *cmd, int dummy __unused)
struct in6_addr *in6;
if (afp->af_af != AF_INET6)
- errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
+ xo_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");
+ xo_errx(EXIT_FAILURE, "interface index is already filled");
if (getifaddrs(&ifap) != 0)
- err(EXIT_FAILURE, "getifaddrs");
+ xo_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,7 +205,7 @@ setip6eui64(if_ctx *ctx, const char *cmd, int dummy __unused)
}
}
if (!lladdr)
- errx(EXIT_FAILURE, "could not determine link local address");
+ xo_errx(EXIT_FAILURE, "could not determine link local address");
memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
@@ -227,7 +229,7 @@ print_addr(struct sockaddr_in6 *sin)
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
sizeof(addr_buf));
- printf("\tinet6 %s", addr_buf);
+ xo_emit("\tinet6 {:inet6-addr/%s}", addr_buf);
}
static void
@@ -240,48 +242,49 @@ print_p2p(struct sockaddr_in6 *sin)
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, sizeof(addr_buf));
- printf(" --> %s", addr_buf);
+ xo_emit(" --> {:dst-addr/%s}", addr_buf);
}
static void
print_mask(int plen)
{
if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
- printf("/%d", plen);
+ xo_emit("/{:prefixlen/%d}", plen);
else
- printf(" prefixlen %d", plen);
+ xo_emit(" prefixlen {:prefixlen/%d}", plen);
}
static void
print_flags(int flags6)
{
+ xo_open_list("flags6");
if ((flags6 & IN6_IFF_ANYCAST) != 0)
- printf(" anycast");
+ xo_emit(" {P:/anycast}{le:flags6/%s}", "anycast");
if ((flags6 & IN6_IFF_TENTATIVE) != 0)
- printf(" tentative");
+ xo_emit(" {P:/tentative}{le:flags6/%s}", "tentative");
if ((flags6 & IN6_IFF_DUPLICATED) != 0)
- printf(" duplicated");
+ xo_emit(" {P:/duplicated}{le:flags6/%s}", "duplicated");
if ((flags6 & IN6_IFF_DETACHED) != 0)
- printf(" detached");
+ xo_emit(" {P:/detached}{le:flags6/%s}", "detached");
if ((flags6 & IN6_IFF_DEPRECATED) != 0)
- printf(" deprecated");
+ xo_emit(" {P:/deprecated}{le:flags6/%s}", "deprecated");
if ((flags6 & IN6_IFF_AUTOCONF) != 0)
- printf(" autoconf");
+ xo_emit(" {P:/autoconf}{le:flags6/%s}", "autoconf");
if ((flags6 & IN6_IFF_TEMPORARY) != 0)
- printf(" temporary");
+ xo_emit(" {P:/temporary}{le:flags6/%s}", "temporary");
if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
- printf(" prefer_source");
-
+ xo_emit(" {P:/prefer_source}{le:flags6/%s}", "prefer_source");
+ xo_close_list("flags6");
}
static void
print_lifetime(const char *prepend, time_t px_time, struct timespec *now)
{
- printf(" %s", prepend);
+ xo_emit(" {P:/%s}", prepend);
if (px_time == 0)
- printf(" infty");
+ xo_emit(" {P:/infty}");
- printf(" %s", px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
+ xo_emit(" {P:/%s}", px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
}
#ifdef WITHOUT_NETLINK
@@ -300,12 +303,12 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
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)");
+ xo_warn("socket(AF_INET6,SOCK_DGRAM)");
return;
}
ifr6.ifr_addr = *sin;
if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
- warn("ioctl(SIOCGIFAFLAG_IN6)");
+ xo_warn("ioctl(SIOCGIFAFLAG_IN6)");
close(s6);
return;
}
@@ -313,7 +316,7 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
memset(&lifetime, 0, sizeof(lifetime));
ifr6.ifr_addr = *sin;
if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
- warn("ioctl(SIOCGIFALIFETIME_IN6)");
+ xo_warn("ioctl(SIOCGIFALIFETIME_IN6)");
close(s6);
return;
}
@@ -340,7 +343,7 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
print_flags(flags6);
if ((satosin6(ifa->ifa_addr))->sin6_scope_id)
- printf(" scopeid 0x%x",
+ xo_emit(" scopeid {:scopeid/0x%x}",
(satosin6(ifa->ifa_addr))->sin6_scope_id);
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
@@ -353,7 +356,7 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
print_vhid(ifa);
- putchar('\n');
+ xo_emit("\n");
}
#else
@@ -399,14 +402,14 @@ in6_status_nl(if_ctx *ctx __unused, if_link_t *link __unused, if_addr_t *ifa)
print_flags(ifa->ifaf_flags);
if (scopeid != 0)
- printf(" scopeid 0x%x", scopeid);
+ xo_emit(" scopeid {:scopeid/0x%x}", scopeid);
show_lifetime(ifa->ifa_cacheinfo);
if (ifa->ifaf_vhid != 0)
- printf(" vhid %d", ifa->ifaf_vhid);
+ xo_emit(" vhid {:vhid/%d}", ifa->ifaf_vhid);
- putchar('\n');
+ xo_emit("\n");
}
static struct in6_px *sin6tab_nl[] = {
@@ -429,9 +432,9 @@ in6_getaddr(const char *addr_str, int which)
struct in6_px *px = sin6tab_nl[which];
if (which == MASK)
- errx(1, "netmask: invalid option for inet6");
+ xo_errx(1, "netmask: invalid option for inet6");
if (which == BRDADDR)
- errx(1, "broadcast: invalid option for inet6");
+ xo_errx(1, "broadcast: invalid option for inet6");
px->set = true;
px->plen = 128;
@@ -441,7 +444,7 @@ in6_getaddr(const char *addr_str, int which)
*p = '\0';
int plen = strtol(p + 1, NULL, 10);
if (plen < 0 || plen > 128)
- errx(1, "%s: bad value", p + 1);
+ xo_errx(1, "%s: bad value", p + 1);
px->plen = plen;
explicit_prefix = 1;
}
@@ -453,7 +456,7 @@ in6_getaddr(const char *addr_str, int which)
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);
+ xo_errx(1, "%s: bad value", addr_str);
} else {
struct sockaddr_in6 *sin6;
@@ -523,7 +526,7 @@ in6_getprefix(const char *plen, int which)
int len = atoi(plen);
if ((len < 0) || (len > 128))
- errx(1, "%s: bad value", plen);
+ xo_errx(1, "%s: bad value", plen);
sin->sin6_len = sizeof(*sin);
if (which != MASK)
sin->sin6_family = AF_INET6;
@@ -563,7 +566,7 @@ in6_getaddr(const char *s, int which)
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);
+ xo_errx(1, "%s: bad value", s);
} else {
bcopy(res->ai_addr, sin, res->ai_addrlen);
freeaddrinfo(res);
@@ -669,7 +672,7 @@ in6_status_tunnel(if_ctx *ctx)
NI_NUMERICHOST) != 0)
dst[0] = '\0';
- printf("\ttunnel inet6 %s --> %s\n", src, dst);
+ xo_emit("\ttunnel inet6 {:tunnel-src/%s} --> {:tunnel-dst/%s}\n", src, dst);
}
static void
@@ -683,7 +686,7 @@ in6_set_tunnel(if_ctx *ctx, struct addrinfo *srcres, struct addrinfo *dstres)
dstres->ai_addr->sa_len);
if (ioctl_ctx(ctx, SIOCSIFPHYADDR_IN6, &in6_req) < 0)
- warn("SIOCSIFPHYADDR_IN6");
+ xo_warn("SIOCSIFPHYADDR_IN6");
}
static void
diff --git a/sbin/ifconfig/af_link.c b/sbin/ifconfig/af_link.c
index 55b75d847c1..80bcb5332a1 100644
--- a/sbin/ifconfig/af_link.c
+++ b/sbin/ifconfig/af_link.c
@@ -45,6 +45,8 @@
#include <net/if_types.h>
#include <net/ethernet.h>
+#include <libxo/xo.h>
+
#include "ifconfig.h"
#include "ifconfig_netlink.h"
@@ -81,7 +83,9 @@ print_ether(const struct ether_addr *addr, const char *prefix)
ether_format[14] = '\0';
}
}
- printf("\t%s %s\n", prefix, ether_format);
+ xo_open_instance("link-address");
+ xo_emit("{P:\t}{:addr-type/%s} {:link-addr/%s}\n", prefix, ether_format);
+ xo_close_instance("link-address");
}
static void
@@ -91,7 +95,9 @@ print_lladdr(struct sockaddr_dl *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);
+ xo_open_instance("link-address");
+ xo_emit("{P:\t}lladdr {:link-addr/%s}\n", link_ntoa(sdl) + n);
+ xo_close_instance("link-address");
}
}
@@ -102,7 +108,7 @@ print_pcp(if_ctx *ctx)
if (ioctl_ctx_ifr(ctx, SIOCGLANPCP, &ifr) == 0 &&
ifr.ifr_lan_pcp != IFNET_PCP_NONE)
- printf("\tpcp %d\n", ifr.ifr_lan_pcp);
+ xo_emit("\tpcp {:pcp/%d}\n", ifr.ifr_lan_pcp);
}
#ifdef WITHOUT_NETLINK
@@ -119,6 +125,7 @@ link_status(if_ctx *ctx, const struct ifaddrs *ifa)
if (sdl == NULL || sdl->sdl_alen == 0)
return;
+ xo_open_list("link-address");
print_lladdr(sdl);
/*
@@ -131,30 +138,38 @@ link_status(if_ctx *ctx, const struct ifaddrs *ifa)
*/
if ((sdl->sdl_type != IFT_ETHER &&
sdl->sdl_type != IFT_IEEE8023ADLAG) ||
- sdl->sdl_alen != ETHER_ADDR_LEN)
+ sdl->sdl_alen != ETHER_ADDR_LEN) {
+ xo_close_list("link-address");
return;
+ }
strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
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)");
+ xo_warn("socket(AF_LOCAL,SOCK_DGRAM)");
+ xo_close_list("link-address");
return;
}
rc = ioctl(sock_hw, SIOCGHWADDR, &ifr);
close(sock_hw);
- if (rc != 0)
+ if (rc != 0) {
+ xo_close_list("link-address");
return;
+ }
/*
* If this is definitely a lagg device or the hwaddr
* matches the link addr, don't bother.
*/
if (memcmp(ifr.ifr_addr.sa_data, laggaddr, sdl->sdl_alen) == 0 ||
- memcmp(ifr.ifr_addr.sa_data, LLADDR(sdl), sdl->sdl_alen) == 0)
+ memcmp(ifr.ifr_addr.sa_data, LLADDR(sdl), sdl->sdl_alen) == 0) {
+ xo_close_list("link-address");
goto pcp;
+ }
print_ether((const struct ether_addr *)&ifr.ifr_addr.sa_data, "hwaddr");
+ xo_close_list("link-address");
pcp:
print_pcp(ctx);
}
@@ -172,6 +187,7 @@ link_status_nl(if_ctx *ctx, if_link_t *link, if_addr_t *ifa __unused)
.sdl_alen = NLA_DATA_LEN(link->ifla_address),
};
memcpy(LLADDR(&sdl), NLA_DATA(link->ifla_address), sdl.sdl_alen);
+ xo_open_list("link-address");
print_lladdr(&sdl);
if (link->iflaf_orig_hwaddr != NULL) {
@@ -180,6 +196,7 @@ link_status_nl(if_ctx *ctx, if_link_t *link, if_addr_t *ifa __unused)
if (memcmp(NLA_DATA(hwaddr), NLA_DATA(link->ifla_address), sdl.sdl_alen))
print_ether((struct ether_addr *)NLA_DATA(hwaddr), "hwaddr");
}
+ xo_close_list("link-address");
}
if (convert_iftype(link->ifi_type) == IFT_ETHER)
print_pcp(ctx);
@@ -194,7 +211,7 @@ link_getaddr(const char *addr, int which)
struct sockaddr *sa = &link_ridreq.ifr_addr;
if (which != ADDR)
- errx(1, "can't set link-level netmask or broadcast");
+ xo_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 +223,16 @@ link_getaddr(const char *addr, int which)
sdl.sdl_data[0] |= 0x02;
} else {
if ((temp = malloc(strlen(addr) + 2)) == NULL)
- errx(1, "malloc failed");
+ xo_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");
+ xo_errx(1, "malformed link-level address");
free(temp);
}
if (sdl.sdl_alen > sizeof(sa->sa_data))
- errx(1, "malformed link-level address");
+ xo_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
index 2899ad6a077..d6f28c32bb5 100644
--- a/sbin/ifconfig/af_nd6.c
+++ b/sbin/ifconfig/af_nd6.c
@@ -49,6 +49,8 @@
#include <netinet6/nd6.h>
+#include <libxo/xo.h>
+
#include "ifconfig.h"
#define MAX_SYSCTL_TRY 5
@@ -83,7 +85,7 @@ setnd6flags(if_ctx *ctx, const char *dummyaddr __unused, int d)
strlcpy(nd.ifname, ctx->ifname, sizeof(nd.ifname));
error = ioctl_ctx(ctx, SIOCGIFINFO_IN6, &nd);
if (error) {
- warn("ioctl(SIOCGIFINFO_IN6)");
+ xo_warn("ioctl(SIOCGIFINFO_IN6)");
return;
}
if (d < 0)
@@ -92,7 +94,7 @@ setnd6flags(if_ctx *ctx, const char *dummyaddr __unused, int d)
nd.ndi.flags |= d;
error = ioctl_ctx(ctx, SIOCSIFINFO_IN6, (caddr_t)&nd);
if (error)
- warn("ioctl(SIOCSIFINFO_IN6)");
+ xo_warn("ioctl(SIOCSIFINFO_IN6)");
}
void
@@ -111,14 +113,14 @@ setnd6defif(if_ctx *ctx, const char *dummyaddr __unused, int d)
} else
return;
} else if ((ifindex = if_nametoindex(ndifreq.ifname)) == 0) {
- warn("if_nametoindex(%s)", ndifreq.ifname);
+ xo_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)");
+ xo_warn("ioctl(SIOCSDEFIFACE_IN6)");
}
static int
@@ -133,7 +135,7 @@ isnd6defif(if_ctx *ctx, int s)
ifindex = if_nametoindex(ndifreq.ifname);
error = ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq);
if (error) {
- warn("ioctl(SIOCGDEFIFACE_IN6)");
+ xo_warn("ioctl(SIOCGDEFIFACE_IN6)");
return (error);
}
return (ndifreq.ifindex == ifindex);
@@ -151,13 +153,13 @@ nd6_status(if_ctx *ctx)
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)");
+ xo_warn("socket(AF_INET6, SOCK_DGRAM)");
return;
}
error = ioctl(s6, SIOCGIFINFO_IN6, &nd);
if (error) {
if (errno != EPFNOSUPPORT)
- warn("ioctl(SIOCGIFINFO_IN6)");
+ xo_warn("ioctl(SIOCGIFINFO_IN6)");
close(s6);
return;
}
@@ -166,7 +168,9 @@ nd6_status(if_ctx *ctx)
if (nd.ndi.flags == 0 && !isdefif)
return;
bits = (nd.ndi.flags | (isdefif << 15));
- printf("\tnd6 options=%x", bits);
+ xo_open_container("nd6-options");
+ xo_emit("\tnd6 options={:options-hex/%x}", bits);
print_bits("options", &bits, 1, ND6BITS, nitems(ND6BITS));
- putchar('\n');
+ xo_emit("\n");
+ xo_close_container("nd6-options");
}
diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c
index 7c7398f92d4..983233e679e 100644
--- a/sbin/ifconfig/carp.c
+++ b/sbin/ifconfig/carp.c
@@ -54,6 +54,7 @@
#include <netdb.h>
#include <libifconfig.h>
+#include <libxo/xo.h>
#include "ifconfig.h"
@@ -84,22 +85,24 @@ carp_status(if_ctx *ctx)
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",
+ xo_emit("{P:\tcarp: }{:carp-state/%s}{P: vhid }{:vhid/%d}"
+ "{P: advbase }{:advbase/%d}{P: advskew }{:advskew/%d}",
carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,
carpr[i].carpr_advbase, carpr[i].carpr_advskew);
if (ctx->args->printkeys && carpr[i].carpr_key[0] != '\0')
- printf(" key \"%s\"\n", carpr[i].carpr_key);
+ xo_emit("{P: key \"}{:carp_key/%s}{P:\"}\n", carpr[i].carpr_key);
else
- printf("\n");
+ xo_emit("\n");
inet_ntop(AF_INET6, &carpr[i].carpr_addr6, addr_buf,
sizeof(addr_buf));
- printf("\t peer %s peer6 %s\n",
+ xo_emit("{P:\t peer }{:carp_peer/%s}{P: peer6 }{:carp_peer6/%s}\n",
inet_ntoa(carpr[i].carpr_addr), addr_buf);
break;
case CARP_VERSION_VRRPv3:
- printf("\tvrrp: %s vrid %d prio %d interval %d\n",
+ xo_emit("{P:\tvrrp: }{:vrrp_state/%s}{P: vrid }{:vrid/%d}"
+ "{P: prio }{:vrrp_prio/%d}{P: interval }{:vrrp_interval/%d}\n",
carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,
carpr[i].carpr_vrrp_prio, carpr[i].carpr_vrrp_adv_inter);
break;
@@ -115,11 +118,11 @@ setcarp_vhid(if_ctx *ctx, const char *val, int dummy __unused)
carpr_vhid = atoi(val);
if (carpr_vhid <= 0 || carpr_vhid > CARP_MAXVHID)
- errx(1, "vhid must be greater than 0 and less than %u",
+ xo_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);
+ xo_errx(1, "%s doesn't support carp(4)", afp->af_name);
afp->af_setvhid(carpr_vhid);
callback_register(setcarp_callback, NULL);
}
@@ -157,7 +160,7 @@ setcarp_callback(if_ctx *ctx, void *arg __unused)
carpr.carpr_vrrp_adv_inter = carpr_vrrp_adv_inter;
if (ifconfig_carp_set_info(lifh, ctx->ifname, &carpr))
- err(1, "SIOCSVH");
+ xo_err(1, "SIOCSVH");
}
static void
@@ -165,7 +168,7 @@ setcarp_passwd(if_ctx *ctx __unused, const char *val, int dummy __unused)
{
if (carpr_vhid == -1)
- errx(1, "passwd requires vhid");
+ xo_errx(1, "passwd requires vhid");
carpr_key = val;
}
@@ -175,7 +178,7 @@ setcarp_advskew(if_ctx *ctx __unused, const char *val, int dummy __unused)
{
if (carpr_vhid == -1)
- errx(1, "advskew requires vhid");
+ xo_errx(1, "advskew requires vhid");
carpr_advskew = atoi(val);
}
@@ -185,7 +188,7 @@ setcarp_advbase(if_ctx *ctx __unused, const char *val, int dummy __unused)
{
if (carpr_vhid == -1)
- errx(1, "advbase requires vhid");
+ xo_errx(1, "advbase requires vhid");
carpr_advbase = atoi(val);
}
@@ -196,7 +199,7 @@ setcarp_state(if_ctx *ctx __unused, const char *val, int dummy __unused)
int i;
if (carpr_vhid == -1)
- errx(1, "state requires vhid");
+ xo_errx(1, "state requires vhid");
for (i = 0; i <= CARP_MAXSTATE; i++)
if (strcasecmp(carp_states[i], val) == 0) {
@@ -204,7 +207,7 @@ setcarp_state(if_ctx *ctx __unused, const char *val, int dummy __unused)
return;
}
- errx(1, "unknown state");
+ xo_errx(1, "unknown state");
}
static void
@@ -229,7 +232,7 @@ setcarp_peer6(if_ctx *ctx __unused, const char *val, int dummy __unused)
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(val, NULL, &hints, &res) != 0)
- errx(1, "Invalid IPv6 address %s", val);
+ xo_errx(1, "Invalid IPv6 address %s", val);
memcpy(&carp_addr6, &(satosin6(res->ai_addr))->sin6_addr, sizeof(carp_addr6));
freeaddrinfo(res);
@@ -250,7 +253,7 @@ setcarp_version(if_ctx *ctx __unused, const char *val, int dummy __unused)
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,
+ xo_errx(1, "version must be %d or %d", CARP_VERSION_CARP,
CARP_VERSION_VRRPv3);
}
@@ -266,7 +269,7 @@ setvrrp_interval(if_ctx *ctx __unused, const char *val, int dummy __unused)
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);
+ xo_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.c b/sbin/ifconfig/ifbridge.c
index 8bcf4a638ad..082f4129fa1 100644
--- a/sbin/ifconfig/ifbridge.c
+++ b/sbin/ifconfig/ifbridge.c
@@ -59,6 +59,7 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
static int parse_vlans(ifbvlan_set_t *set, const char *str);
static int get_val(const char *cp, u_long *valp);
@@ -118,7 +119,7 @@ do_bridgeflag(if_ctx *ctx, const char *ifs, int flag, int set)
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");
+ xo_err(1, "unable to get bridge flags");
if (set)
req.ifbr_ifsflags |= flag;
@@ -126,7 +127,7 @@ do_bridgeflag(if_ctx *ctx, const char *ifs, int flag, int set)
req.ifbr_ifsflags &= ~flag;
if (do_cmd(ctx, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
- err(1, "unable to set bridge flags");
+ xo_err(1, "unable to set bridge flags");
}
static void
@@ -141,25 +142,30 @@ bridge_addresses(if_ctx *ctx, const char *prefix)
for (;;) {
ninbuf = realloc(inbuf, len);
if (ninbuf == NULL)
- err(1, "unable to allocate address buffer");
+ xo_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");
+ xo_err(1, "unable to get address cache");
if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
break;
len *= 2;
}
+ xo_open_list("bridge-address");
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),
+ xo_open_instance("bridge-address");
+ 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);
printb("flags", ifba->ifba_flags, IFBAFBITS);
- printf("\n");
+ xo_emit("\n");
+ xo_close_instance("bridge-address");
}
+ xo_close_list("bridge-address");
free(inbuf);
}
@@ -182,13 +188,17 @@ print_vlans(ifbvlan_set_t *vlans)
++last;
if (printed == 0)
- printf(" tagged ");
+ xo_emit("{P: tagged }");
else
- printf(",");
+ xo_emit("{P:,}");
- printf("%u", vlan);
+ xo_open_list("vlan");
+ xo_open_instance("vlan");
+ xo_emit("{:vlan-id/%d}", vlan);
if (last != vlan)
- printf("-%u", last);
+ xo_emit("{P:-}{:vlan-end/%d}", last);
+ xo_close_instance("vlan");
+ xo_close_list("vlan");
++printed;
vlan = last + 1;
}
@@ -214,7 +224,6 @@ 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;
@@ -223,20 +232,23 @@ bridge_status(if_ctx *ctx)
params = bridge->params;
+ xo_open_list("bridge");
+ xo_open_instance("bridge");
+
PV2ID(params->ifbop_bridgeid, bprio, lladdr);
- printf("\tid %s priority %u hellotime %u fwddelay %u\n",
+ 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);
- printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n",
+ 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);
- printf("\troot id %s priority %d ifcost %u port %u\n",
+ 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,
@@ -244,20 +256,20 @@ bridge_status(if_ctx *ctx)
printb("\tbridge flags", bridge->flags, IFBRFBITS);
if (bridge->defpvid)
- printf(" defuntagged=%u", (unsigned) bridge->defpvid);
- printf("\n");
+ xo_emit("{P: defuntagged=}{:defuntagged/%u}", (unsigned) bridge->defpvid);
+ xo_emit("\n");
- prefix = "\tmember: ";
- pad = "\t ";
+ xo_open_list("member");
for (size_t i = 0; i < bridge->members_count; ++i) {
struct ifbreq *member = &bridge->members[i];
- printf("%s%s ", prefix, member->ifbr_ifsname);
+ xo_open_instance("member");
+ xo_emit("{P:\tmember: }{:member-name/%s}{P: }", member->ifbr_ifsname);
printb("flags", member->ifbr_ifsflags, IFBIFBITS);
- printf("\n%s", pad);
+ xo_emit("\n{P:\t }");
if (member->ifbr_addrmax != 0)
- printf("ifmaxaddr %u ", member->ifbr_addrmax);
- printf("port %u priority %u path cost %u",
+ xo_emit("{P:ifmaxaddr }{:ifmaxaddr/%u}{P: }", member->ifbr_addrmax);
+ 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);
@@ -267,27 +279,32 @@ bridge_status(if_ctx *ctx)
uint8_t state = member->ifbr_state;
if (proto < nitems(stpproto))
- printf(" proto %s", stpproto[proto]);
+ xo_emit("{P: proto }{:stp-proto/%s}", stpproto[proto]);
else
- printf(" <unknown proto %d>", proto);
- printf("\n%s", pad);
+ xo_emit("{P: <unknown proto }{:unknown-proto/%d}{P:>}", proto);
+ xo_emit("\n{P:\t }");
if (role < nitems(stproles))
- printf("role %s", stproles[role]);
+ xo_emit("{P:role }{:stp-role/%s}", stproles[role]);
else
- printf("<unknown role %d>", role);
+ xo_emit("{P:<unknown role }{:unknown-role/%d}{P:>}", role);
if (state < nitems(stpstates))
- printf(" state %s", stpstates[state]);
+ xo_emit("{P: state }{:stp-state/%s}", stpstates[state]);
else
- printf(" <unknown state %d>", state);
+ xo_emit("{P: <unknown state }{:unknown-state/%d}{P:>}", state);
}
if (member->ifbr_vlanproto != 0)
- printf(" vlan protocol %s",
+ xo_emit("{P: vlan protocol }{:vlan-proto/%s}",
vlan_proto_name(member->ifbr_vlanproto));
if (member->ifbr_pvid != 0)
- printf(" untagged %u", (unsigned)member->ifbr_pvid);
+ xo_emit("{P: untagged }{:untagged/%u}", (unsigned)member->ifbr_pvid);
print_vlans(&bridge->member_vlans[i]);
- printf("\n");
+ xo_emit("\n");
+ xo_close_instance("member");
}
+ xo_close_list("member");
+
+ xo_close_instance("bridge");
+ xo_close_list("bridge");
ifconfig_bridge_free_bridge_status(bridge);
}
@@ -303,7 +320,7 @@ setbridge_add(if_ctx *ctx, int argc, const char *const *argv)
memset(&vlreq, 0, sizeof(vlreq));
if (argc < 1)
- errx(1, "usage: addm <interface> [opts ...]");
+ xo_errx(1, "usage: addm <interface> [opts ...]");
strlcpy(req.ifbr_ifsname, argv[0], sizeof(req.ifbr_ifsname));
--argc; ++argv;
@@ -311,22 +328,22 @@ setbridge_add(if_ctx *ctx, int argc, const char *const *argv)
while (argc) {
if (strcmp(argv[0], "untagged") == 0) {
if (argc < 2)
- errx(1, "usage: untagged <vlan id>");
+ xo_errx(1, "usage: untagged <vlan id>");
if (get_vlan_id(argv[1], &req.ifbr_pvid) < 0)
- errx(1, "invalid VLAN identifier: %s", argv[1]);
+ xo_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>");
+ xo_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]);
+ xo_errx(1, "invalid vlan set: %s", argv[1]);
argc -= 2;
argv += 2;
@@ -336,16 +353,16 @@ setbridge_add(if_ctx *ctx, int argc, const char *const *argv)
}
if (do_cmd(ctx, BRDGADD, &req, sizeof(req), 1) < 0)
- err(1, "BRDGADD %s", req.ifbr_ifsname);
+ xo_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,
+ xo_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);
+ xo_err(1, "BRDGSIFVLANSET %s", req.ifbr_ifsname);
return (oargc - argc);
}
@@ -358,7 +375,7 @@ setbridge_delete(if_ctx *ctx, const char *val, int dummy __unused)
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);
+ xo_err(1, "BRDGDEL %s", val);
}
static void
@@ -411,7 +428,7 @@ setbridge_span(if_ctx *ctx, const char *val, int dummy __unused)
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);
+ xo_err(1, "BRDGADDS %s", val);
}
static void
@@ -422,7 +439,7 @@ unsetbridge_span(if_ctx *ctx, const char *val, int dummy __unused)
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);
+ xo_err(1, "BRDGDELS %s", val);
}
static void
@@ -495,7 +512,7 @@ setbridge_flush(if_ctx *ctx, const char *val __unused, int dummy __unused)
memset(&req, 0, sizeof(req));
req.ifbr_ifsflags = IFBF_FLUSHDYN;
if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0)
- err(1, "BRDGFLUSH");
+ xo_err(1, "BRDGFLUSH");
}
static void
@@ -506,7 +523,7 @@ setbridge_flushall(if_ctx *ctx, const char *val __unused, int dummy __unused)
memset(&req, 0, sizeof(req));
req.ifbr_ifsflags = IFBF_FLUSHALL;
if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0)
- err(1, "BRDGFLUSH");
+ xo_err(1, "BRDGFLUSH");
}
static int
@@ -517,7 +534,7 @@ setbridge_static(if_ctx *ctx, int argc, const char *const *argv)
int arg;
if (argc < 2)
- errx(1, "usage: static <interface> <address> [vlan <id>]");
+ xo_errx(1, "usage: static <interface> <address> [vlan <id>]");
arg = 0;
memset(&req, 0, sizeof(req));
@@ -528,24 +545,24 @@ setbridge_static(if_ctx *ctx, int argc, const char *const *argv)
ea = ether_aton(argv[arg]);
if (ea == NULL)
- errx(1, "invalid address: %s", argv[arg]);
+ xo_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> "
+ xo_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]);
+ xo_errx(1, "invalid vlan id: %s", argv[arg]);
++arg;
}
if (do_cmd(ctx, BRDGSADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSADDR");
+ xo_err(1, "BRDGSADDR");
return arg;
}
@@ -557,30 +574,30 @@ setbridge_deladdr(if_ctx *ctx, int argc, const char *const *argv)
int arg;
if (argc < 1)
- errx(1, "usage: deladdr <address> [vlan <id>]");
+ xo_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]);
+ xo_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>]");
+ xo_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]);
+ xo_errx(1, "invalid vlan id: %s", argv[arg]);
++arg;
}
if (do_cmd(ctx, BRDGDADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGDADDR");
+ xo_err(1, "BRDGDADDR");
return arg;
}
@@ -598,12 +615,12 @@ setbridge_maxaddr(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSCACHE %s", arg);
}
static void
@@ -613,12 +630,12 @@ setbridge_hellotime(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSHT %s", arg);
}
static void
@@ -628,12 +645,12 @@ setbridge_fwddelay(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSFD %s", arg);
}
static void
@@ -643,12 +660,12 @@ setbridge_maxage(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSMA %s", arg);
}
static void
@@ -658,12 +675,12 @@ setbridge_priority(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSPRI %s", arg);
}
static void
@@ -676,11 +693,11 @@ setbridge_protocol(if_ctx *ctx, const char *arg, int dummy __unused)
} else if (strcasecmp(arg, "rstp") == 0) {
param.ifbrp_proto = 2;
} else {
- errx(1, "unknown stp protocol");
+ xo_errx(1, "unknown stp protocol");
}
if (do_cmd(ctx, BRDGSPROTO, &param, sizeof(param), 1) < 0)
- err(1, "BRDGSPROTO %s", arg);
+ xo_err(1, "BRDGSPROTO %s", arg);
}
static void
@@ -690,12 +707,12 @@ setbridge_holdcount(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSTXHC %s", arg);
}
static void
@@ -707,13 +724,13 @@ setbridge_ifpriority(if_ctx *ctx, const char *ifn, const char *pri)
memset(&req, 0, sizeof(req));
if (get_val(pri, &val) < 0 || (val & ~0xff) != 0)
- errx(1, "invalid value: %s", pri);
+ xo_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);
+ xo_err(1, "BRDGSIFPRIO %s", pri);
}
static void
@@ -725,13 +742,13 @@ setbridge_ifpathcost(if_ctx *ctx, const char *ifn, const char *cost)
memset(&req, 0, sizeof(req));
if (get_val(cost, &val) < 0)
- errx(1, "invalid value: %s", cost);
+ xo_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);
+ xo_err(1, "BRDGSIFCOST %s", cost);
}
static void
@@ -743,10 +760,10 @@ setbridge_ifuntagged(if_ctx *ctx, const char *ifn, const char *vlanid)
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);
+ xo_errx(1, "invalid VLAN identifier: %s", vlanid);
if (do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPVID %s", vlanid);
+ xo_err(1, "BRDGSIFPVID %s", vlanid);
}
static void
@@ -760,7 +777,7 @@ unsetbridge_ifuntagged(if_ctx *ctx, const char *ifn, int dummy __unused)
req.ifbr_pvid = 0;
if (do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFPVID");
+ xo_err(1, "BRDGSIFPVID");
}
static void
@@ -772,13 +789,13 @@ setbridge_ifmaxaddr(if_ctx *ctx, const char *ifn, const char *arg)
memset(&req, 0, sizeof(req));
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSIFAMAX %s", arg);
}
static void
@@ -788,12 +805,12 @@ setbridge_timeout(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
- errx(1, "invalid value: %s", arg);
+ xo_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);
+ xo_err(1, "BRDGSTO %s", arg);
}
static void
@@ -874,13 +891,13 @@ set_bridge_vlanset(if_ctx *ctx, const char *ifn, const char *vlans, int op)
memset(&req, 0, sizeof(req));
if (parse_vlans(&req.bv_set, vlans) != 0)
- errx(1, "invalid vlan set: %s", vlans);
+ xo_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);
+ xo_err(1, "BRDGSIFVLANSET %s", vlans);
}
static void
@@ -907,12 +924,12 @@ setbridge_flags(if_ctx *ctx, const char *val __unused, int newflags)
struct ifbrparam req;
if (do_cmd(ctx, BRDGGFLAGS, &req, sizeof(req), 0) < 0)
- err(1, "BRDGGFLAGS");
+ xo_err(1, "BRDGGFLAGS");
req.ifbrp_flags |= (uint32_t)newflags;
if (do_cmd(ctx, BRDGSFLAGS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSFLAGS");
+ xo_err(1, "BRDGSFLAGS");
}
static void
@@ -921,12 +938,12 @@ unsetbridge_flags(if_ctx *ctx, const char *val __unused, int newflags)
struct ifbrparam req;
if (do_cmd(ctx, BRDGGFLAGS, &req, sizeof(req), 0) < 0)
- err(1, "BRDGGFLAGS");
+ xo_err(1, "BRDGGFLAGS");
req.ifbrp_flags &= ~(uint32_t)newflags;
if (do_cmd(ctx, BRDGSFLAGS, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSFLAGS");
+ xo_err(1, "BRDGSFLAGS");
}
static void
@@ -936,10 +953,10 @@ setbridge_defuntagged(if_ctx *ctx, const char *arg, int dummy __unused)
memset(&req, 0, sizeof(req));
if (get_vlan_id(arg, &req.ifbrp_defpvid) < 0)
- errx(1, "invalid vlan id: %s", arg);
+ xo_errx(1, "invalid vlan id: %s", arg);
if (do_cmd(ctx, BRDGSDEFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSDEFPVID");
+ xo_err(1, "BRDGSDEFPVID");
}
static void
@@ -951,7 +968,7 @@ unsetbridge_defuntagged(if_ctx *ctx, const char *val __unused, int dummy __unuse
req.ifbrp_defpvid = 0;
if (do_cmd(ctx, BRDGSDEFPVID, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSDEFPVID");
+ xo_err(1, "BRDGSDEFPVID");
}
static void
@@ -979,10 +996,10 @@ setbridge_ifvlanproto(if_ctx *ctx, const char *ifname, const char *proto)
else if (strcmp(proto, "802.1ad") == 0)
req.ifbr_vlanproto = ETHERTYPE_QINQ;
else
- errx(1, "unrecognised VLAN protocol: %s", proto);
+ xo_errx(1, "unrecognised VLAN protocol: %s", proto);
if (do_cmd(ctx, BRDGSIFVLANPROTO, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSIFVLANPROTO");
+ xo_err(1, "BRDGSIFVLANPROTO");
}
static struct cmd bridge_cmds[] = {
diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c
index f44d052c97a..efe505a05b2 100644
--- a/sbin/ifconfig/ifclone.c
+++ b/sbin/ifconfig/ifclone.c
@@ -37,6 +37,7 @@
#include <err.h>
#include <libifconfig.h>
+#include <libxo/xo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -56,16 +57,16 @@ list_cloners(void)
size_t cloners_count;
if (ifconfig_list_cloners(lifh, &cloners, &cloners_count) < 0)
- errc(1, ifconfig_err_errno(lifh), "unable to list cloners");
+ xo_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);
+ xo_emit("{P: }");
+ xo_emit("{:cloner-name/%s}", name);
}
- putchar('\n');
+ xo_emit("\n");
free(cloners);
}
@@ -157,7 +158,7 @@ clone_destroy(if_ctx *ctx, const char *cmd __unused, int d __unused)
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCIFDESTROY, &ifr) < 0)
- err(1, "SIOCIFDESTROY");
+ xo_err(1, "SIOCIFDESTROY");
}
static struct cmd clone_cmds[] = {
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 9aeb4a09ef4..f59e9f27b0c 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -69,10 +69,14 @@
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
+
#include <libifconfig.h>
#include "ifconfig.h"
+#define IFCONFIG_XO_VERSION "1"
+
ifconfig_handle_t *lifh;
#ifdef WITHOUT_NETLINK
@@ -99,6 +103,7 @@ static void status(if_ctx *ctx, const struct sockaddr_dl *sdl,
#endif
static _Noreturn void usage(void);
static void Perrorc(const char *cmd, int error);
+static void xo_cleanup(void);
static int getifflags(const char *ifname, int us, bool err_ok);
@@ -168,7 +173,7 @@ usage(void)
strlcat(options, " ", sizeof(options));
}
- fprintf(stderr,
+ xo_errx(1,
"usage: ifconfig [-j jail] [-f type:format] %sinterface address_family\n"
" [address [dest_address]] [parameters]\n"
" ifconfig [-j jail] interface create\n"
@@ -176,7 +181,6 @@ usage(void)
" ifconfig [-j jail] -l [-d] [-u] [address_family]\n"
" ifconfig [-j jail] %s[-d] [-m] [-u] [-v]\n",
options, options, options);
- exit(1);
}
static void
@@ -211,9 +215,9 @@ ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr)
if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) {
switch (errno) {
case EEXIST:
- errx(1, "interface %s already exists", ifr->ifr_name);
+ xo_errx(1, "interface %s already exists", ifr->ifr_name);
default:
- err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
+ xo_err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name);
}
}
@@ -335,7 +339,7 @@ static void setformat(char *input)
free(f_inet6);
f_inet6 = strdup(category);
} else {
- warnx("Skipping invalid format: %s\n",
+ xo_warnx("Skipping invalid format: %s\n",
category);
}
continue;
@@ -423,7 +427,13 @@ static void
printifnamemaybe(void)
{
if (ifname_to_print[0] != '\0')
- printf("%s\n", ifname_to_print);
+ xo_emit("{:ifname-print/%s}\n", ifname_to_print);
+}
+
+static void
+xo_cleanup(void)
+{
+ xo_finish();
}
static void
@@ -567,7 +577,7 @@ args_parse(struct ifconfig_args *args, int argc, char *argv[])
const struct afswtch *afp = af_getbyname(*argv);
if (afp == NULL) {
- warnx("Address family '%s' unknown.", *argv);
+ xo_warnx("Address family '%s' unknown.", *argv);
usage();
}
if (afp->af_name != NULL)
@@ -626,9 +636,15 @@ main(int ac, char *av[])
.io_s = -1,
};
+ ac = xo_parse_args(ac, av);
+ if (ac < 0)
+ exit(EXIT_FAILURE);
+
+ xo_set_version(IFCONFIG_XO_VERSION);
+
lifh = ifconfig_open();
if (lifh == NULL)
- err(EXIT_FAILURE, "ifconfig_open");
+ xo_err(EXIT_FAILURE, "ifconfig_open");
envformat = getenv("IFCONFIG_FORMAT");
if (envformat != NULL)
@@ -639,9 +655,12 @@ main(int ac, char *av[])
* even if we terminate early due to error.
*/
atexit(printifnamemaybe);
+ atexit(xo_cleanup);
args_parse(args, ac, av);
+ xo_open_container("ifconfig");
+
if (!args->all && !args->namesonly) {
/* not listing, need an argument */
args->ifname = args_pop(args);
@@ -659,7 +678,7 @@ main(int ac, char *av[])
*/
if (isargcreate(arg)) {
if (isnametoolong(args->ifname))
- errx(1, "%s: cloning name too long",
+ xo_errx(1, "%s: cloning name too long",
args->ifname);
ifconfig(&ctx, 1, NULL);
exit(exit_code);
@@ -672,13 +691,13 @@ main(int ac, char *av[])
*/
if (arg != NULL && (strcmp(arg, "-vnet") == 0)) {
if (isnametoolong(args->ifname))
- errx(1, "%s: interface name too long",
+ xo_errx(1, "%s: interface name too long",
args->ifname);
ifconfig(&ctx, 0, NULL);
exit(exit_code);
}
#endif
- errx(1, "interface %s does not exist", args->ifname);
+ xo_errx(1, "interface %s does not exist", args->ifname);
} else {
/*
* Do not allow use `create` command as hostname if
@@ -686,7 +705,7 @@ main(int ac, char *av[])
*/
if (isargcreate(arg)) {
if (args->argc == 1)
- errx(1, "interface %s already exists",
+ xo_errx(1, "interface %s already exists",
args->ifname);
args_pop(args);
}
@@ -707,7 +726,7 @@ main(int ac, char *av[])
*/
if ((args->argc > 0) && (args->ifname != NULL)) {
if (isnametoolong(args->ifname))
- warnx("%s: interface name too long, skipping", args->ifname);
+ xo_warnx("%s: interface name too long, skipping", args->ifname);
else {
flags = getifflags(args->ifname, -1, false);
if (!(((flags & IFF_CANTCONFIG) != 0) ||
@@ -723,6 +742,7 @@ main(int ac, char *av[])
list_interfaces(&ctx);
done:
+ xo_close_container("ifconfig");
freeformat();
ifconfig_close(lifh);
exit(exit_code);
@@ -780,12 +800,12 @@ list_interfaces_ioctl(if_ctx *ctx)
struct ifconfig_args *args = ctx->args;
if (getifaddrs(&ifap) != 0)
- err(EXIT_FAILURE, "getifaddrs");
+ xo_err(EXIT_FAILURE, "getifaddrs");
char *cp = NULL;
if (calcorders(ifap, &q) != 0)
- err(EXIT_FAILURE, "calcorders");
+ xo_err(EXIT_FAILURE, "calcorders");
sifap = sortifaddrs(ifap, cmpifaddrs, &q);
@@ -793,6 +813,7 @@ list_interfaces_ioctl(if_ctx *ctx)
free(cur);
ifindex = 0;
+ xo_open_list("interface");
for (ifa = sifap; ifa; ifa = ifa->ifa_next) {
struct ifreq paifr = {};
const struct sockaddr_dl *sdl;
@@ -812,7 +833,7 @@ list_interfaces_ioctl(if_ctx *ctx)
if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
continue;
if (isnametoolong(ifa->ifa_name)) {
- warnx("%s: interface name too long, skipping",
+ xo_warnx("%s: interface name too long, skipping",
ifa->ifa_name);
continue;
}
@@ -833,9 +854,11 @@ list_interfaces_ioctl(if_ctx *ctx)
continue;
namecp = cp;
ifindex++;
+ xo_open_instance("interface");
if (ifindex > 1)
- printf(" ");
- fputs(cp, stdout);
+ xo_emit("{P: }");
+ xo_emit("{:ifname/%s}", cp);
+ xo_close_instance("interface");
continue;
}
ifindex++;
@@ -845,8 +868,9 @@ list_interfaces_ioctl(if_ctx *ctx)
else
status(ctx, sdl, ifa);
}
+ xo_close_list("interface");
if (args->namesonly)
- printf("\n");
+ xo_emit("\n");
freeifaddrs(ifap);
}
#endif
@@ -879,7 +903,7 @@ group_member(const char *ifname, const char *match, const char *nomatch)
if (sock == -1) {
sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (sock == -1)
- errx(1, "%s: socket(AF_LOCAL,SOCK_DGRAM)", __func__);
+ xo_errx(1, "%s: socket(AF_LOCAL,SOCK_DGRAM)", __func__);
}
/* Determine amount of memory for the list of groups. */
@@ -887,7 +911,7 @@ group_member(const char *ifname, const char *match, const char *nomatch)
if (errno == EINVAL || errno == ENOTTY)
return (false);
else
- errx(1, "%s: SIOCGIFGROUP", __func__);
+ xo_errx(1, "%s: SIOCGIFGROUP", __func__);
}
/* Obtain the list of groups. */
@@ -896,9 +920,9 @@ group_member(const char *ifname, const char *match, const char *nomatch)
(struct ifg_req *)calloc(len / sizeof(*ifg), sizeof(*ifg));
if (ifgr.ifgr_groups == NULL)
- errx(1, "%s: no memory", __func__);
+ xo_errx(1, "%s: no memory", __func__);
if (ioctl(sock, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
- errx(1, "%s: SIOCGIFGROUP", __func__);
+ xo_errx(1, "%s: SIOCGIFGROUP", __func__);
/* Perform matching. */
matched = false;
@@ -1025,7 +1049,7 @@ callback_register(callback_func *func, void *arg)
cb = malloc(sizeof(struct callback));
if (cb == NULL)
- errx(1, "unable to allocate memory for callback");
+ xo_errx(1, "unable to allocate memory for callback");
cb->cb_func = func;
cb->cb_arg = arg;
cb->cb_next = callbacks;
@@ -1057,7 +1081,7 @@ delifaddr(if_ctx *ctx, const struct afswtch *afp)
int error;
if (afp->af_exec == NULL) {
- warnx("interface %s cannot change %s addresses!",
+ xo_warnx("interface %s cannot change %s addresses!",
ctx->ifname, afp->af_name);
clearaddr = 0;
return;
@@ -1076,7 +1100,7 @@ static void
addifaddr(if_ctx *ctx, const struct afswtch *afp)
{
if (afp->af_exec == NULL) {
- warnx("interface %s cannot change %s addresses!",
+ xo_warnx("interface %s cannot change %s addresses!",
ctx->ifname, afp->af_name);
newaddr = 0;
return;
@@ -1128,7 +1152,7 @@ ifconfig_ioctl(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
if (afp == NULL)
afp = af_getbyname("link");
if (afp == NULL) {
- warnx("Please specify an address_family.");
+ xo_warnx("Please specify an address_family.");
usage();
}
@@ -1140,7 +1164,7 @@ ifconfig_ioctl(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
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);
+ xo_err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
ctx->io_s = s;
ctx->afp = afp;
@@ -1155,7 +1179,7 @@ ifconfig_ioctl(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
*/
cb = callbacks;
if (cb == NULL)
- errx(1, "internal error, no callback");
+ xo_errx(1, "internal error, no callback");
callbacks = cb->cb_next;
cb->cb_func(ctx, cb->cb_arg);
iscreate = 0;
@@ -1187,7 +1211,7 @@ ifconfig_ioctl(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
}
if (p->c_parameter == NEXTARG && p->c_u.c_func) {
if (argv[1] == NULL)
- errx(1, "'%s' requires argument",
+ xo_errx(1, "'%s' requires argument",
p->c_name);
p->c_u.c_func(ctx, argv[1], 0);
argc--, argv++;
@@ -1197,7 +1221,7 @@ ifconfig_ioctl(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
argc--, argv++;
} else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
if (argc < 3)
- errx(1, "'%s' requires 2 arguments",
+ xo_errx(1, "'%s' requires 2 arguments",
p->c_name);
p->c_u.c_func2(ctx, argv[1], argv[2]);
argc -= 2, argv += 2;
@@ -1264,21 +1288,21 @@ settunnel(if_ctx *ctx, const char *src, const char *dst)
int ecode;
if (afp->af_settunnel == NULL) {
- warn("address family %s does not support tunnel setup",
+ xo_warn("address family %s does not support tunnel setup",
afp->af_name);
return;
}
if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
- errx(1, "error in parsing address string: %s",
+ xo_errx(1, "error in parsing address string: %s",
gai_strerror(ecode));
if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
- errx(1, "error in parsing address string: %s",
+ xo_errx(1, "error in parsing address string: %s",
gai_strerror(ecode));
if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
- errx(1,
+ xo_errx(1,
"source and destination address families do not match");
afp->af_settunnel(ctx, srcres, dstres);
@@ -1293,7 +1317,7 @@ deletetunnel(if_ctx *ctx, const char *vname __unused, int param __unused)
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCDIFPHYADDR, &ifr) < 0)
- err(1, "SIOCDIFPHYADDR");
+ xo_err(1, "SIOCDIFPHYADDR");
}
#ifdef JAIL
@@ -1304,9 +1328,9 @@ setifvnet(if_ctx *ctx, const char *jname, int dummy __unused)
ifr.ifr_jid = jail_getid(jname);
if (ifr.ifr_jid < 0)
- errx(1, "%s", jail_errmsg);
+ xo_errx(1, "%s", jail_errmsg);
if (ioctl_ctx_ifr(ctx, SIOCSIFVNET, &ifr) < 0)
- err(1, "SIOCSIFVNET");
+ xo_err(1, "SIOCSIFVNET");
}
static void
@@ -1316,9 +1340,9 @@ setifrvnet(if_ctx *ctx, const char *jname, int dummy __unused)
ifr.ifr_jid = jail_getid(jname);
if (ifr.ifr_jid < 0)
- errx(1, "%s", jail_errmsg);
+ xo_errx(1, "%s", jail_errmsg);
if (ioctl_ctx_ifr(ctx, SIOCSIFRVNET, &ifr) < 0)
- err(1, "SIOCSIFRVNET(%d, %s)", ifr.ifr_jid, ifr.ifr_name);
+ xo_err(1, "SIOCSIFRVNET(%d, %s)", ifr.ifr_jid, ifr.ifr_name);
}
#endif
@@ -1378,7 +1402,7 @@ getifflags(const char *ifname, int us, bool err_ok)
(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");
+ xo_err(1, "socket(family AF_LOCAL,SOCK_DGRAM");
} else
s = us;
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
@@ -1484,7 +1508,7 @@ setifcapnv(if_ctx *ctx, const char *vname, const char *arg)
if (ioctl_ctx_ifr(ctx, SIOCGIFCAP, &ifr) < 0)
Perror("ioctl (SIOCGIFCAP)");
if ((ifr.ifr_curcap & IFCAP_NV) == 0) {
- warnx("IFCAP_NV not supported");
+ xo_warnx("IFCAP_NV not supported");
return; /* Not exit() */
}
@@ -1507,7 +1531,7 @@ setifcapnv(if_ctx *ctx, const char *vname, const char *arg)
}
buf = nvlist_pack(nvcap, &nvbuflen);
if (buf == NULL) {
- errx(1, "nvlist_pack error");
+ xo_errx(1, "nvlist_pack error");
exit(1);
}
ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen;
@@ -1526,7 +1550,7 @@ setifmetric(if_ctx *ctx, const char *val, int dummy __unused)
ifr.ifr_metric = atoi(val);
if (ioctl_ctx_ifr(ctx, SIOCSIFMETRIC, &ifr) < 0)
- err(1, "ioctl SIOCSIFMETRIC (set metric)");
+ xo_err(1, "ioctl SIOCSIFMETRIC (set metric)");
}
static void
@@ -1536,7 +1560,7 @@ setifmtu(if_ctx *ctx, const char *val, int dummy __unused)
ifr.ifr_mtu = atoi(val);
if (ioctl_ctx_ifr(ctx, SIOCSIFMTU, &ifr) < 0)
- err(1, "ioctl SIOCSIFMTU (set mtu)");
+ xo_err(1, "ioctl SIOCSIFMTU (set mtu)");
}
static void
@@ -1548,12 +1572,12 @@ setifpcp(if_ctx *ctx, const char *val, int arg __unused)
ul = strtoul(val, &endp, 0);
if (*endp != '\0')
- errx(1, "invalid value for pcp");
+ xo_errx(1, "invalid value for pcp");
if (ul > 7)
- errx(1, "value for pcp out of range");
+ xo_errx(1, "value for pcp out of range");
ifr.ifr_lan_pcp = ul;
if (ioctl_ctx_ifr(ctx, SIOCSLANPCP, &ifr) == -1)
- err(1, "SIOCSLANPCP");
+ xo_err(1, "SIOCSLANPCP");
}
static void
@@ -1563,7 +1587,7 @@ disableifpcp(if_ctx *ctx, const char *val __unused, int arg __unused)
ifr.ifr_lan_pcp = IFNET_PCP_NONE;
if (ioctl_ctx_ifr(ctx, SIOCSLANPCP, &ifr) == -1)
- err(1, "SIOCSLANPCP");
+ xo_err(1, "SIOCSLANPCP");
}
static void
@@ -1575,11 +1599,11 @@ setifname(if_ctx *ctx, const char *val, int dummy __unused)
ifr_set_name(&ifr, ctx->ifname);
newname = strdup(val);
if (newname == NULL)
- err(1, "no memory to set ifname");
+ xo_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)");
+ xo_err(1, "ioctl SIOCSIFNAME (set name)");
}
ifname_update(ctx, newname);
free(newname);
@@ -1599,13 +1623,13 @@ setifdescr(if_ctx *ctx, const char *val, int dummy __unused)
newdescr = strdup(val);
ifr.ifr_buffer.buffer = newdescr;
if (newdescr == NULL) {
- warn("no memory to set ifdescr");
+ xo_warn("no memory to set ifdescr");
return;
}
}
if (ioctl_ctx_ifr(ctx, SIOCSIFDESCR, &ifr) < 0)
- err(1, "ioctl SIOCSIFDESCR (set descr)");
+ xo_err(1, "ioctl SIOCSIFDESCR (set descr)");
free(newdescr);
}
@@ -1695,36 +1719,43 @@ print_ifcap_nv(if_ctx *ctx)
ifr.ifr_cap_nv.length, 0);
if (nvcap == NULL)
Perror("nvlist_unpack");
- printf("\toptions");
+ xo_emit("\toptions");
cookie = NULL;
+ xo_open_list("options");
for (first = true;; first = false) {
nvname = nvlist_next(nvcap, &type, &cookie);
if (nvname == NULL) {
- printf("\n");
+ xo_emit("\n");
break;
}
if (type == NV_TYPE_BOOL) {
val = nvlist_get_bool(nvcap, nvname);
if (val) {
- printf("%c%s",
+ xo_emit("{P:/%c%s}",
first ? ' ' : ',', nvname);
+ xo_emit("{le:options/%s}", nvname);
}
}
}
+ xo_close_list("options");
if (ctx->args->supmedia) {
- printf("\tcapabilities");
+ xo_emit("\tcapabilities");
cookie = NULL;
+ xo_open_list("capabilities");
for (first = true;; first = false) {
nvname = nvlist_next(nvcap, &type,
&cookie);
if (nvname == NULL) {
- printf("\n");
+ xo_emit("\n");
break;
}
- if (type == NV_TYPE_BOOL)
- printf("%c%s", first ? ' ' :
+ if (type == NV_TYPE_BOOL) {
+ xo_emit("{P:/%c%s}", first ? ' ' :
',', nvname);
+ xo_emit("{le:capabilities/%s}", nvname);
+ }
}
+ xo_close_list("capabilities");
}
nvlist_destroy(nvcap);
free(buf);
@@ -1744,26 +1775,33 @@ print_ifcap(if_ctx *ctx)
if ((ifr.ifr_curcap & IFCAP_NV) != 0)
print_ifcap_nv(ctx);
else {
- printf("\toptions=%x", ifr.ifr_curcap);
+ xo_emit("\toptions={:options-hex/%x}", ifr.ifr_curcap);
print_bits("options", &ifr.ifr_curcap, 1, IFCAPBITS, nitems(IFCAPBITS));
- putchar('\n');
+ xo_emit("\n");
if (ctx->args->supmedia && ifr.ifr_reqcap != 0) {
- printf("\tcapabilities=%x", ifr.ifr_reqcap);
+ xo_emit("\tcapabilities={:capab-hex/%x}", ifr.ifr_reqcap);
print_bits("capabilities", &ifr.ifr_reqcap, 1, IFCAPBITS, nitems(IFCAPBITS));
- putchar('\n');
+ xo_emit("\n");
}
}
}
#endif
void
-print_ifstatus(if_ctx *ctx)
+ 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);
+ if (ioctl_ctx(ctx, SIOCGIFSTATUS, &ifs) == 0) {
+ 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);
+ }
}
void
@@ -1772,7 +1810,7 @@ print_metric(if_ctx *ctx)
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCGIFMETRIC, &ifr) != -1)
- printf(" metric %d", ifr.ifr_metric);
+ xo_emit(" metric {:metric/%d}", ifr.ifr_metric);
}
#ifdef WITHOUT_NETLINK
@@ -1782,7 +1820,7 @@ print_mtu(if_ctx *ctx)
struct ifreq ifr = {};
if (ioctl_ctx_ifr(ctx, SIOCGIFMTU, &ifr) != -1)
- printf(" mtu %d", ifr.ifr_mtu);
+ xo_emit(" mtu {:mtu/%d}", ifr.ifr_mtu);
}
static void
@@ -1797,16 +1835,16 @@ print_description(if_ctx *ctx)
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);
+ if (strlen(descr) > 0)
+ xo_emit("\tdescription: {:descr/%s}\n",
+ descr);
} else if (ifr.ifr_buffer.length > descrlen) {
descrlen = ifr.ifr_buffer.length;
continue;
}
}
} else
- warn("unable to allocate memory for interface"
+ xo_warn("unable to allocate memory for interface"
"description");
break;
}
@@ -1833,15 +1871,16 @@ status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa)
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);
+ xo_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);
+ xo_open_instance("interface");
+ xo_emit("{:ifname/%s}: flags={:flags-hex/%x}", ctx->ifname, ifa->ifa_flags);
print_bits("flags", &ifa->ifa_flags, 1, IFFBITS, nitems(IFFBITS));
print_metric(ctx);
print_mtu(ctx);
- putchar('\n');
+ xo_emit("\n");
print_description(ctx);
@@ -1849,6 +1888,7 @@ status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa)
tunnel_status(ctx);
+ xo_open_list("address");
for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
if (ift->ifa_addr == NULL)
continue;
@@ -1857,11 +1897,18 @@ status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa)
if (allfamilies) {
const struct afswtch *p;
p = af_getbyfamily(ift->ifa_addr->sa_family);
- if (p != NULL && p->af_status != NULL)
+ if (p != NULL && p->af_status != NULL) {
+ xo_open_instance("address");
p->af_status(ctx, ift);
- } else if (args->afp->af_af == ift->ifa_addr->sa_family)
+ xo_close_instance("address");
+ }
+ } else if (args->afp->af_af == ift->ifa_addr->sa_family) {
+ xo_open_instance("address");
args->afp->af_status(ctx, ift);
+ xo_close_instance("address");
+ }
}
+ xo_close_list("address");
#if 0
if (allfamilies || afp->af_af == AF_LINK) {
const struct afswtch *lafp;
@@ -1888,6 +1935,7 @@ status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa)
if (args->verbose > 0)
sfp_status(ctx);
+ xo_close_instance("interface");
close(s);
ctx->io_s = old_s;
return;
@@ -1906,15 +1954,15 @@ Perrorc(const char *cmd, int error)
switch (errno) {
case ENXIO:
- errx(1, "%s: no such interface", cmd);
+ xo_errx(1, "%s: no such interface", cmd);
break;
case EPERM:
- errx(1, "%s: permission denied", cmd);
+ xo_errx(1, "%s: permission denied", cmd);
break;
default:
- errc(1, error, "%s", cmd);
+ xo_errc(1, error, "%s", cmd);
}
}
@@ -1929,22 +1977,32 @@ print_bits(const char *btype, uint32_t *v, const int v_count,
const char **names, const int n_count)
{
int num = 0;
+ char tag_fmt[64];
+ snprintf(tag_fmt, sizeof(tag_fmt), "{le:%s/%%s}", btype);
+ 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)
- printf("<");
+ xo_emit("{P:<}");
if (num != 1)
- printf(",");
- if (i < n_count)
- printf("%s", names[i]);
- else
- printf("%s_%d", btype, i);
+ 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)
- printf(">");
+ xo_emit("{P:>}");
+ xo_close_list(btype);
}
/*
@@ -1957,24 +2015,24 @@ printb(const char *s, unsigned v, const char *bits)
char c;
if (bits && *bits == 8)
- printf("%s=%o", s, v);
+ xo_emit("{P:/%s=%o}", s, v);
else
- printf("%s=%x", s, v);
+ xo_emit("{P:/%s=%x}", s, v);
if (bits) {
bits++;
- putchar('<');
+ xo_emit("{P:<}");
while ((i = *bits++) != '\0') {
if (v & (1u << (i-1))) {
if (any)
- putchar(',');
+ xo_emit("{P:,}");
any = 1;
for (; (c = *bits) > 32; bits++)
- putchar(c);
+ xo_emit("{P:/%c}", c);
} else
for (; *bits > 32; bits++)
;
}
- putchar('>');
+ xo_emit("{P:>}");
}
}
@@ -1990,7 +2048,7 @@ print_vhid(const struct ifaddrs *ifa)
if (ifd->ifi_vhid == 0)
return;
- printf(" vhid %d", ifd->ifi_vhid);
+ xo_emit(" vhid {:vhid/%d}", ifd->ifi_vhid);
}
void
diff --git a/sbin/ifconfig/ifconfig_netlink.c b/sbin/ifconfig/ifconfig_netlink.c
index b5badfd585b..ff78b7b598a 100644
--- a/sbin/ifconfig/ifconfig_netlink.c
+++ b/sbin/ifconfig/ifconfig_netlink.c
@@ -35,6 +35,8 @@
#include <errno.h>
#include <netdb.h>
+#include <libxo/xo.h>
+
#include <sys/bitcount.h>
#include <sys/param.h>
#include <sys/linker.h>
@@ -92,12 +94,12 @@ nl_init_socket(struct snl_state *ss)
if (modfind("netlink") == -1 && errno == ENOENT) {
/* Try to load */
if (kldload("netlink") == -1)
- err(1, "netlink is not loaded and load attempt failed");
+ xo_err(1, "netlink is not loaded and load attempt failed");
if (snl_init(ss, NETLINK_ROUTE))
return;
}
- err(1, "unable to open netlink socket");
+ xo_err(1, "unable to open netlink socket");
}
int
@@ -350,17 +352,17 @@ print_ifcaps(if_ctx *ctx, if_link_t *link)
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');
+ xo_emit("\toptions={:options/%x}", caps[0]);
+ print_bits("interface-capabilities", caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
+ xo_emit("\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');
+ xo_emit("\tcapabilities={:capabilities/%x}", caps[0]);
+ print_bits("interface-capabilities", caps, sz_u32, ifcap_bit_names, nitems(ifcap_bit_names));
+ xo_emit("\n");
}
}
@@ -368,19 +370,21 @@ static void
status_nl(if_ctx *ctx, struct iface *iface)
{
if_link_t *link = &iface->link;
+
+ xo_open_instance("interface");
struct ifconfig_args *args = ctx->args;
char *drivername = NULL;
- printf("%s: ", link->ifla_ifname);
+ xo_emit("{:ifname/%s}: ", link->ifla_ifname);
- printf("flags=%x", link->ifi_flags);
- print_bits("IFF", &link->ifi_flags, 1, IFFBITS, nitems(IFFBITS));
+ xo_emit("flags={:flags-hex/%x}", link->ifi_flags);
+ print_bits("interface-flags", &link->ifi_flags, 1, IFFBITS, nitems(IFFBITS));
print_metric(ctx);
- printf(" mtu %d\n", link->ifla_mtu);
+ xo_emit(" mtu {:mtu/%d}\n", link->ifla_mtu);
if (link->ifla_ifalias != NULL)
- printf("\tdescription: %s\n", link->ifla_ifalias);
+ xo_emit("\tdescription: {:descr/%s}\n", link->ifla_ifalias);
print_ifcaps(ctx, link);
tunnel_status(ctx);
@@ -394,18 +398,25 @@ status_nl(if_ctx *ctx, struct iface *iface)
sort_iface_ifaddrs(ctx->io_ss, iface);
+ xo_open_list("address");
for (struct ifa *ifa = iface->ifa; ifa != NULL; ifa = ifa->next) {
if (args->allfamilies) {
const struct afswtch *p = af_getbyfamily(ifa->addr.ifa_family);
- if (p != NULL)
+ if (p != NULL) {
+ xo_open_instance("address");
p->af_status(ctx, link, &ifa->addr);
+ xo_close_instance("address");
+ }
} else if (args->afp->af_af == ifa->addr.ifa_family) {
const struct afswtch *p = args->afp;
+ xo_open_instance("address");
p->af_status(ctx, link, &ifa->addr);
+ xo_close_instance("address");
}
}
+ xo_close_list("address");
/* TODO: convert to netlink */
if (args->allfamilies)
@@ -415,23 +426,23 @@ status_nl(if_ctx *ctx, struct iface *iface)
print_ifstatus(ctx);
if (args->drivername || args->verbose) {
- if (ifconfig_get_orig_name(lifh, link->ifla_ifname,
- &drivername) != 0) {
- if (ifconfig_err_errtype(lifh) == OTHER)
- fprintf(stderr, "get original name: %s\n",
- strerror(ifconfig_err_errno(lifh)));
- else
- fprintf(stderr,
- "get original name: error type %d\n",
- ifconfig_err_errtype(lifh));
- exit_code = 1;
- }
+ if (ifconfig_get_orig_name(lifh, link->ifla_ifname,
+ &drivername) != 0) {
+ if (ifconfig_err_errtype(lifh) == OTHER)
+ xo_warnx("get original name: %s",
+ strerror(ifconfig_err_errno(lifh)));
+ else
+ xo_warnx("get original name: error type %d",
+ ifconfig_err_errtype(lifh));
+ exit_code = 1;
+ }
if (drivername != NULL)
- printf("\tdrivername: %s\n", drivername);
+ xo_emit("\tdrivername: {:drivername/%s}\n", drivername);
free(drivername);
}
if (args->verbose > 0)
sfp_status(ctx);
+ xo_close_instance("interface");
}
static int
@@ -440,7 +451,7 @@ get_local_socket(void)
int s = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (s < 0)
- err(1, "socket(family %u,SOCK_DGRAM)", AF_LOCAL);
+ xo_err(1, "socket(family %u,SOCK_DGRAM)", AF_LOCAL);
return (s);
}
@@ -469,6 +480,7 @@ list_interfaces_nl(struct ifconfig_args *args)
qsort(sorted_ifaces, ifmap->count, sizeof(void *), cmp_iface);
prepare_ifaddrs(&ss, ifmap);
+ xo_open_list("interface");
for (uint32_t i = 0, num = 0; i < ifmap->count; i++) {
struct iface *iface = sorted_ifaces[i];
@@ -478,16 +490,19 @@ list_interfaces_nl(struct ifconfig_args *args)
ctx->ifname = iface->link.ifla_ifname;
if (args->namesonly) {
+ xo_open_instance("interface");
if (num++ != 0)
- printf(" ");
- fputs(iface->link.ifla_ifname, stdout);
+ xo_emit("{P: }");
+ xo_emit("{:ifname/%s}", iface->link.ifla_ifname);
+ xo_close_instance("interface");
} else if (args->argc == 0)
status_nl(ctx, iface);
else
ifconfig_ioctl(ctx, 0, args->afp);
}
+ xo_close_list("interface");
if (args->namesonly)
- printf("\n");
+ xo_emit("\n");
close(ctx->io_s);
snl_free(&ss);
diff --git a/sbin/ifconfig/iffib.c b/sbin/ifconfig/iffib.c
index a99dd6885d0..5c6ebbfd054 100644
--- a/sbin/ifconfig/iffib.c
+++ b/sbin/ifconfig/iffib.c
@@ -36,6 +36,7 @@
#include <net/if.h>
#include <net/route.h>
+#include <libxo/xo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -52,13 +53,13 @@ fib_status(if_ctx *ctx)
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);
+ xo_emit("\tfib: {:fib-id/%u}\n", ifr.ifr_fib);
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);
+ xo_emit("\ttunnelfib: {:tunnelfib-id/%u}\n", ifr.ifr_fib);
}
static void
@@ -70,13 +71,13 @@ setiffib(if_ctx *ctx, const char *val, int dummy __unused)
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX) {
- warn("fib %s not valid", val);
+ xo_warn("fib %s not valid", val);
return;
}
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSIFFIB, &ifr) < 0)
- warn("ioctl (SIOCSIFFIB)");
+ xo_warn("ioctl (SIOCSIFFIB)");
}
static void
@@ -88,13 +89,13 @@ settunfib(if_ctx *ctx, const char *val, int dummy __unused)
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX) {
- warn("fib %s not valid", val);
+ xo_warn("fib %s not valid", val);
return;
}
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSTUNFIB, &ifr) < 0)
- warn("ioctl (SIOCSTUNFIB)");
+ xo_warn("ioctl (SIOCSTUNFIB)");
}
static struct cmd fib_cmds[] = {
diff --git a/sbin/ifconfig/ifgif.c b/sbin/ifconfig/ifgif.c
index 9b8be210a59..ea209529d87 100644
--- a/sbin/ifconfig/ifgif.c
+++ b/sbin/ifconfig/ifgif.c
@@ -39,6 +39,7 @@
#include <net/route.h>
#include <ctype.h>
+#include <libxo/xo.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -63,9 +64,9 @@ gif_status(if_ctx *ctx)
return;
if (opts == 0)
return;
- printf("\toptions=%x", opts);
+ xo_emit("\toptions={:options-hex/%x}", opts);
print_bits("options", &opts, 1, GIFBITS, nitems(GIFBITS));
- putchar('\n');
+ xo_emit("\n");
}
static void
@@ -75,7 +76,7 @@ setgifopts(if_ctx *ctx, const char *val __unused, int d)
struct ifreq ifr = { .ifr_data = (caddr_t)&opts };
if (ioctl_ctx_ifr(ctx, GIFGOPTS, &ifr) == -1) {
- warn("ioctl(GIFGOPTS)");
+ xo_warn("ioctl(GIFGOPTS)");
return;
}
@@ -85,7 +86,7 @@ setgifopts(if_ctx *ctx, const char *val __unused, int d)
opts |= d;
if (ioctl_ctx(ctx, GIFSOPTS, &ifr) == -1) {
- warn("ioctl(GIFSOPTS)");
+ xo_warn("ioctl(GIFSOPTS)");
return;
}
}
diff --git a/sbin/ifconfig/ifgre.c b/sbin/ifconfig/ifgre.c
index 43c86a54616..ca4815f4efc 100644
--- a/sbin/ifconfig/ifgre.c
+++ b/sbin/ifconfig/ifgre.c
@@ -40,6 +40,7 @@
#include <err.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
static const char *GREBITS[] = {
[0] = "ENABLE_CSUM",
@@ -55,7 +56,7 @@ gre_status(if_ctx *ctx)
if (ioctl_ctx(ctx, GREGKEY, &ifr) == 0)
if (opts != 0)
- printf("\tgrekey: 0x%x (%u)\n", opts, opts);
+ xo_emit("\tgrekey: 0x{:x} ({:u})\n", opts, opts);
opts = 0;
if (ioctl_ctx(ctx, GREGOPTS, &ifr) != 0 || opts == 0)
return;
@@ -63,10 +64,10 @@ gre_status(if_ctx *ctx)
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);
+ xo_emit("\tudpport: {:udpport/%u}\n", port);
+ xo_emit("\toptions={:options/%x}", opts);
print_bits("options", &opts, 1, GREBITS, nitems(GREBITS));
- putchar('\n');
+ xo_emit("\n");
}
static void
@@ -77,7 +78,7 @@ setifgrekey(if_ctx *ctx, const char *val, int dummy __unused)
ifr.ifr_data = (caddr_t)&grekey;
if (ioctl_ctx_ifr(ctx, GRESKEY, &ifr) < 0)
- warn("ioctl (set grekey)");
+ xo_warn("ioctl (set grekey)");
}
static void
@@ -87,7 +88,7 @@ setifgreport(if_ctx *ctx, const char *val, int dummy __unused)
struct ifreq ifr = { .ifr_data = (caddr_t)&udpport };
if (ioctl_ctx_ifr(ctx, GRESPORT, &ifr) < 0)
- warn("ioctl (set udpport)");
+ xo_warn("ioctl (set udpport)");
}
static void
@@ -97,7 +98,7 @@ setifgreopts(if_ctx *ctx, const char *val __unused, int d)
struct ifreq ifr = { .ifr_data = (caddr_t)&opts };
if (ioctl_ctx_ifr(ctx, GREGOPTS, &ifr) == -1) {
- warn("ioctl(GREGOPTS)");
+ xo_warn("ioctl(GREGOPTS)");
return;
}
@@ -107,7 +108,7 @@ setifgreopts(if_ctx *ctx, const char *val __unused, int d)
opts |= d;
if (ioctl_ctx(ctx, GRESOPTS, &ifr) == -1) {
- warn("ioctl(GIFSOPTS)");
+ xo_warn("ioctl(GIFSOPTS)");
return;
}
}
diff --git a/sbin/ifconfig/ifgroup.c b/sbin/ifconfig/ifgroup.c
index 49cce678bb5..46f81e75f84 100644
--- a/sbin/ifconfig/ifgroup.c
+++ b/sbin/ifconfig/ifgroup.c
@@ -42,6 +42,8 @@
#include "ifconfig.h"
+#include <libxo/xo.h>
+
static void
setifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
{
@@ -50,12 +52,12 @@ setifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
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");
+ xo_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");
+ xo_errx(1, "setifgroup: group name too long");
if (ioctl_ctx(ctx, SIOCAIFGROUP, (caddr_t)&ifgr) == -1 && errno != EEXIST)
- err(1," SIOCAIFGROUP");
+ xo_err(1," SIOCAIFGROUP");
}
static void
@@ -66,12 +68,12 @@ unsetifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
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");
+ xo_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");
+ xo_errx(1, "unsetifgroup: group name too long");
if (ioctl_ctx(ctx, SIOCDIFGROUP, (caddr_t)&ifgr) == -1 && errno != ENOENT)
- err(1, "SIOCDIFGROUP");
+ xo_err(1, "SIOCDIFGROUP");
}
static void
@@ -84,18 +86,22 @@ getifgroups(if_ctx *ctx)
return;
cnt = 0;
+ xo_open_list("group");
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:");
+ xo_emit("{P:\tgroups:}");
cnt++;
- printf(" %s", ifg->ifgrq_group);
+ xo_open_instance("group");
+ xo_emit(" {:name/%s}", ifg->ifgrq_group);
+ xo_close_instance("group");
}
}
if (cnt)
- printf("\n");
+ xo_emit("\n");
+ xo_close_list("group");
free(ifgr.ifgr_groups);
}
@@ -110,7 +116,7 @@ printgroup(const char *groupname)
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (s == -1)
- err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
+ xo_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) {
@@ -118,19 +124,19 @@ printgroup(const char *groupname)
errno == ENOENT)
exit(exit_code);
else
- err(1, "SIOCGIFGMEMB");
+ xo_err(1, "SIOCGIFGMEMB");
}
len = ifgr.ifgr_len;
if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
- err(1, "printgroup");
+ xo_err(1, "printgroup");
if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
- err(1, "SIOCGIFGMEMB");
+ xo_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);
+ xo_emit("{:member-name/%s}\n", ifg->ifgrq_member);
}
free(ifgr.ifgr_groups);
diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c
index e73dcc2c4f2..c84222dca9d 100644
--- a/sbin/ifconfig/ifieee80211.c
+++ b/sbin/ifconfig/ifieee80211.c
@@ -94,6 +94,7 @@
#include <langinfo.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
#include <lib80211/lib80211_regdomain.h>
#include <lib80211/lib80211_ioctl.h>
@@ -157,6 +158,31 @@ static void LINE_INIT(char c);
static void LINE_BREAK(void);
static void LINE_CHECK(const char *fmt, ...);
+static inline void
+fields_emit(const char *fmt, ...)
+{
+ if (xo_get_style(NULL) == XO_STYLE_TEXT)
+ return;
+ va_list ap;
+ va_start(ap, fmt);
+ xo_emit_hv(NULL, fmt, ap);
+ va_end(ap);
+}
+
+static inline void
+fields_open_list(const char *name)
+{
+ if (xo_get_style(NULL) != XO_STYLE_TEXT)
+ xo_open_list(name);
+}
+
+static inline void
+fields_close_list(const char *name)
+{
+ if (xo_get_style(NULL) != XO_STYLE_TEXT)
+ xo_close_list(name);
+}
+
static const char *modename[IEEE80211_MODE_MAX] = {
[IEEE80211_MODE_AUTO] = "auto",
[IEEE80211_MODE_11A] = "11a",
@@ -209,7 +235,7 @@ gethtconf(if_ctx *ctx)
if (gothtconf)
return;
if (get80211val(ctx, IEEE80211_IOC_HTCONF, &htconf) < 0)
- warn("unable to get HT configuration information");
+ xo_warn("unable to get HT configuration information");
gothtconf = 1;
}
@@ -223,7 +249,7 @@ getvhtconf(if_ctx *ctx)
if (gotvhtconf)
return;
if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
- warn("unable to get VHT configuration information");
+ xo_warn("unable to get VHT configuration information");
gotvhtconf = 1;
}
@@ -238,10 +264,10 @@ getchaninfo(if_ctx *ctx)
return;
chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
if (chaninfo == NULL)
- errx(1, "no space for channel list");
+ xo_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");
+ xo_err(1, "unable to get channel information");
global_ifmr = ifmedia_getstate(ctx);
gethtconf(ctx);
getvhtconf(ctx);
@@ -254,7 +280,7 @@ getregdata(void)
if (rdp == NULL) {
rdp = lib80211_alloc_regdata();
if (rdp == NULL)
- errx(-1, "missing or corrupted regdomain database");
+ xo_errx(-1, "missing or corrupted regdomain database");
}
return rdp;
}
@@ -366,7 +392,7 @@ mapfreq(struct ieee80211_channel *chan, uint16_t freq, unsigned int flags)
return;
}
}
- errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
+ xo_errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
}
static void
@@ -386,7 +412,7 @@ mapchan(struct ieee80211_channel *chan, uint8_t ieee, unsigned int flags)
return;
}
}
- errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
+ xo_errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
}
static const struct ieee80211_channel *
@@ -398,7 +424,7 @@ getcurchan(if_ctx *ctx)
int val;
/* fall back to legacy ioctl */
if (get80211val(ctx, IEEE80211_IOC_CHANNEL, &val) < 0)
- err(-1, "cannot figure out current channel");
+ xo_err(-1, "cannot figure out current channel");
getchaninfo(ctx);
mapchan(&curchan, val, 0);
}
@@ -445,7 +471,7 @@ getroam(if_ctx *ctx)
return;
if (get80211(ctx, IEEE80211_IOC_ROAM,
&roamparams, sizeof(roamparams)) < 0)
- err(1, "unable to get roaming parameters");
+ xo_err(1, "unable to get roaming parameters");
gotroam = 1;
}
@@ -463,7 +489,7 @@ gettxparams(if_ctx *ctx)
return;
if (get80211(ctx, IEEE80211_IOC_TXPARAMS,
&txparams, sizeof(txparams)) < 0)
- err(1, "unable to get transmit parameters");
+ xo_err(1, "unable to get transmit parameters");
gottxparams = 1;
}
@@ -481,7 +507,7 @@ getregdomain(if_ctx *ctx)
return;
if (get80211(ctx, IEEE80211_IOC_REGDOMAIN,
&regdomain, sizeof(regdomain)) < 0)
- err(1, "unable to get regulatory domain info");
+ xo_err(1, "unable to get regulatory domain info");
gotregdomain = 1;
}
@@ -490,7 +516,7 @@ getdevcaps(if_ctx *ctx, struct ieee80211_devcaps_req *dc)
{
if (get80211(ctx, IEEE80211_IOC_DEVCAPS, dc,
IEEE80211_DEVCAPS_SPACE(dc)) < 0)
- err(1, "unable to get device capabilities");
+ xo_err(1, "unable to get device capabilities");
}
static void
@@ -511,7 +537,7 @@ setregdomain_cb(if_ctx *ctx, void *arg)
*/
cc = lib80211_country_findbycc(rdp, rd->country);
if (cc == NULL)
- errx(1, "unknown ISO country code %d", rd->country);
+ xo_errx(1, "unknown ISO country code %d", rd->country);
if (cc->rd->sku != rd->regdomain) {
const struct regdomain *rp;
/*
@@ -529,11 +555,11 @@ setregdomain_cb(if_ctx *ctx, void *arg)
*/
rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
if (rp == NULL)
- errx(1, "country %s (%s) is not usable with "
+ xo_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 "
+ xo_errx(1, "country %s (%s) is not usable with "
"regdomain %s", cc->isoname, cc->name,
rp->name);
}
@@ -546,15 +572,15 @@ setregdomain_cb(if_ctx *ctx, void *arg)
*/
dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
if (dc == NULL)
- errx(1, "no space for device capabilities");
+ xo_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);
+ xo_emit("{P:drivercaps: 0x}{:field1/%x}{P:\n}", dc->dc_drivercaps);
+ xo_emit("{P:cryptocaps: 0x}{:field1/%x}{P:\n}", dc->dc_cryptocaps);
+ xo_emit("{P:htcaps : 0x}{:field1/%x}{P:\n}", dc->dc_htcaps);
+ xo_emit("{P:vhtcaps : 0x}{:field1/%x}{P:\n}", dc->dc_vhtcaps);
#if 0
memcpy(chaninfo, &dc->dc_chaninfo,
IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
@@ -564,7 +590,7 @@ setregdomain_cb(if_ctx *ctx, void *arg)
#endif
req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
if (req == NULL)
- errx(1, "no space for regdomain request");
+ xo_errx(1, "no space for regdomain request");
req->rd = *rd;
regdomain_makechannels(ctx, req, dc);
if (ctx->args->verbose) {
@@ -576,13 +602,13 @@ setregdomain_cb(if_ctx *ctx, void *arg)
free(chaninfo);
chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
if (chaninfo == NULL)
- errx(1, "no space for channel list");
+ xo_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*/);
}
if (req->chaninfo.ic_nchans == 0)
- errx(1, "no channels calculated");
+ xo_errx(1, "no channels calculated");
set80211(ctx, IEEE80211_IOC_REGDOMAIN, 0,
IEEE80211_REGDOMAIN_SPACE(req), req);
free(req);
@@ -711,7 +737,7 @@ getchannelflags(const char *val, int freq)
flags |= IEEE80211_CHAN_STURBO;
break;
default:
- errx(-1, "%s: Invalid channel attribute %c\n",
+ xo_errx(-1, "%s: Invalid channel attribute %c\n",
val, *cp);
}
}
@@ -748,7 +774,7 @@ getchannelflags(const char *val, int freq)
flags |= IEEE80211_CHAN_HT40D;
break;
default:
- errx(-1, "%s: Invalid channel width\n", val);
+ xo_errx(-1, "%s: Invalid channel width\n", val);
}
}
@@ -825,7 +851,7 @@ getchannel(if_ctx *ctx, struct ieee80211_channel *chan, const char *val)
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",
+ xo_errx(1, "invalid channel specification%s",
errno == ERANGE ? " (out of range)" : "");
flags = getchannelflags(val, v);
if (v > 255) { /* treat as frequency */
@@ -871,7 +897,7 @@ set80211authmode(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strcasecmp(val, "wpa") == 0) {
mode = IEEE80211_AUTH_WPA;
} else {
- errx(1, "unknown authmode");
+ xo_errx(1, "unknown authmode");
}
set80211(ctx, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
@@ -893,7 +919,7 @@ set80211powersavemode(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strcasecmp(val, "psp-cam") == 0) {
mode = IEEE80211_POWERSAVE_PSP_CAM;
} else {
- errx(1, "unknown powersavemode");
+ xo_errx(1, "unknown powersavemode");
}
set80211(ctx, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
@@ -928,7 +954,7 @@ set80211wepmode(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strcasecmp(val, "mixed") == 0) {
mode = IEEE80211_WEP_MIXED;
} else {
- errx(1, "unknown wep mode");
+ xo_errx(1, "unknown wep mode");
}
set80211(ctx, IEEE80211_IOC_WEP, mode, 0, NULL);
@@ -1036,7 +1062,7 @@ set80211protmode(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strncasecmp(val, "rtscts", 3) == 0) {
mode = IEEE80211_PROTMODE_RTSCTS;
} else {
- errx(1, "unknown protection mode");
+ xo_errx(1, "unknown protection mode");
}
set80211(ctx, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
@@ -1052,7 +1078,7 @@ set80211htprotmode(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strncasecmp(val, "rts", 3) == 0) {
mode = IEEE80211_PROTMODE_RTSCTS;
} else {
- errx(1, "unknown protection mode");
+ xo_errx(1, "unknown protection mode");
}
set80211(ctx, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
@@ -1066,7 +1092,7 @@ set80211txpower(if_ctx *ctx, const char *val, int dummy __unused)
txpow = (int) (2*v);
if (txpow != 2*v)
- errx(-1, "invalid tx power (must be .5 dBm units)");
+ xo_errx(-1, "invalid tx power (must be .5 dBm units)");
set80211(ctx, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
}
@@ -1086,7 +1112,7 @@ set80211roaming(if_ctx *ctx, const char *val, int dummy __unused)
} else if (strcasecmp(val, "manual") == 0) {
mode = IEEE80211_ROAMING_MANUAL;
} else {
- errx(1, "unknown roaming mode");
+ xo_errx(1, "unknown roaming mode");
}
set80211(ctx, IEEE80211_IOC_ROAMING, mode, 0, NULL);
}
@@ -1129,7 +1155,7 @@ set80211chanlist(if_ctx *ctx, const char *val, int dummy __unused)
temp = malloc(strlen(val) + 1);
if (temp == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
strcpy(temp, val);
memset(&chanlist, 0, sizeof(chanlist));
cp = temp;
@@ -1142,19 +1168,19 @@ set80211chanlist(if_ctx *ctx, const char *val, int dummy __unused)
switch (sscanf(cp, "%u-%u", &first, &last)) {
case 1:
if (first > IEEE80211_CHAN_MAX)
- errx(-1, "channel %u out of range, max %u",
+ xo_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",
+ xo_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",
+ xo_errx(-1, "channel %u out of range, max %u",
last, IEEE80211_CHAN_MAX);
if (first > last)
- errx(-1, "void channel range, %u > %u",
+ xo_errx(-1, "void channel range, %u > %u",
first, last);
for (f = first; f <= last; f++)
setbit(chanlist.ic_channels, f);
@@ -1182,14 +1208,14 @@ set80211bssid(if_ctx *ctx, const char *val, int dummy __unused)
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ xo_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");
+ xo_errx(1, "malformed link-level address");
set80211(ctx, IEEE80211_IOC_BSSID, 0,
IEEE80211_ADDR_LEN, LLADDR(&sdl));
} else {
@@ -1211,7 +1237,7 @@ getac(const char *ac)
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);
+ xo_errx(1, "unknown wme access class %s", ac);
}
static void
@@ -1309,14 +1335,14 @@ set80211macmac(if_ctx *ctx, int op, const char *val)
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ xo_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");
+ xo_errx(1, "malformed link-level address");
set80211(ctx, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
}
@@ -1341,14 +1367,14 @@ set80211kickmac(if_ctx *ctx, const char *val, int dummy __unused)
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ xo_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");
+ xo_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 +1396,14 @@ set80211meshrtmac(if_ctx *ctx, int req, const char *val)
temp = malloc(strlen(val) + 2); /* ':' and '\0' */
if (temp == NULL)
- errx(1, "malloc failed");
+ xo_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");
+ xo_errx(1, "malformed link-level address");
set80211(ctx, IEEE80211_IOC_MESH_RTCMD, req,
IEEE80211_ADDR_LEN, LLADDR(&sdl));
}
@@ -1542,7 +1568,7 @@ getmodeflags(const char *val)
flags |= IEEE80211_CHAN_VHT;
break;
default:
- errx(-1, "%s: Invalid mode attribute %c\n",
+ xo_errx(-1, "%s: Invalid mode attribute %c\n",
val, *cp);
}
}
@@ -1626,7 +1652,7 @@ set80211roamrssi(if_ctx *ctx, const char *val, int dummy __unused)
rssi = (int) (2*v);
if (rssi != 2*v)
- errx(-1, "invalid rssi (must be .5 dBm units)");
+ xo_errx(-1, "invalid rssi (must be .5 dBm units)");
flags = getmodeflags(val);
getroam(ctx);
if (flags == 0) { /* NB: no flags => current channel */
@@ -1645,7 +1671,7 @@ getrate(const char *val, const char *tag)
rate = (int) (2*v);
if (rate != 2*v)
- errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
+ xo_errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
return rate; /* NB: returns 2x the specified value */
}
@@ -1787,7 +1813,7 @@ set80211ampdu(if_ctx *ctx, const char *val __unused, int d)
int ampdu;
if (get80211val(ctx, IEEE80211_IOC_AMPDU, &ampdu) < 0)
- errx(-1, "cannot set AMPDU setting");
+ xo_errx(-1, "cannot set AMPDU setting");
if (d < 0) {
d = -d;
ampdu &= ~d;
@@ -1802,7 +1828,7 @@ set80211stbc(if_ctx *ctx, const char *val __unused, int d)
int stbc;
if (get80211val(ctx, IEEE80211_IOC_STBC, &stbc) < 0)
- errx(-1, "cannot set STBC setting");
+ xo_errx(-1, "cannot set STBC setting");
if (d < 0) {
d = -d;
stbc &= ~d;
@@ -1817,7 +1843,7 @@ set80211ldpc(if_ctx *ctx, const char *val __unused, int d)
int ldpc;
if (get80211val(ctx, IEEE80211_IOC_LDPC, &ldpc) < 0)
- errx(-1, "cannot set LDPC setting");
+ xo_errx(-1, "cannot set LDPC setting");
if (d < 0) {
d = -d;
ldpc &= ~d;
@@ -1855,7 +1881,7 @@ set80211ampdulimit(if_ctx *ctx, const char *val, int dummy __unused)
v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
break;
default:
- errx(-1, "invalid A-MPDU limit %s", val);
+ xo_errx(-1, "invalid A-MPDU limit %s", val);
}
set80211(ctx, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
}
@@ -1894,7 +1920,7 @@ set80211ampdudensity(if_ctx *ctx, const char *val, int dummy __unused)
v = IEEE80211_HTCAP_MPDUDENSITY_16;
break;
default:
- errx(-1, "invalid A-MPDU density %s", val);
+ xo_errx(-1, "invalid A-MPDU density %s", val);
}
set80211(ctx, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
}
@@ -1905,7 +1931,7 @@ set80211amsdu(if_ctx *ctx, const char *val __unused, int d)
int amsdu;
if (get80211val(ctx, IEEE80211_IOC_AMSDU, &amsdu) < 0)
- err(-1, "cannot get AMSDU setting");
+ xo_err(-1, "cannot get AMSDU setting");
if (d < 0) {
d = -d;
amsdu &= ~d;
@@ -1979,7 +2005,7 @@ static void
set80211vhtconf(if_ctx *ctx, const char *val __unused, int d)
{
if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
- errx(-1, "cannot set VHT setting");
+ xo_errx(-1, "cannot set VHT setting");
if (d < 0) {
d = -d;
vhtconf &= ~d;
@@ -2163,11 +2189,11 @@ regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci,
LIST_FOREACH(nb, bands, next) {
b = nb->band;
if (verbose) {
- printf("%s:", __func__);
+ xo_emit("{:field1/%s}{P::}", __func__);
printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
printb(" bandFlags", nb->flags | b->flags,
IEEE80211_CHAN_BITS);
- putchar('\n');
+ xo_emit("{P:\n}");
}
prev = NULL;
@@ -2189,36 +2215,31 @@ regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci,
if ((chanFlags & IEEE80211_CHAN_VHT20) &&
(flags & IEEE80211_CHAN_VHT20) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT20 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not a VHT20 channel\n}", freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT40) &&
(flags & IEEE80211_CHAN_VHT40) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT40 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not a VHT40 channel\n}", freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT80) &&
(flags & IEEE80211_CHAN_VHT80) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT80 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not a VHT80 channel\n}", freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT160) &&
(flags & IEEE80211_CHAN_VHT160) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT160 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not a VHT160 channel\n}", freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_VHT80P80) &&
(flags & IEEE80211_CHAN_VHT80P80) == 0) {
if (verbose)
- printf("%u: skip, not a "
- "VHT80+80 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not a VHT80+80 channel\n}", freq);
continue;
}
flags &= ~IEEE80211_CHAN_VHT;
@@ -2236,15 +2257,13 @@ regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci,
if ((chanFlags & IEEE80211_CHAN_HT20) &&
(flags & IEEE80211_CHAN_HT20) == 0) {
if (verbose)
- printf("%u: skip, not an "
- "HT20 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not an HT20 channel\n}", freq);
continue;
}
if ((chanFlags & IEEE80211_CHAN_HT40) &&
(flags & IEEE80211_CHAN_HT40) == 0) {
if (verbose)
- printf("%u: skip, not an "
- "HT40 channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, not an HT40 channel\n}", freq);
continue;
}
/* NB: HT attribute comes from caller */
@@ -2256,42 +2275,37 @@ regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci,
*/
if (!checkchan(avail, freq, flags)) {
if (verbose) {
- printf("%u: skip, ", freq);
+ xo_emit("{:field1/%u}{P:: skip, }", freq);
printb("flags", flags,
IEEE80211_CHAN_BITS);
- printf(" not available\n");
+ xo_emit("{P: not available\n}");
}
continue;
}
if ((flags & REQ_ECM) && !reg->ecm) {
if (verbose)
- printf("%u: skip, ECM channel\n", freq);
+ xo_emit("{:field1/%u}{P:: skip, ECM channel\n}", freq);
continue;
}
if ((flags & REQ_INDOOR) && reg->location == 'O') {
if (verbose)
- printf("%u: skip, indoor channel\n",
- freq);
+ xo_emit("{:field1/%u}{P:: skip, indoor channel\n}", freq);
continue;
}
if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
if (verbose)
- printf("%u: skip, outdoor channel\n",
- freq);
+ xo_emit("{:field1/%u}{P:: skip, outdoor channel\n}", 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,
- freq - prev->ic_freq, channelSep);
+ xo_emit("{:field1/%u}{P:: skip, only }{:field2/%u}{P: channel separation, need }{:field3/%d}{P:\n}", freq, freq - prev->ic_freq, channelSep);
continue;
}
if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
if (verbose)
- printf("%u: skip, channel table full\n",
- freq);
+ xo_emit("{:field1/%u}{P:: skip, channel table full\n}", freq);
break;
}
c = &ci->ic_chans[ci->ic_nchans++];
@@ -2303,10 +2317,9 @@ regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci,
else
c->ic_maxregpower = nb->maxPower;
if (verbose) {
- printf("[%3d] add freq %u ",
- ci->ic_nchans-1, c->ic_freq);
+ xo_emit("{P:[}{:field1/%3d}{P:] add freq }{:field2/%u}{P: }", ci->ic_nchans-1, c->ic_freq);
printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
- printf(" power %u\n", c->ic_maxregpower);
+ xo_emit("{P: power }{:field1/%u}{P:\n}", c->ic_maxregpower);
}
/* NB: kernel fills in other fields */
prev = c;
@@ -2337,13 +2350,13 @@ regdomain_makechannels(
if (reg->regdomain == 0) {
cc = lib80211_country_findbycc(rdp, reg->country);
if (cc == NULL)
- errx(1, "internal error, country %d not found",
+ xo_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",
+ xo_errx(1, "internal error, regdomain %d not found",
reg->regdomain);
if (rd->sku != SKU_DEBUG) {
/*
@@ -2462,19 +2475,18 @@ list_countries(void)
int i;
i = 0;
- printf("\nCountry codes:\n");
+ xo_emit("{P:\nCountry codes:\n}");
LIST_FOREACH(cp, &rdp->countries, next) {
- printf("%2s %-15.15s%s", cp->isoname,
- cp->name, ((i+1)%4) == 0 ? "\n" : " ");
+ xo_emit("{:field1/%2s}{P: }{:field2/%-15.15s}{:field3/%s}", cp->isoname, cp->name, ((i+1)%4) == 0 ? "\n" : " ");
i++;
}
i = 0;
- printf("\nRegulatory domains:\n");
+ xo_emit("{P:\nRegulatory domains:\n}");
LIST_FOREACH(dp, &rdp->domains, next) {
- printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
+ xo_emit("{:field1/%-15.15s}{:field2/%s}", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
i++;
}
- printf("\n");
+ xo_emit("{P:\n}");
}
static void
@@ -2485,7 +2497,7 @@ defaultcountry(const struct regdomain *rd)
cc = lib80211_country_findbycc(rdp, rd->cc->code);
if (cc == NULL)
- errx(1, "internal error, ISO country code %d not "
+ xo_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 +2518,7 @@ set80211regdomain(if_ctx *ctx, const char *val, int dummy __unused)
if (eptr != val)
rd = lib80211_regdomain_findbysku(rdp, sku);
if (eptr == val || rd == NULL)
- errx(1, "unknown regdomain %s", val);
+ xo_errx(1, "unknown regdomain %s", val);
}
getregdomain(ctx);
regdomain.regdomain = rd->sku;
@@ -2534,7 +2546,7 @@ set80211country(if_ctx *ctx, const char *val, int dummy __unused)
if (eptr != val)
cc = lib80211_country_findbycc(rdp, code);
if (eptr == val || cc == NULL)
- errx(1, "unknown ISO country code %s", val);
+ xo_errx(1, "unknown ISO country code %s", val);
}
getregdomain(ctx);
regdomain.regdomain = cc->rd->sku;
@@ -2574,7 +2586,7 @@ static void
LINE_BREAK(void)
{
if (spacer != '\t') {
- printf("\n");
+ xo_emit("{P:\n}");
spacer = '\t';
}
col = 8; /* 8-col tab */
@@ -2595,8 +2607,8 @@ LINE_CHECK(const char *fmt, ...)
LINE_BREAK();
col += n;
}
- buf[0] = spacer;
- printf("%s", buf);
+ xo_emit("{P:/%c}", spacer);
+ xo_emit("{P:/%s}", buf + 1);
spacer = ' ';
}
@@ -2702,20 +2714,20 @@ getflags(int flags)
static void
printie(if_ctx *ctx, const char* tag, const uint8_t *ie, size_t ielen, unsigned int maxlen)
{
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (ctx->args->verbose) {
maxlen -= strlen(tag)+2;
if (2*ielen > maxlen)
maxlen--;
- printf("<");
+ xo_emit("{P:<}");
for (; ielen > 0; ie++, ielen--) {
if (maxlen-- <= 0)
break;
- printf("%02x", *ie);
+ xo_emit("{:field1/%02x}", *ie);
}
if (ielen != 0)
- printf("-");
- printf(">");
+ xo_emit("{P:-}");
+ xo_emit("{P:>}");
}
}
@@ -2744,37 +2756,31 @@ printwmeparam(if_ctx *ctx, const char *tag, const u_int8_t *ie)
(const struct ieee80211_wme_param *) ie;
int i;
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (!ctx->args->verbose)
return;
- printf("<qosinfo 0x%x", wme->param_qosInfo);
+ xo_emit("{P:<qosinfo 0x}{:field1/%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));
+ xo_emit("{P: }{:field1/%s}{P:[}{:field2/%s}{P:aifsn }{:field3/%u}{P: cwmin }{:field4/%u}{P: cwmax }{:field5/%u}{P: txop }{:field6/%u}{P:]}", 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(">");
+ xo_emit("{P:>}");
}
static void
printwmeinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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);
+ xo_emit("{P:<version 0x}{:field1/%x}{P: info 0x}{:field2/%x}{P:>}", wme->wme_version, wme->wme_info);
}
}
@@ -2786,59 +2792,56 @@ printhecap(if_ctx *ctx, const char *tag, const uint8_t *ie)
unsigned int i;
uint8_t chw;
- printf("%s", tag);
+ xo_emit("{:field1/%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]);
+ xo_emit("{P:<err: he_cap inval. length }{:field1/%#0x}{P:>}", 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");
+ xo_emit("{P:<mac_cap}");
for (i = 0; i < nitems(hecap->mac_cap_info); i++)
- printf(" %#04x", hecap->mac_cap_info[i]);
- printf(" phy_cap");
+ xo_emit("{P: }{:field1/%#04x}", hecap->mac_cap_info[i]);
+ xo_emit("{P: phy_cap}");
for (i = 0; i < nitems(hecap->phy_cap_info); i++)
- printf(" %#04x", hecap->phy_cap_info[i]);
+ xo_emit("{P: }{:field1/%#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);
+ xo_emit("{P: rx/%tx_he_mcs map: loweq80 }{:field1/%#06x}{P://}{:field2/%#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);
+ xo_emit("{P: 160 }{:field1/%#06x}{P://}{:field2/%#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);
+ xo_emit("{P: 80+80 }{:field1/%#06x}{P://}{:field2/%#06x}", mcsnss->rx_mcs_80p80, mcsnss->tx_mcs_80p80);
ie += 2;
}
/* TODO: ppet = (struct ... *)ie; */
- printf(">");
+ xo_emit("{P:>}");
}
static void
printheoper(if_ctx *ctx, const char *tag, const uint8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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]);
+ xo_emit("{P:<err: he_oper inval. length }{:field1/%#0x}{P:>}", ie[1]);
return;
}
/* Skip Element ID, Length, EID Extension. */
@@ -2846,19 +2849,19 @@ printheoper(if_ctx *ctx, const char *tag, const uint8_t *ie)
/* 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);
+ xo_emit("{P:<params }{:field1/%#08x}", params);
+ xo_emit("{P: bss_col }{:field1/%#04x}", (heoper->he_oper_params & 0xff000000) >> 24);
+ xo_emit("{P: mcs_nss }{:field1/%#06x}", heoper->he_mcs_nss_set);
if ((params & (1 << 14)) != 0) {
- printf(" vht_op 0-3");
+ xo_emit("{P: vht_op 0-3}");
}
if ((params & (1 << 15)) != 0) {
- printf(" max_coh_bssid 0-1");
+ xo_emit("{P: max_coh_bssid 0-1}");
}
if ((params & (1 << 17)) != 0) {
- printf(" 6ghz_op 0-5");
+ xo_emit("{P: 6ghz_op 0-5}");
}
- printf(">");
+ xo_emit("{P:>}");
}
}
@@ -2869,31 +2872,27 @@ printmuedcaparamset(if_ctx *ctx, const char *tag, const uint8_t *ie)
const struct ieee80211_mu_edca_param_set *mu_edca;
int i;
- printf("%s", tag);
+ xo_emit("{:field1/%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]);
+ xo_emit("{P:<err: mu_edca inval. length }{:field1/%#04x}{P:>}", 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);
+ xo_emit("{P:<qosinfo 0x}{:field1/%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);
+ xo_emit("{P: }{:field1/%s}{P:[aifsn }{:field2/%u}{P: ecwmin }{:field3/%u}{P: ecwmax }{:field4/%u}{P: timer }{:field5/%u}{P:]}", 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(">");
+ xo_emit("{P:>}");
}
static void
@@ -2901,112 +2900,104 @@ printsupopclass(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
uint8_t len, i;
- printf("%s", tag);
+ xo_emit("{:field1/%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]);
+ xo_emit("{P:<err: sup_op_class inval. length }{:field1/%#04x}{P:>}", ie[1]);
return;
}
ie += 2;
i = 0;
- printf("<cur op class %u", *ie);
+ xo_emit("{P:<cur op class }{:field1/%u}", *ie);
i++;
if (i < len && *(ie + i) != 130)
- printf(" op classes");
+ xo_emit("{P: op classes}");
while (i < len && *(ie + i) != 130) {
- printf(" %u", *(ie + i));
+ xo_emit("{P: }{:field1/%u}", *(ie + i));
i++;
}
if (i > 1 && i < len && *(ie + i) != 130) {
- printf(" parsing error at %#0x>", i);
+ xo_emit("{P: parsing error at }{:field1/%#0x}{P:>}", i);
return;
}
/* Skip OneHundredAndThirty Delimiter. */
i++;
if (i < len && *(ie + i) != 0)
- printf(" ext seq");
+ xo_emit("{P: ext seq}");
while (i < len && *(ie + i) != 0) {
- printf(" %u", *(ie + i));
+ xo_emit("{P: }{:field1/%u}", *(ie + i));
i++;
}
if (i > 1 && i < len && *(ie + i) != 0) {
- printf(" parsing error at %#0x>", i);
+ xo_emit("{P: parsing error at }{:field1/%#0x}{P:>}", i);
return;
}
/* Skip Zero Delimiter. */
i++;
if ((i + 1) < len)
- printf(" duple seq");
+ xo_emit("{P: duple seq}");
while ((i + 1) < len) {
- printf(" %u/%u", *(ie + i), *(ie + i + 1));
+ xo_emit("{P: }{:field1/%u}{P://}{:field2/%u}", *(ie + i), *(ie + i + 1));
i += 2;
}
- printf(">");
+ xo_emit("{P:>}");
}
static void
printvhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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>");
+ 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);
- 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);
+ xo_emit("{P:<cap 0x}{:field1/%08x}", vhtcap_info);
+ xo_emit("{P: rx_mcs_map 0x}{:field1/%x}", LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
+ xo_emit("{P: rx_highest }{:field1/%d}", LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
+ xo_emit("{P: tx_mcs_map 0x}{:field1/%x}", LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
+ xo_emit("{P: tx_highest }{:field1/%d}", LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
- printf(">");
+ xo_emit("{P:>}");
}
}
static void
printvhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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>");
+ xo_emit("{P:<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));
+ xo_emit("{P:<chw }{:field1/%d}{P: freq0_idx }{:field2/%d}{P: freq1_idx }{:field3/%d}{P: basic_mcs_set 0x}{:field4/%04x}{P:>}", 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);
+ xo_emit("{:field1/%s}", tag);
static const char *txpwrmap[] = {
"20",
"40",
@@ -3025,30 +3016,28 @@ printvhtpwrenv(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
/* Trim at ielen */
if (n + 3 > ielen)
n = ielen - 3;
- printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
+ xo_emit("{P:<tx_info 0x}{:field1/%02x}{P: 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);
+ xo_emit("{:field1/%s}{:field2/%s}{P::}{:field3/%.2f}", sep, txpwrmap[i], ((float) ((int8_t) ie[i+3])) / 2.0);
sep = " ";
}
- printf("]>");
+ xo_emit("{P:]>}");
}
}
static void
printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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[");
+ xo_emit("{P:<cap 0x}{:field1/%x}{P: param 0x}{:field2/%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)) {
@@ -3057,33 +3046,28 @@ printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie)
break;
j--;
if (i == j)
- printf("%s%u", sep, i);
+ xo_emit("{:field1/%s}{:field2/%u}", sep, i);
else
- printf("%s%u-%u", sep, i, j);
+ xo_emit("{:field1/%s}{:field2/%u}{P:-}{:field3/%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);
+ xo_emit("{P:] extcap 0x}{:field1/%x}{P: txbf 0x}{:field2/%x}{P: antenna 0x}{:field3/%x}{P:>}", 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);
+ xo_emit("{:field1/%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[");
+ xo_emit("{P:<ctl }{:field1/%u}{P:, }{:field2/%x}{P:,}{:field3/%x}{P:,}{:field4/%x}{P:,}{:field5/%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)) {
@@ -3092,13 +3076,13 @@ printhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie)
break;
j--;
if (i == j)
- printf("%s%u", sep, i);
+ xo_emit("{:field1/%s}{:field2/%u}", sep, i);
else
- printf("%s%u-%u", sep, i, j);
+ xo_emit("{:field1/%s}{:field2/%u}{P:-}{:field3/%u}", sep, i, j);
i += j-i;
sep = ",";
}
- printf("]>");
+ xo_emit("{P:]>}");
}
}
@@ -3106,29 +3090,29 @@ static void
printathie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (ctx->args->verbose) {
const struct ieee80211_ath_ie *ath =
(const struct ieee80211_ath_ie *)ie;
- printf("<");
+ xo_emit("{P:<}");
if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
- printf("DTURBO,");
+ xo_emit("{P:DTURBO,}");
if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
- printf("COMP,");
+ xo_emit("{P:COMP,}");
if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
- printf("FF,");
+ xo_emit("{P:FF,}");
if (ath->ath_capability & ATHEROS_CAP_XR)
- printf("XR,");
+ xo_emit("{P:XR,}");
if (ath->ath_capability & ATHEROS_CAP_AR)
- printf("AR,");
+ xo_emit("{P:AR,}");
if (ath->ath_capability & ATHEROS_CAP_BURST)
- printf("BURST,");
+ xo_emit("{P:BURST,}");
if (ath->ath_capability & ATHEROS_CAP_WME)
- printf("WME,");
+ xo_emit("{P:WME,}");
if (ath->ath_capability & ATHEROS_CAP_BOOST)
- printf("BOOST,");
- printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
+ xo_emit("{P:BOOST,}");
+ xo_emit("{P:0x}{:field1/%x}{P:>}", LE_READ_2(ath->ath_defkeyix));
}
}
@@ -3137,70 +3121,66 @@ static void
printmeshconf(if_ctx *ctx, const char *tag, const uint8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (ctx->args->verbose) {
const struct ieee80211_meshconf_ie *mconf =
(const struct ieee80211_meshconf_ie *)ie;
- printf("<PATH:");
+ xo_emit("{P:<PATH:}");
if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
- printf("HWMP");
+ xo_emit("{P:HWMP}");
else
- printf("UNKNOWN");
- printf(" LINK:");
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: LINK:}");
if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
- printf("AIRTIME");
+ xo_emit("{P:AIRTIME}");
else
- printf("UNKNOWN");
- printf(" CONGESTION:");
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: CONGESTION:}");
if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
- printf("DISABLED");
+ xo_emit("{P:DISABLED}");
else
- printf("UNKNOWN");
- printf(" SYNC:");
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: SYNC:}");
if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
- printf("NEIGHOFF");
+ xo_emit("{P:NEIGHOFF}");
else
- printf("UNKNOWN");
- printf(" AUTH:");
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: AUTH:}");
if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
- printf("DISABLED");
+ xo_emit("{P:DISABLED}");
else
- printf("UNKNOWN");
- printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
- mconf->conf_cap);
+ xo_emit("{P:UNKNOWN}");
+ xo_emit("{P: FORM:0x}{:field1/%x}{P: CAPS:0x}{:field2/%x}{P:>}", mconf->conf_form, mconf->conf_cap);
}
}
static void
printbssload(if_ctx *ctx, const char *tag, const uint8_t *ie)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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);
+ xo_emit("{P:<sta count }{:field1/%d}{P:, chan load }{:field2/%d}{P:, aac }{:field3/%d}{P:>}", 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);
+ xo_emit("{:field1/%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);
+ xo_emit("{P:<class }{:field1/%u}{P:, chan:[}", ap->i_class);
for (size_t i = 3; i < ielen; i++) {
- printf("%s%u", sep, ie[i]);
+ xo_emit("{:field1/%s}{:field2/%u}", sep, ie[i]);
sep = ",";
}
- printf("]>");
+ xo_emit("{P:]>}");
}
}
@@ -3249,17 +3229,17 @@ printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
u_int8_t len = ie[1];
- printf("%s", tag);
+ xo_emit("{:field1/%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));
+ xo_emit("{P:<v}{:field1/%u}", LE_READ_2(ie));
ie += 2, len -= 2;
- printf(" mc:%s", wpa_cipher(ie));
+ xo_emit("{P: mc:}{:field1/%s}", wpa_cipher(ie));
ie += 4, len -= 4;
/* unicast ciphers */
@@ -3267,7 +3247,7 @@ printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
ie += 2, len -= 2;
sep = " uc:";
for (; n > 0; n--) {
- printf("%s%s", sep, wpa_cipher(ie));
+ xo_emit("{:field1/%s}{:field2/%s}", sep, wpa_cipher(ie));
ie += 4, len -= 4;
sep = "+";
}
@@ -3277,14 +3257,14 @@ printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
ie += 2, len -= 2;
sep = " km:";
for (; n > 0; n--) {
- printf("%s%s", sep, wpa_keymgmt(ie));
+ xo_emit("{:field1/%s}{:field2/%s}", sep, wpa_keymgmt(ie));
ie += 4, len -= 4;
sep = "+";
}
if (len > 2) /* optional capabilities */
- printf(", caps 0x%x", LE_READ_2(ie));
- printf(">");
+ xo_emit("{P:, caps 0x}{:field1/%x}", LE_READ_2(ie));
+ xo_emit("{P:>}");
}
}
@@ -3343,17 +3323,17 @@ rsn_keymgmt(const u_int8_t *sel)
static void
printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
{
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (ctx->args->verbose) {
const char *sep;
int n;
ie += 2, ielen -= 2;
- printf("<v%u", LE_READ_2(ie));
+ xo_emit("{P:<v}{:field1/%u}", LE_READ_2(ie));
ie += 2, ielen -= 2;
- printf(" mc:%s", rsn_cipher(ie));
+ xo_emit("{P: mc:}{:field1/%s}", rsn_cipher(ie));
ie += 4, ielen -= 4;
/* unicast ciphers */
@@ -3361,7 +3341,7 @@ printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
ie += 2, ielen -= 2;
sep = " uc:";
for (; n > 0; n--) {
- printf("%s%s", sep, rsn_cipher(ie));
+ xo_emit("{:field1/%s}{:field2/%s}", sep, rsn_cipher(ie));
ie += 4, ielen -= 4;
sep = "+";
}
@@ -3371,15 +3351,15 @@ printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
ie += 2, ielen -= 2;
sep = " km:";
for (; n > 0; n--) {
- printf("%s%s", sep, rsn_keymgmt(ie));
+ xo_emit("{:field1/%s}{:field2/%s}", sep, rsn_keymgmt(ie));
ie += 4, ielen -= 4;
sep = "+";
}
if (ielen > 2) /* optional capabilities */
- printf(", caps 0x%x", LE_READ_2(ie));
+ xo_emit("{P:, caps 0x}{:field1/%x}", LE_READ_2(ie));
/* XXXPMKID */
- printf(">");
+ xo_emit("{P:>}");
}
}
@@ -3388,26 +3368,26 @@ printrsnxe(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
{
size_t n;
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (!ctx->args->verbose)
return;
ie += 2, ielen -= 2;
n = (*ie & 0x0f);
- printf("<%zu", n + 1);
+ xo_emit("{P:<}{:field1/%u}", n + 1);
/* We do not yet know about more than n=1 (0). */
if (n != 0)
goto end;
if (*ie & 0x10)
- printf(" PTWTOPS");
+ xo_emit("{P: PTWTOPS}");
if (*ie & 0x20)
- printf(" SAE h-t-e");
+ xo_emit("{P: SAE h-t-e}");
end:
- printf(">");
+ xo_emit("{P:>}");
}
#define BE_READ_2(p) \
@@ -3420,7 +3400,7 @@ printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
{
u_int8_t len = ie[1];
- printf("%s", tag);
+ xo_emit("{:field1/%s}", tag);
if (ctx->args->verbose) {
static const char *dev_pass_id[] = {
"D", /* Default (PIN) */
@@ -3436,7 +3416,7 @@ printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
ie +=6, len -= 4; /* NB: len is payload only */
/* WPS IE in Beacon and Probe Resp frames have different fields */
- printf("<");
+ xo_emit("{P:<}");
while (len) {
uint16_t tlv_type = BE_READ_2(ie);
uint16_t tlv_len = BE_READ_2(ie + 2);
@@ -3444,9 +3424,7 @@ printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
/* 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);
+ xo_emit("{P:bad frame length tlv_type=0x}{:field1/%02x}{P: tlv_len=}{:field2/%d}{P: len=}{:field3/%d}", tlv_type, tlv_len, len);
break;
}
@@ -3454,38 +3432,38 @@ printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
switch (tlv_type) {
case IEEE80211_WPS_ATTR_VERSION:
- printf("v:%d.%d", *ie >> 4, *ie & 0xf);
+ xo_emit("{P:v:}{:field1/%d}{P:.}{:field2/%d}", *ie >> 4, *ie & 0xf);
break;
case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
- printf(" ap_setup:%s", *ie ? "locked" :
+ xo_emit("{P: ap_setup:}{:field1/%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:");
+ xo_emit("{P: sel_reg_cfg_mthd:}");
else
- printf(" cfg_mthd:" );
+ xo_emit("{P: cfg_mthd:}");
cfg_mthd = BE_READ_2(ie);
f = 0;
for (n = 15; n >= 0; n--) {
if (f) {
- printf(",");
+ xo_emit("{P:,}");
f = 0;
}
switch (cfg_mthd & (1 << n)) {
case 0:
break;
case IEEE80211_WPS_CONFIG_USBA:
- printf("usba");
+ xo_emit("{P:usba}");
f++;
break;
case IEEE80211_WPS_CONFIG_ETHERNET:
- printf("ethernet");
+ xo_emit("{P:ethernet}");
f++;
break;
case IEEE80211_WPS_CONFIG_LABEL:
- printf("label");
+ xo_emit("{P:label}");
f++;
break;
case IEEE80211_WPS_CONFIG_DISPLAY:
@@ -3493,171 +3471,166 @@ printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie)
(IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
IEEE80211_WPS_CONFIG_PHY_DISPLAY)))
{
- printf("display");
+ xo_emit("{P:display}");
f++;
}
break;
case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
- printf("ext_nfc_tokenk");
+ xo_emit("{P:ext_nfc_tokenk}");
f++;
break;
case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
- printf("int_nfc_token");
+ xo_emit("{P:int_nfc_token}");
f++;
break;
case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
- printf("nfc_interface");
+ xo_emit("{P: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");
+ xo_emit("{P:push_button}");
f++;
}
break;
case IEEE80211_WPS_CONFIG_KEYPAD:
- printf("keypad");
+ xo_emit("{P:keypad}");
f++;
break;
case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
- printf("virtual_push_button");
+ xo_emit("{P:virtual_push_button}");
f++;
break;
case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
- printf("physical_push_button");
+ xo_emit("{P:physical_push_button}");
f++;
break;
case IEEE80211_WPS_CONFIG_P2PS:
- printf("p2ps");
+ xo_emit("{P:p2ps}");
f++;
break;
case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
- printf("virtual_display");
+ xo_emit("{P:virtual_display}");
f++;
break;
case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
- printf("physical_display");
+ xo_emit("{P:physical_display}");
f++;
break;
default:
- printf("unknown_wps_config<%04x>",
- cfg_mthd & (1 << n));
+ xo_emit("{P:unknown_wps_config<}{:field1/%04x}{P:>}", cfg_mthd & (1 << n));
f++;
break;
}
}
break;
case IEEE80211_WPS_ATTR_DEV_NAME:
- printf(" device_name:<%.*s>", tlv_len, ie);
+ xo_emit("{P: device_name:<}{:field1/%.*s}{P:>}", 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]);
+ xo_emit("{P: dpi:}{:field1/%s}", dev_pass_id[n]);
break;
case IEEE80211_WPS_ATTR_MANUFACTURER:
- printf(" manufacturer:<%.*s>", tlv_len, ie);
+ xo_emit("{P: manufacturer:<}{:field1/%.*s}{P:>}", tlv_len, ie);
break;
case IEEE80211_WPS_ATTR_MODEL_NAME:
- printf(" model_name:<%.*s>", tlv_len, ie);
+ xo_emit("{P: model_name:<}{:field1/%.*s}{P:>}", tlv_len, ie);
break;
case IEEE80211_WPS_ATTR_MODEL_NUMBER:
- printf(" model_number:<%.*s>", tlv_len, ie);
+ xo_emit("{P: model_number:<}{:field1/%.*s}{P:>}", tlv_len, ie);
break;
case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
- printf(" prim_dev:");
+ xo_emit("{P: prim_dev:}");
for (n = 0; n < tlv_len; n++)
- printf("%02x", ie[n]);
+ xo_emit("{:field1/%02x}", ie[n]);
break;
case IEEE80211_WPS_ATTR_RF_BANDS:
- printf(" rf:");
+ xo_emit("{P: rf:}");
f = 0;
for (n = 7; n >= 0; n--) {
if (f) {
- printf(",");
+ xo_emit("{P:,}");
f = 0;
}
switch (*ie & (1 << n)) {
case 0:
break;
case IEEE80211_WPS_RF_BAND_24GHZ:
- printf("2.4Ghz");
+ xo_emit("{P:2.4Ghz}");
f++;
break;
case IEEE80211_WPS_RF_BAND_50GHZ:
- printf("5Ghz");
+ xo_emit("{P:5Ghz}");
f++;
break;
case IEEE80211_WPS_RF_BAND_600GHZ:
- printf("60Ghz");
+ xo_emit("{P:60Ghz}");
f++;
break;
default:
- printf("unknown<%02x>",
- *ie & (1 << n));
+ xo_emit("{P:unknown<}{:field1/%02x}{P:>}", *ie & (1 << n));
f++;
break;
}
}
break;
case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
- printf(" resp_type:0x%02x", *ie);
+ xo_emit("{P: resp_type:0x}{:field1/%02x}", *ie);
break;
case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
- printf(" sel:%s", *ie ? "T" : "F");
+ xo_emit("{P: sel:}{:field1/%s}", *ie ? "T" : "F");
break;
case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
- printf(" serial_number:<%.*s>", tlv_len, ie);
+ xo_emit("{P: serial_number:<}{:field1/%.*s}{P:>}", tlv_len, ie);
break;
case IEEE80211_WPS_ATTR_UUID_E:
- printf(" uuid-e:");
+ xo_emit("{P: uuid-e:}");
for (n = 0; n < (tlv_len - 1); n++)
- printf("%02x-", ie[n]);
- printf("%02x", ie[n]);
+ xo_emit("{:field1/%02x}{P:-}", ie[n]);
+ xo_emit("{:field1/%02x}", ie[n]);
break;
case IEEE80211_WPS_ATTR_VENDOR_EXT:
- printf(" vendor:");
+ xo_emit("{P: vendor:}");
for (n = 0; n < tlv_len; n++)
- printf("%02x", ie[n]);
+ xo_emit("{:field1/%02x}", ie[n]);
break;
case IEEE80211_WPS_ATTR_WPS_STATE:
switch (*ie) {
case IEEE80211_WPS_STATE_NOT_CONFIGURED:
- printf(" state:N");
+ xo_emit("{P: state:N}");
break;
case IEEE80211_WPS_STATE_CONFIGURED:
- printf(" state:C");
+ xo_emit("{P: state:C}");
break;
default:
- printf(" state:B<%02x>", *ie);
+ xo_emit("{P: state:B<}{:field1/%02x}{P:>}", *ie);
break;
}
break;
default:
- printf(" unknown_wps_attr:0x%x", tlv_type);
+ xo_emit("{P: unknown_wps_attr:0x}{:field1/%x}", tlv_type);
break;
}
ie += tlv_len, len -= tlv_len;
}
- printf(">");
+ xo_emit("{P:>}");
}
}
static void
printtdmaie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen)
{
- printf("%s", tag);
+ xo_emit("{:field1/%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]);
+ xo_emit("{P:<v}{:field1/%u}{P: slot:}{:field2/%u}{P: slotcnt:}{:field3/%u}{P: slotlen:}{:field4/%u}{P: bintval:}{:field5/%u}{P: inuse:0x}{:field6/%x}{P:>}", tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt, LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval, tdma->tdma_inuse[0]);
}
}
@@ -3708,7 +3681,7 @@ 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);
+ xo_emit("{:field1/%s}{P:<}{:field2/%.*s}{P:>}", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
}
static void
@@ -3716,15 +3689,13 @@ printrates(const char *tag, const u_int8_t *ie, size_t ielen)
{
const char *sep;
- printf("%s", tag);
+ xo_emit("{:field1/%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);
+ xo_emit("{:field1/%s}{:field2/%s}{:field3/%d}", sep, ie[i] & IEEE80211_RATE_BASIC ? "B" : "", ie[i] & IEEE80211_RATE_VAL);
sep = ",";
}
- printf(">");
+ xo_emit("{P:>}");
}
static void
@@ -3734,18 +3705,17 @@ printcountry(const char *tag, const u_int8_t *ie)
(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]);
+ xo_emit("{:field1/%s}{P:<}{:field2/%c}{:field3/%c}{:field4/%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);
+ xo_emit("{P: }{:field1/%u}{P:-}{:field2/%u}{P:,}{:field3/%u}", schan, schan + nchan-1, cie->band[i].maxtxpwr);
else
- printf(" %u,%u", schan, cie->band[i].maxtxpwr);
+ xo_emit("{P: }{:field1/%u}{P:,}{:field2/%u}", schan, cie->band[i].maxtxpwr);
}
- printf(">");
+ xo_emit("{P:>}");
}
static __inline int
@@ -3796,8 +3766,7 @@ ie_ext_name(uint8_t ext_elemid)
case IEEE80211_ELEMID_EXT_HE_OPER: return " HEOPER";
case IEEE80211_ELEMID_EXT_MU_EDCA_PARAM_SET: return " MU_EDCA_PARAM_SET";
}
- snprintf(iename_buf, sizeof(iename_buf), " ELEMID_EXT_%d",
- ext_elemid & 0xff);
+ snprintf(iename_buf, sizeof(iename_buf), " ELEMID_EXT_%d", ext_elemid);
return (const char *) iename_buf;
}
@@ -3841,8 +3810,7 @@ iename(uint8_t elemid, const u_int8_t *vp)
return ie_ext_name(vp[2]);
break;
}
- snprintf(iename_buf, sizeof(iename_buf), " ELEMID_%d",
- elemid);
+ snprintf(iename_buf, sizeof(iename_buf), " ELEMID_%d", elemid);
return (const char *) iename_buf;
}
@@ -3890,7 +3858,7 @@ printies(if_ctx *ctx, const u_int8_t *vp, int ielen, unsigned int maxcols)
break;
case IEEE80211_ELEMID_DSPARMS:
if (verbose)
- printf(" DSPARMS<%u>", vp[2]);
+ xo_emit("{P: DSPARMS<}{:field1/%u}{P:>}", vp[2]);
break;
case IEEE80211_ELEMID_COUNTRY:
if (verbose)
@@ -3898,7 +3866,7 @@ printies(if_ctx *ctx, const u_int8_t *vp, int ielen, unsigned int maxcols)
break;
case IEEE80211_ELEMID_ERP:
if (verbose)
- printf(" ERP<0x%x>", vp[2]);
+ xo_emit("{P: ERP<0x}{:field1/%x}{P:>}", vp[2]);
break;
case IEEE80211_ELEMID_VENDOR:
if (iswpaoui(vp))
@@ -3985,15 +3953,7 @@ printmimo(const struct ieee80211_mimo_info *mi)
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]);
+ xo_emit("{P: (rssi }{:field1/%.1f}{P::}{:field2/%.1f}{P::}{:field3/%.1f}{P::}{:field4/%.1f}{P: nf }{:field5/%d}{P::}{:field6/%d}{P::}{:field7/%d}{P::}{:field8/%d}{P:)}", 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
@@ -4004,7 +3964,7 @@ printbssidname(const struct ether_addr *n)
if (ether_ntohost(name, n) != 0)
return;
- printf(" (%s)", name);
+ xo_emit("{P: (}{:hostname/%s}{P:)}", name);
}
static void
@@ -4016,21 +3976,13 @@ list_scan(if_ctx *ctx)
int len, idlen;
if (get80211len(ctx, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
- errx(1, "unable to get scan results");
+ xo_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"
- );
+ xo_emit("{:field1/%-32.32s}{P: }{:field2/%-17.17s}{P: }{:field3/%4s}{P: }{:field4/%4s}{P: }{:field5/%-7s}{P: }{:field6/%3s}{P: }{:field7/%4s}{P:\n}", "SSID/MESH ID", "BSSID", "CHAN", "RATE", " S:N", "INT", "CAPS");
cp = buf;
do {
const struct ieee80211req_scan_result *sr;
@@ -4045,21 +3997,11 @@ list_scan(if_ctx *ctx)
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)
- );
+ xo_emit("{:field1/%-*.*s}{P: }{:field2/%s}{P: }{:field3/%3d}{P: }{:field4/%3d}{P:M }{:field5/%4d}{P::}{:field6/%-4d}{P: }{:field7/%4d}{P: }{:field8/%-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,
sr->isr_ie_len, 24);
printbssidname((const struct ether_addr *)sr->isr_bssid);
- printf("\n");
+ xo_emit("{P:\n}");
cp += sr->isr_len, len -= sr->isr_len;
} while (len >= (int)sizeof(struct ieee80211req_scan_result));
}
@@ -4073,7 +4015,7 @@ scan_and_wait(if_ctx *ctx)
sroute = socket(PF_ROUTE, SOCK_RAW, 0);
if (sroute < 0) {
- perror("socket(PF_ROUTE,SOCK_RAW)");
+ xo_warn("%s", "socket(PF_ROUTE,SOCK_RAW)"); /* perror */
return;
}
memset(&ireq, 0, sizeof(ireq));
@@ -4102,7 +4044,7 @@ scan_and_wait(if_ctx *ctx)
do {
if (read(sroute, buf, sizeof(buf)) < 0) {
- perror("read(PF_ROUTE)");
+ xo_warn("%s", "read(PF_ROUTE)"); /* perror */
break;
}
rtm = (struct rt_msghdr *)(void *)buf;
@@ -4175,38 +4117,16 @@ list_stations(if_ctx *ctx)
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");
+ xo_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"
- );
+ xo_emit("{:field1/%-17.17s}{P: }{:field2/%4s}{P: }{:field3/%5s}{P: }{:field4/%5s}{P: }{:field5/%7s}{P: }{:field6/%4s}{P: }{:field7/%4s}{P: }{:field8/%4s}{P: }{:field9/%6s}{P: }{:field10/%6s}{P:\n}", "ADDR", "CHAN", "LOCAL", "PEER", "STATE", "RATE", "RSSI", "IDLE", "TXSEQ", "RXSEQ");
else
- printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n"
- , "ADDR"
- , "AID"
- , "CHAN"
- , "RATE"
- , "RSSI"
- , "IDLE"
- , "TXSEQ"
- , "RXSEQ"
- , "CAPS"
- , "FLAG"
- );
+ xo_emit("{:field1/%-17.17s}{P: }{:field2/%4s}{P: }{:field3/%4s}{P: }{:field4/%4s}{P: }{:field5/%4s}{P: }{:field6/%4s}{P: }{:field7/%6s}{P: }{:field8/%6s}{P: }{:field9/%4s}{P: }{:field10/%-12s}{P:\n}", "ADDR", "AID", "CHAN", "RATE", "RSSI", "IDLE", "TXSEQ", "RXSEQ", "CAPS", "FLAG");
cp = (const uint8_t *) u.req.info;
do {
const struct ieee80211req_sta_info *si;
@@ -4215,38 +4135,16 @@ list_stations(if_ctx *ctx)
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)
- );
+ xo_emit("{:field1/%s}{P: }{:field2/%4d}{P: }{:field3/%5x}{P: }{:field4/%5x}{P: }{:field5/%7.7s}{P: }{:field6/%3d}{P:M }{:field7/%4.1f}{P: }{:field8/%4d}{P: }{:field9/%6d}{P: }{:field10/%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 %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)
- );
+ xo_emit("{:field1/%s}{P: }{:field2/%4u}{P: }{:field3/%4d}{P: }{:field4/%3d}{P:M }{:field5/%4.1f}{P: }{:field6/%4d}{P: }{:field7/%6d}{P: }{:field8/%6d}{P: }{:field9/%-4.4s}{P: }{:field10/%-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");
+ xo_emit("{P:\n}");
cp += si->isi_len, len -= si->isi_len;
} while (len >= (int)sizeof(struct ieee80211req_sta_info));
}
@@ -4330,19 +4228,9 @@ 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)));
+ xo_emit("{P:Channel }{:field1/%3u}{P: : }{:field2/%u}{:field3/%c}{:field4/%c}{:field5/%c}{:field6/%c}{:field7/%c}{P: MHz}{:field8/%-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)));
+ xo_emit("{P:Channel }{:field1/%3u}{P: : }{:field2/%u}{:field3/%c}{P: MHz}{:field4/%-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)));
}
@@ -4392,14 +4280,14 @@ print_channels(if_ctx *ctx, const struct ieee80211req_chaninfo *chans,
achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
if (achans == NULL)
- errx(1, "no space for active channel list");
+ xo_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");
+ xo_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))
@@ -4441,11 +4329,11 @@ print_channels(if_ctx *ctx, const struct ieee80211req_chaninfo *chans,
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");
+ xo_emit("{P:\n}");
}
if (achans->ic_nchans % 2) {
print_chaninfo(&achans->ic_chans[i], verb);
- printf("\n");
+ xo_emit("{P:\n}");
}
free(achans);
}
@@ -4460,20 +4348,17 @@ list_channels(if_ctx *ctx, int allchans)
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);
+ xo_emit("{P:Channel }{:field1/%3u}{P: : }{:field2/%u}{P: MHz }{:field3/%3.1f}{P: reg }{:field4/%2d}{P: }", 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);
+ xo_emit("{P:min }{:field1/%4.1f}{P: dBm max }{:field2/%3.1f}{P: dBm reg }{:field3/%2d}{P: 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(" <");
+ xo_emit("{P: <}");
}
static void
@@ -4487,7 +4372,7 @@ list_txpow(if_ctx *ctx)
getchaninfo(ctx);
achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
if (achans == NULL)
- errx(1, "no space for active channel list");
+ xo_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++) {
@@ -4513,16 +4398,16 @@ list_txpow(if_ctx *ctx)
for (i = 0; i < achans->ic_nchans / 2; i++) {
print_txpow(&achans->ic_chans[i]);
print_txpow(&achans->ic_chans[half+i]);
- printf("\n");
+ xo_emit("{P:\n}");
}
if (achans->ic_nchans % 2) {
print_txpow(&achans->ic_chans[i]);
- printf("\n");
+ xo_emit("{P:\n}");
}
} else {
for (i = 0; i < achans->ic_nchans; i++) {
print_txpow_verbose(&achans->ic_chans[i]);
- printf("\n");
+ xo_emit("{P:\n}");
}
}
free(achans);
@@ -4544,24 +4429,24 @@ list_capabilities(if_ctx *ctx)
else
dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
if (dc == NULL)
- errx(1, "no space for device capabilities");
+ xo_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);
if (dc->dc_cryptocaps != 0 || verbose) {
- putchar('\n');
+ xo_emit("{P:\n}");
printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
}
if (dc->dc_htcaps != 0 || verbose) {
- putchar('\n');
+ xo_emit("{P:\n}");
printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
}
if (dc->dc_vhtcaps != 0 || verbose) {
- putchar('\n');
+ xo_emit("{P:\n}");
printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
}
- putchar('\n');
+ xo_emit("{P:\n}");
if (verbose) {
chaninfo = &dc->dc_chaninfo; /* XXX */
print_channels(ctx, &dc->dc_chaninfo, 1/*allchans*/, verbose);
@@ -4578,7 +4463,7 @@ get80211wme(if_ctx *ctx, int param, int ac, int *val)
ireq.i_type = param;
ireq.i_len = ac;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) {
- warn("cannot get WME parameter %d, ac %d%s",
+ xo_warn("cannot get WME parameter %d, ac %d%s",
param, ac & IEEE80211_WMEPARAM_VAL,
ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
return -1;
@@ -4592,33 +4477,33 @@ list_wme_aci(if_ctx *ctx, const char *tag, int ac)
{
int val;
- printf("\t%s", tag);
+ xo_open_instance("wme-aci");
+ xo_emit("{:name/%s}", tag);
- /* show WME BSS parameters */
if (get80211wme(ctx, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
- printf(" cwmin %2u", val);
+ xo_emit("{P: cwmin }{:cwmin/%2u}", val);
if (get80211wme(ctx, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
- printf(" cwmax %2u", val);
+ xo_emit("{P: cwmax }{:cwmax/%2u}", val);
if (get80211wme(ctx, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
- printf(" aifs %2u", val);
+ xo_emit("{P: aifs }{:aifs/%2u}", val);
if (get80211wme(ctx, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
- printf(" txopLimit %3u", val);
+ xo_emit("{P: txopLimit }{:txop-limit/%3u}", val);
if (get80211wme(ctx, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
if (val)
- printf(" acm");
+ xo_emit("{P: acm}");
else if (ctx->args->verbose)
- printf(" -acm");
+ xo_emit("{P: -acm}");
}
- /* !BSS only */
if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
if (get80211wme(ctx, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
if (!val)
- printf(" -ack");
+ xo_emit("{P: -ack}");
else if (ctx->args->verbose)
- printf(" ack");
+ xo_emit("{P: ack}");
}
}
- printf("\n");
+ xo_close_instance("wme-aci");
+ xo_emit("{P:\n}");
}
static void
@@ -4627,6 +4512,7 @@ list_wme(if_ctx *ctx)
static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
int ac;
+ xo_open_list("wme-aci");
if (ctx->args->verbose) {
/* display both BSS and local settings */
for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
@@ -4646,6 +4532,7 @@ list_wme(if_ctx *ctx)
for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
list_wme_aci(ctx, acnames[ac], ac);
}
+ xo_close_list("wme-aci");
}
static void
@@ -4753,19 +4640,19 @@ printpolicy(int policy)
{
switch (policy) {
case IEEE80211_MACCMD_POLICY_OPEN:
- printf("policy: open\n");
+ xo_emit("{P:policy: open\n}");
break;
case IEEE80211_MACCMD_POLICY_ALLOW:
- printf("policy: allow\n");
+ xo_emit("{P:policy: allow\n}");
break;
case IEEE80211_MACCMD_POLICY_DENY:
- printf("policy: deny\n");
+ xo_emit("{P:policy: deny\n}");
break;
case IEEE80211_MACCMD_POLICY_RADIUS:
- printf("policy: radius\n");
+ xo_emit("{P:policy: radius\n}");
break;
default:
- printf("policy: unknown (%u)\n", policy);
+ xo_emit("{P:policy: unknown (}{:field1/%u}{P:)\n}", policy);
break;
}
}
@@ -4784,10 +4671,10 @@ list_mac(if_ctx *ctx)
ireq.i_val = IEEE80211_MACCMD_POLICY;
if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) {
if (errno == EINVAL) {
- printf("No acl policy loaded\n");
+ xo_emit("{P:No acl policy loaded\n}");
return;
}
- err(1, "unable to get mac policy");
+ xo_err(1, "unable to get mac policy");
}
policy = ireq.i_val;
if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
@@ -4799,7 +4686,7 @@ list_mac(if_ctx *ctx)
} else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
c = 'r'; /* NB: should never have entries */
} else {
- printf("policy: unknown (%u)\n", policy);
+ xo_emit("{P:policy: unknown (}{:field1/%u}{P:)\n}", policy);
c = '?';
}
if (ctx->args->verbose || c == '?')
@@ -4808,7 +4695,7 @@ list_mac(if_ctx *ctx)
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");
+ xo_err(1, "unable to get mac acl list size");
if (ireq.i_len == 0) { /* NB: no acls */
if (!(ctx->args->verbose || c == '?'))
printpolicy(policy);
@@ -4818,48 +4705,57 @@ list_mac(if_ctx *ctx)
data = malloc(len);
if (data == NULL)
- err(1, "out of memory for acl list");
+ xo_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");
+ xo_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(
+ xo_emit("{:field1/%c}{:field2/%s}{P:\n}", c, ether_ntoa(
(const struct ether_addr *) acllist[i].ml_macaddr));
free(data);
}
static void
-print_regdomain(const struct ieee80211_regdomain *reg, int verb)
+ 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)
+ if (rd == NULL) {
+ fields_emit("{:regdomain/%d}", reg->regdomain);
LINE_CHECK("regdomain %d", reg->regdomain);
- else
+ } else {
+ fields_emit("{:regdomain/%s}", rd->name);
LINE_CHECK("regdomain %s", rd->name);
+ }
}
if (reg->country != 0 || verb) {
const struct country *cc =
lib80211_country_findbycc(getregdata(), reg->country);
- if (cc == NULL)
+ if (cc == NULL) {
+ fields_emit("{:country/%d}", reg->country);
LINE_CHECK("country %d", reg->country);
- else
+ } else {
+ fields_emit("{:country/%s}", cc->isoname);
LINE_CHECK("country %s", cc->isoname);
+ }
}
- if (reg->location == 'I')
+ if (reg->location == 'I') {
+ fields_emit("{:location/%s}", "indoor");
LINE_CHECK("indoor");
- else if (reg->location == 'O')
+ } else if (reg->location == 'O') {
+ fields_emit("{:location/%s}", "outdoor");
LINE_CHECK("outdoor");
- else if (verb)
+ } else if (verb)
LINE_CHECK("anywhere");
- if (reg->ecm)
+ if (reg->ecm) {
+ fields_emit("{:ecm/%d}", true);
LINE_CHECK("ecm");
- else if (verb)
+ } else if (verb)
LINE_CHECK("-ecm");
}
@@ -4890,30 +4786,17 @@ list_mesh(if_ctx *ctx)
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");
+ xo_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");
+ xo_emit("{:field1/%-17.17s}{P: }{:field2/%-17.17s}{P: }{:field3/%4s}{P: }{:field4/%4s}{P: }{:field5/%4s}{P: }{:field6/%6s}{P: }{:field7/%s}{P:\n}", "DEST", "NEXT HOP", "HOPS", "METRIC", "LIFETIME", "MSEQ", "FLAGS");
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) ?
+ xo_emit("{:field1/%s}{P: }", ether_ntoa((const struct ether_addr *)rt->imr_dest));
+ xo_emit("{:field1/%s}{P: }{:field2/%4u}{P: }{:field3/%4u}{P: }{:field4/%6u}{P: }{:field5/%6u}{P: }{:field6/%c}{:field7/%c}{P:\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) ?
+ 'V' : '!', (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
'P' :
(rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
'G' :' ');
@@ -4957,7 +4840,7 @@ set80211list(if_ctx *ctx, const char *arg, int dummy __unused)
else if (iseq(arg, "mesh"))
list_mesh(ctx);
else
- errx(1, "Don't know how to list %s for %s", arg, ctx->ifname);
+ xo_errx(1, "Don't know how to list %s for %s", arg, ctx->ifname);
LINE_BREAK();
#undef iseq
}
@@ -4996,32 +4879,31 @@ printcipher(int s, struct ieee80211req *ireq, int keylenop)
case IEEE80211_CIPHER_WEP:
ireq->i_type = keylenop;
if (ioctl(s, SIOCG80211, ireq) != -1)
- printf("WEP-%s",
- ireq->i_len <= 5 ? "40" :
+ xo_emit("{P:WEP-}{:field1/%s}", ireq->i_len <= 5 ? "40" :
ireq->i_len <= 13 ? "104" : "128");
else
- printf("WEP");
+ xo_emit("{P:WEP}");
break;
case IEEE80211_CIPHER_TKIP:
- printf("TKIP");
+ xo_emit("{P:TKIP}");
break;
case IEEE80211_CIPHER_AES_OCB:
- printf("AES-OCB");
+ xo_emit("{P:AES-OCB}");
break;
case IEEE80211_CIPHER_AES_CCM:
- printf("AES-CCM");
+ xo_emit("{P:AES-CCM}");
break;
case IEEE80211_CIPHER_AES_GCM_128:
- printf("AES-GCM");
+ xo_emit("{P:AES-GCM}");
break;
case IEEE80211_CIPHER_CKIP:
- printf("CKIP");
+ xo_emit("{P:CKIP}");
break;
case IEEE80211_CIPHER_NONE:
- printf("NONE");
+ xo_emit("{P:NONE}");
break;
default:
- printf("UNKNOWN (0x%x)", ireq->i_val);
+ xo_emit("{P:UNKNOWN (0x}{:field1/%x}{P:)}", ireq->i_val);
break;
}
}
@@ -5053,9 +4935,12 @@ printkey(if_ctx *ctx, const struct ieee80211req_key *ik)
if (printcontents)
LINE_BREAK();
printkey_index(ik->ik_keyix, keyix, sizeof(keyix));
+ xo_open_instance("cipher");
switch (ik->ik_type) {
case IEEE80211_CIPHER_WEP:
/* compatibility */
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "WEP", keyix, 8*keylen);
LINE_CHECK("wepkey %s:%s", keyix,
keylen <= 5 ? "40-bit" :
keylen <= 13 ? "104-bit" : "128-bit");
@@ -5063,50 +4948,70 @@ printkey(if_ctx *ctx, const struct ieee80211req_key *ik)
case IEEE80211_CIPHER_TKIP:
if (keylen > 128/8)
keylen -= 128/8; /* ignore MIC for now */
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "TKIP", keyix, 8*keylen);
LINE_CHECK("TKIP %s:%u-bit", keyix, 8*keylen);
break;
case IEEE80211_CIPHER_AES_OCB:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "AES-OCB", keyix, 8*keylen);
LINE_CHECK("AES-OCB %s:%u-bit", keyix, 8*keylen);
break;
case IEEE80211_CIPHER_AES_CCM:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "AES-CCM", keyix, 8*keylen);
LINE_CHECK("AES-CCM %s:%u-bit", keyix, 8*keylen);
break;
case IEEE80211_CIPHER_AES_GCM_128:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "AES-GCM", keyix, 8*keylen);
LINE_CHECK("AES-GCM %s:%u-bit", keyix, 8*keylen);
break;
case IEEE80211_CIPHER_CKIP:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "CKIP", keyix, 8*keylen);
LINE_CHECK("CKIP %s:%u-bit", keyix, 8*keylen);
break;
case IEEE80211_CIPHER_NONE:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "NONE", keyix, 8*keylen);
LINE_CHECK("NULL %s:%u-bit", keyix, 8*keylen);
break;
default:
+ fields_emit("{:type/%s}{P: }{:key_index/%s}{P: }{:bit_length/%u}",
+ "UNKNOWN", keyix, 8*keylen);
LINE_CHECK("UNKNOWN (0x%x) %s:%u-bit",
ik->ik_type, keyix, 8*keylen);
break;
}
+ xo_close_instance("cipher");
if (printcontents) {
u_int i;
- printf(" <");
- for (i = 0; i < keylen; i++)
- printf("%02x", ik->ik_keydata[i]);
- printf(">");
+ xo_emit("{P: <}");
+ xo_open_list("keybyte");
+ for (i = 0; i < keylen; i++) {
+ xo_open_instance("keybyte");
+ xo_emit("{:value/%02x}", ik->ik_keydata[i]);
+ xo_close_instance("keybyte");
+ }
+ xo_close_list("keybyte");
+ xo_emit("{P:>}");
if (ik->ik_type != IEEE80211_CIPHER_WEP &&
(ik->ik_keyrsc != 0 || verbose))
- printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
+ xo_emit("{P: rsc }{:rsc/%u}", (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);
+ xo_emit("{P: tsc }{:tsc/%u}", (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 = "+";
+ xo_emit("{P:/%s}{P:tx}", sep), sep = "+";
if (ik->ik_flags & IEEE80211_KEY_RECV)
- printf("%srx", sep), sep = "+";
+ xo_emit("{P:/%s}{P:rx}", sep), sep = "+";
if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
- printf("%sdef", sep), sep = "+";
+ xo_emit("{P:/%s}{P:def}", sep), sep = "+";
}
LINE_BREAK();
}
@@ -5115,16 +5020,25 @@ printkey(if_ctx *ctx, const struct ieee80211req_key *ik)
static void
printrate(const char *tag, int v, int defrate, int defmcs)
{
+ char fmt[64];
+
if ((v & IEEE80211_RATE_MCS) == 0) {
if (v != defrate) {
- if (v & 1)
+ snprintf(fmt, sizeof(fmt), "{:%s/%%d}", tag);
+ if (v & 1) {
+ fields_emit(fmt, v / 2);
LINE_CHECK("%s %d.5", tag, v/2);
- else
+ } else {
+ fields_emit(fmt, v / 2);
LINE_CHECK("%s %d", tag, v/2);
+ }
}
} else {
- if (v != defmcs)
+ if (v != defmcs) {
+ snprintf(fmt, sizeof(fmt), "{:%s/%%d}", tag);
+ fields_emit(fmt, v & ~0x80);
LINE_CHECK("%s %d", tag, v &~ 0x80);
+ }
}
}
@@ -5189,19 +5103,19 @@ ieee80211_status(if_ctx *ctx)
gothtconf = 0;
gotregdomain = 0;
- printf("\t");
+ xo_emit("{P:\t}");
if (opmode == IEEE80211_M_MBSS) {
- printf("meshid ");
+ xo_emit("{P:meshid }");
getid(ctx, 0, data, sizeof(data), &len, 1);
print_string(data, len);
} else {
if (get80211val(ctx, IEEE80211_IOC_NUMSSIDS, &num) < 0)
num = 0;
- printf("ssid ");
+ xo_emit("{P: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);
+ xo_emit("{P: }{:ssid-num/%d}{P::}", i + 1);
print_string(data, len);
}
}
@@ -5211,19 +5125,18 @@ ieee80211_status(if_ctx *ctx)
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)));
+ xo_emit("{P: channel }{:chan-num/%d}{P: (}{:freq/%u}{P: MHz}{:chan-mode/%s}{P:)}", c->ic_ieee, c->ic_freq, get_chaninfo(c, 1, buf, sizeof(buf)));
} else if (verbose)
- printf(" channel UNDEF");
+ xo_emit("{P: 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));
+ xo_emit("{P: bssid }{:bssid/%s}", ether_ntoa((struct ether_addr *)bssid));
printbssidname((struct ether_addr *)bssid);
}
if (get80211len(ctx, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
- printf("\n\tstationname ");
+ xo_emit("{P:\n\tstationname }");
print_string(data, len);
}
@@ -5236,15 +5149,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_AUTHMODE, &val) != -1) {
switch (val) {
case IEEE80211_AUTH_NONE:
+ fields_emit("{:authmode/%s}", "NONE");
LINE_CHECK("authmode NONE");
break;
case IEEE80211_AUTH_OPEN:
+ fields_emit("{:authmode/%s}", "OPEN");
LINE_CHECK("authmode OPEN");
break;
case IEEE80211_AUTH_SHARED:
+ fields_emit("{:authmode/%s}", "SHARED");
LINE_CHECK("authmode SHARED");
break;
case IEEE80211_AUTH_8021X:
+ fields_emit("{:authmode/%s}", "802.1x");
LINE_CHECK("authmode 802.1x");
break;
case IEEE80211_AUTH_WPA:
@@ -5252,20 +5169,25 @@ ieee80211_status(if_ctx *ctx)
wpa = 1; /* default to WPA1 */
switch (wpa) {
case 2:
+ fields_emit("{:authmode/%s}", "WPA2/802.11i");
LINE_CHECK("authmode WPA2/802.11i");
break;
case 3:
+ fields_emit("{:authmode/%s}", "WPA1+WPA2/802.11i");
LINE_CHECK("authmode WPA1+WPA2/802.11i");
break;
default:
+ fields_emit("{:authmode/%s}", "WPA");
LINE_CHECK("authmode WPA");
break;
}
break;
case IEEE80211_AUTH_AUTO:
+ fields_emit("{:authmode/%s}", "AUTO");
LINE_CHECK("authmode AUTO");
break;
default:
+ fields_emit("{:authmode_raw/%u}", val);
LINE_CHECK("authmode UNKNOWN (0x%x)", val);
break;
}
@@ -5273,18 +5195,21 @@ ieee80211_status(if_ctx *ctx)
if (wpa || verbose) {
if (get80211val(ctx, IEEE80211_IOC_WPS, &val) != -1) {
+ fields_emit("{:wps/%d}", val != 0);
if (val)
LINE_CHECK("wps");
else if (verbose)
LINE_CHECK("-wps");
}
if (get80211val(ctx, IEEE80211_IOC_TSN, &val) != -1) {
+ fields_emit("{:tsn/%d}", val != 0);
if (val)
LINE_CHECK("tsn");
else if (verbose)
LINE_CHECK("-tsn");
}
if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
+ fields_emit("{:countermeasures/%d}", val != 0);
if (val)
LINE_CHECK("countermeasures");
else if (verbose)
@@ -5328,15 +5253,19 @@ ieee80211_status(if_ctx *ctx)
switch (wepmode) {
case IEEE80211_WEP_OFF:
+ fields_emit("{:privacy/%s}", "OFF");
LINE_CHECK("privacy OFF");
break;
case IEEE80211_WEP_ON:
+ fields_emit("{:privacy/%s}", "ON");
LINE_CHECK("privacy ON");
break;
case IEEE80211_WEP_MIXED:
+ fields_emit("{:privacy/%s}", "MIXED");
LINE_CHECK("privacy MIXED");
break;
default:
+ fields_emit("{:privacy_raw/%u}", wepmode);
LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
break;
}
@@ -5347,26 +5276,28 @@ ieee80211_status(if_ctx *ctx)
*/
if (get80211val(ctx, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
- warn("WEP support, but no tx key!");
+ xo_warn("WEP support, but no tx key!");
goto end;
}
- if (val != -1)
+ if (val != -1) {
+ fields_emit("{:deftxkey/%d}", val+1);
LINE_CHECK("deftxkey %d", val+1);
- else if (wepmode != IEEE80211_WEP_OFF || verbose)
+ } else if (wepmode != IEEE80211_WEP_OFF || verbose)
LINE_CHECK("deftxkey UNDEF");
if (get80211val(ctx, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
- warn("WEP support, but no NUMWEPKEYS support!");
+ xo_warn("WEP support, but no NUMWEPKEYS support!");
goto end;
}
+ fields_open_list("cipher");
for (i = 0; i < num; i++) {
struct ieee80211req_key ik;
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!");
+ xo_warn("WEP support, but cannot get keys!");
goto end;
}
if (ik.ik_keylen != 0) {
@@ -5392,6 +5323,7 @@ ieee80211_status(if_ctx *ctx)
}
if (i > 0 && verbose)
LINE_BREAK();
+ fields_close_list("cipher");
end:
;
}
@@ -5401,35 +5333,47 @@ ieee80211_status(if_ctx *ctx)
if (val != IEEE80211_POWERSAVE_OFF || verbose) {
switch (val) {
case IEEE80211_POWERSAVE_OFF:
+ fields_emit("{:powersavemode/%s}", "OFF");
LINE_CHECK("powersavemode OFF");
break;
case IEEE80211_POWERSAVE_CAM:
+ fields_emit("{:powersavemode/%s}", "CAM");
LINE_CHECK("powersavemode CAM");
break;
case IEEE80211_POWERSAVE_PSP:
+ fields_emit("{:powersavemode/%s}", "PSP");
LINE_CHECK("powersavemode PSP");
break;
case IEEE80211_POWERSAVE_PSP_CAM:
+ fields_emit("{:powersavemode/%s}", "PSP-CAM");
LINE_CHECK("powersavemode PSP-CAM");
break;
}
- if (get80211val(ctx, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
+ if (get80211val(ctx, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) {
+ fields_emit("{:powersavesleep/%d}", val);
LINE_CHECK("powersavesleep %d", val);
+ }
}
}
if (get80211val(ctx, IEEE80211_IOC_TXPOWER, &val) != -1) {
- if (val & 1)
+ if (val & 1) {
+ fields_emit("{:txpower/%.1f}", val / 2.0);
LINE_CHECK("txpower %d.5", val/2);
- else
+ } else {
+ fields_emit("{:txpower/%d}", val / 2);
LINE_CHECK("txpower %d", val/2);
+ }
}
if (verbose) {
- if (get80211val(ctx, IEEE80211_IOC_TXPOWMAX, &val) != -1)
+ if (get80211val(ctx, IEEE80211_IOC_TXPOWMAX, &val) != -1) {
+ fields_emit("{:txpowmax/%.1f}", val / 2.);
LINE_CHECK("txpowmax %.1f", val/2.);
+ }
}
if (get80211val(ctx, IEEE80211_IOC_DOTD, &val) != -1) {
+ fields_emit("{:dotd/%d}", val != 0);
if (val)
LINE_CHECK("dotd");
else if (verbose)
@@ -5437,18 +5381,24 @@ ieee80211_status(if_ctx *ctx)
}
if (get80211val(ctx, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
- if (val != IEEE80211_RTS_MAX || verbose)
+ if (val != IEEE80211_RTS_MAX || verbose) {
+ fields_emit("{:rtsthreshold/%d}", val);
LINE_CHECK("rtsthreshold %d", val);
+ }
}
if (get80211val(ctx, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
- if (val != IEEE80211_FRAG_MAX || verbose)
+ if (val != IEEE80211_FRAG_MAX || verbose) {
+ fields_emit("{:fragthreshold/%d}", val);
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)
+ if (val != IEEE80211_HWBMISS_MAX || verbose) {
+ fields_emit("{:bmiss/%d}", val);
LINE_CHECK("bmiss %d", val);
+ }
}
}
@@ -5461,8 +5411,10 @@ ieee80211_status(if_ctx *ctx)
IEEE80211_RATE_MCS|0);
printrate("mgmtrate", tp->mgmtrate, 2*1,
IEEE80211_RATE_MCS|0);
- if (tp->maxretry != 6) /* XXX */
+ if (tp->maxretry != 6) { /* XXX */
+ fields_emit("{:maxretry/%d}", tp->maxretry);
LINE_CHECK("maxretry %d", tp->maxretry);
+ }
} else {
LINE_BREAK();
list_txparams(ctx);
@@ -5472,29 +5424,42 @@ ieee80211_status(if_ctx *ctx)
(void) get80211val(ctx, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
if (get80211val(ctx, IEEE80211_IOC_SCANVALID, &val) != -1) {
- if (val != bgscaninterval || verbose)
+ if (val != bgscaninterval || verbose) {
+ fields_emit("{:scanvalid/%u}", val);
LINE_CHECK("scanvalid %u", val);
+ }
}
bgscan = 0;
if (get80211val(ctx, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
+ fields_emit("{:bgscan/%d}", bgscan != 0);
if (bgscan)
LINE_CHECK("bgscan");
else if (verbose)
LINE_CHECK("-bgscan");
}
if (bgscan || verbose) {
- if (bgscaninterval != -1)
+ if (bgscaninterval != -1) {
+ fields_emit("{:bgscanintvl/%u}", bgscaninterval);
LINE_CHECK("bgscanintvl %u", bgscaninterval);
- if (get80211val(ctx, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
+ }
+ if (get80211val(ctx, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) {
+ fields_emit("{:bgscanidle/%u}", val);
LINE_CHECK("bgscanidle %u", val);
+ }
if (!verbose) {
getroam(ctx);
rp = &roamparams.params[chan2mode(c)];
- if (rp->rssi & 1)
+ if (rp->rssi & 1) {
+ fields_emit("{:roam_rssi/%.1f}", rp->rssi / 2.0);
LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
- else
+ } else {
+ fields_emit("{:roam_rssi/%u}", rp->rssi/2);
LINE_CHECK("roam:rssi %u", rp->rssi/2);
+ }
+ fields_emit("{:roam_rate/%s%u}",
+ (rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
+ get_rate_value(rp->rate));
LINE_CHECK("roam:rate %s%u",
(rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
get_rate_value(rp->rate));
@@ -5507,6 +5472,7 @@ ieee80211_status(if_ctx *ctx)
if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
if (get80211val(ctx, IEEE80211_IOC_PUREG, &val) != -1) {
+ fields_emit("{:pureg/%d}", val != 0);
if (val)
LINE_CHECK("pureg");
else if (verbose)
@@ -5515,15 +5481,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_PROTMODE, &val) != -1) {
switch (val) {
case IEEE80211_PROTMODE_OFF:
+ fields_emit("{:protmode/%s}", "OFF");
LINE_CHECK("protmode OFF");
break;
case IEEE80211_PROTMODE_CTS:
+ fields_emit("{:protmode/%s}", "CTS");
LINE_CHECK("protmode CTS");
break;
case IEEE80211_PROTMODE_RTSCTS:
+ fields_emit("{:protmode/%s}", "RTSCTS");
LINE_CHECK("protmode RTSCTS");
break;
default:
+ fields_emit("{:protmode_raw/%u}", val);
LINE_CHECK("protmode UNKNOWN (0x%x)", val);
break;
}
@@ -5535,17 +5505,22 @@ ieee80211_status(if_ctx *ctx)
switch (htconf & 3) {
case 0:
case 2:
+ fields_emit("{:ht/%d}", false);
LINE_CHECK("-ht");
break;
case 1:
+ fields_emit("{:ht20/%d}", true);
LINE_CHECK("ht20");
break;
case 3:
- if (verbose)
+ if (verbose) {
+ fields_emit("{:ht/%d}", true);
LINE_CHECK("ht");
+ }
break;
}
if (get80211val(ctx, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
+ fields_emit("{:htcompat/%d}", val != 0);
if (!val)
LINE_CHECK("-htcompat");
else if (verbose)
@@ -5554,15 +5529,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_AMPDU, &val) != -1) {
switch (val) {
case 0:
+ fields_emit("{:ampdu/%d}", false);
LINE_CHECK("-ampdu");
break;
case 1:
+ fields_emit("{:ampdutx/%d}{:ampdurx/%d}", true, false);
LINE_CHECK("ampdutx -ampdurx");
break;
case 2:
+ fields_emit("{:ampdutx/%d}{:ampdurx/%d}", false, true);
LINE_CHECK("-ampdutx ampdurx");
break;
case 3:
+ fields_emit("{:ampdu/%d}", true);
if (verbose)
LINE_CHECK("ampdu");
break;
@@ -5572,15 +5551,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
switch (val) {
case IEEE80211_HTCAP_MAXRXAMPDU_8K:
+ fields_emit("{:ampdulimit/%s}", "8k");
LINE_CHECK("ampdulimit 8k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_16K:
+ fields_emit("{:ampdulimit/%s}", "16k");
LINE_CHECK("ampdulimit 16k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_32K:
+ fields_emit("{:ampdulimit/%s}", "32k");
LINE_CHECK("ampdulimit 32k");
break;
case IEEE80211_HTCAP_MAXRXAMPDU_64K:
+ fields_emit("{:ampdulimit/%s}", "64k");
LINE_CHECK("ampdulimit 64k");
break;
}
@@ -5593,24 +5576,31 @@ ieee80211_status(if_ctx *ctx)
LINE_CHECK("ampdudensity NA");
break;
case IEEE80211_HTCAP_MPDUDENSITY_025:
+ fields_emit("{:ampdudensity/%s}", ".25");
LINE_CHECK("ampdudensity .25");
break;
case IEEE80211_HTCAP_MPDUDENSITY_05:
+ fields_emit("{:ampdudensity/%s}", ".5");
LINE_CHECK("ampdudensity .5");
break;
case IEEE80211_HTCAP_MPDUDENSITY_1:
+ fields_emit("{:ampdudensity/%s}", "1");
LINE_CHECK("ampdudensity 1");
break;
case IEEE80211_HTCAP_MPDUDENSITY_2:
+ fields_emit("{:ampdudensity/%s}", "2");
LINE_CHECK("ampdudensity 2");
break;
case IEEE80211_HTCAP_MPDUDENSITY_4:
+ fields_emit("{:ampdudensity/%s}", "4");
LINE_CHECK("ampdudensity 4");
break;
case IEEE80211_HTCAP_MPDUDENSITY_8:
+ fields_emit("{:ampdudensity/%s}", "8");
LINE_CHECK("ampdudensity 8");
break;
case IEEE80211_HTCAP_MPDUDENSITY_16:
+ fields_emit("{:ampdudensity/%s}", "16");
LINE_CHECK("ampdudensity 16");
break;
}
@@ -5618,15 +5608,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_AMSDU, &val) != -1) {
switch (val) {
case 0:
+ fields_emit("{:amsdu/%d}", false);
LINE_CHECK("-amsdu");
break;
case 1:
+ fields_emit("{:amsdutx/%d}{:amsdurx/%d}", true, false);
LINE_CHECK("amsdutx -amsdurx");
break;
case 2:
+ fields_emit("{:amsdutx/%d}{:amsdurx/%d}", false, true);
LINE_CHECK("-amsdutx amsdurx");
break;
case 3:
+ fields_emit("{:amsdu/%d}", true);
if (verbose)
LINE_CHECK("amsdu");
break;
@@ -5634,34 +5628,42 @@ ieee80211_status(if_ctx *ctx)
}
/* XXX amsdu limit */
if (get80211val(ctx, IEEE80211_IOC_SHORTGI, &val) != -1) {
+ fields_emit("{:shortgi/%d}", val != 0);
if (val)
LINE_CHECK("shortgi");
else if (verbose)
LINE_CHECK("-shortgi");
}
if (get80211val(ctx, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
- if (val == IEEE80211_PROTMODE_OFF)
+ if (val == IEEE80211_PROTMODE_OFF) {
+ fields_emit("{:htprotmode/%s}", "OFF");
LINE_CHECK("htprotmode OFF");
- else if (val != IEEE80211_PROTMODE_RTSCTS)
+ } else if (val != IEEE80211_PROTMODE_RTSCTS)
LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
- else if (verbose)
+ else if (verbose) {
+ fields_emit("{:htprotmode/%s}", "RTSCTS");
LINE_CHECK("htprotmode RTSCTS");
+ }
}
if (get80211val(ctx, IEEE80211_IOC_PUREN, &val) != -1) {
+ fields_emit("{:puren/%d}", val != 0);
if (val)
LINE_CHECK("puren");
else if (verbose)
LINE_CHECK("-puren");
}
if (get80211val(ctx, IEEE80211_IOC_SMPS, &val) != -1) {
- if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
+ if (val == IEEE80211_HTCAP_SMPS_DYNAMIC) {
+ fields_emit("{:smps/%s}", "dynamic");
LINE_CHECK("smpsdyn");
- else if (val == IEEE80211_HTCAP_SMPS_ENA)
+ } else if (val == IEEE80211_HTCAP_SMPS_ENA) {
+ fields_emit("{:smps/%s}", "static");
LINE_CHECK("smps");
- else if (verbose)
+ } else if (verbose)
LINE_CHECK("-smps");
}
if (get80211val(ctx, IEEE80211_IOC_RIFS, &val) != -1) {
+ fields_emit("{:rifs/%d}", val != 0);
if (val)
LINE_CHECK("rifs");
else if (verbose)
@@ -5672,15 +5674,19 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_STBC, &val) != -1) {
switch (val) {
case 0:
+ fields_emit("{:stbc/%d}", false);
LINE_CHECK("-stbc");
break;
case 1:
+ fields_emit("{:stbctx/%d}{:stbcrx/%d}", true, false);
LINE_CHECK("stbctx -stbcrx");
break;
case 2:
+ fields_emit("{:stbctx/%d}{:stbcrx/%d}", false, true);
LINE_CHECK("-stbctx stbcrx");
break;
case 3:
+ fields_emit("{:stbc/%d}", true);
if (verbose)
LINE_CHECK("stbc");
break;
@@ -5689,21 +5695,26 @@ ieee80211_status(if_ctx *ctx)
if (get80211val(ctx, IEEE80211_IOC_LDPC, &val) != -1) {
switch (val) {
case 0:
+ fields_emit("{:ldpc/%d}", false);
LINE_CHECK("-ldpc");
break;
case 1:
+ fields_emit("{:ldpctx/%d}{:ldpcrx/%d}", true, false);
LINE_CHECK("ldpctx -ldpcrx");
break;
case 2:
+ fields_emit("{:ldpctx/%d}{:ldpcrx/%d}", false, true);
LINE_CHECK("-ldpctx ldpcrx");
break;
case 3:
+ fields_emit("{:ldpc/%d}", true);
if (verbose)
LINE_CHECK("ldpc");
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_UAPSD, &val) != -1) {
+ fields_emit("{:uapsd/%d}", val != 0);
switch (val) {
case 0:
LINE_CHECK("-uapsd");
@@ -5718,29 +5729,45 @@ ieee80211_status(if_ctx *ctx)
if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
getvhtconf(ctx);
if (vhtconf & IEEE80211_FVHT_VHT) {
+ fields_emit("{:vht/%d}", true);
LINE_CHECK("vht");
- if (vhtconf & IEEE80211_FVHT_USEVHT40)
+ if (vhtconf & IEEE80211_FVHT_USEVHT40) {
+ fields_emit("{:vht40/%d}", true);
LINE_CHECK("vht40");
- else
+ } else {
+ fields_emit("{:vht40/%d}", false);
LINE_CHECK("-vht40");
- if (vhtconf & IEEE80211_FVHT_USEVHT80)
+ }
+ if (vhtconf & IEEE80211_FVHT_USEVHT80) {
+ fields_emit("{:vht80/%d}", true);
LINE_CHECK("vht80");
- else
+ } else {
+ fields_emit("{:vht80/%d}", false);
LINE_CHECK("-vht80");
- if (vhtconf & IEEE80211_FVHT_USEVHT160)
+ }
+ if (vhtconf & IEEE80211_FVHT_USEVHT160) {
+ fields_emit("{:vht160/%d}", true);
LINE_CHECK("vht160");
- else
+ } else {
+ fields_emit("{:vht160/%d}", false);
LINE_CHECK("-vht160");
- if (vhtconf & IEEE80211_FVHT_USEVHT80P80)
+ }
+ if (vhtconf & IEEE80211_FVHT_USEVHT80P80) {
+ fields_emit("{:vht80p80/%d}", true);
LINE_CHECK("vht80p80");
- else
+ } else {
+ fields_emit("{:vht80p80/%d}", false);
LINE_CHECK("-vht80p80");
- } else if (verbose)
+ }
+ } else if (verbose) {
+ fields_emit("{:vht/%d}", false);
LINE_CHECK("-vht");
+ }
}
if (get80211val(ctx, IEEE80211_IOC_WME, &wme) != -1) {
+ fields_emit("{:wme/%d}", wme != 0);
if (wme)
LINE_CHECK("wme");
else if (verbose)
@@ -5749,6 +5776,7 @@ ieee80211_status(if_ctx *ctx)
wme = 0;
if (get80211val(ctx, IEEE80211_IOC_BURST, &val) != -1) {
+ fields_emit("{:burst/%d}", val != 0);
if (val)
LINE_CHECK("burst");
else if (verbose)
@@ -5756,18 +5784,21 @@ ieee80211_status(if_ctx *ctx)
}
if (get80211val(ctx, IEEE80211_IOC_FF, &val) != -1) {
+ fields_emit("{:ff/%d}", val != 0);
if (val)
LINE_CHECK("ff");
else if (verbose)
LINE_CHECK("-ff");
}
if (get80211val(ctx, IEEE80211_IOC_TURBOP, &val) != -1) {
+ fields_emit("{:turbo/%d}", val != 0);
if (val)
LINE_CHECK("dturbo");
else if (verbose)
LINE_CHECK("-dturbo");
}
if (get80211val(ctx, IEEE80211_IOC_DWDS, &val) != -1) {
+ fields_emit("{:dwds/%d}", val != 0);
if (val)
LINE_CHECK("dwds");
else if (verbose)
@@ -5776,33 +5807,40 @@ ieee80211_status(if_ctx *ctx)
if (opmode == IEEE80211_M_HOSTAP) {
if (get80211val(ctx, IEEE80211_IOC_HIDESSID, &val) != -1) {
+ fields_emit("{:hidessid/%d}", val != 0);
if (val)
LINE_CHECK("hidessid");
else if (verbose)
LINE_CHECK("-hidessid");
}
if (get80211val(ctx, IEEE80211_IOC_APBRIDGE, &val) != -1) {
+ fields_emit("{:apbridge/%d}", val != 0);
if (!val)
LINE_CHECK("-apbridge");
else if (verbose)
LINE_CHECK("apbridge");
}
- if (get80211val(ctx, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
+ if (get80211val(ctx, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) {
+ fields_emit("{:dtimperiod/%u}", val);
LINE_CHECK("dtimperiod %u", val);
+ }
if (get80211val(ctx, IEEE80211_IOC_DOTH, &val) != -1) {
+ fields_emit("{:doth/%d}", val != 0);
if (!val)
LINE_CHECK("-doth");
else if (verbose)
LINE_CHECK("doth");
}
if (get80211val(ctx, IEEE80211_IOC_DFS, &val) != -1) {
+ fields_emit("{:dfs/%d}", val != 0);
if (!val)
LINE_CHECK("-dfs");
else if (verbose)
LINE_CHECK("dfs");
}
if (get80211val(ctx, IEEE80211_IOC_INACTIVITY, &val) != -1) {
+ fields_emit("{:inactivity/%d}", val != 0);
if (!val)
LINE_CHECK("-inact");
else if (verbose)
@@ -5813,17 +5851,20 @@ ieee80211_status(if_ctx *ctx)
if (val != IEEE80211_ROAMING_AUTO || verbose) {
switch (val) {
case IEEE80211_ROAMING_DEVICE:
+ fields_emit("{:roaming/%s}", "DEVICE");
LINE_CHECK("roaming DEVICE");
break;
case IEEE80211_ROAMING_AUTO:
+ fields_emit("{:roaming/%s}", "AUTO");
LINE_CHECK("roaming AUTO");
break;
case IEEE80211_ROAMING_MANUAL:
+ fields_emit("{:roaming/%s}", "MANUAL");
LINE_CHECK("roaming MANUAL");
break;
default:
- LINE_CHECK("roaming UNKNOWN (0x%x)",
- val);
+ fields_emit("{:roaming_raw/%u}", val);
+ LINE_CHECK("roaming UNKNOWN (0x%x)", val);
break;
}
}
@@ -5831,18 +5872,28 @@ ieee80211_status(if_ctx *ctx)
}
if (opmode == IEEE80211_M_AHDEMO) {
- if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
+ if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOT, &val) != -1) {
+ fields_emit("{:tdmaslot/%u}", val);
LINE_CHECK("tdmaslot %u", val);
- if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
+ }
+ if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) {
+ fields_emit("{:tdmaslotcnt/%u}", val);
LINE_CHECK("tdmaslotcnt %u", val);
- if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
+ }
+ if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) {
+ fields_emit("{:tdmaslotlen/%u}", val);
LINE_CHECK("tdmaslotlen %u", val);
- if (get80211val(ctx, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
+ }
+ if (get80211val(ctx, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) {
+ fields_emit("{:tdmabintval/%u}", val);
LINE_CHECK("tdmabintval %u", val);
+ }
} else if (get80211val(ctx, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
/* XXX default define not visible */
- if (val != 100 || verbose)
+ if (val != 100 || verbose) {
+ fields_emit("{:bintval/%u}", val);
LINE_CHECK("bintval %u", val);
+ }
}
if (wme && verbose) {
@@ -5852,21 +5903,25 @@ ieee80211_status(if_ctx *ctx)
if (opmode == IEEE80211_M_MBSS) {
if (get80211val(ctx, IEEE80211_IOC_MESH_TTL, &val) != -1) {
+ fields_emit("{:meshttl/%u}", val);
LINE_CHECK("meshttl %u", val);
}
if (get80211val(ctx, IEEE80211_IOC_MESH_AP, &val) != -1) {
+ fields_emit("{:meshpeering/%d}", val != 0);
if (val)
LINE_CHECK("meshpeering");
else
LINE_CHECK("-meshpeering");
}
if (get80211val(ctx, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
+ fields_emit("{:meshforward/%d}", val != 0);
if (val)
LINE_CHECK("meshforward");
else
LINE_CHECK("-meshforward");
}
if (get80211val(ctx, IEEE80211_IOC_MESH_GATE, &val) != -1) {
+ fields_emit("{:meshgate/%d}", val != 0);
if (val)
LINE_CHECK("meshgate");
else
@@ -5875,42 +5930,51 @@ ieee80211_status(if_ctx *ctx)
if (get80211len(ctx, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
&len) != -1) {
data[len] = '\0';
+ fields_emit("{:meshmetric/%s}", data);
LINE_CHECK("meshmetric %s", data);
}
if (get80211len(ctx, IEEE80211_IOC_MESH_PR_PATH, data, 12,
&len) != -1) {
data[len] = '\0';
+ fields_emit("{:meshpath/%s}", data);
LINE_CHECK("meshpath %s", data);
}
if (get80211val(ctx, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
switch (val) {
case IEEE80211_HWMP_ROOTMODE_DISABLED:
+ fields_emit("{:hwmprootmode/%s}", "DISABLED");
LINE_CHECK("hwmprootmode DISABLED");
break;
case IEEE80211_HWMP_ROOTMODE_NORMAL:
+ fields_emit("{:hwmprootmode/%s}", "NORMAL");
LINE_CHECK("hwmprootmode NORMAL");
break;
case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
+ fields_emit("{:hwmprootmode/%s}", "PROACTIVE");
LINE_CHECK("hwmprootmode PROACTIVE");
break;
case IEEE80211_HWMP_ROOTMODE_RANN:
+ fields_emit("{:hwmprootmode/%s}", "RANN");
LINE_CHECK("hwmprootmode RANN");
break;
default:
+ fields_emit("{:hwmprootmode_raw/%u}", val);
LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
break;
}
}
if (get80211val(ctx, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
+ fields_emit("{:hwmpmaxhops/%u}", val);
LINE_CHECK("hwmpmaxhops %u", val);
}
}
LINE_BREAK();
- if (getdevicename(ctx, data, sizeof(data), &len) < 0)
- return;
- LINE_CHECK("parent interface: %s", data);
+ if (getdevicename(ctx, data, sizeof(data), &len) >= 0) {
+ fields_emit("{:parent/%s}", data);
+ LINE_CHECK("parent interface: %s", data);
+ }
LINE_BREAK();
}
@@ -5943,7 +6007,7 @@ set80211(if_ctx *ctx, int type, int val, int len, void *data)
ret = lib80211_set80211(ctx->io_s, ctx->ifname, type, val, len, data);
if (ret < 0)
- err(1, "SIOCS80211");
+ xo_err(1, "SIOCS80211");
}
static const char *
@@ -5967,19 +6031,19 @@ get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
}
if (hexstr) {
if (!isxdigit((u_char)val[0])) {
- warnx("bad hexadecimal digits");
+ xo_warnx("bad hexadecimal digits");
return NULL;
}
if (!isxdigit((u_char)val[1])) {
- warnx("odd count hexadecimal digits");
+ xo_warnx("odd count hexadecimal digits");
return NULL;
}
}
if (p >= buf + len) {
if (hexstr)
- warnx("hexadecimal digits too long");
+ xo_warnx("hexadecimal digits too long");
else
- warnx("string too long");
+ xo_warnx("string too long");
return NULL;
}
if (hexstr) {
@@ -6023,13 +6087,13 @@ print_string(const u_int8_t *buf, int len)
}
if (i == len || utf8) {
if (hasspc || len == 0 || buf[0] == '\0')
- printf("\"%.*s\"", len, buf);
+ xo_emit("{P:\"}{:ssid/%.*s}{P:\"}", len, buf);
else
- printf("%.*s", len, buf);
+ xo_emit("{:ssid/%.*s}", len, buf);
} else {
- printf("0x");
+ xo_emit("{P:0x}");
for (i = 0; i < len; i++)
- printf("%02x", buf[i]);
+ xo_emit("{:hex/%02x}", buf[i]);
}
}
@@ -6055,7 +6119,7 @@ setdefregdomain(if_ctx *ctx)
/* Set FCC/US as default. */
rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
if (rd == NULL)
- errx(1, "FCC regdomain was not found");
+ xo_errx(1, "FCC regdomain was not found");
regdomain.regdomain = rd->sku;
if (rd->cc != NULL)
@@ -6084,11 +6148,11 @@ wlan_create(if_ctx *ctx, struct ifreq *ifr)
static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
if (params.icp_parent[0] == '\0')
- errx(1, "must specify a parent device (wlandev) when creating "
+ xo_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)");
+ xo_errx(1, "no bssid specified for WDS (use wlanbssid)");
ifr->ifr_data = (caddr_t) &params;
ifcreate_ioctl(ctx, ifr);
@@ -6108,7 +6172,7 @@ set80211clone_wlanbssid(if_ctx *ctx __unused, const char *arg, int dummy __unuse
ea = ether_aton(arg);
if (ea == NULL)
- errx(1, "%s: cannot parse bssid", arg);
+ xo_errx(1, "%s: cannot parse bssid", arg);
memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
}
@@ -6119,7 +6183,7 @@ set80211clone_wlanaddr(if_ctx *ctx __unused, const char *arg, int dummy __unused
ea = ether_aton(arg);
if (ea == NULL)
- errx(1, "%s: cannot parse address", arg);
+ xo_errx(1, "%s: cannot parse address", arg);
memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
params.icp_flags |= IEEE80211_CLONE_MACADDR;
}
@@ -6146,7 +6210,7 @@ set80211clone_wlanmode(if_ctx *ctx, const char *arg, int dummy __unused)
} 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);
+ xo_errx(1, "Don't know to create %s for %s", arg, ctx->ifname);
#undef iseq
}
@@ -6399,4 +6463,4 @@ ieee80211_ctor(void)
cmd_register(&ieee80211_cmds[i]);
af_register(&af_ieee80211);
clone_setdefcallback_prefix("wlan", wlan_create);
-}
+}
\ No newline at end of file
diff --git a/sbin/ifconfig/ifipsec.c b/sbin/ifconfig/ifipsec.c
index b8ab38d6165..0e4a1adf51b 100644
--- a/sbin/ifconfig/ifipsec.c
+++ b/sbin/ifconfig/ifipsec.c
@@ -46,6 +46,7 @@
#include <errno.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
static void
ipsec_status(if_ctx *ctx)
@@ -55,7 +56,7 @@ ipsec_status(if_ctx *ctx)
if (ioctl_ctx_ifr(ctx, IPSECGREQID, &ifr) == -1)
return;
- printf("\treqid: %u\n", reqid);
+ xo_emit("\treqid: {:reqid/%u}\n", reqid);
}
static void
@@ -67,11 +68,11 @@ setreqid(if_ctx *ctx, const char *val, int dummy __unused)
v = strtoul(val, &ep, 0);
if (*ep != '\0') {
- warn("Invalid reqid value %s", val);
+ xo_warn("Invalid reqid value %s", val);
return;
}
if (ioctl_ctx_ifr(ctx, IPSECSREQID, &ifr) == -1) {
- warn("ioctl(IPSECSREQID)");
+ xo_warn("ioctl(IPSECSREQID)");
return;
}
}
diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c
index 4de437d25bd..a60838f9cae 100644
--- a/sbin/ifconfig/iflagg.c
+++ b/sbin/ifconfig/iflagg.c
@@ -26,6 +26,7 @@
#include <libifconfig.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
static struct iflaggparam params = {
.lagg_type = LAGG_TYPE_DEFAULT,
@@ -48,7 +49,7 @@ setlaggport(if_ctx *ctx, const char *val, int dummy __unused)
* 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",
+ xo_warnx("%s %s: SIOCSLAGGPORT: %s",
ctx->ifname, val, strerror(errno));
exit_code = 1;
}
@@ -63,7 +64,7 @@ unsetlaggport(if_ctx *ctx, const char *val, int dummy __unused)
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
if (ioctl_ctx(ctx, SIOCSLAGGDELPORT, &rp))
- err(1, "SIOCSLAGGDELPORT");
+ xo_err(1, "SIOCSLAGGDELPORT");
}
static void
@@ -82,11 +83,11 @@ setlaggproto(if_ctx *ctx, const char *val, int dummy __unused)
}
}
if (ra.ra_proto == LAGG_PROTO_MAX)
- errx(1, "Invalid aggregation protocol: %s", val);
+ xo_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");
+ xo_err(1, "SIOCSLAGG");
}
static void
@@ -98,10 +99,10 @@ setlaggflowidshift(if_ctx *ctx, const char *val, int dummy __unused)
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);
+ xo_errx(1, "Invalid flowid_shift option: %s", val);
if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0)
- err(1, "SIOCSLAGGOPTS");
+ xo_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -113,10 +114,10 @@ setlaggrr_limit(if_ctx *ctx, const char *val, int dummy __unused)
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);
+ xo_errx(1, "Invalid round-robin stride: %s", val);
if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0)
- err(1, "SIOCSLAGGOPTS");
+ xo_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -140,12 +141,12 @@ setlaggsetopt(if_ctx *ctx, const char *val __unused, int d)
case -LAGG_OPT_LACP_FAST_TIMO:
break;
default:
- err(1, "Invalid lagg option");
+ xo_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");
+ xo_err(1, "SIOCSLAGGOPTS");
}
static void
@@ -165,15 +166,15 @@ setlagghash(if_ctx *ctx, const char *val, int dummy __unused)
else if (strcmp(tok, "l4") == 0)
rf.rf_flags |= LAGG_F_HASHL4;
else
- errx(1, "Invalid lagghash option: %s", tok);
+ xo_errx(1, "Invalid lagghash option: %s", tok);
}
free(str);
if (rf.rf_flags == 0)
- errx(1, "No lagghash options supplied");
+ xo_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");
+ xo_err(1, "SIOCSLAGGHASH");
}
static char *
@@ -232,54 +233,61 @@ lagg_status(if_ctx *ctx)
break;
}
}
- printf("\tlaggproto %s", proto);
+ xo_emit("{P:\tlaggproto }{:lagg-proto/%s}", proto);
if (rf->rf_flags & LAGG_F_HASHMASK) {
- const char *sep = "";
+ int need_sep = 0;
- printf(" lagghash ");
+ xo_emit("{P: lagghash }");
if (rf->rf_flags & LAGG_F_HASHL2) {
- printf("%sl2", sep);
- sep = ",";
+ xo_emit("{:lagg-hash-l2/%s}", "l2");
+ need_sep = 1;
}
if (rf->rf_flags & LAGG_F_HASHL3) {
- printf("%sl3", sep);
- sep = ",";
+ if (need_sep)
+ xo_emit("{P:,}");
+ xo_emit("{:lagg-hash-l3/%s}", "l3");
+ need_sep = 1;
}
if (rf->rf_flags & LAGG_F_HASHL4) {
- printf("%sl4", sep);
- sep = ",";
+ if (need_sep)
+ xo_emit("{P:,}");
+ xo_emit("{:lagg-hash-l4/%s}", "l4");
}
}
- putchar('\n');
+ xo_emit("\n");
if (verbose) {
- printf("\tlagg options:\n");
+ xo_emit("{P:\tlagg options:}\n");
printb("\t\tflags", ro->ro_opts, LAGG_OPT_BITS);
- putchar('\n');
- printf("\t\tflowid_shift: %d\n", ro->ro_flowid_shift);
+ xo_emit("\n");
+ xo_emit("{P:\t\tflowid_shift: }{:flowid-shift/%d}\n", ro->ro_flowid_shift);
if (ra->ra_proto == LAGG_PROTO_ROUNDROBIN)
- printf("\t\trr_limit: %d\n", ro->ro_bkt);
- printf("\tlagg statistics:\n");
- printf("\t\tactive ports: %d\n", ro->ro_active);
- printf("\t\tflapping: %u\n", ro->ro_flapping);
+ xo_emit("{P:\t\trr_limit: }{:rr-limit/%d}\n", ro->ro_bkt);
+ xo_emit("{P:\tlagg statistics:}\n");
+ xo_emit("{P:\t\tactive ports: }{:active-ports/%d}\n", ro->ro_active);
+ xo_emit("{P:\t\tflapping: }{:flapping/%u}\n", ro->ro_flapping);
if (ra->ra_proto == LAGG_PROTO_LACP) {
lp = &ra->ra_lacpreq;
- printf("\tlag id: %s\n",
+ xo_emit("{P:\tlag id: }{:lag-id/%s}\n",
lacp_format_peer(lp, "\n\t\t "));
}
}
+ xo_open_list("laggport");
for (size_t i = 0; i < (size_t)ra->ra_ports; ++i) {
lp = &ports[i].rp_lacpreq;
- printf("\tlaggport: %s ", ports[i].rp_portname);
+ xo_open_instance("laggport");
+ xo_emit("{P:\tlaggport: }{:name/%s} ", ports[i].rp_portname);
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');
+ xo_emit("\n");
if (verbose && ra->ra_proto == LAGG_PROTO_LACP)
- printf("\t\t%s\n",
+ xo_emit("{P:\t\t}{:lacp-peer/%s}\n",
lacp_format_peer(lp, "\n\t\t "));
+ xo_close_instance("laggport");
}
+ xo_close_list("laggport");
ifconfig_lagg_free_lagg_status(lagg);
}
@@ -295,7 +303,7 @@ setlaggtype(if_ctx *ctx __unused, const char *arg, int dummy __unused)
return;
}
}
- errx(1, "invalid lagg type: %s", arg);
+ xo_errx(1, "invalid lagg type: %s", arg);
}
static void
diff --git a/sbin/ifconfig/ifmac.c b/sbin/ifconfig/ifmac.c
index 278d2e79592..81fc442e0e3 100644
--- a/sbin/ifconfig/ifmac.c
+++ b/sbin/ifconfig/ifmac.c
@@ -48,6 +48,7 @@
#include <string.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
static void
maclabel_status(if_ctx *ctx)
@@ -70,7 +71,7 @@ maclabel_status(if_ctx *ctx)
goto mac_free;
if (strlen(label_text) != 0)
- printf("\tmaclabel %s\n", label_text);
+ xo_emit("{T:}maclabel {:maclabel/%s}\n", label_text);
free(label_text);
mac_free:
@@ -85,7 +86,7 @@ setifmaclabel(if_ctx *ctx, const char *val, int d __unused)
int error;
if (mac_from_text(&label, val) == -1) {
- perror(val);
+ xo_warn("%s", val); /* perror */
return;
}
@@ -96,7 +97,7 @@ setifmaclabel(if_ctx *ctx, const char *val, int d __unused)
error = ioctl(ctx->io_s, SIOCSIFMAC, &ifr);
mac_free(label);
if (error == -1)
- perror("setifmac");
+ xo_warn("%s", "setifmac"); /* perror */
}
static struct cmd mac_cmds[] = {
diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c
index 8f355bc5187..ccd6072ec52 100644
--- a/sbin/ifconfig/ifmedia.c
+++ b/sbin/ifconfig/ifmedia.c
@@ -89,6 +89,8 @@
#include "ifconfig.h"
+#include <libxo/xo.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 *);
@@ -105,51 +107,54 @@ media_status(if_ctx *ctx)
return;
if (ifmr->ifm_count == 0) {
- warnx("%s: no media types?", ctx->ifname);
+ xo_warnx("%s: no media types?", ctx->ifname);
goto free;
}
- printf("\tmedia: ");
+ xo_emit("{P:\tmedia: }");
+ xo_open_list("media");
print_media(ifmr->ifm_current, true);
if (ifmr->ifm_active != ifmr->ifm_current) {
- putchar(' ');
- putchar('(');
+ xo_emit("{P: (}");
print_media(ifmr->ifm_active, false);
- putchar(')');
+ xo_emit("{P:)}");
}
+ xo_close_list("media");
- putchar('\n');
+ xo_emit("{P:\n}");
if (ifmr->ifm_status & IFM_AVALID) {
struct ifdownreason ifdr;
const char *status;
status = ifconfig_media_get_status(ifmr);
- printf("\tstatus: %s", status);
+ xo_emit("{P:\tstatus: }{:status/%s}", 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);
+ xo_emit("{P: (}{:reason-msg/%s}{P:)}", ifdr.ifdr_msg);
break;
case IFDR_REASON_VENDOR:
- printf(" (vendor code %d)",
+ xo_emit("{P: (vendor code }{:vendor-code/%d}{P:)}",
ifdr.ifdr_vendor);
break;
default:
break;
}
}
- putchar('\n');
+ xo_emit("{P:\n}");
}
if (ctx->args->supmedia) {
- printf("\tsupported media:\n");
+ xo_emit("{P:\tsupported media:}{P:\n}");
+ xo_open_list("media");
for (int i = 0; i < ifmr->ifm_count; ++i) {
- printf("\t\t");
+ xo_emit("{P:\t\t}");
print_media_ifconfig(ifmr->ifm_ulist[i]);
- putchar('\n');
+ xo_emit("{P:\n}");
}
+ xo_close_list("media");
}
free:
free(ifmr);
@@ -164,11 +169,11 @@ ifmedia_getstate(if_ctx *ctx)
return (ifmr);
if (ifconfig_media_get_mediareq(lifh, ctx->ifname, &ifmr) == -1)
- errc(1, ifconfig_err_errno(lifh),
+ xo_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);
+ xo_errx(1, "%s: no media types?", ctx->ifname);
return (ifmr);
}
@@ -183,7 +188,7 @@ setifmediacallback(if_ctx *ctx, void *arg)
if (!did_it) {
ifr.ifr_media = ifmr->ifm_current;
if (ioctl_ctx_ifr(ctx, SIOCSIFMEDIA, &ifr) < 0)
- err(1, "SIOCSIFMEDIA (media)");
+ xo_err(1, "SIOCSIFMEDIA (media)");
free(ifmr);
did_it = true;
}
@@ -260,7 +265,7 @@ setmediainst(if_ctx *ctx, const char *val, int d __unused)
inst = atoi(val);
if (inst < 0 || inst > (int)IFM_INST_MAX)
- errx(1, "invalid media instance: %s", val);
+ xo_errx(1, "invalid media instance: %s", val);
ifmr->ifm_current = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
@@ -292,11 +297,11 @@ get_media_subtype(ifmedia_t media, const char *val)
return (subtype);
switch (errno) {
case EINVAL:
- errx(EXIT_FAILURE, "unknown media type 0x%x", media);
+ xo_errx(EXIT_FAILURE, "unknown media type 0x%x", media);
case ENOENT:
- errx(EXIT_FAILURE, "unknown media subtype: %s", val);
+ xo_errx(EXIT_FAILURE, "unknown media subtype: %s", val);
default:
- err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
+ xo_err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
}
/*NOTREACHED*/
}
@@ -311,11 +316,11 @@ get_media_mode(ifmedia_t media, const char *val)
return (mode);
switch (errno) {
case EINVAL:
- errx(EXIT_FAILURE, "unknown media type 0x%x", media);
+ xo_errx(EXIT_FAILURE, "unknown media type 0x%x", media);
case ENOENT:
return (INVALID_IFMEDIA);
default:
- err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
+ xo_err(EXIT_FAILURE, "ifconfig_media_lookup_subtype");
}
/*NOTREACHED*/
}
@@ -334,7 +339,7 @@ get_media_options(ifmedia_t media, const char *val)
*/
opts = strdup(val);
if (opts == NULL)
- err(EXIT_FAILURE, "strdup");
+ xo_err(EXIT_FAILURE, "strdup");
/*
* Split the comma-delimited list into separate strings.
@@ -348,7 +353,7 @@ get_media_options(ifmedia_t media, const char *val)
}
optnames = calloc(nopts, sizeof(*optnames));
if (optnames == NULL)
- err(EXIT_FAILURE, "calloc");
+ xo_err(EXIT_FAILURE, "calloc");
opt = opts;
for (size_t i = 0; i < nopts; ++i) {
optnames[i] = opt;
@@ -360,11 +365,11 @@ get_media_options(ifmedia_t media, const char *val)
*/
options = ifconfig_media_lookup_options(media, optnames, nopts);
if (options == NULL)
- err(EXIT_FAILURE, "ifconfig_media_lookup_options");
+ xo_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]);
+ xo_errx(EXIT_FAILURE, "unknown option: %s", optnames[i]);
rval |= options[i];
}
free(options);
@@ -378,42 +383,54 @@ print_media(ifmedia_t media, bool print_toptype)
{
const char *val, **options;
+ xo_open_instance("media");
+
val = ifconfig_media_get_type(media);
if (val == NULL) {
- printf("<unknown type>");
+ xo_emit("{P:<unknown type>}");
+ xo_close_instance("media");
return;
} else if (print_toptype) {
- printf("%s", val);
+ xo_emit("{:type/%s}", val);
}
val = ifconfig_media_get_subtype(media);
if (val == NULL) {
- printf("<unknown subtype>");
+ xo_emit("{P:<unknown subtype>}");
+ xo_close_instance("media");
return;
}
if (print_toptype)
- putchar(' ');
+ xo_emit("{P: }");
- printf("%s", val);
+ xo_emit("{:subtype/%s}", val);
if (print_toptype) {
val = ifconfig_media_get_mode(media);
if (val != NULL && strcasecmp("autoselect", val) != 0)
- printf(" mode %s", val);
+ xo_emit("{P: mode }{: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(">");
+ 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)
- printf(" instance %d", IFM_INST(media));
+ xo_emit("{P: instance }{:instance/%d}", IFM_INST(media));
+
+ xo_close_instance("media");
}
static void
@@ -421,9 +438,12 @@ print_media_ifconfig(ifmedia_t media)
{
const char *val, **options;
+ xo_open_instance("media");
+
val = ifconfig_media_get_type(media);
if (val == NULL) {
- printf("<unknown type>");
+ xo_emit("{P:<unknown type>}");
+ xo_close_instance("media");
return;
}
@@ -434,26 +454,35 @@ print_media_ifconfig(ifmedia_t media)
val = ifconfig_media_get_subtype(media);
if (val == NULL) {
- printf("<unknown subtype>");
+ xo_emit("{P:<unknown subtype>}");
+ xo_close_instance("media");
return;
}
- printf("media %s", val);
+ xo_emit("{P:media }{:subtype/%s}", val);
val = ifconfig_media_get_mode(media);
if (val != NULL)
- printf(" mode %s", val);
+ xo_emit("{P: mode }{: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]);
+ 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)
- printf(" instance %d", IFM_INST(media));
+ xo_emit("{P: instance }{:instance/%d}", IFM_INST(media));
+
+ xo_close_instance("media");
}
/**********************************************************************
diff --git a/sbin/ifconfig/ifpfsync.c b/sbin/ifconfig/ifpfsync.c
index 264b1ecd5b5..e65a990dbaf 100644
--- a/sbin/ifconfig/ifpfsync.c
+++ b/sbin/ifconfig/ifpfsync.c
@@ -40,6 +40,7 @@
#include <arpa/inet.h>
#include <err.h>
+#include <libxo/xo.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
@@ -173,10 +174,10 @@ setpfsync_syncdev(if_ctx *ctx, const char *val, int dummy __unused)
nvlist_t *nvl = nvlist_create(0);
if (strlen(val) > IFNAMSIZ)
- errx(1, "interface name %s is too long", val);
+ xo_errx(1, "interface name %s is too long", val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_string(nvl, "syncdev"))
nvlist_free_string(nvl, "syncdev");
@@ -184,7 +185,7 @@ setpfsync_syncdev(if_ctx *ctx, const char *val, int dummy __unused)
nvlist_add_string(nvl, "syncdev", val);
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ xo_err(1, "SIOCSETPFSYNCNV");
}
static void
@@ -193,7 +194,7 @@ unsetpfsync_syncdev(if_ctx *ctx, const char *val __unused, int dummy __unused)
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_string(nvl, "syncdev"))
nvlist_free_string(nvl, "syncdev");
@@ -201,7 +202,7 @@ unsetpfsync_syncdev(if_ctx *ctx, const char *val __unused, int dummy __unused)
nvlist_add_string(nvl, "syncdev", "");
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ xo_err(1, "SIOCSETPFSYNCNV");
}
static void
@@ -214,10 +215,10 @@ setpfsync_syncpeer(if_ctx *ctx, const char *val, int dummy __unused)
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_err(1, "SIOCGETPFSYNCNV");
if ((ecode = getaddrinfo(val, NULL, NULL, &peerres)) != 0)
- errx(1, "error in parsing address string: %s",
+ xo_errx(1, "error in parsing address string: %s",
gai_strerror(ecode));
switch (peerres->ai_family) {
@@ -238,7 +239,7 @@ setpfsync_syncpeer(if_ctx *ctx, const char *val, int dummy __unused)
}
#endif
default:
- errx(1, "syncpeer address %s not supported", val);
+ xo_errx(1, "syncpeer address %s not supported", val);
}
if (nvlist_exists_nvlist(nvl, "syncpeer"))
@@ -248,7 +249,7 @@ setpfsync_syncpeer(if_ctx *ctx, const char *val, int dummy __unused)
pfsync_sockaddr_to_syncpeer_nvlist(&addr));
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ xo_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
freeaddrinfo(peerres);
@@ -263,7 +264,7 @@ unsetpfsync_syncpeer(if_ctx *ctx, const char *val __unused, int dummy __unused)
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_err(1, "SIOCGETPFSYNCNV");
if (nvlist_exists_nvlist(nvl, "syncpeer"))
nvlist_free_nvlist(nvl, "syncpeer");
@@ -272,7 +273,7 @@ unsetpfsync_syncpeer(if_ctx *ctx, const char *val __unused, int dummy __unused)
pfsync_sockaddr_to_syncpeer_nvlist(&addr));
if (pfsync_do_ioctl(ctx, SIOCSETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCSETPFSYNCNV");
+ xo_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -285,16 +286,16 @@ setpfsync_maxupd(if_ctx *ctx, const char *val, int dummy __unused)
maxupdates = atoi(val);
if ((maxupdates < 0) || (maxupdates > 255))
- errx(1, "maxupd %s: out of range", val);
+ xo_errx(1, "maxupd %s: out of range", val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_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");
+ xo_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -305,13 +306,13 @@ setpfsync_defer(if_ctx *ctx, const char *val __unused, int d)
nvlist_t *nvl = nvlist_create(0);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_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");
+ xo_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -326,13 +327,13 @@ setpfsync_version(if_ctx *ctx, const char *val, int dummy __unused)
version = atoi(val);
if (pfsync_do_ioctl(ctx, SIOCGETPFSYNCNV, &nvl) == -1)
- err(1, "SIOCGETPFSYNCNV");
+ xo_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");
+ xo_err(1, "SIOCSETPFSYNCNV");
nvlist_destroy(nvl);
}
@@ -374,10 +375,10 @@ pfsync_status(if_ctx *ctx)
nvlist_destroy(nvl);
- printf("\t");
+ xo_emit("\t");
if (syncdev[0] != '\0')
- printf("syncdev: %s ", syncdev);
+ xo_emit("syncdev: {:syncdev/%s} ", syncdev);
if ((syncpeer.ss_family == AF_INET &&
((struct sockaddr_in *)&syncpeer)->sin_addr.s_addr !=
@@ -388,14 +389,14 @@ pfsync_status(if_ctx *ctx)
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);
+ xo_errx(1, "getnameinfo: %s", gai_strerror(error));
+ xo_emit("syncpeer: {:syncpeer-str/%s} ", 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);
+ xo_emit("maxupd: {:maxupdates/%d} ", maxupdates);
+ xo_emit("defer: {:defer-status/%s} ", (flags & PFSYNCF_DEFER) ? "on" : "off");
+ xo_emit("version: {:pfsync-version/%d}\n", version);
+ xo_emit("\tsyncok: {:syncok/%d}\n", (flags & PFSYNCF_OK) ? 1 : 0);
}
static struct cmd pfsync_cmds[] = {
diff --git a/sbin/ifconfig/ifstf.c b/sbin/ifconfig/ifstf.c
index a99592b4801..cbe09b43420 100644
--- a/sbin/ifconfig/ifstf.c
+++ b/sbin/ifconfig/ifstf.c
@@ -42,6 +42,7 @@
#include <arpa/inet.h>
#include <ctype.h>
+#include <libxo/xo.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -72,9 +73,10 @@ stf_status(if_ctx *ctx)
if (do_cmd(ctx, STF6RD_GV4NET, &param, sizeof(param), 0) < 0)
return;
- printf("\tv4net %s/%d -> ", inet_ntoa(param.srcv4_addr),
+ xo_emit("\tv4net {:srcv4-addr/%s}/{:v4-prefixlen/%d} -> ",
+ inet_ntoa(param.srcv4_addr),
param.v4_prefixlen ? param.v4_prefixlen : 32);
- printf("tv4br %s\n", inet_ntoa(param.braddr));
+ xo_emit("tv4br {:braddr/%s}\n", inet_ntoa(param.braddr));
}
static void
@@ -89,11 +91,11 @@ setstf_br(if_ctx *ctx, const char *val, int d __unused)
sin.sin_family = AF_INET;
if (!inet_aton(val, &sin.sin_addr))
- errx(1, "%s: bad value", val);
+ xo_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);
+ xo_err(1, "STF6RD_SBR%s", val);
}
static void
@@ -111,21 +113,21 @@ setstf_set(if_ctx *ctx, const char *val, int d __unused)
p = strrchr(val, '/');
if (p == NULL)
- errx(2, "Wrong argument given");
+ xo_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);
+ xo_errx(1, "%s: bad value (prefix length %s)", val, errstr);
}
if (!inet_aton(val, &sin.sin_addr))
- errx(1, "%s: bad value", val);
+ xo_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);
+ xo_err(1, "STF6RD_SV4NET %s", val);
}
static struct cmd stf_cmds[] = {
diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c
index 0a2603f1736..0a37f4453c3 100644
--- a/sbin/ifconfig/ifvlan.c
+++ b/sbin/ifconfig/ifvlan.c
@@ -41,6 +41,8 @@
#include <sys/socket.h>
#include <sys/sockio.h>
+#include <libxo/xo.h>
+
#include <stdlib.h>
#include <unistd.h>
@@ -79,23 +81,23 @@ vlan_status(if_ctx *ctx)
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
return;
- printf("\tvlan: %d", vreq.vlr_tag);
- printf(" vlanproto: ");
+ xo_emit("{P:\tvlan: }{:vlantag/%d}", vreq.vlr_tag);
+ xo_emit("{P: vlanproto: }");
switch (vreq.vlr_proto) {
case ETHERTYPE_VLAN:
- printf(proto_8021Q);
+ xo_emit("{:vlan-protocol/%s}", proto_8021Q);
break;
case ETHERTYPE_QINQ:
- printf(proto_8021ad);
+ xo_emit("{:vlan-protocol/%s}", proto_8021ad);
break;
default:
- printf("0x%04x", vreq.vlr_proto);
+ xo_emit("{P:0x}{:vlan-protocol/%04x}", vreq.vlr_proto);
}
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");
+ xo_emit("{P: vlanpcp: }{:vlanpcp/%u}", ifr.ifr_vlan_pcp);
+ xo_emit("{P: parent interface: }{:parent-ifname/%s}",
+ vreq.vlr_parent[0] == '\0' ? "<none>" : vreq.vlr_parent);
+ xo_emit("\n");
}
static int
@@ -119,16 +121,16 @@ vlan_parse_ethervid(const char *name)
*/
*cp++ = '\0';
if ((*cp < '1') || (*cp > '9'))
- errx(1, "invalid vlan tag");
+ xo_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");
+ xo_errx(1, "invalid vlan tag");
}
if (*cp != '\0')
- errx(1, "invalid vlan tag");
+ xo_errx(1, "invalid vlan tag");
/*
* allow "devX.Y vlandev devX vlan Y" syntax
@@ -136,13 +138,13 @@ vlan_parse_ethervid(const char *name)
if (params.vlr_tag == NOTAG || params.vlr_tag == vid)
params.vlr_tag = vid;
else
- errx(1, "ambiguous vlan specification");
+ xo_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");
+ xo_errx(1, "ambiguous vlan specification");
}
static void
@@ -155,9 +157,9 @@ vlan_create(if_ctx *ctx, struct ifreq *ifr)
* One or both parameters were specified, make sure both.
*/
if (params.vlr_tag == NOTAG)
- errx(1, "must specify a tag for vlan create");
+ xo_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");
+ xo_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 +171,7 @@ static void
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");
+ xo_errx(1, "both vlan and vlandev must be specified");
}
static void
@@ -180,7 +182,7 @@ vlan_set(int s, struct ifreq *ifr)
params.vlr_proto = ETHERTYPE_VLAN;
ifr->ifr_data = (caddr_t) &params;
if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1)
- err(1, "SIOCSETVLAN");
+ xo_err(1, "SIOCSETVLAN");
}
}
@@ -194,11 +196,11 @@ setvlantag(if_ctx *ctx, const char *val, int dummy __unused)
ul = strtoul(val, &endp, 0);
if (*endp != '\0')
- errx(1, "invalid value for vlan");
+ xo_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");
+ xo_errx(1, "value for vlan out of range");
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
/*
@@ -240,7 +242,7 @@ setvlanproto(if_ctx *ctx, const char *val, int dummy __unused)
|| (strncasecmp(proto_qinq, val, strlen(proto_qinq)) == 0)) {
params.vlr_proto = ETHERTYPE_QINQ;
} else
- errx(1, "invalid value for vlanproto");
+ xo_errx(1, "invalid value for vlanproto");
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
/*
@@ -266,12 +268,12 @@ setvlanpcp(if_ctx *ctx, const char *val, int dummy __unused)
ul = strtoul(val, &endp, 0);
if (*endp != '\0')
- errx(1, "invalid value for vlanpcp");
+ xo_errx(1, "invalid value for vlanpcp");
if (ul > 7)
- errx(1, "value for vlanpcp out of range");
+ xo_errx(1, "value for vlanpcp out of range");
ifr.ifr_vlan_pcp = ul;
if (ioctl_ctx_ifr(ctx, SIOCSVLANPCP, &ifr) == -1)
- err(1, "SIOCSVLANPCP");
+ xo_err(1, "SIOCSVLANPCP");
}
static void
@@ -281,13 +283,13 @@ unsetvlandev(if_ctx *ctx, const char *val __unused, int dummy __unused)
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
- err(1, "SIOCGETVLAN");
+ xo_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");
+ xo_err(1, "SIOCSETVLAN");
}
static struct cmd vlan_cmds[] = {
diff --git a/sbin/ifconfig/ifvxlan.c b/sbin/ifconfig/ifvxlan.c
index cbea685b6ba..ee027be190d 100644
--- a/sbin/ifconfig/ifvxlan.c
+++ b/sbin/ifconfig/ifvxlan.c
@@ -41,6 +41,7 @@
#include <netinet/in.h>
#include <ctype.h>
+#include <libxo/xo.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -130,24 +131,25 @@ vxlan_status(if_ctx *ctx)
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 ? "[" : "",
+ xo_emit("\tvxlan vni {:vni/%d}", vni);
+ xo_emit(" local {P:/%s}{:local-src/%s}{P:/%s}:{:local-src-port/%s}",
+ ipv6 ? "[" : "", src, ipv6 ? "]" : "", srcport);
+ xo_emit(" {:peer-type/%s} {P:/%s}{:remote-dst/%s}{P:/%s}:{:remote-dst-port/%s}",
+ mc ? "group" : "remote", ipv6 ? "[" : "",
dst, ipv6 ? "]" : "", dstport);
if (ctx->args->verbose) {
- printf("\n\t\tconfig: ");
- printf("%slearning portrange %d-%d ttl %d",
+ xo_emit("{P:\n\t\tconfig: }");
+ 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);
- printf("\n\t\tftable: ");
- printf("cnt %d max %d timeout %d",
+ xo_emit("{P:\n\t\tftable: }");
+ 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);
}
- putchar('\n');
+ xo_emit("{P:\n}");
}
#define _LOCAL_ADDR46 \
@@ -160,14 +162,14 @@ vxlan_check_params(void)
{
if ((params.vxlp_with & _LOCAL_ADDR46) == _LOCAL_ADDR46)
- errx(1, "cannot specify both local IPv4 and IPv6 addresses");
+ xo_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");
+ xo_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");
+ xo_errx(1, "cannot mix IPv4 and IPv6 addresses");
}
#undef _LOCAL_ADDR46
@@ -190,7 +192,7 @@ setvxlan_vni(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || val >= VXLAN_VNI_MAX)
- errx(1, "invalid network identifier: %s", arg);
+ xo_errx(1, "invalid network identifier: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_VNI;
@@ -202,7 +204,7 @@ setvxlan_vni(if_ctx *ctx, const char *arg, int dummy __unused)
cmd.vxlcmd_vni = val;
if (do_cmd(ctx, VXLAN_CMD_SET_VNI, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_VNI");
+ xo_err(1, "VXLAN_CMD_SET_VNI");
}
static void
@@ -218,7 +220,7 @@ setvxlan_local(if_ctx *ctx, const char *addr, int dummy __unused)
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing local address string: %s",
+ xo_errx(1, "error in parsing local address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -231,7 +233,7 @@ setvxlan_local(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in *sin = satosin(sa);
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "local address cannot be multicast");
+ xo_errx(1, "local address cannot be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -242,14 +244,14 @@ setvxlan_local(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in6 *sin6 = satosin6(sa);
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "local address cannot be multicast");
+ xo_errx(1, "local address cannot be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "local address %s not supported", addr);
+ xo_errx(1, "local address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -266,7 +268,7 @@ setvxlan_local(if_ctx *ctx, const char *addr, int dummy __unused)
}
if (do_cmd(ctx, VXLAN_CMD_SET_LOCAL_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_LOCAL_ADDR");
+ xo_err(1, "VXLAN_CMD_SET_LOCAL_ADDR");
}
static void
@@ -282,7 +284,7 @@ setvxlan_remote(if_ctx *ctx, const char *addr, int dummy __unused)
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing remote address string: %s",
+ xo_errx(1, "error in parsing remote address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -295,7 +297,7 @@ setvxlan_remote(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in *sin = satosin(sa);
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "remote address cannot be multicast");
+ xo_errx(1, "remote address cannot be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -306,14 +308,14 @@ setvxlan_remote(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in6 *sin6 = satosin6(sa);
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "remote address cannot be multicast");
+ xo_errx(1, "remote address cannot be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "remote address %s not supported", addr);
+ xo_errx(1, "remote address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -330,7 +332,7 @@ setvxlan_remote(if_ctx *ctx, const char *addr, int dummy __unused)
}
if (do_cmd(ctx, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
+ xo_err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
}
static void
@@ -346,7 +348,7 @@ setvxlan_group(if_ctx *ctx, const char *addr, int dummy __unused)
bzero(&cmd, sizeof(cmd));
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
- errx(1, "error in parsing group address string: %s",
+ xo_errx(1, "error in parsing group address string: %s",
gai_strerror(error));
#if (defined INET || defined INET6)
@@ -359,7 +361,7 @@ setvxlan_group(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in *sin = satosin(sa);
if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
- errx(1, "group address must be multicast");
+ xo_errx(1, "group address must be multicast");
cmd.vxlcmd_sa.in4 = *sin;
break;
@@ -370,14 +372,14 @@ setvxlan_group(if_ctx *ctx, const char *addr, int dummy __unused)
struct sockaddr_in6 *sin6 = satosin6(sa);
if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- errx(1, "group address must be multicast");
+ xo_errx(1, "group address must be multicast");
cmd.vxlcmd_sa.in6 = *sin6;
break;
}
#endif
default:
- errx(1, "group address %s not supported", addr);
+ xo_errx(1, "group address %s not supported", addr);
}
freeaddrinfo(ai);
@@ -394,7 +396,7 @@ setvxlan_group(if_ctx *ctx, const char *addr, int dummy __unused)
}
if (do_cmd(ctx, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
+ xo_err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
}
static void
@@ -404,7 +406,7 @@ setvxlan_local_port(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid local port: %s", arg);
+ xo_errx(1, "invalid local port: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_LOCAL_PORT;
@@ -416,7 +418,7 @@ setvxlan_local_port(if_ctx *ctx, const char *arg, int dummy __unused)
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");
+ xo_err(1, "VXLAN_CMD_SET_LOCAL_PORT");
}
static void
@@ -426,7 +428,7 @@ setvxlan_remote_port(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
- errx(1, "invalid remote port: %s", arg);
+ xo_errx(1, "invalid remote port: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_PORT;
@@ -438,7 +440,7 @@ setvxlan_remote_port(if_ctx *ctx, const char *arg, int dummy __unused)
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");
+ xo_err(1, "VXLAN_CMD_SET_REMOTE_PORT");
}
static void
@@ -448,11 +450,11 @@ setvxlan_port_range(if_ctx *ctx, const char *arg1, const char *arg2)
u_long min, max;
if (get_val(arg1, &min) < 0 || min >= UINT16_MAX)
- errx(1, "invalid port range minimum: %s", arg1);
+ xo_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);
+ xo_errx(1, "invalid port range maximum: %s", arg2);
if (max < min)
- errx(1, "invalid port range");
+ xo_errx(1, "invalid port range");
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_PORT_RANGE;
@@ -466,7 +468,7 @@ setvxlan_port_range(if_ctx *ctx, const char *arg1, const char *arg2)
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");
+ xo_err(1, "VXLAN_CMD_SET_PORT_RANGE");
}
static void
@@ -476,7 +478,7 @@ setvxlan_timeout(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid timeout value: %s", arg);
+ xo_errx(1, "invalid timeout value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_TIMEOUT;
@@ -488,7 +490,7 @@ setvxlan_timeout(if_ctx *ctx, const char *arg, int dummy __unused)
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");
+ xo_err(1, "VXLAN_CMD_SET_FTABLE_TIMEOUT");
}
static void
@@ -498,7 +500,7 @@ setvxlan_maxaddr(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
- errx(1, "invalid maxaddr value: %s", arg);
+ xo_errx(1, "invalid maxaddr value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_MAX;
@@ -510,7 +512,7 @@ setvxlan_maxaddr(if_ctx *ctx, const char *arg, int dummy __unused)
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");
+ xo_err(1, "VXLAN_CMD_SET_FTABLE_MAX");
}
static void
@@ -529,7 +531,7 @@ setvxlan_dev(if_ctx *ctx, const char *arg, int dummy __unused)
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");
+ xo_err(1, "VXLAN_CMD_SET_MULTICAST_IF");
}
static void
@@ -539,7 +541,7 @@ setvxlan_ttl(if_ctx *ctx, const char *arg, int dummy __unused)
u_long val;
if (get_val(arg, &val) < 0 || val > 256)
- errx(1, "invalid TTL value: %s", arg);
+ xo_errx(1, "invalid TTL value: %s", arg);
if (!vxlan_exists(ctx)) {
params.vxlp_with |= VXLAN_PARAM_WITH_TTL;
@@ -551,7 +553,7 @@ setvxlan_ttl(if_ctx *ctx, const char *arg, int dummy __unused)
cmd.vxlcmd_ttl = val;
if (do_cmd(ctx, VXLAN_CMD_SET_TTL, &cmd, sizeof(cmd), 1) < 0)
- err(1, "VXLAN_CMD_SET_TTL");
+ xo_err(1, "VXLAN_CMD_SET_TTL");
}
static void
@@ -570,7 +572,7 @@ setvxlan_learn(if_ctx *ctx, const char *arg __unused, int d)
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");
+ xo_err(1, "VXLAN_CMD_SET_LEARN");
}
static void
@@ -583,7 +585,7 @@ setvxlan_flush(if_ctx *ctx, const char *val __unused, int d)
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");
+ xo_err(1, "VXLAN_CMD_FLUSH");
}
static struct cmd vxlan_cmds[] = {
diff --git a/sbin/ifconfig/sfp.c b/sbin/ifconfig/sfp.c
index 0dc1def751b..f62dd5d96bc 100644
--- a/sbin/ifconfig/sfp.c
+++ b/sbin/ifconfig/sfp.c
@@ -48,6 +48,27 @@
#include <libifconfig_sfp.h>
#include "ifconfig.h"
+#include <libxo/xo.h>
+
+static void
+sfp_dump_bytes(const uint8_t *data, size_t len)
+{
+
+ xo_open_list("sfp-dump");
+ for (size_t i = 0; i < len; i++) {
+ if (i % 16 == 0) {
+ if (i > 0)
+ xo_emit("{P:\n}");
+ xo_emit("{P:\t}");
+ }
+ xo_emit("{P:/%02x}", data[i]);
+ xo_emit("{le:sfp-dump/%u}", data[i]);
+ if (i % 16 != 15 && i + 1 < len)
+ xo_emit("{P: }");
+ }
+ xo_emit("{P:\n}");
+ xo_close_list("sfp-dump");
+}
void
sfp_status(if_ctx *ctx)
@@ -64,7 +85,7 @@ sfp_status(if_ctx *ctx)
ifconfig_sfp_get_sfp_info_strings(&info, &strings);
- printf("\tplugged: %s %s (%s)\n",
+ 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);
@@ -72,34 +93,33 @@ sfp_status(if_ctx *ctx)
if (ifconfig_sfp_get_sfp_vendor_info(lifh, ctx->ifname, &vendor_info) == -1)
return;
- printf("\tvendor: %s PN: %s SN: %s DATE: %s\n",
+ 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);
if (ifconfig_sfp_id_is_qsfp(info.sfp_id)) {
if (verbose > 1)
- printf("\tcompliance level: %s\n", strings.sfp_rev);
+ xo_emit("{P:\tcompliance level: }{:sfp-revision/%s}{P:\n}", strings.sfp_rev);
} else {
if (verbose > 5) {
- printf("Class: %s\n",
+ xo_emit("{P:Class: }{:sfp-class/%s}{P:\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);
+ xo_emit("{P:Length: }{:sfp-length/%s}{P:\n}", strings.sfp_fc_len);
+ xo_emit("{P:Tech: }{:sfp-tech/%s}{P:\n}", strings.sfp_cab_tech);
+ xo_emit("{P:Media: }{:sfp-media/%s}{P:\n}", strings.sfp_fc_media);
+ xo_emit("{P:Speed: }{:sfp-speed/%s}{P:\n}", strings.sfp_fc_speed);
}
}
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",
+ xo_emit("{P:\tnominal bitrate: }{:sfp-bitrate/%u}{P: Mbps\n}", status.bitrate);
+ xo_emit("{P:\tmodule temperature: }{:sfp-temperature/%.2f}{P: C voltage: }{:sfp-voltage/%.2f}{P: Volts\n}",
status.temp, status.voltage);
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",
+ 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));
}
ifconfig_sfp_free_sfp_status(&status);
@@ -112,16 +132,13 @@ sfp_status(if_ctx *ctx)
return;
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);
+ xo_emit("{P:\n\tSFF8436 DUMP (0xA0 128..255 range):\n}");
+ sfp_dump_bytes(dump.data + QSFP_DUMP1_START, QSFP_DUMP1_SIZE);
+ xo_emit("{P:\n\tSFF8436 DUMP (0xA0 0..81 range):\n}");
+ sfp_dump_bytes(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);
+ xo_emit("{P:\n\tSFF8472 DUMP (0xA0 0..127 range):\n}");
+ sfp_dump_bytes(dump.data + SFP_DUMP_START, SFP_DUMP_SIZE);
}
}
}
@paigeadelethompson

Copy link
Copy Markdown
Author

ovpn looks ok but I seem to remember theres a param for this driver that is settable and Im not sure at the moment... doesn't seem to be supported by ifconfig atm

@paigeadelethompson

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment