linux stack of neighborhood subsystem (two related processes)

  

as before neighborhood subsystem initialization, linux source code version 2.6.21void __init arp_init (void) (net /ipv4 /arp.c) {//neighbor table initialization neigh_table_init (& arp_tbl); //Register arp protocol dev_add_pack (& ​​amp; arp_packet_type); //establish proc objects arp_proc_init (); # ifdef CONFIG_SYSCTLneigh_sysctl_register (NULL, & arp_tbl.parms, NET_IPV4, NET_IPV4_NEIGH, " ipv4 " , NULL); #endif //event notification list register_netdevice_notifier (& arp_netdev_notifier); } In neigh_table_init (& arp_tbl);, the neighbor table is initialized accordingly, in particular, a garbage collection timer is initialized. The content of the discussion arp_packet_type is: static struct packet_type arp_packet_type = {.type = __constant_htons(ETH_P_ARP), (protocol number corresponding to the link layer). func = arp_rcv, "packet processing function" can be seen from above out, when receiving the data arp packet, () treated with five arp_rcv: neighbor system data structure analysis neigh_table structure: struct neigh_table {//a next neighbor struct neigh_table * next; //protocol stack int family; //inlet length, i.e. the size of a neighbor structure is initialized to sizeof (neighbour) +4 (4 for the length of an IP address) int entry_size; //key hash value of a length that is the length of an IP address for 4int key_len; //Ha The count function of the hash value (the hash value is calculated by the corresponding device net_device and the destination Ip) __u32 (*hash) (const void *pkey, const struct net_device *); //neighbor initialization function int (*constructor) (struct Neighbor *);int (*pconstructor)(struct pneigh_entry *);void (*pdestructor)(struct pneigh_entry *);void (*proxy_redo)(struct sk_buff *skb);//The name of the neighbor table char *id;struct Neigh_parms parms;/* HACK. gc_* shoul follow parms without a gap! *///regular garbage collection int gc_interval; int gc_thresh1; //second threshold, if the neighbor exceeds this value, when creating a new neighbor If /if there is no refresh for more than five seconds, it must be refreshed immediately, forcing garbage collection int gc_thresh2; //allow the upper limit of the neighbor int gc_thresh3; //recent refresh time unsigned long last_flush; //regular garbage collection timer struct timer_list gc_timer ;struct timer_list proxy_timer;struct sk_buff_head proxy_queue;//number of neighbors in the entire table int entries;rwlock_t lock;unsigned long last_rand;struct neigh_parms *parms_list;kmem_cache_t *kmem_cachep;struct neigh_statistics *stats;//Hash array, stored in Neighbor struct neighbour **hash_buckets;//Hash array size mask unsigned int hash_mask;__u32 hash_rnd;unsigned int hash_chain_gc;//related to proxy arp struct pneigh_entry **phash_buckets;#ifdef CONFIG_PROC_FSstruct proc_dir_entry *pde;#endif} Neighbour structure: struct neighbour{//next neighbor struct neighbou r *next; //where the neighbor table struct neigh_table * tbl; //arp transfer parameter struct neigh_parms * parms; //neighbors corresponding network device struct net_device * dev; //last use time unsigned long used; unsigned long Confirmed; //update time unsigned long updated; __u8 flags; //neighbors corresponding state __u8 nud_state; __u8 type; //survival flag, if dead is 1, then the garbage collection function will delete this item __u8 dead; //Retry the number of times to send arp request atomic_t probes; rwlock_t lock; //corresponding neighbor's header cache unsigned char ha [(MAX_ADDR_LEN + sizeof (unsigned long) -1) & ~ (sizeof (unsigned long) -1) Struct hh_cache *hh; //reference count atomic_t refcnt; //neighbor corresponding to the send function int (*output) (struct sk_buff * skb); //corresponding send skb queue struct sk_buff_head arp_queue; //timer struct Timer_list timer;struct neigh_ops *ops;//hash keyword u8 primary_key[0];};

Copyright © Windows knowledge All Rights Reserved