mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
all: use atomic.Pointer
Also add some missing docs. Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
5381437664
commit
9bb5a038e5
@ -1151,8 +1151,8 @@ var clockNow = time.Now
|
|||||||
|
|
||||||
// opt.Bool configs from control.
|
// opt.Bool configs from control.
|
||||||
var (
|
var (
|
||||||
controlUseDERPRoute atomic.Value
|
controlUseDERPRoute atomic.Value // of opt.Bool
|
||||||
controlTrimWGConfig atomic.Value
|
controlTrimWGConfig atomic.Value // of opt.Bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func setControlAtomic(dst *atomic.Value, v opt.Bool) {
|
func setControlAtomic(dst *atomic.Value, v opt.Bool) {
|
||||||
|
@ -130,7 +130,7 @@ type LocalBackend struct {
|
|||||||
sshAtomicBool syncs.AtomicBool
|
sshAtomicBool syncs.AtomicBool
|
||||||
shutdownCalled bool // if Shutdown has been called
|
shutdownCalled bool // if Shutdown has been called
|
||||||
|
|
||||||
filterAtomic atomic.Value // of *filter.Filter
|
filterAtomic atomic.Pointer[filter.Filter]
|
||||||
containsViaIPFuncAtomic atomic.Value // of func(netip.Addr) bool
|
containsViaIPFuncAtomic atomic.Value // of func(netip.Addr) bool
|
||||||
|
|
||||||
// The mutex protects the following elements.
|
// The mutex protects the following elements.
|
||||||
@ -577,8 +577,8 @@ func (b *LocalBackend) PeerCaps(src netip.Addr) []string {
|
|||||||
if b.netMap == nil {
|
if b.netMap == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
filt, ok := b.filterAtomic.Load().(*filter.Filter)
|
filt := b.filterAtomic.Load()
|
||||||
if !ok {
|
if filt == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, a := range b.netMap.Addresses {
|
for _, a := range b.netMap.Addresses {
|
||||||
|
@ -973,8 +973,8 @@ func (h *peerAPIHandler) replyToDNSQueries() bool {
|
|||||||
// ourselves. As a proxy for autogroup:internet access, we see
|
// ourselves. As a proxy for autogroup:internet access, we see
|
||||||
// if we would've accepted a packet to 0.0.0.0:53. We treat
|
// if we would've accepted a packet to 0.0.0.0:53. We treat
|
||||||
// the IP 0.0.0.0 as being "the internet".
|
// the IP 0.0.0.0 as being "the internet".
|
||||||
f, ok := b.filterAtomic.Load().(*filter.Filter)
|
f := b.filterAtomic.Load()
|
||||||
if !ok {
|
if f == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// Note: we check TCP here because the Filter type already had
|
// Note: we check TCP here because the Filter type already had
|
||||||
|
@ -24,8 +24,8 @@ func init() {
|
|||||||
} else if n > 10000 {
|
} else if n > 10000 {
|
||||||
n = 10000
|
n = 10000
|
||||||
}
|
}
|
||||||
fl, ok := fwdLogAtomic.Load().(*fwdLog)
|
fl := fwdLogAtomic.Load()
|
||||||
if !ok || n != len(fl.ent) {
|
if fl == nil || n != len(fl.ent) {
|
||||||
fl = &fwdLog{ent: make([]fwdLogEntry, n)}
|
fl = &fwdLog{ent: make([]fwdLogEntry, n)}
|
||||||
fwdLogAtomic.Store(fl)
|
fwdLogAtomic.Store(fl)
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ func init() {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
var fwdLogAtomic atomic.Value // of *fwdLog
|
var fwdLogAtomic atomic.Pointer[fwdLog]
|
||||||
|
|
||||||
type fwdLog struct {
|
type fwdLog struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
@ -688,7 +688,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fl, ok := fwdLogAtomic.Load().(*fwdLog); ok {
|
if fl := fwdLogAtomic.Load(); fl != nil {
|
||||||
fl.addName(string(domain))
|
fl.addName(string(domain))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ type Wrapper struct {
|
|||||||
eventsOther chan tun.Event
|
eventsOther chan tun.Event
|
||||||
|
|
||||||
// filter atomically stores the currently active packet filter
|
// filter atomically stores the currently active packet filter
|
||||||
filter atomic.Value // of *filter.Filter
|
filter atomic.Pointer[filter.Filter]
|
||||||
// filterFlags control the verbosity of logging packet drops/accepts.
|
// filterFlags control the verbosity of logging packet drops/accepts.
|
||||||
filterFlags filter.RunFlags
|
filterFlags filter.RunFlags
|
||||||
|
|
||||||
@ -477,8 +477,7 @@ func (t *Wrapper) filterOut(p *packet.Parsed) filter.Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filt, _ := t.filter.Load().(*filter.Filter)
|
filt := t.filter.Load()
|
||||||
|
|
||||||
if filt == nil {
|
if filt == nil {
|
||||||
return filter.Drop
|
return filter.Drop
|
||||||
}
|
}
|
||||||
@ -606,8 +605,7 @@ func (t *Wrapper) filterIn(buf []byte) filter.Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filt, _ := t.filter.Load().(*filter.Filter)
|
filt := t.filter.Load()
|
||||||
|
|
||||||
if filt == nil {
|
if filt == nil {
|
||||||
return filter.Drop
|
return filter.Drop
|
||||||
}
|
}
|
||||||
@ -698,8 +696,7 @@ func (t *Wrapper) tdevWrite(buf []byte, offset int) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Wrapper) GetFilter() *filter.Filter {
|
func (t *Wrapper) GetFilter() *filter.Filter {
|
||||||
filt, _ := t.filter.Load().(*filter.Filter)
|
return t.filter.Load()
|
||||||
return filt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Wrapper) SetFilter(filt *filter.Filter) {
|
func (t *Wrapper) SetFilter(filt *filter.Filter) {
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
// AppSharedDir is a string set by the iOS or Android app on start
|
// AppSharedDir is a string set by the iOS or Android app on start
|
||||||
// containing a directory we can read/write in.
|
// containing a directory we can read/write in.
|
||||||
var AppSharedDir atomic.Value
|
var AppSharedDir atomic.Value // of string
|
||||||
|
|
||||||
// DefaultTailscaledSocket returns the path to the tailscaled Unix socket
|
// DefaultTailscaledSocket returns the path to the tailscaled Unix socket
|
||||||
// or the empty string if there's no reasonable default.
|
// or the empty string if there's no reasonable default.
|
||||||
|
@ -43,7 +43,7 @@ func IsSandboxedMacOS() bool {
|
|||||||
return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale")
|
return strings.HasSuffix(exe, "/Contents/MacOS/Tailscale")
|
||||||
}
|
}
|
||||||
|
|
||||||
var isMacSysExt atomic.Value
|
var isMacSysExt atomic.Value // of bool
|
||||||
|
|
||||||
// IsMacSysExt whether this binary is from the standalone "System
|
// IsMacSysExt whether this binary is from the standalone "System
|
||||||
// Extension" (a.k.a. "macsys") version of Tailscale for macOS.
|
// Extension" (a.k.a. "macsys") version of Tailscale for macOS.
|
||||||
|
@ -305,9 +305,9 @@ type Conn struct {
|
|||||||
// derpMapAtomic is the same as derpMap, but without requiring
|
// derpMapAtomic is the same as derpMap, but without requiring
|
||||||
// sync.Mutex. For use with NewRegionClient's callback, to avoid
|
// sync.Mutex. For use with NewRegionClient's callback, to avoid
|
||||||
// lock ordering deadlocks. See issue 3726 and mu field docs.
|
// lock ordering deadlocks. See issue 3726 and mu field docs.
|
||||||
derpMapAtomic atomic.Value // of *tailcfg.DERPMap
|
derpMapAtomic atomic.Pointer[tailcfg.DERPMap]
|
||||||
|
|
||||||
lastNetCheckReport atomic.Value // of *netcheck.Report
|
lastNetCheckReport atomic.Pointer[netcheck.Report]
|
||||||
|
|
||||||
// port is the preferred port from opts.Port; 0 means auto.
|
// port is the preferred port from opts.Port; 0 means auto.
|
||||||
port syncs.AtomicUint32
|
port syncs.AtomicUint32
|
||||||
@ -1357,7 +1357,7 @@ func (c *Conn) derpWriteChanOfAddr(addr netip.AddrPort, peer key.NodePublic) cha
|
|||||||
// We're closing anyway; return nil to stop dialing.
|
// We're closing anyway; return nil to stop dialing.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
derpMap, _ := c.derpMapAtomic.Load().(*tailcfg.DERPMap)
|
derpMap := c.derpMapAtomic.Load()
|
||||||
if derpMap == nil {
|
if derpMap == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -4142,7 +4142,7 @@ func (di *discoInfo) setNodeKey(nk key.NodePublic) {
|
|||||||
type derpAddrFamSelector struct{ c *Conn }
|
type derpAddrFamSelector struct{ c *Conn }
|
||||||
|
|
||||||
func (s derpAddrFamSelector) PreferIPv6() bool {
|
func (s derpAddrFamSelector) PreferIPv6() bool {
|
||||||
if r, ok := s.c.lastNetCheckReport.Load().(*netcheck.Report); ok {
|
if r := s.c.lastNetCheckReport.Load(); r != nil {
|
||||||
return r.IPv6
|
return r.IPv6
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user