public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT
@ 2025-04-26 15:32 Felix Fietkau
  2025-04-28 16:17 ` Willem de Bruijn
  2025-04-29 22:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Felix Fietkau @ 2025-04-26 15:32 UTC (permalink / raw)
  To: netdev, David S. Miller, David Ahern, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Steffen Klassert,
	Willem de Bruijn
  Cc: linux-kernel

If any address or port is changed, update it in all packets and recalculate
checksum.

Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 2c0725583be3..9a8142ccbabe 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -247,6 +247,62 @@ static struct sk_buff *__udpv4_gso_segment_list_csum(struct sk_buff *segs)
 	return segs;
 }
 
+static void __udpv6_gso_segment_csum(struct sk_buff *seg,
+				     struct in6_addr *oldip,
+				     const struct in6_addr *newip,
+				     __be16 *oldport, __be16 newport)
+{
+	struct udphdr *uh = udp_hdr(seg);
+
+	if (ipv6_addr_equal(oldip, newip) && *oldport == newport)
+		return;
+
+	if (uh->check) {
+		inet_proto_csum_replace16(&uh->check, seg, oldip->s6_addr32,
+					  newip->s6_addr32, true);
+
+		inet_proto_csum_replace2(&uh->check, seg, *oldport, newport,
+					 false);
+		if (!uh->check)
+			uh->check = CSUM_MANGLED_0;
+	}
+
+	*oldip = *newip;
+	*oldport = newport;
+}
+
+static struct sk_buff *__udpv6_gso_segment_list_csum(struct sk_buff *segs)
+{
+	const struct ipv6hdr *iph;
+	const struct udphdr *uh;
+	struct ipv6hdr *iph2;
+	struct sk_buff *seg;
+	struct udphdr *uh2;
+
+	seg = segs;
+	uh = udp_hdr(seg);
+	iph = ipv6_hdr(seg);
+	uh2 = udp_hdr(seg->next);
+	iph2 = ipv6_hdr(seg->next);
+
+	if (!(*(const u32 *)&uh->source ^ *(const u32 *)&uh2->source) &&
+	    ipv6_addr_equal(&iph->saddr, &iph2->saddr) &&
+	    ipv6_addr_equal(&iph->daddr, &iph2->daddr))
+		return segs;
+
+	while ((seg = seg->next)) {
+		uh2 = udp_hdr(seg);
+		iph2 = ipv6_hdr(seg);
+
+		__udpv6_gso_segment_csum(seg, &iph2->saddr, &iph->saddr,
+					 &uh2->source, uh->source);
+		__udpv6_gso_segment_csum(seg, &iph2->daddr, &iph->daddr,
+					 &uh2->dest, uh->dest);
+	}
+
+	return segs;
+}
+
 static struct sk_buff *__udp_gso_segment_list(struct sk_buff *skb,
 					      netdev_features_t features,
 					      bool is_ipv6)
@@ -259,7 +315,10 @@ static struct sk_buff *__udp_gso_segment_list(struct sk_buff *skb,
 
 	udp_hdr(skb)->len = htons(sizeof(struct udphdr) + mss);
 
-	return is_ipv6 ? skb : __udpv4_gso_segment_list_csum(skb);
+	if (is_ipv6)
+		return __udpv6_gso_segment_list_csum(skb);
+	else
+		return __udpv4_gso_segment_list_csum(skb);
 }
 
 struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT
  2025-04-26 15:32 [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT Felix Fietkau
@ 2025-04-28 16:17 ` Willem de Bruijn
  2025-04-29 22:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Willem de Bruijn @ 2025-04-28 16:17 UTC (permalink / raw)
  To: Felix Fietkau, netdev, David S. Miller, David Ahern, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Steffen Klassert,
	Willem de Bruijn
  Cc: linux-kernel

Felix Fietkau wrote:
> If any address or port is changed, update it in all packets and recalculate
> checksum.
> 
> Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
> Signed-off-by: Felix Fietkau <nbd@nbd.name>

Reviewed-by: Willem de Bruijn <willemb@google.com>

This is the IPv6 equivalent to commit c3df39ac9b0e ("udp: ipv4:
manipulate network header of NATed UDP GRO fraglist"). Not sure why
IPv6 was missed at the time.

> ---
>  net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
> index 2c0725583be3..9a8142ccbabe 100644
> --- a/net/ipv4/udp_offload.c
> +++ b/net/ipv4/udp_offload.c
> @@ -247,6 +247,62 @@ static struct sk_buff *__udpv4_gso_segment_list_csum(struct sk_buff *segs)
>  	return segs;
>  }
>  
> +static void __udpv6_gso_segment_csum(struct sk_buff *seg,
> +				     struct in6_addr *oldip,
> +				     const struct in6_addr *newip,
> +				     __be16 *oldport, __be16 newport)
> +{
> +	struct udphdr *uh = udp_hdr(seg);
> +
> +	if (ipv6_addr_equal(oldip, newip) && *oldport == newport)
> +		return;
> +
> +	if (uh->check) {
> +		inet_proto_csum_replace16(&uh->check, seg, oldip->s6_addr32,
> +					  newip->s6_addr32, true);
> +
> +		inet_proto_csum_replace2(&uh->check, seg, *oldport, newport,
> +					 false);
> +		if (!uh->check)
> +			uh->check = CSUM_MANGLED_0;
> +	}
> +
> +	*oldip = *newip;
> +	*oldport = newport;
> +}
> +
> +static struct sk_buff *__udpv6_gso_segment_list_csum(struct sk_buff *segs)
> +{
> +	const struct ipv6hdr *iph;
> +	const struct udphdr *uh;
> +	struct ipv6hdr *iph2;
> +	struct sk_buff *seg;
> +	struct udphdr *uh2;
> +
> +	seg = segs;
> +	uh = udp_hdr(seg);
> +	iph = ipv6_hdr(seg);
> +	uh2 = udp_hdr(seg->next);
> +	iph2 = ipv6_hdr(seg->next);
> +
> +	if (!(*(const u32 *)&uh->source ^ *(const u32 *)&uh2->source) &&

only if respin: this could be a simpler equality test?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT
  2025-04-26 15:32 [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT Felix Fietkau
  2025-04-28 16:17 ` Willem de Bruijn
@ 2025-04-29 22:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-29 22:20 UTC (permalink / raw)
  To: Felix Fietkau
  Cc: netdev, davem, dsahern, edumazet, kuba, pabeni, horms,
	steffen.klassert, willemb, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sat, 26 Apr 2025 17:32:09 +0200 you wrote:
> If any address or port is changed, update it in all packets and recalculate
> checksum.
> 
> Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
> Signed-off-by: Felix Fietkau <nbd@nbd.name>
> ---
>  net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 60 insertions(+), 1 deletion(-)

Here is the summary with links:
  - [net] net: ipv6: fix UDPv6 GSO segmentation with NAT
    https://git.kernel.org/netdev/net/c/b936a9b8d4a5

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-29 22:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-26 15:32 [PATCH net] net: ipv6: fix UDPv6 GSO segmentation with NAT Felix Fietkau
2025-04-28 16:17 ` Willem de Bruijn
2025-04-29 22:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox