netlink

package
v0.0.0-...-c936f35 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 20

Documentation

Overview

Package netlink uses the netlink library to watch for changes in link states.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	Name         string
	State        OperState
	HardwareAddr net.HardwareAddr
	IPs          []net.IP
}

Link represents a network link.

type LinkIndex

type LinkIndex int

LinkIndex is an opaque identifier for a link as used by netlink.

type MultiSubscription

type MultiSubscription struct{}

MultiSubscription represents a subscription over all links.

func All

func All() MultiSubscription

All creates a netlink watcher for all links.

func (MultiSubscription) Get

func (s MultiSubscription) Get() []Link

Get returns the most recent Link that matches the subscription conditions.

func (MultiSubscription) Next

func (s MultiSubscription) Next() <-chan struct{}

Next returns a channel that will be closed on the next update.

type OperState

type OperState int

OperState represents the operating state of a link.

const (
	Gone           OperState = -1 // Special value sent when a link is deleted.
	Unknown        OperState = 0
	NotPresent     OperState = 1
	Down           OperState = 2
	LowerLayerDown OperState = 3
	Testing        OperState = 4
	Dormant        OperState = 5
	Up             OperState = 6
)

Operating states, from the IF_OPER_* constants in linux.

type Subscription

type Subscription struct {
	C <-chan struct{}
	// contains filtered or unexported fields
}

Subscription represents a potentially filtered subscription to netlink, which returns the best link that matches the filter conditions specified.

func Any

func Any() *Subscription

Any creates a netlink watcher that returns the 'best' link. Links are preferred in order of their status, and then by name. The status order is Up > Dormant > Testing > LowerLayerDown > Down > NotPresent > Unknown. (A 'virtual' link with status Gone may be returned if no links are available). If multiple links have the same status, they are ordered alphabetically by their name.

func ByName

func ByName(name string) *Subscription

ByName creates a netlink watcher for the named interface. Any updates to the named interface will cause the current information about that link to be sent on the returned channel.

func WithPrefix

func WithPrefix(prefix string) *Subscription

WithPrefix creates a netlink watcher that returns the 'best' link beginning with the given prefix (e.g. 'wl' for wireless, or 'e' for ethernet). See #Any() for details on link priority.

func (*Subscription) Get

func (s *Subscription) Get() Link

Get returns the most recent Link that matches the subscription conditions.

func (*Subscription) Next

func (s *Subscription) Next() <-chan struct{}

Next returns a channel that will be closed on the next update.

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

Unsubscribe stops further notifications and closes the channel.

type Tester

type Tester interface {
	AddLink(Link) LinkIndex
	UpdateLink(LinkIndex, Link)
	RemoveLink(LinkIndex)
	AddIP(LinkIndex, net.IP)
	RemoveIP(LinkIndex, net.IP)
}

Tester provides methods to simulate netlink messages for testing.

func TestMode

func TestMode() Tester

TestMode puts the netlink watcher in test mode, and resets the link and subscriber states.

Jump to

Keyboard shortcuts

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