link

package module
v0.0.0-...-d42cb4e Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// IPLayerOffsetEthernet denotes the ethernet header offset
	IPLayerOffsetEthernet = 14

	// IPLayerOffsetLinuxSLL2 denotes the Linux SLL2 header offset
	IPLayerOffsetLinuxSLL2 = 20

	// LayerOffsetPPPOE denotes the additional offset for PPPOE (session) packets
	LayerOffsetPPPOE = 8
)

Variables

View Source
var (

	// ErrNotExist denotes that the interface in question does not exist
	ErrNotExist = errors.New("interface does not exist")

	// ErrNotUp denotes that the interface in question is not up
	ErrNotUp = errors.New("interface is currently not up")
)
View Source
var EmptyEthernetLink = Link{
	Type: TypeEthernet,
}

EmptyEthernetLink provides a quick access to a plain / empty ethernet-type link

View Source
var (
	// ErrIndexOutOfBounds denotes the (unlikely) case of an invalid index being outside the range of an int
	ErrIndexOutOfBounds = errors.New("interface index out of bounds")
)

Functions

This section is empty.

Types

type Link struct {
	Name   string
	Index  int
	Type   Type
	IsVLAN bool
}

Link is the low-level representation of a network interface

func New

func New(name string, opts ...func(*Link)) (link *Link, err error)

New instantiates a new link / interface It will return an error if the interface does not exist or is not up

func (*Link) IPs

func (l *Link) IPs() ([]net.IP, error)

IPs retrieves all IPv4 and IPv6 addresses assigned to the interface using a minimal netlink RTM_GETADDR dump to avoid the higher-level net package. Mostly extracted from the net package internals (net.Interface.Addrs()).

func (*Link) IsUp

func (l *Link) IsUp() (bool, error)

IsUp determines if an interface is currently up (at the time of the call)

func (Link) String

func (l Link) String() string

String returns the name of the network interface (Stringer interface)

type Links []*Link

Links is a slice of Link pointers

func HostLinks(names ...string) (Links, error)

HostLinks returns all (or selected) host interfaces The function will not fail if a link is down, but will fail if a link does not exist

func (Links) IPs

func (l Links) IPs() (map[string][]net.IP, error)

IPs returns all IP addresses assigned to all links in the slice

type Type

type Type int

Type denotes the linux interface type

const (

	// TypeInvalid denotes an invalid link type
	TypeInvalid Type = iota

	// TypeEthernet denotes a link of type ARPHRD_ETHER
	TypeEthernet Type = 1

	// TypeLoopback denotes a link of type ARPHRD_LOOPBACK
	TypeLoopback Type = 772

	// TypePPP denotes a link of type ARPHRD_PPP
	TypePPP Type = 512

	// TypeIP6IP6 denotes a link of type ARPHRD_TUNNEL6
	TypeIP6IP6 Type = 769

	// TypeGRE denotes a link of type ARPHRD_IPGRE
	TypeGRE Type = 778

	// TypeGRE6 denotes a link of type ARPHRD_IP6GRE
	TypeGRE6 Type = 823

	// TypeLinuxSLL2 denotes a link of type LINUX_SLL2
	TypeLinuxSLL2 Type = 276

	// TypeNone denotes a link of type ARPHRD_NONE:
	// Tunnel / anything else (confirmed: Wireguard, OpenVPN)
	TypeNone Type = 65534
)

func (Type) IPHeaderOffset

func (l Type) IPHeaderOffset() byte

IPHeaderOffset returns the link / interface specific payload offset for the IP header c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/if_arp.h

Jump to

Keyboard shortcuts

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