Skip to content

Commit 8d23a54

Browse files
vladimirolteandavem330
authored andcommitted
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: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27c5f74 commit 8d23a54

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

include/net/switchdev.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ struct switchdev_obj_port_vlan {
8181
struct switchdev_obj obj;
8282
u16 flags;
8383
u16 vid;
84+
/* If set, the notifier signifies a change of one of the following
85+
* flags for a VLAN that already exists:
86+
* - BRIDGE_VLAN_INFO_PVID
87+
* - BRIDGE_VLAN_INFO_UNTAGGED
88+
* Entries with BRIDGE_VLAN_INFO_BRENTRY unset are not notified at all.
89+
*/
90+
bool changed;
8491
};
8592

8693
#define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \

net/bridge/br_private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ void br_switchdev_mdb_notify(struct net_device *dev,
19851985
struct net_bridge_port_group *pg,
19861986
int type);
19871987
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1988-
struct netlink_ext_ack *extack);
1988+
bool changed, struct netlink_ext_ack *extack);
19891989
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
19901990
void br_switchdev_init(struct net_bridge *br);
19911991

@@ -2052,8 +2052,8 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
20522052
return 0;
20532053
}
20542054

2055-
static inline int br_switchdev_port_vlan_add(struct net_device *dev,
2056-
u16 vid, u16 flags,
2055+
static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid,
2056+
u16 flags, bool changed,
20572057
struct netlink_ext_ack *extack)
20582058
{
20592059
return -EOPNOTSUPP;

net/bridge/br_switchdev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ br_switchdev_fdb_notify(struct net_bridge *br,
160160
}
161161

162162
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
163-
struct netlink_ext_ack *extack)
163+
bool changed, struct netlink_ext_ack *extack)
164164
{
165165
struct switchdev_obj_port_vlan v = {
166166
.obj.orig_dev = dev,
167167
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
168168
.flags = flags,
169169
.vid = vid,
170+
.changed = changed,
170171
};
171172

172173
return switchdev_port_obj_add(dev, &v.obj, extack);

net/bridge/br_vlan.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
109109
/* Try switchdev op first. In case it is not supported, fallback to
110110
* 8021q add.
111111
*/
112-
err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack);
112+
err = br_switchdev_port_vlan_add(dev, v->vid, flags, false, extack);
113113
if (err == -EOPNOTSUPP)
114114
return vlan_vid_add(dev, br->vlan_proto, v->vid);
115115
v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV;
@@ -303,7 +303,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags,
303303
} else {
304304
if (br_vlan_should_use(v)) {
305305
err = br_switchdev_port_vlan_add(dev, v->vid, flags,
306-
extack);
306+
false, extack);
307307
if (err && err != -EOPNOTSUPP)
308308
goto out;
309309
}
@@ -714,7 +714,7 @@ static int br_vlan_add_existing(struct net_bridge *br,
714714
*/
715715
if (becomes_brentry || would_change) {
716716
err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags,
717-
extack);
717+
would_change, extack);
718718
if (err && err != -EOPNOTSUPP)
719719
return err;
720720
}
@@ -1289,8 +1289,8 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
12891289

12901290
if (would_change) {
12911291
/* Pass the flags to the hardware bridge */
1292-
ret = br_switchdev_port_vlan_add(port->dev, vid,
1293-
flags, extack);
1292+
ret = br_switchdev_port_vlan_add(port->dev, vid, flags,
1293+
true, extack);
12941294
if (ret && ret != -EOPNOTSUPP)
12951295
return ret;
12961296
}

0 commit comments

Comments
 (0)