Skip to content

Commit 2d5e9e4

Browse files
committed
fix duplicated default routes on Linux
1 parent c0ef702 commit 2d5e9e4

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

cni/network/invoker_cns.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,16 +488,13 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
488488
return err
489489
}
490490

491-
defaultRouteDstPrefix := network.Ipv4DefaultRouteDstPrefix
492-
ncgw := net.ParseIP(info.ncGatewayIPAddress)
493-
494491
resRoute := addResult.interfaceInfo[key].Routes
495492
if len(routes) > 0 {
496493
resRoute = append(resRoute, routes...)
497494
} else { // add default route to customer vnet on swiftv2 windows
498495
resRoute = append(resRoute, network.RouteInfo{
499-
Dst: defaultRouteDstPrefix,
500-
Gw: ncgw,
496+
Dst: network.Ipv4DefaultRouteDstPrefix,
497+
Gw: net.ParseIP(info.ncGatewayIPAddress),
501498
})
502499
}
503500

network/transparent_endpointclient_linux.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (client *TransparentEndpointClient) ConfigureContainerInterfacesAndRoutes(e
233233

234234
// add route for virtualgwip
235235
// ip route add 169.254.1.1/32 dev eth0
236-
virtualGwIP, virtualGwNet, _ := net.ParseCIDR(virtualGwIPString)
236+
_, virtualGwNet, _ := net.ParseCIDR(virtualGwIPString)
237237
routeInfo := RouteInfo{
238238
Dst: *virtualGwNet,
239239
Scope: netlink.RT_SCOPE_LINK,
@@ -242,18 +242,7 @@ func (client *TransparentEndpointClient) ConfigureContainerInterfacesAndRoutes(e
242242
return newErrorTransparentEndpointClient(err)
243243
}
244244

245-
if !epInfo.SkipDefaultRoutes {
246-
// ip route add default via 169.254.1.1 dev eth0
247-
_, defaultIPNet, _ := net.ParseCIDR(defaultGwCidr)
248-
dstIP := net.IPNet{IP: net.ParseIP(defaultGw), Mask: defaultIPNet.Mask}
249-
routeInfo = RouteInfo{
250-
Dst: dstIP,
251-
Gw: virtualGwIP,
252-
}
253-
if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, []RouteInfo{routeInfo}); err != nil {
254-
return err
255-
}
256-
} else if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, epInfo.Routes); err != nil {
245+
if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, epInfo.Routes); err != nil {
257246
return newErrorTransparentEndpointClient(err)
258247
}
259248

0 commit comments

Comments
 (0)