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

net: bridge: fdb: convert is_static to bitops

Convert the is_static to bitops, make use of the combined
test_and_set/clear_bit to simplify expressions in fdb_add_entry.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6869c3b0
...@@ -75,8 +75,9 @@ static inline unsigned long hold_time(const struct net_bridge *br) ...@@ -75,8 +75,9 @@ static inline unsigned long hold_time(const struct net_bridge *br)
static inline int has_expired(const struct net_bridge *br, 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 !fdb->is_static && !fdb->added_by_external_learn && return !test_bit(BR_FDB_STATIC, &fdb->flags) &&
time_before_eq(fdb->updated + hold_time(br), jiffies); !fdb->added_by_external_learn &&
time_before_eq(fdb->updated + hold_time(br), jiffies);
} }
static void fdb_rcu_free(struct rcu_head *head) static void fdb_rcu_free(struct rcu_head *head)
...@@ -197,7 +198,7 @@ static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f, ...@@ -197,7 +198,7 @@ static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f,
{ {
trace_fdb_delete(br, f); trace_fdb_delete(br, f);
if (f->is_static) if (test_bit(BR_FDB_STATIC, &f->flags))
fdb_del_hw_addr(br, f->key.addr.addr); fdb_del_hw_addr(br, f->key.addr.addr);
hlist_del_init_rcu(&f->fdb_node); hlist_del_init_rcu(&f->fdb_node);
...@@ -350,7 +351,8 @@ void br_fdb_cleanup(struct work_struct *work) ...@@ -350,7 +351,8 @@ void br_fdb_cleanup(struct work_struct *work)
hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
unsigned long this_timer; unsigned long this_timer;
if (f->is_static || f->added_by_external_learn) if (test_bit(BR_FDB_STATIC, &f->flags) ||
f->added_by_external_learn)
continue; continue;
this_timer = f->updated + delay; this_timer = f->updated + delay;
if (time_after(this_timer, now)) { if (time_after(this_timer, now)) {
...@@ -377,7 +379,7 @@ void br_fdb_flush(struct net_bridge *br) ...@@ -377,7 +379,7 @@ void br_fdb_flush(struct net_bridge *br)
spin_lock_bh(&br->hash_lock); spin_lock_bh(&br->hash_lock);
hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) { hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) {
if (!f->is_static) if (!test_bit(BR_FDB_STATIC, &f->flags))
fdb_delete(br, f, true); fdb_delete(br, f, true);
} }
spin_unlock_bh(&br->hash_lock); spin_unlock_bh(&br->hash_lock);
...@@ -401,7 +403,8 @@ void br_fdb_delete_by_port(struct net_bridge *br, ...@@ -401,7 +403,8 @@ void br_fdb_delete_by_port(struct net_bridge *br,
continue; continue;
if (!do_all) if (!do_all)
if (f->is_static || (vid && f->key.vlan_id != vid)) if (test_bit(BR_FDB_STATIC, &f->flags) ||
(vid && f->key.vlan_id != vid))
continue; continue;
if (test_bit(BR_FDB_LOCAL, &f->flags)) if (test_bit(BR_FDB_LOCAL, &f->flags))
...@@ -474,7 +477,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf, ...@@ -474,7 +477,7 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf,
fe->port_hi = f->dst->port_no >> 8; fe->port_hi = f->dst->port_no >> 8;
fe->is_local = test_bit(BR_FDB_LOCAL, &f->flags); fe->is_local = test_bit(BR_FDB_LOCAL, &f->flags);
if (!f->is_static) if (!test_bit(BR_FDB_STATIC, &f->flags))
fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated); fe->ageing_timer_value = jiffies_delta_to_clock_t(jiffies - f->updated);
++fe; ++fe;
++num; ++num;
...@@ -501,7 +504,8 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, ...@@ -501,7 +504,8 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
fdb->flags = 0; fdb->flags = 0;
if (is_local) if (is_local)
set_bit(BR_FDB_LOCAL, &fdb->flags); set_bit(BR_FDB_LOCAL, &fdb->flags);
fdb->is_static = is_static; if (is_static)
set_bit(BR_FDB_STATIC, &fdb->flags);
fdb->added_by_user = 0; fdb->added_by_user = 0;
fdb->added_by_external_learn = 0; fdb->added_by_external_learn = 0;
fdb->offloaded = 0; fdb->offloaded = 0;
...@@ -624,7 +628,7 @@ static int fdb_to_nud(const struct net_bridge *br, ...@@ -624,7 +628,7 @@ static int fdb_to_nud(const struct net_bridge *br,
{ {
if (test_bit(BR_FDB_LOCAL, &fdb->flags)) if (test_bit(BR_FDB_LOCAL, &fdb->flags))
return NUD_PERMANENT; return NUD_PERMANENT;
else if (fdb->is_static) else if (test_bit(BR_FDB_STATIC, &fdb->flags))
return NUD_NOARP; return NUD_NOARP;
else if (has_expired(br, fdb)) else if (has_expired(br, fdb))
return NUD_STALE; return NUD_STALE;
...@@ -847,22 +851,16 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, ...@@ -847,22 +851,16 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
if (fdb_to_nud(br, fdb) != state) { if (fdb_to_nud(br, fdb) != state) {
if (state & NUD_PERMANENT) { if (state & NUD_PERMANENT) {
set_bit(BR_FDB_LOCAL, &fdb->flags); set_bit(BR_FDB_LOCAL, &fdb->flags);
if (!fdb->is_static) { if (!test_and_set_bit(BR_FDB_STATIC, &fdb->flags))
fdb->is_static = 1;
fdb_add_hw_addr(br, addr); fdb_add_hw_addr(br, addr);
}
} else if (state & NUD_NOARP) { } else if (state & NUD_NOARP) {
clear_bit(BR_FDB_LOCAL, &fdb->flags); clear_bit(BR_FDB_LOCAL, &fdb->flags);
if (!fdb->is_static) { if (!test_and_set_bit(BR_FDB_STATIC, &fdb->flags))
fdb->is_static = 1;
fdb_add_hw_addr(br, addr); fdb_add_hw_addr(br, addr);
}
} else { } else {
clear_bit(BR_FDB_LOCAL, &fdb->flags); clear_bit(BR_FDB_LOCAL, &fdb->flags);
if (fdb->is_static) { if (test_and_clear_bit(BR_FDB_STATIC, &fdb->flags))
fdb->is_static = 0;
fdb_del_hw_addr(br, addr); fdb_del_hw_addr(br, addr);
}
} }
modified = true; modified = true;
...@@ -1070,7 +1068,7 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p) ...@@ -1070,7 +1068,7 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p)
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
/* We only care for static entries */ /* We only care for static entries */
if (!f->is_static) if (!test_bit(BR_FDB_STATIC, &f->flags))
continue; continue;
err = dev_uc_add(p->dev, f->key.addr.addr); err = dev_uc_add(p->dev, f->key.addr.addr);
if (err) if (err)
...@@ -1084,7 +1082,7 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p) ...@@ -1084,7 +1082,7 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p)
rollback: rollback:
hlist_for_each_entry_rcu(tmp, &br->fdb_list, fdb_node) { hlist_for_each_entry_rcu(tmp, &br->fdb_list, fdb_node) {
/* We only care for static entries */ /* We only care for static entries */
if (!tmp->is_static) if (!test_bit(BR_FDB_STATIC, &tmp->flags))
continue; continue;
if (tmp == f) if (tmp == f)
break; break;
...@@ -1103,7 +1101,7 @@ void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p) ...@@ -1103,7 +1101,7 @@ void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p)
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) {
/* We only care for static entries */ /* We only care for static entries */
if (!f->is_static) if (!test_bit(BR_FDB_STATIC, &f->flags))
continue; continue;
dev_uc_del(p->dev, f->key.addr.addr); dev_uc_del(p->dev, f->key.addr.addr);
......
...@@ -175,6 +175,7 @@ struct net_bridge_vlan_group { ...@@ -175,6 +175,7 @@ struct net_bridge_vlan_group {
/* bridge fdb flags */ /* bridge fdb flags */
enum { enum {
BR_FDB_LOCAL, BR_FDB_LOCAL,
BR_FDB_STATIC,
}; };
struct net_bridge_fdb_key { struct net_bridge_fdb_key {
...@@ -189,8 +190,7 @@ struct net_bridge_fdb_entry { ...@@ -189,8 +190,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 is_static:1, unsigned char is_sticky:1,
is_sticky:1,
added_by_user:1, added_by_user:1,
added_by_external_learn:1, added_by_external_learn:1,
offloaded:1; offloaded:1;
......
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