zhanglin496 发表于 2015-11-06 10:46

init_conntrack函数

内核版本linux-4.0.5,init_conntrack函数中,这里为什么要禁用软中断,
        local_bh_disable();
        if (net->ct.expect_count) {
                spin_lock(&nf_conntrack_expect_lock);
                exp = nf_ct_find_expectation(net, zone, tuple);
                if (exp) {
                        pr_debug("conntrack: expectation arrives ct=%p exp=%p\n",
                               ct, exp);
                        /* Welcome, Mr. Bond.We've been expecting you... */
                        __set_bit(IPS_EXPECTED_BIT, &ct->status);



还有在__nf_conntrack_confirm插入hash表的时候也禁用了软中断,

        local_bh_disable();

        do {
                sequence = read_seqcount_begin(&net->ct.generation);
                /* reuse the hash saved before */
                hash = *(unsigned long *)&ct->tuplehash.hnnode.pprev;
                hash = hash_bucket(hash, net);
                reply_hash = hash_conntrack(net, zone,
                                           &ct->tuplehash.tuple);

        } while (nf_conntrack_double_lock(net, hash, reply_hash, sequence));


我感觉不需要禁用软中断啊,直接加锁就行了,本身就在软中断中执行。有熟悉的人指点下,谢谢!

philarlala 发表于 2015-11-06 17:08

同问,坐等大神回复

nswcfd 发表于 2015-11-09 14:58

包路径上的代码会关闭bh,说明这段代码有可能被其他路径调用,是转发路径和控制路径的公共函数。
否则的确没有必要。

zhanglin496 发表于 2016-08-31 16:15

可能是因为内部调用了NF_CT_STAT_INC做数据统计,需要禁止软中断,为什么不直接调用NF_CT_STAT_INC_ATOMIC?
页: [1]
查看完整版本: init_conntrack函数