Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6325213rwb; Tue, 22 Nov 2022 11:41:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7C7ou7w2qYR2NsZFJkWGLimMQtl8DMyGXgVbbOqDd/zS+k8KOfbE91duO4dPQZbqgwqSKe X-Received: by 2002:aa7:c60b:0:b0:462:750b:bced with SMTP id h11-20020aa7c60b000000b00462750bbcedmr21827156edq.313.1669146113310; Tue, 22 Nov 2022 11:41:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669146113; cv=none; d=google.com; s=arc-20160816; b=i6tsSIokMlEpYxKnfOeS9fan/fSsB48lsWlCH3USVzo6gAsUGhOKiGk69cpz3K+8pR QFajfe5fwp7dL8rTlS4oDQrylf37V7r6ug7kv2RAcQJggCEjAO0Pwbm0IBUVcYCTXKbu PQNpXQzqhSVLFdYt7nENgOKItN6FhlkfRrj08FqBJhiw8ZOds1XTji5NF/QWQoO9pMPh wNYHe2RxTnmzcxFgrvf9Phk83yyfBgk6xLCOzmI1HLiEsBhLPHJkLFCjR+bVojzHYxQz 9uKkiF1U+mdXCv4WtR1NM7zq+6VxtlOLPORfC99lMCJ5XBmmt/X/jwQWqiqiH/9D1/ME KYmQ== 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=mpsxgL4J7jH1V90MXsCgIR25TFLK7ajfoilM0OWi7h3Ssa7Osh/3LwVIExVemVNrCR 6qyZyHVKyufejLkHCi+CuJ/JJHZdGnD4qkFEbjrqvEIB+1r4yJbL4j/YDbdOJ1oQHHK7 cp5Z5xb1HWChGasCk+qbq3T7bBhoX4S3pRtixgfhM1WeFvETtwngBcJZOPHOFlM33Re7 bRbAQ4ET8VDgRqCHe9EBmwMt2EU+lwodlqxMY3NkDNrqWnCS/A7P8A3jFCK7yVCCOhZs 09ARoMH8MMNxAgSF4dtMROQGSG9pv1P4iZ0CEmdeaczOum1doyu81DyGaWirEYfzjEkJ 2zlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rG8Z0Vfw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd10-20020a170907968a00b007830f14fffesi14265068ejc.375.2022.11.22.11.41.30; Tue, 22 Nov 2022 11:41:53 -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=rG8Z0Vfw; 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 S234626AbiKVTd2 (ORCPT + 90 others); Tue, 22 Nov 2022 14:33:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234830AbiKVTdE (ORCPT ); Tue, 22 Nov 2022 14:33:04 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE8B1F2D3 for ; Tue, 22 Nov 2022 11:32:51 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id u6-20020a170903124600b00188cd4769bcso12174612plh.0 for ; Tue, 22 Nov 2022 11:32:51 -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=rG8Z0VfwaA61bPZeGe5CnP8ilpFBvhTqlF9lTA6QpM53rohJc2wzAw7rs1GQZW+NEv RLWLFEJhfvjgk5RbgXqLj58WpJioOScTUo8jdDGop2H5QOtDBWju/w7GfldL1KQnuH+l PuB6BmbX81PIYU7z0tKY2wbl/4rPYVu3PedIbk4oZgIXnLCNEfxYxBRLjdjn2pI1pQJG az8cFasXy0LoGu8oiPGcvsZyccvAbo3ftp8Rxl8viuaU6Ti8i91/Oy//HMFGJjLWNDrD QtdgFE0FLx2dPwPNoRl5SdCCwfUfsRmyqW56AIBGr6vVUb8+gBKn1amV8CZPUjCXvtLD v41g== 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=20o+olvYcCx8HHVRnBWj2oEpsIyaDYw1gbRftEChfhW4cer6bBMYHFOtcZyFNy6+m7 3QcSGbu4csh71PYd1zxEThhI6rKAQRF13gs3fLO05hVBV1zTCtimnExOEdIqvDAxnXR3 2nJ4xSaOANvdpvQWrQoK5DxmSTrSlbTMTWmuq976glq+KYogAk9pXLo4SMWR1lGyO9GA 4nEE5Hw0c3TOCMLz9MT6BZ86IZ4hMqNj6nNpOfvNWdK9GBC7zsPUCRCgD5vRAwSIcQbR j9ujBzQvqMNr4umCz9eLQAe3NGH9U1PlKpM2gwlCL4owzd4dhpSrdoAx7tTOsGsyjR5h W1GQ== X-Gm-Message-State: ANoB5pk6+RGMX6WPSbEcsn2f0KqcIU8T4kTHb6pXRUkMAce6Q5SAkzzS vvv5V/ZCWro51ETRuzL6kilT43/RtN02kSE= X-Received: from lixiaoyan-desktop.svl.corp.google.com ([2620:15c:2c4:201:d85f:1168:cf63:556b]) (user=lixiaoyan job=sendgmr) by 2002:a17:902:a989:b0:188:d6c7:e7b7 with SMTP id bh9-20020a170902a98900b00188d6c7e7b7mr5323760plb.16.1669145571058; Tue, 22 Nov 2022 11:32:51 -0800 (PST) Date: Tue, 22 Nov 2022 11:32:38 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221122193239.3159985-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 To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Michael Chan Cc: linux-kernel@vger.kernel.org, Coco Li 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 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; + + /* 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 -- 2.38.1.584.g0f3c55d4c2-goog