|
9 | 9 | "fmt" |
10 | 10 | "net" |
11 | 11 | "os" |
| 12 | + "strconv" |
12 | 13 | "time" |
13 | 14 |
|
14 | 15 | "github.com/Azure/azure-container-networking/aitelemetry" |
@@ -41,6 +42,8 @@ const ( |
41 | 42 | // Supported IP version. Currently support only IPv4 |
42 | 43 | ipamV6 = "azure-vnet-ipamv6" |
43 | 44 | defaultRequestTimeout = 15 * time.Second |
| 45 | + ipv4FullMask = 32 |
| 46 | + ipv6FullMask = 128 |
44 | 47 | ) |
45 | 48 |
|
46 | 49 | // CNI Operation Types |
@@ -1341,20 +1344,30 @@ func convertNnsToCniResult( |
1341 | 1344 |
|
1342 | 1345 | intIndex := i |
1343 | 1346 | for _, ip := range ni.Ipaddresses { |
| 1347 | + ipAddr := net.ParseIP(ip.Ip) |
1344 | 1348 |
|
1345 | | - ipWithPrefix := fmt.Sprintf("%s/%s", ip.Ip, ip.PrefixLength) |
1346 | | - _, ipNet, err := net.ParseCIDR(ipWithPrefix) |
| 1349 | + prefixLength, err := strconv.Atoi(ip.PrefixLength) |
1347 | 1350 | if err != nil { |
1348 | | - log.Logger.Error("Error while converting to cni result", |
| 1351 | + log.Logger.Error("Error parsing prefix length while converting to cni result", |
| 1352 | + zap.String("prefixLength", ip.PrefixLength), |
1349 | 1353 | zap.String("operation", operationName), |
1350 | 1354 | zap.String("pod", podName), |
1351 | 1355 | zap.Error(err)) |
1352 | 1356 | continue |
1353 | 1357 | } |
1354 | 1358 |
|
| 1359 | + address := net.IPNet{ |
| 1360 | + IP: ipAddr, |
| 1361 | + Mask: net.CIDRMask(prefixLength, ipv6FullMask), |
| 1362 | + } |
| 1363 | + |
| 1364 | + if ipAddr.To4() != nil { |
| 1365 | + address.Mask = net.CIDRMask(prefixLength, ipv4FullMask) |
| 1366 | + } |
| 1367 | + |
1355 | 1368 | gateway := net.ParseIP(ip.DefaultGateway) |
1356 | 1369 | ipConfig := &cniTypesCurr.IPConfig{ |
1357 | | - Address: *ipNet, |
| 1370 | + Address: address, |
1358 | 1371 | Gateway: gateway, |
1359 | 1372 | Interface: &intIndex, |
1360 | 1373 | } |
|
0 commit comments