Main Page | Class List | File List | Class Members | File Members

neighbour.h

Go to the documentation of this file.
00001 #ifndef _NET_NEIGHBOUR_H 00002 #define _NET_NEIGHBOUR_H 00003 00004 /* 00005 * Generic neighbour manipulation 00006 * 00007 * Authors: 00008 * Pedro Roque <roque@di.fc.ul.pt> 00009 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 00010 */ 00011 00012 /* The following flags & states are exported to user space, 00013 so that they should be moved to include/linux/ directory. 00014 */ 00015 00016 /* 00017 * Neighbor Cache Entry Flags 00018 */ 00019 00020 #define NTF_PROXY 0x08 /* == ATF_PUBL */ 00021 #define NTF_ROUTER 0x80 00022 00023 /* 00024 * Neighbor Cache Entry States. 00025 */ 00026 00027 #define NUD_INCOMPLETE 0x01 00028 #define NUD_REACHABLE 0x02 00029 #define NUD_STALE 0x04 00030 #define NUD_DELAY 0x08 00031 #define NUD_PROBE 0x10 00032 #define NUD_FAILED 0x20 00033 00034 /* Dummy states */ 00035 #define NUD_NOARP 0x40 00036 #define NUD_PERMANENT 0x80 00037 #define NUD_NONE 0x00 00038 00039 /* NUD_NOARP & NUD_PERMANENT are pseudostates, they never change 00040 and make no address resolution or NUD. 00041 NUD_PERMANENT is also cannot be deleted by garbage collectors. 00042 */ 00043 00044 #ifdef __KERNEL__ 00045 00046 #include <asm/atomic.h> 00047 #include <linux/skbuff.h> 00048 00049 #define NUD_IN_TIMER (NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE) 00050 #define NUD_VALID (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY) 00051 #define NUD_CONNECTED (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE) 00052 00053 struct neigh_parms 00054 { 00055 struct neigh_parms *next; 00056 int (*neigh_setup)(struct neighbour *); 00057 struct neigh_table *tbl; 00058 int entries; 00059 void *priv; 00060 00061 void *sysctl_table; 00062 00063 int base_reachable_time; 00064 int retrans_time; 00065 int gc_staletime; 00066 int reachable_time; 00067 int delay_probe_time; 00068 00069 int queue_len; 00070 int ucast_probes; 00071 int app_probes; 00072 int mcast_probes; 00073 int anycast_delay; 00074 int proxy_delay; 00075 int proxy_qlen; 00076 int locktime; 00077 }; 00078 00079 struct neigh_statistics 00080 { 00081 unsigned long allocs; 00082 unsigned long res_failed; 00083 unsigned long rcv_probes_mcast; 00084 unsigned long rcv_probes_ucast; 00085 }; 00086 00087 struct neighbour 00088 { 00089 struct neighbour *next; 00090 struct neigh_table *tbl; 00091 struct neigh_parms *parms; 00092 struct net_device *dev; 00093 unsigned long used; 00094 unsigned long confirmed; 00095 unsigned long updated; 00096 __u8 flags; 00097 __u8 nud_state; 00098 __u8 type; 00099 __u8 dead; 00100 atomic_t probes; 00101 rwlock_t lock; 00102 unsigned char ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)]; 00103 struct hh_cache *hh; 00104 atomic_t refcnt; 00105 int (*output)(struct sk_buff *skb); 00106 struct sk_buff_head arp_queue; 00107 struct timer_list timer; 00108 struct neigh_ops *ops; 00109 u8 primary_key[0]; 00110 }; 00111 00112 struct neigh_ops 00113 { 00114 int family; 00115 void (*destructor)(struct neighbour *); 00116 void (*solicit)(struct neighbour *, struct sk_buff*); 00117 void (*error_report)(struct neighbour *, struct sk_buff*); 00118 int (*output)(struct sk_buff*); 00119 int (*connected_output)(struct sk_buff*); 00120 int (*hh_output)(struct sk_buff*); 00121 int (*queue_xmit)(struct sk_buff*); 00122 }; 00123 00124 struct pneigh_entry 00125 { 00126 struct pneigh_entry *next; 00127 struct net_device *dev; 00128 u8 key[0]; 00129 }; 00130 00131 #define NEIGH_HASHMASK 0x1F 00132 #define PNEIGH_HASHMASK 0xF 00133 00134 /* 00135 * neighbour table manipulation 00136 */ 00137 00138 00139 struct neigh_table 00140 { 00141 struct neigh_table *next; 00142 int family; 00143 int entry_size; 00144 int key_len; 00145 __u32 (*hash)(const void *pkey, const struct net_device *); 00146 int (*constructor)(struct neighbour *); 00147 int (*pconstructor)(struct pneigh_entry *); 00148 void (*pdestructor)(struct pneigh_entry *); 00149 void (*proxy_redo)(struct sk_buff *skb); 00150 char *id; 00151 struct neigh_parms parms; 00152 /* HACK. gc_* shoul follow parms without a gap! */ 00153 int gc_interval; 00154 int gc_thresh1; 00155 int gc_thresh2; 00156 int gc_thresh3; 00157 unsigned long last_flush; 00158 struct timer_list gc_timer; 00159 struct timer_list proxy_timer; 00160 struct sk_buff_head proxy_queue; 00161 int entries; 00162 rwlock_t lock; 00163 unsigned long last_rand; 00164 struct neigh_parms *parms_list; 00165 kmem_cache_t *kmem_cachep; 00166 struct tasklet_struct gc_task; 00167 struct neigh_statistics stats; 00168 struct neighbour *hash_buckets[NEIGH_HASHMASK+1]; 00169 struct pneigh_entry *phash_buckets[PNEIGH_HASHMASK+1]; 00170 }; 00171 00172 extern void neigh_table_init(struct neigh_table *tbl); 00173 extern int neigh_table_clear(struct neigh_table *tbl); 00174 extern struct neighbour * neigh_lookup(struct neigh_table *tbl, 00175 const void *pkey, 00176 struct net_device *dev); 00177 extern struct neighbour * neigh_create(struct neigh_table *tbl, 00178 const void *pkey, 00179 struct net_device *dev); 00180 extern void neigh_destroy(struct neighbour *neigh); 00181 extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb); 00182 extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, int override, int arp); 00183 extern void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev); 00184 extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev); 00185 extern int neigh_resolve_output(struct sk_buff *skb); 00186 extern int neigh_connected_output(struct sk_buff *skb); 00187 extern int neigh_compat_output(struct sk_buff *skb); 00188 extern struct neighbour *neigh_event_ns(struct neigh_table *tbl, 00189 u8 *lladdr, void *saddr, 00190 struct net_device *dev); 00191 00192 extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl); 00193 extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms); 00194 extern unsigned long neigh_rand_reach_time(unsigned long base); 00195 00196 extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, 00197 struct sk_buff *skb); 00198 extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat); 00199 extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev); 00200 00201 struct netlink_callback; 00202 struct nlmsghdr; 00203 extern int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb); 00204 extern int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); 00205 extern int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); 00206 extern void neigh_app_ns(struct neighbour *n); 00207 00208 extern int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, 00209 int p_id, int pdev_id, char *p_name); 00210 extern void neigh_sysctl_unregister(struct neigh_parms *p); 00211 00212 /* 00213 * Neighbour references 00214 */ 00215 00216 static inline void neigh_release(struct neighbour *neigh) 00217 { 00218 if (atomic_dec_and_test(&neigh->refcnt)) 00219 neigh_destroy(neigh); 00220 } 00221 00222 static inline struct neighbour * neigh_clone(struct neighbour *neigh) 00223 { 00224 if (neigh) 00225 atomic_inc(&neigh->refcnt); 00226 return neigh; 00227 } 00228 00229 #define neigh_hold(n) atomic_inc(&(n)->refcnt) 00230 00231 static inline void neigh_confirm(struct neighbour *neigh) 00232 { 00233 if (neigh) 00234 neigh->confirmed = jiffies; 00235 } 00236 00237 static inline int neigh_is_connected(struct neighbour *neigh) 00238 { 00239 return neigh->nud_state&NUD_CONNECTED; 00240 } 00241 00242 static inline int neigh_is_valid(struct neighbour *neigh) 00243 { 00244 return neigh->nud_state&NUD_VALID; 00245 } 00246 00247 static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) 00248 { 00249 neigh->used = jiffies; 00250 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE))) 00251 return __neigh_event_send(neigh, skb); 00252 return 0; 00253 } 00254 00255 static inline struct neighbour * 00256 __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat) 00257 { 00258 struct neighbour *n = neigh_lookup(tbl, pkey, dev); 00259 00260 if (n || !creat) 00261 return n; 00262 00263 n = neigh_create(tbl, pkey, dev); 00264 return IS_ERR(n) ? NULL : n; 00265 } 00266 00267 static inline struct neighbour * 00268 __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey, 00269 struct net_device *dev) 00270 { 00271 struct neighbour *n = neigh_lookup(tbl, pkey, dev); 00272 00273 if (n) 00274 return n; 00275 00276 return neigh_create(tbl, pkey, dev); 00277 } 00278 00279 #endif 00280 #endif 00281 00282

Generated on Wed Dec 1 21:25:32 2004 for Linux 2.4.23 Networking by doxygen 1.3.8