【发布时间】:2023-03-29 13:56:01
【问题描述】:
使用netlink_kernel_create() 创建netlink 套接字时,函数指针作为参数传递给此函数,当在此套接字上接收到消息时调用该函数。这个回调函数接收一个sk_buff作为参数,其中包含接收到的消息。
我的问题是释放这个sk_buff是谁的责任?
示例代码
#include
#include
#include
#include#define NETLINK_USER 31
结构袜子 *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);}
静态 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;}
【问题讨论】:
标签: linux-kernel linux-device-driver