Page MenuHomeFreeBSD

netlink: add netlink KPI to the kernel by default.

Authored by melifaro on Mar 25 2023, 6:27 PM.
Referenced Files
Sat, Jun 3, 5:08 PM
Unknown Object (File)
Fri, May 19, 12:01 AM
Unknown Object (File)
Thu, May 18, 11:56 PM
Unknown Object (File)
Thu, May 18, 11:55 PM
Unknown Object (File)
Thu, May 18, 11:55 PM
Unknown Object (File)
Mon, May 15, 5:39 AM
Unknown Object (File)
Sat, May 13, 7:20 AM
Unknown Object (File)
May 3 2023, 5:37 PM



This change employs a different approach than D39047.

Effectibely, it tries to address both the desire for the ability to compile out Netlink and keep the ease of Netlink-dependent module development.
It is understandable that for some embedded use cases, the additional +100KiB+ of space/memory may represent a non-negligible percentage of the kernel size, and it is desirable to permit users to have it optional.
It is also desired not to overcomplicate Netlink interfaces with the loadability concern. Otherwise, adding (optional) Netlink support to some of the loadable modules may become notably harder.

This change proposes the following:

  • Base Netlink KPIs (ability to register the family, parse and/or write a Netlink message) are always present in the kernel. Specifically,
  • Implementation of genetlink family/group registration/removal, some base accessors (netlink_generic_kpi.c, 260 LoC) is compiled in unconditionally.
  • Basic TLV parser functions (netlink_message_parser.c, 507 LoC) are compiled in unconditionally.
  • Glue functions (netlink<>rtsock), malloc/core sysctl definitions (netlink_glue.c, 259 LoC) are compiled in unconditionally.
  • The rest of the KPI _functions_ are defined in the netlink_glue.c, but their implementation calls a pointer to either the stub function or the actual function, depending on whether the module is loaded or not.

This approach allows to have only 1k LoC out of ~3.7k LoC (current sys/netlink implementation) in the kernel, which will not grow further.
It also allows for the generic netlink kernel customers to load successfully without requiring Netlink module and operate correctly once Netlink module is loaded.

Size diff with this approach:

  • kernel.ko (main GENERIC w/o all netlink files, stripped): 28 240 440
  • kernel.ko (main GENERIC w/o option NETLINK, stripped): 28 241 928 (+1.5KiB)
  • netlink.ko (stripped): 105 864

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

Generally I like this approach. I didn't see anything that would add a huge amount of overhead in doing it this way.

2 ↗(On Diff #119457)

This should be BSD-2-Clause. The -FreeBSD variant is obsolete. I have a pass over the tree I've been putting off until post 13.2...

This revision is now accepted and ready to land.Mar 26 2023, 9:14 PM

The general approach seems fine to me.

Are there any concerns related to the transition at the time the module is loaded / unloaded?