在ipv4_conntrack_in函数中调用了nf_conntrack_in函数对数据包进行会话的建立,其中最关键的函数是resolve_normal_ct(),在该函数中有下面一段代码:
点击(此处)折叠或打开
-
h = nf_conntrack_find_get(net, &tuple);/*这里对会话进行查找,如果没有查找到,调用init_conntrack函数Allocate a new conntrack*/
-
if (!h) {
-
h = init_conntrack(net, &tuple, l3proto, l4proto, skb, dataoff, hooknum);
-
if (!h)
-
return NULL;
-
if (IS_ERR(h))
-
return (void *)h;
- }
点击(此处)折叠或打开
-
if (!l4proto->new(ct, skb, dataoff)) {
-
nf_conntrack_free(ct);
-
pr_debug("init conntrack: can't track with proto module\n");
-
/*return NULL; */
-
goto ERR;
- }
点击(此处)折叠或打开
-
static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,
-
unsigned int dataoff)
-
{
-
static const u_int8_t valid_new[] = {
-
[ICMP_ECHO] = 1,
-
[ICMP_TIMESTAMP] = 1,
-
[ICMP_INFO_REQUEST] = 1,
-
[ICMP_ADDRESS] = 1
-
};
-
-
if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new)
-
|| !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) {
-
/* Can't create a new ICMP `conn' with this. */
-
pr_debug("icmp: can't create new conn with type %u\n",
-
ct->tuplehash[0].tuple.dst.u.icmp.type);
-
nf_ct_dump_tuple_ip(&ct->tuplehash[0].tuple);
-
return false;
-
}
- return true;