Lunatik

netlink.messageModule

Netlink wire codec shared by the netlink modules.

Builds nlmsghdr/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. A number value 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, where body holds the bytes after the nlmsghdr (family header and attributes).

Parameters

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 set NLA_F_NESTED appears under type | 0x8000. A nested payload stays a string, which message.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; nil is passed through. (optional)

Returns

    string or nil the decoded string.
u32 ([value])
Decodes a u32 attribute value.

Parameters

  • value string raw attribute payload; nil is passed through. (optional)

Returns

    integer or nil the decoded integer.