Merge branch 'XTLS:main' into dns-new-f

This commit is contained in:
patterniha 2025-05-07 03:28:38 +03:30 committed by GitHub
commit a81a8fee84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 75 additions and 52 deletions

View file

@ -2,7 +2,6 @@ package dns
import (
"context"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/strmatcher"
@ -41,8 +40,6 @@ func NewStaticHosts(hosts []*Config_HostMapping) (*StaticHosts, error) {
}
ips = append(ips, addr)
}
default:
return nil, errors.New("neither IP address nor proxied domain specified for domain: ", mapping.Domain).AtWarning()
}
sh.ips[id] = ips
@ -62,9 +59,14 @@ func filterIP(ips []net.Address, option dns.IPOption) []net.Address {
}
func (h *StaticHosts) lookupInternal(domain string) []net.Address {
var ips []net.Address
ips := make([]net.Address, 0)
found := false
for _, id := range h.matchers.Match(domain) {
ips = append(ips, h.ips[id]...)
found = true
}
if !found {
return nil
}
return ips
}
@ -72,7 +74,7 @@ func (h *StaticHosts) lookupInternal(domain string) []net.Address {
func (h *StaticHosts) lookup(domain string, option dns.IPOption, maxDepth int) []net.Address {
switch addrs := h.lookupInternal(domain); {
case len(addrs) == 0: // Not recorded in static hosts, return nil
return nil
return addrs
case len(addrs) == 1 && addrs[0].Family().IsDomain(): // Try to unwrap domain
errors.LogDebug(context.Background(), "found replaced domain: ", domain, " -> ", addrs[0].Domain(), ". Try to unwrap it")
if maxDepth > 0 {