Documentation ¶
Overview ¶
Package linuxcalls contains wrappers over Netlink APIs related to Linux VETH interfaces or Linux interfaces in general.
Index ¶
- Constants
- func AddInterfaceIP(ifName string, addr *net.IPNet, timeLog measure.StopWatchEntry) error
- func AddVethInterface(ifName, peerIfName string, log logging.Logger, timeLog measure.StopWatchEntry) error
- func DelInterfaceIP(ifName string, addr *net.IPNet, timeLog measure.StopWatchEntry) error
- func DelVethInterface(ifName, peerIfName string, log logging.Logger, timeLog measure.StopWatchEntry) error
- func DeleteNamedNetNs(namespace string, log logging.Logger) error
- func GetInterfaceType(ifName string, timeLog measure.StopWatchEntry) (string, error)
- func GetVethPeerName(ifName string, timeLog measure.StopWatchEntry) (string, error)
- func InterfaceAdminDown(ifName string, timeLog measure.StopWatchEntry) error
- func InterfaceAdminUp(ifName string, timeLog measure.StopWatchEntry) error
- func InterfaceExists(ifName string, timeLog measure.StopWatchEntry) (bool, error)
- func NamedNetNsExists(namespace string, log logging.Logger) (bool, error)
- func NamespaceToStr(namespace *intf.LinuxInterfaces_Interface_Namespace) string
- func SetInterfaceMTU(ifName string, mtu int, timeLog measure.StopWatchEntry) error
- func SetInterfaceMac(ifName string, macAddress string, timeLog measure.StopWatchEntry) error
- func SetInterfaceNamespace(ctx *NamespaceMgmtCtx, ifName string, ...) error
- func ToInterfaceNs(ns *Namespace) (*intf.LinuxInterfaces_Interface_Namespace, error)
- type Namespace
- type NamespaceMgmtCtx
Constants ¶
const ( PidRefNs = 0 MicroserviceRefNs = 1 NamedNs = 2 FileRefNs = 3 )
Namespace types
Variables ¶
This section is empty.
Functions ¶
func AddInterfaceIP ¶
AddInterfaceIP calls AddrAdd Netlink API.
func AddVethInterface ¶
func AddVethInterface(ifName, peerIfName string, log logging.Logger, timeLog measure.StopWatchEntry) error
AddVethInterface calls LinkAdd Netlink API for the Netlink.Veth interface type.
func DelInterfaceIP ¶
DelInterfaceIP calls AddrDel Netlink API.
func DelVethInterface ¶
func DelVethInterface(ifName, peerIfName string, log logging.Logger, timeLog measure.StopWatchEntry) error
DelVethInterface calls LinkDel Netlink API for the Netlink.Veth interface type.
func DeleteNamedNetNs ¶
DeleteNamedNetNs deletes an existing named Linux network namespace. It does exactly the same thing as the command "ip netns del NAMESPACE".
func GetInterfaceType ¶
func GetInterfaceType(ifName string, timeLog measure.StopWatchEntry) (string, error)
GetInterfaceType returns the type (string representation) of a given interface.
func GetVethPeerName ¶
func GetVethPeerName(ifName string, timeLog measure.StopWatchEntry) (string, error)
GetVethPeerName return the peer name for a given VETH interface.
func InterfaceAdminDown ¶
func InterfaceAdminDown(ifName string, timeLog measure.StopWatchEntry) error
InterfaceAdminDown calls Netlink API LinkSetDown.
func InterfaceAdminUp ¶
func InterfaceAdminUp(ifName string, timeLog measure.StopWatchEntry) error
InterfaceAdminUp calls Netlink API LinkSetUp.
func InterfaceExists ¶
func InterfaceExists(ifName string, timeLog measure.StopWatchEntry) (bool, error)
InterfaceExists checks if interface with a given name exists.
func NamedNetNsExists ¶
NamedNetNsExists checks whether namespace exists.
func NamespaceToStr ¶
func NamespaceToStr(namespace *intf.LinuxInterfaces_Interface_Namespace) string
NamespaceToStr returns a string representation of a namespace suitable for logging purposes.
func SetInterfaceMTU ¶
func SetInterfaceMTU(ifName string, mtu int, timeLog measure.StopWatchEntry) error
SetInterfaceMTU calls LinkSetMTU Netlink API.
func SetInterfaceMac ¶
func SetInterfaceMac(ifName string, macAddress string, timeLog measure.StopWatchEntry) error
SetInterfaceMac calls LinkSetHardwareAddr netlink API.
func SetInterfaceNamespace ¶
func SetInterfaceNamespace(ctx *NamespaceMgmtCtx, ifName string, namespace *intf.LinuxInterfaces_Interface_Namespace, log logging.Logger, stopwatch *measure.Stopwatch) error
SetInterfaceNamespace moves a given Linux interface into a specified namespace.
func ToInterfaceNs ¶
func ToInterfaceNs(ns *Namespace) (*intf.LinuxInterfaces_Interface_Namespace, error)
ToInterfaceNs converts generic namespace to interface-type namespace
Types ¶
type Namespace ¶
Namespace is a generic representation of typed namespace (interface, arp, etc...)
func CreateNamedNetNs ¶
CreateNamedNetNs creates a new named Linux network namespace. It does exactly the same thing as the command "ip netns add NAMESPACE".
func GetDefaultNamespace ¶
func GetDefaultNamespace() *Namespace
GetDefaultNamespace returns a generic default namespace
func ToGenericNs ¶
func ToGenericNs(ns *intf.LinuxInterfaces_Interface_Namespace) *Namespace
ToGenericNs converts interface-type namespace to generic type namespace. Such an object can be used to call common namespace-related methods
func (*Namespace) CompareNamespaces ¶
CompareNamespaces is a comparison function for "Namespace" type.
func (*Namespace) GetOrCreateNs ¶
GetOrCreateNs returns an existing Linux network namespace or creates a new one if it doesn't exist yet. It is, however, only possible to create "named" namespaces. For PID-based namespaces, process with the given PID must exists, otherwise the function returns an error.
func (*Namespace) NamespaceToStr ¶
NamespaceToStr returns a string representation of a namespace suitable for logging purposes.
func (*Namespace) SwitchNamespace ¶
func (ns *Namespace) SwitchNamespace(ctx *NamespaceMgmtCtx, log logging.Logger) (revert func(), err error)
SwitchNamespace switches the network namespace of the current thread. Caller should eventually call the returned "revert" function in order to get back to the original network namespace (for example using "defer revert()").
type NamespaceMgmtCtx ¶
type NamespaceMgmtCtx struct {
// contains filtered or unexported fields
}
NamespaceMgmtCtx represents context of an ongoing management of Linux namespaces. The same context should not be used concurrently.
func NewNamespaceMgmtCtx ¶
func NewNamespaceMgmtCtx() *NamespaceMgmtCtx
NewNamespaceMgmtCtx creates and returns a new context for management of Linux namespaces.