cmd/tailscale/cli: add support for tailscale {up,set} --exit-node=auto:any

If the specified exit node string starts with "auto:" (i.e., can be parsed as an ipn.ExitNodeExpression),
we update ipn.Prefs.AutoExitNode instead of ipn.Prefs.ExitNodeID.

Fixes #16459

Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
Nick Khyl
2025-07-09 12:07:44 -05:00
committed by Nick Khyl
parent cc2f4ac921
commit c5fdf9e1db
3 changed files with 34 additions and 6 deletions
+22 -2
View File
@@ -972,8 +972,7 @@ func TestPrefFlagMapping(t *testing.T) {
// No CLI flag for this.
continue
case "AutoExitNode":
// TODO(nickkhyl): should be handled by tailscale {set,up} --exit-node.
// See tailscale/tailscale#16459.
// Handled by tailscale {set,up} --exit-node=auto:any.
continue
}
t.Errorf("unexpected new ipn.Pref field %q is not handled by up.go (see addPrefFlagMapping and checkForAccidentalSettingReverts)", prefName)
@@ -1338,6 +1337,27 @@ func TestUpdatePrefs(t *testing.T) {
}
},
},
{
name: "auto_exit_node",
flags: []string{"--exit-node=auto:any"},
curPrefs: &ipn.Prefs{
ControlURL: ipn.DefaultControlURL,
CorpDNS: true, // enabled by [ipn.NewPrefs] by default
NetfilterMode: preftype.NetfilterOn, // enabled by [ipn.NewPrefs] by default
},
wantJustEditMP: &ipn.MaskedPrefs{
WantRunningSet: true, // enabled by default for tailscale up
AutoExitNodeSet: true,
ExitNodeIDSet: true, // we want ExitNodeID cleared
ExitNodeIPSet: true, // same for ExitNodeIP
},
env: upCheckEnv{backendState: "Running"},
checkUpdatePrefsMutations: func(t *testing.T, newPrefs *ipn.Prefs) {
if newPrefs.AutoExitNode != ipn.AnyExitNode {
t.Errorf("AutoExitNode: got %q; want %q", newPrefs.AutoExitNode, ipn.AnyExitNode)
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {