/usr/src/linux-2.6.19/include/net/dst.h
最終生成的IP數據報的路由稱爲目的入口(dst_entry),目的入口反映了相鄰的外部主機在本地主機內部的一種“映象”,目的入口在內核中的定義如下
struct dst_entry
{
struct dst_entry *next;
atomic_t __refcnt;
int __use;
struct dst_entry *child;
struct net_device *dev;
short error;
short obsolete;
int flags;
unsigned long lastuse;
unsigned long expires;
unsigned short header_len;
unsigned short nfheader_len;
unsigned short trailer_len;
u32 metrics[RTAX_MAX];
struct dst_entry *path;
unsigned long rate_last;
unsigned long rate_tokens;
struct neighbour *neighbour;
struct hh_cache *hh;
struct xfrm_state *xfrm;
int (*input)(struct sk_buff*);
int (*output)(struct sk_buff*);
#ifdef CONFIG_NET_CLS_ROUTE
__u32 tclassid;
#endif
struct dst_ops *ops;
struct rcu_head rcu_head;
char info[0];
};
dst_entry->__refcnt
"目的入口"的引用計數,創建成功後即設爲1
dst_entry->__use
一個統計數值,該"目的入口"被使用一次(發送一個IP數據報),__use就加1
dst_entry->dev
該路由的輸出網絡設備接口
dst_entry->flags
標誌位,其取值可以是DST_HOST, DST_NOXFRM, DST_NOPOLICY, DST_NOHASH, DST_BALANCED(用在路由有多路徑的情況下)
dst_entry->lastuse
一個時間值,每次目的入口被用於發送IP數據報,就將該值設置爲當前系統時間值。該值被用於幾個地方,路由緩存表 rt_hash_table是一個很大的數組(依據系統的內存大小而定),每一項都是一個struct rtable的鏈表,當要往緩存表的某一個鏈表中插入一個新的struct rtable時,如果這個鏈表的長度已經超出ip_rt_gc_elasticity(值爲8),則需要刪掉一個當前使用價值最低的,已保持鏈表長度的平衡。函數rt_score()就是用於爲每個struct rtable計算價值分數,分數是一個32位值,最高位表示非常有價值,當struct rtable的成員rt_flags上有標誌RTCF_REDIRECTED或RTCF_NOTIFY,或者目的入口的超時時間未到時,置該位,次高位價值次之,餘下的30位由lastuse決定,該目的入口距上次使用時間越長,價值越低。另外,用於在rt_may_expire函數中判斷一個struct rtable是否超時。
dst_entry->expires
一個超時時間值,定時器rt_periodic_timer定期掃描路由緩存表rt_hash_table,如果發現expires值爲0,或者小於當前系統時間值,並符合其它超時條件,則把該路由從緩存表中刪除。
dst_entry->neighbour
爲該路由綁定的鄰居節點(與ARP相關)
dst_entry->hh
硬件頭緩存,ARP解析得到的鄰居的mac地址緩存在這裏,再次發送IP數據報的時候,就不需要再到ARP緩存中去取硬件頭。
dst_entry->input
dst_entry->output
input和output分別是該目的入口的輸入和輸出函數。
最終生成的IP數據報的路由稱爲目的入口(dst_entry),目的入口反映了相鄰的外部主機在本地主機內部的一種“映象”,目的入口在內核中的定義如下
struct dst_entry
{
struct dst_entry *next;
atomic_t __refcnt;
int __use;
struct dst_entry *child;
struct net_device *dev;
short error;
short obsolete;
int flags;
unsigned long lastuse;
unsigned long expires;
unsigned short header_len;
unsigned short nfheader_len;
unsigned short trailer_len;
u32 metrics[RTAX_MAX];
struct dst_entry *path;
unsigned long rate_last;
unsigned long rate_tokens;
struct neighbour *neighbour;
struct hh_cache *hh;
struct xfrm_state *xfrm;
int (*input)(struct sk_buff*);
int (*output)(struct sk_buff*);
#ifdef CONFIG_NET_CLS_ROUTE
__u32 tclassid;
#endif
struct dst_ops *ops;
struct rcu_head rcu_head;
char info[0];
};
dst_entry->__refcnt
"目的入口"的引用計數,創建成功後即設爲1
dst_entry->__use
一個統計數值,該"目的入口"被使用一次(發送一個IP數據報),__use就加1
dst_entry->dev
該路由的輸出網絡設備接口
dst_entry->flags
標誌位,其取值可以是DST_HOST, DST_NOXFRM, DST_NOPOLICY, DST_NOHASH, DST_BALANCED(用在路由有多路徑的情況下)
dst_entry->lastuse
一個時間值,每次目的入口被用於發送IP數據報,就將該值設置爲當前系統時間值。該值被用於幾個地方,路由緩存表 rt_hash_table是一個很大的數組(依據系統的內存大小而定),每一項都是一個struct rtable的鏈表,當要往緩存表的某一個鏈表中插入一個新的struct rtable時,如果這個鏈表的長度已經超出ip_rt_gc_elasticity(值爲8),則需要刪掉一個當前使用價值最低的,已保持鏈表長度的平衡。函數rt_score()就是用於爲每個struct rtable計算價值分數,分數是一個32位值,最高位表示非常有價值,當struct rtable的成員rt_flags上有標誌RTCF_REDIRECTED或RTCF_NOTIFY,或者目的入口的超時時間未到時,置該位,次高位價值次之,餘下的30位由lastuse決定,該目的入口距上次使用時間越長,價值越低。另外,用於在rt_may_expire函數中判斷一個struct rtable是否超時。
dst_entry->expires
一個超時時間值,定時器rt_periodic_timer定期掃描路由緩存表rt_hash_table,如果發現expires值爲0,或者小於當前系統時間值,並符合其它超時條件,則把該路由從緩存表中刪除。
dst_entry->neighbour
爲該路由綁定的鄰居節點(與ARP相關)
dst_entry->hh
硬件頭緩存,ARP解析得到的鄰居的mac地址緩存在這裏,再次發送IP數據報的時候,就不需要再到ARP緩存中去取硬件頭。
dst_entry->input
dst_entry->output
input和output分別是該目的入口的輸入和輸出函數。