Two kernel modules, each uses netlink socket. How to use them both at the same time?
Asked Answered
S

1

10

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?

Swats answered 12/9, 2013 at 14:32 Comment(2)
Use different netlinks IDs.Suannesuarez
@IlyaMatveychikov Different netlink IDs - different NETLINK_USER values? What values are allowed for usage?Swats
S
10

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.

Suannesuarez answered 4/10, 2013 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.