in common/core/network.go [240:288]
func addEndpointGatewaysFromConfig(
endpointInfo *network.EndpointInfo,
cniConfig *cni.NetworkConfig) {
defaultDestipv4, defaultDestipv4Network, _ := net.ParseCIDR("0.0.0.0/0")
defaultDestipv6, defaultDestipv6Network, _ := net.ParseCIDR("::/0")
for _, addr := range cniConfig.AdditionalRoutes {
var isv4 bool
if addr.GW.To4() != nil {
isv4 = true
}
if isv4 {
if endpointInfo.Gateway == nil {
logrus.Debugf("[cni-net] Found no ipv4 gateway")
m1, _ := addr.Dst.Mask.Size()
m2, _ := defaultDestipv4Network.Mask.Size()
if m1 == m2 &&
addr.Dst.IP.Equal(defaultDestipv4) {
endpointInfo.Gateway = addr.GW
logrus.Debugf("[cni-net] Assigned % as ipv4 gateway", endpointInfo.Gateway.String())
}
}
} else {
if endpointInfo.Gateway6 == nil {
logrus.Debugf("[cni-net] Found no ipv6 gateway")
m1, _ := addr.Dst.Mask.Size()
m2, _ := defaultDestipv6Network.Mask.Size()
if m1 == m2 &&
addr.Dst.IP.Equal(defaultDestipv6) {
endpointInfo.Gateway6 = addr.GW
logrus.Debugf("[cni-net] Assigned % as ipv6 gateway", endpointInfo.Gateway6.String())
}
}
}
if endpointInfo.Gateway != nil && endpointInfo.Gateway6 != nil {
break
}
}
}