11

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
Ibrar Ahmed
  • 1,039
  • 1
  • 13
  • 25

3 Answers3

13

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.

Javid Pack
  • 462
  • 5
  • 15
6

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.

Technologeeks
  • 7,674
  • 25
  • 36
  • 1
    Is there any example available? – Ibrar Ahmed Apr 11 '13 at 20:34
  • 1
    With such a new kernel, probably not. Though it should be a fairly straightforward process to modify your implementation to accommodate for the newer APIs. Unfortunately, this is something we've had to deal with in the past, as well (as Linux kernel APIs are evolving, and often quite unstable) – Technologeeks Apr 11 '13 at 21:09
0
    netlink_kernel_create(struct net *net, int unit, struct netlink_kernel_cfg *cfg)

    struct netlink_kernel_cfg cfg = {
        .groups = SELNLGRP_MAX,
        .flags  = NL_CFG_F_NONROOT_RECV,
    };

    selnl = netlink_kernel_create(&init_net, NETLINK_SELINUX, &cfg);
    if (selnl == NULL)
        panic("SELinux:  Cannot create netlink socket.");
leesagacious
  • 182
  • 1
  • 8