Re: about netlink: skb_recv_datagram() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For better understanding about my doubt, here is the full code. It is
based at http://www.linuxjournal.com/article/7356. I have applied some
changes because the available version is based on older kernel.

#include <linux/socket.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netlink.h>
#include <net/sock.h>

#define NETLINK_TEST 17

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Test");
MODULE_DESCRIPTION("Testing Kernel/User socket");

static int debug = 0;

module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "Debug information (default 0)");

static struct sock *nl_sk = NULL;

static void nl_data_ready (struct sock *sk, int len)
{
	wake_up_interruptible(sk->sk_sleep);
}

static void netlink_test(void)
{
	struct sk_buff *skb = NULL;
	struct nlmsghdr *nlh = NULL;
	int err;
	u32 pid;
	
	nl_sk = netlink_kernel_create(NETLINK_TEST, 0, 
				      nl_data_ready, THIS_MODULE);
	
	if (!nl_sk) {
		printk(KERN_ERR
		       "netlink_test: unable to create netlink socket!\n");
		return;
	}

	skb = skb_recv_datagram(nl_sk, 0, 0, &err);
	if (!skb) {
		printk(KERN_ERR
		       "netlink_test: skb_recv_datagram!\n");
		return;
	}

	nlh = (struct nlmsghdr *)skb->data;
	printk(KERN_INFO "%s: received netlink message payload: %s\n",
	       __FUNCTION__, (char *)NLMSG_DATA(nlh));
	
	pid = nlh->nlmsg_pid;
	NETLINK_CB(skb).pid = 0;
	NETLINK_CB(skb).dst_pid = pid;
	NETLINK_CB(skb).dst_group = 0;
	netlink_unicast(nl_sk, skb, pid, MSG_DONTWAIT);
	sock_release(nl_sk->sk_socket);
}

static int __init my_module_init(void)
{
	printk(KERN_INFO "Initializing Netlink Socket\n");
	netlink_test();
	return 0;
}

static void __exit my_module_exit(void)
{
	printk(KERN_INFO "Goodbye\n");
}

module_init(my_module_init);
module_exit(my_module_exit);


--- Mauricio Lin <mauriciolin2000@xxxxxxxxxxxx> escreveu:

> Hi all,
> 
> I am using a module that employs netlink functions and data.
> 
> After compiling it, I insert the module as:
> 
> # insmod test.ko
> 
> but the terminal (prompt) gets locked. After debugging the module, I
> noticed that skb_recv_datagram() is responsible for that.
> 
> Take a look the snippet of the code:
> 
> skb = skb_recv_datagram(nl_sk, 0, 0, &err);
> if (!skb) {
> 	printk(KERN_ERR
> 	       "netlink_test: skb_recv_datagram!\n");
> 	return;
> }
> 
> When I interrupt the prompt (as it was locked by inserting the
> module)
> typing <Control>+C, the message "netlink_test: skb_recv_datagram!" is
> printed, so I wonder why this is happening.
> 
> Is it normal skb_recv_datagram() blocks the terminal? How can I solve
> it?
> 
> BR,
> 
> Mauricio Lin.
> 
> 
> 		
> _______________________________________________________ 
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu
> celular. Registre seu aparelho agora! 
> http://br.mobile.yahoo.com/mailalertas/ 
>  
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 



		
_______________________________________________________ 
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale 
o discador agora! 
http://br.acesso.yahoo.com

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux