GENETLINK(4)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1, nixpkgs unstable

okay so this is from the Kernel Interfaces Manual (section 4, iykyk), and it's literally all about genetlink β€” Generic Netlink. buckle up, it's cuter than it sounds πŸŽ€


✨ NAME ✨

genetlink β€” Generic Netlink. that's it, that's the vibe πŸ¦‹


✨ SYNOPSIS ✨

#include <netlink/netlink.h>
#include <netlink/netlink_generic.h>

int
socket(AF_NETLINK, SOCK_DGRAM, NETLINK_GENERIC);

✨ DESCRIPTION ✨

okay so NETLINK_GENERIC is a "container" family β€” think of it as the group chat that other families get added to πŸ‘‘. it's used for dynamic registration of other families that belong to all the various subsystems.

here's the tea πŸ“: those subsystems hand over a string family name when they register, and in exchange they get a dynamically-allocated family id. then applications use those allocated family identifiers to actually get at the functions that subsystem provides over netlink. and yes, there are standard methods for turning a string family name into a family id β€” no cap. a similar mechanism works for the notification groups that those families provide, too ✨.

all generic netlink families share a common header:

struct genlmsghdr {
        uint8_t         cmd;            /* command within the family */
        uint8_t         version;        /* ABI version for the cmd */
        uint16_t        reserved;       /* reserved: set to 0 */
};

the family id is encoded in the nlmsg_type of the base netlink header. the cmd field is the command identifier within the family, and the version field is the command version. slay πŸ’…


✨ METHODS ✨

the generic Netlink framework provides the base family, GENL_ID_CTRL ("nlctrl"), with a fixed family id. this family is literally the one you use to list the details of all the registered families 🫢.

the framework supports the following messages:

🌸 CTRL_CMD_GETFAMILY 🌸

fetches a single family β€” or all registered families, depending on the NLM_F_DUMP flag. each family gets reported as a CTRL_CMD_NEWFAMILY message ⭐.

the kernel recognises these filters:

      CTRL_ATTR_FAMILY_ID     (uint16_t) current family id assigned by kernel
      CTRL_ATTR_FAMILY_NAME   (string) family name

🌸 TLVs 🌸

  • CTRL_ATTR_FAMILY_ID β€” (uint16_t) the dynamically-assigned family identifier.
  • CTRL_ATTR_FAMILY_NAME β€” (string) the family name.
  • CTRL_ATTR_HDRSIZE β€” (uint32_t) family mandatory header size (typically 0).
  • CTRL_ATTR_MAXATTR β€” (uint32_t) maximum attribute number that's valid for the family.
  • CTRL_ATTR_OPS β€” (nested) the list of operations supported by the family. the attribute consists of a list of nested TLVs, with attribute values monotonically incremented, starting from 0. each TLV contains the following attributes:
    • CTRL_ATTR_OP_ID β€” operation (message) number.
    • CTRL_ATTR_OP_FLAGS β€” operation flags. the following flags are supported:
      • GENL_ADMIN_PERM β€” requires elevated permissions
      • GENL_CMD_CAP_DO β€” operation is a modification request
      • GENL_CMD_CAP_DUMP β€” operation is a get/dump request
  • CTRL_ATTR_MCAST_GROUPS β€” (nested) the list of notification groups supported by the family. this attribute consists of a list of nested TLVs, with attribute values monotonically incremented, starting from 0. each TLV contains the following attributes:
    • CTRL_ATTR_MCAST_GRP_ID β€” group id that can be used in NETLINK_ADD_MEMBERSHIP setsockopt(2).
    • CTRL_ATTR_MCAST_GRP_NAME β€” (string) human-readable name of the group.

🌸 Groups 🌸

the following groups are defined:

      "notify"        Notifies on family registrations/removal.

so like… "notify" tells you when families get registered or removed. main character energy honestly πŸ’€


✨ SEE ALSO ✨


✨ HISTORY ✨

the NETLINK_GENERIC protocol family appeared in FreeBSD 13.2 🌈.


✨ AUTHORS ✨

the netlink was implemented by Alexander Chernikov <melifaro@FreeBSD.org>. it was derived from the Google Summer of Code 2021 project by Ng Peng Nam Sean. iconic behavior honestly πŸ‘‘


ngl bestie, if you made it this far you deserve a little treat πŸ“ β€” go read netlink(4) next, it's giving required reading 🧚

and that's the whole page, periodt πŸ’œ β€” this cutie came to you from Debian, dated November 1, 2022. bye bestie, go write some netlink code πŸ¦‹βœ¨

πŸ“¦ where this page comes from