Example for Implementing a Custom Netlink Family in Userland (C & Rust) + Linux Kernel Module for IPC Using Generic Netlink
Netlink is one of the nicer interfaces to communicate between userland and Linux kernel (IPC), but it’s still quite hard/complex, tho. For an uni project I had to figure it out how to communicate between userland and a self written Linux kernel module using the generic part of the netlink protocol. Because it was quite tough, I want to share my findings with the open source world.
I chosed Rust as the language for the userland and “neli” as library. All my code can be found on Github. I recommend directly visiting Github for all the latest comments and code. The repo also includes two C components for comparision. One C component uses
libnl whereas the other uses raw sockets without any library. All the code is well and intensively documented, also a few examples for changes you could make are given. My tutorial includes Netlink validation (Kernel), error responses (from Kernel), and regular IPC (Kernel, userland [Rust], userland [Pure C], userland [C with libnl]).
This repository on Github: https://github.com/phip1611/generic-netlink-user-kernel-rust/