netfilter: updates for net-next
Subsystems (4)
Florian Westphal
maintainercover netfilter: updates for net-next
Hi,
The following patchset contains Netfilter fixes for *net-next*:
1) prefer vmalloc_array in ebtables, from Qianfeng Rong.
2) Use csum_replace4 instead of open-coding it, from Christophe Leroy. 3+4) Get rid of GFP_ATOMIC in transaction object allocations, those cause silly failures with large sets under memory pressure, from myself.
5) Introduce new NFTA_DEVICE_PREFIX attribute in nftables netlink api, re-using old NFTA_DEVICE_NAME led to confusion with different kernel/userspace versions. This refines the wildcard interface support added in 6.16 release. From Phil Sutter.
6) Remove test for AVX cpu feature in nftables pipapo set type, testing for AVX2 feature is sufficient.
7) Unexport a few function in nf_reject infra: no external callers.
8) Extend payload offset to u16, this was restricted to values <=255 so far, from Fernando Fernandez Mancera.
Please, pull these changes from:
The following changes since commit 864ecc4a6dade82d3f70eab43dad0e277aa6fc78:
Merge branch 'net-add-rcu-safety-to-dst-dev' (2025-08-29 19:36:34 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git tags/nf-next-25-09-01
for you to fetch changes up to 0618948e58e09e1ebf59078bf5b7841bbd1ce1d2:
netfilter: nft_payload: extend offset to 65535 bytes (2025-09-01 09:53:17 +0200)
----------------------------------------------------------------
netfilter pull request nf-next-25-09-01
----------------------------------------------------------------
Christophe Leroy (1):
netfilter: nft_payload: Use csum_replace4() instead of opencoding
Fernando Fernandez Mancera (1):
netfilter: nft_payload: extend offset to 65535 bytes
Florian Westphal (4):
netfilter: nf_tables: allow iter callbacks to sleep
netfilter: nf_tables: all transaction allocations can now sleep
netfilter: nft_set_pipapo: remove redundant test for avx feature bit
netfilter: nf_reject: remove unneeded exports
Phil Sutter (1):
netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
Qianfeng Rong (1):
netfilter: ebtables: Use vmalloc_array() to improve code
include/net/netfilter/ipv4/nf_reject.h | 8 -- include/net/netfilter/ipv6/nf_reject.h | 10 --- include/net/netfilter/nf_tables.h | 2 + include/net/netfilter/nf_tables_core.h | 2 +- include/uapi/linux/netfilter/nf_tables.h | 2 + net/bridge/netfilter/ebtables.c | 14 ++-- net/ipv4/netfilter/nf_reject_ipv4.c | 27 +++--- net/ipv6/netfilter/nf_reject_ipv6.c | 37 ++++++--- net/netfilter/nf_tables_api.c | 89 +++++++++++--------- net/netfilter/nft_payload.c | 20 +++-- net/netfilter/nft_set_hash.c | 100 ++++++++++++++++++++++- net/netfilter/nft_set_pipapo.c | 3 +- net/netfilter/nft_set_pipapo_avx2.c | 2 +- net/netfilter/nft_set_rbtree.c | 35 ++++++-- 14 files changed, 242 insertions(+), 109 deletions(-)
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 1/8 netfilter: ebtables: Use vmalloc_array() to improve code
From: Qianfeng Rong <[email protected]>
Remove array_size() calls and replace vmalloc() with vmalloc_array() to simplify the code. vmalloc_array() is also optimized better, uses fewer instructions, and handles overflow more concisely[1].
[1]: https://lore.kernel.org/lkml/[email protected]/
--- net/bridge/netfilter/ebtables.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/bridge/netfilter/ebtables.c +7 -7
@@ -920,8 +920,8 @@ static int translate_table(struct net *net, const char *name,* if an error occurs */ newinfo->chainstack = -vmalloc (array_size (nr_cpu_ids, -sizeof (*(newinfo->chainstack)))); +vmalloc_array (nr_cpu_ids, +sizeof (*(newinfo->chainstack)));if (!newinfo->chainstack)return -ENOMEM ;for_each_possible_cpu (i) {
@@ -938,7 +938,7 @@ static int translate_table(struct net *net, const char *name, } } - cl_s =vmalloc (array_size (udc_cnt,sizeof (*cl_s))); + cl_s =vmalloc_array (udc_cnt,sizeof (*cl_s));if (!cl_s)return -ENOMEM ; i =0 ;/* the i'th udc */
@@ -1018,8 +1018,8 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,* the check on the size is done later, when we have the lock */ if (repl->num_counters) { -unsigned long size = repl->num_counters *sizeof (*counterstmp); - counterstmp =vmalloc (size); + counterstmp =vmalloc_array (repl->num_counters, +sizeof (*counterstmp));if (!counterstmp)return -ENOMEM ; }
@@ -1386,7 +1386,7 @@ static int do_update_counters(struct net *net, const char *name,if (num_counters ==0 )return -EINVAL ; - tmp =vmalloc (array_size (num_counters,sizeof (*tmp))); + tmp =vmalloc_array (num_counters,sizeof (*tmp));if (!tmp)return -ENOMEM ;
@@ -1526,7 +1526,7 @@ static int copy_counters_to_user(struct ebt_table *t,if (num_counters != nentries)return -EINVAL ; - counterstmp =vmalloc (array_size (nentries,sizeof (*counterstmp))); + counterstmp =vmalloc_array (nentries,sizeof (*counterstmp));if (!counterstmp)return -ENOMEM ;
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 2/8 netfilter: nft_payload: Use csum_replace4() instead of opencoding
In reply to Florian WestphalFrom: Christophe Leroy <[email protected]>
Open coded calculation can be avoided and replaced by the equivalent csum_replace4() in nft_csum_replace().
--- net/netfilter/nft_payload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_payload.c +1 -1
@@ -684,7 +684,7 @@ static const struct nft_expr_ops nft_payload_inner_ops = {static inline void nft_csum_replace (__sum16 *sum,__wsum fsum,__wsum tsum) { - *sum =csum_fold (csum_add (csum_sub (~csum_unfold (*sum), fsum), tsum)); +csum_replace4 (sum, (__force __be32 )fsum, (__force __be32 )tsum);if (*sum ==0 ) *sum =CSUM_MANGLED_0 ; }
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 3/8 netfilter: nf_tables: allow iter callbacks to sleep
In reply to Florian WestphalQuoting Sven Auhagen:
we do see on occasions that we get the following error message, more so on x86 systems than on arm64:
Error: Could not process rule: Cannot allocate memory delete table inet filter
It is not a consistent error and does not happen all the time. We are on Kernel 6.6.80, seems to me like we have something along the lines of the nf_tables: allow clone callbacks to sleep problem using GFP_ATOMIC.
As hinted at by Sven, this is because of GFP_ATOMIC allocations during set flush.
When set is flushed, all elements are deactivated. This triggers a set walk and each element gets added to the transaction list.
The rbtree and rhashtable sets don't allow the iter callback to sleep:
rbtree walk acquires read side of an rwlock with bh disabled, rhashtable walk happens with rcu read lock held.
Rbtree is simple enough to resolve:
When the walk context is ITER_READ, no change is needed (the iter callback must not deactivate elements; we're not in a transaction).
When the iter type is ITER_UPDATE, the rwlock isn't needed because the caller holds the transaction mutex, this prevents any and all changes to the ruleset, including add/remove of set elements.
Rhashtable is slightly more complex.
When the iter type is ITER_READ, no change is needed, like rbtree.
For ITER_UPDATE, we hold transaction mutex which prevents elements from getting free'd, even outside of rcu read lock section.
So build a temporary list of all elements while doing the rcu iteration and then call the iterator in a second pass.
The disadvantage is the need to iterate twice, but this cost comes with the benefit to allow the iter callback to use GFP_KERNEL allocations in a followup patch.
The new list based logic makes it necessary to catch recursive calls to the same set earlier.
Such walk -> iter -> walk recursion for the same set can happen during ruleset validation in case userspace gave us a bogus (cyclic) ruleset where verdict map m jumps to chain that sooner or later also calls "vmap @m".
Before the new ->in_update_walk test, the ruleset is rejected because the infinite recursion causes ctx->level to exceed the allowed maximum.
But with the new logic added here, elements would get skipped:
nft_rhash_walk_update would see elements that are on the walk_list of an older stack frame.
As all recursive calls into same map results in -EMLINK, we can avoid this problem by using the new in_update_walk flag and reject immediately.
Next patch converts the problematic GFP_ATOMIC allocations.
--- include/net/netfilter/nf_tables.h | 2 + net/netfilter/nft_set_hash.c | 100 +++++++++++++++++++++++++++++- net/netfilter/nft_set_rbtree.c | 35 ++++++++--- 3 files changed, 126 insertions(+), 11 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -556,6 +556,7 @@ struct nft_set_elem_expr {* @size: maximum set size * @field_len: length of each field in concatenation, bytes * @field_count: number of concatenated fields in element +* @in_update_walk: true during ->walk() in transaction phase * @use: number of rules references to this set * @nelems: number of elements * @ndeact: number of deactivated elements queued for removal
@@ -590,6 +591,7 @@ struct nft_set {u32 size;u8 field_len[NFT_REG32_COUNT ];u8 field_count; +bool in_update_walk;u32 use;atomic_t nelems;u32 ndeact;
net/netfilter/nft_set_hash.c +97 -3
133 lines not on this page · raw message
net/netfilter/nft_set_rbtree.c +27 -8
@@ -584,15 +584,14 @@ nft_rbtree_deactivate(const struct net *net, const struct nft_set *set,return NULL ; } -static void nft_rbtree_walk (const struct nft_ctx *ctx, -struct nft_set *set, -struct nft_set_iter *iter) +static void nft_rbtree_do_walk (const struct nft_ctx *ctx, +struct nft_set *set, +struct nft_set_iter *iter) {struct nft_rbtree *priv =nft_set_priv (set);struct nft_rbtree_elem *rbe;struct rb_node *node; -read_lock_bh (&priv->lock);for (node =rb_first (&priv->root); node !=NULL ; node =rb_next (node)) { rbe = rb_entry(node, struct nft_rbtree_elem, node);
@@ -600,14 +599,34 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx, goto cont; iter->err = iter->fn (ctx, set, iter, &rbe->priv); -if (iter->err <0 ) { -read_unlock_bh (&priv->lock); +if (iter->err <0 )return ; - } cont: iter->count++; } -read_unlock_bh (&priv->lock); +} + +static void nft_rbtree_walk (const struct nft_ctx *ctx, +struct nft_set *set, +struct nft_set_iter *iter) +{ +struct nft_rbtree *priv =nft_set_priv (set); + +switch (iter->type) { +case NFT_ITER_UPDATE : +lockdep_assert_held (&nft_pernet (ctx->net)->commit_mutex); +nft_rbtree_do_walk (ctx, set, iter); +break ; +case NFT_ITER_READ : +read_lock_bh (&priv->lock); +nft_rbtree_do_walk (ctx, set, iter); +read_unlock_bh (&priv->lock); +break ; +default : + iter->err = -EINVAL ; +WARN_ON_ONCE (1 ); +break ; + } } static void nft_rbtree_gc_remove(struct net *net, struct nft_set *set,
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 4/8 netfilter: nf_tables: all transaction allocations can now sleep
In reply to Florian WestphalNow that nft_setelem_flush is not called with rcu read lock held or disabled softinterrupts anymore this can now use GFP_KERNEL too.
This is the last atomic allocation of transaction elements, so remove all gfp_t arguments and the wrapper function.
This makes attempts to delete large sets much more reliable, before this was prone to transient memory allocation failures.
--- net/netfilter/nf_tables_api.c | 47 ++++++++++++++--------------------- 1 file changed, 19 insertions(+), 28 deletions(-)
net/netfilter/nf_tables_api.c +19 -28
@@ -151,12 +151,12 @@ static void nft_ctx_init(struct nft_ctx *ctx,bitmap_zero (ctx->reg_inited,NFT_REG32_NUM ); } -static struct nft_trans *nft_trans_alloc_gfp (const struct nft_ctx *ctx, -int msg_type,u32 size,gfp_t gfp) +static struct nft_trans *nft_trans_alloc (const struct nft_ctx *ctx, +int msg_type,u32 size) {struct nft_trans *trans; - trans =kzalloc (size, gfp); + trans =kzalloc (size,GFP_KERNEL );if (trans ==NULL )return NULL ;
@@ -172,12 +172,6 @@ static struct nft_trans *nft_trans_alloc_gfp(const struct nft_ctx *ctx,return trans; } -static struct nft_trans *nft_trans_alloc (const struct nft_ctx *ctx, -int msg_type,u32 size) -{ -return nft_trans_alloc_gfp (ctx, msg_type, size,GFP_KERNEL ); -} -static struct nft_trans_binding *nft_trans_get_binding (struct nft_trans *trans) {switch (trans->msg_type) {
@@ -442,8 +436,7 @@ static bool nft_trans_collapse_set_elem_allowed(const struct nft_trans_elem *a,static bool nft_trans_collapse_set_elem (struct nftables_pernet *nft_net,struct nft_trans_elem *tail, -struct nft_trans_elem *trans, -gfp_t gfp) +struct nft_trans_elem *trans) {unsigned int nelems, old_nelems = tail->nelems;struct nft_trans_elem *new_trans;
@@ -466,9 +459,11 @@ static bool nft_trans_collapse_set_elem(struct nftables_pernet *nft_net,/* krealloc might free tail which invalidates list pointers */ list_del_init (&tail->nft_trans.list); - new_trans =krealloc (tail,struct_size (tail, elems, nelems), gfp); + new_trans =krealloc (tail,struct_size (tail, elems, nelems), +GFP_KERNEL );if (!new_trans) { -list_add_tail (&tail->nft_trans.list, &nft_net->commit_list); +list_add_tail (&tail->nft_trans.list, + &nft_net->commit_list);return false; }
@@ -484,7 +479,7 @@ static bool nft_trans_collapse_set_elem(struct nftables_pernet *nft_net, }static bool nft_trans_try_collapse (struct nftables_pernet *nft_net, -struct nft_trans *trans,gfp_t gfp) +struct nft_trans *trans) {struct nft_trans *tail;
@@ -501,7 +496,7 @@ static bool nft_trans_try_collapse(struct nftables_pernet *nft_net,case NFT_MSG_DELSETELEM :return nft_trans_collapse_set_elem (nft_net,nft_trans_container_elem (tail), -nft_trans_container_elem (trans), gfp); +nft_trans_container_elem (trans)); }return false;
@@ -537,17 +532,14 @@ static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *tr } } -static void nft_trans_commit_list_add_elem (struct net *net,struct nft_trans *trans, -gfp_t gfp) +static void nft_trans_commit_list_add_elem (struct net *net,struct nft_trans *trans) {struct nftables_pernet *nft_net =nft_pernet (net);WARN_ON_ONCE (trans->msg_type !=NFT_MSG_NEWSETELEM && trans->msg_type !=NFT_MSG_DELSETELEM ); -might_alloc (gfp); - -if (nft_trans_try_collapse (nft_net, trans, gfp)) { +if (nft_trans_try_collapse (nft_net, trans)) {kfree (trans);return ; }
@@ -7549,7 +7541,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, } ue->priv = elem_priv; -nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); +nft_trans_commit_list_add_elem (ctx->net, trans); goto err_elem_free; } }
@@ -7573,7 +7565,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, }nft_trans_container_elem (trans)->elems[0 ].priv = elem.priv; -nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); +nft_trans_commit_list_add_elem (ctx->net, trans);return 0 ; err_set_full:
@@ -7839,7 +7831,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,nft_setelem_data_deactivate (ctx->net, set, elem.priv);nft_trans_container_elem (trans)->elems[0 ].priv = elem.priv; -nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); +nft_trans_commit_list_add_elem (ctx->net, trans);return 0 ; fail_ops:
@@ -7864,9 +7856,8 @@ static int nft_setelem_flush(const struct nft_ctx *ctx,if (!nft_set_elem_active (ext, iter->genmask))return 0 ; - trans =nft_trans_alloc_gfp (ctx,NFT_MSG_DELSETELEM , - struct_size_t(struct nft_trans_elem, elems, 1), -GFP_ATOMIC ); + trans =nft_trans_alloc (ctx,NFT_MSG_DELSETELEM , + struct_size_t(struct nft_trans_elem, elems, 1));if (!trans)return -ENOMEM ;
@@ -7877,7 +7868,7 @@ static int nft_setelem_flush(const struct nft_ctx *ctx,nft_trans_elem_set (trans) = set;nft_trans_container_elem (trans)->nelems =1 ;nft_trans_container_elem (trans)->elems[0 ].priv = elem_priv; -nft_trans_commit_list_add_elem (ctx->net, trans,GFP_ATOMIC ); +nft_trans_commit_list_add_elem (ctx->net, trans);return 0 ; }
@@ -7894,7 +7885,7 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx,nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_trans_container_elem (trans)->elems[0 ].priv = elem_priv; -nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); +nft_trans_commit_list_add_elem (ctx->net, trans);return 0 ; }
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 5/8 netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
In reply to Florian WestphalFrom: Phil Sutter <[email protected]>
This new attribute is supposed to be used instead of NFTA_DEVICE_NAME for simple wildcard interface specs. It holds a NUL-terminated string representing an interface name prefix to match on.
While kernel code to distinguish full names from prefixes in NFTA_DEVICE_NAME is simpler than this solution, reusing the existing attribute with different semantics leads to confusion between different versions of kernel and user space though:
* With old kernels, wildcards submitted by user space are accepted yet silently treated as regular names.
* With old user space, wildcards submitted by kernel may cause crashes since libnftnl expects NUL-termination when there is none.
Using a distinct attribute type sanitizes these situations as the receiving part detects and rejects the unexpected attribute nested in *_HOOK_DEVS attributes.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 42 +++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1784,10 +1784,12 @@ enum nft_synproxy_attributes {* enum nft_device_attributes - nf_tables device netlink attributes * * @NFTA_DEVICE_NAME: name of this device (NLA_STRING) +* @NFTA_DEVICE_PREFIX: device name prefix, a simple wildcard (NLA_STRING) */ enum nft_devices_attributes {NFTA_DEVICE_UNSPEC ,NFTA_DEVICE_NAME , +NFTA_DEVICE_PREFIX , __NFTA_DEVICE_MAX };#define NFTA_DEVICE_MAX (__NFTA_DEVICE_MAX - 1)
net/netfilter/nf_tables_api.c +31 -11
96 lines not on this page · raw message
Signature · 1 line
2.49.1
Jakub Kicinski
maintainerRe: [PATCH net-next 5/8] netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
Quoted 14 lines · On Mon, 1 Sep 2025 10:08:39 +0200 Florian Westphal wrote:
This new attribute is supposed to be used instead of
NFTA_DEVICE_NAMEfor simple wildcard interface specs. It holds a NUL-terminated string representing an interface name prefix to match on.While kernel code to distinguish full names from prefixes in
NFTA_DEVICE_NAMEis simpler than this solution, reusing the existing attribute with different semantics leads to confusion between different versions of kernel and user space though:* With old kernels, wildcards submitted by user space are accepted yet silently treated as regular names.
* With old user space, wildcards submitted by kernel may cause crashes since libnftnl expects NUL-termination when there is none.
Quoted 5 lines
Using a distinct attribute type sanitizes these situations as the receiving part detects and rejects the unexpected attribute nested in
*_HOOK_DEVSattributes.Fixes 6d07a289504a ("netfilter: nf_tables: Support wildcard netdev hook specs")
Why is this not targeting net? The sooner we adjust the uAPI the better.
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 5/8] netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Mon, 1 Sep 2025 10:08:39 +0200 Florian Westphal wrote:
This new attribute is supposed to be used instead of
NFTA_DEVICE_NAMEfor simple wildcard interface specs. It holds a NUL-terminated string representing an interface name prefix to match on.While kernel code to distinguish full names from prefixes in
NFTA_DEVICE_NAMEis simpler than this solution, reusing the existing attribute with different semantics leads to confusion between different versions of kernel and user space though:* With old kernels, wildcards submitted by user space are accepted yet silently treated as regular names.
* With old user space, wildcards submitted by kernel may cause crashes since libnftnl expects NUL-termination when there is none.
Quoted 7 lines
Quoted 5 lines
Using a distinct attribute type sanitizes these situations as the receiving part detects and rejects the unexpected attribute nested in
*_HOOK_DEVSattributes.Fixes 6d07a289504a ("netfilter: nf_tables: Support wildcard netdev hook specs")Why is this not targeting net? The sooner we adjust the uAPI the better.
I think there were doubts that was possible at this stage.
But I agree, it is a bit late but better fix it there.
Florian?
Florian Westphal
maintainerRe: [PATCH net-next 5/8] netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Jakub Kicinski
Why is this not targeting net? The sooner we adjust the uAPI the better.
I considered it a new feature rather than a bug fix:
Userspace can't rely on the existing api because kernels before 6.16 don't special-case the names provided, and nftables doesn't make use of the 6.16 "accident" (the attempt to re-use the existing device name attribute for this).
The corresponding userspace changes (v4 uses the new attribute) haven't been merged yet.
But sure, getting rid of the "accident" faster makes sense, thanks for suggesting this.
Quoted 2 lines
I think there were doubts that was possible at this stage. But I agree, it is a bit late but better fix it there.
Alright, I'll send a new nf-next PR with this one dropped in a few hours and a separate nf.git PR with this patch included.
If you prefer to just apply this series sand this patch that worls for me too, I'll just follow this changesets' patchwork state.
Paolo Abeni
maintainerRe: [PATCH net-next 5/8] netfilter: nf_tables: Introduce NFTA_DEVICE_PREFIX
Quoted 14 lines · Florian Westphal
Quoted 2 lines · Pablo Neira Ayuso
Quoted 1 line · Jakub Kicinski
Why is this not targeting net? The sooner we adjust the uAPI the better.
I considered it a new feature rather than a bug fix:
Userspace can't rely on the existing api because kernels before 6.16 don't special-case the names provided, and nftables doesn't make use of the 6.16 "accident" (the attempt to re-use the existing device name attribute for this).
The corresponding userspace changes (v4 uses the new attribute) haven't been merged yet.
Quoted 8 lines
But sure, getting rid of the "accident" faster makes sense, thanks for suggesting this.
Quoted 2 lines
I think there were doubts that was possible at this stage. But I agree, it is a bit late but better fix it there.
Alright, I'll send a new nf-next PR with this one dropped in a few hours and a separate nf.git PR with this patch included.
I agree that this latter option is preferable.
Thanks,
Paolo
Florian Westphal
maintainerPATCH 6/8 netfilter: nft_set_pipapo: remove redundant test for avx feature bit
In reply to Florian WestphalSebastian points out that avx2 depends on avx, see check_cpufeature_deps() in arch/x86/kernel/cpu/cpuid-deps.c:
avx2 feature bit will be cleared when avx isn't available.
No functional change intended.
--- net/netfilter/nft_set_pipapo.c | 3 +-- net/netfilter/nft_set_pipapo_avx2.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
net/netfilter/nft_set_pipapo.c +1 -2
@@ -530,8 +530,7 @@ static struct nft_pipapo_elem *pipapo_get(const struct nft_pipapo_match *m,local_bh_disable ();#if defined(CONFIG_X86_64 ) && !defined(CONFIG_UML ) -if (boot_cpu_has (X86_FEATURE_AVX2 ) &&boot_cpu_has (X86_FEATURE_AVX ) && -irq_fpu_usable ()) { +if (boot_cpu_has (X86_FEATURE_AVX2 ) &&irq_fpu_usable ()) { e =pipapo_get_avx2 (m, data, genmask, tstamp);local_bh_enable ();return e;
net/netfilter/nft_set_pipapo_avx2.c +1 -1
@@ -1099,7 +1099,7 @@ bool nft_pipapo_avx2_estimate(const struct nft_set_desc *desc, u32 features, desc->field_count < NFT_PIPAPO_MIN_FIELDS)return false; -if (!boot_cpu_has (X86_FEATURE_AVX2 ) || !boot_cpu_has (X86_FEATURE_AVX )) +if (!boot_cpu_has (X86_FEATURE_AVX2 ))return false; est->size =pipapo_estimate_size (desc);
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 7/8 netfilter: nf_reject: remove unneeded exports
In reply to Florian WestphalThese functions have no external callers and can be static.
--- include/net/netfilter/ipv4/nf_reject.h | 8 ------ include/net/netfilter/ipv6/nf_reject.h | 10 ------- net/ipv4/netfilter/nf_reject_ipv4.c | 27 ++++++++++++------- net/ipv6/netfilter/nf_reject_ipv6.c | 37 +++++++++++++++++--------- 4 files changed, 42 insertions(+), 40 deletions(-)
include/net/netfilter/ipv4/nf_reject.h +0 -8
@@ -10,14 +10,6 @@void nf_send_unreach (struct sk_buff *skb_in,int code,int hook);void nf_send_reset (struct net *net,struct sock *,struct sk_buff *oldskb,int hook); -const struct tcphdr *nf_reject_ip_tcphdr_get (struct sk_buff *oldskb, -struct tcphdr *_oth,int hook); -struct iphdr *nf_reject_iphdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -__u8 protocol,int ttl); -void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb, -const struct tcphdr *oth); - struct sk_buff *nf_reject_skb_v4_unreach(struct net *net, struct sk_buff *oldskb, const struct net_device *dev,
include/net/netfilter/ipv6/nf_reject.h +0 -10
@@ -9,16 +9,6 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in, unsigned char cod unsigned int hooknum);void nf_send_reset6 (struct net *net,struct sock *sk,struct sk_buff *oldskb,int hook); -const struct tcphdr *nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb, -struct tcphdr *otcph, -unsigned int *otcplen,int hook); -struct ipv6hdr *nf_reject_ip6hdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -__u8 protocol,int hoplimit); -void nf_reject_ip6_tcphdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -const struct tcphdr *oth,unsigned int otcplen); - struct sk_buff *nf_reject_skb_v6_tcp_reset(struct net *net, struct sk_buff *oldskb, const struct net_device *dev,
net/ipv4/netfilter/nf_reject_ipv4.c +17 -10
@@ -12,6 +12,15 @@#include <linux/netfilter_ipv4.h> #include <linux/netfilter_bridge.h> +static struct iphdr *nf_reject_iphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__u8 protocol,int ttl); +static void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb, +const struct tcphdr *oth); +static const struct tcphdr * +nf_reject_ip_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *_oth,int hook); +static int nf_reject_iphdr_validate (struct sk_buff *skb) {struct iphdr *iph;
@@ -136,8 +145,9 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net, }EXPORT_SYMBOL_GPL (nf_reject_skb_v4_unreach); -const struct tcphdr *nf_reject_ip_tcphdr_get (struct sk_buff *oldskb, -struct tcphdr *_oth,int hook) +static const struct tcphdr * +nf_reject_ip_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *_oth,int hook) {const struct tcphdr *oth;
@@ -163,11 +173,10 @@ const struct tcphdr *nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,return oth; } -EXPORT_SYMBOL_GPL (nf_reject_ip_tcphdr_get); -struct iphdr *nf_reject_iphdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -__u8 protocol,int ttl) +static struct iphdr *nf_reject_iphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__u8 protocol,int ttl) {struct iphdr *niph, *oiph =ip_hdr (oldskb);
@@ -188,10 +197,9 @@ struct iphdr *nf_reject_iphdr_put(struct sk_buff *nskb,return niph; } -EXPORT_SYMBOL_GPL (nf_reject_iphdr_put); -void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb, -const struct tcphdr *oth) +static void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb, +const struct tcphdr *oth) {struct iphdr *niph =ip_hdr (nskb);struct tcphdr *tcph;
@@ -218,7 +226,6 @@ void nf_reject_ip_tcphdr_put(struct sk_buff *nskb, const struct sk_buff *oldskb, nskb->csum_start = (unsigned char *)tcph - nskb->head; nskb->csum_offset = offsetof(struct tcphdr , check); } -EXPORT_SYMBOL_GPL (nf_reject_ip_tcphdr_put);static int nf_reject_fill_skb_dst (struct sk_buff *skb_in) {
net/ipv6/netfilter/nf_reject_ipv6.c +25 -12
@@ -12,6 +12,19 @@#include <linux/netfilter_ipv6.h> #include <linux/netfilter_bridge.h> +static struct ipv6hdr * +nf_reject_ip6hdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__u8 protocol,int hoplimit); +static void +nf_reject_ip6_tcphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +const struct tcphdr *oth,unsigned int otcplen); +static const struct tcphdr * +nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *otcph, +unsigned int *otcplen,int hook); +static bool nf_reject_v6_csum_ok (struct sk_buff *skb,int hook) {const struct ipv6hdr *ip6h =ipv6_hdr (skb);
@@ -146,9 +159,10 @@ struct sk_buff *nf_reject_skb_v6_unreach(struct net *net, }EXPORT_SYMBOL_GPL (nf_reject_skb_v6_unreach); -const struct tcphdr *nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb, -struct tcphdr *otcph, -unsigned int *otcplen,int hook) +static const struct tcphdr * +nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *otcph, +unsigned int *otcplen,int hook) {const struct ipv6hdr *oip6h =ipv6_hdr (oldskb);u8 proto;
@@ -192,11 +206,11 @@ const struct tcphdr *nf_reject_ip6_tcphdr_get(struct sk_buff *oldskb,return otcph; } -EXPORT_SYMBOL_GPL (nf_reject_ip6_tcphdr_get); -struct ipv6hdr *nf_reject_ip6hdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -__u8 protocol,int hoplimit) +static struct ipv6hdr * +nf_reject_ip6hdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__u8 protocol,int hoplimit) {struct ipv6hdr *ip6h;const struct ipv6hdr *oip6h =ipv6_hdr (oldskb);
@@ -216,11 +230,11 @@ struct ipv6hdr *nf_reject_ip6hdr_put(struct sk_buff *nskb,return ip6h; } -EXPORT_SYMBOL_GPL (nf_reject_ip6hdr_put); -void nf_reject_ip6_tcphdr_put (struct sk_buff *nskb, -const struct sk_buff *oldskb, -const struct tcphdr *oth,unsigned int otcplen) +static void +nf_reject_ip6_tcphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +const struct tcphdr *oth,unsigned int otcplen) {struct tcphdr *tcph;
@@ -248,7 +262,6 @@ void nf_reject_ip6_tcphdr_put(struct sk_buff *nskb,csum_partial (tcph, sizeof(struct tcphdr), 0)); } -EXPORT_SYMBOL_GPL (nf_reject_ip6_tcphdr_put);static int nf_reject6_fill_skb_dst (struct sk_buff *skb_in) {
Signature · 1 line
2.49.1
Florian Westphal
maintainerPATCH 8/8 netfilter: nft_payload: extend offset to 65535 bytes
In reply to Florian WestphalFrom: Fernando Fernandez Mancera <[email protected]>
In some situations 255 bytes offset is not enough to match or manipulate the desired packet field. Increase the offset limit to 65535 or U16_MAX.
In addition, the nla policy maximum value is not set anymore as it is limited to s16. Instead, the maximum value is checked during the payload expression initialization function.
Tested with the nft command line tool.
table ip filter {
chain output {
@nh,2040,8 set 0xff
@nh,524280,8 set 0xff
@nh,524280,8 0xff
@nh,2040,8 0xff
}
}--- include/net/netfilter/nf_tables_core.h | 2 +- net/netfilter/nft_payload.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-)
include/net/netfilter/nf_tables_core.h +1 -1
@@ -73,7 +73,7 @@ struct nft_ct {struct nft_payload {enum nft_payload_bases base:8 ; -u8 offset; +u16 offset;u8 len;u8 dreg; };
net/netfilter/nft_payload.c +11 -7
@@ -40,7 +40,7 @@ static bool nft_payload_rebuild_vlan_hdr(const struct sk_buff *skb, int mac_off,/* add vlan header into the user buffer for if tag was removed by offloads */ static bool -nft_payload_copy_vlan (u32 *d,const struct sk_buff *skb,u8 offset,u8 len) +nft_payload_copy_vlan (u32 *d,const struct sk_buff *skb,u16 offset,u8 len) {int mac_off =skb_mac_header (skb) - skb->data;u8 *vlanh, *dst_u8 = (u8 *) d;
@@ -212,7 +212,7 @@ static const struct nla_policy nft_payload_policy[NFTA_PAYLOAD_MAX + 1] = { [NFTA_PAYLOAD_SREG] = { .type = NLA_U32 }, [NFTA_PAYLOAD_DREG] = { .type = NLA_U32 }, [NFTA_PAYLOAD_BASE] = { .type = NLA_U32 }, - [NFTA_PAYLOAD_OFFSET] = NLA_POLICY_MAX(NLA_BE32, 255), + [NFTA_PAYLOAD_OFFSET] = { .type = NLA_BE32 }, [NFTA_PAYLOAD_LEN] = NLA_POLICY_MAX(NLA_BE32, 255), [NFTA_PAYLOAD_CSUM_TYPE] = { .type = NLA_U32 }, [NFTA_PAYLOAD_CSUM_OFFSET] = NLA_POLICY_MAX(NLA_BE32, 255),
@@ -797,7 +797,7 @@ static int nft_payload_csum_inet(struct sk_buff *skb, const u32 *src,struct nft_payload_set {enum nft_payload_bases base:8 ; -u8 offset; +u16 offset;u8 len;u8 sreg;u8 csum_type;
@@ -812,7 +812,7 @@ struct nft_payload_vlan_hdr { };static bool -nft_payload_set_vlan (const u32 *src,struct sk_buff *skb,u8 offset,u8 len, +nft_payload_set_vlan (const u32 *src,struct sk_buff *skb,u16 offset,u8 len,int *vlan_hlen) {struct nft_payload_vlan_hdr *vlanh;
@@ -940,14 +940,18 @@ static int nft_payload_set_init(const struct nft_ctx *ctx,const struct nft_expr *expr, const struct nlattr * const tb[]) { + u32 csum_offset, offset, csum_type = NFT_PAYLOAD_CSUM_NONE;struct nft_payload_set *priv =nft_expr_priv (expr); -u32 csum_offset, csum_type =NFT_PAYLOAD_CSUM_NONE ;int err; priv->base =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_BASE ])); - priv->offset =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_OFFSET ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ])); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset); +if (err <0 ) +return err; + priv->offset = offset; +if (tb[NFTA_PAYLOAD_CSUM_TYPE ]) csum_type =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_CSUM_TYPE ]));if (tb[NFTA_PAYLOAD_CSUM_OFFSET ]) {
@@ -1069,7 +1073,7 @@ nft_payload_select_ops(const struct nft_ctx *ctx,if (tb[NFTA_PAYLOAD_DREG ] ==NULL )return ERR_PTR (-EINVAL ); - err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U8_MAX , &offset); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset);if (err <0 )return ERR_PTR (err);
Signature · 1 line
2.49.1
Florian Westphal
maintainerQuoted 11 lines · Florian Westphal
The following patchset contains Netfilter fixes for *net-next*:
1) prefer
vmalloc_arrayin ebtables, from Qianfeng Rong.
2) Usecsum_replace4instead of open-coding it, from Christophe Leroy. 3+4) Get rid ofGFP_ATOMICin transaction object allocations, those cause silly failures with large sets under memory pressure, from myself.
5) Introduce newNFTA_DEVICE_PREFIXattribute in nftables netlink api, re-using oldNFTA_DEVICE_NAMEled to confusion with different kernel/userspace versions. This refines the wildcard interface support added in 6.16 release. From Phil Sutter.
As per discussion I'll route patch 5 via net tree instead, so:
pw-bot: changes-requested
A new nf-next -> net-next MR will follow.