Skip to content

Commit 2fe28bd

Browse files
committed
dnsx,xdns: 1s ttl for block/alg responses
1 parent 6ecf947 commit 2fe28bd

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

intra/dnsx/alg.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ import (
2727
)
2828

2929
const (
30-
timeout = 15 * time.Second
31-
ttl2m = 2 * time.Minute // 2m ttl for alg/nat ip
32-
algttl = 15 // 15s ttl for alg dns
33-
key4 = ":a"
34-
key6 = ":aaaa"
30+
timeout = 15 * time.Second
31+
ttl2m = 2 * time.Minute // 2m ttl for alg/nat ip
32+
33+
algXlatTtl = xdns.BlockTTL
34+
algFixedAnsTtl = xdns.AnsTTL
35+
36+
key4 = ":a"
37+
key6 = ":aaaa"
38+
3539
notransport = "NoTransport"
36-
maxiter = 100 // max number alg/nat evict iterations
40+
41+
maxiter = 100 // max number alg/nat evict iterations
3742
)
3843

3944
type iptype int
@@ -668,19 +673,19 @@ func (t *dnsgateway) q(t1, t2 Transport, preset []netip.Addr, network string, q
668673
ansout := ansin.Copy()
669674
// TODO: substitute ips in additional section
670675
if algip4hints.IsValid() {
671-
substok4 = xdns.SubstSVCBRecordIPs( /*out*/ ansout, dns.SVCB_IPV4HINT, algip4hints, algttl) || substok4
676+
substok4 = xdns.SubstSVCBRecordIPs( /*out*/ ansout, dns.SVCB_IPV4HINT, algip4hints, algXlatTtl) || substok4
672677
mustsubst = true
673678
}
674679
if algip6hints.IsValid() {
675-
substok6 = xdns.SubstSVCBRecordIPs( /*out*/ ansout, dns.SVCB_IPV6HINT, algip6hints, algttl) || substok6
680+
substok6 = xdns.SubstSVCBRecordIPs( /*out*/ ansout, dns.SVCB_IPV6HINT, algip6hints, algXlatTtl) || substok6
676681
mustsubst = true
677682
}
678683
if algip4s.IsValid() {
679-
substok4 = xdns.SubstARecords( /*out*/ ansout, algip4s, algttl) || substok4
684+
substok4 = xdns.SubstARecords( /*out*/ ansout, algip4s, algXlatTtl) || substok4
680685
mustsubst = true
681686
}
682687
if algip6s.IsValid() {
683-
substok6 = xdns.SubstAAAARecords( /*out*/ ansout, algip6s, algttl) || substok6
688+
substok6 = xdns.SubstAAAARecords( /*out*/ ansout, algip6s, algXlatTtl) || substok6
684689
mustsubst = true
685690
}
686691

@@ -1337,13 +1342,12 @@ func synthesizeOrQuery(preset []netip.Addr, tr Transport, msg *dns.Msg, network
13371342
return nil, errNoAnswer
13381343
}
13391344
var ok4, ok6 bool
1340-
ttl := int(xdns.AnsTTL)
13411345
ip4s, ip6s := splitIPFamilies(preset)
13421346
if len(ip4s) > 0 {
1343-
ok4 = xdns.SubstSVCBRecordIPs( /*out*/ ans, dns.SVCB_IPV4HINT, ip4s[0], ttl)
1347+
ok4 = xdns.SubstSVCBRecordIPs( /*out*/ ans, dns.SVCB_IPV4HINT, ip4s[0], algXlatTtl)
13441348
}
13451349
if len(ip6s) > 0 {
1346-
ok6 = xdns.SubstSVCBRecordIPs( /*out*/ ans, dns.SVCB_IPV6HINT, ip6s[0], ttl)
1350+
ok6 = xdns.SubstSVCBRecordIPs( /*out*/ ans, dns.SVCB_IPV6HINT, ip6s[0], algXlatTtl)
13471351
}
13481352

13491353
withPresetSummary(smm, true /*req sent?*/, fixed)

intra/xdns/common.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ const (
4444
)
4545

4646
var (
47-
CertMagic = [4]byte{0x44, 0x4e, 0x53, 0x43}
48-
ServerMagic = [8]byte{0x72, 0x36, 0x66, 0x6e, 0x76, 0x57, 0x6a, 0x38}
47+
CertMagic = [4]byte{0x44, 0x4e, 0x53, 0x43}
48+
ServerMagic = [8]byte{0x72, 0x36, 0x66, 0x6e, 0x76, 0x57, 0x6a, 0x38}
49+
)
50+
51+
const (
4952
MinDNSPacketSize = 12 + 5
5053
MaxDNSPacketSize = 4096
5154
MaxDNSUDPPacketSize = 4096
5255
MaxDNSUDPSafePacketSize = 1252
53-
BlockTTL = uint32(5)
56+
BlockTTL = uint32(1)
5457
AnsTTL = uint32(60)
5558
MaxMTU = 0xffff // 65k, ought to be enough for everybody
5659
)

intra/xdns/dnsutil.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func HasAAAAAnswer(msg *dns.Msg) bool {
717717
return false
718718
}
719719

720-
func SubstAAAARecords(out *dns.Msg, subip6s netip.Addr, ttl int) bool {
720+
func SubstAAAARecords(out *dns.Msg, subip6s netip.Addr, ttl uint32) bool {
721721
if out == nil || !subip6s.IsValid() {
722722
return false
723723
}
@@ -751,7 +751,7 @@ func SubstAAAARecords(out *dns.Msg, subip6s netip.Addr, ttl int) bool {
751751
return len(touched) > 0
752752
}
753753

754-
func SubstARecords(out *dns.Msg, subip4s netip.Addr, ttl int) bool {
754+
func SubstARecords(out *dns.Msg, subip4s netip.Addr, ttl uint32) bool {
755755
if out == nil || !subip4s.IsValid() {
756756
return false
757757
}
@@ -809,7 +809,7 @@ func httpsstr(r *dns.HTTPS) (s string) {
809809
return strings.TrimSpace(s)
810810
}
811811

812-
func SubstSVCBRecordIPs(out *dns.Msg, x dns.SVCBKey, subiphints netip.Addr, ttl int) bool {
812+
func SubstSVCBRecordIPs(out *dns.Msg, x dns.SVCBKey, subiphints netip.Addr, ttl uint32) bool {
813813
if out == nil || !subiphints.IsValid() {
814814
return false
815815
}
@@ -825,13 +825,13 @@ func SubstSVCBRecordIPs(out *dns.Msg, x dns.SVCBKey, subiphints netip.Addr, ttl
825825
rec.Value[j] = &dns.SVCBIPv6Hint{
826826
Hint: []net.IP{subiphints.AsSlice()},
827827
}
828-
rec.Hdr.Ttl = uint32(ttl)
828+
rec.Hdr.Ttl = ttl
829829
i++
830830
} else if k == x && x == dns.SVCB_IPV4HINT {
831831
rec.Value[j] = &dns.SVCBIPv4Hint{
832832
Hint: []net.IP{subiphints.AsSlice()},
833833
}
834-
rec.Hdr.Ttl = uint32(ttl)
834+
rec.Hdr.Ttl = ttl
835835
i++
836836
}
837837
}
@@ -848,13 +848,13 @@ func SubstSVCBRecordIPs(out *dns.Msg, x dns.SVCBKey, subiphints netip.Addr, ttl
848848
rec.Value[j] = &dns.SVCBIPv6Hint{
849849
Hint: []net.IP{subiphints.AsSlice()},
850850
}
851-
rec.Hdr.Ttl = uint32(ttl)
851+
rec.Hdr.Ttl = ttl
852852
i++
853853
} else if k == x && x == dns.SVCB_IPV4HINT {
854854
rec.Value[j] = &dns.SVCBIPv4Hint{
855855
Hint: []net.IP{subiphints.AsSlice()},
856856
}
857-
rec.Hdr.Ttl = uint32(ttl)
857+
rec.Hdr.Ttl = ttl
858858
i++
859859
}
860860
}
@@ -1043,11 +1043,10 @@ func HasHTTPQuestion(msg *dns.Msg) (ok bool) {
10431043
return
10441044
}
10451045

1046-
func MakeARecord(name string, ip4 string, expiry int) *dns.A {
1046+
func MakeARecord(name string, ip4 string, ttl uint32) *dns.A {
10471047
if len(ip4) <= 0 || len(name) <= 0 {
10481048
return nil
10491049
}
1050-
ttl := uint32(expiry)
10511050

10521051
b := net.ParseIP(ip4)
10531052
if len(b) <= 0 {
@@ -1065,11 +1064,10 @@ func MakeARecord(name string, ip4 string, expiry int) *dns.A {
10651064
return rec
10661065
}
10671066

1068-
func MakeAAAARecord(name string, ip6 string, expiry int) *dns.AAAA {
1067+
func MakeAAAARecord(name string, ip6 string, ttl uint32) *dns.AAAA {
10691068
if len(ip6) <= 0 || len(name) <= 0 {
10701069
return nil
10711070
}
1072-
ttl := uint32(expiry)
10731071

10741072
b := net.ParseIP(ip6)
10751073
if len(b) <= 0 {

0 commit comments

Comments
 (0)