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
?
Example Code
#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;
}