LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 11-26-2009, 12:08 AM   #1
priyankal
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
Help regarding Netlink sockets for 2.6 kernels: Kernel module


Hi,
I'm a netlink newbie developing a kernel module (as stated above) for 2.6.x kernels.
I'm simply truing to pass a(any) message between the user space and the kernel.

The changes to the netlink APIs from kernel to kernel are confusing.
Below is my kernel code:
Code:
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define NETLINK_TEST 17
#define VFW_GROUP 0
#define MSG_SIZE NLMSG_SPACE(1024)

static struct sock *nl_sk = NULL;

static void nltest_rcv(struct sock *sk, int len)
{
struct sk_buff *nl_skb;
struct nlmsghdr *nl_hdr;
int pid;
while ((nl_skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
nl_hdr = (struct nlmsghdr *)nl_skb->data;
pid = nl_hdr->nlmsg_pid;
printk(KERN_ALERT "*** Message from user with PID: (pid = %d) is %s\n", pid, (char*)NLMSG_DATA(nl_hdr));
nl_skb = alloc_skb(MSG_SIZE, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
skb_put(nl_skb, MSG_SIZE);
nl_hdr = (struct nlmsghdr *)nl_skb->data;
nl_hdr->nlmsg_len = MSG_SIZE;
nl_hdr->nlmsg_pid = pid;
nl_hdr->nlmsg_flags = 0;
strcpy(NLMSG_DATA(nl_hdr), "HELLO HELLO HELLO");
NETLINK_CB(nl_skb).pid = 0;
NETLINK_CB(nl_skb).dst_pid = pid;
NETLINK_CB(nl_skb).dst_group = VFW_GROUP;
netlink_unicast(nl_sk, nl_skb, pid, 0);
kfree_skb(nl_skb);
}
}

/* LXR reference:http://lxr.linux.no/#linux+v2.6.26.7/net/netlink/af_netlink.c#L1358
struct sock * netlink_kernel_create
(struct net *net, int unit, unsigned int groups,void (*input)(struct sk_buff *skb),struct mutex *cb_mutex, struct module *module)
*/

static int __init nltest_init(void)
{
struct net *net;
printk(KERN_ALERT "INIT/START: nltest\n");
nl_sk = netlink_kernel_create(net,NETLINK_TEST, VFW_GROUP, nltest_rcv, 0, THIS_MODULE);
if (!nl_sk) {
printk(KERN_ALERT "ERROR: nltest - netlink_kernel_create() failed\n");
return -1;
}
return 0;
}
static void __exit nltest_exit(void)
{
printk(KERN_ALERT "EXIT: nltest\n");
sock_release(nl_sk->sk_socket);

return;
}
module_init(nltest_init);
module_exit(nltest_exit);

MODULE_DESCRIPTION("Module_Test_Netlink");
MODULE_LICENSE("GPL");
when I run a make on this file, it shows the following errors:

root@ubuntu:/home/p# make
make -C /lib/modules/2.6.27-15-generic/build M=/home/p modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-15-generic'
CC [M] /home/priyanka/kern.o
/home/p/kern.c: In function ‘nltest_rcv’:
/home/p/kern.c:37: error: ‘struct netlink_skb_parms’ has no member named ‘dst_pid’
/home/p/kern.c: In function ‘nltest_init’:
/home/p/kern.c:54: warning: passing argument 4 of ‘netlink_kernel_create’ from incompatible pointer type
make[2]: *** [/home/p/kern.o] Error 1
make[1]: *** [_module_/home/p] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-15-generic'
make: *** [all] Error 2

The two errors are for
1. netlink_kernel_create function
2. struct netlink_skb_parms

Can anyone help me figure out how to solve these errors?

Thanks!
 
Old 11-26-2009, 04:49 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,599
Blog Entries: 29

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
The two errors are for
1. netlink_kernel_create function
2. struct netlink_skb_parms
I don't know much about Netlink, but if these functions are pre-defined why don't u check their declarations in their corresponding header files i.e. the ones which u have included in the above shown code!

Quote:
error: ‘struct netlink_skb_parms’ has no member named ‘dst_pid’
/home/p/kern.c: In function ‘nltest_init’:
/home/p/kern.c:54: warning: passing argument 4 of ‘netlink_kernel_create’ from incompatible pointer type
From the errors u are receiving it seems u have passed the wrong parameters !

Last edited by TheIndependentAquarius; 11-26-2009 at 05:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netlink sockets usage to communicate b/w user and kernel space. vinodkr83 Linux - Newbie 1 07-03-2009 03:22 AM
Generic Netlink sockets krishna123 Linux - Networking 0 03-04-2009 01:30 AM
Netlink in a kernel module SebX86 Programming 0 02-22-2009 04:48 PM
A question about netlink sockets alfrag Linux - Newbie 1 12-26-2008 08:48 AM
Kernel module using netlink sockets arunka Programming 1 03-31-2005 07:42 AM


All times are GMT -5. The time now is 10:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration