1 #ifndef _NET_NEIGHBOUR_H
2 #define _NET_NEIGHBOUR_H
5 * Generic neighbour manipulation
8 * Pedro Roque <pedro_m@yahoo.com>
9 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
13 * Harald Welte: <laforge@gnumonks.org>
14 * - Add neighbour cache statistics like rtstat
17 /* The following flags & states are exported to user space,
18 so that they should be moved to include/linux/ directory.
22 * Neighbor Cache Entry Flags
25 #define NTF_PROXY 0x08 /* == ATF_PUBL */
26 #define NTF_ROUTER 0x80
29 * Neighbor Cache Entry States.
32 #define NUD_INCOMPLETE 0x01
33 #define NUD_REACHABLE 0x02
34 #define NUD_STALE 0x04
35 #define NUD_DELAY 0x08
36 #define NUD_PROBE 0x10
37 #define NUD_FAILED 0x20
40 #define NUD_NOARP 0x40
41 #define NUD_PERMANENT 0x80
44 /* NUD_NOARP & NUD_PERMANENT are pseudostates, they never change
45 and make no address resolution or NUD.
46 NUD_PERMANENT is also cannot be deleted by garbage collectors.
51 #include <asm/atomic.h>
52 #include <linux/skbuff.h>
53 #include <linux/seq_file.h>
55 #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE)
56 #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
57 #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
61 struct neigh_parms *next;
62 int (*neigh_setup)(struct neighbour *);
63 struct neigh_table *tbl;
69 int base_reachable_time;
85 struct neigh_statistics
87 unsigned long allocs; /* number of allocated neighs */
88 unsigned long destroys; /* number of destroyed neighs */
89 unsigned long hash_grows; /* number of hash resizes */
91 unsigned long res_failed; /* nomber of failed resolutions */
93 unsigned long lookups; /* number of lookups */
94 unsigned long hits; /* number of hits (among lookups) */
96 unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
97 unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
99 unsigned long periodic_gc_runs; /* number of periodic GC runs */
100 unsigned long forced_gc_runs; /* number of forced GC runs */
103 #define NEIGH_CACHE_STAT_INC(tbl, field) \
104 ((tbl)->stats[smp_processor_id()].field++)
108 struct neighbour *next;
109 struct neigh_table *tbl;
110 struct neigh_parms *parms;
111 struct net_device *dev;
113 unsigned long confirmed;
114 unsigned long updated;
121 unsigned char ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)];
124 int (*output)(struct sk_buff *skb);
125 struct sk_buff_head arp_queue;
126 struct timer_list timer;
127 struct neigh_ops *ops;
134 void (*destructor)(struct neighbour *);
135 void (*solicit)(struct neighbour *, struct sk_buff*);
136 void (*error_report)(struct neighbour *, struct sk_buff*);
137 int (*output)(struct sk_buff*);
138 int (*connected_output)(struct sk_buff*);
139 int (*hh_output)(struct sk_buff*);
140 int (*queue_xmit)(struct sk_buff*);
145 struct pneigh_entry *next;
146 struct net_device *dev;
151 * neighbour table manipulation
157 struct neigh_table *next;
161 __u32 (*hash)(const void *pkey, const struct net_device *);
162 int (*constructor)(struct neighbour *);
163 int (*pconstructor)(struct pneigh_entry *);
164 void (*pdestructor)(struct pneigh_entry *);
165 void (*proxy_redo)(struct sk_buff *skb);
167 struct neigh_parms parms;
168 /* HACK. gc_* shoul follow parms without a gap! */
173 unsigned long last_flush;
174 struct timer_list gc_timer;
175 struct timer_list proxy_timer;
176 struct sk_buff_head proxy_queue;
179 unsigned long last_rand;
180 struct neigh_parms *parms_list;
181 kmem_cache_t *kmem_cachep;
182 struct tasklet_struct gc_task;
183 struct neigh_statistics stats[NR_CPUS];
184 struct neighbour **hash_buckets;
185 unsigned int hash_mask;
187 unsigned int hash_chain_gc;
188 struct pneigh_entry **phash_buckets;
189 #ifdef CONFIG_PROC_FS
190 struct proc_dir_entry *pde;
194 extern void neigh_table_init(struct neigh_table *tbl);
195 extern int neigh_table_clear(struct neigh_table *tbl);
196 extern struct neighbour * neigh_lookup(struct neigh_table *tbl,
198 struct net_device *dev);
199 extern struct neighbour * neigh_lookup_nodev(struct neigh_table *tbl,
201 extern struct neighbour * neigh_create(struct neigh_table *tbl,
203 struct net_device *dev);
204 extern void neigh_destroy(struct neighbour *neigh);
205 extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
206 extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, int override, int arp);
207 extern void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
208 extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
209 extern int neigh_resolve_output(struct sk_buff *skb);
210 extern int neigh_connected_output(struct sk_buff *skb);
211 extern int neigh_compat_output(struct sk_buff *skb);
212 extern struct neighbour *neigh_event_ns(struct neigh_table *tbl,
213 u8 *lladdr, void *saddr,
214 struct net_device *dev);
216 extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl);
217 extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
218 extern unsigned long neigh_rand_reach_time(unsigned long base);
220 extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
221 struct sk_buff *skb);
222 extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat);
223 extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev);
225 struct netlink_callback;
227 extern int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb);
228 extern int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
229 extern int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
230 extern void neigh_app_ns(struct neighbour *n);
232 extern void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie);
233 extern void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *));
234 extern void pneigh_for_each(struct neigh_table *tbl, void (*cb)(struct pneigh_entry *));
236 struct neigh_seq_state {
237 struct neigh_table *tbl;
238 void *(*neigh_sub_iter)(struct neigh_seq_state *state,
239 struct neighbour *n, loff_t *pos);
242 #define NEIGH_SEQ_NEIGH_ONLY 0x00000001
243 #define NEIGH_SEQ_IS_PNEIGH 0x00000002
244 #define NEIGH_SEQ_SKIP_NOARP 0x00000004
246 extern void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *, unsigned int);
247 extern void *neigh_seq_next(struct seq_file *, void *, loff_t *);
248 extern void neigh_seq_stop(struct seq_file *, void *);
250 extern int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
251 int p_id, int pdev_id, char *p_name);
252 extern void neigh_sysctl_unregister(struct neigh_parms *p);
255 * Neighbour references
258 static inline void neigh_release(struct neighbour *neigh)
260 if (atomic_dec_and_test(&neigh->refcnt))
261 neigh_destroy(neigh);
264 static inline struct neighbour * neigh_clone(struct neighbour *neigh)
267 atomic_inc(&neigh->refcnt);
271 #define neigh_hold(n) atomic_inc(&(n)->refcnt)
273 static inline void neigh_confirm(struct neighbour *neigh)
276 neigh->confirmed = jiffies;
279 static inline int neigh_is_connected(struct neighbour *neigh)
281 return neigh->nud_state&NUD_CONNECTED;
284 static inline int neigh_is_valid(struct neighbour *neigh)
286 return neigh->nud_state&NUD_VALID;
289 static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
291 neigh->used = jiffies;
292 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
293 return __neigh_event_send(neigh, skb);
297 static inline struct neighbour *
298 __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
300 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
305 n = neigh_create(tbl, pkey, dev);
306 return IS_ERR(n) ? NULL : n;
309 static inline struct neighbour *
310 __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
311 struct net_device *dev)
313 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
318 return neigh_create(tbl, pkey, dev);