adnanwaheed |
07-23-2010 03:24 AM |
Whose responsibility is it to free sk_buff
While creating a netlink socket using netlink_kernel_create() a function pointer is passed as argument to this function which is called when a message is received on this socket. This call back function receives an sk_buff as parameter which contains the message received.
My question is that whose responsibility is it to free this sk_buff?
Also plz take a look at the following code. Here i get a new skb to send reply to user program but when i call nlmsg_free() on it, my machine hangs and I hav to restart
Quote:
#include <linux/module.h>
#include <net/sock.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>
#define NETLINK_USER 31
struct sock *nl_sk = NULL;
static void hello_nl_recv_msg(struct sk_buff *skb)
{
struct nlmsghdr *nlh;
int pid;
struct sk_buff *skb_out;
int msg_size,real_size;
char *msg="Hello from kernel";
int res;
msg_size=strlen(msg);
skb_out = nlmsg_new(msg_size,0);
nlh=(struct nlmsghdr*)skb->data;
printk(KERN_INFO "Netlink received msg payload: %s\n",(char*)nlmsg_data(nlh));
pid = nlh->nlmsg_pid; /*pid of sending process */
if(!skb_out)
{
printk(KERN_ERR "Failed to allocate new skb\n");
return;
}
nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0);
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
//NETLINK_CB(skb_out).pid = 0; /* from kernel */
strncpy(nlmsg_data(nlh),msg,msg_size);
printk("About to send msg bak:\n");
res=netlink_unicast(nl_sk,skb_out,pid,MSG_DONTWAIT);
if(res<0)
printk(KERN_INFO "Error while sending bak to user\n");
//nlmsg_free(skb_out);
}
static int __init hello_init(void)
{
printk("Entering: %s\n",__FUNCTION__);
nl_sk=netlink_kernel_create(&init_net, NETLINK_USER, 0, hello_nl_recv_msg, NULL, THIS_MODULE);
if(!nl_sk)
{
printk(KERN_ALERT "Error creating socket.\n");
return -10;
}
return 0;
}
static void __exit hello_exit(void){
printk(KERN_INFO "exiting hello module\n");
netlink_kernel_release(nl_sk);
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
|
Thank you and I highly appreciate your help
|