barista.run: barista.run/base/watchers/netlink Index | Files

package netlink

import "barista.run/base/watchers/netlink"

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

Index

Package Files

netlink.go nl.go

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

Link represents a network link.

type LinkIndex Uses

type LinkIndex int

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

type MultiSubscription Uses

type MultiSubscription struct{}

MultiSubscription represents a subscription over all links.

func All Uses

func All() MultiSubscription

All creates a netlink watcher for all links.

func (MultiSubscription) Get Uses

func (s MultiSubscription) Get() []Link

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

func (MultiSubscription) Next Uses

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

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

type OperState Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (s *Subscription) Get() Link

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

func (*Subscription) Next Uses

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

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

func (*Subscription) Unsubscribe Uses

func (s *Subscription) Unsubscribe()

Unsubscribe stops further notifications and closes the channel.

type Tester Uses

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 Uses

func TestMode() Tester

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

Package netlink imports 9 packages (graph) and is imported by 5 packages. Updated 2019-12-08. Refresh now. Tools for package owners.