Linux路由proto字段


 

ip -d route

 

 

proto字段的定義如下(部分):

#define RTPROT_UNSPEC   0
#define RTPROT_REDIRECT 1   /* Route installed by ICMP redirects; not used by current IPv4 */
#define RTPROT_KERNEL   2   /* Route installed by kernel        */
#define RTPROT_BOOT     3   /* Route installed during boot      */
#define RTPROT_STATIC   4   /* Route installed by administrator */

 

proto字段的定義在內核中並沒有實質的意義,只是一個顯示字段。RTPROT_UNSPEC表示未指定;RTPROT_REDIRECT已經不再使用;內核自身添加的路由使用RTPROT_KERNEL;RTPROT_BOOT為在啟動過程中安裝的路由;

例如對於RTPROT_KERNEL類型,內核函數fib_magic添加的路由的protocol固定為RTPROT_KERNEL。在為內核接口添加IP地址時,觸發此函數,用於添加相關的直連路由。

static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa, u32 rt_priority) { struct fib_config cfg = { .fc_protocol = RTPROT_KERNEL, .fc_type = type, .fc_dst = dst, .fc_dst_len = dst_len, .fc_priority = rt_priority, .fc_prefsrc = ifa->ifa_local, .fc_oif = ifa->ifa_dev->dev->ifindex, if (cmd == RTM_NEWROUTE) fib_table_insert(net, tb, &cfg, NULL); }

 

對於RTPROT_BOOT類型,一方面通過ioctl接口(如route命令)添加的路由proto字段會設置為RTPROT_BOOT;此外,如果使能了IP地址自動配置功能,內核可在啟動過程中通過DHCP或者RARP等獲取IP地址信息,此時,在添加與之相關的路由時,路由項也會使用RTPROT_BOOT類型。

數值大於RTPROT_STATIC(4)的proto值,不由內核解釋。內核只是在路由下發時保存此值,顯示時回顯此值。目前定義的值如下:

#define RTPROT_GATED    8   /* Apparently, GateD */
#define RTPROT_RA       9   /* RDISC/ND router advertisements */
#define RTPROT_MRT      10  /* Merit MRT */
#define RTPROT_ZEBRA    11  /* Zebra */
#define RTPROT_BIRD     12  /* BIRD */
#define RTPROT_DNROUTED 13  /* DECnet routing daemon */
#define RTPROT_XORP     14  /* XORP */
#define RTPROT_NTK      15  /* Netsukuku */
#define RTPROT_DHCP     16     /* DHCP client */
#define RTPROT_MROUTED  17     /* Multicast daemon */
#define RTPROT_BABEL    42     /* Babel daemon */
#define RTPROT_BGP      186    /* BGP Routes */
#define RTPROT_ISIS     187    /* ISIS Routes */
#define RTPROT_OSPF     188    /* OSPF Routes */
#define RTPROT_RIP      189    /* RIP Routes */
#define RTPROT_EIGRP    192    /* EIGRP Routes */

 

比如quagga路由程序下發的動態路由(RIP/OSPF/BGP/ISIS)同一使用RTPROT_ZEBRA類型proto值。這也說明這個字段的使用比較混亂。

內核版本 5.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM