From patchwork Fri Jan 27 15:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118889 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 E4134C61DA4 for ; Fri, 27 Jan 2023 16:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234181AbjA0QAI (ORCPT ); Fri, 27 Jan 2023 11:00:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234122AbjA0QAC (ORCPT ); Fri, 27 Jan 2023 11:00:02 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB4BA7F6A9 for ; Fri, 27 Jan 2023 08:00:00 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id x5so4358283qti.3 for ; Fri, 27 Jan 2023 08:00:00 -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=n0eBLaQ0piq5nQS2gFn1vaSPymqbYNahrFzNETi2aRVELLQ8l+AJqYn8Za9kCuixqZ 0nVSlnrHZ5hVO+O3kkr8Zb/ysV9uhyLTbjdVvLZSyanV6Jpz0yH76iYFTBMB40WnMWpe CkhG7XdIztW7dLeaSciQ+eVjELBcf6nEGhXiCEZMvWArBo8YWOltt5qOIVlDN6Ct2bUd A0YFTMLZuDe+1pEqjg3URq7sjeJ5vTxJC3TwctIguxyP3gQytbk6EgAdz7VuZPet5kZE 3ibUchqzXqbvS3Aflx09T8XvqiK1mRW/I/Ld8M0k27bpJrrcIe1GKBR8egQWh7onAHye ReLg== 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=o5ZjFMHwSgh5FvN+AEKiwLzJz+aIHmBTTQQY8UB8nTcJ1PusnwkjpbS8+SmFHoPAnq w2qhmoqdt2hs2PF5kqAMDtmI8OGi9T+brAF3zoJDs1+K8QQWuCGCu9aZzF70Mw0KO0k+ Kcx1RJ2U5HdwzjjAo7tu5OIgi8PuzdI8CWtyTK79XSLPNxQrqk0lncZ2pbW/B3qHSLcM aAqBrpDOkyNxQhPF0Qcwn8UFzHsCT8wPxQFxLHZHpQBGfWDDPJKT25jUV07WPnRcrIKK nao2krdOfb1C64EMCPATSuRXYrlJp/BovU/mrWbljyQ7LM0GIbU4COfma/Pt5XOc6iW4 hoTw== X-Gm-Message-State: AFqh2kqS6qtC90Xds6+sj7Rl9jZoyehdAnpDTQz0lWFDOrUjRb0ZHzhf 3wUt9J7T/v5k6RfPmFLNciERKzyt0cJmWQ== X-Google-Smtp-Source: AMrXdXvrC8d6CyKufeUaRQQGyPTcu28uAVcfbmnBXC/w7zvZKDp6tghu2kUn9tld0Kvg+J0iTApTqw== X-Received: by 2002:ac8:7312:0:b0:3ab:7bb3:4707 with SMTP id x18-20020ac87312000000b003ab7bb34707mr50654709qto.64.1674835199731; Fri, 27 Jan 2023 07:59:59 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.07.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 07:59:59 -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: [PATCHv3 net-next 01/10] net: add a couple of helpers for iph tot_len Date: Fri, 27 Jan 2023 10:59:47 -0500 Message-Id: <520630e418a95e6085b7c7399f9741570af82079.1674835106.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 --- 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 Fri Jan 27 15:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118888 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 79CA4C61DB3 for ; Fri, 27 Jan 2023 16:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234244AbjA0QAJ (ORCPT ); Fri, 27 Jan 2023 11:00:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233836AbjA0QAE (ORCPT ); Fri, 27 Jan 2023 11:00:04 -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 DB2448660D for ; Fri, 27 Jan 2023 08:00:01 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id g16so4369388qtu.2 for ; Fri, 27 Jan 2023 08:00:01 -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=SH9RcQM9TnI9XyzH6t13UlVw/Hjl/S3j2aRuXsmLPKuT0Jf1B99BnMJrJFnc5RQJj/ MF/J29BC91NZ1cqjuw2/ImV5AGzqvOoqQ7ae5sjIn67U5QhPlUukFQW0VDJIZiqOWcnY PhynjpfFcBP/DHWvFob5NkAnCdgzVndC9aXCEZLYguDXxnKtUdSTwQp6m3atxvAQ4C5X 1HHMW18OCLgyEdaFjrYI8txab4jeiZFVy0EqunhTkrc/wEJHPsJ6xpnaoeUCwECQtsqP 2BOLN6lnQcmmZzA2JHbJBTQargKURZmaADgh0CCaYa5pWDGCvWKnBc41033hYu3bi12f eswg== 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=U8CNbU0TE4V+Mw486ir0OwoW+gcHvOqZ0nCm85cPtZI44zScTmeTuNswUXg2rmXAPy YeV0t60ULNMAZJ5Uv0jCM2Nrf0X2C8dlPrB34nDfOnbnJxTXjDhw6f6dD3pbTAZTP+gy sLnofkacssAl8XgtAXqMzxllVW0q5zLc6p8j5uDb1uAzjVxI0oyB3i383PgxNy2m1Pak IxXgXHUgSsq3XB0oXeUT0vvVGj5X+jaMyZPBflaLqXl1vTqG26KzRjyuK32G8b42I5Rp gEhJkNlWbiQv2KiWeiUlbYBHxJdC7oz1d5oRu1y+Ii+Oa/uZC1KS4v24jsyuLSVaQeRe kg4A== X-Gm-Message-State: AFqh2kpfwZp0FF9hxJZrTMahVsuQ9M5BRvDckm8Ikm5fjHMfyU8klE7r s9JTPmxSftDYMmdV2W02ryOOrKKpFr765Q== X-Google-Smtp-Source: AMrXdXuofNTDzS7P0CaB7TS2lacppCl/aw5ApXHS4hL/BIxQ40U0gPFHqGO1HRxKBK7+pgMbLevedQ== X-Received: by 2002:ac8:4d02:0:b0:3b4:63d8:bcbb with SMTP id w2-20020ac84d02000000b003b463d8bcbbmr56210837qtv.28.1674835200877; Fri, 27 Jan 2023 08:00:00 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.07.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:00 -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: [PATCHv3 net-next 02/10] bridge: use skb_ip_totlen in br netfilter Date: Fri, 27 Jan 2023 10:59:48 -0500 Message-Id: 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 --- 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 Fri Jan 27 15:59:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118890 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 1310FC54EAA for ; Fri, 27 Jan 2023 16:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234269AbjA0QAL (ORCPT ); Fri, 27 Jan 2023 11:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234147AbjA0QAG (ORCPT ); Fri, 27 Jan 2023 11:00:06 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E12486268 for ; Fri, 27 Jan 2023 08:00:02 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id v19so4329415qtq.13 for ; Fri, 27 Jan 2023 08:00:02 -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=qiKeqXjwPpwW1JVF88Ste6Pnpftt1spzfTCFWCrfYIfszzkSkPhlkzzPAw/QOo1bTN EHEcInvld4LEI9dzfUhaaA9lqC4j7B+apapvqsMNOrbxbt2Clmq6HqZiHQn5IqofAtMX UOB1hgDWLezIrcNifBsNPM7+xcu0+KM3lcmCyQS2eugPuoG5flWYHN/om2FHlec/PfNM 6m5XxnlOCMgqWWmmNcnkfv8vsQCoiw/q057xIjCk2UX9megtIwHhHiMOjugahCO1y19R GC6zutREr06sX0vatmkrpudmAvlE3xtZP/KOvQGrdyaBfuM972Z3w0ClvzwW232i32yi LuuA== 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=TVtgvze/Z9VWlMaG3qlfgcDRO4WAQGPhAq5+s/wKW7dooyzGMd5AAtrMWiq8iIpVTl gA9Os/kudO9y6rnpHTNLoAm3yzIDJZWymNI1CDx0Ln47K8Fbz+TvrGHdxVzYSz413TbX 6+4iD5slzypeKFiQUkcVkzO3Jfs9w4FI5zXG6sqFHlvOU6teyVAIhEFtHHAwRi+pN94f mi4b3xbmEA8ogYNnWdb8hqv6o89wTTnMiGWQ0l1ISWgr53HTOKfNvNm6CZ5J/nuW8KXS /jVpo+LDFUejlUj1lEeMKj63jvWJTLaE3tLMd2tNyfSGzT1CllE0bcMWbLnM+n+hldR5 YnWA== X-Gm-Message-State: AO0yUKWQWu3QRgPhtmADomdEYOvi1tBZ2GFKUxXTw4iz+UobUNp9sIX8 gWn7+skIYjsHy8Wa8xZEIRVG3MbRSe7TGw== X-Google-Smtp-Source: AK7set/dB5zjQgOckPD3E9XfGBUJMl3cKOwBWbL2Px8NIFKKvxGq2XBUc7yprWRcZjT9kBiCTDUGAQ== X-Received: by 2002:a05:622a:11d6:b0:3b8:2175:fd06 with SMTP id n22-20020a05622a11d600b003b82175fd06mr5231342qtk.62.1674835202030; Fri, 27 Jan 2023 08:00:02 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:01 -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: [PATCHv3 net-next 03/10] openvswitch: use skb_ip_totlen in conntrack Date: Fri, 27 Jan 2023 10:59:49 -0500 Message-Id: <297d80ee701093f58c340e88e6fb8d05fd0d2052.1674835106.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 --- 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 Fri Jan 27 15:59:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118891 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 D8194C61DA4 for ; Fri, 27 Jan 2023 16:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233374AbjA0QAN (ORCPT ); Fri, 27 Jan 2023 11:00:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234105AbjA0QAG (ORCPT ); Fri, 27 Jan 2023 11:00:06 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C34B97B40C for ; Fri, 27 Jan 2023 08:00:03 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id x5so4358483qti.3 for ; Fri, 27 Jan 2023 08:00:03 -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=p5WBTbSkUIO8MH1J5V29oBhslUnc+3cM6mJhV2w/sKXaxhtFGXR7CCAEFda9n+WuJR qKy+kyyCS53/GjxaPGSXFq8jYHWEN+c1CxKD4N5w9YepGQkiWm0ALbT1Pixkinn/e/OV 7YKLGjE/L93bPno/klQeMnU6Wq8kRYQpmyRN/zOk+S2bJMGSgEpp+9kSLRG9XAzhCWy6 AWw8PuzHmrHHRl91pzBcC11zb4Iq+3XsMTuglJGTSVb9NGo4yyYFYFJjfaItRyV6nKnX 7kW/uuqQgVuKZ8KDgCVBP16H09DbiWUtya6LJ2YqjLsjJK4HGKJlmDT4TBAuz9QmHD1u C/7w== 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=cLMyCXdlLlg0TZ25nEisLp141DxLhLNy3EL2UvSqTqQ33G+fzHW3m/kyDt1xwo+Nqr i5ULebP5UBe9fr8exFQ1hDFWgij3TYnX9hdIeyxrFNRy4YEY6gxfzyVqKR3sD5Yy1dEe p70SQiHzQYjh/8v9e9BGZSXi8zu/sMaSj8+4emDMJvSk3TQkb2IWfH7aftito7YyoFrd vEHPqc+wcJNHZ/lEMpJkuErIxCLYifjFXSsPiZPJBv8gVdzUq3D+BHyU7aXQP4dy8+aY Wtkf7dihA6o1tHG4KJT1aEDIeMgeQ8AY+ML+W0bDrG7PaZfce3nrtSVO+1yWa9l6Tgx6 ZzGQ== X-Gm-Message-State: AFqh2krfBffhMuMb+dwXQE8g6w3PSJMVEHrRVdANUfjgcrrlB6bqRryC a8NmDLoPeTNHg7Hq/5nXfi56f7xtojOPCQ== X-Google-Smtp-Source: AMrXdXt2Km6nxtyMoYV+b6VzlTHHS3lRImsBYNJ2Iac4VymkpZT+mOotPjf2KhZVOtskUGWpV53EaA== X-Received: by 2002:a05:622a:5917:b0:3b6:2c11:ec76 with SMTP id ga23-20020a05622a591700b003b62c11ec76mr65480788qtb.52.1674835203230; Fri, 27 Jan 2023 08:00:03 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:02 -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: [PATCHv3 net-next 04/10] net: sched: use skb_ip_totlen and iph_totlen Date: Fri, 27 Jan 2023 10:59:50 -0500 Message-Id: <5f3d4ec30f3ae239f24bd05d7fc495a794ef42f2.1674835106.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 Fri Jan 27 15:59:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118892 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 11C03C54EAA for ; Fri, 27 Jan 2023 16:00:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234328AbjA0QAO (ORCPT ); Fri, 27 Jan 2023 11:00:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234179AbjA0QAI (ORCPT ); Fri, 27 Jan 2023 11:00:08 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86EEE84FB8 for ; Fri, 27 Jan 2023 08:00:05 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id o5so4332539qtr.11 for ; Fri, 27 Jan 2023 08:00:05 -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=AdxHxAREE2gWG+0qLgobJuWXZHf3oqb+0jSTD9SmCNEExf6jR0tRORXDal218fXDGk TBHDVGttXMCAtJxK+q+pJv54GdZEbdaDSEQ+RjSyCzIJLUqzEIveZq8hQPbUYHQnHYSX z2LVgqVJC10tTa2l5FiQW4Ck8s65PLldSu2qAx6mPEPlpdW042ZSGYjhrVrv/4o7a5uw AI3lvL1UoMbeJgVAJ9IFSQqHscG5Tb51sL5E4PnLtI3GKAsQ4UQYDVroapqqDsdBJGbu segONwPLOoWHk1Eeib315Y0EPXScfaUAwl8TifKoHolrL9DPN5UlkbPmGBJz/Ng5Z2nw ECcA== 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=EXfSgWH7WDZI7uhUAFrUageaxsrfBKeILW4JNtXa0R2+pBXhj1K2Yg18HgRMvtj9i+ E5qHCQylfiFNeUDeMbOuV9Bsdm4kSg8j9w1EgicKPAWHht8aWypxDNMuaJxuJHUgKJTO bxNv9AXK619+qfmdKsXnc87uOQ3hZzwAQrQ/gSPb5Gyk3WLjPfnXKsDMBMVeS/J4w7uv 1Sfpp7dn+WqGq0+yRb/DX6+hxMdHvtDh4oSpbyWfkmUmuIaR9DPapwX+8d8Rxx4witMg U+sxNnhr5NX4NRuyVaK2s2IwzqNpN+mWPDjOjXLMSjUqLMNLOmLpfkcXlvIkgc7a2bHv Uzcg== X-Gm-Message-State: AFqh2kp9p54oyHixU7cRWLtCTXjGLzh6JP0MIDcV4b0mBpjH5nrgmKOy BbpBdIHUYvQ1xJ2M9t5fPbc7QIML95WkEw== X-Google-Smtp-Source: AMrXdXtbtfLmpG1UL9ECV7M8vR4TbZooJIrl2VQnS0VVtOtUmj/OaNnpDeMYjC+dAjsD+1i1TaK0Zg== X-Received: by 2002:ac8:6a0f:0:b0:3b1:691f:3d7a with SMTP id t15-20020ac86a0f000000b003b1691f3d7amr54695739qtr.68.1674835204436; Fri, 27 Jan 2023 08:00:04 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:04 -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: [PATCHv3 net-next 05/10] netfilter: use skb_ip_totlen and iph_totlen Date: Fri, 27 Jan 2023 10:59:51 -0500 Message-Id: <01124636f6f251be439cb4e048a66e8f5f11d31d.1674835106.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 Fri Jan 27 15:59:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118893 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 44737C54EAA for ; Fri, 27 Jan 2023 16:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233710AbjA0QAo (ORCPT ); Fri, 27 Jan 2023 11:00:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234160AbjA0QAK (ORCPT ); Fri, 27 Jan 2023 11:00:10 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DB408661F for ; Fri, 27 Jan 2023 08:00:06 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id v19so4329704qtq.13 for ; Fri, 27 Jan 2023 08:00:06 -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=AL7nrsM+AYnosEMDtBqwM7rbIGQMFuqdbmi9amDaGZF3vbX3jhCVR06DCGGWl2zRPn ghgV6n1AWI4K4Fe9ceVNVxI0D8vDXHhxrERD3F0rFIpR/B/9rOuEtwF+7581xl4p0/qw ej34/3y3SxN1WrtPwRgTGqbSnQZsvGHjIzstxGBcpRicyP5rVYLzyyf1UZ85zS3rxsGf nlXZqZglAJ134Uuk8KthtF2yBKagkvY3jhiAT0/ROtOBYexxAePD1BlxHh5mmzf9A55S CJu5MBBctvyibxPzL9EgSzvHFXNyvvRGoPhgQS1poiks+UumRpO4bDq9hnIcdoS6nR4n Bqlw== 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=k3DJH7qb7Qk93ipTcqbMewDfl2qJ5kwod7rIz3juEaRdvjZwYGdE59xo+IKJSzFHzx HByBPqGvymkildvMzZoEazZWfagCC5IdY297YYij2o+DUgOkql+KcFAKSnXc7xevI1vn bIGQWgEyAk4rek0M+QXDxHeZ9gwfTDGWYQNyxqzz6ka58JSu27s2FDm63L2UFVNFJy60 0tq+ggQXh1HrbCh1smPQ7InqbWNL3eb9tzg+f16U1V44fUPw5Vw2vnUHAoCmz7KiDxUn dUP+G/1Ae2HNSrQKUDu5sqaNfKsHkDJ+NYOZMkMEO+bxhEn9JcbaDhqU5LfEEn9wTpJ+ 6x5w== X-Gm-Message-State: AFqh2kqamelQqvVjC3TI8CW9dXrInBRKGR6MvyzHsStgWldbMm3n4FPb okLS4xqRW1JKqKGH2xsD7pln+yL6Hut8Mw== X-Google-Smtp-Source: AMrXdXtiMMY81LR0A0xRGRA727wc8gSbwRU7+hB4hYy6UbmmR3+p4sc3N8ShKQ+s8k5EpZJtgrvltA== X-Received: by 2002:ac8:734d:0:b0:3a8:ef7:f29c with SMTP id q13-20020ac8734d000000b003a80ef7f29cmr53783683qtp.46.1674835205689; Fri, 27 Jan 2023 08:00:05 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:05 -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: [PATCHv3 net-next 06/10] cipso_ipv4: use iph_set_totlen in skbuff_setattr Date: Fri, 27 Jan 2023 10:59:52 -0500 Message-Id: <7787b2075a69cd864f7b74244b041f8b12389ea2.1674835106.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 Fri Jan 27 15:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118894 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 B0802C61DA3 for ; Fri, 27 Jan 2023 16:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbjA0QAu (ORCPT ); Fri, 27 Jan 2023 11:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234114AbjA0QAN (ORCPT ); Fri, 27 Jan 2023 11:00:13 -0500 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B08D86607 for ; Fri, 27 Jan 2023 08:00:08 -0800 (PST) Received: by mail-qt1-x833.google.com with SMTP id h24so4332233qta.12 for ; Fri, 27 Jan 2023 08:00:07 -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=RHDOGWFskTH+S695hRndHW/elYN/db6W6kAiWVKEsv3iFmjZXKiZOrHDQ0NKrlYLoJ 0pPNApzJllulZZ5hNJ6C7rBF8w+Ex5Cfoe7S8vXwqsr5NcDAKhuLqAHcPJu5jiBxKZ22 +zq5vVNe0142/o3/WSefe7+TuFdXp1PYnO7VJIXucRFAzKc4afXwxwHn9raxT3FBRE23 mL4CyFaVMcRHuHRX+FjA4WqejXE6s3VB+pHfNdia6LjiBGTangLy0PHI2aX9RpN1NGg7 QaPhSwz5kRp0o9T+pc9AAzVWvATC3CyW9G8Xo7pustMv1+g+DS1/bp0Ojeg/zFIZSQ2u HnuQ== 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=bEGTeSN7BFw2wkID0sZccPeuYky5CG6H2lTL8e8gSoq4l/u3NMxOpbqqpTIW8d+1et a+EG957eCvTyEam++Tn7a00PtTy2hNosJkIhRK/UaEiVSS6wdjBCU7iOisOTXviGR7zu CBF4kNJHXC6B7L/tZQzpuYwd9uBkhuAB/yphuPJz5b7foJFmWwxEg6MH/mQ32CJ3Y4yn TxACG/7HMR10WTch86hZ/BOeZq4zIj4kZDJTjCmBRkhk/dI58riqY40gnDww4M99o4fd 6Kcfcq9txsUFRJlx0OpkAoUnRDKi8ani6kbbinQrf3hIZ9b9+jXaWtHes+ZIJ8K4rjDg mNdA== X-Gm-Message-State: AFqh2krPZZKE4wvGOH8EUsoH1128hupTf1XQVn+dmfbNZ7uCxBbvIsx4 AIFim5MeOA4pRwF3uG+vtusfLM5wdrZjnQ== X-Google-Smtp-Source: AMrXdXvExk28WbcYqmo1lKpad+57SdzJrWD36dTxKq31v4fcOiBldkzRwnXhgf+sOaXEgr+aYTlsEw== X-Received: by 2002:ac8:4703:0:b0:3a5:4064:9fd3 with SMTP id f3-20020ac84703000000b003a540649fd3mr58503529qtp.24.1674835206903; Fri, 27 Jan 2023 08:00:06 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:06 -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: [PATCHv3 net-next 07/10] ipvlan: use skb_ip_totlen in ipvlan_get_L3_hdr Date: Fri, 27 Jan 2023 10:59:53 -0500 Message-Id: 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 Fri Jan 27 15:59:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118895 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 9D7B9C61DA4 for ; Fri, 27 Jan 2023 16:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234114AbjA0QAw (ORCPT ); Fri, 27 Jan 2023 11:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234365AbjA0QAP (ORCPT ); Fri, 27 Jan 2023 11:00:15 -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 235AE87154 for ; Fri, 27 Jan 2023 08:00:09 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id z9so4358651qtv.5 for ; Fri, 27 Jan 2023 08:00:09 -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=plkvxr0E5bSGi+PYG79GHrxYLZ03VgUt6tGfa1wHB69PUp9EpFRENIrIhFRnCgxyFL 2sbT8R4XpJluo94FcS0ACzppTHsNGsGjQi5rPyA+7jAjvW+09skgMGbtD+r9pKPOcKEp bH5SXcShVvJKhN2wMlK9yH3m0t/hjtUcZTIoYCV410glLxklKPxb/87VvjaOqxF+6mIb nJRmE/bTOtrD42xuBcEjUcgxfDx/sMdc8J7/lmJxYbnroF/bfysazidIJ5CbDmkcZUzj WnvpnsP5RdIakrS+H0ZVuN6510fZ1ds3F1Sim2do12h+SxnIpL7VmC1Fbp3KhWSZfryP l5ZA== 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=v4gGsk+AeIIauNeqePGqAfSRZFGvgBqtKslJWd4YeAS/NY6jjHsHN86IzyKY3nseiE PkR0PSYRLCXjx986t6DwvHLQ6SyaM+5sZLTICv1Q89a0JKYoxSQ9vCuRjatml+g1M1B/ rxhHdZruM8V1ucyU4wzOeXw4d+dVcfvIyVpUEjZgBqI8eJMoL0xnZFKhAO/fRUmTkQIQ apsjbSr8N9ClRwXPNRxMpYvwFrQcUzZRN0XU9dUzDvIRzz1s5zO42AtFXGwLGiu9EOzM O+Dgd/rUXy/3INK4IKpfzpj2DkUSNdOxxduyYX6/BQXNOMIGUlc8CDeBWTQMS6FCO85k 6TOw== X-Gm-Message-State: AFqh2koZuipawxhDGPSvYOct6pqFD/6pDLR1rYzZIRirkax91cwsAcAh sT/mVbBdY7DYOc67qQclQgoUs/YYoHY1Zg== X-Google-Smtp-Source: AMrXdXtPNmdm1xJ4OmhLT0ehdPOn88hFn3wcj2wAjmTbVJx8MVRvwjh1Z633KzV5/2kvrrNwpsS/lQ== X-Received: by 2002:ac8:7107:0:b0:3ab:d932:6c4e with SMTP id z7-20020ac87107000000b003abd9326c4emr50218998qto.18.1674835208025; Fri, 27 Jan 2023 08:00:08 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:07 -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: [PATCHv3 net-next 08/10] packet: add TP_STATUS_GSO_TCP for tp_status Date: Fri, 27 Jan 2023 10:59:54 -0500 Message-Id: <5107430f3d93d5e3fe21e269e5d30667b01daadd.1674835106.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 --- 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 Fri Jan 27 15:59:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118897 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 B2418C54EAA for ; Fri, 27 Jan 2023 16:01:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232568AbjA0QBA (ORCPT ); Fri, 27 Jan 2023 11:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234432AbjA0QAR (ORCPT ); Fri, 27 Jan 2023 11:00:17 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C746841AE for ; Fri, 27 Jan 2023 08:00:10 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id s4so4353833qtx.6 for ; Fri, 27 Jan 2023 08:00:10 -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=qYcQMbnIgjsq+2qoHJRXRTXFWfa6vSS9/8tTjeYDvZc=; b=l/AeVhDcrjtzX/lPFsK19b49/Q/JTsHD5XKyw1tjeUGGjKweu6et02j9LpjZwRsOXJ QbpR26b6UjcAyPJTKQx6J3F+FNx8IWlFcZnUCRGGCRDJtpo+0FlYztj5waLhOrAeD7ZN SJFnEMQD9ffqmNDv73teojSVp3Yv0Dxkymbrzw0nSFvyFTbHsG45y99urqU+Y45AHifR 0o+IQe6pw3aL5X03XsBREHm366OaDdQEStB5hDMCSriGmsVgd+XxfwU2I03OPdeSlqw1 dxiTXeHiowN+d1YjMQIKSexLJupopMDKuT3RmdpMDxNsPSbolMxvBHvF55gnrWSChuRD /0lw== 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=qYcQMbnIgjsq+2qoHJRXRTXFWfa6vSS9/8tTjeYDvZc=; b=bkB9vyz0tEESWPVgwqCRnJhlCN4qNUsu9ERvabu1v7siPyF+W5H7/x82iswYyN2lui wOmcB8t0GftOeoVsTsYUTLBrwZkC3Yo1i/Nq45oabPk/Nzs2j6IY3xv4pZki2lbQhcUC H7YDnPxgmbgZ1Mp/6F5JBuQajEkhS+9lKjBINZ/MV890QLvBIIEjiTEx/UlYe6cFW6FP uFqOmezxGvCg00toWt9Nca9KMPxXCJivpERylbbkbw+B3Bc2H3f6MZSRuSb43j2FGIhG RIk9TO+TmM31v1FfTyxi4IqqsklxcT9o2zrSlkrxIk+i2Jbqqex73xE+l6o2+sKjgpTW Be6g== X-Gm-Message-State: AFqh2kpC+1LjrokhZKup/gieWkIVwiry8Z99gE4I73KSAO5cFhG7d2sx GZRCvW8nD94q80WdtTNxWcsYkQds8rr5sw== X-Google-Smtp-Source: AMrXdXsgj4w2wvKcvwQdGh24//vbwzT3JLlnj0hxS/35rnZII3142jzuJE6akgaw4K/iPJSwwqCYTw== X-Received: by 2002:ac8:5707:0:b0:3b1:80ab:38e with SMTP id 7-20020ac85707000000b003b180ab038emr76912718qtw.0.1674835209193; Fri, 27 Jan 2023 08:00:09 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:09 -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: [PATCHv3 net-next 09/10] net: add gso_ipv4_max_size and gro_ipv4_max_size per device Date: Fri, 27 Jan 2023 10:59:55 -0500 Message-Id: <905adccfe82888a8f0ca05fe6f2abd7e3a9649a0.1674835106.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 --- 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 63b77cbc947e..ce075241ec47 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2010,6 +2010,9 @@ enum netdev_ml_priv_type { * SET_NETDEV_DEVLINK_PORT macro. This pointer is static * during the time netdevice is registered. * + * @gso_ipv4_max_size: Maximum size of IPv4 GSO packets. + * @gro_ipv4_max_size: Maximum size of IPv4 GRO packets. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2362,6 +2365,9 @@ struct net_device { struct rtnl_hw_stats64 *offload_xstats_l3; struct devlink_port *devlink_port; + + unsigned int gso_ipv4_max_size; + unsigned int gro_ipv4_max_size; }; #define to_net_dev(d) container_of(d, struct net_device, dev) 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 9c60190fe352..45e955eadca4 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); @@ -10610,6 +10612,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 Fri Jan 27 15:59:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13118896 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 ED74CC38142 for ; Fri, 27 Jan 2023 16:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234391AbjA0QA7 (ORCPT ); Fri, 27 Jan 2023 11:00:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234413AbjA0QAR (ORCPT ); Fri, 27 Jan 2023 11:00:17 -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 7425E8663F for ; Fri, 27 Jan 2023 08:00:11 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id m26so4342168qtp.9 for ; Fri, 27 Jan 2023 08:00:11 -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=0droLD9xWCEleZyachsSghGy62xKncNAXBCionjipGQ=; b=TnjJeUePPXtrUdtkEmfUx24evk3Dmem396bz05imOX/WmmcbdPf5IPJsQkzBfRxNRw wltR6hROhssO526Fn0dbgz1qpnXsG47Xr2n3Rceuz/zcyt13064euPvUnZTVETCFPUzW FZkd/AcU2YDpVq2e9yFdMNrZyzn0/cDIbnKVI3SSFBYbIXjE+20lBETY7oVjeXGq52Kr UKrzG1Or4p8W+/vk4nrcV5eChCf3hiiiMDT9Knz+b1dc44T9nJbb+sMcxpAM2wy5E2aQ iJBp1MXxEni+/IDu/m3o9/e7dbw/0thv8KDi/rHribnuDosldtG1H21e40AaqrYr2ipN wChw== 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=0droLD9xWCEleZyachsSghGy62xKncNAXBCionjipGQ=; b=FHjgq4NwTja5ZZAYvU3SXajCKpwFZU+mdoqEV+3wQ55/Sg38FPsanmOFub4ty43Dva hr1caR0l6RGAlpyia6611lBWeXROOZqR8AhhvXJvktekR7bDcQUC4TE8SMkHF16Ux20B GO41CT0V589du4EhoVXGIYh3Q0/IA/3kcC7hL16lnXL6jr6WG8cc2jDFp59Q2yypoFiu qoBC/iJmuJIg8OaQ/ZGI7EVFYoc9xnOM1txTZcr0a4GKiWE2OnXyXmy7pIu/LLYF60UA XWsYiEolDQhF91FLPTQSnUEqT6qmLbUWilb30Ru3a6W7ClcxJoRW8JvC8r/VV12Ts65E zluA== X-Gm-Message-State: AFqh2kpzD/HYfeq6Ww86AqW+ONy+LAoowfPujaM5oLrtkCChZdCGboea k8dEYzSJMUMt+Hd6bbh6x8xWwYYaCDrOuw== X-Google-Smtp-Source: AMrXdXvOOyNGiBD7UJVHVwvpSVRFnxU3OGNUKdEktxlEsUvpY3iALi8yKS8C3ZyfyWO0pyYfYSfhpA== X-Received: by 2002:ac8:4742:0:b0:3b6:8ece:caae with SMTP id k2-20020ac84742000000b003b68ececaaemr42676070qtp.28.1674835210371; Fri, 27 Jan 2023 08:00:10 -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 z3-20020a05622a124300b003b62bc6cd1csm2860659qtx.82.2023.01.27.08.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:00:10 -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: [PATCHv3 net-next 10/10] net: add support for ipv4 big tcp Date: Fri, 27 Jan 2023 10:59:56 -0500 Message-Id: <798ca80553e73028eeec4be08ba1549d08b2e5fc.1674835106.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 --- net/core/gro.c | 12 +++++++----- net/core/sock.c | 8 ++++++-- net/ipv4/af_inet.c | 7 ++++--- net/ipv4/ip_input.c | 2 +- net/ipv4/ip_output.c | 2 +- 5 files changed, 19 insertions(+), 12 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..c98f9a4eeff9 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2383,6 +2383,8 @@ static void sk_trim_gso_size(struct sock *sk) !ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)) return; #endif + if (sk->sk_family == AF_INET && sk_is_tcp(sk)) + return; sk->sk_gso_max_size = GSO_LEGACY_MAX_SIZE; } @@ -2403,8 +2405,10 @@ 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); + /* pairs with the WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ + sk->sk_gso_max_size = sk->sk_family == AF_INET6 ? + READ_ONCE(dst->dev->gso_max_size) : + READ_ONCE(dst->dev->gso_ipv4_max_size); sk_trim_gso_size(sk); sk->sk_gso_max_size -= (MAX_TCP_HEADER + 1); /* pairs with the WRITE_ONCE() in netif_set_gso_max_segs() */ 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..0aa8c49b4e1b 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 = skb_ip_totlen(skb); 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