netns

package
v1.16.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 14

Documentation

Overview

Package netns contains various utility functions to work with network namespaces

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNetNSCookie

func GetNetNSCookie() (uint64, error)

GetNetNSCookie tries to retrieve the cookie of the host netns.

Types

type NetNS added in v1.16.0

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

func Current added in v1.16.0

func Current() (*NetNS, error)

Current returns a handle to the network namespace of the calling goroutine's underlying OS thread.

func New added in v1.16.0

func New() (*NetNS, error)

New creates a network namespace and returns a handle to it.

The namespace created by this call is not pinned and will be closed when the last process in the namespace terminates, or when the handle is either Close()d explicitly or garbage collected.

Not calling Close() is an error.

func OpenPinned added in v1.16.0

func OpenPinned(path string) (*NetNS, error)

OpenPinned opens a handle to the existing, pinned network namespace at the given path. Useful for running code within a netns managed by another process that pinned a network namespace to an nsfs.

Not calling Close() is an error.

func (*NetNS) Close added in v1.16.0

func (h *NetNS) Close() error

Close closes the handle to the network namespace. This does not necessarily mean destroying the network namespace itself, which only happens when all references to it are gone and all of its processes have been terminated.

func (*NetNS) Do added in v1.16.0

func (h *NetNS) Do(f func() error) error

Do runs the provided func in the netns without changing the calling thread's netns.

The code in f and any code called by f must NOT call runtime.LockOSThread, as this could leave the goroutine created by Do permanently pinned to an OS thread.

func (*NetNS) FD added in v1.16.0

func (h *NetNS) FD() int

FD returns the underlying file descriptor representing the netns handle.

Jump to

Keyboard shortcuts

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