1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020, Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
3 #include <linux/kernel.h>
4 #include <linux/netdevice.h>
5 #include <linux/rtnetlink.h>
6 #include <linux/slab.h>
7 #include <net/ip_tunnels.h>
9 #include "br_private.h"
10 #include "br_private_tunnel.h"
12 static bool __vlan_tun_put(struct sk_buff *skb, const struct net_bridge_vlan *v)
14 __be32 tid = tunnel_id_to_key32(v->tinfo.tunnel_id);
17 if (!v->tinfo.tunnel_dst)
20 nest = nla_nest_start(skb, BRIDGE_VLANDB_ENTRY_TUNNEL_INFO);
23 if (nla_put_u32(skb, BRIDGE_VLANDB_TINFO_ID, be32_to_cpu(tid))) {
24 nla_nest_cancel(skb, nest);
27 nla_nest_end(skb, nest);
32 static bool __vlan_tun_can_enter_range(const struct net_bridge_vlan *v_curr,
33 const struct net_bridge_vlan *range_end)
35 return (!v_curr->tinfo.tunnel_dst && !range_end->tinfo.tunnel_dst) ||
36 vlan_tunid_inrange(v_curr, range_end);
39 /* check if the options' state of v_curr allow it to enter the range */
40 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
41 const struct net_bridge_vlan *range_end)
43 u8 range_mc_rtr = br_vlan_multicast_router(range_end);
44 u8 curr_mc_rtr = br_vlan_multicast_router(v_curr);
46 return v_curr->state == range_end->state &&
47 __vlan_tun_can_enter_range(v_curr, range_end) &&
48 curr_mc_rtr == range_mc_rtr;
51 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v,
52 const struct net_bridge_port *p)
54 if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_STATE, br_vlan_get_state(v)) ||
55 !__vlan_tun_put(skb, v) ||
56 nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_NEIGH_SUPPRESS,
57 !!(v->priv_flags & BR_VLFLAG_NEIGH_SUPPRESS_ENABLED)))
60 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
61 if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
62 br_vlan_multicast_router(v)))
64 if (p && !br_multicast_port_ctx_vlan_disabled(&v->port_mcast_ctx) &&
65 (nla_put_u32(skb, BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS,
66 br_multicast_ngroups_get(&v->port_mcast_ctx)) ||
67 nla_put_u32(skb, BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS,
68 br_multicast_ngroups_get_max(&v->port_mcast_ctx))))
75 size_t br_vlan_opts_nl_size(void)
77 return nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_STATE */
78 + nla_total_size(0) /* BRIDGE_VLANDB_ENTRY_TUNNEL_INFO */
79 + nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_TINFO_ID */
80 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
81 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_MCAST_ROUTER */
82 + nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_ENTRY_MCAST_N_GROUPS */
83 + nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS */
85 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_NEIGH_SUPPRESS */
89 static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,
90 struct net_bridge_vlan *v,
93 struct netlink_ext_ack *extack)
95 struct net_bridge *br;
99 if (state > BR_STATE_BLOCKING) {
100 NL_SET_ERR_MSG_MOD(extack, "Invalid vlan state");
104 if (br_vlan_is_brentry(v))
109 if (br->stp_enabled == BR_KERNEL_STP) {
110 NL_SET_ERR_MSG_MOD(extack, "Can't modify vlan state when using kernel STP");
114 if (br_opt_get(br, BROPT_MST_ENABLED)) {
115 NL_SET_ERR_MSG_MOD(extack, "Can't modify vlan state directly when MST is enabled");
119 if (v->state == state)
122 if (v->vid == br_get_pvid(vg))
123 br_vlan_set_pvid_state(vg, state);
125 br_vlan_set_state(v, state);
131 static const struct nla_policy br_vlandb_tinfo_pol[BRIDGE_VLANDB_TINFO_MAX + 1] = {
132 [BRIDGE_VLANDB_TINFO_ID] = { .type = NLA_U32 },
133 [BRIDGE_VLANDB_TINFO_CMD] = { .type = NLA_U32 },
136 static int br_vlan_modify_tunnel(const struct net_bridge_port *p,
137 struct net_bridge_vlan *v,
140 struct netlink_ext_ack *extack)
142 struct nlattr *tun_tb[BRIDGE_VLANDB_TINFO_MAX + 1], *attr;
143 struct bridge_vlan_info *vinfo;
148 NL_SET_ERR_MSG_MOD(extack, "Can't modify tunnel mapping of non-port vlans");
151 if (!(p->flags & BR_VLAN_TUNNEL)) {
152 NL_SET_ERR_MSG_MOD(extack, "Port doesn't have tunnel flag set");
156 attr = tb[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO];
157 err = nla_parse_nested(tun_tb, BRIDGE_VLANDB_TINFO_MAX, attr,
158 br_vlandb_tinfo_pol, extack);
162 if (!tun_tb[BRIDGE_VLANDB_TINFO_CMD]) {
163 NL_SET_ERR_MSG_MOD(extack, "Missing tunnel command attribute");
166 cmd = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_CMD]);
169 if (!tun_tb[BRIDGE_VLANDB_TINFO_ID]) {
170 NL_SET_ERR_MSG_MOD(extack, "Missing tunnel id attribute");
173 /* when working on vlan ranges this is the starting tunnel id */
174 tun_id = nla_get_u32(tun_tb[BRIDGE_VLANDB_TINFO_ID]);
175 /* vlan info attr is guaranteed by br_vlan_rtm_process_one */
176 vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]);
177 /* tunnel ids are mapped to each vlan in increasing order,
178 * the starting vlan is in BRIDGE_VLANDB_ENTRY_INFO and v is the
179 * current vlan, so we compute: tun_id + v - vinfo->vid
181 tun_id += v->vid - vinfo->vid;
186 NL_SET_ERR_MSG_MOD(extack, "Unsupported tunnel command");
190 return br_vlan_tunnel_info(p, cmd, v->vid, tun_id, changed);
193 static int br_vlan_process_one_opts(const struct net_bridge *br,
194 const struct net_bridge_port *p,
195 struct net_bridge_vlan_group *vg,
196 struct net_bridge_vlan *v,
199 struct netlink_ext_ack *extack)
204 if (tb[BRIDGE_VLANDB_ENTRY_STATE]) {
205 u8 state = nla_get_u8(tb[BRIDGE_VLANDB_ENTRY_STATE]);
207 err = br_vlan_modify_state(vg, v, state, changed, extack);
211 if (tb[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO]) {
212 err = br_vlan_modify_tunnel(p, v, tb, changed, extack);
217 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
218 if (tb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]) {
221 val = nla_get_u8(tb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]);
222 err = br_multicast_set_vlan_router(v, val);
227 if (tb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS]) {
231 NL_SET_ERR_MSG_MOD(extack, "Can't set mcast_max_groups for non-port vlans");
234 if (br_multicast_port_ctx_vlan_disabled(&v->port_mcast_ctx)) {
235 NL_SET_ERR_MSG_MOD(extack, "Multicast snooping disabled on this VLAN");
239 val = nla_get_u32(tb[BRIDGE_VLANDB_ENTRY_MCAST_MAX_GROUPS]);
240 br_multicast_ngroups_set_max(&v->port_mcast_ctx, val);
245 if (tb[BRIDGE_VLANDB_ENTRY_NEIGH_SUPPRESS]) {
246 bool enabled = v->priv_flags & BR_VLFLAG_NEIGH_SUPPRESS_ENABLED;
247 bool val = nla_get_u8(tb[BRIDGE_VLANDB_ENTRY_NEIGH_SUPPRESS]);
250 NL_SET_ERR_MSG_MOD(extack, "Can't set neigh_suppress for non-port vlans");
254 if (val != enabled) {
255 v->priv_flags ^= BR_VLFLAG_NEIGH_SUPPRESS_ENABLED;
263 int br_vlan_process_options(const struct net_bridge *br,
264 const struct net_bridge_port *p,
265 struct net_bridge_vlan *range_start,
266 struct net_bridge_vlan *range_end,
268 struct netlink_ext_ack *extack)
270 struct net_bridge_vlan *v, *curr_start = NULL, *curr_end = NULL;
271 struct net_bridge_vlan_group *vg;
276 vg = nbp_vlan_group(p);
278 vg = br_vlan_group(br);
280 if (!range_start || !br_vlan_should_use(range_start)) {
281 NL_SET_ERR_MSG_MOD(extack, "Vlan range start doesn't exist, can't process options");
284 if (!range_end || !br_vlan_should_use(range_end)) {
285 NL_SET_ERR_MSG_MOD(extack, "Vlan range end doesn't exist, can't process options");
289 pvid = br_get_pvid(vg);
290 for (vid = range_start->vid; vid <= range_end->vid; vid++) {
291 bool changed = false;
293 v = br_vlan_find(vg, vid);
294 if (!v || !br_vlan_should_use(v)) {
295 NL_SET_ERR_MSG_MOD(extack, "Vlan in range doesn't exist, can't process options");
300 err = br_vlan_process_one_opts(br, p, vg, v, tb, &changed,
306 /* vlan options changed, check for range */
313 if (v->vid == pvid ||
314 !br_vlan_can_enter_range(v, curr_end)) {
315 br_vlan_notify(br, p, curr_start->vid,
316 curr_end->vid, RTM_NEWVLAN);
321 /* nothing changed and nothing to notify yet */
325 br_vlan_notify(br, p, curr_start->vid, curr_end->vid,
332 br_vlan_notify(br, p, curr_start->vid, curr_end->vid,
338 bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr,
339 const struct net_bridge_vlan *r_end)
341 return v_curr->vid - r_end->vid == 1 &&
342 v_curr->msti == r_end->msti &&
343 ((v_curr->priv_flags ^ r_end->priv_flags) &
344 BR_VLFLAG_GLOBAL_MCAST_ENABLED) == 0 &&
345 br_multicast_ctx_options_equal(&v_curr->br_mcast_ctx,
346 &r_end->br_mcast_ctx);
349 bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
350 const struct net_bridge_vlan *v_opts)
352 struct nlattr *nest2 __maybe_unused;
353 u64 clockval __maybe_unused;
356 nest = nla_nest_start(skb, BRIDGE_VLANDB_GLOBAL_OPTIONS);
360 if (nla_put_u16(skb, BRIDGE_VLANDB_GOPTS_ID, vid))
363 if (vid_range && vid < vid_range &&
364 nla_put_u16(skb, BRIDGE_VLANDB_GOPTS_RANGE, vid_range))
367 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
368 if (nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING,
369 !!(v_opts->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)) ||
370 nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION,
371 v_opts->br_mcast_ctx.multicast_igmp_version) ||
372 nla_put_u32(skb, BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT,
373 v_opts->br_mcast_ctx.multicast_last_member_count) ||
374 nla_put_u32(skb, BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT,
375 v_opts->br_mcast_ctx.multicast_startup_query_count) ||
376 nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_QUERIER,
377 v_opts->br_mcast_ctx.multicast_querier) ||
378 br_multicast_dump_querier_state(skb, &v_opts->br_mcast_ctx,
379 BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE))
382 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_last_member_interval);
383 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL,
384 clockval, BRIDGE_VLANDB_GOPTS_PAD))
386 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_membership_interval);
387 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL,
388 clockval, BRIDGE_VLANDB_GOPTS_PAD))
390 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_querier_interval);
391 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL,
392 clockval, BRIDGE_VLANDB_GOPTS_PAD))
394 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_query_interval);
395 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL,
396 clockval, BRIDGE_VLANDB_GOPTS_PAD))
398 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_query_response_interval);
399 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL,
400 clockval, BRIDGE_VLANDB_GOPTS_PAD))
402 clockval = jiffies_to_clock_t(v_opts->br_mcast_ctx.multicast_startup_query_interval);
403 if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL,
404 clockval, BRIDGE_VLANDB_GOPTS_PAD))
407 if (br_rports_have_mc_router(&v_opts->br_mcast_ctx)) {
408 nest2 = nla_nest_start(skb,
409 BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS);
414 if (br_rports_fill_info(skb, &v_opts->br_mcast_ctx)) {
416 nla_nest_cancel(skb, nest2);
421 nla_nest_end(skb, nest2);
424 #if IS_ENABLED(CONFIG_IPV6)
425 if (nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION,
426 v_opts->br_mcast_ctx.multicast_mld_version))
431 if (nla_put_u16(skb, BRIDGE_VLANDB_GOPTS_MSTI, v_opts->msti))
434 nla_nest_end(skb, nest);
439 nla_nest_cancel(skb, nest);
443 static size_t rtnl_vlan_global_opts_nlmsg_size(const struct net_bridge_vlan *v)
445 return NLMSG_ALIGN(sizeof(struct br_vlan_msg))
446 + nla_total_size(0) /* BRIDGE_VLANDB_GLOBAL_OPTIONS */
447 + nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_GOPTS_ID */
448 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
449 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING */
450 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION */
451 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION */
452 + nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT */
453 + nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT */
454 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL */
455 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL */
456 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL */
457 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL */
458 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL */
459 + nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL */
460 + nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER */
461 + br_multicast_querier_state_size() /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE */
462 + nla_total_size(0) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
463 + br_rports_size(&v->br_mcast_ctx) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
465 + nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_GOPTS_MSTI */
466 + nla_total_size(sizeof(u16)); /* BRIDGE_VLANDB_GOPTS_RANGE */
469 static void br_vlan_global_opts_notify(const struct net_bridge *br,
470 u16 vid, u16 vid_range)
472 struct net_bridge_vlan *v;
473 struct br_vlan_msg *bvm;
474 struct nlmsghdr *nlh;
478 /* right now notifications are done only with rtnl held */
481 /* need to find the vlan due to flags/options */
482 v = br_vlan_find(br_vlan_group(br), vid);
486 skb = nlmsg_new(rtnl_vlan_global_opts_nlmsg_size(v), GFP_KERNEL);
491 nlh = nlmsg_put(skb, 0, 0, RTM_NEWVLAN, sizeof(*bvm), 0);
494 bvm = nlmsg_data(nlh);
495 memset(bvm, 0, sizeof(*bvm));
496 bvm->family = AF_BRIDGE;
497 bvm->ifindex = br->dev->ifindex;
499 if (!br_vlan_global_opts_fill(skb, vid, vid_range, v))
503 rtnl_notify(skb, dev_net(br->dev), 0, RTNLGRP_BRVLAN, NULL, GFP_KERNEL);
507 rtnl_set_sk_err(dev_net(br->dev), RTNLGRP_BRVLAN, err);
511 static int br_vlan_process_global_one_opts(const struct net_bridge *br,
512 struct net_bridge_vlan_group *vg,
513 struct net_bridge_vlan *v,
516 struct netlink_ext_ack *extack)
518 int err __maybe_unused;
521 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
522 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]) {
525 mc_snooping = nla_get_u8(tb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]);
526 if (br_multicast_toggle_global_vlan(v, !!mc_snooping))
529 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]) {
532 ver = nla_get_u8(tb[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION]);
533 err = br_multicast_set_igmp_version(&v->br_mcast_ctx, ver);
538 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT]) {
541 cnt = nla_get_u32(tb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT]);
542 v->br_mcast_ctx.multicast_last_member_count = cnt;
545 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]) {
548 cnt = nla_get_u32(tb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT]);
549 v->br_mcast_ctx.multicast_startup_query_count = cnt;
552 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL]) {
555 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL]);
556 v->br_mcast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val);
559 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]) {
562 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL]);
563 v->br_mcast_ctx.multicast_membership_interval = clock_t_to_jiffies(val);
566 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL]) {
569 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL]);
570 v->br_mcast_ctx.multicast_querier_interval = clock_t_to_jiffies(val);
573 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL]) {
576 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL]);
577 br_multicast_set_query_intvl(&v->br_mcast_ctx, val);
580 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL]) {
583 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL]);
584 v->br_mcast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val);
587 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL]) {
590 val = nla_get_u64(tb[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL]);
591 br_multicast_set_startup_query_intvl(&v->br_mcast_ctx, val);
594 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER]) {
597 val = nla_get_u8(tb[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER]);
598 err = br_multicast_set_querier(&v->br_mcast_ctx, val);
603 #if IS_ENABLED(CONFIG_IPV6)
604 if (tb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]) {
607 ver = nla_get_u8(tb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]);
608 err = br_multicast_set_mld_version(&v->br_mcast_ctx, ver);
615 if (tb[BRIDGE_VLANDB_GOPTS_MSTI]) {
618 msti = nla_get_u16(tb[BRIDGE_VLANDB_GOPTS_MSTI]);
619 err = br_mst_vlan_set_msti(v, msti);
628 static const struct nla_policy br_vlan_db_gpol[BRIDGE_VLANDB_GOPTS_MAX + 1] = {
629 [BRIDGE_VLANDB_GOPTS_ID] = { .type = NLA_U16 },
630 [BRIDGE_VLANDB_GOPTS_RANGE] = { .type = NLA_U16 },
631 [BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING] = { .type = NLA_U8 },
632 [BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION] = { .type = NLA_U8 },
633 [BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL] = { .type = NLA_U64 },
634 [BRIDGE_VLANDB_GOPTS_MCAST_QUERIER] = { .type = NLA_U8 },
635 [BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION] = { .type = NLA_U8 },
636 [BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT] = { .type = NLA_U32 },
637 [BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT] = { .type = NLA_U32 },
638 [BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_INTVL] = { .type = NLA_U64 },
639 [BRIDGE_VLANDB_GOPTS_MCAST_MEMBERSHIP_INTVL] = { .type = NLA_U64 },
640 [BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL] = { .type = NLA_U64 },
641 [BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL] = { .type = NLA_U64 },
642 [BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL] = { .type = NLA_U64 },
643 [BRIDGE_VLANDB_GOPTS_MSTI] = NLA_POLICY_MAX(NLA_U16, VLAN_N_VID - 1),
646 int br_vlan_rtm_process_global_options(struct net_device *dev,
647 const struct nlattr *attr,
649 struct netlink_ext_ack *extack)
651 struct net_bridge_vlan *v, *curr_start = NULL, *curr_end = NULL;
652 struct nlattr *tb[BRIDGE_VLANDB_GOPTS_MAX + 1];
653 struct net_bridge_vlan_group *vg;
654 u16 vid, vid_range = 0;
655 struct net_bridge *br;
658 if (cmd != RTM_NEWVLAN) {
659 NL_SET_ERR_MSG_MOD(extack, "Global vlan options support only set operation");
662 if (!netif_is_bridge_master(dev)) {
663 NL_SET_ERR_MSG_MOD(extack, "Global vlan options can only be set on bridge device");
666 br = netdev_priv(dev);
667 vg = br_vlan_group(br);
671 err = nla_parse_nested(tb, BRIDGE_VLANDB_GOPTS_MAX, attr,
672 br_vlan_db_gpol, extack);
676 if (!tb[BRIDGE_VLANDB_GOPTS_ID]) {
677 NL_SET_ERR_MSG_MOD(extack, "Missing vlan entry id");
680 vid = nla_get_u16(tb[BRIDGE_VLANDB_GOPTS_ID]);
681 if (!br_vlan_valid_id(vid, extack))
684 if (tb[BRIDGE_VLANDB_GOPTS_RANGE]) {
685 vid_range = nla_get_u16(tb[BRIDGE_VLANDB_GOPTS_RANGE]);
686 if (!br_vlan_valid_id(vid_range, extack))
688 if (vid >= vid_range) {
689 NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
696 for (; vid <= vid_range; vid++) {
697 bool changed = false;
699 v = br_vlan_find(vg, vid);
701 NL_SET_ERR_MSG_MOD(extack, "Vlan in range doesn't exist, can't process global options");
706 err = br_vlan_process_global_one_opts(br, vg, v, tb, &changed,
712 /* vlan options changed, check for range */
719 if (!br_vlan_global_opts_can_enter_range(v, curr_end)) {
720 br_vlan_global_opts_notify(br, curr_start->vid,
726 /* nothing changed and nothing to notify yet */
730 br_vlan_global_opts_notify(br, curr_start->vid,
737 br_vlan_global_opts_notify(br, curr_start->vid, curr_end->vid);