views:

1403

answers:

4

Now I want to create a netlink which is used to communicate between the user and kernel space. My Linux kernel version is 2.6.28. the following is my wrong code:

nf_sock=netlink_kernel_create(NL_PROTO,0,nl_user_skb,THIS_MODULE);

The error message is briefly as:

error: too few arguments to function 'netlink_kernel_creat'

In the file , the function 'netlink_kernel_create()' is defined as

extern 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)

I don't known what't the meaning by the argument net, who can give me some explanation, thanks!

+1  A: 

You seem to have been following a guide such as this one, which (being from 2005) might well have been outpaced by the development of the kernel. It seems the internal API to create a netlink from the kernel side has changed.

Either check the Documentation/ folder in your local kernel tree for some (hopefully fresher) documentation, or read the code itself. You could also trawl the Linux Kernel mailing list archives for any mention of the changes that seem to have happened.

Here is the actual implemntation as of 2.6.29, if you'd rather puzzle it out backwards (and haven't already checked this in your own tree, of course).

unwind
@unwind: Your last link was broken so I changed it. I pretty confident in my guess, but please check it to make sure I linked to the right page.
Bill the Lizard
A: 

I would suggest ioctl for kernel/user communication. The ioctl interface is standard and the chance of been updated between kernels is small.

Ilya
ioctl's may work for simple changes but the interface is a hoary and brittle one to manage. Netlink is the preferred API of kernel developers for anything moderately complex.
stsquad
+2  A: 

A struct net contains information about the network namespace, a set of network resources available to processes. Note that there could be multiple network namespaces (i.e. multiple instances of the networking stack), but most drivers use the init_net namespace.

Your call should probably look something like the following

nf_sock = netlink_kernel_create(&init_net,
                                NETLINK_USERSOCK,
                                0,
                                nl_rcv_func,
                                NULL,
                                THIS_MODULE);

where nl_rcv_func is a function taking struct sk_buff *skb as the only argument and processes the received netlink message.

ctuffli
A: 

Can you post the sample code of nl_rcv_func used in netlink_kernel_create function

nf_sock = netlink_kernel_create(&init_net, NETLINK_USERSOCK, 0, nl_rcv_func, NULL, THIS_MODULE);

coolraj