diff --git a/cmd/tailscaled/depaware-min.txt b/cmd/tailscaled/depaware-min.txt index fb12159c3..2b6eaef32 100644 --- a/cmd/tailscaled/depaware-min.txt +++ b/cmd/tailscaled/depaware-min.txt @@ -39,7 +39,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de 💣 go4.org/mem from tailscale.com/control/controlbase+ go4.org/netipx from tailscale.com/ipn/ipnlocal+ tailscale.com from tailscale.com/version - tailscale.com/appc from tailscale.com/ipn/ipnlocal tailscale.com/atomicfile from tailscale.com/ipn+ tailscale.com/client/tailscale/apitype from tailscale.com/ipn/ipnauth+ tailscale.com/cmd/tailscaled/childproc from tailscale.com/cmd/tailscaled @@ -142,7 +141,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/ipproto from tailscale.com/ipn+ tailscale.com/types/key from tailscale.com/control/controlbase+ tailscale.com/types/lazy from tailscale.com/hostinfo+ - tailscale.com/types/logger from tailscale.com/appc+ + tailscale.com/types/logger from tailscale.com/cmd/tailscaled+ tailscale.com/types/logid from tailscale.com/cmd/tailscaled+ tailscale.com/types/mapx from tailscale.com/ipn/ipnext+ tailscale.com/types/netlogfunc from tailscale.com/net/tstun+ @@ -154,19 +153,19 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/result from tailscale.com/util/lineiter tailscale.com/types/structs from tailscale.com/control/controlclient+ tailscale.com/types/tkatype from tailscale.com/control/controlclient+ - tailscale.com/types/views from tailscale.com/appc+ + tailscale.com/types/views from tailscale.com/control/controlclient+ tailscale.com/util/backoff from tailscale.com/control/controlclient+ tailscale.com/util/bufiox from tailscale.com/types/key tailscale.com/util/checkchange from tailscale.com/ipn/ipnlocal+ tailscale.com/util/cibuild from tailscale.com/health+ - tailscale.com/util/clientmetric from tailscale.com/appc+ + tailscale.com/util/clientmetric from tailscale.com/control/controlclient+ tailscale.com/util/cloudenv from tailscale.com/hostinfo+ tailscale.com/util/cloudinfo from tailscale.com/wgengine/magicsock tailscale.com/util/ctxkey from tailscale.com/client/tailscale/apitype+ tailscale.com/util/def from tailscale.com/ipn/localapi - tailscale.com/util/dnsname from tailscale.com/appc+ + tailscale.com/util/dnsname from tailscale.com/hostinfo+ tailscale.com/util/eventbus from tailscale.com/control/controlclient+ - tailscale.com/util/execqueue from tailscale.com/appc+ + tailscale.com/util/execqueue from tailscale.com/control/controlclient+ tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal tailscale.com/util/groupmember from tailscale.com/ipn/ipnauth tailscale.com/util/httpbody from tailscale.com/control/controlclient+ @@ -184,7 +183,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/util/ringlog from tailscale.com/wgengine/magicsock tailscale.com/util/set from tailscale.com/control/controlclient+ tailscale.com/util/singleflight from tailscale.com/control/controlclient+ - tailscale.com/util/slicesx from tailscale.com/appc+ + tailscale.com/util/slicesx from tailscale.com/control/controlclient+ tailscale.com/util/syspolicy/pkey from tailscale.com/cmd/tailscaled+ tailscale.com/util/syspolicy/policyclient from tailscale.com/cmd/tailscaled+ tailscale.com/util/syspolicy/ptype from tailscale.com/ipn/ipnlocal+ diff --git a/cmd/tailscaled/depaware-minbox.txt b/cmd/tailscaled/depaware-minbox.txt index caf037ae0..8804c6d2d 100644 --- a/cmd/tailscaled/depaware-minbox.txt +++ b/cmd/tailscaled/depaware-minbox.txt @@ -44,7 +44,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de 💣 go4.org/mem from tailscale.com/control/controlbase+ go4.org/netipx from tailscale.com/ipn/ipnlocal+ tailscale.com from tailscale.com/version - tailscale.com/appc from tailscale.com/ipn/ipnlocal tailscale.com/atomicfile from tailscale.com/ipn+ tailscale.com/client/local from tailscale.com/client/tailscale+ tailscale.com/client/tailscale from tailscale.com/internal/client/tailscale @@ -161,7 +160,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/ipproto from tailscale.com/ipn+ tailscale.com/types/key from tailscale.com/client/local+ tailscale.com/types/lazy from tailscale.com/hostinfo+ - tailscale.com/types/logger from tailscale.com/appc+ + tailscale.com/types/logger from tailscale.com/cmd/tailscale/cli+ tailscale.com/types/logid from tailscale.com/cmd/tailscaled+ tailscale.com/types/mapx from tailscale.com/ipn/ipnext+ tailscale.com/types/netlogfunc from tailscale.com/net/tstun+ @@ -173,19 +172,19 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/result from tailscale.com/util/lineiter tailscale.com/types/structs from tailscale.com/control/controlclient+ tailscale.com/types/tkatype from tailscale.com/control/controlclient+ - tailscale.com/types/views from tailscale.com/appc+ + tailscale.com/types/views from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/backoff from tailscale.com/control/controlclient+ tailscale.com/util/bufiox from tailscale.com/types/key tailscale.com/util/checkchange from tailscale.com/ipn/ipnlocal+ tailscale.com/util/cibuild from tailscale.com/health+ - tailscale.com/util/clientmetric from tailscale.com/appc+ + tailscale.com/util/clientmetric from tailscale.com/client/local+ tailscale.com/util/cloudenv from tailscale.com/hostinfo+ tailscale.com/util/cloudinfo from tailscale.com/wgengine/magicsock tailscale.com/util/ctxkey from tailscale.com/client/tailscale/apitype+ tailscale.com/util/def from tailscale.com/ipn/localapi - tailscale.com/util/dnsname from tailscale.com/appc+ + tailscale.com/util/dnsname from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/eventbus from tailscale.com/client/local+ - tailscale.com/util/execqueue from tailscale.com/appc+ + tailscale.com/util/execqueue from tailscale.com/control/controlclient+ tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal tailscale.com/util/groupmember from tailscale.com/ipn/ipnauth tailscale.com/util/httpbody from tailscale.com/control/controlclient+ @@ -205,7 +204,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/util/ringlog from tailscale.com/wgengine/magicsock tailscale.com/util/set from tailscale.com/control/controlclient+ tailscale.com/util/singleflight from tailscale.com/control/controlclient+ - tailscale.com/util/slicesx from tailscale.com/appc+ + tailscale.com/util/slicesx from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/syspolicy/pkey from tailscale.com/cmd/tailscaled+ tailscale.com/util/syspolicy/policyclient from tailscale.com/cmd/tailscaled+ tailscale.com/util/syspolicy/ptype from tailscale.com/ipn/ipnlocal+ diff --git a/cmd/tailscaled/deps_test.go b/cmd/tailscaled/deps_test.go index 337ead2ef..38683f5eb 100644 --- a/cmd/tailscaled/deps_test.go +++ b/cmd/tailscaled/deps_test.go @@ -81,6 +81,21 @@ func TestOmitDNSResolveCache(t *testing.T) { }.Check(t) } +func TestOmitAppConnectors(t *testing.T) { + const msg = "unexpected app connector usage with ts_omit_appconnectors" + deptest.DepChecker{ + GOOS: "linux", + GOARCH: "amd64", + // conn25 also uses appc, so omit it too to check that nothing + // else pulls appc in. + Tags: "ts_omit_appconnectors,ts_omit_conn25,ts_include_cli", + BadDeps: map[string]string{ + "tailscale.com/appc": msg, + "tailscale.com/feature/appconnectors": msg, + }, + }.Check(t) +} + func TestOmitSyspolicy(t *testing.T) { const msg = "unexpected syspolicy usage with ts_omit_syspolicy" deptest.DepChecker{ diff --git a/ipn/ipnlocal/appconnector.go b/ipn/ipnlocal/appconnector.go new file mode 100644 index 000000000..83a866f22 --- /dev/null +++ b/ipn/ipnlocal/appconnector.go @@ -0,0 +1,39 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build !ts_omit_appconnectors + +package ipnlocal + +import ( + "tailscale.com/appc" + "tailscale.com/types/appctype" + "tailscale.com/types/logger" + "tailscale.com/util/eventbus" +) + +// appcAppConnector is [appc.AppConnector] in builds that include app +// connectors. Builds with ts_omit_appconnectors substitute a stub type +// (see appconnector_omit.go) so that this package does not import appc +// at all, which keeps appc and its dependencies out of those binaries. +type appcAppConnector = appc.AppConnector + +// newAppConnector returns a new [appc.AppConnector] publishing to bus, +// seeded with the previously stored routes in ri (which may be nil). +func newAppConnector(logf logger.Logf, bus *eventbus.Bus, ri *appctype.RouteInfo, storeRoutes bool) *appcAppConnector { + return appc.NewAppConnector(appc.Config{ + Logf: logf, + EventBus: bus, + RouteInfo: ri, + HasStoredRoutes: storeRoutes, + }) +} + +// AppConnector returns the current AppConnector, or nil if not configured. +// +// TODO(nickkhyl): move app connectors to [nodeBackend], or perhaps a feature package? +func (b *LocalBackend) AppConnector() *appc.AppConnector { + b.mu.Lock() + defer b.mu.Unlock() + return b.appConnector +} diff --git a/ipn/ipnlocal/appconnector_omit.go b/ipn/ipnlocal/appconnector_omit.go new file mode 100644 index 000000000..8f498cb00 --- /dev/null +++ b/ipn/ipnlocal/appconnector_omit.go @@ -0,0 +1,35 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build ts_omit_appconnectors + +package ipnlocal + +import ( + "net/netip" + + "tailscale.com/types/appctype" + "tailscale.com/types/logger" + "tailscale.com/util/eventbus" +) + +// appcAppConnector stands in for [tailscale.com/appc.AppConnector] in +// builds without app connectors, so that this package does not import +// appc. Its methods exist only so that the shared code in local.go type +// checks; they are never reached, because every caller first checks +// [buildfeatures.HasAppConnectors] and b.appConnector is always nil. +type appcAppConnector struct{} + +func newAppConnector(logf logger.Logf, bus *eventbus.Bus, ri *appctype.RouteInfo, storeRoutes bool) *appcAppConnector { + panic("unreachable with ts_omit_appconnectors") +} + +func (*appcAppConnector) Close() {} +func (*appcAppConnector) ShouldStoreRoutes() bool { return false } +func (*appcAppConnector) UpdateDomainsAndRoutes(domains []string, routes []netip.Prefix) {} +func (*appcAppConnector) DomainRoutes() map[string][]netip.Addr { return nil } +func (*appcAppConnector) ObserveDNSResponse(res []byte) error { return nil } +func (*appcAppConnector) ClearRoutes() error { return nil } + +// AppConnector returns nil; app connectors are omitted from this build. +func (b *LocalBackend) AppConnector() *appcAppConnector { return nil } diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index fa2e6a987..2f6de2f11 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -35,7 +35,6 @@ import ( "go4.org/mem" "go4.org/netipx" "golang.org/x/net/dns/dnsmessage" - "tailscale.com/appc" "tailscale.com/client/tailscale/apitype" "tailscale.com/control/controlclient" "tailscale.com/control/controlknobs" @@ -325,10 +324,10 @@ type LocalBackend struct { conf *conffile.Config // latest parsed config, or nil if not in declarative mode pm *profileManager // mu guards access lastFilterInputs *filterInputs - httpTestClient *http.Client // for controlclient. nil by default, used by tests. - ccGen clientGen // function for producing controlclient; lazily populated - sshServer SSHServer // or nil, initialized lazily. - appConnector *appc.AppConnector // or nil, initialized when configured. + httpTestClient *http.Client // for controlclient. nil by default, used by tests. + ccGen clientGen // function for producing controlclient; lazily populated + sshServer SSHServer // or nil, initialized lazily. + appConnector *appcAppConnector // or nil, initialized when configured. // notifyCancel cancels notifications to the current SetNotifyCallback. notifyCancel context.CancelFunc cc controlclient.Client // TODO(nickkhyl): move to nodeBackend @@ -6012,12 +6011,7 @@ func (b *LocalBackend) reconfigAppConnectorLocked(selfNode tailcfg.NodeView, pre b.logf("Unsuccessful Read RouteInfo: %v", err) } b.appConnector.Close() // clean up a previous connector (safe on nil) - b.appConnector = appc.NewAppConnector(appc.Config{ - Logf: b.logf, - EventBus: b.sys.Bus.Get(), - RouteInfo: ri, - HasStoredRoutes: shouldStoreRoutes, - }) + b.appConnector = newAppConnector(b.logf, b.sys.Bus.Get(), ri, shouldStoreRoutes) } if !selfNode.Valid() { return @@ -7910,18 +7904,6 @@ func (b *LocalBackend) OfferingAppConnector() bool { return b.appConnector != nil } -// AppConnector returns the current AppConnector, or nil if not configured. -// -// TODO(nickkhyl): move app connectors to [nodeBackend], or perhaps a feature package? -func (b *LocalBackend) AppConnector() *appc.AppConnector { - if !buildfeatures.HasAppConnectors { - return nil - } - b.mu.Lock() - defer b.mu.Unlock() - return b.appConnector -} - // allowExitNodeDNSProxyToServeName reports whether the Exit Node DNS // proxy is allowed to serve responses for the provided DNS name. func (b *LocalBackend) allowExitNodeDNSProxyToServeName(name string) bool { @@ -8604,7 +8586,7 @@ func (b *LocalBackend) ObserveDNSResponse(res []byte) error { if !buildfeatures.HasAppConnectors { return nil } - var appConnector *appc.AppConnector + var appConnector *appcAppConnector b.mu.Lock() if b.appConnector == nil { b.mu.Unlock()