Commit b5cd9f7c authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

net: bridge: fdb: convert added_by_external_learn to use bitops

Convert the added_by_external_learn field to a flag and use bitops.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ac3ca6af
...@@ -76,7 +76,7 @@ static inline int has_expired(const struct net_bridge *br, ...@@ -76,7 +76,7 @@ static inline int has_expired(const struct net_bridge *br,
const struct net_bridge_fdb_entry *fdb) const struct net_bridge_fdb_entry *fdb)
{ {
return !test_bit(BR_FDB_STATIC, &fdb->flags) && return !test_bit(BR_FDB_STATIC, &fdb->flags) &&
!fdb->added_by_external_learn && !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags) &&
time_before_eq(fdb->updated + hold_time(br), jiffies); time_before_eq(fdb->updated + hold_time(br), jiffies);
} }
...@@ -352,7 +352,7 @@ void br_fdb_cleanup(struct work_struct *work) ...@@ -352,7 +352,7 @@ void br_fdb_cleanup(struct work_struct *work)
unsigned long this_timer; unsigned long this_timer;
if (test_bit(BR_FDB_STATIC, &f->flags) || if (test_bit(BR_FDB_STATIC, &f->flags) ||
f->added_by_external_learn) test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags))
continue; continue;
this_timer = f->updated + delay; this_timer = f->updated + delay;
if (time_after(this_timer, now)) { if (time_after(this_timer, now)) {
...@@ -506,7 +506,6 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, ...@@ -506,7 +506,6 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
set_bit(BR_FDB_LOCAL, &fdb->flags); set_bit(BR_FDB_LOCAL, &fdb->flags);
if (is_static) if (is_static)
set_bit(BR_FDB_STATIC, &fdb->flags); set_bit(BR_FDB_STATIC, &fdb->flags);
fdb->added_by_external_learn = 0;
fdb->offloaded = 0; fdb->offloaded = 0;
fdb->updated = fdb->used = jiffies; fdb->updated = fdb->used = jiffies;
if (rhashtable_lookup_insert_fast(&br->fdb_hash_tbl, if (rhashtable_lookup_insert_fast(&br->fdb_hash_tbl,
...@@ -593,8 +592,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, ...@@ -593,8 +592,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
fdb->dst = source; fdb->dst = source;
fdb_modified = true; fdb_modified = true;
/* Take over HW learned entry */ /* Take over HW learned entry */
if (unlikely(fdb->added_by_external_learn)) test_and_clear_bit(BR_FDB_ADDED_BY_EXT_LEARN,
fdb->added_by_external_learn = 0; &fdb->flags);
} }
if (now != fdb->updated) if (now != fdb->updated)
fdb->updated = now; fdb->updated = now;
...@@ -659,7 +658,7 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br, ...@@ -659,7 +658,7 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
if (fdb->offloaded) if (fdb->offloaded)
ndm->ndm_flags |= NTF_OFFLOADED; ndm->ndm_flags |= NTF_OFFLOADED;
if (fdb->added_by_external_learn) if (test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
ndm->ndm_flags |= NTF_EXT_LEARNED; ndm->ndm_flags |= NTF_EXT_LEARNED;
if (test_bit(BR_FDB_STICKY, &fdb->flags)) if (test_bit(BR_FDB_STICKY, &fdb->flags))
ndm->ndm_flags |= NTF_STICKY; ndm->ndm_flags |= NTF_STICKY;
...@@ -1129,7 +1128,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, ...@@ -1129,7 +1128,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
} }
if (swdev_notify) if (swdev_notify)
set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
fdb->added_by_external_learn = 1; set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags);
fdb_notify(br, fdb, RTM_NEWNEIGH, swdev_notify); fdb_notify(br, fdb, RTM_NEWNEIGH, swdev_notify);
} else { } else {
fdb->updated = jiffies; fdb->updated = jiffies;
...@@ -1139,12 +1138,12 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, ...@@ -1139,12 +1138,12 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
modified = true; modified = true;
} }
if (fdb->added_by_external_learn) { if (test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
/* Refresh entry */ /* Refresh entry */
fdb->used = jiffies; fdb->used = jiffies;
} else if (!test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags)) { } else if (!test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags)) {
/* Take over SW learned entry */ /* Take over SW learned entry */
fdb->added_by_external_learn = 1; set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags);
modified = true; modified = true;
} }
...@@ -1171,7 +1170,7 @@ int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, ...@@ -1171,7 +1170,7 @@ int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
spin_lock_bh(&br->hash_lock); spin_lock_bh(&br->hash_lock);
fdb = br_fdb_find(br, addr, vid); fdb = br_fdb_find(br, addr, vid);
if (fdb && fdb->added_by_external_learn) if (fdb && test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
fdb_delete(br, fdb, swdev_notify); fdb_delete(br, fdb, swdev_notify);
else else
err = -ENOENT; err = -ENOENT;
......
...@@ -178,6 +178,7 @@ enum { ...@@ -178,6 +178,7 @@ enum {
BR_FDB_STATIC, BR_FDB_STATIC,
BR_FDB_STICKY, BR_FDB_STICKY,
BR_FDB_ADDED_BY_USER, BR_FDB_ADDED_BY_USER,
BR_FDB_ADDED_BY_EXT_LEARN,
}; };
struct net_bridge_fdb_key { struct net_bridge_fdb_key {
...@@ -192,8 +193,7 @@ struct net_bridge_fdb_entry { ...@@ -192,8 +193,7 @@ struct net_bridge_fdb_entry {
struct net_bridge_fdb_key key; struct net_bridge_fdb_key key;
struct hlist_node fdb_node; struct hlist_node fdb_node;
unsigned long flags; unsigned long flags;
unsigned char added_by_external_learn:1, unsigned char offloaded:1;
offloaded:1;
/* write-heavy members should not affect lookups */ /* write-heavy members should not affect lookups */
unsigned long updated ____cacheline_aligned_in_smp; unsigned long updated ____cacheline_aligned_in_smp;
......
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