Skip to content

Commit

Permalink
dnsforward: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jan 23, 2023
1 parent a580e92 commit de3e84b
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions internal/dnsforward/dns64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dnsforward

import (
"fmt"
"math"
"net"
"net/netip"

Expand Down Expand Up @@ -181,11 +180,10 @@ func (s *Server) synthDNS64(origReq, origResp, resp *dns.Msg) (ok bool) {
}

// The Time to Live (TTL) field is set to the minimum of the TTL of the
// original A RR and the SOA RR for the queried domain.
//
// Set initially to [math.MaxUint32], so that if there is no SOA record, the
// TTL will still be set according to the rules.
soaTTL := uint32(math.MaxUint32)
// original A RR and the SOA RR for the queried domain. If the original
// response contains no SOA records, the minimum of the TTL of the original
// A RR and [maxDNS64SynTTL] should be used. See [maxDNS64SynTTL].
soaTTL := maxDNS64SynTTL
for _, rr := range origResp.Ns {
if hdr := rr.Header(); hdr.Rrtype == dns.TypeSOA && hdr.Name == origReq.Question[0].Name {
soaTTL = hdr.Ttl
Expand Down Expand Up @@ -277,9 +275,7 @@ func (s *Server) performDNS64(prx *proxy.Proxy, dctx *dnsContext) (rc resultCode
// synthRR synthesizes a DNS64 resource record in compliance with RFC 6147. If
// rr is not an A record, it's returned as is. A records are modified to become
// a DNS64-synthesized AAAA records, and the TTL is set according to the
// original TTL of a record and soaTTL. If the original response contains no
// SOA records, soaTTL is expected to be [mathMaxUint32]. It returns nil on
// invalid A records.
// original TTL of a record and soaTTL. It returns nil on invalid A records.
func (s *Server) synthRR(rr dns.RR, soaTTL uint32) (result dns.RR) {
aResp, ok := rr.(*dns.A)
if !ok {
Expand All @@ -302,13 +298,6 @@ func (s *Server) synthRR(rr dns.RR, soaTTL uint32) (result dns.RR) {
AAAA: s.mapDNS64(addr),
}

// Use [maxDNS64SynTTL] as value of SOA's TTL in case the SOA record is
// absent since the resulting TTL still should be picked as the minimum of
// the original TTL and the compared value.
if soaTTL == math.MaxUint32 {
soaTTL = maxDNS64SynTTL
}

if rrTTL := aResp.Hdr.Ttl; rrTTL < soaTTL {
aaaa.Hdr.Ttl = rrTTL
} else {
Expand Down

0 comments on commit de3e84b

Please sign in to comment.