Movatterモバイル変換


[0]ホーム

URL:


router

package
v1.92.2Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:17Imported by:37

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var HookCleanUpfeature.Hook[func(_logger.Logf, _ *netmon.Monitor, ifNamestring)]

HookCleanUp is the optional registration point for router implementationsto register a cleanup function forCleanUp to use. It's meant forimplementations in wgengine/router/osrouter.

View Source
var HookNewUserspaceRouterfeature.Hook[func(NewOpts) (Router,error)]

HookNewUserspaceRouter is the registration point for router implementationsto register a constructor for userspace routers. It's meant for implementationsin wgengine/router/osrouter.

If no implementation is registered,New will return an error.

Functions

funcCleanUpadded inv1.64.0

func CleanUp(logflogger.Logf, netMon *netmon.Monitor, interfaceNamestring)

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

Types

typeCallbackRouteradded inv1.8.0

type CallbackRouter struct {SetBoth  func(rcfg *Config, dcfg *dns.OSConfig)errorSplitDNSbool// 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)// InitialMTU is the MTU the tun should be initialized with.// Zero means don't change the MTU from the default. This MTU// is applied only once, shortly after the TUN is created, and// ignored thereafter.InitialMTUuint32// 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 andDNS configuration simultaneously (Mac, iOS, Android).

func (*CallbackRouter)Closeadded inv1.8.0

func (r *CallbackRouter) Close()error

func (*CallbackRouter)GetBaseConfigadded inv1.8.0

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

func (*CallbackRouter)Setadded inv1.8.0

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

Set implements Router.

func (*CallbackRouter)SetDNSadded inv1.8.0

func (r *CallbackRouter) SetDNS(dcfgdns.OSConfig)error

SetDNS implements dns.OSConfigurator.

func (*CallbackRouter)SupportsSplitDNSadded inv1.8.0

func (r *CallbackRouter) SupportsSplitDNS()bool

SupportsSplitDNS implements dns.OSConfigurator.

func (*CallbackRouter)Upadded inv1.8.0

func (r *CallbackRouter) Up()error

Up implements Router.

typeConfig

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 []netip.Prefix// 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 []netip.Prefix// 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 []netip.Prefix// NewMTU is currently only used by the MacOS network extension// app to set the MTU of the tun in the router configuration// callback. If zero, the MTU is unchanged.NewMTUint// SubnetRoutes is the list of subnets that this node is// advertising to other Tailscale nodes.// As of 2023-10-11, this field is only used for network// flow logging and is otherwise ignored.SubnetRoutes []netip.Prefix// Linux-only things below, ignored on other platforms.SNATSubnetRoutesbool// SNAT traffic to local subnetsStatefulFilteringbool// Apply stateful filtering to inbound connectionsNetfilterModepreftype.NetfilterMode// how much to manage netfilter rulesNetfilterKindstring// what kind of netfilter to use ("nftables", "iptables", or "" to auto-detect)}

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

func (*Config)Cloneadded inv1.90.0

func (c *Config) Clone() *Config

func (*Config)Equaladded inv1.26.2

func (a *Config) Equal(b *Config)bool

typeNewOptsadded inv1.90.0

type NewOpts struct {Logflogger.Logf// requiredTuntun.Device// requiredNetMon *netmon.Monitor// optionalHealth *health.Tracker// required (but TODO: support optional later)Bus    *eventbus.Bus// required}

NewOpts are the options passed to the NewUserspaceRouter hook.

typePortUpdateadded inv1.90.0

type PortUpdate struct {UDPPortuint16EndpointNetworkstring// either "udp4" or "udp6".}

PortUpdate is an eventbus value, reporting the port and address familymagicsock is currently listening on, so it can be threaded through firewallsand such.

typeRouter

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.

funcConsolidatingRoutesadded inv1.66.0

func ConsolidatingRoutes(logflogger.Logf, routerRouter)Router

ConsolidatingRoutes wraps a Router with logic that consolidates Routeswhenever Set is called. It attempts to consolidate cfg.Routes into thesmallest possible set.

funcNew

func New(logflogger.Logf, tundevtun.Device, netMon *netmon.Monitor,health *health.Tracker, bus *eventbus.Bus,) (Router,error)

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

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

funcNewFake

func NewFake(logflogger.Logf)Router

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

Source Files

View all Source files

Directories

PathSynopsis
Package osrouter contains OS-specific router implementations.
Package osrouter contains OS-specific router implementations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp