Example for Implementing a Custom Netlink Family in Userland (C & Rust) + Linux Kernel Module for IPC Using Generic Netlink

Published by Philipp Schuster on

Netlink code snippet (kernel code)

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/

Netlink code snippet (kernel code)

Netlink code snippet (kernel code)

Philipp Schuster

Hi, I'm Philipp and interested in Computer Science. I especially like low level development, making ugly things nice, and de-mystify "low level magic".


Leave a Reply

Your email address will not be published. Required fields are marked *