DNS: Support returning upstream TTL to clients (#4526)

Closes https://github.com/XTLS/Xray-core/issues/4527
This commit is contained in:
Meo597 2025-03-24 21:33:56 +08:00 committed by GitHub
parent 2d3210e4b8
commit 4afe2d0cff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 168 additions and 157 deletions

View file

@ -20,9 +20,9 @@ func (FakeDNSServer) Name() string {
return "FakeDNS"
}
func (f *FakeDNSServer) QueryIP(ctx context.Context, domain string, _ net.IP, opt dns.IPOption, _ bool) ([]net.IP, error) {
func (f *FakeDNSServer) QueryIP(ctx context.Context, domain string, _ net.IP, opt dns.IPOption, _ bool) ([]net.IP, uint32, error) {
if f.fakeDNSEngine == nil {
return nil, errors.New("Unable to locate a fake DNS Engine").AtError()
return nil, 0, errors.New("Unable to locate a fake DNS Engine").AtError()
}
var ips []net.Address
@ -34,13 +34,13 @@ func (f *FakeDNSServer) QueryIP(ctx context.Context, domain string, _ net.IP, op
netIP, err := toNetIP(ips)
if err != nil {
return nil, errors.New("Unable to convert IP to net ip").Base(err).AtError()
return nil, 0, errors.New("Unable to convert IP to net ip").Base(err).AtError()
}
errors.LogInfo(ctx, f.Name(), " got answer: ", domain, " -> ", ips)
if len(netIP) > 0 {
return netIP, nil
return netIP, 1, nil // fakeIP ttl is 1
}
return nil, dns.ErrEmptyResponse
return nil, 0, dns.ErrEmptyResponse
}