11

kernel编译使用 netlink 函数的旧模块时出现编译器错误。

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;
    }
 ....

以前它工作正常,但现在我收到此错误。

error: too many arguments to function 'netlink_kernel_create'

操作系统信息

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
4

3 回答 3

13

只需更换

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

与以下

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

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

它应该可以工作。我遇到了同样的问题。

于 2013-07-12T02:44:23.723 回答
6

这是因为在 3.8 中 netlink_kernel_create 原型已更改:

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

(和 qv http://lxr.linux.no/linux+v3.8/include/linux/netlink.h#L48

您别无选择,只能重写内核模块,删除额外的参数 (THIS_MODULE),并实现 netlink_kernel_cfg 结构。

于 2013-04-11T02:16:36.337 回答
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.");
于 2018-07-22T15:15:37.983 回答