From patchwork Wed Apr 14 23:25:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 421522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CDADC433ED for ; Wed, 14 Apr 2021 23:25:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EA2D61220 for ; Wed, 14 Apr 2021 23:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237481AbhDNX0S (ORCPT ); Wed, 14 Apr 2021 19:26:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:49902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233459AbhDNX0O (ORCPT ); Wed, 14 Apr 2021 19:26:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B38CE61242; Wed, 14 Apr 2021 23:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618442753; bh=T7KqcsJXuzCajU7swIRrYJFoQd5vgDu/miTpVfFOxRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmmiQomsK14szSeFW/FfGOVbOivgka0CCqvkJ4KLfHQG/5x1/Q09uu6x4uma9geoz SxWdjew002fr9h77VA6n84pD2Wc3LihbLILe4qSSqmGwWPfCncNG8aGXQNJA56EM+0 OVGVfVvhkn1/eX5HsNo1EIh9EqPyscXoLfCU5gAkeCjNZI1u2mKT5b382/pE8ILsDR WL9/QR0n1dw/r4CTv8yK4F3VoC3v0nvyMqAPKMslNxIpLjEOFM22N5dItBd9Vd+n/P s9RF1v15nJVLch/+JAwizRX98tLjDdXeg4wLWD6TyWDETLwDEFEfiz2SK3ZuVeDXaR 6yNxjDS9VtfhA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, "Cc : Steffen Klassert" , Huy Nguyen , Raed Salem Subject: [PATCH net 2/3] net/xfrm: Add inner_ipproto into sec_path Date: Wed, 14 Apr 2021 16:25:39 -0700 Message-Id: <20210414232540.138232-3-saeed@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210414232540.138232-1-saeed@kernel.org> References: <20210414232540.138232-1-saeed@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Huy Nguyen The inner_ipproto saves the inner IP protocol of the plain text packet. This allows vendor's IPsec feature making offload decision at skb's features_check and configuring hardware at ndo_start_xmit. For example, ConnectX6-DX IPsec device needs the plaintext's IP protocol to support partial checksum offload on VXLAN/GENEVE packet over IPsec transport mode tunnel. Signed-off-by: Raed Salem Signed-off-by: Huy Nguyen Cc: Steffen Klassert --- include/net/xfrm.h | 1 + net/xfrm/xfrm_output.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/net/xfrm.h b/include/net/xfrm.h index c58a6d4eb610..e535700431fb 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -1032,6 +1032,7 @@ struct sec_path { struct xfrm_state *xvec[XFRM_MAX_DEPTH]; struct xfrm_offload ovec[XFRM_MAX_OFFLOAD_DEPTH]; + u8 inner_ipproto; }; struct sec_path *secpath_set(struct sk_buff *skb); diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c index e4cb0ff4dcf4..da412928093b 100644 --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c @@ -565,6 +565,36 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skb return 0; } +/* Save inner ip protocol for vendor offload usage */ +static void get_inner_ipproto(struct sk_buff *skb, struct sec_path *sp) +{ + const struct ethhdr *eth; + + if (!skb->inner_protocol) + return; + + if (skb->inner_protocol_type == ENCAP_TYPE_IPPROTO) { + sp->inner_ipproto = skb->inner_protocol; + return; + } + + if (skb->inner_protocol_type != ENCAP_TYPE_ETHER) + return; + + eth = (struct ethhdr *)skb_inner_mac_header(skb); + + switch (eth->h_proto) { + case ntohs(ETH_P_IPV6): + sp->inner_ipproto = inner_ipv6_hdr(skb)->nexthdr; + break; + case ntohs(ETH_P_IP): + sp->inner_ipproto = inner_ip_hdr(skb)->protocol; + break; + default: + return; + } +} + int xfrm_output(struct sock *sk, struct sk_buff *skb) { struct net *net = dev_net(skb_dst(skb)->dev); @@ -594,8 +624,12 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) kfree_skb(skb); return -ENOMEM; } - skb->encapsulation = 1; + sp->inner_ipproto = 0; + if (skb->encapsulation) + get_inner_ipproto(skb, sp); + + skb->encapsulation = 1; sp->olen++; sp->xvec[sp->len++] = x; xfrm_state_hold(x);