mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-12 15:18:41 +00:00
Merge branch 'dns' into features-looutbound
This commit is contained in:
commit
ab3b0f843d
71 changed files with 2447 additions and 1156 deletions
|
@ -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())
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue