Skip to content

Commit 6be144f

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
bridge: vlan: use br_vlan_should_use to simplify __vlan_add/del
The checks that lead to num_vlans change are always what br_vlan_should_use checks for, namely if the vlan is only a context or not and depending on that it's either not counted or counted as a real/used vlan respectively. Also give better explanation in br_vlan_should_use's comment. Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2ffdf50 commit 6be144f

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

net/bridge/br_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
400400
return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
401401
}
402402

403-
/* check if we should use the vlan entry is usable */
403+
/* check if we should use the vlan entry, returns false if it's only context */
404404
static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
405405
{
406406
if (br_vlan_is_master(v)) {

net/bridge/br_vlan.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,20 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
195195
{
196196
struct net_bridge_vlan *masterv = NULL;
197197
struct net_bridge_port *p = NULL;
198-
struct rhashtable *tbl;
198+
struct net_bridge_vlan_group *vg;
199199
struct net_device *dev;
200200
struct net_bridge *br;
201201
int err;
202202

203203
if (br_vlan_is_master(v)) {
204204
br = v->br;
205205
dev = br->dev;
206-
tbl = &br->vlgrp->vlan_hash;
206+
vg = br->vlgrp;
207207
} else {
208208
p = v->port;
209209
br = p->br;
210210
dev = p->dev;
211-
tbl = &p->vlgrp->vlan_hash;
211+
vg = p->vlgrp;
212212
}
213213

214214
if (p) {
@@ -234,32 +234,31 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
234234
v->brvlan = masterv;
235235
}
236236

237-
/* Add the dev mac only if it's a usable vlan */
237+
/* Add the dev mac and count the vlan only if it's usable */
238238
if (br_vlan_should_use(v)) {
239239
err = br_fdb_insert(br, p, dev->dev_addr, v->vid);
240240
if (err) {
241241
br_err(br, "failed insert local address into bridge forwarding table\n");
242242
goto out_filt;
243243
}
244+
vg->num_vlans++;
244245
}
245246

246-
err = rhashtable_lookup_insert_fast(tbl, &v->vnode, br_vlan_rht_params);
247+
err = rhashtable_lookup_insert_fast(&vg->vlan_hash, &v->vnode,
248+
br_vlan_rht_params);
247249
if (err)
248250
goto out_fdb_insert;
249251

250252
__vlan_add_list(v);
251253
__vlan_add_flags(v, flags);
252-
if (br_vlan_is_master(v)) {
253-
if (br_vlan_is_brentry(v))
254-
br->vlgrp->num_vlans++;
255-
} else {
256-
p->vlgrp->num_vlans++;
257-
}
258254
out:
259255
return err;
260256

261257
out_fdb_insert:
262-
br_fdb_find_delete_local(br, p, br->dev->dev_addr, v->vid);
258+
if (br_vlan_should_use(v)) {
259+
br_fdb_find_delete_local(br, p, dev->dev_addr, v->vid);
260+
vg->num_vlans--;
261+
}
263262

264263
out_filt:
265264
if (p) {
@@ -278,15 +277,12 @@ static int __vlan_del(struct net_bridge_vlan *v)
278277
struct net_bridge_vlan *masterv = v;
279278
struct net_bridge_vlan_group *vg;
280279
struct net_bridge_port *p = NULL;
281-
struct net_bridge *br;
282280
int err = 0;
283281

284282
if (br_vlan_is_master(v)) {
285-
br = v->br;
286283
vg = v->br->vlgrp;
287284
} else {
288285
p = v->port;
289-
br = p->br;
290286
vg = v->port->vlgrp;
291287
masterv = v->brvlan;
292288
}
@@ -298,13 +294,9 @@ static int __vlan_del(struct net_bridge_vlan *v)
298294
goto out;
299295
}
300296

301-
if (br_vlan_is_master(v)) {
302-
if (br_vlan_is_brentry(v)) {
303-
v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY;
304-
br->vlgrp->num_vlans--;
305-
}
306-
} else {
307-
p->vlgrp->num_vlans--;
297+
if (br_vlan_should_use(v)) {
298+
v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY;
299+
vg->num_vlans--;
308300
}
309301

310302
if (masterv != v) {

0 commit comments

Comments
 (0)