From patchwork Sat Jan 28 15:58:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119869 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 351DAC27C76 for ; Sat, 28 Jan 2023 15:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234421AbjA1P65 (ORCPT ); Sat, 28 Jan 2023 10:58:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbjA1P6y (ORCPT ); Sat, 28 Jan 2023 10:58:54 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8514130B1A for ; Sat, 28 Jan 2023 07:58:43 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id ll10so4878334qvb.6 for ; Sat, 28 Jan 2023 07:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IPo2A8/WyRg0uZtMgMrJXTBrF2bqp+xJsCXZ+utu8AQ=; b=bAY+cUHXwYrY8TWyEPo7qAwYVGbVc8SeroagwyR+TekNCmaIiSNMtiuE+Q9LiUol+A 5ccA4bk8He8EnawA6rAAHj8ZJdSNQr+fOcq0ehv0sHQ+woJZBikE7KMiQvaTymYoUZW8 elEUR5j2/SCulGejumMQ7lHjHAMMA6oYYJ5JPQ9uHynmUP9KExAQC9Va3KK7RABU3WrK dKP24tQ4e/wQGrL+q5sBxqd3rFCxvldXJ0xczoFy10QE5yqXuoJVyPQb5r52Nl+7Ce4n 6TDBq5qosRxkrjuP+5kDuMqnI+V6KHtvxm5hjJxQidZWdurwLI/gR/V7kTjnlUeVDKry he/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IPo2A8/WyRg0uZtMgMrJXTBrF2bqp+xJsCXZ+utu8AQ=; b=3j6lXMiAAwZWUGs7udJqMxqNjJ3+XNEYK79fZYElQmjkEiPSzAixP0AV6wLKB66yjA LQhKnNwhxzG+fl6dl8LYXyXWAL+WHDsrcHKAAODaXJ4gmwtni9qUmmMtFNerjHWXVovo ntAmt6ocNVMFnqaVMZugWwkKv1dDN8yEKBx93R3/ZLP7tGxn93wiiNBX/iacIQb2rq8p 3TRl0NPcx7IkvO7/Zvo1563D0HEhlfpmQ3rfr7rybfS/DnRkuX3iMMuWk4QFtKSYAPuy eAJnzdYILyUXBqoWxJzq0PR2/s007neZhZz5EakamBwgMRB7+Mql3SaG57eT/SnnwBYA TPIQ== X-Gm-Message-State: AO0yUKUMfWQWxfyTH0lja4kxz1JGQiEN3GggWTTppB+Ebf3De2Pa7kE3 p9ADKy2/VCTBQAkmcmpLIG7IILp+fuNv3Q== X-Google-Smtp-Source: AK7set+EYCXAlvAOMFD68ir0VQV0WpFaQ8mPs0IjY5LueEscMrnsvtd2IN6hoGhFiiy4hMlt/SJ7NA== X-Received: by 2002:a05:6214:190f:b0:537:7c16:1775 with SMTP id er15-20020a056214190f00b005377c161775mr14271427qvb.44.1674921522219; Sat, 28 Jan 2023 07:58:42 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:42 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 01/10] net: add a couple of helpers for iph tot_len Date: Sat, 28 Jan 2023 10:58:30 -0500 Message-Id: <9a810d8265b12d95e6effff76e2ec722f283b094.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds three APIs to replace the iph->tot_len setting and getting in all places where IPv4 BIG TCP packets may reach, they will be used in the following patches. Note that iph_totlen() will be used when iph is not in linear data of the skb. Signed-off-by: Xin Long Reviewed-by: David Ahern --- include/linux/ip.h | 21 +++++++++++++++++++++ include/net/route.h | 3 --- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/linux/ip.h b/include/linux/ip.h index 3d9c6750af62..d11c25f5030a 100644 --- a/include/linux/ip.h +++ b/include/linux/ip.h @@ -35,4 +35,25 @@ static inline unsigned int ip_transport_len(const struct sk_buff *skb) { return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb); } + +static inline unsigned int iph_totlen(const struct sk_buff *skb, const struct iphdr *iph) +{ + u32 len = ntohs(iph->tot_len); + + return (len || !skb_is_gso(skb) || !skb_is_gso_tcp(skb)) ? + len : skb->len - skb_network_offset(skb); +} + +static inline unsigned int skb_ip_totlen(const struct sk_buff *skb) +{ + return iph_totlen(skb, ip_hdr(skb)); +} + +/* IPv4 datagram length is stored into 16bit field (tot_len) */ +#define IP_MAX_MTU 0xFFFFU + +static inline void iph_set_totlen(struct iphdr *iph, unsigned int len) +{ + iph->tot_len = len <= IP_MAX_MTU ? htons(len) : 0; +} #endif /* _LINUX_IP_H */ diff --git a/include/net/route.h b/include/net/route.h index 6e92dd5bcd61..fe00b0a2e475 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -35,9 +35,6 @@ #include #include -/* IPv4 datagram length is stored into 16bit field (tot_len) */ -#define IP_MAX_MTU 0xFFFFU - #define RTO_ONLINK 0x01 #define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE)) From patchwork Sat Jan 28 15:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119870 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EF85C38142 for ; Sat, 28 Jan 2023 15:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbjA1P7H (ORCPT ); Sat, 28 Jan 2023 10:59:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231496AbjA1P6z (ORCPT ); Sat, 28 Jan 2023 10:58:55 -0500 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C174E2943B for ; Sat, 28 Jan 2023 07:58:44 -0800 (PST) Received: by mail-qv1-xf2b.google.com with SMTP id jf11so2256627qvb.4 for ; Sat, 28 Jan 2023 07:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tl5Hvsf/bhbzo4TjITsPEwXtRmHZPlZaj/ryQGs8Zww=; b=GoCzo2xvQ5wjPwW1SIpoPIv7J0LYWPvzomvgTUVTHqCeUwYvD/0QGeyBEWzDl2O+Ru Qj/0txIRCGfK31jDrfrBj5JTkmykZXBLQ3dNyT5W3x88lLeLG9cIDkMsyaitAj0zt/E0 LDOIR5TVUAlWXfc+x4w4N6NzckkyJfSPuLIsKxo8JsMf/iDEqkDuMILlwjftFlzWfvHK 8LVaMF8qttSfbFOfpp44qHsXBtLs5D7iWAtMvhm0f4OCoFiSdnhbnSM7tQabYhcueWMH 2RpkiAE9rRAp7KydQI6qg3h9F2kNtkkhnYje20PzhOwPwxHXhvXfLC/ky5UlQjbpQ2dm 6piQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tl5Hvsf/bhbzo4TjITsPEwXtRmHZPlZaj/ryQGs8Zww=; b=gmMilo+HRYBuDKrkM8iGzzK3b+RFZgDFFVaMhhO7238HdbOe0yVZUj0Y+87awi3aNV ntQkUQwpwQ31TE6Lg9rJKoX69dpJI+W6LsOwaqEpltyiX7RLe7zwu36ubyqYf3Hc1sYz A6H8GoPekQ6U6ntxOHs8FkdyPJqdvqTps1HTMFbmVkg7MnyAAzYEhUC+iUdtkIKmGCdB lI7iuxZVfulHCsEu2OdlZuFS8AiMGsI98hLKdPZMGpV+93yCpaux5G3HfgJ4CDrjaOfo 0vFedN0WtO0BIEPHvA4gzFK7JNpMuXgJqMp6YyjWiwj+2CeyDYBcITsruxz4eEJ6m48n UKDg== X-Gm-Message-State: AO0yUKUD4LxWaXlx5FT0YZ6UTgBCHeCbMnHHXZaDGXQU4v3im+UK9xnb V/D66d9Az01E+6KhWvEBK/BwGem40q36FQ== X-Google-Smtp-Source: AK7set+sTvZa/K5s+5/+d7n8APwh8duYvXDQQi+Uq5/GdptoSFGX4u4/cpqlAZ6ny14DgH83HHR86Q== X-Received: by 2002:a05:6214:d4f:b0:53a:1a88:f740 with SMTP id 15-20020a0562140d4f00b0053a1a88f740mr5609249qvr.27.1674921523421; Sat, 28 Jan 2023 07:58:43 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:43 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 02/10] bridge: use skb_ip_totlen in br netfilter Date: Sat, 28 Jan 2023 10:58:31 -0500 Message-Id: <4542573738ca3499bd15b2e9980c0176db442dc7.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org These 3 places in bridge netfilter are called on RX path after GRO and IPv4 TCP GSO packets may come through, so replace iph tot_len accessing with skb_ip_totlen() in there. Signed-off-by: Xin Long Reviewed-by: Nikolay Aleksandrov --- net/bridge/br_netfilter_hooks.c | 2 +- net/bridge/netfilter/nf_conntrack_bridge.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c index f20f4373ff40..b67c9c98effa 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -214,7 +214,7 @@ static int br_validate_ipv4(struct net *net, struct sk_buff *skb) if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) goto csum_error; - len = ntohs(iph->tot_len); + len = skb_ip_totlen(skb); if (skb->len < len) { __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c index 5c5dd437f1c2..71056ee84773 100644 --- a/net/bridge/netfilter/nf_conntrack_bridge.c +++ b/net/bridge/netfilter/nf_conntrack_bridge.c @@ -212,7 +212,7 @@ static int nf_ct_br_ip_check(const struct sk_buff *skb) iph->version != 4) return -1; - len = ntohs(iph->tot_len); + len = skb_ip_totlen(skb); if (skb->len < nhoff + len || len < (iph->ihl * 4)) return -1; @@ -256,7 +256,7 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb, if (!pskb_may_pull(skb, sizeof(struct iphdr))) return NF_ACCEPT; - len = ntohs(ip_hdr(skb)->tot_len); + len = skb_ip_totlen(skb); if (pskb_trim_rcsum(skb, len)) return NF_ACCEPT; From patchwork Sat Jan 28 15:58:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119871 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 065A6C27C76 for ; Sat, 28 Jan 2023 15:59:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234496AbjA1P7I (ORCPT ); Sat, 28 Jan 2023 10:59:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbjA1P6z (ORCPT ); Sat, 28 Jan 2023 10:58:55 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C45163401A for ; Sat, 28 Jan 2023 07:58:45 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id o5so6546996qtr.11 for ; Sat, 28 Jan 2023 07:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hndcFGcKXsUPoSfBcORkIp1PbmWGWJK7GRgLe6RV99s=; b=Nf5WzrdVRjj1JZEc88Jb9MRW3O2fqDrxAjneWJrm39mErcA3ywJyq94XmXq3rlrOOB UZqpnWjM56Aaup6kE9oH+J0RSOSSRpHjnaLBakNrGmzWeeQHNV9LkopV38xaRH0vbvYr R7qcdjm1BXaqLVJzfNQN6pS0UcoZvGB6DMklcFiEKdUfv/HkocfzhGcWi798mfnrs7sC Zl9vqxM17JNVu7nbO7CJe26IeID+R9fZsSAO9rLneMp3qNcm77EIokBoizXCXYlHunI8 cy/OEgyhEnmVYVFsRTgpgBuz5uHIqlihaMm9Ij8lVWHVfyvl2JHsNm46UG2rlhGeVqP+ wKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hndcFGcKXsUPoSfBcORkIp1PbmWGWJK7GRgLe6RV99s=; b=zw/NwNeNnetagUS9Kc4AgE1vVXkD2NRVVi1n/iamFfE5bxZOWzV3QulRXlQnjNgylc AmnLAaScFXHaEn6rRqWjgqIALNSP8kw2Szy5zexeLpe07ytov+r4BS/JfDILcjMNBxRn 1n+IWAlfHDPF8mD96OMorCSMrPNzJwKfvCaOWJZevfWB/WfCgSi/06Ns7EVgHzKB8vSi ELkUn36Ol4JBa4ghlU57wYfwo7NBDido/Le7lC2/N+4M7U3SvVnthoznQgnqx9HYwBwk x12XATEFJqWmIZHdbc8vq4+iltYCKUcAVsbVE49N5czXEqdO8Zy4iNwp52+D0MV5hoGt 1UhA== X-Gm-Message-State: AFqh2kp20eSH8hqv+Fs44ZcllU5htengf230/9ttIW70wBHYQj7i3g2Y Yj1HnOq6pIOgvJurkORhp+4giMIBXrErtg== X-Google-Smtp-Source: AMrXdXu+n9BuV4pLHUpLj+kizgdRahvETZsjNFV0/rKBbcs0pArGRdUmone/I2Rel1SYEgJsRk5XcQ== X-Received: by 2002:ac8:7341:0:b0:3b6:334b:2cb7 with SMTP id q1-20020ac87341000000b003b6334b2cb7mr66061716qtp.19.1674921524560; Sat, 28 Jan 2023 07:58:44 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:44 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 03/10] openvswitch: use skb_ip_totlen in conntrack Date: Sat, 28 Jan 2023 10:58:32 -0500 Message-Id: <8ea56cf09856cedfa4c7a3f6e266c84723de8544.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org IPv4 GSO packets may get processed in ovs_skb_network_trim(), and we need to use skb_ip_totlen() to get iph totlen. Signed-off-by: Xin Long Reviewed-by: Aaron Conole --- net/openvswitch/conntrack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c index c8b137649ca4..2172930b1f17 100644 --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -1103,7 +1103,7 @@ static int ovs_skb_network_trim(struct sk_buff *skb) switch (skb->protocol) { case htons(ETH_P_IP): - len = ntohs(ip_hdr(skb)->tot_len); + len = skb_ip_totlen(skb); break; case htons(ETH_P_IPV6): len = sizeof(struct ipv6hdr) From patchwork Sat Jan 28 15:58:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119872 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF463C61D97 for ; Sat, 28 Jan 2023 15:59:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234122AbjA1P7J (ORCPT ); Sat, 28 Jan 2023 10:59:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234077AbjA1P64 (ORCPT ); Sat, 28 Jan 2023 10:58:56 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E7230B3D for ; Sat, 28 Jan 2023 07:58:46 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id q15so6617006qtn.0 for ; Sat, 28 Jan 2023 07:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uV8oKg/2RyjtLIY7E/4LxV+Y00Cwz/EH5dgxKXOqfWQ=; b=hNYBgbcN29Mi/UztiiRLWzxxkbaew/3tC57kEl+OZ7pK5theW0nRXW03ia6rzTj/Sb gWVQVGE+wDh152t5Bh3JKRv59mwl7r7AodCNMIwj8FQfqiCRF1NmmKwVBnYJfE7fiN/t 9ZigKPfzHFPx+MScWoidxUCy29sEX3rh3KRle100ln7yhzKE0OmbnmsEpE1IdOB/+VFr xPemZR6NhaME0pG57IXPkp2g5bsVKLL8ZRtvh8FuAQSK4XbClXQKNSNXaUog6j4Ki3Vw CQngqKBOpyzCdE/r3VoeSg5jve11TgJOEfaQ7DLoF97IlSsvBSUz/M0fw4KSlVNf5904 ksfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uV8oKg/2RyjtLIY7E/4LxV+Y00Cwz/EH5dgxKXOqfWQ=; b=M5LrqEGVwoSNnxzTSpJqBtnInZVXecc8Mx2Ap+KUNoGcI3nZ6SXvuTVahYaehGEI7J UGLGeeuJtjuYBSWXeKA5lWEVkUv0g7Bshz59xJd6a+R2cn33Jbz6/+Dlgvo8NZLabAQW dQp5HCxwzk1r0fbxMG4F6dYRAM6HH8pGaSYbSRsgDudfXVdONccYLUMttV2IHCAus7R8 /wrBsm+CCNbJ8bNsg1Uc+UMozQtAdahc+lSJYwv0WDcQ7pyxrdej0a3YrOTv77GWeAAv e4AutAcMykjM3yYTTexD9ZuEjAUcJd8SHkph4oyOolDfR1NBecfH52J8ZURkPmjjcl7J LC3w== X-Gm-Message-State: AO0yUKWysaBNHw6nAVVY/V+n1cvPf/ehXVfjGLXUldmVh/IX4+UmMRWY 16smVT9i94dkKYcG6pNBdrh2+QpbkZayGQ== X-Google-Smtp-Source: AK7set96arZ43OIUv82ZNjxl6eO+vnp+bknkXCBv04j2hL/ffJfMp0qllmBRma4rBCIYN3nRGCtOzA== X-Received: by 2002:a05:622a:1352:b0:3b8:4729:8225 with SMTP id w18-20020a05622a135200b003b847298225mr2324334qtk.9.1674921525717; Sat, 28 Jan 2023 07:58:45 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:45 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 04/10] net: sched: use skb_ip_totlen and iph_totlen Date: Sat, 28 Jan 2023 10:58:33 -0500 Message-Id: <0f06c043ca0b55cc1d3a848cf3013fb165a84bb2.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are 1 action and 1 qdisc that may process IPv4 TCP GSO packets and access iph->tot_len, replace them with skb_ip_totlen() and iph_totlen() accordingly. Note that we don't need to replace the one in tcf_csum_ipv4(), as it will return for TCP GSO packets in tcf_csum_ipv4_tcp(). Signed-off-by: Xin Long --- net/sched/act_ct.c | 2 +- net/sched/sch_cake.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 0ca2bb8ed026..d68bb5dbf0dc 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -707,7 +707,7 @@ static int tcf_ct_skb_network_trim(struct sk_buff *skb, int family) switch (family) { case NFPROTO_IPV4: - len = ntohs(ip_hdr(skb)->tot_len); + len = skb_ip_totlen(skb); break; case NFPROTO_IPV6: len = sizeof(struct ipv6hdr) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 3ed0c3342189..7970217b565a 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -1209,7 +1209,7 @@ static struct sk_buff *cake_ack_filter(struct cake_sched_data *q, iph_check->daddr != iph->daddr) continue; - seglen = ntohs(iph_check->tot_len) - + seglen = iph_totlen(skb, iph_check) - (4 * iph_check->ihl); } else if (iph_check->version == 6) { ipv6h = (struct ipv6hdr *)iph; From patchwork Sat Jan 28 15:58:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119873 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7636C38142 for ; Sat, 28 Jan 2023 15:59:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234140AbjA1P7K (ORCPT ); Sat, 28 Jan 2023 10:59:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234368AbjA1P64 (ORCPT ); Sat, 28 Jan 2023 10:58:56 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849FC34004 for ; Sat, 28 Jan 2023 07:58:48 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id h10so6026542qvq.7 for ; Sat, 28 Jan 2023 07:58:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=afll7bLWeOuZyip2GcygUZAanANAFhqpn9H/tM0HPJw=; b=BqdJ/5mEF8oUUpZogDzr1K5mgTgs48Yo0Rj3mHMzT/zAua9RX9pJ+RC+C4ZLz4wBwq QYDRx58aaTJFedlx42a+v7yMUGy8F6QjZOuLfloB4G+cxZsCpnJEzrO3imbcKLiFxo1b KkIdoRoeL734nlnsBRxAn6g5YCqLuHckpU5r99x7eMWbAPg0/8NemBkhpvC2ZH1B9nUW hRBcn2s8scIyQ+QfdgJ8x47GT1g1iGR7WX58yFJA5mrWldwqPqz+C2CiwYFeTJM8EgPa Er5abkY/UmMDxr3/sp9mwQL1SbFvDBQMQcQgTuYjMCjGWQUAmmEjJcyI0FYdKEyR0RyG uSNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=afll7bLWeOuZyip2GcygUZAanANAFhqpn9H/tM0HPJw=; b=zim+L3ShjeyKvb8TnDLZET+CbNRtw/7ZmzQgyieoyojJ1FcVPEItgxc31bo5h+wu8y gT4qGPcTG5uKhJdqXQtkcdTr+/px/S0IW0K0Gh5Y1dVGnzudu/28G565RLQlBojDAgzY rl01G5MLQqsrz2NijWNfNylyTr7GIB00H6LwLFJYbMmwv15b89MScfzXmDa2dmnVn5OT E0AOmYyLsCe6xcTEfNYs34ydVWOqu283M/ZWRMD3H9t5YwPM7fLpb8MfHLSBJRC8ITzP 2x7fnalAQpnMvMS8Jg1gN+GvB228Q4I2PcWPx6wjl0R+d1K4US/aVVZEOhcYWqkoAj3d cxYw== X-Gm-Message-State: AO0yUKWJzdmlnm9sTRCKLAPIln4gT0XLFUA0evQ6T6zqzzz8/n4EVN0n J5ijxXAndJJChfEOMBR30qD9V/RW+YuZ7w== X-Google-Smtp-Source: AK7set/4446tGgKk1iqaIgcO0sfcOe/L+gLaqKr0izoKaFC7YQRSfeKEvluA6+j1fu7lluTKm8VWMQ== X-Received: by 2002:a05:6214:1d09:b0:534:bcba:13f2 with SMTP id e9-20020a0562141d0900b00534bcba13f2mr4211629qvd.51.1674921526902; Sat, 28 Jan 2023 07:58:46 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:46 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 05/10] netfilter: use skb_ip_totlen and iph_totlen Date: Sat, 28 Jan 2023 10:58:34 -0500 Message-Id: <4a0907aff980537af36aafb49291049ecde89f27.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are also quite some places in netfilter that may process IPv4 TCP GSO packets, we need to replace them too. In length_mt(), we have to use u_int32_t/int to accept skb_ip_totlen() return value, otherwise it may overflow and mismatch. This change will also help us add selftest for IPv4 BIG TCP in the following patch. Note that we don't need to replace the one in tcpmss_tg4(), as it will return if there is data after tcphdr in tcpmss_mangle_packet(). The same in mangle_contents() in nf_nat_helper.c, it returns false when skb->len + extra > 65535 in enlarge_skb(). Signed-off-by: Xin Long --- include/net/netfilter/nf_tables_ipv4.h | 4 ++-- net/netfilter/ipvs/ip_vs_xmit.c | 2 +- net/netfilter/nf_log_syslog.c | 2 +- net/netfilter/xt_length.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/net/netfilter/nf_tables_ipv4.h b/include/net/netfilter/nf_tables_ipv4.h index 112708f7a6b4..947973623dc7 100644 --- a/include/net/netfilter/nf_tables_ipv4.h +++ b/include/net/netfilter/nf_tables_ipv4.h @@ -29,7 +29,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt) if (iph->ihl < 5 || iph->version != 4) return -1; - len = ntohs(iph->tot_len); + len = iph_totlen(pkt->skb, iph); thoff = iph->ihl * 4; if (pkt->skb->len < len) return -1; @@ -64,7 +64,7 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt) if (iph->ihl < 5 || iph->version != 4) goto inhdr_error; - len = ntohs(iph->tot_len); + len = iph_totlen(pkt->skb, iph); thoff = iph->ihl * 4; if (pkt->skb->len < len) { __IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INTRUNCATEDPKTS); diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c index 029171379884..80448885c3d7 100644 --- a/net/netfilter/ipvs/ip_vs_xmit.c +++ b/net/netfilter/ipvs/ip_vs_xmit.c @@ -994,7 +994,7 @@ ip_vs_prepare_tunneled_skb(struct sk_buff *skb, int skb_af, old_dsfield = ipv4_get_dsfield(old_iph); *ttl = old_iph->ttl; if (payload_len) - *payload_len = ntohs(old_iph->tot_len); + *payload_len = skb_ip_totlen(skb); } /* Implement full-functionality option for ECN encapsulation */ diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c index cb894f0d63e9..c66689ad2b49 100644 --- a/net/netfilter/nf_log_syslog.c +++ b/net/netfilter/nf_log_syslog.c @@ -322,7 +322,7 @@ dump_ipv4_packet(struct net *net, struct nf_log_buf *m, /* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */ nf_log_buf_add(m, "LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ", - ntohs(ih->tot_len), ih->tos & IPTOS_TOS_MASK, + iph_totlen(skb, ih), ih->tos & IPTOS_TOS_MASK, ih->tos & IPTOS_PREC_MASK, ih->ttl, ntohs(ih->id)); /* Max length: 6 "CE DF MF " */ diff --git a/net/netfilter/xt_length.c b/net/netfilter/xt_length.c index 1873da3a945a..b3d623a52885 100644 --- a/net/netfilter/xt_length.c +++ b/net/netfilter/xt_length.c @@ -21,7 +21,7 @@ static bool length_mt(const struct sk_buff *skb, struct xt_action_param *par) { const struct xt_length_info *info = par->matchinfo; - u_int16_t pktlen = ntohs(ip_hdr(skb)->tot_len); + u32 pktlen = skb_ip_totlen(skb); return (pktlen >= info->min && pktlen <= info->max) ^ info->invert; } From patchwork Sat Jan 28 15:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119874 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25D04C61DA4 for ; Sat, 28 Jan 2023 15:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234368AbjA1P7L (ORCPT ); Sat, 28 Jan 2023 10:59:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234157AbjA1P65 (ORCPT ); Sat, 28 Jan 2023 10:58:57 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B3334337 for ; Sat, 28 Jan 2023 07:58:49 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id d3so6569275qte.8 for ; Sat, 28 Jan 2023 07:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MRncoLC16sCZcT7mVpILb/C22ea0oeFd+8wfM8ixo3g=; b=lb0ABjRc6TlYm3pppuqizqvL55M/wwY0zRBlnx+IGJq7n2j2STa0rsQm6yv/4LXePr BHfTO6Swb7N3AqqBLm5R6jN7rkOlOFLsuogIVhcGGVEUi4lEpCtGKd+5FztdyWtln+aU /8nax5s+oQsot0nQ0gxsUd0i6Q0Vd5KfFVbMSwQpzk7jkj6yfW4MAmA4Qcg92Gx/WyNK 1yvYghNMpF0RDW31Y2VE7aV0WD0aebVBr27LGBXWg1AGSpZ28YBaCfMrI0YoUpbf6CLQ c/uv0FPZmZBlYBLBs6Yam2ZMNTJBdh5XF4U63V5lgTbM2nVqVVQTCrxt5NQxegsqvTy7 3kIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MRncoLC16sCZcT7mVpILb/C22ea0oeFd+8wfM8ixo3g=; b=XNIeoE699XA29etbZgN6cDAJqLHVMa2s5jVrENjXOLtc8d2fnCmzyTvEljsdUy9vkK zoPL1EGGUjByzwaa5JLEAMQ9DsLbIQppZupjPXquUR0EKx6yPxxOkCm0J99M1qyz13NI I3nIxxMMU72NFG+H3p+wLUCqatEDq5WUASuZX3MYPuuOmN1knBhrQUuRq4ocarLemRcL wlHCIRU3Df2zLuvvsXCWhqo1l97KVTobdLjtKaD2XCFhMw4dxKVbGEYZRiLYNrTWQRef N1vyeMIAXxWbExTAMWqRgQEVNa/iZnH+AcMCX6XpibPm+XTnMFUK2fB4OPkrPEL5I7YH tIsA== X-Gm-Message-State: AO0yUKV3H/qimjjEKIxBHAE1MAe0K+lha2kYBbg94DiAkHFyxEI05B+1 /n/cv5CZWyOFznaXksa7XM05YanDu5zXBA== X-Google-Smtp-Source: AK7set+rC8aMBZhTTGZ6t6ZBn5bOYEhWl5fHgt48bFiwN28/gey9r+q4pSOYokUX6V6nnPPJK9i+LA== X-Received: by 2002:a05:622a:1207:b0:3b8:2ea9:a09c with SMTP id y7-20020a05622a120700b003b82ea9a09cmr7231199qtx.1.1674921528105; Sat, 28 Jan 2023 07:58:48 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:47 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 06/10] cipso_ipv4: use iph_set_totlen in skbuff_setattr Date: Sat, 28 Jan 2023 10:58:35 -0500 Message-Id: <9518ab1e4124466c1bb9e026b5923d3562eef394.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It may process IPv4 TCP GSO packets in cipso_v4_skbuff_setattr(), so the iph->tot_len update should use iph_set_totlen(). Note that for these non GSO packets, the new iph tot_len with extra iph option len added may become greater than 65535, the old process will cast it and set iph->tot_len to it, which is a bug. In theory, iph options shouldn't be added for these big packets in here, a fix may be needed here in the future. For now this patch is only to set iph->tot_len to 0 when it happens. Signed-off-by: Xin Long --- net/ipv4/cipso_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 6cd3b6c559f0..79ae7204e8ed 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -2222,7 +2222,7 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb, memset((char *)(iph + 1) + buf_len, 0, opt_len - buf_len); if (len_delta != 0) { iph->ihl = 5 + (opt_len >> 2); - iph->tot_len = htons(skb->len); + iph_set_totlen(iph, skb->len); } ip_send_check(iph); From patchwork Sat Jan 28 15:58:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119875 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6231C27C76 for ; Sat, 28 Jan 2023 15:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234543AbjA1P7T (ORCPT ); Sat, 28 Jan 2023 10:59:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234429AbjA1P65 (ORCPT ); Sat, 28 Jan 2023 10:58:57 -0500 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C9936443 for ; Sat, 28 Jan 2023 07:58:50 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id d3so6569314qte.8 for ; Sat, 28 Jan 2023 07:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HaCBPY9taiJwDw7qkQaAo7rOjDTTF2XX5hJIsC+YZm4=; b=iAJ50hgQTZGs0VeREuqjkOqZEH98eDTHJDIOF8jknqNFJRcBlAwMDMNK/xGD2Rf3SK xNz9wmqSXNZ3h9Y2r8YdDn7z/lQICJvnKiODW2/KbfsG+w+9skKZYvhVhqS3xQePxcin SzoHCd5E7cYJwX478zPubdZcCVGTexGmD9uvjdVOH7vMTW/poErywtFDQel5t9czsxBb thpGi7+Aw0h01JohOXl9vz6FrfmZd5odjqJF/OpzKNdhSpJLFeCrwKEksym2CwyMSIQk uLq05Sdra/RHG3p/nP49XdHJqgX0Gxa4uKRTB7okaiUMSKlnvtoihFswVuD6h/kK4Z8t 3ABw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HaCBPY9taiJwDw7qkQaAo7rOjDTTF2XX5hJIsC+YZm4=; b=qtzqUZ1Yq9i03t7bsifpc64XiDmomtaOjx4pqHE7infRbVgW8h0gyifrUA6LxGEsr6 0bwd92mgtFNrYgA0vCPHRydok2zx9jpIIgbGOIuWf/HLHrpS2k1stCg4hplf8sg9Y6/k 02YMyUvV1OFIA8Qm9o8OHfjJJtMH8A1EJ6KGo5ZIkEZtX7yfPeK5B8uUPPdLZMzrmsVa iO3D1GsfbPOnomi34PGGODOwkBs7JVwUWjP985p7GOvIQFB/o+q8S1Ok+mecpoF6VR7Y aZmkjZ1FskKELsl/1N2jlNshEb59+OYP4noN2opgo264ALCBZIGOq4LEdsxZm1NSaX1P KMhQ== X-Gm-Message-State: AO0yUKXhbCML8lSAIQbZTgsCAha5Mri7pUWxkm2BpQjCg85BWqWNbaa2 /hxg4XtoD2hqfeY8zVpA9L2cZb5lzFMKkQ== X-Google-Smtp-Source: AK7set8ozJfq8Zxq5D9uJVtEBL//Joc1Z8LZnYjGch/q5+U+azdfg+A57UF/VOOOsTVyo17dTz+slg== X-Received: by 2002:a05:622a:95:b0:3b8:5aa8:7d7a with SMTP id o21-20020a05622a009500b003b85aa87d7amr425892qtw.68.1674921529274; Sat, 28 Jan 2023 07:58:49 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:49 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 07/10] ipvlan: use skb_ip_totlen in ipvlan_get_L3_hdr Date: Sat, 28 Jan 2023 10:58:36 -0500 Message-Id: <6d314a3fa799e50632e708d4cb31d636f3d21567.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ipvlan devices calls netif_inherit_tso_max() to get the tso_max_size/segs from the lower device, so when lower device supports BIG TCP, the ipvlan devices support it too. We also should consider its iph tot_len accessing. Signed-off-by: Xin Long --- drivers/net/ipvlan/ipvlan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c index bb1c298c1e78..460b3d4f2245 100644 --- a/drivers/net/ipvlan/ipvlan_core.c +++ b/drivers/net/ipvlan/ipvlan_core.c @@ -157,7 +157,7 @@ void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type) return NULL; ip4h = ip_hdr(skb); - pktlen = ntohs(ip4h->tot_len); + pktlen = skb_ip_totlen(skb); if (ip4h->ihl < 5 || ip4h->version != 4) return NULL; if (skb->len < pktlen || pktlen < (ip4h->ihl * 4)) From patchwork Sat Jan 28 15:58:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119876 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83D50C27C76 for ; Sat, 28 Jan 2023 15:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234309AbjA1P7Z (ORCPT ); Sat, 28 Jan 2023 10:59:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbjA1P7G (ORCPT ); Sat, 28 Jan 2023 10:59:06 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88B2E3402F for ; Sat, 28 Jan 2023 07:58:51 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id v19so6548271qtq.13 for ; Sat, 28 Jan 2023 07:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0hbUyBh1zPDHGKtsmgkDKwqAxLhgAY3/Mg+p631es5Y=; b=LR9/RCa51DJ3fi+0XANMBS3usA2/zbWS7zR19Mbsca4WjMCfDUN/pZnH8GGRMF8Rsj fSnyomT51zEPZnnxbKNn/of1PscB0LJSnw6fgMnb8ysqDjSFibCVZvUAfqSw95Vgr9bo wkC+6NX8mcaSmiR6sexi+BhGhj/CFijQS0S4QTmnjjLKZmyFnjVSmgVRuPziPWTB8GDT k/cjmIs1WSVZEd5fS/KQrEAHaMrHP9BMTO2jYqDKEsN5w0ayfcZgPv4JqeYxjOr/9e9I t0bSbemMyUtm37B4NqOG0iidB6dGs3PC9LudLCVshYS/6yuzWxKSk+m30H75/0vUQSs5 5Q6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0hbUyBh1zPDHGKtsmgkDKwqAxLhgAY3/Mg+p631es5Y=; b=cbZXYfW1ShG4xnDiGKFufGyO0Zeey6GNFfFcr9NiOggDq7JeVbgPoxYZ+0z0hQe16L 8hgUUls9fIH19+bDtcc8Ee5b8UBP4MZPyY1t96CmFKxGtOtsNFlUs77E6VyIjmD44dvB f0YAE5y3kU5JqOvoYuMoy8qKxp28tZQ+K7KVaOra4sVaTlU8OAJqK4dLAjcEMPr4wfdt i0JtyLrrjhNg1sdDxTZIYugAWhqpWqDaCol8ZgHvQ4Ga8PiAfIcUl1QqF2q9TkI/PN6G ImN3Syn+mdsEh6Ka25Lf7ObR7P4NUJEni/hoplSuYgpSkEs0MyfkT87NAMIvYAdL6Wrm oV5w== X-Gm-Message-State: AO0yUKVUYVzcdLPgyGcGOnz8o9OR84whdBI/Y7VCFcf1W28D8KgufPOr PUVFBodgltHFYFXw0amoKKf2nlEaGSD9nw== X-Google-Smtp-Source: AK7set9qW42KsgKcD0YT7m7+eu6b2xuqSwttn0WuZYlnEdbSKHXB2w63AjZF92GC4sskiJBvekzIyw== X-Received: by 2002:ac8:5b89:0:b0:3a4:fddd:f8ef with SMTP id a9-20020ac85b89000000b003a4fdddf8efmr4176571qta.53.1674921530462; Sat, 28 Jan 2023 07:58:50 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:50 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 08/10] packet: add TP_STATUS_GSO_TCP for tp_status Date: Sat, 28 Jan 2023 10:58:37 -0500 Message-Id: <0436a569c630a93e7abeedaa7ceccfc369f73c39.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Introduce TP_STATUS_GSO_TCP tp_status flag to tell the af_packet user that this is a TCP GSO packet. When parsing IPv4 BIG TCP packets in tcpdump/libpcap, it can use tp_len as the IPv4 packet len when this flag is set, as iph tot_len is set to 0 for IPv4 BIG TCP packets. Signed-off-by: Xin Long Reviewed-by: David Ahern --- include/uapi/linux/if_packet.h | 1 + net/packet/af_packet.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/uapi/linux/if_packet.h b/include/uapi/linux/if_packet.h index a8516b3594a4..78c981d6a9d4 100644 --- a/include/uapi/linux/if_packet.h +++ b/include/uapi/linux/if_packet.h @@ -115,6 +115,7 @@ struct tpacket_auxdata { #define TP_STATUS_BLK_TMO (1 << 5) #define TP_STATUS_VLAN_TPID_VALID (1 << 6) /* auxdata has valid tp_vlan_tpid */ #define TP_STATUS_CSUM_VALID (1 << 7) +#define TP_STATUS_GSO_TCP (1 << 8) /* Tx ring - header status */ #define TP_STATUS_AVAILABLE 0 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index b5ab98ca2511..8ffb19c643ab 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2296,6 +2296,8 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, else if (skb->pkt_type != PACKET_OUTGOING && skb_csum_unnecessary(skb)) status |= TP_STATUS_CSUM_VALID; + if (skb_is_gso(skb) && skb_is_gso_tcp(skb)) + status |= TP_STATUS_GSO_TCP; if (snaplen > res) snaplen = res; @@ -3522,6 +3524,8 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, else if (skb->pkt_type != PACKET_OUTGOING && skb_csum_unnecessary(skb)) aux.tp_status |= TP_STATUS_CSUM_VALID; + if (skb_is_gso(skb) && skb_is_gso_tcp(skb)) + aux.tp_status |= TP_STATUS_GSO_TCP; aux.tp_len = origlen; aux.tp_snaplen = skb->len; From patchwork Sat Jan 28 15:58:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119877 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8F75C38142 for ; Sat, 28 Jan 2023 15:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234450AbjA1P70 (ORCPT ); Sat, 28 Jan 2023 10:59:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234456AbjA1P7G (ORCPT ); Sat, 28 Jan 2023 10:59:06 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B26012A143 for ; Sat, 28 Jan 2023 07:58:52 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id e8so6585156qts.1 for ; Sat, 28 Jan 2023 07:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZNEc7yx9vM6DvoqCIp74I08UHkEg4YRarn2/YK5h2lU=; b=X+iyssBCDSJPDcvbFyTUa2IV3rVkQf5nvQbBHoN+G01xvPvI/NsWkCeoZTBrIJAz7D J7KDq/KCjTMtnXgEu8kcGkmrZbYtDjBvGdenNXgpX3NP5yjln9R+iLqqPvcLoxIHqmdH RstSwYOikYM8OzV0iZWvyr2gn7oCN2sdwNzLvrMPNikeeYrcXotQ+8/UdYoEUjQD2KOJ JoEtJ7sqNMwr9ynptICn76KA/BJJez5AhhOxoxGHgg3/rPj12R6zAgAznJiFZgOrKiJ7 mNtN7OsDraFa9G3LbZ32DmrbSmWNiFPlu/YThOSNTJ4wAJiQXGSrmIOTjOQRezknHo8j Xrww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZNEc7yx9vM6DvoqCIp74I08UHkEg4YRarn2/YK5h2lU=; b=Dn8FtjIrXuQcxm4MxxOdvMN1xEyMR4H2JhRKKW8ag1RFkn+qtakvrwfRGrWQDfNnNX SOuu1fgDie5VCyx697ISqvfbZl2br1SKo0GoMYTDSYPhwtx20vnSAIwxWixQRQWDprJM EiEPAk6SzUejTyebpUo/pnxp37F0rF2xxsi8Nc/PqyDHgRi/I/iApUBahR/ozyqFpb9c 9p6ccePA8ywBa6VySbhSar86nUHSbs9840PO77hdasY2WfpI4CtCOs/58H9yMHOj0WxF DLxtAxyZY2FK6yh+bdXchwecotvxKtcWYoLySL1sktuA16J3D1gpvESsxRoChMTS+6/z F/fQ== X-Gm-Message-State: AFqh2kpg6xscA8UOwDGGMX+uiTYmTbo36FRs8rurRSd0WX9WvsCZKu3i +eZsCatXeST0W66j+yKRyIm/rAvFtiMYwg== X-Google-Smtp-Source: AMrXdXukWeTzwgrbb+nD8zsORrzcv9xeTMvkBThNV75BYZbKZIOFWFjD+1hSDB/JeJ1NYTsLXrTXWA== X-Received: by 2002:a05:622a:a07:b0:3b6:2fd2:84b5 with SMTP id bv7-20020a05622a0a0700b003b62fd284b5mr70758176qtb.57.1674921531639; Sat, 28 Jan 2023 07:58:51 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:51 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 09/10] net: add gso_ipv4_max_size and gro_ipv4_max_size per device Date: Sat, 28 Jan 2023 10:58:38 -0500 Message-Id: <7e1f733cc96c7f7658fbf3276a90281b2f37acd1.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch introduces gso_ipv4_max_size and gro_ipv4_max_size per device and adds netlink attributes for them, so that IPV4 BIG TCP can be guarded by a separate tunable in the next patch. To not break the old application using "gso/gro_max_size" for IPv4 GSO packets, this patch updates "gso/gro_ipv4_max_size" in netif_set_gso/gro_max_size() if the new size isn't greater than GSO_LEGACY_MAX_SIZE, so that nothing will change even if userspace doesn't realize the new netlink attributes. Signed-off-by: Xin Long Reviewed-by: David Ahern --- include/linux/netdevice.h | 6 ++++++ include/uapi/linux/if_link.h | 3 +++ net/core/dev.c | 4 ++++ net/core/dev.h | 18 ++++++++++++++++++ net/core/rtnetlink.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 2466afa25078..d5ef4c1fedd2 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1964,6 +1964,8 @@ enum netdev_ml_priv_type { * @gso_max_segs: Maximum number of segments that can be passed to the * NIC for GSO * @tso_max_segs: Device (as in HW) limit on the max TSO segment count + * @gso_ipv4_max_size: Maximum size of generic segmentation offload, + * for IPv4. * * @dcbnl_ops: Data Center Bridging netlink ops * @num_tc: Number of traffic classes in the net device @@ -2004,6 +2006,8 @@ enum netdev_ml_priv_type { * keep a list of interfaces to be deleted. * @gro_max_size: Maximum size of aggregated packet in generic * receive offload (GRO) + * @gro_ipv4_max_size: Maximum size of aggregated packet in generic + * receive offload (GRO), for IPv4. * * @dev_addr_shadow: Copy of @dev_addr to catch direct writes. * @linkwatch_dev_tracker: refcount tracker used by linkwatch. @@ -2207,6 +2211,7 @@ struct net_device { */ #define GRO_MAX_SIZE (8 * 65535u) unsigned int gro_max_size; + unsigned int gro_ipv4_max_size; rx_handler_func_t __rcu *rx_handler; void __rcu *rx_handler_data; @@ -2330,6 +2335,7 @@ struct net_device { u16 gso_max_segs; #define TSO_MAX_SEGS U16_MAX u16 tso_max_segs; + unsigned int gso_ipv4_max_size; #ifdef CONFIG_DCB const struct dcbnl_rtnl_ops *dcbnl_ops; diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 1021a7e47a86..02b87e4c65be 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -374,6 +374,9 @@ enum { IFLA_DEVLINK_PORT, + IFLA_GSO_IPV4_MAX_SIZE, + IFLA_GRO_IPV4_MAX_SIZE, + __IFLA_MAX }; diff --git a/net/core/dev.c b/net/core/dev.c index f72f5c4ee7e2..bb42150a38ec 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3001,6 +3001,8 @@ void netif_set_tso_max_size(struct net_device *dev, unsigned int size) dev->tso_max_size = min(GSO_MAX_SIZE, size); if (size < READ_ONCE(dev->gso_max_size)) netif_set_gso_max_size(dev, size); + if (size < READ_ONCE(dev->gso_ipv4_max_size)) + netif_set_gso_ipv4_max_size(dev, size); } EXPORT_SYMBOL(netif_set_tso_max_size); @@ -10614,6 +10616,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, dev->gso_max_size = GSO_LEGACY_MAX_SIZE; dev->gso_max_segs = GSO_MAX_SEGS; dev->gro_max_size = GRO_LEGACY_MAX_SIZE; + dev->gso_ipv4_max_size = GSO_LEGACY_MAX_SIZE; + dev->gro_ipv4_max_size = GRO_LEGACY_MAX_SIZE; dev->tso_max_size = TSO_LEGACY_MAX_SIZE; dev->tso_max_segs = TSO_MAX_SEGS; dev->upper_level = 1; diff --git a/net/core/dev.h b/net/core/dev.h index 814ed5b7b960..a065b7571441 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -100,6 +100,8 @@ static inline void netif_set_gso_max_size(struct net_device *dev, { /* dev->gso_max_size is read locklessly from sk_setup_caps() */ WRITE_ONCE(dev->gso_max_size, size); + if (size <= GSO_LEGACY_MAX_SIZE) + WRITE_ONCE(dev->gso_ipv4_max_size, size); } static inline void netif_set_gso_max_segs(struct net_device *dev, @@ -114,6 +116,22 @@ static inline void netif_set_gro_max_size(struct net_device *dev, { /* This pairs with the READ_ONCE() in skb_gro_receive() */ WRITE_ONCE(dev->gro_max_size, size); + if (size <= GRO_LEGACY_MAX_SIZE) + WRITE_ONCE(dev->gro_ipv4_max_size, size); +} + +static inline void netif_set_gso_ipv4_max_size(struct net_device *dev, + unsigned int size) +{ + /* dev->gso_ipv4_max_size is read locklessly from sk_setup_caps() */ + WRITE_ONCE(dev->gso_ipv4_max_size, size); +} + +static inline void netif_set_gro_ipv4_max_size(struct net_device *dev, + unsigned int size) +{ + /* This pairs with the READ_ONCE() in skb_gro_receive() */ + WRITE_ONCE(dev->gro_ipv4_max_size, size); } #endif diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 64289bc98887..b9f584955b77 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1074,6 +1074,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, + nla_total_size(4) /* IFLA_GSO_MAX_SEGS */ + nla_total_size(4) /* IFLA_GSO_MAX_SIZE */ + nla_total_size(4) /* IFLA_GRO_MAX_SIZE */ + + nla_total_size(4) /* IFLA_GSO_IPV4_MAX_SIZE */ + + nla_total_size(4) /* IFLA_GRO_IPV4_MAX_SIZE */ + nla_total_size(4) /* IFLA_TSO_MAX_SIZE */ + nla_total_size(4) /* IFLA_TSO_MAX_SEGS */ + nla_total_size(1) /* IFLA_OPERSTATE */ @@ -1807,6 +1809,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, nla_put_u32(skb, IFLA_GSO_MAX_SEGS, dev->gso_max_segs) || nla_put_u32(skb, IFLA_GSO_MAX_SIZE, dev->gso_max_size) || nla_put_u32(skb, IFLA_GRO_MAX_SIZE, dev->gro_max_size) || + nla_put_u32(skb, IFLA_GSO_IPV4_MAX_SIZE, dev->gso_ipv4_max_size) || + nla_put_u32(skb, IFLA_GRO_IPV4_MAX_SIZE, dev->gro_ipv4_max_size) || nla_put_u32(skb, IFLA_TSO_MAX_SIZE, dev->tso_max_size) || nla_put_u32(skb, IFLA_TSO_MAX_SEGS, dev->tso_max_segs) || #ifdef CONFIG_RPS @@ -1968,6 +1972,8 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_TSO_MAX_SIZE] = { .type = NLA_REJECT }, [IFLA_TSO_MAX_SEGS] = { .type = NLA_REJECT }, [IFLA_ALLMULTI] = { .type = NLA_REJECT }, + [IFLA_GSO_IPV4_MAX_SIZE] = { .type = NLA_U32 }, + [IFLA_GRO_IPV4_MAX_SIZE] = { .type = NLA_U32 }, }; static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { @@ -2883,6 +2889,29 @@ static int do_setlink(const struct sk_buff *skb, } } + if (tb[IFLA_GSO_IPV4_MAX_SIZE]) { + u32 max_size = nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]); + + if (max_size > dev->tso_max_size) { + err = -EINVAL; + goto errout; + } + + if (dev->gso_ipv4_max_size ^ max_size) { + netif_set_gso_ipv4_max_size(dev, max_size); + status |= DO_SETLINK_MODIFIED; + } + } + + if (tb[IFLA_GRO_IPV4_MAX_SIZE]) { + u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE]); + + if (dev->gro_ipv4_max_size ^ gro_max_size) { + netif_set_gro_ipv4_max_size(dev, gro_max_size); + status |= DO_SETLINK_MODIFIED; + } + } + if (tb[IFLA_OPERSTATE]) set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); @@ -3325,6 +3354,10 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname, netif_set_gso_max_segs(dev, nla_get_u32(tb[IFLA_GSO_MAX_SEGS])); if (tb[IFLA_GRO_MAX_SIZE]) netif_set_gro_max_size(dev, nla_get_u32(tb[IFLA_GRO_MAX_SIZE])); + if (tb[IFLA_GSO_IPV4_MAX_SIZE]) + netif_set_gso_ipv4_max_size(dev, nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE])); + if (tb[IFLA_GRO_IPV4_MAX_SIZE]) + netif_set_gro_ipv4_max_size(dev, nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE])); return dev; } From patchwork Sat Jan 28 15:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13119878 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88AA3C27C76 for ; Sat, 28 Jan 2023 15:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234337AbjA1P71 (ORCPT ); Sat, 28 Jan 2023 10:59:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbjA1P7H (ORCPT ); Sat, 28 Jan 2023 10:59:07 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 189E22684A for ; Sat, 28 Jan 2023 07:58:54 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id k2so5988235qvd.12 for ; Sat, 28 Jan 2023 07:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VQ+SlAzDYNj/x0UmLVUgDvqzPt1svT+GgrrSzkr8LB0=; b=Yu/sYBVUIU+FjC/GUgmAWZcv8yye5hs1dMis7EZTf8cNo38SmpO922F3UcoiYBQZ1E PLeySjphNmFdbdpyFUT+oNLgSbA7lWIXAifjmTAIjq+GvwxYdkBppfnjxMzCraTd85W9 4UhagMBt7Ios8PoBeRiVBg4ADPQ4URGwJg9+0JJXOBnpDroDtuQNYtN6eBfhHAOBKUhi aLFJv3+p+GXkppqqyTE6ACtiCSVyhOAbcuLYPr+adDTXuhV+XOlMZdWeL+HSnFbFXBqK bKoIaWaE2nCPArQ/FbvFD+5Megm6QPmNoxNPZfXaYxbhTCDWfCRy3TvUkziYYQphjyM5 H/gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VQ+SlAzDYNj/x0UmLVUgDvqzPt1svT+GgrrSzkr8LB0=; b=DPdMDTvPty3/rK5Dlr8XdhkQ2svAoO7X1CskfDI/JpoBYaTruGMzmx3bgg6JqLIFST FFCCp4qCvoelmx+XX1waXe5NJAd5TQwYUlxxdvrRqlN88XaOAmWEgwydXGPOGHbewIPG EtMezth0pS/D2F76WnAcKnS3oFN4LvEM4u6LlZsQSW/MGrMhzvZ3TztAi0WX3TmRL9pK 6Wa85i5ZRFUDjHe6vKPYcDK5Kv6teMxchUVWQ49eg+0vtHEilJNYyBd/SjDutWCCP6md UQIrImSfyXfRe9dHEJiwrF1mawiiGKHBAguf6awDMLtmEFpIuEqg454fzIT/jd+Ei/v9 BbgA== X-Gm-Message-State: AO0yUKUwdm5nuYwI1iz0Q3iHbicQm8O8ujbENYchu6Q8pFFq6Lvtc7Cs 0NJXaFeESGNxC0wKbjdIfmIRumEjN2qzOg== X-Google-Smtp-Source: AK7set/McABAtSvdX0CMBXedfdqtoSkCRwcAYAYPaIx1vBusWHmvPhQIlN+bNEkEVrifrFjjFycISQ== X-Received: by 2002:ad4:5311:0:b0:53a:a39f:b24e with SMTP id y17-20020ad45311000000b0053aa39fb24emr2000179qvr.11.1674921532846; Sat, 28 Jan 2023 07:58:52 -0800 (PST) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a0a0700b006fbbdc6c68fsm4955174qka.68.2023.01.28.07.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 07:58:52 -0800 (PST) From: Xin Long To: network dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , David Ahern , Hideaki YOSHIFUJI , Pravin B Shelar , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Pablo Neira Ayuso , Florian Westphal , Marcelo Ricardo Leitner , Ilya Maximets , Aaron Conole , Roopa Prabhu , Nikolay Aleksandrov , Mahesh Bandewar , Paul Moore , Guillaume Nault Subject: [PATCHv4 net-next 10/10] net: add support for ipv4 big tcp Date: Sat, 28 Jan 2023 10:58:39 -0500 Message-Id: <637aa55b8dbf0c85c2ee8892df26a8bbbf9f2ef5.1674921359.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Similar to Eric's IPv6 BIG TCP, this patch is to enable IPv4 BIG TCP. Firstly, allow sk->sk_gso_max_size to be set to a value greater than GSO_LEGACY_MAX_SIZE by not trimming gso_max_size in sk_trim_gso_size() for IPv4 TCP sockets. Then on TX path, set IP header tot_len to 0 when skb->len > IP_MAX_MTU in __ip_local_out() to allow to send BIG TCP packets, and this implies that skb->len is the length of a IPv4 packet; On RX path, use skb->len as the length of the IPv4 packet when the IP header tot_len is 0 and skb->len > IP_MAX_MTU in ip_rcv_core(). As the API iph_set_totlen() and skb_ip_totlen() are used in __ip_local_out() and ip_rcv_core(), we only need to update these APIs. Also in GRO receive, add the check for ETH_P_IP/IPPROTO_TCP, and allows the merged packet size >= GRO_LEGACY_MAX_SIZE in skb_gro_receive(). In GRO complete, set IP header tot_len to 0 when the merged packet size greater than IP_MAX_MTU in iph_set_totlen() so that it can be processed on RX path. Note that by checking skb_is_gso_tcp() in API iph_totlen(), it makes this implementation safe to use iph->len == 0 indicates IPv4 BIG TCP packets. Signed-off-by: Xin Long Reviewed-by: David Ahern --- net/core/gro.c | 12 +++++++----- net/core/sock.c | 26 ++++++++++++++------------ net/ipv4/af_inet.c | 7 ++++--- net/ipv4/ip_input.c | 2 +- net/ipv4/ip_output.c | 2 +- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/net/core/gro.c b/net/core/gro.c index 506f83d715f8..b15f85546bdd 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -162,16 +162,18 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) struct sk_buff *lp; int segs; - /* pairs with WRITE_ONCE() in netif_set_gro_max_size() */ - gro_max_size = READ_ONCE(p->dev->gro_max_size); + /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ + gro_max_size = p->protocol == htons(ETH_P_IPV6) ? + READ_ONCE(p->dev->gro_max_size) : + READ_ONCE(p->dev->gro_ipv4_max_size); if (unlikely(p->len + len >= gro_max_size || NAPI_GRO_CB(skb)->flush)) return -E2BIG; if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) { - if (p->protocol != htons(ETH_P_IPV6) || - skb_headroom(p) < sizeof(struct hop_jumbo_hdr) || - ipv6_hdr(p)->nexthdr != IPPROTO_TCP || + if (NAPI_GRO_CB(skb)->proto != IPPROTO_TCP || + (p->protocol == htons(ETH_P_IPV6) && + skb_headroom(p) < sizeof(struct hop_jumbo_hdr)) || p->encapsulation) return -E2BIG; } diff --git a/net/core/sock.c b/net/core/sock.c index 7ba4891460ad..f08b76acde9b 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2373,17 +2373,22 @@ void sk_free_unlock_clone(struct sock *sk) } EXPORT_SYMBOL_GPL(sk_free_unlock_clone); -static void sk_trim_gso_size(struct sock *sk) +static u32 sk_dst_gso_max_size(struct sock *sk, struct dst_entry *dst) { - if (sk->sk_gso_max_size <= GSO_LEGACY_MAX_SIZE) - return; + bool is_ipv6 = false; + u32 max_size; + #if IS_ENABLED(CONFIG_IPV6) - if (sk->sk_family == AF_INET6 && - sk_is_tcp(sk) && - !ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)) - return; + is_ipv6 = (sk->sk_family == AF_INET6 && + !ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)); #endif - sk->sk_gso_max_size = GSO_LEGACY_MAX_SIZE; + /* pairs with the WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ + max_size = is_ipv6 ? READ_ONCE(dst->dev->gso_max_size) : + READ_ONCE(dst->dev->gso_ipv4_max_size); + if (max_size > GSO_LEGACY_MAX_SIZE && !sk_is_tcp(sk)) + max_size = GSO_LEGACY_MAX_SIZE; + + return max_size - (MAX_TCP_HEADER + 1); } void sk_setup_caps(struct sock *sk, struct dst_entry *dst) @@ -2403,10 +2408,7 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst) sk->sk_route_caps &= ~NETIF_F_GSO_MASK; } else { sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM; - /* pairs with the WRITE_ONCE() in netif_set_gso_max_size() */ - sk->sk_gso_max_size = READ_ONCE(dst->dev->gso_max_size); - sk_trim_gso_size(sk); - sk->sk_gso_max_size -= (MAX_TCP_HEADER + 1); + sk->sk_gso_max_size = sk_dst_gso_max_size(sk, dst); /* pairs with the WRITE_ONCE() in netif_set_gso_max_segs() */ max_segs = max_t(u32, READ_ONCE(dst->dev->gso_max_segs), 1); } diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 6c0ec2789943..2f992a323b95 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1485,6 +1485,7 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb) if (unlikely(ip_fast_csum((u8 *)iph, 5))) goto out; + NAPI_GRO_CB(skb)->proto = proto; id = ntohl(*(__be32 *)&iph->id); flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF)); id >>= 16; @@ -1618,9 +1619,9 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) int inet_gro_complete(struct sk_buff *skb, int nhoff) { - __be16 newlen = htons(skb->len - nhoff); struct iphdr *iph = (struct iphdr *)(skb->data + nhoff); const struct net_offload *ops; + __be16 totlen = iph->tot_len; int proto = iph->protocol; int err = -ENOSYS; @@ -1629,8 +1630,8 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff) skb_set_inner_network_header(skb, nhoff); } - csum_replace2(&iph->check, iph->tot_len, newlen); - iph->tot_len = newlen; + iph_set_totlen(iph, skb->len - nhoff); + csum_replace2(&iph->check, totlen, iph->tot_len); ops = rcu_dereference(inet_offloads[proto]); if (WARN_ON(!ops || !ops->callbacks.gro_complete)) diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index e880ce77322a..fe9ead9ee863 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -511,7 +511,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) goto csum_error; - len = ntohs(iph->tot_len); + len = iph_totlen(skb, iph); if (skb->len < len) { drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL; __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 922c87ef1ab5..4e4e308c3230 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -100,7 +100,7 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) { struct iphdr *iph = ip_hdr(skb); - iph->tot_len = htons(skb->len); + iph_set_totlen(iph, skb->len); ip_send_check(iph); /* if egress device is enslaved to an L3 master device pass the