谁的责任是释放sk_buff

时间:2010-07-22 19:05:38

标签: linux-kernel linux-device-driver

使用netlink_kernel_create()创建netlink套接字时,函数指针作为参数传递给此函数,该函数在此套接字上收到消息时调用。此回调函数接收sk_buff作为参数,其中包含收到的消息。

我的问题是,谁负责释放这个sk_buff

示例代码

  

#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 my_nl_recv_msg(struct sk_buff * skb){

struct nlmsghdr *nlh;  
int pid;  

printk(KERN_INFO "Entering: %s\n", __FUNCTION__);  

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 */  
NETLINK_CB(skb).dst_group = 0; /* not in mcast group */  
NETLINK_CB(skb).pid = 0;      /* from kernel */  
//printk("About to send msg bak:\n");  
//netlink_unicast(nl_sk,skb,pid,MSG_DONTWAIT);
     

}

     

static int __init hello_init(void){

printk("Entering: %s\n",__FUNCTION__);  
nl_sk=netlink_kernel_create(&init_net, NETLINK_USER, 0,  
        my_nl_recv_msg, NULL, THIS_MODULE);  
if(!nl_sk)  
{  
    printk(KERN_ALERT "Error creating socket.\n");  
    return -10;  
}  
return 0;
     

}

1 个答案:

答案 0 :(得分:1)

net/netlink/af_netlink.cnetlink_unicast_kernelmy_nl_recv_msg函数的调用者将负责释放它。