Discussion:
ÐŽµÄµÚÒ»žöŒòµ¥µÄnetfilterÄ£¿éŸÍ³öÁËÎÊÌâÁË
(时间太久无法回复)
nicky
2004-10-23 11:46:10 UTC
Permalink
//test.c
#define __KERNEL__
#define MODULE

#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/config.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/netfilter_ipv4.h>

static unsigned int sample(unsigned int hooknum,struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,int (*okfn)(struct sk_buff *))
{
return NF_ACCEPT
}

static struct nf_hook_ops iplimitfilter={ {NULL,NULL} ,sample,PF_INET,NF_IP_PRE_ROUTING,NF_IP_PRI_FILTER-1};

int init_module(void)
{
return nf_register_hook(&iplimitfilter);
}

void cleanup_module(void)
{
nf_unregister_hook(&iplimitfilter);
}
大家帮帮忙啊,谢谢啦~~~!!
编译后输出的错误结果是,
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c test.c
test.c:1:1: warning: "__KERNEL__" redefined
test.c:1:1: warning: this is the location of the previous definition
test.c:2:1: warning: "MODULE" redefined
test.c:1:1: warning: this is the location of the previous definition
In file included from /usr/include/linux/fs.h:23,
from /usr/include/linux/capability.h:17,
from /usr/include/linux/binfmts.h:5,
from /usr/include/linux/sched.h:9,
from /usr/include/linux/skbuff.h:19,
from test.c:5:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userla
nd!
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/skbuff.h:19,
from test.c:5:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from /usr/include/linux/skbuff.h:19,
from test.c:5:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not avail
able on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in users
pace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/skbuff.h:19,
from test.c:5:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from /usr/include/linux/skbuff.h:19,
from test.c:5:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
In file included from /usr/include/linux/highmem.h:5,
from /usr/include/linux/skbuff.h:26,
from test.c:5:
/usr/include/asm/pgalloc.h:6:24: asm/fixmap.h: 没有那个文件或目录
In file included from /usr/include/linux/highmem.h:5,
from /usr/include/linux/skbuff.h:26,
from test.c:5:
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:57: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `get_pgd_slow':
/usr/include/asm/pgalloc.h:59: `pgd_t' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:59: (Each undeclared identifier is reported only once
/usr/include/asm/pgalloc.h:59: for each function it appears in.)
/usr/include/asm/pgalloc.h:59: `pgd' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:59: parse error before ')' token
/usr/include/asm/pgalloc.h:62: `USER_PTRS_PER_PGD' undeclared (first use in this
function)
/usr/include/asm/pgalloc.h:63: `swapper_pg_dir' undeclared (first use in this fu
nction)
/usr/include/asm/pgalloc.h:63: `PTRS_PER_PGD' undeclared (first use in this func
tion)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:70: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `get_pgd_fast':
/usr/include/asm/pgalloc.h:80: `pgd_t' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:80: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:83: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `free_pgd_fast':
/usr/include/asm/pgalloc.h:85: `pgd' undeclared (first use in this function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:90: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `free_pgd_slow':
/usr/include/asm/pgalloc.h:99: `pgd' undeclared (first use in this function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:103: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_alloc_one':
/usr/include/asm/pgalloc.h:105: `pte_t' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:105: `pte' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:109: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:118: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_alloc_one_fast':
/usr/include/asm/pgalloc.h:127: `pte_t' undeclared (first use in this function)
/usr/include/asm/pgalloc.h:127: parse error before ')' token
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:130: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_free_fast':
/usr/include/asm/pgalloc.h:132: `pte' undeclared (first use in this function)
/usr/include/asm/pgalloc.h: At top level:
/usr/include/asm/pgalloc.h:137: parse error before '*' token
/usr/include/asm/pgalloc.h: In function `pte_free_slow':
/usr/include/asm/pgalloc.h:139: `pte' undeclared (first use in this function)
/usr/include/asm/pgalloc.h: In function `flush_tlb_mm':
/usr/include/asm/pgalloc.h:183: `current' undeclared (first use in this function
)
/usr/include/asm/pgalloc.h: In function `flush_tlb_page':
/usr/include/asm/pgalloc.h:190: dereferencing pointer to incomplete type
/usr/include/asm/pgalloc.h:190: `current' undeclared (first use in this function
)
/usr/include/asm/pgalloc.h: In function `flush_tlb_range':
/usr/include/asm/pgalloc.h:197: `current' undeclared (first use in this function
)
In file included from test.c:5:
/usr/include/linux/skbuff.h: At top level:
/usr/include/linux/skbuff.h:100: parse error before "spinlock_t"
/usr/include/linux/skbuff.h:120: parse error before "atomic_t"
/usr/include/linux/skbuff.h:124: parse error before '}' token
/usr/include/linux/skbuff.h:183: parse error before "atomic_t"
/usr/include/linux/skbuff.h:215: parse error before '}' token
In file included from test.c:11:
/usr/include/linux/netfilter_ipv4.h:53: `INT_MIN' undeclared here (not in a func
tion)
/usr/include/linux/netfilter_ipv4.h:53: enumerator value for `NF_IP_PRI_FIRST' n
ot integer constant
/usr/include/linux/netfilter_ipv4.h:59: `INT_MAX' undeclared here (not in a func
tion)
/usr/include/linux/netfilter_ipv4.h:59: enumerator value for `NF_IP_PRI_LAST' no
t integer constant
test.c: In function `sample':
test.c:18: parse error before '}' token
test.c: At top level:
test.c:20: variable `iplimitfilter' has initializer but incomplete type
test.c:20: extra brace group at end of initializer
test.c:20: (near initialization for `iplimitfilter')
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `iplimitfilter')
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `iplimitfilter')
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `iplimitfilter')
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `iplimitfilter')
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `iplimitfilter')
test.c: In function `init_module':
test.c:24: warning: implicit declaration of function `nf_register_hook'
test.c: In function `cleanup_module':
test.c:29: warning: implicit declaration of function `nf_unregister_hook'
test.c: At top level:
test.c:20: storage size of `iplimitfilter' isn't known
make: *** [sample.o] Error 1


--

※ 来源:・BBS 水木清华站 http://smth.org・[FROM: 202.117.14.*]
nicky
2004-10-23 14:44:31 UTC
Permalink
netfilter作为模块的,没有编译进内核,没有关系吧?


【 在 nplum (nicky) 的大作中提到: 】
: //test.c
: #define __KERNEL__
: #define MODULE
: ...................

--

※ 来源:・BBS 水木清华站 smth.org・[FROM: 202.117.14.*]
ÀÃÈË@dhxy.dhs.org
2004-10-23 17:42:02 UTC
Permalink
没问题,一样的
【 在 nplum (nicky) 的大作中提到: 】
: netfilter作为模块的,没有编译进内核,没有关系吧?


--

※ 来源:・BBS 水木清华站 smth.org・[FROM: 61.50.172.*]
nicky
2004-10-24 01:06:47 UTC
Permalink
那错误是什么原因呢?

【 在 leo2000 (烂人@dhxy.dhs.org) 的大作中提到: 】
: 没问题,一样的


--

※ 来源:・BBS 水木清华站 smth.org・[FROM: 202.117.14.*]
BeQuiet
2004-10-24 06:33:46 UTC
Permalink
头文件#include <linux/kernel.h>
编译:gcc -I/usr/src/linux-2.4.20/include -c test.c
好像是没有指定源代码的路径吧

【 在 nplum (nicky) 的大作中提到: 】
: //test.c
: #define __KERNEL__
: #define MODULE
: ...................

--


※ 来源:・BBS 水木清华站 smth.org・[FROM: 202.119.230.*]
ÀÃÈË@dhxy.dhs.org
2004-10-24 06:36:31 UTC
Permalink
对,编译模块一定要include kernel source里面的.h
【 在 wzy123 (BeQuiet) 的大作中提到: 】
: 头文件#include <linux/kernel.h>
: 编译:gcc -I/usr/src/linux-2.4.20/include -c test.c
: 好像是没有指定源代码的路径吧
: ...................

--

※ 来源:・BBS 水木清华站 smth.org・[FROM: 61.50.172.*]
继续阅读narkive:
Loading...