Module eco.genl
Generic Netlink helpers.
This module provides convenience helpers for working with Generic Netlink (NETLINK_GENERIC) via eco.nl.
It can query the kernel controller (nlctrl) to resolve:
- a family name to numeric family id
- multicast group name to group id
Exported constants include:
GENL_ID_CTRLCTRL_CMD_*andCTRL_ATTR_*GENLMSGHDR_SIZE
Usage:
local genl = require 'eco.genl' local info, err = genl.get_family_byname('nlctrl') assert(info, err) print(info.name, info.id)
Functions
| get_family_byid (id) | Query Generic Netlink family info by numeric id. |
| get_family_byname (name) | Query Generic Netlink family info by family name. |
| get_family_id (name) | Get numeric family id by family name. |
| get_group_id (family, group) | Get multicast group id for a family/group name pair. |
| genlmsghdr (t) | Build a struct genlmsghdr. |
| parse_genlmsghdr (msg) | Parse a struct genlmsghdr from a netlink message parser. |
Tables
| family | Generic netlink family info. |
Functions
- get_family_byid (id)
-
Query Generic Netlink family info by numeric id.
Results are cached in-process.
Parameters:
- id int Family id.
Returns:
-
family
info
Or
- nil On failure.
- string Error message.
- get_family_byname (name)
-
Query Generic Netlink family info by family name.
Results are cached in-process.
Parameters:
- name string Family name.
Returns:
-
family
info
Or
- nil On failure.
- string Error message.
- get_family_id (name)
-
Get numeric family id by family name.
Parameters:
- name string Family name.
Returns:
-
int
id
Or
- nil On failure.
- string Error message.
- get_group_id (family, group)
-
Get multicast group id for a family/group name pair.
Parameters:
Returns:
-
int or nil
id Group id (or
nilif not found).Or
- nil On failure.
- string Error message.
- genlmsghdr (t)
-
Build a
struct genlmsghdr.Returns a binary string containing the packed C structure.
Parameters:
- t
table
Table fields:
cmd(int): generic netlink command.version(int, optional): defaults to 1.
Returns:
-
string
Packed
struct genlmsghdr. - t
table
- parse_genlmsghdr (msg)
-
Parse a
struct genlmsghdrfrom a netlink message parser.The parser must currently point at a Generic Netlink message (i.e. a netlink message with
nlmsg_type >= NLMSG_MIN_TYPE).Parameters:
- msg nlmsg_ker Netlink message parser returned by nl.nlmsg_ker.
Returns:
-
table
hdr Header table with fields:
cmd,version.Or
- nil On failure.
- string Error message.
Tables
- family
-
Generic netlink family info.
Returned by get_family_byid and get_family_byname.
Fields:
- name string Family name.
- id int Numeric family id.
- version int Family version.
- hdrsize int Header size.
- maxattr int Max attribute id.
- groups table Map: group name (string) -> group id (int).