Documentation
¶
Overview ¶
Package nlmsg provides helpers to parse and construct netlink messages.
Index ¶
- func HostToNetU16(v uint16) uint16
- func HostToNetU32(v uint32) uint32
- func HostToNetU64(v uint64) uint64
- func NetToHostU16(v uint16) uint16
- func NetToHostU32(v uint32) uint32
- func NetToHostU64(v uint64) uint64
- func PeekHeader(buf []byte) (linux.NetlinkMessageHeader, bool)
- func PutU16(val uint16) marshal.Marshallable
- func PutU32(val uint32) marshal.Marshallable
- func PutU64(val uint64) marshal.Marshallable
- 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)
- func (m *Message) PutNestedAttr(atype uint16, v NestedAttr)
- type MessageSet
- type NestedAttr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HostToNetU16 ¶
HostToNetU16 converts a uint16 in host byte order to network byte order value.
func HostToNetU32 ¶
HostToNetU32 converts a uint32 in host byte order to network byte order value.
func HostToNetU64 ¶
HostToNetU64 converts a uint64 in host byte order to network byte order value.
func NetToHostU16 ¶
NetToHostU16 converts a uint16 in network byte order to host byte order value.
func NetToHostU32 ¶
NetToHostU32 converts a uint32 in network byte order to host byte order value.
func NetToHostU64 ¶
NetToHostU64 converts a uint64 in network byte order to host byte order value.
func PeekHeader ¶
func PeekHeader(buf []byte) (linux.NetlinkMessageHeader, bool)
PeekHeader peeks at the header of the message from the given buffer, leaving the buffer unchanged. If the header is not present, it returns false.
func PutU16 ¶
func PutU16(val uint16) marshal.Marshallable
PutU16 converts a uint16 to network byte order and returns it as a marshal.Marshallable.
func PutU32 ¶
func PutU32(val uint32) marshal.Marshallable
PutU32 converts a uint32 to network byte order and returns it as a marshal.Marshallable.
func PutU64 ¶
func PutU64(val uint64) marshal.Marshallable
PutU64 converts a uint64 to network byte order and returns it as a marshal.Marshallable.
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.
func (*BytesView) Retrieve ¶
Retrieve returns the first n bytes from v, leaving v unchanged. 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.
func (*Message) PutNestedAttr ¶
func (m *Message) PutNestedAttr(atype uint16, v NestedAttr)
PutNestedAttr adds v to the message as a netlink nested 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 // ContainsError indicates that the message set contains at least one error. ContainsError bool }
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.
type NestedAttr ¶
type NestedAttr []byte
NestedAttr represents a nested netlink attribute.
func (*NestedAttr) PutAttr ¶
func (n *NestedAttr) PutAttr(atype uint16, v marshal.Marshallable)
PutAttr adds v to the provided NestedAttr, creating nested attributes.
func (*NestedAttr) PutAttrString ¶
func (n *NestedAttr) PutAttrString(atype uint16, s string)
PutAttrString adds s to the provided NestedAttr, creating nested attributes.