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
- func DeleteNamed(name string) error
- func Set(ns NsHandle) (err error)
- func Setns(ns NsHandle, nstype int) (err error)
- type NsHandle
- func Get() (NsHandle, error)
- func GetFromDocker(id string) (NsHandle, error)
- func GetFromName(name string) (NsHandle, error)
- func GetFromPath(path string) (NsHandle, error)
- func GetFromPid(pid int) (NsHandle, error)
- func GetFromThread(pid, tid int) (NsHandle, error)
- func New() (ns NsHandle, err error)
- func NewNamed(name string) (NsHandle, error)
- func None() NsHandle
- func (ns *NsHandle) Close() error
- func (ns NsHandle) Equal(_ NsHandle) bool
- func (ns NsHandle) IsOpen() bool
- func (ns NsHandle) String() string
- func (ns NsHandle) UniqueId() string
Variables ¶
Functions ¶
func DeleteNamed ¶
func Set ¶
func Setns ¶
Setns sets namespace using golang.org/x/sys/unix.Setns on Linux. It is not implemented on other platforms.
Deprecated: Use golang.org/x/sys/unix.Setns instead.
Types ¶
type NsHandle ¶
type NsHandle int
NsHandle is a handle to a network namespace. It can only be used on Linux, but provides stub methods on other platforms.
func Get ¶
func GetFromDocker ¶
func GetFromName ¶
func GetFromPath ¶
func GetFromPid ¶
func GetFromThread ¶
func New ¶
func NewNamed ¶
func None ¶
func None() NsHandle
None gets an empty (closed) NsHandle.
func (*NsHandle) Close ¶
Close closes the NsHandle and resets its file descriptor to -1. It is only implemented on Linux.
func (NsHandle) Equal ¶
Equal determines if two network handles refer to the same network namespace. It is only implemented on Linux.
func (NsHandle) IsOpen ¶
IsOpen returns true if Close() has not been called. It is only implemented on Linux and always returns false on other platforms.
func (NsHandle) String ¶
String shows the file descriptor number and its dev and inode. It is only implemented on Linux, and returns "NS(none)" on other platforms.
func (NsHandle) UniqueId ¶
UniqueId returns a string which uniquely identifies the namespace associated with the network handle. It is only implemented on Linux, and returns "NS(none)" on other platforms.
Source Files ¶
doc.go netns_others.go nshandle_others.go
- Version
- v0.0.2
- Published
- Jan 13, 2023
- Platform
- js/wasm
- Imports
- 1 packages
- Last checked
- now –
Tools for package owners.