]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: vlan: dump port only if there are any vlans
authorNikolay Aleksandrov <nikolay@nvidia.com>
Fri, 23 Apr 2021 12:10:18 +0000 (15:10 +0300)
committerDavid Ahern <dsahern@kernel.org>
Mon, 26 Apr 2021 02:32:46 +0000 (02:32 +0000)
When I added support for new vlan rtm dumping, I made a mistake in the
output format when there are no vlans on the port. This patch fixes it by
not printing ports without vlan entries (similar to current situation).

Example (no vlans):
$ bridge -d vlan show
port              vlan-id

Fixes: e5f87c834193 ("bridge: vlan: add support for the new rtm dump call")
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/vlan.c

index 9bb9e28d11bbf6a95358a8d95ff825c79ac8f44d..9b6511f189ff14c985647b81f2e30741a1c3675b 100644 (file)
@@ -626,7 +626,6 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor)
        struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *a;
        struct br_vlan_msg *bvm = NLMSG_DATA(n);
        int len = n->nlmsg_len;
-       bool newport = false;
        int rem;
 
        if (n->nlmsg_type != RTM_NEWVLAN && n->nlmsg_type != RTM_DELVLAN &&
@@ -654,12 +653,9 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor)
        if (monitor)
                vlan_rtm_cur_ifidx = -1;
 
-       if (vlan_rtm_cur_ifidx == -1 || vlan_rtm_cur_ifidx != bvm->ifindex) {
-               if (vlan_rtm_cur_ifidx != -1)
-                       close_vlan_port();
-               open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN);
-               vlan_rtm_cur_ifidx = bvm->ifindex;
-               newport = true;
+       if (vlan_rtm_cur_ifidx != -1 && vlan_rtm_cur_ifidx != bvm->ifindex) {
+               close_vlan_port();
+               vlan_rtm_cur_ifidx = -1;
        }
 
        rem = len;
@@ -707,11 +703,14 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor)
                                vstats.tx_bytes = rta_getattr_u64(attr);
                        }
                }
-               open_json_object(NULL);
-               if (!newport)
+               if (vlan_rtm_cur_ifidx != bvm->ifindex) {
+                       open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN);
+                       open_json_object(NULL);
+                       vlan_rtm_cur_ifidx = bvm->ifindex;
+               } else {
+                       open_json_object(NULL);
                        print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s  ", "");
-               else
-                       newport = false;
+               }
                print_range("vlan", vinfo->vid, vrange);
                print_vlan_flags(vinfo->flags);
                print_nl();