all: use atomic.Pointer
Also add some missing docs. Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -24,8 +24,8 @@ func init() {
|
||||
} else if n > 10000 {
|
||||
n = 10000
|
||||
}
|
||||
fl, ok := fwdLogAtomic.Load().(*fwdLog)
|
||||
if !ok || n != len(fl.ent) {
|
||||
fl := fwdLogAtomic.Load()
|
||||
if fl == nil || n != len(fl.ent) {
|
||||
fl = &fwdLog{ent: make([]fwdLogEntry, n)}
|
||||
fwdLogAtomic.Store(fl)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func init() {
|
||||
}))
|
||||
}
|
||||
|
||||
var fwdLogAtomic atomic.Value // of *fwdLog
|
||||
var fwdLogAtomic atomic.Pointer[fwdLog]
|
||||
|
||||
type fwdLog struct {
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
+4
-7
@@ -126,7 +126,7 @@ type Wrapper struct {
|
||||
eventsOther chan tun.Event
|
||||
|
||||
// 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 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 {
|
||||
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 {
|
||||
return filter.Drop
|
||||
}
|
||||
@@ -698,8 +696,7 @@ func (t *Wrapper) tdevWrite(buf []byte, offset int) (int, error) {
|
||||
}
|
||||
|
||||
func (t *Wrapper) GetFilter() *filter.Filter {
|
||||
filt, _ := t.filter.Load().(*filter.Filter)
|
||||
return filt
|
||||
return t.filter.Load()
|
||||
}
|
||||
|
||||
func (t *Wrapper) SetFilter(filt *filter.Filter) {
|
||||
|
||||
Reference in New Issue
Block a user