mirror of
https://github.com/daeuniverse/dae.git
synced 2024-12-22 22:25:00 +07:00
remove zero ttl and recover normal ttl
This commit is contained in:
parent
689fa0f01c
commit
e82444e281
@ -6,6 +6,7 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"math"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
@ -21,16 +22,20 @@ type DnsCache struct {
|
||||
|
||||
func (c *DnsCache) FillInto(req *dnsmessage.Message) {
|
||||
req.Answers = deepcopy.Copy(c.Answers).([]dnsmessage.Resource)
|
||||
// No need to align because of no flipping now.
|
||||
//// Align question and answer Name.
|
||||
//if len(req.Questions) > 0 {
|
||||
// q := req.Questions[0]
|
||||
// for i := range req.Answers {
|
||||
// if strings.EqualFold(req.Answers[i].Header.Name.String(), q.Name.String()) {
|
||||
// req.Answers[i].Header.Name.Data = q.Name.Data
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
now := time.Now()
|
||||
// Set ttl.
|
||||
// TODO: give a domain hash (uint64) and let us to know whether the domain matches.
|
||||
for i := range req.Answers {
|
||||
// Use ceil because we want downstream to send requests to us after our cache missing.
|
||||
ttl := math.Ceil(c.Deadline.Sub(now).Seconds())
|
||||
if ttl < 0 {
|
||||
ttl = 0
|
||||
} else if ttl > math.MaxUint32 {
|
||||
ttl = math.MaxUint32 - 1
|
||||
}
|
||||
req.Answers[i].Header.TTL = uint32(ttl)
|
||||
}
|
||||
|
||||
req.RCode = dnsmessage.RCodeSuccess
|
||||
req.Response = true
|
||||
req.RecursionAvailable = true
|
||||
|
@ -220,13 +220,6 @@ func (c *DnsController) DnsRespHandler(data []byte, validateRushAns bool) (newMs
|
||||
return &msg, nil
|
||||
}
|
||||
|
||||
// Set ttl.
|
||||
for i := range msg.Answers {
|
||||
// Set TTL = zero. This requests applications must resend every request.
|
||||
// However, it may be not defined in the standard.
|
||||
msg.Answers[i].Header.TTL = 0
|
||||
}
|
||||
|
||||
// Check if request A/AAAA record.
|
||||
var reqIpRecord bool
|
||||
loop:
|
||||
|
Loading…
Reference in New Issue
Block a user