为什么内核 function:get_next_corpse 在找到 nf_conn 后增加计数器?
Why does the kernel function:get_next_corpse increase counter after a nf_conn is found?
我正在阅读内核源代码并尝试了解ip conntrack的机制。如何理解函数 get_next_corpse 增加被发现要清理的 nf_conn 结构的计数器。
static struct nf_conn *
get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
void *data, unsigned int *bucket)
{
struct nf_conntrack_tuple_hash *h;
struct nf_conn *ct;
struct hlist_nulls_node *n;
spin_lock_bh(&nf_conntrack_lock);
for (; *bucket < nf_conntrack_htable_size; (*bucket)++) {
hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) {
ct = nf_ct_tuplehash_to_ctrack(h);
if (iter(ct, data))
goto found;
}
}
hlist_nulls_for_each_entry(h, n, &net->ct.unconfirmed, hnnode) {
ct = nf_ct_tuplehash_to_ctrack(h);
if (iter(ct, data))
set_bit(IPS_DYING_BIT, &ct->status);
}
spin_unlock_bh(&nf_conntrack_lock);
return NULL;
found:
atomic_inc(&ct->ct_general.use); //Why ??!
spin_unlock_bh(&nf_conntrack_lock);
return ct;
}
既然ct被发现要清洗,为什么还要atomic_inc(&ct->ct_general.use)?
只是为了保持 concurrency/preemption.
连接跟踪的一致性
就像OS教科书介绍的P/V操作
我正在阅读内核源代码并尝试了解ip conntrack的机制。如何理解函数 get_next_corpse 增加被发现要清理的 nf_conn 结构的计数器。
static struct nf_conn *
get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
void *data, unsigned int *bucket)
{
struct nf_conntrack_tuple_hash *h;
struct nf_conn *ct;
struct hlist_nulls_node *n;
spin_lock_bh(&nf_conntrack_lock);
for (; *bucket < nf_conntrack_htable_size; (*bucket)++) {
hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) {
ct = nf_ct_tuplehash_to_ctrack(h);
if (iter(ct, data))
goto found;
}
}
hlist_nulls_for_each_entry(h, n, &net->ct.unconfirmed, hnnode) {
ct = nf_ct_tuplehash_to_ctrack(h);
if (iter(ct, data))
set_bit(IPS_DYING_BIT, &ct->status);
}
spin_unlock_bh(&nf_conntrack_lock);
return NULL;
found:
atomic_inc(&ct->ct_general.use); //Why ??!
spin_unlock_bh(&nf_conntrack_lock);
return ct;
}
既然ct被发现要清洗,为什么还要atomic_inc(&ct->ct_general.use)?
只是为了保持 concurrency/preemption.
连接跟踪的一致性就像OS教科书介绍的P/V操作