fix: echo edns0 opt in dns replies when the request carries one - #3041
Merged
Conversation
Collaborator
|
You should also add a comment in the code explaining the choice of the value 1232; otherwise, readers might be confused about where this "magic number" comes from. |
Author
Added |
This was referenced Jul 29, 2026
onesyue
pushed a commit
to onesyue/mihomo
that referenced
this pull request
Aug 11, 2026
…CubeX#3041) (cherry picked from commit ace2037)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
RFC 6891 requires a responder to include an OPT record whenever the request
carries one:
mihomo strips the upstream OPT before caching , which is itself correct — OPT
is a per-hop pseudo-record and must not be cached:
mihomo/dns/util.go
Lines 69 to 72 in f298cd2
But it never generated a fresh OPT when answering, so cache hits were
plain-DNS replies. Clients such as systemd-resolved treat a missing OPT as an
EDNS0 failure (
dns_server_packet_bad_opt)and downgrade the server:
after which they periodically re-probe, adding timeouts and extra round trips.
Fix
Synthesize an OPT at the
ServeMsgconvergence point (covers both the DNSlistener and the TUN hijack path) when the request has one and the reply does
not:
RFC 3225 §3:
Verification
Before the fix the second (cached) reply has no
OPT PSEUDOSECTION, andresolvectl log-level debugshows the downgrade message above; after the fixthe OPT is present on every reply and the feature set stays
UDP+EDNS0.systemd-resolved works well
dig dns query works well
verify config: