tailscale.comtailscale.com/net/tsdial Index | Files

package tsdial

import "tailscale.com/net/tsdial"

Package tsdial provides a Dialer type that can dial out of tailscaled.

Index

Types

type Dialer

type Dialer struct {
	Logf logger.Logf
	// UseNetstackForIP if non-nil is whether NetstackDialTCP (if
	// it's non-nil) should be used to dial the provided IP.
	UseNetstackForIP func(netip.Addr) bool

	// NetstackDialTCP dials the provided IPPort using netstack.
	// If nil, it's not used.
	NetstackDialTCP func(context.Context, netip.AddrPort) (net.Conn, error)

	// NetstackDialUDP dials the provided IPPort using netstack.
	// If nil, it's not used.
	NetstackDialUDP func(context.Context, netip.AddrPort) (net.Conn, error)
	// contains filtered or unexported fields
}

Dialer dials out of tailscaled, while taking care of details while handling the dozens of edge cases depending on the server mode (TUN, netstack), the OS network sandboxing style (macOS/iOS Extension, none), user-selected route acceptance prefs, etc.

Before use, SetNetMon should be called with a netmon.Monitor.

func NewDialer

func NewDialer(netMon *netmon.Monitor) *Dialer

NewDialer returns a new Dialer that can dial out of tailscaled. Its exported fields should be set before use, if any.

func (*Dialer) Close

func (d *Dialer) Close() error

func (*Dialer) NetMon

func (d *Dialer) NetMon() *netmon.Monitor

NetMon returns the Dialer's network monitor. It returns nil if SetNetMon has not been called.

func (*Dialer) PeerAPIHTTPClient

func (d *Dialer) PeerAPIHTTPClient() *http.Client

PeerAPIHTTPClient returns an HTTP Client to call peers' peerapi endpoints. // The returned Client must not be mutated; it's owned by the Dialer and shared by callers.

func (*Dialer) PeerAPITransport

func (d *Dialer) PeerAPITransport() *http.Transport

PeerAPITransport returns a Transport to call peers' peerapi endpoints.

The returned value must not be mutated; it's owned by the Dialer and shared by callers.

func (*Dialer) PeerDialControlFunc

func (d *Dialer) PeerDialControlFunc() func(network, address string, c syscall.RawConn) error

PeerDialControlFunc returns a function that can assigned to net.Dialer.Control to set sockopts or whatnot to make a dial escape the current platform's network sandbox.

On many platforms the returned func will be nil.

Notably, this is non-nil on iOS and macOS when run as a Network or System Extension (the GUI variants).

func (*Dialer) SetExitDNSDoH

func (d *Dialer) SetExitDNSDoH(doh string)

SetExitDNSDoH sets (or clears) the exit node DNS DoH server base URL to use. The doh URL should contain the scheme, authority, and path, but without a '?' and/or query parameters.

For example, "http://100.68.82.120:47830/dns-query".

func (*Dialer) SetNetMap

func (d *Dialer) SetNetMap(nm *netmap.NetworkMap)

SetNetMap sets the current network map and notably, the DNS names in its DNS configuration.

func (*Dialer) SetNetMon

func (d *Dialer) SetNetMon(netMon *netmon.Monitor)

SetNetMon sets d's network monitor to netMon. It is a no-op to call SetNetMon with the same netMon as the current one.

func (*Dialer) SetRoutes

func (d *Dialer) SetRoutes(routes, localRoutes []netip.Prefix)

SetRoutes configures the dialer to dial the specified routes via Tailscale, and the specified localRoutes using the default interface.

func (*Dialer) SetSystemDialerForTest

func (d *Dialer) SetSystemDialerForTest(fn netx.DialFunc)

SetSystemDialerForTest sets an alternate function to use for SystemDial instead of netns.Dialer. This is intended for use with nettest.MemoryNetwork.

func (*Dialer) SetTUNName

func (d *Dialer) SetTUNName(name string)

SetTUNName sets the name of the tun device in use ("tailscale0", "utun6", etc). This is needed on some platforms to set sockopts to bind to the same interface index.

func (*Dialer) SystemDial

func (d *Dialer) SystemDial(ctx context.Context, network, addr string) (net.Conn, error)

SystemDial connects to the provided network address without going over Tailscale. It prefers going over the default interface and closes existing connections if the default interface changes. It is used to connect to Control and (in the future, as of 2022-04-27) DERPs..

func (*Dialer) TUNName

func (d *Dialer) TUNName() string

TUNName returns the name of the tun device in use, if any. Example format ("tailscale0", "utun6").

func (*Dialer) UserDial

func (d *Dialer) UserDial(ctx context.Context, network, addr string) (net.Conn, error)

UserDial connects to the provided network address as if a user were initiating the dial. (e.g. from a SOCKS or HTTP outbound proxy)

Source Files

dnsmap.go dohclient.go tsdial.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
29 packages
Last checked
1 day ago

Tools for package owners.