Documentation
¶
Overview ¶
Package tsdns provides DNS resolution through the Tailscale local API.
This works around tailscale/tailscale#5840 where tsnet.Server.Dial falls back to the system resolver for non-tailnet names, breaking split DNS resolution.
Index ¶
- func FetchDNSRoutes(ctx context.Context, watchIPNBus WatchIPNBusFunc) (map[string][]string, error)
- func ForwardQuery(ctx context.Context, listenPacket ListenPacketFunc, ...) ([]byte, error)
- func LookupHost(ctx context.Context, query QueryFunc, host string) ([]string, error)
- func NewDialer(tsDial func(ctx context.Context, network, addr string) (net.Conn, error), ...) func(ctx context.Context, network, addr string) (net.Conn, error)
- func NewLookupFunc(query QueryFunc) func(ctx context.Context, host string) ([]string, error)
- type DialFunc
- type IPNBusWatcher
- type ListenPacketFunc
- type QueryFunc
- type SRVRecord
- type WatchIPNBusFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchDNSRoutes ¶ added in v0.4.8
FetchDNSRoutes reads DNS routes from the Tailscale network map via the IPN bus. It returns a simplified map of domain suffix → resolver address list.
func ForwardQuery ¶ added in v0.4.8
func ForwardQuery(ctx context.Context, listenPacket ListenPacketFunc, resolver, fqdn, qtype string) ([]byte, error)
ForwardQuery builds a DNS query for fqdn/qtype, sends it to resolver via listenPacket (which creates a UDP socket in Tailscale's userspace network stack), and returns the raw DNS response bytes.
Using ListenPacket instead of Dial ensures both send and receive stay within gVisor's netstack, avoiding a mismatch where the response arrives in userspace but the socket lives in the kernel.
func LookupHost ¶
LookupHost resolves a hostname to IP addresses using the provided Tailscale DNS query function. The query function should call local.Client.QueryDNS (or equivalent) which goes through the full Tailscale DNS stack including MagicDNS and split DNS.
func NewDialer ¶
func NewDialer(tsDial func(ctx context.Context, network, addr string) (net.Conn, error), query QueryFunc) func(ctx context.Context, network, addr string) (net.Conn, error)
NewDialer creates a dialer that resolves hostnames through Tailscale's DNS stack before dialing via the provided Tailscale dialer. This ensures split DNS domains are resolved correctly.
Types ¶
type DialFunc ¶ added in v0.4.8
DialFunc dials a network connection, matching tsnet.Server.Dial's signature.
type IPNBusWatcher ¶ added in v0.4.8
IPNBusWatcher abstracts the watcher returned by WatchIPNBus so that FetchDNSRoutes can be tested without a real Tailscale client.
type ListenPacketFunc ¶ added in v0.4.11
type ListenPacketFunc func(network, addr string) (net.PacketConn, error)
ListenPacketFunc creates a PacketConn, matching tsnet.Server.ListenPacket's signature.
type QueryFunc ¶
QueryFunc matches the signature of local.Client.QueryDNS.
func NewRoutedQueryFunc ¶ added in v0.4.8
func NewRoutedQueryFunc(fallback QueryFunc, listenPacket ListenPacketFunc, routes map[string][]string) QueryFunc
NewRoutedQueryFunc returns a QueryFunc that routes DNS queries matching configured route suffixes through listenPacket (Tailscale userspace network) and falls back to fallback (typically lc.QueryDNS) for everything else.
type WatchIPNBusFunc ¶ added in v0.4.8
type WatchIPNBusFunc func(ctx context.Context, mask ipn.NotifyWatchOpt) (IPNBusWatcher, error)
WatchIPNBusFunc matches the signature of tailscale.com/client/local.Client.WatchIPNBus.