monitor

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package monitor provides facilities for monitoring network interface and route changes. It primarily exists to know when portable devices move between different networks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeFunc

type ChangeFunc func(changed bool, state *interfaces.State)

ChangeFunc is a callback function that's called when the network changed. The changed parameter is whether the network changed enough for interfaces.State to have changed since the last callback.

type Mon

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

Mon represents a monitoring instance.

func New

func New(logf logger.Logf) (*Mon, error)

New instantiates and starts a monitoring instance. The returned monitor is inactive until it's started by the Start method. Use RegisterChangeCallback to get notified of network changes.

func (*Mon) Close

func (m *Mon) Close() error

Close closes the monitor.

func (*Mon) GatewayAndSelfIP added in v1.6.0

func (m *Mon) GatewayAndSelfIP() (gw, myIP netaddr.IP, ok bool)

GatewayAndSelfIP returns the current network's default gateway, and the machine's default IP for that gateway.

It's the same as interfaces.LikelyHomeRouterIP, but it caches the result until the monitor detects a network change.

func (*Mon) InjectEvent added in v1.6.0

func (m *Mon) InjectEvent()

InjectEvent forces the monitor to pretend there was a network change and re-check the state of the network. Any registered ChangeFunc callbacks will be called within the event coalescing period (under a fraction of a second).

func (*Mon) InterfaceState added in v1.6.0

func (m *Mon) InterfaceState() *interfaces.State

InterfaceState returns the state of the machine's network interfaces, without any Tailscale ones.

func (*Mon) RegisterChangeCallback added in v1.6.0

func (m *Mon) RegisterChangeCallback(callback ChangeFunc) (unregister func())

RegisterChangeCallback adds callback to the set of parties to be notified (in their own goroutine) when the network state changes. To remove this callback, call unregister (or close the monitor).

func (*Mon) RegisterRuleDeleteCallback added in v1.12.0

func (m *Mon) RegisterRuleDeleteCallback(callback RuleDeleteCallback) (unregister func())

RegisterRuleDeleteCallback adds callback to the set of parties to be notified (in their own goroutine) when a Linux ip rule is deleted. To remove this callback, call unregister (or close the monitor).

func (*Mon) Start

func (m *Mon) Start()

Start starts the monitor. A monitor can only be started & closed once.

type RuleDeleteCallback added in v1.12.0

type RuleDeleteCallback func(table uint8, priority uint32)

RuleDeleteCallback is a callback when a Linux IP policy routing rule is deleted. The table is the table number (52, 253, 354) and priority is the priority order number (for Tailscale rules currently: 5210, 5230, 5250, 5270)

Jump to

Keyboard shortcuts

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