Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么netfilter.h中缺少nf_hookfn、nf_hook_ops等的typedef?_C_Linux_Kernel Module_Apt_Netfilter - Fatal编程技术网

C 为什么netfilter.h中缺少nf_hookfn、nf_hook_ops等的typedef?

C 为什么netfilter.h中缺少nf_hookfn、nf_hook_ops等的typedef?,c,linux,kernel-module,apt,netfilter,C,Linux,Kernel Module,Apt,Netfilter,我正在尝试编写一个netfilter模块。我的第一次尝试 我的Makefile是: obj-m += someModule.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 我得到的编译时错误清楚地表明,structs nf\u hookfn,nf\u hoo

我正在尝试编写一个netfilter模块。我的第一次尝试

我的Makefile是:

obj-m += someModule.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
我得到的编译时错误清楚地表明,
structs nf\u hookfn
nf\u hook\u ops
等的
typedefs
没有被拾取或错误地拾取

我知道钩子函数的参数列表在以后的内核中发生了变化。无论如何,我都没有在
/usr/include/linux/netfilter.h
中看到我需要的
typedef

我试过什么

我尝试更新内核头:

 sudo apt-get install linux-headers-$(uname -r)
 [sudo] password for xxx: 
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 linux-headers-4.15.0-33-generic is already the newest version (4.15.0-33.36).
0已升级,0已新安装,0已删除,397未升级

我在中看到了所有必需的def

/usr/src/linux-headers-4.15.0-33/include/linux/netfilter.h
当然,我可以包含此文件,或者有指向它的链接

这似乎不是正确的做法。正确的方法是什么

编辑: make-V1的输出为:

  gcc -Wp,-MD,/home/somedir/.someModule.o.d  -nostdinc 
  -isystem /usr/lib/gcc/x86_64-linux-gnu/7/include 
  -I./arch/x86/include -I./arch/x86/include/generated  
  -I./include -I./arch/x86/include/uapi 
  -I./arch/x86/include/generated/uapi 
   -I./include/uapi 
  -I./include/generated/uapi -include ./include/linux/kconfig.h 
  -Iubuntu/include  -D__KERNEL__ -Wall -Wundef 
  -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing 
  -fno-common -fshort-wchar -Werror-implicit-function-declaration 
  -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 
  -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 
  -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup 
  -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time 
  -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 
  -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 
  -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 
  -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 
  -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe 
  -Wno-sign-compare -fno-asynchronous-unwind-tables 
  -mindirect-branch=thunk-extern -mindirect-branch-register 
  -DRETPOLINE -fno-delete-null-pointer-checks -Wno-frame-address 
  -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -O2 
  --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 
  -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable 
  -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments 
  -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign 
  -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check 
  -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time 
  -Werror=incompatible-pointer-types -Werror=designated-init  -DMODULE  -DKBUILD_BASENAME='"someModule"'  
  -DKBUILD_MODNAME='"someModule"' -c -o /home/somedir/someModule.o /home/somedir/someModule.c

编辑:我的代码中的错误是我在网上遇到了一个例子。钩子函数的签名和一些函数名也发生了变化。如果您遇到在网络上使用netfilter函数的示例,请确保您使用的是正确版本的API

如果您的内核模块包含来自
/usr/include/linux
的头文件,那么那里确实出了问题:
/usr/include/linux
中的文件供用户区应用程序使用(请参阅),而不是内核模块

相反,您的模块应该在内核源代码中包含头文件

值得一提的是,这似乎是我系统的默认设置。如果我编译这个非内核模块:

#include <linux/netfilter.h>

void my_fn(void) {
    struct nf_hook_ops ops;
}

如果您的代码不正确,则说明出现了问题,但如果不查看代码,则很难判断问题所在。

请查看我的编辑。我接受你的回答,因为它确实澄清了很多。另外,您提供的链接也很有用。@asinix您的
#include
行与我的示例中的第一行看起来一样吗?是的!完全一样,终于开始工作了。。。我的代码中有错误。很高兴您已经解决了您的问题。但是如果没有代码和错误消息(不是您提供的对该消息的描述,而是错误消息本身),这个问题对未来的读者来说就没有什么价值了。另请参见。@Tsyvarev您是对的。我编辑了我的答案,添加了一条评论,这将有助于未来的读者。代码和错误信息应该在问题帖中。把他们放在答题台上是不够的。换句话说,没有答案的问题应该是可以理解的。与此相反,问题帖子不应该包含决议(如问题帖子中的“编辑”段落):所有决议都在答案中描述。
gcc ... -nostdinc ... -I./include ...