DNS: Add allowUnexpectedIPs for DnsServerObject (#4497)

Closes https://github.com/XTLS/Xray-core/issues/4424
This commit is contained in:
patterniha 2025-03-20 13:09:02 +01:00 committed by GitHub
parent 335845a9b2
commit 6a211a0bb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 34 deletions

View file

@ -25,11 +25,12 @@ type Server interface {
// Client is the interface for DNS client.
type Client struct {
server Server
clientIP net.IP
skipFallback bool
domains []string
expectIPs []*router.GeoIPMatcher
server Server
clientIP net.IP
skipFallback bool
domains []string
expectIPs []*router.GeoIPMatcher
allowUnexpectedIPs bool
}
var errExpectedIPNonMatch = errors.New("expectIPs not match")
@ -166,6 +167,7 @@ func NewClient(
client.skipFallback = ns.SkipFallback
client.domains = rules
client.expectIPs = matchers
client.allowUnexpectedIPs = ns.AllowUnexpectedIPs
return nil
})
return client, err
@ -203,6 +205,9 @@ func (c *Client) MatchExpectedIPs(domain string, ips []net.IP) ([]net.IP, error)
}
}
if len(newIps) == 0 {
if c.allowUnexpectedIPs {
return ips, nil
}
return nil, errExpectedIPNonMatch
}
errors.LogDebug(context.Background(), "domain ", domain, " expectIPs ", newIps, " matched at server ", c.Name())