networkmonitor

package
v0.84.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change added in v0.84.0

type Change struct {
	Kind   ChangeKind
	Before NextHops
	After  NextHops
}

Change describes one debounced underlay change.

type ChangeKind added in v0.84.0

type ChangeKind int

ChangeKind classifies how the underlay default route moved.

const (
	// ChangeNone means the default next hops are the same as before, as after
	// a route flap.
	ChangeNone ChangeKind = iota
	// ChangeAddress means the default interface and gateway stayed, but the
	// interface addresses changed, as with a new DHCP lease.
	ChangeAddress
	// ChangeGateway means the default route stayed on the same interface but
	// its gateway changed, as when the same Wi-Fi adapter joins another network.
	ChangeGateway
	// ChangeInterface means the default route moved to another interface,
	// even through the same gateway, as when a cable or a dock is plugged in.
	ChangeInterface
	// ChangeOffline means no default route is left at all, as with Wi-Fi off
	// and no cable. The snapshot after it is empty and must not become the
	// baseline: the next change is compared with the network before it.
	ChangeOffline
	// ChangeWake means the system woke up from sleep during the change,
	// whatever the routes did. Wake-ups keep today's restart.
	ChangeWake
	// ChangeUnknown means the underlay could not be read after the event.
	// It says nothing about the network, so nothing is changed on it.
	ChangeUnknown
)

func (ChangeKind) String added in v0.84.0

func (k ChangeKind) String() string

String returns the change kind as it appears in logs.

type NetworkMonitor added in v0.27.8

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

NetworkMonitor watches for changes in network configuration.

func New

func New() *NetworkMonitor

New creates a new network monitor.

func (*NetworkMonitor) Listen added in v0.38.0

func (nw *NetworkMonitor) Listen(ctx context.Context, baseline NextHops) (change Change, err error)

Listen begins monitoring network changes. When a change is detected, it returns how the underlay moved. It can be called again after it returns, to watch for the next change. The caller passes the snapshot to compare with, normally the After of the previous change; an empty baseline makes Listen read the current one and wait until a default route exists.

func (*NetworkMonitor) Stop added in v0.27.8

func (nw *NetworkMonitor) Stop()

Stop stops the network monitor.

type NextHops added in v0.84.0

type NextHops struct {
	V4 systemops.Nexthop
	V6 systemops.Nexthop
	// Addrs holds the unicast addresses of the default interfaces, sorted and
	// without link-local ones.
	Addrs []netip.Addr
}

NextHops is the underlay snapshot: the default next hop of each address family and the addresses of the default interfaces.

func (NextHops) HasDefault added in v0.84.0

func (n NextHops) HasDefault() bool

HasDefault reports whether the snapshot has a default route in any family.

Jump to

Keyboard shortcuts

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