Skip to content

Set truncate bit for DNS responses#35

Open
kanashimia wants to merge 1 commit intoletsencrypt:mainfrom
kanashimia:truncate
Open

Set truncate bit for DNS responses#35
kanashimia wants to merge 1 commit intoletsencrypt:mainfrom
kanashimia:truncate

Conversation

@kanashimia
Copy link

@kanashimia kanashimia commented Feb 17, 2026

UDP buffer is only 512 bytes by default, it is pretty much never enough for the cases when there are multiple DNS records in a single response, so the responses are cut at arbitrary points which causes problems.

This fixes that by truncating responses at record boundaries and setting TC bit, DNS clients should then read TC bit and retry over TCP which allows for a 64KB buffer.

Truncate function also enables compression if message doesn't fit in the buffer uncompressed but fits if it is compressed.

See docs: https://pkg.go.dev/github.com/miekg/dns#Msg.Truncate

Also here is a link for the source code of Truncate func, with regards to how it handles compression: https://github.com/miekg/dns/blob/ce76cb6c9b5f3b75ff44996597994ae6f13eae28/msg_truncate.go#L29-L51
Plus although I never used go before, Compress is set to false by default anyways from what I understand,
so I removed that m.Compress = false, it is too confusing otherwise, Truncate overrides that value anyways.

Was originally found in
letsencrypt/pebble#536 (comment)

@beautifulentropy

Although pebble now always queries over TCP, other clients still do a UDP->TCP fallback based on a TC bit set.

UDP buffer is only 512 bytes by default, it is pretty much never enough
for the cases when there are multiple DNS records in a single response,
so the responses are cut at arbitrary points which causes problems.

This fixes that by truncating responses at record boundaries
and setting TC bit, DNS clients should then read TC bit and retry
over TCP which allows for a 64KB buffer.

Truncate function also enables compression if message doesn't fit in
the buffer uncompressed but fits if it is compressed.

See docs: https://pkg.go.dev/github.com/miekg/dns#Msg.Truncate

Was originally found in
letsencrypt/pebble#536 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants