Thread (31 messages) 31 messages, 3 authors, 2020-10-09

Re: [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment

From: Xin Long <lucien.xin@gmail.com>
Date: 2020-10-08 10:01:42
Also in: linux-sctp

CCing Tom Herbert

On Thu, Oct 8, 2020 at 5:48 PM Xin Long [off-list ref] wrote:
quoted hunk ↗ jump to hunk
This patch fixes two things:

  When skb->ip_summed == CHECKSUM_PARTIAL, skb_checksum_help() should be
  called do the checksum, instead of gso_make_checksum(), which is used
  to do the checksum for current proto after calling skb_segment(), not
  after the inner proto's gso_segment().

  When offload_csum is disabled, the hardware will not do the checksum
  for the current proto, udp. So instead of calling gso_make_checksum(),
  it should calculate checksum for udp itself.

Cc: Tom Herbert <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/ipv4/udp_offload.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index e67a66f..c0b010b 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -131,14 +131,15 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
                uh->check = ~csum_fold(csum_add(partial,
                                       (__force __wsum)htonl(len)));

-               if (skb->encapsulation || !offload_csum) {
-                       uh->check = gso_make_checksum(skb, ~uh->check);
-                       if (uh->check == 0)
-                               uh->check = CSUM_MANGLED_0;
-               } else {
+               if (skb->encapsulation)
+                       skb_checksum_help(skb);
+
+               if (offload_csum) {
                        skb->ip_summed = CHECKSUM_PARTIAL;
                        skb->csum_start = skb_transport_header(skb) - skb->head;
                        skb->csum_offset = offsetof(struct udphdr, check);
+               } else {
+                       uh->check = csum_fold(skb_checksum(skb, udp_offset, len, 0));
                }
        } while ((skb = skb->next));
 out:
--
2.1.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help