wgengine

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: BSD-3-Clause Imports: 48 Imported by: 39

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEngineClosing = errors.New("engine closing; no status")
View Source
var ErrNoChanges = errors.New("no changes made to Engine config")

ErrNoChanges is returned by Engine.Reconfig if no changes were made.

View Source
var NetstackRouterType reflect.Type

NetstackRouterType is a gross cross-package init-time registration from netstack to here, informing this package of netstack's router type.

Functions

func IsNetstack added in v1.8.0

func IsNetstack(e Engine) bool

IsNetstack reports whether e is a netstack-based TUN-free engine.

func IsNetstackRouter added in v1.8.0

func IsNetstackRouter(e Engine) bool

IsNetstackRouter reports whether e is either fully netstack based (without TUN) or is at least using netstack for routing.

Types

type BIRDClient added in v1.16.0

type BIRDClient interface {
	EnableProtocol(proto string) error
	DisableProtocol(proto string) error
	Close() error
}

BIRDClient handles communication with the BIRD Internet Routing Daemon.

type Config added in v1.6.0

type Config struct {
	// Tun is the device used by the Engine to exchange packets with
	// the OS.
	// If nil, a fake Device that does nothing is used.
	Tun tun.Device

	// IsTAP is whether Tun is actually a TAP (Layer 2) device that'll
	// require ethernet headers.
	IsTAP bool

	// Router interfaces the Engine to the OS network stack.
	// If nil, a fake Router that does nothing is used.
	Router router.Router

	// DNS interfaces the Engine to the OS DNS resolver configuration.
	// If nil, a fake OSConfigurator that does nothing is used.
	DNS dns.OSConfigurator

	// LinkMonitor optionally provides an existing link monitor to re-use.
	// If nil, a new link monitor is created.
	LinkMonitor *monitor.Mon

	// Dialer is the dialer to use for outbound connections.
	// If nil, a new Dialer is created
	Dialer *tsdial.Dialer

	// ListenPort is the port on which the engine will listen.
	// If zero, a port is automatically selected.
	ListenPort uint16

	// RespondToPing determines whether this engine should internally
	// reply to ICMP pings, without involving the OS.
	// Used in "fake" mode for development.
	RespondToPing bool

	// BIRDClient, if non-nil, will be used to configure BIRD whenever
	// this node is a primary subnet router.
	BIRDClient BIRDClient
}

Config is the engine configuration.

type Engine

type Engine interface {
	// Reconfig reconfigures WireGuard and makes sure it's running.
	// This also handles setting up any kernel routes.
	//
	// This is called whenever tailcontrol (the control plane)
	// sends an updated network map.
	//
	// The *tailcfg.Debug parameter can be nil.
	//
	// The returned error is ErrNoChanges if no changes were made.
	Reconfig(*wgcfg.Config, *router.Config, *dns.Config, *tailcfg.Debug) error

	// PeerForIP returns the node to which the provided IP routes,
	// if any. If none is found, (nil, nil) is returned.
	PeerForIP(netaddr.IP) (_ PeerForIP, ok bool)

	// GetFilter returns the current packet filter, if any.
	GetFilter() *filter.Filter

	// SetFilter updates the packet filter.
	SetFilter(*filter.Filter)

	// SetStatusCallback sets the function to call when the
	// WireGuard status changes.
	SetStatusCallback(StatusCallback)

	// GetLinkMonitor returns the link monitor.
	GetLinkMonitor() *monitor.Mon

	// RequestStatus requests a WireGuard status update right
	// away, sent to the callback registered via SetStatusCallback.
	RequestStatus()

	// Close shuts down this wireguard instance, remove any routes
	// it added, etc. To bring it up again later, you'll need a
	// new Engine.
	Close()

	// Wait waits until the Engine's Close method is called or the
	// engine aborts with an error. You don't have to call this.
	// TODO: return an error?
	Wait()

	// LinkChange informs the engine that the system network
	// link has changed.
	//
	// The isExpensive parameter is not used.
	//
	// LinkChange should be called whenever something changed with
	// the network, no matter how minor.
	//
	// Deprecated: don't use this method. It was removed shortly
	// before the Tailscale 1.6 release when we remembered that
	// Android doesn't use the Linux-based link monitor and has
	// its own mechanism that uses LinkChange. Android is the only
	// caller of this method now. Don't add more.
	LinkChange(isExpensive bool)

	// SetDERPMap controls which (if any) DERP servers are used.
	// If nil, DERP is disabled. It starts disabled until a DERP map
	// is configured.
	SetDERPMap(*tailcfg.DERPMap)

	// SetNetworkMap informs the engine of the latest network map
	// from the server. The network map's DERPMap field should be
	// ignored as as it might be disabled; get it from SetDERPMap
	// instead.
	// The network map should only be read from.
	SetNetworkMap(*netmap.NetworkMap)

	// AddNetworkMapCallback adds a function to a list of callbacks
	// that are called when the network map updates. It returns a
	// function that when called would remove the function from the
	// list of callbacks.
	AddNetworkMapCallback(NetworkMapCallback) (removeCallback func())

	// SetNetInfoCallback sets the function to call when a
	// new NetInfo summary is available.
	SetNetInfoCallback(NetInfoCallback)

	// DiscoPublicKey gets the public key used for path discovery
	// messages.
	DiscoPublicKey() key.DiscoPublic

	// UpdateStatus populates the network state using the provided
	// status builder.
	UpdateStatus(*ipnstate.StatusBuilder)

	// Ping is a request to start a discovery ping with the peer handling
	// the given IP and then call cb with its ping latency & method.
	Ping(ip netaddr.IP, useTSMP bool, cb func(*ipnstate.PingResult))

	// RegisterIPPortIdentity registers a given node (identified by its
	// Tailscale IP) as temporarily having the given IP:port for whois lookups.
	// The IP:port is generally a localhost IP and an ephemeral port, used
	// while proxying connections to localhost when tailscaled is running
	// in netstack mode.
	RegisterIPPortIdentity(netaddr.IPPort, netaddr.IP)

	// UnregisterIPPortIdentity removes a temporary IP:port registration
	// made previously by RegisterIPPortIdentity.
	UnregisterIPPortIdentity(netaddr.IPPort)

	// WhoIsIPPort looks up an IP:port in the temporary registrations,
	// and returns a matching Tailscale IP, if it exists.
	WhoIsIPPort(netaddr.IPPort) (netaddr.IP, bool)
}

Engine is the Tailscale WireGuard engine interface.

func NewFakeUserspaceEngine

func NewFakeUserspaceEngine(logf logger.Logf, listenPort uint16) (Engine, error)

func NewUserspaceEngine

func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error)

NewUserspaceEngine creates the named tun device and returns a Tailscale Engine running on it.

func NewWatchdog

func NewWatchdog(e Engine) Engine

NewWatchdog wraps an Engine and makes sure that all methods complete within a reasonable amount of time.

If they do not, the watchdog crashes the process.

type InternalsGetter added in v1.6.0

type InternalsGetter interface {
	GetInternals() (_ *tstun.Wrapper, _ *magicsock.Conn, ok bool)
}

InternalsGetter is implemented by Engines that can export their internals.

type NetInfoCallback

type NetInfoCallback func(*tailcfg.NetInfo)

NetInfoCallback is the type used by Engine.SetNetInfoCallback.

type NetworkMapCallback added in v1.4.0

type NetworkMapCallback func(*netmap.NetworkMap)

NetworkMapCallback is the type used by callbacks that hook into network map updates.

type PeerForIP added in v1.20.0

type PeerForIP struct {
	// Node is the matched node. It's always non-nil when
	// Engine.PeerForIP returns ok==true.
	Node *tailcfg.Node

	// IsSelf is whether the Node is the local process.
	IsSelf bool

	// Route is the route that matched the IP provided
	// to Engine.PeerForIP.
	Route netaddr.IPPrefix
}

PeerForIP is the type returned by Engine.PeerForIP.

type ResolvingEngine added in v1.20.0

type ResolvingEngine interface {
	GetResolver() (_ *resolver.Resolver, ok bool)
}

ResolvingEngine is implemented by Engines that have DNS resolvers.

type Status

type Status struct {
	Peers      []ipnstate.PeerStatusLite
	LocalAddrs []tailcfg.Endpoint // the set of possible endpoints for the magic conn
	DERPs      int                // number of active DERP connections
}

Status is the Engine status.

TODO(bradfitz): remove this, subset of ipnstate? Need to migrate users.

type StatusCallback

type StatusCallback func(*Status, error)

StatusCallback is the type of status callbacks used by Engine.SetStatusCallback.

Exactly one of Status or error is non-nil.

Directories

Path Synopsis
Create two wgengine instances and pass data through them, measuring throughput, latency, and packet loss.
Create two wgengine instances and pass data through them, measuring throughput, latency, and packet loss.
Package filter is a stateful packet filter.
Package filter is a stateful packet filter.
Package magicsock implements a socket that can change its communication path while in use, actively searching for the best way to communicate.
Package magicsock implements a socket that can change its communication path while in use, actively searching for the best way to communicate.
Package monitor provides facilities for monitoring network interface and route changes.
Package monitor provides facilities for monitoring network interface and route changes.
Package netstack wires up gVisor's netstack into Tailscale.
Package netstack wires up gVisor's netstack into Tailscale.
Package router presents an interface to manipulate the host network stack's state.
Package router presents an interface to manipulate the host network stack's state.
Package wgcfg has types and a parser for representing WireGuard config.
Package wgcfg has types and a parser for representing WireGuard config.
nmcfg
Package nmcfg converts a controlclient.NetMap into a wgcfg config.
Package nmcfg converts a controlclient.NetMap into a wgcfg config.
Package wglog contains logging helpers for wireguard-go.
Package wglog contains logging helpers for wireguard-go.

Jump to

Keyboard shortcuts

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