nlmsg

package
v0.0.0-...-74f2288 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0, MIT Imports: 7 Imported by: 6

Documentation

Overview

Package nlmsg provides helpers to parse and construct netlink messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttrsView

type AttrsView []byte

AttrsView is a view into the attributes portion of a netlink message.

func (AttrsView) Empty

func (v AttrsView) Empty() bool

Empty returns whether there is no attribute left in v.

func (AttrsView) Parse

func (v AttrsView) Parse() (map[uint16]BytesView, bool)

Parse parses netlink attributes.

func (AttrsView) ParseFirst

func (v AttrsView) ParseFirst() (hdr linux.NetlinkAttrHeader, value []byte, rest AttrsView, ok bool)

ParseFirst parses first netlink attribute at the beginning of v.

type BytesView

type BytesView []byte

BytesView supports extracting data from a byte slice with bounds checking.

func (*BytesView) Extract

func (v *BytesView) Extract(n int) ([]byte, bool)

Extract removes the first n bytes from v and returns it. If n is out of bounds, it returns false.

func (*BytesView) String

func (v *BytesView) String() string

String converts the raw attribute value to string.

func (*BytesView) Uint32

func (v *BytesView) Uint32() (uint32, bool)

Uint32 converts the raw attribute value to uint32.

type Message

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

Message contains a complete serialized netlink message.

func NewMessage

func NewMessage(hdr linux.NetlinkMessageHeader) *Message

NewMessage creates a new Message containing the passed header.

The header length will be updated by Finalize.

func ParseMessage

func ParseMessage(buf []byte) (msg *Message, rest []byte, ok bool)

ParseMessage parses the first message seen at buf, returning the rest of the buffer. If message is malformed, ok of false is returned. For last message, padding check is loose, if there isn't enough padding, whole buf is consumed and ok is set to true.

func (*Message) Finalize

func (m *Message) Finalize() []byte

Finalize returns the []byte containing the entire message, with the total length set in the message header. The Message must not be modified after calling Finalize.

func (*Message) GetData

func (m *Message) GetData(msg marshal.Marshallable) (AttrsView, bool)

GetData unmarshals the payload message header from this netlink message, and returns the attributes portion.

func (*Message) Header

func (m *Message) Header() linux.NetlinkMessageHeader

Header returns the header of this message.

func (*Message) Put

func (m *Message) Put(v marshal.Marshallable)

Put serializes v into the message.

func (*Message) PutAttr

func (m *Message) PutAttr(atype uint16, v marshal.Marshallable)

PutAttr adds v to the message as a netlink attribute.

Preconditions: The serialized attribute (linux.NetlinkAttrHeaderSize + v.SizeBytes()) fits in math.MaxUint16 bytes.

func (*Message) PutAttrString

func (m *Message) PutAttrString(atype uint16, s string)

PutAttrString adds s to the message as a netlink attribute.

type MessageSet

type MessageSet struct {
	// Multi indicates that this a multi-part message, to be terminated by
	// NLMSG_DONE. NLMSG_DONE is sent even if the set contains only one
	// Message.
	//
	// If Multi is set, all added messages will have NLM_F_MULTI set.
	Multi bool

	// PortID is the destination port for all messages.
	PortID int32

	// Seq is the sequence counter for all messages in the set.
	Seq uint32

	// Messages contains the messages in the set.
	Messages []*Message
}

MessageSet contains a series of netlink messages.

func NewMessageSet

func NewMessageSet(portID int32, seq uint32) *MessageSet

NewMessageSet creates a new MessageSet.

portID is the destination port to set as PortID in all messages.

seq is the sequence counter to set as seq in all messages in the set.

func (*MessageSet) AddMessage

func (ms *MessageSet) AddMessage(hdr linux.NetlinkMessageHeader) *Message

AddMessage adds a new message to the set and returns it for further additions.

The passed header will have Seq, PortID and the multi flag set automatically.

Jump to

Keyboard shortcuts

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