Skip to content

Commit

Permalink
Fix init node transport interface bug (#2670)
Browse files Browse the repository at this point in the history
1.Fix adding node routes crash bug, which caused by uninitialized DualStackIPs
param.

2.Fix ipv4 address and ipv6 address confused bug and return the first ipv4 and
ipv6 ips for transport interface.

Signed-off-by: Wu zhengdong <[email protected]>
  • Loading branch information
Wu zhengdong committed Aug 28, 2021
1 parent 04619b6 commit 05684da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/controller/noderoute/node_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
8 changes: 6 additions & 2 deletions pkg/agent/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (

FamilyIPv4 uint8 = 4
FamilyIPv6 uint8 = 6
// IP address lengths (bytes).
IPv6len = 16
)

func generateInterfaceName(key string, name string, useHead bool) string {
Expand Down Expand Up @@ -165,9 +167,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
}
}
}
Expand Down

0 comments on commit 05684da

Please sign in to comment.