neigh: Factor out ___neigh_lookup_noref
While looking at the mpls code I found myself writing yet another version of neigh_lookup_noref. We currently have __ipv4_lookup_noref and __ipv6_lookup_noref. So to make my work a little easier and to make it a smidge easier to verify/maintain the mpls code in the future I stopped and wrote ___neigh_lookup_noref. Then I rewote __ipv4_lookup_noref and __ipv6_lookup_noref in terms of this new function. I tested my new version by verifying that the same code is generated in ip_finish_output2 and ip6_finish_output2 where these functions are inlined. To get to ___neigh_lookup_noref I added a new neighbour cache table function key_eq. So that the static size of the key would be available. I also added __neigh_lookup_noref for people who want to to lookup a neighbour table entry quickly but don't know which neibhgour table they are going to look up. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
2f56f6be47
commit
60395a20ff
@@ -397,25 +397,15 @@ struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
|
||||
struct net_device *dev)
|
||||
{
|
||||
struct neighbour *n;
|
||||
int key_len = tbl->key_len;
|
||||
u32 hash_val;
|
||||
struct neigh_hash_table *nht;
|
||||
|
||||
NEIGH_CACHE_STAT_INC(tbl, lookups);
|
||||
|
||||
rcu_read_lock_bh();
|
||||
nht = rcu_dereference_bh(tbl->nht);
|
||||
hash_val = tbl->hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
|
||||
|
||||
for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
|
||||
n != NULL;
|
||||
n = rcu_dereference_bh(n->next)) {
|
||||
if (dev == n->dev && !memcmp(n->primary_key, pkey, key_len)) {
|
||||
if (!atomic_inc_not_zero(&n->refcnt))
|
||||
n = NULL;
|
||||
NEIGH_CACHE_STAT_INC(tbl, hits);
|
||||
break;
|
||||
}
|
||||
n = __neigh_lookup_noref(tbl, pkey, dev);
|
||||
if (n) {
|
||||
if (!atomic_inc_not_zero(&n->refcnt))
|
||||
n = NULL;
|
||||
NEIGH_CACHE_STAT_INC(tbl, hits);
|
||||
}
|
||||
|
||||
rcu_read_unlock_bh();
|
||||
|
Reference in New Issue
Block a user