]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: monitor: add support for vlan monitoring
authorNikolay Aleksandrov <nikolay@nvidia.com>
Sun, 18 Apr 2021 12:01:37 +0000 (15:01 +0300)
committerDavid Ahern <dsahern@kernel.org>
Thu, 22 Apr 2021 05:13:39 +0000 (05:13 +0000)
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 <nikolay@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/br_common.h
bridge/mdb.c
bridge/monitor.c
bridge/vlan.c
man/man8/bridge.8

index 43870546ff284999b28457f9c246e33fb18ce1a6..b9adafd98deaf06a9aad8640a38f45344f0b5a2b 100644 (file)
@@ -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);
index ef89258bc5c39037f84b49d2550afb86403a0506..b427d878677f5084850e0f30875e8793c19a2710 100644 (file)
@@ -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
index 08439a60288a93ce78227677b948e548817b390d..88f52f52f0840fa20d71486e48ef96848051194e 100644 (file)
@@ -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)
index c681e14189b8afeabd7ba1159711cb8de8cdf517..9bb9e28d11bbf6a95358a8d95ff825c79ac8f44d 100644 (file)
@@ -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);
index 9c8ebac3c6aa754820047cc828294b13bba3ffec..eec7df4383bc96e1eca50bac0089058f333f2a8e 100644 (file)
@@ -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,