Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp176179pxb; Thu, 21 Jan 2021 04:33:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWeqey2detFjdAqdf0F7xkCtN5alxUI667VJ2oOX3cQu3fVasDcIsNzOF9JLkQbDRDYwMt X-Received: by 2002:aa7:d3c5:: with SMTP id o5mr11116815edr.122.1611232424502; Thu, 21 Jan 2021 04:33:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611232424; cv=none; d=google.com; s=arc-20160816; b=v5CaBifQtpaMaQ74gRihoy/KVyaPoqDf6gZp/yHThuUWJ0eAf6vOhe214GadmrHZ0T vOvl3J+NM0EPFLO2LqkvYy5i8otKt02Cx3Gudb3lrdR/fzeyQ6nR2w4FL2JphOzxyUpA SvkK/x+w3UgpndMJnulU8CbdLFHNryq2Mpj+AH1+SbBCVbWFcxuccyN+8wC47mzdyJKn TDoZ7QZ8OC3W41nUXZpnKgORptljU3HtjDb4ryTl91myR+QC1G6UKFdz8lyqfH5r5NYb EvUY+7YRRF/3ixkci2aRvAd/yZkfNTpixHvmXNGhjyhsAklrC/mxbmmSDQx6RVpJCo5X L5aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2kFWNEN1v8i3Xq4ZA1UqCDWW6INE/4bElMovwNGHWsA=; b=wz9Sf/ORpMS5KV6pexT+m7vr8h1vua0OHNCUiYLTX/i6CceU5aCrqQLMSLA9pq15qW I6AMt85CUQyyC00t9DSiQB9pOH2rjBNU7VBh+E/uMr2ItDqXm8d4iS5iZfhuxIW+tvXr eLedCxCk/ufu7Z9Y0K3zlWmySZTbASd0irth6h8fXz56U/rBiMXjqi/4ZE+hiMmJ6xI7 9MY03++NJG2oetbN+FhV/Z52lNgMzpLsCHscxXrVAHjQNMpWfT3CH8DscQaOWj//ov+p iIhm1hEwiCrwIWY0m8VYWFF5/IfjdlakdFhB1HW8THqvnFYkyxN6NwVAAqa6HK1P8Qa+ dREg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c14si2067464edv.132.2021.01.21.04.33.20; Thu, 21 Jan 2021 04:33:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731234AbhAUMb1 (ORCPT + 99 others); Thu, 21 Jan 2021 07:31:27 -0500 Received: from a.mx.secunet.com ([62.96.220.36]:56452 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731137AbhAUM3t (ORCPT ); Thu, 21 Jan 2021 07:29:49 -0500 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 04C322018D; Thu, 21 Jan 2021 13:28:59 +0100 (CET) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FC8YExFQj8NY; Thu, 21 Jan 2021 13:28:58 +0100 (CET) Received: from mail-essen-01.secunet.de (unknown [10.53.40.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 0E689200AC; Thu, 21 Jan 2021 13:28:58 +0100 (CET) Received: from mbx-essen-01.secunet.de (10.53.40.197) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 21 Jan 2021 13:28:57 +0100 Received: from gauss2.secunet.de (10.182.7.193) by mbx-essen-01.secunet.de (10.53.40.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Thu, 21 Jan 2021 13:28:57 +0100 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 49CFE3181CAC; Thu, 21 Jan 2021 13:28:57 +0100 (CET) Date: Thu, 21 Jan 2021 13:28:57 +0100 From: Steffen Klassert To: Dongseok Yi CC: "'David S. Miller'" , 'Alexander Lobakin' , , 'Jakub Kicinski' , 'Hideaki YOSHIFUJI' , "'Willem de Bruijn'" , , Subject: Re: [PATCH net v2] udp: ipv4: manipulate network header of NATed UDP GRO fraglist Message-ID: <20210121122857.GS3576117@gauss3.secunet.de> References: <1610716836-140533-1-git-send-email-dseok.yi@samsung.com> <20210118132736.GM3576117@gauss3.secunet.de> <012d01d6eef9$45516d40$cff447c0$@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <012d01d6eef9$45516d40$cff447c0$@samsung.com> X-ClientProxiedBy: cas-essen-01.secunet.de (10.53.40.201) To mbx-essen-01.secunet.de (10.53.40.197) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 03:55:42PM +0900, Dongseok Yi wrote: > On 2021-01-18 22:27, Steffen Klassert wrote: > > On Fri, Jan 15, 2021 at 10:20:35PM +0900, Dongseok Yi wrote: > > > UDP/IP header of UDP GROed frag_skbs are not updated even after NAT > > > forwarding. Only the header of head_skb from ip_finish_output_gso -> > > > skb_gso_segment is updated but following frag_skbs are not updated. > > > > > > A call path skb_mac_gso_segment -> inet_gso_segment -> > > > udp4_ufo_fragment -> __udp_gso_segment -> __udp_gso_segment_list > > > does not try to update UDP/IP header of the segment list but copy > > > only the MAC header. > > > > > > Update dport, daddr and checksums of each skb of the segment list > > > in __udp_gso_segment_list. It covers both SNAT and DNAT. > > > > > > Fixes: 9fd1ff5d2ac7 (udp: Support UDP fraglist GRO/GSO.) > > > Signed-off-by: Dongseok Yi > > > --- > > > v1: > > > Steffen Klassert said, there could be 2 options. > > > https://lore.kernel.org/patchwork/patch/1362257/ > > > I was trying to write a quick fix, but it was not easy to forward > > > segmented list. Currently, assuming DNAT only. > > > > > > v2: > > > Per Steffen Klassert request, move the procedure from > > > udp4_ufo_fragment to __udp_gso_segment_list and support SNAT. > > > > > > To Alexander Lobakin, I've checked your email late. Just use this > > > patch as a reference. It support SNAT too, but does not support IPv6 > > > yet. I cannot make IPv6 header changes in __udp_gso_segment_list due > > > to the file is in IPv4 directory. > > > > > > include/net/udp.h | 2 +- > > > net/ipv4/udp_offload.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- > > > net/ipv6/udp_offload.c | 2 +- > > > 3 files changed, 59 insertions(+), 7 deletions(-) > > > > > > diff --git a/include/net/udp.h b/include/net/udp.h > > > index 877832b..01351ba 100644 > > > --- a/include/net/udp.h > > > +++ b/include/net/udp.h > > > @@ -178,7 +178,7 @@ struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, > > > int udp_gro_complete(struct sk_buff *skb, int nhoff, udp_lookup_t lookup); > > > > > > struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, > > > - netdev_features_t features); > > > + netdev_features_t features, bool is_ipv6); > > > > > > static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb) > > > { > > > diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c > > > index ff39e94..c532d3b 100644 > > > --- a/net/ipv4/udp_offload.c > > > +++ b/net/ipv4/udp_offload.c > > > @@ -187,8 +187,57 @@ struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb, > > > } > > > EXPORT_SYMBOL(skb_udp_tunnel_segment); > > > > > > +static void __udpv4_gso_segment_csum(struct sk_buff *seg, > > > + __be32 *oldip, __be32 *newip, > > > + __be16 *oldport, __be16 *newport) > > > +{ > > > + struct udphdr *uh = udp_hdr(seg); > > > + struct iphdr *iph = ip_hdr(seg); > > > + > > > + if (uh->check) { > > > + inet_proto_csum_replace4(&uh->check, seg, *oldip, *newip, > > > + true); > > > + inet_proto_csum_replace2(&uh->check, seg, *oldport, *newport, > > > + false); > > > + if (!uh->check) > > > + uh->check = CSUM_MANGLED_0; > > > + } > > > + uh->dest = *newport; > > > + > > > + csum_replace4(&iph->check, *oldip, *newip); > > > + iph->daddr = *newip; > > > +} > > > > Can't we just do the checksum recalculation for this case as it is done > > with standard GRO? > > If I understand standard GRO correctly, it calculates full checksum. > Should we adopt the same method to UDP GRO fraglist? I did not find > a simple method for the incremental checksum update. > > > > > > + > > > +static struct sk_buff *__udpv4_gso_segment_list_csum(struct sk_buff *segs) > > > +{ > > > + struct sk_buff *seg; > > > + struct udphdr *uh, *uh2; > > > + struct iphdr *iph, *iph2; > > > + > > > + seg = segs; > > > + uh = udp_hdr(seg); > > > + iph = ip_hdr(seg); > > > + > > > + while ((seg = seg->next)) { > > > + uh2 = udp_hdr(seg); > > > + iph2 = ip_hdr(seg); > > > + > > > + if (uh->source != uh2->source || iph->saddr != iph2->saddr) > > > + __udpv4_gso_segment_csum(seg, > > > + &iph2->saddr, &iph->saddr, > > > + &uh2->source, &uh->source); > > > + > > > + if (uh->dest != uh2->dest || iph->daddr != iph2->daddr) > > > + __udpv4_gso_segment_csum(seg, > > > + &iph2->daddr, &iph->daddr, > > > + &uh2->dest, &uh->dest); > > > + } > > > > You don't need to check the addresses and ports of all packets in the > > segment list. If the addresses and ports are equal for the first and > > second packet in the list, then this also holds for the rest of the > > packets. > > I think we can try this with an additional flag (seg_csum). > > diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c > index 36b7e30..3f892df 100644 > --- a/net/ipv4/udp_offload.c > +++ b/net/ipv4/udp_offload.c > @@ -213,25 +213,36 @@ static struct sk_buff *__udpv4_gso_segment_list_csum(struct sk_buff *segs) > struct sk_buff *seg; > struct udphdr *uh, *uh2; > struct iphdr *iph, *iph2; > + bool seg_csum = false; > > seg = segs; > uh = udp_hdr(seg); > iph = ip_hdr(seg); Why not if ((udp_hdr(seg)->dest == udp_hdr(seg->next)->dest) && (udp_hdr(seg)->source == udp_hdr(seg->next)->source) && (ip_hdr(seg)->daddr == ip_hdr(seg->next)->daddr) && (ip_hdr(seg)->saddr == ip_hdr(seg->next)->saddr)) return segs; Then you don't need to test inside the loop. Just update all packets if there is a header mismatch. > > - while ((seg = seg->next)) { > + seg = seg->next; > + do { > + if (!seg) > + break; > + > uh2 = udp_hdr(seg); > iph2 = ip_hdr(seg); > > - if (uh->source != uh2->source || iph->saddr != iph2->saddr) > + if (uh->source != uh2->source || iph->saddr != iph2->saddr) { > __udpv4_gso_segment_csum(seg, > &iph2->saddr, &iph->saddr, > &uh2->source, &uh->source); > + seg_csum = true; > + } > > - if (uh->dest != uh2->dest || iph->daddr != iph2->daddr) > + if (uh->dest != uh2->dest || iph->daddr != iph2->daddr) { > __udpv4_gso_segment_csum(seg, > &iph2->daddr, &iph->daddr, > &uh2->dest, &uh->dest); > - } > + seg_csum = true; > + } > + > + seg = seg->next; > + } while (seg_csum); > > return segs; > }