feat(resolver): support udp:///tcp:///tls:// schemes in RESOLVER_ADDRESS - #1212
Open
yangyaofei wants to merge 1 commit into
Open
feat(resolver): support udp:///tcp:///tls:// schemes in RESOLVER_ADDRESS#1212yangyaofei wants to merge 1 commit into
yangyaofei wants to merge 1 commit into
Conversation
Scheme-prefixed addresses were silently mis-parsed: validation passed (net.SplitHostPort splits at the last colon, so "tls://223.5.5.5" yielded host=tls, port=//223.5.5.5) while every lookup failed at dial time with a cryptic "unknown port" error, leaving the built-in healthcheck permanently unhealthy and making record updates blind writes. - parse optional scheme prefixes and select the transport accordingly; defaults to plaintext UDP when no scheme is present (unchanged) - apply transport default ports when omitted: udp/tcp -> :53, tls -> :853 - DNS-over-TLS dials TCP then wraps the conn in tls.Client with ServerName set from the address host; the handshake honors the resolver context deadline. A tls.Conn satisfies net.Conn so it plugs directly into net.Resolver.Dial (PreferGo is already set) - fail fast on unknown schemes (e.g. https://) instead of passing them through as garbage dial targets Fixes qdm12#1211
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.
Fixes #1211
Root cause
RESOLVER_ADDRESSvalues carrying a scheme prefix (tls://223.5.5.5in my case, to dodge fake-IP DNS hijacking on my LAN) were silently mis-parsed:Settings.validate()rannet.SplitHostPort()before any scheme handling — and Go splits at the last colon, sotls://223.5.5.5"validated" ashost=tls,port=//223.5.5.5New()then installed a custom Dial closure hardcodingprotocol = "udp"and dialing the raw string including the scheme → every lookup failed withlookup udp///223.5.5.5: unknown portshouldUpdateRecordWithLookuptreats lookup failure as "update anyway" → blind unconditional record writes every periodChanges
1.1.1.1,udp://…tcp://…tls://…splitTransport); unknown schemes now fail fast with an actionable error instead of garbage dial targetstls.ClientwithServerNamefrom the address host; handshake honors the resolver context deadline; atls.Connsatisfiesnet.Connso it plugs straight intonet.Resolver.Dial(PreferGoalready set)Testing
With this patch both consequences above disappear: lookups succeed behind DNS-hijacking middleboxes, so the update-loop comparison is meaningful again and the built-in healthcheck goes green.