* [PATCH iproute2 1/3] bridge: minor change to mdb print @ 2018-09-06 15:30 Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 2/3] bridge: use print_json for some outputs Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 3/3] bridge: fix vlan show formatting Stephen Hemminger 0 siblings, 2 replies; 4+ messages in thread From: Stephen Hemminger @ 2018-09-06 15:30 UTC (permalink / raw) To: netdev; +Cc: Stephen Hemminger Get port ifname once rather than on both sides of if(is_json_context). Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- bridge/mdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridge/mdb.c b/bridge/mdb.c index f38dc67c849a..9bdef0262c54 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -208,19 +208,19 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n, } else { struct rtattr *i = RTA_DATA(router); uint32_t *port_ifindex = RTA_DATA(i); + const char *port_name = ll_index_to_name(*port_ifindex); if (is_json_context()) { open_json_array(PRINT_JSON, brifname); open_json_object(NULL); print_string(PRINT_JSON, "port", NULL, - ll_index_to_name(*port_ifindex)); + port_name); close_json_object(); close_json_array(PRINT_JSON, NULL); } else { fprintf(fp, "router port dev %s master %s\n", - ll_index_to_name(*port_ifindex), - brifname); + port_name, brifname); } } close_json_array(PRINT_JSON, NULL); -- 2.17.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH iproute2 2/3] bridge: use print_json for some outputs 2018-09-06 15:30 [PATCH iproute2 1/3] bridge: minor change to mdb print Stephen Hemminger @ 2018-09-06 15:30 ` Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 3/3] bridge: fix vlan show formatting Stephen Hemminger 1 sibling, 0 replies; 4+ messages in thread From: Stephen Hemminger @ 2018-09-06 15:30 UTC (permalink / raw) To: netdev; +Cc: Stephen Hemminger Rather than using is_json_context(), use the print_string functions which handle both cases. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- bridge/mdb.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/bridge/mdb.c b/bridge/mdb.c index 9bdef0262c54..cc1b4547865c 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -131,15 +131,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e, if (n->nlmsg_type == RTM_DELMDB) print_bool(PRINT_ANY, "deleted", "Deleted ", true); - - if (is_json_context()) { - print_int(PRINT_JSON, "index", NULL, ifindex); - print_string(PRINT_JSON, "dev", NULL, dev); - } else { - fprintf(f, "%u: ", ifindex); - color_fprintf(f, COLOR_IFNAME, "%s ", dev); - } - + print_int(PRINT_ANY, "index", "%u: ", ifindex); + print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s ", dev); print_string(PRINT_ANY, "port", " %s ", ll_index_to_name(e->ifindex)); -- 2.17.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH iproute2 3/3] bridge: fix vlan show formatting 2018-09-06 15:30 [PATCH iproute2 1/3] bridge: minor change to mdb print Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 2/3] bridge: use print_json for some outputs Stephen Hemminger @ 2018-09-06 15:30 ` Stephen Hemminger 2018-09-10 11:52 ` Tobias Jungel 1 sibling, 1 reply; 4+ messages in thread From: Stephen Hemminger @ 2018-09-06 15:30 UTC (permalink / raw) To: netdev; +Cc: Stephen Hemminger The output of vlan show was broken previous change to use json_print. Clean the code up and return to original format. Note: the JSON syntax has changed to make the bridge vlan show more like other outputs (e.g. ip -j li show). Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- bridge/br_common.h | 2 +- bridge/link.c | 6 ++--- bridge/vlan.c | 61 +++++++++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index 2f1cb8fd9f3d..69665fde32b6 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -6,7 +6,7 @@ #define MDB_RTR_RTA(r) \ ((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32)))) -extern void print_vlan_info(FILE *fp, struct rtattr *tb); +extern void print_vlan_info(struct rtattr *tb, int ifindex); extern int print_linkinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); diff --git a/bridge/link.c b/bridge/link.c index 8d89aca2e638..a5ee9a5c58e6 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -161,7 +161,7 @@ static void print_protinfo(FILE *fp, struct rtattr *attr) * This is reported by HW devices that have some bridging * capabilities. */ -static void print_af_spec(FILE *fp, struct rtattr *attr) +static void print_af_spec(struct rtattr *attr, int ifindex) { struct rtattr *aftb[IFLA_BRIDGE_MAX+1]; @@ -174,7 +174,7 @@ static void print_af_spec(FILE *fp, struct rtattr *attr) return; if (aftb[IFLA_BRIDGE_VLAN_INFO]) - print_vlan_info(fp, aftb[IFLA_BRIDGE_VLAN_INFO]); + print_vlan_info(aftb[IFLA_BRIDGE_VLAN_INFO], ifindex); } int print_linkinfo(const struct sockaddr_nl *who, @@ -229,7 +229,7 @@ int print_linkinfo(const struct sockaddr_nl *who, print_protinfo(fp, tb[IFLA_PROTINFO]); if (tb[IFLA_AF_SPEC]) - print_af_spec(fp, tb[IFLA_AF_SPEC]); + print_af_spec(tb[IFLA_AF_SPEC], ifi->ifi_index); print_string(PRINT_FP, NULL, "%s", "\n"); close_json_object(); diff --git a/bridge/vlan.c b/bridge/vlan.c index 19a36b804069..bdce55ae4e14 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -252,10 +252,18 @@ static int filter_vlan_check(__u16 vid, __u16 flags) return 1; } -static void print_vlan_port(FILE *fp, int ifi_index) +static void open_vlan_port(int ifi_index) { - print_string(PRINT_ANY, NULL, "%s", + open_json_object(NULL); + print_string(PRINT_ANY, "ifname", "%s", ll_index_to_name(ifi_index)); + open_json_array(PRINT_JSON, "vlans"); +} + +static void close_vlan_port(void) +{ + close_json_array(PRINT_JSON, NULL); + close_json_object(); } static void print_range(const char *name, __u16 start, __u16 id) @@ -278,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) __u32 last_tunid_start = 0; if (!filter_vlan) - print_vlan_port(fp, ifindex); + open_vlan_port(ifindex); open_json_array(PRINT_JSON, "tunnel"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { @@ -323,18 +331,20 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) continue; if (filter_vlan) - print_vlan_port(fp, ifindex); + open_vlan_port(ifindex); open_json_object(NULL); print_range("vlan", last_vid_start, tunnel_vid); print_range("tunid", last_tunid_start, tunnel_id); close_json_object(); - if (!is_json_context()) - fprintf(fp, "\n"); - + print_string(PRINT_FP, NULL, "%s", _SL_); + if (filter_vlan) + close_vlan_port(); } - close_json_array(PRINT_JSON, NULL); + + if (!filter_vlan) + close_vlan_port(); } static int print_vlan_tunnel(const struct sockaddr_nl *who, @@ -421,8 +431,8 @@ static int print_vlan(const struct sockaddr_nl *who, return 0; } - print_vlan_port(fp, ifm->ifi_index); - print_vlan_info(fp, tb[IFLA_AF_SPEC]); + print_vlan_info(tb[IFLA_AF_SPEC], ifm->ifi_index); + print_string(PRINT_FP, NULL, "%s", _SL_); fflush(fp); return 0; @@ -430,11 +440,16 @@ static int print_vlan(const struct sockaddr_nl *who, static void print_vlan_flags(__u16 flags) { + if (flags == 0) + return; + + open_json_array(PRINT_JSON, "flags"); if (flags & BRIDGE_VLAN_INFO_PVID) - print_null(PRINT_ANY, "pvid", " %s", "PVID"); + print_string(PRINT_ANY, NULL, " %s", "PVID"); if (flags & BRIDGE_VLAN_INFO_UNTAGGED) - print_null(PRINT_ANY, "untagged", " %s", "untagged"); + print_string(PRINT_ANY, NULL, " %s", "Egress Untagged"); + close_json_array(PRINT_JSON, NULL); } static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) @@ -461,6 +476,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) { struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1]; struct rtattr *i, *list; + const char *ifname; int rem; parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr), @@ -471,13 +487,12 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) list = brtb[LINK_XSTATS_TYPE_BRIDGE]; rem = RTA_PAYLOAD(list); - open_json_object(NULL); + ifname = ll_index_to_name(ifindex); + open_json_object(ifname); - print_color_string(PRINT_ANY, COLOR_IFNAME, - "dev", "%-16s", - ll_index_to_name(ifindex)); + print_color_string(PRINT_FP, COLOR_IFNAME, + NULL, "%-16s", ifname); - open_json_array(PRINT_JSON, "xstats"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { const struct bridge_vlan_xstats *vstats = RTA_DATA(i); @@ -494,7 +509,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) print_one_vlan_stats(vstats); } - close_json_array(PRINT_ANY, "\n"); close_json_object(); } @@ -623,16 +637,13 @@ static int vlan_show(int argc, char **argv) return 0; } -void print_vlan_info(FILE *fp, struct rtattr *tb) +void print_vlan_info(struct rtattr *tb, int ifindex) { struct rtattr *i, *list = tb; int rem = RTA_PAYLOAD(list); __u16 last_vid_start = 0; - if (!is_json_context()) - fprintf(fp, "%s", _SL_); - - open_json_array(PRINT_JSON, "vlan"); + open_vlan_port(ifindex); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { struct bridge_vlan_info *vinfo; @@ -656,9 +667,9 @@ void print_vlan_info(FILE *fp, struct rtattr *tb) print_vlan_flags(vinfo->flags); close_json_object(); + print_string(PRINT_FP, NULL, "%s", _SL_); } - - close_json_array(PRINT_ANY, "\n"); + close_vlan_port(); } int do_vlan(int argc, char **argv) -- 2.17.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2 3/3] bridge: fix vlan show formatting 2018-09-06 15:30 ` [PATCH iproute2 3/3] bridge: fix vlan show formatting Stephen Hemminger @ 2018-09-10 11:52 ` Tobias Jungel 0 siblings, 0 replies; 4+ messages in thread From: Tobias Jungel @ 2018-09-10 11:52 UTC (permalink / raw) To: Stephen Hemminger, netdev Hi Stephen, I just have seen this patch, hence please ignore the "bridge: Correct json output" I sent. This one solves the issue in a way more elegant manor. I tested the JSON output in this series and it works as intended. Thanks Reviewed-by: Tobias Jungel <tobias.jungel@bisdn.de> On Thu, 2018-09-06 at 16:30 +0100, Stephen Hemminger wrote: > The output of vlan show was broken previous change to use json_print. > Clean the code up and return to original format. > > Note: the JSON syntax has changed to make the bridge vlan > show more like other outputs (e.g. ip -j li show). > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > bridge/br_common.h | 2 +- > bridge/link.c | 6 ++--- > bridge/vlan.c | 61 +++++++++++++++++++++++++++----------------- > -- > 3 files changed, 40 insertions(+), 29 deletions(-) > > diff --git a/bridge/br_common.h b/bridge/br_common.h > index 2f1cb8fd9f3d..69665fde32b6 100644 > --- a/bridge/br_common.h > +++ b/bridge/br_common.h > @@ -6,7 +6,7 @@ > #define MDB_RTR_RTA(r) \ > ((struct rtattr *)(((char *)(r)) + > RTA_ALIGN(sizeof(__u32)))) > > -extern void print_vlan_info(FILE *fp, struct rtattr *tb); > +extern void print_vlan_info(struct rtattr *tb, int ifindex); nitpick, this does not apply to master. > extern int print_linkinfo(const struct sockaddr_nl *who, > struct nlmsghdr *n, > void *arg); > diff --git a/bridge/link.c b/bridge/link.c > index 8d89aca2e638..a5ee9a5c58e6 100644 > --- a/bridge/link.c > +++ b/bridge/link.c > @@ -161,7 +161,7 @@ static void print_protinfo(FILE *fp, struct > rtattr *attr) > * This is reported by HW devices that have some bridging > * capabilities. > */ > -static void print_af_spec(FILE *fp, struct rtattr *attr) > +static void print_af_spec(struct rtattr *attr, int ifindex) > { > struct rtattr *aftb[IFLA_BRIDGE_MAX+1]; > > @@ -174,7 +174,7 @@ static void print_af_spec(FILE *fp, struct rtattr > *attr) > return; > > if (aftb[IFLA_BRIDGE_VLAN_INFO]) > - print_vlan_info(fp, aftb[IFLA_BRIDGE_VLAN_INFO]); > + print_vlan_info(aftb[IFLA_BRIDGE_VLAN_INFO], ifindex); > } > > int print_linkinfo(const struct sockaddr_nl *who, > @@ -229,7 +229,7 @@ int print_linkinfo(const struct sockaddr_nl *who, > print_protinfo(fp, tb[IFLA_PROTINFO]); > > if (tb[IFLA_AF_SPEC]) > - print_af_spec(fp, tb[IFLA_AF_SPEC]); > + print_af_spec(tb[IFLA_AF_SPEC], ifi->ifi_index); > > print_string(PRINT_FP, NULL, "%s", "\n"); > close_json_object(); > diff --git a/bridge/vlan.c b/bridge/vlan.c > index 19a36b804069..bdce55ae4e14 100644 > --- a/bridge/vlan.c > +++ b/bridge/vlan.c > @@ -252,10 +252,18 @@ static int filter_vlan_check(__u16 vid, __u16 > flags) > return 1; > } > > -static void print_vlan_port(FILE *fp, int ifi_index) > +static void open_vlan_port(int ifi_index) > { > - print_string(PRINT_ANY, NULL, "%s", > + open_json_object(NULL); > + print_string(PRINT_ANY, "ifname", "%s", > ll_index_to_name(ifi_index)); > + open_json_array(PRINT_JSON, "vlans"); > +} > + > +static void close_vlan_port(void) > +{ > + close_json_array(PRINT_JSON, NULL); > + close_json_object(); > } > > static void print_range(const char *name, __u16 start, __u16 id) > @@ -278,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, > struct rtattr *tb, int ifindex) > __u32 last_tunid_start = 0; > > if (!filter_vlan) > - print_vlan_port(fp, ifindex); > + open_vlan_port(ifindex); > > open_json_array(PRINT_JSON, "tunnel"); > for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) > { > @@ -323,18 +331,20 @@ static void print_vlan_tunnel_info(FILE *fp, > struct rtattr *tb, int ifindex) > continue; > > if (filter_vlan) > - print_vlan_port(fp, ifindex); > + open_vlan_port(ifindex); > > open_json_object(NULL); > print_range("vlan", last_vid_start, tunnel_vid); > print_range("tunid", last_tunid_start, tunnel_id); > close_json_object(); > > - if (!is_json_context()) > - fprintf(fp, "\n"); > - > + print_string(PRINT_FP, NULL, "%s", _SL_); > + if (filter_vlan) > + close_vlan_port(); > } > - close_json_array(PRINT_JSON, NULL); > + > + if (!filter_vlan) > + close_vlan_port(); > } > > static int print_vlan_tunnel(const struct sockaddr_nl *who, > @@ -421,8 +431,8 @@ static int print_vlan(const struct sockaddr_nl > *who, > return 0; > } > > - print_vlan_port(fp, ifm->ifi_index); > - print_vlan_info(fp, tb[IFLA_AF_SPEC]); > + print_vlan_info(tb[IFLA_AF_SPEC], ifm->ifi_index); > + print_string(PRINT_FP, NULL, "%s", _SL_); > > fflush(fp); > return 0; > @@ -430,11 +440,16 @@ static int print_vlan(const struct sockaddr_nl > *who, > > static void print_vlan_flags(__u16 flags) > { > + if (flags == 0) > + return; > + > + open_json_array(PRINT_JSON, "flags"); > if (flags & BRIDGE_VLAN_INFO_PVID) > - print_null(PRINT_ANY, "pvid", " %s", "PVID"); > + print_string(PRINT_ANY, NULL, " %s", "PVID"); > > if (flags & BRIDGE_VLAN_INFO_UNTAGGED) > - print_null(PRINT_ANY, "untagged", " %s", "untagged"); > + print_string(PRINT_ANY, NULL, " %s", "Egress > Untagged"); > + close_json_array(PRINT_JSON, NULL); > } > > static void print_one_vlan_stats(const struct bridge_vlan_xstats > *vstats) > @@ -461,6 +476,7 @@ static void print_vlan_stats_attr(struct rtattr > *attr, int ifindex) > { > struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1]; > struct rtattr *i, *list; > + const char *ifname; > int rem; > > parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr), > @@ -471,13 +487,12 @@ static void print_vlan_stats_attr(struct rtattr > *attr, int ifindex) > list = brtb[LINK_XSTATS_TYPE_BRIDGE]; > rem = RTA_PAYLOAD(list); > > - open_json_object(NULL); > + ifname = ll_index_to_name(ifindex); > + open_json_object(ifname); > > - print_color_string(PRINT_ANY, COLOR_IFNAME, > - "dev", "%-16s", > - ll_index_to_name(ifindex)); > + print_color_string(PRINT_FP, COLOR_IFNAME, > + NULL, "%-16s", ifname); > > - open_json_array(PRINT_JSON, "xstats"); > for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) > { > const struct bridge_vlan_xstats *vstats = RTA_DATA(i); > > @@ -494,7 +509,6 @@ static void print_vlan_stats_attr(struct rtattr > *attr, int ifindex) > > print_one_vlan_stats(vstats); > } > - close_json_array(PRINT_ANY, "\n"); > close_json_object(); > > } > @@ -623,16 +637,13 @@ static int vlan_show(int argc, char **argv) > return 0; > } > > -void print_vlan_info(FILE *fp, struct rtattr *tb) > +void print_vlan_info(struct rtattr *tb, int ifindex) > { > struct rtattr *i, *list = tb; > int rem = RTA_PAYLOAD(list); > __u16 last_vid_start = 0; > > - if (!is_json_context()) > - fprintf(fp, "%s", _SL_); > - > - open_json_array(PRINT_JSON, "vlan"); > + open_vlan_port(ifindex); > > for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) > { > struct bridge_vlan_info *vinfo; > @@ -656,9 +667,9 @@ void print_vlan_info(FILE *fp, struct rtattr *tb) > > print_vlan_flags(vinfo->flags); > close_json_object(); > + print_string(PRINT_FP, NULL, "%s", _SL_); > } > - > - close_json_array(PRINT_ANY, "\n"); > + close_vlan_port(); > } > > int do_vlan(int argc, char **argv) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-10 16:45 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-06 15:30 [PATCH iproute2 1/3] bridge: minor change to mdb print Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 2/3] bridge: use print_json for some outputs Stephen Hemminger 2018-09-06 15:30 ` [PATCH iproute2 3/3] bridge: fix vlan show formatting Stephen Hemminger 2018-09-10 11:52 ` Tobias Jungel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox