bridge: vlan: fix standard stats output

Each of the commits below broke the vlan stats output in a different
way:
- 45fca4ed94 ("bridge: fix vlan show stats formatting")
 Added a second print of an interface name (e.g. eth4eth4)
- c7c1a1ef51 ("bridge: colorize output and use JSON print library")
 Broke normal vlan stats output by not printing a new line after them
 Also printed interfaces without any vlans when printing stats

This fix is not pretty but it brings back the previous behaviour.

Before this fix:
$ bridge -s vlan show
port             vlan id
br0br0              1 PVID Egress Untagged
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packets 4
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packetseth4eth4             4
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packetsroot@debian:~/

After this fix:
$ bridge -s vlan show
port             vlan id
br0              1 PVID Egress Untagged
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packets
                 4
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packets
eth4             4
                   RX: 0 bytes 0 packets
                   TX: 0 bytes 0 packets

Fixes: 45fca4ed94 ("bridge: fix vlan show stats formatting")
Fixes: c7c1a1ef51 ("bridge: colorize output and use JSON print library")
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Nikolay Aleksandrov 2019-04-16 18:30:12 +03:00 committed by Stephen Hemminger
parent b11b495e7c
commit 6e982e7b9b
1 changed files with 19 additions and 15 deletions

View File

@ -252,11 +252,11 @@ static int filter_vlan_check(__u16 vid, __u16 flags)
return 1;
}
static void open_vlan_port(int ifi_index)
static void open_vlan_port(int ifi_index, const char *fmt)
{
open_json_object(NULL);
print_string(PRINT_ANY, "ifname", "%s",
ll_index_to_name(ifi_index));
print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt,
ll_index_to_name(ifi_index));
open_json_array(PRINT_JSON, "vlans");
}
@ -286,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
__u32 last_tunid_start = 0;
if (!filter_vlan)
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
open_json_array(PRINT_JSON, "tunnel");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
@ -331,7 +331,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex)
continue;
if (filter_vlan)
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
open_json_object(NULL);
print_range("vlan", last_vid_start, tunnel_vid);
@ -463,7 +463,7 @@ static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats)
print_lluint(PRINT_ANY, "tx_bytes",
" TX: %llu bytes",
vstats->tx_bytes);
print_lluint(PRINT_ANY, "tx_packets", " %llu packets",
print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n",
vstats->tx_packets);
close_json_object();
}
@ -472,7 +472,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;
bool found_vlan = false;
int rem;
parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr),
@ -483,12 +483,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
list = brtb[LINK_XSTATS_TYPE_BRIDGE];
rem = RTA_PAYLOAD(list);
ifname = ll_index_to_name(ifindex);
open_vlan_port(ifindex);
print_color_string(PRINT_FP, COLOR_IFNAME,
NULL, "%-16s", ifname);
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
const struct bridge_vlan_xstats *vstats = RTA_DATA(i);
@ -503,9 +497,19 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex)
!(vstats->flags & BRIDGE_VLAN_INFO_BRENTRY))
continue;
/* found vlan stats, first time print the interface name */
if (!found_vlan) {
open_vlan_port(ifindex, "%-16s");
found_vlan = true;
} else {
print_string(PRINT_FP, NULL, "%-16s", "");
}
print_one_vlan_stats(vstats);
}
close_vlan_port();
/* vlan_port is opened only if there are any vlan stats */
if (found_vlan)
close_vlan_port();
}
static int print_vlan_stats(struct nlmsghdr *n, void *arg)
@ -632,7 +636,7 @@ void print_vlan_info(struct rtattr *tb, int ifindex)
int rem = RTA_PAYLOAD(list);
__u16 last_vid_start = 0;
open_vlan_port(ifindex);
open_vlan_port(ifindex, "%s");
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo;