Refine DNS Options

This commit is contained in:
JimhHan 2021-04-10 11:36:58 +08:00
parent f20c445974
commit 217844cc37
No known key found for this signature in database
GPG key ID: 48D5D7CF95157AC5
10 changed files with 82 additions and 55 deletions

View file

@ -199,18 +199,16 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
var err error
var ttl uint32 = 600
var opt = dns.LookupIP
var opt dns.Option
switch qType {
case dnsmessage.TypeA:
opt = dns.LookupIPv4
opt = dns.LookupIPv4Only
case dnsmessage.TypeAAAA:
opt = dns.LookupIPv6
opt = dns.LookupIPv6Only
}
opt.FakeEnable = true
ips, err = h.client.LookupOptions(domain, opt)
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()

View file

@ -59,15 +59,14 @@ func (h *Handler) policy() policy.Session {
}
func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Address) net.Address {
var opt = dns.LookupIP
var opt dns.Option
if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
opt = dns.LookupIPv4
opt = dns.LookupIPv4Only
} else if h.config.DomainStrategy == Config_USE_IP6 || (localAddr != nil && localAddr.Family().IsIPv6()) {
opt = dns.LookupIPv6
opt = dns.LookupIPv6Only
}
opt.FakeEnable = true
ips, err := h.dns.LookupOptions(domain, opt)
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))
}