bridge: monitor: add support for vlan monitoring

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>
This commit is contained in:
Nikolay Aleksandrov 2021-04-18 15:01:37 +03:00 committed by David Ahern
parent e5f87c8341
commit c311404780
5 changed files with 35 additions and 7 deletions

View File

@ -12,7 +12,7 @@ int print_mdb_mon(struct nlmsghdr *n, void *arg);
int print_fdb(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg);
void print_stp_state(__u8 state); void print_stp_state(__u8 state);
int parse_stp_state(const char *arg); 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_fdb(int argc, char **argv);
int do_mdb(int argc, char **argv); int do_mdb(int argc, char **argv);

View File

@ -16,9 +16,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "libnetlink.h" #include "libnetlink.h"
#include "utils.h"
#include "br_common.h" #include "br_common.h"
#include "rt_names.h" #include "rt_names.h"
#include "utils.h"
#include "json_print.h" #include "json_print.h"
#ifndef MDBA_RTA #ifndef MDBA_RTA

View File

@ -31,7 +31,7 @@ static int prefix_banner;
static void usage(void) 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); exit(-1);
} }
@ -67,6 +67,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
print_nlmsg_timestamp(fp, n); print_nlmsg_timestamp(fp, n);
return 0; return 0;
case RTM_NEWVLAN:
case RTM_DELVLAN:
if (prefix_banner)
fprintf(fp, "[VLAN]");
return print_vlan_rtm(n, arg, true);
default: default:
return 0; return 0;
} }
@ -79,6 +85,7 @@ int do_monitor(int argc, char **argv)
int llink = 0; int llink = 0;
int lneigh = 0; int lneigh = 0;
int lmdb = 0; int lmdb = 0;
int lvlan = 0;
rtnl_close(&rth); rtnl_close(&rth);
@ -95,8 +102,12 @@ int do_monitor(int argc, char **argv)
} else if (matches(*argv, "mdb") == 0) { } else if (matches(*argv, "mdb") == 0) {
lmdb = 1; lmdb = 1;
groups = 0; groups = 0;
} else if (matches(*argv, "vlan") == 0) {
lvlan = 1;
groups = 0;
} else if (strcmp(*argv, "all") == 0) { } else if (strcmp(*argv, "all") == 0) {
groups = ~RTMGRP_TC; groups = ~RTMGRP_TC;
lvlan = 1;
prefix_banner = 1; prefix_banner = 1;
} else if (matches(*argv, "help") == 0) { } else if (matches(*argv, "help") == 0) {
usage(); usage();
@ -134,6 +145,12 @@ int do_monitor(int argc, char **argv)
if (rtnl_open(&rth, groups) < 0) if (rtnl_open(&rth, groups) < 0)
exit(1); 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); ll_init_map(&rth);
if (rtnl_listen(&rth, accept_msg, stdout) < 0) if (rtnl_listen(&rth, accept_msg, stdout) < 0)

View File

@ -621,7 +621,7 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg)
return 0; 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 rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *a;
struct br_vlan_msg *bvm = NLMSG_DATA(n); 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) if (filter_index && filter_index != bvm->ifindex)
return 0; 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 || vlan_rtm_cur_ifidx != bvm->ifindex) {
if (vlan_rtm_cur_ifidx != -1) if (vlan_rtm_cur_ifidx != -1)
close_vlan_port(); close_vlan_port();
@ -720,6 +726,11 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg)
return 0; 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) static int vlan_show(int argc, char **argv, int subject)
{ {
char *filter_dev = NULL; char *filter_dev = NULL;
@ -764,7 +775,7 @@ static int vlan_show(int argc, char **argv, int subject)
printf("\n"); printf("\n");
} }
ret = rtnl_dump_filter(&rth, print_vlan_rtm, &subject); ret = rtnl_dump_filter(&rth, print_vlan_rtm_filter, &subject);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Dump terminated\n"); fprintf(stderr, "Dump terminated\n");
exit(1); exit(1);

View File

@ -153,7 +153,7 @@ bridge \- show / manipulate bridge addresses and devices
.IR DEV " ]" .IR DEV " ]"
.ti -8 .ti -8
.BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " ]" .BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " | " vlan " ]"
.SH OPTIONS .SH OPTIONS
@ -911,7 +911,7 @@ command is the first in the command line and then the object list follows:
.I OBJECT-LIST .I OBJECT-LIST
is the list of object types that we want to monitor. is the list of object types that we want to monitor.
It may contain It may contain
.BR link ", " fdb ", and " mdb "." .BR link ", " fdb ", " vlan " and " mdb "."
If no If no
.B file .B file
argument is given, argument is given,