From: Nikolay Aleksandrov <niko...@nvidia.com>

Add support for vlan activity monitoring, we display vlan notifications on
vlan add/del/options change. The man page and help are also updated
accordingly.

Signed-off-by: Nikolay Aleksandrov <niko...@nvidia.com>
---
 bridge/br_common.h |  2 +-
 bridge/mdb.c       |  2 +-
 bridge/monitor.c   | 19 ++++++++++++++++++-
 bridge/vlan.c      | 15 +++++++++++++--
 man/man8/bridge.8  |  4 ++--
 5 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/bridge/br_common.h b/bridge/br_common.h
index 43870546ff28..b9adafd98dea 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -12,7 +12,7 @@ int print_mdb_mon(struct nlmsghdr *n, void *arg);
 int print_fdb(struct nlmsghdr *n, void *arg);
 void print_stp_state(__u8 state);
 int parse_stp_state(const char *arg);
-int print_vlan_rtm(struct nlmsghdr *n, void *arg);
+int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor);
 
 int do_fdb(int argc, char **argv);
 int do_mdb(int argc, char **argv);
diff --git a/bridge/mdb.c b/bridge/mdb.c
index ef89258bc5c3..b427d878677f 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -16,9 +16,9 @@
 #include <arpa/inet.h>
 
 #include "libnetlink.h"
+#include "utils.h"
 #include "br_common.h"
 #include "rt_names.h"
-#include "utils.h"
 #include "json_print.h"
 
 #ifndef MDBA_RTA
diff --git a/bridge/monitor.c b/bridge/monitor.c
index 08439a60288a..88f52f52f084 100644
--- a/bridge/monitor.c
+++ b/bridge/monitor.c
@@ -31,7 +31,7 @@ static int prefix_banner;
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: bridge monitor [file | link | fdb | mdb | 
all]\n");
+       fprintf(stderr, "Usage: bridge monitor [file | link | fdb | mdb | vlan 
| all]\n");
        exit(-1);
 }
 
@@ -67,6 +67,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
                print_nlmsg_timestamp(fp, n);
                return 0;
 
+       case RTM_NEWVLAN:
+       case RTM_DELVLAN:
+               if (prefix_banner)
+                       fprintf(fp, "[VLAN]");
+               return print_vlan_rtm(n, arg, true);
+
        default:
                return 0;
        }
@@ -79,6 +85,7 @@ int do_monitor(int argc, char **argv)
        int llink = 0;
        int lneigh = 0;
        int lmdb = 0;
+       int lvlan = 0;
 
        rtnl_close(&rth);
 
@@ -95,8 +102,12 @@ int do_monitor(int argc, char **argv)
                } else if (matches(*argv, "mdb") == 0) {
                        lmdb = 1;
                        groups = 0;
+               } else if (matches(*argv, "vlan") == 0) {
+                       lvlan = 1;
+                       groups = 0;
                } else if (strcmp(*argv, "all") == 0) {
                        groups = ~RTMGRP_TC;
+                       lvlan = 1;
                        prefix_banner = 1;
                } else if (matches(*argv, "help") == 0) {
                        usage();
@@ -134,6 +145,12 @@ int do_monitor(int argc, char **argv)
 
        if (rtnl_open(&rth, groups) < 0)
                exit(1);
+
+       if (lvlan && rtnl_add_nl_group(&rth, RTNLGRP_BRVLAN) < 0) {
+               fprintf(stderr, "Failed to add bridge vlan group to list\n");
+               exit(1);
+       }
+
        ll_init_map(&rth);
 
        if (rtnl_listen(&rth, accept_msg, stdout) < 0)
diff --git a/bridge/vlan.c b/bridge/vlan.c
index c681e14189b8..9bb9e28d11bb 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -621,7 +621,7 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg)
        return 0;
 }
 
-int print_vlan_rtm(struct nlmsghdr *n, void *arg)
+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);
@@ -648,6 +648,12 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg)
        if (filter_index && filter_index != bvm->ifindex)
                return 0;
 
+       if (n->nlmsg_type == RTM_DELVLAN)
+               print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+
+       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();
@@ -720,6 +726,11 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg)
        return 0;
 }
 
+static int print_vlan_rtm_filter(struct nlmsghdr *n, void *arg)
+{
+       return print_vlan_rtm(n, arg, false);
+}
+
 static int vlan_show(int argc, char **argv, int subject)
 {
        char *filter_dev = NULL;
@@ -764,7 +775,7 @@ static int vlan_show(int argc, char **argv, int subject)
                        printf("\n");
                }
 
-               ret = rtnl_dump_filter(&rth, print_vlan_rtm, &subject);
+               ret = rtnl_dump_filter(&rth, print_vlan_rtm_filter, &subject);
                if (ret < 0) {
                        fprintf(stderr, "Dump terminated\n");
                        exit(1);
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 9c8ebac3c6aa..eec7df4383bc 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -153,7 +153,7 @@ bridge \- show / manipulate bridge addresses and devices
 .IR DEV " ]"
 
 .ti -8
-.BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " ]"
+.BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " | " vlan " ]"
 
 .SH OPTIONS
 
@@ -911,7 +911,7 @@ command is the first in the command line and then the 
object list follows:
 .I OBJECT-LIST
 is the list of object types that we want to monitor.
 It may contain
-.BR link ", " fdb ", and " mdb "."
+.BR link ", " fdb ", " vlan " and " mdb "."
 If no
 .B file
 argument is given,
-- 
2.30.2

Reply via email to