Skip to content

Commit 05d6f38

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: vlan: account for router port lists when notifying
When sending a global vlan notification we should account for the number of router ports when allocating the skb, otherwise we might end up losing notifications. Fixes: dc00287 ("net: bridge: vlan: use br_rports_fill_info() to export mcast router ports") Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b92dace commit 05d6f38

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

net/bridge/br_mdb.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ br_ip6_rports_get_timer(struct net_bridge_mcast_port *pmctx,
3737
#endif
3838
}
3939

40+
static size_t __br_rports_one_size(void)
41+
{
42+
return nla_total_size(sizeof(u32)) + /* MDBA_ROUTER_PORT */
43+
nla_total_size(sizeof(u32)) + /* MDBA_ROUTER_PATTR_TIMER */
44+
nla_total_size(sizeof(u8)) + /* MDBA_ROUTER_PATTR_TYPE */
45+
nla_total_size(sizeof(u32)) + /* MDBA_ROUTER_PATTR_INET_TIMER */
46+
nla_total_size(sizeof(u32)) + /* MDBA_ROUTER_PATTR_INET6_TIMER */
47+
nla_total_size(sizeof(u32)); /* MDBA_ROUTER_PATTR_VID */
48+
}
49+
50+
size_t br_rports_size(const struct net_bridge_mcast *brmctx)
51+
{
52+
struct net_bridge_mcast_port *pmctx;
53+
size_t size = nla_total_size(0); /* MDBA_ROUTER */
54+
55+
rcu_read_lock();
56+
hlist_for_each_entry_rcu(pmctx, &brmctx->ip4_mc_router_list,
57+
ip4_rlist)
58+
size += __br_rports_one_size();
59+
60+
#if IS_ENABLED(CONFIG_IPV6)
61+
hlist_for_each_entry_rcu(pmctx, &brmctx->ip6_mc_router_list,
62+
ip6_rlist)
63+
size += __br_rports_one_size();
64+
#endif
65+
rcu_read_unlock();
66+
67+
return size;
68+
}
69+
4070
int br_rports_fill_info(struct sk_buff *skb,
4171
const struct net_bridge_mcast *brmctx)
4272
{

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ int br_multicast_dump_querier_state(struct sk_buff *skb,
952952
const struct net_bridge_mcast *brmctx,
953953
int nest_attr);
954954
size_t br_multicast_querier_state_size(void);
955+
size_t br_rports_size(const struct net_bridge_mcast *brmctx);
955956

956957
static inline bool br_group_is_l2(const struct br_ip *group)
957958
{

net/bridge/br_vlan_options.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
362362
return false;
363363
}
364364

365-
static size_t rtnl_vlan_global_opts_nlmsg_size(void)
365+
static size_t rtnl_vlan_global_opts_nlmsg_size(const struct net_bridge_vlan *v)
366366
{
367367
return NLMSG_ALIGN(sizeof(struct br_vlan_msg))
368368
+ nla_total_size(0) /* BRIDGE_VLANDB_GLOBAL_OPTIONS */
@@ -382,6 +382,8 @@ static size_t rtnl_vlan_global_opts_nlmsg_size(void)
382382
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER */
383383
+ nla_total_size(sizeof(u8)) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER */
384384
+ br_multicast_querier_state_size() /* BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE */
385+
+ nla_total_size(0) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
386+
+ br_rports_size(&v->br_mcast_ctx) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */
385387
#endif
386388
+ nla_total_size(sizeof(u16)); /* BRIDGE_VLANDB_GOPTS_RANGE */
387389
}
@@ -398,7 +400,12 @@ static void br_vlan_global_opts_notify(const struct net_bridge *br,
398400
/* right now notifications are done only with rtnl held */
399401
ASSERT_RTNL();
400402

401-
skb = nlmsg_new(rtnl_vlan_global_opts_nlmsg_size(), GFP_KERNEL);
403+
/* need to find the vlan due to flags/options */
404+
v = br_vlan_find(br_vlan_group(br), vid);
405+
if (!v)
406+
return;
407+
408+
skb = nlmsg_new(rtnl_vlan_global_opts_nlmsg_size(v), GFP_KERNEL);
402409
if (!skb)
403410
goto out_err;
404411

@@ -411,11 +418,6 @@ static void br_vlan_global_opts_notify(const struct net_bridge *br,
411418
bvm->family = AF_BRIDGE;
412419
bvm->ifindex = br->dev->ifindex;
413420

414-
/* need to find the vlan due to flags/options */
415-
v = br_vlan_find(br_vlan_group(br), vid);
416-
if (!v)
417-
goto out_kfree;
418-
419421
if (!br_vlan_global_opts_fill(skb, vid, vid_range, v))
420422
goto out_err;
421423

@@ -425,7 +427,6 @@ static void br_vlan_global_opts_notify(const struct net_bridge *br,
425427

426428
out_err:
427429
rtnl_set_sk_err(dev_net(br->dev), RTNLGRP_BRVLAN, err);
428-
out_kfree:
429430
kfree_skb(skb);
430431
}
431432

0 commit comments

Comments
 (0)