Commit 8d23a54f authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: bridge: switchdev: differentiate new VLANs from changed ones

br_switchdev_port_vlan_add() currently emits a SWITCHDEV_PORT_OBJ_ADD
event with a SWITCHDEV_OBJ_ID_PORT_VLAN for 2 distinct cases:

- a struct net_bridge_vlan got created
- an existing struct net_bridge_vlan was modified

This makes it impossible for switchdev drivers to properly balance
PORT_OBJ_ADD with PORT_OBJ_DEL events, so if we want to allow that to
happen, we must provide a way for drivers to distinguish between a
VLAN with changed flags and a new one.

Annotate struct switchdev_obj_port_vlan with a "bool changed" that
distinguishes the 2 cases above.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 27c5f74c
...@@ -81,6 +81,13 @@ struct switchdev_obj_port_vlan { ...@@ -81,6 +81,13 @@ struct switchdev_obj_port_vlan {
struct switchdev_obj obj; struct switchdev_obj obj;
u16 flags; u16 flags;
u16 vid; u16 vid;
/* If set, the notifier signifies a change of one of the following
* flags for a VLAN that already exists:
* - BRIDGE_VLAN_INFO_PVID
* - BRIDGE_VLAN_INFO_UNTAGGED
* Entries with BRIDGE_VLAN_INFO_BRENTRY unset are not notified at all.
*/
bool changed;
}; };
#define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \ #define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \
......
...@@ -1985,7 +1985,7 @@ void br_switchdev_mdb_notify(struct net_device *dev, ...@@ -1985,7 +1985,7 @@ void br_switchdev_mdb_notify(struct net_device *dev,
struct net_bridge_port_group *pg, struct net_bridge_port_group *pg,
int type); int type);
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
struct netlink_ext_ack *extack); bool changed, struct netlink_ext_ack *extack);
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
void br_switchdev_init(struct net_bridge *br); void br_switchdev_init(struct net_bridge *br);
...@@ -2052,8 +2052,8 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, ...@@ -2052,8 +2052,8 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
return 0; return 0;
} }
static inline int br_switchdev_port_vlan_add(struct net_device *dev, static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid,
u16 vid, u16 flags, u16 flags, bool changed,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -160,13 +160,14 @@ br_switchdev_fdb_notify(struct net_bridge *br, ...@@ -160,13 +160,14 @@ br_switchdev_fdb_notify(struct net_bridge *br,
} }
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
struct netlink_ext_ack *extack) bool changed, struct netlink_ext_ack *extack)
{ {
struct switchdev_obj_port_vlan v = { struct switchdev_obj_port_vlan v = {
.obj.orig_dev = dev, .obj.orig_dev = dev,
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
.flags = flags, .flags = flags,
.vid = vid, .vid = vid,
.changed = changed,
}; };
return switchdev_port_obj_add(dev, &v.obj, extack); return switchdev_port_obj_add(dev, &v.obj, extack);
......
...@@ -109,7 +109,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, ...@@ -109,7 +109,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
/* Try switchdev op first. In case it is not supported, fallback to /* Try switchdev op first. In case it is not supported, fallback to
* 8021q add. * 8021q add.
*/ */
err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack); err = br_switchdev_port_vlan_add(dev, v->vid, flags, false, extack);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
return vlan_vid_add(dev, br->vlan_proto, v->vid); return vlan_vid_add(dev, br->vlan_proto, v->vid);
v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV; v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV;
...@@ -303,7 +303,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, ...@@ -303,7 +303,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags,
} else { } else {
if (br_vlan_should_use(v)) { if (br_vlan_should_use(v)) {
err = br_switchdev_port_vlan_add(dev, v->vid, flags, err = br_switchdev_port_vlan_add(dev, v->vid, flags,
extack); false, extack);
if (err && err != -EOPNOTSUPP) if (err && err != -EOPNOTSUPP)
goto out; goto out;
} }
...@@ -714,7 +714,7 @@ static int br_vlan_add_existing(struct net_bridge *br, ...@@ -714,7 +714,7 @@ static int br_vlan_add_existing(struct net_bridge *br,
*/ */
if (becomes_brentry || would_change) { if (becomes_brentry || would_change) {
err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags, err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags,
extack); would_change, extack);
if (err && err != -EOPNOTSUPP) if (err && err != -EOPNOTSUPP)
return err; return err;
} }
...@@ -1289,8 +1289,8 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, ...@@ -1289,8 +1289,8 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
if (would_change) { if (would_change) {
/* Pass the flags to the hardware bridge */ /* Pass the flags to the hardware bridge */
ret = br_switchdev_port_vlan_add(port->dev, vid, ret = br_switchdev_port_vlan_add(port->dev, vid, flags,
flags, extack); true, extack);
if (ret && ret != -EOPNOTSUPP) if (ret && ret != -EOPNOTSUPP)
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment