Skip to content

Commit 2796d84

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: vlan: convert mcast router global option to per-vlan entry
The per-vlan router option controls the port/vlan and host vlan entries' mcast router config. The global option controlled only the host vlan config, but that is unnecessary and incosistent as it's not really a global vlan option, but rather bridge option to control host router config, so convert BRIDGE_VLANDB_GOPTS_MCAST_ROUTER to BRIDGE_VLANDB_ENTRY_MCAST_ROUTER which can be used to control both host vlan and port vlan mcast router config. Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a53581d commit 2796d84

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ enum {
506506
BRIDGE_VLANDB_ENTRY_STATE,
507507
BRIDGE_VLANDB_ENTRY_TUNNEL_INFO,
508508
BRIDGE_VLANDB_ENTRY_STATS,
509+
BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
509510
__BRIDGE_VLANDB_ENTRY_MAX,
510511
};
511512
#define BRIDGE_VLANDB_ENTRY_MAX (__BRIDGE_VLANDB_ENTRY_MAX - 1)
@@ -561,7 +562,6 @@ enum {
561562
BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL,
562563
BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL,
563564
BRIDGE_VLANDB_GOPTS_MCAST_QUERIER,
564-
BRIDGE_VLANDB_GOPTS_MCAST_ROUTER,
565565
BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS,
566566
BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE,
567567
__BRIDGE_VLANDB_GOPTS_MAX

net/bridge/br_multicast.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,6 +4310,19 @@ int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx,
43104310
return err;
43114311
}
43124312

4313+
int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router)
4314+
{
4315+
int err;
4316+
4317+
if (br_vlan_is_master(v))
4318+
err = br_multicast_set_router(&v->br_mcast_ctx, mcast_router);
4319+
else
4320+
err = br_multicast_set_port_router(&v->port_mcast_ctx,
4321+
mcast_router);
4322+
4323+
return err;
4324+
}
4325+
43134326
static void br_multicast_start_querier(struct net_bridge_mcast *brmctx,
43144327
struct bridge_mcast_own_query *query)
43154328
{

net/bridge/br_private.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,20 @@ static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
676676
return true;
677677
}
678678

679+
static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v)
680+
{
681+
u8 mcast_router = MDB_RTR_TYPE_DISABLED;
682+
683+
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
684+
if (!br_vlan_is_master(v))
685+
mcast_router = v->port_mcast_ctx.multicast_router;
686+
else
687+
mcast_router = v->br_mcast_ctx.multicast_router;
688+
#endif
689+
690+
return mcast_router;
691+
}
692+
679693
static inline int br_afspec_cmd_to_rtm(int cmd)
680694
{
681695
switch (cmd) {
@@ -881,6 +895,7 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb,
881895
int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val);
882896
int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx,
883897
unsigned long val);
898+
int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router);
884899
int br_multicast_toggle(struct net_bridge *br, unsigned long val,
885900
struct netlink_ext_ack *extack);
886901
int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val);

net/bridge/br_vlan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ static const struct nla_policy br_vlan_db_policy[BRIDGE_VLANDB_ENTRY_MAX + 1] =
21362136
[BRIDGE_VLANDB_ENTRY_RANGE] = { .type = NLA_U16 },
21372137
[BRIDGE_VLANDB_ENTRY_STATE] = { .type = NLA_U8 },
21382138
[BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] = { .type = NLA_NESTED },
2139+
[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER] = { .type = NLA_U8 },
21392140
};
21402141

21412142
static int br_vlan_rtm_process_one(struct net_device *dev,

net/bridge/br_vlan_options.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,38 @@ static bool __vlan_tun_can_enter_range(const struct net_bridge_vlan *v_curr,
4040
bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
4141
const struct net_bridge_vlan *range_end)
4242
{
43+
u8 range_mc_rtr = br_vlan_multicast_router(range_end);
44+
u8 curr_mc_rtr = br_vlan_multicast_router(v_curr);
45+
4346
return v_curr->state == range_end->state &&
44-
__vlan_tun_can_enter_range(v_curr, range_end);
47+
__vlan_tun_can_enter_range(v_curr, range_end) &&
48+
curr_mc_rtr == range_mc_rtr;
4549
}
4650

4751
bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v)
4852
{
49-
return !nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_STATE,
50-
br_vlan_get_state(v)) &&
51-
__vlan_tun_put(skb, v);
53+
if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_STATE, br_vlan_get_state(v)) ||
54+
!__vlan_tun_put(skb, v))
55+
return false;
56+
57+
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
58+
if (nla_put_u8(skb, BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
59+
br_vlan_multicast_router(v)))
60+
return false;
61+
#endif
62+
63+
return true;
5264
}
5365

5466
size_t br_vlan_opts_nl_size(void)
5567
{
5668
return nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_STATE */
5769
+ nla_total_size(0) /* BRIDGE_VLANDB_ENTRY_TUNNEL_INFO */
58-
+ nla_total_size(sizeof(u32)); /* BRIDGE_VLANDB_TINFO_ID */
70+
+ nla_total_size(sizeof(u32)) /* BRIDGE_VLANDB_TINFO_ID */
71+
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
72+
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_ENTRY_MCAST_ROUTER */
73+
#endif
74+
+ 0;
5975
}
6076

6177
static int br_vlan_modify_state(struct net_bridge_vlan_group *vg,
@@ -181,6 +197,18 @@ static int br_vlan_process_one_opts(const struct net_bridge *br,
181197
return err;
182198
}
183199

200+
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
201+
if (tb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]) {
202+
u8 val;
203+
204+
val = nla_get_u8(tb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]);
205+
err = br_multicast_set_vlan_router(v, val);
206+
if (err)
207+
return err;
208+
*changed = true;
209+
}
210+
#endif
211+
184212
return 0;
185213
}
186214

@@ -298,8 +326,6 @@ bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
298326
v_opts->br_mcast_ctx.multicast_startup_query_count) ||
299327
nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_QUERIER,
300328
v_opts->br_mcast_ctx.multicast_querier) ||
301-
nla_put_u8(skb, BRIDGE_VLANDB_GOPTS_MCAST_ROUTER,
302-
v_opts->br_mcast_ctx.multicast_router) ||
303329
br_multicast_dump_querier_state(skb, &v_opts->br_mcast_ctx,
304330
BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE))
305331
goto out_err;
@@ -380,7 +406,6 @@ static size_t rtnl_vlan_global_opts_nlmsg_size(const struct net_bridge_vlan *v)
380406
+ nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL */
381407
+ nla_total_size(sizeof(u64)) /* BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL */
382408
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER */
383-
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER */
384409
+ br_multicast_querier_state_size() /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE */
385410
+ nla_total_size(0) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
386411
+ br_rports_size(&v->br_mcast_ctx) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
@@ -522,15 +547,6 @@ static int br_vlan_process_global_one_opts(const struct net_bridge *br,
522547
return err;
523548
*changed = true;
524549
}
525-
if (tb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER]) {
526-
u8 val;
527-
528-
val = nla_get_u8(tb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER]);
529-
err = br_multicast_set_router(&v->br_mcast_ctx, val);
530-
if (err)
531-
return err;
532-
*changed = true;
533-
}
534550
#if IS_ENABLED(CONFIG_IPV6)
535551
if (tb[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION]) {
536552
u8 ver;
@@ -554,7 +570,6 @@ static const struct nla_policy br_vlan_db_gpol[BRIDGE_VLANDB_GOPTS_MAX + 1] = {
554570
[BRIDGE_VLANDB_GOPTS_MCAST_MLD_VERSION] = { .type = NLA_U8 },
555571
[BRIDGE_VLANDB_GOPTS_MCAST_QUERY_INTVL] = { .type = NLA_U64 },
556572
[BRIDGE_VLANDB_GOPTS_MCAST_QUERIER] = { .type = NLA_U8 },
557-
[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER] = { .type = NLA_U8 },
558573
[BRIDGE_VLANDB_GOPTS_MCAST_IGMP_VERSION] = { .type = NLA_U8 },
559574
[BRIDGE_VLANDB_GOPTS_MCAST_LAST_MEMBER_CNT] = { .type = NLA_U32 },
560575
[BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_CNT] = { .type = NLA_U32 },

0 commit comments

Comments
 (0)