Skip to content

Commit c614623

Browse files
committed
Export APIs
1 parent 59b3101 commit c614623

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

ipn/ipnlocal/local.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import (
5858
"github.com/sagernet/tailscale/ipn/ipnstate"
5959
"github.com/sagernet/tailscale/ipn/policy"
6060
"github.com/sagernet/tailscale/log/sockstatlog"
61-
"github.com/sagernet/tailscale/logpolicy"
6261
"github.com/sagernet/tailscale/net/captivedetection"
6362
"github.com/sagernet/tailscale/net/dns"
6463
"github.com/sagernet/tailscale/net/dnscache"
@@ -378,6 +377,10 @@ type LocalBackend struct {
378377
// backend is healthy and captive portal detection is not required
379378
// (sending false).
380379
needsCaptiveDetection chan bool
380+
381+
cfg *wgcfg.Config
382+
rcfg *router.Config
383+
dcfg *dns.Config
381384
}
382385

383386
// HealthTracker returns the health tracker for the backend.
@@ -502,10 +505,10 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
502505
}()
503506

504507
netMon := sys.NetMon.Get()
505-
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker())
506-
if err != nil {
507-
log.Printf("error setting up sockstat logger: %v", err)
508-
}
508+
//b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker())
509+
//if err != nil {
510+
// log.Printf("error setting up sockstat logger: %v", err)
511+
//}
509512
// Enable sockstats logs only on non-mobile unstable builds
510513
if version.IsUnstableBuild() && !version.IsMobile() && b.sockstatLogger != nil {
511514
b.sockstatLogger.SetLoggingEnabled(true)
@@ -4344,6 +4347,10 @@ func (b *LocalBackend) authReconfig() {
43444347
}
43454348

43464349
b.initPeerAPIListener()
4350+
4351+
b.cfg = cfg
4352+
b.rcfg = rcfg
4353+
b.dcfg = dcfg
43474354
}
43484355

43494356
// shouldUseOneCGNATRoute reports whether we should prefer to make one big

ipn/ipnlocal/local_export.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ipnlocal
2+
3+
import (
4+
"sync/atomic"
5+
6+
"github.com/sagernet/tailscale/net/dns"
7+
"github.com/sagernet/tailscale/wgengine/filter"
8+
"github.com/sagernet/tailscale/wgengine/router"
9+
"github.com/sagernet/tailscale/wgengine/wgcfg"
10+
)
11+
12+
func (b *LocalBackend) ExportFilter() *atomic.Pointer[filter.Filter] {
13+
return &b.filterAtomic
14+
}
15+
16+
func (b *LocalBackend) ExportConfig() (*wgcfg.Config, *dns.Config, *router.Config) {
17+
return b.cfg, b.dcfg, b.rcfg
18+
}

tsnet/tsnet_export.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tsnet
2+
3+
import (
4+
"github.com/sagernet/tailscale/ipn/ipnlocal"
5+
"github.com/sagernet/tailscale/wgengine/netstack"
6+
)
7+
8+
func (s *Server) ExportNetstack() *netstack.Impl {
9+
return s.netstack
10+
}
11+
12+
func (s *Server) ExportLocalBackend() *ipnlocal.LocalBackend {
13+
return s.lb
14+
}

version/version_export.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package version
2+
3+
import "github.com/sagernet/tailscale/types/lazy"
4+
5+
func SetVersion(version string) {
6+
short = lazy.SyncValue[string]{}
7+
short.MustSet(version)
8+
long = lazy.SyncValue[string]{}
9+
long.MustSet(version)
10+
}

wgengine/netstack/netstack_export.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package netstack
2+
3+
import "github.com/sagernet/gvisor/pkg/tcpip/stack"
4+
5+
func (ns *Impl) ExportIPStack() *stack.Stack {
6+
return ns.ipstack
7+
}

0 commit comments

Comments
 (0)