首页 存档 技术 查看内容

Linux网络子系统安全性模块详细分析之核心文件分析-结构体定义及内外部函数

2018-3-30 13:00 |来自: 互联网 362 0

摘要: 2.4.2.3 结构体定义 nf_hook_ops 结构体定义如下: struct nf_hook_ops { struct list_head list; nf_hookfn *hook; struct module *owner; u_int8_t pf; unsigned int hooknum; int priority; }; 该结构体描述钩 ...

2.4.2.3 结构体定义

nf_hook_ops 结构体定义如下:

struct nf_hook_ops {

struct list_head list;

nf_hookfn *hook;

struct module *owner;

u_int8_t pf;

unsigned int hooknum;

int priority;

};

该结构体描述钩子点的操作集合。list成员将钩子点上的所有集合用链表组织起来;hook表示钩子点的处理函数;hooknum表示钩子点的序号;priority表示操作集的优先级。

2.4.2.4 外部函数

参见2.4.1和2.4.3

2.4.2.5 内部函数

1.nf_nat_standalone_init( )

函数原型:

static int __init nf_nat_standalone_init(void)

函数参数:空。

函数功能:完成nat表的初始化,并进一步对nat进行注册,同时注册了两个targetSNATDNAT;完成操作集的注册。返回值:成功时返回0;反之返回相应的错误码。

2.nf_nat_fn( )

函数原型:static unsigned int nf_nat_fn(unsigned int hooknum,struct sk_buff *skb,const struct net_device *in,const struct net_device *out, int (*okfn)(struct sk_buff *))

函数参数:hooknum表示哪一个钩子点处,skb表示数据包的结构体,out表示出去的网络设备接口,in表示进来的网络设备接口,okfn执行数据包的处理函数指针。

函数功能:nf_nat_fn( )函数会根据连接信息结构体ip_conntrack_info,也就是连接的方向,这里主要就分两个方向,判断是发送的包还是回应的包。如果是发送的包,会首先调用nf_nat_rule_find( )函数查找规则,并调用ipt_do_table( ),进行规则的遍历,并执行目标。

返回值:不成功时返回相应的错误码。

2.4.2.6 核心代码注释

nf_nat_fn( )是nat hook的主处理函数,其它几个钩子函数最终都调用这个函数。nf_nat_fn( )函数会根据连接信息结构体ip_conntrack_info,也就是连接的方向,判断是发送的包还是回应的包。如果是发送的包,会首先调用nf_nat_rule_find( )函数查找规则,并调用ipt_do_table( ),进行规则的遍历,并执行目标为SNAT的操作。

static unsigned int nf_nat_fn(unsigned int hooknum,struct sk_buff *skb,

const struct net_device *in,const struct net_device *out,

int (*okfn)(struct sk_buff *))

{

struct nf_conn *ct;

enum ip_conntrack_info ctinfo;

struct nf_conn_nat *nat;

/*标志snat还是dnat转换*/

enum nf_nat_manip_type maniptype = HOOK2MANIP(hooknum)

NF_CT_ASSERT(!(ip_hdr(skb)-

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部