Skip to content

Commit e62bfe0

Browse files
chore: change DNS record TTL from 10 minutes to 2 seconds (#70)
Relates to coder/internal#466 This modifies the TTL of all DNS records programmed into the DNS resolver. I've tested this by running Coder Desktop macOS against a fresh dylib: ``` $ dig -6 @fD60:627a:a42b::53 pog2.coder AAAA ; <<>> DiG 9.10.6 <<>> -6 @fD60:627a:a42b::53 pog2.coder AAAA ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37590 ;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;pog2.coder. IN AAAA ;; ANSWER SECTION: pog2.coder. 2 IN AAAA fd60:627a:a42b:415e:bb03:e708:fd73:c6cb ;; Query time: 6 msec ;; SERVER: fd60:627a:a42b::53#53(fd60:627a:a42b::53) ;; WHEN: Wed Apr 09 15:14:20 AEST 2025 ;; MSG SIZE rcvd: 66 ```
1 parent c998353 commit e62bfe0

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

net/dns/resolver/tsdns.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ const dnsSymbolicFQDN = "magicdns.localhost-tailscale-daemon."
4545
const maxResponseBytes = 4095
4646

4747
// defaultTTL is the TTL of all responses from Resolver.
48-
const defaultTTL = 600 * time.Second
48+
// Coder: We've changed this from 10 minutes to 2 seconds, as we'd like to use
49+
// the existence of Coder Connect DNS records to determine whether Coder Connect
50+
// is running.
51+
const defaultTTL = 2 * time.Second
4952

5053
var (
5154
errNotQuery = errors.New("not a DNS query")

net/dns/resolver/tsdns_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ var allResponse = []byte{
730730
// Answer:
731731
0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x03, 0x69, 0x70, 0x6e, 0x03, 0x64, 0x65, 0x76, 0x00, // name
732732
0x00, 0x01, 0x00, 0x01, // type A, class IN
733-
0x00, 0x00, 0x02, 0x58, // TTL: 600
733+
0x00, 0x00, 0x00, 0x02, // TTL: 2
734734
0x00, 0x04, // length: 4 bytes
735735
0x01, 0x02, 0x03, 0x04, // A: 1.2.3.4
736736
}
@@ -747,7 +747,7 @@ var ipv4Response = []byte{
747747
// Answer:
748748
0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x03, 0x69, 0x70, 0x6e, 0x03, 0x64, 0x65, 0x76, 0x00, // name
749749
0x00, 0x01, 0x00, 0x01, // type A, class IN
750-
0x00, 0x00, 0x02, 0x58, // TTL: 600
750+
0x00, 0x00, 0x00, 0x02, // TTL: 2
751751
0x00, 0x04, // length: 4 bytes
752752
0x01, 0x02, 0x03, 0x04, // A: 1.2.3.4
753753
}
@@ -764,7 +764,7 @@ var ipv6Response = []byte{
764764
// Answer:
765765
0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x03, 0x69, 0x70, 0x6e, 0x03, 0x64, 0x65, 0x76, 0x00, // name
766766
0x00, 0x1c, 0x00, 0x01, // type AAAA, class IN
767-
0x00, 0x00, 0x02, 0x58, // TTL: 600
767+
0x00, 0x00, 0x00, 0x02, // TTL: 2
768768
0x00, 0x10, // length: 16 bytes
769769
// AAAA: 0001:0203:0405:0607:0809:0A0B:0C0D:0E0F
770770
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0xb, 0xc, 0xd, 0xe, 0xf,
@@ -782,7 +782,7 @@ var ipv4UppercaseResponse = []byte{
782782
// Answer:
783783
0x05, 0x54, 0x45, 0x53, 0x54, 0x31, 0x03, 0x49, 0x50, 0x4e, 0x03, 0x44, 0x45, 0x56, 0x00, // name
784784
0x00, 0x01, 0x00, 0x01, // type A, class IN
785-
0x00, 0x00, 0x02, 0x58, // TTL: 600
785+
0x00, 0x00, 0x00, 0x02, // TTL: 2
786786
0x00, 0x04, // length: 4 bytes
787787
0x01, 0x02, 0x03, 0x04, // A: 1.2.3.4
788788
}
@@ -801,7 +801,7 @@ var ptrResponse = []byte{
801801
0x01, 0x34, 0x01, 0x33, 0x01, 0x32, 0x01, 0x31, 0x07,
802802
0x69, 0x6e, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61, 0x00,
803803
0x00, 0x0c, 0x00, 0x01, // type PTR, class IN
804-
0x00, 0x00, 0x02, 0x58, // TTL: 600
804+
0x00, 0x00, 0x00, 0x02, // TTL: 2
805805
0x00, 0x0f, // length: 15 bytes
806806
// PTR: test1.ipn.dev
807807
0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x03, 0x69, 0x70, 0x6e, 0x03, 0x64, 0x65, 0x76, 0x00,
@@ -837,7 +837,7 @@ var ptrResponse6 = []byte{
837837
0x03, 0x69, 0x70, 0x36,
838838
0x04, 0x61, 0x72, 0x70, 0x61, 0x00,
839839
0x00, 0x0c, 0x00, 0x01, // type PTR, class IN
840-
0x00, 0x00, 0x02, 0x58, // TTL: 600
840+
0x00, 0x00, 0x00, 0x02, // TTL: 2
841841
0x00, 0x0f, // length: 15 bytes
842842
// PTR: test2.ipn.dev
843843
0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x03, 0x69, 0x70, 0x6e, 0x03, 0x64, 0x65, 0x76, 0x00,
@@ -1162,34 +1162,33 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
11621162
{
11631163
Type: dns.TypeA,
11641164
Name: "one-a.test.",
1165-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05one-a\x04test\x00\x00\x01\x00\x01\x05one-a\x04test\x00\x00\x01\x00\x01\x00\x00\x02X\x00\x04\x01\x02\x03\x04"),
1165+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05one-a\x04test\x00\x00\x01\x00\x01\x05one-a\x04test\x00\x00\x01\x00\x01\x00\x00\x00\x02\x00\x04\x01\x02\x03\x04"),
11661166
},
11671167
{
11681168
Type: dns.TypeA,
11691169
Name: "two-a.test.",
1170-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x05two-a\x04test\x00\x00\x01\x00\x01\xc0\f\x00\x01\x00\x01\x00\x00\x02X\x00\x04\x01\x02\x03\x04\xc0\f\x00\x01\x00\x01\x00\x00\x02X\x00\x04\x05\x06\a\b"),
1170+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x05two-a\x04test\x00\x00\x01\x00\x01\xc0\f\x00\x01\x00\x01\x00\x00\x00\x02\x00\x04\x01\x02\x03\x04\xc0\f\x00\x01\x00\x01\x00\x00\x00\x02\x00\x04\x05\x06\a\b"),
11711171
},
11721172
{
11731173
Type: dns.TypeAAAA,
11741174
Name: "one-aaaa.test.",
1175-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\bone-aaaa\x04test\x00\x00\x1c\x00\x01\bone-aaaa\x04test\x00\x00\x1c\x00\x01\x00\x00\x02X\x00\x10\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"),
1175+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\bone-aaaa\x04test\x00\x00\x1c\x00\x01\bone-aaaa\x04test\x00\x00\x1c\x00\x01\x00\x00\x00\x02\x00\x10\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"),
11761176
},
11771177
{
11781178
Type: dns.TypeAAAA,
11791179
Name: "two-aaaa.test.",
1180-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\btwo-aaaa\x04test\x00\x00\x1c\x00\x01\xc0\f\x00\x1c\x00\x01\x00\x00\x02X\x00\x10\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xc0\f\x00\x1c\x00\x01\x00\x00\x02X\x00\x10\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"),
1180+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\btwo-aaaa\x04test\x00\x00\x1c\x00\x01\xc0\f\x00\x1c\x00\x01\x00\x00\x00\x02\x00\x10\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xc0\f\x00\x1c\x00\x01\x00\x00\x00\x02\x00\x10\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"),
11811181
},
11821182
{
11831183
Type: dns.TypePTR,
11841184
Name: "4.3.2.1.in-addr.arpa.",
1185-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x014\x013\x012\x011\ain-addr\x04arpa\x00\x00\f\x00\x01\x014\x013\x012\x011\ain-addr\x04arpa\x00\x00\f\x00\x01\x00\x00\x02X\x00\t\x03foo\x03com\x00"),
1185+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x014\x013\x012\x011\ain-addr\x04arpa\x00\x00\f\x00\x01\x014\x013\x012\x011\ain-addr\x04arpa\x00\x00\f\x00\x01\x00\x00\x00\x02\x00\t\x03foo\x03com\x00"),
11861186
},
11871187
{
11881188
Type: dns.TypeCNAME,
11891189
Name: "cname.test.",
1190-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05cname\x04test\x00\x00\x05\x00\x01\x05cname\x04test\x00\x00\x05\x00\x01\x00\x00\x02X\x00\x10\nthe-target\x03foo\x00"),
1190+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x05cname\x04test\x00\x00\x05\x00\x01\x05cname\x04test\x00\x00\x05\x00\x01\x00\x00\x00\x02\x00\x10\nthe-target\x03foo\x00"),
11911191
},
1192-
11931192
// No records of various types
11941193
{
11951194
Type: dns.TypeA,
@@ -1214,17 +1213,17 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
12141213
{
12151214
Type: dns.TypeTXT,
12161215
Name: "txt.test.",
1217-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x03\x00\x00\x00\x00\x03txt\x04test\x00\x00\x10\x00\x01\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x02X\x00\t\btxt1=one\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x02X\x00\t\btxt2=two\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x02X\x00\v\ntxt3=three"),
1216+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x03\x00\x00\x00\x00\x03txt\x04test\x00\x00\x10\x00\x01\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x02\x00\t\btxt1=one\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x02\x00\t\btxt2=two\x03txt\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x02\x00\v\ntxt3=three"),
12181217
},
12191218
{
12201219
Type: dns.TypeSRV,
12211220
Name: "srv.test.",
1222-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x03srv\x04test\x00\x00!\x00\x01\x03srv\x04test\x00\x00!\x00\x01\x00\x00\x02X\x00\x0f\x00\x01\x00\x02\x00\x03\x03foo\x03com\x00\x03srv\x04test\x00\x00!\x00\x01\x00\x00\x02X\x00\x0f\x00\x04\x00\x05\x00\x06\x03bar\x03com\x00"),
1221+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x03srv\x04test\x00\x00!\x00\x01\x03srv\x04test\x00\x00!\x00\x01\x00\x00\x00\x02\x00\x0f\x00\x01\x00\x02\x00\x03\x03foo\x03com\x00\x03srv\x04test\x00\x00!\x00\x01\x00\x00\x00\x02\x00\x0f\x00\x04\x00\x05\x00\x06\x03bar\x03com\x00"),
12231222
},
12241223
{
12251224
Type: dns.TypeNS,
12261225
Name: "ns.test.",
1227-
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x02ns\x04test\x00\x00\x02\x00\x01\x02ns\x04test\x00\x00\x02\x00\x01\x00\x00\x02X\x00\t\x03ns1\x03foo\x00\x02ns\x04test\x00\x00\x02\x00\x01\x00\x00\x02X\x00\t\x03ns2\x03bar\x00"),
1226+
Check: matchPacked("\x00{\x84\x00\x00\x01\x00\x02\x00\x00\x00\x00\x02ns\x04test\x00\x00\x02\x00\x01\x02ns\x04test\x00\x00\x02\x00\x01\x00\x00\x00\x02\x00\t\x03ns1\x03foo\x00\x02ns\x04test\x00\x00\x02\x00\x01\x00\x00\x00\x02\x00\t\x03ns2\x03bar\x00"),
12281227
},
12291228
}
12301229

0 commit comments

Comments
 (0)