内核路由表设计与实现

一、路由表的数据结构

Linux 支持最多252张路由表。 255 表示 local 表, 254 表示 main 路由表。

 

 

struct fib_table *fib_tables[RT_TABLE_MAX+1];

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];
};

 

 

 

 

 

 

 

 
以上代码表示使用一个数组来表示255个路由表,每个数组指针指向一个路由表。
 
 
 
 
 
 
 
 
二、路由表的查找
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

posted @ 2017-12-26 10:24  elewei  阅读(950)  评论(0)    收藏  举报