netfilter: conntrack: simplify the code by using nf_conntrack_get_ht
Since commit 64b87639c9
("netfilter: conntrack: fix race between
nf_conntrack proc read and hash resize") introduce the
nf_conntrack_get_ht, so there's no need to check nf_conntrack_generation
again and again to get the hash table and hash size. And convert
nf_conntrack_get_ht to inline function here.
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:

committed by
Pablo Neira Ayuso

parent
adf0516845
commit
92e47ba883
@@ -303,9 +303,29 @@ struct kernel_param;
|
||||
|
||||
int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp);
|
||||
int nf_conntrack_hash_resize(unsigned int hashsize);
|
||||
|
||||
extern struct hlist_nulls_head *nf_conntrack_hash;
|
||||
extern unsigned int nf_conntrack_htable_size;
|
||||
extern seqcount_t nf_conntrack_generation;
|
||||
extern unsigned int nf_conntrack_max;
|
||||
|
||||
/* must be called with rcu read lock held */
|
||||
static inline void
|
||||
nf_conntrack_get_ht(struct hlist_nulls_head **hash, unsigned int *hsize)
|
||||
{
|
||||
struct hlist_nulls_head *hptr;
|
||||
unsigned int sequence, hsz;
|
||||
|
||||
do {
|
||||
sequence = read_seqcount_begin(&nf_conntrack_generation);
|
||||
hsz = nf_conntrack_htable_size;
|
||||
hptr = nf_conntrack_hash;
|
||||
} while (read_seqcount_retry(&nf_conntrack_generation, sequence));
|
||||
|
||||
*hash = hptr;
|
||||
*hsize = hsz;
|
||||
}
|
||||
|
||||
struct nf_conn *nf_ct_tmpl_alloc(struct net *net,
|
||||
const struct nf_conntrack_zone *zone,
|
||||
gfp_t flags);
|
||||
|
@@ -51,8 +51,6 @@ bool nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
|
||||
const struct nf_conntrack_l3proto *l3proto,
|
||||
const struct nf_conntrack_l4proto *l4proto);
|
||||
|
||||
void nf_conntrack_get_ht(struct hlist_nulls_head **hash, unsigned int *hsize);
|
||||
|
||||
/* Find a connection corresponding to a tuple. */
|
||||
struct nf_conntrack_tuple_hash *
|
||||
nf_conntrack_find_get(struct net *net,
|
||||
@@ -83,7 +81,6 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
|
||||
|
||||
#define CONNTRACK_LOCKS 1024
|
||||
|
||||
extern struct hlist_nulls_head *nf_conntrack_hash;
|
||||
extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];
|
||||
void nf_conntrack_lock(spinlock_t *lock);
|
||||
|
||||
|
Reference in New Issue
Block a user