自己写 Netfilter 匹配器[1]
[入库:2006年2月23日] [更新:2007年3月24日]
![[Illustration]](http://www.tldp.org/linuxfocus/common/images2/article367.png)
写一个 iptables/netfilter 匹配模块的大体步骤如下:
1.0 iptables 模块
iptables 库的用途基本上讲就是和用户交互,它捕获用户要传送给核心态程序的参数。
1.1 可用的数据结构和函数
首先是一些基本数据结构。
<
iptables/include/iptables.h>
稍后文中就将可以看到这些结构的用途了。
/* Include file for additions: new matches and targets. */ struct iptables_match { struct iptables_match *next;
ipt_chainlabel name;
const char *version;
/* Size of match data. */ size_t size;
/* Size of match data relevent for userspace comparison purposes */ size_t userspacesize;
/* Function which prints out usage message. */ void (*help)(void);
/* Initialize the match. */ void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
/* Function which parses command options; returns true if it ate an option */ int (*parse)(int c, char **argv, int invert, unsigned int *flags, const struct ipt_entry *entry, unsigned int *nfcache, struct ipt_entry_match **match);
/* Final check; exit if not ok. */ void (*final_check)(unsigned int flags);
/* Prints out the match iff non-NULL: put space at end */ void (*print)(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric);
/* Saves the match info in parsable form to stdout. */ void (*save)(const struct ipt_ip *ip, const struct ipt_entry_match *match);
/* Pointer to list of extra command-line options */ const struct option *extra_opts;
/* Ignore these men behind the curtain: */ unsigned int option_offset; struct ipt_entry_match *m; unsigned int mflags; #ifdef NO_SHARED_LIBS unsigned int loaded; /* simulate loading so options are merged properly */ #endif };
|
本文关键:自己写 Netfilter 匹配器
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)