From d2eecb9d1d4823a04431debd990824a5d610bfcf Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:47 +0300 Subject: [PATCH 01/19] ip: bridge: add support for mcast_vlan_snooping Add support for mcast_vlan_snooping option which controls per-vlan multicast snooping, also update the man page. Syntax: $ ip link set dev bridge type bridge mcast_vlan_snooping 0/1 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- ip/iplink_bridge.c | 29 +++++++++++++++++++++++++++++ man/man8/ip-link.8.in | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index d12fd055..c2e63f6e 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -43,6 +43,7 @@ static void print_explain(FILE *f) " [ vlan_stats_enabled VLAN_STATS_ENABLED ]\n" " [ vlan_stats_per_port VLAN_STATS_PER_PORT ]\n" " [ mcast_snooping MULTICAST_SNOOPING ]\n" + " [ mcast_vlan_snooping MULTICAST_VLAN_SNOOPING ]\n" " [ mcast_router MULTICAST_ROUTER ]\n" " [ mcast_query_use_ifaddr MCAST_QUERY_USE_IFADDR ]\n" " [ mcast_querier MULTICAST_QUERIER ]\n" @@ -83,6 +84,7 @@ void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len) static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { + struct br_boolopt_multi bm = {}; __u32 val; while (argc > 0) { @@ -200,6 +202,18 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, invarg("invalid mcast_snooping", *argv); addattr8(n, 1024, IFLA_BR_MCAST_SNOOPING, mcast_snoop); + } else if (strcmp(*argv, "mcast_vlan_snooping") == 0) { + __u32 mcvl_bit = 1 << BR_BOOLOPT_MCAST_VLAN_SNOOPING; + __u8 mcast_vlan_snooping; + + NEXT_ARG(); + if (get_u8(&mcast_vlan_snooping, *argv, 0)) + invarg("invalid mcast_vlan_snooping", *argv); + bm.optmask |= 1 << BR_BOOLOPT_MCAST_VLAN_SNOOPING; + if (mcast_vlan_snooping) + bm.optval |= mcvl_bit; + else + bm.optval &= ~mcvl_bit; } else if (matches(*argv, "mcast_query_use_ifaddr") == 0) { __u8 mcast_qui; @@ -379,6 +393,9 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, argc--, argv++; } + if (bm.optmask) + addattr_l(n, 1024, IFLA_BR_MULTI_BOOLOPT, + &bm, sizeof(bm)); return 0; } @@ -559,6 +576,18 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) "mcast_snooping %u ", rta_getattr_u8(tb[IFLA_BR_MCAST_SNOOPING])); + if (tb[IFLA_BR_MULTI_BOOLOPT]) { + __u32 mcvl_bit = 1 << BR_BOOLOPT_MCAST_VLAN_SNOOPING; + struct br_boolopt_multi *bm; + + bm = RTA_DATA(tb[IFLA_BR_MULTI_BOOLOPT]); + if (bm->optmask & mcvl_bit) + print_uint(PRINT_ANY, + "mcast_vlan_snooping", + "mcast_vlan_snooping %u ", + !!(bm->optval & mcvl_bit)); + } + if (tb[IFLA_BR_MCAST_ROUTER]) print_uint(PRINT_ANY, "mcast_router", diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 572bed87..2c278d53 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -1492,6 +1492,8 @@ the following additional arguments are supported: ] [ .BI mcast_snooping " MULTICAST_SNOOPING " ] [ +.BI mcast_vlan_snooping " MULTICAST_VLAN_SNOOPING " +] [ .BI mcast_router " MULTICAST_ROUTER " ] [ .BI mcast_query_use_ifaddr " MCAST_QUERY_USE_IFADDR " @@ -1614,6 +1616,12 @@ per-VLAN per-port stats accounting. Can be changed only when there are no port V or off .RI ( MULTICAST_SNOOPING " == 0). " +.BI mcast_vlan_snooping " MULTICAST_VLAN_SNOOPING " +- turn multicast VLAN snooping on +.RI ( MULTICAST_VLAN_SNOOPING " > 0) " +or off +.RI ( MULTICAST_VLAN_SNOOPING " == 0). " + .BI mcast_router " MULTICAST_ROUTER " - set bridge's multicast router if IGMP snooping is enabled. .I MULTICAST_ROUTER From 312e22fe79f9cc4d645e0371ef2ba08dc7647e01 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:48 +0300 Subject: [PATCH 02/19] bridge: vlan: factor out vlan option printing Factor out the code which prints current per-vlan options from print_vlan_rtm without any changes, later we'll filter based on the vlan attribute and add support for global vlan option printing. Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 110 ++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 9b6511f1..b9d92801 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -621,11 +621,67 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } +static void print_vlan_opts(struct rtattr *a) +{ + struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1]; + struct bridge_vlan_xstats vstats; + struct bridge_vlan_info *vinfo; + __u16 vrange = 0; + __u8 state = 0; + + parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a), + RTA_PAYLOAD(a), NLA_F_NESTED); + vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]); + + memset(&vstats, 0, sizeof(vstats)); + if (vtb[BRIDGE_VLANDB_ENTRY_RANGE]) + vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_ENTRY_RANGE]); + else + vrange = vinfo->vid; + + if (vtb[BRIDGE_VLANDB_ENTRY_STATE]) + state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]); + + if (vtb[BRIDGE_VLANDB_ENTRY_STATS]) { + struct rtattr *stb[BRIDGE_VLANDB_STATS_MAX+1]; + struct rtattr *attr; + + attr = vtb[BRIDGE_VLANDB_ENTRY_STATS]; + parse_rtattr(stb, BRIDGE_VLANDB_STATS_MAX, RTA_DATA(attr), + RTA_PAYLOAD(attr)); + + if (stb[BRIDGE_VLANDB_STATS_RX_BYTES]) { + attr = stb[BRIDGE_VLANDB_STATS_RX_BYTES]; + vstats.rx_bytes = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_RX_PACKETS]) { + attr = stb[BRIDGE_VLANDB_STATS_RX_PACKETS]; + vstats.rx_packets = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_TX_PACKETS]) { + attr = stb[BRIDGE_VLANDB_STATS_TX_PACKETS]; + vstats.tx_packets = rta_getattr_u64(attr); + } + if (stb[BRIDGE_VLANDB_STATS_TX_BYTES]) { + attr = stb[BRIDGE_VLANDB_STATS_TX_BYTES]; + vstats.tx_bytes = rta_getattr_u64(attr); + } + } + print_range("vlan", vinfo->vid, vrange); + print_vlan_flags(vinfo->flags); + print_nl(); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_stp_state(state); + print_nl(); + if (show_stats) + __print_one_vlan_stats(&vstats); +} + 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; + struct rtattr *a; int rem; if (n->nlmsg_type != RTM_NEWVLAN && n->nlmsg_type != RTM_DELVLAN && @@ -660,49 +716,6 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) rem = len; for (a = BRVLAN_RTA(bvm); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) { - struct bridge_vlan_xstats vstats; - struct bridge_vlan_info *vinfo; - __u32 vrange = 0; - __u8 state = 0; - - parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a), - RTA_PAYLOAD(a), NLA_F_NESTED); - vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]); - - memset(&vstats, 0, sizeof(vstats)); - if (vtb[BRIDGE_VLANDB_ENTRY_RANGE]) - vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_ENTRY_RANGE]); - else - vrange = vinfo->vid; - - if (vtb[BRIDGE_VLANDB_ENTRY_STATE]) - state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]); - - if (vtb[BRIDGE_VLANDB_ENTRY_STATS]) { - struct rtattr *stb[BRIDGE_VLANDB_STATS_MAX+1]; - struct rtattr *attr; - - attr = vtb[BRIDGE_VLANDB_ENTRY_STATS]; - parse_rtattr(stb, BRIDGE_VLANDB_STATS_MAX, RTA_DATA(attr), - RTA_PAYLOAD(attr)); - - if (stb[BRIDGE_VLANDB_STATS_RX_BYTES]) { - attr = stb[BRIDGE_VLANDB_STATS_RX_BYTES]; - vstats.rx_bytes = rta_getattr_u64(attr); - } - if (stb[BRIDGE_VLANDB_STATS_RX_PACKETS]) { - attr = stb[BRIDGE_VLANDB_STATS_RX_PACKETS]; - vstats.rx_packets = rta_getattr_u64(attr); - } - if (stb[BRIDGE_VLANDB_STATS_TX_PACKETS]) { - attr = stb[BRIDGE_VLANDB_STATS_TX_PACKETS]; - vstats.tx_packets = rta_getattr_u64(attr); - } - if (stb[BRIDGE_VLANDB_STATS_TX_BYTES]) { - attr = stb[BRIDGE_VLANDB_STATS_TX_BYTES]; - vstats.tx_bytes = rta_getattr_u64(attr); - } - } if (vlan_rtm_cur_ifidx != bvm->ifindex) { open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN); open_json_object(NULL); @@ -711,14 +724,7 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) open_json_object(NULL); print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); } - print_range("vlan", vinfo->vid, vrange); - print_vlan_flags(vinfo->flags); - print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); - print_stp_state(state); - print_nl(); - if (show_stats) - __print_one_vlan_stats(&vstats); + print_vlan_opts(a); close_json_object(); } From d3a961a9b16cd9cf4528c30e58032511f5c40917 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:49 +0300 Subject: [PATCH 03/19] bridge: vlan: skip unknown attributes when printing options Skip unknown attributes when printing vlan options in print_vlan_rtm. Make sure print_vlan_opts doesn't accept attributes it doesn't understand. Currently we print only one type, later global vlan options support will be added. Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index b9d92801..7e425428 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -629,6 +629,9 @@ static void print_vlan_opts(struct rtattr *a) __u16 vrange = 0; __u8 state = 0; + if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_ENTRY) + return; + parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a), RTA_PAYLOAD(a), NLA_F_NESTED); vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]); @@ -716,6 +719,12 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) rem = len; for (a = BRVLAN_RTA(bvm); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) { + unsigned short rta_type = a->rta_type & NLA_TYPE_MASK; + + /* skip unknown attributes */ + if (rta_type > BRIDGE_VLANDB_MAX) + continue; + if (vlan_rtm_cur_ifidx != bvm->ifindex) { open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN); open_json_object(NULL); @@ -724,7 +733,11 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) open_json_object(NULL); print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); } - print_vlan_opts(a); + switch (rta_type) { + case BRIDGE_VLANDB_ENTRY: + print_vlan_opts(a); + break; + } close_json_object(); } From 720f8613bd161253fc115b8e93f02a2d5f98c04b Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:50 +0300 Subject: [PATCH 04/19] bridge: vlan: add support to show global vlan options Add support for new bridge vlan command grouping called global which operates on global options. The first command it supports is "show". To do that we update print_vlan_rtm to recognize the global vlan options attribute and parse it properly. Man page and help are also updated with the new command. Syntax is: $ bridge vlan global show [ vid VID ] [ dev DEV ] Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/br_common.h | 3 +- bridge/monitor.c | 2 +- bridge/vlan.c | 110 +++++++++++++++++++++++++++++++++++++++++++-- man/man8/bridge.8 | 21 +++++++++ 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index b9adafd9..09f42c81 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -12,7 +12,8 @@ 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, bool monitor); +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, + bool global_only); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/monitor.c b/bridge/monitor.c index 88f52f52..845e221a 100644 --- a/bridge/monitor.c +++ b/bridge/monitor.c @@ -71,7 +71,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, case RTM_DELVLAN: if (prefix_banner) fprintf(fp, "[VLAN]"); - return print_vlan_rtm(n, arg, true); + return print_vlan_rtm(n, arg, true, false); default: return 0; diff --git a/bridge/vlan.c b/bridge/vlan.c index 7e425428..8a2cc306 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -36,7 +36,8 @@ static void usage(void) " [ self ] [ master ]\n" " bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n" " bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n" - " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n"); + " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" + " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -621,6 +622,25 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } +static void print_vlan_global_opts(struct rtattr *a) +{ + struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1]; + __u16 vid, vrange = 0; + + if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_GLOBAL_OPTIONS) + return; + + parse_rtattr_flags(vtb, BRIDGE_VLANDB_GOPTS_MAX, RTA_DATA(a), + RTA_PAYLOAD(a), NLA_F_NESTED); + vid = rta_getattr_u16(vtb[BRIDGE_VLANDB_GOPTS_ID]); + if (vtb[BRIDGE_VLANDB_GOPTS_RANGE]) + vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_GOPTS_RANGE]); + else + vrange = vid; + print_range("vlan", vid, vrange); + print_nl(); +} + static void print_vlan_opts(struct rtattr *a) { struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1]; @@ -680,7 +700,7 @@ static void print_vlan_opts(struct rtattr *a) __print_one_vlan_stats(&vstats); } -int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only) { struct br_vlan_msg *bvm = NLMSG_DATA(n); int len = n->nlmsg_len; @@ -722,7 +742,8 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) unsigned short rta_type = a->rta_type & NLA_TYPE_MASK; /* skip unknown attributes */ - if (rta_type > BRIDGE_VLANDB_MAX) + if (rta_type > BRIDGE_VLANDB_MAX || + (global_only && rta_type != BRIDGE_VLANDB_GLOBAL_OPTIONS)) continue; if (vlan_rtm_cur_ifidx != bvm->ifindex) { @@ -737,6 +758,9 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) case BRIDGE_VLANDB_ENTRY: print_vlan_opts(a); break; + case BRIDGE_VLANDB_GLOBAL_OPTIONS: + print_vlan_global_opts(a); + break; } close_json_object(); } @@ -746,7 +770,12 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor) static int print_vlan_rtm_filter(struct nlmsghdr *n, void *arg) { - return print_vlan_rtm(n, arg, false); + return print_vlan_rtm(n, arg, false, false); +} + +static int print_vlan_rtm_global_filter(struct nlmsghdr *n, void *arg) +{ + return print_vlan_rtm(n, arg, false, true); } static int vlan_show(int argc, char **argv, int subject) @@ -864,6 +893,61 @@ out: return 0; } +static int vlan_global_show(int argc, char **argv) +{ + __u32 dump_flags = BRIDGE_VLANDB_DUMPF_GLOBAL; + int ret = 0, subject = VLAN_SHOW_VLAN; + char *filter_dev = NULL; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + if (filter_dev) + duparg("dev", *argv); + filter_dev = *argv; + } else if (strcmp(*argv, "vid") == 0) { + NEXT_ARG(); + if (filter_vlan) + duparg("vid", *argv); + filter_vlan = atoi(*argv); + } + argc--; argv++; + } + + if (filter_dev) { + filter_index = ll_name_to_index(filter_dev); + if (!filter_index) + return nodev(filter_dev); + } + + new_json_obj(json); + + if (rtnl_brvlandump_req(&rth, PF_BRIDGE, dump_flags) < 0) { + perror("Cannot send dump request"); + exit(1); + } + + if (!is_json_context()) { + printf("%-" __stringify(IFNAMSIZ) "s %-" + __stringify(VLAN_ID_LEN) "s", "port", + "vlan-id"); + printf("\n"); + } + + ret = rtnl_dump_filter(&rth, print_vlan_rtm_global_filter, &subject); + if (ret < 0) { + fprintf(stderr, "Dump terminated\n"); + exit(1); + } + + if (vlan_rtm_cur_ifidx != -1) + close_vlan_port(); + + delete_json_obj(); + fflush(stdout); + return 0; +} + void print_vlan_info(struct rtattr *tb, int ifindex) { struct rtattr *i, *list = tb; @@ -908,6 +992,22 @@ void print_vlan_info(struct rtattr *tb, int ifindex) close_vlan_port(); } +static int vlan_global(int argc, char **argv) +{ + if (argc > 0) { + if (strcmp(*argv, "show") == 0 || + strcmp(*argv, "lst") == 0 || + strcmp(*argv, "list") == 0) + return vlan_global_show(argc-1, argv+1); + else + usage(); + } else { + return vlan_global_show(0, NULL); + } + + return 0; +} + int do_vlan(int argc, char **argv) { ll_init_map(&rth); @@ -926,6 +1026,8 @@ int do_vlan(int argc, char **argv) } if (matches(*argv, "set") == 0) return vlan_option_set(argc-1, argv+1); + if (strcmp(*argv, "global") == 0) + return vlan_global(argc-1, argv+1); if (matches(*argv, "help") == 0) usage(); } else { diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index eec7df43..9ec4cb1d 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -152,6 +152,13 @@ bridge \- show / manipulate bridge addresses and devices .B dev .IR DEV " ]" +.ti -8 +.BR "bridge vlan global" " [ " show " ] [ " +.B dev +.IR DEV " ] [ " +.B vid +.IR VID " ]" + .ti -8 .BR "bridge monitor" " [ " all " | " neigh " | " link " | " mdb " | " vlan " ]" @@ -895,6 +902,20 @@ option, the command displays per-vlan traffic statistics. This command displays the current vlan tunnel info mapping. +.SS bridge vlan global show - list global vlan options. + +This command displays the global VLAN options for each VLAN entry. + +.TP +.BI dev " DEV" +the interface only whose VLAN global options should be listed. Default is to list +all bridge interfaces. + +.TP +.BI vid " VID" +the VLAN ID only whose global options should be listed. Default is to list +all vlans. + .SH bridge monitor - state monitoring The From ecf6d8b4a1c5532040943620ec035aeec63c3e15 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:51 +0300 Subject: [PATCH 05/19] bridge: vlan: add support for vlan filtering when dumping options In order to allow vlan filtering when dumping options we need to move all print operations into the option dumping functions and add the filtering after we've parsed the nested attributes so we can extract the start and end vlan ids. Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 8a2cc306..77db90d8 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -622,7 +622,7 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } -static void print_vlan_global_opts(struct rtattr *a) +static void print_vlan_global_opts(struct rtattr *a, int ifindex) { struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1]; __u16 vid, vrange = 0; @@ -637,11 +637,24 @@ static void print_vlan_global_opts(struct rtattr *a) vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_GOPTS_RANGE]); else vrange = vid; + + if (filter_vlan && (filter_vlan < vid || filter_vlan > vrange)) + return; + + if (vlan_rtm_cur_ifidx != ifindex) { + open_vlan_port(ifindex, VLAN_SHOW_VLAN); + open_json_object(NULL); + vlan_rtm_cur_ifidx = ifindex; + } else { + open_json_object(NULL); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + } print_range("vlan", vid, vrange); print_nl(); + close_json_object(); } -static void print_vlan_opts(struct rtattr *a) +static void print_vlan_opts(struct rtattr *a, int ifindex) { struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1]; struct bridge_vlan_xstats vstats; @@ -662,6 +675,9 @@ static void print_vlan_opts(struct rtattr *a) else vrange = vinfo->vid; + if (filter_vlan && (filter_vlan < vinfo->vid || filter_vlan > vrange)) + return; + if (vtb[BRIDGE_VLANDB_ENTRY_STATE]) state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]); @@ -690,6 +706,15 @@ static void print_vlan_opts(struct rtattr *a) vstats.tx_bytes = rta_getattr_u64(attr); } } + + if (vlan_rtm_cur_ifidx != ifindex) { + open_vlan_port(ifindex, VLAN_SHOW_VLAN); + open_json_object(NULL); + vlan_rtm_cur_ifidx = ifindex; + } else { + open_json_object(NULL); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + } print_range("vlan", vinfo->vid, vrange); print_vlan_flags(vinfo->flags); print_nl(); @@ -698,6 +723,7 @@ static void print_vlan_opts(struct rtattr *a) print_nl(); if (show_stats) __print_one_vlan_stats(&vstats); + close_json_object(); } int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only) @@ -746,23 +772,14 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only (global_only && rta_type != BRIDGE_VLANDB_GLOBAL_OPTIONS)) continue; - 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 ", ""); - } switch (rta_type) { case BRIDGE_VLANDB_ENTRY: - print_vlan_opts(a); + print_vlan_opts(a, bvm->ifindex); break; case BRIDGE_VLANDB_GLOBAL_OPTIONS: - print_vlan_global_opts(a); + print_vlan_global_opts(a, bvm->ifindex); break; } - close_json_object(); } return 0; From dee5eb05e51a5af522424d4eeacd18a3573db06a Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:52 +0300 Subject: [PATCH 06/19] bridge: vlan: add support to set global vlan options Add support to change global vlan options via a new vlan global set subcommand similar to the current vlan set subcommand. The man page and help are updated accordingly. The command works only with bridge devices. It doesn't support any options yet. Syntax: $ bridge vlan global set vid VID dev DEV Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++ man/man8/bridge.8 | 20 ++++++++++++ 2 files changed, 100 insertions(+) diff --git a/bridge/vlan.c b/bridge/vlan.c index 77db90d8..c9b445bc 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -37,6 +37,7 @@ static void usage(void) " bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n" " bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" + " bridge vlan global { set } vid VLAN_ID dev DEV\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -338,6 +339,83 @@ static int vlan_option_set(int argc, char **argv) return 0; } +static int vlan_global_option_set(int argc, char **argv) +{ + struct { + struct nlmsghdr n; + struct br_vlan_msg bvm; + char buf[1024]; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_vlan_msg)), + .n.nlmsg_flags = NLM_F_REQUEST, + .n.nlmsg_type = RTM_NEWVLAN, + .bvm.family = PF_BRIDGE, + }; + struct rtattr *afspec; + short vid_end = -1; + char *d = NULL; + short vid = -1; + + afspec = addattr_nest(&req.n, sizeof(req), + BRIDGE_VLANDB_GLOBAL_OPTIONS); + afspec->rta_type |= NLA_F_NESTED; + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + d = *argv; + req.bvm.ifindex = ll_name_to_index(d); + if (req.bvm.ifindex == 0) { + fprintf(stderr, "Cannot find network device \"%s\"\n", + d); + return -1; + } + } else if (strcmp(*argv, "vid") == 0) { + char *p; + + NEXT_ARG(); + p = strchr(*argv, '-'); + if (p) { + *p = '\0'; + p++; + vid = atoi(*argv); + vid_end = atoi(p); + if (vid >= vid_end || vid_end >= 4096) { + fprintf(stderr, "Invalid VLAN range \"%hu-%hu\"\n", + vid, vid_end); + return -1; + } + } else { + vid = atoi(*argv); + } + if (vid >= 4096) { + fprintf(stderr, "Invalid VLAN ID \"%hu\"\n", + vid); + return -1; + } + addattr16(&req.n, sizeof(req), BRIDGE_VLANDB_GOPTS_ID, + vid); + if (vid_end != -1) + addattr16(&req.n, sizeof(req), + BRIDGE_VLANDB_GOPTS_RANGE, vid_end); + } else { + if (strcmp(*argv, "help") == 0) + NEXT_ARG(); + } + argc--; argv++; + } + addattr_nest_end(&req.n, afspec); + + if (d == NULL || vid == -1) { + fprintf(stderr, "Device and VLAN ID are required arguments.\n"); + return -1; + } + + if (rtnl_talk(&rth, &req.n, NULL) < 0) + return -1; + + return 0; +} + /* In order to use this function for both filtering and non-filtering cases * we need to make it a tristate: * return -1 - if filtering we've gone over so don't continue @@ -1016,6 +1094,8 @@ static int vlan_global(int argc, char **argv) strcmp(*argv, "lst") == 0 || strcmp(*argv, "list") == 0) return vlan_global_show(argc-1, argv+1); + else if (strcmp(*argv, "set") == 0) + return vlan_global_option_set(argc-1, argv+1); else usage(); } else { diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 9ec4cb1d..796d20b6 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -152,6 +152,13 @@ bridge \- show / manipulate bridge addresses and devices .B dev .IR DEV " ]" +.ti -8 +.BR "bridge vlan global set" +.B dev +.I DEV +.B vid +.IR VID " [ ]" + .ti -8 .BR "bridge vlan global" " [ " show " ] [ " .B dev @@ -902,6 +909,19 @@ option, the command displays per-vlan traffic statistics. This command displays the current vlan tunnel info mapping. +.SS bridge vlan global set - change vlan filter entry's global options + +This command changes vlan filter entry's global options. + +.TP +.BI dev " NAME" +the interface with which this vlan is associated. Only bridge devices are +supported for global options. + +.TP +.BI vid " VID" +the VLAN ID that identifies the vlan. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 1f608d590c071b450dac6051bf1a616460961520 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:53 +0300 Subject: [PATCH 07/19] bridge: vlan: add global mcast_snooping option Add control and dump support for the global mcast_snooping option which controls if multicast snooping is enabled or disabled for a single vlan. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_snooping 1 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 18 +++++++++++++++++- man/man8/bridge.8 | 11 ++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index c9b445bc..220ba303 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "json_print.h" #include "libnetlink.h" @@ -38,6 +39,7 @@ static void usage(void) " bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan global { set } vid VLAN_ID dev DEV\n" + " [ mcast_snooping MULTICAST_SNOOPING ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -355,6 +357,7 @@ static int vlan_global_option_set(int argc, char **argv) short vid_end = -1; char *d = NULL; short vid = -1; + __u8 val8; afspec = addattr_nest(&req.n, sizeof(req), BRIDGE_VLANDB_GLOBAL_OPTIONS); @@ -397,6 +400,12 @@ static int vlan_global_option_set(int argc, char **argv) if (vid_end != -1) addattr16(&req.n, sizeof(req), BRIDGE_VLANDB_GOPTS_RANGE, vid_end); + } else if (strcmp(*argv, "mcast_snooping") == 0) { + NEXT_ARG(); + if (get_u8(&val8, *argv, 0)) + invarg("invalid mcast_snooping", *argv); + addattr8(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING, val8); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -702,7 +711,7 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) static void print_vlan_global_opts(struct rtattr *a, int ifindex) { - struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1]; + struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1], *vattr; __u16 vid, vrange = 0; if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_GLOBAL_OPTIONS) @@ -729,6 +738,13 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) } print_range("vlan", vid, vrange); print_nl(); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]; + print_uint(PRINT_ANY, "mcast_snooping", "mcast_snooping %u ", + rta_getattr_u8(vattr)); + } + print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 796d20b6..d894289b 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -157,7 +157,9 @@ bridge \- show / manipulate bridge addresses and devices .B dev .I DEV .B vid -.IR VID " [ ]" +.IR VID " [ " +.B mcast_snooping +.IR MULTICAST_SNOOPING " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -922,6 +924,13 @@ supported for global options. .BI vid " VID" the VLAN ID that identifies the vlan. +.TP +.BI mcast_snooping " MULTICAST_SNOOPING " +turn multicast snooping for VLAN entry with VLAN ID on +.RI ( MULTICAST_SNOOPING " > 0) " +or off +.RI ( MULTICAST_SNOOPING " == 0). Default is on. " + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 29fada0f412004470c049a571c5a5845ca2e2bb5 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:54 +0300 Subject: [PATCH 08/19] bridge: vlan: add global mcast_igmp_version option Add control and dump support for the global mcast_igmp_version option which controls the IGMP version on the vlan (default 2). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_igmp_version 3 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 12 ++++++++++++ man/man8/bridge.8 | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 220ba303..0864f3b7 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -40,6 +40,7 @@ static void usage(void) " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan global { set } vid VLAN_ID dev DEV\n" " [ mcast_snooping MULTICAST_SNOOPING ]\n" + " [ mcast_igmp_version IGMP_VERSION ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -406,6 +407,12 @@ static int vlan_global_option_set(int argc, char **argv) invarg("invalid mcast_snooping", *argv); addattr8(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING, val8); + } else if (strcmp(*argv, "mcast_igmp_version") == 0) { + NEXT_ARG(); + if (get_u8(&val8, *argv, 0)) + invarg("invalid mcast_igmp_version", *argv); + addattr8(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION, val8); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -744,6 +751,11 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) print_uint(PRINT_ANY, "mcast_snooping", "mcast_snooping %u ", rta_getattr_u8(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]; + print_uint(PRINT_ANY, "mcast_igmp_version", + "mcast_igmp_version %u ", rta_getattr_u8(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index d894289b..224647b4 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -159,7 +159,9 @@ bridge \- show / manipulate bridge addresses and devices .B vid .IR VID " [ " .B mcast_snooping -.IR MULTICAST_SNOOPING " ]" +.IR MULTICAST_SNOOPING " ] [ " +.B mcast_igmp_version +.IR IGMP_VERSION " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -931,6 +933,10 @@ turn multicast snooping for VLAN entry with VLAN ID on or off .RI ( MULTICAST_SNOOPING " == 0). Default is on. " +.TP +.BI mcast_igmp_version " IGMP_VERSION " +set the IGMP version. Default is 2. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From a8d7212a4f39b207c7a513e4161608b75522cc45 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:55 +0300 Subject: [PATCH 09/19] bridge: vlan: add global mcast_mld_version option Add control and dump support for the global mcast_mld_version option which controls the MLD version on the vlan (default 1). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_mld_version 2 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 12 ++++++++++++ man/man8/bridge.8 | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0864f3b7..fd9539ae 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -41,6 +41,7 @@ static void usage(void) " bridge vlan global { set } vid VLAN_ID dev DEV\n" " [ mcast_snooping MULTICAST_SNOOPING ]\n" " [ mcast_igmp_version IGMP_VERSION ]\n" + " [ mcast_mld_version MLD_VERSION ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -413,6 +414,12 @@ static int vlan_global_option_set(int argc, char **argv) invarg("invalid mcast_igmp_version", *argv); addattr8(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION, val8); + } else if (strcmp(*argv, "mcast_mld_version") == 0) { + NEXT_ARG(); + if (get_u8(&val8, *argv, 0)) + invarg("invalid mcast_mld_version", *argv); + addattr8(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION, val8); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -756,6 +763,11 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) print_uint(PRINT_ANY, "mcast_igmp_version", "mcast_igmp_version %u ", rta_getattr_u8(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]; + print_uint(PRINT_ANY, "mcast_mld_version", + "mcast_mld_version %u ", rta_getattr_u8(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 224647b4..dcbff936 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -161,7 +161,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_snooping .IR MULTICAST_SNOOPING " ] [ " .B mcast_igmp_version -.IR IGMP_VERSION " ]" +.IR IGMP_VERSION " ] [ " +.B mcast_mld_version +.IR MLD_VERSION " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -937,6 +939,10 @@ or off .BI mcast_igmp_version " IGMP_VERSION " set the IGMP version. Default is 2. +.TP +.BI mcast_mld_version " MLD_VERSION " +set the MLD version. Default is 1. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 3399c0759f3126ef672ae9ecb839f95c922c67c2 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:56 +0300 Subject: [PATCH 10/19] bridge: vlan: add global mcast_last_member_count option Add control and dump support for the global mcast_last_member_count option which controls the number of queries the bridge will send on the vlan after a leave is received (default 2). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_last_member_count 10 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index fd9539ae..0bdaaabb 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -42,6 +42,7 @@ static void usage(void) " [ mcast_snooping MULTICAST_SNOOPING ]\n" " [ mcast_igmp_version IGMP_VERSION ]\n" " [ mcast_mld_version MLD_VERSION ]\n" + " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -359,6 +360,7 @@ static int vlan_global_option_set(int argc, char **argv) short vid_end = -1; char *d = NULL; short vid = -1; + __u32 val32; __u8 val8; afspec = addattr_nest(&req.n, sizeof(req), @@ -420,6 +422,13 @@ static int vlan_global_option_set(int argc, char **argv) invarg("invalid mcast_mld_version", *argv); addattr8(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION, val8); + } else if (strcmp(*argv, "mcast_last_member_count") == 0) { + NEXT_ARG(); + if (get_u32(&val32, *argv, 0)) + invarg("invalid mcast_last_member_count", *argv); + addattr32(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT, + val32); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -768,6 +777,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) print_uint(PRINT_ANY, "mcast_mld_version", "mcast_mld_version %u ", rta_getattr_u8(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT]; + print_uint(PRINT_ANY, "mcast_last_member_count", + "mcast_last_member_count %u ", + rta_getattr_u32(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index dcbff936..cea75518 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -163,7 +163,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_igmp_version .IR IGMP_VERSION " ] [ " .B mcast_mld_version -.IR MLD_VERSION " ]" +.IR MLD_VERSION " ] [ " +.B mcast_last_member_count +.IR LAST_MEMBER_COUNT " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -943,6 +945,12 @@ set the IGMP version. Default is 2. .BI mcast_mld_version " MLD_VERSION " set the MLD version. Default is 1. +.TP +.BI mcast_last_member_count " LAST_MEMBER_COUNT " +set multicast last member count, ie the number of queries the bridge +will send before stopping forwarding a multicast group after a "leave" +message has been received. Default is 2. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 7cc7dbf4472212d380b5e9c2dfc89326d9de1ae0 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:57 +0300 Subject: [PATCH 11/19] bridge: vlan: add global mcast_startup_query_count option Add control and dump support for the global mcast_startup_query_count option which controls the number of queries the bridge will send on the vlan during startup phase (default 2). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_startup_query_count 5 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0bdaaabb..c68f8340 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -43,6 +43,7 @@ static void usage(void) " [ mcast_igmp_version IGMP_VERSION ]\n" " [ mcast_mld_version MLD_VERSION ]\n" " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" + " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -429,6 +430,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr32(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT, val32); + } else if (strcmp(*argv, "mcast_startup_query_count") == 0) { + NEXT_ARG(); + if (get_u32(&val32, *argv, 0)) + invarg("invalid mcast_startup_query_count", + *argv); + addattr32(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT, + val32); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -783,6 +792,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_last_member_count %u ", rta_getattr_u32(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]; + print_uint(PRINT_ANY, "mcast_startup_query_count", + "mcast_startup_query_count %u ", + rta_getattr_u32(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index cea75518..77413823 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -165,7 +165,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_mld_version .IR MLD_VERSION " ] [ " .B mcast_last_member_count -.IR LAST_MEMBER_COUNT " ]" +.IR LAST_MEMBER_COUNT " ] [ " +.B mcast_startup_query_count +.IR STARTUP_QUERY_COUNT " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -951,6 +953,10 @@ set multicast last member count, ie the number of queries the bridge will send before stopping forwarding a multicast group after a "leave" message has been received. Default is 2. +.TP +.BI mcast_startup_query_count " STARTUP_QUERY_COUNT " +set the number of queries to send during startup phase. Default is 2. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 2b6cc38d526278d43a718432e0d57f27d577daa9 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:58 +0300 Subject: [PATCH 12/19] bridge: vlan: add global mcast_last_member_interval option Add control and dump support for the global mcast_last_member_interval option which controls the interval between queries to find remaining members of a group after a leave message. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. The default is 100 (1 second). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_last_member_interval 200 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 16 ++++++++++++++++ man/man8/bridge.8 | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/bridge/vlan.c b/bridge/vlan.c index c68f8340..446a611f 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -43,6 +43,7 @@ static void usage(void) " [ mcast_igmp_version IGMP_VERSION ]\n" " [ mcast_mld_version MLD_VERSION ]\n" " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" + " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n" " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); @@ -361,6 +362,7 @@ static int vlan_global_option_set(int argc, char **argv) short vid_end = -1; char *d = NULL; short vid = -1; + __u64 val64; __u32 val32; __u8 val8; @@ -438,6 +440,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr32(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT, val32); + } else if (strcmp(*argv, "mcast_last_member_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_last_member_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -792,6 +802,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_last_member_count %u ", rta_getattr_u32(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL]; + print_lluint(PRINT_ANY, "mcast_last_member_interval", + "mcast_last_member_interval %llu ", + rta_getattr_u64(vattr)); + } if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]) { vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]; print_uint(PRINT_ANY, "mcast_startup_query_count", diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 77413823..0d973a9d 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -166,6 +166,8 @@ bridge \- show / manipulate bridge addresses and devices .IR MLD_VERSION " ] [ " .B mcast_last_member_count .IR LAST_MEMBER_COUNT " ] [ " +.B mcast_last_member_interval +.IR LAST_MEMBER_INTERVAL " ] [ " .B mcast_startup_query_count .IR STARTUP_QUERY_COUNT " ]" @@ -953,6 +955,11 @@ set multicast last member count, ie the number of queries the bridge will send before stopping forwarding a multicast group after a "leave" message has been received. Default is 2. +.TP +.BI mcast_last_member_interval " LAST_MEMBER_INTERVAL " +interval between queries to find remaining members of a group, +after a "leave" message is received. + .TP .BI mcast_startup_query_count " STARTUP_QUERY_COUNT " set the number of queries to send during startup phase. Default is 2. From 3ae784f5898076414b1b6767d9562ee416374e9a Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:07:59 +0300 Subject: [PATCH 13/19] bridge: vlan: add global mcast_membership_interval option Add control and dump support for the global mcast_membership_interval option which controls the interval after which the bridge will leave a group if no reports have been received for it. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. The default is 26000 (260 seconds). Syntax: $ bridge vlan global set dev bridge vid 1 mcast_membership_interval 13000 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 446a611f..9f948190 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -45,6 +45,7 @@ static void usage(void) " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n" " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" + " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -448,6 +449,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL, val64); + } else if (strcmp(*argv, "mcast_membership_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_membership_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -814,6 +823,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_startup_query_count %u ", rta_getattr_u32(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]; + print_lluint(PRINT_ANY, "mcast_membership_interval", + "mcast_membership_interval %llu ", + rta_getattr_u64(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index 0d973a9d..a026ca16 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -169,7 +169,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_last_member_interval .IR LAST_MEMBER_INTERVAL " ] [ " .B mcast_startup_query_count -.IR STARTUP_QUERY_COUNT " ]" +.IR STARTUP_QUERY_COUNT " ] [ " +.B mcast_membership_interval +.IR MEMBERSHIP_INTERVAL " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -964,6 +966,11 @@ after a "leave" message is received. .BI mcast_startup_query_count " STARTUP_QUERY_COUNT " set the number of queries to send during startup phase. Default is 2. +.TP +.BI mcast_membership_interval " MEMBERSHIP_INTERVAL " +delay after which the bridge will leave a group, +if no membership reports for this group are received. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From ebcee09ca1a7a871b1042d46cf46d66cf08d0921 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:00 +0300 Subject: [PATCH 14/19] bridge: vlan: add global mcast_querier_interval option Add control and dump support for the global mcast_querier_interval option which controls the interval after which if no other router queries are seen the bridge will start sending its own queries. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_querier_interval 13000 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 9f948190..275589af 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -46,6 +46,7 @@ static void usage(void) " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n" " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n" + " [ mcast_querier_interval QUERIER_INTERVAL ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -457,6 +458,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL, val64); + } else if (strcmp(*argv, "mcast_querier_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_querier_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -829,6 +838,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_membership_interval %llu ", rta_getattr_u64(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL]; + print_lluint(PRINT_ANY, "mcast_querier_interval", + "mcast_querier_interval %llu ", + rta_getattr_u64(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index a026ca16..f5c72ec8 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -171,7 +171,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_startup_query_count .IR STARTUP_QUERY_COUNT " ] [ " .B mcast_membership_interval -.IR MEMBERSHIP_INTERVAL " ]" +.IR MEMBERSHIP_INTERVAL " ] [ " +.B mcast_querier_interval +.IR QUERIER_INTERVAL " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -971,6 +973,14 @@ set the number of queries to send during startup phase. Default is 2. delay after which the bridge will leave a group, if no membership reports for this group are received. +.TP +.BI mcast_querier_interval " QUERIER_INTERVAL " +interval between queries sent by other routers. If no queries are seen +after this delay has passed, the bridge will start to send its own queries +(as if +.BI mcast_querier +was enabled). + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 0e4cfa03708e3d5333df2fd8311b1dd012044b36 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:01 +0300 Subject: [PATCH 15/19] bridge: vlan: add global mcast_query_interval option Add control and dump support for the global mcast_query_interval option which controls the interval between queries sent by the bridge after the end of the startup phase. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_query_interval 13000 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 275589af..0d70753a 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -47,6 +47,7 @@ static void usage(void) " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n" " [ mcast_querier_interval QUERIER_INTERVAL ]\n" + " [ mcast_query_interval QUERY_INTERVAL ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -466,6 +467,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL, val64); + } else if (strcmp(*argv, "mcast_query_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_query_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -844,6 +853,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_querier_interval %llu ", rta_getattr_u64(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL]; + print_lluint(PRINT_ANY, "mcast_query_interval", + "mcast_query_interval %llu ", + rta_getattr_u64(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index f5c72ec8..cb1170f8 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -173,7 +173,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_membership_interval .IR MEMBERSHIP_INTERVAL " ] [ " .B mcast_querier_interval -.IR QUERIER_INTERVAL " ]" +.IR QUERIER_INTERVAL " ] [ " +.B mcast_query_interval +.IR QUERY_INTERVAL " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -981,6 +983,11 @@ after this delay has passed, the bridge will start to send its own queries .BI mcast_querier was enabled). +.TP +.BI mcast_query_interval " QUERY_INTERVAL " +interval between queries sent by the bridge after the end of the +startup phase. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 60dcd5c318d60fedc984a40236740b16d0fde24a Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:02 +0300 Subject: [PATCH 16/19] bridge: vlan: add global mcast_query_response_interval option Add control and dump support for the global mcast_query_response_interval option which sets the Max Response Time/Maximum Response Delay for IGMP/MLD queries sent by the bridge. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_query_response_interval 13000 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0d70753a..83fd5379 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -48,6 +48,7 @@ static void usage(void) " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n" " [ mcast_querier_interval QUERIER_INTERVAL ]\n" " [ mcast_query_interval QUERY_INTERVAL ]\n" + " [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -475,6 +476,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL, val64); + } else if (strcmp(*argv, "mcast_query_response_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_query_response_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -859,6 +868,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_query_interval %llu ", rta_getattr_u64(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL]; + print_lluint(PRINT_ANY, "mcast_query_response_interval", + "mcast_query_response_interval %llu ", + rta_getattr_u64(vattr)); + } print_nl(); close_json_object(); } diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index cb1170f8..e9cd5f9f 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -175,7 +175,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_querier_interval .IR QUERIER_INTERVAL " ] [ " .B mcast_query_interval -.IR QUERY_INTERVAL " ]" +.IR QUERY_INTERVAL " ] [ " +.B mcast_query_response_interval +.IR QUERY_RESPONSE_INTERVAL " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -988,6 +990,11 @@ was enabled). interval between queries sent by the bridge after the end of the startup phase. +.TP +.BI mcast_query_response_interval " QUERY_RESPONSE_INTERVAL " +set the Max Response Time/Maximum Response Delay for IGMP/MLD +queries sent by the bridge. + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From 061da2e2226020e0b9ac4b5017067689fd9c702f Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:03 +0300 Subject: [PATCH 17/19] bridge: vlan: add global mcast_startup_query_interval option Add control and dump support for the global mcast_startup_query_interval option which controls the interval between queries in the startup phase. To be consistent with the same bridge-wide option the value is reported with USER_HZ granularity and the same granularity is expected when setting it. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_startup_query_interval 15000 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 15 +++++++++++++++ man/man8/bridge.8 | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/bridge/vlan.c b/bridge/vlan.c index 83fd5379..54910793 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -45,6 +45,7 @@ static void usage(void) " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n" " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n" + " [ mcast_startup_query_interval STARTUP_QUERY_INTERVAL ]\n" " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n" " [ mcast_querier_interval QUERIER_INTERVAL ]\n" " [ mcast_query_interval QUERY_INTERVAL ]\n" @@ -484,6 +485,14 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL, val64); + } else if (strcmp(*argv, "mcast_startup_query_interval") == 0) { + NEXT_ARG(); + if (get_u64(&val64, *argv, 0)) + invarg("invalid mcast_startup_query_interval", + *argv); + addattr64(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL, + val64); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -850,6 +859,12 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_startup_query_count %u ", rta_getattr_u32(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL]; + print_lluint(PRINT_ANY, "mcast_startup_query_interval", + "mcast_startup_query_interval %llu ", + rta_getattr_u64(vattr)); + } if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]) { vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]; print_lluint(PRINT_ANY, "mcast_membership_interval", diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index e9cd5f9f..eeceb309 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -170,6 +170,8 @@ bridge \- show / manipulate bridge addresses and devices .IR LAST_MEMBER_INTERVAL " ] [ " .B mcast_startup_query_count .IR STARTUP_QUERY_COUNT " ] [ " +.B mcast_startup_query_interval +.IR STARTUP_QUERY_INTERVAL " ] [ " .B mcast_membership_interval .IR MEMBERSHIP_INTERVAL " ] [ " .B mcast_querier_interval @@ -972,6 +974,10 @@ after a "leave" message is received. .BI mcast_startup_query_count " STARTUP_QUERY_COUNT " set the number of queries to send during startup phase. Default is 2. +.TP +.BI mcast_startup_query_interval " STARTUP_QUERY_INTERVAL " +interval between queries in the startup phase. + .TP .BI mcast_membership_interval " MEMBERSHIP_INTERVAL " delay after which the bridge will leave a group, From 7ad5505bb5331c523ac0371949dfeb8d2360c4b0 Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:04 +0300 Subject: [PATCH 18/19] bridge: vlan: add global mcast_querier option Add control and dump support for the global mcast_querier option which controls if the bridge will act as a multicast querier for that vlan. Syntax: $ bridge vlan global set dev bridge vid 1 mcast_querier 1 Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/vlan.c | 12 ++++++++++++ man/man8/bridge.8 | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/bridge/vlan.c b/bridge/vlan.c index 54910793..abc24deb 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -40,6 +40,7 @@ static void usage(void) " bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n" " bridge vlan global { set } vid VLAN_ID dev DEV\n" " [ mcast_snooping MULTICAST_SNOOPING ]\n" + " [ mcast_querier MULTICAST_QUERIER ]\n" " [ mcast_igmp_version IGMP_VERSION ]\n" " [ mcast_mld_version MLD_VERSION ]\n" " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n" @@ -418,6 +419,12 @@ static int vlan_global_option_set(int argc, char **argv) invarg("invalid mcast_snooping", *argv); addattr8(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING, val8); + } else if (strcmp(*argv, "mcast_querier") == 0) { + NEXT_ARG(); + if (get_u8(&val8, *argv, 0)) + invarg("invalid mcast_querier", *argv); + addattr8(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MCAST_QUERIER, val8); } else if (strcmp(*argv, "mcast_igmp_version") == 0) { NEXT_ARG(); if (get_u8(&val8, *argv, 0)) @@ -831,6 +838,11 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) print_uint(PRINT_ANY, "mcast_snooping", "mcast_snooping %u ", rta_getattr_u8(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER]; + print_uint(PRINT_ANY, "mcast_querier", "mcast_querier %u ", + rta_getattr_u8(vattr)); + } if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]) { vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]; print_uint(PRINT_ANY, "mcast_igmp_version", diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index eeceb309..76d2fa09 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -160,6 +160,8 @@ bridge \- show / manipulate bridge addresses and devices .IR VID " [ " .B mcast_snooping .IR MULTICAST_SNOOPING " ] [ " +.B mcast_querier +.IR MULTICAST_QUERIER " ] [ " .B mcast_igmp_version .IR IGMP_VERSION " ] [ " .B mcast_mld_version @@ -951,6 +953,14 @@ turn multicast snooping for VLAN entry with VLAN ID on or off .RI ( MULTICAST_SNOOPING " == 0). Default is on. " +.TP +.BI mcast_querier " MULTICAST_QUERIER " +enable +.RI ( MULTICAST_QUERIER " > 0) " +or disable +.RI ( MULTICAST_QUERIER " == 0) " +IGMP/MLD querier, ie sending of multicast queries by the bridge. Default is disabled. + .TP .BI mcast_igmp_version " IGMP_VERSION " set the IGMP version. Default is 2. From 72222cd467cabc9f2be7b88e275ea8c35918294b Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Sat, 28 Aug 2021 14:08:05 +0300 Subject: [PATCH 19/19] bridge: vlan: add support for dumping router ports Add dump support for vlan multicast router ports and their details if requested. If details are requested we print 1 entry per line, otherwise we print all router ports on a single line similar to how mdb prints them. Looks like: $ bridge vlan global show vid 100 port vlan-id bridge 100 mcast_snooping 1 mcast_querier 0 mcast_igmp_version 2 mcast_mld_version 1 mcast_last_member_count 2 mcast_last_member_interval 100 mcast_startup_query_count 2 mcast_startup_query_interval 3125 mcast_membership_interval 26000 mcast_querier_interval 25500 mcast_query_interval 12500 mcast_query_response_interval 1000 router ports: ens20 ens16 Looks like (with -s): $ bridge -s vlan global show vid 100 port vlan-id bridge 100 mcast_snooping 1 mcast_querier 0 mcast_igmp_version 2 mcast_mld_version 1 mcast_last_member_count 2 mcast_last_member_interval 100 mcast_startup_query_count 2 mcast_startup_query_interval 3125 mcast_membership_interval 26000 mcast_querier_interval 25500 mcast_query_interval 12500 mcast_query_response_interval 1000 router ports: ens20 187.57 temp ens16 118.27 temp Signed-off-by: Nikolay Aleksandrov Signed-off-by: David Ahern --- bridge/br_common.h | 1 + bridge/mdb.c | 6 +++--- bridge/vlan.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index 09f42c81..610e83f6 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -14,6 +14,7 @@ void print_stp_state(__u8 state); int parse_stp_state(const char *arg); int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only); +void br_print_router_port_stats(struct rtattr *pattr); 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 b427d878..7b5863d3 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -59,7 +59,7 @@ static const char *format_timer(__u32 ticks, int align) return tbuf; } -static void __print_router_port_stats(FILE *f, struct rtattr *pattr) +void br_print_router_port_stats(struct rtattr *pattr) { struct rtattr *tb[MDBA_ROUTER_PATTR_MAX + 1]; @@ -101,13 +101,13 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr, print_string(PRINT_JSON, "port", NULL, port_ifname); if (show_stats) - __print_router_port_stats(f, i); + br_print_router_port_stats(i); close_json_object(); } else if (show_stats) { fprintf(f, "router ports on %s: %s", brifname, port_ifname); - __print_router_port_stats(f, i); + br_print_router_port_stats(i); fprintf(f, "\n"); } else { fprintf(f, "%s ", port_ifname); diff --git a/bridge/vlan.c b/bridge/vlan.c index abc24deb..4ead57b7 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -803,6 +803,36 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg) return 0; } +static void print_vlan_router_ports(struct rtattr *rattr) +{ + int rem = RTA_PAYLOAD(rattr); + struct rtattr *i; + + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + open_json_array(PRINT_ANY, is_json_context() ? "router_ports" : + "router ports: "); + for (i = RTA_DATA(rattr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { + uint32_t *port_ifindex = RTA_DATA(i); + const char *port_ifname = ll_index_to_name(*port_ifindex); + + open_json_object(NULL); + if (show_stats && i != RTA_DATA(rattr)) { + print_nl(); + /* start: IFNAMSIZ + 4 + strlen("router ports: ") */ + print_string(PRINT_FP, NULL, + "%-" __stringify(IFNAMSIZ) "s " + " ", + ""); + } + print_string(PRINT_ANY, "port", "%s ", port_ifname); + if (show_stats) + br_print_router_port_stats(i); + close_json_object(); + } + close_json_array(PRINT_JSON, NULL); + print_nl(); +} + static void print_vlan_global_opts(struct rtattr *a, int ifindex) { struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1], *vattr; @@ -902,6 +932,10 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) rta_getattr_u64(vattr)); } print_nl(); + if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS]) { + vattr = RTA_DATA(vtb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS]); + print_vlan_router_ports(vattr); + } close_json_object(); }