From patchwork Fri Dec 2 22:12:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coco Li X-Patchwork-Id: 29123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1096202wrr; Fri, 2 Dec 2022 14:17:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Rdu6yrLxedDRI9YGHS0bygBWM5Q/NWuhKSjsn2RqwBt5DV+5zaeMSEqzeRMLUxmf35McN X-Received: by 2002:a17:906:54cf:b0:7ae:43f5:a2a3 with SMTP id c15-20020a17090654cf00b007ae43f5a2a3mr59775417ejp.595.1670019466785; Fri, 02 Dec 2022 14:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670019466; cv=none; d=google.com; s=arc-20160816; b=Smgpc9k9YJxy2WWUuPITDJrn0mojixIgALKWnFiumZb7cne1cdU8ZjM584fwP6ZouO 84U/hWuDnlDGNC6o8qYbpCXmR1jvA68EbSk6E72uCYII0KFt6kFtZ3p+z5VdduSrB27x QpR4tAyS8OEqewNsPK/HNDWLwmgKNmbDna1PfN6kZ8zJmL3yK7WCX4KXiFPUfa1fxQI4 nVlsZUPkHYm+f5IPlZtPOTN4uYsbDAPnTYhO3xCbF2EfSG9j8kBJFIpyqrylsGrWY5gp AwAk1pgBgO6KJyfdgezyBW3VErW99COaMOCHm96CGQ7KiMnN25tf6jMdyaOe8X7ihz69 e/Eg== 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=aqtQqt3CYbfEmZYhGTH/QgYDRef/TM1s51odegjsqeI=; b=JHiYLZhh4+f1x3eRaKG5A1CI/EPfs9t+G3wUwZTJBMwA5nhQ0JlQeT1DUSgLg/ODVn xLciY6+yfY+6zE041iMTTTC8/1/bPfUdGiNCxMGf27gDW1Iu1IZOehTuge3ywIMdVgiR gmwRDB3qwXs7HL7vXVdCUOxG4kvoM+E3nTHIg21yuDqzOOC/pKEZFfVLoyVBoEUYYgfJ 78mCaM3cFP79UHMjCCGVFlnOtCxyvV8y8u9NHVuTp9eclb0wbuYK/k7o2uluSVXs8lZZ Ni7dZvpxM0cduVGm/LXntjFkZql1h/9au0s42rMGsztIx1ZVIAhEWMtfQLbczcFViOh7 VFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HdgVFnSL; 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 y17-20020a056402171100b0046800749660si6450759edu.207.2022.12.02.14.17.20; Fri, 02 Dec 2022 14:17:46 -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=HdgVFnSL; 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 S229436AbiLBWMV (ORCPT + 99 others); Fri, 2 Dec 2022 17:12:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbiLBWMU (ORCPT ); Fri, 2 Dec 2022 17:12:20 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08392F899C for ; Fri, 2 Dec 2022 14:12:19 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3d0465d32deso63620787b3.20 for ; Fri, 02 Dec 2022 14:12:18 -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=aqtQqt3CYbfEmZYhGTH/QgYDRef/TM1s51odegjsqeI=; b=HdgVFnSLUnEmFG4MkBjFMO4G2tTWjjsOcCEdrCCe+T/mJxH48wYxh0iNqe6oMNckjR OPoNQfdgUK0jrKTtdGC9jVZRT8z+mfsZwc65UsCrVc/ms9azzlRS/eOsXn00RItDM4TL 1b623/78nCbsdtkrLJe7LBgL2mlvaW2QnLxQDEECMJy8iN18LfGdLCv1XAanIvgQ/ifn hKzUAN9CEY98iN9PzLbfT3UDryQE3BXEzb/qWphS/1MWZNDX25qiiIeHhGSWJ6UVIcVG 0Uqu6qrgKrnGHZJ3OKKgpDfz8JkTn92v0KcwF/ZxfzKV+epZN5gnlW3XbWzpPa8xogbh tpTQ== 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=aqtQqt3CYbfEmZYhGTH/QgYDRef/TM1s51odegjsqeI=; b=emIyguDtRiHgHjfWr8g8D92R9FxrnIj1dQFwzQKG08+++eZ+eLUO+xQQ7GSro/pRzs AIJ3pSmbodOHRQJgJwLkHp/c3okwWd3wm9LunDfnAgK1pGq0albLw6a5y+jY5ZmI0BhB hwmJ1E0TT30EqYOjlhWzGyBMC6lI/U9JtDAS6cb7PTNwFcWim4H7lq0DG7p0qQEnwhdT HyKVFDYjElQjB2Mke7tDa3qn0OTYvS0GMND9EdwE2fcLe2s0FLaWE4WVv9Xhg4u+Xs/S 2/O1qZwuY+qYeEMAEHPZBJ8JIYBqB0qZILWKiJZ/XZ8KJAX6czjaU/gu0u9TAfaI+YPt YFCA== X-Gm-Message-State: ANoB5pmFPb7NQeVwR/r8LiohM+W/dBXNU3JYAQpI63GHQQiZuJCKa//f wiRSfW792qNSdGGoGQ3OVVvN4iNt7STzEOw= X-Received: from lixiaoyan-desktop.svl.corp.google.com ([2620:15c:2c4:201:806c:1abb:ce24:13cf]) (user=lixiaoyan job=sendgmr) by 2002:a81:510:0:b0:356:4adb:67b4 with SMTP id 16-20020a810510000000b003564adb67b4mr57763344ywf.141.1670019138178; Fri, 02 Dec 2022 14:12:18 -0800 (PST) Date: Fri, 2 Dec 2022 14:12:12 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221202221213.236564-1-lixiaoyan@google.com> Subject: [RFC net-next v4 1/2] IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver From: Coco Li To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Michael Chan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Coco Li 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751142332509341396?= X-GMAIL-MSGID: =?utf-8?q?1751142332509341396?= 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 --- include/net/ipv6.h | 35 +++++++++++++++++++++++++++++++++++ net/ipv6/ip6_offload.c | 27 ++++----------------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index d383c895592a..08adec74f067 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -500,6 +500,41 @@ 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_mac_header(skb) + hophdr_len, skb_mac_header(skb), + skb_network_header(skb) - skb_mac_header(skb) + + sizeof(struct ipv6hdr)); + + if (unlikely(!pskb_may_pull(skb, hophdr_len))) + return -1; + + skb->network_header += hophdr_len; + skb->mac_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 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c index 3ee345672849..00dc2e3b0184 100644 --- a/net/ipv6/ip6_offload.c +++ b/net/ipv6/ip6_offload.c @@ -77,7 +77,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, struct sk_buff *segs = ERR_PTR(-EINVAL); struct ipv6hdr *ipv6h; const struct net_offload *ops; - int proto, nexthdr; + int proto, err; struct frag_hdr *fptr; unsigned int payload_len; u8 *prevhdr; @@ -87,28 +87,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, bool gso_partial; skb_reset_network_header(skb); - nexthdr = ipv6_has_hopopt_jumbo(skb); - if (nexthdr) { - const int hophdr_len = sizeof(struct hop_jumbo_hdr); - int err; - - err = skb_cow_head(skb, 0); - if (err < 0) - return ERR_PTR(err); - - /* remove the HBH header. - * Layout: [Ethernet header][IPv6 header][HBH][TCP header] - */ - memmove(skb_mac_header(skb) + hophdr_len, - skb_mac_header(skb), - ETH_HLEN + sizeof(struct ipv6hdr)); - skb->data += hophdr_len; - skb->len -= hophdr_len; - skb->network_header += hophdr_len; - skb->mac_header += hophdr_len; - ipv6h = (struct ipv6hdr *)skb->data; - ipv6h->nexthdr = nexthdr; - } + err = ipv6_hopopt_jumbo_remove(skb); + if (err) + return ERR_PTR(err); nhoff = skb_network_header(skb) - skb_mac_header(skb); if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) goto out;