LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-23-2010, 03:24 AM   #1
adnanwaheed
LQ Newbie
 
Registered: Jul 2010
Posts: 1

Rep: Reputation: 0
Post 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
 
Old 07-23-2010, 02:16 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
Network device driver will free sk_buff.
 
  


Reply

Tags
kernel, netlink



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is my responsibility for being a tor relay? pielas General 4 07-23-2010 11:22 AM
LXer: Computer Take Back Campaign places recycling responsibility on manufacturers LXer Syndicated Linux News 0 09-27-2007 02:00 AM
LXer: Computer Take Back Campaign places recycling responsibility on manufacturers LXer Syndicated Linux News 0 09-27-2007 01:21 AM
LXer: W3C, Accessibility and the Web: A Shared Responsibility LXer Syndicated Linux News 0 04-14-2007 07:02 PM
Firefox 1.0.7 root administrator responsibility Fedora 4 landonmkelsey Linux - General 2 11-03-2005 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration