Basic Internet Protocol Routing

介绍关于ip路由的基本概念和内部的数据结构。
        linux为路由维护三种数据结构,一种用于与本节点直接物理相连的节点的路由,其它的两种用于与其它间接节点相邻的情况。
        前者叫做neighbor table,它保存着通往每一个节点的所用的设备和协议的种类,linux使用arp协议来维护该表。其中的每个条目都是soft state。
        linux使用后两种路由表来维护ip地址:Forward Infomation Base(FIB)保存了通向所有可达节点的路由信息。以及另一个较小和较快的route cache,保存经常使用的路由信息。
        当系统要往外发包时,它首先检查路由是否存在于route cache中,如果没有,则检查FIB,如果找到的话,把此entry插入到route cache中,然后返回。FIB中的条目一般是不会变化的,除非路由器重启,或者down掉而route cache中的条目如果一定时间内不用的话,则会从route cache中删除掉。


fib

138 #ifndef CONFIG_IP_MULTIPLE_TABLES
139
140 extern struct fib_table *local_table;
141 extern struct fib_table *main_table;

169 #else /* CONFIG_IP_MULTIPLE_TABLES */

170 #define local_table (fib_tables[RT_TABLE_LOCAL])
171 #define main_table (fib_tables[RT_TABLE_MAIN])

¢
local_table, main_table是全局的指针变量,用来访问FIB表。
FIB Table fib_table结构:
        int (*tb_functions)() -指向对表进行操纵的函数(lookup,delete,insert等等),在系统初始化时,由fn_hash_function()进行设置。
        unsigned char tb_data[0]-指向关联的FIB hash table的指针。
        unsigned char tb_id-table identifier,对local_table是255,对main_table是254。
        unsigned tb_stamp
Netmask Table fn_hash结构:在net/ipv4/fib_hash.c-这个结构包含指向individual zones的指针,根据netmask进行组织。(每一个zone对应一个特定的network mask),所以一共有32个+全部是零=33个。
            struct fn_zone *fn_zones[33]-指向zone entry的指针数组,fn_zone[0]指向netmask为0x0000的zone,fn_zone[1]指向0x8000,fn_zone[32]指向zone 0xffff。
            struct fn_zone *fn_zone_list:指向第一个非空的zone,如果0xffff entry非空的话,指向0xffff的entry。
Network Zone fn_zone结构:net/ipv4/fib_hash.c,这个结构包含hash的信息和指向hash table节点的指针。每一个netmask对应一个。
            struct fn_zone *fz_next-指向下一个在hash结构中非空的zone(例如fn_hash->fn_zone[28]->fz_next可能是fn_hash->fn_zone[27]。
            struct fib_node **fn_hash-pointer to a hash table of nodes for this zone。
            int fz_nent-the number of entries(nodes) in this zone。
            int fx_divisor-the number of buckets in the hash table associated with this zone;
there are 16 buckets in the table for most zones(except the first zone-0000 - the loopback device).
            u32 fz_hashmask - a mask for entering the hash table of nodes; 15(0x0F) for most zones, 0 for zone 0).
            int fz_order - the index of this zone in the parent fn_hash structure(0 to 32)
            u32 fz_mask - the zone netmask defined as ~((1<<(32-fz_order))-1); for example, the first (zero) element is 1 shifted left 32 minus 0 times(0x10000), minus 1(0xFFFF), and complemented(0x0000). The second element has a netmask of 0x8000, the next 0xC000, the next oxE000, 0xF0000, 0xF8000, and so on to the last (32d) element whose mask is oxFFFF.

Network NOde Information fib_node Structure - net/ipv4/fib_hash.c - 这个结构包含了唯一特定的针对一个地址集合的信息,以及一个指向通用属性的指针(如设备和协议)。
            struct fib_node *fn_next - pointer to the next node.
            struct fib_info *fn_info - pointer to more information about this node(that is shared by many nodes).
            fn_key_t fn_key - hash table key - the least significant 8 bits of the destination address(or 0 for the loopback device).
        Other fields include specific information about this node(like fn_tos and fn_state).



Network Protocol Information (fib_info) Structure - include/net/ip_fib.h - 这个结构包含特定接口的协议和硬件信息,所以对一些zone来说是相同的,一些网络可以通过同一个接口来进行寻址。所以zone可以共享fib_info。
            fib_protocol - index to a network protocol (e.g. ip) used for this route.
            struct fib_nh fib_nh[0] - contains a pointer to the device used for sending or receiving traffic for this route.
            Other fields include list pointers and statistical and refreence data(like fib_refcnt and fib_flags)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值