Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

netlink_kernel_create is not working with latest linux kernel

Tags:

c

kernel

netlink

I am getting compiler error while compiling my old kernel module which is using netlink functions.

int
init_module()
{
    /* Initialize the Netlink kernel interface */
    nl_sk = netlink_kernel_create(&init_net, 17, 0, recv_cmd, NULL, THIS_MODULE);
    if(!nl_sk)
    {
            printk(KERN_INFO "failed to initialize system (error: 1001)\n");
            return -ENOMEM;
    }
 ....

Previously it works fine but now I am getting this error.

error: too many arguments to function 'netlink_kernel_create'

OS Information

uname -a

Linux ibrar-ahmed 3.8.0-17-generic #27-Ubuntu SMP Sun Apr 7 19:39:35 UTC 2013 x86_64  x86_64 x86_64 GNU/Linux
like image 745
Ibrar Ahmed Avatar asked Apr 10 '13 22:04

Ibrar Ahmed


2 Answers

Just replace

nl_sk = netlink_kernel_create(&init_net, 17, 0, recv_cmd, NULL, THIS_MODULE);

with the following

struct netlink_kernel_cfg cfg = {
    .input = recv_cmd,
};

nl_sk = netlink_kernel_create(&init_net, 17, &cfg);

and it should work. I ran into the same problems.

like image 158
Javid Pack Avatar answered Nov 17 '22 07:11

Javid Pack


That's because in 3.8 the netlink_kernel_create prototype has been changed:

netlink_kernel_create(struct net *net, int unit, struct netlink_kernel_cfg *cfg)

(and q.v. http://lxr.linux.no/linux+v3.8/include/linux/netlink.h#L48)

You've no option but to rewrite the kernel module, and remove that extra argument (THIS_MODULE), as well as implement the netlink_kernel_cfg struct.

like image 20
Technologeeks Avatar answered Nov 17 '22 07:11

Technologeeks