Document serial number【UU89WT-UU98YT-UU8CB-UUUT-UUT108】
路由过程分析
重要数据结构
struct fib_config {
u8 fc_dst_len; We drop all the packets that has local source
* addresses, because every properly looped back packet
* must have correct destination already attached by output routine.
*
* Such approach solves two big problems:
* 1. Not simplex devices are handled properly.
* 2. IP spoofing attempts are filtered with 100% of guarantee.
*/
非本机发往本机
与本机发往本机的流程相比,非本机发往本机的流程显得比较简单
首先netif_recveive_skb从网卡接收到IP报文,遍历ptype_base列表,调用ip_rcv 进入网络三层
ip_rcv
-> ip_rcv_finish
-> skb_dst (skb) == NULL,故需要走ip_route_input 进行目的路由查找
-> ip_route_input
-> ip_route_input_slow
-> fib_lookup
-> ip_mkroute_input (转发)
-> dst_input
校验函数fib_lookup返回结果,若结果 == RTN_LOCAL表明是发往本机的报文,否则需要转发.
若发往本机:
= net->loopback_dev
= ip_local_deliver
若需要转发:
首先检测是否开启了ip_forward (通过echo 1 > /proc/sys/net/ipv4/ip_forward开启)
ip_mkroute_input
-> __mkroute_input
->
->
-> 加入缓存
故最终
若发往本机,则调用dst_input = [skb_dst(skb)->input] = ip_local_deliver
若需要转发,则调用dst_input = [skb_dst(skb)->input] = ip_forward
而ip_forward又调用dst_output = [skb_dst(skb)->output] = ip_output
内核与用户接口
ip route命令
[***@net/ipv4/]
rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL, NULL); .)
-> notifier_chain_register(...) // 注册通知
[***@net/ipv4/]
inet_rtm_newaddr
-> 给网卡
路由过程分析 来自淘豆网m.daumloan.com转载请标明出处.