package ns

import "github.com/containernetworking/plugins/pkg/ns"

Index

Constants

const (
	// https://github.com/torvalds/linux/blob/master/include/uapi/linux/magic.h
	NSFS_MAGIC   = unix.NSFS_MAGIC
	PROCFS_MAGIC = unix.PROC_SUPER_MAGIC
)

Functions

func IsNSorErr

func IsNSorErr(nspath string) error

func WithNetNSPath

func WithNetNSPath(nspath string, toRun func(NetNS) error) error

WithNetNSPath executes the passed closure under the given network namespace, restoring the original namespace afterwards.

Types

type NSPathNotExistErr

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

func (NSPathNotExistErr) Error

func (e NSPathNotExistErr) Error() string

type NSPathNotNSErr

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

func (NSPathNotNSErr) Error

func (e NSPathNotNSErr) Error() string

type NetNS

type NetNS interface {
	// Executes the passed closure in this object's network namespace,
	// attempting to restore the original namespace before returning.
	// However, since each OS thread can have a different network namespace,
	// and Go's thread scheduling is highly variable, callers cannot
	// guarantee any specific namespace is set unless operations that
	// require that namespace are wrapped with Do().  Also, no code called
	// from Do() should call runtime.UnlockOSThread(), or the risk
	// of executing code in an incorrect namespace will be greater.  See
	// https://github.com/golang/go/wiki/LockOSThread for further details.
	Do(toRun func(NetNS) error) error

	// Sets the current network namespace to this object's network namespace.
	// Note that since Go's thread scheduling is highly variable, callers
	// cannot guarantee the requested namespace will be the current namespace
	// after this function is called; to ensure this wrap operations that
	// require the namespace with Do() instead.
	Set() error

	// Returns the filesystem path representing this object's network namespace
	Path() string

	// Returns a file descriptor representing this object's network namespace
	Fd() uintptr

	// Cleans up this instance of the network namespace; if this instance
	// is the last user the namespace will be destroyed
	Close() error
}

func GetCurrentNS

func GetCurrentNS() (NetNS, error)

Returns an object representing the current OS thread's network namespace

func GetNS

func GetNS(nspath string) (NetNS, error)

Returns an object representing the namespace referred to by @path

func TempNetNS

func TempNetNS() (NetNS, error)

Returns a new empty NetNS. Calling Close() let the kernel garbage collect the network namespace.

Source Files

ns_linux.go

Version
v1.7.1 (latest)
Published
Apr 25, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
1 week ago

Tools for package owners.