Two kernel modules, each using a netlink socket. How to use them at the same time?

Good day. I would like to create two (almost identical) modules - each module uses a netlink socket and responds to an incoming message from a user space program.

During initialization of the first module, it successfully executes the following command:

netlink kernel create(&init_net, NETLINK_USER, &cfg) 

However, if I run the second module with the same arguments, the same command will cause an error.

I thought this error occurred because the NETLINK_USER value of both modules was the same - 31 - which is why I could not create a second socket connection for the same netlink user. However, if I try the NETLINK_USER value of 32, a kernel error will occur. Any other value is an error.

Please tell me what I need to do to use two kernel modules at the same time?

+8
linux-kernel kernel sockets netlink kernel-module
source share
1 answer

By default, the kernel has 32 network slots. Some of them are used by the system (for example, the audit subsystem). Here you can find information about predefined constants here . As for your question, try using the following:

 // module 1 netlink kernel create(&init_net, MAX_LINKS - 1, &cfg) // module 2 netlink kernel create(&init_net, MAX_LINKS - 2, &cfg) 

MAX_LINKS is the limit for network lines supported by the kernel.

+8
source share

All Articles