diff options
author | David S. Miller <davem@davemloft.net> | 2011-12-28 15:41:23 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-12-28 15:41:23 -0500 |
commit | f83c7790dc0025fffbd8684f3803a7571f624baa (patch) | |
tree | 9e745f6b44b1947033a143423560af6a3157fce7 /include/net/ndisc.h | |
parent | 2c2aba6c561ac425602f4a0be61422224cb87151 (diff) |
ipv6: Create fast inline ipv6 neigh lookup just like ipv4.
Also, create and use an rt6_bind_neighbour() in net/ipv6/route.c to
consolidate some common logic.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/ndisc.h')
-rw-r--r-- | include/net/ndisc.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/include/net/ndisc.h b/include/net/ndisc.h index e9c30023b784..e3133c23980e 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -89,6 +89,33 @@ static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, _ (p32[3] * hash_rnd[3])); } +static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey) +{ + struct neigh_hash_table *nht; + const u32 *p32 = pkey; + struct neighbour *n; + u32 hash_val; + + rcu_read_lock_bh(); + nht = rcu_dereference_bh(tbl->nht); + hash_val = ndisc_hashfn(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)) { + u32 *n32 = (u32 *) n->primary_key; + if (n->dev == dev && + ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) | + (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0) { + if (!atomic_inc_not_zero(&n->refcnt)) + n = NULL; + break; + } + } + rcu_read_unlock_bh(); + + return n; +} + extern int ndisc_init(void); extern void ndisc_cleanup(void); |