I have some issues using the netlink sockets with a new netlink family...in particular with groups. I use netlink_broadcast
or nlmsg_multicast
methods in kernel space to send messages to userspace. I have an header, for example, with the defs:
#define NETLINK_MYFAMILY 20
#define NL_MYGRP 2
and a process that opens a socket and binds to a netlink address:
int sock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_MYFAMILY);
...
struct sockaddr_nl nl_addr;
memset(&nl_addr, 0, sizeof(struct sockaddr_nl));
nl_addr.nl_family = AF_NETLINK;
nl_addr.nl_pid = getpid();
nl_addr.nl_groups = NL_MYGRP;
int r = bind(sock, (struct sockaddr *)&nl_addr, sizeof(struct sockaddr_nl));
...
obsiously in kernel space i call:
struct sock *s = netlink_kernel_create(&init_net,
NETLINK_MYFAMILY,
NL_MYGRP,
recv_cb,
NULL, THIS_MODULE);
where recv_cb
is the callback called when a process sends a message from userspace.
Now i try to send a message to userspace with:
netlink_broadcast(s, skb, 0, NL_MYGRP, GFP_ATOMIC);
I can read correctly the message in the process only if the NL_MYGRP
is 1. I can't figure out the problem...All netlink families are specified in linux/netlink.h
and the number 20 doesn't exist so i think it could be used to specify my new family. What is wrong? Thank you all.