aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/neighbour.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/neighbour.h')
-rw-r--r--include/net/neighbour.h370
1 files changed, 370 insertions, 0 deletions
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
new file mode 100644
index 000000000000..4f33bbc21e7f
--- /dev/null
+++ b/include/net/neighbour.h
@@ -0,0 +1,370 @@
1#ifndef _NET_NEIGHBOUR_H
2#define _NET_NEIGHBOUR_H
3
4/*
5 * Generic neighbour manipulation
6 *
7 * Authors:
8 * Pedro Roque <roque@di.fc.ul.pt>
9 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
10 *
11 * Changes:
12 *
13 * Harald Welte: <laforge@gnumonks.org>
14 * - Add neighbour cache statistics like rtstat
15 */
16
17/* The following flags & states are exported to user space,
18 so that they should be moved to include/linux/ directory.
19 */
20
21/*
22 * Neighbor Cache Entry Flags
23 */
24
25#define NTF_PROXY 0x08 /* == ATF_PUBL */
26#define NTF_ROUTER 0x80
27
28/*
29 * Neighbor Cache Entry States.
30 */
31
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
38
39/* Dummy states */
40#define NUD_NOARP 0x40
41#define NUD_PERMANENT 0x80
42#define NUD_NONE 0x00
43
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.
47 */
48
49#ifdef __KERNEL__
50
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>
56
57#include <linux/err.h>
58#include <linux/sysctl.h>
59
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)
63
64struct neighbour;
65
66struct neigh_parms
67{
68 struct neigh_parms *next;
69 int (*neigh_setup)(struct neighbour *);
70 struct neigh_table *tbl;
71 int entries;
72 void *priv;
73
74 void *sysctl_table;
75
76 int dead;
77 atomic_t refcnt;
78 struct rcu_head rcu_head;
79
80 int base_reachable_time;
81 int retrans_time;
82 int gc_staletime;
83 int reachable_time;
84 int delay_probe_time;
85
86 int queue_len;
87 int ucast_probes;
88 int app_probes;
89 int mcast_probes;
90 int anycast_delay;
91 int proxy_delay;
92 int proxy_qlen;
93 int locktime;
94};
95
96struct neigh_statistics
97{
98 unsigned long allocs; /* number of allocated neighs */
99 unsigned long destroys; /* number of destroyed neighs */
100 unsigned long hash_grows; /* number of hash resizes */
101
102 unsigned long res_failed; /* nomber of failed resolutions */
103
104 unsigned long lookups; /* number of lookups */
105 unsigned long hits; /* number of hits (among lookups) */
106
107 unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
108 unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
109
110 unsigned long periodic_gc_runs; /* number of periodic GC runs */
111 unsigned long forced_gc_runs; /* number of forced GC runs */
112};
113
114#define NEIGH_CACHE_STAT_INC(tbl, field) \
115 do { \
116 preempt_disable(); \
117 (per_cpu_ptr((tbl)->stats, smp_processor_id())->field)++; \
118 preempt_enable(); \
119 } while (0)
120
121struct neighbour
122{
123 struct neighbour *next;
124 struct neigh_table *tbl;
125 struct neigh_parms *parms;
126 struct net_device *dev;
127 unsigned long used;
128 unsigned long confirmed;
129 unsigned long updated;
130 __u8 flags;
131 __u8 nud_state;
132 __u8 type;
133 __u8 dead;
134 atomic_t probes;
135 rwlock_t lock;
136 unsigned char ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)];
137 struct hh_cache *hh;
138 atomic_t refcnt;
139 int (*output)(struct sk_buff *skb);
140 struct sk_buff_head arp_queue;
141 struct timer_list timer;
142 struct neigh_ops *ops;
143 u8 primary_key[0];
144};
145
146struct neigh_ops
147{
148 int family;
149 void (*destructor)(struct neighbour *);
150 void (*solicit)(struct neighbour *, struct sk_buff*);
151 void (*error_report)(struct neighbour *, struct sk_buff*);
152 int (*output)(struct sk_buff*);
153 int (*connected_output)(struct sk_buff*);
154 int (*hh_output)(struct sk_buff*);
155 int (*queue_xmit)(struct sk_buff*);
156};
157
158struct pneigh_entry
159{
160 struct pneigh_entry *next;
161 struct net_device *dev;
162 u8 key[0];
163};
164
165/*
166 * neighbour table manipulation
167 */
168
169
170struct neigh_table
171{
172 struct neigh_table *next;
173 int family;
174 int entry_size;
175 int key_len;
176 __u32 (*hash)(const void *pkey, const struct net_device *);
177 int (*constructor)(struct neighbour *);
178 int (*pconstructor)(struct pneigh_entry *);
179 void (*pdestructor)(struct pneigh_entry *);
180 void (*proxy_redo)(struct sk_buff *skb);
181 char *id;
182 struct neigh_parms parms;
183 /* HACK. gc_* shoul follow parms without a gap! */
184 int gc_interval;
185 int gc_thresh1;
186 int gc_thresh2;
187 int gc_thresh3;
188 unsigned long last_flush;
189 struct timer_list gc_timer;
190 struct timer_list proxy_timer;
191 struct sk_buff_head proxy_queue;
192 atomic_t entries;
193 rwlock_t lock;
194 unsigned long last_rand;
195 struct neigh_parms *parms_list;
196 kmem_cache_t *kmem_cachep;
197 struct neigh_statistics *stats;
198 struct neighbour **hash_buckets;
199 unsigned int hash_mask;
200 __u32 hash_rnd;
201 unsigned int hash_chain_gc;
202 struct pneigh_entry **phash_buckets;
203#ifdef CONFIG_PROC_FS
204 struct proc_dir_entry *pde;
205#endif
206};
207
208/* flags for neigh_update() */
209#define NEIGH_UPDATE_F_OVERRIDE 0x00000001
210#define NEIGH_UPDATE_F_WEAK_OVERRIDE 0x00000002
211#define NEIGH_UPDATE_F_OVERRIDE_ISROUTER 0x00000004
212#define NEIGH_UPDATE_F_ISROUTER 0x40000000
213#define NEIGH_UPDATE_F_ADMIN 0x80000000
214
215extern void neigh_table_init(struct neigh_table *tbl);
216extern int neigh_table_clear(struct neigh_table *tbl);
217extern struct neighbour * neigh_lookup(struct neigh_table *tbl,
218 const void *pkey,
219 struct net_device *dev);
220extern struct neighbour * neigh_lookup_nodev(struct neigh_table *tbl,
221 const void *pkey);
222extern struct neighbour * neigh_create(struct neigh_table *tbl,
223 const void *pkey,
224 struct net_device *dev);
225extern void neigh_destroy(struct neighbour *neigh);
226extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
227extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
228 u32 flags);
229extern void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
230extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
231extern int neigh_resolve_output(struct sk_buff *skb);
232extern int neigh_connected_output(struct sk_buff *skb);
233extern int neigh_compat_output(struct sk_buff *skb);
234extern struct neighbour *neigh_event_ns(struct neigh_table *tbl,
235 u8 *lladdr, void *saddr,
236 struct net_device *dev);
237
238extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl);
239extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
240extern void neigh_parms_destroy(struct neigh_parms *parms);
241extern unsigned long neigh_rand_reach_time(unsigned long base);
242
243extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
244 struct sk_buff *skb);
245extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat);
246extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev);
247
248struct netlink_callback;
249struct nlmsghdr;
250extern int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb);
251extern int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
252extern int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
253extern void neigh_app_ns(struct neighbour *n);
254
255extern void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie);
256extern void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *));
257extern void pneigh_for_each(struct neigh_table *tbl, void (*cb)(struct pneigh_entry *));
258
259struct neigh_seq_state {
260 struct neigh_table *tbl;
261 void *(*neigh_sub_iter)(struct neigh_seq_state *state,
262 struct neighbour *n, loff_t *pos);
263 unsigned int bucket;
264 unsigned int flags;
265#define NEIGH_SEQ_NEIGH_ONLY 0x00000001
266#define NEIGH_SEQ_IS_PNEIGH 0x00000002
267#define NEIGH_SEQ_SKIP_NOARP 0x00000004
268};
269extern void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *, unsigned int);
270extern void *neigh_seq_next(struct seq_file *, void *, loff_t *);
271extern void neigh_seq_stop(struct seq_file *, void *);
272
273extern int neigh_sysctl_register(struct net_device *dev,
274 struct neigh_parms *p,
275 int p_id, int pdev_id,
276 char *p_name,
277 proc_handler *proc_handler,
278 ctl_handler *strategy);
279extern void neigh_sysctl_unregister(struct neigh_parms *p);
280
281static inline void __neigh_parms_put(struct neigh_parms *parms)
282{
283 atomic_dec(&parms->refcnt);
284}
285
286static inline void neigh_parms_put(struct neigh_parms *parms)
287{
288 if (atomic_dec_and_test(&parms->refcnt))
289 neigh_parms_destroy(parms);
290}
291
292static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
293{
294 atomic_inc(&parms->refcnt);
295 return parms;
296}
297
298/*
299 * Neighbour references
300 */
301
302static inline void neigh_release(struct neighbour *neigh)
303{
304 if (atomic_dec_and_test(&neigh->refcnt))
305 neigh_destroy(neigh);
306}
307
308static inline struct neighbour * neigh_clone(struct neighbour *neigh)
309{
310 if (neigh)
311 atomic_inc(&neigh->refcnt);
312 return neigh;
313}
314
315#define neigh_hold(n) atomic_inc(&(n)->refcnt)
316
317static inline void neigh_confirm(struct neighbour *neigh)
318{
319 if (neigh)
320 neigh->confirmed = jiffies;
321}
322
323static inline int neigh_is_connected(struct neighbour *neigh)
324{
325 return neigh->nud_state&NUD_CONNECTED;
326}
327
328static inline int neigh_is_valid(struct neighbour *neigh)
329{
330 return neigh->nud_state&NUD_VALID;
331}
332
333static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
334{
335 neigh->used = jiffies;
336 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
337 return __neigh_event_send(neigh, skb);
338 return 0;
339}
340
341static inline struct neighbour *
342__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
343{
344 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
345
346 if (n || !creat)
347 return n;
348
349 n = neigh_create(tbl, pkey, dev);
350 return IS_ERR(n) ? NULL : n;
351}
352
353static inline struct neighbour *
354__neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
355 struct net_device *dev)
356{
357 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
358
359 if (n)
360 return n;
361
362 return neigh_create(tbl, pkey, dev);
363}
364
365#define LOCALLY_ENQUEUED -2
366
367#endif
368#endif
369
370