netlink.messageModule
Netlink wire codec shared by the netlink modules.
Buildsnlmsghdr/nlattr
structures via the struct codec and parses received buffers into Lua
tables.
Functions
| attrs (attrs) | Serializes a {[type] = value} table into netlink attributes. |
| encode (mtype, flags, seq, payload) | Builds a complete netlink message. |
| parse (buf) | Parses a buffer into a list of {type, flags, body} messages, where body
holds the bytes after the nlmsghdr (family header and attributes). |
| parseattrs (body[, pos=1]) | Parses the netlink attributes of a message body into a {[type] = value} table. |
| str ([value]) | Decodes a NUL-terminated string attribute value. |
| u32 ([value]) | Decodes a u32 attribute value. |
Functions in detail
- attrs (attrs)
-
Serializes a
{[type] = value}table into netlink attributes. Anumbervalue is packed as a u32; a string is used verbatim.Parameters
- attrs table attribute table.
Returns
-
string
the serialized attributes.
- encode (mtype, flags, seq, payload)
-
Builds a complete netlink message.
Parameters
- mtype integer message type.
- flags integer NLM_F_* flags.
- seq integer sequence number.
- payload string family header and/or attributes.
Returns
-
string
the serialized message.
- parse (buf)
-
Parses a buffer into a list of
{type, flags, body}messages, wherebodyholds the bytes after thenlmsghdr(family header and attributes).Parameters
- buf string received buffer.
Returns
-
table
list of messages.
- parseattrs (body[, pos=1])
-
Parses the netlink attributes of a message body into a
{[type] = value}table. A key is the raw attribute type, flag bits included: a nested attribute whose sender setNLA_F_NESTEDappears undertype | 0x8000. A nested payload stays a string, whichmessage.parseattrs(value)parses in turn.Parameters
- body string message body.
- pos integer 1-based position of the first attribute. (default 1)
Returns
-
table
the parsed attributes.
- str ([value])
-
Decodes a NUL-terminated string attribute value.
Parameters
- value
string
raw attribute payload;
nilis passed through. (optional)
Returns
-
string or nil
the decoded string.
- value
string
raw attribute payload;
- u32 ([value])
-
Decodes a u32 attribute value.
Parameters
- value
string
raw attribute payload;
nilis passed through. (optional)
Returns
-
integer or nil
the decoded integer.
- value
string
raw attribute payload;