From 04b6e709b74a72ade906a13dc76711b734602f51 Mon Sep 17 00:00:00 2001 From: rammiah Date: Sat, 3 Aug 2024 15:37:01 +0800 Subject: [PATCH] feat: dns server ipv6 option --- dns/doh.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dns/doh.go b/dns/doh.go index 97e01ea7..bb4b9bf5 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -16,6 +16,7 @@ import ( "time" "github.com/metacubex/mihomo/component/ca" + "github.com/metacubex/mihomo/component/resolver" C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/log" "github.com/metacubex/quic-go" @@ -67,6 +68,7 @@ type dnsOverHTTPS struct { dialer *dnsDialer addr string skipCertVerify bool + ipv6 bool } // type check @@ -93,11 +95,15 @@ func newDoHClient(urlString string, r *Resolver, preferH3 bool, params map[strin TokenStore: newQUICTokenStore(), }, httpVersions: httpVersions, + ipv6: resolver.DisableIPv6, } if params["skip-cert-verify"] == "true" { doh.skipCertVerify = true } + if params["ipv6"] == "false" { + doh.ipv6 = false + } runtime.SetFinalizer(doh, (*dnsOverHTTPS).Close) @@ -110,6 +116,10 @@ func (doh *dnsOverHTTPS) Address() string { } func (doh *dnsOverHTTPS) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) { + // check is ipv6 query + if m.Question[0].Qtype == D.TypeAAAA && !doh.ipv6 { + return handleMsgWithEmptyAnswer(m), nil + } // Quote from https://www.rfc-editor.org/rfc/rfc8484.html: // In order to maximize HTTP cache friendliness, DoH clients using media // formats that include the ID field from the DNS message header, such