Don't use To16() != nil to detect IPv6 addresses

The ip.To16() function returns non-nil if `ip` is any kind
of IP address, including IPv4. To look for IPv6 specifically,
use ip.To4() == nil.

Signed-off-by: Sam Edwards <CFSworks@gmail.com>
This commit is contained in:
Sam Edwards 2023-09-08 21:43:23 -06:00
parent 210db9b101
commit 88a849626f
2 changed files with 2 additions and 2 deletions

View File

@ -612,7 +612,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin
}
case "ipv6":
for i, ip := range configs {
if ip.IP.To16() != nil {
if ip.IP.To4() == nil {
return ipString(ip), append(extra, toStrings(configs[i+1:])...)
}
extra = append(extra, ipString(ip))

View File

@ -692,7 +692,7 @@ func selectPodIPs(ctx context.Context, configs []*cni.IPConfig, preference strin
}
case "ipv6":
for i, ip := range configs {
if ip.IP.To16() != nil {
if ip.IP.To4() == nil {
return ipString(ip), append(extra, toStrings(configs[i+1:])...)
}
extra = append(extra, ipString(ip))