networking

package
v0.0.0-...-e82d903 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentNetns = ""

CurrentNetns can be passed to L3Segment.AddHost to indicate that the host lives in the current network namespace (eg. where dockerd runs).

Variables

This section is empty.

Functions

func SetFilterForwardPolicies

func SetFilterForwardPolicies(t *testing.T, policy string)

SetFilterForwardPolicies sets the default policy for the FORWARD chain in the filter tables for both IPv4 and IPv6. The original policy is restored using t.Cleanup().

There's only one filter-FORWARD policy, so this won't behave well if used by tests running in parallel in a single network namespace that expect different behaviour.

Types

type Host

type Host struct {
	Name  string
	Iface string // Iface is the interface name in the host network namespace.
	// contains filtered or unexported fields
}

func (Host) Destroy

func (h Host) Destroy(t *testing.T)

func (Host) Do

func (h Host) Do(t *testing.T, fn func())

Do run the provided function in the host's network namespace.

func (Host) MustRun

func (h Host) MustRun(t *testing.T, cmd string, args ...string) string

MustRun executes the provided command in the host's network namespace and returns its combined stdout/stderr, failing the test if the command returns an error.

func (Host) Run

func (h Host) Run(t *testing.T, cmd string, args ...string) (string, error)

Run executes the provided command in the host's network namespace, returns its combined stdout/stderr, and error.

type L3Segment

type L3Segment struct {
	Hosts map[string]Host
	// contains filtered or unexported fields
}

L3Segment simulates a switched, dual-stack capable network that interconnects multiple hosts running in their own network namespace.

func NewL3Segment

func NewL3Segment(t *testing.T, nsName string, addrs ...netip.Prefix) *L3Segment

NewL3Segment creates a new L3Segment. The bridge interface interconnecting all the hosts is created in a new network namespace named nsName and it's assigned one or more IP addresses. Those need to be unmasked netip.Prefix.

func (*L3Segment) AddHost

func (l3 *L3Segment) AddHost(t *testing.T, hostname, nsName, ifname string, addrs ...netip.Prefix)

func (*L3Segment) Destroy

func (l3 *L3Segment) Destroy(t *testing.T)

Jump to

Keyboard shortcuts

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