[LinuxPPS] Multiple netlink sockets
Rodolfo Giometti
giometti at linux.it
Mon Oct 23 18:00:21 CEST 2006
Hello,
I'd like to use several netlink sockets in one process.
Into "man 7 netlink" I read:
nl_pid is the unicast address of netlink socket. It's always 0 if the
destination is in the kernel. For a userspace process, nl_pid is usu-
ally the PID of the process owning the destination socket. However,
nl_pid identifies a netlink socket, not a process. If a process owns
several netlink sockets, then nl_pid can only be equal to the process
ID for at most one socket. There are two ways to assign nl_pid to a
netlink socket. If the application sets nl_pid before calling bind(2),
then it is up to the application to make sure that nl_pid is unique.
If the application sets it to 0, the kernel takes care of assigning it.
The kernel assigns the process ID to the first netlink socket the pro-
cess opens and assigns a unique nl_pid to every netlink socket that the
process subsequently creates.
So to execute the bind() in userland I do:
/* Bind the socket with the source address */
memset(&src_addr, 0, sizeof(src_addr));
src_addr.nl_family = AF_NETLINK;
src_addr.nl_pid = 0;
src_addr.nl_groups = 0; /* not in mcast groups */
ret = bind(handle->socket, (struct sockaddr *) &src_addr, sizeof(src_addr));
if (ret < 0) {
close(handle->socket);
return ret;
}
and to replay into kernelland I do:
/* Send an answer to the userland */
dbg("start sending replay...");
NETLINK_CB(skb).pid = 0; /* from the kernel */
NETLINK_CB(skb).dst_pid = nlh->nlmsg_pid;
NETLINK_CB(skb).dst_group = 0; /* not in mcast groups */
ret = netlink_unicast(nl_sk, skb, nlh->nlmsg_pid, MSG_DONTWAIT);
dbg("... replay sent (%d)", ret);
When I open the first socket everything works well, but when I use the
second I notice that the request goes into the kernel which in turn
replays using netlink_unicast() but the userland program blocks
forever.
Can you pleae suggest me where I do wrong?
Thanks,
Rodolfo
--
GNU/Linux Solutions e-mail: giometti at enneenne.com
Linux Device Driver giometti at gnudd.com
Embedded Systems giometti at linux.it
UNIX programming phone: +39 349 2432127
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://ml.enneenne.com/pipermail/linuxpps/attachments/20061023/faa7740e/attachment.pgp
More information about the LinuxPPS
mailing list