all: use buildfeatures.HasCapture const in a handful of places

Help out the linker's dead code elimination.

Updates #12614

Change-Id: I6c13cb44d3250bf1e3a01ad393c637da4613affb
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-09-23 18:15:48 -07:00 committed by Brad Fitzpatrick
parent 8fe575409f
commit b54cdf9f38
5 changed files with 21 additions and 0 deletions

View File

@ -1026,6 +1026,9 @@ func (b *LocalBackend) onHealthChange(change health.Change) {
// GetOrSetCaptureSink returns the current packet capture sink, creating it // GetOrSetCaptureSink returns the current packet capture sink, creating it
// with the provided newSink function if it does not already exist. // with the provided newSink function if it does not already exist.
func (b *LocalBackend) GetOrSetCaptureSink(newSink func() packet.CaptureSink) packet.CaptureSink { func (b *LocalBackend) GetOrSetCaptureSink(newSink func() packet.CaptureSink) packet.CaptureSink {
if !buildfeatures.HasCapture {
return nil
}
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
@ -1039,6 +1042,9 @@ func (b *LocalBackend) GetOrSetCaptureSink(newSink func() packet.CaptureSink) pa
} }
func (b *LocalBackend) ClearCaptureSink() { func (b *LocalBackend) ClearCaptureSink() {
if !buildfeatures.HasCapture {
return
}
// Shut down & uninstall the sink if there are no longer // Shut down & uninstall the sink if there are no longer
// any outputs on it. // any outputs on it.
b.mu.Lock() b.mu.Lock()

View File

@ -24,6 +24,7 @@ import (
"go4.org/mem" "go4.org/mem"
"gvisor.dev/gvisor/pkg/tcpip/stack" "gvisor.dev/gvisor/pkg/tcpip/stack"
"tailscale.com/disco" "tailscale.com/disco"
"tailscale.com/feature/buildfeatures"
tsmetrics "tailscale.com/metrics" tsmetrics "tailscale.com/metrics"
"tailscale.com/net/connstats" "tailscale.com/net/connstats"
"tailscale.com/net/packet" "tailscale.com/net/packet"
@ -1491,5 +1492,8 @@ var (
) )
func (t *Wrapper) InstallCaptureHook(cb packet.CaptureCallback) { func (t *Wrapper) InstallCaptureHook(cb packet.CaptureCallback) {
if !buildfeatures.HasCapture {
return
}
t.captureHook.Store(cb) t.captureHook.Store(cb)
} }

View File

@ -890,6 +890,9 @@ func deregisterMetrics(m *metrics) {
// can be called with a nil argument to uninstall the capture // can be called with a nil argument to uninstall the capture
// hook. // hook.
func (c *Conn) InstallCaptureHook(cb packet.CaptureCallback) { func (c *Conn) InstallCaptureHook(cb packet.CaptureCallback) {
if !buildfeatures.HasCapture {
return
}
c.captureHook.Store(cb) c.captureHook.Store(cb)
} }

View File

@ -23,6 +23,7 @@ import (
"tailscale.com/control/controlknobs" "tailscale.com/control/controlknobs"
"tailscale.com/drive" "tailscale.com/drive"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/feature/buildfeatures"
"tailscale.com/health" "tailscale.com/health"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/net/dns" "tailscale.com/net/dns"
@ -1652,6 +1653,9 @@ var (
) )
func (e *userspaceEngine) InstallCaptureHook(cb packet.CaptureCallback) { func (e *userspaceEngine) InstallCaptureHook(cb packet.CaptureCallback) {
if !buildfeatures.HasCapture {
return
}
e.tundev.InstallCaptureHook(cb) e.tundev.InstallCaptureHook(cb)
e.magicConn.InstallCaptureHook(cb) e.magicConn.InstallCaptureHook(cb)
} }

View File

@ -15,6 +15,7 @@ import (
"time" "time"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/feature/buildfeatures"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/net/dns" "tailscale.com/net/dns"
"tailscale.com/net/packet" "tailscale.com/net/packet"
@ -163,6 +164,9 @@ func (e *watchdogEngine) Done() <-chan struct{} {
} }
func (e *watchdogEngine) InstallCaptureHook(cb packet.CaptureCallback) { func (e *watchdogEngine) InstallCaptureHook(cb packet.CaptureCallback) {
if !buildfeatures.HasCapture {
return
}
e.wrap.InstallCaptureHook(cb) e.wrap.InstallCaptureHook(cb)
} }