insmod:错误:无法插入模块kernel.ko:无效的参数-与内核模块的命名方案有关的错误 [英] insmod: ERROR: could not insert module kernel.ko: Invalid parameters - Error related to naming scheme of kernel module

查看:727
本文介绍了insmod:错误:无法插入模块kernel.ko:无效的参数-与内核模块的命名方案有关的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C创建一个自定义内核模块,以挂接到我的Ubuntu盒上的netfilter操作.但是,我遇到了一个围绕module_param参数的问题.插入模块时,我尝试添加自定义字段,特别是在指定时,这将丢弃ICMP流量.使用标准的make文件可以很好地编译代码,但是当使用insmod插入文件时,出现错误

I'm using C to create a custom kernel module to hook into the netfilter operation on my Ubuntu box. However, I'm running into a problem revolving around the module_param argument. When inserting the module, I'm attempting to add a custom field, specifically this will drop ICMP traffic when specified. The code compiles fine using a standard make file but when using insmod to insert it, I get the error

insmod: ERROR: could not insert module kernel.ko: Invalid parameters

我正在使用命令

insmod kernel.ko dropicmp=1

根据我所读的内容,这应该与模块params参数一起使用,但是我尝试过的任何方法都无法解决此问题.

From what I've read, this should work with the module params argument, but nothing I've tried has fixed this.

请在下面找到我的代码.

Please find my code below.

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>
#include <linux/tcp.h>

static struct nf_hook_ops nfho;
struct iphdr *iph;
struct tcphdr *tcp_header;
struct sk_buff *sock_buff;
unsigned int sport, dport;

// command line argument | called using insmod kernel_firewall.ko drop_icmp=1 
static int dropicmp = 1;

module_param(dropicmp, int , 0); // takes in an int from command line | (name, variable, permissions)

unsigned int hook_func(unsigned int hooknum,
                       struct sk_buff **skb,
                       const struct net_device *in,
                       const struct net_device *out,
                       int (*okfn)(struct sk_buff *)){

    sock_buff = skb;

    if (!sock_buff) { // if there is no socket buffer, accept
        return NF_ACCEPT;
    }

    iph = (struct iphdr *)skb_network_header(sock_buff); // using the socket buffer, create our ip header structure out of packets in it

    if (!iph) {
        printk(KERN_INFO "no ip header, dropping\n"); // self explanatory
        return NF_DROP;
    }

    if(iph->protocol==IPPROTO_TCP) {
        if(iph->saddr | 0x11000000){ // if the first prefix is in the 192 range | might need to change the if statement up | considering sprintf
            printk(KERN_INFO "192 subnet detected, dropping\n");
            return NF_DROP;
        }
        else{
            return NF_ACCEPT;
        }
    }

    if(iph->protocol==IPPROTO_ICMP) { // if ICMP

        if(dropicmp == 1){
            return NF_DROP; // drop our ICMP traffic if required
        }
        else{
            return NF_ACCEPT;
        }
    }

    return NF_ACCEPT; // default to accept

}

// initialize
static int __init initialize(void) {
    nfho.hook = hook_func;
    nfho.hooknum = NF_INET_POST_ROUTING;
    nfho.pf = PF_INET;
    nfho.priority = NF_IP_PRI_FIRST;
    nf_register_hook(&nfho);
    return 0;
}

// rmmod 
static void __exit teardown(void) {
    nf_unregister_hook(&nfho);
}

module_init(initialize);
module_exit(teardown);

推荐答案

这全都归功于我的愚蠢的命名方案...我将模块内核命名为...内核显然已经在使用该模块......所以不要那样做...

This was all due to my dumb naming scheme... I named the module kernel... Which is obviously already in use by the kernel...... So don't do that...

这篇关于insmod:错误:无法插入模块kernel.ko:无效的参数-与内核模块的命名方案有关的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆