/* Returns verdict. Argument order changed since2.4, as this
mustnow handle non-linear skbs, using skb_copy_bits and
skb_ip_make_writable. */
unsigned int (*target)(struct sk_buff **pskb,
const structnet_device *in,
const structnet_device *out,
unsigned inthooknum,
const void*targinfo,
void*userdata);
/* Set this to THIS_MODULE. */
struct module *me;
};
该结构中有以下几个参数:
struct list_head list:用来挂接到目标链表,必须初始化为{NULL, NULL};
name: 该目标名称的名称,必须是唯一的;
checkentry函数:用于对用户层传入的数据进行合法性检查,如目标数据长度是否正确,是否是在正确的表中使用等;
destroy函数:用于释放该目标中动态分配的资源,在规则删除时会调用;
target函数:该函数是最主要函数,完成对数据包的策略处理,包括对包中的数据进行修改,函数返回结果可能是NF_ACCEPT(接受)/NF_DROP(丢弃)/NF_STOLEN(偷窃,指该包处理由该目标接管,不再由系统网络栈处理)/IPT_CONTINUE(继续,继续按后面的规则对该包进行检查)等;
struct module *me:指向模块本身。本例中的目标结构定义如下:
static struct ipt_target ipt_id_reg = {
.name= "ID",
.target= target,
.checkentry= checkentry,
.me= THIS_MODULE,
};
target函数是目标的核心函数,返回1表示数据符合目标条件,0表示不目标,函数定义为:
unsigned int (*target)(struct sk_buff **pskb,
const structnet_device *in,
const structnet_device *out,
unsigned inthooknum,
const void*targinfo,
void*userdata);
在target函数参数为:
skb:数据包
in:数据进入的网卡
out:数据发出的网卡
hooknum:hook号,取值为:NF_IP_PRE_ROUTING/NF_IP_LOCAL_IN/NF_IP_FORWARD/
NF_IP_LOCAL_OUT/NF_IP_POST_ROUTING之一
targetinfo:目标条件信息的指针
offset:碎片数据偏移量
userdata:特殊专用数据,目前内核中基本没有用到,通常都是NULL;
check函数对数据进行检查,返回1表示数据合法,0表示非法,函数定义为:
int (*checkentry)(const char *tablename,
const struct ipt_entry *e,
void *targinfo,
unsigned int targinfosize,
unsigned int hook_mask);
tablename:表名,如“filter”,“nat”,“mangle”等,可用来限制目标只能在指定的表中处理;
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34719-2.html
嗨喽能问你个问题吗
联想不思进取