Linux v2.6.13-rc3
[pohmelfs.git] / include / net / neighbour.h
blob89809891e5ab2e8e9430ccac31255d22ee364231
1 #ifndef _NET_NEIGHBOUR_H
2 #define _NET_NEIGHBOUR_H
4 /*
5 * Generic neighbour manipulation
7 * Authors:
8 * Pedro Roque <roque@di.fc.ul.pt>
9 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
11 * Changes:
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
39 /* Dummy states */
40 #define NUD_NOARP 0x40
41 #define NUD_PERMANENT 0x80
42 #define NUD_NONE 0x00
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.
49 #ifdef __KERNEL__
51 #include <asm/atomic.h>
52 #include <linux/skbuff.h>
53 #include <linux/netdevice.h>
54 #include <linux/rcupdate.h>
55 #include <linux/seq_file.h>
57 #include <linux/err.h>
58 #include <linux/sysctl.h>
60 #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE)
61 #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
62 #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
64 struct neighbour;
66 struct neigh_parms
68 struct net_device *dev;
69 struct neigh_parms *next;
70 int (*neigh_setup)(struct neighbour *);
71 struct neigh_table *tbl;
73 void *sysctl_table;
75 int dead;
76 atomic_t refcnt;
77 struct rcu_head rcu_head;
79 int base_reachable_time;
80 int retrans_time;
81 int gc_staletime;
82 int reachable_time;
83 int delay_probe_time;
85 int queue_len;
86 int ucast_probes;
87 int app_probes;
88 int mcast_probes;
89 int anycast_delay;
90 int proxy_delay;
91 int proxy_qlen;
92 int locktime;
95 struct neigh_statistics
97 unsigned long allocs; /* number of allocated neighs */
98 unsigned long destroys; /* number of destroyed neighs */
99 unsigned long hash_grows; /* number of hash resizes */
101 unsigned long res_failed; /* nomber of failed resolutions */
103 unsigned long lookups; /* number of lookups */
104 unsigned long hits; /* number of hits (among lookups) */
106 unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
107 unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
109 unsigned long periodic_gc_runs; /* number of periodic GC runs */
110 unsigned long forced_gc_runs; /* number of forced GC runs */
113 #define NEIGH_CACHE_STAT_INC(tbl, field) \
114 do { \
115 preempt_disable(); \
116 (per_cpu_ptr((tbl)->stats, smp_processor_id())->field)++; \
117 preempt_enable(); \
118 } while (0)
120 struct neighbour
122 struct neighbour *next;
123 struct neigh_table *tbl;
124 struct neigh_parms *parms;
125 struct net_device *dev;
126 unsigned long used;
127 unsigned long confirmed;
128 unsigned long updated;
129 __u8 flags;
130 __u8 nud_state;
131 __u8 type;
132 __u8 dead;
133 atomic_t probes;
134 rwlock_t lock;
135 unsigned char ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)];
136 struct hh_cache *hh;
137 atomic_t refcnt;
138 int (*output)(struct sk_buff *skb);
139 struct sk_buff_head arp_queue;
140 struct timer_list timer;
141 struct neigh_ops *ops;
142 u8 primary_key[0];
145 struct neigh_ops
147 int family;
148 void (*destructor)(struct neighbour *);
149 void (*solicit)(struct neighbour *, struct sk_buff*);
150 void (*error_report)(struct neighbour *, struct sk_buff*);
151 int (*output)(struct sk_buff*);
152 int (*connected_output)(struct sk_buff*);
153 int (*hh_output)(struct sk_buff*);
154 int (*queue_xmit)(struct sk_buff*);
157 struct pneigh_entry
159 struct pneigh_entry *next;
160 struct net_device *dev;
161 u8 key[0];
165 * neighbour table manipulation
169 struct neigh_table
171 struct neigh_table *next;
172 int family;
173 int entry_size;
174 int key_len;
175 __u32 (*hash)(const void *pkey, const struct net_device *);
176 int (*constructor)(struct neighbour *);
177 int (*pconstructor)(struct pneigh_entry *);
178 void (*pdestructor)(struct pneigh_entry *);
179 void (*proxy_redo)(struct sk_buff *skb);
180 char *id;
181 struct neigh_parms parms;
182 /* HACK. gc_* shoul follow parms without a gap! */
183 int gc_interval;
184 int gc_thresh1;
185 int gc_thresh2;
186 int gc_thresh3;
187 unsigned long last_flush;
188 struct timer_list gc_timer;
189 struct timer_list proxy_timer;
190 struct sk_buff_head proxy_queue;
191 atomic_t entries;
192 rwlock_t lock;
193 unsigned long last_rand;
194 kmem_cache_t *kmem_cachep;
195 struct neigh_statistics *stats;
196 struct neighbour **hash_buckets;
197 unsigned int hash_mask;
198 __u32 hash_rnd;
199 unsigned int hash_chain_gc;
200 struct pneigh_entry **phash_buckets;
201 #ifdef CONFIG_PROC_FS
202 struct proc_dir_entry *pde;
203 #endif
206 /* flags for neigh_update() */
207 #define NEIGH_UPDATE_F_OVERRIDE 0x00000001
208 #define NEIGH_UPDATE_F_WEAK_OVERRIDE 0x00000002
209 #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER 0x00000004
210 #define NEIGH_UPDATE_F_ISROUTER 0x40000000
211 #define NEIGH_UPDATE_F_ADMIN 0x80000000
213 extern void neigh_table_init(struct neigh_table *tbl);
214 extern int neigh_table_clear(struct neigh_table *tbl);
215 extern struct neighbour * neigh_lookup(struct neigh_table *tbl,
216 const void *pkey,
217 struct net_device *dev);
218 extern struct neighbour * neigh_lookup_nodev(struct neigh_table *tbl,
219 const void *pkey);
220 extern struct neighbour * neigh_create(struct neigh_table *tbl,
221 const void *pkey,
222 struct net_device *dev);
223 extern void neigh_destroy(struct neighbour *neigh);
224 extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
225 extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
226 u32 flags);
227 extern void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
228 extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
229 extern int neigh_resolve_output(struct sk_buff *skb);
230 extern int neigh_connected_output(struct sk_buff *skb);
231 extern int neigh_compat_output(struct sk_buff *skb);
232 extern struct neighbour *neigh_event_ns(struct neigh_table *tbl,
233 u8 *lladdr, void *saddr,
234 struct net_device *dev);
236 extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl);
237 extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
238 extern void neigh_parms_destroy(struct neigh_parms *parms);
239 extern unsigned long neigh_rand_reach_time(unsigned long base);
241 extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
242 struct sk_buff *skb);
243 extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat);
244 extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev);
246 struct netlink_callback;
247 struct nlmsghdr;
248 extern int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb);
249 extern int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
250 extern int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
251 extern void neigh_app_ns(struct neighbour *n);
253 extern int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb);
254 extern int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
256 extern void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie);
257 extern void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *));
258 extern void pneigh_for_each(struct neigh_table *tbl, void (*cb)(struct pneigh_entry *));
260 struct neigh_seq_state {
261 struct neigh_table *tbl;
262 void *(*neigh_sub_iter)(struct neigh_seq_state *state,
263 struct neighbour *n, loff_t *pos);
264 unsigned int bucket;
265 unsigned int flags;
266 #define NEIGH_SEQ_NEIGH_ONLY 0x00000001
267 #define NEIGH_SEQ_IS_PNEIGH 0x00000002
268 #define NEIGH_SEQ_SKIP_NOARP 0x00000004
270 extern void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *, unsigned int);
271 extern void *neigh_seq_next(struct seq_file *, void *, loff_t *);
272 extern void neigh_seq_stop(struct seq_file *, void *);
274 extern int neigh_sysctl_register(struct net_device *dev,
275 struct neigh_parms *p,
276 int p_id, int pdev_id,
277 char *p_name,
278 proc_handler *proc_handler,
279 ctl_handler *strategy);
280 extern void neigh_sysctl_unregister(struct neigh_parms *p);
282 static inline void __neigh_parms_put(struct neigh_parms *parms)
284 atomic_dec(&parms->refcnt);
287 static inline void neigh_parms_put(struct neigh_parms *parms)
289 if (atomic_dec_and_test(&parms->refcnt))
290 neigh_parms_destroy(parms);
293 static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
295 atomic_inc(&parms->refcnt);
296 return parms;
300 * Neighbour references
303 static inline void neigh_release(struct neighbour *neigh)
305 if (atomic_dec_and_test(&neigh->refcnt))
306 neigh_destroy(neigh);
309 static inline struct neighbour * neigh_clone(struct neighbour *neigh)
311 if (neigh)
312 atomic_inc(&neigh->refcnt);
313 return neigh;
316 #define neigh_hold(n) atomic_inc(&(n)->refcnt)
318 static inline void neigh_confirm(struct neighbour *neigh)
320 if (neigh)
321 neigh->confirmed = jiffies;
324 static inline int neigh_is_connected(struct neighbour *neigh)
326 return neigh->nud_state&NUD_CONNECTED;
329 static inline int neigh_is_valid(struct neighbour *neigh)
331 return neigh->nud_state&NUD_VALID;
334 static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
336 neigh->used = jiffies;
337 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
338 return __neigh_event_send(neigh, skb);
339 return 0;
342 static inline struct neighbour *
343 __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
345 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
347 if (n || !creat)
348 return n;
350 n = neigh_create(tbl, pkey, dev);
351 return IS_ERR(n) ? NULL : n;
354 static inline struct neighbour *
355 __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
356 struct net_device *dev)
358 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
360 if (n)
361 return n;
363 return neigh_create(tbl, pkey, dev);
366 #define LOCALLY_ENQUEUED -2
368 #endif
369 #endif