wgengine

package
v0.97.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: BSD-3-Clause Imports: 30 Imported by: 39

Documentation

Index

Constants

View Source
const DefaultTunName = "tailscale0"

Variables

View Source
var SetRoutesFunc func(rs RouteSettings) error

SetRoutesFunc applies the given route settings to the OS network stack.

This is logically part of the router_darwin.go implementation, and should not be used on other platforms.

The code to reconfigure the network stack on MacOS and iOS is in the non-open `ipn-go-bridge` package, which bridges between the Go and Swift pieces of the application. The ipn-go-bridge sets SetRoutesFunc at startup.

So why isn't this in router_darwin.go? Because in the non-oss repository, we build ipn-go-bridge when developing on Linux as well as MacOS, so that we don't have to wait until the Mac CI to discover that we broke it. So this one definition needs to exist in both the darwin and linux builds. Hence this file and build tag.

Functions

func NewFakeTun

func NewFakeTun() tun.Device

NewFakeTun returns a fake TUN device that does not depend on the operating system or any special permissions. It primarily exists for testing.

func RusagePrefixLog

func RusagePrefixLog(logf logger.Logf) logger.Logf

RusagePrefixLog returns a Logf func wrapping the provided logf func that adds a prefixed log message to each line with the current binary memory usage and max RSS.

Types

type ByteCount

type ByteCount int64

ByteCount is the number of bytes that have been sent or received.

TODO: why is this a type? remove? TODO: document whether it's payload bytes only or if it includes framing overhead.

type Engine

type Engine interface {
	// Reconfig reconfigures WireGuard and makes sure it's running.
	// This also handles setting up any kernel routes.
	//
	// The provided DNS domains are not part of wgcfg.Config, as
	// WireGuard itself doesn't care about such things.
	//
	// This is called whenever the tailcontrol (control plane)
	// sends an updated network map.
	Reconfig(cfg *wgcfg.Config, dnsDomains []string) error

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

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

	// 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 set on links
	// where sending packets uses substantial power or money,
	// such as mobile data on a phone.
	//
	// LinkChange should be called whenever something changed with
	// the network, no matter how minor. The implementation should
	// look at the state of the network and decide whether the
	// change from before is interesting enough to warrant taking
	// action on.
	LinkChange(isExpensive bool)

	// SetDERPEnabled controls whether DERP is enabled.
	// It starts enabled by default.
	SetDERPEnabled(bool)

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

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, tunname string, listenPort uint16) (Engine, error)

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

func NewUserspaceEngineAdvanced

func NewUserspaceEngineAdvanced(logf logger.Logf, tundev tun.Device, routerGen RouterGen, listenPort uint16) (Engine, error)

NewUserspaceEngineAdvanced is like NewUserspaceEngine but takes a pre-created TUN device and allows specifing a custom router constructor and listening port.

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 Loggify

type Loggify struct {
	// contains filtered or unexported fields
}

func (*Loggify) Write

func (l *Loggify) Write(b []byte) (int, error)

type NetInfoCallback

type NetInfoCallback func(*tailcfg.NetInfo)

NetInfoCallback is the type used by Engine.SetNetInfoCallback.

type PeerStatus

type PeerStatus struct {
	TxBytes, RxBytes ByteCount
	LastHandshake    time.Time
	NodeKey          tailcfg.NodeKey
}

type RouteSettings

type RouteSettings struct {
	LocalAddr  wgcfg.CIDR // TODO: why is this here? how does it differ from wgcfg.Config's info?
	DNS        []wgcfg.IP
	DNSDomains []string
	Cfg        *wgcfg.Config
}

RouteSettings is the full WireGuard config data (set of peers keys, IP, etc in wgcfg.Config) plus the things that WireGuard doesn't do itself, like DNS stuff.

func (*RouteSettings) OnlyRelevantParts

func (rs *RouteSettings) OnlyRelevantParts() string

OnlyRelevantParts returns a string minimally describing the route settings.

type Router

type Router interface {
	// Up brings the router up.
	Up() error

	// SetRoutes is called regularly on network map updates.
	// It's how you kernel route table entries are populated for
	// each peer.
	SetRoutes(RouteSettings) error

	// Close closes the router.
	Close() error
}

Router is responsible for managing the system route table.

There's only one instance, and one per-OS implementation.

func NewFakeRouter

func NewFakeRouter(logf logger.Logf, _ *device.Device, _ tun.Device) (Router, error)

NewFakeRouter returns a new fake Router implementation whose implementation does nothing and always returns nil errors.

func NewUserspaceRouter

func NewUserspaceRouter(logf logger.Logf, wgdev *device.Device, tundev tun.Device) (Router, error)

NewUserspaceRouter returns a new Router for the current platform, using the provided tun device.

type RouterGen

type RouterGen func(logf logger.Logf, wgdev *device.Device, tundev tun.Device) (Router, error)

RouterGen is the signature for the two funcs that create Router implementations: NewUserspaceRouter (which varies by operating system) and NewFakeRouter.

type Status

type Status struct {
	Peers      []PeerStatus
	LocalAddrs []string // TODO(crawshaw): []wgcfg.Endpoint?
}

Status is the Engine status.

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
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 changes.
Package monitor provides facilities for monitoring network interface changes.

Jump to

Keyboard shortcuts

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