Previously, on dual-homed hosts the GetPrivateIP, GetPublicIP, GetPrivateInterfaces, and GetPublicInterfaces methods could return incorrect values.
Suppose the hypothetical host:
net0 has a public IP and has adjacency to the default route
net1 has a private IP
Under this scenario, GetPublicIP and GetPublicInterfaces would succeed, but GetPrivateIP and GetPrivateInterfaces would not because GetPrivateInterfaces was incorrectly using GetDefaultInterfaces at its initial seed of IfAddrs. Instead, change the behavior to use GetAllInterfaces and then sort based on whether or not the interface has a default route, meaning we prefer IfAddr entries that have a default route, but it isn't required. Provide the same logic for GetPublicInterface.
Fix a bug where the flags selector was ORing two conditions: flags "forwardable|up" was incorrect, it should have been flags "forwardable" | flags "up". Without this change it was possible that GetPrivateIP could return the loopback address because it is up even if it is not forwardable.
Previously, on dual-homed hosts the
GetPrivateIP
,GetPublicIP
,GetPrivateInterfaces
, andGetPublicInterfaces
methods could return incorrect values.Suppose the hypothetical host:
net0
has a public IP and has adjacency to the default routenet1
has a private IPUnder this scenario,
GetPublicIP
andGetPublicInterfaces
would succeed, butGetPrivateIP
andGetPrivateInterfaces
would not becauseGetPrivateInterfaces
was incorrectly usingGetDefaultInterfaces
at its initial seed ofIfAddrs
. Instead, change the behavior to useGetAllInterfaces
and then sort based on whether or not the interface has a default route, meaning we preferIfAddr
entries that have a default route, but it isn't required. Provide the same logic forGetPublicInterface
.Fix a bug where the flags selector was
OR
ing two conditions:flags "forwardable|up"
was incorrect, it should have beenflags "forwardable" | flags "up"
. Without this change it was possible thatGetPrivateIP
could return the loopback address because it isup
even if it is notforwardable
.