Reputation: 1026
Good day. I would like to create two (almost same) modules - each module uses netlink socket and replies to the incoming message from userspace program.
During the initialization of the first module, it executes the following command successfully:
netlink kernel create(&init_net, NETLINK_USER, &cfg)
However, if I launch a second module, with the same arguments, the same command will cause an error.
I thought that this error happens because NETLINK_USER value of both modules was the same - 31 - that is why I could not have created the second socket connection for the same netlink user. However, if I try NETLINK_USER value as 32, there would be a kernel error. Any other value - error as well.
Please tell me, what I need to do, in order to use two kernel modules at the same time?
Upvotes: 10
Views: 1086
Reputation: 4024
There are 32 netlink slots available on the kernel by default. Some of them are used by the system (for example, by the audit subsystem). You can find the details about predefined constants here. As for your question, try to use 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 here is the limit of netlink slots that kernel supports.
Upvotes: 10