Skip to content

Commit f27b2cf

Browse files
committed
appc,cmd/sniproxy,ipn/ipnlocal: split sniproxy configuration code out of appc
The design changed during integration and testing, resulting in the earlier implementation growing in the appc package to be intended now only for the sniproxy implementation. That code is moved to it's final location, and the current App Connector code is now renamed. Updates tailscale/corp#15437 Signed-off-by: James Tucker <james@tailscale.com>
1 parent 6c0ac8b commit f27b2cf

File tree

11 files changed

+43
-51
lines changed

11 files changed

+43
-51
lines changed

appc/embedded.go renamed to appc/appconnector.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
// Package appc implements App Connectors. An AppConnector provides domain
5-
// oriented routing of traffic.
4+
// Package appc implements App Connectors.
5+
// An AppConnector provides DNS domain oriented routing of traffic. An App
6+
// Connector becomes a DNS server for a peer, authoritative for the set of
7+
// configured domains. DNS resolution of the target domain triggers dynamic
8+
// publication of routes to ensure that traffic to the domain is routed through
9+
// the App Connector.
610
package appc
711

812
import (
@@ -17,12 +21,6 @@ import (
1721
"tailscale.com/types/views"
1822
)
1923

20-
/*
21-
* TODO(raggi): the sniproxy servicing portions of this package will be moved
22-
* into the sniproxy or deprecated at some point, when doing so is not
23-
* disruptive. At that time EmbeddedAppConnector can be renamed to AppConnector.
24-
*/
25-
2624
// RouteAdvertiser is an interface that allows the AppConnector to advertise
2725
// newly discovered routes that need to be served through the AppConnector.
2826
type RouteAdvertiser interface {
@@ -31,7 +29,7 @@ type RouteAdvertiser interface {
3129
AdvertiseRoute(netip.Prefix) error
3230
}
3331

34-
// EmbeddedAppConnector is an implementation of an AppConnector that performs
32+
// AppConnector is an implementation of an AppConnector that performs
3533
// its function as a subsystem inside of a tailscale node. At the control plane
3634
// side App Connector routing is configured in terms of domains rather than IP
3735
// addresses.
@@ -40,7 +38,7 @@ type RouteAdvertiser interface {
4038
// DNS requests for configured domains are observed. If the domains resolve to
4139
// routes not yet served by the AppConnector the local node configuration is
4240
// updated to advertise the new route.
43-
type EmbeddedAppConnector struct {
41+
type AppConnector struct {
4442
logf logger.Logf
4543
routeAdvertiser RouteAdvertiser
4644

@@ -51,9 +49,9 @@ type EmbeddedAppConnector struct {
5149
domains map[string][]netip.Addr
5250
}
5351

54-
// NewEmbeddedAppConnector creates a new EmbeddedAppConnector.
55-
func NewEmbeddedAppConnector(logf logger.Logf, routeAdvertiser RouteAdvertiser) *EmbeddedAppConnector {
56-
return &EmbeddedAppConnector{
52+
// NewAppConnector creates a new AppConnector.
53+
func NewAppConnector(logf logger.Logf, routeAdvertiser RouteAdvertiser) *AppConnector {
54+
return &AppConnector{
5755
logf: logger.WithPrefix(logf, "appc: "),
5856
routeAdvertiser: routeAdvertiser,
5957
}
@@ -62,7 +60,7 @@ func NewEmbeddedAppConnector(logf logger.Logf, routeAdvertiser RouteAdvertiser)
6260
// UpdateDomains replaces the current set of configured domains with the
6361
// supplied set of domains. Domains must not contain a trailing dot, and should
6462
// be lower case.
65-
func (e *EmbeddedAppConnector) UpdateDomains(domains []string) {
63+
func (e *AppConnector) UpdateDomains(domains []string) {
6664
e.mu.Lock()
6765
defer e.mu.Unlock()
6866

@@ -76,7 +74,7 @@ func (e *EmbeddedAppConnector) UpdateDomains(domains []string) {
7674
}
7775

7876
// Domains returns the currently configured domain list.
79-
func (e *EmbeddedAppConnector) Domains() views.Slice[string] {
77+
func (e *AppConnector) Domains() views.Slice[string] {
8078
e.mu.Lock()
8179
defer e.mu.Unlock()
8280

@@ -87,7 +85,7 @@ func (e *EmbeddedAppConnector) Domains() views.Slice[string] {
8785
// response is being returned over the PeerAPI. The response is parsed and
8886
// matched against the configured domains, if matched the routeAdvertiser is
8987
// advised to advertise the discovered route.
90-
func (e *EmbeddedAppConnector) ObserveDNSResponse(res []byte) {
88+
func (e *AppConnector) ObserveDNSResponse(res []byte) {
9189
var p dnsmessage.Parser
9290
if _, err := p.Start(res); err != nil {
9391
return

appc/embedded_test.go renamed to appc/appconnector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestUpdateDomains(t *testing.T) {
17-
a := NewEmbeddedAppConnector(t.Logf, nil)
17+
a := NewAppConnector(t.Logf, nil)
1818
a.UpdateDomains([]string{"example.com"})
1919
if got, want := a.Domains().AsSlice(), []string{"example.com"}; !slices.Equal(got, want) {
2020
t.Errorf("got %v; want %v", got, want)
@@ -37,7 +37,7 @@ func TestUpdateDomains(t *testing.T) {
3737

3838
func TestObserveDNSResponse(t *testing.T) {
3939
rc := &routeCollector{}
40-
a := NewEmbeddedAppConnector(t.Logf, rc)
40+
a := NewAppConnector(t.Logf, rc)
4141

4242
// a has no domains configured, so it should not advertise any routes
4343
a.ObserveDNSResponse(dnsResponse("example.com.", "192.0.0.8"))

appc/handlers.go renamed to cmd/sniproxy/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
package appc
4+
package main
55

66
import (
77
"context"

appc/handlers_test.go renamed to cmd/sniproxy/handlers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
package appc
4+
package main
55

66
import (
77
"bytes"

appc/appc.go renamed to cmd/sniproxy/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
// Package appc implements App Connectors.
5-
package appc
4+
package main
65

76
import (
87
"expvar"

appc/appc_test.go renamed to cmd/sniproxy/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
package appc
4+
package main
55

66
import (
77
"net/netip"

cmd/sniproxy/sniproxy.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"strings"
2323

2424
"github.com/peterbourgon/ff/v3"
25-
"golang.org/x/net/dns/dnsmessage"
26-
"tailscale.com/appc"
2725
"tailscale.com/client/tailscale"
2826
"tailscale.com/hostinfo"
2927
"tailscale.com/ipn"
@@ -38,8 +36,6 @@ import (
3836

3937
const configCapKey = "tailscale.com/sniproxy"
4038

41-
var tsMBox = dnsmessage.MustNewName("support.tailscale.com.")
42-
4339
// portForward is the state for a single port forwarding entry, as passed to the --forward flag.
4440
type portForward struct {
4541
Port int
@@ -99,7 +95,7 @@ func main() {
9995
func run(ctx context.Context, ts *tsnet.Server, wgPort int, hostname string, promoteHTTPS bool, debugPort int, ports, forwards string) {
10096
// Wire up Tailscale node + app connector server
10197
hostinfo.SetApp("sniproxy")
102-
var s server
98+
var s sniproxy
10399
s.ts = ts
104100

105101
s.ts.Port = uint16(wgPort)
@@ -110,7 +106,7 @@ func run(ctx context.Context, ts *tsnet.Server, wgPort int, hostname string, pro
110106
log.Fatalf("LocalClient() failed: %v", err)
111107
}
112108
s.lc = lc
113-
s.ts.RegisterFallbackTCPHandler(s.appc.HandleTCPFlow)
109+
s.ts.RegisterFallbackTCPHandler(s.srv.HandleTCPFlow)
114110

115111
// Start special-purpose listeners: dns, http promotion, debug server
116112
ln, err := s.ts.Listen("udp", ":53")
@@ -181,18 +177,18 @@ func run(ctx context.Context, ts *tsnet.Server, wgPort int, hostname string, pro
181177
// on the command line. This is intentionally done after we advertise any routes
182178
// because its never correct to advertise the nodes native IP addresses.
183179
s.mergeConfigFromFlags(&c, ports, forwards)
184-
s.appc.Configure(&c)
180+
s.srv.Configure(&c)
185181
}
186182
}
187183
}
188184

189-
type server struct {
190-
appc appc.Server
191-
ts *tsnet.Server
192-
lc *tailscale.LocalClient
185+
type sniproxy struct {
186+
srv Server
187+
ts *tsnet.Server
188+
lc *tailscale.LocalClient
193189
}
194190

195-
func (s *server) advertiseRoutesFromConfig(ctx context.Context, c *appctype.AppConnectorConfig) error {
191+
func (s *sniproxy) advertiseRoutesFromConfig(ctx context.Context, c *appctype.AppConnectorConfig) error {
196192
// Collect the set of addresses to advertise, using a map
197193
// to avoid duplicate entries.
198194
addrs := map[netip.Addr]struct{}{}
@@ -224,7 +220,7 @@ func (s *server) advertiseRoutesFromConfig(ctx context.Context, c *appctype.AppC
224220
return err
225221
}
226222

227-
func (s *server) mergeConfigFromFlags(out *appctype.AppConnectorConfig, ports, forwards string) {
223+
func (s *sniproxy) mergeConfigFromFlags(out *appctype.AppConnectorConfig, ports, forwards string) {
228224
ip4, ip6 := s.ts.TailscaleIPs()
229225

230226
sniConfigFromFlags := appctype.SNIProxyConfig{
@@ -276,18 +272,18 @@ func (s *server) mergeConfigFromFlags(out *appctype.AppConnectorConfig, ports, f
276272
}
277273
}
278274

279-
func (s *server) serveDNS(ln net.Listener) {
275+
func (s *sniproxy) serveDNS(ln net.Listener) {
280276
for {
281277
c, err := ln.Accept()
282278
if err != nil {
283279
log.Printf("serveDNS accept: %v", err)
284280
return
285281
}
286-
go s.appc.HandleDNS(c.(nettype.ConnPacketConn))
282+
go s.srv.HandleDNS(c.(nettype.ConnPacketConn))
287283
}
288284
}
289285

290-
func (s *server) promoteHTTPS(ln net.Listener) {
286+
func (s *sniproxy) promoteHTTPS(ln net.Listener) {
291287
err := http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
292288
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusFound)
293289
}))

cmd/tailscaled/depaware.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
216216
gvisor.dev/gvisor/pkg/tcpip/transport/udp from tailscale.com/net/tstun+
217217
gvisor.dev/gvisor/pkg/waiter from gvisor.dev/gvisor/pkg/context+
218218
inet.af/peercred from tailscale.com/ipn/ipnauth
219-
inet.af/tcpproxy from tailscale.com/appc
220219
W 💣 inet.af/wf from tailscale.com/wf
221220
nhooyr.io/websocket from tailscale.com/derp/derphttp+
222221
nhooyr.io/websocket/internal/errd from nhooyr.io/websocket
@@ -321,7 +320,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
321320
tailscale.com/tstime/mono from tailscale.com/net/tstun+
322321
tailscale.com/tstime/rate from tailscale.com/wgengine/filter+
323322
tailscale.com/tsweb/varz from tailscale.com/cmd/tailscaled
324-
tailscale.com/types/appctype from tailscale.com/appc+
323+
tailscale.com/types/appctype from tailscale.com/ipn/ipnlocal
325324
tailscale.com/types/dnstype from tailscale.com/ipn/ipnlocal+
326325
tailscale.com/types/empty from tailscale.com/ipn+
327326
tailscale.com/types/flagtype from tailscale.com/cmd/tailscaled

ipn/ipnlocal/local.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ type LocalBackend struct {
205205
conf *conffile.Config // latest parsed config, or nil if not in declarative mode
206206
pm *profileManager // mu guards access
207207
filterHash deephash.Sum
208-
httpTestClient *http.Client // for controlclient. nil by default, used by tests.
209-
ccGen clientGen // function for producing controlclient; lazily populated
210-
sshServer SSHServer // or nil, initialized lazily.
211-
appConnector *appc.EmbeddedAppConnector // or nil, initialized when configured.
208+
httpTestClient *http.Client // for controlclient. nil by default, used by tests.
209+
ccGen clientGen // function for producing controlclient; lazily populated
210+
sshServer SSHServer // or nil, initialized lazily.
211+
appConnector *appc.AppConnector // or nil, initialized when configured.
212212
webClient webClient
213213
notify func(ipn.Notify)
214214
cc controlclient.Client
@@ -3250,7 +3250,7 @@ func (b *LocalBackend) reconfigAppConnectorLocked(nm *netmap.NetworkMap, prefs i
32503250
}
32513251

32523252
if b.appConnector == nil {
3253-
b.appConnector = appc.NewEmbeddedAppConnector(b.logf, b)
3253+
b.appConnector = appc.NewAppConnector(b.logf, b)
32543254
}
32553255
if nm == nil {
32563256
return
@@ -5476,7 +5476,7 @@ func (b *LocalBackend) DebugBreakDERPConns() error {
54765476
// ObserveDNSResponse passes a DNS response from the PeerAPI DNS server to the
54775477
// App Connector to enable route discovery.
54785478
func (b *LocalBackend) ObserveDNSResponse(res []byte) {
5479-
var appConnector *appc.EmbeddedAppConnector
5479+
var appConnector *appc.AppConnector
54805480
b.mu.Lock()
54815481
if b.appConnector == nil {
54825482
b.mu.Unlock()

ipn/ipnlocal/local_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ func TestOfferingAppConnector(t *testing.T) {
11511151
if b.OfferingAppConnector() {
11521152
t.Fatal("unexpected offering app connector")
11531153
}
1154-
b.appConnector = appc.NewEmbeddedAppConnector(t.Logf, nil)
1154+
b.appConnector = appc.NewAppConnector(t.Logf, nil)
11551155
if !b.OfferingAppConnector() {
11561156
t.Fatal("unexpected not offering app connector")
11571157
}
@@ -1173,7 +1173,7 @@ func TestAppConnectorHostinfoService(t *testing.T) {
11731173
if hasAppConnectorService(b.peerAPIServicesLocked()) {
11741174
t.Fatal("unexpected app connector service")
11751175
}
1176-
b.appConnector = appc.NewEmbeddedAppConnector(t.Logf, nil)
1176+
b.appConnector = appc.NewAppConnector(t.Logf, nil)
11771177
if !hasAppConnectorService(b.peerAPIServicesLocked()) {
11781178
t.Fatal("expected app connector service")
11791179
}
@@ -1199,7 +1199,7 @@ func TestObserveDNSResponse(t *testing.T) {
11991199
b.ObserveDNSResponse(dnsResponse("example.com.", "192.0.0.8"))
12001200

12011201
rc := &routeCollector{}
1202-
b.appConnector = appc.NewEmbeddedAppConnector(t.Logf, rc)
1202+
b.appConnector = appc.NewAppConnector(t.Logf, rc)
12031203
b.appConnector.UpdateDomains([]string{"example.com"})
12041204

12051205
b.ObserveDNSResponse(dnsResponse("example.com.", "192.0.0.8"))

0 commit comments

Comments
 (0)