gpt4 book ai didi

sockets - IPv6 范围 ID 与 IPv4

转载 作者:行者123 更新时间:2023-12-03 11:50:02 24 4
gpt4 key购买 nike

最近我正在使用用于 IPv6 的 Berkeley 套接字 API,并注意到 IPv6 地址 ( sockaddr_in6 ) 有一个名为 sin6_scope_id 的字段。 ,这不是 IPv4 地址的一部分。

经过一番搜索,我了解到 scope_id用于标识网络接口(interface),因为多个网络接口(interface)可以具有相同的链路本地 IPv6 地址。这是有道理的,但是我不明白的是 IPv4 是如何处理这个问题的,如果那里没有等效的范围 ID?

内核中是否有一种机制可以防止多个 IPv4 接口(interface)被分配相同的链路本地地址?

如果是这样,那为什么有必要为 IPv6 发明范围 ID 而不是采用与 IPv4 相同的解决方案呢?

此外,scope_id 是否仅用于区分具有相同链路本地地址的接口(interface),还是还有其他用例?

最佳答案

简而言之,不,没有定义明确的机制来处理具有多个接口(interface)的主机上的链路本地 IPv4 地址。没有什么可以阻止为两个不同的接口(interface)选择相同的链路本地地址(但是,如果两个接口(interface)位于同一网络链路上,则基于 ARP 的冲突检测将导致其中至少一个被重新分配)。
RFC 3927 section 3.2涵盖“地址歧义”的问题:

Given that the IP stack must have the outbound interface associatedwith a packet that needs to be sent to a Link-Local destinationaddress, interface selection must occur. The outbound interfacecannot be derived from the packet's header parameters such as sourceor destination address (e.g., by using the forwarding table lookup).Therefore, outbound interface association must be done explicitlythrough other means. The specification does not stipulate thosemeans.


还有 section 6.3 :

Application software run on a multi-homed host that supports IPv4Link-Local address configuration on more than one interface may fail.

This is because application software assumes that an IPv4 address isunambiguous, that it can refer to only one host. IPv4 Link-Localaddresses are unique only on a single link. A host attached tomultiple links can easily encounter a situation where the sameaddress is present on more than one interface, or first on oneinterface, later on another; in any case associated with more thanone host. Most existing software is not prepared for this ambiguity.In the future, application programming interfaces could be developedto prevent this problem.


这个问题在 IPv6 中通过引入 得到了解决。范围 ID .
目前 scope id is only used for link-local addressing .

关于sockets - IPv6 范围 ID 与 IPv4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48328995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com