neighbour.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _NET_NEIGHBOUR_H
  3. #define _NET_NEIGHBOUR_H
  4. #include <linux/neighbour.h>
  5. /*
  6. * Generic neighbour manipulation
  7. *
  8. * Authors:
  9. * Pedro Roque <roque@di.fc.ul.pt>
  10. * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  11. *
  12. * Changes:
  13. *
  14. * Harald Welte: <laforge@gnumonks.org>
  15. * - Add neighbour cache statistics like rtstat
  16. */
  17. #include <linux/atomic.h>
  18. #include <linux/refcount.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/bitmap.h>
  24. #include <linux/err.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/workqueue.h>
  27. #include <net/rtnetlink.h>
  28. #include <net/neighbour_tables.h>
  29. /*
  30. * NUD stands for "neighbor unreachability detection"
  31. */
  32. #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE)
  33. #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
  34. #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
  35. struct neighbour;
  36. enum {
  37. NEIGH_VAR_MCAST_PROBES,
  38. NEIGH_VAR_UCAST_PROBES,
  39. NEIGH_VAR_APP_PROBES,
  40. NEIGH_VAR_MCAST_REPROBES,
  41. NEIGH_VAR_RETRANS_TIME,
  42. NEIGH_VAR_BASE_REACHABLE_TIME,
  43. NEIGH_VAR_DELAY_PROBE_TIME,
  44. NEIGH_VAR_INTERVAL_PROBE_TIME_MS,
  45. NEIGH_VAR_GC_STALETIME,
  46. NEIGH_VAR_QUEUE_LEN_BYTES,
  47. NEIGH_VAR_PROXY_QLEN,
  48. NEIGH_VAR_ANYCAST_DELAY,
  49. NEIGH_VAR_PROXY_DELAY,
  50. NEIGH_VAR_LOCKTIME,
  51. #define NEIGH_VAR_DATA_MAX (NEIGH_VAR_LOCKTIME + 1)
  52. /* Following are used as a second way to access one of the above */
  53. NEIGH_VAR_QUEUE_LEN, /* same data as NEIGH_VAR_QUEUE_LEN_BYTES */
  54. NEIGH_VAR_RETRANS_TIME_MS, /* same data as NEIGH_VAR_RETRANS_TIME */
  55. NEIGH_VAR_BASE_REACHABLE_TIME_MS, /* same data as NEIGH_VAR_BASE_REACHABLE_TIME */
  56. /* Following are used by "default" only */
  57. NEIGH_VAR_GC_INTERVAL,
  58. NEIGH_VAR_GC_THRESH1,
  59. NEIGH_VAR_GC_THRESH2,
  60. NEIGH_VAR_GC_THRESH3,
  61. NEIGH_VAR_MAX
  62. };
  63. struct neigh_parms {
  64. possible_net_t net;
  65. struct net_device *dev;
  66. netdevice_tracker dev_tracker;
  67. struct list_head list;
  68. int (*neigh_setup)(struct neighbour *);
  69. struct neigh_table *tbl;
  70. void *sysctl_table;
  71. int dead;
  72. refcount_t refcnt;
  73. struct rcu_head rcu_head;
  74. int reachable_time;
  75. u32 qlen;
  76. int data[NEIGH_VAR_DATA_MAX];
  77. DECLARE_BITMAP(data_state, NEIGH_VAR_DATA_MAX);
  78. };
  79. static inline void neigh_var_set(struct neigh_parms *p, int index, int val)
  80. {
  81. set_bit(index, p->data_state);
  82. WRITE_ONCE(p->data[index], val);
  83. }
  84. #define __NEIGH_VAR(p, attr) ((p)->data[NEIGH_VAR_ ## attr])
  85. #define NEIGH_VAR(p, attr) READ_ONCE(__NEIGH_VAR(p, attr))
  86. #define NEIGH_VAR_PTR(p, attr) (&(__NEIGH_VAR(p, attr)))
  87. /* In ndo_neigh_setup, NEIGH_VAR_INIT should be used.
  88. * In other cases, NEIGH_VAR_SET should be used.
  89. */
  90. #define NEIGH_VAR_INIT(p, attr, val) (__NEIGH_VAR(p, attr) = val)
  91. #define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val)
  92. static inline void neigh_parms_data_state_setall(struct neigh_parms *p)
  93. {
  94. bitmap_fill(p->data_state, NEIGH_VAR_DATA_MAX);
  95. }
  96. static inline void neigh_parms_data_state_cleanall(struct neigh_parms *p)
  97. {
  98. bitmap_zero(p->data_state, NEIGH_VAR_DATA_MAX);
  99. }
  100. struct neigh_statistics {
  101. unsigned long allocs; /* number of allocated neighs */
  102. unsigned long destroys; /* number of destroyed neighs */
  103. unsigned long hash_grows; /* number of hash resizes */
  104. unsigned long res_failed; /* number of failed resolutions */
  105. unsigned long lookups; /* number of lookups */
  106. unsigned long hits; /* number of hits (among lookups) */
  107. unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
  108. unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
  109. unsigned long periodic_gc_runs; /* number of periodic GC runs */
  110. unsigned long forced_gc_runs; /* number of forced GC runs */
  111. unsigned long unres_discards; /* number of unresolved drops */
  112. unsigned long table_fulls; /* times even gc couldn't help */
  113. };
  114. #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
  115. struct neighbour {
  116. struct hlist_node hash;
  117. struct hlist_node dev_list;
  118. struct neigh_table *tbl;
  119. struct neigh_parms *parms;
  120. unsigned long confirmed;
  121. unsigned long updated;
  122. rwlock_t lock;
  123. refcount_t refcnt;
  124. unsigned int arp_queue_len_bytes;
  125. struct sk_buff_head arp_queue;
  126. struct timer_list timer;
  127. unsigned long used;
  128. atomic_t probes;
  129. u8 nud_state;
  130. u8 type;
  131. u8 dead;
  132. u8 protocol;
  133. u32 flags;
  134. seqlock_t ha_lock;
  135. unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))] __aligned(8);
  136. struct hh_cache hh;
  137. int (*output)(struct neighbour *, struct sk_buff *);
  138. const struct neigh_ops *ops;
  139. struct list_head gc_list;
  140. struct list_head managed_list;
  141. struct rcu_head rcu;
  142. struct net_device *dev;
  143. netdevice_tracker dev_tracker;
  144. u8 primary_key[];
  145. } __randomize_layout;
  146. struct neigh_ops {
  147. int family;
  148. void (*solicit)(struct neighbour *, struct sk_buff *);
  149. void (*error_report)(struct neighbour *, struct sk_buff *);
  150. int (*output)(struct neighbour *, struct sk_buff *);
  151. int (*connected_output)(struct neighbour *, struct sk_buff *);
  152. };
  153. struct pneigh_entry {
  154. struct pneigh_entry __rcu *next;
  155. possible_net_t net;
  156. struct net_device *dev;
  157. netdevice_tracker dev_tracker;
  158. union {
  159. struct list_head free_node;
  160. struct rcu_head rcu;
  161. };
  162. u32 flags;
  163. u8 protocol;
  164. bool permanent;
  165. u32 key[];
  166. };
  167. /*
  168. * neighbour table manipulation
  169. */
  170. #define NEIGH_NUM_HASH_RND 4
  171. struct neigh_hash_table {
  172. struct hlist_head *hash_heads;
  173. unsigned int hash_shift;
  174. __u32 hash_rnd[NEIGH_NUM_HASH_RND];
  175. struct rcu_head rcu;
  176. };
  177. struct neigh_table {
  178. int family;
  179. unsigned int entry_size;
  180. unsigned int key_len;
  181. __be16 protocol;
  182. __u32 (*hash)(const void *pkey,
  183. const struct net_device *dev,
  184. __u32 *hash_rnd);
  185. bool (*key_eq)(const struct neighbour *, const void *pkey);
  186. int (*constructor)(struct neighbour *);
  187. int (*pconstructor)(struct pneigh_entry *);
  188. void (*pdestructor)(struct pneigh_entry *);
  189. void (*proxy_redo)(struct sk_buff *skb);
  190. int (*is_multicast)(const void *pkey);
  191. bool (*allow_add)(const struct net_device *dev,
  192. struct netlink_ext_ack *extack);
  193. char *id;
  194. struct neigh_parms parms;
  195. struct list_head parms_list;
  196. int gc_interval;
  197. int gc_thresh1;
  198. int gc_thresh2;
  199. int gc_thresh3;
  200. unsigned long last_flush;
  201. struct delayed_work gc_work;
  202. struct delayed_work managed_work;
  203. struct timer_list proxy_timer;
  204. struct sk_buff_head proxy_queue;
  205. atomic_t entries;
  206. atomic_t gc_entries;
  207. struct list_head gc_list;
  208. struct list_head managed_list;
  209. spinlock_t lock;
  210. unsigned long last_rand;
  211. struct neigh_statistics __percpu *stats;
  212. struct neigh_hash_table __rcu *nht;
  213. struct mutex phash_lock;
  214. struct pneigh_entry __rcu **phash_buckets;
  215. };
  216. static inline int neigh_parms_family(struct neigh_parms *p)
  217. {
  218. return p->tbl->family;
  219. }
  220. #define NEIGH_PRIV_ALIGN sizeof(long long)
  221. #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
  222. static inline void *neighbour_priv(const struct neighbour *n)
  223. {
  224. return (char *)n + n->tbl->entry_size;
  225. }
  226. /* flags for neigh_update() */
  227. #define NEIGH_UPDATE_F_OVERRIDE BIT(0)
  228. #define NEIGH_UPDATE_F_WEAK_OVERRIDE BIT(1)
  229. #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER BIT(2)
  230. #define NEIGH_UPDATE_F_USE BIT(3)
  231. #define NEIGH_UPDATE_F_MANAGED BIT(4)
  232. #define NEIGH_UPDATE_F_EXT_LEARNED BIT(5)
  233. #define NEIGH_UPDATE_F_ISROUTER BIT(6)
  234. #define NEIGH_UPDATE_F_ADMIN BIT(7)
  235. #define NEIGH_UPDATE_F_EXT_VALIDATED BIT(8)
  236. /* In-kernel representation for NDA_FLAGS_EXT flags: */
  237. #define NTF_OLD_MASK 0xff
  238. #define NTF_EXT_SHIFT 8
  239. #define NTF_EXT_MASK (NTF_EXT_MANAGED | NTF_EXT_EXT_VALIDATED)
  240. #define NTF_MANAGED (NTF_EXT_MANAGED << NTF_EXT_SHIFT)
  241. #define NTF_EXT_VALIDATED (NTF_EXT_EXT_VALIDATED << NTF_EXT_SHIFT)
  242. extern const struct nla_policy nda_policy[];
  243. #define neigh_for_each_in_bucket(pos, head) hlist_for_each_entry(pos, head, hash)
  244. #define neigh_for_each_in_bucket_rcu(pos, head) \
  245. hlist_for_each_entry_rcu(pos, head, hash)
  246. #define neigh_for_each_in_bucket_safe(pos, tmp, head) \
  247. hlist_for_each_entry_safe(pos, tmp, head, hash)
  248. static inline bool neigh_key_eq32(const struct neighbour *n, const void *pkey)
  249. {
  250. return *(const u32 *)n->primary_key == *(const u32 *)pkey;
  251. }
  252. static inline bool neigh_key_eq128(const struct neighbour *n, const void *pkey)
  253. {
  254. const u32 *n32 = (const u32 *)n->primary_key;
  255. const u32 *p32 = pkey;
  256. return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
  257. (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
  258. }
  259. static inline struct neighbour *___neigh_lookup_noref(
  260. struct neigh_table *tbl,
  261. bool (*key_eq)(const struct neighbour *n, const void *pkey),
  262. __u32 (*hash)(const void *pkey,
  263. const struct net_device *dev,
  264. __u32 *hash_rnd),
  265. const void *pkey,
  266. struct net_device *dev)
  267. {
  268. struct neigh_hash_table *nht = rcu_dereference(tbl->nht);
  269. struct neighbour *n;
  270. u32 hash_val;
  271. hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
  272. neigh_for_each_in_bucket_rcu(n, &nht->hash_heads[hash_val])
  273. if (n->dev == dev && key_eq(n, pkey))
  274. return n;
  275. return NULL;
  276. }
  277. static inline struct neighbour *__neigh_lookup_noref(struct neigh_table *tbl,
  278. const void *pkey,
  279. struct net_device *dev)
  280. {
  281. return ___neigh_lookup_noref(tbl, tbl->key_eq, tbl->hash, pkey, dev);
  282. }
  283. static inline void neigh_confirm(struct neighbour *n)
  284. {
  285. if (n) {
  286. unsigned long now = jiffies;
  287. /* avoid dirtying neighbour */
  288. if (READ_ONCE(n->confirmed) != now)
  289. WRITE_ONCE(n->confirmed, now);
  290. }
  291. }
  292. void neigh_table_init(int index, struct neigh_table *tbl);
  293. int neigh_table_clear(int index, struct neigh_table *tbl);
  294. struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
  295. struct net_device *dev);
  296. struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
  297. struct net_device *dev, bool want_ref);
  298. static inline struct neighbour *neigh_create(struct neigh_table *tbl,
  299. const void *pkey,
  300. struct net_device *dev)
  301. {
  302. return __neigh_create(tbl, pkey, dev, true);
  303. }
  304. void neigh_destroy(struct neighbour *neigh);
  305. int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
  306. const bool immediate_ok);
  307. int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags,
  308. u32 nlmsg_pid);
  309. void __neigh_set_probe_once(struct neighbour *neigh);
  310. bool neigh_remove_one(struct neighbour *ndel);
  311. void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
  312. int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
  313. int neigh_carrier_down(struct neigh_table *tbl, struct net_device *dev);
  314. int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb);
  315. int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb);
  316. int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb);
  317. struct neighbour *neigh_event_ns(struct neigh_table *tbl,
  318. u8 *lladdr, void *saddr,
  319. struct net_device *dev);
  320. struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
  321. struct neigh_table *tbl);
  322. void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
  323. static inline
  324. struct net *neigh_parms_net(const struct neigh_parms *parms)
  325. {
  326. return read_pnet(&parms->net);
  327. }
  328. unsigned long neigh_rand_reach_time(unsigned long base);
  329. static inline void neigh_set_reach_time(struct neigh_parms *p)
  330. {
  331. unsigned long base = NEIGH_VAR(p, BASE_REACHABLE_TIME);
  332. WRITE_ONCE(p->reachable_time, neigh_rand_reach_time(base));
  333. }
  334. void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
  335. struct sk_buff *skb);
  336. struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net,
  337. const void *key, struct net_device *dev);
  338. int pneigh_create(struct neigh_table *tbl, struct net *net, const void *key,
  339. struct net_device *dev, u32 flags, u8 protocol,
  340. bool permanent);
  341. int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key,
  342. struct net_device *dev);
  343. static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)
  344. {
  345. return read_pnet(&pneigh->net);
  346. }
  347. void neigh_app_ns(struct neighbour *n);
  348. void neigh_for_each(struct neigh_table *tbl,
  349. void (*cb)(struct neighbour *, void *), void *cookie);
  350. void __neigh_for_each_release(struct neigh_table *tbl,
  351. int (*cb)(struct neighbour *));
  352. int neigh_xmit(int fam, struct net_device *, const void *, struct sk_buff *);
  353. struct neigh_seq_state {
  354. struct seq_net_private p;
  355. struct neigh_table *tbl;
  356. struct neigh_hash_table *nht;
  357. void *(*neigh_sub_iter)(struct neigh_seq_state *state,
  358. struct neighbour *n, loff_t *pos);
  359. unsigned int bucket;
  360. unsigned int flags;
  361. #define NEIGH_SEQ_NEIGH_ONLY 0x00000001
  362. #define NEIGH_SEQ_IS_PNEIGH 0x00000002
  363. #define NEIGH_SEQ_SKIP_NOARP 0x00000004
  364. };
  365. void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *,
  366. unsigned int);
  367. void *neigh_seq_next(struct seq_file *, void *, loff_t *);
  368. void neigh_seq_stop(struct seq_file *, void *);
  369. int neigh_proc_dointvec(const struct ctl_table *ctl, int write,
  370. void *buffer, size_t *lenp, loff_t *ppos);
  371. int neigh_proc_dointvec_jiffies(const struct ctl_table *ctl, int write,
  372. void *buffer,
  373. size_t *lenp, loff_t *ppos);
  374. int neigh_proc_dointvec_ms_jiffies(const struct ctl_table *ctl, int write,
  375. void *buffer, size_t *lenp, loff_t *ppos);
  376. int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
  377. proc_handler *proc_handler);
  378. void neigh_sysctl_unregister(struct neigh_parms *p);
  379. static inline void __neigh_parms_put(struct neigh_parms *parms)
  380. {
  381. refcount_dec(&parms->refcnt);
  382. }
  383. static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
  384. {
  385. refcount_inc(&parms->refcnt);
  386. return parms;
  387. }
  388. /*
  389. * Neighbour references
  390. */
  391. static inline void neigh_release(struct neighbour *neigh)
  392. {
  393. if (refcount_dec_and_test(&neigh->refcnt))
  394. neigh_destroy(neigh);
  395. }
  396. static inline struct neighbour * neigh_clone(struct neighbour *neigh)
  397. {
  398. if (neigh)
  399. refcount_inc(&neigh->refcnt);
  400. return neigh;
  401. }
  402. #define neigh_hold(n) refcount_inc(&(n)->refcnt)
  403. static __always_inline int neigh_event_send_probe(struct neighbour *neigh,
  404. struct sk_buff *skb,
  405. const bool immediate_ok)
  406. {
  407. unsigned long now = jiffies;
  408. if (READ_ONCE(neigh->used) != now)
  409. WRITE_ONCE(neigh->used, now);
  410. if (!(READ_ONCE(neigh->nud_state) & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE)))
  411. return __neigh_event_send(neigh, skb, immediate_ok);
  412. return 0;
  413. }
  414. static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
  415. {
  416. return neigh_event_send_probe(neigh, skb, true);
  417. }
  418. #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
  419. static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb)
  420. {
  421. unsigned int seq, hh_alen;
  422. do {
  423. seq = read_seqbegin(&hh->hh_lock);
  424. hh_alen = HH_DATA_ALIGN(ETH_HLEN);
  425. memcpy(skb->data - hh_alen, hh->hh_data, ETH_ALEN + hh_alen - ETH_HLEN);
  426. } while (read_seqretry(&hh->hh_lock, seq));
  427. return 0;
  428. }
  429. #endif
  430. static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  431. {
  432. unsigned int hh_alen = 0;
  433. unsigned int seq;
  434. unsigned int hh_len;
  435. do {
  436. seq = read_seqbegin(&hh->hh_lock);
  437. hh_len = READ_ONCE(hh->hh_len);
  438. if (likely(hh_len <= HH_DATA_MOD)) {
  439. hh_alen = HH_DATA_MOD;
  440. /* skb_push() would proceed silently if we have room for
  441. * the unaligned size but not for the aligned size:
  442. * check headroom explicitly.
  443. */
  444. if (likely(skb_headroom(skb) >= HH_DATA_MOD)) {
  445. /* this is inlined by gcc */
  446. memcpy(skb->data - HH_DATA_MOD, hh->hh_data,
  447. HH_DATA_MOD);
  448. }
  449. } else {
  450. hh_alen = HH_DATA_ALIGN(hh_len);
  451. if (likely(skb_headroom(skb) >= hh_alen)) {
  452. memcpy(skb->data - hh_alen, hh->hh_data,
  453. hh_alen);
  454. }
  455. }
  456. } while (read_seqretry(&hh->hh_lock, seq));
  457. if (WARN_ON_ONCE(skb_headroom(skb) < hh_alen)) {
  458. kfree_skb(skb);
  459. return NET_XMIT_DROP;
  460. }
  461. __skb_push(skb, hh_len);
  462. return dev_queue_xmit(skb);
  463. }
  464. static inline int neigh_output(struct neighbour *n, struct sk_buff *skb,
  465. bool skip_cache)
  466. {
  467. const struct hh_cache *hh = &n->hh;
  468. /* n->nud_state and hh->hh_len could be changed under us.
  469. * neigh_hh_output() is taking care of the race later.
  470. */
  471. if (!skip_cache &&
  472. (READ_ONCE(n->nud_state) & NUD_CONNECTED) &&
  473. READ_ONCE(hh->hh_len))
  474. return neigh_hh_output(hh, skb);
  475. return READ_ONCE(n->output)(n, skb);
  476. }
  477. static inline struct neighbour *
  478. __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
  479. {
  480. struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  481. if (n || !creat)
  482. return n;
  483. n = neigh_create(tbl, pkey, dev);
  484. return IS_ERR(n) ? NULL : n;
  485. }
  486. static inline struct neighbour *
  487. __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
  488. struct net_device *dev)
  489. {
  490. struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  491. if (n)
  492. return n;
  493. return neigh_create(tbl, pkey, dev);
  494. }
  495. struct neighbour_cb {
  496. unsigned long sched_next;
  497. unsigned int flags;
  498. };
  499. #define LOCALLY_ENQUEUED 0x1
  500. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  501. static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  502. const struct net_device *dev)
  503. {
  504. unsigned int seq;
  505. do {
  506. seq = read_seqbegin(&n->ha_lock);
  507. memcpy(dst, n->ha, dev->addr_len);
  508. } while (read_seqretry(&n->ha_lock, seq));
  509. }
  510. static inline void neigh_update_is_router(struct neighbour *neigh, u32 flags,
  511. int *notify)
  512. {
  513. u8 ndm_flags = 0;
  514. ndm_flags |= (flags & NEIGH_UPDATE_F_ISROUTER) ? NTF_ROUTER : 0;
  515. if ((neigh->flags ^ ndm_flags) & NTF_ROUTER) {
  516. if (ndm_flags & NTF_ROUTER)
  517. neigh->flags |= NTF_ROUTER;
  518. else
  519. neigh->flags &= ~NTF_ROUTER;
  520. *notify = 1;
  521. }
  522. }
  523. #endif