tsdns

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchDNSRoutes added in v0.4.8

func FetchDNSRoutes(ctx context.Context, watchIPNBus WatchIPNBusFunc) (map[string][]string, error)

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

func LookupHost(ctx context.Context, query QueryFunc, host string) ([]string, error)

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.

func NewLookupFunc

func NewLookupFunc(query QueryFunc) func(ctx context.Context, host string) ([]string, error)

NewLookupFunc returns a LookupFunc suitable for use with pgx or similar libraries that perform DNS resolution separately from dialing.

Types

type DialFunc added in v0.4.8

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialFunc dials a network connection, matching tsnet.Server.Dial's signature.

type IPNBusWatcher added in v0.4.8

type IPNBusWatcher interface {
	Next() (ipn.Notify, error)
	Close() error
}

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

type QueryFunc func(ctx context.Context, name, queryType string) ([]byte, error)

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 SRVRecord added in v0.6.4

type SRVRecord struct {
	Target   string
	Port     uint16
	Priority uint16
	Weight   uint16
}

SRVRecord is a DNS SRV answer.

func LookupSRV added in v0.6.4

func LookupSRV(ctx context.Context, query QueryFunc, name string) ([]SRVRecord, error)

LookupSRV resolves SRV records using the provided Tailscale DNS query function. The name should be the full SRV owner name, such as _mongodb._tcp.cluster.example.com.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL