ifaces

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type      EventType
	Interface Interface
}

Event of a network interface, given the type (added, removed) and the interface name

type EventType

type EventType int

EventType for an interface: added, deleted

const (
	EventAdded EventType = iota
	EventDeleted
)

func (EventType) String

func (e EventType) String() string

type Informer

type Informer interface {
	// Subscribe returns a channel that sends Event instances.
	Subscribe(ctx context.Context) (<-chan Event, error)
}

Informer provides notifications about each network interface that is added or removed from the host. Production implementations: Poller and Watcher.

type Interface

type Interface struct {
	Name  string
	Index int
}

type Poller

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

Poller periodically looks for the network interfaces in the system and forwards Event notifications when interfaces are added or deleted.

func NewPoller

func NewPoller(period time.Duration, bufLen int) *Poller

func (*Poller) Subscribe

func (np *Poller) Subscribe(ctx context.Context) (<-chan Event, error)

type Registerer

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

Registerer is an informer that wraps another informer implementation, and keeps track of the currently existing interfaces in the system, accessible through the IfaceNameForIndex method.

func NewRegisterer

func NewRegisterer(inner Informer, bufLen int) *Registerer

func (*Registerer) IfaceNameForIndex

func (r *Registerer) IfaceNameForIndex(idx int) (string, bool)

IfaceNameForIndex gets the interface name given an index as recorded by the underlying interfaces' informer. It backs up into the net.InterfaceByIndex function if the interface has not been previously registered

func (*Registerer) Subscribe

func (r *Registerer) Subscribe(ctx context.Context) (<-chan Event, error)

type Watcher

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

Watcher uses system's netlink to get real-time information events about network interfaces' addition or removal.

func NewWatcher

func NewWatcher(bufLen int) *Watcher

func (*Watcher) Subscribe

func (w *Watcher) Subscribe(ctx context.Context) (<-chan Event, error)

Jump to

Keyboard shortcuts

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