Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net: apply ICANN/IANA-managed semantics to IP.IsGlobalUnicast #11772
net.IP.IsGlobalUnicast() applies incorrect address semantics. The current implementation returns True if the address is not Unspecified, Loopback, LinkLocal, or Multicast. However, a Global Unicast address, by definition, excludes more than just those categories. Class E space is to be excluded, as is all of RFC1918 & RFC6598.
This manifests in a few significant ways:
net.ParseIP("255.255.255.255").IsGlobalUnicast() currently returns True
I would propose the following changes:
Ideally, it would be even better to extend both further using the tables in RFC6890 as a guideline.
The IsGlobalUnicast method of IP struct simply follows RFC 4291 when the IP is an IPv6 address. That means that the method just uses address type identification of https://tools.ietf.org/html/rfc4291#section-2.5.4 because it's hard to identify various IPv6 addresses without context; for example, in the case of constructing sort of IPv4-IPv6 translator applications using addresses defined in RFC 6052.
There are a few options: a) just updating documentation like "it just follows RFC 4291", b) making IsGlobalUnicast on unique local IPv6 unicast addresses return false, c) adding IsUniqueLocalUnicast method to IP, though I have no strong opinion about the latter two.