linuxcalls

package
v2.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package linuxcalls contains wrappers over Netlink & OS APIs related to Linux namespaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystemAPI

type FileSystemAPI interface {
	// FileExists checks whether the file exists.
	FileExists(name string) (bool, error)
	// OpenFile opens a file.
	OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
	// MkDirAll creates a directory with all parent directories.
	MkDirAll(path string, perm os.FileMode) error
	// Remove removes named file or directory.
	Remove(name string) error
	// Mount makes resources available.
	Mount(source string, target string, fsType string, flags uintptr, data string) error
	// Unmount resources.
	Unmount(target string, flags int) (err error)
}

FileSystemAPI defines all methods used to access file system.

type NamedNetNsAPI

type NamedNetNsAPI interface {
	// CreateNamedNetNs creates a new named Linux network namespace.
	// It does exactly the same thing as the command "ip netns add NAMESPACE".
	CreateNamedNetNs(ctx NamespaceMgmtCtx, nsName string) (netns.NsHandle, error)
	// DeleteNamedNetNs deletes an existing named Linux network namespace.
	// It does exactly the same thing as the command "ip netns del NAMESPACE".
	DeleteNamedNetNs(nsName string) error
	// NamedNetNsExists checks whether named namespace exists.
	NamedNetNsExists(nsName string) (bool, error)
}

NamedNetNsAPI defines methods related to management of named network namespaces.

func NewNamedNetNsHandler

func NewNamedNetNsHandler(sysHandler SystemAPI, log logging.Logger) NamedNetNsAPI

NewNamedNetNsHandler creates new instance of namespace handler

type NamespaceMgmtCtx

type NamespaceMgmtCtx interface {
	// LockOSThread wires the calling goroutine to its current operating system thread.
	// The method should implement re-entrant lock always called from a single go routine.
	LockOSThread()
	// UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
	// The method should implement re-entrant lock always called from a single go routine.
	UnlockOSThread()
}

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.

type NetworkNamespaceAPI

type NetworkNamespaceAPI interface {
	// NewNetworkNamespace creates a new namespace and returns a handle to manage it further.
	NewNetworkNamespace() (ns netns.NsHandle, err error)
	// DuplicateNamespaceHandle duplicates network namespace handle.
	DuplicateNamespaceHandle(ns netns.NsHandle) (netns.NsHandle, error)
	// GetCurrentNamespace gets a handle to the current threads network namespace.
	GetCurrentNamespace() (ns netns.NsHandle, err error)
	// GetNamespaceFromPath gets a handle to a network namespace identified
	// by the path.
	GetNamespaceFromPath(path string) (ns netns.NsHandle, err error)
	// GetNamespaceFromPid gets a handle to the network namespace of a given pid.
	GetNamespaceFromPid(pid int) (ns netns.NsHandle, err error)
	// GetNamespaceFromName gets a handle to a named network namespace such as one
	// created by `ip netns add`.
	GetNamespaceFromName(name string) (ns netns.NsHandle, err error)
	// SetNamespace sets the current namespace to the namespace represented by the handle.
	SetNamespace(ns netns.NsHandle) (err error)
}

NetworkNamespaceAPI defines methods for low-level handling of network namespaces.

type SystemAPI

type SystemAPI interface {
	FileSystemAPI
	NetworkNamespaceAPI
}

SystemAPI defines all methods required for managing network namespaces on the system level.

func NewSystemHandler

func NewSystemHandler() SystemAPI

NewSystemHandler returns new handler.

Jump to

Keyboard shortcuts

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