linuxcalls

package
v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 17 Imported by: 45

Documentation

Overview

Package linuxcalls contains wrappers over Netlink APIs related to Linux VETH interfaces or Linux interfaces in general.

Index

Constants

View Source
const (
	// defaultLoopbackName is the name used to access loopback interface in linux
	// host_if_name field in config is effectively ignored
	DefaultLoopbackName = "lo"
)

Variables

This section is empty.

Functions

func GetTapAlias

func GetTapAlias(linuxIf *interfaces.Interface, origHostIfName string) string

GetTapAlias returns alias for Linux TAP interface managed by the agent. The alias stores the TAP_TO_VPP logical name together with VPP-TAP logical name and the host interface name as originally set by VPP side.

func GetVethAlias

func GetVethAlias(vethName, peerName string) string

GetVethAlias returns alias for Linux VETH interface managed by the agent. The alias stores the VETH logical name together with the peer (logical) name.

func ParseTapAlias

func ParseTapAlias(alias string) (linuxTapName, vppTapName, origHostIfName string)

ParseTapAlias parses out TAP_TO_VPP logical name together with the name of the linked VPP-TAP and the original TAP host interface name.

func ParseVethAlias

func ParseVethAlias(alias string) (vethName, peerName string)

ParseVethAlias parses out VETH logical name together with the peer name from the alias.

Types

type InterfaceDetails

type InterfaceDetails struct {
	Interface *interfaces.Interface `json:"interface"`
	Meta      *InterfaceMeta        `json:"interface_meta"`
}

InterfaceDetails is an object combining linux interface data based on proto model with additional metadata

type InterfaceMeta

type InterfaceMeta struct {
	LinuxIfIndex  int    `json:"linux_if_index"`
	ParentIndex   int    `json:"parent_index"`
	MasterIndex   int    `json:"master_index"`
	OperState     uint8  `json:"oper_state"`
	Flags         uint32 `json:"flags"`
	Encapsulation string `json:"encapsulation"`
	NumRxQueues   int    `json:"num_rx_queue"`
	NumTxQueues   int    `json:"num_tx_queue"`
	TxQueueLen    int    `json:"tx_queue_len"`
}

InterfaceMeta represents linux interface metadata

type InterfaceStatistics

type InterfaceStatistics struct {
	Name         string                    `json:"interface_name"`
	Type         interfaces.Interface_Type `json:"interface_type"`
	LinuxIfIndex int                       `json:"linux_if_index"`

	// stats data
	RxPackets uint64 `json:"rx_packets"`
	TxPackets uint64 `json:"tx_packets"`
	RxBytes   uint64 `json:"rx_bytes"`
	TxBytes   uint64 `json:"tx_bytes"`
	RxErrors  uint64 `json:"rx_errors"`
	TxErrors  uint64 `json:"tx_errors"`
	RxDropped uint64 `json:"rx_dropped"`
	TxDropped uint64 `json:"tx_dropped"`
}

Statistics are represented here since there is currently no model

type NetLinkHandler added in v1.8.1

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

NetLinkHandler is accessor for Netlink methods.

func NewNetLinkHandler

func NewNetLinkHandler(
	nsPlugin nsplugin.API,
	ifIndexes ifaceidx.LinuxIfMetadataIndex,
	agentPrefix string,
	goRoutineCount int,
	log logging.Logger,
) *NetLinkHandler

NewNetLinkHandler creates new instance of Netlink handler.

func (*NetLinkHandler) AddInterfaceIP added in v1.8.1

func (h *NetLinkHandler) AddInterfaceIP(ifName string, ip *net.IPNet) error

AddInterfaceIP calls AddrAdd Netlink API.

func (*NetLinkHandler) AddVethInterfacePair added in v1.8.1

func (h *NetLinkHandler) AddVethInterfacePair(ifName, peerIfName string) error

AddVethInterfacePair calls LinkAdd Netlink API for the Netlink.Veth interface type.

func (*NetLinkHandler) DelInterfaceIP added in v1.8.1

func (h *NetLinkHandler) DelInterfaceIP(ifName string, ip *net.IPNet) error

DelInterfaceIP calls AddrDel Netlink API.

func (*NetLinkHandler) DeleteInterface

func (h *NetLinkHandler) DeleteInterface(ifName string) error

DeleteInterface removes the given interface.

func (*NetLinkHandler) DumpInterfaceStats

func (h *NetLinkHandler) DumpInterfaceStats() ([]*InterfaceStatistics, error)

DumpInterfaceStats retrieves statistics for all linux interfaces from default namespace and from all the other namespaces based on known linux interfaces from the index map.

func (*NetLinkHandler) DumpInterfaceStatsFromNamespaces

func (h *NetLinkHandler) DumpInterfaceStatsFromNamespaces(nsList []*namespaces.NetNamespace) ([]*InterfaceStatistics, error)

DumpInterfaceStatsFromNamespaces requires context in form of the namespace list of which linux interface stats will be retrieved. If no context is provided, interface stats only from the default namespace interfaces are retrieved.

func (*NetLinkHandler) DumpInterfaces added in v1.8.1

func (h *NetLinkHandler) DumpInterfaces() ([]*InterfaceDetails, error)

DumpInterfaces retrieves all linux interfaces from default namespace and from all the other namespaces based on known linux interfaces from the index map.

func (*NetLinkHandler) DumpInterfacesFromNamespaces

func (h *NetLinkHandler) DumpInterfacesFromNamespaces(nsList []*namespaces.NetNamespace) ([]*InterfaceDetails, error)

DumpInterfacesFromNamespaces requires context in form of the namespace list of which linux interfaces will be retrieved. If no context is provided, interfaces only from the default namespace are retrieved.

func (*NetLinkHandler) GetAddressList added in v1.8.1

func (h *NetLinkHandler) GetAddressList(ifName string) ([]netlink.Addr, error)

GetAddressList calls AddrList netlink API

func (*NetLinkHandler) GetChecksumOffloading

func (h *NetLinkHandler) GetChecksumOffloading(ifName string) (rxOn, txOn bool, err error)

GetChecksumOffloading returns the state of Rx/Tx checksum offloading for the given interface.

func (*NetLinkHandler) GetInterfaceType added in v1.8.1

func (h *NetLinkHandler) GetInterfaceType(ifName string) (string, error)

GetInterfaceType returns the type (string representation) of a given interface.

func (*NetLinkHandler) GetLinkByName added in v1.8.1

func (h *NetLinkHandler) GetLinkByName(ifName string) (netlink.Link, error)

GetLinkByName calls netlink API to get Link type from interface name

func (h *NetLinkHandler) GetLinkList() ([]netlink.Link, error)

GetLinkList calls netlink API to get all Links in namespace

func (*NetLinkHandler) InterfaceExists added in v1.8.1

func (h *NetLinkHandler) InterfaceExists(ifName string) (bool, error)

InterfaceExists checks if interface with a given name exists.

func (*NetLinkHandler) IsInterfaceUp

func (h *NetLinkHandler) IsInterfaceUp(ifName string) (bool, error)

IsInterfaceUp checks if the interface is UP.

func (*NetLinkHandler) LinkSubscribe

func (h *NetLinkHandler) LinkSubscribe(ch chan<- netlink.LinkUpdate, done <-chan struct{}) error

LinkSubscribe takes a channel to which notifications will be sent when links change. Close the 'done' chan to stop subscription.

func (*NetLinkHandler) RenameInterface added in v1.8.1

func (h *NetLinkHandler) RenameInterface(ifName string, newName string) error

RenameInterface changes the name of the interface <ifName> to <newName>.

func (*NetLinkHandler) SetChecksumOffloading

func (h *NetLinkHandler) SetChecksumOffloading(ifName string, rxOn, txOn bool) error

SetChecksumOffloading enables/disables Rx/Tx checksum offloading for the given interface.

func (*NetLinkHandler) SetInterfaceAlias

func (h *NetLinkHandler) SetInterfaceAlias(ifName, alias string) error

SetInterfaceAlias sets the alias of the given interface. Equivalent to: `ip link set dev $ifName alias $alias`

func (*NetLinkHandler) SetInterfaceDown added in v1.8.1

func (h *NetLinkHandler) SetInterfaceDown(ifName string) error

SetInterfaceDown calls Netlink API LinkSetDown.

func (*NetLinkHandler) SetInterfaceMTU added in v1.8.1

func (h *NetLinkHandler) SetInterfaceMTU(ifName string, mtu int) error

SetInterfaceMTU calls LinkSetMTU Netlink API.

func (*NetLinkHandler) SetInterfaceMac added in v1.8.1

func (h *NetLinkHandler) SetInterfaceMac(ifName string, macAddress string) error

SetInterfaceMac calls LinkSetHardwareAddr netlink API.

func (*NetLinkHandler) SetInterfaceUp added in v1.8.1

func (h *NetLinkHandler) SetInterfaceUp(ifName string) error

SetInterfaceUp calls Netlink API LinkSetUp.

func (*NetLinkHandler) SetLinkNamespace

func (h *NetLinkHandler) SetLinkNamespace(link netlink.Link, ns netns.NsHandle) (err error)

SetLinkNamespace puts link into a network namespace.

type NetlinkAPI

type NetlinkAPI interface {
	NetlinkAPIRead

	// AddVethInterfacePair configures two connected VETH interfaces
	AddVethInterfacePair(ifName, peerIfName string) error
	// DeleteInterface removes the given interface.
	DeleteInterface(ifName string) error
	// SetInterfaceUp sets interface state to 'up'
	SetInterfaceUp(ifName string) error
	// SetInterfaceDown sets interface state to 'down'
	SetInterfaceDown(ifName string) error
	// AddInterfaceIP adds new IP address
	AddInterfaceIP(ifName string, addr *net.IPNet) error
	// DelInterfaceIP removes IP address from linux interface
	DelInterfaceIP(ifName string, addr *net.IPNet) error
	// SetInterfaceMac sets MAC address
	SetInterfaceMac(ifName string, macAddress string) error
	// SetInterfaceMTU set maximum transmission unit for interface
	SetInterfaceMTU(ifName string, mtu int) error
	// RenameInterface changes interface host name
	RenameInterface(ifName string, newName string) error
	// SetInterfaceAlias sets the alias of the given interface.
	// Equivalent to: `ip link set dev $ifName alias $alias`
	SetInterfaceAlias(ifName, alias string) error
	// SetLinkNamespace puts link into a network namespace.
	SetLinkNamespace(link netlink.Link, ns netns.NsHandle) error
	// SetChecksumOffloading enables/disables Rx/Tx checksum offloading
	// for the given interface.
	SetChecksumOffloading(ifName string, rxOn, txOn bool) error
}

NetlinkAPI interface covers all methods inside linux calls package needed to manage linux interfaces.

type NetlinkAPIRead added in v1.8.1

type NetlinkAPIRead interface {
	// GetLinkByName returns netlink interface type
	GetLinkByName(ifName string) (netlink.Link, error)
	// GetLinkList return all links from namespace
	GetLinkList() ([]netlink.Link, error)
	// LinkSubscribe takes a channel to which notifications will be sent
	// when links change. Close the 'done' chan to stop subscription.
	LinkSubscribe(ch chan<- netlink.LinkUpdate, done <-chan struct{}) error
	// GetAddressList reads all IP addresses
	GetAddressList(ifName string) ([]netlink.Addr, error)
	// InterfaceExists verifies interface existence
	InterfaceExists(ifName string) (bool, error)
	// IsInterfaceUp checks if the interface is UP.
	IsInterfaceUp(ifName string) (bool, error)
	// GetInterfaceType returns linux interface type
	GetInterfaceType(ifName string) (string, error)
	// GetChecksumOffloading returns the state of Rx/Tx checksum offloading
	// for the given interface.
	GetChecksumOffloading(ifName string) (rxOn, txOn bool, err error)
	// DumpInterfaces uses local cache to gather information about linux
	// namespaces and retrieves interfaces from them.
	DumpInterfaces() ([]*InterfaceDetails, error)
	// DumpInterfacesFromNamespaces retrieves all linux interfaces based
	// on provided namespace context.
	DumpInterfacesFromNamespaces(nsList []*namespaces.NetNamespace) ([]*InterfaceDetails, error)
	// DumpInterfaceStats uses local cache to gather information about linux
	// namespaces and retrieves stats for interfaces in that namespace them.
	DumpInterfaceStats() ([]*InterfaceStatistics, error)
	// DumpInterfaceStatsFromNamespaces retrieves all linux interface stats based
	// on provided namespace context.
	DumpInterfaceStatsFromNamespaces(nsList []*namespaces.NetNamespace) ([]*InterfaceStatistics, error)
}

NetlinkAPIRead interface covers read methods inside linux calls package needed to manage linux interfaces.

Jump to

Keyboard shortcuts

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