mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
A TCP retry to the server that just answered can only return the same rcode, and when that server accepted the connection and never answered, the query ran the full 10s dnsQueryTimeout and the client got nothing. An upstream rcode now ends the UDP/TCP race when it arrives, and the client gets it once every resolver has had udpRaceTimeout to answer instead of waiting for all of them to report. tcpQueryTimeout is also set on the conn, since a context cannot interrupt a blocked read, and a new dns_query_fwd_udp_read_ctx_done counter separates query teardown from upstream read errors. Fixes #20826 Signed-off-by: Brendan Creane <[email protected]>
163 lines
5.7 KiB
Go
163 lines
5.7 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package vnet
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
)
|
|
|
|
var vips = map[string]virtualIP{} // DNS name => details
|
|
|
|
var (
|
|
fakeDNS = newVIP("dns", "4.11.4.11", "2411::411")
|
|
fakeProxyControlplane = newVIP("controlplane.tailscale.com", 1)
|
|
fakeTestAgent = newVIP("test-driver.tailscale", 2)
|
|
fakeControl = newVIP("control.tailscale", 3)
|
|
fakeDERP1 = newVIP("derp1.tailscale", "33.4.0.1") // 3340=DERP; 1=derp 1
|
|
fakeDERP2 = newVIP("derp2.tailscale", "33.4.0.2") // 3340=DERP; 2=derp 2
|
|
fakeLogCatcher = newVIP("log.tailscale.com", 4)
|
|
fakeSyslog = newVIP("syslog.tailscale", 9)
|
|
fakeCloudInit = newVIP("cloud-init.tailscale", 5) // serves cloud-init metadata/userdata per node
|
|
fakeFiles = newVIP("files.tailscale", 6) // serves binary files (tta, tailscale, tailscaled) to VMs
|
|
fakeACME = newVIP("acme.example", 7) // fake ACME CA for vmtests
|
|
|
|
// fakeSplitDNS is a second DNS server, distinct from fakeDNS, serving only
|
|
// splitDNSZone.
|
|
fakeSplitDNS = newVIP("split-dns", "4.11.4.12", "2411::412")
|
|
|
|
// FakeDualStackWeb is a dual-stack webserver VIP used by
|
|
// TestExitNodeV4Only to verify that traffic works through an
|
|
// IPv4-only exit node even when DNS returns both A and AAAA.
|
|
FakeDualStackWeb = newVIP("dualstack-web.example.com", "5.0.0.100", "2052::5:100")
|
|
)
|
|
|
|
// The zone served *only* by fakeSplitDNS, never by the default fakeDNS. An
|
|
// answer of SplitDNSAddr for SplitDNSName therefore proves a split-DNS route to
|
|
// fakeSplitDNS was honored; point a route for SplitDNSDomain at
|
|
// [FakeSplitDNSIPv4] to verify that. Names are in DNS wire format, as the query
|
|
// parser produces them: no trailing dot.
|
|
const (
|
|
SplitDNSDomain = "split-dns.example"
|
|
SplitDNSName = "internal." + SplitDNSDomain
|
|
SplitDNSAddr = "10.99.1.1"
|
|
|
|
// SplitDNSBareName is a single label, for tests that need an
|
|
// upstream-only answer for a name no search domain has completed. Being
|
|
// outside SplitDNSDomain, it is reached by a resolver pointed at
|
|
// [FakeSplitDNSIPv4], not by a route for that domain.
|
|
SplitDNSBareName = "bare-upstream-only"
|
|
SplitDNSBareAddr = "10.99.1.2"
|
|
|
|
// SplitDNSRefusedName is answered REFUSED by fakeSplitDNS instead of with an
|
|
// address, for tests that need an upstream rcode rather than a resolution
|
|
// failure. Nothing in vnet serves DNS over TCP, and TCP to a DNS VIP is
|
|
// dropped rather than refused, so a forwarder that retries this rcode over
|
|
// TCP waits on an answer that never comes.
|
|
SplitDNSRefusedName = "refused." + SplitDNSDomain
|
|
)
|
|
|
|
// splitDNSZone holds the names served only by fakeSplitDNS.
|
|
var splitDNSZone = map[string]netip.Addr{
|
|
SplitDNSName: netip.MustParseAddr(SplitDNSAddr),
|
|
SplitDNSBareName: netip.MustParseAddr(SplitDNSBareAddr),
|
|
}
|
|
|
|
// FakeSplitDNSIPv4 returns the IPv4 address of the secondary (split-DNS) fake
|
|
// DNS server. It answers only [SplitDNSName] and [SplitDNSBareName].
|
|
func FakeSplitDNSIPv4() netip.Addr { return fakeSplitDNS.v4 }
|
|
|
|
// FakeSplitDNSIPv6 returns the IPv6 address of the secondary (split-DNS) fake
|
|
// DNS server.
|
|
func FakeSplitDNSIPv6() netip.Addr { return fakeSplitDNS.v6 }
|
|
|
|
type virtualIP struct {
|
|
name string // for DNS
|
|
v4 netip.Addr
|
|
v6 netip.Addr
|
|
}
|
|
|
|
func (v virtualIP) Match(a netip.Addr) bool {
|
|
return v.v4 == a.Unmap() || v.v6 == a
|
|
}
|
|
|
|
// TestDriverIPv4 returns the IPv4 address of the test driver VIP (52.52.0.2).
|
|
// TTA agents dial this IP on port TestDriverPort to connect to the test harness.
|
|
func TestDriverIPv4() netip.Addr { return fakeTestAgent.v4 }
|
|
|
|
// TestDriverPort is the port the test driver listens on.
|
|
const TestDriverPort = 8008
|
|
|
|
// FakeDNSIPv4 returns the fake DNS IPv4 address.
|
|
func FakeDNSIPv4() netip.Addr { return fakeDNS.v4 }
|
|
|
|
// FakeLogCatcherIPv4 returns the IPv4 address of the fake log.tailscale.com,
|
|
// which collects the tailscaled logs that [Server.NodeLogs] returns. It
|
|
// accepts uploads over HTTPS on port 443 and over plain HTTP on port 80.
|
|
func FakeLogCatcherIPv4() netip.Addr { return fakeLogCatcher.v4 }
|
|
|
|
// FakeDNSIPv6 returns the fake DNS IPv6 address.
|
|
func FakeDNSIPv6() netip.Addr { return fakeDNS.v6 }
|
|
|
|
// FakeSyslogIPv4 returns the fake syslog IPv4 address.
|
|
func FakeSyslogIPv4() netip.Addr { return fakeSyslog.v4 }
|
|
|
|
// FakeSyslogIPv6 returns the fake syslog IPv6 address.
|
|
func FakeSyslogIPv6() netip.Addr { return fakeSyslog.v6 }
|
|
|
|
// newVIP returns a new virtual IP.
|
|
//
|
|
// opts may be an IPv4 an IPv6 (in string form) or an int (bounded by uint8) to
|
|
// use IPv4 of 52.52.0.x.
|
|
//
|
|
// If the IPv6 is omitted, one is derived from the IPv4.
|
|
//
|
|
// If an opt is invalid or the DNS name is already used, it panics.
|
|
func newVIP(name string, opts ...any) (v virtualIP) {
|
|
if _, ok := vips[name]; ok {
|
|
panic(fmt.Sprintf("duplicate VIP %q", name))
|
|
}
|
|
v.name = name
|
|
for _, o := range opts {
|
|
switch o := o.(type) {
|
|
case string:
|
|
if ip, err := netip.ParseAddr(o); err == nil {
|
|
if ip.Is4() {
|
|
v.v4 = ip
|
|
} else if ip.Is6() {
|
|
v.v6 = ip
|
|
}
|
|
} else {
|
|
panic(fmt.Sprintf("unsupported string option %q", o))
|
|
}
|
|
case int:
|
|
if o <= 0 || o > 255 {
|
|
panic(fmt.Sprintf("bad octet %d", o))
|
|
}
|
|
v.v4 = netip.AddrFrom4([4]byte{52, 52, 0, byte(o)})
|
|
default:
|
|
panic(fmt.Sprintf("unknown option type %T", o))
|
|
}
|
|
}
|
|
if !v.v6.IsValid() && v.v4.IsValid() {
|
|
// Map 1.2.3.4 to 2052::0102:0304
|
|
// But make 52.52.0.x map to 2052::x
|
|
a := [16]byte{0: 0x20, 1: 0x52} // 2052::
|
|
v4 := v.v4.As4()
|
|
if v4[0] == 52 && v4[1] == 52 && v4[2] == 0 {
|
|
a[15] = v4[3]
|
|
} else {
|
|
copy(a[12:], v.v4.AsSlice())
|
|
}
|
|
v.v6 = netip.AddrFrom16(a)
|
|
}
|
|
for _, b := range vips {
|
|
if b.Match(v.v4) || b.Match(v.v6) {
|
|
panic(fmt.Sprintf("VIP %q collides with %q", name, v.name))
|
|
}
|
|
}
|
|
vips[name] = v
|
|
return v
|
|
}
|