Skip to content

Commit ac803e0

Browse files
committed
Merge branch 'master' into AGDNS-3863-gopacket-dhcp-vol.34
2 parents 7c42638 + b0e930c commit ac803e0

7 files changed

Lines changed: 24 additions & 22 deletions

File tree

internal/aghnet/dhcp_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func checkOtherDHCP(
1313
_ context.Context,
1414
_ *slog.Logger,
15-
ifaceName string,
15+
_ string,
1616
) (ok4, ok6 bool, err4, err6 error) {
1717
return false,
1818
false,

internal/aghnet/hostscontainer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func TestNewHostsContainer(t *testing.T) {
6464
return nil
6565
}
6666

67-
var eventsCalledCounter uint32
67+
var eventsCalledCounter atomic.Uint32
6868
eventsCh := make(chan struct{})
6969
onEvents := func() (e <-chan struct{}) {
70-
assert.Equal(t, uint32(1), atomic.AddUint32(&eventsCalledCounter, 1))
70+
assert.Equal(t, uint32(1), eventsCalledCounter.Add(1))
7171

7272
return eventsCh
7373
}
@@ -95,7 +95,7 @@ func TestNewHostsContainer(t *testing.T) {
9595
assert.NotNil(t, <-hc.Upd())
9696

9797
eventsCh <- struct{}{}
98-
assert.Equal(t, uint32(1), atomic.LoadUint32(&eventsCalledCounter))
98+
assert.Equal(t, uint32(1), eventsCalledCounter.Load())
9999
})
100100
}
101101

internal/aghnet/interfaces_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// listenPacketReusable announces on the local network address additionally
1313
// configuring the socket to have a reusable binding.
14-
func listenPacketReusable(ifaceName, network, address string) (c net.PacketConn, err error) {
14+
func listenPacketReusable(ifaceName, _, address string) (c net.PacketConn, err error) {
1515
var port uint16
1616
_, port, err = netutil.SplitHostPort(address)
1717
if err != nil {

internal/dnsforward/dnsforward_internal_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func TestBlockedRequest(t *testing.T) {
837837
func TestServerCustomClientUpstream(t *testing.T) {
838838
const defaultCacheSize = 1024 * 1024
839839

840-
var upsCalledCounter uint32
840+
var upsCalledCounter atomic.Uint32
841841

842842
forwardConf := ServerConfig{
843843
UDPListenAddrs: []*net.UDPAddr{{}},
@@ -862,7 +862,7 @@ func TestServerCustomClientUpstream(t *testing.T) {
862862
)
863863

864864
ups := aghtest.NewUpstreamMock(func(req *dns.Msg) (resp *dns.Msg, err error) {
865-
atomic.AddUint32(&upsCalledCounter, 1)
865+
upsCalledCounter.Add(1)
866866

867867
return cmp.Or(
868868
aghtest.MatchedResponse(req, dns.TypeA, "host", "192.168.0.1"),
@@ -902,11 +902,11 @@ func TestServerCustomClientUpstream(t *testing.T) {
902902

903903
assert.Equal(t, dns.RcodeSuccess, reply.Rcode)
904904
assert.Equal(t, net.IP{192, 168, 0, 1}, reply.Answer[0].(*dns.A).A)
905-
assert.Equal(t, uint32(1), atomic.LoadUint32(&upsCalledCounter))
905+
assert.Equal(t, uint32(1), upsCalledCounter.Load())
906906

907907
_, err = dns.Exchange(req, addr)
908908
require.NoError(t, err)
909-
assert.Equal(t, uint32(1), atomic.LoadUint32(&upsCalledCounter))
909+
assert.Equal(t, uint32(1), upsCalledCounter.Load())
910910
}
911911

912912
// testCNAMEs is a map of names and CNAMEs necessary for the TestUpstream work.
@@ -1576,10 +1576,10 @@ func TestPTRResponseFromHosts(t *testing.T) {
15761576
OnHostByIP: func(ip netip.Addr) (host string) { return "" },
15771577
}
15781578

1579-
var eventsCalledCounter uint32
1579+
var eventsCalledCounter atomic.Uint32
15801580
watcher := aghtest.NewFSWatcher()
15811581
watcher.OnEvents = func() (e <-chan aghos.Event) {
1582-
assert.Equal(t, uint32(1), atomic.AddUint32(&eventsCalledCounter, 1))
1582+
assert.Equal(t, uint32(1), eventsCalledCounter.Add(1))
15831583

15841584
return nil
15851585
}
@@ -1593,7 +1593,7 @@ func TestPTRResponseFromHosts(t *testing.T) {
15931593
hc, err := aghnet.NewHostsContainer(ctx, testLogger, testFS, watcher, hostsFilename)
15941594
require.NoError(t, err)
15951595
t.Cleanup(func() {
1596-
assert.Equal(t, uint32(1), atomic.LoadUint32(&eventsCalledCounter))
1596+
assert.Equal(t, uint32(1), eventsCalledCounter.Load())
15971597
})
15981598

15991599
flt, err := filtering.New(&filtering.Config{

internal/filtering/filtering.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ type Config struct {
169169
//
170170
// It is of type uint32 to be accessed by atomic.
171171
//
172-
// TODO(e.burkov): Use atomic.Bool in Go 1.19.
172+
// TODO(e.burkov): Use *atomic.Bool once this entire package is refactored.
173+
// Do not use it until then, since *newConf = *oldConf will copy an atomic
174+
// bool by value, which is prohibited.
173175
enabled uint32
174176

175177
// FiltersUpdateIntervalHours is the time period to update filters

internal/querylog/qlogfile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,20 @@ func newQLogFile(path string) (qf *qLogFile, err error) {
7070
// validateQLogLineIdx returns error if the line index is not valid to continue
7171
// search.
7272
func (q *qLogFile) validateQLogLineIdx(lineIdx, lastProbeLineIdx, ts, fSize int64) (err error) {
73-
if lineIdx == lastProbeLineIdx {
73+
switch lineIdx {
74+
case lastProbeLineIdx:
7475
if lineIdx == 0 {
7576
return errTSTooEarly
7677
}
7778

7879
// If we're testing the same line twice then most likely the scope is
7980
// too narrow and we won't find anything anymore in any other file.
8081
return fmt.Errorf("looking up timestamp %d in %q: %w", ts, q.file.Name(), errTSNotFound)
81-
} else if lineIdx == fSize {
82+
case fSize:
8283
return errTSTooLate
84+
default:
85+
return nil
8386
}
84-
85-
return nil
8687
}
8788

8889
// seekTS performs binary search in the query log file looking for a record

internal/stats/stats_internal_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ func newTestStatsCtx(tb testing.TB, c Config) (s *StatsCtx) {
4545
}
4646

4747
func TestStats_races(t *testing.T) {
48-
var r uint32
49-
idGen := func() (id uint32) { return atomic.LoadUint32(&r) }
48+
var currentRound atomic.Uint32
5049
s := newTestStatsCtx(t, Config{
51-
UnitID: idGen,
50+
UnitID: currentRound.Load,
5251
Enabled: true,
5352
})
5453

@@ -81,14 +80,14 @@ func TestStats_races(t *testing.T) {
8180
}
8281

8382
const (
84-
roundsNum = 3
83+
roundsNum uint32 = 3
8584

8685
writersNum = 10
8786
readersNum = 5
8887
)
8988

9089
for round := range roundsNum {
91-
atomic.StoreUint32(&r, uint32(round))
90+
currentRound.Store(round)
9291

9392
startWG, finWG := &sync.WaitGroup{}, &sync.WaitGroup{}
9493
waitCh := make(chan unit)

0 commit comments

Comments
 (0)