Discussion:
netlink API
Vinay Venkataraghavan
2009-03-04 22:08:37 UTC
Permalink
Hi folks,

It looks like the netlink interface has changed in the 2.6.X kernel. I am not sure what X is. But the old API used to be:



extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));


The new API is as follows:


extern struct sock *netlink_kernel_create(struct net *net,
int unit,unsigned int groups,
void (*input)(struct sk_buff *skb),
struct mutex *cb_mutex,
struct module *module);

But I am having problems getting my user space application to communicate with my driver.

I am creating a netlink kernel socket in my driver as follows:


nls = netlink_kernel_create(&init_net, NETLINK_USERSOCK, 0,
my_input, 0, THIS_MODULE);


and in my user space program i am trying to open a socket and write to it as follows:

struct sockaddr_nl nlDest;

sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);

if(sockfd < 0) {
perror("Unable to create netlink socket. \n");
}
else {
memset(&nlDest, 0, sizeof(nlDest));
nlDest.nl_family = AF_NETLINK;
nlDest.nl_pid = getpid();
nlDest.nl_groups = 0;
if (bind(sockfd, (struct sockaddr *)&nlDest, sizeof(nlDest)) < 0)
{
perror("could not bind netlink socket.\n");
close(sockfd);
exit(0);
}
}

But when I try to send a message using:

rc = sendmsg(sockfd, &msg, MSG_DONTWAIT);

I get an error with errno = 22. This mean Invalid argument.

msg here is of type struct msghdr.

A couple of other things that would help is:

- how do I know that the netlink socket in the kernel has been created?
- secondly how do I know that the message will be appropriately routed to my function that I have registered with the socket.


Any help in this matter would be greatly appreciated.

Thanks,
Vinay



--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Vinay Venkataraghavan
2009-03-04 22:12:49 UTC
Permalink
Hi folks,

It looks like the netlink interface has changed in the 2.6.X kernel. I am not sure what X is. But the old API used to be:



extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));


The new API is as follows:


extern struct sock *netlink_kernel_create(struct net *net,
int unit,unsigned int groups,
void (*input)(struct sk_buff *skb),
struct mutex *cb_mutex,
struct module *module);

But I am having problems getting my user space application to communicate with my driver.

I am creating a netlink kernel socket in my driver as follows:


nls = netlink_kernel_create(&init_net, NETLINK_USERSOCK, 0,
my_input, 0, THIS_MODULE);


and in my user space program i am trying to open a socket and write to it as follows:

struct sockaddr_nl nlDest;

sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);

if(sockfd < 0) {
perror("Unable to create netlink socket. \n");
}
else {
memset(&nlDest, 0, sizeof(nlDest));
nlDest.nl_family = AF_NETLINK;
nlDest.nl_pid = getpid();
nlDest.nl_groups = 0;
if (bind(sockfd, (struct sockaddr *)&nlDest, sizeof(nlDest)) < 0)
{
perror("could not bind netlink socket.\n");
close(sockfd);
exit(0);
}
}

But when I try to send a message using:

rc = sendmsg(sockfd, &msg, MSG_DONTWAIT);

I get an error with errno = 22. This mean Invalid argument.

msg here is of type struct msghdr.

A couple of other things that would help is:

- how do I know that the netlink socket in the kernel has been created?
- secondly how do I know that the message will be appropriately routed to my function that I have registered with the socket.


Any help in this matter would be greatly appreciated.

Thanks,
Vinay



--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...