memo.log

技術情報の雑なメモ

ip route や /proc/net/route のFlagsについて

/proc/net/route を見ると Flags というカラムがある。

% cat /proc/net/route
Iface   Destination     Gateway         Flags   RefCnt  Use     Metric  Mask            MTU     Window  IRTT                                                       
eth0    00000000        01001FAC        0003    0       0       0       00000000        0       0       0
eth1    00000000        01001FAC        0003    0       0       10001   00000000        0       0       0
eth2    00000000        01001FAC        0003    0       0       10002   00000000        0       0       0
eth0    FEA9FEA9        00000000        0005    0       0       0       FFFFFFFF        0       0       0 
eth0    00001FAC        00000000        0001    0       0       0       00F0FFFF        0       0       0
eth1    00001FAC        00000000        0001    0       0       0       00F0FFFF        0       0       0
eth2    00001FAC        00000000        0001    0       0       0       00F0FFFF        0       0       0

これはなんだろうと思って、 ip route コマンドの結果をみてみると、 scope link (隣接(直接宛先と通信できる)のネットワーク)が 0001 と整合しているように見える。

% ip route
default via 172.31.0.1 dev eth0 
default via 172.31.0.1 dev eth1 metric 10001 
default via 172.31.0.1 dev eth2 metric 10002 
169.254.169.254 dev eth0 
172.31.0.0/20 dev eth0 proto kernel scope link src 172.31.7.56 
172.31.0.0/20 dev eth1 proto kernel scope link src 172.31.11.244 
172.31.0.0/20 dev eth2 proto kernel scope link src 172.31.11.75 

route コマンドで見ると Flags が U という文字列で表現されている。

% route                         
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         ip-172-31-0-1.a 0.0.0.0         UG    0      0        0 eth0
default         ip-172-31-0-1.a 0.0.0.0         UG    10001  0        0 eth1
default         ip-172-31-0-1.a 0.0.0.0         UG    10002  0        0 eth2
instance-data.a 0.0.0.0         255.255.255.255 UH    0      0        0 eth0
172.31.0.0      0.0.0.0         255.255.240.0   U     0      0        0 eth0
172.31.0.0      0.0.0.0         255.255.240.0   U     0      0        0 eth1
172.31.0.0      0.0.0.0         255.255.240.0   U     0      0        0 eth2

以下のファイルを見ると、 RTF_UP 0x0001 / route usable /ということで、上記認識で合っているみたい。

/usr/include/linux/route.h

#define RTF_UP          0x0001          /* route usable                 */
#define RTF_GATEWAY     0x0002          /* destination is a gateway     */
#define RTF_HOST        0x0004          /* host entry (net otherwise)   */
#define RTF_REINSTATE   0x0008          /* reinstate route after tmout  */
#define RTF_DYNAMIC     0x0010          /* created dyn. (by redirect)   */
#define RTF_MODIFIED    0x0020          /* modified dyn. (by redirect)  */
#define RTF_MTU         0x0040          /* specific MTU for this route  */
#define RTF_MSS         RTF_MTU         /* Compatibility :-(            */
#define RTF_WINDOW      0x0080          /* per route window clamping    */
#define RTF_IRTT        0x0100          /* Initial round trip time      */
#define RTF_REJECT      0x0200          /* Reject route                 */

参考

android - What's the meaning of /proc/net/rotue columns? especially Flags column - Stack Overflow https://stackoverflow.com/questions/33231034/whats-the-meaning-of-proc-net-rotue-columns-especially-flags-column