|
Kernel Panic when netlink message is sent from User space to kernel space
Hi all,
The below code is w.r.t netlinks. I just ported the below code from 2.6.27 kernel to 2.6.34 kernel. And this code works fine in 2.6.27 kernel and when I run it in 2.6.34 it is giving kernel panic. When I debugged it "nlh" value is null i.e skb->data is pointing to some garbage value. What could be the reason. Please help me.
Kernel Code:
------------
int nl_rcv_func (struct sk_buff *skb)
{
struct nlmsghdr *nlh;
if (!skb && !(struct nlmsghdr *)skb->data)
return FAILURE;
/* Get the Netlink message header from the buffer */
nlh = (struct nlmsghdr *)skb->data;
/* Kernel panic is happening here since nlh is NULL */
printk (KERN_INFO "%d:"nlh->nlmsg_len);
}
struct sock *nl_sock ()
{
struct sock *ns = NULL;
ns = netlink_kernel_create (&init_net, NETLINK_USERSOCK, 0,
nl_rcv_func, &rtnl_mutex,THIS_MODULE);
return ns;
}
UserSpace Code:
----------------
int init_module ( )
{
struct ctrl c;
struct sockaddr_nl nladdr;
struct
{
struct nlmsghdr nlmh;
struct ctrl c;
}
rq;
int ns;
/* Initialize the socket */
ns = netlink_open ();
if (ns <= 0)
{
perror ("socket failed");
return -1;
}
pal_mem_set(&rq, 0, sizeof(rq));
pal_mem_set(&nladdr, 0, sizeof(nladdr));
void *data = NLMSG_DATA(&rq);
req.nlmh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ctrl));
pal_mem_cpy(data, 40, sizeof(struct ctrl));
nladdr.nl_family = AF_NETLINK;
return sendto(ns, (u_char *)&rq, 20, 0, (struct sockaddr *)&nladdr,
sizeof(nladdr));
}
|