netns

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package netns supports running unit tests in separated transient network namespaces.

Usage

Just call [EnterTransientNetns] and defer its return value.

  import "github.com/notwork/netns"

  It("tests something inside a temporary network namespace", func() {
	defer netns.EnterTransientNetns()() // !!! double ()
	// ...
  })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current added in v1.3.0

func Current() int

Current returns a file descriptor referencing the current network namespace. In particular, the current network namespace of the OS-level thread of the caller's Go routine (which should ideally be thread-locked).

func CurrentIno added in v1.3.0

func CurrentIno() uint64

CurrentIno returns the identification/inode number of the network namespace for the current thread.

func EnterTransient added in v1.3.0

func EnterTransient() func()

EnterTransient creates and enters a new (and isolated) network namespace, returning a function that needs to be defer'ed in order to correctly switch the calling go routine and its locked OS-level thread back when the caller itself returns.

In case the caller cannot be switched back correctly, the defer'ed clean up will panic with an error description.

func Execute added in v1.3.0

func Execute(netnsfd int, fn func())

Execute a function fn in the specified network namespace, referenced by the open file descriptor netnsfd.

func Ino added in v1.3.0

func Ino[R ~int | ~string](netns R) uint64

Ino returns the identification/inode number of the passed network namespace.

func NewNetlinkHandle added in v1.3.0

func NewNetlinkHandle(netnsfd int) *netlink.Handle

NewNetlinkHandle returns a netlink handle connected to the network namespace referenced by the specified fd (file descriptor). For instance, this file descriptor might be one returned by NewTransient or Current.

func NewTransient added in v1.3.0

func NewTransient() int

NewTransient creates a new network namespace, but doesn't enter it. Instead, it returns a file descriptor referencing the new network namespace. It additionally schedules a Ginkgo deferred cleanup in order to close the fd referencing the newly created network namespace.

Types

This section is empty.

Jump to

Keyboard shortcuts

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