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

问题描述 投票:0回答:1

我正在尝试编写一个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

我收到编译时错误,清楚地表明typedefsstructs nf_hookfn等的nf_hook_ops没有被拾取或错误地被拾取。

我知道钩子函数的参数列表在以后的内核中已更改。无论哪种方式,我都根本看不到typedefs中需要的任何/usr/include/linux/netfilter.h

我尝试了什么?

我试图更新内核头文件:

 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未升级。

我在]中看到所有必需的defs>

/usr/src/linux-headers-4.15.0-33/include/linux/netfilter.h

当然,我可以包含此文件或具有指向该文件的链接。

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

编辑:make -V 1的输出是:

  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

EDIT

:我的代码中的错误是我在跟踪一个网上遇到的示例。挂钩函数的签名以及实际上一些函数名称也已更改。如果遇到网络上使用netfilter函数的示例,请确保使用的API版本正确。

我正在尝试编写一个netfilter模块。我的第一次尝试。我的Makefile是:obj-m + = someModule.o全部:make -C / lib / modules / $(shell uname -r)/ build M = $(PWD)模块clean:make -C / lib / ...] >

c linux kernel-module apt netfilter
1个回答
1
投票

如果您的内核模块包含/usr/include/linux的标头,则确实存在问题:/usr/include/linux中的文件供用户级应用程序使用(请参阅What's the difference between /usr/include/linux and the include folder in linux kernel source?),而不是内核模块使用。

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

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.