Deprecated: use golang.org/x/sys/unix pkg instead.
const ( CLONE_NEWUTS = unix.CLONE_NEWUTS /* New utsname group? */ CLONE_NEWIPC = unix.CLONE_NEWIPC /* New ipcs */ CLONE_NEWUSER = unix.CLONE_NEWUSER /* New user namespace */ CLONE_NEWPID = unix.CLONE_NEWPID /* New pid namespace */ CLONE_NEWNET = unix.CLONE_NEWNET /* New network namespace */ CLONE_IO = unix.CLONE_IO /* Get io context */ )
func DeleteNamed(name string) error
DeleteNamed deletes a named network namespace
func Set(ns NsHandle) (err error)
Set sets the current network namespace to the namespace represented by NsHandle.
func Setns(ns NsHandle, nstype int) (err error)
Setns sets namespace using golang.org/x/sys/unix.Setns.
Deprecated: Use golang.org/x/sys/unix.Setns instead.
NsHandle is a handle to a network namespace. It can be cast directly to an int and used as a file descriptor.
type NsHandle int
func Get() (NsHandle, error)
Get gets a handle to the current threads network namespace.
func GetFromDocker(id string) (NsHandle, error)
GetFromDocker gets a handle to the network namespace of a docker container. Id is prefixed matched against the running docker containers, so a short identifier can be used as long as it isn't ambiguous.
func GetFromName(name string) (NsHandle, error)
GetFromName gets a handle to a named network namespace such as one created by `ip netns add`.
func GetFromPath(path string) (NsHandle, error)
GetFromPath gets a handle to a network namespace identified by the path
func GetFromPid(pid int) (NsHandle, error)
GetFromPid gets a handle to the network namespace of a given pid.
func GetFromThread(pid, tid int) (NsHandle, error)
GetFromThread gets a handle to the network namespace of a given pid and tid.
func New() (ns NsHandle, err error)
New creates a new network namespace, sets it as current and returns a handle to it.
func NewNamed(name string) (NsHandle, error)
NewNamed creates a new named network namespace, sets it as current, and returns a handle to it
func None() NsHandle
None gets an empty (closed) NsHandle.
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 (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 (ns NsHandle) IsOpen() bool
IsOpen returns true if Close() has not been called.
func (ns NsHandle) String() string
String shows the file descriptor number and its dev and inode.
func (ns NsHandle) UniqueId() string
UniqueId returns a string which uniquely identifies the namespace associated with the network handle.