Skip to content

Commit 6869c3b

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: fdb: convert is_local to bitops
The patch adds a new fdb flags field in the hole between the two cache lines and uses it to convert is_local to bitops. Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8466a57 commit 6869c3b

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

‎net/bridge/br_fdb.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ void br_fdb_find_delete_local(struct net_bridge *br,
250250

251251
spin_lock_bh(&br->hash_lock);
252252
f = br_fdb_find(br, addr, vid);
253-
if (f && f->is_local && !f->added_by_user && f->dst == p)
253+
if (f && test_bit(BR_FDB_LOCAL, &f->flags) &&
254+
!f->added_by_user && f->dst == p)
254255
fdb_delete_local(br, p, f);
255256
spin_unlock_bh(&br->hash_lock);
256257
}
@@ -265,7 +266,8 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
265266
spin_lock_bh(&br->hash_lock);
266267
vg = nbp_vlan_group(p);
267268
hlist_for_each_entry(f, &br->fdb_list, fdb_node) {
268-
if (f->dst == p && f->is_local && !f->added_by_user) {
269+
if (f->dst == p && test_bit(BR_FDB_LOCAL, &f->flags) &&
270+
!f->added_by_user) {
269271
/* delete old one */
270272
fdb_delete_local(br, p, f);
271273

@@ -306,7 +308,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
306308

307309
/* If old entry was unassociated with any port, then delete it. */
308310
f = br_fdb_find(br, br->dev->dev_addr, 0);
309-
if (f && f->is_local && !f->dst && !f->added_by_user)
311+
if (f && test_bit(BR_FDB_LOCAL, &f->flags) &&
312+
!f->dst && !f->added_by_user)
310313
fdb_delete_local(br, NULL, f);
311314

312315
fdb_insert(br, NULL, newaddr, 0);
@@ -321,7 +324,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
321324
if (!br_vlan_should_use(v))
322325
continue;
323326
f = br_fdb_find(br, br->dev->dev_addr, v->vid);
324-
if (f && f->is_local && !f->dst && !f->added_by_user)
327+
if (f && test_bit(BR_FDB_LOCAL, &f->flags) &&
328+
!f->dst && !f->added_by_user)
325329
fdb_delete_local(br, NULL, f);
326330
fdb_insert(br, NULL, newaddr, v->vid);
327331
}
@@ -400,7 +404,7 @@ void br_fdb_delete_by_port(struct net_bridge *br,
400404
if (f->is_static || (vid && f->key.vlan_id != vid))
401405
continue;
402406

403-
if (f->is_local)
407+
if (test_bit(BR_FDB_LOCAL, &f->flags))
404408
fdb_delete_local(br, p, f);
405409
else
406410
fdb_delete(br, f, true);
@@ -469,7 +473,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf,
469473
fe->port_no = f->dst->port_no;
470474
fe->port_hi = f->dst->port_no >> 8;
471475

472-
fe->is_local = f->is_local;
476+
fe->is_local = test_bit(BR_FDB_LOCAL, &f->flags);
473477
if (!f->is_static)
474478
fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
475479
++fe;
@@ -494,7 +498,9 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
494498
memcpy(fdb->key.addr.addr, addr, ETH_ALEN);
495499
fdb->dst = source;
496500
fdb->key.vlan_id = vid;
497-
fdb->is_local = is_local;
501+
fdb->flags = 0;
502+
if (is_local)
503+
set_bit(BR_FDB_LOCAL, &fdb->flags);
498504
fdb->is_static = is_static;
499505
fdb->added_by_user = 0;
500506
fdb->added_by_external_learn = 0;
@@ -526,7 +532,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
526532
/* it is okay to have multiple ports with same
527533
* address, just use the first one.
528534
*/
529-
if (fdb->is_local)
535+
if (test_bit(BR_FDB_LOCAL, &fdb->flags))
530536
return 0;
531537
br_warn(br, "adding interface %s with same address as a received packet (addr:%pM, vlan:%u)\n",
532538
source ? source->dev->name : br->dev->name, addr, vid);
@@ -572,7 +578,7 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
572578
fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid);
573579
if (likely(fdb)) {
574580
/* attempt to update an entry for a local interface */
575-
if (unlikely(fdb->is_local)) {
581+
if (unlikely(test_bit(BR_FDB_LOCAL, &fdb->flags))) {
576582
if (net_ratelimit())
577583
br_warn(br, "received packet on %s with own address as source address (addr:%pM, vlan:%u)\n",
578584
source->dev->name, addr, vid);
@@ -616,7 +622,7 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
616622
static int fdb_to_nud(const struct net_bridge *br,
617623
const struct net_bridge_fdb_entry *fdb)
618624
{
619-
if (fdb->is_local)
625+
if (test_bit(BR_FDB_LOCAL, &fdb->flags))
620626
return NUD_PERMANENT;
621627
else if (fdb->is_static)
622628
return NUD_NOARP;
@@ -840,19 +846,19 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
840846

841847
if (fdb_to_nud(br, fdb) != state) {
842848
if (state & NUD_PERMANENT) {
843-
fdb->is_local = 1;
849+
set_bit(BR_FDB_LOCAL, &fdb->flags);
844850
if (!fdb->is_static) {
845851
fdb->is_static = 1;
846852
fdb_add_hw_addr(br, addr);
847853
}
848854
} else if (state & NUD_NOARP) {
849-
fdb->is_local = 0;
855+
clear_bit(BR_FDB_LOCAL, &fdb->flags);
850856
if (!fdb->is_static) {
851857
fdb->is_static = 1;
852858
fdb_add_hw_addr(br, addr);
853859
}
854860
} else {
855-
fdb->is_local = 0;
861+
clear_bit(BR_FDB_LOCAL, &fdb->flags);
856862
if (fdb->is_static) {
857863
fdb->is_static = 0;
858864
fdb_del_hw_addr(br, addr);

‎net/bridge/br_input.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
151151
if (dst) {
152152
unsigned long now = jiffies;
153153

154-
if (dst->is_local)
154+
if (test_bit(BR_FDB_LOCAL, &dst->flags))
155155
return br_pass_frame_up(skb);
156156

157157
if (now != dst->used)

‎net/bridge/br_private.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ struct net_bridge_vlan_group {
172172
u16 pvid;
173173
};
174174

175+
/* bridge fdb flags */
176+
enum {
177+
BR_FDB_LOCAL,
178+
};
179+
175180
struct net_bridge_fdb_key {
176181
mac_addr addr;
177182
u16 vlan_id;
@@ -183,8 +188,8 @@ struct net_bridge_fdb_entry {
183188

184189
struct net_bridge_fdb_key key;
185190
struct hlist_node fdb_node;
186-
unsigned char is_local:1,
187-
is_static:1,
191+
unsigned long flags;
192+
unsigned char is_static:1,
188193
is_sticky:1,
189194
added_by_user:1,
190195
added_by_external_learn:1,

0 commit comments

Comments
 (0)