netfilter: nat: update hash bucket if nat changed after ct confirmed
Subsystems (3)
PATCH 1/3 netfilter: nat: update hash bucket if nat changed after ct confirmed
From: Xiaoping Fan <[email protected]>
In some situations, NAT information is created after connection is confirmed. Since 5 tuple for reply direction is changed when creating NAT information, so we need to update hash bucket of connection.
Signed-off-by Xiaoping Fan <[email protected]>
--- include/net/netfilter/nf_conntrack.h | 5 ++++ net/netfilter/nf_conntrack_core.c | 51 ++++++++++++++++++++++++++++++++++-- net/netfilter/nf_nat_core.c | 9 +++++++ 3 files changed, 63 insertions(+), 2 deletions(-)
include/net/netfilter/nf_conntrack.h +5 -0
@@ -191,6 +191,9 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls);void nf_ct_free_hashtable (void *hash,unsigned int size);int nf_conntrack_hash_check_insert (struct nf_conn *ct); +void nf_conntrack_ct_hash_bucket_update (struct nf_conn *ct, +unsigned int old_hash, +unsigned int old_reply_hash);bool nf_ct_delete (struct nf_conn *ct,u32 pid,int report); bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
@@ -305,6 +308,8 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp);int nf_conntrack_hash_resize (unsigned int hashsize);extern unsigned int nf_conntrack_htable_size;extern unsigned int nf_conntrack_max; +u_int32_t hash_conntrack (const struct net *net, +const struct nf_conntrack_tuple *tuple); struct nf_conn *nf_ct_tmpl_alloc(struct net *net, const struct nf_conntrack_zone *zone,
net/netfilter/nf_conntrack_core.c +49 -2
66 lines not on this page · raw message
net/netfilter/nf_nat_core.c +9 -0
@@ -405,8 +405,10 @@ nf_nat_setup_info(struct nf_conn *ct,const struct nf_nat_range *range, enum nf_nat_manip_type maniptype) { + struct net *net = nf_ct_net(ct);struct nf_conntrack_tuple curr_tuple, new_tuple;struct nf_conn_nat *nat; +unsigned int old_hash, old_reply_hash;/* nat helper or nfctnetlink also setup binding */ nat =nf_ct_nat_ext_add (ct);
@@ -417,6 +419,11 @@ nf_nat_setup_info(struct nf_conn *ct, maniptype == NF_NAT_MANIP_DST);BUG_ON (nf_nat_initialized (ct, maniptype)); + old_hash =hash_conntrack (net, + &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple); + old_reply_hash =hash_conntrack (net, + &ct->tuplehash[IP_CT_DIR_REPLY ].tuple); +/* What we've got will look like inverse of reply. Normally * this is what is in the conntrack, except for prior * manipulations (future optimization: if num_manips == 0,
@@ -460,6 +467,8 @@ nf_nat_setup_info(struct nf_conn *ct,else ct->status |=IPS_SRC_NAT_DONE ; +nf_conntrack_ct_hash_bucket_update (ct, old_hash, old_reply_hash); +return NF_ACCEPT ; }EXPORT_SYMBOL (nf_nat_setup_info);
Signature · 1 line
1.9.1
Florian Westphal
maintainerQuoted 4 lines · [email protected] <[email protected]> wrote:
From: Xiaoping Fan <[email protected]>
In some situations, NAT information is created after connection is confirmed.
That sounds like a bug.
How can this happen?
nf_nat_setup_info() is only safe for non-confirmed conntracks (not in hash table).