Skip to content

Commit

Permalink
Export APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 22, 2024
1 parent 7c5eb01 commit c544091
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ipn/ipnlocal/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ type LocalBackend struct {
// backend is healthy and captive portal detection is not required
// (sending false).
needsCaptiveDetection chan bool

cfg *wgcfg.Config
rcfg *router.Config
dcfg *dns.Config
}

// HealthTracker returns the health tracker for the backend.
Expand Down Expand Up @@ -486,10 +490,10 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
}

netMon := sys.NetMon.Get()
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker())
if err != nil {
log.Printf("error setting up sockstat logger: %v", err)
}
//b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker())
//if err != nil {
// log.Printf("error setting up sockstat logger: %v", err)
//}
// Enable sockstats logs only on non-mobile unstable builds
if version.IsUnstableBuild() && !version.IsMobile() && b.sockstatLogger != nil {
b.sockstatLogger.SetLoggingEnabled(true)
Expand Down Expand Up @@ -4261,6 +4265,10 @@ func (b *LocalBackend) authReconfig() {
}

b.initPeerAPIListener()

b.cfg = cfg
b.rcfg = rcfg
b.dcfg = dcfg
}

// shouldUseOneCGNATRoute reports whether we should prefer to make one big
Expand Down
18 changes: 18 additions & 0 deletions ipn/ipnlocal/local_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ipnlocal

import (
"sync/atomic"

"github.com/sagernet/tailscale/net/dns"
"github.com/sagernet/tailscale/wgengine/filter"
"github.com/sagernet/tailscale/wgengine/router"
"github.com/sagernet/tailscale/wgengine/wgcfg"
)

func (b *LocalBackend) ExportFilter() *atomic.Pointer[filter.Filter] {
return &b.filterAtomic
}

func (b *LocalBackend) ExportConfig() (*wgcfg.Config, *dns.Config, *router.Config) {
return b.cfg, b.dcfg, b.rcfg
}
14 changes: 14 additions & 0 deletions tsnet/tsnet_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tsnet

import (
"github.com/sagernet/tailscale/ipn/ipnlocal"
"github.com/sagernet/tailscale/wgengine/netstack"
)

func (s *Server) ExportNetstack() *netstack.Impl {
return s.netstack
}

func (s *Server) ExportLocalBackend() *ipnlocal.LocalBackend {
return s.lb
}
10 changes: 10 additions & 0 deletions version/version_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package version

import "github.com/sagernet/tailscale/types/lazy"

func SetVersion(version string) {
short = lazy.SyncValue[string]{}
short.MustSet(version)
long = lazy.SyncValue[string]{}
long.MustSet(version)
}
7 changes: 7 additions & 0 deletions wgengine/netstack/netstack_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package netstack

import "github.com/sagernet/gvisor/pkg/tcpip/stack"

func (ns *Impl) ExportIPStack() *stack.Stack {
return ns.ipstack
}

0 comments on commit c544091

Please sign in to comment.