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 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/socket.h>
23 #include <linux/sched.h>
24 #include <linux/netdevice.h>
25 #include <linux/proc_fs.h>
27 #include <linux/sysctl.h>
29 #include <linux/times.h>
30 #include <net/neighbour.h>
33 #include <linux/rtnetlink.h>
34 #include <linux/random.h>
35 #include <linux/string.h>
39 #define NEIGH_PRINTK(x...) printk(x)
40 #define NEIGH_NOPRINTK(x...) do { ; } while(0)
41 #define NEIGH_PRINTK0 NEIGH_PRINTK
42 #define NEIGH_PRINTK1 NEIGH_NOPRINTK
43 #define NEIGH_PRINTK2 NEIGH_NOPRINTK
47 #define NEIGH_PRINTK1 NEIGH_PRINTK
51 #define NEIGH_PRINTK2 NEIGH_PRINTK
54 #define PNEIGH_HASHMASK 0xF
56 static void neigh_timer_handler(unsigned long arg);
58 static void neigh_app_notify(struct neighbour *n);
60 static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
61 void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
63 static struct neigh_table *neigh_tables;
64 static 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.
93 The last lock is neigh_tbl_lock. It is pure SMP lock, protecting
94 list of neighbour tables. This list is used only in process context,
97 static DEFINE_RWLOCK(neigh_tbl_lock);
99 static int neigh_blackhole(struct sk_buff *skb)
106 * It is random distribution in the interval (1/2)*base...(3/2)*base.
107 * It corresponds to default IPv6 settings and is not overridable,
108 * because it is really reasonable choice.
111 unsigned long neigh_rand_reach_time(unsigned long base)
113 return (base ? (net_random() % base) + (base >> 1) : 0);
117 static int neigh_forced_gc(struct neigh_table *tbl)
122 NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
124 write_lock_bh(&tbl->lock);
125 for (i = 0; i <= tbl->hash_mask; i++) {
126 struct neighbour *n, **np;
128 np = &tbl->hash_buckets[i];
129 while ((n = *np) != NULL) {
130 /* Neighbour record may be discarded if:
131 * - nobody refers to it.
132 * - it is not permanent
134 write_lock(&n->lock);
135 if (atomic_read(&n->refcnt) == 1 &&
136 !(n->nud_state & NUD_PERMANENT)) {
140 write_unlock(&n->lock);
144 write_unlock(&n->lock);
149 tbl->last_flush = jiffies;
151 write_unlock_bh(&tbl->lock);
156 static int neigh_del_timer(struct neighbour *n)
158 if ((n->nud_state & NUD_IN_TIMER) &&
159 del_timer(&n->timer)) {
166 static void pneigh_queue_purge(struct sk_buff_head *list)
170 while ((skb = skb_dequeue(list)) != NULL) {
176 void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev)
180 write_lock_bh(&tbl->lock);
182 for (i=0; i <= tbl->hash_mask; i++) {
183 struct neighbour *n, **np;
185 np = &tbl->hash_buckets[i];
186 while ((n = *np) != NULL) {
187 if (dev && n->dev != dev) {
192 write_lock_bh(&n->lock);
195 write_unlock_bh(&n->lock);
200 write_unlock_bh(&tbl->lock);
203 int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
207 write_lock_bh(&tbl->lock);
209 for (i = 0; i <= tbl->hash_mask; i++) {
210 struct neighbour *n, **np = &tbl->hash_buckets[i];
212 while ((n = *np) != NULL) {
213 if (dev && n->dev != dev) {
218 write_lock(&n->lock);
222 if (atomic_read(&n->refcnt) != 1) {
223 /* The most unpleasant situation.
224 We must destroy neighbour entry,
225 but someone still uses it.
227 The destroy will be delayed until
228 the last user releases us, but
229 we must kill timers etc. and move
232 skb_queue_purge(&n->arp_queue);
233 n->output = neigh_blackhole;
234 if (n->nud_state & NUD_VALID)
235 n->nud_state = NUD_NOARP;
237 n->nud_state = NUD_NONE;
238 NEIGH_PRINTK2("neigh %p is stray.\n", n);
240 write_unlock(&n->lock);
245 pneigh_ifdown(tbl, dev);
246 write_unlock_bh(&tbl->lock);
248 del_timer_sync(&tbl->proxy_timer);
249 pneigh_queue_purge(&tbl->proxy_queue);
253 static struct neighbour *neigh_alloc(struct neigh_table *tbl)
255 struct neighbour *n = NULL;
256 unsigned long now = jiffies;
259 entries = atomic_inc_return(&tbl->entries) - 1;
260 if (entries >= tbl->gc_thresh3 ||
261 (entries >= tbl->gc_thresh2 &&
262 time_after(now, tbl->last_flush + 5 * HZ))) {
263 if (!neigh_forced_gc(tbl) &&
264 entries >= tbl->gc_thresh3)
268 n = kmem_cache_alloc(tbl->kmem_cachep, SLAB_ATOMIC);
272 memset(n, 0, tbl->entry_size);
274 skb_queue_head_init(&n->arp_queue);
275 rwlock_init(&n->lock);
276 n->updated = n->used = now;
277 n->nud_state = NUD_NONE;
278 n->output = neigh_blackhole;
279 n->parms = neigh_parms_clone(&tbl->parms);
280 init_timer(&n->timer);
281 n->timer.function = neigh_timer_handler;
282 n->timer.data = (unsigned long)n;
284 NEIGH_CACHE_STAT_INC(tbl, allocs);
286 atomic_set(&n->refcnt, 1);
292 atomic_dec(&tbl->entries);
296 static struct neighbour **neigh_hash_alloc(unsigned int entries)
298 unsigned long size = entries * sizeof(struct neighbour *);
299 struct neighbour **ret;
301 if (size <= PAGE_SIZE) {
302 ret = kmalloc(size, GFP_ATOMIC);
304 ret = (struct neighbour **)
305 __get_free_pages(GFP_ATOMIC, get_order(size));
308 memset(ret, 0, size);
313 static void neigh_hash_free(struct neighbour **hash, unsigned int entries)
315 unsigned long size = entries * sizeof(struct neighbour *);
317 if (size <= PAGE_SIZE)
320 free_pages((unsigned long)hash, get_order(size));
323 static void neigh_hash_grow(struct neigh_table *tbl, unsigned long new_entries)
325 struct neighbour **new_hash, **old_hash;
326 unsigned int i, new_hash_mask, old_entries;
328 NEIGH_CACHE_STAT_INC(tbl, hash_grows);
330 BUG_ON(new_entries & (new_entries - 1));
331 new_hash = neigh_hash_alloc(new_entries);
335 old_entries = tbl->hash_mask + 1;
336 new_hash_mask = new_entries - 1;
337 old_hash = tbl->hash_buckets;
339 get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd));
340 for (i = 0; i < old_entries; i++) {
341 struct neighbour *n, *next;
343 for (n = old_hash[i]; n; n = next) {
344 unsigned int hash_val = tbl->hash(n->primary_key, n->dev);
346 hash_val &= new_hash_mask;
349 n->next = new_hash[hash_val];
350 new_hash[hash_val] = n;
353 tbl->hash_buckets = new_hash;
354 tbl->hash_mask = new_hash_mask;
356 neigh_hash_free(old_hash, old_entries);
359 struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
360 struct net_device *dev)
363 int key_len = tbl->key_len;
364 u32 hash_val = tbl->hash(pkey, dev) & tbl->hash_mask;
366 NEIGH_CACHE_STAT_INC(tbl, lookups);
368 read_lock_bh(&tbl->lock);
369 for (n = tbl->hash_buckets[hash_val]; n; n = n->next) {
370 if (dev == n->dev && !memcmp(n->primary_key, pkey, key_len)) {
372 NEIGH_CACHE_STAT_INC(tbl, hits);
376 read_unlock_bh(&tbl->lock);
380 struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, const void *pkey)
383 int key_len = tbl->key_len;
384 u32 hash_val = tbl->hash(pkey, NULL) & tbl->hash_mask;
386 NEIGH_CACHE_STAT_INC(tbl, lookups);
388 read_lock_bh(&tbl->lock);
389 for (n = tbl->hash_buckets[hash_val]; n; n = n->next) {
390 if (!memcmp(n->primary_key, pkey, key_len)) {
392 NEIGH_CACHE_STAT_INC(tbl, hits);
396 read_unlock_bh(&tbl->lock);
400 struct neighbour *neigh_create(struct neigh_table *tbl, const void *pkey,
401 struct net_device *dev)
404 int key_len = tbl->key_len;
406 struct neighbour *n1, *rc, *n = neigh_alloc(tbl);
409 rc = ERR_PTR(-ENOBUFS);
413 memcpy(n->primary_key, pkey, key_len);
417 /* Protocol specific setup. */
418 if (tbl->constructor && (error = tbl->constructor(n)) < 0) {
420 goto out_neigh_release;
423 /* Device specific setup. */
424 if (n->parms->neigh_setup &&
425 (error = n->parms->neigh_setup(n)) < 0) {
427 goto out_neigh_release;
430 n->confirmed = jiffies - (n->parms->base_reachable_time << 1);
432 write_lock_bh(&tbl->lock);
434 if (atomic_read(&tbl->entries) > (tbl->hash_mask + 1))
435 neigh_hash_grow(tbl, (tbl->hash_mask + 1) << 1);
437 hash_val = tbl->hash(pkey, dev) & tbl->hash_mask;
439 if (n->parms->dead) {
440 rc = ERR_PTR(-EINVAL);
444 for (n1 = tbl->hash_buckets[hash_val]; n1; n1 = n1->next) {
445 if (dev == n1->dev && !memcmp(n1->primary_key, pkey, key_len)) {
452 n->next = tbl->hash_buckets[hash_val];
453 tbl->hash_buckets[hash_val] = n;
456 write_unlock_bh(&tbl->lock);
457 NEIGH_PRINTK2("neigh %p is created.\n", n);
462 write_unlock_bh(&tbl->lock);
468 struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl, const void *pkey,
469 struct net_device *dev, int creat)
471 struct pneigh_entry *n;
472 int key_len = tbl->key_len;
473 u32 hash_val = *(u32 *)(pkey + key_len - 4);
475 hash_val ^= (hash_val >> 16);
476 hash_val ^= hash_val >> 8;
477 hash_val ^= hash_val >> 4;
478 hash_val &= PNEIGH_HASHMASK;
480 read_lock_bh(&tbl->lock);
482 for (n = tbl->phash_buckets[hash_val]; n; n = n->next) {
483 if (!memcmp(n->key, pkey, key_len) &&
484 (n->dev == dev || !n->dev)) {
485 read_unlock_bh(&tbl->lock);
489 read_unlock_bh(&tbl->lock);
494 n = kmalloc(sizeof(*n) + key_len, GFP_KERNEL);
498 memcpy(n->key, pkey, key_len);
503 if (tbl->pconstructor && tbl->pconstructor(n)) {
511 write_lock_bh(&tbl->lock);
512 n->next = tbl->phash_buckets[hash_val];
513 tbl->phash_buckets[hash_val] = n;
514 write_unlock_bh(&tbl->lock);
520 int pneigh_delete(struct neigh_table *tbl, const void *pkey,
521 struct net_device *dev)
523 struct pneigh_entry *n, **np;
524 int key_len = tbl->key_len;
525 u32 hash_val = *(u32 *)(pkey + key_len - 4);
527 hash_val ^= (hash_val >> 16);
528 hash_val ^= hash_val >> 8;
529 hash_val ^= hash_val >> 4;
530 hash_val &= PNEIGH_HASHMASK;
532 write_lock_bh(&tbl->lock);
533 for (np = &tbl->phash_buckets[hash_val]; (n = *np) != NULL;
535 if (!memcmp(n->key, pkey, key_len) && n->dev == dev) {
537 write_unlock_bh(&tbl->lock);
538 if (tbl->pdestructor)
546 write_unlock_bh(&tbl->lock);
550 static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
552 struct pneigh_entry *n, **np;
555 for (h = 0; h <= PNEIGH_HASHMASK; h++) {
556 np = &tbl->phash_buckets[h];
557 while ((n = *np) != NULL) {
558 if (!dev || n->dev == dev) {
560 if (tbl->pdestructor)
575 * neighbour must already be out of the table;
578 void neigh_destroy(struct neighbour *neigh)
582 NEIGH_CACHE_STAT_INC(neigh->tbl, destroys);
586 "Destroying alive neighbour %p\n", neigh);
591 if (neigh_del_timer(neigh))
592 printk(KERN_WARNING "Impossible event.\n");
594 while ((hh = neigh->hh) != NULL) {
595 neigh->hh = hh->hh_next;
597 write_lock_bh(&hh->hh_lock);
598 hh->hh_output = neigh_blackhole;
599 write_unlock_bh(&hh->hh_lock);
600 if (atomic_dec_and_test(&hh->hh_refcnt))
604 if (neigh->ops && neigh->ops->destructor)
605 (neigh->ops->destructor)(neigh);
607 skb_queue_purge(&neigh->arp_queue);
610 neigh_parms_put(neigh->parms);
612 NEIGH_PRINTK2("neigh %p is destroyed.\n", neigh);
614 atomic_dec(&neigh->tbl->entries);
615 kmem_cache_free(neigh->tbl->kmem_cachep, neigh);
618 /* Neighbour state is suspicious;
621 Called with write_locked neigh.
623 static void neigh_suspect(struct neighbour *neigh)
627 NEIGH_PRINTK2("neigh %p is suspected.\n", neigh);
629 neigh->output = neigh->ops->output;
631 for (hh = neigh->hh; hh; hh = hh->hh_next)
632 hh->hh_output = neigh->ops->output;
635 /* Neighbour state is OK;
638 Called with write_locked neigh.
640 static void neigh_connect(struct neighbour *neigh)
644 NEIGH_PRINTK2("neigh %p is connected.\n", neigh);
646 neigh->output = neigh->ops->connected_output;
648 for (hh = neigh->hh; hh; hh = hh->hh_next)
649 hh->hh_output = neigh->ops->hh_output;
652 static void neigh_periodic_timer(unsigned long arg)
654 struct neigh_table *tbl = (struct neigh_table *)arg;
655 struct neighbour *n, **np;
656 unsigned long expire, now = jiffies;
658 NEIGH_CACHE_STAT_INC(tbl, periodic_gc_runs);
660 write_lock(&tbl->lock);
663 * periodically recompute ReachableTime from random function
666 if (time_after(now, tbl->last_rand + 300 * HZ)) {
667 struct neigh_parms *p;
668 tbl->last_rand = now;
669 for (p = &tbl->parms; p; p = p->next)
671 neigh_rand_reach_time(p->base_reachable_time);
674 np = &tbl->hash_buckets[tbl->hash_chain_gc];
675 tbl->hash_chain_gc = ((tbl->hash_chain_gc + 1) & tbl->hash_mask);
677 while ((n = *np) != NULL) {
680 write_lock(&n->lock);
682 state = n->nud_state;
683 if (state & (NUD_PERMANENT | NUD_IN_TIMER)) {
684 write_unlock(&n->lock);
688 if (time_before(n->used, n->confirmed))
689 n->used = n->confirmed;
691 if (atomic_read(&n->refcnt) == 1 &&
692 (state == NUD_FAILED ||
693 time_after(now, n->used + n->parms->gc_staletime))) {
696 write_unlock(&n->lock);
700 write_unlock(&n->lock);
706 /* Cycle through all hash buckets every base_reachable_time/2 ticks.
707 * ARP entry timeouts range from 1/2 base_reachable_time to 3/2
708 * base_reachable_time.
710 expire = tbl->parms.base_reachable_time >> 1;
711 expire /= (tbl->hash_mask + 1);
715 mod_timer(&tbl->gc_timer, now + expire);
717 write_unlock(&tbl->lock);
720 static __inline__ int neigh_max_probes(struct neighbour *n)
722 struct neigh_parms *p = n->parms;
723 return (n->nud_state & NUD_PROBE ?
725 p->ucast_probes + p->app_probes + p->mcast_probes);
729 /* Called when a timer expires for a neighbour entry. */
731 static void neigh_timer_handler(unsigned long arg)
733 unsigned long now, next;
734 struct neighbour *neigh = (struct neighbour *)arg;
738 write_lock(&neigh->lock);
740 state = neigh->nud_state;
744 if (!(state & NUD_IN_TIMER)) {
746 printk(KERN_WARNING "neigh: timer & !nud_in_timer\n");
751 if (state & NUD_REACHABLE) {
752 if (time_before_eq(now,
753 neigh->confirmed + neigh->parms->reachable_time)) {
754 NEIGH_PRINTK2("neigh %p is still alive.\n", neigh);
755 next = neigh->confirmed + neigh->parms->reachable_time;
756 } else if (time_before_eq(now,
757 neigh->used + neigh->parms->delay_probe_time)) {
758 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh);
759 neigh->nud_state = NUD_DELAY;
760 neigh_suspect(neigh);
761 next = now + neigh->parms->delay_probe_time;
763 NEIGH_PRINTK2("neigh %p is suspected.\n", neigh);
764 neigh->nud_state = NUD_STALE;
765 neigh_suspect(neigh);
767 } else if (state & NUD_DELAY) {
768 if (time_before_eq(now,
769 neigh->confirmed + neigh->parms->delay_probe_time)) {
770 NEIGH_PRINTK2("neigh %p is now reachable.\n", neigh);
771 neigh->nud_state = NUD_REACHABLE;
772 neigh_connect(neigh);
773 next = neigh->confirmed + neigh->parms->reachable_time;
775 NEIGH_PRINTK2("neigh %p is probed.\n", neigh);
776 neigh->nud_state = NUD_PROBE;
777 atomic_set(&neigh->probes, 0);
778 next = now + neigh->parms->retrans_time;
781 /* NUD_PROBE|NUD_INCOMPLETE */
782 next = now + neigh->parms->retrans_time;
785 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
786 atomic_read(&neigh->probes) >= neigh_max_probes(neigh)) {
789 neigh->nud_state = NUD_FAILED;
791 NEIGH_CACHE_STAT_INC(neigh->tbl, res_failed);
792 NEIGH_PRINTK2("neigh %p is failed.\n", neigh);
794 /* It is very thin place. report_unreachable is very complicated
795 routine. Particularly, it can hit the same neighbour entry!
797 So that, we try to be accurate and avoid dead loop. --ANK
799 while (neigh->nud_state == NUD_FAILED &&
800 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
801 write_unlock(&neigh->lock);
802 neigh->ops->error_report(neigh, skb);
803 write_lock(&neigh->lock);
805 skb_queue_purge(&neigh->arp_queue);
808 if (neigh->nud_state & NUD_IN_TIMER) {
810 if (time_before(next, jiffies + HZ/2))
811 next = jiffies + HZ/2;
812 neigh->timer.expires = next;
813 add_timer(&neigh->timer);
815 if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
816 struct sk_buff *skb = skb_peek(&neigh->arp_queue);
817 /* keep skb alive even if arp_queue overflows */
820 write_unlock(&neigh->lock);
821 neigh->ops->solicit(neigh, skb);
822 atomic_inc(&neigh->probes);
827 write_unlock(&neigh->lock);
831 if (notify && neigh->parms->app_probes)
832 neigh_app_notify(neigh);
834 neigh_release(neigh);
837 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
842 write_lock_bh(&neigh->lock);
845 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
850 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
851 if (neigh->parms->mcast_probes + neigh->parms->app_probes) {
852 atomic_set(&neigh->probes, neigh->parms->ucast_probes);
853 neigh->nud_state = NUD_INCOMPLETE;
855 neigh->timer.expires = now + 1;
856 add_timer(&neigh->timer);
858 neigh->nud_state = NUD_FAILED;
859 write_unlock_bh(&neigh->lock);
865 } else if (neigh->nud_state & NUD_STALE) {
866 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh);
868 neigh->nud_state = NUD_DELAY;
869 neigh->timer.expires = jiffies + neigh->parms->delay_probe_time;
870 add_timer(&neigh->timer);
873 if (neigh->nud_state == NUD_INCOMPLETE) {
875 if (skb_queue_len(&neigh->arp_queue) >=
876 neigh->parms->queue_len) {
877 struct sk_buff *buff;
878 buff = neigh->arp_queue.next;
879 __skb_unlink(buff, &neigh->arp_queue);
882 __skb_queue_tail(&neigh->arp_queue, skb);
887 write_unlock_bh(&neigh->lock);
891 static __inline__ void neigh_update_hhs(struct neighbour *neigh)
894 void (*update)(struct hh_cache*, struct net_device*, unsigned char *) =
895 neigh->dev->header_cache_update;
898 for (hh = neigh->hh; hh; hh = hh->hh_next) {
899 write_lock_bh(&hh->hh_lock);
900 update(hh, neigh->dev, neigh->ha);
901 write_unlock_bh(&hh->hh_lock);
908 /* Generic update routine.
909 -- lladdr is new lladdr or NULL, if it is not supplied.
912 NEIGH_UPDATE_F_OVERRIDE allows to override existing lladdr,
914 NEIGH_UPDATE_F_WEAK_OVERRIDE will suspect existing "connected"
915 lladdr instead of overriding it
917 It also allows to retain current state
918 if lladdr is unchanged.
919 NEIGH_UPDATE_F_ADMIN means that the change is administrative.
921 NEIGH_UPDATE_F_OVERRIDE_ISROUTER allows to override existing
923 NEIGH_UPDATE_F_ISROUTER indicates if the neighbour is known as
926 Caller MUST hold reference count on the entry.
929 int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
937 struct net_device *dev;
938 int update_isrouter = 0;
940 write_lock_bh(&neigh->lock);
943 old = neigh->nud_state;
946 if (!(flags & NEIGH_UPDATE_F_ADMIN) &&
947 (old & (NUD_NOARP | NUD_PERMANENT)))
950 if (!(new & NUD_VALID)) {
951 neigh_del_timer(neigh);
952 if (old & NUD_CONNECTED)
953 neigh_suspect(neigh);
954 neigh->nud_state = new;
957 notify = old & NUD_VALID;
962 /* Compare new lladdr with cached one */
963 if (!dev->addr_len) {
964 /* First case: device needs no address. */
967 /* The second case: if something is already cached
968 and a new address is proposed:
970 - if they are different, check override flag
972 if ((old & NUD_VALID) &&
973 !memcmp(lladdr, neigh->ha, dev->addr_len))
976 /* No address is supplied; if we know something,
977 use it, otherwise discard the request.
980 if (!(old & NUD_VALID))
985 if (new & NUD_CONNECTED)
986 neigh->confirmed = jiffies;
987 neigh->updated = jiffies;
989 /* If entry was valid and address is not changed,
990 do not change entry state, if new one is STALE.
993 update_isrouter = flags & NEIGH_UPDATE_F_OVERRIDE_ISROUTER;
994 if (old & NUD_VALID) {
995 if (lladdr != neigh->ha && !(flags & NEIGH_UPDATE_F_OVERRIDE)) {
997 if ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) &&
998 (old & NUD_CONNECTED)) {
1004 if (lladdr == neigh->ha && new == NUD_STALE &&
1005 ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
1006 (old & NUD_CONNECTED))
1013 neigh_del_timer(neigh);
1014 if (new & NUD_IN_TIMER) {
1016 neigh->timer.expires = jiffies +
1017 ((new & NUD_REACHABLE) ?
1018 neigh->parms->reachable_time : 0);
1019 add_timer(&neigh->timer);
1021 neigh->nud_state = new;
1024 if (lladdr != neigh->ha) {
1025 memcpy(&neigh->ha, lladdr, dev->addr_len);
1026 neigh_update_hhs(neigh);
1027 if (!(new & NUD_CONNECTED))
1028 neigh->confirmed = jiffies -
1029 (neigh->parms->base_reachable_time << 1);
1036 if (new & NUD_CONNECTED)
1037 neigh_connect(neigh);
1039 neigh_suspect(neigh);
1040 if (!(old & NUD_VALID)) {
1041 struct sk_buff *skb;
1043 /* Again: avoid dead loop if something went wrong */
1045 while (neigh->nud_state & NUD_VALID &&
1046 (skb = __skb_dequeue(&neigh->arp_queue)) != NULL) {
1047 struct neighbour *n1 = neigh;
1048 write_unlock_bh(&neigh->lock);
1049 /* On shaper/eql skb->dst->neighbour != neigh :( */
1050 if (skb->dst && skb->dst->neighbour)
1051 n1 = skb->dst->neighbour;
1053 write_lock_bh(&neigh->lock);
1055 skb_queue_purge(&neigh->arp_queue);
1058 if (update_isrouter) {
1059 neigh->flags = (flags & NEIGH_UPDATE_F_ISROUTER) ?
1060 (neigh->flags | NTF_ROUTER) :
1061 (neigh->flags & ~NTF_ROUTER);
1063 write_unlock_bh(&neigh->lock);
1065 if (notify && neigh->parms->app_probes)
1066 neigh_app_notify(neigh);
1071 struct neighbour *neigh_event_ns(struct neigh_table *tbl,
1072 u8 *lladdr, void *saddr,
1073 struct net_device *dev)
1075 struct neighbour *neigh = __neigh_lookup(tbl, saddr, dev,
1076 lladdr || !dev->addr_len);
1078 neigh_update(neigh, lladdr, NUD_STALE,
1079 NEIGH_UPDATE_F_OVERRIDE);
1083 static void neigh_hh_init(struct neighbour *n, struct dst_entry *dst,
1086 struct hh_cache *hh;
1087 struct net_device *dev = dst->dev;
1089 for (hh = n->hh; hh; hh = hh->hh_next)
1090 if (hh->hh_type == protocol)
1093 if (!hh && (hh = kmalloc(sizeof(*hh), GFP_ATOMIC)) != NULL) {
1094 memset(hh, 0, sizeof(struct hh_cache));
1095 rwlock_init(&hh->hh_lock);
1096 hh->hh_type = protocol;
1097 atomic_set(&hh->hh_refcnt, 0);
1099 if (dev->hard_header_cache(n, hh)) {
1103 atomic_inc(&hh->hh_refcnt);
1104 hh->hh_next = n->hh;
1106 if (n->nud_state & NUD_CONNECTED)
1107 hh->hh_output = n->ops->hh_output;
1109 hh->hh_output = n->ops->output;
1113 atomic_inc(&hh->hh_refcnt);
1118 /* This function can be used in contexts, where only old dev_queue_xmit
1119 worked, f.e. if you want to override normal output path (eql, shaper),
1120 but resolution is not made yet.
1123 int neigh_compat_output(struct sk_buff *skb)
1125 struct net_device *dev = skb->dev;
1127 __skb_pull(skb, skb->nh.raw - skb->data);
1129 if (dev->hard_header &&
1130 dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL,
1132 dev->rebuild_header(skb))
1135 return dev_queue_xmit(skb);
1138 /* Slow and careful. */
1140 int neigh_resolve_output(struct sk_buff *skb)
1142 struct dst_entry *dst = skb->dst;
1143 struct neighbour *neigh;
1146 if (!dst || !(neigh = dst->neighbour))
1149 __skb_pull(skb, skb->nh.raw - skb->data);
1151 if (!neigh_event_send(neigh, skb)) {
1153 struct net_device *dev = neigh->dev;
1154 if (dev->hard_header_cache && !dst->hh) {
1155 write_lock_bh(&neigh->lock);
1157 neigh_hh_init(neigh, dst, dst->ops->protocol);
1158 err = dev->hard_header(skb, dev, ntohs(skb->protocol),
1159 neigh->ha, NULL, skb->len);
1160 write_unlock_bh(&neigh->lock);
1162 read_lock_bh(&neigh->lock);
1163 err = dev->hard_header(skb, dev, ntohs(skb->protocol),
1164 neigh->ha, NULL, skb->len);
1165 read_unlock_bh(&neigh->lock);
1168 rc = neigh->ops->queue_xmit(skb);
1175 NEIGH_PRINTK1("neigh_resolve_output: dst=%p neigh=%p\n",
1176 dst, dst ? dst->neighbour : NULL);
1183 /* As fast as possible without hh cache */
1185 int neigh_connected_output(struct sk_buff *skb)
1188 struct dst_entry *dst = skb->dst;
1189 struct neighbour *neigh = dst->neighbour;
1190 struct net_device *dev = neigh->dev;
1192 __skb_pull(skb, skb->nh.raw - skb->data);
1194 read_lock_bh(&neigh->lock);
1195 err = dev->hard_header(skb, dev, ntohs(skb->protocol),
1196 neigh->ha, NULL, skb->len);
1197 read_unlock_bh(&neigh->lock);
1199 err = neigh->ops->queue_xmit(skb);
1207 static void neigh_proxy_process(unsigned long arg)
1209 struct neigh_table *tbl = (struct neigh_table *)arg;
1210 long sched_next = 0;
1211 unsigned long now = jiffies;
1212 struct sk_buff *skb;
1214 spin_lock(&tbl->proxy_queue.lock);
1216 skb = tbl->proxy_queue.next;
1218 while (skb != (struct sk_buff *)&tbl->proxy_queue) {
1219 struct sk_buff *back = skb;
1220 long tdif = NEIGH_CB(back)->sched_next - now;
1224 struct net_device *dev = back->dev;
1225 __skb_unlink(back, &tbl->proxy_queue);
1226 if (tbl->proxy_redo && netif_running(dev))
1227 tbl->proxy_redo(back);
1232 } else if (!sched_next || tdif < sched_next)
1235 del_timer(&tbl->proxy_timer);
1237 mod_timer(&tbl->proxy_timer, jiffies + sched_next);
1238 spin_unlock(&tbl->proxy_queue.lock);
1241 void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
1242 struct sk_buff *skb)
1244 unsigned long now = jiffies;
1245 unsigned long sched_next = now + (net_random() % p->proxy_delay);
1247 if (tbl->proxy_queue.qlen > p->proxy_qlen) {
1252 NEIGH_CB(skb)->sched_next = sched_next;
1253 NEIGH_CB(skb)->flags |= LOCALLY_ENQUEUED;
1255 spin_lock(&tbl->proxy_queue.lock);
1256 if (del_timer(&tbl->proxy_timer)) {
1257 if (time_before(tbl->proxy_timer.expires, sched_next))
1258 sched_next = tbl->proxy_timer.expires;
1260 dst_release(skb->dst);
1263 __skb_queue_tail(&tbl->proxy_queue, skb);
1264 mod_timer(&tbl->proxy_timer, sched_next);
1265 spin_unlock(&tbl->proxy_queue.lock);
1269 struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1270 struct neigh_table *tbl)
1272 struct neigh_parms *p = kmalloc(sizeof(*p), GFP_KERNEL);
1275 memcpy(p, &tbl->parms, sizeof(*p));
1277 atomic_set(&p->refcnt, 1);
1278 INIT_RCU_HEAD(&p->rcu_head);
1280 neigh_rand_reach_time(p->base_reachable_time);
1282 if (dev->neigh_setup && dev->neigh_setup(dev, p)) {
1290 p->sysctl_table = NULL;
1291 write_lock_bh(&tbl->lock);
1292 p->next = tbl->parms.next;
1293 tbl->parms.next = p;
1294 write_unlock_bh(&tbl->lock);
1299 static void neigh_rcu_free_parms(struct rcu_head *head)
1301 struct neigh_parms *parms =
1302 container_of(head, struct neigh_parms, rcu_head);
1304 neigh_parms_put(parms);
1307 void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
1309 struct neigh_parms **p;
1311 if (!parms || parms == &tbl->parms)
1313 write_lock_bh(&tbl->lock);
1314 for (p = &tbl->parms.next; *p; p = &(*p)->next) {
1318 write_unlock_bh(&tbl->lock);
1320 dev_put(parms->dev);
1321 call_rcu(&parms->rcu_head, neigh_rcu_free_parms);
1325 write_unlock_bh(&tbl->lock);
1326 NEIGH_PRINTK1("neigh_parms_release: not found\n");
1329 void neigh_parms_destroy(struct neigh_parms *parms)
1335 void neigh_table_init(struct neigh_table *tbl)
1337 unsigned long now = jiffies;
1338 unsigned long phsize;
1340 atomic_set(&tbl->parms.refcnt, 1);
1341 INIT_RCU_HEAD(&tbl->parms.rcu_head);
1342 tbl->parms.reachable_time =
1343 neigh_rand_reach_time(tbl->parms.base_reachable_time);
1345 if (!tbl->kmem_cachep)
1346 tbl->kmem_cachep = kmem_cache_create(tbl->id,
1348 0, SLAB_HWCACHE_ALIGN,
1351 if (!tbl->kmem_cachep)
1352 panic("cannot create neighbour cache");
1354 tbl->stats = alloc_percpu(struct neigh_statistics);
1356 panic("cannot create neighbour cache statistics");
1358 #ifdef CONFIG_PROC_FS
1359 tbl->pde = create_proc_entry(tbl->id, 0, proc_net_stat);
1361 panic("cannot create neighbour proc dir entry");
1362 tbl->pde->proc_fops = &neigh_stat_seq_fops;
1363 tbl->pde->data = tbl;
1367 tbl->hash_buckets = neigh_hash_alloc(tbl->hash_mask + 1);
1369 phsize = (PNEIGH_HASHMASK + 1) * sizeof(struct pneigh_entry *);
1370 tbl->phash_buckets = kmalloc(phsize, GFP_KERNEL);
1372 if (!tbl->hash_buckets || !tbl->phash_buckets)
1373 panic("cannot allocate neighbour cache hashes");
1375 memset(tbl->phash_buckets, 0, phsize);
1377 get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd));
1379 rwlock_init(&tbl->lock);
1380 init_timer(&tbl->gc_timer);
1381 tbl->gc_timer.data = (unsigned long)tbl;
1382 tbl->gc_timer.function = neigh_periodic_timer;
1383 tbl->gc_timer.expires = now + 1;
1384 add_timer(&tbl->gc_timer);
1386 init_timer(&tbl->proxy_timer);
1387 tbl->proxy_timer.data = (unsigned long)tbl;
1388 tbl->proxy_timer.function = neigh_proxy_process;
1389 skb_queue_head_init(&tbl->proxy_queue);
1391 tbl->last_flush = now;
1392 tbl->last_rand = now + tbl->parms.reachable_time * 20;
1393 write_lock(&neigh_tbl_lock);
1394 tbl->next = neigh_tables;
1396 write_unlock(&neigh_tbl_lock);
1399 int neigh_table_clear(struct neigh_table *tbl)
1401 struct neigh_table **tp;
1403 /* It is not clean... Fix it to unload IPv6 module safely */
1404 del_timer_sync(&tbl->gc_timer);
1405 del_timer_sync(&tbl->proxy_timer);
1406 pneigh_queue_purge(&tbl->proxy_queue);
1407 neigh_ifdown(tbl, NULL);
1408 if (atomic_read(&tbl->entries))
1409 printk(KERN_CRIT "neighbour leakage\n");
1410 write_lock(&neigh_tbl_lock);
1411 for (tp = &neigh_tables; *tp; tp = &(*tp)->next) {
1417 write_unlock(&neigh_tbl_lock);
1419 neigh_hash_free(tbl->hash_buckets, tbl->hash_mask + 1);
1420 tbl->hash_buckets = NULL;
1422 kfree(tbl->phash_buckets);
1423 tbl->phash_buckets = NULL;
1428 int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1430 struct ndmsg *ndm = NLMSG_DATA(nlh);
1431 struct rtattr **nda = arg;
1432 struct neigh_table *tbl;
1433 struct net_device *dev = NULL;
1436 if (ndm->ndm_ifindex &&
1437 (dev = dev_get_by_index(ndm->ndm_ifindex)) == NULL)
1440 read_lock(&neigh_tbl_lock);
1441 for (tbl = neigh_tables; tbl; tbl = tbl->next) {
1442 struct rtattr *dst_attr = nda[NDA_DST - 1];
1443 struct neighbour *n;
1445 if (tbl->family != ndm->ndm_family)
1447 read_unlock(&neigh_tbl_lock);
1450 if (!dst_attr || RTA_PAYLOAD(dst_attr) < tbl->key_len)
1453 if (ndm->ndm_flags & NTF_PROXY) {
1454 err = pneigh_delete(tbl, RTA_DATA(dst_attr), dev);
1461 n = neigh_lookup(tbl, RTA_DATA(dst_attr), dev);
1463 err = neigh_update(n, NULL, NUD_FAILED,
1464 NEIGH_UPDATE_F_OVERRIDE|
1465 NEIGH_UPDATE_F_ADMIN);
1470 read_unlock(&neigh_tbl_lock);
1471 err = -EADDRNOTAVAIL;
1479 int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1481 struct ndmsg *ndm = NLMSG_DATA(nlh);
1482 struct rtattr **nda = arg;
1483 struct neigh_table *tbl;
1484 struct net_device *dev = NULL;
1487 if (ndm->ndm_ifindex &&
1488 (dev = dev_get_by_index(ndm->ndm_ifindex)) == NULL)
1491 read_lock(&neigh_tbl_lock);
1492 for (tbl = neigh_tables; tbl; tbl = tbl->next) {
1493 struct rtattr *lladdr_attr = nda[NDA_LLADDR - 1];
1494 struct rtattr *dst_attr = nda[NDA_DST - 1];
1496 struct neighbour *n;
1498 if (tbl->family != ndm->ndm_family)
1500 read_unlock(&neigh_tbl_lock);
1503 if (!dst_attr || RTA_PAYLOAD(dst_attr) < tbl->key_len)
1506 if (ndm->ndm_flags & NTF_PROXY) {
1508 if (pneigh_lookup(tbl, RTA_DATA(dst_attr), dev, 1))
1516 if (lladdr_attr && RTA_PAYLOAD(lladdr_attr) < dev->addr_len)
1519 n = neigh_lookup(tbl, RTA_DATA(dst_attr), dev);
1521 if (nlh->nlmsg_flags & NLM_F_EXCL) {
1527 override = nlh->nlmsg_flags & NLM_F_REPLACE;
1528 } else if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
1532 n = __neigh_lookup_errno(tbl, RTA_DATA(dst_attr), dev);
1539 err = neigh_update(n,
1540 lladdr_attr ? RTA_DATA(lladdr_attr) : NULL,
1542 (override ? NEIGH_UPDATE_F_OVERRIDE : 0) |
1543 NEIGH_UPDATE_F_ADMIN);
1549 read_unlock(&neigh_tbl_lock);
1550 err = -EADDRNOTAVAIL;
1558 static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
1560 struct rtattr *nest = NULL;
1562 nest = RTA_NEST(skb, NDTA_PARMS);
1565 RTA_PUT_U32(skb, NDTPA_IFINDEX, parms->dev->ifindex);
1567 RTA_PUT_U32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt));
1568 RTA_PUT_U32(skb, NDTPA_QUEUE_LEN, parms->queue_len);
1569 RTA_PUT_U32(skb, NDTPA_PROXY_QLEN, parms->proxy_qlen);
1570 RTA_PUT_U32(skb, NDTPA_APP_PROBES, parms->app_probes);
1571 RTA_PUT_U32(skb, NDTPA_UCAST_PROBES, parms->ucast_probes);
1572 RTA_PUT_U32(skb, NDTPA_MCAST_PROBES, parms->mcast_probes);
1573 RTA_PUT_MSECS(skb, NDTPA_REACHABLE_TIME, parms->reachable_time);
1574 RTA_PUT_MSECS(skb, NDTPA_BASE_REACHABLE_TIME,
1575 parms->base_reachable_time);
1576 RTA_PUT_MSECS(skb, NDTPA_GC_STALETIME, parms->gc_staletime);
1577 RTA_PUT_MSECS(skb, NDTPA_DELAY_PROBE_TIME, parms->delay_probe_time);
1578 RTA_PUT_MSECS(skb, NDTPA_RETRANS_TIME, parms->retrans_time);
1579 RTA_PUT_MSECS(skb, NDTPA_ANYCAST_DELAY, parms->anycast_delay);
1580 RTA_PUT_MSECS(skb, NDTPA_PROXY_DELAY, parms->proxy_delay);
1581 RTA_PUT_MSECS(skb, NDTPA_LOCKTIME, parms->locktime);
1583 return RTA_NEST_END(skb, nest);
1586 return RTA_NEST_CANCEL(skb, nest);
1589 static int neightbl_fill_info(struct neigh_table *tbl, struct sk_buff *skb,
1590 struct netlink_callback *cb)
1592 struct nlmsghdr *nlh;
1593 struct ndtmsg *ndtmsg;
1595 nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg),
1598 ndtmsg = NLMSG_DATA(nlh);
1600 read_lock_bh(&tbl->lock);
1601 ndtmsg->ndtm_family = tbl->family;
1602 ndtmsg->ndtm_pad1 = 0;
1603 ndtmsg->ndtm_pad2 = 0;
1605 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id);
1606 RTA_PUT_MSECS(skb, NDTA_GC_INTERVAL, tbl->gc_interval);
1607 RTA_PUT_U32(skb, NDTA_THRESH1, tbl->gc_thresh1);
1608 RTA_PUT_U32(skb, NDTA_THRESH2, tbl->gc_thresh2);
1609 RTA_PUT_U32(skb, NDTA_THRESH3, tbl->gc_thresh3);
1612 unsigned long now = jiffies;
1613 unsigned int flush_delta = now - tbl->last_flush;
1614 unsigned int rand_delta = now - tbl->last_rand;
1616 struct ndt_config ndc = {
1617 .ndtc_key_len = tbl->key_len,
1618 .ndtc_entry_size = tbl->entry_size,
1619 .ndtc_entries = atomic_read(&tbl->entries),
1620 .ndtc_last_flush = jiffies_to_msecs(flush_delta),
1621 .ndtc_last_rand = jiffies_to_msecs(rand_delta),
1622 .ndtc_hash_rnd = tbl->hash_rnd,
1623 .ndtc_hash_mask = tbl->hash_mask,
1624 .ndtc_hash_chain_gc = tbl->hash_chain_gc,
1625 .ndtc_proxy_qlen = tbl->proxy_queue.qlen,
1628 RTA_PUT(skb, NDTA_CONFIG, sizeof(ndc), &ndc);
1633 struct ndt_stats ndst;
1635 memset(&ndst, 0, sizeof(ndst));
1637 for (cpu = 0; cpu < NR_CPUS; cpu++) {
1638 struct neigh_statistics *st;
1640 if (!cpu_possible(cpu))
1643 st = per_cpu_ptr(tbl->stats, cpu);
1644 ndst.ndts_allocs += st->allocs;
1645 ndst.ndts_destroys += st->destroys;
1646 ndst.ndts_hash_grows += st->hash_grows;
1647 ndst.ndts_res_failed += st->res_failed;
1648 ndst.ndts_lookups += st->lookups;
1649 ndst.ndts_hits += st->hits;
1650 ndst.ndts_rcv_probes_mcast += st->rcv_probes_mcast;
1651 ndst.ndts_rcv_probes_ucast += st->rcv_probes_ucast;
1652 ndst.ndts_periodic_gc_runs += st->periodic_gc_runs;
1653 ndst.ndts_forced_gc_runs += st->forced_gc_runs;
1656 RTA_PUT(skb, NDTA_STATS, sizeof(ndst), &ndst);
1659 BUG_ON(tbl->parms.dev);
1660 if (neightbl_fill_parms(skb, &tbl->parms) < 0)
1661 goto rtattr_failure;
1663 read_unlock_bh(&tbl->lock);
1664 return NLMSG_END(skb, nlh);
1667 read_unlock_bh(&tbl->lock);
1668 return NLMSG_CANCEL(skb, nlh);
1674 static int neightbl_fill_param_info(struct neigh_table *tbl,
1675 struct neigh_parms *parms,
1676 struct sk_buff *skb,
1677 struct netlink_callback *cb)
1679 struct ndtmsg *ndtmsg;
1680 struct nlmsghdr *nlh;
1682 nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWNEIGHTBL, sizeof(struct ndtmsg),
1685 ndtmsg = NLMSG_DATA(nlh);
1687 read_lock_bh(&tbl->lock);
1688 ndtmsg->ndtm_family = tbl->family;
1689 ndtmsg->ndtm_pad1 = 0;
1690 ndtmsg->ndtm_pad2 = 0;
1691 RTA_PUT_STRING(skb, NDTA_NAME, tbl->id);
1693 if (neightbl_fill_parms(skb, parms) < 0)
1694 goto rtattr_failure;
1696 read_unlock_bh(&tbl->lock);
1697 return NLMSG_END(skb, nlh);
1700 read_unlock_bh(&tbl->lock);
1701 return NLMSG_CANCEL(skb, nlh);
1707 static inline struct neigh_parms *lookup_neigh_params(struct neigh_table *tbl,
1710 struct neigh_parms *p;
1712 for (p = &tbl->parms; p; p = p->next)
1713 if ((p->dev && p->dev->ifindex == ifindex) ||
1714 (!p->dev && !ifindex))
1720 int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1722 struct neigh_table *tbl;
1723 struct ndtmsg *ndtmsg = NLMSG_DATA(nlh);
1724 struct rtattr **tb = arg;
1727 if (!tb[NDTA_NAME - 1] || !RTA_PAYLOAD(tb[NDTA_NAME - 1]))
1730 read_lock(&neigh_tbl_lock);
1731 for (tbl = neigh_tables; tbl; tbl = tbl->next) {
1732 if (ndtmsg->ndtm_family && tbl->family != ndtmsg->ndtm_family)
1735 if (!rtattr_strcmp(tb[NDTA_NAME - 1], tbl->id))
1745 * We acquire tbl->lock to be nice to the periodic timers and
1746 * make sure they always see a consistent set of values.
1748 write_lock_bh(&tbl->lock);
1750 if (tb[NDTA_THRESH1 - 1])
1751 tbl->gc_thresh1 = RTA_GET_U32(tb[NDTA_THRESH1 - 1]);
1753 if (tb[NDTA_THRESH2 - 1])
1754 tbl->gc_thresh2 = RTA_GET_U32(tb[NDTA_THRESH2 - 1]);
1756 if (tb[NDTA_THRESH3 - 1])
1757 tbl->gc_thresh3 = RTA_GET_U32(tb[NDTA_THRESH3 - 1]);
1759 if (tb[NDTA_GC_INTERVAL - 1])
1760 tbl->gc_interval = RTA_GET_MSECS(tb[NDTA_GC_INTERVAL - 1]);
1762 if (tb[NDTA_PARMS - 1]) {
1763 struct rtattr *tbp[NDTPA_MAX];
1764 struct neigh_parms *p;
1767 if (rtattr_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS - 1]) < 0)
1768 goto rtattr_failure;
1770 if (tbp[NDTPA_IFINDEX - 1])
1771 ifindex = RTA_GET_U32(tbp[NDTPA_IFINDEX - 1]);
1773 p = lookup_neigh_params(tbl, ifindex);
1776 goto rtattr_failure;
1779 if (tbp[NDTPA_QUEUE_LEN - 1])
1780 p->queue_len = RTA_GET_U32(tbp[NDTPA_QUEUE_LEN - 1]);
1782 if (tbp[NDTPA_PROXY_QLEN - 1])
1783 p->proxy_qlen = RTA_GET_U32(tbp[NDTPA_PROXY_QLEN - 1]);
1785 if (tbp[NDTPA_APP_PROBES - 1])
1786 p->app_probes = RTA_GET_U32(tbp[NDTPA_APP_PROBES - 1]);
1788 if (tbp[NDTPA_UCAST_PROBES - 1])
1790 RTA_GET_U32(tbp[NDTPA_UCAST_PROBES - 1]);
1792 if (tbp[NDTPA_MCAST_PROBES - 1])
1794 RTA_GET_U32(tbp[NDTPA_MCAST_PROBES - 1]);
1796 if (tbp[NDTPA_BASE_REACHABLE_TIME - 1])
1797 p->base_reachable_time =
1798 RTA_GET_MSECS(tbp[NDTPA_BASE_REACHABLE_TIME - 1]);
1800 if (tbp[NDTPA_GC_STALETIME - 1])
1802 RTA_GET_MSECS(tbp[NDTPA_GC_STALETIME - 1]);
1804 if (tbp[NDTPA_DELAY_PROBE_TIME - 1])
1805 p->delay_probe_time =
1806 RTA_GET_MSECS(tbp[NDTPA_DELAY_PROBE_TIME - 1]);
1808 if (tbp[NDTPA_RETRANS_TIME - 1])
1810 RTA_GET_MSECS(tbp[NDTPA_RETRANS_TIME - 1]);
1812 if (tbp[NDTPA_ANYCAST_DELAY - 1])
1814 RTA_GET_MSECS(tbp[NDTPA_ANYCAST_DELAY - 1]);
1816 if (tbp[NDTPA_PROXY_DELAY - 1])
1818 RTA_GET_MSECS(tbp[NDTPA_PROXY_DELAY - 1]);
1820 if (tbp[NDTPA_LOCKTIME - 1])
1821 p->locktime = RTA_GET_MSECS(tbp[NDTPA_LOCKTIME - 1]);
1827 write_unlock_bh(&tbl->lock);
1829 read_unlock(&neigh_tbl_lock);
1833 int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
1836 int s_idx = cb->args[0];
1837 struct neigh_table *tbl;
1839 family = ((struct rtgenmsg *)NLMSG_DATA(cb->nlh))->rtgen_family;
1841 read_lock(&neigh_tbl_lock);
1842 for (tbl = neigh_tables, idx = 0; tbl; tbl = tbl->next) {
1843 struct neigh_parms *p;
1845 if (idx < s_idx || (family && tbl->family != family))
1848 if (neightbl_fill_info(tbl, skb, cb) <= 0)
1851 for (++idx, p = tbl->parms.next; p; p = p->next, idx++) {
1855 if (neightbl_fill_param_info(tbl, p, skb, cb) <= 0)
1861 read_unlock(&neigh_tbl_lock);
1867 static int neigh_fill_info(struct sk_buff *skb, struct neighbour *n,
1868 u32 pid, u32 seq, int event, unsigned int flags)
1870 unsigned long now = jiffies;
1871 unsigned char *b = skb->tail;
1872 struct nda_cacheinfo ci;
1875 struct nlmsghdr *nlh = NLMSG_NEW(skb, pid, seq, event,
1876 sizeof(struct ndmsg), flags);
1877 struct ndmsg *ndm = NLMSG_DATA(nlh);
1879 ndm->ndm_family = n->ops->family;
1882 ndm->ndm_flags = n->flags;
1883 ndm->ndm_type = n->type;
1884 ndm->ndm_ifindex = n->dev->ifindex;
1885 RTA_PUT(skb, NDA_DST, n->tbl->key_len, n->primary_key);
1886 read_lock_bh(&n->lock);
1888 ndm->ndm_state = n->nud_state;
1889 if (n->nud_state & NUD_VALID)
1890 RTA_PUT(skb, NDA_LLADDR, n->dev->addr_len, n->ha);
1891 ci.ndm_used = now - n->used;
1892 ci.ndm_confirmed = now - n->confirmed;
1893 ci.ndm_updated = now - n->updated;
1894 ci.ndm_refcnt = atomic_read(&n->refcnt) - 1;
1895 probes = atomic_read(&n->probes);
1896 read_unlock_bh(&n->lock);
1898 RTA_PUT(skb, NDA_CACHEINFO, sizeof(ci), &ci);
1899 RTA_PUT(skb, NDA_PROBES, sizeof(probes), &probes);
1900 nlh->nlmsg_len = skb->tail - b;
1906 read_unlock_bh(&n->lock);
1907 skb_trim(skb, b - skb->data);
1912 static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
1913 struct netlink_callback *cb)
1915 struct neighbour *n;
1916 int rc, h, s_h = cb->args[1];
1917 int idx, s_idx = idx = cb->args[2];
1919 for (h = 0; h <= tbl->hash_mask; h++) {
1924 read_lock_bh(&tbl->lock);
1925 for (n = tbl->hash_buckets[h], idx = 0; n; n = n->next, idx++) {
1928 if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).pid,
1931 NLM_F_MULTI) <= 0) {
1932 read_unlock_bh(&tbl->lock);
1937 read_unlock_bh(&tbl->lock);
1946 int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
1948 struct neigh_table *tbl;
1951 read_lock(&neigh_tbl_lock);
1952 family = ((struct rtgenmsg *)NLMSG_DATA(cb->nlh))->rtgen_family;
1955 for (tbl = neigh_tables, t = 0; tbl; tbl = tbl->next, t++) {
1956 if (t < s_t || (family && tbl->family != family))
1959 memset(&cb->args[1], 0, sizeof(cb->args) -
1960 sizeof(cb->args[0]));
1961 if (neigh_dump_table(tbl, skb, cb) < 0)
1964 read_unlock(&neigh_tbl_lock);
1970 void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie)
1974 read_lock_bh(&tbl->lock);
1975 for (chain = 0; chain <= tbl->hash_mask; chain++) {
1976 struct neighbour *n;
1978 for (n = tbl->hash_buckets[chain]; n; n = n->next)
1981 read_unlock_bh(&tbl->lock);
1983 EXPORT_SYMBOL(neigh_for_each);
1985 /* The tbl->lock must be held as a writer and BH disabled. */
1986 void __neigh_for_each_release(struct neigh_table *tbl,
1987 int (*cb)(struct neighbour *))
1991 for (chain = 0; chain <= tbl->hash_mask; chain++) {
1992 struct neighbour *n, **np;
1994 np = &tbl->hash_buckets[chain];
1995 while ((n = *np) != NULL) {
1998 write_lock(&n->lock);
2005 write_unlock(&n->lock);
2011 EXPORT_SYMBOL(__neigh_for_each_release);
2013 #ifdef CONFIG_PROC_FS
2015 static struct neighbour *neigh_get_first(struct seq_file *seq)
2017 struct neigh_seq_state *state = seq->private;
2018 struct neigh_table *tbl = state->tbl;
2019 struct neighbour *n = NULL;
2020 int bucket = state->bucket;
2022 state->flags &= ~NEIGH_SEQ_IS_PNEIGH;
2023 for (bucket = 0; bucket <= tbl->hash_mask; bucket++) {
2024 n = tbl->hash_buckets[bucket];
2027 if (state->neigh_sub_iter) {
2031 v = state->neigh_sub_iter(state, n, &fakep);
2035 if (!(state->flags & NEIGH_SEQ_SKIP_NOARP))
2037 if (n->nud_state & ~NUD_NOARP)
2046 state->bucket = bucket;
2051 static struct neighbour *neigh_get_next(struct seq_file *seq,
2052 struct neighbour *n,
2055 struct neigh_seq_state *state = seq->private;
2056 struct neigh_table *tbl = state->tbl;
2058 if (state->neigh_sub_iter) {
2059 void *v = state->neigh_sub_iter(state, n, pos);
2067 if (state->neigh_sub_iter) {
2068 void *v = state->neigh_sub_iter(state, n, pos);
2073 if (!(state->flags & NEIGH_SEQ_SKIP_NOARP))
2076 if (n->nud_state & ~NUD_NOARP)
2085 if (++state->bucket > tbl->hash_mask)
2088 n = tbl->hash_buckets[state->bucket];
2096 static struct neighbour *neigh_get_idx(struct seq_file *seq, loff_t *pos)
2098 struct neighbour *n = neigh_get_first(seq);
2102 n = neigh_get_next(seq, n, pos);
2107 return *pos ? NULL : n;
2110 static struct pneigh_entry *pneigh_get_first(struct seq_file *seq)
2112 struct neigh_seq_state *state = seq->private;
2113 struct neigh_table *tbl = state->tbl;
2114 struct pneigh_entry *pn = NULL;
2115 int bucket = state->bucket;
2117 state->flags |= NEIGH_SEQ_IS_PNEIGH;
2118 for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) {
2119 pn = tbl->phash_buckets[bucket];
2123 state->bucket = bucket;
2128 static struct pneigh_entry *pneigh_get_next(struct seq_file *seq,
2129 struct pneigh_entry *pn,
2132 struct neigh_seq_state *state = seq->private;
2133 struct neigh_table *tbl = state->tbl;
2137 if (++state->bucket > PNEIGH_HASHMASK)
2139 pn = tbl->phash_buckets[state->bucket];
2150 static struct pneigh_entry *pneigh_get_idx(struct seq_file *seq, loff_t *pos)
2152 struct pneigh_entry *pn = pneigh_get_first(seq);
2156 pn = pneigh_get_next(seq, pn, pos);
2161 return *pos ? NULL : pn;
2164 static void *neigh_get_idx_any(struct seq_file *seq, loff_t *pos)
2166 struct neigh_seq_state *state = seq->private;
2169 rc = neigh_get_idx(seq, pos);
2170 if (!rc && !(state->flags & NEIGH_SEQ_NEIGH_ONLY))
2171 rc = pneigh_get_idx(seq, pos);
2176 void *neigh_seq_start(struct seq_file *seq, loff_t *pos, struct neigh_table *tbl, unsigned int neigh_seq_flags)
2178 struct neigh_seq_state *state = seq->private;
2179 loff_t pos_minus_one;
2183 state->flags = (neigh_seq_flags & ~NEIGH_SEQ_IS_PNEIGH);
2185 read_lock_bh(&tbl->lock);
2187 pos_minus_one = *pos - 1;
2188 return *pos ? neigh_get_idx_any(seq, &pos_minus_one) : SEQ_START_TOKEN;
2190 EXPORT_SYMBOL(neigh_seq_start);
2192 void *neigh_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2194 struct neigh_seq_state *state;
2197 if (v == SEQ_START_TOKEN) {
2198 rc = neigh_get_idx(seq, pos);
2202 state = seq->private;
2203 if (!(state->flags & NEIGH_SEQ_IS_PNEIGH)) {
2204 rc = neigh_get_next(seq, v, NULL);
2207 if (!(state->flags & NEIGH_SEQ_NEIGH_ONLY))
2208 rc = pneigh_get_first(seq);
2210 BUG_ON(state->flags & NEIGH_SEQ_NEIGH_ONLY);
2211 rc = pneigh_get_next(seq, v, NULL);
2217 EXPORT_SYMBOL(neigh_seq_next);
2219 void neigh_seq_stop(struct seq_file *seq, void *v)
2221 struct neigh_seq_state *state = seq->private;
2222 struct neigh_table *tbl = state->tbl;
2224 read_unlock_bh(&tbl->lock);
2226 EXPORT_SYMBOL(neigh_seq_stop);
2228 /* statistics via seq_file */
2230 static void *neigh_stat_seq_start(struct seq_file *seq, loff_t *pos)
2232 struct proc_dir_entry *pde = seq->private;
2233 struct neigh_table *tbl = pde->data;
2237 return SEQ_START_TOKEN;
2239 for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
2240 if (!cpu_possible(cpu))
2243 return per_cpu_ptr(tbl->stats, cpu);
2248 static void *neigh_stat_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2250 struct proc_dir_entry *pde = seq->private;
2251 struct neigh_table *tbl = pde->data;
2254 for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
2255 if (!cpu_possible(cpu))
2258 return per_cpu_ptr(tbl->stats, cpu);
2263 static void neigh_stat_seq_stop(struct seq_file *seq, void *v)
2268 static int neigh_stat_seq_show(struct seq_file *seq, void *v)
2270 struct proc_dir_entry *pde = seq->private;
2271 struct neigh_table *tbl = pde->data;
2272 struct neigh_statistics *st = v;
2274 if (v == SEQ_START_TOKEN) {
2275 seq_printf(seq, "entries allocs destroys hash_grows lookups hits res_failed rcv_probes_mcast rcv_probes_ucast periodic_gc_runs forced_gc_runs\n");
2279 seq_printf(seq, "%08x %08lx %08lx %08lx %08lx %08lx %08lx "
2280 "%08lx %08lx %08lx %08lx\n",
2281 atomic_read(&tbl->entries),
2292 st->rcv_probes_mcast,
2293 st->rcv_probes_ucast,
2295 st->periodic_gc_runs,
2302 static struct seq_operations neigh_stat_seq_ops = {
2303 .start = neigh_stat_seq_start,
2304 .next = neigh_stat_seq_next,
2305 .stop = neigh_stat_seq_stop,
2306 .show = neigh_stat_seq_show,
2309 static int neigh_stat_seq_open(struct inode *inode, struct file *file)
2311 int ret = seq_open(file, &neigh_stat_seq_ops);
2314 struct seq_file *sf = file->private_data;
2315 sf->private = PDE(inode);
2320 static struct file_operations neigh_stat_seq_fops = {
2321 .owner = THIS_MODULE,
2322 .open = neigh_stat_seq_open,
2324 .llseek = seq_lseek,
2325 .release = seq_release,
2328 #endif /* CONFIG_PROC_FS */
2331 void neigh_app_ns(struct neighbour *n)
2333 struct nlmsghdr *nlh;
2334 int size = NLMSG_SPACE(sizeof(struct ndmsg) + 256);
2335 struct sk_buff *skb = alloc_skb(size, GFP_ATOMIC);
2340 if (neigh_fill_info(skb, n, 0, 0, RTM_GETNEIGH, 0) < 0) {
2344 nlh = (struct nlmsghdr *)skb->data;
2345 nlh->nlmsg_flags = NLM_F_REQUEST;
2346 NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH;
2347 netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC);
2350 static void neigh_app_notify(struct neighbour *n)
2352 struct nlmsghdr *nlh;
2353 int size = NLMSG_SPACE(sizeof(struct ndmsg) + 256);
2354 struct sk_buff *skb = alloc_skb(size, GFP_ATOMIC);
2359 if (neigh_fill_info(skb, n, 0, 0, RTM_NEWNEIGH, 0) < 0) {
2363 nlh = (struct nlmsghdr *)skb->data;
2364 NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH;
2365 netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC);
2368 #endif /* CONFIG_ARPD */
2370 #ifdef CONFIG_SYSCTL
2372 static struct neigh_sysctl_table {
2373 struct ctl_table_header *sysctl_header;
2374 ctl_table neigh_vars[__NET_NEIGH_MAX];
2375 ctl_table neigh_dev[2];
2376 ctl_table neigh_neigh_dir[2];
2377 ctl_table neigh_proto_dir[2];
2378 ctl_table neigh_root_dir[2];
2379 } neigh_sysctl_template = {
2382 .ctl_name = NET_NEIGH_MCAST_SOLICIT,
2383 .procname = "mcast_solicit",
2384 .maxlen = sizeof(int),
2386 .proc_handler = &proc_dointvec,
2389 .ctl_name = NET_NEIGH_UCAST_SOLICIT,
2390 .procname = "ucast_solicit",
2391 .maxlen = sizeof(int),
2393 .proc_handler = &proc_dointvec,
2396 .ctl_name = NET_NEIGH_APP_SOLICIT,
2397 .procname = "app_solicit",
2398 .maxlen = sizeof(int),
2400 .proc_handler = &proc_dointvec,
2403 .ctl_name = NET_NEIGH_RETRANS_TIME,
2404 .procname = "retrans_time",
2405 .maxlen = sizeof(int),
2407 .proc_handler = &proc_dointvec_userhz_jiffies,
2410 .ctl_name = NET_NEIGH_REACHABLE_TIME,
2411 .procname = "base_reachable_time",
2412 .maxlen = sizeof(int),
2414 .proc_handler = &proc_dointvec_jiffies,
2415 .strategy = &sysctl_jiffies,
2418 .ctl_name = NET_NEIGH_DELAY_PROBE_TIME,
2419 .procname = "delay_first_probe_time",
2420 .maxlen = sizeof(int),
2422 .proc_handler = &proc_dointvec_jiffies,
2423 .strategy = &sysctl_jiffies,
2426 .ctl_name = NET_NEIGH_GC_STALE_TIME,
2427 .procname = "gc_stale_time",
2428 .maxlen = sizeof(int),
2430 .proc_handler = &proc_dointvec_jiffies,
2431 .strategy = &sysctl_jiffies,
2434 .ctl_name = NET_NEIGH_UNRES_QLEN,
2435 .procname = "unres_qlen",
2436 .maxlen = sizeof(int),
2438 .proc_handler = &proc_dointvec,
2441 .ctl_name = NET_NEIGH_PROXY_QLEN,
2442 .procname = "proxy_qlen",
2443 .maxlen = sizeof(int),
2445 .proc_handler = &proc_dointvec,
2448 .ctl_name = NET_NEIGH_ANYCAST_DELAY,
2449 .procname = "anycast_delay",
2450 .maxlen = sizeof(int),
2452 .proc_handler = &proc_dointvec_userhz_jiffies,
2455 .ctl_name = NET_NEIGH_PROXY_DELAY,
2456 .procname = "proxy_delay",
2457 .maxlen = sizeof(int),
2459 .proc_handler = &proc_dointvec_userhz_jiffies,
2462 .ctl_name = NET_NEIGH_LOCKTIME,
2463 .procname = "locktime",
2464 .maxlen = sizeof(int),
2466 .proc_handler = &proc_dointvec_userhz_jiffies,
2469 .ctl_name = NET_NEIGH_GC_INTERVAL,
2470 .procname = "gc_interval",
2471 .maxlen = sizeof(int),
2473 .proc_handler = &proc_dointvec_jiffies,
2474 .strategy = &sysctl_jiffies,
2477 .ctl_name = NET_NEIGH_GC_THRESH1,
2478 .procname = "gc_thresh1",
2479 .maxlen = sizeof(int),
2481 .proc_handler = &proc_dointvec,
2484 .ctl_name = NET_NEIGH_GC_THRESH2,
2485 .procname = "gc_thresh2",
2486 .maxlen = sizeof(int),
2488 .proc_handler = &proc_dointvec,
2491 .ctl_name = NET_NEIGH_GC_THRESH3,
2492 .procname = "gc_thresh3",
2493 .maxlen = sizeof(int),
2495 .proc_handler = &proc_dointvec,
2498 .ctl_name = NET_NEIGH_RETRANS_TIME_MS,
2499 .procname = "retrans_time_ms",
2500 .maxlen = sizeof(int),
2502 .proc_handler = &proc_dointvec_ms_jiffies,
2503 .strategy = &sysctl_ms_jiffies,
2506 .ctl_name = NET_NEIGH_REACHABLE_TIME_MS,
2507 .procname = "base_reachable_time_ms",
2508 .maxlen = sizeof(int),
2510 .proc_handler = &proc_dointvec_ms_jiffies,
2511 .strategy = &sysctl_ms_jiffies,
2516 .ctl_name = NET_PROTO_CONF_DEFAULT,
2517 .procname = "default",
2521 .neigh_neigh_dir = {
2523 .procname = "neigh",
2527 .neigh_proto_dir = {
2534 .ctl_name = CTL_NET,
2541 int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2542 int p_id, int pdev_id, char *p_name,
2543 proc_handler *handler, ctl_handler *strategy)
2545 struct neigh_sysctl_table *t = kmalloc(sizeof(*t), GFP_KERNEL);
2546 const char *dev_name_source = NULL;
2547 char *dev_name = NULL;
2552 memcpy(t, &neigh_sysctl_template, sizeof(*t));
2553 t->neigh_vars[0].data = &p->mcast_probes;
2554 t->neigh_vars[1].data = &p->ucast_probes;
2555 t->neigh_vars[2].data = &p->app_probes;
2556 t->neigh_vars[3].data = &p->retrans_time;
2557 t->neigh_vars[4].data = &p->base_reachable_time;
2558 t->neigh_vars[5].data = &p->delay_probe_time;
2559 t->neigh_vars[6].data = &p->gc_staletime;
2560 t->neigh_vars[7].data = &p->queue_len;
2561 t->neigh_vars[8].data = &p->proxy_qlen;
2562 t->neigh_vars[9].data = &p->anycast_delay;
2563 t->neigh_vars[10].data = &p->proxy_delay;
2564 t->neigh_vars[11].data = &p->locktime;
2567 dev_name_source = dev->name;
2568 t->neigh_dev[0].ctl_name = dev->ifindex;
2569 t->neigh_vars[12].procname = NULL;
2570 t->neigh_vars[13].procname = NULL;
2571 t->neigh_vars[14].procname = NULL;
2572 t->neigh_vars[15].procname = NULL;
2574 dev_name_source = t->neigh_dev[0].procname;
2575 t->neigh_vars[12].data = (int *)(p + 1);
2576 t->neigh_vars[13].data = (int *)(p + 1) + 1;
2577 t->neigh_vars[14].data = (int *)(p + 1) + 2;
2578 t->neigh_vars[15].data = (int *)(p + 1) + 3;
2581 t->neigh_vars[16].data = &p->retrans_time;
2582 t->neigh_vars[17].data = &p->base_reachable_time;
2584 if (handler || strategy) {
2586 t->neigh_vars[3].proc_handler = handler;
2587 t->neigh_vars[3].strategy = strategy;
2588 t->neigh_vars[3].extra1 = dev;
2590 t->neigh_vars[4].proc_handler = handler;
2591 t->neigh_vars[4].strategy = strategy;
2592 t->neigh_vars[4].extra1 = dev;
2593 /* RetransTime (in milliseconds)*/
2594 t->neigh_vars[16].proc_handler = handler;
2595 t->neigh_vars[16].strategy = strategy;
2596 t->neigh_vars[16].extra1 = dev;
2597 /* ReachableTime (in milliseconds) */
2598 t->neigh_vars[17].proc_handler = handler;
2599 t->neigh_vars[17].strategy = strategy;
2600 t->neigh_vars[17].extra1 = dev;
2603 dev_name = kstrdup(dev_name_source, GFP_KERNEL);
2609 t->neigh_dev[0].procname = dev_name;
2611 t->neigh_neigh_dir[0].ctl_name = pdev_id;
2613 t->neigh_proto_dir[0].procname = p_name;
2614 t->neigh_proto_dir[0].ctl_name = p_id;
2616 t->neigh_dev[0].child = t->neigh_vars;
2617 t->neigh_neigh_dir[0].child = t->neigh_dev;
2618 t->neigh_proto_dir[0].child = t->neigh_neigh_dir;
2619 t->neigh_root_dir[0].child = t->neigh_proto_dir;
2621 t->sysctl_header = register_sysctl_table(t->neigh_root_dir, 0);
2622 if (!t->sysctl_header) {
2626 p->sysctl_table = t;
2638 void neigh_sysctl_unregister(struct neigh_parms *p)
2640 if (p->sysctl_table) {
2641 struct neigh_sysctl_table *t = p->sysctl_table;
2642 p->sysctl_table = NULL;
2643 unregister_sysctl_table(t->sysctl_header);
2644 kfree(t->neigh_dev[0].procname);
2649 #endif /* CONFIG_SYSCTL */
2651 EXPORT_SYMBOL(__neigh_event_send);
2652 EXPORT_SYMBOL(neigh_add);
2653 EXPORT_SYMBOL(neigh_changeaddr);
2654 EXPORT_SYMBOL(neigh_compat_output);
2655 EXPORT_SYMBOL(neigh_connected_output);
2656 EXPORT_SYMBOL(neigh_create);
2657 EXPORT_SYMBOL(neigh_delete);
2658 EXPORT_SYMBOL(neigh_destroy);
2659 EXPORT_SYMBOL(neigh_dump_info);
2660 EXPORT_SYMBOL(neigh_event_ns);
2661 EXPORT_SYMBOL(neigh_ifdown);
2662 EXPORT_SYMBOL(neigh_lookup);
2663 EXPORT_SYMBOL(neigh_lookup_nodev);
2664 EXPORT_SYMBOL(neigh_parms_alloc);
2665 EXPORT_SYMBOL(neigh_parms_release);
2666 EXPORT_SYMBOL(neigh_rand_reach_time);
2667 EXPORT_SYMBOL(neigh_resolve_output);
2668 EXPORT_SYMBOL(neigh_table_clear);
2669 EXPORT_SYMBOL(neigh_table_init);
2670 EXPORT_SYMBOL(neigh_update);
2671 EXPORT_SYMBOL(neigh_update_hhs);
2672 EXPORT_SYMBOL(pneigh_enqueue);
2673 EXPORT_SYMBOL(pneigh_lookup);
2674 EXPORT_SYMBOL(neightbl_dump_info);
2675 EXPORT_SYMBOL(neightbl_set);
2678 EXPORT_SYMBOL(neigh_app_ns);
2680 #ifdef CONFIG_SYSCTL
2681 EXPORT_SYMBOL(neigh_sysctl_register);
2682 EXPORT_SYMBOL(neigh_sysctl_unregister);