Merge branch 'dns' into features-looutbound

This commit is contained in:
秋のかえで 2021-04-14 23:24:22 +08:00
commit ab3b0f843d
No known key found for this signature in database
GPG key ID: B208CDDD55BEF92C
71 changed files with 2447 additions and 1156 deletions

View file

@ -43,6 +43,7 @@ type Handler struct {
func (h *Handler) Init(config *Config, dnsClient dns.Client) error {
h.client = dnsClient
if v, ok := dnsClient.(ownLinkVerifier); ok {
h.ownLinkVerifier = v
}
@ -198,22 +199,16 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
var err error
var ttl uint32 = 600
var opt dns.Option
switch qType {
case dnsmessage.TypeA:
ips, err = h.client.LookupIP(domain, dns.IPOption{
IPv4Enable: true,
IPv6Enable: false,
FakeEnable: true,
})
opt = dns.LookupIPv4Only
case dnsmessage.TypeAAAA:
ips, err = h.client.LookupIP(domain, dns.IPOption{
IPv4Enable: false,
IPv6Enable: true,
FakeEnable: true,
})
opt = dns.LookupIPv6Only
}
ips, err = h.client.LookupOptions(domain, opt, dns.LookupFake)
rcode := dns.RCodeFromError(err)
if rcode == 0 && len(ips) == 0 && err != dns.ErrEmptyResponse {
newError("ip query").Base(err).WriteToLog()
@ -228,7 +223,6 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
RecursionAvailable: true,
RecursionDesired: true,
Response: true,
Authoritative: true,
})
builder.EnableCompression()
common.Must(builder.StartQuestions())

View file

@ -59,26 +59,14 @@ func (h *Handler) policy() policy.Session {
}
func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Address) net.Address {
var option dns.IPOption = dns.IPOption{
IPv4Enable: true,
IPv6Enable: true,
FakeEnable: false,
}
var opt dns.Option
if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
option = dns.IPOption{
IPv4Enable: true,
IPv6Enable: false,
FakeEnable: false,
}
opt = dns.LookupIPv4Only
} else if h.config.DomainStrategy == Config_USE_IP6 || (localAddr != nil && localAddr.Family().IsIPv6()) {
option = dns.IPOption{
IPv4Enable: false,
IPv6Enable: true,
FakeEnable: false,
}
opt = dns.LookupIPv6Only
}
ips, err := h.dns.LookupIP(domain, option)
ips, err := h.dns.LookupOptions(domain, opt, dns.LookupNoFake)
if err != nil {
newError("failed to get IP address for domain ", domain).Base(err).WriteToLog(session.ExportIDToError(ctx))
}