2 * Generic address resolution entity
5 * Pedro Roque <roque@di.fc.ul.pt>
6 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 * Vitaly E. Lavrov releasing NULL neighbor in neigh_add.
15 * Harald Welte Add neighbour cache statistics like rtstat
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/slab.h>
21 #include <linux/kmemleak.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/socket.h>
26 #include <linux/netdevice.h>
27 #include <linux/proc_fs.h>
29 #include <linux/sysctl.h>
31 #include <linux/times.h>
32 #include <net/net_namespace.h>
33 #include <net/neighbour.h>
37 #include <net/netevent.h>
38 #include <net/netlink.h>
39 #include <linux/rtnetlink.h>
40 #include <linux/random.h>
41 #include <linux/string.h>
42 #include <linux/log2.h>
43 #include <linux/inetdevice.h>
44 #include <net/addrconf.h>
48 #define neigh_dbg(level, fmt, ...) \
50 if (level <= NEIGH_DEBUG) \
51 pr_debug(fmt, ##__VA_ARGS__); \
54 #define PNEIGH_HASHMASK 0xF
56 static void neigh_timer_handler(unsigned long arg);
57 static void __neigh_notify(struct neighbour *n, int type, int flags);
58 static void neigh_update_notify(struct neighbour *neigh);
59 static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
60 struct net_device *dev);
63 static const struct file_operations neigh_stat_seq_fops;
67 Neighbour hash table buckets are protected with rwlock tbl->lock.
69 - All the scans/updates to hash buckets MUST be made under this lock.
70 - NOTHING clever should be made under this lock: no callbacks
71 to protocol backends, no attempts to send something to network.
72 It will result in deadlocks, if backend/driver wants to use neighbour
74 - If the entry requires some non-trivial actions, increase
75 its reference count and release table lock.
77 Neighbour entries are protected:
78 - with reference count.
79 - with rwlock neigh->lock
81 Reference count prevents destruction.
83 neigh->lock mainly serializes ll address data and its validity state.
84 However, the same lock is used to protect another entry fields:
88 Again, nothing clever shall be made under neigh->lock,
89 the most complicated procedure, which we allow is dev->hard_header.
90 It is supposed, that dev->hard_header is simplistic and does
91 not make callbacks to neighbour tables.
94 static int neigh_blackhole(struct neighbour *neigh, struct sk_buff *skb)
100 static void neigh_cleanup_and_release(struct neighbour *neigh)
102 if (neigh->parms->neigh_cleanup)
103 neigh->parms->neigh_cleanup(neigh);
105 __neigh_notify(neigh, RTM_DELNEIGH, 0);
106 neigh_release(neigh);
110 * It is random distribution in the interval (1/2)*base...(3/2)*base.
111 * It corresponds to default IPv6 settings and is not overridable,
112 * because it is really reasonable choice.
115 unsigned long neigh_rand_reach_time(unsigned long base)
117 return base ? (prandom_u32() % base) + (base >> 1) : 0;
119 EXPORT_SYMBOL(neigh_rand_reach_time);
122 static int neigh_forced_gc(struct neigh_table *tbl)
126 struct neigh_hash_table *nht;
128 NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
130 write_lock_bh(&tbl->lock);
131 nht = rcu_dereference_protected(tbl->nht,
132 lockdep_is_held(&tbl->lock));
133 for (i = 0; i < (1 << nht->hash_shift); i++) {
135 struct neighbour __rcu **np;
137 np = &nht->hash_buckets[i];
138 while ((n = rcu_dereference_protected(*np,
139 lockdep_is_held(&tbl->lock))) != NULL) {
140 /* Neighbour record may be discarded if:
141 * - nobody refers to it.
142 * - it is not permanent
144 write_lock(&n->lock);
145 if (atomic_read(&n->refcnt) == 1 &&
146 !(n->nud_state & NUD_PERMANENT)) {
147 rcu_assign_pointer(*np,
148 rcu_dereference_protected(n->next,
149 lockdep_is_held(&tbl->lock)));
152 write_unlock(&n->lock);
153 neigh_cleanup_and_release(n);
156 write_unlock(&n->lock);
161 tbl->last_flush = jiffies;
163 write_unlock_bh(&tbl->lock);
168 static void neigh_add_timer(struct neighbour *n, unsigned long when)
171 if (unlikely(mod_timer(&n->timer, when))) {
172 printk("NEIGH: BUG, double timer add, state is %x\n",
178 static int neigh_del_timer(struct neighbour *n)
180 if ((n->nud_state & NUD_IN_TIMER) &&
181 del_timer(&n->timer)) {
188 static void pneigh_queue_purge(struct sk_buff_head *list)
192 while ((skb = skb_dequeue(list)) != NULL) {
198 static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev)
201 struct neigh_hash_table *nht;
203 nht = rcu_dereference_protected(tbl->nht,
204 lockdep_is_held(&tbl->lock));
206 for (i = 0; i < (1 << nht->hash_shift); i++) {
208 struct neighbour __rcu **np = &nht->hash_buckets[i];
210 while ((n = rcu_dereference_protected(*np,
211 lockdep_is_held(&tbl->lock))) != NULL) {
212 if (dev && n->dev != dev) {
216 rcu_assign_pointer(*np,
217 rcu_dereference_protected(n->next,
218 lockdep_is_held(&tbl->lock)));
219 write_lock(&n->lock);
223 if (atomic_read(&n->refcnt) != 1) {
224 /* The most unpleasant situation.
225 We must destroy neighbour entry,
226 but someone still uses it.
228 The destroy will be delayed until
229 the last user releases us, but
230 we must kill timers etc. and move
233 __skb_queue_purge(&n->arp_queue);
234 n->arp_queue_len_bytes = 0;
235 n->output = neigh_blackhole;
236 if (n->nud_state & NUD_VALID)
237 n->nud_state = NUD_NOARP;
239 n->nud_state = NUD_NONE;
240 neigh_dbg(2, "neigh %p is stray\n", n);
242 write_unlock(&n->lock);
243 neigh_cleanup_and_release(n);
248 void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev)
250 write_lock_bh(&tbl->lock);
251 neigh_flush_dev(tbl, dev);
252 write_unlock_bh(&tbl->lock);
254 EXPORT_SYMBOL(neigh_changeaddr);
256 int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
258 write_lock_bh(&tbl->lock);
259 neigh_flush_dev(tbl, dev);
260 pneigh_ifdown_and_unlock(tbl, dev);
262 del_timer_sync(&tbl->proxy_timer);
263 pneigh_queue_purge(&tbl->proxy_queue);
266 EXPORT_SYMBOL(neigh_ifdown);
268 static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device *dev)
270 struct neighbour *n = NULL;
271 unsigned long now = jiffies;
274 entries = atomic_inc_return(&tbl->entries) - 1;
275 if (entries >= tbl->gc_thresh3 ||
276 (entries >= tbl->gc_thresh2 &&
277 time_after(now, tbl->last_flush + 5 * HZ))) {
278 if (!neigh_forced_gc(tbl) &&
279 entries >= tbl->gc_thresh3) {
280 net_info_ratelimited("%s: neighbor table overflow!\n",
282 NEIGH_CACHE_STAT_INC(tbl, table_fulls);
287 n = kzalloc(tbl->entry_size + dev->neigh_priv_len, GFP_ATOMIC);
291 __skb_queue_head_init(&n->arp_queue);
292 rwlock_init(&n->lock);
293 seqlock_init(&n->ha_lock);
294 n->updated = n->used = now;
295 n->nud_state = NUD_NONE;
296 n->output = neigh_blackhole;
297 seqlock_init(&n->hh.hh_lock);
298 n->parms = neigh_parms_clone(&tbl->parms);
299 setup_timer(&n->timer, neigh_timer_handler, (unsigned long)n);
301 NEIGH_CACHE_STAT_INC(tbl, allocs);
303 atomic_set(&n->refcnt, 1);
309 atomic_dec(&tbl->entries);
313 static void neigh_get_hash_rnd(u32 *x)
315 get_random_bytes(x, sizeof(*x));
319 static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)
321 size_t size = (1 << shift) * sizeof(struct neighbour *);
322 struct neigh_hash_table *ret;
323 struct neighbour __rcu **buckets;
326 ret = kmalloc(sizeof(*ret), GFP_ATOMIC);
329 if (size <= PAGE_SIZE) {
330 buckets = kzalloc(size, GFP_ATOMIC);
332 buckets = (struct neighbour __rcu **)
333 __get_free_pages(GFP_ATOMIC | __GFP_ZERO,
335 kmemleak_alloc(buckets, size, 1, GFP_ATOMIC);
341 ret->hash_buckets = buckets;
342 ret->hash_shift = shift;
343 for (i = 0; i < NEIGH_NUM_HASH_RND; i++)
344 neigh_get_hash_rnd(&ret->hash_rnd[i]);
348 static void neigh_hash_free_rcu(struct rcu_head *head)
350 struct neigh_hash_table *nht = container_of(head,
351 struct neigh_hash_table,
353 size_t size = (1 << nht->hash_shift) * sizeof(struct neighbour *);
354 struct neighbour __rcu **buckets = nht->hash_buckets;
356 if (size <= PAGE_SIZE) {
359 kmemleak_free(buckets);
360 free_pages((unsigned long)buckets, get_order(size));
365 static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl,
366 unsigned long new_shift)
368 unsigned int i, hash;
369 struct neigh_hash_table *new_nht, *old_nht;
371 NEIGH_CACHE_STAT_INC(tbl, hash_grows);
373 old_nht = rcu_dereference_protected(tbl->nht,
374 lockdep_is_held(&tbl->lock));
375 new_nht = neigh_hash_alloc(new_shift);
379 for (i = 0; i < (1 << old_nht->hash_shift); i++) {
380 struct neighbour *n, *next;
382 for (n = rcu_dereference_protected(old_nht->hash_buckets[i],
383 lockdep_is_held(&tbl->lock));
386 hash = tbl->hash(n->primary_key, n->dev,
389 hash >>= (32 - new_nht->hash_shift);
390 next = rcu_dereference_protected(n->next,
391 lockdep_is_held(&tbl->lock));
393 rcu_assign_pointer(n->next,
394 rcu_dereference_protected(
395 new_nht->hash_buckets[hash],
396 lockdep_is_held(&tbl->lock)));
397 rcu_assign_pointer(new_nht->hash_buckets[hash], n);
401 rcu_assign_pointer(tbl->nht, new_nht);
402 call_rcu(&old_nht->rcu, neigh_hash_free_rcu);
406 struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
407 struct net_device *dev)
411 NEIGH_CACHE_STAT_INC(tbl, lookups);
414 n = __neigh_lookup_noref(tbl, pkey, dev);
416 if (!atomic_inc_not_zero(&n->refcnt))
418 NEIGH_CACHE_STAT_INC(tbl, hits);
421 rcu_read_unlock_bh();
424 EXPORT_SYMBOL(neigh_lookup);
426 struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
430 int key_len = tbl->key_len;
432 struct neigh_hash_table *nht;
434 NEIGH_CACHE_STAT_INC(tbl, lookups);
437 nht = rcu_dereference_bh(tbl->nht);
438 hash_val = tbl->hash(pkey, NULL, nht->hash_rnd) >> (32 - nht->hash_shift);
440 for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
442 n = rcu_dereference_bh(n->next)) {
443 if (!memcmp(n->primary_key, pkey, key_len) &&
444 net_eq(dev_net(n->dev), net)) {
445 if (!atomic_inc_not_zero(&n->refcnt))
447 NEIGH_CACHE_STAT_INC(tbl, hits);
452 rcu_read_unlock_bh();
455 EXPORT_SYMBOL(neigh_lookup_nodev);
457 struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
458 struct net_device *dev, bool want_ref)
461 int key_len = tbl->key_len;
463 struct neighbour *n1, *rc, *n = neigh_alloc(tbl, dev);
464 struct neigh_hash_table *nht;
467 rc = ERR_PTR(-ENOBUFS);
471 memcpy(n->primary_key, pkey, key_len);
475 /* Protocol specific setup. */
476 if (tbl->constructor && (error = tbl->constructor(n)) < 0) {
478 goto out_neigh_release;
481 if (dev->netdev_ops->ndo_neigh_construct) {
482 error = dev->netdev_ops->ndo_neigh_construct(n);
485 goto out_neigh_release;
489 /* Device specific setup. */
490 if (n->parms->neigh_setup &&
491 (error = n->parms->neigh_setup(n)) < 0) {
493 goto out_neigh_release;
496 n->confirmed = jiffies - (NEIGH_VAR(n->parms, BASE_REACHABLE_TIME) << 1);
498 write_lock_bh(&tbl->lock);
499 nht = rcu_dereference_protected(tbl->nht,
500 lockdep_is_held(&tbl->lock));
502 if (atomic_read(&tbl->entries) > (1 << nht->hash_shift))
503 nht = neigh_hash_grow(tbl, nht->hash_shift + 1);
505 hash_val = tbl->hash(n->primary_key, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
507 if (n->parms->dead) {
508 rc = ERR_PTR(-EINVAL);
512 for (n1 = rcu_dereference_protected(nht->hash_buckets[hash_val],
513 lockdep_is_held(&tbl->lock));
515 n1 = rcu_dereference_protected(n1->next,
516 lockdep_is_held(&tbl->lock))) {
517 if (dev == n1->dev && !memcmp(n1->primary_key, n->primary_key, key_len)) {
528 rcu_assign_pointer(n->next,
529 rcu_dereference_protected(nht->hash_buckets[hash_val],
530 lockdep_is_held(&tbl->lock)));
531 rcu_assign_pointer(nht->hash_buckets[hash_val], n);
532 write_unlock_bh(&tbl->lock);
533 neigh_dbg(2, "neigh %p is created\n", n);
538 write_unlock_bh(&tbl->lock);
543 EXPORT_SYMBOL(__neigh_create);
545 static u32 pneigh_hash(const void *pkey, int key_len)
547 u32 hash_val = *(u32 *)(pkey + key_len - 4);
548 hash_val ^= (hash_val >> 16);
549 hash_val ^= hash_val >> 8;
550 hash_val ^= hash_val >> 4;
551 hash_val &= PNEIGH_HASHMASK;
555 static struct pneigh_entry *__pneigh_lookup_1(struct pneigh_entry *n,
559 struct net_device *dev)
562 if (!memcmp(n->key, pkey, key_len) &&
563 net_eq(pneigh_net(n), net) &&
564 (n->dev == dev || !n->dev))
571 struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl,
572 struct net *net, const void *pkey, struct net_device *dev)
574 int key_len = tbl->key_len;
575 u32 hash_val = pneigh_hash(pkey, key_len);
577 return __pneigh_lookup_1(tbl->phash_buckets[hash_val],
578 net, pkey, key_len, dev);
580 EXPORT_SYMBOL_GPL(__pneigh_lookup);
582 struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
583 struct net *net, const void *pkey,
584 struct net_device *dev, int creat)
586 struct pneigh_entry *n;
587 int key_len = tbl->key_len;
588 u32 hash_val = pneigh_hash(pkey, key_len);
590 read_lock_bh(&tbl->lock);
591 n = __pneigh_lookup_1(tbl->phash_buckets[hash_val],
592 net, pkey, key_len, dev);
593 read_unlock_bh(&tbl->lock);
600 n = kzalloc(sizeof(*n) + key_len, GFP_KERNEL);
604 write_pnet(&n->net, net);
605 memcpy(n->key, pkey, key_len);
610 if (tbl->pconstructor && tbl->pconstructor(n)) {
618 write_lock_bh(&tbl->lock);
619 n->next = tbl->phash_buckets[hash_val];
620 tbl->phash_buckets[hash_val] = n;
621 write_unlock_bh(&tbl->lock);
625 EXPORT_SYMBOL(pneigh_lookup);
628 int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
629 struct net_device *dev)
631 struct pneigh_entry *n, **np;
632 int key_len = tbl->key_len;
633 u32 hash_val = pneigh_hash(pkey, key_len);
635 write_lock_bh(&tbl->lock);
636 for (np = &tbl->phash_buckets[hash_val]; (n = *np) != NULL;
638 if (!memcmp(n->key, pkey, key_len) && n->dev == dev &&
639 net_eq(pneigh_net(n), net)) {
641 write_unlock_bh(&tbl->lock);
642 if (tbl->pdestructor)
650 write_unlock_bh(&tbl->lock);
654 static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
655 struct net_device *dev)
657 struct pneigh_entry *n, **np, *freelist = NULL;
660 for (h = 0; h <= PNEIGH_HASHMASK; h++) {
661 np = &tbl->phash_buckets[h];
662 while ((n = *np) != NULL) {
663 if (!dev || n->dev == dev) {
672 write_unlock_bh(&tbl->lock);
673 while ((n = freelist)) {
676 if (tbl->pdestructor)
685 static void neigh_parms_destroy(struct neigh_parms *parms);
687 static inline void neigh_parms_put(struct neigh_parms *parms)
689 if (atomic_dec_and_test(&parms->refcnt))
690 neigh_parms_destroy(parms);
694 * neighbour must already be out of the table;
697 void neigh_destroy(struct neighbour *neigh)
699 struct net_device *dev = neigh->dev;
701 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys);
704 pr_warn("Destroying alive neighbour %p\n", neigh);
709 if (neigh_del_timer(neigh))
710 pr_warn("Impossible event\n");
712 write_lock_bh(&neigh->lock);
713 __skb_queue_purge(&neigh->arp_queue);
714 write_unlock_bh(&neigh->lock);
715 neigh->arp_queue_len_bytes = 0;
717 if (dev->netdev_ops->ndo_neigh_destroy)
718 dev->netdev_ops->ndo_neigh_destroy(neigh);
721 neigh_parms_put(neigh->parms);
723 neigh_dbg(2, "neigh %p is destroyed\n", neigh);
725 atomic_dec(&neigh->tbl->entries);
726 kfree_rcu(neigh, rcu);
728 EXPORT_SYMBOL(neigh_destroy);
730 /* Neighbour state is suspicious;
733 Called with write_locked neigh.
735 static void neigh_suspect(struct neighbour *neigh)
737 neigh_dbg(2, "neigh %p is suspected\n", neigh);
739 neigh->output = neigh->ops->output;
742 /* Neighbour state is OK;
745 Called with write_locked neigh.
747 static void neigh_connect(struct neighbour *neigh)
749 neigh_dbg(2, "neigh %p is connected\n", neigh);
751 neigh->output = neigh->ops->connected_output;
754 static void neigh_periodic_work(struct work_struct *work)
756 struct neigh_table *tbl = container_of(work, struct neigh_table, gc_work.work);
758 struct neighbour __rcu **np;
760 struct neigh_hash_table *nht;
762 NEIGH_CACHE_STAT_INC(tbl, periodic_gc_runs);
764 write_lock_bh(&tbl->lock);
765 nht = rcu_dereference_protected(tbl->nht,
766 lockdep_is_held(&tbl->lock));
769 * periodically recompute ReachableTime from random function
772 if (time_after(jiffies, tbl->last_rand + 300 * HZ)) {
773 struct neigh_parms *p;
774 tbl->last_rand = jiffies;
775 list_for_each_entry(p, &tbl->parms_list, list)
777 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
780 if (atomic_read(&tbl->entries) < tbl->gc_thresh1)
783 for (i = 0 ; i < (1 << nht->hash_shift); i++) {
784 np = &nht->hash_buckets[i];
786 while ((n = rcu_dereference_protected(*np,
787 lockdep_is_held(&tbl->lock))) != NULL) {
790 write_lock(&n->lock);
792 state = n->nud_state;
793 if (state & (NUD_PERMANENT | NUD_IN_TIMER)) {
794 write_unlock(&n->lock);
798 if (time_before(n->used, n->confirmed))
799 n->used = n->confirmed;
801 if (atomic_read(&n->refcnt) == 1 &&
802 (state == NUD_FAILED ||
803 time_after(jiffies, n->used + NEIGH_VAR(n->parms, GC_STALETIME)))) {
806 write_unlock(&n->lock);
807 neigh_cleanup_and_release(n);
810 write_unlock(&n->lock);
816 * It's fine to release lock here, even if hash table
817 * grows while we are preempted.
819 write_unlock_bh(&tbl->lock);
821 write_lock_bh(&tbl->lock);
822 nht = rcu_dereference_protected(tbl->nht,
823 lockdep_is_held(&tbl->lock));
826 /* Cycle through all hash buckets every BASE_REACHABLE_TIME/2 ticks.
827 * ARP entry timeouts range from 1/2 BASE_REACHABLE_TIME to 3/2
828 * BASE_REACHABLE_TIME.
830 queue_delayed_work(system_power_efficient_wq, &tbl->gc_work,
831 NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1);
832 write_unlock_bh(&tbl->lock);
835 static __inline__ int neigh_max_probes(struct neighbour *n)
837 struct neigh_parms *p = n->parms;
838 return NEIGH_VAR(p, UCAST_PROBES) + NEIGH_VAR(p, APP_PROBES) +
839 (n->nud_state & NUD_PROBE ? NEIGH_VAR(p, MCAST_REPROBES) :
840 NEIGH_VAR(p, MCAST_PROBES));
843 static void neigh_invalidate(struct neighbour *neigh)
844 __releases(neigh->lock)
845 __acquires(neigh->lock)
849 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
850 neigh_dbg(2, "neigh %p is failed\n", neigh);
851 neigh->updated = jiffies;
853 /* It is very thin place. report_unreachable is very complicated
854 routine. Particularly, it can hit the same neighbour entry!
856 So that, we try to be accurate and avoid dead loop. --ANK
858 while (neigh->nud_state == NUD_FAILED &&
859 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
860 write_unlock(&neigh->lock);
861 neigh->ops->error_report(neigh, skb);
862 write_lock(&neigh->lock);
864 __skb_queue_purge(&neigh->arp_queue);
865 neigh->arp_queue_len_bytes = 0;
868 static void neigh_probe(struct neighbour *neigh)
869 __releases(neigh->lock)
871 struct sk_buff *skb = skb_peek_tail(&neigh->arp_queue);
872 /* keep skb alive even if arp_queue overflows */
874 skb = skb_clone(skb, GFP_ATOMIC);
875 write_unlock(&neigh->lock);
876 if (neigh->ops->solicit)
877 neigh->ops->solicit(neigh, skb);
878 atomic_inc(&neigh->probes);
882 /* Called when a timer expires for a neighbour entry. */
884 static void neigh_timer_handler(unsigned long arg)
886 unsigned long now, next;
887 struct neighbour *neigh = (struct neighbour *)arg;
891 write_lock(&neigh->lock);
893 state = neigh->nud_state;
897 if (!(state & NUD_IN_TIMER))
900 if (state & NUD_REACHABLE) {
901 if (time_before_eq(now,
902 neigh->confirmed + neigh->parms->reachable_time)) {
903 neigh_dbg(2, "neigh %p is still alive\n", neigh);
904 next = neigh->confirmed + neigh->parms->reachable_time;
905 } else if (time_before_eq(now,
907 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
908 neigh_dbg(2, "neigh %p is delayed\n", neigh);
909 neigh->nud_state = NUD_DELAY;
910 neigh->updated = jiffies;
911 neigh_suspect(neigh);
912 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME);
914 neigh_dbg(2, "neigh %p is suspected\n", neigh);
915 neigh->nud_state = NUD_STALE;
916 neigh->updated = jiffies;
917 neigh_suspect(neigh);
920 } else if (state & NUD_DELAY) {
921 if (time_before_eq(now,
923 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
924 neigh_dbg(2, "neigh %p is now reachable\n", neigh);
925 neigh->nud_state = NUD_REACHABLE;
926 neigh->updated = jiffies;
927 neigh_connect(neigh);
929 next = neigh->confirmed + neigh->parms->reachable_time;
931 neigh_dbg(2, "neigh %p is probed\n", neigh);
932 neigh->nud_state = NUD_PROBE;
933 neigh->updated = jiffies;
934 atomic_set(&neigh->probes, 0);
936 next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);
939 /* NUD_PROBE|NUD_INCOMPLETE */
940 next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);
943 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
944 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) {
945 neigh->nud_state = NUD_FAILED;
947 neigh_invalidate(neigh);
951 if (neigh->nud_state & NUD_IN_TIMER) {
952 if (time_before(next, jiffies + HZ/2))
953 next = jiffies + HZ/2;
954 if (!mod_timer(&neigh->timer, next))
957 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
961 write_unlock(&neigh->lock);
965 neigh_update_notify(neigh);
967 neigh_release(neigh);
970 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
973 bool immediate_probe = false;
975 write_lock_bh(&neigh->lock);
978 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
983 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
984 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
985 NEIGH_VAR(neigh->parms, APP_PROBES)) {
986 unsigned long next, now = jiffies;
988 atomic_set(&neigh->probes,
989 NEIGH_VAR(neigh->parms, UCAST_PROBES));
990 neigh_del_timer(neigh);
991 neigh->nud_state = NUD_INCOMPLETE;
992 neigh->updated = now;
993 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
995 neigh_add_timer(neigh, next);
996 immediate_probe = true;
998 neigh->nud_state = NUD_FAILED;
999 neigh->updated = jiffies;
1000 write_unlock_bh(&neigh->lock);
1005 } else if (neigh->nud_state & NUD_STALE) {
1006 neigh_dbg(2, "neigh %p is delayed\n", neigh);
1007 neigh_del_timer(neigh);
1008 neigh->nud_state = NUD_DELAY;
1009 neigh->updated = jiffies;
1010 neigh_add_timer(neigh, jiffies +
1011 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME));
1014 if (neigh->nud_state == NUD_INCOMPLETE) {
1016 while (neigh->arp_queue_len_bytes + skb->truesize >
1017 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) {
1018 struct sk_buff *buff;
1020 buff = __skb_dequeue(&neigh->arp_queue);
1023 neigh->arp_queue_len_bytes -= buff->truesize;
1025 NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards);
1028 __skb_queue_tail(&neigh->arp_queue, skb);
1029 neigh->arp_queue_len_bytes += skb->truesize;
1034 if (immediate_probe)
1037 write_unlock(&neigh->lock);
1042 if (neigh->nud_state & NUD_STALE)
1044 write_unlock_bh(&neigh->lock);
1048 EXPORT_SYMBOL(__neigh_event_send);
1050 static void neigh_update_hhs(struct neighbour *neigh)
1052 struct hh_cache *hh;
1053 void (*update)(struct hh_cache*, const struct net_device*, const unsigned char *)
1056 if (neigh->dev->header_ops)
1057 update = neigh->dev->header_ops->cache_update;
1061 if (READ_ONCE(hh->hh_len)) {
1062 write_seqlock_bh(&hh->hh_lock);
1063 update(hh, neigh->dev, neigh->ha);
1064 write_sequnlock_bh(&hh->hh_lock);
1071 /* Generic update routine.
1072 -- lladdr is new lladdr or NULL, if it is not supplied.
1073 -- new is new state.
1075 NEIGH_UPDATE_F_OVERRIDE allows to override existing lladdr,
1077 NEIGH_UPDATE_F_WEAK_OVERRIDE will suspect existing "connected"
1078 lladdr instead of overriding it
1080 It also allows to retain current state
1081 if lladdr is unchanged.
1082 NEIGH_UPDATE_F_ADMIN means that the change is administrative.
1084 NEIGH_UPDATE_F_OVERRIDE_ISROUTER allows to override existing
1086 NEIGH_UPDATE_F_ISROUTER indicates if the neighbour is known as
1089 Caller MUST hold reference count on the entry.
1092 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1098 struct net_device *dev;
1099 int update_isrouter = 0;
1101 write_lock_bh(&neigh->lock);
1104 old = neigh->nud_state;
1107 if (!(flags & NEIGH_UPDATE_F_ADMIN) &&
1108 (old & (NUD_NOARP | NUD_PERMANENT)))
1113 if (!(new & NUD_VALID)) {
1114 neigh_del_timer(neigh);
1115 if (old & NUD_CONNECTED)
1116 neigh_suspect(neigh);
1117 neigh->nud_state = new;
1119 notify = old & NUD_VALID;
1120 if ((old & (NUD_INCOMPLETE | NUD_PROBE)) &&
1121 (new & NUD_FAILED)) {
1122 neigh_invalidate(neigh);
1128 /* Compare new lladdr with cached one */
1129 if (!dev->addr_len) {
1130 /* First case: device needs no address. */
1132 } else if (lladdr) {
1133 /* The second case: if something is already cached
1134 and a new address is proposed:
1136 - if they are different, check override flag
1138 if ((old & NUD_VALID) &&
1139 !memcmp(lladdr, neigh->ha, dev->addr_len))
1142 /* No address is supplied; if we know something,
1143 use it, otherwise discard the request.
1146 if (!(old & NUD_VALID))
1151 /* Update confirmed timestamp for neighbour entry after we
1152 * received ARP packet even if it doesn't change IP to MAC binding.
1154 if (new & NUD_CONNECTED)
1155 neigh->confirmed = jiffies;
1157 /* If entry was valid and address is not changed,
1158 do not change entry state, if new one is STALE.
1161 update_isrouter = flags & NEIGH_UPDATE_F_OVERRIDE_ISROUTER;
1162 if (old & NUD_VALID) {
1163 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) {
1164 update_isrouter = 0;
1165 if ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) &&
1166 (old & NUD_CONNECTED)) {
1172 if (lladdr == neigh->ha && new == NUD_STALE &&
1173 ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
1174 (old & NUD_CONNECTED))
1180 /* Update timestamp only once we know we will make a change to the
1181 * neighbour entry. Otherwise we risk to move the locktime window with
1182 * noop updates and ignore relevant ARP updates.
1184 if (new != old || lladdr != neigh->ha)
1185 neigh->updated = jiffies;
1188 neigh_del_timer(neigh);
1189 if (new & NUD_PROBE)
1190 atomic_set(&neigh->probes, 0);
1191 if (new & NUD_IN_TIMER)
1192 neigh_add_timer(neigh, (jiffies +
1193 ((new & NUD_REACHABLE) ?
1194 neigh->parms->reachable_time :
1196 neigh->nud_state = new;
1200 if (lladdr != neigh->ha) {
1201 write_seqlock(&neigh->ha_lock);
1202 memcpy(&neigh->ha, lladdr, dev->addr_len);
1203 write_sequnlock(&neigh->ha_lock);
1204 neigh_update_hhs(neigh);
1205 if (!(new & NUD_CONNECTED))
1206 neigh->confirmed = jiffies -
1207 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1);
1212 if (new & NUD_CONNECTED)
1213 neigh_connect(neigh);
1215 neigh_suspect(neigh);
1216 if (!(old & NUD_VALID)) {
1217 struct sk_buff *skb;
1219 /* Again: avoid dead loop if something went wrong */
1221 while (neigh->nud_state & NUD_VALID &&
1222 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1223 struct dst_entry *dst = skb_dst(skb);
1224 struct neighbour *n2, *n1 = neigh;
1225 write_unlock_bh(&neigh->lock);
1229 /* Why not just use 'neigh' as-is? The problem is that
1230 * things such as shaper, eql, and sch_teql can end up
1231 * using alternative, different, neigh objects to output
1232 * the packet in the output path. So what we need to do
1233 * here is re-lookup the top-level neigh in the path so
1234 * we can reinject the packet there.
1237 if (dst && dst->obsolete != DST_OBSOLETE_DEAD) {
1238 n2 = dst_neigh_lookup_skb(dst, skb);
1242 n1->output(n1, skb);
1247 write_lock_bh(&neigh->lock);
1249 __skb_queue_purge(&neigh->arp_queue);
1250 neigh->arp_queue_len_bytes = 0;
1253 if (update_isrouter) {
1254 neigh->flags = (flags & NEIGH_UPDATE_F_ISROUTER) ?
1255 (neigh->flags | NTF_ROUTER) :
1256 (neigh->flags & ~NTF_ROUTER);
1258 write_unlock_bh(&neigh->lock);
1261 neigh_update_notify(neigh);
1265 EXPORT_SYMBOL(neigh_update);
1267 /* Update the neigh to listen temporarily for probe responses, even if it is
1268 * in a NUD_FAILED state. The caller has to hold neigh->lock for writing.
1270 void __neigh_set_probe_once(struct neighbour *neigh)
1274 neigh->updated = jiffies;
1275 if (!(neigh->nud_state & NUD_FAILED))
1277 neigh->nud_state = NUD_INCOMPLETE;
1278 atomic_set(&neigh->probes, neigh_max_probes(neigh));
1279 neigh_add_timer(neigh,
1280 jiffies + NEIGH_VAR(neigh->parms, RETRANS_TIME));
1282 EXPORT_SYMBOL(__neigh_set_probe_once);
1284 struct neighbour *neigh_event_ns(struct neigh_table *tbl,
1285 u8 *lladdr, void *saddr,
1286 struct net_device *dev)
1288 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev,
1289 lladdr || !dev->addr_len);
1291 neigh_update(neigh, lladdr, NUD_STALE,
1292 NEIGH_UPDATE_F_OVERRIDE);
1295 EXPORT_SYMBOL(neigh_event_ns);
1297 /* called with read_lock_bh(&n->lock); */
1298 static void neigh_hh_init(struct neighbour *n)
1300 struct net_device *dev = n->dev;
1301 __be16 prot = n->tbl->protocol;
1302 struct hh_cache *hh = &n->hh;
1304 write_lock_bh(&n->lock);
1306 /* Only one thread can come in here and initialize the
1310 dev->header_ops->cache(n, hh, prot);
1312 write_unlock_bh(&n->lock);
1315 /* Slow and careful. */
1317 int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
1321 if (!neigh_event_send(neigh, skb)) {
1323 struct net_device *dev = neigh->dev;
1326 if (dev->header_ops->cache && !READ_ONCE(neigh->hh.hh_len))
1327 neigh_hh_init(neigh);
1330 __skb_pull(skb, skb_network_offset(skb));
1331 seq = read_seqbegin(&neigh->ha_lock);
1332 err = dev_hard_header(skb, dev, ntohs(skb->protocol),
1333 neigh->ha, NULL, skb->len);
1334 } while (read_seqretry(&neigh->ha_lock, seq));
1337 rc = dev_queue_xmit(skb);
1348 EXPORT_SYMBOL(neigh_resolve_output);
1350 /* As fast as possible without hh cache */
1352 int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
1354 struct net_device *dev = neigh->dev;
1359 __skb_pull(skb, skb_network_offset(skb));
1360 seq = read_seqbegin(&neigh->ha_lock);
1361 err = dev_hard_header(skb, dev, ntohs(skb->protocol),
1362 neigh->ha, NULL, skb->len);
1363 } while (read_seqretry(&neigh->ha_lock, seq));
1366 err = dev_queue_xmit(skb);
1373 EXPORT_SYMBOL(neigh_connected_output);
1375 int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb)
1377 return dev_queue_xmit(skb);
1379 EXPORT_SYMBOL(neigh_direct_output);
1381 static void neigh_proxy_process(unsigned long arg)
1383 struct neigh_table *tbl = (struct neigh_table *)arg;
1384 long sched_next = 0;
1385 unsigned long now = jiffies;
1386 struct sk_buff *skb, *n;
1388 spin_lock(&tbl->proxy_queue.lock);
1390 skb_queue_walk_safe(&tbl->proxy_queue, skb, n) {
1391 long tdif = NEIGH_CB(skb)->sched_next - now;
1394 struct net_device *dev = skb->dev;
1396 __skb_unlink(skb, &tbl->proxy_queue);
1397 if (tbl->proxy_redo && netif_running(dev)) {
1399 tbl->proxy_redo(skb);
1406 } else if (!sched_next || tdif < sched_next)
1409 del_timer(&tbl->proxy_timer);
1411 mod_timer(&tbl->proxy_timer, jiffies + sched_next);
1412 spin_unlock(&tbl->proxy_queue.lock);
1415 void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
1416 struct sk_buff *skb)
1418 unsigned long now = jiffies;
1420 unsigned long sched_next = now + (prandom_u32() %
1421 NEIGH_VAR(p, PROXY_DELAY));
1423 if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) {
1428 NEIGH_CB(skb)->sched_next = sched_next;
1429 NEIGH_CB(skb)->flags |= LOCALLY_ENQUEUED;
1431 spin_lock(&tbl->proxy_queue.lock);
1432 if (del_timer(&tbl->proxy_timer)) {
1433 if (time_before(tbl->proxy_timer.expires, sched_next))
1434 sched_next = tbl->proxy_timer.expires;
1438 __skb_queue_tail(&tbl->proxy_queue, skb);
1439 mod_timer(&tbl->proxy_timer, sched_next);
1440 spin_unlock(&tbl->proxy_queue.lock);
1442 EXPORT_SYMBOL(pneigh_enqueue);
1444 static inline struct neigh_parms *lookup_neigh_parms(struct neigh_table *tbl,
1445 struct net *net, int ifindex)
1447 struct neigh_parms *p;
1449 list_for_each_entry(p, &tbl->parms_list, list) {
1450 if ((p->dev && p->dev->ifindex == ifindex && net_eq(neigh_parms_net(p), net)) ||
1451 (!p->dev && !ifindex && net_eq(net, &init_net)))
1458 struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1459 struct neigh_table *tbl)
1461 struct neigh_parms *p;
1462 struct net *net = dev_net(dev);
1463 const struct net_device_ops *ops = dev->netdev_ops;
1465 p = kmemdup(&tbl->parms, sizeof(*p), GFP_KERNEL);
1468 atomic_set(&p->refcnt, 1);
1470 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
1473 write_pnet(&p->net, net);
1474 p->sysctl_table = NULL;
1476 if (ops->ndo_neigh_setup && ops->ndo_neigh_setup(dev, p)) {
1482 write_lock_bh(&tbl->lock);
1483 list_add(&p->list, &tbl->parms.list);
1484 write_unlock_bh(&tbl->lock);
1486 neigh_parms_data_state_cleanall(p);
1490 EXPORT_SYMBOL(neigh_parms_alloc);
1492 static void neigh_rcu_free_parms(struct rcu_head *head)
1494 struct neigh_parms *parms =
1495 container_of(head, struct neigh_parms, rcu_head);
1497 neigh_parms_put(parms);
1500 void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
1502 if (!parms || parms == &tbl->parms)
1504 write_lock_bh(&tbl->lock);
1505 list_del(&parms->list);
1507 write_unlock_bh(&tbl->lock);
1509 dev_put(parms->dev);
1510 call_rcu(&parms->rcu_head, neigh_rcu_free_parms);
1512 EXPORT_SYMBOL(neigh_parms_release);
1514 static void neigh_parms_destroy(struct neigh_parms *parms)
1519 static struct lock_class_key neigh_table_proxy_queue_class;
1521 static struct neigh_table *neigh_tables[NEIGH_NR_TABLES] __read_mostly;
1523 void neigh_table_init(int index, struct neigh_table *tbl)
1525 unsigned long now = jiffies;
1526 unsigned long phsize;
1528 INIT_LIST_HEAD(&tbl->parms_list);
1529 list_add(&tbl->parms.list, &tbl->parms_list);
1530 write_pnet(&tbl->parms.net, &init_net);
1531 atomic_set(&tbl->parms.refcnt, 1);
1532 tbl->parms.reachable_time =
1533 neigh_rand_reach_time(NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME));
1535 tbl->stats = alloc_percpu(struct neigh_statistics);
1537 panic("cannot create neighbour cache statistics");
1539 #ifdef CONFIG_PROC_FS
1540 if (!proc_create_data(tbl->id, 0, init_net.proc_net_stat,
1541 &neigh_stat_seq_fops, tbl))
1542 panic("cannot create neighbour proc dir entry");
1545 RCU_INIT_POINTER(tbl->nht, neigh_hash_alloc(3));
1547 phsize = (PNEIGH_HASHMASK + 1) * sizeof(struct pneigh_entry *);
1548 tbl->phash_buckets = kzalloc(phsize, GFP_KERNEL);
1550 if (!tbl->nht || !tbl->phash_buckets)
1551 panic("cannot allocate neighbour cache hashes");
1553 if (!tbl->entry_size)
1554 tbl->entry_size = ALIGN(offsetof(struct neighbour, primary_key) +
1555 tbl->key_len, NEIGH_PRIV_ALIGN);
1557 WARN_ON(tbl->entry_size % NEIGH_PRIV_ALIGN);
1559 rwlock_init(&tbl->lock);
1560 INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work);
1561 queue_delayed_work(system_power_efficient_wq, &tbl->gc_work,
1562 tbl->parms.reachable_time);
1563 setup_timer(&tbl->proxy_timer, neigh_proxy_process, (unsigned long)tbl);
1564 skb_queue_head_init_class(&tbl->proxy_queue,
1565 &neigh_table_proxy_queue_class);
1567 tbl->last_flush = now;
1568 tbl->last_rand = now + tbl->parms.reachable_time * 20;
1570 neigh_tables[index] = tbl;
1572 EXPORT_SYMBOL(neigh_table_init);
1574 int neigh_table_clear(int index, struct neigh_table *tbl)
1576 neigh_tables[index] = NULL;
1577 /* It is not clean... Fix it to unload IPv6 module safely */
1578 cancel_delayed_work_sync(&tbl->gc_work);
1579 del_timer_sync(&tbl->proxy_timer);
1580 pneigh_queue_purge(&tbl->proxy_queue);
1581 neigh_ifdown(tbl, NULL);
1582 if (atomic_read(&tbl->entries))
1583 pr_crit("neighbour leakage\n");
1585 call_rcu(&rcu_dereference_protected(tbl->nht, 1)->rcu,
1586 neigh_hash_free_rcu);
1589 kfree(tbl->phash_buckets);
1590 tbl->phash_buckets = NULL;
1592 remove_proc_entry(tbl->id, init_net.proc_net_stat);
1594 free_percpu(tbl->stats);
1599 EXPORT_SYMBOL(neigh_table_clear);
1601 static struct neigh_table *neigh_find_table(int family)
1603 struct neigh_table *tbl = NULL;
1607 tbl = neigh_tables[NEIGH_ARP_TABLE];
1610 tbl = neigh_tables[NEIGH_ND_TABLE];
1613 tbl = neigh_tables[NEIGH_DN_TABLE];
1620 static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh)
1622 struct net *net = sock_net(skb->sk);
1624 struct nlattr *dst_attr;
1625 struct neigh_table *tbl;
1626 struct neighbour *neigh;
1627 struct net_device *dev = NULL;
1631 if (nlmsg_len(nlh) < sizeof(*ndm))
1634 dst_attr = nlmsg_find_attr(nlh, sizeof(*ndm), NDA_DST);
1635 if (dst_attr == NULL)
1638 ndm = nlmsg_data(nlh);
1639 if (ndm->ndm_ifindex) {
1640 dev = __dev_get_by_index(net, ndm->ndm_ifindex);
1647 tbl = neigh_find_table(ndm->ndm_family);
1649 return -EAFNOSUPPORT;
1651 if (nla_len(dst_attr) < tbl->key_len)
1654 if (ndm->ndm_flags & NTF_PROXY) {
1655 err = pneigh_delete(tbl, net, nla_data(dst_attr), dev);
1662 neigh = neigh_lookup(tbl, nla_data(dst_attr), dev);
1663 if (neigh == NULL) {
1668 err = neigh_update(neigh, NULL, NUD_FAILED,
1669 NEIGH_UPDATE_F_OVERRIDE |
1670 NEIGH_UPDATE_F_ADMIN);
1671 neigh_release(neigh);
1677 static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh)
1679 int flags = NEIGH_UPDATE_F_ADMIN | NEIGH_UPDATE_F_OVERRIDE;
1680 struct net *net = sock_net(skb->sk);
1682 struct nlattr *tb[NDA_MAX+1];
1683 struct neigh_table *tbl;
1684 struct net_device *dev = NULL;
1685 struct neighbour *neigh;
1690 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
1695 if (tb[NDA_DST] == NULL)
1698 ndm = nlmsg_data(nlh);
1699 if (ndm->ndm_ifindex) {
1700 dev = __dev_get_by_index(net, ndm->ndm_ifindex);
1706 if (tb[NDA_LLADDR] && nla_len(tb[NDA_LLADDR]) < dev->addr_len)
1710 tbl = neigh_find_table(ndm->ndm_family);
1712 return -EAFNOSUPPORT;
1714 if (nla_len(tb[NDA_DST]) < tbl->key_len)
1716 dst = nla_data(tb[NDA_DST]);
1717 lladdr = tb[NDA_LLADDR] ? nla_data(tb[NDA_LLADDR]) : NULL;
1719 if (ndm->ndm_flags & NTF_PROXY) {
1720 struct pneigh_entry *pn;
1723 pn = pneigh_lookup(tbl, net, dst, dev, 1);
1725 pn->flags = ndm->ndm_flags;
1734 neigh = neigh_lookup(tbl, dst, dev);
1735 if (neigh == NULL) {
1736 if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
1741 neigh = __neigh_lookup_errno(tbl, dst, dev);
1742 if (IS_ERR(neigh)) {
1743 err = PTR_ERR(neigh);
1747 if (nlh->nlmsg_flags & NLM_F_EXCL) {
1749 neigh_release(neigh);
1753 if (!(nlh->nlmsg_flags & NLM_F_REPLACE))
1754 flags &= ~NEIGH_UPDATE_F_OVERRIDE;
1757 if (ndm->ndm_flags & NTF_USE) {
1758 neigh_event_send(neigh, NULL);
1761 err = neigh_update(neigh, lladdr, ndm->ndm_state, flags);
1762 neigh_release(neigh);
1768 static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
1770 struct nlattr *nest;
1772 nest = nla_nest_start(skb, NDTA_PARMS);
1777 nla_put_u32(skb, NDTPA_IFINDEX, parms->dev->ifindex)) ||
1778 nla_put_u32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt)) ||
1779 nla_put_u32(skb, NDTPA_QUEUE_LENBYTES,
1780 NEIGH_VAR(parms, QUEUE_LEN_BYTES)) ||
1781 /* approximative value for deprecated QUEUE_LEN (in packets) */
1782 nla_put_u32(skb, NDTPA_QUEUE_LEN,
1783 NEIGH_VAR(parms, QUEUE_LEN_BYTES) / SKB_TRUESIZE(ETH_FRAME_LEN)) ||
1784 nla_put_u32(skb, NDTPA_PROXY_QLEN, NEIGH_VAR(parms, PROXY_QLEN)) ||
1785 nla_put_u32(skb, NDTPA_APP_PROBES, NEIGH_VAR(parms, APP_PROBES)) ||
1786 nla_put_u32(skb, NDTPA_UCAST_PROBES,
1787 NEIGH_VAR(parms, UCAST_PROBES)) ||
1788 nla_put_u32(skb, NDTPA_MCAST_PROBES,
1789 NEIGH_VAR(parms, MCAST_PROBES)) ||
1790 nla_put_u32(skb, NDTPA_MCAST_REPROBES,
1791 NEIGH_VAR(parms, MCAST_REPROBES)) ||
1792 nla_put_msecs(skb, NDTPA_REACHABLE_TIME, parms->reachable_time) ||
1793 nla_put_msecs(skb, NDTPA_BASE_REACHABLE_TIME,
1794 NEIGH_VAR(parms, BASE_REACHABLE_TIME)) ||
1795 nla_put_msecs(skb, NDTPA_GC_STALETIME,
1796 NEIGH_VAR(parms, GC_STALETIME)) ||
1797 nla_put_msecs(skb, NDTPA_DELAY_PROBE_TIME,
1798 NEIGH_VAR(parms, DELAY_PROBE_TIME)) ||
1799 nla_put_msecs(skb, NDTPA_RETRANS_TIME,
1800 NEIGH_VAR(parms, RETRANS_TIME)) ||
1801 nla_put_msecs(skb, NDTPA_ANYCAST_DELAY,
1802 NEIGH_VAR(parms, ANYCAST_DELAY)) ||
1803 nla_put_msecs(skb, NDTPA_PROXY_DELAY,
1804 NEIGH_VAR(parms, PROXY_DELAY)) ||
1805 nla_put_msecs(skb, NDTPA_LOCKTIME,
1806 NEIGH_VAR(parms, LOCKTIME)))
1807 goto nla_put_failure;
1808 return nla_nest_end(skb, nest);
1811 nla_nest_cancel(skb, nest);
1815 static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
1816 u32 pid, u32 seq, int type, int flags)
1818 struct nlmsghdr *nlh;
1819 struct ndtmsg *ndtmsg;
1821 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndtmsg), flags);
1825 ndtmsg = nlmsg_data(nlh);
1827 read_lock_bh(&tbl->lock);
1828 ndtmsg->ndtm_family = tbl->family;
1829 ndtmsg->ndtm_pad1 = 0;
1830 ndtmsg->ndtm_pad2 = 0;
1832 if (nla_put_string(skb, NDTA_NAME, tbl->id) ||
1833 nla_put_msecs(skb, NDTA_GC_INTERVAL, tbl->gc_interval) ||
1834 nla_put_u32(skb, NDTA_THRESH1, tbl->gc_thresh1) ||
1835 nla_put_u32(skb, NDTA_THRESH2, tbl->gc_thresh2) ||
1836 nla_put_u32(skb, NDTA_THRESH3, tbl->gc_thresh3))
1837 goto nla_put_failure;
1839 unsigned long now = jiffies;
1840 long flush_delta = now - tbl->last_flush;
1841 long rand_delta = now - tbl->last_rand;
1842 struct neigh_hash_table *nht;
1843 struct ndt_config ndc = {
1844 .ndtc_key_len = tbl->key_len,
1845 .ndtc_entry_size = tbl->entry_size,
1846 .ndtc_entries = atomic_read(&tbl->entries),
1847 .ndtc_last_flush = jiffies_to_msecs(flush_delta),
1848 .ndtc_last_rand = jiffies_to_msecs(rand_delta),
1849 .ndtc_proxy_qlen = tbl->proxy_queue.qlen,
1853 nht = rcu_dereference_bh(tbl->nht);
1854 ndc.ndtc_hash_rnd = nht->hash_rnd[0];
1855 ndc.ndtc_hash_mask = ((1 << nht->hash_shift) - 1);
1856 rcu_read_unlock_bh();
1858 if (nla_put(skb, NDTA_CONFIG, sizeof(ndc), &ndc))
1859 goto nla_put_failure;
1864 struct ndt_stats ndst;
1866 memset(&ndst, 0, sizeof(ndst));
1868 for_each_possible_cpu(cpu) {
1869 struct neigh_statistics *st;
1871 st = per_cpu_ptr(tbl->stats, cpu);
1872 ndst.ndts_allocs += st->allocs;
1873 ndst.ndts_destroys += st->destroys;
1874 ndst.ndts_hash_grows += st->hash_grows;
1875 ndst.ndts_res_failed += st->res_failed;
1876 ndst.ndts_lookups += st->lookups;
1877 ndst.ndts_hits += st->hits;
1878 ndst.ndts_rcv_probes_mcast += st->rcv_probes_mcast;
1879 ndst.ndts_rcv_probes_ucast += st->rcv_probes_ucast;
1880 ndst.ndts_periodic_gc_runs += st->periodic_gc_runs;
1881 ndst.ndts_forced_gc_runs += st->forced_gc_runs;
1882 ndst.ndts_table_fulls += st->table_fulls;
1885 if (nla_put(skb, NDTA_STATS, sizeof(ndst), &ndst))
1886 goto nla_put_failure;
1889 BUG_ON(tbl->parms.dev);
1890 if (neightbl_fill_parms(skb, &tbl->parms) < 0)
1891 goto nla_put_failure;
1893 read_unlock_bh(&tbl->lock);
1894 nlmsg_end(skb, nlh);
1898 read_unlock_bh(&tbl->lock);
1899 nlmsg_cancel(skb, nlh);
1903 static int neightbl_fill_param_info(struct sk_buff *skb,
1904 struct neigh_table *tbl,
1905 struct neigh_parms *parms,
1906 u32 pid, u32 seq, int type,
1909 struct ndtmsg *ndtmsg;
1910 struct nlmsghdr *nlh;
1912 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndtmsg), flags);
1916 ndtmsg = nlmsg_data(nlh);
1918 read_lock_bh(&tbl->lock);
1919 ndtmsg->ndtm_family = tbl->family;
1920 ndtmsg->ndtm_pad1 = 0;
1921 ndtmsg->ndtm_pad2 = 0;
1923 if (nla_put_string(skb, NDTA_NAME, tbl->id) < 0 ||
1924 neightbl_fill_parms(skb, parms) < 0)
1927 read_unlock_bh(&tbl->lock);
1928 nlmsg_end(skb, nlh);
1931 read_unlock_bh(&tbl->lock);
1932 nlmsg_cancel(skb, nlh);
1936 static const struct nla_policy nl_neightbl_policy[NDTA_MAX+1] = {
1937 [NDTA_NAME] = { .type = NLA_STRING },
1938 [NDTA_THRESH1] = { .type = NLA_U32 },
1939 [NDTA_THRESH2] = { .type = NLA_U32 },
1940 [NDTA_THRESH3] = { .type = NLA_U32 },
1941 [NDTA_GC_INTERVAL] = { .type = NLA_U64 },
1942 [NDTA_PARMS] = { .type = NLA_NESTED },
1945 static const struct nla_policy nl_ntbl_parm_policy[NDTPA_MAX+1] = {
1946 [NDTPA_IFINDEX] = { .type = NLA_U32 },
1947 [NDTPA_QUEUE_LEN] = { .type = NLA_U32 },
1948 [NDTPA_PROXY_QLEN] = { .type = NLA_U32 },
1949 [NDTPA_APP_PROBES] = { .type = NLA_U32 },
1950 [NDTPA_UCAST_PROBES] = { .type = NLA_U32 },
1951 [NDTPA_MCAST_PROBES] = { .type = NLA_U32 },
1952 [NDTPA_MCAST_REPROBES] = { .type = NLA_U32 },
1953 [NDTPA_BASE_REACHABLE_TIME] = { .type = NLA_U64 },
1954 [NDTPA_GC_STALETIME] = { .type = NLA_U64 },
1955 [NDTPA_DELAY_PROBE_TIME] = { .type = NLA_U64 },
1956 [NDTPA_RETRANS_TIME] = { .type = NLA_U64 },
1957 [NDTPA_ANYCAST_DELAY] = { .type = NLA_U64 },
1958 [NDTPA_PROXY_DELAY] = { .type = NLA_U64 },
1959 [NDTPA_LOCKTIME] = { .type = NLA_U64 },
1962 static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh)
1964 struct net *net = sock_net(skb->sk);
1965 struct neigh_table *tbl;
1966 struct ndtmsg *ndtmsg;
1967 struct nlattr *tb[NDTA_MAX+1];
1971 err = nlmsg_parse(nlh, sizeof(*ndtmsg), tb, NDTA_MAX,
1972 nl_neightbl_policy);
1976 if (tb[NDTA_NAME] == NULL) {
1981 ndtmsg = nlmsg_data(nlh);
1983 for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) {
1984 tbl = neigh_tables[tidx];
1987 if (ndtmsg->ndtm_family && tbl->family != ndtmsg->ndtm_family)
1989 if (nla_strcmp(tb[NDTA_NAME], tbl->id) == 0) {
1999 * We acquire tbl->lock to be nice to the periodic timers and
2000 * make sure they always see a consistent set of values.
2002 write_lock_bh(&tbl->lock);
2004 if (tb[NDTA_PARMS]) {
2005 struct nlattr *tbp[NDTPA_MAX+1];
2006 struct neigh_parms *p;
2009 err = nla_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS],
2010 nl_ntbl_parm_policy);
2012 goto errout_tbl_lock;
2014 if (tbp[NDTPA_IFINDEX])
2015 ifindex = nla_get_u32(tbp[NDTPA_IFINDEX]);
2017 p = lookup_neigh_parms(tbl, net, ifindex);
2020 goto errout_tbl_lock;
2023 for (i = 1; i <= NDTPA_MAX; i++) {
2028 case NDTPA_QUEUE_LEN:
2029 NEIGH_VAR_SET(p, QUEUE_LEN_BYTES,
2030 nla_get_u32(tbp[i]) *
2031 SKB_TRUESIZE(ETH_FRAME_LEN));
2033 case NDTPA_QUEUE_LENBYTES:
2034 NEIGH_VAR_SET(p, QUEUE_LEN_BYTES,
2035 nla_get_u32(tbp[i]));
2037 case NDTPA_PROXY_QLEN:
2038 NEIGH_VAR_SET(p, PROXY_QLEN,
2039 nla_get_u32(tbp[i]));
2041 case NDTPA_APP_PROBES:
2042 NEIGH_VAR_SET(p, APP_PROBES,
2043 nla_get_u32(tbp[i]));
2045 case NDTPA_UCAST_PROBES:
2046 NEIGH_VAR_SET(p, UCAST_PROBES,
2047 nla_get_u32(tbp[i]));
2049 case NDTPA_MCAST_PROBES:
2050 NEIGH_VAR_SET(p, MCAST_PROBES,
2051 nla_get_u32(tbp[i]));
2053 case NDTPA_MCAST_REPROBES:
2054 NEIGH_VAR_SET(p, MCAST_REPROBES,
2055 nla_get_u32(tbp[i]));
2057 case NDTPA_BASE_REACHABLE_TIME:
2058 NEIGH_VAR_SET(p, BASE_REACHABLE_TIME,
2059 nla_get_msecs(tbp[i]));
2060 /* update reachable_time as well, otherwise, the change will
2061 * only be effective after the next time neigh_periodic_work
2062 * decides to recompute it (can be multiple minutes)
2065 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
2067 case NDTPA_GC_STALETIME:
2068 NEIGH_VAR_SET(p, GC_STALETIME,
2069 nla_get_msecs(tbp[i]));
2071 case NDTPA_DELAY_PROBE_TIME:
2072 NEIGH_VAR_SET(p, DELAY_PROBE_TIME,
2073 nla_get_msecs(tbp[i]));
2075 case NDTPA_RETRANS_TIME:
2076 NEIGH_VAR_SET(p, RETRANS_TIME,
2077 nla_get_msecs(tbp[i]));
2079 case NDTPA_ANYCAST_DELAY:
2080 NEIGH_VAR_SET(p, ANYCAST_DELAY,
2081 nla_get_msecs(tbp[i]));
2083 case NDTPA_PROXY_DELAY:
2084 NEIGH_VAR_SET(p, PROXY_DELAY,
2085 nla_get_msecs(tbp[i]));
2087 case NDTPA_LOCKTIME:
2088 NEIGH_VAR_SET(p, LOCKTIME,
2089 nla_get_msecs(tbp[i]));
2096 if ((tb[NDTA_THRESH1] || tb[NDTA_THRESH2] ||
2097 tb[NDTA_THRESH3] || tb[NDTA_GC_INTERVAL]) &&
2098 !net_eq(net, &init_net))
2099 goto errout_tbl_lock;
2101 if (tb[NDTA_THRESH1])
2102 tbl->gc_thresh1 = nla_get_u32(tb[NDTA_THRESH1]);
2104 if (tb[NDTA_THRESH2])
2105 tbl->gc_thresh2 = nla_get_u32(tb[NDTA_THRESH2]);
2107 if (tb[NDTA_THRESH3])
2108 tbl->gc_thresh3 = nla_get_u32(tb[NDTA_THRESH3]);
2110 if (tb[NDTA_GC_INTERVAL])
2111 tbl->gc_interval = nla_get_msecs(tb[NDTA_GC_INTERVAL]);
2116 write_unlock_bh(&tbl->lock);
2121 static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
2123 struct net *net = sock_net(skb->sk);
2124 int family, tidx, nidx = 0;
2125 int tbl_skip = cb->args[0];
2126 int neigh_skip = cb->args[1];
2127 struct neigh_table *tbl;
2129 family = ((struct rtgenmsg *) nlmsg_data(cb->nlh))->rtgen_family;
2131 for (tidx = 0; tidx < NEIGH_NR_TABLES; tidx++) {
2132 struct neigh_parms *p;
2134 tbl = neigh_tables[tidx];
2138 if (tidx < tbl_skip || (family && tbl->family != family))
2141 if (neightbl_fill_info(skb, tbl, NETLINK_CB(cb->skb).portid,
2142 cb->nlh->nlmsg_seq, RTM_NEWNEIGHTBL,
2147 p = list_next_entry(&tbl->parms, list);
2148 list_for_each_entry_from(p, &tbl->parms_list, list) {
2149 if (!net_eq(neigh_parms_net(p), net))
2152 if (nidx < neigh_skip)
2155 if (neightbl_fill_param_info(skb, tbl, p,
2156 NETLINK_CB(cb->skb).portid,
2174 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
2175 u32 pid, u32 seq, int type, unsigned int flags)
2177 unsigned long now = jiffies;
2178 struct nda_cacheinfo ci;
2179 struct nlmsghdr *nlh;
2182 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), flags);
2186 ndm = nlmsg_data(nlh);
2187 ndm->ndm_family = neigh->ops->family;
2190 ndm->ndm_flags = neigh->flags;
2191 ndm->ndm_type = neigh->type;
2192 ndm->ndm_ifindex = neigh->dev->ifindex;
2194 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key))
2195 goto nla_put_failure;
2197 read_lock_bh(&neigh->lock);
2198 ndm->ndm_state = neigh->nud_state;
2199 if (neigh->nud_state & NUD_VALID) {
2200 char haddr[MAX_ADDR_LEN];
2202 neigh_ha_snapshot(haddr, neigh, neigh->dev);
2203 if (nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, haddr) < 0) {
2204 read_unlock_bh(&neigh->lock);
2205 goto nla_put_failure;
2209 ci.ndm_used = jiffies_to_clock_t(now - neigh->used);
2210 ci.ndm_confirmed = jiffies_to_clock_t(now - neigh->confirmed);
2211 ci.ndm_updated = jiffies_to_clock_t(now - neigh->updated);
2212 ci.ndm_refcnt = atomic_read(&neigh->refcnt) - 1;
2213 read_unlock_bh(&neigh->lock);
2215 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) ||
2216 nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
2217 goto nla_put_failure;
2219 nlmsg_end(skb, nlh);
2223 nlmsg_cancel(skb, nlh);
2227 static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn,
2228 u32 pid, u32 seq, int type, unsigned int flags,
2229 struct neigh_table *tbl)
2231 struct nlmsghdr *nlh;
2234 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), flags);
2238 ndm = nlmsg_data(nlh);
2239 ndm->ndm_family = tbl->family;
2242 ndm->ndm_flags = pn->flags | NTF_PROXY;
2243 ndm->ndm_type = RTN_UNICAST;
2244 ndm->ndm_ifindex = pn->dev ? pn->dev->ifindex : 0;
2245 ndm->ndm_state = NUD_NONE;
2247 if (nla_put(skb, NDA_DST, tbl->key_len, pn->key))
2248 goto nla_put_failure;
2250 nlmsg_end(skb, nlh);
2254 nlmsg_cancel(skb, nlh);
2258 static void neigh_update_notify(struct neighbour *neigh)
2260 call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, neigh);
2261 __neigh_notify(neigh, RTM_NEWNEIGH, 0);
2264 static bool neigh_master_filtered(struct net_device *dev, int master_idx)
2266 struct net_device *master;
2271 master = netdev_master_upper_dev_get(dev);
2272 if (!master || master->ifindex != master_idx)
2278 static bool neigh_ifindex_filtered(struct net_device *dev, int filter_idx)
2280 if (filter_idx && dev->ifindex != filter_idx)
2286 static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
2287 struct netlink_callback *cb)
2289 struct net *net = sock_net(skb->sk);
2290 const struct nlmsghdr *nlh = cb->nlh;
2291 struct nlattr *tb[NDA_MAX + 1];
2292 struct neighbour *n;
2293 int rc, h, s_h = cb->args[1];
2294 int idx, s_idx = idx = cb->args[2];
2295 struct neigh_hash_table *nht;
2296 int filter_master_idx = 0, filter_idx = 0;
2297 unsigned int flags = NLM_F_MULTI;
2300 err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
2302 if (tb[NDA_IFINDEX]) {
2303 if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32))
2305 filter_idx = nla_get_u32(tb[NDA_IFINDEX]);
2307 if (tb[NDA_MASTER]) {
2308 if (nla_len(tb[NDA_MASTER]) != sizeof(u32))
2310 filter_master_idx = nla_get_u32(tb[NDA_MASTER]);
2312 if (filter_idx || filter_master_idx)
2313 flags |= NLM_F_DUMP_FILTERED;
2317 nht = rcu_dereference_bh(tbl->nht);
2319 for (h = s_h; h < (1 << nht->hash_shift); h++) {
2322 for (n = rcu_dereference_bh(nht->hash_buckets[h]), idx = 0;
2324 n = rcu_dereference_bh(n->next)) {
2325 if (!net_eq(dev_net(n->dev), net))
2327 if (neigh_ifindex_filtered(n->dev, filter_idx))
2329 if (neigh_master_filtered(n->dev, filter_master_idx))
2333 if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
2346 rcu_read_unlock_bh();
2352 static int pneigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
2353 struct netlink_callback *cb)
2355 struct pneigh_entry *n;
2356 struct net *net = sock_net(skb->sk);
2357 int rc, h, s_h = cb->args[3];
2358 int idx, s_idx = idx = cb->args[4];
2360 read_lock_bh(&tbl->lock);
2362 for (h = s_h; h <= PNEIGH_HASHMASK; h++) {
2365 for (n = tbl->phash_buckets[h], idx = 0; n; n = n->next) {
2366 if (pneigh_net(n) != net)
2370 if (pneigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
2373 NLM_F_MULTI, tbl) < 0) {
2374 read_unlock_bh(&tbl->lock);
2383 read_unlock_bh(&tbl->lock);
2392 static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
2394 struct neigh_table *tbl;
2399 family = ((struct rtgenmsg *) nlmsg_data(cb->nlh))->rtgen_family;
2401 /* check for full ndmsg structure presence, family member is
2402 * the same for both structures
2404 if (nlmsg_len(cb->nlh) >= sizeof(struct ndmsg) &&
2405 ((struct ndmsg *) nlmsg_data(cb->nlh))->ndm_flags == NTF_PROXY)
2410 for (t = 0; t < NEIGH_NR_TABLES; t++) {
2411 tbl = neigh_tables[t];
2415 if (t < s_t || (family && tbl->family != family))
2418 memset(&cb->args[1], 0, sizeof(cb->args) -
2419 sizeof(cb->args[0]));
2421 err = pneigh_dump_table(tbl, skb, cb);
2423 err = neigh_dump_table(tbl, skb, cb);
2432 void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie)
2435 struct neigh_hash_table *nht;
2438 nht = rcu_dereference_bh(tbl->nht);
2440 read_lock(&tbl->lock); /* avoid resizes */
2441 for (chain = 0; chain < (1 << nht->hash_shift); chain++) {
2442 struct neighbour *n;
2444 for (n = rcu_dereference_bh(nht->hash_buckets[chain]);
2446 n = rcu_dereference_bh(n->next))
2449 read_unlock(&tbl->lock);
2450 rcu_read_unlock_bh();
2452 EXPORT_SYMBOL(neigh_for_each);
2454 /* The tbl->lock must be held as a writer and BH disabled. */
2455 void __neigh_for_each_release(struct neigh_table *tbl,
2456 int (*cb)(struct neighbour *))
2459 struct neigh_hash_table *nht;
2461 nht = rcu_dereference_protected(tbl->nht,
2462 lockdep_is_held(&tbl->lock));
2463 for (chain = 0; chain < (1 << nht->hash_shift); chain++) {
2464 struct neighbour *n;
2465 struct neighbour __rcu **np;
2467 np = &nht->hash_buckets[chain];
2468 while ((n = rcu_dereference_protected(*np,
2469 lockdep_is_held(&tbl->lock))) != NULL) {
2472 write_lock(&n->lock);
2475 rcu_assign_pointer(*np,
2476 rcu_dereference_protected(n->next,
2477 lockdep_is_held(&tbl->lock)));
2481 write_unlock(&n->lock);
2483 neigh_cleanup_and_release(n);
2487 EXPORT_SYMBOL(__neigh_for_each_release);
2489 int neigh_xmit(int index, struct net_device *dev,
2490 const void *addr, struct sk_buff *skb)
2492 int err = -EAFNOSUPPORT;
2493 if (likely(index < NEIGH_NR_TABLES)) {
2494 struct neigh_table *tbl;
2495 struct neighbour *neigh;
2497 tbl = neigh_tables[index];
2501 if (index == NEIGH_ARP_TABLE) {
2502 u32 key = *((u32 *)addr);
2504 neigh = __ipv4_neigh_lookup_noref(dev, key);
2506 neigh = __neigh_lookup_noref(tbl, addr, dev);
2509 neigh = __neigh_create(tbl, addr, dev, false);
2510 err = PTR_ERR(neigh);
2511 if (IS_ERR(neigh)) {
2512 rcu_read_unlock_bh();
2515 err = neigh->output(neigh, skb);
2516 rcu_read_unlock_bh();
2518 else if (index == NEIGH_LINK_TABLE) {
2519 err = dev_hard_header(skb, dev, ntohs(skb->protocol),
2520 addr, NULL, skb->len);
2523 err = dev_queue_xmit(skb);
2531 EXPORT_SYMBOL(neigh_xmit);
2533 #ifdef CONFIG_PROC_FS
2535 static struct neighbour *neigh_get_first(struct seq_file *seq)
2537 struct neigh_seq_state *state = seq->private;
2538 struct net *net = seq_file_net(seq);
2539 struct neigh_hash_table *nht = state->nht;
2540 struct neighbour *n = NULL;
2541 int bucket = state->bucket;
2543 state->flags &= ~NEIGH_SEQ_IS_PNEIGH;
2544 for (bucket = 0; bucket < (1 << nht->hash_shift); bucket++) {
2545 n = rcu_dereference_bh(nht->hash_buckets[bucket]);
2548 if (!net_eq(dev_net(n->dev), net))
2550 if (state->neigh_sub_iter) {
2554 v = state->neigh_sub_iter(state, n, &fakep);
2558 if (!(state->flags & NEIGH_SEQ_SKIP_NOARP))
2560 if (n->nud_state & ~NUD_NOARP)
2563 n = rcu_dereference_bh(n->next);
2569 state->bucket = bucket;
2574 static struct neighbour *neigh_get_next(struct seq_file *seq,
2575 struct neighbour *n,
2578 struct neigh_seq_state *state = seq->private;
2579 struct net *net = seq_file_net(seq);
2580 struct neigh_hash_table *nht = state->nht;
2582 if (state->neigh_sub_iter) {
2583 void *v = state->neigh_sub_iter(state, n, pos);
2587 n = rcu_dereference_bh(n->next);
2591 if (!net_eq(dev_net(n->dev), net))
2593 if (state->neigh_sub_iter) {
2594 void *v = state->neigh_sub_iter(state, n, pos);
2599 if (!(state->flags & NEIGH_SEQ_SKIP_NOARP))
2602 if (n->nud_state & ~NUD_NOARP)
2605 n = rcu_dereference_bh(n->next);
2611 if (++state->bucket >= (1 << nht->hash_shift))
2614 n = rcu_dereference_bh(nht->hash_buckets[state->bucket]);
2622 static struct neighbour *neigh_get_idx(struct seq_file *seq, loff_t *pos)
2624 struct neighbour *n = neigh_get_first(seq);
2629 n = neigh_get_next(seq, n, pos);
2634 return *pos ? NULL : n;
2637 static struct pneigh_entry *pneigh_get_first(struct seq_file *seq)
2639 struct neigh_seq_state *state = seq->private;
2640 struct net *net = seq_file_net(seq);
2641 struct neigh_table *tbl = state->tbl;
2642 struct pneigh_entry *pn = NULL;
2643 int bucket = state->bucket;
2645 state->flags |= NEIGH_SEQ_IS_PNEIGH;
2646 for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) {
2647 pn = tbl->phash_buckets[bucket];
2648 while (pn && !net_eq(pneigh_net(pn), net))
2653 state->bucket = bucket;
2658 static struct pneigh_entry *pneigh_get_next(struct seq_file *seq,
2659 struct pneigh_entry *pn,
2662 struct neigh_seq_state *state = seq->private;
2663 struct net *net = seq_file_net(seq);
2664 struct neigh_table *tbl = state->tbl;
2668 } while (pn && !net_eq(pneigh_net(pn), net));
2671 if (++state->bucket > PNEIGH_HASHMASK)
2673 pn = tbl->phash_buckets[state->bucket];
2674 while (pn && !net_eq(pneigh_net(pn), net))
2686 static struct pneigh_entry *pneigh_get_idx(struct seq_file *seq, loff_t *pos)
2688 struct pneigh_entry *pn = pneigh_get_first(seq);
2693 pn = pneigh_get_next(seq, pn, pos);
2698 return *pos ? NULL : pn;
2701 static void *neigh_get_idx_any(struct seq_file *seq, loff_t *pos)
2703 struct neigh_seq_state *state = seq->private;
2705 loff_t idxpos = *pos;
2707 rc = neigh_get_idx(seq, &idxpos);
2708 if (!rc && !(state->flags & NEIGH_SEQ_NEIGH_ONLY))
2709 rc = pneigh_get_idx(seq, &idxpos);
2714 void *neigh_seq_start(struct seq_file *seq, loff_t *pos, struct neigh_table *tbl, unsigned int neigh_seq_flags)
2715 __acquires(tbl->lock)
2718 struct neigh_seq_state *state = seq->private;
2722 state->flags = (neigh_seq_flags & ~NEIGH_SEQ_IS_PNEIGH);
2725 state->nht = rcu_dereference_bh(tbl->nht);
2726 read_lock(&tbl->lock);
2728 return *pos ? neigh_get_idx_any(seq, pos) : SEQ_START_TOKEN;
2730 EXPORT_SYMBOL(neigh_seq_start);
2732 void *neigh_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2734 struct neigh_seq_state *state;
2737 if (v == SEQ_START_TOKEN) {
2738 rc = neigh_get_first(seq);
2742 state = seq->private;
2743 if (!(state->flags & NEIGH_SEQ_IS_PNEIGH)) {
2744 rc = neigh_get_next(seq, v, NULL);
2747 if (!(state->flags & NEIGH_SEQ_NEIGH_ONLY))
2748 rc = pneigh_get_first(seq);
2750 BUG_ON(state->flags & NEIGH_SEQ_NEIGH_ONLY);
2751 rc = pneigh_get_next(seq, v, NULL);
2757 EXPORT_SYMBOL(neigh_seq_next);
2759 void neigh_seq_stop(struct seq_file *seq, void *v)
2760 __releases(tbl->lock)
2763 struct neigh_seq_state *state = seq->private;
2764 struct neigh_table *tbl = state->tbl;
2766 read_unlock(&tbl->lock);
2767 rcu_read_unlock_bh();
2769 EXPORT_SYMBOL(neigh_seq_stop);
2771 /* statistics via seq_file */
2773 static void *neigh_stat_seq_start(struct seq_file *seq, loff_t *pos)
2775 struct neigh_table *tbl = seq->private;
2779 return SEQ_START_TOKEN;
2781 for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
2782 if (!cpu_possible(cpu))
2785 return per_cpu_ptr(tbl->stats, cpu);
2790 static void *neigh_stat_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2792 struct neigh_table *tbl = seq->private;
2795 for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
2796 if (!cpu_possible(cpu))
2799 return per_cpu_ptr(tbl->stats, cpu);
2805 static void neigh_stat_seq_stop(struct seq_file *seq, void *v)
2810 static int neigh_stat_seq_show(struct seq_file *seq, void *v)
2812 struct neigh_table *tbl = seq->private;
2813 struct neigh_statistics *st = v;
2815 if (v == SEQ_START_TOKEN) {
2816 seq_printf(seq, "entries allocs destroys hash_grows lookups hits res_failed rcv_probes_mcast rcv_probes_ucast periodic_gc_runs forced_gc_runs unresolved_discards table_fulls\n");
2820 seq_printf(seq, "%08x %08lx %08lx %08lx %08lx %08lx %08lx "
2821 "%08lx %08lx %08lx %08lx %08lx %08lx\n",
2822 atomic_read(&tbl->entries),
2833 st->rcv_probes_mcast,
2834 st->rcv_probes_ucast,
2836 st->periodic_gc_runs,
2845 static const struct seq_operations neigh_stat_seq_ops = {
2846 .start = neigh_stat_seq_start,
2847 .next = neigh_stat_seq_next,
2848 .stop = neigh_stat_seq_stop,
2849 .show = neigh_stat_seq_show,
2852 static int neigh_stat_seq_open(struct inode *inode, struct file *file)
2854 int ret = seq_open(file, &neigh_stat_seq_ops);
2857 struct seq_file *sf = file->private_data;
2858 sf->private = PDE_DATA(inode);
2863 static const struct file_operations neigh_stat_seq_fops = {
2864 .owner = THIS_MODULE,
2865 .open = neigh_stat_seq_open,
2867 .llseek = seq_lseek,
2868 .release = seq_release,
2871 #endif /* CONFIG_PROC_FS */
2873 static inline size_t neigh_nlmsg_size(void)
2875 return NLMSG_ALIGN(sizeof(struct ndmsg))
2876 + nla_total_size(MAX_ADDR_LEN) /* NDA_DST */
2877 + nla_total_size(MAX_ADDR_LEN) /* NDA_LLADDR */
2878 + nla_total_size(sizeof(struct nda_cacheinfo))
2879 + nla_total_size(4); /* NDA_PROBES */
2882 static void __neigh_notify(struct neighbour *n, int type, int flags)
2884 struct net *net = dev_net(n->dev);
2885 struct sk_buff *skb;
2888 skb = nlmsg_new(neigh_nlmsg_size(), GFP_ATOMIC);
2892 err = neigh_fill_info(skb, n, 0, 0, type, flags);
2894 /* -EMSGSIZE implies BUG in neigh_nlmsg_size() */
2895 WARN_ON(err == -EMSGSIZE);
2899 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
2903 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
2906 void neigh_app_ns(struct neighbour *n)
2908 __neigh_notify(n, RTM_GETNEIGH, NLM_F_REQUEST);
2910 EXPORT_SYMBOL(neigh_app_ns);
2912 #ifdef CONFIG_SYSCTL
2914 static int int_max = INT_MAX;
2915 static int unres_qlen_max = INT_MAX / SKB_TRUESIZE(ETH_FRAME_LEN);
2917 static int proc_unres_qlen(struct ctl_table *ctl, int write,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2921 struct ctl_table tmp = *ctl;
2924 tmp.extra2 = &unres_qlen_max;
2927 size = *(int *)ctl->data / SKB_TRUESIZE(ETH_FRAME_LEN);
2928 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
2931 *(int *)ctl->data = size * SKB_TRUESIZE(ETH_FRAME_LEN);
2935 static struct neigh_parms *neigh_get_dev_parms_rcu(struct net_device *dev,
2940 return __in_dev_arp_parms_get_rcu(dev);
2942 return __in6_dev_nd_parms_get_rcu(dev);
2947 static void neigh_copy_dflt_parms(struct net *net, struct neigh_parms *p,
2950 struct net_device *dev;
2951 int family = neigh_parms_family(p);
2954 for_each_netdev_rcu(net, dev) {
2955 struct neigh_parms *dst_p =
2956 neigh_get_dev_parms_rcu(dev, family);
2958 if (dst_p && !test_bit(index, dst_p->data_state))
2959 dst_p->data[index] = p->data[index];
2964 static void neigh_proc_update(struct ctl_table *ctl, int write)
2966 struct net_device *dev = ctl->extra1;
2967 struct neigh_parms *p = ctl->extra2;
2968 struct net *net = neigh_parms_net(p);
2969 int index = (int *) ctl->data - p->data;
2974 set_bit(index, p->data_state);
2975 if (!dev) /* NULL dev means this is default value */
2976 neigh_copy_dflt_parms(net, p, index);
2979 static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
2980 void __user *buffer,
2981 size_t *lenp, loff_t *ppos)
2983 struct ctl_table tmp = *ctl;
2987 tmp.extra2 = &int_max;
2989 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
2990 neigh_proc_update(ctl, write);
2994 int neigh_proc_dointvec(struct ctl_table *ctl, int write,
2995 void __user *buffer, size_t *lenp, loff_t *ppos)
2997 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
2999 neigh_proc_update(ctl, write);
3002 EXPORT_SYMBOL(neigh_proc_dointvec);
3004 int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,
3005 void __user *buffer,
3006 size_t *lenp, loff_t *ppos)
3008 int ret = proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
3010 neigh_proc_update(ctl, write);
3013 EXPORT_SYMBOL(neigh_proc_dointvec_jiffies);
3015 static int neigh_proc_dointvec_userhz_jiffies(struct ctl_table *ctl, int write,
3016 void __user *buffer,
3017 size_t *lenp, loff_t *ppos)
3019 int ret = proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos);
3021 neigh_proc_update(ctl, write);
3025 int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write,
3026 void __user *buffer,
3027 size_t *lenp, loff_t *ppos)
3029 int ret = proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos);
3031 neigh_proc_update(ctl, write);
3034 EXPORT_SYMBOL(neigh_proc_dointvec_ms_jiffies);
3036 static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write,
3037 void __user *buffer,
3038 size_t *lenp, loff_t *ppos)
3040 int ret = proc_unres_qlen(ctl, write, buffer, lenp, ppos);
3042 neigh_proc_update(ctl, write);
3046 static int neigh_proc_base_reachable_time(struct ctl_table *ctl, int write,
3047 void __user *buffer,
3048 size_t *lenp, loff_t *ppos)
3050 struct neigh_parms *p = ctl->extra2;
3053 if (strcmp(ctl->procname, "base_reachable_time") == 0)
3054 ret = neigh_proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
3055 else if (strcmp(ctl->procname, "base_reachable_time_ms") == 0)
3056 ret = neigh_proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos);
3060 if (write && ret == 0) {
3061 /* update reachable_time as well, otherwise, the change will
3062 * only be effective after the next time neigh_periodic_work
3063 * decides to recompute it
3066 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
3071 #define NEIGH_PARMS_DATA_OFFSET(index) \
3072 (&((struct neigh_parms *) 0)->data[index])
3074 #define NEIGH_SYSCTL_ENTRY(attr, data_attr, name, mval, proc) \
3075 [NEIGH_VAR_ ## attr] = { \
3077 .data = NEIGH_PARMS_DATA_OFFSET(NEIGH_VAR_ ## data_attr), \
3078 .maxlen = sizeof(int), \
3080 .proc_handler = proc, \
3083 #define NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(attr, name) \
3084 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_zero_intmax)
3086 #define NEIGH_SYSCTL_JIFFIES_ENTRY(attr, name) \
3087 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_jiffies)
3089 #define NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(attr, name) \
3090 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_userhz_jiffies)
3092 #define NEIGH_SYSCTL_MS_JIFFIES_ENTRY(attr, name) \
3093 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_ms_jiffies)
3095 #define NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(attr, data_attr, name) \
3096 NEIGH_SYSCTL_ENTRY(attr, data_attr, name, 0644, neigh_proc_dointvec_ms_jiffies)
3098 #define NEIGH_SYSCTL_UNRES_QLEN_REUSED_ENTRY(attr, data_attr, name) \
3099 NEIGH_SYSCTL_ENTRY(attr, data_attr, name, 0644, neigh_proc_dointvec_unres_qlen)
3101 static struct neigh_sysctl_table {
3102 struct ctl_table_header *sysctl_header;
3103 struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1];
3104 } neigh_sysctl_template __read_mostly = {
3106 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_PROBES, "mcast_solicit"),
3107 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(UCAST_PROBES, "ucast_solicit"),
3108 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(APP_PROBES, "app_solicit"),
3109 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_REPROBES, "mcast_resolicit"),
3110 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(RETRANS_TIME, "retrans_time"),
3111 NEIGH_SYSCTL_JIFFIES_ENTRY(BASE_REACHABLE_TIME, "base_reachable_time"),
3112 NEIGH_SYSCTL_JIFFIES_ENTRY(DELAY_PROBE_TIME, "delay_first_probe_time"),
3113 NEIGH_SYSCTL_JIFFIES_ENTRY(GC_STALETIME, "gc_stale_time"),
3114 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(QUEUE_LEN_BYTES, "unres_qlen_bytes"),
3115 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(PROXY_QLEN, "proxy_qlen"),
3116 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(ANYCAST_DELAY, "anycast_delay"),
3117 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(PROXY_DELAY, "proxy_delay"),
3118 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(LOCKTIME, "locktime"),
3119 NEIGH_SYSCTL_UNRES_QLEN_REUSED_ENTRY(QUEUE_LEN, QUEUE_LEN_BYTES, "unres_qlen"),
3120 NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(RETRANS_TIME_MS, RETRANS_TIME, "retrans_time_ms"),
3121 NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(BASE_REACHABLE_TIME_MS, BASE_REACHABLE_TIME, "base_reachable_time_ms"),
3122 [NEIGH_VAR_GC_INTERVAL] = {
3123 .procname = "gc_interval",
3124 .maxlen = sizeof(int),
3126 .proc_handler = proc_dointvec_jiffies,
3128 [NEIGH_VAR_GC_THRESH1] = {
3129 .procname = "gc_thresh1",
3130 .maxlen = sizeof(int),
3134 .proc_handler = proc_dointvec_minmax,
3136 [NEIGH_VAR_GC_THRESH2] = {
3137 .procname = "gc_thresh2",
3138 .maxlen = sizeof(int),
3142 .proc_handler = proc_dointvec_minmax,
3144 [NEIGH_VAR_GC_THRESH3] = {
3145 .procname = "gc_thresh3",
3146 .maxlen = sizeof(int),
3150 .proc_handler = proc_dointvec_minmax,
3156 int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
3157 proc_handler *handler)
3160 struct neigh_sysctl_table *t;
3161 const char *dev_name_source;
3162 char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
3165 t = kmemdup(&neigh_sysctl_template, sizeof(*t), GFP_KERNEL);
3169 for (i = 0; i < NEIGH_VAR_GC_INTERVAL; i++) {
3170 t->neigh_vars[i].data += (long) p;
3171 t->neigh_vars[i].extra1 = dev;
3172 t->neigh_vars[i].extra2 = p;
3176 dev_name_source = dev->name;
3177 /* Terminate the table early */
3178 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
3179 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
3181 struct neigh_table *tbl = p->tbl;
3182 dev_name_source = "default";
3183 t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &tbl->gc_interval;
3184 t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &tbl->gc_thresh1;
3185 t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &tbl->gc_thresh2;
3186 t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &tbl->gc_thresh3;
3191 t->neigh_vars[NEIGH_VAR_RETRANS_TIME].proc_handler = handler;
3193 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler = handler;
3194 /* RetransTime (in milliseconds)*/
3195 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler;
3196 /* ReachableTime (in milliseconds) */
3197 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler;
3199 /* Those handlers will update p->reachable_time after
3200 * base_reachable_time(_ms) is set to ensure the new timer starts being
3201 * applied after the next neighbour update instead of waiting for
3202 * neigh_periodic_work to update its value (can be multiple minutes)
3203 * So any handler that replaces them should do this as well
3206 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler =
3207 neigh_proc_base_reachable_time;
3208 /* ReachableTime (in milliseconds) */
3209 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler =
3210 neigh_proc_base_reachable_time;
3213 /* Don't export sysctls to unprivileged users */
3214 if (neigh_parms_net(p)->user_ns != &init_user_ns)
3215 t->neigh_vars[0].procname = NULL;
3217 switch (neigh_parms_family(p)) {
3228 snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",
3229 p_name, dev_name_source);
3231 register_net_sysctl(neigh_parms_net(p), neigh_path, t->neigh_vars);
3232 if (!t->sysctl_header)
3235 p->sysctl_table = t;
3243 EXPORT_SYMBOL(neigh_sysctl_register);
3245 void neigh_sysctl_unregister(struct neigh_parms *p)
3247 if (p->sysctl_table) {
3248 struct neigh_sysctl_table *t = p->sysctl_table;
3249 p->sysctl_table = NULL;
3250 unregister_net_sysctl_table(t->sysctl_header);
3254 EXPORT_SYMBOL(neigh_sysctl_unregister);
3256 #endif /* CONFIG_SYSCTL */
3258 static int __init neigh_init(void)
3260 rtnl_register(PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, NULL);
3261 rtnl_register(PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, NULL);
3262 rtnl_register(PF_UNSPEC, RTM_GETNEIGH, NULL, neigh_dump_info, NULL);
3264 rtnl_register(PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info,
3266 rtnl_register(PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, NULL);
3271 subsys_initcall(neigh_init);