neighbour.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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 <[email protected]>
  10. * Alexey Kuznetsov <[email protected]>
  11. *
  12. * Changes:
  13. *
  14. * Harald Welte: <[email protected]>
  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 <linux/android_kabi.h>
  28. #include <net/rtnetlink.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. ANDROID_KABI_RESERVE(1);
  79. };
  80. static inline void neigh_var_set(struct neigh_parms *p, int index, int val)
  81. {
  82. set_bit(index, p->data_state);
  83. p->data[index] = val;
  84. }
  85. #define NEIGH_VAR(p, attr) ((p)->data[NEIGH_VAR_ ## attr])
  86. /* In ndo_neigh_setup, NEIGH_VAR_INIT should be used.
  87. * In other cases, NEIGH_VAR_SET should be used.
  88. */
  89. #define NEIGH_VAR_INIT(p, attr, val) (NEIGH_VAR(p, attr) = val)
  90. #define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val)
  91. static inline void neigh_parms_data_state_setall(struct neigh_parms *p)
  92. {
  93. bitmap_fill(p->data_state, NEIGH_VAR_DATA_MAX);
  94. }
  95. static inline void neigh_parms_data_state_cleanall(struct neigh_parms *p)
  96. {
  97. bitmap_zero(p->data_state, NEIGH_VAR_DATA_MAX);
  98. }
  99. struct neigh_statistics {
  100. unsigned long allocs; /* number of allocated neighs */
  101. unsigned long destroys; /* number of destroyed neighs */
  102. unsigned long hash_grows; /* number of hash resizes */
  103. unsigned long res_failed; /* number of failed resolutions */
  104. unsigned long lookups; /* number of lookups */
  105. unsigned long hits; /* number of hits (among lookups) */
  106. unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
  107. unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
  108. unsigned long periodic_gc_runs; /* number of periodic GC runs */
  109. unsigned long forced_gc_runs; /* number of forced GC runs */
  110. unsigned long unres_discards; /* number of unresolved drops */
  111. unsigned long table_fulls; /* times even gc couldn't help */
  112. };
  113. #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
  114. struct neighbour {
  115. struct neighbour __rcu *next;
  116. struct neigh_table *tbl;
  117. struct neigh_parms *parms;
  118. unsigned long confirmed;
  119. unsigned long updated;
  120. rwlock_t lock;
  121. refcount_t refcnt;
  122. unsigned int arp_queue_len_bytes;
  123. struct sk_buff_head arp_queue;
  124. struct timer_list timer;
  125. unsigned long used;
  126. atomic_t probes;
  127. u8 nud_state;
  128. u8 type;
  129. u8 dead;
  130. u8 protocol;
  131. u32 flags;
  132. seqlock_t ha_lock;
  133. unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))] __aligned(8);
  134. struct hh_cache hh;
  135. int (*output)(struct neighbour *, struct sk_buff *);
  136. const struct neigh_ops *ops;
  137. struct list_head gc_list;
  138. struct list_head managed_list;
  139. struct rcu_head rcu;
  140. struct net_device *dev;
  141. netdevice_tracker dev_tracker;
  142. ANDROID_KABI_RESERVE(1);
  143. u8 primary_key[0];
  144. } __randomize_layout;
  145. struct neigh_ops {
  146. int family;
  147. void (*solicit)(struct neighbour *, struct sk_buff *);
  148. void (*error_report)(struct neighbour *, struct sk_buff *);
  149. int (*output)(struct neighbour *, struct sk_buff *);
  150. int (*connected_output)(struct neighbour *, struct sk_buff *);
  151. };
  152. struct pneigh_entry {
  153. struct pneigh_entry *next;
  154. possible_net_t net;
  155. struct net_device *dev;
  156. netdevice_tracker dev_tracker;
  157. u32 flags;
  158. u8 protocol;
  159. u32 key[];
  160. };
  161. /*
  162. * neighbour table manipulation
  163. */
  164. #define NEIGH_NUM_HASH_RND 4
  165. struct neigh_hash_table {
  166. struct neighbour __rcu **hash_buckets;
  167. unsigned int hash_shift;
  168. __u32 hash_rnd[NEIGH_NUM_HASH_RND];
  169. struct rcu_head rcu;
  170. };
  171. struct neigh_table {
  172. int family;
  173. unsigned int entry_size;
  174. unsigned int key_len;
  175. __be16 protocol;
  176. __u32 (*hash)(const void *pkey,
  177. const struct net_device *dev,
  178. __u32 *hash_rnd);
  179. bool (*key_eq)(const struct neighbour *, const void *pkey);
  180. int (*constructor)(struct neighbour *);
  181. int (*pconstructor)(struct pneigh_entry *);
  182. void (*pdestructor)(struct pneigh_entry *);
  183. void (*proxy_redo)(struct sk_buff *skb);
  184. int (*is_multicast)(const void *pkey);
  185. bool (*allow_add)(const struct net_device *dev,
  186. struct netlink_ext_ack *extack);
  187. char *id;
  188. struct neigh_parms parms;
  189. struct list_head parms_list;
  190. int gc_interval;
  191. int gc_thresh1;
  192. int gc_thresh2;
  193. int gc_thresh3;
  194. unsigned long last_flush;
  195. struct delayed_work gc_work;
  196. struct delayed_work managed_work;
  197. struct timer_list proxy_timer;
  198. struct sk_buff_head proxy_queue;
  199. atomic_t entries;
  200. atomic_t gc_entries;
  201. struct list_head gc_list;
  202. struct list_head managed_list;
  203. rwlock_t lock;
  204. unsigned long last_rand;
  205. struct neigh_statistics __percpu *stats;
  206. struct neigh_hash_table __rcu *nht;
  207. struct pneigh_entry **phash_buckets;
  208. ANDROID_KABI_RESERVE(1);
  209. };
  210. enum {
  211. NEIGH_ARP_TABLE = 0,
  212. NEIGH_ND_TABLE = 1,
  213. NEIGH_DN_TABLE = 2,
  214. NEIGH_NR_TABLES,
  215. NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */
  216. };
  217. static inline int neigh_parms_family(struct neigh_parms *p)
  218. {
  219. return p->tbl->family;
  220. }
  221. #define NEIGH_PRIV_ALIGN sizeof(long long)
  222. #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
  223. static inline void *neighbour_priv(const struct neighbour *n)
  224. {
  225. return (char *)n + n->tbl->entry_size;
  226. }
  227. /* flags for neigh_update() */
  228. #define NEIGH_UPDATE_F_OVERRIDE BIT(0)
  229. #define NEIGH_UPDATE_F_WEAK_OVERRIDE BIT(1)
  230. #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER BIT(2)
  231. #define NEIGH_UPDATE_F_USE BIT(3)
  232. #define NEIGH_UPDATE_F_MANAGED BIT(4)
  233. #define NEIGH_UPDATE_F_EXT_LEARNED BIT(5)
  234. #define NEIGH_UPDATE_F_ISROUTER BIT(6)
  235. #define NEIGH_UPDATE_F_ADMIN BIT(7)
  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)
  240. #define NTF_MANAGED (NTF_EXT_MANAGED << NTF_EXT_SHIFT)
  241. extern const struct nla_policy nda_policy[];
  242. static inline bool neigh_key_eq32(const struct neighbour *n, const void *pkey)
  243. {
  244. return *(const u32 *)n->primary_key == *(const u32 *)pkey;
  245. }
  246. static inline bool neigh_key_eq128(const struct neighbour *n, const void *pkey)
  247. {
  248. const u32 *n32 = (const u32 *)n->primary_key;
  249. const u32 *p32 = pkey;
  250. return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
  251. (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
  252. }
  253. static inline struct neighbour *___neigh_lookup_noref(
  254. struct neigh_table *tbl,
  255. bool (*key_eq)(const struct neighbour *n, const void *pkey),
  256. __u32 (*hash)(const void *pkey,
  257. const struct net_device *dev,
  258. __u32 *hash_rnd),
  259. const void *pkey,
  260. struct net_device *dev)
  261. {
  262. struct neigh_hash_table *nht = rcu_dereference(tbl->nht);
  263. struct neighbour *n;
  264. u32 hash_val;
  265. hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
  266. for (n = rcu_dereference(nht->hash_buckets[hash_val]);
  267. n != NULL;
  268. n = rcu_dereference(n->next)) {
  269. if (n->dev == dev && key_eq(n, pkey))
  270. return n;
  271. }
  272. return NULL;
  273. }
  274. static inline struct neighbour *__neigh_lookup_noref(struct neigh_table *tbl,
  275. const void *pkey,
  276. struct net_device *dev)
  277. {
  278. return ___neigh_lookup_noref(tbl, tbl->key_eq, tbl->hash, pkey, dev);
  279. }
  280. static inline void neigh_confirm(struct neighbour *n)
  281. {
  282. if (n) {
  283. unsigned long now = jiffies;
  284. /* avoid dirtying neighbour */
  285. if (READ_ONCE(n->confirmed) != now)
  286. WRITE_ONCE(n->confirmed, now);
  287. }
  288. }
  289. void neigh_table_init(int index, struct neigh_table *tbl);
  290. int neigh_table_clear(int index, struct neigh_table *tbl);
  291. struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
  292. struct net_device *dev);
  293. struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
  294. struct net_device *dev, bool want_ref);
  295. static inline struct neighbour *neigh_create(struct neigh_table *tbl,
  296. const void *pkey,
  297. struct net_device *dev)
  298. {
  299. return __neigh_create(tbl, pkey, dev, true);
  300. }
  301. void neigh_destroy(struct neighbour *neigh);
  302. int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
  303. const bool immediate_ok);
  304. int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags,
  305. u32 nlmsg_pid);
  306. void __neigh_set_probe_once(struct neighbour *neigh);
  307. bool neigh_remove_one(struct neighbour *ndel, struct neigh_table *tbl);
  308. void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
  309. int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
  310. int neigh_carrier_down(struct neigh_table *tbl, struct net_device *dev);
  311. int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb);
  312. int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb);
  313. int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb);
  314. struct neighbour *neigh_event_ns(struct neigh_table *tbl,
  315. u8 *lladdr, void *saddr,
  316. struct net_device *dev);
  317. struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
  318. struct neigh_table *tbl);
  319. void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
  320. static inline
  321. struct net *neigh_parms_net(const struct neigh_parms *parms)
  322. {
  323. return read_pnet(&parms->net);
  324. }
  325. unsigned long neigh_rand_reach_time(unsigned long base);
  326. void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
  327. struct sk_buff *skb);
  328. struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net,
  329. const void *key, struct net_device *dev,
  330. int creat);
  331. struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl, struct net *net,
  332. const void *key, struct net_device *dev);
  333. int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key,
  334. struct net_device *dev);
  335. static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)
  336. {
  337. return read_pnet(&pneigh->net);
  338. }
  339. void neigh_app_ns(struct neighbour *n);
  340. void neigh_for_each(struct neigh_table *tbl,
  341. void (*cb)(struct neighbour *, void *), void *cookie);
  342. void __neigh_for_each_release(struct neigh_table *tbl,
  343. int (*cb)(struct neighbour *));
  344. int neigh_xmit(int fam, struct net_device *, const void *, struct sk_buff *);
  345. void pneigh_for_each(struct neigh_table *tbl,
  346. void (*cb)(struct pneigh_entry *));
  347. struct neigh_seq_state {
  348. struct seq_net_private p;
  349. struct neigh_table *tbl;
  350. struct neigh_hash_table *nht;
  351. void *(*neigh_sub_iter)(struct neigh_seq_state *state,
  352. struct neighbour *n, loff_t *pos);
  353. unsigned int bucket;
  354. unsigned int flags;
  355. #define NEIGH_SEQ_NEIGH_ONLY 0x00000001
  356. #define NEIGH_SEQ_IS_PNEIGH 0x00000002
  357. #define NEIGH_SEQ_SKIP_NOARP 0x00000004
  358. };
  359. void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *,
  360. unsigned int);
  361. void *neigh_seq_next(struct seq_file *, void *, loff_t *);
  362. void neigh_seq_stop(struct seq_file *, void *);
  363. int neigh_proc_dointvec(struct ctl_table *ctl, int write,
  364. void *buffer, size_t *lenp, loff_t *ppos);
  365. int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,
  366. void *buffer,
  367. size_t *lenp, loff_t *ppos);
  368. int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write,
  369. void *buffer, size_t *lenp, loff_t *ppos);
  370. int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
  371. proc_handler *proc_handler);
  372. void neigh_sysctl_unregister(struct neigh_parms *p);
  373. static inline void __neigh_parms_put(struct neigh_parms *parms)
  374. {
  375. refcount_dec(&parms->refcnt);
  376. }
  377. static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
  378. {
  379. refcount_inc(&parms->refcnt);
  380. return parms;
  381. }
  382. /*
  383. * Neighbour references
  384. */
  385. static inline void neigh_release(struct neighbour *neigh)
  386. {
  387. if (refcount_dec_and_test(&neigh->refcnt))
  388. neigh_destroy(neigh);
  389. }
  390. static inline struct neighbour * neigh_clone(struct neighbour *neigh)
  391. {
  392. if (neigh)
  393. refcount_inc(&neigh->refcnt);
  394. return neigh;
  395. }
  396. #define neigh_hold(n) refcount_inc(&(n)->refcnt)
  397. static __always_inline int neigh_event_send_probe(struct neighbour *neigh,
  398. struct sk_buff *skb,
  399. const bool immediate_ok)
  400. {
  401. unsigned long now = jiffies;
  402. if (READ_ONCE(neigh->used) != now)
  403. WRITE_ONCE(neigh->used, now);
  404. if (!(READ_ONCE(neigh->nud_state) & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE)))
  405. return __neigh_event_send(neigh, skb, immediate_ok);
  406. return 0;
  407. }
  408. static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
  409. {
  410. return neigh_event_send_probe(neigh, skb, true);
  411. }
  412. #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
  413. static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb)
  414. {
  415. unsigned int seq, hh_alen;
  416. do {
  417. seq = read_seqbegin(&hh->hh_lock);
  418. hh_alen = HH_DATA_ALIGN(ETH_HLEN);
  419. memcpy(skb->data - hh_alen, hh->hh_data, ETH_ALEN + hh_alen - ETH_HLEN);
  420. } while (read_seqretry(&hh->hh_lock, seq));
  421. return 0;
  422. }
  423. #endif
  424. static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  425. {
  426. unsigned int hh_alen = 0;
  427. unsigned int seq;
  428. unsigned int hh_len;
  429. do {
  430. seq = read_seqbegin(&hh->hh_lock);
  431. hh_len = READ_ONCE(hh->hh_len);
  432. if (likely(hh_len <= HH_DATA_MOD)) {
  433. hh_alen = HH_DATA_MOD;
  434. /* skb_push() would proceed silently if we have room for
  435. * the unaligned size but not for the aligned size:
  436. * check headroom explicitly.
  437. */
  438. if (likely(skb_headroom(skb) >= HH_DATA_MOD)) {
  439. /* this is inlined by gcc */
  440. memcpy(skb->data - HH_DATA_MOD, hh->hh_data,
  441. HH_DATA_MOD);
  442. }
  443. } else {
  444. hh_alen = HH_DATA_ALIGN(hh_len);
  445. if (likely(skb_headroom(skb) >= hh_alen)) {
  446. memcpy(skb->data - hh_alen, hh->hh_data,
  447. hh_alen);
  448. }
  449. }
  450. } while (read_seqretry(&hh->hh_lock, seq));
  451. if (WARN_ON_ONCE(skb_headroom(skb) < hh_alen)) {
  452. kfree_skb(skb);
  453. return NET_XMIT_DROP;
  454. }
  455. __skb_push(skb, hh_len);
  456. return dev_queue_xmit(skb);
  457. }
  458. static inline int neigh_output(struct neighbour *n, struct sk_buff *skb,
  459. bool skip_cache)
  460. {
  461. const struct hh_cache *hh = &n->hh;
  462. /* n->nud_state and hh->hh_len could be changed under us.
  463. * neigh_hh_output() is taking care of the race later.
  464. */
  465. if (!skip_cache &&
  466. (READ_ONCE(n->nud_state) & NUD_CONNECTED) &&
  467. READ_ONCE(hh->hh_len))
  468. return neigh_hh_output(hh, skb);
  469. return READ_ONCE(n->output)(n, skb);
  470. }
  471. static inline struct neighbour *
  472. __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
  473. {
  474. struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  475. if (n || !creat)
  476. return n;
  477. n = neigh_create(tbl, pkey, dev);
  478. return IS_ERR(n) ? NULL : n;
  479. }
  480. static inline struct neighbour *
  481. __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
  482. struct net_device *dev)
  483. {
  484. struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  485. if (n)
  486. return n;
  487. return neigh_create(tbl, pkey, dev);
  488. }
  489. struct neighbour_cb {
  490. unsigned long sched_next;
  491. unsigned int flags;
  492. };
  493. #define LOCALLY_ENQUEUED 0x1
  494. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  495. static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  496. const struct net_device *dev)
  497. {
  498. unsigned int seq;
  499. do {
  500. seq = read_seqbegin(&n->ha_lock);
  501. memcpy(dst, n->ha, dev->addr_len);
  502. } while (read_seqretry(&n->ha_lock, seq));
  503. }
  504. static inline void neigh_update_is_router(struct neighbour *neigh, u32 flags,
  505. int *notify)
  506. {
  507. u8 ndm_flags = 0;
  508. ndm_flags |= (flags & NEIGH_UPDATE_F_ISROUTER) ? NTF_ROUTER : 0;
  509. if ((neigh->flags ^ ndm_flags) & NTF_ROUTER) {
  510. if (ndm_flags & NTF_ROUTER)
  511. neigh->flags |= NTF_ROUTER;
  512. else
  513. neigh->flags &= ~NTF_ROUTER;
  514. *notify = 1;
  515. }
  516. }
  517. #endif