]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/net/neighbour.h
[TCP]: Do not purge sk_forward_alloc entirely in tcp_delack_timer().
[net-next-2.6.git] / include / net / neighbour.h
CommitLineData
1da177e4
LT
1#ifndef _NET_NEIGHBOUR_H
2#define _NET_NEIGHBOUR_H
3
9067c722
TG
4#include <linux/neighbour.h>
5
1da177e4
LT
6/*
7 * Generic neighbour manipulation
8 *
9 * Authors:
10 * Pedro Roque <roque@di.fc.ul.pt>
11 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
12 *
13 * Changes:
14 *
15 * Harald Welte: <laforge@gnumonks.org>
16 * - Add neighbour cache statistics like rtstat
17 */
18
1da177e4 19#include <asm/atomic.h>
1da177e4 20#include <linux/netdevice.h>
14c85021 21#include <linux/skbuff.h>
1da177e4
LT
22#include <linux/rcupdate.h>
23#include <linux/seq_file.h>
24
25#include <linux/err.h>
26#include <linux/sysctl.h>
c8822a4e 27#include <net/rtnetlink.h>
1da177e4
LT
28
29#define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE)
30#define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
31#define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
32
33struct neighbour;
34
35struct neigh_parms
36{
426b5303 37 struct net *net;
c7fb64db 38 struct net_device *dev;
1da177e4
LT
39 struct neigh_parms *next;
40 int (*neigh_setup)(struct neighbour *);
ecbb4169 41 void (*neigh_cleanup)(struct neighbour *);
1da177e4 42 struct neigh_table *tbl;
1da177e4
LT
43
44 void *sysctl_table;
45
46 int dead;
47 atomic_t refcnt;
48 struct rcu_head rcu_head;
49
50 int base_reachable_time;
51 int retrans_time;
52 int gc_staletime;
53 int reachable_time;
54 int delay_probe_time;
55
56 int queue_len;
57 int ucast_probes;
58 int app_probes;
59 int mcast_probes;
60 int anycast_delay;
61 int proxy_delay;
62 int proxy_qlen;
63 int locktime;
64};
65
66struct neigh_statistics
67{
68 unsigned long allocs; /* number of allocated neighs */
69 unsigned long destroys; /* number of destroyed neighs */
70 unsigned long hash_grows; /* number of hash resizes */
71
72 unsigned long res_failed; /* nomber of failed resolutions */
73
74 unsigned long lookups; /* number of lookups */
75 unsigned long hits; /* number of hits (among lookups) */
76
77 unsigned long rcv_probes_mcast; /* number of received mcast ipv6 */
78 unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
79
80 unsigned long periodic_gc_runs; /* number of periodic GC runs */
81 unsigned long forced_gc_runs; /* number of forced GC runs */
82};
83
84#define NEIGH_CACHE_STAT_INC(tbl, field) \
85 do { \
86 preempt_disable(); \
87 (per_cpu_ptr((tbl)->stats, smp_processor_id())->field)++; \
88 preempt_enable(); \
89 } while (0)
90
91struct neighbour
92{
93 struct neighbour *next;
94 struct neigh_table *tbl;
95 struct neigh_parms *parms;
96 struct net_device *dev;
97 unsigned long used;
98 unsigned long confirmed;
99 unsigned long updated;
100 __u8 flags;
101 __u8 nud_state;
102 __u8 type;
103 __u8 dead;
104 atomic_t probes;
105 rwlock_t lock;
d924424a 106 unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))];
1da177e4
LT
107 struct hh_cache *hh;
108 atomic_t refcnt;
109 int (*output)(struct sk_buff *skb);
110 struct sk_buff_head arp_queue;
111 struct timer_list timer;
112 struct neigh_ops *ops;
113 u8 primary_key[0];
114};
115
116struct neigh_ops
117{
118 int family;
1da177e4
LT
119 void (*solicit)(struct neighbour *, struct sk_buff*);
120 void (*error_report)(struct neighbour *, struct sk_buff*);
121 int (*output)(struct sk_buff*);
122 int (*connected_output)(struct sk_buff*);
123 int (*hh_output)(struct sk_buff*);
124 int (*queue_xmit)(struct sk_buff*);
125};
126
127struct pneigh_entry
128{
129 struct pneigh_entry *next;
426b5303
EB
130 struct net *net;
131 struct net_device *dev;
62dd9318 132 u8 flags;
1da177e4
LT
133 u8 key[0];
134};
135
136/*
137 * neighbour table manipulation
138 */
139
140
141struct neigh_table
142{
143 struct neigh_table *next;
144 int family;
145 int entry_size;
146 int key_len;
147 __u32 (*hash)(const void *pkey, const struct net_device *);
148 int (*constructor)(struct neighbour *);
149 int (*pconstructor)(struct pneigh_entry *);
150 void (*pdestructor)(struct pneigh_entry *);
151 void (*proxy_redo)(struct sk_buff *skb);
152 char *id;
153 struct neigh_parms parms;
154 /* HACK. gc_* shoul follow parms without a gap! */
155 int gc_interval;
156 int gc_thresh1;
157 int gc_thresh2;
158 int gc_thresh3;
159 unsigned long last_flush;
160 struct timer_list gc_timer;
161 struct timer_list proxy_timer;
162 struct sk_buff_head proxy_queue;
163 atomic_t entries;
164 rwlock_t lock;
165 unsigned long last_rand;
e18b890b 166 struct kmem_cache *kmem_cachep;
1da177e4
LT
167 struct neigh_statistics *stats;
168 struct neighbour **hash_buckets;
169 unsigned int hash_mask;
170 __u32 hash_rnd;
171 unsigned int hash_chain_gc;
172 struct pneigh_entry **phash_buckets;
173#ifdef CONFIG_PROC_FS
174 struct proc_dir_entry *pde;
175#endif
176};
177
178/* flags for neigh_update() */
179#define NEIGH_UPDATE_F_OVERRIDE 0x00000001
180#define NEIGH_UPDATE_F_WEAK_OVERRIDE 0x00000002
181#define NEIGH_UPDATE_F_OVERRIDE_ISROUTER 0x00000004
182#define NEIGH_UPDATE_F_ISROUTER 0x40000000
183#define NEIGH_UPDATE_F_ADMIN 0x80000000
184
185extern void neigh_table_init(struct neigh_table *tbl);
bd89efc5 186extern void neigh_table_init_no_netlink(struct neigh_table *tbl);
1da177e4
LT
187extern int neigh_table_clear(struct neigh_table *tbl);
188extern struct neighbour * neigh_lookup(struct neigh_table *tbl,
189 const void *pkey,
190 struct net_device *dev);
191extern struct neighbour * neigh_lookup_nodev(struct neigh_table *tbl,
426b5303 192 struct net *net,
1da177e4
LT
193 const void *pkey);
194extern struct neighbour * neigh_create(struct neigh_table *tbl,
195 const void *pkey,
196 struct net_device *dev);
197extern void neigh_destroy(struct neighbour *neigh);
198extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
199extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
200 u32 flags);
201extern void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
202extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
203extern int neigh_resolve_output(struct sk_buff *skb);
204extern int neigh_connected_output(struct sk_buff *skb);
205extern int neigh_compat_output(struct sk_buff *skb);
206extern struct neighbour *neigh_event_ns(struct neigh_table *tbl,
207 u8 *lladdr, void *saddr,
208 struct net_device *dev);
209
210extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl);
211extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
212extern void neigh_parms_destroy(struct neigh_parms *parms);
213extern unsigned long neigh_rand_reach_time(unsigned long base);
214
215extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
216 struct sk_buff *skb);
426b5303
EB
217extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev, int creat);
218extern int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev);
1da177e4 219
1da177e4 220extern void neigh_app_ns(struct neighbour *n);
1da177e4
LT
221extern void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void *), void *cookie);
222extern void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *));
223extern void pneigh_for_each(struct neigh_table *tbl, void (*cb)(struct pneigh_entry *));
224
225struct neigh_seq_state {
42508461 226 struct seq_net_private p;
1da177e4
LT
227 struct neigh_table *tbl;
228 void *(*neigh_sub_iter)(struct neigh_seq_state *state,
229 struct neighbour *n, loff_t *pos);
230 unsigned int bucket;
231 unsigned int flags;
232#define NEIGH_SEQ_NEIGH_ONLY 0x00000001
233#define NEIGH_SEQ_IS_PNEIGH 0x00000002
234#define NEIGH_SEQ_SKIP_NOARP 0x00000004
235};
236extern void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *, unsigned int);
237extern void *neigh_seq_next(struct seq_file *, void *, loff_t *);
238extern void neigh_seq_stop(struct seq_file *, void *);
239
240extern int neigh_sysctl_register(struct net_device *dev,
241 struct neigh_parms *p,
242 int p_id, int pdev_id,
243 char *p_name,
244 proc_handler *proc_handler,
245 ctl_handler *strategy);
246extern void neigh_sysctl_unregister(struct neigh_parms *p);
247
248static inline void __neigh_parms_put(struct neigh_parms *parms)
249{
250 atomic_dec(&parms->refcnt);
251}
252
253static inline void neigh_parms_put(struct neigh_parms *parms)
254{
255 if (atomic_dec_and_test(&parms->refcnt))
256 neigh_parms_destroy(parms);
257}
258
259static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
260{
261 atomic_inc(&parms->refcnt);
262 return parms;
263}
264
265/*
266 * Neighbour references
267 */
268
269static inline void neigh_release(struct neighbour *neigh)
270{
271 if (atomic_dec_and_test(&neigh->refcnt))
272 neigh_destroy(neigh);
273}
274
275static inline struct neighbour * neigh_clone(struct neighbour *neigh)
276{
277 if (neigh)
278 atomic_inc(&neigh->refcnt);
279 return neigh;
280}
281
282#define neigh_hold(n) atomic_inc(&(n)->refcnt)
283
284static inline void neigh_confirm(struct neighbour *neigh)
285{
286 if (neigh)
287 neigh->confirmed = jiffies;
288}
289
290static inline int neigh_is_connected(struct neighbour *neigh)
291{
292 return neigh->nud_state&NUD_CONNECTED;
293}
294
1da177e4
LT
295
296static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
297{
298 neigh->used = jiffies;
299 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
300 return __neigh_event_send(neigh, skb);
301 return 0;
302}
303
3644f0ce
SH
304static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
305{
306 unsigned seq;
307 int hh_len;
308
309 do {
310 int hh_alen;
311
312 seq = read_seqbegin(&hh->hh_lock);
313 hh_len = hh->hh_len;
314 hh_alen = HH_DATA_ALIGN(hh_len);
315 memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
316 } while (read_seqretry(&hh->hh_lock, seq));
317
318 skb_push(skb, hh_len);
319 return hh->hh_output(skb);
320}
321
1da177e4
LT
322static inline struct neighbour *
323__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
324{
325 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
326
327 if (n || !creat)
328 return n;
329
330 n = neigh_create(tbl, pkey, dev);
331 return IS_ERR(n) ? NULL : n;
332}
333
334static inline struct neighbour *
335__neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
336 struct net_device *dev)
337{
338 struct neighbour *n = neigh_lookup(tbl, pkey, dev);
339
340 if (n)
341 return n;
342
343 return neigh_create(tbl, pkey, dev);
344}
345
a61bbcf2
PM
346struct neighbour_cb {
347 unsigned long sched_next;
348 unsigned int flags;
349};
350
351#define LOCALLY_ENQUEUED 0x1
352
353#define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
1da177e4
LT
354
355#endif