From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nf-next,v2 1/2] netfilter: nfnetlink_queue: add helper function to retrieve hook entries
Date: Tue, 20 Oct 2026 19:45:57 +0200 [thread overview]
Message-ID: <20261020174558.1922531-1-pablo@netfilter.org> (raw)
Add nf_queue_hook_entry() and nf_queue_hook_entries() helper functions
to retrieve hook entries and use them.
This comes in preparation for a fix to restrict expectation creation to
nfnetlink_cthelper.
No functional changes are intended.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: no changes
net/netfilter/nfnetlink_queue.c | 43 ++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 00b76c25d55c..bd3567f29752 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -358,30 +358,45 @@ static int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry)
return ret;
}
+static const struct nf_hook_entries *
+nf_queue_hook_entries(struct nf_queue_entry *entry)
+{
+ const struct net *net = entry->state.net;
+ u8 pf = entry->state.pf;
+
+ return nf_hook_entries_head(net, pf, entry->state.hook);
+}
+
+static const struct nf_hook_entry *
+nf_queue_hook_entry(const struct nf_hook_entries *hooks,
+ struct nf_queue_entry *entry)
+{
+ unsigned int i = entry->hook_index;
+
+ if (i >= hooks->num_hook_entries)
+ return NULL;
+
+ return &hooks->hooks[i];
+}
+
/* caller must hold rcu read-side lock */
static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
{
const struct nf_hook_entry *hook_entry;
const struct nf_hook_entries *hooks;
struct sk_buff *skb = entry->skb;
- const struct net *net;
unsigned int i;
int err;
- u8 pf;
- net = entry->state.net;
- pf = entry->state.pf;
+ hooks = nf_queue_hook_entries(entry);
+ if (!hooks)
+ goto drop;
- hooks = nf_hook_entries_head(net, pf, entry->state.hook);
+ hook_entry = nf_queue_hook_entry(hooks, entry);
+ if (!hook_entry)
+ goto drop;
i = entry->hook_index;
- if (!hooks || i >= hooks->num_hook_entries) {
- kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP);
- nf_queue_entry_free(entry);
- return;
- }
-
- hook_entry = &hooks->hooks[i];
/* Continue traversal iff userspace said ok... */
if (verdict == NF_REPEAT)
@@ -417,6 +432,10 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
}
nf_queue_entry_free(entry);
+ return;
+drop:
+ kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP);
+ nf_queue_entry_free(entry);
}
/* return true if the entry has an unconfirmed conntrack attached that isn't owned by us
--
2.47.3
next reply other threads:[~2026-10-20 17:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 17:45 Pablo Neira Ayuso [this message]
2026-10-20 17:45 ` [PATCH nf-next,v2 2/2] netfilter: nfnetlink_queue: restrict NFQA_EXP to userspace helpers 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=20261020174558.1922531-1-pablo@netfilter.org \
--to=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.