[net-next,1/2] IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver
Message ID | 20221122232740.3180560-1-lixiaoyan@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2495226wrr; Tue, 22 Nov 2022 15:39:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf66QjkG7FrRZNpdZvqKLABgLQ9k8SY2Jm+oU6J1IDfGbxtZ1vbk2crj83VZcuhn2AHMUoI1 X-Received: by 2002:a17:907:9879:b0:7ac:9917:c997 with SMTP id ko25-20020a170907987900b007ac9917c997mr20565083ejc.463.1669160375170; Tue, 22 Nov 2022 15:39:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669160375; cv=none; d=google.com; s=arc-20160816; b=tAFnDel0Kw4t0LtdNhzkjx7crv/NX3Ueod7H4HnYaTAOmRKU5t0Hfvwa7aA6mlUJkg +Cm2YpEmxNy6+FV8iI8Vrb+0YC4qwAOn5h7CHZ+fPpSEkgAr8v77hr4+mH6zaSFVla46 WOqmZa1gmGfdyI8W/hYS/QAuYyAEmLuWn8tWd8M7Qk2CW+Xr24QrH1ziG17RrZFsqbA1 I3H7DoPy1MMa0IYSZwODFC4f7p+CcYlPonutTWSxh3Ry7LAorvCHHpSu63YjaP4ke2Nx ehvB3fFpCbVzddFn5HvDSnpq1tYfkZaRNTFI/xfotlUMZ5LMqqmlwxcBBV/hQ/HeyxPc gYqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=N4Pb5W255LH0BWY4yuGbMLQMKFxJAPzH0I4oKHVGlwI=; b=gDJv+lpHLm8uYVkO/3DG5ZBSPYIAZSw7vokJoo6e9wpIOBuTjljKzV7d72ItTCbB3e NOP5jbxCAoQyg9Y32VFOldJ9aaokCsd5WWag6FCL4oUgC8u4JpznDuryGGhAzIVhOYat XQPse85IEorMyZ//SEgVT4EJD/iAWpk1JQfhSbpkEoJhOVnQoF2T+NraP37e95CrLRZG TcXNgqqhh+F6fjZUiyyC3+/hxMY0RWIkvRlDayXVCfiMb3MJhXwkUxJdeN7/GHFXBZWb FM9NO3bfSMc4nG8syNBOOmtiBPL06soeTqa14YUU8ae0LNPENeYnAU11tzk5l/X1VB9E +OJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tVENbIig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ml21-20020a170906cc1500b0073d71124609si2152425ejb.182.2022.11.22.15.39.11; Tue, 22 Nov 2022 15:39:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tVENbIig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235287AbiKVX1t (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 18:27:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235218AbiKVX1p (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 18:27:45 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B017814020 for <linux-kernel@vger.kernel.org>; Tue, 22 Nov 2022 15:27:44 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id f71-20020a25384a000000b006dd7876e98eso14797367yba.15 for <linux-kernel@vger.kernel.org>; Tue, 22 Nov 2022 15:27:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=N4Pb5W255LH0BWY4yuGbMLQMKFxJAPzH0I4oKHVGlwI=; b=tVENbIig4zypZwKmQ8inC+vVevHwdkxN3+2CDSJoyit+ZLSa3OQ4M0yZm3xuNJO/iV pvnLbIBWaitur/9N2aB6j/szXg4KaoROCYpX4flHftkXwcK66thm3kcTyd9bnlipNvSp PWPoohMT/PRh0llw7fLXgxR7OhfPTw7AJrhwAlpxgp6UAFE0IaCqZtX8mubLKclEz6wc 2O4cPZ0Cl0jpm+/fTry6Zz5GDpQNezmUf/49rA72ZIM4HFA+XHecxlsB3MMRZ0OoLlJH Vc09rEmxO4npluR0WxsxMhFasByZzrilkdWYFt8ntObt6mdFvGtnhr3GuYwcmN8npbbc Q87Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=N4Pb5W255LH0BWY4yuGbMLQMKFxJAPzH0I4oKHVGlwI=; b=2//J4ULLBrrm/y8lYFWOMpSiQBLJ/cYw4ul7rDuejKpgjD92hGYO61iNNm9vUbfmv9 F2XmpSqC78Jlgpdd/GZ7ozPTERDfbmOeey+QzpmlNIBu6tV2nE97Ak5YZ1Cjyp9gReoo HTlzQPMIYpgBuQnpl99HBkd+xgiDKGcjDOSA/Vs7gpd4YRAzO4Om80lvRgE+6QXK8F/p BhwBeJVuVSFGTHbEZCQMjIAbr6y7OVb2OoyUbSDXhdEnivmuDZ2pfqxvNhiZtNQV4u/l 98ESvjffxbcSEO304Rwdto8UTppW8aGaKdIQR7W/n9Jghb8Rscr03iwAyjIuHPpUyH0t nq1A== X-Gm-Message-State: ANoB5pnrD8gUKyX4aqFK0ikw6bv4IM5tMhZWJU1fSmiZN5Q7a8QUz0Z7 plRdZmfGPuhncil0O5T502eEleVgjLpuemk= X-Received: from lixiaoyan-desktop.svl.corp.google.com ([2620:15c:2c4:201:d85f:1168:cf63:556b]) (user=lixiaoyan job=sendgmr) by 2002:a25:738a:0:b0:6ca:18d4:db86 with SMTP id o132-20020a25738a000000b006ca18d4db86mr24881575ybc.111.1669159663938; Tue, 22 Nov 2022 15:27:43 -0800 (PST) Date: Tue, 22 Nov 2022 15:27:39 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221122232740.3180560-1-lixiaoyan@google.com> Subject: [PATCH net-next 1/2] IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver From: Coco Li <lixiaoyan@google.com> To: "David S. Miller" <davem@davemloft.net>, Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>, David Ahern <dsahern@kernel.org>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Michael Chan <michael.chan@broadcom.com> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Coco Li <lixiaoyan@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750241509327965169?= X-GMAIL-MSGID: =?utf-8?q?1750241509327965169?= |
Series |
[net-next,1/2] IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver
|
|
Commit Message
Coco Li
Nov. 22, 2022, 11:27 p.m. UTC
IPv6/TCP and GRO stacks can build big TCP packets with an added
temporary Hop By Hop header.
Is GSO is not involved, then the temporary header needs to be removed in
the driver. This patch provides a generic helper for drivers that need
to modify their headers in place.
Signed-off-by: Coco Li <lixiaoyan@google.com>
---
include/net/ipv6.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
Comments
From: Coco Li <lixiaoyan@google.com> Date: Tue, 22 Nov 2022 15:27:39 -0800 > IPv6/TCP and GRO stacks can build big TCP packets with an added > temporary Hop By Hop header. > > Is GSO is not involved, then the temporary header needs to be removed in > the driver. This patch provides a generic helper for drivers that need > to modify their headers in place. > > Signed-off-by: Coco Li <lixiaoyan@google.com> > --- > include/net/ipv6.h | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/include/net/ipv6.h b/include/net/ipv6.h > index d383c895592a..a11d58c85c05 100644 > --- a/include/net/ipv6.h > +++ b/include/net/ipv6.h > @@ -500,6 +500,39 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb) > return jhdr->nexthdr; > } > > +/* Return 0 if HBH header is successfully removed > + * Or if HBH removal is unnecessary (packet is not big TCP) > + * Return error to indicate dropping the packet > + */ > +static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb) > +{ > + const int hophdr_len = sizeof(struct hop_jumbo_hdr); > + int nexthdr = ipv6_has_hopopt_jumbo(skb); > + struct ipv6hdr *h6; > + > + if (!nexthdr) > + return 0; > + > + if (skb_cow_head(skb, 0)) > + return -1; err = skb_cow_head(skb, 0); if (err) return err; Alternatively, if you want to keep it simple, make the function bool and return false on `if (skb_cow_head(skb, 0)` and true otherwise. > + > + /* Remove the HBH header. > + * Layout: [Ethernet header][IPv6 header][HBH][L4 Header] > + */ > + memmove(skb->data + hophdr_len, > + skb->data, This can fit into the previous line. > + ETH_HLEN + sizeof(struct ipv6hdr)); Not correct at this point. I assume you took the implementation from ip6_offload.c[0], but ::gso_segment() and ::ndo_start_xmit() are two different entry points. Here you may have not only Eth header, but also VLAN, MPLS and whatnot. Correct way would be: memmove(skb_mac_header(skb) + hophdr_len, skb_mac_header(skb), ipv6_hdr(skb) - skb_mac_header(skb) + sizeof(struct ipv6hdr)); > + > + skb->data += hophdr_len; > + skb->len -= hophdr_len; > + skb->network_header += hophdr_len; skb->mac_header also needs to be adjusted, the fact that it's equal to skb->data at the entry of ::ndo_start_xmit() doesn't mean anything. > + > + h6 = ipv6_hdr(skb); > + h6->nexthdr = nexthdr; > + > + return 0; > +} Please switch all the places where the same logics is used to your new helper. > + > static inline bool ipv6_accept_ra(struct inet6_dev *idev) > { > /* If forwarding is enabled, RA are not accepted unless the special > -- > 2.38.1.584.g0f3c55d4c2-goog Thanks, Olek
From: Alexander Lobakin <alexandr.lobakin@intel.com> Date: Wed, 23 Nov 2022 17:38:25 +0100 > From: Coco Li <lixiaoyan@google.com> > Date: Tue, 22 Nov 2022 15:27:39 -0800 > > > IPv6/TCP and GRO stacks can build big TCP packets with an added > > temporary Hop By Hop header. > > > > Is GSO is not involved, then the temporary header needs to be removed in > > the driver. This patch provides a generic helper for drivers that need > > to modify their headers in place. > > > > Signed-off-by: Coco Li <lixiaoyan@google.com> > > --- > > include/net/ipv6.h | 33 +++++++++++++++++++++++++++++++++ > > 1 file changed, 33 insertions(+) > > > > diff --git a/include/net/ipv6.h b/include/net/ipv6.h > > index d383c895592a..a11d58c85c05 100644 > > --- a/include/net/ipv6.h > > +++ b/include/net/ipv6.h > > @@ -500,6 +500,39 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb) > > return jhdr->nexthdr; > > } > > > > +/* Return 0 if HBH header is successfully removed > > + * Or if HBH removal is unnecessary (packet is not big TCP) > > + * Return error to indicate dropping the packet > > + */ > > +static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb) > > +{ > > + const int hophdr_len = sizeof(struct hop_jumbo_hdr); > > + int nexthdr = ipv6_has_hopopt_jumbo(skb); > > + struct ipv6hdr *h6; > > + > > + if (!nexthdr) > > + return 0; > > + > > + if (skb_cow_head(skb, 0)) > > + return -1; > > err = skb_cow_head(skb, 0); > if (err) > return err; > > Alternatively, if you want to keep it simple, make the function bool > and return false on `if (skb_cow_head(skb, 0)` and true otherwise. > > > + > > + /* Remove the HBH header. > > + * Layout: [Ethernet header][IPv6 header][HBH][L4 Header] > > + */ > > + memmove(skb->data + hophdr_len, > > + skb->data, > > This can fit into the previous line. > > > + ETH_HLEN + sizeof(struct ipv6hdr)); > > Not correct at this point. I assume you took the implementation from > ip6_offload.c[0], but ::gso_segment() and ::ndo_start_xmit() are two Traditionally forgot to paste the links to the end of the mail. Pls look at the end of this one for them (if I don't forget to paste them again :clownface:). > different entry points. Here you may have not only Eth header, but > also VLAN, MPLS and whatnot. > Correct way would be: > > memmove(skb_mac_header(skb) + hophdr_len, skb_mac_header(skb), > ipv6_hdr(skb) - skb_mac_header(skb) + > sizeof(struct ipv6hdr)); > > > + > > + skb->data += hophdr_len; > > + skb->len -= hophdr_len; > > + skb->network_header += hophdr_len; > > skb->mac_header also needs to be adjusted, the fact that it's equal > to skb->data at the entry of ::ndo_start_xmit() doesn't mean > anything. Also, while I'm here: you should use skb_may_pull() + {,__}skb_pull() here instead of manual maths. ::network_header and ::mac_header still need to be adjusted manually tho. > > > + > > + h6 = ipv6_hdr(skb); > > + h6->nexthdr = nexthdr; > > + > > + return 0; > > +} > > Please switch all the places where the same logics is used to your > new helper. > > > + > > static inline bool ipv6_accept_ra(struct inet6_dev *idev) > > { > > /* If forwarding is enabled, RA are not accepted unless the special > > -- > > 2.38.1.584.g0f3c55d4c2-goog > > Thanks, > Olek [0] https://elixir.bootlin.com/linux/v6.1-rc6/source/net/ipv6/ip6_offload.c#L92 Thanks, Olek
diff --git a/include/net/ipv6.h b/include/net/ipv6.h index d383c895592a..a11d58c85c05 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -500,6 +500,39 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb) return jhdr->nexthdr; } +/* Return 0 if HBH header is successfully removed + * Or if HBH removal is unnecessary (packet is not big TCP) + * Return error to indicate dropping the packet + */ +static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb) +{ + const int hophdr_len = sizeof(struct hop_jumbo_hdr); + int nexthdr = ipv6_has_hopopt_jumbo(skb); + struct ipv6hdr *h6; + + if (!nexthdr) + return 0; + + if (skb_cow_head(skb, 0)) + return -1; + + /* Remove the HBH header. + * Layout: [Ethernet header][IPv6 header][HBH][L4 Header] + */ + memmove(skb->data + hophdr_len, + skb->data, + ETH_HLEN + sizeof(struct ipv6hdr)); + + skb->data += hophdr_len; + skb->len -= hophdr_len; + skb->network_header += hophdr_len; + + h6 = ipv6_hdr(skb); + h6->nexthdr = nexthdr; + + return 0; +} + static inline bool ipv6_accept_ra(struct inet6_dev *idev) { /* If forwarding is enabled, RA are not accepted unless the special