bridge: minor change to mdb print
Subsystems (2)
PATCH 1/3 bridge: minor change to mdb print
Get port ifname once rather than on both sides of if(is_json_context).
--- bridge/mdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
bridge/mdb.c +3 -3
@@ -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 );
Signature · 1 line
2.17.1
PATCH 2/3 bridge: use print_json for some outputs
Rather than using is_json_context(), use the print_string functions which handle both cases.
--- bridge/mdb.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
bridge/mdb.c +2 -9
@@ -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));
Signature · 1 line
2.17.1
PATCH 3/3 bridge: fix vlan show formatting
In reply to Stephen HemmingerThe 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).
--- bridge/br_common.h | 2 +- bridge/link.c | 6 ++--- bridge/vlan.c | 61 +++++++++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 29 deletions(-)
bridge/br_common.h +1 -1
@@ -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);
bridge/link.c +3 -3
@@ -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 ();
bridge/vlan.c +36 -25
141 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH iproute2 3/3] bridge: fix vlan show formatting
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
Quoted 19 lines · 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 <[email protected]>--- bridge/br_common.h | 2 +- bridge/link.c | 6 ++--- bridge/vlan.c | 61 +++++++++++++++++++++++++++----------------- -- 3 files changed, 40 insertions(+), 29 deletions(-)bridge/br_common.h +0
-0
bridge/br_common.h line 10
Quoted 6 lines
bridge/br_common.h +1
-1@@ -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.
Quoted 204 lines
bridge/br_common.h +0
-0extern int print_linkinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,bridge/br_common.h +0
-0void *arg);bridge/link.c +2
-2@@ -161,7 +161,7 @@ static void print_protinfo(FILE *fp, structrtattr *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,bridge/link.c +1
-1@@ -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 ();bridge/vlan.c +10
-2@@ -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)bridge/vlan.c +1
-1@@ -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))
{bridge/vlan.c +7
-5@@ -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,bridge/vlan.c +2
-2@@ -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);bridge/vlan.c +7
-2return 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)bridge/vlan.c +1
-0@@ -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;bridge/vlan.c +4
-5parse_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)) {bridge/vlan.c +0
-1const 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 ();}
bridge/vlan.c +2
-5@@ -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)) {bridge/vlan.c +2
-2struct 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)