netlink

package
v0.0.0-...-7ae270e Latest Latest
Warning

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

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

Documentation

Overview

Package netlink provides a Go interface to netlink via the libnl library.

Index

Constants

View Source
const (
	MFRequest  = C.NLM_F_REQUEST
	MFMulti    = C.NLM_F_MULTI
	MFACK      = C.NLM_F_ACK
	MFEcho     = C.NLM_F_ECHO
	MFDumpIntr = C.NLM_F_DUMP_INTR
	MFRoot     = C.NLM_F_ROOT
	MFMatch    = C.NLM_F_MATCH
	MFAtomic   = C.NLM_F_ATOMIC
	MFDump     = C.NLM_F_DUMP
	MFReplace  = C.NLM_F_REPLACE
	MFExcl     = C.NLM_F_EXCL
	MFCreate   = C.NLM_F_CREATE
	MFAppend   = C.NLM_F_APPEND
)

Netlink message flags.

Variables

This section is empty.

Functions

func Family

func Family(name string) (int, error)

Family returns the family identifier for the specified family name.

func SendMessage

func SendMessage(command, family, flags int) error

SendMessage creates and sends a netlink message.

func SendMessageCallback

func SendMessageCallback(command, family, flags int, cb CallbackFunc, arg interface{}) error

SendMessageCallback creates and sends a netlink message. The specified callback function will be called for each message that is received in response.

func SendMessageMarshalled

func SendMessageMarshalled(command, family, flags int, v interface{}) error

SendMessageMarshalled creates a netlink message and marshals the given struct into the message, before sending it.

func SendMessageUnmarshal

func SendMessageUnmarshal(command, family, flags int, v interface{}) error

SendMessageUnmarshal creates and sends a netlink message. All messages received in response will be unmarshalled into the given struct.

Types

type CallbackFunc

type CallbackFunc func(*Message, interface{}) error

CallbackFunc is a netlink message callback function.

type Error

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

Error represents a netlink error.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of a netlink error.

type Marshaler

type Marshaler interface {
	// Bytes returns a byte slice containing the netlink representation of
	// the given type.
	Bytes() []byte
}

Marshaler represents a type that is capable of marshaling itself into its netlink representation.

type Message

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

Message represents a netlink message.

func NewMessage

func NewMessage(command, family, flags int) (*Message, error)

NewMessage returns an initialised netlink message.

func NewMessageFromBytes

func NewMessageFromBytes(nlb []byte) (*Message, error)

NewMessageFromBytes returns a netlink message that is initialised from the given byte slice.

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes returns the byte slice representation of a netlink message.

func (*Message) Free

func (m *Message) Free()

Free frees resources associated with a netlink message.

func (*Message) Marshal

func (m *Message) Marshal(v interface{}) error

Marshal converts the given struct into a netlink message. Each field within the struct is added as netlink data, with structs and pointers to structs being recursively added as nested data.

Supported data types and their netlink mappings are as follows:

uint8:		NLA_U8
uint16:		NLA_U16
uint32:		NLA_U32
uint64:		NLA_U64
string:		NLA_STRING
byte array:	NLA_UNSPEC
struct:		NLA_NESTED
net.IP:		NLA_UNSPEC

Each field must have a `netlink' tag, which can contain the following comma separated options:

attr:x		specify the netlink attribute for this field (required)
network		value will be converted to its network byte order
omitempty	if the field has a zero value it will be omitted
optional	mark the field as being an optional (for unmarshalling)

Other Go data types are unsupported and an error will be returned if one is encountered.

func (*Message) Send

func (m *Message) Send() error

Send sends the netlink message.

func (*Message) SendCallback

func (m *Message) SendCallback(fn CallbackFunc, arg interface{}) error

SendCallback sends the netlink message. The specified callback function will be called for each message that is received in response.

func (*Message) Unmarshal

func (m *Message) Unmarshal(v interface{}) error

Unmarshal parses the netlink message and fills the struct referenced by the given pointer. The supported data types and netlink encodings are the same as for Marshal.

type Unmarshaler

type Unmarshaler interface {
	// SetBytes sets the value of the given type from a byte slice that
	// contains its netlink representation.
	SetBytes([]byte)
}

Unmarshaler represents a type that is capable of unmarshaling itself from its netlink representation.

Jump to

Keyboard shortcuts

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