The kernel provides the base infrastructure for netlink, including APIs and data structures; all the required ones are exported and thus available to you as a module author. We use several of them; the steps to program our kernel netlink component – our kernel module – are outlined here:
- Just as with the user space app, the first thing we must do is get ourselves a netlink socket. The kernel API is netlink_kernel_create(), and its signature is as follows:
struct sock * netlink_kernel_create(struct net *, int , struct netlink_kernel_cfg *);
The first parameter is a generic network structure; we pass the kernel's existing and valid init_net structure here. The second parameter is the protocol number (unit) to use; we shall specify the same number (31) as we did for the user space app. The third parameter is a pointer to an (optional) netlink configuration structure; here, we only set the...