Skip to content

Commit 22f67cd

Browse files
vladimirolteandavem330
authored andcommitted
net: bridge: add helper to replay VLANs installed on port
Currently this simple setup with DSA: ip link add br0 type bridge vlan_filtering 1 ip link add bond0 type bond ip link set bond0 master br0 ip link set swp0 master bond0 will not work because the bridge has created the PVID in br_add_if -> nbp_vlan_init, and it has notified switchdev of the existence of VLAN 1, but that was too early, since swp0 was not yet a lower of bond0, so it had no reason to act upon that notification. We need a helper in the bridge to replay the switchdev VLAN objects that were notified since the bridge port creation, because some of them may have been missed. As opposed to the br_mdb_replay function, the vg->vlan_list write side protection is offered by the rtnl_mutex which is sleepable, so we don't need to queue up the objects in atomic context, we can replay them right away. Signed-off-by: Vladimir Oltean <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 04846f9 commit 22f67cd

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

include/linux/if_bridge.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid);
111111
int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
112112
int br_vlan_get_info(const struct net_device *dev, u16 vid,
113113
struct bridge_vlan_info *p_vinfo);
114+
int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
115+
struct notifier_block *nb, struct netlink_ext_ack *extack);
114116
#else
115117
static inline bool br_vlan_enabled(const struct net_device *dev)
116118
{
@@ -137,6 +139,14 @@ static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
137139
{
138140
return -EINVAL;
139141
}
142+
143+
static inline int br_vlan_replay(struct net_device *br_dev,
144+
struct net_device *dev,
145+
struct notifier_block *nb,
146+
struct netlink_ext_ack *extack)
147+
{
148+
return -EOPNOTSUPP;
149+
}
140150
#endif
141151

142152
#if IS_ENABLED(CONFIG_BRIDGE)

net/bridge/br_vlan.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,79 @@ void br_vlan_notify(const struct net_bridge *br,
17511751
kfree_skb(skb);
17521752
}
17531753

1754+
static int br_vlan_replay_one(struct notifier_block *nb,
1755+
struct net_device *dev,
1756+
struct switchdev_obj_port_vlan *vlan,
1757+
struct netlink_ext_ack *extack)
1758+
{
1759+
struct switchdev_notifier_port_obj_info obj_info = {
1760+
.info = {
1761+
.dev = dev,
1762+
.extack = extack,
1763+
},
1764+
.obj = &vlan->obj,
1765+
};
1766+
int err;
1767+
1768+
err = nb->notifier_call(nb, SWITCHDEV_PORT_OBJ_ADD, &obj_info);
1769+
return notifier_to_errno(err);
1770+
}
1771+
1772+
int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
1773+
struct notifier_block *nb, struct netlink_ext_ack *extack)
1774+
{
1775+
struct net_bridge_vlan_group *vg;
1776+
struct net_bridge_vlan *v;
1777+
struct net_bridge_port *p;
1778+
struct net_bridge *br;
1779+
int err = 0;
1780+
u16 pvid;
1781+
1782+
ASSERT_RTNL();
1783+
1784+
if (!netif_is_bridge_master(br_dev))
1785+
return -EINVAL;
1786+
1787+
if (!netif_is_bridge_master(dev) && !netif_is_bridge_port(dev))
1788+
return -EINVAL;
1789+
1790+
if (netif_is_bridge_master(dev)) {
1791+
br = netdev_priv(dev);
1792+
vg = br_vlan_group(br);
1793+
p = NULL;
1794+
} else {
1795+
p = br_port_get_rtnl(dev);
1796+
if (WARN_ON(!p))
1797+
return -EINVAL;
1798+
vg = nbp_vlan_group(p);
1799+
br = p->br;
1800+
}
1801+
1802+
if (!vg)
1803+
return 0;
1804+
1805+
pvid = br_get_pvid(vg);
1806+
1807+
list_for_each_entry(v, &vg->vlan_list, vlist) {
1808+
struct switchdev_obj_port_vlan vlan = {
1809+
.obj.orig_dev = dev,
1810+
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
1811+
.flags = br_vlan_flags(v, pvid),
1812+
.vid = v->vid,
1813+
};
1814+
1815+
if (!br_vlan_should_use(v))
1816+
continue;
1817+
1818+
br_vlan_replay_one(nb, dev, &vlan, extack);
1819+
if (err)
1820+
return err;
1821+
}
1822+
1823+
return err;
1824+
}
1825+
EXPORT_SYMBOL_GPL(br_vlan_replay);
1826+
17541827
/* check if v_curr can enter a range ending in range_end */
17551828
bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
17561829
const struct net_bridge_vlan *range_end)

0 commit comments

Comments
 (0)