分类: LINUX
2010-03-11 16:51:58
struct fib_table *fib_tables[RT_TABLE_MAX+1]; // RT_TABLE_MAX 为255 |
struct fib_table { unsigned char tb_id; unsigned tb_stamp; int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res); int (*tb_insert)(struct fib_table *table, struct rtmsg *r, …… void (*tb_select_default)(struct fib_table *table, const struct flowi *flp, struct fib_result *res); unsigned char tb_data[0]; }; |
struct fn_hash { struct fn_zone *fn_zones[33]; struct fn_zone *fn_zone_list; }; |
struct fn_zone { struct fn_zone *fz_next; /* Next not empty zone */ struct hlist_head *fz_hash; /* Hash table pointer */ int fz_nent; /* Number of entries */ int fz_divisor; /* Hash divisor */ u32 fz_hashmask; /* (fz_divisor - 1) */ #define FZ_HASHMASK(fz) ((fz)->fz_hashmask) int fz_order; /* Zone order */ u32 fz_mask; #define FZ_MASK(fz) ((fz)->fz_mask) }; |
这个fn_zone域就是我们上面提前的结构,用于将路由根据子网掩码的长度分开成33个部分,其中fn_zones[0]用于默认网关。而fn_zone_list域就是将正在使用的fn_zone链成一个链表。接着再深入到struct fn_zone结构中:
struct fib_node { struct hlist_node fn_hash; struct list_head fn_alias; u32 fn_key; }; |
struct fib_alias { struct list_head fa_list; struct rcu_head rcu; struct fib_info *fa_info; u8 fa_tos; u8 fa_type; u8 fa_scope; u8 fa_state; }; |
struct fib_info { struct hlist_node fib_hash; struct hlist_node fib_lhash; …… int fib_dead; unsigned fib_flags; int fib_protocol; u32 fib_prefsrc; u32 fib_priority; …… int fib_nhs; struct fib_nh fib_nh[0]; #define fib_dev fib_nh[0].nh_dev }; |
struct fib_nh { struct net_device *nh_dev; struct hlist_node nh_hash; struct fib_info *nh_parent; unsigned nh_flags; unsigned char nh_scope; #ifdef CONFIG_IP_ROUTE_MULTIPATH int nh_weight; int nh_power; #endif #ifdef CONFIG_NET_CLS_ROUTE __u32 nh_tclassid; #endif int nh_oif; u32 nh_gw; }; |
ip rule add from 10.1.1.0/24 table TR1 ip rule add iff eth0 table RT2 |
dst nexthop dev 10.1.0.0/16 10.1.1.1 eth0 10.1.0.0/24 10.1.0.1 eth1 |
dst nexthop dev 10.1.0.0/24 10.1.0.1 eth1 10.1.0.0/24 10.1.0.2 eth1 |