router

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: BSD-3-Clause Imports: 26 Imported by: 33

Documentation

Overview

Package router presents an interface to manipulate the host network stack's state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup added in v1.0.0

func Cleanup(logf logger.Logf, interfaceName string)

Cleanup restores the system network configuration to its original state in case the Tailscale daemon terminated without closing the router. No other state needs to be instantiated before this runs.

Types

type CallbackRouter added in v1.8.0

type CallbackRouter struct {
	SetBoth  func(rcfg *Config, dcfg *dns.OSConfig) error
	SplitDNS bool

	// GetBaseConfigFunc optionally specifies a function to return the current DNS
	// config in response to GetBaseConfig.
	//
	// If nil, reading the current config isn't supported and GetBaseConfig()
	// will return ErrGetBaseConfigNotSupported.
	GetBaseConfigFunc func() (dns.OSConfig, error)
	// contains filtered or unexported fields
}

CallbackRouter is an implementation of both Router and dns.OSConfigurator. When either network or DNS settings are changed, SetBoth is called with both configs. Mainly used as a shim for OSes that want to set both network and DNS configuration simultaneously (iOS, android).

func (*CallbackRouter) Close added in v1.8.0

func (r *CallbackRouter) Close() error

func (*CallbackRouter) GetBaseConfig added in v1.8.0

func (r *CallbackRouter) GetBaseConfig() (dns.OSConfig, error)

func (*CallbackRouter) Set added in v1.8.0

func (r *CallbackRouter) Set(rcfg *Config) error

Set implements Router.

func (*CallbackRouter) SetDNS added in v1.8.0

func (r *CallbackRouter) SetDNS(dcfg dns.OSConfig) error

SetDNS implements dns.OSConfigurator.

func (*CallbackRouter) SupportsSplitDNS added in v1.8.0

func (r *CallbackRouter) SupportsSplitDNS() bool

SupportsSplitDNS implements dns.OSConfigurator.

func (*CallbackRouter) Up added in v1.8.0

func (r *CallbackRouter) Up() error

Up implements Router.

type Config

type Config struct {
	// LocalAddrs are the address(es) for this node. This is
	// typically one IPv4/32 (the 100.x.y.z CGNAT) and one
	// IPv6/128 (Tailscale ULA).
	LocalAddrs []netaddr.IPPrefix

	// Routes are the routes that point into the Tailscale
	// interface.  These are the /32 and /128 routes to peers, as
	// well as any other subnets that peers are advertising and
	// this node has chosen to use.
	Routes []netaddr.IPPrefix

	// LocalRoutes are the routes that should not be routed through Tailscale.
	// There are no priorities set in how these routes are added, normal
	// routing rules apply.
	LocalRoutes []netaddr.IPPrefix

	// Linux-only things below, ignored on other platforms.
	SubnetRoutes     []netaddr.IPPrefix     // subnets being advertised to other Tailscale nodes
	SNATSubnetRoutes bool                   // SNAT traffic to local subnets
	NetfilterMode    preftype.NetfilterMode // how much to manage netfilter rules
}

Config is the subset of Tailscale configuration that is relevant to the OS's network stack.

type Router

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

	// Set updates the OS network stack with a new Config. It may be
	// called multiple times with identical Configs, which the
	// implementation should handle gracefully.
	Set(*Config) error

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

Router is responsible for managing the system network stack.

There is typically only one instance of this interface per process.

func New

func New(logf logger.Logf, tundev tun.Device, linkMon *monitor.Mon) (Router, error)

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

If linkMon is nil, it's not used. It's currently (2021-07-20) only used on Linux in some situations.

func NewFake

func NewFake(logf logger.Logf) Router

NewFake returns a Router that does nothing when called and always returns nil errors.

Jump to

Keyboard shortcuts

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