@@ -294,6 +294,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl)
294294
295295 skb_queue_head_init (& n -> arp_queue );
296296 rwlock_init (& n -> lock );
297+ seqlock_init (& n -> ha_lock );
297298 n -> updated = n -> used = now ;
298299 n -> nud_state = NUD_NONE ;
299300 n -> output = neigh_blackhole ;
@@ -1015,7 +1016,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
10151016}
10161017EXPORT_SYMBOL (__neigh_event_send );
10171018
1018- static void neigh_update_hhs (struct neighbour * neigh )
1019+ static void neigh_update_hhs (const struct neighbour * neigh )
10191020{
10201021 struct hh_cache * hh ;
10211022 void (* update )(struct hh_cache * , const struct net_device * , const unsigned char * )
@@ -1151,7 +1152,9 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
11511152 }
11521153
11531154 if (lladdr != neigh -> ha ) {
1155+ write_seqlock (& neigh -> ha_lock );
11541156 memcpy (& neigh -> ha , lladdr , dev -> addr_len );
1157+ write_sequnlock (& neigh -> ha_lock );
11551158 neigh_update_hhs (neigh );
11561159 if (!(new & NUD_CONNECTED ))
11571160 neigh -> confirmed = jiffies -
@@ -1214,6 +1217,7 @@ static inline bool neigh_hh_lookup(struct neighbour *n, struct dst_entry *dst,
12141217{
12151218 struct hh_cache * hh ;
12161219
1220+ smp_rmb (); /* paired with smp_wmb() in neigh_hh_init() */
12171221 for (hh = n -> hh ; hh ; hh = hh -> hh_next ) {
12181222 if (hh -> hh_type == protocol ) {
12191223 atomic_inc (& hh -> hh_refcnt );
@@ -1248,8 +1252,8 @@ static void neigh_hh_init(struct neighbour *n, struct dst_entry *dst,
12481252 kfree (hh );
12491253 return ;
12501254 }
1251- read_unlock ( & n -> lock );
1252- write_lock (& n -> lock );
1255+
1256+ write_lock_bh (& n -> lock );
12531257
12541258 /* must check if another thread already did the insert */
12551259 if (neigh_hh_lookup (n , dst , protocol )) {
@@ -1263,13 +1267,13 @@ static void neigh_hh_init(struct neighbour *n, struct dst_entry *dst,
12631267 hh -> hh_output = n -> ops -> output ;
12641268
12651269 hh -> hh_next = n -> hh ;
1270+ smp_wmb (); /* paired with smp_rmb() in neigh_hh_lookup() */
12661271 n -> hh = hh ;
12671272
12681273 if (unlikely (cmpxchg (& dst -> hh , NULL , hh ) != NULL ))
12691274 hh_cache_put (hh );
12701275end :
1271- write_unlock (& n -> lock );
1272- read_lock (& n -> lock );
1276+ write_unlock_bh (& n -> lock );
12731277}
12741278
12751279/* This function can be used in contexts, where only old dev_queue_xmit
@@ -1308,16 +1312,18 @@ int neigh_resolve_output(struct sk_buff *skb)
13081312 if (!neigh_event_send (neigh , skb )) {
13091313 int err ;
13101314 struct net_device * dev = neigh -> dev ;
1315+ unsigned int seq ;
13111316
1312- read_lock_bh (& neigh -> lock );
13131317 if (dev -> header_ops -> cache &&
13141318 !dst -> hh &&
13151319 !(dst -> flags & DST_NOCACHE ))
13161320 neigh_hh_init (neigh , dst , dst -> ops -> protocol );
13171321
1318- err = dev_hard_header (skb , dev , ntohs (skb -> protocol ),
1319- neigh -> ha , NULL , skb -> len );
1320- read_unlock_bh (& neigh -> lock );
1322+ do {
1323+ seq = read_seqbegin (& neigh -> ha_lock );
1324+ err = dev_hard_header (skb , dev , ntohs (skb -> protocol ),
1325+ neigh -> ha , NULL , skb -> len );
1326+ } while (read_seqretry (& neigh -> ha_lock , seq ));
13211327
13221328 if (err >= 0 )
13231329 rc = neigh -> ops -> queue_xmit (skb );
@@ -1344,13 +1350,16 @@ int neigh_connected_output(struct sk_buff *skb)
13441350 struct dst_entry * dst = skb_dst (skb );
13451351 struct neighbour * neigh = dst -> neighbour ;
13461352 struct net_device * dev = neigh -> dev ;
1353+ unsigned int seq ;
13471354
13481355 __skb_pull (skb , skb_network_offset (skb ));
13491356
1350- read_lock_bh (& neigh -> lock );
1351- err = dev_hard_header (skb , dev , ntohs (skb -> protocol ),
1352- neigh -> ha , NULL , skb -> len );
1353- read_unlock_bh (& neigh -> lock );
1357+ do {
1358+ seq = read_seqbegin (& neigh -> ha_lock );
1359+ err = dev_hard_header (skb , dev , ntohs (skb -> protocol ),
1360+ neigh -> ha , NULL , skb -> len );
1361+ } while (read_seqretry (& neigh -> ha_lock , seq ));
1362+
13541363 if (err >= 0 )
13551364 err = neigh -> ops -> queue_xmit (skb );
13561365 else {
@@ -2148,10 +2157,14 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
21482157
21492158 read_lock_bh (& neigh -> lock );
21502159 ndm -> ndm_state = neigh -> nud_state ;
2151- if ((neigh -> nud_state & NUD_VALID ) &&
2152- nla_put (skb , NDA_LLADDR , neigh -> dev -> addr_len , neigh -> ha ) < 0 ) {
2153- read_unlock_bh (& neigh -> lock );
2154- goto nla_put_failure ;
2160+ if (neigh -> nud_state & NUD_VALID ) {
2161+ char haddr [MAX_ADDR_LEN ];
2162+
2163+ neigh_ha_snapshot (haddr , neigh , neigh -> dev );
2164+ if (nla_put (skb , NDA_LLADDR , neigh -> dev -> addr_len , haddr ) < 0 ) {
2165+ read_unlock_bh (& neigh -> lock );
2166+ goto nla_put_failure ;
2167+ }
21552168 }
21562169
21572170 ci .ndm_used = jiffies_to_clock_t (now - neigh -> used );
0 commit comments