Import 2.1.89
[davej-history.git] / include / net / neighbour.h
blob76dd6f4fd94330a119320c071b0ee1978cc9fb52
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>
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
34 /* Dummy states */
35 #define NUD_NOARP 0x40
36 #define NUD_PERMANENT 0x80
37 #define NUD_NONE 0x00
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.
44 #ifdef __KERNEL__
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)
53 struct neigh_parms
55 struct neigh_parms *next;
56 int(*neigh_setup)(struct neighbour *);
57 struct neigh_table *tbl;
58 int entries;
59 void*priv;
61 void*sysctl_table;
63 int base_reachable_time;
64 int retrans_time;
65 int gc_staletime;
66 int reachable_time;
67 int delay_probe_time;
69 int queue_len;
70 int ucast_probes;
71 int app_probes;
72 int mcast_probes;
73 int anycast_delay;
74 int proxy_delay;
75 int proxy_qlen;
76 int locktime;
79 struct neigh_statistics
81 unsigned long allocs;
82 unsigned long res_failed;
83 unsigned long rcv_probes_mcast;
84 unsigned long rcv_probes_ucast;
87 struct neighbour
89 struct neighbour *next;
90 struct neigh_table *tbl;
91 struct neigh_parms *parms;
92 struct device *dev;
93 unsigned long used;
94 unsigned long confirmed;
95 unsigned long updated;
96 __u8 flags;
97 __u8 nud_state;
98 __u8 type;
99 __u8 probes;
100 unsigned char ha[MAX_ADDR_LEN];
101 struct hh_cache *hh;
102 atomic_t refcnt;
103 int(*output)(struct sk_buff *skb);
104 struct sk_buff_head arp_queue;
105 struct timer_list timer;
106 struct neigh_ops *ops;
107 u8 primary_key[0];
110 struct neigh_ops
112 int family;
113 void(*destructor)(struct neighbour *);
114 void(*solicit)(struct neighbour *,struct sk_buff*);
115 void(*error_report)(struct neighbour *,struct sk_buff*);
116 int(*output)(struct sk_buff*);
117 int(*connected_output)(struct sk_buff*);
118 int(*hh_output)(struct sk_buff*);
119 int(*queue_xmit)(struct sk_buff*);
122 struct pneigh_entry
124 struct pneigh_entry *next;
125 struct device *dev;
126 u8 key[0];
129 #define NEIGH_HASHMASK 0x1F
130 #define PNEIGH_HASHMASK 0xF
133 * neighbour table manipulation
137 struct neigh_table
139 struct neigh_table *next;
140 int family;
141 int entry_size;
142 int key_len;
143 int(*constructor)(struct neighbour *);
144 int(*pconstructor)(struct pneigh_entry *);
145 void(*pdestructor)(struct pneigh_entry *);
146 void(*proxy_redo)(struct sk_buff *skb);
147 struct neigh_parms parms;
148 /* HACK. gc_* shoul follow parms without a gap! */
149 int gc_interval;
150 int gc_thresh1;
151 int gc_thresh2;
152 int gc_thresh3;
153 unsigned long last_flush;
154 struct timer_list gc_timer;
155 struct timer_list proxy_timer;
156 struct sk_buff_head proxy_queue;
157 int entries;
158 atomic_t lock;
159 unsigned long last_rand;
160 struct neigh_parms *parms_list;
161 struct neigh_statistics stats;
162 struct neighbour *hash_buckets[NEIGH_HASHMASK+1];
163 struct pneigh_entry *phash_buckets[PNEIGH_HASHMASK+1];
166 externvoidneigh_table_init(struct neigh_table *tbl);
167 externintneigh_table_clear(struct neigh_table *tbl);
168 externstruct neighbour *__neigh_lookup(struct neigh_table *tbl,
169 const void*pkey,struct device *dev,
170 int creat);
171 externvoidneigh_destroy(struct neighbour *neigh);
172 externint__neigh_event_send(struct neighbour *neigh,struct sk_buff *skb);
173 externintneigh_update(struct neighbour *neigh, u8 *lladdr, u8 new,int override,int arp);
174 externintneigh_ifdown(struct neigh_table *tbl,struct device *dev);
175 externintneigh_resolve_output(struct sk_buff *skb);
176 externintneigh_connected_output(struct sk_buff *skb);
177 externintneigh_compat_output(struct sk_buff *skb);
178 externstruct neighbour *neigh_event_ns(struct neigh_table *tbl,
179 u8 *lladdr,void*saddr,
180 struct device *dev);
182 externstruct neigh_parms *neigh_parms_alloc(struct device *dev,struct neigh_table *tbl);
183 externvoidneigh_parms_release(struct neigh_table *tbl,struct neigh_parms *parms);
184 externunsigned longneigh_rand_reach_time(unsigned long base);
186 externvoidpneigh_enqueue(struct neigh_table *tbl,struct neigh_parms *p,
187 struct sk_buff *skb);
188 externstruct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,const void*key,struct device *dev,int creat);
189 externintpneigh_delete(struct neigh_table *tbl,const void*key,struct device *dev);
191 struct netlink_callback;
192 struct nlmsghdr;
193 externintneigh_dump_info(struct sk_buff *skb,struct netlink_callback *cb);
194 externintneigh_add(struct sk_buff *skb,struct nlmsghdr *nlh,void*arg);
195 externintneigh_delete(struct sk_buff *skb,struct nlmsghdr *nlh,void*arg);
196 externvoidneigh_app_ns(struct neighbour *n);
198 externintneigh_sysctl_register(struct device *dev,struct neigh_parms *p,
199 int p_id,int pdev_id,char*p_name);
200 externvoidneigh_sysctl_unregister(struct neigh_parms *p);
203 * Neighbour references
205 * When neighbour pointers are passed to "client" code the
206 * reference count is increased. The count is 0 if the node
207 * is only referenced by the corresponding table.
210 extern __inline__ voidneigh_release(struct neighbour *neigh)
212 if(atomic_dec_and_test(&neigh->refcnt) && neigh->tbl == NULL)
213 neigh_destroy(neigh);
216 extern __inline__ struct neighbour *neigh_clone(struct neighbour *neigh)
218 if(neigh)
219 atomic_inc(&neigh->refcnt);
220 return neigh;
223 extern __inline__ voidneigh_confirm(struct neighbour *neigh)
225 if(neigh)
226 neigh->confirmed = jiffies;
230 extern __inline__ struct neighbour *
231 neigh_lookup(struct neigh_table *tbl,const void*pkey,struct device *dev)
233 struct neighbour *neigh;
234 start_bh_atomic();
235 neigh =__neigh_lookup(tbl, pkey, dev,0);
236 end_bh_atomic();
237 return neigh;
240 extern __inline__ intneigh_is_connected(struct neighbour *neigh)
242 return neigh->nud_state&NUD_CONNECTED;
245 extern __inline__ intneigh_is_valid(struct neighbour *neigh)
247 return neigh->nud_state&NUD_VALID;
250 extern __inline__ intneigh_event_send(struct neighbour *neigh,struct sk_buff *skb)
252 neigh->used = jiffies;
253 if(!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
254 return__neigh_event_send(neigh, skb);
255 return0;
258 extern __inline__ voidneigh_table_lock(struct neigh_table *tbl)
260 atomic_inc(&tbl->lock);
263 extern __inline__ voidneigh_table_unlock(struct neigh_table *tbl)
265 atomic_dec(&tbl->lock);
269 #endif
270 #endif
close