Skip to content

Commit ac3175f

Browse files
yoshfujidavem330
authored andcommitted
ndisc: Introduce __ipv6_neigh_lookup_noref().
This function, which looks up neighbour entry for an IPv6 address without touching refcnt, will be used for patches to remove dependency on rt->n (neighbour entry in rt6_info). Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dd0cbf2 commit ac3175f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

include/net/ndisc.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,13 @@ static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, _
148148
(p32[3] * hash_rnd[3]));
149149
}
150150

151-
static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey)
151+
static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
152152
{
153153
struct neigh_hash_table *nht;
154154
const u32 *p32 = pkey;
155155
struct neighbour *n;
156156
u32 hash_val;
157157

158-
rcu_read_lock_bh();
159158
nht = rcu_dereference_bh(nd_tbl.nht);
160159
hash_val = ndisc_hashfn(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
161160
for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
@@ -164,12 +163,21 @@ static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, cons
164163
u32 *n32 = (u32 *) n->primary_key;
165164
if (n->dev == dev &&
166165
((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
167-
(n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0) {
168-
if (!atomic_inc_not_zero(&n->refcnt))
169-
n = NULL;
170-
break;
171-
}
166+
(n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0)
167+
return n;
172168
}
169+
170+
return NULL;
171+
}
172+
173+
static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey)
174+
{
175+
struct neighbour *n;
176+
177+
rcu_read_lock_bh();
178+
n = __ipv6_neigh_lookup_noref(dev, pkey);
179+
if (n && !atomic_inc_not_zero(&n->refcnt))
180+
n = NULL;
173181
rcu_read_unlock_bh();
174182

175183
return n;

0 commit comments

Comments
 (0)