From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net 06/15] netfilter: nat: include zone id in nat table hash again
Date: Sat, 25 Sep 2021 00:11:04 +0200 [thread overview]
Message-ID: <20210924221113.348767-7-pablo@netfilter.org> (raw)
In-Reply-To: <20210924221113.348767-1-pablo@netfilter.org>
From: Florian Westphal <fw@strlen.de>
Similar to the conntrack change, also use the zone id for the nat source
lists if the zone id is valid in both directions.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_nat_core.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 7008961f5cb0..273117683922 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -150,13 +150,16 @@ static void __nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl)
/* We keep an extra hash for each conntrack, for fast searching. */
static unsigned int
-hash_by_src(const struct net *n, const struct nf_conntrack_tuple *tuple)
+hash_by_src(const struct net *net,
+ const struct nf_conntrack_zone *zone,
+ const struct nf_conntrack_tuple *tuple)
{
unsigned int hash;
struct {
struct nf_conntrack_man src;
u32 net_mix;
u32 protonum;
+ u32 zone;
} __aligned(SIPHASH_ALIGNMENT) combined;
get_random_once(&nf_nat_hash_rnd, sizeof(nf_nat_hash_rnd));
@@ -165,9 +168,13 @@ hash_by_src(const struct net *n, const struct nf_conntrack_tuple *tuple)
/* Original src, to ensure we map it consistently if poss. */
combined.src = tuple->src;
- combined.net_mix = net_hash_mix(n);
+ combined.net_mix = net_hash_mix(net);
combined.protonum = tuple->dst.protonum;
+ /* Zone ID can be used provided its valid for both directions */
+ if (zone->dir == NF_CT_DEFAULT_ZONE_DIR)
+ combined.zone = zone->id;
+
hash = siphash(&combined, sizeof(combined), &nf_nat_hash_rnd);
return reciprocal_scale(hash, nf_nat_htable_size);
@@ -272,7 +279,7 @@ find_appropriate_src(struct net *net,
struct nf_conntrack_tuple *result,
const struct nf_nat_range2 *range)
{
- unsigned int h = hash_by_src(net, tuple);
+ unsigned int h = hash_by_src(net, zone, tuple);
const struct nf_conn *ct;
hlist_for_each_entry_rcu(ct, &nf_nat_bysource[h], nat_bysource) {
@@ -619,7 +626,7 @@ nf_nat_setup_info(struct nf_conn *ct,
unsigned int srchash;
spinlock_t *lock;
- srchash = hash_by_src(net,
+ srchash = hash_by_src(net, nf_ct_zone(ct),
&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
lock = &nf_nat_locks[srchash % CONNTRACK_LOCKS];
spin_lock_bh(lock);
@@ -788,7 +795,7 @@ static void __nf_nat_cleanup_conntrack(struct nf_conn *ct)
{
unsigned int h;
- h = hash_by_src(nf_ct_net(ct), &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
+ h = hash_by_src(nf_ct_net(ct), nf_ct_zone(ct), &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
spin_lock_bh(&nf_nat_locks[h % CONNTRACK_LOCKS]);
hlist_del_rcu(&ct->nat_bysource);
spin_unlock_bh(&nf_nat_locks[h % CONNTRACK_LOCKS]);
--
2.30.2
next prev parent reply other threads:[~2021-09-24 22:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-24 22:10 [PATCH net 00/15] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2021-09-24 22:10 ` [PATCH net 01/15] netfilter: ipset: Fix oversized kvmalloc() calls Pablo Neira Ayuso
2021-09-25 3:40 ` patchwork-bot+netdevbpf
2021-09-24 22:11 ` [PATCH net 02/15] ipvs: check that ip_vs_conn_tab_bits is between 8 and 20 Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 03/15] netfilter: ip6_tables: zero-initialize fragment offset Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 04/15] netfilter: conntrack: make max chain length random Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 05/15] netfilter: conntrack: include zone id in tuple hash again Pablo Neira Ayuso
2021-09-24 22:11 ` Pablo Neira Ayuso [this message]
2021-09-24 22:11 ` [PATCH net 07/15] selftests: netfilter: add selftest for directional zone support Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 08/15] selftests: netfilter: add zone stress test with colliding tuples Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 09/15] netfilter: nf_tables: unlink table before deleting it Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 10/15] netfilter: nf_tables: Fix oversized kvmalloc() calls Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 11/15] netfilter: nf_nat_masquerade: make async masq_inet6_event handling generic Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 12/15] netfilter: nf_nat_masquerade: defer conntrack walk to work queue Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 13/15] netfilter: iptable_raw: drop bogus net_init annotation Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 14/15] netfilter: log: work around missing softdep backend module Pablo Neira Ayuso
2021-09-24 22:11 ` [PATCH net 15/15] netfilter: conntrack: serialize hash resizes and cleanups Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210924221113.348767-7-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).