diff --git a/pkg/agent/controller/noderoute/node_route_controller.go b/pkg/agent/controller/noderoute/node_route_controller.go index 4d8ecf1e967..c2feea33eed 100644 --- a/pkg/agent/controller/noderoute/node_route_controller.go +++ b/pkg/agent/controller/noderoute/node_route_controller.go @@ -739,7 +739,7 @@ func getNodeMAC(node *corev1.Node) (net.HardwareAddr, error) { } func (c *Controller) getNodeTransportAddrs(node *corev1.Node) (*utilip.DualStackIPs, error) { - var transportAddrs *utilip.DualStackIPs + transportAddrs := &utilip.DualStackIPs{} if c.networkConfig.TransportIface != "" { transportAddrsStr := node.Annotations[types.NodeTransportAddressAnnotationKey] if transportAddrsStr != "" { diff --git a/pkg/agent/util/net.go b/pkg/agent/util/net.go index abaee70f683..dec5cf412c1 100644 --- a/pkg/agent/util/net.go +++ b/pkg/agent/util/net.go @@ -165,9 +165,11 @@ func GetIPNetDeviceByName(ifaceName string) (v4IPNet *net.IPNet, v6IPNet *net.IP if ipNet, ok := addr.(*net.IPNet); ok { if ipNet.IP.IsGlobalUnicast() { if ipNet.IP.To4() != nil { + if v4IPNet == nil { + v4IPNet = ipNet + } + } else if v6IPNet == nil { v6IPNet = ipNet - } else { - v4IPNet = ipNet } } }