Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Commit e932423

Browse files
sfllawsailorfrag
authored andcommitted
cmd/tailscale: fix default for tailscale set --accept-routes
The default values for `tailscale up` and `tailscale set` are supposed to agree for all common flags. But they don’t for `--accept-routes` on Windows and from the Mac OS App Store, because `tailscale up` computes this value based on the operating system: user@host:~$ tailscale up --help 2>&1 | grep -A1 accept-routes --accept-dns, --accept-dns=false accept DNS configuration from the admin panel (default true) user@host:~$ tailscale set --help 2>&1 | grep -A1 accept-routes --accept-dns, --accept-dns=false accept DNS configuration from the admin panel Luckily, `tailscale set` uses `ipn.MaskedPrefs`, so the default values don’t logically matter. But someone will get the wrong idea if they trust the `tailscale set --help` documentation. In addition, `ipn.Prefs.RouteAll` defaults to true so it disagrees with both of the flags above. This patch makes `--accept-routes` use the same logic for in both commands by hoisting the logic that was buried in `cmd/tailscale/cli` to `ipn.Prefs.DefaultRouteAll`. Then, all three of defaults can agree. Fixes: tailscale#15319 Signed-off-by: Simon Law <sfllaw@sfllaw.ca>
1 parent 7fc9099 commit e932423

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

cmd/tailscale/cli/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func newSetFlagSet(goos string, setArgs *setArgsT) *flag.FlagSet {
6868
setf := newFlagSet("set")
6969

7070
setf.StringVar(&setArgs.profileName, "nickname", "", "nickname for the current account")
71-
setf.BoolVar(&setArgs.acceptRoutes, "accept-routes", false, "accept routes advertised by other Tailscale nodes")
71+
setf.BoolVar(&setArgs.acceptRoutes, "accept-routes", acceptRouteDefault(goos), "accept routes advertised by other Tailscale nodes")
7272
setf.BoolVar(&setArgs.acceptDNS, "accept-dns", true, "accept DNS configuration from the admin panel")
7373
setf.StringVar(&setArgs.exitNodeIP, "exit-node", "", "Tailscale exit node (IP or base name) for internet traffic, or empty string to not use an exit node")
7474
setf.BoolVar(&setArgs.exitNodeAllowLANAccess, "exit-node-allow-lan-access", false, "Allow direct access to the local network when routing traffic via an exit node")

cmd/tailscale/cli/up.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"tailscale.com/types/preftype"
4040
"tailscale.com/types/views"
4141
"tailscale.com/util/dnsname"
42-
"tailscale.com/version"
4342
"tailscale.com/version/distro"
4443
)
4544

@@ -79,14 +78,8 @@ func effectiveGOOS() string {
7978
// acceptRouteDefault returns the CLI's default value of --accept-routes as
8079
// a function of the platform it's running on.
8180
func acceptRouteDefault(goos string) bool {
82-
switch goos {
83-
case "windows":
84-
return true
85-
case "darwin":
86-
return version.IsSandboxedMacOS()
87-
default:
88-
return false
89-
}
81+
var p *ipn.Prefs
82+
return p.DefaultRouteAll(goos)
9083
}
9184

9285
var upFlagSet = newUpFlagSet(effectiveGOOS(), &upArgsGlobal, "up")

ipn/prefs.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"tailscale.com/types/views"
3030
"tailscale.com/util/dnsname"
3131
"tailscale.com/util/syspolicy"
32+
"tailscale.com/version"
3233
)
3334

3435
// DefaultControlURL is the URL base of the control plane
@@ -664,15 +665,14 @@ func NewPrefs() *Prefs {
664665
// Provide default values for options which might be missing
665666
// from the json data for any reason. The json can still
666667
// override them to false.
667-
return &Prefs{
668+
p := &Prefs{
668669
// ControlURL is explicitly not set to signal that
669670
// it's not yet configured, which relaxes the CLI "up"
670671
// safety net features. It will get set to DefaultControlURL
671672
// on first up. Or, if not, DefaultControlURL will be used
672673
// later anyway.
673674
ControlURL: "",
674675

675-
RouteAll: true,
676676
CorpDNS: true,
677677
WantRunning: false,
678678
NetfilterMode: preftype.NetfilterOn,
@@ -682,6 +682,8 @@ func NewPrefs() *Prefs {
682682
Apply: opt.Bool("unset"),
683683
},
684684
}
685+
p.RouteAll = p.DefaultRouteAll(runtime.GOOS)
686+
return p
685687
}
686688

687689
// ControlURLOrDefault returns the coordination server's URL base.
@@ -711,6 +713,19 @@ func (p *Prefs) ControlURLOrDefault() string {
711713
return DefaultControlURL
712714
}
713715

716+
// DefaultRouteAll returns the default value of [Prefs.RouteAll] as a function
717+
// of the platform it's running on.
718+
func (p *Prefs) DefaultRouteAll(goos string) bool {
719+
switch goos {
720+
case "windows":
721+
return true
722+
case "darwin":
723+
return version.IsSandboxedMacOS()
724+
default:
725+
return false
726+
}
727+
}
728+
714729
// AdminPageURL returns the admin web site URL for the current ControlURL.
715730
func (p PrefsView) AdminPageURL() string { return p.ж.AdminPageURL() }
716731

0 commit comments

Comments
 (0)