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 12/* The following flags & states are exported to user space, 13 so that they should be moved to include/linux/ directory. 14 */ 15 16/* 17 * Neighbor Cache Entry Flags 18 */ 19 20#define NTF_PROXY 0x08 /* == ATF_PUBL */ 21#define NTF_ROUTER 0x80 22 23/* 24 * Neighbor Cache Entry States. 25 */ 26 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 33 34/* Dummy states */ 35#define NUD_NOARP 0x40 36#define NUD_PERMANENT 0x80 37#define NUD_NONE 0x00 38 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. 42 */ 43 44#ifdef __KERNEL__ 45 46#include <asm/atomic.h> 47#include <linux/skbuff.h> 48 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) 52 53struct neigh_parms 54{ 55 struct neigh_parms *next; 56 int (*neigh_setup)(struct neighbour *); 57 struct neigh_table *tbl; 58 int entries; 59 void *priv; 60 61 void *sysctl_table; 62 63 int base_reachable_time; 64 int retrans_time; 65 int gc_staletime; 66 int reachable_time; 67 int delay_probe_time; 68 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; 77}; 78 79struct neigh_statistics 80{ 81 unsigned long allocs; 82 unsigned long res_failed; 83 unsigned long rcv_probes_mcast; 84 unsigned long rcv_probes_ucast; 85}; 86 87struct neighbour 88{ 89 struct neighbour *next; 90 struct neigh_table *tbl; 91 struct neigh_parms *parms; 92 struct net_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 dead; 100 atomic_t probes; 101 rwlock_t lock; 102 unsigned char ha[(MAX_ADDR_LEN+sizeof(unsigned long)-1)&~(sizeof(unsigned long)-1)]; 103 struct hh_cache *hh; 104 atomic_t refcnt; 105 int (*output)(struct sk_buff *skb); 106 struct sk_buff_head arp_queue; 107 struct timer_list timer; 108 struct neigh_ops *ops; 109 u8 primary_key[0]; 110}; 111 112struct neigh_ops 113{ 114 int family; 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*); 122}; 123 124struct pneigh_entry 125{ 126 struct pneigh_entry *next; 127 struct net_device *dev; 128 u8 key[0]; 129}; 130 131#define NEIGH_HASHMASK 0x1F 132#define PNEIGH_HASHMASK 0xF 133 134/* 135 * neighbour table manipulation 136 */ 137 138 139struct neigh_table 140{ 141 struct neigh_table *next; 142 int family; 143 int entry_size; 144 int key_len; 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); 150 char *id; 151 struct neigh_parms parms; 152 /* HACK. gc_* shoul follow parms without a gap! */ 153 int gc_interval; 154 int gc_thresh1; 155 int gc_thresh2; 156 int gc_thresh3; 157 unsigned long last_flush; 158 struct timer_list gc_timer; 159 struct timer_list proxy_timer; 160 struct sk_buff_head proxy_queue; 161 int entries; 162 rwlock_t lock; 163 unsigned long last_rand; 164 struct neigh_parms *parms_list; 165 kmem_cache_t *kmem_cachep; 166 struct tasklet_struct gc_task; 167 struct neigh_statistics stats; 168 struct neighbour *hash_buckets[NEIGH_HASHMASK+1]; 169 struct pneigh_entry *phash_buckets[PNEIGH_HASHMASK+1]; 170}; 171 172extern void neigh_table_init(struct neigh_table *tbl); 173extern int neigh_table_clear(struct neigh_table *tbl); 174extern struct neighbour * neigh_lookup(struct neigh_table *tbl, 175 const void *pkey, 176 struct net_device *dev); 177extern struct neighbour * neigh_create(struct neigh_table *tbl, 178 const void *pkey, 179 struct net_device *dev); 180extern void neigh_destroy(struct neighbour *neigh); 181extern int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb); 182extern int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, int override, int arp); 183extern int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev); 184extern int neigh_resolve_output(struct sk_buff *skb); 185extern int neigh_connected_output(struct sk_buff *skb); 186extern int neigh_compat_output(struct sk_buff *skb); 187extern struct neighbour *neigh_event_ns(struct neigh_table *tbl, 188 u8 *lladdr, void *saddr, 189 struct net_device *dev); 190 191extern struct neigh_parms *neigh_parms_alloc(struct net_device *dev, struct neigh_table *tbl); 192extern void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms); 193extern unsigned long neigh_rand_reach_time(unsigned long base); 194 195extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, 196 struct sk_buff *skb); 197extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev, int creat); 198extern int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev); 199 200struct netlink_callback; 201struct nlmsghdr; 202extern int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb); 203extern int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); 204extern int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); 205extern void neigh_app_ns(struct neighbour *n); 206 207extern int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, 208 int p_id, int pdev_id, char *p_name); 209extern void neigh_sysctl_unregister(struct neigh_parms *p); 210 211/* 212 * Neighbour references 213 */ 214 215static inline void neigh_release(struct neighbour *neigh) 216{ 217 if (atomic_dec_and_test(&neigh->refcnt)) 218 neigh_destroy(neigh); 219} 220 221static inline struct neighbour * neigh_clone(struct neighbour *neigh) 222{ 223 if (neigh) 224 atomic_inc(&neigh->refcnt); 225 return neigh; 226} 227 228#define neigh_hold(n) atomic_inc(&(n)->refcnt) 229 230static inline void neigh_confirm(struct neighbour *neigh) 231{ 232 if (neigh) 233 neigh->confirmed = jiffies; 234} 235 236static inline int neigh_is_connected(struct neighbour *neigh) 237{ 238 return neigh->nud_state&NUD_CONNECTED; 239} 240 241static inline int neigh_is_valid(struct neighbour *neigh) 242{ 243 return neigh->nud_state&NUD_VALID; 244} 245 246static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb) 247{ 248 neigh->used = jiffies; 249 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE))) 250 return __neigh_event_send(neigh, skb); 251 return 0; 252} 253 254static inline struct neighbour * 255__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat) 256{ 257 struct neighbour *n = neigh_lookup(tbl, pkey, dev); 258 259 if (n || !creat) 260 return n; 261 262 n = neigh_create(tbl, pkey, dev); 263 return IS_ERR(n) ? NULL : n; 264} 265 266static inline struct neighbour * 267__neigh_lookup_errno(struct neigh_table *tbl, const void *pkey, 268 struct net_device *dev) 269{ 270 struct neighbour *n = neigh_lookup(tbl, pkey, dev); 271 272 if (n) 273 return n; 274 275 return neigh_create(tbl, pkey, dev); 276} 277 278#endif 279#endif 280 281 282