在使用函数指针创建 netlink 套接字netlink_kernel_create()
时,将作为参数传递给此函数,当在此套接字上接收到消息时调用该函数。这个回调函数接收一个sk_buff
包含接收到的消息的 as 参数。
我的问题是,释放这个是谁的责任sk_buff
?
示例代码
#include <linux/module.h>
#include <net/sock.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>#define NETLINK_USER 31
结构袜子 *nl_sk = NULL;
静态无效 my_nl_recv_msg(结构 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);
}
静态 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;
}