linux镜像confirm,__ip_conntrack_confirm(struct sk_buff **pskb)扔包的一个疑惑

下面是这个函数,请看最后一行drop操作的疑惑:

/* Confirm a connection given skb; places it in hash table */

int

__ip_conntrack_confirm(struct sk_buff **pskb)

{

unsigned int hash, repl_hash;

struct ip_conntrack *ct;

enum ip_conntrack_info ctinfo;

ct = ip_conntrack_get(*pskb, &ctinfo);

/* ipt_REJECT uses ip_conntrack_attach to attach related

ICMP/TCP RST packets in other direction.  Actual packet

which created connection will be IP_CT_NEW or for an

expected connection, IP_CT_RELATED. */

if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) //ip_conntrack_confirm() blocked confirmed packet

return NF_ACCEPT; //so only confirm original and unconfirmed packet

hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);

repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);

/* We're not in hash table, and we refuse to set up related

connections for unconfirmed conns.  But packet copies and

REJECT will give spurious warnings here. */

/* IP_NF_ASSERT(atomic_read(&ct->ct_general.use) == 1); */

/* No external references means noone else could have

confirmed us. */

IP_NF_ASSERT(!is_confirmed(ct));

DEBUGP("Confirming conntrack %p\n", ct);

write_lock_bh(&ip_conntrack_lock);

/* See if there's one in the list already, including reverse:

NAT could have grabbed it without realizing, since we're

not in the hash.  If there is, we lost race. */

if (!LIST_FIND(&ip_conntrack_hash[hash],

conntrack_tuple_cmp,

struct ip_conntrack_tuple_hash *,

&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, NULL)

&& !LIST_FIND(&ip_conntrack_hash[repl_hash],

conntrack_tuple_cmp,

struct ip_conntrack_tuple_hash *,

&ct->tuplehash[IP_CT_DIR_REPLY].tuple, NULL)) {

/* Remove from unconfirmed list */

list_del(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list);

__ip_conntrack_hash_insert(ct, hash, repl_hash); //insert in ct hash table

/* Timer relative to confirmation time, not original

setting time, otherwise we'd get timer wrap in

weird delay cases. */

ct->timeout.expires += jiffies;

add_timer(&ct->timeout);

atomic_inc(&ct->ct_general.use);

set_bit(IPS_CONFIRMED_BIT, &ct->status);

CONNTRACK_STAT_INC(insert);

write_unlock_bh(&ip_conntrack_lock);

if (ct->helper)

ip_conntrack_event_cache(IPCT_HELPER, *pskb);

#ifdef CONFIG_IP_NF_NAT_NEEDED

if (test_bit(IPS_SRC_NAT_DONE_BIT, &ct->status) ||

test_bit(IPS_DST_NAT_DONE_BIT, &ct->status))

ip_conntrack_event_cache(IPCT_NATINFO, *pskb);

#endif

ip_conntrack_event_cache(master_ct(ct) ?

IPCT_RELATED : IPCT_NEW, *pskb);

return NF_ACCEPT;

}

CONNTRACK_STAT_INC(insert_failed);

write_unlock_bh(&ip_conntrack_lock);

return NF_DROP; //why drop? 前面条件判断该tuple是否已经加入tuple_hash链表,程序走到这里说明已经有同一个tuple的另外一个包已经把tuple加入hash链表了,当前这个包“we lost race”了,但是这一个包为什么要drop掉呢?

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值