1 #ifndef _NET_NEIGHBOUR_H
2 #define _NET_NEIGHBOUR_H
5 * Generic neighbour manipulation
8 * Pedro Roque <roque@di.fc.ul.pt>
9 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
12 /* The following flags & states are exported to user space,
13 so that they should be moved to include/linux/ directory.
17 * Neighbor Cache Entry Flags
20 #define NTF_PROXY 0x08 /* == ATF_PUBL */
21 #define NTF_ROUTER 0x80
24 * Neighbor Cache Entry States.
27 #define NUD_INCOMPLETE 0x01
28 #define NUD_REACHABLE 0x02
29 #define NUD_STALE 0x04
30 #define NUD_DELAY 0x08
31 #define NUD_PROBE 0x10
32 #define NUD_FAILED 0x20
35 #define NUD_NOARP 0x40
36 #define NUD_PERMANENT 0x80
39 /* NUD_NOARP & NUD_PERMANENT are pseudostates, they never change
40 and make no address resolution or NUD.
41 NUD_PERMANENT is also cannot be deleted by garbage collectors.
46 #include <asm/atomic.h>
47 #include <linux/skbuff.h>
49 #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE)
50 #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
51 #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
55 struct neigh_parms
*next
;
56 int (*neigh_setup
)(struct neighbour
*);
57 struct neigh_table
*tbl
;
63 int base_reachable_time
;
79 struct neigh_statistics
82 unsigned long res_failed
;
83 unsigned long rcv_probes_mcast
;
84 unsigned long rcv_probes_ucast
;
89 struct neighbour
*next
;
90 struct neigh_table
*tbl
;
91 struct neigh_parms
*parms
;
92 struct net_device
*dev
;
94 unsigned long confirmed
;
95 unsigned long updated
;
102 unsigned char ha
[(MAX_ADDR_LEN
+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)];
105 int (*output
)(struct sk_buff
*skb
);
106 struct sk_buff_head arp_queue
;
107 struct timer_list timer
;
108 struct neigh_ops
*ops
;
115 void (*destructor
)(struct neighbour
*);
116 void (*solicit
)(struct neighbour
*, struct sk_buff
*);
117 void (*error_report
)(struct neighbour
*, struct sk_buff
*);
118 int (*output
)(struct sk_buff
*);
119 int (*connected_output
)(struct sk_buff
*);
120 int (*hh_output
)(struct sk_buff
*);
121 int (*queue_xmit
)(struct sk_buff
*);
126 struct pneigh_entry
*next
;
127 struct net_device
*dev
;
131 #define NEIGH_HASHMASK 0x1F
132 #define PNEIGH_HASHMASK 0xF
135 * neighbour table manipulation
141 struct neigh_table
*next
;
145 __u32 (*hash
)(const void *pkey
, const struct net_device
*);
146 int (*constructor
)(struct neighbour
*);
147 int (*pconstructor
)(struct pneigh_entry
*);
148 void (*pdestructor
)(struct pneigh_entry
*);
149 void (*proxy_redo
)(struct sk_buff
*skb
);
151 struct neigh_parms parms
;
152 /* HACK. gc_* shoul follow parms without a gap! */
157 unsigned long last_flush
;
158 struct timer_list gc_timer
;
159 struct timer_list proxy_timer
;
160 struct sk_buff_head proxy_queue
;
163 unsigned long last_rand
;
164 struct neigh_parms
*parms_list
;
165 kmem_cache_t
*kmem_cachep
;
166 struct neigh_statistics stats
;
167 struct neighbour
*hash_buckets
[NEIGH_HASHMASK
+1];
168 struct pneigh_entry
*phash_buckets
[PNEIGH_HASHMASK
+1];
171 extern void neigh_table_init(struct neigh_table
*tbl
);
172 extern int neigh_table_clear(struct neigh_table
*tbl
);
173 extern struct neighbour
* neigh_lookup(struct neigh_table
*tbl
,
175 struct net_device
*dev
);
176 extern struct neighbour
* neigh_create(struct neigh_table
*tbl
,
178 struct net_device
*dev
);
179 extern void neigh_destroy(struct neighbour
*neigh
);
180 extern int __neigh_event_send(struct neighbour
*neigh
, struct sk_buff
*skb
);
181 extern int neigh_update(struct neighbour
*neigh
, const u8
*lladdr
, u8
new, int override
, int arp
);
182 extern int neigh_ifdown(struct neigh_table
*tbl
, struct net_device
*dev
);
183 extern int neigh_resolve_output(struct sk_buff
*skb
);
184 extern int neigh_connected_output(struct sk_buff
*skb
);
185 extern int neigh_compat_output(struct sk_buff
*skb
);
186 extern struct neighbour
*neigh_event_ns(struct neigh_table
*tbl
,
187 u8
*lladdr
, void *saddr
,
188 struct net_device
*dev
);
190 extern struct neigh_parms
*neigh_parms_alloc(struct net_device
*dev
, struct neigh_table
*tbl
);
191 extern void neigh_parms_release(struct neigh_table
*tbl
, struct neigh_parms
*parms
);
192 extern unsigned long neigh_rand_reach_time(unsigned long base
);
194 extern void pneigh_enqueue(struct neigh_table
*tbl
, struct neigh_parms
*p
,
195 struct sk_buff
*skb
);
196 extern struct pneigh_entry
*pneigh_lookup(struct neigh_table
*tbl
, const void *key
, struct net_device
*dev
, int creat
);
197 extern int pneigh_delete(struct neigh_table
*tbl
, const void *key
, struct net_device
*dev
);
199 struct netlink_callback
;
201 extern int neigh_dump_info(struct sk_buff
*skb
, struct netlink_callback
*cb
);
202 extern int neigh_add(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
);
203 extern int neigh_delete(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
);
204 extern void neigh_app_ns(struct neighbour
*n
);
206 extern int neigh_sysctl_register(struct net_device
*dev
, struct neigh_parms
*p
,
207 int p_id
, int pdev_id
, char *p_name
);
208 extern void neigh_sysctl_unregister(struct neigh_parms
*p
);
211 * Neighbour references
214 extern __inline__
void neigh_release(struct neighbour
*neigh
)
216 if (atomic_dec_and_test(&neigh
->refcnt
))
217 neigh_destroy(neigh
);
220 extern __inline__
struct neighbour
* neigh_clone(struct neighbour
*neigh
)
223 atomic_inc(&neigh
->refcnt
);
227 #define neigh_hold(n) atomic_inc(&(n)->refcnt)
229 extern __inline__
void neigh_confirm(struct neighbour
*neigh
)
232 neigh
->confirmed
= jiffies
;
235 extern __inline__
int neigh_is_connected(struct neighbour
*neigh
)
237 return neigh
->nud_state
&NUD_CONNECTED
;
240 extern __inline__
int neigh_is_valid(struct neighbour
*neigh
)
242 return neigh
->nud_state
&NUD_VALID
;
245 extern __inline__
int neigh_event_send(struct neighbour
*neigh
, struct sk_buff
*skb
)
247 neigh
->used
= jiffies
;
248 if (!(neigh
->nud_state
&(NUD_CONNECTED
|NUD_DELAY
|NUD_PROBE
)))
249 return __neigh_event_send(neigh
, skb
);
253 extern __inline__
struct neighbour
*
254 __neigh_lookup(struct neigh_table
*tbl
, const void *pkey
, struct net_device
*dev
, int creat
)
256 struct neighbour
*n
= neigh_lookup(tbl
, pkey
, dev
);
261 return neigh_create(tbl
, pkey
, dev
);