Skip to content

Commit

Permalink
Fixed tailscale node IP dualstack mode in case of IPv4 only node
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bonafiglia <[email protected]>
  • Loading branch information
rbrtbnfgl committed Oct 9, 2023
1 parent ba750e2 commit ced25af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
22 changes: 10 additions & 12 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit ced25af

Please sign in to comment.