Skip to content

Commit

Permalink
net: bridge: allow the switchdev replay functions to be called for de…
Browse files Browse the repository at this point in the history
…letion

When a switchdev port leaves a LAG that is a bridge port, the switchdev
objects and port attributes offloaded to that port are not removed:

ip link add br0 type bridge
ip link add bond0 type bond mode 802.3ad
ip link set swp0 master bond0
ip link set bond0 master br0
bridge vlan add dev bond0 vid 100
ip link set swp0 nomaster

VLAN 100 will remain installed on swp0 despite it going into standalone
mode, because as far as the bridge is concerned, nothing ever happened
to its bridge port.

Let's extend the bridge vlan, fdb and mdb replay functions to take a
'bool adding' argument, and make DSA and ocelot call the replay
functions with 'adding' as false from the switchdev unsync path, for the
switch port that leaves the bridge.

Note that this patch in itself does not salvage anything, because in the
current pull mode of operation, DSA still needs to call the replay
helpers with adding=false. This will be done in another patch.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed Jun 28, 2021
1 parent bdf123b commit 7e8c185
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
4 changes: 2 additions & 2 deletions drivers/net/ethernet/mscc/ocelot_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,12 @@ static int ocelot_switchdev_sync(struct ocelot *ocelot, int port,
ageing_time = br_get_ageing_time(bridge_dev);
ocelot_port_attr_ageing_set(ocelot, port, ageing_time);

err = br_mdb_replay(bridge_dev, brport_dev, priv,
err = br_mdb_replay(bridge_dev, brport_dev, priv, true,
&ocelot_switchdev_blocking_nb, extack);
if (err && err != -EOPNOTSUPP)
return err;

err = br_vlan_replay(bridge_dev, brport_dev, priv,
err = br_vlan_replay(bridge_dev, brport_dev, priv, true,
&ocelot_switchdev_blocking_nb, extack);
if (err && err != -EOPNOTSUPP)
return err;
Expand Down
12 changes: 6 additions & 6 deletions include/linux/if_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
bool br_multicast_enabled(const struct net_device *dev);
bool br_multicast_router(const struct net_device *dev);
int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
const void *ctx, struct notifier_block *nb,
const void *ctx, bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack);
#else
static inline int br_multicast_list_adjacent(struct net_device *dev,
Expand Down Expand Up @@ -106,7 +106,7 @@ static inline bool br_multicast_router(const struct net_device *dev)
}
static inline int br_mdb_replay(const struct net_device *br_dev,
const struct net_device *dev, const void *ctx,
struct notifier_block *nb,
bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return -EOPNOTSUPP;
Expand All @@ -121,7 +121,7 @@ int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
int br_vlan_get_info(const struct net_device *dev, u16 vid,
struct bridge_vlan_info *p_vinfo);
int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
const void *ctx, struct notifier_block *nb,
const void *ctx, bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack);
#else
static inline bool br_vlan_enabled(const struct net_device *dev)
Expand Down Expand Up @@ -152,7 +152,7 @@ static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,

static inline int br_vlan_replay(struct net_device *br_dev,
struct net_device *dev, const void *ctx,
struct notifier_block *nb,
bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return -EOPNOTSUPP;
Expand All @@ -168,7 +168,7 @@ bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
u8 br_port_get_stp_state(const struct net_device *dev);
clock_t br_get_ageing_time(const struct net_device *br_dev);
int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev,
const void *ctx, struct notifier_block *nb);
const void *ctx, bool adding, struct notifier_block *nb);
#else
static inline struct net_device *
br_fdb_find_port(const struct net_device *br_dev,
Expand Down Expand Up @@ -200,7 +200,7 @@ static inline clock_t br_get_ageing_time(const struct net_device *br_dev)

static inline int br_fdb_replay(const struct net_device *br_dev,
const struct net_device *dev, const void *ctx,
struct notifier_block *nb)
bool adding, struct notifier_block *nb)
{
return -EOPNOTSUPP;
}
Expand Down
15 changes: 11 additions & 4 deletions net/bridge/br_fdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ static inline size_t fdb_nlmsg_size(void)

static int br_fdb_replay_one(struct notifier_block *nb,
const struct net_bridge_fdb_entry *fdb,
struct net_device *dev, const void *ctx)
struct net_device *dev, unsigned long action,
const void *ctx)
{
struct switchdev_notifier_fdb_info item;
int err;
Expand All @@ -741,22 +742,28 @@ static int br_fdb_replay_one(struct notifier_block *nb,
item.info.dev = dev;
item.info.ctx = ctx;

err = nb->notifier_call(nb, SWITCHDEV_FDB_ADD_TO_DEVICE, &item);
err = nb->notifier_call(nb, action, &item);
return notifier_to_errno(err);
}

int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev,
const void *ctx, struct notifier_block *nb)
const void *ctx, bool adding, struct notifier_block *nb)
{
struct net_bridge_fdb_entry *fdb;
struct net_bridge *br;
unsigned long action;
int err = 0;

if (!netif_is_bridge_master(br_dev) || !netif_is_bridge_port(dev))
return -EINVAL;

br = netdev_priv(br_dev);

if (adding)
action = SWITCHDEV_FDB_ADD_TO_DEVICE;
else
action = SWITCHDEV_FDB_DEL_TO_DEVICE;

rcu_read_lock();

hlist_for_each_entry_rcu(fdb, &br->fdb_list, fdb_node) {
Expand All @@ -767,7 +774,7 @@ int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev,
if (dst_dev != br_dev && dst_dev != dev)
continue;

err = br_fdb_replay_one(nb, fdb, dst_dev, ctx);
err = br_fdb_replay_one(nb, fdb, dst_dev, action, ctx);
if (err)
break;
}
Expand Down
15 changes: 11 additions & 4 deletions net/bridge/br_mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ static void br_switchdev_mdb_populate(struct switchdev_obj_port_mdb *mdb,

static int br_mdb_replay_one(struct notifier_block *nb, struct net_device *dev,
const struct switchdev_obj_port_mdb *mdb,
const void *ctx, struct netlink_ext_ack *extack)
unsigned long action, const void *ctx,
struct netlink_ext_ack *extack)
{
struct switchdev_notifier_port_obj_info obj_info = {
.info = {
Expand All @@ -580,7 +581,7 @@ static int br_mdb_replay_one(struct notifier_block *nb, struct net_device *dev,
};
int err;

err = nb->notifier_call(nb, SWITCHDEV_PORT_OBJ_ADD, &obj_info);
err = nb->notifier_call(nb, action, &obj_info);
return notifier_to_errno(err);
}

Expand All @@ -604,12 +605,13 @@ static int br_mdb_queue_one(struct list_head *mdb_list,
}

int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
const void *ctx, struct notifier_block *nb,
const void *ctx, bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
const struct net_bridge_mdb_entry *mp;
struct switchdev_obj *obj, *tmp;
struct net_bridge *br;
unsigned long action;
LIST_HEAD(mdb_list);
int err = 0;

Expand Down Expand Up @@ -664,9 +666,14 @@ int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,

rcu_read_unlock();

if (adding)
action = SWITCHDEV_PORT_OBJ_ADD;
else
action = SWITCHDEV_PORT_OBJ_DEL;

list_for_each_entry(obj, &mdb_list, list) {
err = br_mdb_replay_one(nb, dev, SWITCHDEV_OBJ_PORT_MDB(obj),
ctx, extack);
action, ctx, extack);
if (err)
goto out_free_mdb;
}
Expand Down
15 changes: 11 additions & 4 deletions net/bridge/br_vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,8 @@ void br_vlan_notify(const struct net_bridge *br,
static int br_vlan_replay_one(struct notifier_block *nb,
struct net_device *dev,
struct switchdev_obj_port_vlan *vlan,
const void *ctx, struct netlink_ext_ack *extack)
const void *ctx, unsigned long action,
struct netlink_ext_ack *extack)
{
struct switchdev_notifier_port_obj_info obj_info = {
.info = {
Expand All @@ -1819,18 +1820,19 @@ static int br_vlan_replay_one(struct notifier_block *nb,
};
int err;

err = nb->notifier_call(nb, SWITCHDEV_PORT_OBJ_ADD, &obj_info);
err = nb->notifier_call(nb, action, &obj_info);
return notifier_to_errno(err);
}

int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
const void *ctx, struct notifier_block *nb,
const void *ctx, bool adding, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
struct net_bridge_vlan_group *vg;
struct net_bridge_vlan *v;
struct net_bridge_port *p;
struct net_bridge *br;
unsigned long action;
int err = 0;
u16 pvid;

Expand All @@ -1857,6 +1859,11 @@ int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
if (!vg)
return 0;

if (adding)
action = SWITCHDEV_PORT_OBJ_ADD;
else
action = SWITCHDEV_PORT_OBJ_DEL;

pvid = br_get_pvid(vg);

list_for_each_entry(v, &vg->vlan_list, vlist) {
Expand All @@ -1870,7 +1877,7 @@ int br_vlan_replay(struct net_device *br_dev, struct net_device *dev,
if (!br_vlan_should_use(v))
continue;

err = br_vlan_replay_one(nb, dev, &vlan, ctx, extack);
err = br_vlan_replay_one(nb, dev, &vlan, ctx, action, extack);
if (err)
return err;
}
Expand Down
13 changes: 6 additions & 7 deletions net/dsa/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ static int dsa_port_switchdev_sync(struct dsa_port *dp,
if (err && err != -EOPNOTSUPP)
return err;

err = br_mdb_replay(br, brport_dev, dp,
&dsa_slave_switchdev_blocking_notifier,
extack);
err = br_mdb_replay(br, brport_dev, dp, true,
&dsa_slave_switchdev_blocking_notifier, extack);
if (err && err != -EOPNOTSUPP)
return err;

err = br_fdb_replay(br, brport_dev, dp, &dsa_slave_switchdev_notifier);
err = br_fdb_replay(br, brport_dev, dp, true,
&dsa_slave_switchdev_notifier);
if (err && err != -EOPNOTSUPP)
return err;

err = br_vlan_replay(br, brport_dev, dp,
&dsa_slave_switchdev_blocking_notifier,
extack);
err = br_vlan_replay(br, brport_dev, dp, true,
&dsa_slave_switchdev_blocking_notifier, extack);
if (err && err != -EOPNOTSUPP)
return err;

Expand Down

0 comments on commit 7e8c185

Please sign in to comment.