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_CTRL
  • CTRL_CMD_* and CTRL_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

  1. nil On failure.
  2. string Error message.
get_family_byname (name)
Query Generic Netlink family info by family name.

Results are cached in-process.

Parameters:

Returns:

    family info

Or

  1. nil On failure.
  2. string Error message.
get_family_id (name)
Get numeric family id by family name.

Parameters:

Returns:

    int id

Or

  1. nil On failure.
  2. string Error message.
get_group_id (family, group)
Get multicast group id for a family/group name pair.

Parameters:

  • family string Generic netlink family name.
  • group string Multicast group name.

Returns:

    int or nil id Group id (or nil if not found).

Or

  1. nil On failure.
  2. 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.
parse_genlmsghdr (msg)
Parse a struct genlmsghdr from 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

  1. nil On failure.
  2. 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).
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22