mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-25 14:21:29 +02:00
all: use buildfeatures consts in a few more places
Saves ~25 KB. Updates #12614 Change-Id: I7b976e57819a0d2692824d779c8cc98033df0d30 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
44e1d735c3
commit
541a4ed5b4
@ -752,6 +752,9 @@ func (lc *Client) PushFile(ctx context.Context, target tailcfg.StableNodeID, siz
|
||||
// machine is properly configured to forward IP packets as a subnet router
|
||||
// or exit node.
|
||||
func (lc *Client) CheckIPForwarding(ctx context.Context) error {
|
||||
if !buildfeatures.HasAdvertiseRoutes {
|
||||
return nil
|
||||
}
|
||||
body, err := lc.get200(ctx, "/localapi/v0/check-ip-forwarding")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -24,6 +24,7 @@ import (
|
||||
shellquote "github.com/kballard/go-shellquote"
|
||||
"github.com/peterbourgon/ff/v3/ffcli"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
"tailscale.com/feature/buildfeatures"
|
||||
_ "tailscale.com/feature/condregister/oauthkey"
|
||||
"tailscale.com/health/healthmsg"
|
||||
"tailscale.com/internal/client/tailscale"
|
||||
@ -1136,7 +1137,8 @@ func exitNodeIP(p *ipn.Prefs, st *ipnstate.Status) (ip netip.Addr) {
|
||||
}
|
||||
|
||||
func warnOnAdvertiseRoutes(ctx context.Context, prefs *ipn.Prefs) {
|
||||
if len(prefs.AdvertiseRoutes) > 0 || prefs.AppConnector.Advertise {
|
||||
if buildfeatures.HasAdvertiseRoutes && len(prefs.AdvertiseRoutes) > 0 ||
|
||||
buildfeatures.HasAppConnectors && prefs.AppConnector.Advertise {
|
||||
// TODO(jwhited): compress CheckIPForwarding and CheckUDPGROForwarding
|
||||
// into a single HTTP req.
|
||||
if err := localClient.CheckIPForwarding(ctx); err != nil {
|
||||
|
||||
@ -945,7 +945,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
||||
ConnectionHandleForTest: connectionHandleForTest,
|
||||
}
|
||||
var extraDebugFlags []string
|
||||
if hi != nil && c.netMon != nil && !c.skipIPForwardingCheck &&
|
||||
if buildfeatures.HasAdvertiseRoutes && hi != nil && c.netMon != nil && !c.skipIPForwardingCheck &&
|
||||
ipForwardingBroken(hi.RoutableIPs, c.netMon.InterfaceState()) {
|
||||
extraDebugFlags = append(extraDebugFlags, "warn-ip-forwarding-off")
|
||||
}
|
||||
|
||||
@ -586,7 +586,12 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
|
||||
func (b *LocalBackend) consumeEventbusTopics(ec *eventbus.Client) func(*eventbus.Client) {
|
||||
clientVersionSub := eventbus.Subscribe[tailcfg.ClientVersion](ec)
|
||||
autoUpdateSub := eventbus.Subscribe[controlclient.AutoUpdate](ec)
|
||||
healthChangeSub := eventbus.Subscribe[health.Change](ec)
|
||||
|
||||
var healthChange <-chan health.Change
|
||||
if buildfeatures.HasHealth {
|
||||
healthChangeSub := eventbus.Subscribe[health.Change](ec)
|
||||
healthChange = healthChangeSub.Events()
|
||||
}
|
||||
changeDeltaSub := eventbus.Subscribe[netmon.ChangeDelta](ec)
|
||||
|
||||
var portlist <-chan PortlistServices
|
||||
@ -604,7 +609,7 @@ func (b *LocalBackend) consumeEventbusTopics(ec *eventbus.Client) func(*eventbus
|
||||
b.onClientVersion(&clientVersion)
|
||||
case au := <-autoUpdateSub.Events():
|
||||
b.onTailnetDefaultAutoUpdate(au.Value)
|
||||
case change := <-healthChangeSub.Events():
|
||||
case change := <-healthChange:
|
||||
b.onHealthChange(change)
|
||||
case changeDelta := <-changeDeltaSub.Events():
|
||||
b.linkChange(&changeDelta)
|
||||
@ -996,6 +1001,9 @@ var (
|
||||
)
|
||||
|
||||
func (b *LocalBackend) onHealthChange(change health.Change) {
|
||||
if !buildfeatures.HasHealth {
|
||||
return
|
||||
}
|
||||
if change.WarnableChanged {
|
||||
w := change.Warnable
|
||||
us := change.UnhealthyState
|
||||
@ -6025,10 +6033,10 @@ func (b *LocalBackend) resolveExitNode() (changed bool) {
|
||||
//
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) reconcilePrefsLocked(prefs *ipn.Prefs) (changed bool) {
|
||||
if b.applySysPolicyLocked(prefs) {
|
||||
if buildfeatures.HasSystemPolicy && b.applySysPolicyLocked(prefs) {
|
||||
changed = true
|
||||
}
|
||||
if b.resolveExitNodeInPrefsLocked(prefs) {
|
||||
if buildfeatures.HasUseExitNode && b.resolveExitNodeInPrefsLocked(prefs) {
|
||||
changed = true
|
||||
}
|
||||
if changed {
|
||||
@ -6043,6 +6051,9 @@ func (b *LocalBackend) reconcilePrefsLocked(prefs *ipn.Prefs) (changed bool) {
|
||||
//
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) resolveExitNodeInPrefsLocked(prefs *ipn.Prefs) (changed bool) {
|
||||
if !buildfeatures.HasUseExitNode {
|
||||
return false
|
||||
}
|
||||
if b.resolveAutoExitNodeLocked(prefs) {
|
||||
changed = true
|
||||
}
|
||||
@ -6338,6 +6349,9 @@ func peerAPIPorts(peer tailcfg.NodeView) (p4, p6 uint16) {
|
||||
}
|
||||
|
||||
func (b *LocalBackend) CheckIPForwarding() error {
|
||||
if !buildfeatures.HasAdvertiseRoutes {
|
||||
return nil
|
||||
}
|
||||
if b.sys.IsNetstackRouter() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -72,15 +72,12 @@ var handler = map[string]LocalAPIHandler{
|
||||
// The other /localapi/v0/NAME handlers are exact matches and contain only NAME
|
||||
// without a trailing slash:
|
||||
"alpha-set-device-attrs": (*Handler).serveSetDeviceAttrs, // see tailscale/corp#24690
|
||||
"check-ip-forwarding": (*Handler).serveCheckIPForwarding,
|
||||
"check-prefs": (*Handler).serveCheckPrefs,
|
||||
"check-reverse-path-filtering": (*Handler).serveCheckReversePathFiltering,
|
||||
"check-udp-gro-forwarding": (*Handler).serveCheckUDPGROForwarding,
|
||||
"derpmap": (*Handler).serveDERPMap,
|
||||
"dial": (*Handler).serveDial,
|
||||
"disconnect-control": (*Handler).disconnectControl,
|
||||
"dns-osconfig": (*Handler).serveDNSOSConfig,
|
||||
"dns-query": (*Handler).serveDNSQuery,
|
||||
"goroutines": (*Handler).serveGoroutines,
|
||||
"handle-push-message": (*Handler).serveHandlePushMessage,
|
||||
"id-token": (*Handler).serveIDToken,
|
||||
@ -111,6 +108,9 @@ func init() {
|
||||
if buildfeatures.HasAppConnectors {
|
||||
Register("appc-route-info", (*Handler).serveGetAppcRouteInfo)
|
||||
}
|
||||
if buildfeatures.HasAdvertiseRoutes {
|
||||
Register("check-ip-forwarding", (*Handler).serveCheckIPForwarding)
|
||||
}
|
||||
if buildfeatures.HasUseExitNode {
|
||||
Register("suggest-exit-node", (*Handler).serveSuggestExitNode)
|
||||
Register("set-use-exit-node-enabled", (*Handler).serveSetUseExitNodeEnabled)
|
||||
@ -122,6 +122,10 @@ func init() {
|
||||
Register("bugreport", (*Handler).serveBugReport)
|
||||
Register("pprof", (*Handler).servePprof)
|
||||
}
|
||||
if buildfeatures.HasDNS {
|
||||
Register("dns-osconfig", (*Handler).serveDNSOSConfig)
|
||||
Register("dns-query", (*Handler).serveDNSQuery)
|
||||
}
|
||||
}
|
||||
|
||||
// Register registers a new LocalAPI handler for the given name.
|
||||
|
||||
64
ipn/prefs.go
64
ipn/prefs.go
@ -532,12 +532,16 @@ func (p *Prefs) Pretty() string { return p.pretty(runtime.GOOS) }
|
||||
func (p *Prefs) pretty(goos string) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("Prefs{")
|
||||
fmt.Fprintf(&sb, "ra=%v ", p.RouteAll)
|
||||
fmt.Fprintf(&sb, "dns=%v want=%v ", p.CorpDNS, p.WantRunning)
|
||||
if p.RunSSH {
|
||||
if buildfeatures.HasUseRoutes {
|
||||
fmt.Fprintf(&sb, "ra=%v ", p.RouteAll)
|
||||
}
|
||||
if buildfeatures.HasDNS {
|
||||
fmt.Fprintf(&sb, "dns=%v want=%v ", p.CorpDNS, p.WantRunning)
|
||||
}
|
||||
if buildfeatures.HasSSH && p.RunSSH {
|
||||
sb.WriteString("ssh=true ")
|
||||
}
|
||||
if p.RunWebClient {
|
||||
if buildfeatures.HasWebClient && p.RunWebClient {
|
||||
sb.WriteString("webclient=true ")
|
||||
}
|
||||
if p.LoggedOut {
|
||||
@ -552,26 +556,30 @@ func (p *Prefs) pretty(goos string) string {
|
||||
if p.ShieldsUp {
|
||||
sb.WriteString("shields=true ")
|
||||
}
|
||||
if p.ExitNodeIP.IsValid() {
|
||||
fmt.Fprintf(&sb, "exit=%v lan=%t ", p.ExitNodeIP, p.ExitNodeAllowLANAccess)
|
||||
} else if !p.ExitNodeID.IsZero() {
|
||||
fmt.Fprintf(&sb, "exit=%v lan=%t ", p.ExitNodeID, p.ExitNodeAllowLANAccess)
|
||||
if buildfeatures.HasUseExitNode {
|
||||
if p.ExitNodeIP.IsValid() {
|
||||
fmt.Fprintf(&sb, "exit=%v lan=%t ", p.ExitNodeIP, p.ExitNodeAllowLANAccess)
|
||||
} else if !p.ExitNodeID.IsZero() {
|
||||
fmt.Fprintf(&sb, "exit=%v lan=%t ", p.ExitNodeID, p.ExitNodeAllowLANAccess)
|
||||
}
|
||||
if p.AutoExitNode.IsSet() {
|
||||
fmt.Fprintf(&sb, "auto=%v ", p.AutoExitNode)
|
||||
}
|
||||
}
|
||||
if p.AutoExitNode.IsSet() {
|
||||
fmt.Fprintf(&sb, "auto=%v ", p.AutoExitNode)
|
||||
}
|
||||
if len(p.AdvertiseRoutes) > 0 || goos == "linux" {
|
||||
fmt.Fprintf(&sb, "routes=%v ", p.AdvertiseRoutes)
|
||||
}
|
||||
if len(p.AdvertiseRoutes) > 0 || p.NoSNAT {
|
||||
fmt.Fprintf(&sb, "snat=%v ", !p.NoSNAT)
|
||||
}
|
||||
if len(p.AdvertiseRoutes) > 0 || p.NoStatefulFiltering.EqualBool(true) {
|
||||
// Only print if we're advertising any routes, or the user has
|
||||
// turned off stateful filtering (NoStatefulFiltering=true ⇒
|
||||
// StatefulFiltering=false).
|
||||
bb, _ := p.NoStatefulFiltering.Get()
|
||||
fmt.Fprintf(&sb, "statefulFiltering=%v ", !bb)
|
||||
if buildfeatures.HasAdvertiseRoutes {
|
||||
if len(p.AdvertiseRoutes) > 0 || goos == "linux" {
|
||||
fmt.Fprintf(&sb, "routes=%v ", p.AdvertiseRoutes)
|
||||
}
|
||||
if len(p.AdvertiseRoutes) > 0 || p.NoSNAT {
|
||||
fmt.Fprintf(&sb, "snat=%v ", !p.NoSNAT)
|
||||
}
|
||||
if len(p.AdvertiseRoutes) > 0 || p.NoStatefulFiltering.EqualBool(true) {
|
||||
// Only print if we're advertising any routes, or the user has
|
||||
// turned off stateful filtering (NoStatefulFiltering=true ⇒
|
||||
// StatefulFiltering=false).
|
||||
bb, _ := p.NoStatefulFiltering.Get()
|
||||
fmt.Fprintf(&sb, "statefulFiltering=%v ", !bb)
|
||||
}
|
||||
}
|
||||
if len(p.AdvertiseTags) > 0 {
|
||||
fmt.Fprintf(&sb, "tags=%s ", strings.Join(p.AdvertiseTags, ","))
|
||||
@ -594,9 +602,13 @@ func (p *Prefs) pretty(goos string) string {
|
||||
if p.NetfilterKind != "" {
|
||||
fmt.Fprintf(&sb, "netfilterKind=%s ", p.NetfilterKind)
|
||||
}
|
||||
sb.WriteString(p.AutoUpdate.Pretty())
|
||||
sb.WriteString(p.AppConnector.Pretty())
|
||||
if p.RelayServerPort != nil {
|
||||
if buildfeatures.HasClientUpdate {
|
||||
sb.WriteString(p.AutoUpdate.Pretty())
|
||||
}
|
||||
if buildfeatures.HasAppConnectors {
|
||||
sb.WriteString(p.AppConnector.Pretty())
|
||||
}
|
||||
if buildfeatures.HasRelayServer && p.RelayServerPort != nil {
|
||||
fmt.Fprintf(&sb, "relayServerPort=%d ", *p.RelayServerPort)
|
||||
}
|
||||
if p.Persist != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user