3. iptables用户层目标模块iptables中的扩展目标模块是以动态库方式处理,在命令行中用“-jxxx”来使iptables调用相应的libipt_xxx.so动态库,扩展的目标代码通常在iptables-<version>/extension目录下,编译好的动态库缺省放在/usr/local/lib/iptables目录下。
目标动态库的作用用于解析用户输入的目标信息,显示目标信息等功能。
写好libipt_xxx.c程序后放到iptables-<version>/extension目录下,修改该目录下的Makefile文件,将xxx添加到扩展表中,make就能自动将其编译为动态库。
对于目标,最重要的数据结构就是structiptables_target结构,扩展的目标程序就是要定义一个这个结构并将其挂接到iptables目标链表中,该结构定义如下:
struct iptables_target
{
struct iptables_target *next;
ipt_chainlabel name;
const char *version;
/* Size of target data. */
size_t size;
/* Size of target data relevent for userspace comparisonpurposes */
size_t userspacesize;
/* Function which prints out usage message. */
void (*help)(void);
/* Initialize the target. */
void (*init)(struct ipt_entry_target *t, unsigned int*nfcache);
/* Function which parses command options; returns true ifit
ate anoption */
int (*parse)(int c, char **argv, int invert, unsigned int*flags,
const struct ipt_entry*entry,
struct ipt_entry_target**target);
/* Final check; exit if not ok. */
void (*final_check)(unsigned int flags);
/* Prints out the target iff non-NULL: put space at end*/
void (*print)(const struct ipt_ip *ip,
const structipt_entry_target *target, int numeric);
/* Saves the targinfo in parsable form to stdout. */
void (*save)(const struct ipt_ip *ip,
const struct ipt_entry_target*target);
/* Pointer to list of extra command-line options */
struct option *extra_opts;
/* Ignore these men behind the curtain: */
unsigned int option_offset;
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34719-5.html
高营养高蛋白
跟我有什么关系吗