From ced25af5b1d591927860f1003abf41361ee15d34 Mon Sep 17 00:00:00 2001 From: Roberto Bonafiglia Date: Tue, 3 Oct 2023 12:28:13 +0200 Subject: [PATCH] Fixed tailscale node IP dualstack mode in case of IPv4 only node Signed-off-by: Roberto Bonafiglia --- pkg/agent/config/config.go | 22 ++++++++++------------ pkg/cli/server/server.go | 8 +------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index 817a70514eae..b0a2c8e0da53 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -408,20 +408,18 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N // Pass ipv4, ipv6 or both depending on nodeIPs mode var vpnIPs []net.IP - dualNode, err := utilsnet.IsDualStackIPs(nodeIPs) - if err != nil { - return nil, errors.Wrapf(err, "failed to validate node-ip: %v", nodeIPs) - } - if dualNode && vpnInfo.IPv4Address != nil && vpnInfo.IPv6Address != nil { - vpnIPs = append(vpnIPs, vpnInfo.IPv4Address, vpnInfo.IPv6Address) - } else { - if utilsnet.IsIPv4(nodeIPs[0]) && vpnInfo.IPv4Address != nil { - vpnIPs = append(vpnIPs, vpnInfo.IPv4Address) - } else if utilsnet.IsIPv6(nodeIPs[0]) && vpnInfo.IPv6Address != nil { + if utilsnet.IsIPv4(nodeIPs[0]) && vpnInfo.IPv4Address != nil { + vpnIPs = append(vpnIPs, vpnInfo.IPv4Address) + if vpnInfo.IPv6Address != nil { vpnIPs = append(vpnIPs, vpnInfo.IPv6Address) - } else { - return nil, errors.Errorf("address family mismatch when assigning VPN addresses to node: node=%v, VPN ipv4=%v ipv6=%v", nodeIPs, vpnInfo.IPv4Address, vpnInfo.IPv6Address) } + } else if utilsnet.IsIPv6(nodeIPs[0]) && vpnInfo.IPv6Address != nil { + vpnIPs = append(vpnIPs, vpnInfo.IPv6Address) + if vpnInfo.IPv4Address != nil { + vpnIPs = append(vpnIPs, vpnInfo.IPv4Address) + } + } else { + return nil, errors.Errorf("address family mismatch when assigning VPN addresses to node: node=%v, VPN ipv4=%v ipv6=%v", nodeIPs, vpnInfo.IPv4Address, vpnInfo.IPv6Address) } // Overwrite nodeip and flannel interface and throw a warning if user explicitly set those parameters diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 4fa77d4b2dd2..e0ab7d5110f8 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -248,14 +248,8 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont return err } - logrus.Debugf("Processing vpn node-ip based on the detected nodeIPs: %v", nodeIPs) - dualNode, err := utilsnet.IsDualStackIPs(nodeIPs) - if err != nil { - return errors.Wrapf(err, "failed to validate node-ip: %v", nodeIPs) - } - // If we are in ipv6-only mode, we should pass the ipv6 address. Otherwise, ipv4 - if !dualNode && utilsnet.IsIPv6(nodeIPs[0]) { + if utilsnet.IsIPv6(nodeIPs[0]) { if vpnInfo.IPv6Address != nil { logrus.Infof("Changed advertise-address to %v due to VPN", vpnInfo.IPv6Address) if serverConfig.ControlConfig.AdvertiseIP != "" {