[PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding

Subsystems: netfilter, networking [general], the rest

STALE372d

2 messages, 2 authors, 2025-08-27 · open the first message on its own page

[PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding

From: Christophe Leroy <hidden>
Date: 2025-08-18 10:20:38

Open coded calculation can be avoided and replaced by the
equivalent csum_replace4() in nft_csum_replace().

Signed-off-by: Christophe Leroy <redacted>
---
v2: Add cast to __be32 to match csum_replace4() expected param types
---
 net/netfilter/nft_payload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 7dfc5343dae4..059b28ffad0e 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -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;
 }
-- 
2.49.0

Re: [PATCH net-next v2] netfilter: nft_payload: Use csum_replace4() instead of opencoding

From: Simon Horman <horms@kernel.org>
Date: 2025-08-27 12:41:07

On Mon, Aug 18, 2025 at 11:48:30AM +0200, Christophe Leroy wrote:
Open coded calculation can be avoided and replaced by the
equivalent csum_replace4() in nft_csum_replace().

Signed-off-by: Christophe Leroy <redacted>
Reviewed-by: Simon Horman <horms@kernel.org>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help