genltest

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package genltest provides utilities for generic netlink testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(fn Func) *genetlink.Conn

Dial sets up a genetlink.Conn for testing using the specified Func. All requests sent from the connection will be passed to the Func. The connection should be closed as usual when it is no longer needed.

func Error

func Error(number int) error

Error returns a netlink error to the caller with the specified error number.

Types

type Func

type Func func(greq genetlink.Message, nreq netlink.Message) ([]genetlink.Message, error)

A Func is a function that can be used to test genetlink.Conn interactions. The function can choose to return zero or more generic netlink messages, or an error if needed.

For a netlink request/response interaction, the requests greq and nreq are populated by genetlink.Conn.Send and passed to the function. greq is created from the body of nreq.

For multicast interactions, both greq and nreq are empty when passed to the function when genetlink.Conn.Receive is called.

If a Func returns an error, the error will be returned as-is to the caller. If no messages and io.EOF are returned, no messages and no error will be returned to the caller, simulating a multi-part message with no data.

func CheckRequest

func CheckRequest(family uint16, command uint8, flags netlink.HeaderFlags, fn Func) Func

CheckRequest returns a Func that verifies that an incoming request message has the specified generic netlink family, command, and netlink header flags, and then passes the request through to fn.

If family, command, or flags are set to the zero value, the specific check for that value will be skipped for request message.

func ServeFamily

func ServeFamily(f genetlink.Family, fn Func) Func

ServeFamily returns a Func that intercepts "get family" commands to the generic netlink controller, verifies that the requested family name matches the provided one, and then returns family information specified by f.

Requests which are not related to requesting a family are passed through to fn.

ServeFamily is primarily useful in tests for packages which interact with a specific generic netlink family.

Jump to

Keyboard shortcuts

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