Skip to content

net: apply ICANN/IANA-managed semantics to IP.IsGlobalUnicast #11772

@mike-joseph

Description

@mike-joseph

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
net.ParseIP("10.1.2.3").IsGlobalUnicast() currently returns True

I would propose the following changes:

  • Rename IsGlobalUnicast() to IsUnicast()
  • Add a check to IsUnicast() to exclude Class E and broadcast addresses
  • Create a new IsGlobalUnicast() which extends IsUnicast() by also excluding RFC1918 & RFC6598 addresses

Ideally, it would be even better to extend both further using the tables in RFC6890 as a guideline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions