Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/atunnel/dns/pendingreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ package dns

import (
"bytes"
"math/rand/v2"
"crypto/rand"
"encoding/binary"
"net"
"sync"
"time"
Expand Down Expand Up @@ -110,11 +111,14 @@ func (p *pendingRequests) record(
clientAddr net.Addr,
upstreams []string,
) (uint16, bool) {
// Probe from a random starting ID so upstream transaction IDs are not predictable.
var buf [2]byte
_, _ = rand.Read(buf[:])
start := binary.BigEndian.Uint16(buf[:])

p.mu.Lock()
defer p.mu.Unlock()

// Probe from a random starting ID so upstream transaction IDs are not predictable.
start := uint16(rand.Uint32())
upstreamID, ok := p.inUse.FindFirstUnsetFrom(start)
if !ok {
p.limiter.inFlight.release()
Expand Down
Loading