IPv6 范围 ID 与 IPv4
IPv6 scope ID vs IPv4
最近我在使用用于 IPv6 的 Berkeley 套接字 API,并注意到 IPv6 地址 (sockaddr_in6
) 有一个名为 sin6_scope_id
的字段,它不是 IPv4 地址的一部分.
经过一番搜索,我了解到 scope_id
是用来标识网络接口的,因为多个网络接口可以具有相同的 link-local IPv6 地址。这是有道理的,但我不明白的是 IPv4 如何处理这个问题,如果那里没有等效的范围 ID?
内核中是否有一种机制可以防止多个 IPv4 接口被分配相同的 link-本地地址?
如果是这样,那为什么有必要为 IPv6 发明范围 ID 而不是采用与 IPv4 相同的解决方案?
此外,scope_id 仅用于区分具有相同 link 本地地址的接口,还是还有其他用例?
简而言之,不,没有明确定义的机制来处理具有多个接口的主机上的 link- 本地 IPv4 地址。没有什么可以阻止为两个不同的接口选择相同的 link-本地地址(但是,如果两个接口在同一网络上 link,那么基于 ARP 的冲突检测将至少导致其中一个待重新分配)。
RFC 3927 section 3.2涵盖了“地址歧义”的问题:
Given that the IP stack must have the outbound interface associated
with a packet that needs to be sent to a Link-Local destination
address, interface selection must occur. The outbound interface
cannot be derived from the packet's header parameters such as source
or destination address (e.g., by using the forwarding table lookup).
Therefore, outbound interface association must be done explicitly
through other means. The specification does not stipulate those
means.
还有 section 6.3:
Application software run on a multi-homed host that supports IPv4
Link-Local address configuration on more than one interface may fail.
This is because application software assumes that an IPv4 address is
unambiguous, that it can refer to only one host. IPv4 Link-Local
addresses are unique only on a single link. A host attached to
multiple links can easily encounter a situation where the same
address is present on more than one interface, or first on one
interface, later on another; in any case associated with more than
one host. Most existing software is not prepared for this ambiguity.
In the future, application programming interfaces could be developed
to prevent this problem.
这个问题在 IPv6 中通过引入 范围 ID 得到解决。
最近我在使用用于 IPv6 的 Berkeley 套接字 API,并注意到 IPv6 地址 (sockaddr_in6
) 有一个名为 sin6_scope_id
的字段,它不是 IPv4 地址的一部分.
经过一番搜索,我了解到 scope_id
是用来标识网络接口的,因为多个网络接口可以具有相同的 link-local IPv6 地址。这是有道理的,但我不明白的是 IPv4 如何处理这个问题,如果那里没有等效的范围 ID?
内核中是否有一种机制可以防止多个 IPv4 接口被分配相同的 link-本地地址?
如果是这样,那为什么有必要为 IPv6 发明范围 ID 而不是采用与 IPv4 相同的解决方案?
此外,scope_id 仅用于区分具有相同 link 本地地址的接口,还是还有其他用例?
简而言之,不,没有明确定义的机制来处理具有多个接口的主机上的 link- 本地 IPv4 地址。没有什么可以阻止为两个不同的接口选择相同的 link-本地地址(但是,如果两个接口在同一网络上 link,那么基于 ARP 的冲突检测将至少导致其中一个待重新分配)。
RFC 3927 section 3.2涵盖了“地址歧义”的问题:
Given that the IP stack must have the outbound interface associated with a packet that needs to be sent to a Link-Local destination address, interface selection must occur. The outbound interface cannot be derived from the packet's header parameters such as source or destination address (e.g., by using the forwarding table lookup). Therefore, outbound interface association must be done explicitly through other means. The specification does not stipulate those means.
还有 section 6.3:
Application software run on a multi-homed host that supports IPv4 Link-Local address configuration on more than one interface may fail.
This is because application software assumes that an IPv4 address is unambiguous, that it can refer to only one host. IPv4 Link-Local addresses are unique only on a single link. A host attached to multiple links can easily encounter a situation where the same address is present on more than one interface, or first on one interface, later on another; in any case associated with more than one host. Most existing software is not prepared for this ambiguity. In the future, application programming interfaces could be developed to prevent this problem.
这个问题在 IPv6 中通过引入 范围 ID 得到解决。