Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175481
  • 博文数量: 37
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 256
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-06 23:02
文章分类

全部博文(37)

分类: LINUX

2015-12-28 13:51:33

/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分别是该目的入口的输入和输出函数。
阅读(3268) | 评论(0) | 转发(0) |
0

上一篇:CTAGS

下一篇:struct ip_queue_xmit

给主人留下些什么吧!~~