ifa_local 和 ifa_address区别联系: 1. 在配置了支持广播的接口上,与IFA_LOCAL […]
分类目录归档:IP结构与操作
IP结构与操作之inet_addr_onlink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* 根据指定设备的ip配置块,判断地址a,b是否在同一子网 */ /* --邻居项要求,在同一子网中的两个设备, 至少有一个接口有相同的子网配置, --也就是说对端的in_dev->ifa_list中也能找到一个与当前 in_dev->ifa_list中相同的ifa_mask --如果有这样一个ifa_mask使得两个地址与其计算后 网络部分相同,则在同一子网 */ int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b) { rcu_read_lock(); /* 遍历主地址 */ for_primary_ifa(in_dev) { /* a与ifa在同一网段 */ if (inet_ifa_match(a, ifa)) { /* b不存在,或者b与ifa在同一网段 */ if (!b || inet_ifa_match(b, ifa)) { rcu_read_unlock(); /* ab在同一子网 */ return 1; } } } endfor_ifa(in_dev); rcu_read_unlock(); return 0; } |
IP结构与操作之inet_confirm_addr && confirm_addr_indev
确认给定参数范围的ip地址是否存在;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* * Confirm that local IP address exists using wildcards: * - net: netns to check, cannot be NULL * - in_dev: only on this interface, NULL=any interface * - dst: only in the same subnet as dst, 0=any dst * - local: address, 0=autoselect the local address * - scope: maximum allowed scope value for the local address */ /* 确认参数中给定的本地地址是否存在 net: net命名空间,不能为空 in_dev: 在此ip控制块上,空表示任何设备上的控制块 dst: 与dst在同一子网,0表示不限制 local: 本地地址,0表示自动选择本地地址 scope: 本地地址最大允许的地址范围 */ __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst, __be32 local, int scope) { __be32 addr = 0; struct net_device *dev; /* ip控制块存在,则从该控制块中选择地址 */ if (in_dev) return confirm_addr_indev(in_dev, dst, local, scope); rcu_read_lock(); /* ip控制块不存在,则遍历所有设备 */ for_each_netdev_rcu(net, dev) { /* 找到设备中的ip控制块 */ in_dev = __in_dev_get_rcu(dev); /* 如果ip控制块存在 */ if (in_dev) { /* 从该控制块选择地址 */ addr = confirm_addr_indev(in_dev, dst, local, scope); /* 找到则结束 */ if (addr) break; } } rcu_read_unlock(); return addr; } |
&nb […]
IP结构与操作之inet_select_addr
当通过输出设备向目的地址发送报文时,如果没有源地址,则需要调用inet_select_addr来选择ip地址作 […]
IP结构与操作之inetdev_init && inetdev_destroy
inetdev_init为传入设备分配和绑定ip控制块,查看其调用关系如下: [crayon-5ded8e5f […]
IP结构与操作之in_device结构和in_ifaddr结构
in_device为ip配置块,关联了二层设备,包含ip地址列表,组播配置,arp参数,接口配置等; [cra […]