fix: let doh/dot server follow hosts and can remotely resolve itself ip

This commit is contained in:
wwqgtxx
2022-12-07 20:01:44 +08:00
parent e03fcd24dd
commit a6f7e1472b
7 changed files with 76 additions and 81 deletions

View File

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"net"
"net/netip"
"runtime"
"strconv"
"sync"
@ -41,8 +40,6 @@ const (
DefaultTimeout = time.Second * 5
)
type dialHandler func(ctx context.Context, network, addr string) (net.Conn, error)
// dnsOverQUIC is a struct that implements the Upstream interface for the
// DNS-over-QUIC protocol (spec: https://www.rfc-editor.org/rfc/rfc9250.html).
type dnsOverQUIC struct {
@ -345,12 +342,7 @@ func (doq *dnsOverQUIC) openConnection(ctx context.Context) (conn quic.Connectio
return nil, err
}
} else {
ipAddr, err := netip.ParseAddr(ip)
if err != nil {
return nil, err
}
conn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", ipAddr, port)
conn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", addr, doq.r)
if err != nil {
return nil, err
}
@ -498,21 +490,3 @@ func isQUICRetryError(err error) (ok bool) {
return false
}
func getDialHandler(r *Resolver, proxyAdapter string) dialHandler {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
ip, err := r.ResolveIP(ctx, host)
if err != nil {
return nil, err
}
if len(proxyAdapter) == 0 {
return dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), port), dialer.WithDirect())
} else {
return dialContextExtra(ctx, proxyAdapter, network, ip.Unmap(), port)
}
}
}