Skip to content

Commit d66e434

Browse files
pmachatadavem330
authored andcommitted
net: bridge: Extract boilerplate around switchdev_port_obj_*()
A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves initializing a struct switchdev_obj_port_vlan, a piece of code that repeats on each call site almost verbatim. While in the current codebase there is just one duplicated add call, the follow-up patches add more of both add and del calls. Thus to remove the duplication, extract the repetition into named functions and reuse. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 32d26a6 commit d66e434

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎net/bridge/br_private.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,8 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
11391139
unsigned long mask);
11401140
void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
11411141
int type);
1142+
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
1143+
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
11421144

11431145
static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
11441146
{
@@ -1168,6 +1170,17 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p,
11681170
return 0;
11691171
}
11701172

1173+
static inline int br_switchdev_port_vlan_add(struct net_device *dev,
1174+
u16 vid, u16 flags)
1175+
{
1176+
return -EOPNOTSUPP;
1177+
}
1178+
1179+
static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
1180+
{
1181+
return -EOPNOTSUPP;
1182+
}
1183+
11711184
static inline void
11721185
br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
11731186
{

‎net/bridge/br_switchdev.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,28 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
136136
break;
137137
}
138138
}
139+
140+
int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags)
141+
{
142+
struct switchdev_obj_port_vlan v = {
143+
.obj.orig_dev = dev,
144+
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
145+
.flags = flags,
146+
.vid_begin = vid,
147+
.vid_end = vid,
148+
};
149+
150+
return switchdev_port_obj_add(dev, &v.obj);
151+
}
152+
153+
int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid)
154+
{
155+
struct switchdev_obj_port_vlan v = {
156+
.obj.orig_dev = dev,
157+
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
158+
.vid_begin = vid,
159+
.vid_end = vid,
160+
};
161+
162+
return switchdev_port_obj_del(dev, &v.obj);
163+
}

‎net/bridge/br_vlan.c‎

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,12 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags)
8282
static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
8383
u16 vid, u16 flags)
8484
{
85-
struct switchdev_obj_port_vlan v = {
86-
.obj.orig_dev = dev,
87-
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
88-
.flags = flags,
89-
.vid_begin = vid,
90-
.vid_end = vid,
91-
};
9285
int err;
9386

9487
/* Try switchdev op first. In case it is not supported, fallback to
9588
* 8021q add.
9689
*/
97-
err = switchdev_port_obj_add(dev, &v.obj);
90+
err = br_switchdev_port_vlan_add(dev, vid, flags);
9891
if (err == -EOPNOTSUPP)
9992
return vlan_vid_add(dev, br->vlan_proto, vid);
10093
return err;
@@ -130,18 +123,12 @@ static void __vlan_del_list(struct net_bridge_vlan *v)
130123
static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
131124
u16 vid)
132125
{
133-
struct switchdev_obj_port_vlan v = {
134-
.obj.orig_dev = dev,
135-
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
136-
.vid_begin = vid,
137-
.vid_end = vid,
138-
};
139126
int err;
140127

141128
/* Try switchdev op first. In case it is not supported, fallback to
142129
* 8021q del.
143130
*/
144-
err = switchdev_port_obj_del(dev, &v.obj);
131+
err = br_switchdev_port_vlan_del(dev, vid);
145132
if (err == -EOPNOTSUPP) {
146133
vlan_vid_del(dev, br->vlan_proto, vid);
147134
return 0;
@@ -1053,13 +1040,6 @@ int nbp_vlan_init(struct net_bridge_port *p)
10531040
int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
10541041
bool *changed)
10551042
{
1056-
struct switchdev_obj_port_vlan v = {
1057-
.obj.orig_dev = port->dev,
1058-
.obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
1059-
.flags = flags,
1060-
.vid_begin = vid,
1061-
.vid_end = vid,
1062-
};
10631043
struct net_bridge_vlan *vlan;
10641044
int ret;
10651045

@@ -1069,7 +1049,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
10691049
vlan = br_vlan_find(nbp_vlan_group(port), vid);
10701050
if (vlan) {
10711051
/* Pass the flags to the hardware bridge */
1072-
ret = switchdev_port_obj_add(port->dev, &v.obj);
1052+
ret = br_switchdev_port_vlan_add(port->dev, vid, flags);
10731053
if (ret && ret != -EOPNOTSUPP)
10741054
return ret;
10751055
*changed = __vlan_add_flags(vlan, flags);

0 commit comments

Comments
 (0)