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

@ -38,14 +38,15 @@ type IPRecord struct {
RawHeader *dnsmessage.Header
}
func (r *IPRecord) getIPs() ([]net.Address, error) {
func (r *IPRecord) getIPs() ([]net.Address, uint32, error) {
if r == nil || r.Expire.Before(time.Now()) {
return nil, errRecordNotFound
return nil, 0, errRecordNotFound
}
if r.RCode != dnsmessage.RCodeSuccess {
return nil, dns_feature.RCodeError(r.RCode)
return nil, 0, dns_feature.RCodeError(r.RCode)
}
return r.IP, nil
ttl := uint32(time.Until(r.Expire) / time.Second)
return r.IP, ttl, nil
}
func isNewer(baseRec *IPRecord, newRec *IPRecord) bool {