netns – github.com/vishvananda/netns Index | Files

package netns

import "github.com/vishvananda/netns"

Package netns allows ultra-simple network namespace handling. NsHandles can be retrieved and set. Note that the current namespace is thread local so actions that set and reset namespaces should use LockOSThread to make sure the namespace doesn't change due to a goroutine switch. It is best to close NsHandles when you are done with them. This can be accomplished via a `defer ns.Close()` on the handle. Changing namespaces requires elevated privileges, so in most cases this code needs to be run as root.

Index

Variables

var (
	ErrNotImplemented = errors.New("not implemented")
)

Functions

func DeleteNamed

func DeleteNamed(name string) error

func Set

func Set(ns NsHandle) (err error)

func Setns

func Setns(ns NsHandle, nstype int) (err error)

Types

type NsHandle

type NsHandle int

NsHandle is a handle to a network namespace. It can be cast directly to an int and used as a file descriptor.

func Get

func Get() (NsHandle, error)

func GetFromDocker

func GetFromDocker(id string) (NsHandle, error)

func GetFromName

func GetFromName(name string) (NsHandle, error)

func GetFromPath

func GetFromPath(path string) (NsHandle, error)

func GetFromPid

func GetFromPid(pid int) (NsHandle, error)

func GetFromThread

func GetFromThread(pid, tid int) (NsHandle, error)

func New

func New() (ns NsHandle, err error)

func NewNamed

func NewNamed(name string) (NsHandle, error)

func None

func None() NsHandle

None gets an empty (closed) NsHandle.

func (*NsHandle) Close

func (ns *NsHandle) Close() error

Close closes the NsHandle and resets its file descriptor to -1. It is not safe to use an NsHandle after Close() is called.

func (NsHandle) Equal

func (ns NsHandle) Equal(other NsHandle) bool

Equal determines if two network handles refer to the same network namespace. This is done by comparing the device and inode that the file descriptors point to.

func (NsHandle) IsOpen

func (ns NsHandle) IsOpen() bool

IsOpen returns true if Close() has not been called.

func (NsHandle) String

func (ns NsHandle) String() string

String shows the file descriptor number and its dev and inode.

func (NsHandle) UniqueId

func (ns NsHandle) UniqueId() string

UniqueId returns a string which uniquely identifies the namespace associated with the network handle.

Source Files

netns.go netns_unspecified.go

Version
v0.0.1
Published
Nov 2, 2022
Platform
js/wasm
Imports
3 packages
Last checked
now

Tools for package owners.