fixup! cmd/tailscale: get command for printing settings

`tailscale up --accept-routes` had a different default than
`tailscale set --accept-routes` that had a different default than
`ipn.Prefs.RouteAll`.

This patch hoists the logic that was buried in `cmd/tailscale/cli` to
`ipn.Prefs.DefaultRouteAll`. Then, all three of defaults can agree.

Signed-off-by: Simon Law <sfllaw@sfllaw.ca>
This commit is contained in:
Simon Law 2025-03-18 15:46:57 -07:00
parent ebdf466f6d
commit 6f679d5bc0
No known key found for this signature in database
GPG Key ID: C535BDB0FBAD9164
4 changed files with 20 additions and 16 deletions

View File

@ -142,10 +142,6 @@ func TestGetDefaultSettings(t *testing.T) {
want := f.DefValue
switch f.Name {
case "accept-routes":
// ipn.NewPrefs sets this to true
// but tailscale up sets it on start.
want = "true"
case "auto-update":
// Unset by tailscale up.
want = "unset"

View File

@ -68,7 +68,7 @@ func newSetFlagSet(goos string, setArgs *setArgsT) *flag.FlagSet {
setf := newFlagSet("set")
setf.StringVar(&setArgs.profileName, "nickname", "", "nickname for the current account")
setf.BoolVar(&setArgs.acceptRoutes, "accept-routes", false, "accept routes advertised by other Tailscale nodes")
setf.BoolVar(&setArgs.acceptRoutes, "accept-routes", acceptRouteDefault(goos), "accept routes advertised by other Tailscale nodes")
setf.BoolVar(&setArgs.acceptDNS, "accept-dns", true, "accept DNS configuration from the admin panel")
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")
setf.BoolVar(&setArgs.exitNodeAllowLANAccess, "exit-node-allow-lan-access", false, "Allow direct access to the local network when routing traffic via an exit node")

View File

@ -39,7 +39,6 @@ import (
"tailscale.com/types/preftype"
"tailscale.com/types/views"
"tailscale.com/util/dnsname"
"tailscale.com/version"
"tailscale.com/version/distro"
)
@ -79,14 +78,8 @@ func effectiveGOOS() string {
// acceptRouteDefault returns the CLI's default value of --accept-routes as
// a function of the platform it's running on.
func acceptRouteDefault(goos string) bool {
switch goos {
case "windows":
return true
case "darwin":
return version.IsSandboxedMacOS()
default:
return false
}
var p *ipn.Prefs
return p.DefaultRouteAll(goos)
}
var upFlagSet = newUpFlagSet(effectiveGOOS(), &upArgsGlobal, "up")

View File

@ -29,6 +29,7 @@ import (
"tailscale.com/types/views"
"tailscale.com/util/dnsname"
"tailscale.com/util/syspolicy"
"tailscale.com/version"
)
// DefaultControlURL is the URL base of the control plane
@ -664,7 +665,7 @@ func NewPrefs() *Prefs {
// Provide default values for options which might be missing
// from the json data for any reason. The json can still
// override them to false.
return &Prefs{
p := &Prefs{
// ControlURL is explicitly not set to signal that
// it's not yet configured, which relaxes the CLI "up"
// safety net features. It will get set to DefaultControlURL
@ -672,7 +673,6 @@ func NewPrefs() *Prefs {
// later anyway.
ControlURL: "",
RouteAll: true,
CorpDNS: true,
WantRunning: false,
NetfilterMode: preftype.NetfilterOn,
@ -682,6 +682,8 @@ func NewPrefs() *Prefs {
Apply: opt.Bool("unset"),
},
}
p.RouteAll = p.DefaultRouteAll(runtime.GOOS)
return p
}
// ControlURLOrDefault returns the coordination server's URL base.
@ -711,6 +713,19 @@ func (p *Prefs) ControlURLOrDefault() string {
return DefaultControlURL
}
// DefaultRouteAll returns the default value of [Prefs.RouteAll] as a function
// of the platform it's running on.
func (p *Prefs) DefaultRouteAll(goos string) bool {
switch goos {
case "windows":
return true
case "darwin":
return version.IsSandboxedMacOS()
default:
return false
}
}
// AdminPageURL returns the admin web site URL for the current ControlURL.
func (p PrefsView) AdminPageURL() string { return p.ж.AdminPageURL() }