netfilter: expect: Add one common func nf_ct_remove_expect to simplify codes
Subsystems (2)
PATCH 1/1 netfilter: expect: Add one common func nf_ct_remove_expect to simplify codes
From: Gao Feng <[email protected]>
When remove one expect, it needs three statements. And there are multiple duplicated codes in current codes. So add one common func nf_ct_remove_expect to simplify the codes.
--- include/net/netfilter/nf_conntrack_expect.h | 1 + net/netfilter/nf_conntrack_expect.c | 33 +++++++++++++++-------------- net/netfilter/nf_conntrack_helper.c | 6 ++---- net/netfilter/nf_conntrack_sip.c | 4 +--- 4 files changed, 21 insertions(+), 23 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -104,6 +104,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_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 nf_ct_expect_related. You will have to call put afterwards. */
net/netfilter/nf_conntrack_expect.c +17 -16
@@ -103,6 +103,18 @@ static unsigned int nf_ct_expect_dst_hash(const struct net *n, const struct nf_cnf_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 * __nf_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone,
@@ -211,10 +223,7 @@ void nf_ct_remove_expectations(struct nf_conn *ct)spin_lock_bh (&nf_conntrack_expect_lock);hlist_for_each_entry_safe (exp, next, &help->expectations, lnode) { -if (del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); -nf_ct_expect_put (exp); - } +nf_ct_remove_expect (exp); }spin_unlock_bh (&nf_conntrack_expect_lock); }
@@ -255,10 +264,7 @@ static inline int expect_matches(const struct nf_conntrack_expect *a,void nf_ct_unexpect_related (struct nf_conntrack_expect *exp) {spin_lock_bh (&nf_conntrack_expect_lock); -if (del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); -nf_ct_expect_put (exp); - } +nf_ct_remove_expect (exp);spin_unlock_bh (&nf_conntrack_expect_lock); }EXPORT_SYMBOL_GPL (nf_ct_unexpect_related);
@@ -394,10 +400,8 @@ static void evict_oldest_expect(struct nf_conn *master, last = exp; } -if (last &&del_timer (&last->timeout)) { -nf_ct_unlink_expect (last); -nf_ct_expect_put (last); - } +if (last) +nf_ct_remove_expect (last); }static inline int __nf_ct_expect_check (struct nf_conntrack_expect *expect)
@@ -419,11 +423,8 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect) h =nf_ct_expect_dst_hash (net, &expect->tuple);hlist_for_each_entry_safe (i, next, &nf_ct_expect_hash[h], hnode) {if (expect_matches (i, expect)) { -if (del_timer (&i->timeout)) { -nf_ct_unlink_expect (i); -nf_ct_expect_put (i); +if (nf_ct_remove_expect (expect))break ; - } }else if (expect_clash (i, expect)) { ret = -EBUSY ; goto out;
net/netfilter/nf_conntrack_helper.c +2 -4
@@ -448,10 +448,8 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)if ((rcu_dereference_protected ( help->helper,lockdep_is_held (&nf_conntrack_expect_lock) - ) == me || exp->helper == me) && -del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); -nf_ct_expect_put (exp); + ) == me || exp->helper == me)) { +nf_ct_remove_expect (exp); } } }
net/netfilter/nf_conntrack_sip.c +1 -3
@@ -829,10 +829,8 @@ static void flush_expectations(struct nf_conn *ct, bool media)hlist_for_each_entry_safe (exp, next, &help->expectations, lnode) {if ((exp->class !=SIP_EXPECT_SIGNALLING ) ^ media)continue ; -if (!del_timer (&exp->timeout)) +if (!nf_ct_remove_expect (exp))continue ; -nf_ct_unlink_expect (exp); -nf_ct_expect_put (exp);if (!media)break ; }
Signature · 1 line
1.9.1
Pablo Neira Ayuso
maintainerQuoted 5 lines · On Mon, Mar 27, 2017 at 10:31:26AM +0800, [email protected] wrote:
From: Gao Feng <[email protected]>
When remove one expect, it needs three statements. And there are multiple duplicated codes in current codes. So add one common func
nf_ct_remove_expectto simplify the codes.
Applied with short name:
netfilter: nf_ct_expect: Add nf_ct_remove_expect()
And...
Quoted 5 lines
net/netfilter/nf_conntrack_helper.c +0
-0
net/netfilter/nf_conntrack_helper.c void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me) · line 453
Quoted 10 lines
net/netfilter/nf_conntrack_helper.c +2
-4@@ -448,10 +448,8 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)if ((rcu_dereference_protected ( help->helper,lockdep_is_held (&nf_conntrack_expect_lock) - ) == me || exp->helper == me) && -del_timer (&exp->timeout)) { -nf_ct_unlink_expect (exp); -nf_ct_expect_put (exp); + ) == me || exp->helper == me)) { +nf_ct_remove_expect (exp); }
We can now remove braces for single statement in if(), I've done this manually here.