Documentation ¶
Overview ¶
Package link provides access to network interfaces and their parameters, such as link type and flags. In addition, it provides the IP layer offset for each link type and implements default BPF filtering to maximize throughput (by selecting only packets that subsequently can be processed / parsed by the routines provided by slimcap).
Index ¶
Constants ¶
const ( // IPLayerOffsetEthernet denotes the ethernet header offset IPLayerOffsetEthernet = 14 // LayerOffsetPPPOE denotes the additional offset for PPPOE (session) packets LayerOffsetPPPOE = 8 )
Variables ¶
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") )
var ( // CaptureLengthFixed denotes a simple fixed snaplen strategy CaptureLengthFixed = func(snaplen int) CaptureLengthStrategy { return func(l *Link) int { return snaplen } } // CaptureLengthMinimalIPv4Header indicates that the minimal necessary length to // facilitate IPv4 layer analysis should be chosen CaptureLengthMinimalIPv4Header = func(l *Link) int { return int(l.Type.IPHeaderOffset()) + ipv4.HeaderLen } // CaptureLengthMinimalIPv6Header indicates that the minimal necessary length to // facilitate IPv6 layer analysis should be chosen CaptureLengthMinimalIPv6Header = func(l *Link) int { return int(l.Type.IPHeaderOffset()) + ipv6.HeaderLen } // CaptureLengthMinimalIPv4Transport indicates that the minimal necessary length to // facilitate IPv4 transport layer analysis should be chosen CaptureLengthMinimalIPv4Transport = func(l *Link) int { return int(l.Type.IPHeaderOffset()) + ipv4.HeaderLen + 14 } // CaptureLengthMinimalIPv6Transport indicates that the minimal necessary length to // facilitate IPv6 transport layer analysis should be chosen CaptureLengthMinimalIPv6Transport = func(l *Link) int { return int(l.Type.IPHeaderOffset()) + ipv6.HeaderLen + 14 } )
var EmptyEthernetLink = Link{ Interface: Interface{ Type: TypeEthernet, }, }
EmptyEthernetLink provides a quick access to a plain / empty ethernet-type link
var ErrIndexOutOfBounds = errors.New("interface index out of bounds")
ErrIndexOutOfBounds denotes the (unlikely) case of an invalid index being outside the range of an int
Functions ¶
This section is empty.
Types ¶
type CaptureLengthStrategy ¶
CaptureLengthStrategy denotes a strategy to calculate an optimal snaplen for a link (type) depending on the use case
type EtherType ¶
type EtherType uint16
EtherType denotes the protocol encapsulated in the payload of the ethernet frame
func (EtherType) HasValidIPLayer ¶
HasValidIPLayer determines if the ethernet frame has a valid IPv4 or IPv6 layer
type Interface ¶
Interface is the low-level representation of a network interface
func NewInterface ¶
NewInterface instantiates a new network interface and obtains its basic parameters
type Link ¶
type Link struct {
Interface
}
Link denotes a link, i.e. an interface (wrapped) and its link type
func FindAllLinks ¶
FindAllLinks retrieves all system network interfaces and their link type
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 // TypeNone denotes a link of type ARPHRD_NONE: // Tunnel / anything else (confirmed: Wireguard, OpenVPN) TypeNone Type = 65534 )
func (Type) BPFFilter ¶
func (l Type) BPFFilter() func(snapLen int) []bpf.RawInstruction
BPFFilter returns the link / interface specific raw BPF instructions to filter for valid packets only
func (Type) IPHeaderOffset ¶
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