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

neighbour.h File Reference

#include <asm/atomic.h>
#include <linux/skbuff.h>

Go to the source code of this file.

Classes

struct  neigh_parms
struct  neigh_statistics
struct  neighbour
struct  neigh_ops
struct  pneigh_entry
struct  neigh_table

Defines

#define NTF_PROXY   0x08
#define NTF_ROUTER   0x80
#define NUD_INCOMPLETE   0x01
#define NUD_REACHABLE   0x02
#define NUD_STALE   0x04
#define NUD_DELAY   0x08
#define NUD_PROBE   0x10
#define NUD_FAILED   0x20
#define NUD_NOARP   0x40
#define NUD_PERMANENT   0x80
#define NUD_NONE   0x00
#define NUD_IN_TIMER   (NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE)
#define NUD_VALID   (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
#define NUD_CONNECTED   (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
#define NEIGH_HASHMASK   0x1F
#define PNEIGH_HASHMASK   0xF
#define neigh_hold(n)   atomic_inc(&(n)->refcnt)

Functions

void neigh_table_init (struct neigh_table *tbl)
int neigh_table_clear (struct neigh_table *tbl)
neighbourneigh_lookup (struct neigh_table *tbl, const void *pkey, struct net_device *dev)
neighbourneigh_create (struct neigh_table *tbl, const void *pkey, struct net_device *dev)
void neigh_destroy (struct neighbour *neigh)
int __neigh_event_send (struct neighbour *neigh, struct sk_buff *skb)
int neigh_update (struct neighbour *neigh, const u8 *lladdr, u8 new, int override, int arp)
void neigh_changeaddr (struct neigh_table *tbl, struct net_device *dev)
int neigh_ifdown (struct neigh_table *tbl, struct net_device *dev)
int neigh_resolve_output (struct sk_buff *skb)
int neigh_connected_output (struct sk_buff *skb)
int neigh_compat_output (struct sk_buff *skb)
neighbourneigh_event_ns (struct neigh_table *tbl, u8 *lladdr, void *saddr, struct net_device *dev)
neigh_parmsneigh_parms_alloc (struct net_device *dev, struct neigh_table *tbl)
void neigh_parms_release (struct neigh_table *tbl, struct neigh_parms *parms)
unsigned long neigh_rand_reach_time (unsigned long base)
void pneigh_enqueue (struct neigh_table *tbl, struct neigh_parms *p, struct sk_buff *skb)
pneigh_entrypneigh_lookup (struct neigh_table *tbl, const void *key, struct net_device *dev, int creat)
int pneigh_delete (struct neigh_table *tbl, const void *key, struct net_device *dev)
int neigh_dump_info (struct sk_buff *skb, struct netlink_callback *cb)
int neigh_add (struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
int neigh_delete (struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
void neigh_app_ns (struct neighbour *n)
int neigh_sysctl_register (struct net_device *dev, struct neigh_parms *p, int p_id, int pdev_id, char *p_name)
void neigh_sysctl_unregister (struct neigh_parms *p)
void neigh_release (struct neighbour *neigh)
neighbourneigh_clone (struct neighbour *neigh)
void neigh_confirm (struct neighbour *neigh)
int neigh_is_connected (struct neighbour *neigh)
int neigh_is_valid (struct neighbour *neigh)
int neigh_event_send (struct neighbour *neigh, struct sk_buff *skb)
neighbour__neigh_lookup (struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
neighbour__neigh_lookup_errno (struct neigh_table *tbl, const void *pkey, struct net_device *dev)


Define Documentation

#define NEIGH_HASHMASK   0x1F
 

Definition at line 131 of file neighbour.h.

Referenced by arp_hash(), neigh_changeaddr(), neigh_dump_table(), neigh_forced_gc(), and neigh_ifdown().

#define neigh_hold  )     atomic_inc(&(n)->refcnt)
 

Definition at line 229 of file neighbour.h.

Referenced by __neigh_event_send(), neigh_create(), and neigh_lookup().

#define NTF_PROXY   0x08
 

Definition at line 20 of file neighbour.h.

Referenced by neigh_add(), and neigh_delete().

#define NTF_ROUTER   0x80
 

Definition at line 21 of file neighbour.h.

#define NUD_CONNECTED   (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
 

Definition at line 51 of file neighbour.h.

Referenced by __neigh_event_send(), neigh_event_send(), neigh_hh_init(), neigh_is_connected(), and neigh_update().

#define NUD_DELAY   0x08
 

Definition at line 30 of file neighbour.h.

Referenced by __neigh_event_send(), neigh_event_send(), and neigh_timer_handler().

#define NUD_FAILED   0x20
 

Definition at line 32 of file neighbour.h.

Referenced by __neigh_event_send(), arp_req_delete(), neigh_delete(), and neigh_timer_handler().

#define NUD_IN_TIMER   (NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE)
 

Definition at line 49 of file neighbour.h.

Referenced by neigh_del_timer(), and neigh_timer_handler().

#define NUD_INCOMPLETE   0x01
 

Definition at line 27 of file neighbour.h.

Referenced by __neigh_event_send(), and neigh_forced_gc().

#define NUD_NOARP   0x40
 

Definition at line 35 of file neighbour.h.

Referenced by arp_constructor(), arp_req_delete(), neigh_ifdown(), neigh_sync(), and neigh_update().

#define NUD_NONE   0x00
 

Definition at line 37 of file neighbour.h.

Referenced by fib_detect_death(), neigh_alloc(), and neigh_ifdown().

#define NUD_PERMANENT   0x80
 

Definition at line 36 of file neighbour.h.

Referenced by arp_req_set(), arp_state_to_flags(), neigh_forced_gc(), neigh_sync(), and neigh_update().

#define NUD_PROBE   0x10
 

Definition at line 31 of file neighbour.h.

Referenced by __neigh_event_send(), neigh_event_send(), and neigh_timer_handler().

#define NUD_REACHABLE   0x02
 

Definition at line 28 of file neighbour.h.

Referenced by arp_process(), fib_detect_death(), neigh_sync(), and neigh_timer_handler().

#define NUD_STALE   0x04
 

Definition at line 29 of file neighbour.h.

Referenced by __neigh_event_send(), arp_process(), arp_req_set(), neigh_event_ns(), neigh_sync(), and neigh_update().

#define NUD_VALID   (NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
 

Definition at line 50 of file neighbour.h.

Referenced by arp_constructor(), arp_find(), arp_solicit(), arp_state_to_flags(), fib_detect_death(), ip_rt_redirect(), neigh_fill_info(), neigh_ifdown(), neigh_is_valid(), neigh_sync(), neigh_timer_handler(), and neigh_update().

#define PNEIGH_HASHMASK   0xF
 

Definition at line 132 of file neighbour.h.

Referenced by pneigh_delete(), pneigh_ifdown(), and pneigh_lookup().


Function Documentation

int __neigh_event_send struct neighbour neigh,
struct sk_buff skb
 

Definition at line 717 of file neighbour.c.

References __skb_queue_tail(), __skb_unlink(), neigh_parms::app_probes, neighbour::arp_queue, neigh_parms::delay_probe_time, kfree_skb(), neighbour::lock, neigh_parms::mcast_probes, neigh_hold, NEIGH_PRINTK2, sk_buff_head::next, NUD_CONNECTED, NUD_DELAY, NUD_FAILED, NUD_INCOMPLETE, NUD_PROBE, NUD_STALE, neighbour::nud_state, neighbour::ops, neighbour::parms, neighbour::probes, neigh_parms::queue_len, neigh_parms::retrans_time, skb_queue_len(), neigh_ops::solicit, neighbour::timer, and neigh_parms::ucast_probes.

Referenced by neigh_event_send().

00718 { 00719 write_lock_bh(&neigh->lock); 00720 if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE))) { 00721 if (!(neigh->nud_state&(NUD_STALE|NUD_INCOMPLETE))) { 00722 if (neigh->parms->mcast_probes + neigh->parms->app_probes) { 00723 atomic_set(&neigh->probes, neigh->parms->ucast_probes); 00724 neigh->nud_state = NUD_INCOMPLETE; 00725 neigh_hold(neigh); 00726 neigh->timer.expires = jiffies + neigh->parms->retrans_time; 00727 add_timer(&neigh->timer); 00728 write_unlock_bh(&neigh->lock); 00729 neigh->ops->solicit(neigh, skb); 00730 atomic_inc(&neigh->probes); 00731 write_lock_bh(&neigh->lock); 00732 } else { 00733 neigh->nud_state = NUD_FAILED; 00734 write_unlock_bh(&neigh->lock); 00735 00736 if (skb) 00737 kfree_skb(skb); 00738 return 1; 00739 } 00740 } 00741 if (neigh->nud_state == NUD_INCOMPLETE) { 00742 if (skb) { 00743 if (skb_queue_len(&neigh->arp_queue) >= neigh->parms->queue_len) { 00744 struct sk_buff *buff; 00745 buff = neigh->arp_queue.next; 00746 __skb_unlink(buff, &neigh->arp_queue); 00747 kfree_skb(buff); 00748 } 00749 __skb_queue_tail(&neigh->arp_queue, skb); 00750 } 00751 write_unlock_bh(&neigh->lock); 00752 return 1; 00753 } 00754 if (neigh->nud_state == NUD_STALE) { 00755 NEIGH_PRINTK2("neigh %p is delayed.\n", neigh); 00756 neigh_hold(neigh); 00757 neigh->nud_state = NUD_DELAY; 00758 neigh->timer.expires = jiffies + neigh->parms->delay_probe_time; 00759 add_timer(&neigh->timer); 00760 } 00761 } 00762 write_unlock_bh(&neigh->lock); 00763 return 0; 00764 }

struct neighbour* __neigh_lookup struct neigh_table tbl,
const void *  pkey,
struct net_device dev,
int  creat
[inline, static]
 

Definition at line 256 of file neighbour.h.

References neigh_create(), and neigh_lookup().

Referenced by arp_find(), arp_process(), ndisc_get_neigh(), and neigh_event_ns().

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 }

struct neighbour* __neigh_lookup_errno struct neigh_table tbl,
const void *  pkey,
struct net_device dev
[inline, static]
 

Definition at line 268 of file neighbour.h.

References neigh_create(), and neigh_lookup().

Referenced by arp_bind_neighbour(), arp_req_set(), and neigh_add().

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 }

int neigh_add struct sk_buff skb,
struct nlmsghdr nlh,
void *  arg
 

Definition at line 1245 of file neighbour.c.

References __neigh_lookup_errno(), dev_get_by_index(), dev_put(), neigh_lookup(), neigh_release(), neigh_tables, neigh_tbl_lock, neigh_update(), neigh_table::next, NLM_F_CREATE, NLM_F_EXCL, NLM_F_REPLACE, NLMSG_DATA, nlmsghdr::nlmsg_flags, NTF_PROXY, and pneigh_lookup().

01246 { 01247 struct ndmsg *ndm = NLMSG_DATA(nlh); 01248 struct rtattr **nda = arg; 01249 struct neigh_table *tbl; 01250 struct net_device *dev = NULL; 01251 01252 if (ndm->ndm_ifindex) { 01253 if ((dev = dev_get_by_index(ndm->ndm_ifindex)) == NULL) 01254 return -ENODEV; 01255 } 01256 01257 read_lock(&neigh_tbl_lock); 01258 for (tbl=neigh_tables; tbl; tbl = tbl->next) { 01259 int err = 0; 01260 int override = 1; 01261 struct neighbour *n; 01262 01263 if (tbl->family != ndm->ndm_family) 01264 continue; 01265 read_unlock(&neigh_tbl_lock); 01266 01267 err = -EINVAL; 01268 if (nda[NDA_DST-1] == NULL || 01269 nda[NDA_DST-1]->rta_len != RTA_LENGTH(tbl->key_len)) 01270 goto out; 01271 if (ndm->ndm_flags&NTF_PROXY) { 01272 err = -ENOBUFS; 01273 if (pneigh_lookup(tbl, RTA_DATA(nda[NDA_DST-1]), dev, 1)) 01274 err = 0; 01275 goto out; 01276 } 01277 if (dev == NULL) 01278 return -EINVAL; 01279 err = -EINVAL; 01280 if (nda[NDA_LLADDR-1] != NULL && 01281 nda[NDA_LLADDR-1]->rta_len != RTA_LENGTH(dev->addr_len)) 01282 goto out; 01283 err = 0; 01284 n = neigh_lookup(tbl, RTA_DATA(nda[NDA_DST-1]), dev); 01285 if (n) { 01286 if (nlh->nlmsg_flags&NLM_F_EXCL) 01287 err = -EEXIST; 01288 override = nlh->nlmsg_flags&NLM_F_REPLACE; 01289 } else if (!(nlh->nlmsg_flags&NLM_F_CREATE)) 01290 err = -ENOENT; 01291 else { 01292 n = __neigh_lookup_errno(tbl, RTA_DATA(nda[NDA_DST-1]), dev); 01293 if (IS_ERR(n)) { 01294 err = PTR_ERR(n); 01295 n = NULL; 01296 } 01297 } 01298 if (err == 0) { 01299 err = neigh_update(n, nda[NDA_LLADDR-1] ? RTA_DATA(nda[NDA_LLADDR-1]) : NULL, 01300 ndm->ndm_state, 01301 override, 0); 01302 } 01303 if (n) 01304 neigh_release(n); 01305 out: 01306 if (dev) 01307 dev_put(dev); 01308 return err; 01309 } 01310 read_unlock(&neigh_tbl_lock); 01311 01312 if (dev) 01313 dev_put(dev); 01314 return -EADDRNOTAVAIL; 01315 }

void neigh_app_ns struct neighbour n  ) 
 

Referenced by arp_solicit().

void neigh_changeaddr struct neigh_table tbl,
struct net_device dev
 

Definition at line 173 of file neighbour.c.

References neigh_table::hash_buckets, neigh_table::lock, neigh_del_timer(), NEIGH_HASHMASK, neigh_release(), and neighbour::next.

00174 { 00175 int i; 00176 00177 write_lock_bh(&tbl->lock); 00178 00179 for (i=0; i <= NEIGH_HASHMASK; i++) { 00180 struct neighbour *n, **np; 00181 00182 np = &tbl->hash_buckets[i]; 00183 while ((n = *np) != NULL) { 00184 if (dev && n->dev != dev) { 00185 np = &n->next; 00186 continue; 00187 } 00188 *np = n->next; 00189 write_lock_bh(&n->lock); 00190 n->dead = 1; 00191 neigh_del_timer(n); 00192 write_unlock_bh(&n->lock); 00193 neigh_release(n); 00194 } 00195 } 00196 00197 write_unlock_bh(&tbl->lock); 00198 }

struct neighbour* neigh_clone struct neighbour neigh  )  [inline, static]
 

Definition at line 222 of file neighbour.h.

References neighbour::refcnt.

00223 { 00224 if (neigh) 00225 atomic_inc(&neigh->refcnt); 00226 return neigh; 00227 }

int neigh_compat_output struct sk_buff skb  ) 
 

Definition at line 951 of file neighbour.c.

References __skb_pull(), sk_buff::data, sk_buff::dev, dev_queue_xmit(), sk_buff::len, sk_buff::nh, and sk_buff::protocol.

00952 { 00953 struct net_device *dev = skb->dev; 00954 00955 __skb_pull(skb, skb->nh.raw - skb->data); 00956 00957 if (dev->hard_header && 00958 dev->hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, skb->len) < 0 && 00959 dev->rebuild_header(skb)) 00960 return 0; 00961 00962 return dev_queue_xmit(skb); 00963 }

void neigh_confirm struct neighbour neigh  )  [inline, static]
 

Definition at line 231 of file neighbour.h.

References neighbour::confirmed.

Referenced by dst_confirm().

00232 { 00233 if (neigh) 00234 neigh->confirmed = jiffies; 00235 }

int neigh_connected_output struct sk_buff skb  ) 
 

Definition at line 1006 of file neighbour.c.

References __skb_pull(), sk_buff::data, neighbour::dev, sk_buff::dst, kfree_skb(), sk_buff::len, dst_entry::neighbour, sk_buff::nh, and sk_buff::protocol.

01007 { 01008 int err; 01009 struct dst_entry *dst = skb->dst; 01010 struct neighbour *neigh = dst->neighbour; 01011 struct net_device *dev = neigh->dev; 01012 01013 __skb_pull(skb, skb->nh.raw - skb->data); 01014 01015 read_lock_bh(&neigh->lock); 01016 err = dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, NULL, skb->len); 01017 read_unlock_bh(&neigh->lock); 01018 if (err >= 0) 01019 return neigh->ops->queue_xmit(skb); 01020 kfree_skb(skb); 01021 return -EINVAL; 01022 }

struct neighbour* neigh_create struct neigh_table tbl,
const void *  pkey,
struct net_device dev
 

Definition at line 310 of file neighbour.c.

References neigh_table::constructor, neighbour::dead, dev_hold, error, neigh_table::hash, neigh_table::hash_buckets, neigh_table::key_len, neigh_table::lock, neigh_alloc(), neigh_hold, NEIGH_PRINTK2, neigh_release(), and neighbour::next.

Referenced by __neigh_lookup(), and __neigh_lookup_errno().

00312 { 00313 struct neighbour *n, *n1; 00314 u32 hash_val; 00315 int key_len = tbl->key_len; 00316 int error; 00317 00318 n = neigh_alloc(tbl); 00319 if (n == NULL) 00320 return ERR_PTR(-ENOBUFS); 00321 00322 memcpy(n->primary_key, pkey, key_len); 00323 n->dev = dev; 00324 dev_hold(dev); 00325 00326 /* Protocol specific setup. */ 00327 if (tbl->constructor && (error = tbl->constructor(n)) < 0) { 00328 neigh_release(n); 00329 return ERR_PTR(error); 00330 } 00331 00332 /* Device specific setup. */ 00333 if (n->parms->neigh_setup && 00334 (error = n->parms->neigh_setup(n)) < 0) { 00335 neigh_release(n); 00336 return ERR_PTR(error); 00337 } 00338 00339 n->confirmed = jiffies - (n->parms->base_reachable_time<<1); 00340 00341 hash_val = tbl->hash(pkey, dev); 00342 00343 write_lock_bh(&tbl->lock); 00344 for (n1 = tbl->hash_buckets[hash_val]; n1; n1 = n1->next) { 00345 if (dev == n1->dev && 00346 memcmp(n1->primary_key, pkey, key_len) == 0) { 00347 neigh_hold(n1); 00348 write_unlock_bh(&tbl->lock); 00349 neigh_release(n); 00350 return n1; 00351 } 00352 } 00353 00354 n->next = tbl->hash_buckets[hash_val]; 00355 tbl->hash_buckets[hash_val] = n; 00356 n->dead = 0; 00357 neigh_hold(n); 00358 write_unlock_bh(&tbl->lock); 00359 NEIGH_PRINTK2("neigh %p is created.\n", n); 00360 return n; 00361 }

int neigh_delete struct sk_buff skb,
struct nlmsghdr nlh,
void *  arg
 

Definition at line 1193 of file neighbour.c.

References dev_get_by_index(), dev_put(), neigh_lookup(), neigh_release(), neigh_tables, neigh_tbl_lock, neigh_update(), neigh_table::next, NLMSG_DATA, NTF_PROXY, NUD_FAILED, and pneigh_delete().

01194 { 01195 struct ndmsg *ndm = NLMSG_DATA(nlh); 01196 struct rtattr **nda = arg; 01197 struct neigh_table *tbl; 01198 struct net_device *dev = NULL; 01199 int err = 0; 01200 01201 if (ndm->ndm_ifindex) { 01202 if ((dev = dev_get_by_index(ndm->ndm_ifindex)) == NULL) 01203 return -ENODEV; 01204 } 01205 01206 read_lock(&neigh_tbl_lock); 01207 for (tbl=neigh_tables; tbl; tbl = tbl->next) { 01208 struct neighbour *n; 01209 01210 if (tbl->family != ndm->ndm_family) 01211 continue; 01212 read_unlock(&neigh_tbl_lock); 01213 01214 err = -EINVAL; 01215 if (nda[NDA_DST-1] == NULL || 01216 nda[NDA_DST-1]->rta_len != RTA_LENGTH(tbl->key_len)) 01217 goto out; 01218 01219 if (ndm->ndm_flags&NTF_PROXY) { 01220 err = pneigh_delete(tbl, RTA_DATA(nda[NDA_DST-1]), dev); 01221 goto out; 01222 } 01223 01224 if (dev == NULL) 01225 return -EINVAL; 01226 01227 n = neigh_lookup(tbl, RTA_DATA(nda[NDA_DST-1]), dev); 01228 if (n) { 01229 err = neigh_update(n, NULL, NUD_FAILED, 1, 0); 01230 neigh_release(n); 01231 } 01232 out: 01233 if (dev) 01234 dev_put(dev); 01235 return err; 01236 } 01237 read_unlock(&neigh_tbl_lock); 01238 01239 if (dev) 01240 dev_put(dev); 01241 01242 return -EADDRNOTAVAIL; 01243 }

void neigh_destroy struct neighbour neigh  ) 
 

Definition at line 461 of file neighbour.c.

References neighbour::arp_queue, neighbour::dead, neigh_ops::destructor, neighbour::dev, dev_put(), neigh_table::entries, neighbour::hh, hh_cache::hh_next, neigh_table::kmem_cachep, neigh_blackhole(), neigh_del_timer(), neigh_glbl_allocs, NEIGH_PRINTK2, neighbour::ops, skb_queue_purge(), and neighbour::tbl.

Referenced by neigh_release().

00462 { 00463 struct hh_cache *hh; 00464 00465 if (!neigh->dead) { 00466 printk("Destroying alive neighbour %p\n", neigh); 00467 dump_stack(); 00468 return; 00469 } 00470 00471 if (neigh_del_timer(neigh)) 00472 printk("Impossible event.\n"); 00473 00474 while ((hh = neigh->hh) != NULL) { 00475 neigh->hh = hh->hh_next; 00476 hh->hh_next = NULL; 00477 write_lock_bh(&hh->hh_lock); 00478 hh->hh_output = neigh_blackhole; 00479 write_unlock_bh(&hh->hh_lock); 00480 if (atomic_dec_and_test(&hh->hh_refcnt)) 00481 kfree(hh); 00482 } 00483 00484 if (neigh->ops && neigh->ops->destructor) 00485 (neigh->ops->destructor)(neigh); 00486 00487 skb_queue_purge(&neigh->arp_queue); 00488 00489 dev_put(neigh->dev); 00490 00491 NEIGH_PRINTK2("neigh %p is destroyed.\n", neigh); 00492 00493 neigh_glbl_allocs--; 00494 neigh->tbl->entries--; 00495 kmem_cache_free(neigh->tbl->kmem_cachep, neigh); 00496 }

int neigh_dump_info struct sk_buff skb,
struct netlink_callback cb
 

Definition at line 1392 of file neighbour.c.

References netlink_callback::args, sk_buff::len, neigh_dump_table(), neigh_tables, neigh_tbl_lock, neigh_table::next, netlink_callback::nlh, and NLMSG_DATA.

01393 { 01394 int t; 01395 int s_t; 01396 struct neigh_table *tbl; 01397 int family = ((struct rtgenmsg*)NLMSG_DATA(cb->nlh))->rtgen_family; 01398 01399 s_t = cb->args[0]; 01400 01401 read_lock(&neigh_tbl_lock); 01402 for (tbl=neigh_tables, t=0; tbl; tbl = tbl->next, t++) { 01403 if (t < s_t) continue; 01404 if (family && tbl->family != family) 01405 continue; 01406 if (t > s_t) 01407 memset(&cb->args[1], 0, sizeof(cb->args)-sizeof(cb->args[0])); 01408 if (neigh_dump_table(tbl, skb, cb) < 0) 01409 break; 01410 } 01411 read_unlock(&neigh_tbl_lock); 01412 01413 cb->args[0] = t; 01414 01415 return skb->len; 01416 }

struct neighbour* neigh_event_ns struct neigh_table tbl,
u8 *  lladdr,
void *  saddr,
struct net_device dev
 

Definition at line 900 of file neighbour.c.

References __neigh_lookup(), net_device::addr_len, neigh_update(), and NUD_STALE.

Referenced by arp_process().

00903 { 00904 struct neighbour *neigh; 00905 00906 neigh = __neigh_lookup(tbl, saddr, dev, lladdr || !dev->addr_len); 00907 if (neigh) 00908 neigh_update(neigh, lladdr, NUD_STALE, 1, 1); 00909 return neigh; 00910 }

int neigh_event_send struct neighbour neigh,
struct sk_buff skb
[inline, static]
 

Definition at line 247 of file neighbour.h.

References __neigh_event_send(), NUD_CONNECTED, NUD_DELAY, NUD_PROBE, neighbour::nud_state, and neighbour::used.

Referenced by arp_find(), ip_rt_redirect(), and neigh_resolve_output().

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 }

int neigh_ifdown struct neigh_table tbl,
struct net_device dev
 

Definition at line 200 of file neighbour.c.

References neigh_table::hash_buckets, neigh_table::lock, neigh_blackhole(), neigh_del_timer(), NEIGH_HASHMASK, NEIGH_PRINTK2, neigh_release(), neighbour::next, NUD_NOARP, NUD_NONE, NUD_VALID, neigh_table::parms, pneigh_ifdown(), pneigh_queue_purge(), neigh_table::proxy_queue, neigh_table::proxy_timer, and skb_queue_purge().

Referenced by arp_ifdown(), and neigh_table_clear().

00201 { 00202 int i; 00203 00204 write_lock_bh(&tbl->lock); 00205 00206 for (i=0; i<=NEIGH_HASHMASK; i++) { 00207 struct neighbour *n, **np; 00208 00209 np = &tbl->hash_buckets[i]; 00210 while ((n = *np) != NULL) { 00211 if (dev && n->dev != dev) { 00212 np = &n->next; 00213 continue; 00214 } 00215 *np = n->next; 00216 write_lock(&n->lock); 00217 neigh_del_timer(n); 00218 n->dead = 1; 00219 00220 if (atomic_read(&n->refcnt) != 1) { 00221 /* The most unpleasant situation. 00222 We must destroy neighbour entry, 00223 but someone still uses it. 00224 00225 The destroy will be delayed until 00226 the last user releases us, but 00227 we must kill timers etc. and move 00228 it to safe state. 00229 */ 00230 n->parms = &tbl->parms; 00231 skb_queue_purge(&n->arp_queue); 00232 n->output = neigh_blackhole; 00233 if (n->nud_state&NUD_VALID) 00234 n->nud_state = NUD_NOARP; 00235 else 00236 n->nud_state = NUD_NONE; 00237 NEIGH_PRINTK2("neigh %p is stray.\n", n); 00238 } 00239 write_unlock(&n->lock); 00240 neigh_release(n); 00241 } 00242 } 00243 00244 pneigh_ifdown(tbl, dev); 00245 write_unlock_bh(&tbl->lock); 00246 00247 del_timer_sync(&tbl->proxy_timer); 00248 pneigh_queue_purge(&tbl->proxy_queue); 00249 return 0; 00250 }

int neigh_is_connected struct neighbour neigh  )  [inline, static]
 

Definition at line 237 of file neighbour.h.

References NUD_CONNECTED, and neighbour::nud_state.

00238 { 00239 return neigh->nud_state&NUD_CONNECTED; 00240 }

int neigh_is_valid struct neighbour neigh  )  [inline, static]
 

Definition at line 242 of file neighbour.h.

References neighbour::nud_state, and NUD_VALID.

00243 { 00244 return neigh->nud_state&NUD_VALID; 00245 }

struct neighbour* neigh_lookup struct neigh_table tbl,
const void *  pkey,
struct net_device dev
 

Definition at line 289 of file neighbour.c.

References neigh_table::hash, neigh_table::hash_buckets, neigh_table::key_len, neigh_table::lock, neigh_hold, and neighbour::next.

Referenced by __neigh_lookup(), __neigh_lookup_errno(), arp_req_delete(), arp_req_get(), fib_detect_death(), neigh_add(), and neigh_delete().

00291 { 00292 struct neighbour *n; 00293 u32 hash_val; 00294 int key_len = tbl->key_len; 00295 00296 hash_val = tbl->hash(pkey, dev); 00297 00298 read_lock_bh(&tbl->lock); 00299 for (n = tbl->hash_buckets[hash_val]; n; n = n->next) { 00300 if (dev == n->dev && 00301 memcmp(n->primary_key, pkey, key_len) == 0) { 00302 neigh_hold(n); 00303 break; 00304 } 00305 } 00306 read_unlock_bh(&tbl->lock); 00307 return n; 00308 }

struct neigh_parms* neigh_parms_alloc struct net_device dev,
struct neigh_table tbl
 

Definition at line 1086 of file neighbour.c.

References neigh_table::lock, neigh_rand_reach_time(), net_device::neigh_setup, neigh_parms::next, and neigh_table::parms.

Referenced by inetdev_init().

01087 { 01088 struct neigh_parms *p; 01089 p = kmalloc(sizeof(*p), GFP_KERNEL); 01090 if (p) { 01091 memcpy(p, &tbl->parms, sizeof(*p)); 01092 p->tbl = tbl; 01093 p->reachable_time = neigh_rand_reach_time(p->base_reachable_time); 01094 if (dev && dev->neigh_setup) { 01095 if (dev->neigh_setup(dev, p)) { 01096 kfree(p); 01097 return NULL; 01098 } 01099 } 01100 p->sysctl_table = NULL; 01101 write_lock_bh(&tbl->lock); 01102 p->next = tbl->parms.next; 01103 tbl->parms.next = p; 01104 write_unlock_bh(&tbl->lock); 01105 } 01106 return p; 01107 }

void neigh_parms_release struct neigh_table tbl,
struct neigh_parms parms
 

Definition at line 1109 of file neighbour.c.

References neigh_table::lock, NEIGH_PRINTK1, neigh_sysctl_unregister(), neigh_parms::next, and neigh_table::parms.

Referenced by inetdev_destroy().

01110 { 01111 struct neigh_parms **p; 01112 01113 if (parms == NULL || parms == &tbl->parms) 01114 return; 01115 write_lock_bh(&tbl->lock); 01116 for (p = &tbl->parms.next; *p; p = &(*p)->next) { 01117 if (*p == parms) { 01118 *p = parms->next; 01119 write_unlock_bh(&tbl->lock); 01120 #ifdef CONFIG_SYSCTL 01121 neigh_sysctl_unregister(parms); 01122 #endif 01123 kfree(parms); 01124 return; 01125 } 01126 } 01127 write_unlock_bh(&tbl->lock); 01128 NEIGH_PRINTK1("neigh_parms_release: not found\n"); 01129 }

unsigned long neigh_rand_reach_time unsigned long  base  ) 
 

Definition at line 103 of file neighbour.c.

References net_random().

Referenced by neigh_parms_alloc(), and neigh_table_init().

00104 { 00105 return (net_random() % base) + (base>>1); 00106 }

void neigh_release struct neighbour neigh  )  [inline, static]
 

Definition at line 216 of file neighbour.h.

References neigh_destroy(), and neighbour::refcnt.

Referenced by arp_find(), arp_process(), arp_req_delete(), arp_req_get(), arp_req_set(), dst_destroy(), fib_detect_death(), neigh_add(), neigh_changeaddr(), neigh_create(), neigh_del_timer(), neigh_delete(), neigh_forced_gc(), neigh_ifdown(), and neigh_timer_handler().

00217 { 00218 if (atomic_dec_and_test(&neigh->refcnt)) 00219 neigh_destroy(neigh); 00220 }

int neigh_resolve_output struct sk_buff skb  ) 
 

Definition at line 967 of file neighbour.c.

References __skb_pull(), sk_buff::data, sk_buff::dst, kfree_skb(), sk_buff::len, neigh_event_send(), neigh_hh_init(), NEIGH_PRINTK1, sk_buff::nh, and sk_buff::protocol.

00968 { 00969 struct dst_entry *dst = skb->dst; 00970 struct neighbour *neigh; 00971 00972 if (!dst || !(neigh = dst->neighbour)) 00973 goto discard; 00974 00975 __skb_pull(skb, skb->nh.raw - skb->data); 00976 00977 if (neigh_event_send(neigh, skb) == 0) { 00978 int err; 00979 struct net_device *dev = neigh->dev; 00980 if (dev->hard_header_cache && dst->hh == NULL) { 00981 write_lock_bh(&neigh->lock); 00982 if (dst->hh == NULL) 00983 neigh_hh_init(neigh, dst, dst->ops->protocol); 00984 err = dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, NULL, skb->len); 00985 write_unlock_bh(&neigh->lock); 00986 } else { 00987 read_lock_bh(&neigh->lock); 00988 err = dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, NULL, skb->len); 00989 read_unlock_bh(&neigh->lock); 00990 } 00991 if (err >= 0) 00992 return neigh->ops->queue_xmit(skb); 00993 kfree_skb(skb); 00994 return -EINVAL; 00995 } 00996 return 0; 00997 00998 discard: 00999 NEIGH_PRINTK1("neigh_resolve_output: dst=%p neigh=%p\n", dst, dst ? dst->neighbour : NULL); 01000 kfree_skb(skb); 01001 return -EINVAL; 01002 }

int neigh_sysctl_register struct net_device dev,
struct neigh_parms p,
int  p_id,
int  pdev_id,
char *  p_name
 

Referenced by arp_init(), and inetdev_init().

void neigh_sysctl_unregister struct neigh_parms p  ) 
 

Referenced by neigh_parms_release(), and neigh_table_clear().

int neigh_table_clear struct neigh_table tbl  ) 
 

Definition at line 1167 of file neighbour.c.

References neigh_table::entries, neigh_table::gc_task, neigh_table::gc_timer, neigh_ifdown(), neigh_sysctl_unregister(), neigh_tables, neigh_tbl_lock, neigh_table::next, neigh_table::parms, pneigh_queue_purge(), neigh_table::proxy_queue, and neigh_table::proxy_timer.

01168 { 01169 struct neigh_table **tp; 01170 01171 /* It is not clean... Fix it to unload IPv6 module safely */ 01172 del_timer_sync(&tbl->gc_timer); 01173 tasklet_kill(&tbl->gc_task); 01174 del_timer_sync(&tbl->proxy_timer); 01175 pneigh_queue_purge(&tbl->proxy_queue); 01176 neigh_ifdown(tbl, NULL); 01177 if (tbl->entries) 01178 printk(KERN_CRIT "neighbour leakage\n"); 01179 write_lock(&neigh_tbl_lock); 01180 for (tp = &neigh_tables; *tp; tp = &(*tp)->next) { 01181 if (*tp == tbl) { 01182 *tp = tbl->next; 01183 break; 01184 } 01185 } 01186 write_unlock(&neigh_tbl_lock); 01187 #ifdef CONFIG_SYSCTL 01188 neigh_sysctl_unregister(&tbl->parms); 01189 #endif 01190 return 0; 01191 }

void neigh_table_init struct neigh_table tbl  ) 
 

Definition at line 1132 of file neighbour.c.

References neigh_parms::base_reachable_time, neigh_table::entry_size, neigh_table::gc_task, neigh_table::id, neigh_table::kmem_cachep, neigh_periodic_timer, neigh_proxy_process(), neigh_rand_reach_time(), neigh_tables, neigh_tbl_lock, neigh_table::parms, neigh_parms::reachable_time, and skb_queue_head_init().

Referenced by arp_init().

01133 { 01134 unsigned long now = jiffies; 01135 01136 tbl->parms.reachable_time = neigh_rand_reach_time(tbl->parms.base_reachable_time); 01137 01138 if (tbl->kmem_cachep == NULL) 01139 tbl->kmem_cachep = kmem_cache_create(tbl->id, 01140 (tbl->entry_size+15)&~15, 01141 0, SLAB_HWCACHE_ALIGN, 01142 NULL, NULL); 01143 01144 #ifdef CONFIG_SMP 01145 tasklet_init(&tbl->gc_task, SMP_TIMER_NAME(neigh_periodic_timer), (unsigned long)tbl); 01146 #endif 01147 init_timer(&tbl->gc_timer); 01148 tbl->lock = RW_LOCK_UNLOCKED; 01149 tbl->gc_timer.data = (unsigned long)tbl; 01150 tbl->gc_timer.function = neigh_periodic_timer; 01151 tbl->gc_timer.expires = now + tbl->gc_interval + tbl->parms.reachable_time; 01152 add_timer(&tbl->gc_timer); 01153 01154 init_timer(&tbl->proxy_timer); 01155 tbl->proxy_timer.data = (unsigned long)tbl; 01156 tbl->proxy_timer.function = neigh_proxy_process; 01157 skb_queue_head_init(&tbl->proxy_queue); 01158 01159 tbl->last_flush = now; 01160 tbl->last_rand = now + tbl->parms.reachable_time*20; 01161 write_lock(&neigh_tbl_lock); 01162 tbl->next = neigh_tables; 01163 neigh_tables = tbl; 01164 write_unlock(&neigh_tbl_lock); 01165 }

int neigh_update struct neighbour neigh,
const u8 *  lladdr,
u8  new,
int  override,
int  arp
 

Definition at line 792 of file neighbour.c.

References __skb_dequeue(), neigh_parms::app_probes, neighbour::arp_queue, neigh_parms::base_reachable_time, neighbour::confirmed, neighbour::dev, neighbour::ha, neighbour::lock, neigh_connect(), neigh_del_timer(), neigh_suspect(), neigh_sync(), neigh_update_hhs(), NUD_CONNECTED, NUD_NOARP, NUD_PERMANENT, NUD_STALE, neighbour::nud_state, NUD_VALID, neighbour::parms, skb_queue_purge(), and neighbour::updated.

Referenced by arp_process(), arp_req_delete(), arp_req_set(), neigh_add(), neigh_delete(), and neigh_event_ns().

00793 { 00794 u8 old; 00795 int err; 00796 int notify = 0; 00797 struct net_device *dev = neigh->dev; 00798 00799 write_lock_bh(&neigh->lock); 00800 old = neigh->nud_state; 00801 00802 err = -EPERM; 00803 if (arp && (old&(NUD_NOARP|NUD_PERMANENT))) 00804 goto out; 00805 00806 if (!(new&NUD_VALID)) { 00807 neigh_del_timer(neigh); 00808 if (old&NUD_CONNECTED) 00809 neigh_suspect(neigh); 00810 neigh->nud_state = new; 00811 err = 0; 00812 notify = old&NUD_VALID; 00813 goto out; 00814 } 00815 00816 /* Compare new lladdr with cached one */ 00817 if (dev->addr_len == 0) { 00818 /* First case: device needs no address. */ 00819 lladdr = neigh->ha; 00820 } else if (lladdr) { 00821 /* The second case: if something is already cached 00822 and a new address is proposed: 00823 - compare new & old 00824 - if they are different, check override flag 00825 */ 00826 if (old&NUD_VALID) { 00827 if (memcmp(lladdr, neigh->ha, dev->addr_len) == 0) 00828 lladdr = neigh->ha; 00829 else if (!override) 00830 goto out; 00831 } 00832 } else { 00833 /* No address is supplied; if we know something, 00834 use it, otherwise discard the request. 00835 */ 00836 err = -EINVAL; 00837 if (!(old&NUD_VALID)) 00838 goto out; 00839 lladdr = neigh->ha; 00840 } 00841 00842 neigh_sync(neigh); 00843 old = neigh->nud_state; 00844 if (new&NUD_CONNECTED) 00845 neigh->confirmed = jiffies; 00846 neigh->updated = jiffies; 00847 00848 /* If entry was valid and address is not changed, 00849 do not change entry state, if new one is STALE. 00850 */ 00851 err = 0; 00852 if (old&NUD_VALID) { 00853 if (lladdr == neigh->ha) 00854 if (new == old || (new == NUD_STALE && (old&NUD_CONNECTED))) 00855 goto out; 00856 } 00857 neigh_del_timer(neigh); 00858 neigh->nud_state = new; 00859 if (lladdr != neigh->ha) { 00860 memcpy(&neigh->ha, lladdr, dev->addr_len); 00861 neigh_update_hhs(neigh); 00862 if (!(new&NUD_CONNECTED)) 00863 neigh->confirmed = jiffies - (neigh->parms->base_reachable_time<<1); 00864 #ifdef CONFIG_ARPD 00865 notify = 1; 00866 #endif 00867 } 00868 if (new == old) 00869 goto out; 00870 if (new&NUD_CONNECTED) 00871 neigh_connect(neigh); 00872 else 00873 neigh_suspect(neigh); 00874 if (!(old&NUD_VALID)) { 00875 struct sk_buff *skb; 00876 00877 /* Again: avoid dead loop if something went wrong */ 00878 00879 while (neigh->nud_state&NUD_VALID && 00880 (skb=__skb_dequeue(&neigh->arp_queue)) != NULL) { 00881 struct neighbour *n1 = neigh; 00882 write_unlock_bh(&neigh->lock); 00883 /* On shaper/eql skb->dst->neighbour != neigh :( */ 00884 if (skb->dst && skb->dst->neighbour) 00885 n1 = skb->dst->neighbour; 00886 n1->output(skb); 00887 write_lock_bh(&neigh->lock); 00888 } 00889 skb_queue_purge(&neigh->arp_queue); 00890 } 00891 out: 00892 write_unlock_bh(&neigh->lock); 00893 #ifdef CONFIG_ARPD 00894 if (notify && neigh->parms->app_probes) 00895 neigh_app_notify(neigh); 00896 #endif 00897 return err; 00898 }

int pneigh_delete struct neigh_table tbl,
const void *  key,
struct net_device dev
 

Definition at line 409 of file neighbour.c.

References neigh_table::key_len, neigh_table::lock, pneigh_entry::next, neigh_table::pdestructor, neigh_table::phash_buckets, and PNEIGH_HASHMASK.

Referenced by arp_req_delete(), and neigh_delete().

00410 { 00411 struct pneigh_entry *n, **np; 00412 u32 hash_val; 00413 int key_len = tbl->key_len; 00414 00415 hash_val = *(u32*)(pkey + key_len - 4); 00416 hash_val ^= (hash_val>>16); 00417 hash_val ^= hash_val>>8; 00418 hash_val ^= hash_val>>4; 00419 hash_val &= PNEIGH_HASHMASK; 00420 00421 for (np = &tbl->phash_buckets[hash_val]; (n=*np) != NULL; np = &n->next) { 00422 if (memcmp(n->key, pkey, key_len) == 0 && n->dev == dev) { 00423 write_lock_bh(&tbl->lock); 00424 *np = n->next; 00425 write_unlock_bh(&tbl->lock); 00426 if (tbl->pdestructor) 00427 tbl->pdestructor(n); 00428 kfree(n); 00429 return 0; 00430 } 00431 } 00432 return -ENOENT; 00433 }

void pneigh_enqueue struct neigh_table tbl,
struct neigh_parms p,
struct sk_buff skb
 

Definition at line 1058 of file neighbour.c.

References __skb_queue_tail(), sk_buff::dev, dev_hold, sk_buff::dst, dst_release(), kfree_skb(), sk_buff_head::lock, net_random(), neigh_parms::proxy_delay, neigh_parms::proxy_qlen, neigh_table::proxy_queue, neigh_table::proxy_timer, sk_buff_head::qlen, and sk_buff::stamp.

Referenced by arp_process().

01060 { 01061 unsigned long now = jiffies; 01062 long sched_next = net_random()%p->proxy_delay; 01063 01064 if (tbl->proxy_queue.qlen > p->proxy_qlen) { 01065 kfree_skb(skb); 01066 return; 01067 } 01068 skb->stamp.tv_sec = 0; 01069 skb->stamp.tv_usec = now + sched_next; 01070 01071 spin_lock(&tbl->proxy_queue.lock); 01072 if (del_timer(&tbl->proxy_timer)) { 01073 long tval = tbl->proxy_timer.expires - now; 01074 if (tval < sched_next) 01075 sched_next = tval; 01076 } 01077 dst_release(skb->dst); 01078 skb->dst = NULL; 01079 dev_hold(skb->dev); 01080 __skb_queue_tail(&tbl->proxy_queue, skb); 01081 mod_timer(&tbl->proxy_timer, now + sched_next); 01082 spin_unlock(&tbl->proxy_queue.lock); 01083 }

struct pneigh_entry* pneigh_lookup struct neigh_table tbl,
const void *  key,
struct net_device dev,
int  creat
 

Definition at line 363 of file neighbour.c.

References neigh_table::key_len, neigh_table::lock, pneigh_entry::next, neigh_table::pconstructor, neigh_table::phash_buckets, and PNEIGH_HASHMASK.

Referenced by arp_process(), arp_req_set(), and neigh_add().

00365 { 00366 struct pneigh_entry *n; 00367 u32 hash_val; 00368 int key_len = tbl->key_len; 00369 00370 hash_val = *(u32*)(pkey + key_len - 4); 00371 hash_val ^= (hash_val>>16); 00372 hash_val ^= hash_val>>8; 00373 hash_val ^= hash_val>>4; 00374 hash_val &= PNEIGH_HASHMASK; 00375 00376 read_lock_bh(&tbl->lock); 00377 00378 for (n = tbl->phash_buckets[hash_val]; n; n = n->next) { 00379 if (memcmp(n->key, pkey, key_len) == 0 && 00380 (n->dev == dev || !n->dev)) { 00381 read_unlock_bh(&tbl->lock); 00382 return n; 00383 } 00384 } 00385 read_unlock_bh(&tbl->lock); 00386 if (!creat) 00387 return NULL; 00388 00389 n = kmalloc(sizeof(*n) + key_len, GFP_KERNEL); 00390 if (n == NULL) 00391 return NULL; 00392 00393 memcpy(n->key, pkey, key_len); 00394 n->dev = dev; 00395 00396 if (tbl->pconstructor && tbl->pconstructor(n)) { 00397 kfree(n); 00398 return NULL; 00399 } 00400 00401 write_lock_bh(&tbl->lock); 00402 n->next = tbl->phash_buckets[hash_val]; 00403 tbl->phash_buckets[hash_val] = n; 00404 write_unlock_bh(&tbl->lock); 00405 return n; 00406 }


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