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