Place the knetlink.c
and Makefile
into a folder. Then build the module using your host (in my case Ubuntu)
KERNEL_SRC=/usr/src/linux-headers-$(uname -r) make
Run this command to build the executable
gcc netlinkuser.c -o netlink
Use this command on a separate console to trace the dmesg
sudo dmesg -wH
Now load the kernel module on your host
sudo insmod knetlink.ko
You can use any docker image, but I'm using the image that I use for building Yocto images. Run this command to execute the user-space netlink client inside docker.
docker run -it --rm --privileged --net=host --cap-add=ALL -v $(pwd):/docker -w /docker allwinner-yocto-image /bin/bash -c "./netlink"
This should output:
Sending message to kernel
Waiting for message from kernel
Received message payload: Hello from kernel