Linux内核路由表介绍及相关函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012247418/article/details/89103701

内核对路由表的操作

  • 更新

  • 插入

  • 删除

  • 查找

路由表种类

  • 网络路由表:ip_fib_main_table

  • 本地路由表:ip_fib_local_table

  • 路由缓存:rt_hash_table

  • 策略路由:根据策略支持多张路由表

表项

  • 路由缓存表项:rtable, 一般使用dst_entry,rtable是对dst_entry的包裹,另外rtable中还有协议相关的信息。

  • dst_entry:对一条路由缓存存储协议无关的信息

更新:

1. 路由缓存

rt_cache_flush()    安排刷新路由缓存

2. 路由表

fib_sync_down()     当一个设备被关闭或删除一个本地地址时更新路由表

fib_flush()         扫描路由表,删除路由项

插入:

1. 路由缓存

rt_intern_hash()    向路由缓存添加一条表项

2. 路由表,分为用户空间插入方法和内核方法,用户空间最终是通过调用内核方法实现。

删除:

1. 路由缓存

rt_free()           删除路由缓存中的一条表项

dst_free()          删除dst_entry

2. 路由表,分为用户空间插入方法和内核方法,用户空间最终是通过调用内核方法实现。

fib_del_ifaddr()    标记一个需要删除的路由项,然后调用fib_sync_down()或fib_flush()来清理路由表

查找:

1. 路由缓存

入口流量:ip_route_input()

出口流量:ip_route_output_key()

2. 路由表

入口流量:ip_route_input_slow()

出口流量:ip_route_output_slow()

猜你喜欢

转载自blog.csdn.net/u012247418/article/details/89103701