netfilter: nf_ct_expect: Add nf_ct_remove_expect()
When remove one expect, it needs three statements. And there are multiple duplicated codes in current code. So add one common function nf_ct_remove_expect to consolidate this. Signed-off-by: Gao Feng <fgao@ikuai8.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
parent
92f73221f9
commit
ec0e3f0111
|
@ -105,6 +105,7 @@ static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
|
||||||
|
|
||||||
void nf_ct_remove_expectations(struct nf_conn *ct);
|
void nf_ct_remove_expectations(struct nf_conn *ct);
|
||||||
void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
|
void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
|
||||||
|
bool nf_ct_remove_expect(struct nf_conntrack_expect *exp);
|
||||||
|
|
||||||
/* Allocate space for an expectation: this is mandatory before calling
|
/* Allocate space for an expectation: this is mandatory before calling
|
||||||
nf_ct_expect_related. You will have to call put afterwards. */
|
nf_ct_expect_related. You will have to call put afterwards. */
|
||||||
|
|
|
@ -103,6 +103,17 @@ nf_ct_exp_equal(const struct nf_conntrack_tuple *tuple,
|
||||||
nf_ct_zone_equal_any(i->master, zone);
|
nf_ct_zone_equal_any(i->master, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nf_ct_remove_expect(struct nf_conntrack_expect *exp)
|
||||||
|
{
|
||||||
|
if (del_timer(&exp->timeout)) {
|
||||||
|
nf_ct_unlink_expect(exp);
|
||||||
|
nf_ct_expect_put(exp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(nf_ct_remove_expect);
|
||||||
|
|
||||||
struct nf_conntrack_expect *
|
struct nf_conntrack_expect *
|
||||||
__nf_ct_expect_find(struct net *net,
|
__nf_ct_expect_find(struct net *net,
|
||||||
const struct nf_conntrack_zone *zone,
|
const struct nf_conntrack_zone *zone,
|
||||||
|
@ -211,10 +222,7 @@ void nf_ct_remove_expectations(struct nf_conn *ct)
|
||||||
|
|
||||||
spin_lock_bh(&nf_conntrack_expect_lock);
|
spin_lock_bh(&nf_conntrack_expect_lock);
|
||||||
hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
|
hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
|
||||||
if (del_timer(&exp->timeout)) {
|
nf_ct_remove_expect(exp);
|
||||||
nf_ct_unlink_expect(exp);
|
|
||||||
nf_ct_expect_put(exp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
spin_unlock_bh(&nf_conntrack_expect_lock);
|
spin_unlock_bh(&nf_conntrack_expect_lock);
|
||||||
}
|
}
|
||||||
|
@ -255,10 +263,7 @@ static inline int expect_matches(const struct nf_conntrack_expect *a,
|
||||||
void nf_ct_unexpect_related(struct nf_conntrack_expect *exp)
|
void nf_ct_unexpect_related(struct nf_conntrack_expect *exp)
|
||||||
{
|
{
|
||||||
spin_lock_bh(&nf_conntrack_expect_lock);
|
spin_lock_bh(&nf_conntrack_expect_lock);
|
||||||
if (del_timer(&exp->timeout)) {
|
nf_ct_remove_expect(exp);
|
||||||
nf_ct_unlink_expect(exp);
|
|
||||||
nf_ct_expect_put(exp);
|
|
||||||
}
|
|
||||||
spin_unlock_bh(&nf_conntrack_expect_lock);
|
spin_unlock_bh(&nf_conntrack_expect_lock);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_ct_unexpect_related);
|
EXPORT_SYMBOL_GPL(nf_ct_unexpect_related);
|
||||||
|
@ -394,10 +399,8 @@ static void evict_oldest_expect(struct nf_conn *master,
|
||||||
last = exp;
|
last = exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last && del_timer(&last->timeout)) {
|
if (last)
|
||||||
nf_ct_unlink_expect(last);
|
nf_ct_remove_expect(last);
|
||||||
nf_ct_expect_put(last);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
|
static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
|
||||||
|
@ -419,11 +422,8 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
|
||||||
h = nf_ct_expect_dst_hash(net, &expect->tuple);
|
h = nf_ct_expect_dst_hash(net, &expect->tuple);
|
||||||
hlist_for_each_entry_safe(i, next, &nf_ct_expect_hash[h], hnode) {
|
hlist_for_each_entry_safe(i, next, &nf_ct_expect_hash[h], hnode) {
|
||||||
if (expect_matches(i, expect)) {
|
if (expect_matches(i, expect)) {
|
||||||
if (del_timer(&i->timeout)) {
|
if (nf_ct_remove_expect(expect))
|
||||||
nf_ct_unlink_expect(i);
|
|
||||||
nf_ct_expect_put(i);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
} else if (expect_clash(i, expect)) {
|
} else if (expect_clash(i, expect)) {
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -451,11 +451,8 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
|
||||||
if ((rcu_dereference_protected(
|
if ((rcu_dereference_protected(
|
||||||
help->helper,
|
help->helper,
|
||||||
lockdep_is_held(&nf_conntrack_expect_lock)
|
lockdep_is_held(&nf_conntrack_expect_lock)
|
||||||
) == me || exp->helper == me) &&
|
) == me || exp->helper == me))
|
||||||
del_timer(&exp->timeout)) {
|
nf_ct_remove_expect(exp);
|
||||||
nf_ct_unlink_expect(exp);
|
|
||||||
nf_ct_expect_put(exp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spin_unlock_bh(&nf_conntrack_expect_lock);
|
spin_unlock_bh(&nf_conntrack_expect_lock);
|
||||||
|
|
|
@ -829,10 +829,8 @@ static void flush_expectations(struct nf_conn *ct, bool media)
|
||||||
hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
|
hlist_for_each_entry_safe(exp, next, &help->expectations, lnode) {
|
||||||
if ((exp->class != SIP_EXPECT_SIGNALLING) ^ media)
|
if ((exp->class != SIP_EXPECT_SIGNALLING) ^ media)
|
||||||
continue;
|
continue;
|
||||||
if (!del_timer(&exp->timeout))
|
if (!nf_ct_remove_expect(exp))
|
||||||
continue;
|
continue;
|
||||||
nf_ct_unlink_expect(exp);
|
|
||||||
nf_ct_expect_put(exp);
|
|
||||||
if (!media)
|
if (!media)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue