Documentation ¶
Overview ¶
Package nlmsg provides helpers to parse and construct netlink messages.
Index ¶
- type AttrsView
- type BytesView
- type Message
- func (m *Message) Finalize() []byte
- func (m *Message) GetData(msg marshal.Marshallable) (AttrsView, bool)
- func (m *Message) Header() linux.NetlinkMessageHeader
- func (m *Message) Put(v marshal.Marshallable)
- func (m *Message) PutAttr(atype uint16, v marshal.Marshallable)
- func (m *Message) PutAttrString(atype uint16, s string)
- type MessageSet
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) 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 ¶
Extract removes the first n bytes from v and returns it. If n is out of bounds, it returns false.
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 ¶
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 ¶
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 ¶
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.