@@ -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
3937const 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.
4440type portForward struct {
4541 Port int
@@ -99,7 +95,7 @@ func main() {
9995func 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 }))
0 commit comments