dst_entry结构
struct dst_entry
{
struct rcu_head rcu_head;
struct dst_entry *child;
struct net_device *dev;
short error;
short obsolete;
int flags;
#define DST_HOST 1
#define DST_NOXFRM 2
#define DST_NOPOLICY 4
#define DST_NOHASH 8
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;
unsigned long lastuse;
atomic_t __refcnt;
int __use;
union {
struct dst_entry *next;
struct rtable *rt_next;
struct rt6_info *rt6_next;
struct dn_route *dn_next;
};
char info[0];
};
struct net_device *dev; //用于网络接口的指针
int __use; //该表项已经被使用的次数(即缓存查找返回该表项的次数)
short error; //当fib_lookup失败时,错误值被保存在error(用一个正值)
中,在ip_error成员中使用该值来决定如何处理本次路由查找失败(即决定生成哪一类ICMP消息)。
struct neighbour *neighbour; //这个路由路径上下一个neighbour结构的指针。
int (*input)(struct sk_buff*);
int (*output)(struct sk_buff*);
//input 和 output 分别对应着在IP层的输入和输出函数,output对应着下一层发送数据的函数(dev_queue_xmit),input对应着向上一层发送数据的函数(例如tcp_recv)
这几个结构的关系如下:
![linux路由内核实现分析(四)---路由缓存机制(2) linux路由内核实现分析(四)---路由缓存机制(2)](https://i-blog.csdnimg.cn/blog_migrate/f17364fa2eff2a426082dba3347fb0e5.jpeg)
用rt_hash_bucket来管理一张哈希表,存储了rtable结构,rtable结构中内含的dst_entry结构可以找出邻居节点,用以确认next hop