Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147895394
D4252.1784714391.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
25 KB
Referenced Files
None
Subscribers
None
D4252.1784714391.diff
View Options
Index: usr.sbin/ndp/Makefile
===================================================================
--- usr.sbin/ndp/Makefile
+++ usr.sbin/ndp/Makefile
@@ -24,4 +24,6 @@
WARNS?= 1
+LIBADD= xo
+
.include <bsd.prog.mk>
Index: usr.sbin/ndp/ndp.8
===================================================================
--- usr.sbin/ndp/ndp.8
+++ usr.sbin/ndp/ndp.8
@@ -79,6 +79,13 @@
utility manipulates the address mapping table
used by the Neighbor Discovery Protocol (NDP).
.Bl -tag -width indent
+.It Fl -libxo
+Generate output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_parse_args 3
+for details on command line arguments.
.It Fl a
Dump the currently existing NDP entries.
The following information will be printed:
Index: usr.sbin/ndp/ndp.c
===================================================================
--- usr.sbin/ndp/ndp.c
+++ usr.sbin/ndp/ndp.c
@@ -107,6 +107,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "gmt2local.h"
#define NEXTADDR(w, s) \
@@ -163,6 +164,12 @@
pid = getpid();
thiszone = gmt2local(0);
+
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+ atexit(xo_finish_atexit);
+
while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1)
switch (ch) {
case 'a':
@@ -243,12 +250,12 @@
if_nametoindex(*argv))
setdefif(*argv);
else
- errx(1, "invalid interface %s", *argv);
+ xo_errx(1, "invalid interface %s", *argv);
}
getdefif(); /* always call it to print the result */
break;
#else
- errx(1, "not supported yet");
+ xo_errx(1, "not supported yet");
/*NOTREACHED*/
#endif
case 'p':
@@ -315,7 +322,7 @@
char line[100], arg[5][50], *args[5], *p;
if ((fp = fopen(name, "r")) == NULL)
- err(1, "cannot open %s", name);
+ xo_err(1, "cannot open %s", name);
args[0] = &arg[0][0];
args[1] = &arg[1][0];
args[2] = &arg[2][0];
@@ -331,7 +338,7 @@
i = sscanf(line, "%49s %49s %49s %49s %49s",
arg[0], arg[1], arg[2], arg[3], arg[4]);
if (i < 2) {
- warnx("bad line: %s", line);
+ xo_warnx("bad line: %s", line);
retval = 1;
continue;
}
@@ -348,7 +355,7 @@
if (s < 0) {
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0) {
- err(1, "socket");
+ xo_err(1, "socket");
/* NOTREACHED */
}
}
@@ -399,8 +406,7 @@
hints.ai_family = AF_INET6;
gai_error = getaddrinfo(host, NULL, &hints, &res);
if (gai_error) {
- fprintf(stderr, "ndp: %s: %s\n", host,
- gai_strerror(gai_error));
+ xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error));
return 1;
}
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
@@ -421,7 +427,7 @@
argv++;
}
if (rtmsg(RTM_GET) < 0) {
- errx(1, "RTM_GET(%s) failed", host);
+ xo_errx(1, "RTM_GET(%s) failed", host);
/* NOTREACHED */
}
sin = (struct sockaddr_in6 *)(rtm + 1);
@@ -436,13 +442,14 @@
goto overwrite;
}
}
- fprintf(stderr, "set: cannot configure a new entry\n");
+ xo_warnx("set: cannot configure a new entry");
return 1;
}
overwrite:
if (sdl->sdl_family != AF_LINK) {
- printf("cannot intuit interface index and type for %s\n", host);
+ xo_warnx("cannot intuit interface index and type for %s",
+ host);
return (1);
}
sdl_m.sdl_type = sdl->sdl_type;
@@ -465,8 +472,7 @@
hints.ai_family = AF_INET6;
gai_error = getaddrinfo(host, NULL, &hints, &res);
if (gai_error) {
- fprintf(stderr, "ndp: %s: %s\n", host,
- gai_strerror(gai_error));
+ xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error));
return;
}
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
@@ -477,8 +483,7 @@
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf,
sizeof(host_buf), NULL ,0,
(nflag ? NI_NUMERICHOST : 0));
- printf("%s (%s) -- no entry\n", host, host_buf);
- exit(1);
+ xo_errx(1, "%s (%s) -- no entry", host, host_buf);
}
}
@@ -502,8 +507,7 @@
hints.ai_family = AF_INET6;
gai_error = getaddrinfo(host, NULL, &hints, &res);
if (gai_error) {
- fprintf(stderr, "ndp: %s: %s\n", host,
- gai_strerror(gai_error));
+ xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error));
return 1;
}
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
@@ -510,7 +514,7 @@
sin->sin6_scope_id =
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
if (rtmsg(RTM_GET) < 0) {
- errx(1, "RTM_GET(%s) failed", host);
+ xo_errx(1, "RTM_GET(%s) failed", host);
/* NOTREACHED */
}
sin = (struct sockaddr_in6 *)(rtm + 1);
@@ -520,13 +524,13 @@
!(rtm->rtm_flags & RTF_GATEWAY)) {
goto delete;
}
- fprintf(stderr, "delete: cannot delete non-NDP entry\n");
+ xo_warnx("delete: cannot delete non-NDP entry");
return 1;
}
delete:
if (sdl->sdl_family != AF_LINK) {
- printf("cannot locate %s\n", host);
+ xo_warnx("cannot locate %s", host);
return (1);
}
/*
@@ -540,7 +544,7 @@
sin->sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
(nflag ? NI_NUMERICHOST : 0));
- printf("%s (%s) deleted\n", host, host_buf);
+ xo_warnx("%s (%s) deleted", host, host_buf);
}
return 0;
@@ -571,11 +575,20 @@
char flgbuf[8];
char *ifname;
+ xo_open_container("ndp-entries");
+ if (repeat) {
+ xo_open_list("repeat");
+ xo_open_instance("repeat");
+ }
+ xo_open_list("neighbor-entry");
+
/* Print header */
if (!tflag && !cflag)
- printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n",
- W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address",
- W_IF, W_IF, "Netif", "Expire", "S", "Flags");
+ xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} {T:/%-9.9s}"
+ " {T:/%1s} {T:/%5s}\n",
+ W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL,
+ "Linklayer Address", W_IF, W_IF, "Netif", "Expire", "S",
+ "Flags");
again:;
mib[0] = CTL_NET;
@@ -589,12 +602,12 @@
mib[5] = 0;
#endif
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
- err(1, "sysctl(PF_ROUTE estimate)");
+ xo_err(1, "sysctl(PF_ROUTE estimate)");
if (needed > 0) {
if ((buf = malloc(needed)) == NULL)
- err(1, "malloc");
+ xo_err(1, "malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
- err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
+ xo_err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
lim = buf + needed;
} else
buf = lim = NULL;
@@ -655,6 +668,9 @@
#endif
continue;
}
+
+ xo_open_instance("neighbor-entry");
+
gettimeofday(&now, 0);
if (tflag)
ts_print(&now);
@@ -672,44 +688,52 @@
if (W_ADDR + W_LL + W_IF - addrwidth - llwidth > ifwidth)
ifwidth = W_ADDR + W_LL + W_IF - addrwidth - llwidth;
- printf("%-*.*s %-*.*s %*.*s", addrwidth, addrwidth, host_buf,
- llwidth, llwidth, ether_str(sdl), ifwidth, ifwidth, ifname);
+ xo_emit("{d:neighbor/%-*.*s}{e:neighbor}",
+ addrwidth, addrwidth, host_buf, host_buf);
+ xo_emit(" {d:linklayer-address/%-*.*s}{e:linklayer-address}",
+ llwidth, llwidth, ether_str(sdl), ether_str(sdl));
+ xo_emit(" {d:interface/%*.*s}{e:interface}",
+ ifwidth, ifwidth, ifname, ifname);
/* Print neighbor discovery specific information */
expire = rtm->rtm_rmx.rmx_expire;
- if (expire > now.tv_sec)
- printf(" %-9.9s", sec2str(expire - now.tv_sec));
- else if (expire == 0)
- printf(" %-9.9s", "permanent");
+ if (expire > now.tv_sec) {
+ char *sec = sec2str(expire - now.tv_sec);
+
+ xo_emit(" {d:expire/%-9.9s}{e:expire}", sec, sec);
+ } else if (expire == 0)
+ xo_emit(" {t:expire/%-9.9s}", "permanent");
else
- printf(" %-9.9s", "expired");
+ xo_emit(" {t:expire/%-9.9s}", "expired");
switch (rtm->rtm_rmx.rmx_state) {
case ND6_LLINFO_NOSTATE:
- printf(" N");
+ xo_emit(" {:state}{e:state_pretty}", "N", "nostate");
break;
#ifdef ND6_LLINFO_WAITDELETE
case ND6_LLINFO_WAITDELETE:
- printf(" W");
+ xo_emit(" {:state}{e:state_pretty}", "W",
+ "waitdelete");
break;
#endif
case ND6_LLINFO_INCOMPLETE:
- printf(" I");
+ xo_emit(" {:state}{e:state_pretty}", "I",
+ "incomplete");
break;
case ND6_LLINFO_REACHABLE:
- printf(" R");
+ xo_emit(" {:state}{e:state_pretty}", "R", "reachable");
break;
case ND6_LLINFO_STALE:
- printf(" S");
+ xo_emit(" {:state}{e:state_pretty}", "S", "stale");
break;
case ND6_LLINFO_DELAY:
- printf(" D");
+ xo_emit(" {:state}{e:state_pretty}", "D", "delay");
break;
case ND6_LLINFO_PROBE:
- printf(" P");
+ xo_emit(" {:state}{e:state_pretty}", "P", "probe");
break;
default:
- printf(" ?");
+ xo_emit(" {:state}{e:state_pretty}", "?", "unknown");
break;
}
@@ -738,22 +762,48 @@
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
#endif
}
- printf(" %s", flgbuf);
+ xo_emit(" {:flags}", flgbuf);
+ if (isrouter)
+ xo_emit("{el:flags_pretty}", "router");
+ if ((rtm->rtm_flags & RTF_ANNOUNCE))
+ xo_emit("{el:flags_pretty}", "proxy");
+#if 0 /* W and P are mystery even for us */
+ if ((rtm->rtm_addrs & RTA_NETMASK) != 0) {
+ sin = (struct sockaddr_in6 *)
+ (sdl->sdl_len + (char *)sdl);
+ if (!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr))
+ xo_emit("{el:flags_pretty", "P");
+ if ((sin->sin6_len != sizeof(struct sockaddr_in6)))
+ xo_emit("{el:flags_pretty}", "W");
+ }
+#endif
if (prbs)
- printf(" %d", prbs);
+ xo_emit(" {:prbs/%d}", prbs);
- printf("\n");
+ xo_emit("\n");
+ xo_close_instance("neighbor-entry");
}
if (buf != NULL)
free(buf);
if (repeat) {
- printf("\n");
- fflush(stdout);
+ xo_emit("\n");
+ xo_close_list("neighbor-entry");
+ xo_close_instance("repeat");
+ xo_flush();
sleep(repeat);
+ xo_open_instance("repeat");
+ xo_open_list("neighbor-entry");
goto again;
}
+
+ xo_close_list("neighbor-entry");
+ if (repeat) {
+ xo_close_instance("repeat");
+ xo_close_list("repeat");
+ }
+ xo_close_container("ndp-entries");
}
static struct in6_nbrinfo *
@@ -763,7 +813,7 @@
int s;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
bzero(&nbi, sizeof(nbi));
if_indextoname(ifindex, nbi.ifname);
@@ -770,7 +820,7 @@
nbi.addr = *addr;
if (ioctl(s, SIOCGNBRINFO_IN6, (caddr_t)&nbi) < 0) {
if (warning)
- warn("ioctl(SIOCGNBRINFO_IN6)");
+ xo_warn("ioctl(SIOCGNBRINFO_IN6)");
close(s);
return(NULL);
}
@@ -804,7 +854,7 @@
i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2],
&o[3], &o[4], &o[5]);
if (i != 6) {
- fprintf(stderr, "ndp: invalid Ethernet address '%s'\n", a);
+ xo_warnx("ndp: invalid Ethernet address '%s'", a);
return (1);
}
for (i = 0; i < 6; i++)
@@ -815,16 +865,17 @@
static void
usage()
{
- printf("usage: ndp [-nt] hostname\n");
- printf(" ndp [-nt] -a | -c | -p | -r | -H | -P | -R\n");
- printf(" ndp [-nt] -A wait\n");
- printf(" ndp [-nt] -d hostname\n");
- printf(" ndp [-nt] -f filename\n");
- printf(" ndp [-nt] -i interface [flags...]\n");
+ xo_error("%s",
+ "usage: ndp [-nt] hostname\n"
+ " ndp [-nt] -a | -c | -p | -r | -H | -P | -R\n"
+ " ndp [-nt] -A wait\n"
+ " ndp [-nt] -d hostname\n"
+ " ndp [-nt] -f filename\n"
+ " ndp [-nt] -i interface [flags...]\n"
#ifdef SIOCSDEFIFACE_IN6
- printf(" ndp [-nt] -I [interface|delete]\n");
+ " ndp [-nt] -I [interface|delete]\n"
#endif
- printf(" ndp [-nt] -s nodename etheraddr [temp] [proxy]\n");
+ " ndp [-nt] -s nodename etheraddr [temp] [proxy]\n");
exit(1);
}
@@ -846,8 +897,7 @@
switch (cmd) {
default:
- fprintf(stderr, "ndp: internal wrong cmd\n");
- exit(1);
+ xo_errx(1, "ndp: internal wrong cmd");
case RTM_ADD:
rtm->rtm_addrs |= RTA_GATEWAY;
if (expire_time) {
@@ -880,7 +930,7 @@
rtm->rtm_type = cmd;
if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) {
if (errno != ESRCH || cmd != RTM_DELETE) {
- err(1, "writing to routing socket");
+ xo_err(1, "writing to routing socket");
/* NOTREACHED */
}
}
@@ -888,8 +938,7 @@
l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg));
} while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid));
if (l < 0)
- (void) fprintf(stderr, "ndp: read from routing socket: %s\n",
- strerror(errno));
+ xo_warnx("ndp: read from routing socket: %s", strerror(errno));
return (0);
}
@@ -904,13 +953,13 @@
#endif
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- err(1, "socket");
+ xo_err(1, "socket");
/* NOTREACHED */
}
bzero(&nd, sizeof(nd));
strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
- err(1, "ioctl(SIOCGIFINFO_IN6)");
+ xo_err(1, "ioctl(SIOCGIFINFO_IN6)");
/* NOTREACHED */
}
#define ND nd.ndi
@@ -945,11 +994,11 @@
if (strncmp(cp, f, strlen(f)) == 0) { \
valptr = strchr(cp, '='); \
if (valptr == NULL) \
- err(1, "syntax error in %s field", (f)); \
+ xo_err(1, "syntax error in %s field", (f)); \
errno = 0; \
newval = strtoul(++valptr, NULL, 0); \
if (errno) \
- err(1, "syntax error in %s's value", (f)); \
+ xo_err(1, "syntax error in %s's value", (f)); \
v = newval; \
} \
} while (0)
@@ -971,7 +1020,7 @@
ND.flags = newflags;
if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) {
- err(1, "ioctl(SIOCSIFINFO_IN6)");
+ xo_err(1, "ioctl(SIOCSIFINFO_IN6)");
/* NOTREACHED */
}
#undef SETFLAG
@@ -979,71 +1028,80 @@
}
if (!ND.initialized) {
- errx(1, "%s: not initialized yet", ifname);
+ xo_errx(1, "%s: not initialized yet", ifname);
/* NOTREACHED */
}
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
- err(1, "ioctl(SIOCGIFINFO_IN6)");
+ xo_err(1, "ioctl(SIOCGIFINFO_IN6)");
/* NOTREACHED */
}
- printf("linkmtu=%d", ND.linkmtu);
- printf(", maxmtu=%d", ND.maxmtu);
- printf(", curhlim=%d", ND.chlim);
- printf(", basereachable=%ds%dms",
+
+ xo_open_container("nd-information");
+ xo_emit("{L:linkmtu}={:link-mtu/%d}", ND.linkmtu);
+ xo_emit(", {L:maxmtu}={:max-link-mtu/%d}", ND.maxmtu);
+ xo_emit(", {L:curhlim}={:current-hop-limit/%d}", ND.chlim);
+ xo_emit(", {L:basereachable}={:base-reachable-time/%ds%dms}",
ND.basereachable / 1000, ND.basereachable % 1000);
- printf(", reachable=%ds", ND.reachable);
- printf(", retrans=%ds%dms", ND.retrans / 1000, ND.retrans % 1000);
+ xo_emit(", {L:reachable}={:reachable-time/%ds}", ND.reachable);
+ xo_emit(", {L:retrans}={:retrans-timer/%ds%dms}", ND.retrans / 1000,
+ ND.retrans % 1000);
#ifdef IPV6CTL_USETEMPADDR
memset(nullbuf, 0, sizeof(nullbuf));
if (memcmp(nullbuf, ND.randomid, sizeof(nullbuf)) != 0) {
int j;
- u_int8_t *rbuf;
+ char rbuf[17];
+ u_int8_t *rptr[] = {
+ ND.randomseed0, ND.randomseed1, ND.randomid
+ };
for (i = 0; i < 3; i++) {
+ for (j = 0; j < 8; j++)
+ snprintf(rbuf + j * 2, sizeof(rbuf) - j * 2,
+ "%02x", rptr[i][j]);
switch (i) {
case 0:
- printf("\nRandom seed(0): ");
- rbuf = ND.randomseed0;
+ xo_emit("\n{[:-16}{Lc:Random seed(0)}{]:}"
+ "{:random-seed-0}", rbuf);
break;
case 1:
- printf("\nRandom seed(1): ");
- rbuf = ND.randomseed1;
+ xo_emit("\n{[:-16}{Lc:Random seed(1)}{]:}"
+ "{:random-seed-1}", rbuf);
break;
case 2:
- printf("\nRandom ID: ");
- rbuf = ND.randomid;
+ xo_emit("\n{[:-16}{Lc:Random ID}{]:}"
+ "{:random-id}", rbuf);
break;
default:
- errx(1, "impossible case for tempaddr display");
+ xo_errx(1,
+ "impossible case for tempaddr display");
}
- for (j = 0; j < 8; j++)
- printf("%02x", rbuf[j]);
}
}
#endif
if (ND.flags) {
- printf("\nFlags: ");
+ xo_emit("\nFlags: ");
#ifdef ND6_IFF_IFDISABLED
if ((ND.flags & ND6_IFF_IFDISABLED))
- printf("disabled ");
+ xo_emit("{l:flags} ", "disabled");
#endif
if ((ND.flags & ND6_IFF_PERFORMNUD))
- printf("nud ");
+ xo_emit("{l:flags} ", "nud");
#ifdef ND6_IFF_ACCEPT_RTADV
if ((ND.flags & ND6_IFF_ACCEPT_RTADV))
- printf("accept_rtadv ");
+ xo_emit("{l:flags} ", "accept_rtadv");
#endif
#ifdef ND6_IFF_AUTO_LINKLOCAL
if ((ND.flags & ND6_IFF_AUTO_LINKLOCAL))
- printf("auto_linklocal ");
+ xo_emit("{l:flags} ", "auto_linklocal");
#endif
#ifdef ND6_IFF_NO_PREFER_IFACE
if ((ND.flags & ND6_IFF_NO_PREFER_IFACE))
- printf("no_prefer_iface ");
+ xo_emit("{l:flags} ", "no_prefer_iface");
#endif
}
- putc('\n', stdout);
+ xo_emit("\n");
+ xo_close_container("nd-information");
#undef ND
close(s);
@@ -1063,7 +1121,7 @@
struct timeval now;
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
- err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
+ xo_err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
/*NOTREACHED*/
}
if (l == 0)
@@ -1070,39 +1128,53 @@
return;
buf = malloc(l);
if (!buf) {
- err(1, "malloc");
+ xo_err(1, "malloc");
/*NOTREACHED*/
}
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
- err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
+ xo_err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
/*NOTREACHED*/
}
+ xo_open_container("default-router-list");
+ xo_open_list("default-router-entry");
+
ep = (struct in6_defrouter *)(buf + l);
for (p = (struct in6_defrouter *)buf; p < ep; p++) {
int rtpref;
+ xo_open_instance("default-router-entry");
+
if (getnameinfo((struct sockaddr *)&p->rtaddr,
p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0,
(nflag ? NI_NUMERICHOST : 0)) != 0)
strlcpy(host_buf, "?", sizeof(host_buf));
- printf("%s if=%s", host_buf,
+ xo_emit("{:address} {L:if}={:interface}", host_buf,
if_indextoname(p->if_index, ifix_buf));
- printf(", flags=%s%s",
+ xo_emit(", {L:flags}={:flags/%s%s}",
p->flags & ND_RA_FLAG_MANAGED ? "M" : "",
p->flags & ND_RA_FLAG_OTHER ? "O" : "");
+ if (p->flags & ND_RA_FLAG_MANAGED)
+ xo_emit("{el:flags_pretty}", "managed");
+ if (p->flags & ND_RA_FLAG_OTHER)
+ xo_emit("{el:flags_pretty}", "other");
rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff;
- printf(", pref=%s", rtpref_str[rtpref]);
+ xo_emit(", {L:pref}={:preference}", rtpref_str[rtpref]);
gettimeofday(&now, 0);
if (p->expire == 0)
- printf(", expire=Never\n");
+ xo_emit(", {L:expire}={:expire}\n", "Never");
else
- printf(", expire=%s\n",
+ xo_emit(", {L:expire}={:expire}\n",
sec2str(p->expire - now.tv_sec));
+
+ xo_close_instance("default-router-entry");
}
free(buf);
+
+ xo_close_list("default-router-entry");
+ xo_close_container("default-router-list");
}
static void
@@ -1119,30 +1191,35 @@
char namebuf[NI_MAXHOST];
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
- err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
+ xo_err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
/*NOTREACHED*/
}
buf = malloc(l);
if (!buf) {
- err(1, "malloc");
+ xo_err(1, "malloc");
/*NOTREACHED*/
}
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
- err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
+ xo_err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
/*NOTREACHED*/
}
+ xo_open_container("prefix-list");
+ xo_open_list("prefix-entry");
+
ep = (struct in6_prefix *)(buf + l);
for (p = (struct in6_prefix *)buf; p < ep; p = n) {
advrtr = (struct sockaddr_in6 *)(p + 1);
n = (struct in6_prefix *)&advrtr[p->advrtrs];
+ xo_open_instance("prefix-entry");
+
if (getnameinfo((struct sockaddr *)&p->prefix,
p->prefix.sin6_len, namebuf, sizeof(namebuf),
NULL, 0, niflags) != 0)
strlcpy(namebuf, "?", sizeof(namebuf));
- printf("%s/%d if=%s\n", namebuf, p->prefixlen,
- if_indextoname(p->if_index, ifix_buf));
+ xo_emit("{q:prefix/%s%c%d} {L:if}={:interface}\n", namebuf,
+ '/', p->prefixlen, if_indextoname(p->if_index, ifix_buf));
gettimeofday(&now, 0);
/*
@@ -1149,7 +1226,7 @@
* meaning of fields, especially flags, is very different
* by origin. notify the difference to the users.
*/
- printf("flags=%s%s%s%s%s",
+ xo_emit("{L:flags}={:flags/%s%s%s%s%s}",
p->raflags.onlink ? "L" : "",
p->raflags.autonomous ? "A" : "",
(p->flags & NDPRF_ONLINK) != 0 ? "O" : "",
@@ -1160,23 +1237,38 @@
""
#endif
);
+ if (p->raflags.onlink)
+ xo_emit("{el:flags_pretty}", "onlink");
+ if (p->raflags.autonomous)
+ xo_emit("{el:flags_pretty}", "autonomous");
+ if ((p->flags & NDPRF_ONLINK) != 0)
+ xo_emit("{el:flags_pretty}", "ndprf_onlink");
+ if ((p->flags & NDPRF_DETACHED) != 0)
+ xo_emit("{el:flags_pretty}", "ndprf_detached");
+#ifdef NDPRF_HOME
+ if ((p->flags & NDPRF_HOME) != 0)
+ xo_emit("{el:flags_pretty}", "ndprf_home");
+#endif
if (p->vltime == ND6_INFINITE_LIFETIME)
- printf(" vltime=infinity");
+ xo_emit(" {L:vltime}={:valid-lifetime}", "infinity");
else
- printf(" vltime=%lu", (unsigned long)p->vltime);
+ xo_emit(" {L:vltime}={:valid-lifetime/%lu}",
+ (unsigned long)p->vltime);
if (p->pltime == ND6_INFINITE_LIFETIME)
- printf(", pltime=infinity");
+ xo_emit(", {L:pltime}={:preferred-lifetime}",
+ "infinity");
else
- printf(", pltime=%lu", (unsigned long)p->pltime);
+ xo_emit(", {L:pltime}={:preferred-lifetime/%lu}",
+ (unsigned long)p->pltime);
if (p->expire == 0)
- printf(", expire=Never");
+ xo_emit(", {L:expire}={:expire}", "Never");
else if (p->expire >= now.tv_sec)
- printf(", expire=%s",
+ xo_emit(", {L:expire}={:expire}",
sec2str(p->expire - now.tv_sec));
else
- printf(", expired");
- printf(", ref=%d", p->refcnt);
- printf("\n");
+ xo_emit(", {:expire}", "expired");
+ xo_emit(", {L:ref}={:reference-count/%d}", p->refcnt);
+ xo_emit("\n");
/*
* "advertising router" list is meaningful only if the prefix
* information is from RA.
@@ -1186,15 +1278,17 @@
struct sockaddr_in6 *sin6;
sin6 = advrtr;
- printf(" advertised by\n");
+ xo_emit("{P: }advertised by\n");
+ xo_open_list("advertised-by");
for (j = 0; j < p->advrtrs; j++) {
struct in6_nbrinfo *nbi;
+ xo_open_instance("advertised-by");
if (getnameinfo((struct sockaddr *)sin6,
sin6->sin6_len, namebuf, sizeof(namebuf),
NULL, 0, ninflags) != 0)
strlcpy(namebuf, "?", sizeof(namebuf));
- printf(" %s", namebuf);
+ xo_emit("{P: }{:address}", namebuf);
nbi = getnbrinfo(&sin6->sin6_addr,
p->if_index, 0);
@@ -1204,19 +1298,26 @@
case ND6_LLINFO_STALE:
case ND6_LLINFO_DELAY:
case ND6_LLINFO_PROBE:
- printf(" (reachable)\n");
+ xo_emit(" {d:/(reachable)}"
+ "{eq:reachable/yes}\n");
break;
default:
- printf(" (unreachable)\n");
+ xo_emit(" {d:/(unreachable)}"
+ "{eq:reachable/no}\n");
}
} else
- printf(" (no neighbor state)\n");
+ xo_emit(" (no neighbor state)\n");
+ xo_close_instance("advertised-by");
sin6++;
}
+ xo_close_list("advertised-by");
} else
- printf(" No advertising router\n");
+ xo_emit(" No advertising router\n");
}
free(buf);
+
+ xo_close_list("prefix-entry");
+ xo_close_container("prefix-list");
}
static void
@@ -1226,10 +1327,10 @@
int s;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0)
- err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
+ xo_err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
}
static void
@@ -1239,10 +1340,10 @@
int s;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0)
- err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
+ xo_err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
close(s);
}
@@ -1254,10 +1355,10 @@
int s;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
if (ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0)
- err(1, "ioctl(SIOCSNDFLUSH_IN6)");
+ xo_err(1, "ioctl(SIOCSNDFLUSH_IN6)");
close(s);
}
@@ -1273,17 +1374,18 @@
ifindex = 0;
else {
if ((ifindex = if_nametoindex(ifname)) == 0)
- err(1, "failed to resolve i/f index for %s", ifname);
+ xo_err(1, "failed to resolve i/f index for %s",
+ ifname);
}
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
ndifreq.ifindex = ifindex;
if (ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
- err(1, "ioctl(SIOCSDEFIFACE_IN6)");
+ xo_err(1, "ioctl(SIOCSDEFIFACE_IN6)");
close(s);
}
@@ -1295,22 +1397,24 @@
char ifname[IFNAMSIZ+8];
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- err(1, "socket");
+ xo_err(1, "socket");
memset(&ndifreq, 0, sizeof(ndifreq));
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
if (ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
- err(1, "ioctl(SIOCGDEFIFACE_IN6)");
+ xo_err(1, "ioctl(SIOCGDEFIFACE_IN6)");
+ xo_open_container("nd-default-interface");
if (ndifreq.ifindex == 0)
- printf("No default interface.\n");
+ xo_warnx("No default interface.");
else {
if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL)
- err(1, "failed to resolve ifname for index %lu",
+ xo_err(1, "failed to resolve ifname for index %lu",
ndifreq.ifindex);
- printf("ND default interface = %s\n", ifname);
+ xo_emit("{L:ND default interface} = {:interface}\n", ifname);
}
+ xo_close_container("nd-default-interface");
close(s);
}
@@ -1368,7 +1472,7 @@
/* Default */
s = (tvp->tv_sec + thiszone) % 86400;
- (void)printf("%02d:%02d:%02d.%06u ",
+ xo_emit("{q:timestamp/%02d:%02d:%02d.%06u} ",
s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tvp->tv_usec);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 22, 9:59 AM (23 m, 29 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29226803
Default Alt Text
D4252.1784714391.diff (25 KB)
Attached To
Mode
D4252: Add libxo support for ndp(8)
Attached
Detach File
Event Timeline
Log In to Comment