mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-05 04:11:59 +00:00
syncs, all: move to using Go's new atomic types instead of ours
Fixes #5185 Change-Id: I850dd532559af78c3895e2924f8237ccc328449d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
9bb5a038e5
commit
4950fe60bd
@@ -18,25 +18,25 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"sync/atomic"
|
||||
|
||||
"tailscale.com/net/netknob"
|
||||
"tailscale.com/syncs"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
var disabled syncs.AtomicBool
|
||||
var disabled atomic.Bool
|
||||
|
||||
// SetEnabled enables or disables netns for the process.
|
||||
// It defaults to being enabled.
|
||||
func SetEnabled(on bool) {
|
||||
disabled.Set(!on)
|
||||
disabled.Store(!on)
|
||||
}
|
||||
|
||||
// Listener returns a new net.Listener with its Control hook func
|
||||
// initialized as necessary to run in logical network namespace that
|
||||
// doesn't route back into Tailscale.
|
||||
func Listener(logf logger.Logf) *net.ListenConfig {
|
||||
if disabled.Get() {
|
||||
if disabled.Load() {
|
||||
return new(net.ListenConfig)
|
||||
}
|
||||
return &net.ListenConfig{Control: control(logf)}
|
||||
@@ -57,7 +57,7 @@ func NewDialer(logf logger.Logf) Dialer {
|
||||
// handles using a SOCKS if configured in the environment with
|
||||
// ALL_PROXY.
|
||||
func FromDialer(logf logger.Logf, d *net.Dialer) Dialer {
|
||||
if disabled.Get() {
|
||||
if disabled.Load() {
|
||||
return d
|
||||
}
|
||||
d.Control = control(logf)
|
||||
|
||||
Reference in New Issue
Block a user