smalllife // packet & bench

Why Unbound kept retrying over TCP on large DNSSEC answers

2024-10-26 · dns, dnssec, ipv6

Looking at unbound-control stats_noreset on gw01, roughly 4% of cold-cache queries showed a 1.5-second latency spike paired with incrementing num.query.tcpout. All of them were DNSSEC-signed zones during ZSK rollover over IPv6 transport.

Fragmented UDP over IPv6

An old config snippet I had copied years ago still set edns-buffer-size: 4096. When an authoritative server replied with a 1780-byte signed UDP packet over IPv6, it attached an IPv6 Fragment Header; somewhere upstream of my PPPoE session, fragmented UDP/53 packets were dropped on sight. Unbound waited for UDP timeout before falling back to EDNS 512 / TCP.

Stick to the Flag Day 2020 default (1232)

Modern Unbound already defaults to 1232 bytes (1280-byte minimum IPv6 MTU minus 40-byte IPv6 header minus 8-byte UDP header) as long as you delete stale overrides:

# /etc/unbound/unbound.conf.d/local.conf
server:
    edns-buffer-size: 1232
    max-udp-size: 1232
    harden-algo-downgrade: yes
    qname-minimisation: yes

With 1232, the authoritative server sees the smaller buffer advertisement immediately, sets the TC=1 truncated bit in a single unfragmented UDP reply, and Unbound retries over TCP in one RTT instead of burning a full UDP retransmission timer first.

$ dig @127.0.0.1 +dnssec +bufsize=1232 org. DNSKEY | grep -E 'flags:|Query time:|MSG SIZE'
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; Query time: 38 msec
;; MSG SIZE  rcvd: 1624