FreeBSD Bugzilla – Attachment 177639 Details for
Bug 215008
[patch] jls(8) separate lists for IPv4 and IPv6 in verbose libxo output
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
[Patch 2/2] Emit IP addresses as lists in -n and encoding-format mode.
jls_ip4_ip6_as_lists.patch (text/plain), 5.34 KB, created by
Christian Schwarz
on 2016-12-03 21:14:44 UTC
(
hide
)
Description:
[Patch 2/2] Emit IP addresses as lists in -n and encoding-format mode.
Filename:
MIME Type:
Creator:
Christian Schwarz
Created:
2016-12-03 21:14:44 UTC
Size:
5.34 KB
patch
obsolete
>commit 98251921e15b592b8e23d302f7abb25c327ad57f >Author: Christian Schwarz <me@cschwarz.com> >Date: Sat Dec 3 23:08:24 2016 +0100 > > Print ip4.addr and ip6.addr as lists for libxo encoded output (json, xml). > > Instead of providing a comma-separated list, ip4.addr and ip6.addr are > thus represented in the encoding format's natural structure. > > This patch also unifies / simplifies the IP presentation format conversion. > > The XO_VERSION is not incremented because this patch builds upon a previous one. > > New output format: > > jls -n all --libxo json > ... > "ip4.addr": [ > "10.1.1.1", > "10.1.1.2", > "10.1.1.3" > ], > "ip4.saddrsel": true, > "ip6.addr": [ > "fe80::1000:1", > "fe80::1000:2" > ], > ... > > jls -n all --libxo xml > ... > <ip4.addr>10.1.1.1</ip4.addr> > <ip4.addr>10.1.1.2</ip4.addr> > <ip4.addr>10.1.1.3</ip4.addr> > <ip4.saddrsel>true</ip4.saddrsel> > <ip6.addr>fe80::1000:1</ip6.addr> > <ip6.addr>fe80::1000:2</ip6.addr> > ... > >diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c >index 85a7d4b..d0090f8 100644 >--- a/usr.sbin/jls/jls.c >+++ b/usr.sbin/jls/jls.c >@@ -77,7 +77,9 @@ static int sort_param(const void *a, const void *b); > static char *noname(const char *name); > static char *nononame(const char *name); > static int print_jail(int pflags, int jflags); >+static int special_print(int pflags, struct jailparam *param); > static void quoted_print(int pflags, char *name, char *value); >+static void emit_ip_addr(int af_family, struct jailparam *param); > > int > main(int argc, char **argv) >@@ -379,8 +381,7 @@ print_jail(int pflags, int jflags) > { > char *nname, *xo_nname; > char **param_values; >- int i, ai, jid, count, n, spc; >- char ipbuf[INET6_ADDRSTRLEN]; >+ int i, jid, n, spc; > > jid = jailparam_get(params, nparams, jflags); > if (jid < 0) >@@ -402,34 +403,15 @@ print_jail(int pflags, int jflags) > #ifdef INET > if (ip4_ok && !strcmp(params[n].jp_name, "ip4.addr")) { > xo_open_list("ipv4_addrs"); >- count = params[n].jp_valuelen / sizeof(struct in_addr); >- for (ai = 0; ai < count; ai++) { >- if (inet_ntop(AF_INET, >- &((struct in_addr *)params[n].jp_value)[ai], >- ipbuf, sizeof(ipbuf)) == NULL) { >- xo_err(1, "inet_ntop"); >- } else { >- xo_emit("{P: }{ql:ipv4_addr}{P:\n}", ipbuf); >- } >- } >+ emit_ip_addr(AF_INET, params + n); > xo_close_list("ipv4_addrs"); > n++; > } > #endif > #ifdef INET6 > if (ip6_ok && !strcmp(params[n].jp_name, "ip6.addr")) { >- count = params[n].jp_valuelen / sizeof(struct in6_addr); > xo_open_list("ipv6_addrs"); >- for (ai = 0; ai < count; ai++) { >- if (inet_ntop(AF_INET6, >- &((struct in6_addr *) >- params[n].jp_value)[ai], >- ipbuf, sizeof(ipbuf)) == NULL) { >- xo_err(1, "inet_ntop"); >- } else { >- xo_emit("{P: }{ql:ipv6_addr}{P:\n}", ipbuf); >- } >- } >+ emit_ip_addr(AF_INET6, params + n); > xo_close_list("ipv6_addrs"); > n++; > } >@@ -457,6 +439,7 @@ print_jail(int pflags, int jflags) > if (!(params[i].jp_flags & JP_USER)) > continue; > param_values[i] = jailparam_export(params + i); >+ param_values[i] = jailparam_export(params + i); > if (param_values[i] == NULL) > xo_errx(1, "%s", jail_errmsg); > } >@@ -506,14 +489,10 @@ print_jail(int pflags, int jflags) > } > xo_emit("{d:%s}=", params[i].jp_name); > } >- if (params[i].jp_valuelen == 0) { >- if (pflags & PRINT_QUOTED) >- xo_emit("{P:\"\"}"); >- else if (!(pflags & PRINT_NAMEVAL)) >- xo_emit("{P:-}"); >- } else { >+ >+ if (!special_print(pflags, params + i)) > quoted_print(pflags, params[i].jp_name, param_values[i]); >- } >+ > } > xo_emit("{P:\n}"); > for (i = 0; i < nparams; i++) >@@ -560,3 +539,72 @@ quoted_print(int pflags, char *name, char *value) > if (qc && pflags & PRINT_QUOTED) > xo_emit("{P:/%c}", qc); > } >+ >+static int >+special_print(int pflags, struct jailparam *param) { >+ >+ int ip_as_list; >+ >+ switch (xo_get_style(NULL)) { >+ case XO_STYLE_JSON: >+ case XO_STYLE_XML: >+ ip_as_list = 1; >+ break; >+ default: >+ ip_as_list = 0; >+ } >+ >+ if (!ip_as_list && param->jp_valuelen == 0) { >+ if (pflags & PRINT_QUOTED) >+ xo_emit("{P:\"\"}"); >+ else if (!(pflags & PRINT_NAMEVAL)) >+ xo_emit("{P:-}"); >+ } else if (ip_as_list && !strcmp(param->jp_name, "ip4.addr")) { >+ xo_open_list("ip4.addr"); >+ emit_ip_addr(AF_INET, param); >+ xo_close_list("ip4.addr"); >+ } else if (ip_as_list && !strcmp(param->jp_name, "ip6.addr")) { >+ xo_open_list("ip6.addr"); >+ emit_ip_addr(AF_INET6, param); >+ xo_close_list("ip6.addr"); >+ } else { >+ return 0; >+ } >+ >+ return 1; >+} >+ >+static void >+emit_ip_addr(int af_family, struct jailparam *param) { >+ char ipbuf[INET6_ADDRSTRLEN]; >+ size_t addr_len; >+ const char *emit_str; >+ int count, ai; >+ >+ switch (af_family) { >+ case AF_INET: >+ addr_len = sizeof(struct in_addr); >+ emit_str = "{P: }{ql:ipv4_addr}{P:\n}"; >+ break; >+ case AF_INET6: >+ addr_len = sizeof(struct in6_addr); >+ emit_str = "{P: }{ql:ipv6_addr}{P:\n}"; >+ break; >+ default: >+ xo_err(1, "unsupported af_family"); >+ return; >+ } >+ >+ count = param->jp_valuelen / addr_len; >+ >+ for (ai = 0; ai < count; ai++) { >+ if (inet_ntop(af_family, >+ ((uint8_t*)param->jp_value) + addr_len*ai, >+ ipbuf, sizeof(ipbuf)) == NULL) { >+ xo_err(1, "inet_ntop"); >+ } else { >+ xo_emit(emit_str, ipbuf); >+ } >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 215008
:
177607
| 177639