nftest

package
v0.0.0-...-ec9672c Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package nftest contains utility functions for nftables testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupSystemConn

func CleanupSystemConn(t *testing.T, newNS netns.NsHandle)

func Diff

func Diff(got []netlink.Message, want [][]byte) string

Diff returns the first difference between the specified netlink messages and the expected netlink message payloads.

func MatchRulesetBytes

func MatchRulesetBytes(t *testing.T, fillRuleset func(c *nftables.Conn), want [][]byte)

MatchRulesetBytes is a test helper that ensures the fillRuleset modifications correspond to the provided want netlink message payloads

func OpenSystemConn

func OpenSystemConn(t *testing.T, enableSysTests bool) (*nftables.Conn, netns.NsHandle)

OpenSystemConn returns a netlink connection that tests against the running kernel in a separate network namespace. nftest.CleanupSystemConn() must be called from a defer to cleanup created network namespace.

Types

type Recorder

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

Recorder provides an nftables connection that does not send to the Linux kernel but instead records netlink messages into the recorder. The recorded requests can later be obtained using Requests and compared using Diff.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns a ready-to-use Recorder.

func (*Recorder) Conn

func (r *Recorder) Conn() (*nftables.Conn, error)

Conn opens an nftables connection that records netlink messages into the Recorder.

func (*Recorder) Requests

func (r *Recorder) Requests() []netlink.Message

Requests returns the recorded netlink messages (typically nftables requests).

Jump to

Keyboard shortcuts

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