Move wgengine/tsdns to net/dns.

Straight move+fixup, no other changes. In prep for merging with
wgengine/router/dns.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2021-03-25 14:50:21 -07:00 committed by Dave Anderson
parent 81143b6d9a
commit 8432999835
15 changed files with 32 additions and 32 deletions

View File

@ -22,6 +22,7 @@
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/ipn/policy" "tailscale.com/ipn/policy"
"tailscale.com/net/dns"
"tailscale.com/net/interfaces" "tailscale.com/net/interfaces"
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
"tailscale.com/portlist" "tailscale.com/portlist"
@ -37,8 +38,7 @@
"tailscale.com/wgengine" "tailscale.com/wgengine"
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
"tailscale.com/wgengine/router" "tailscale.com/wgengine/router"
"tailscale.com/wgengine/router/dns" rdns "tailscale.com/wgengine/router/dns"
"tailscale.com/wgengine/tsdns"
"tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg"
"tailscale.com/wgengine/wgcfg/nmcfg" "tailscale.com/wgengine/wgcfg/nmcfg"
) )
@ -847,8 +847,8 @@ func (b *LocalBackend) updateDNSMap(netMap *netmap.NetworkMap) {
} }
set(netMap.Name, netMap.Addresses) set(netMap.Name, netMap.Addresses)
dnsMap := tsdns.NewMap(nameToIP, magicDNSRootDomains(netMap)) dnsMap := dns.NewMap(nameToIP, magicDNSRootDomains(netMap))
// map diff will be logged in tsdns.Resolver.SetMap. // map diff will be logged in dns.Resolver.SetMap.
b.e.SetDNSMap(dnsMap) b.e.SetDNSMap(dnsMap)
} }
@ -1420,7 +1420,7 @@ func (b *LocalBackend) authReconfig() {
b.logf("[unexpected] dns proxied but no nameservers") b.logf("[unexpected] dns proxied but no nameservers")
proxied = false proxied = false
} }
rcfg.DNS = dns.Config{ rcfg.DNS = rdns.Config{
Nameservers: nm.DNS.Nameservers, Nameservers: nm.DNS.Nameservers,
Domains: nm.DNS.Domains, Domains: nm.DNS.Domains,
PerDomain: nm.DNS.PerDomain, PerDomain: nm.DNS.PerDomain,

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"bytes" "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 var b *backoff.Backoff // lazily initialized, since it is not needed in the common case
backOff := func(err error) { backOff := func(err error) {
if b == nil { 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) b.BackOff(context.Background(), err)
} }

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"sort" "sort"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"errors" "errors"

View File

@ -4,7 +4,7 @@
// +build !darwin,!windows // +build !darwin,!windows
package tsdns package dns
func networkIsDown(err error) bool { return false } func networkIsDown(err error) bool { return false }
func networkIsUnreachable(err error) bool { return false } func networkIsUnreachable(err error) bool { return false }

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"net" "net"

View File

@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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. // domains on a Tailscale network.
package tsdns package dns
import ( import (
"encoding/hex" "encoding/hex"
@ -100,7 +100,7 @@ type ResolverConfig struct {
// The root domain must be in canonical form (with a trailing period). // The root domain must be in canonical form (with a trailing period).
func NewResolver(config ResolverConfig) *Resolver { func NewResolver(config ResolverConfig) *Resolver {
r := &Resolver{ r := &Resolver{
logf: logger.WithPrefix(config.Logf, "tsdns: "), logf: logger.WithPrefix(config.Logf, "dns: "),
linkMon: config.LinkMonitor, linkMon: config.LinkMonitor,
queue: make(chan Packet, queueSize), queue: make(chan Packet, queueSize),
responses: make(chan Packet), responses: make(chan Packet),

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"log" "log"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tsdns package dns
import ( import (
"bytes" "bytes"

View File

@ -730,7 +730,7 @@ type DNSConfig struct {
// Some OSes and OS configurations don't support per-domain DNS configuration, // 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. // in which case Nameservers applies to all DNS requests regardless of PerDomain's value.
PerDomain bool 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. // This enables MagicDNS. It is togglable independently of PerDomain.
Proxied bool Proxied bool
} }

View File

@ -22,7 +22,7 @@ type Config struct {
// Note that Nameservers may still be applied to all queries // Note that Nameservers may still be applied to all queries
// if the manager does not support per-domain settings. // if the manager does not support per-domain settings.
PerDomain bool 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. // This enables MagicDNS.
Proxied bool Proxied bool
} }

View File

@ -47,7 +47,7 @@
"tailscale.com/wgengine/magicsock" "tailscale.com/wgengine/magicsock"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
"tailscale.com/wgengine/router" "tailscale.com/wgengine/router"
"tailscale.com/wgengine/tsdns" "tailscale.com/net/dns"
"tailscale.com/wgengine/tstun" "tailscale.com/wgengine/tstun"
"tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg"
"tailscale.com/wgengine/wglog" "tailscale.com/wgengine/wglog"
@ -95,7 +95,7 @@ type userspaceEngine struct {
tundev *tstun.TUN tundev *tstun.TUN
wgdev *device.Device wgdev *device.Device
router router.Router router router.Router
resolver *tsdns.Resolver resolver *dns.Resolver
magicConn *magicsock.Conn magicConn *magicsock.Conn
linkMon *monitor.Mon linkMon *monitor.Mon
linkMonOwned bool // whether we created linkMon (and thus need to close it) 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.linkMonOwned = true
} }
e.resolver = tsdns.NewResolver(tsdns.ResolverConfig{ e.resolver = dns.NewResolver(dns.ResolverConfig{
Logf: logf, Logf: logf,
Forward: true, Forward: true,
LinkMonitor: e.linkMon, LinkMonitor: e.linkMon,
@ -476,13 +476,13 @@ func (e *userspaceEngine) isLocalAddr(ip netaddr.IP) bool {
// handleDNS is an outbound pre-filter resolving Tailscale domains. // handleDNS is an outbound pre-filter resolving Tailscale domains.
func (e *userspaceEngine) handleDNS(p *packet.Parsed, t *tstun.TUN) filter.Response { 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 { 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()...), Payload: append([]byte(nil), p.Payload()...),
Addr: netaddr.IPPort{IP: p.Src.IP, Port: p.Src.Port}, Addr: netaddr.IPPort{IP: p.Src.IP, Port: p.Src.Port},
} }
err := e.resolver.EnqueueRequest(request) err := e.resolver.EnqueueRequest(request)
if err != nil { if err != nil {
e.logf("tsdns: enqueue: %v", err) e.logf("dns: enqueue: %v", err)
} }
return filter.Drop return filter.Drop
} }
@ -493,11 +493,11 @@ func (e *userspaceEngine) handleDNS(p *packet.Parsed, t *tstun.TUN) filter.Respo
func (e *userspaceEngine) pollResolver() { func (e *userspaceEngine) pollResolver() {
for { for {
resp, err := e.resolver.NextResponse() resp, err := e.resolver.NextResponse()
if err == tsdns.ErrClosed { if err == dns.ErrClosed {
return return
} }
if err != nil { if err != nil {
e.logf("tsdns: error: %v", err) e.logf("dns: error: %v", err)
continue continue
} }
@ -511,7 +511,7 @@ func (e *userspaceEngine) pollResolver() {
} }
hlen := h.Len() 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 const offset = tstun.PacketStartOffset
buf := make([]byte, offset+hlen+len(resp.Payload)) buf := make([]byte, offset+hlen+len(resp.Payload))
copy(buf[offset+hlen:], resp.Payload) copy(buf[offset+hlen:], resp.Payload)
@ -1047,7 +1047,7 @@ func (e *userspaceEngine) SetFilter(filt *filter.Filter) {
e.tundev.SetFilter(filt) e.tundev.SetFilter(filt)
} }
func (e *userspaceEngine) SetDNSMap(dm *tsdns.Map) { func (e *userspaceEngine) SetDNSMap(dm *dns.Map) {
e.resolver.SetMap(dm) e.resolver.SetMap(dm)
} }

View File

@ -19,7 +19,7 @@
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
"tailscale.com/wgengine/router" "tailscale.com/wgengine/router"
"tailscale.com/wgengine/tsdns" "tailscale.com/net/dns"
"tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg"
) )
@ -84,7 +84,7 @@ func (e *watchdogEngine) GetFilter() *filter.Filter {
func (e *watchdogEngine) SetFilter(filt *filter.Filter) { func (e *watchdogEngine) SetFilter(filt *filter.Filter) {
e.watchdog("SetFilter", func() { e.wrap.SetFilter(filt) }) 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) }) e.watchdog("SetDNSMap", func() { e.wrap.SetDNSMap(dm) })
} }
func (e *watchdogEngine) SetStatusCallback(cb StatusCallback) { func (e *watchdogEngine) SetStatusCallback(cb StatusCallback) {

View File

@ -14,7 +14,7 @@
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
"tailscale.com/wgengine/router" "tailscale.com/wgengine/router"
"tailscale.com/wgengine/tsdns" "tailscale.com/net/dns"
"tailscale.com/wgengine/wgcfg" "tailscale.com/wgengine/wgcfg"
) )
@ -66,7 +66,7 @@ type Engine interface {
SetFilter(*filter.Filter) SetFilter(*filter.Filter)
// SetDNSMap updates the DNS map. // SetDNSMap updates the DNS map.
SetDNSMap(*tsdns.Map) SetDNSMap(*dns.Map)
// SetStatusCallback sets the function to call when the // SetStatusCallback sets the function to call when the
// WireGuard status changes. // WireGuard status changes.