Skip to content

Commit 91847f5

Browse files
committed
bug fix
1 parent 8e94fc6 commit 91847f5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

cni/network/invoker_cns.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ func getRoutes(cnsRoutes []cns.Route, skipDefaultRoutes bool) ([]network.RouteIn
362362
}
363363

364364
gw := net.ParseIP(route.GatewayIPAddress)
365-
// if gw == nil && skipDefaultRoutes {
366-
// return nil, errors.Wrap(errInvalidGatewayIP, route.GatewayIPAddress)
367-
// }
365+
if gw == nil && skipDefaultRoutes {
366+
return nil, errors.Wrap(errInvalidGatewayIP, route.GatewayIPAddress)
367+
}
368368

369369
routes = append(routes,
370370
network.RouteInfo{

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package middlewares
22

33
import (
4+
"net"
45
"net/netip"
56

67
"github.com/Azure/azure-container-networking/cns"
@@ -71,9 +72,13 @@ func (k *K8sSWIFTv2Middleware) addDefaultRoute(podIPInfo *cns.PodIpInfo, gateway
7172
func (k *K8sSWIFTv2Middleware) addRoutes(cidrs []string) []cns.Route {
7273
routes := make([]cns.Route, len(cidrs))
7374
for i, cidr := range cidrs {
75+
ip, _, err := net.ParseCIDR(cidr)
76+
if err != nil {
77+
return nil
78+
}
7479
routes[i] = cns.Route{
7580
IPAddress: cidr,
76-
GatewayIPAddress: "", // gateway IP is not required for infraNIC
81+
GatewayIPAddress: ip.String(),
7782
}
7883
}
7984
return routes

network/endpoint_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,15 @@ func (nw *network) configureHcnEndpoint(epInfo *EndpointInfo) (*hcn.HostComputeE
333333
}
334334

335335
for _, route := range epInfo.Routes {
336+
nextHop := route.Gw.String()
337+
// If the route is for the frontend NIC, the next hop should be empty.
338+
// This is because the containerd does not require next hop to configure route and the expected route entry on lcow should be like:
339+
// 10.224.0.0/12 dev eth0
340+
if epInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
341+
nextHop = ""
342+
}
336343
hcnRoute := hcn.Route{
337-
NextHop: route.Gw.String(),
344+
NextHop: nextHop,
338345
DestinationPrefix: route.Dst.String(),
339346
}
340347

0 commit comments

Comments
 (0)