IPv6 support for hexCIDR()
Includes these changes: - Modified so that IPv6 CIDRs can be converted correctly. - Added test cases for IPv6 addresses. - Split UTs for hexCIDR() and asciiCIDR() so that masking can be tested. - Add UTs for failure cases. Note: Some code that calls hexCIDR() builds a CIDR from the pod IP string and the concatenation of "/32". These should, in the future, use "128", if/when the pod IP is IPv6. Not addressed as part of this commit.
This commit is contained in:
@@ -101,7 +101,7 @@ func hexCIDR(cidr string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
ip = ip.Mask(ipnet.Mask)
|
||||
hexIP := hex.EncodeToString([]byte(ip.To4()))
|
||||
hexIP := hex.EncodeToString([]byte(ip))
|
||||
hexMask := ipnet.Mask.String()
|
||||
return hexIP + "/" + hexMask, nil
|
||||
}
|
||||
@@ -119,6 +119,9 @@ func asciiCIDR(cidr string) (string, error) {
|
||||
ip := net.IP(ipData)
|
||||
|
||||
maskData, err := hex.DecodeString(parts[1])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
mask := net.IPMask(maskData)
|
||||
size, _ := mask.Size()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user