From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, me@ubique.spb.ru,
Florian Westphal <fw@strlen.de>
Subject: [PATCH RFC nf-next 2/9] netfilter: nat: split nat hook iteration into a helper
Date: Thu, 14 Oct 2021 14:10:39 +0200 [thread overview]
Message-ID: <20211014121046.29329-4-fw@strlen.de> (raw)
In-Reply-To: <20211014121046.29329-1-fw@strlen.de>
Makes conversion in followup patch simpler.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_nat_core.c | 46 +++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 273117683922..a6a273fff3f6 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -699,6 +699,32 @@ unsigned int nf_nat_packet(struct nf_conn *ct,
}
EXPORT_SYMBOL_GPL(nf_nat_packet);
+static unsigned int nf_nat_inet_run_hooks(const struct nf_hook_state *state,
+ struct sk_buff *skb,
+ struct nf_conn *ct,
+ struct nf_nat_lookup_hook_priv *lpriv)
+{
+ enum nf_nat_manip_type maniptype = HOOK2MANIP(state->hook);
+ struct nf_hook_entries *e = rcu_dereference(lpriv->entries);
+ unsigned int ret;
+ int i;
+
+ if (!e)
+ goto null_bind;
+
+ for (i = 0; i < e->num_hook_entries; i++) {
+ ret = e->hooks[i].hook(e->hooks[i].priv, skb, state);
+ if (ret != NF_ACCEPT)
+ return ret;
+
+ if (nf_nat_initialized(ct, maniptype))
+ return NF_ACCEPT;
+ }
+
+null_bind:
+ return nf_nat_alloc_null_binding(ct, state->hook);
+}
+
unsigned int
nf_nat_inet_fn(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
@@ -730,23 +756,9 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,
*/
if (!nf_nat_initialized(ct, maniptype)) {
struct nf_nat_lookup_hook_priv *lpriv = priv;
- struct nf_hook_entries *e = rcu_dereference(lpriv->entries);
unsigned int ret;
- int i;
-
- if (!e)
- goto null_bind;
-
- for (i = 0; i < e->num_hook_entries; i++) {
- ret = e->hooks[i].hook(e->hooks[i].priv, skb,
- state);
- if (ret != NF_ACCEPT)
- return ret;
- if (nf_nat_initialized(ct, maniptype))
- goto do_nat;
- }
-null_bind:
- ret = nf_nat_alloc_null_binding(ct, state->hook);
+
+ ret = nf_nat_inet_run_hooks(state, skb, ct, lpriv);
if (ret != NF_ACCEPT)
return ret;
} else {
@@ -765,7 +777,7 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,
if (nf_nat_oif_changed(state->hook, ctinfo, nat, state->out))
goto oif_changed;
}
-do_nat:
+
return nf_nat_packet(ct, ctinfo, state->hook, skb);
oif_changed:
--
2.32.0
next prev parent reply other threads:[~2021-10-14 12:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 12:10 [PATCH RFC nf-next 0/9] netfilter: bpf base hook program generator Florian Westphal
2021-10-14 12:10 ` [PATCH 1/1] netfilter: add " Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 1/9] netfilter: nf_queue: carry index in hook state Florian Westphal
2021-10-14 12:10 ` Florian Westphal [this message]
2021-10-14 12:10 ` [PATCH RFC nf-next 3/9] netfilter: remove hook index from nf_hook_slow arguments Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 4/9] netfilter: make hook functions accept only one argument Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 5/9] netfilter: reduce allowed hook count to 32 Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 6/9] netfilter: add bpf base hook program generator Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 7/9] netfilter: core: do not rebuild bpf program on dying netns Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 8/9] netfilter: ingress: switch to invocation via bpf Florian Westphal
2021-10-14 12:10 ` [PATCH RFC nf-next 9/9] netfilter: hook_jit: add prog cache Florian Westphal
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=20211014121046.29329-4-fw@strlen.de \
--to=fw@strlen.de \
--cc=bpf@vger.kernel.org \
--cc=me@ubique.spb.ru \
--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).