Page MenuHomeFreeBSD

netlink: add netlink KPI to the kernel by default.
ClosedPublic

Authored by melifaro on Mar 25 2023, 6:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 7 2024, 9:47 PM
Unknown Object (File)
Mar 7 2024, 9:43 PM
Unknown Object (File)
Mar 7 2024, 9:43 PM
Unknown Object (File)
Mar 7 2024, 9:42 PM
Unknown Object (File)
Mar 7 2024, 9:30 PM
Unknown Object (File)
Feb 16 2024, 6:17 PM
Unknown Object (File)
Jan 24 2024, 11:27 PM
Unknown Object (File)
Jan 4 2024, 9:23 PM
Subscribers

Details

Summary

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

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
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.

sys/netlink/netlink_glue.c
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?