11

I am planning to use netlink for communication between two userland processes. Part of the reason being so picky about netlink is - Most of the processing for one of the process would eventually go in kernel space and netlink based communication can be used as it is (hopefully).

The approach I am taking is - define a new Generic Netlink family (I will have to write a kernel module just to support that family - as it appears so at the moment). That is fine, I was looking at some example code, where kernel was essentially only routing messages between different processes and not really doing any work - the actual population of those messages is handled by the processes.

My question is - is anyone using netlink in the similar manner in any of the projects? Also - does the above approach makes sense?

I read about a proposal about netlink based DBUS. But haven't found any implementation of that. That comes closest to my requirements.

Thanks.

gabhijit
  • 3,345
  • 2
  • 23
  • 36

1 Answers1

6

What you are looking for is NETLINK_USERSOCK if you want to communicate between userspace processes.

Netlink documentation is awfully scarce unfortunately. This might help a bit: Who can give me the latest netlink programming samples?

Just make sure nl_pid is non-zero and matches what userspace peer is bind'ed to and that you're sending a unicast.

Community
  • 1
  • 1
domen
  • 1,819
  • 12
  • 19
  • Ahh thanks - how did I overlook something this obvious! Yes - I did something very similar to one of the examples mentioned. Unfortunately I don't want to use libnl (reason being in my application, I want to avoid external dependencies as much as possible), so I'd to do some heavy lifting to get the thing working. – gabhijit Oct 08 '14 at 18:13
  • In this case, you're talking about something that's unlikely to NOT be on the system unless you're talking an embedded target. Pretty much all distributions provide it. Having said this, you should be able to use libnl as a crib-sheet to do things the "right" way within your "heavy lifting" if you still don't want to use libnl. – Svartalf Dec 08 '14 at 17:27
  • @Svartalf That's precisely what I did. Thanks. – gabhijit Dec 13 '14 at 04:08
  • NETLINK_USERSOCK seems to work in: `socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK); ` This saved me when trying to test/simulate kernel/user interaction in the user-space. It worked without the need for libnl. Thanks! – hesham_EE Dec 03 '15 at 17:39