Skip to content

Commit

Permalink
add default route on customer vnets
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Sep 24, 2024
1 parent 3a6959c commit 5852af3
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,15 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
resRoute := addResult.interfaceInfo[key].Routes
if len(routes) > 0 {
resRoute = append(resRoute, routes...)
} else { // add default routes if none are provided
resRoute = append(resRoute, network.RouteInfo{
Dst: defaultRouteDstPrefix,
Gw: ncgw,
})
} else { // add default routes if none are provided and skipDefaultRoute is false
if !info.skipDefaultRoutes {
resRoute = append(resRoute, network.RouteInfo{
Dst: defaultRouteDstPrefix,
Gw: ncgw,
})
}
}

// if we have multiple infra ip result infos, we effectively append routes and ip configs to that same interface info each time
// the host subnet prefix (in ipv4 or ipv6) will always refer to the same interface regardless of which ip result info we look at
addResult.interfaceInfo[key] = network.InterfaceInfo{
Expand Down Expand Up @@ -484,6 +487,19 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
return err
}

defaultRouteDstPrefix := network.Ipv4DefaultRouteDstPrefix
ncgw := net.ParseIP(info.ncGatewayIPAddress)

resRoute := addResult.interfaceInfo[key].Routes
if len(routes) > 0 {
resRoute = append(resRoute, routes...)
} else { // add default routes for secondary interfaces
resRoute = append(resRoute, network.RouteInfo{
Dst: defaultRouteDstPrefix,
Gw: ncgw,
})
}

addResult.interfaceInfo[key] = network.InterfaceInfo{
IPConfigs: []*network.IPConfig{
{
Expand All @@ -494,7 +510,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
Gateway: net.ParseIP(info.ncGatewayIPAddress),
},
},
Routes: routes,
Routes: resRoute,
NICType: info.nicType,
MacAddress: macAddress,
SkipDefaultRoutes: info.skipDefaultRoutes,
Expand Down

0 comments on commit 5852af3

Please sign in to comment.