diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index c714bb933..245c50b76 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -22,6 +22,7 @@ "tailscale.com/ipn" "tailscale.com/ipn/ipnstate" "tailscale.com/ipn/policy" + "tailscale.com/net/dns" "tailscale.com/net/interfaces" "tailscale.com/net/tsaddr" "tailscale.com/portlist" @@ -37,8 +38,7 @@ "tailscale.com/wgengine" "tailscale.com/wgengine/filter" "tailscale.com/wgengine/router" - "tailscale.com/wgengine/router/dns" - "tailscale.com/wgengine/tsdns" + rdns "tailscale.com/wgengine/router/dns" "tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg/nmcfg" ) @@ -847,8 +847,8 @@ func (b *LocalBackend) updateDNSMap(netMap *netmap.NetworkMap) { } set(netMap.Name, netMap.Addresses) - dnsMap := tsdns.NewMap(nameToIP, magicDNSRootDomains(netMap)) - // map diff will be logged in tsdns.Resolver.SetMap. + dnsMap := dns.NewMap(nameToIP, magicDNSRootDomains(netMap)) + // map diff will be logged in dns.Resolver.SetMap. b.e.SetDNSMap(dnsMap) } @@ -1420,7 +1420,7 @@ func (b *LocalBackend) authReconfig() { b.logf("[unexpected] dns proxied but no nameservers") proxied = false } - rcfg.DNS = dns.Config{ + rcfg.DNS = rdns.Config{ Nameservers: nm.DNS.Nameservers, Domains: nm.DNS.Domains, PerDomain: nm.DNS.PerDomain, diff --git a/wgengine/tsdns/forwarder.go b/net/dns/forwarder.go similarity index 99% rename from wgengine/tsdns/forwarder.go rename to net/dns/forwarder.go index 470748c4a..519c00027 100644 --- a/wgengine/tsdns/forwarder.go +++ b/net/dns/forwarder.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "bytes" @@ -316,7 +316,7 @@ func (c *fwdConn) send(packet []byte, dst net.Addr) { var b *backoff.Backoff // lazily initialized, since it is not needed in the common case backOff := func(err error) { if b == nil { - b = backoff.NewBackoff("tsdns-fwdConn-send", c.logf, 30*time.Second) + b = backoff.NewBackoff("dns-fwdConn-send", c.logf, 30*time.Second) } b.BackOff(context.Background(), err) } diff --git a/wgengine/tsdns/map.go b/net/dns/map.go similarity index 99% rename from wgengine/tsdns/map.go rename to net/dns/map.go index c51dbf59b..119b6cc0a 100644 --- a/wgengine/tsdns/map.go +++ b/net/dns/map.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "sort" diff --git a/wgengine/tsdns/map_test.go b/net/dns/map_test.go similarity index 99% rename from wgengine/tsdns/map_test.go rename to net/dns/map_test.go index dba9bb586..c438f95a0 100644 --- a/wgengine/tsdns/map_test.go +++ b/net/dns/map_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "fmt" diff --git a/wgengine/tsdns/neterr_darwin.go b/net/dns/neterr_darwin.go similarity index 97% rename from wgengine/tsdns/neterr_darwin.go rename to net/dns/neterr_darwin.go index 62bab6488..7fd621fc7 100644 --- a/wgengine/tsdns/neterr_darwin.go +++ b/net/dns/neterr_darwin.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "errors" diff --git a/wgengine/tsdns/neterr_other.go b/net/dns/neterr_other.go similarity index 95% rename from wgengine/tsdns/neterr_other.go rename to net/dns/neterr_other.go index d245d0c38..b652f6e8b 100644 --- a/wgengine/tsdns/neterr_other.go +++ b/net/dns/neterr_other.go @@ -4,7 +4,7 @@ // +build !darwin,!windows -package tsdns +package dns func networkIsDown(err error) bool { return false } func networkIsUnreachable(err error) bool { return false } diff --git a/wgengine/tsdns/neterr_windows.go b/net/dns/neterr_windows.go similarity index 97% rename from wgengine/tsdns/neterr_windows.go rename to net/dns/neterr_windows.go index 90f0db2ab..2b197ee2b 100644 --- a/wgengine/tsdns/neterr_windows.go +++ b/net/dns/neterr_windows.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "net" diff --git a/wgengine/tsdns/tsdns.go b/net/dns/tsdns.go similarity index 99% rename from wgengine/tsdns/tsdns.go rename to net/dns/tsdns.go index b68b8c04e..2b530b81e 100644 --- a/wgengine/tsdns/tsdns.go +++ b/net/dns/tsdns.go @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package tsdns provides a Resolver capable of resolving +// Package dns provides a Resolver capable of resolving // domains on a Tailscale network. -package tsdns +package dns import ( "encoding/hex" @@ -100,7 +100,7 @@ type ResolverConfig struct { // The root domain must be in canonical form (with a trailing period). func NewResolver(config ResolverConfig) *Resolver { r := &Resolver{ - logf: logger.WithPrefix(config.Logf, "tsdns: "), + logf: logger.WithPrefix(config.Logf, "dns: "), linkMon: config.LinkMonitor, queue: make(chan Packet, queueSize), responses: make(chan Packet), diff --git a/wgengine/tsdns/tsdns_server_test.go b/net/dns/tsdns_server_test.go similarity index 99% rename from wgengine/tsdns/tsdns_server_test.go rename to net/dns/tsdns_server_test.go index df9047fc6..95544ba18 100644 --- a/wgengine/tsdns/tsdns_server_test.go +++ b/net/dns/tsdns_server_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "log" diff --git a/wgengine/tsdns/tsdns_test.go b/net/dns/tsdns_test.go similarity index 99% rename from wgengine/tsdns/tsdns_test.go rename to net/dns/tsdns_test.go index 66a62d107..59bcd8ec1 100644 --- a/wgengine/tsdns/tsdns_test.go +++ b/net/dns/tsdns_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package tsdns +package dns import ( "bytes" diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index e070c82af..cd1d159d9 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -730,7 +730,7 @@ type DNSConfig struct { // Some OSes and OS configurations don't support per-domain DNS configuration, // in which case Nameservers applies to all DNS requests regardless of PerDomain's value. PerDomain bool - // Proxied indicates whether DNS requests are proxied through a tsdns.Resolver. + // Proxied indicates whether DNS requests are proxied through a dns.Resolver. // This enables MagicDNS. It is togglable independently of PerDomain. Proxied bool } diff --git a/wgengine/router/dns/config.go b/wgengine/router/dns/config.go index 0f752d0f8..db08df7aa 100644 --- a/wgengine/router/dns/config.go +++ b/wgengine/router/dns/config.go @@ -22,7 +22,7 @@ type Config struct { // Note that Nameservers may still be applied to all queries // if the manager does not support per-domain settings. PerDomain bool - // Proxied indicates whether DNS requests are proxied through a tsdns.Resolver. + // Proxied indicates whether DNS requests are proxied through a dns.Resolver. // This enables MagicDNS. Proxied bool } diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 7334677bf..ab4d9f78b 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -47,7 +47,7 @@ "tailscale.com/wgengine/magicsock" "tailscale.com/wgengine/monitor" "tailscale.com/wgengine/router" - "tailscale.com/wgengine/tsdns" + "tailscale.com/net/dns" "tailscale.com/wgengine/tstun" "tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wglog" @@ -95,7 +95,7 @@ type userspaceEngine struct { tundev *tstun.TUN wgdev *device.Device router router.Router - resolver *tsdns.Resolver + resolver *dns.Resolver magicConn *magicsock.Conn linkMon *monitor.Mon linkMonOwned bool // whether we created linkMon (and thus need to close it) @@ -246,7 +246,7 @@ func newUserspaceEngine(logf logger.Logf, rawTUNDev tun.Device, conf Config) (_ e.linkMonOwned = true } - e.resolver = tsdns.NewResolver(tsdns.ResolverConfig{ + e.resolver = dns.NewResolver(dns.ResolverConfig{ Logf: logf, Forward: true, LinkMonitor: e.linkMon, @@ -476,13 +476,13 @@ func (e *userspaceEngine) isLocalAddr(ip netaddr.IP) bool { // handleDNS is an outbound pre-filter resolving Tailscale domains. func (e *userspaceEngine) handleDNS(p *packet.Parsed, t *tstun.TUN) filter.Response { if p.Dst.IP == magicDNSIP && p.Dst.Port == magicDNSPort && p.IPProto == ipproto.UDP { - request := tsdns.Packet{ + request := dns.Packet{ Payload: append([]byte(nil), p.Payload()...), Addr: netaddr.IPPort{IP: p.Src.IP, Port: p.Src.Port}, } err := e.resolver.EnqueueRequest(request) if err != nil { - e.logf("tsdns: enqueue: %v", err) + e.logf("dns: enqueue: %v", err) } return filter.Drop } @@ -493,11 +493,11 @@ func (e *userspaceEngine) handleDNS(p *packet.Parsed, t *tstun.TUN) filter.Respo func (e *userspaceEngine) pollResolver() { for { resp, err := e.resolver.NextResponse() - if err == tsdns.ErrClosed { + if err == dns.ErrClosed { return } if err != nil { - e.logf("tsdns: error: %v", err) + e.logf("dns: error: %v", err) continue } @@ -511,7 +511,7 @@ func (e *userspaceEngine) pollResolver() { } hlen := h.Len() - // TODO(dmytro): avoid this allocation without importing tstun quirks into tsdns. + // TODO(dmytro): avoid this allocation without importing tstun quirks into dns. const offset = tstun.PacketStartOffset buf := make([]byte, offset+hlen+len(resp.Payload)) copy(buf[offset+hlen:], resp.Payload) @@ -1047,7 +1047,7 @@ func (e *userspaceEngine) SetFilter(filt *filter.Filter) { e.tundev.SetFilter(filt) } -func (e *userspaceEngine) SetDNSMap(dm *tsdns.Map) { +func (e *userspaceEngine) SetDNSMap(dm *dns.Map) { e.resolver.SetMap(dm) } diff --git a/wgengine/watchdog.go b/wgengine/watchdog.go index 6a607ce03..bc83044ca 100644 --- a/wgengine/watchdog.go +++ b/wgengine/watchdog.go @@ -19,7 +19,7 @@ "tailscale.com/wgengine/filter" "tailscale.com/wgengine/monitor" "tailscale.com/wgengine/router" - "tailscale.com/wgengine/tsdns" + "tailscale.com/net/dns" "tailscale.com/wgengine/wgcfg" ) @@ -84,7 +84,7 @@ func (e *watchdogEngine) GetFilter() *filter.Filter { func (e *watchdogEngine) SetFilter(filt *filter.Filter) { e.watchdog("SetFilter", func() { e.wrap.SetFilter(filt) }) } -func (e *watchdogEngine) SetDNSMap(dm *tsdns.Map) { +func (e *watchdogEngine) SetDNSMap(dm *dns.Map) { e.watchdog("SetDNSMap", func() { e.wrap.SetDNSMap(dm) }) } func (e *watchdogEngine) SetStatusCallback(cb StatusCallback) { diff --git a/wgengine/wgengine.go b/wgengine/wgengine.go index 2e3a8fd36..efb2b34d5 100644 --- a/wgengine/wgengine.go +++ b/wgengine/wgengine.go @@ -14,7 +14,7 @@ "tailscale.com/wgengine/filter" "tailscale.com/wgengine/monitor" "tailscale.com/wgengine/router" - "tailscale.com/wgengine/tsdns" + "tailscale.com/net/dns" "tailscale.com/wgengine/wgcfg" ) @@ -66,7 +66,7 @@ type Engine interface { SetFilter(*filter.Filter) // SetDNSMap updates the DNS map. - SetDNSMap(*tsdns.Map) + SetDNSMap(*dns.Map) // SetStatusCallback sets the function to call when the // WireGuard status changes.