From patchwork Sat Apr 16 00:10:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815516 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 0C61AC433F5 for ; Sat, 16 Apr 2022 00:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344227AbiDPANk (ORCPT ); Fri, 15 Apr 2022 20:13:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233645AbiDPANh (ORCPT ); Fri, 15 Apr 2022 20:13:37 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DABFB41332 for ; Fri, 15 Apr 2022 17:11:07 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id s137so9030443pgs.5 for ; Fri, 15 Apr 2022 17:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0T6Pv25KNqD6Qm26oE/uG+HtT+P6NupR7dYzjUxtIek=; b=D5Fz13nsuTknxo4Rdd8rcIudfvdNHRjWcomMatDSEyxMZiO8L08ziaG20UDW9BTVrl ao0vH8p9MfTApJJfgQBjDzqXW49YWNBWQtOzfcUWtfLWZcbrbQq5AKALLRAdzqeACn4d VyqFNaoRy1FrlOeW4ubE+m8B8GJOMMlv1y2OcFOPjI0YExJgqZ+KdUh1vTf0b08EdYqH yyjm6KhhnLN4+sykVGnoCQc9YEb9axMZB3KuJGfb4Do9fXq7X34iVDy/aWEGl/Mwl4on SMjNsUakIR61sy+eqtOp/lPjk+fC3DMzsKAC8uAmKVPcSXq2f//Z9lj20bPBvVpcnAXs ZUkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0T6Pv25KNqD6Qm26oE/uG+HtT+P6NupR7dYzjUxtIek=; b=EB/yBg81DHsPVR6w2J2ICAUINjLqBkluJrzluvQCqsRdEGUJLRKDLnu/Yn6d7G90cd oaShfKlJTVLXX/rrRv7S7mQTunP+84cv8jy1x8g7POCZUhNJcO3l+PGMKb9wKvb2Dzlb TVBwq7xmx5cpCPTxg03HDnQ0ynEpFv7PBFwgG9GAZ67sjmKAhwTUEZSNsaQU2mcz6j+O PkF+WxDHgOORptfWK+4jbe6rbwpcuu7WalZbo2Fc7+jUz4VdXpEc0175nF0GkUKubIds R6SO9mEnYGZk7sDQLROntSDvYUAOmgsLABMftjudGgaOO9HUZjkKER6bfGowPnwYtRk0 JwVA== X-Gm-Message-State: AOAM532Ik9rM0RKoFJwFGUkwKV7imxH+Jn0uKDQbRXWJrps7GnJQbJED +mmY26OaQmOMNHXATQqTT3o= X-Google-Smtp-Source: ABdhPJzFmRZMEdgKxugPJdvGF8M0o+loHTukMGzUYVlCQP875/NW2aPZe8djtzsl6wSRbGLhcKgSUA== X-Received: by 2002:a05:6a02:184:b0:373:a24e:5ab with SMTP id bj4-20020a056a02018400b00373a24e05abmr1119576pgb.400.1650067867482; Fri, 15 Apr 2022 17:11:07 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:07 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 01/10] tcp: consume incoming skb leading to a reset Date: Fri, 15 Apr 2022 17:10:39 -0700 Message-Id: <20220416001048.2218911-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Whenever tcp_validate_incoming() handles a valid RST packet, we should not pretend the packet was dropped. Create a special section at the end of tcp_validate_incoming() to handle this case. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 1595b76ea2bea195b8896f4cd533beb14b56dd96..d4bc717791704795a9a159baf4ccd501a9471609 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5700,7 +5700,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, &tp->last_oow_ack_time)) tcp_send_dupack(sk, skb); } else if (tcp_reset_check(sk, skb)) { - tcp_reset(sk, skb); + goto reset; } goto discard; } @@ -5736,17 +5736,16 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, } if (rst_seq_match) - tcp_reset(sk, skb); - else { - /* Disable TFO if RST is out-of-order - * and no data has been received - * for current active TFO socket - */ - if (tp->syn_fastopen && !tp->data_segs_in && - sk->sk_state == TCP_ESTABLISHED) - tcp_fastopen_active_disable(sk); - tcp_send_challenge_ack(sk); - } + goto reset; + + /* Disable TFO if RST is out-of-order + * and no data has been received + * for current active TFO socket + */ + if (tp->syn_fastopen && !tp->data_segs_in && + sk->sk_state == TCP_ESTABLISHED) + tcp_fastopen_active_disable(sk); + tcp_send_challenge_ack(sk); goto discard; } @@ -5771,6 +5770,11 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, discard: tcp_drop(sk, skb); return false; + +reset: + tcp_reset(sk, skb); + __kfree_skb(skb); + return false; } /* From patchwork Sat Apr 16 00:10:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815519 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 BD030C433EF for ; Sat, 16 Apr 2022 00:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244765AbiDPANu (ORCPT ); Fri, 15 Apr 2022 20:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237029AbiDPANo (ORCPT ); Fri, 15 Apr 2022 20:13:44 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7AC4339E for ; Fri, 15 Apr 2022 17:11:10 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id bg9so9014862pgb.9 for ; Fri, 15 Apr 2022 17:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1sHaqTtYvmcIs/oUCIOZjafImQ79kQw8G0/TmQWihB8=; b=Tg6n9tL5dQBdE7HdNe54kMFnBtq72qtACymM1Y0v7wchy0brUSJGum/QypTLfudrFr 5Fvttyl6T5w0JHLboUPDeEMauCFGkDRhxlZ8S7N8RknlheyJIZfO8GCQJ40/JBa1P3WS xVVrkGl+NNvVikY7Fq5j3pPG9ChR3+7Zljwc6G3CTr9nO5WjrbyDm1sOS6GBwIrwVsSd roPacSyLcQLwEoDkgeQVXeIfV8RzoyZmaPgPtz3mZK31Rb9T1xjBvIWK9aJFs9IkQirC i1+09410b3Nk7s/nYYkJXCI1uV6I9EkTxJxjlY9qX2LOfRBlygJHDBP9dxD4CH8fC+rg HJ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1sHaqTtYvmcIs/oUCIOZjafImQ79kQw8G0/TmQWihB8=; b=gat9RusPgI6hgk+MNG3GXZySIYQIh8d6a5/a+Gll7+f9OCl2Rvx2TksMRT6zNH0gDa 7jPqDO/i5whm/vuexYicI0rSmfWAUTEXF3Dr5gK2IZ7Yp6vFROkmzsXNpyweSe9G4IER TSFMS4druue1igfTAJmciSArhTvo3aMOKh/lMERQ47+fnaH17eURwAHnDPQE8yof4rfx F6qhtgNg6j3UIkzQCt0K1eTYAepBdDcTYGmCPLAiauUeZ1Uy5H8CexuzXP46HrTaUuQ3 9X1zvHsTH8GwjFoyiVOPlVAkcQ/7whCXyOhoUv1KbIsnPlRfur/583daOspMNM8qW+hZ nkGQ== X-Gm-Message-State: AOAM533ZJ5VdgZIetDtyh7mrWipWasKWshVn+RvCZP/L2sZ24lTfUqR4 lVuIhWnGi6w4JDX34IVKhUw= X-Google-Smtp-Source: ABdhPJwdta1lpwmIKyjGKDe/lQ63xxaIvpV13aZrpFv75jmKL7eom6qvqzX3SQOFOwqpQflVzNLYpg== X-Received: by 2002:a62:e210:0:b0:508:3708:9c20 with SMTP id a16-20020a62e210000000b0050837089c20mr1266614pfi.29.1650067869947; Fri, 15 Apr 2022 17:11:09 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:09 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 02/10] tcp: get rid of rst_seq_match Date: Fri, 15 Apr 2022 17:10:40 -0700 Message-Id: <20220416001048.2218911-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Small cleanup in tcp_validate_incoming(), no need for rst_seq_match setting and testing. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index d4bc717791704795a9a159baf4ccd501a9471609..b2d5fbef6ce3baa9426b3c9750002317a8915596 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5667,7 +5667,6 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, const struct tcphdr *th, int syn_inerr) { struct tcp_sock *tp = tcp_sk(sk); - bool rst_seq_match = false; /* RFC1323: H1. Apply PAWS check first. */ if (tcp_fast_parse_options(sock_net(sk), skb, th, tp) && @@ -5717,9 +5716,10 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, * Send a challenge ACK */ if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt || - tcp_reset_check(sk, skb)) { - rst_seq_match = true; - } else if (tcp_is_sack(tp) && tp->rx_opt.num_sacks > 0) { + tcp_reset_check(sk, skb)) + goto reset; + + if (tcp_is_sack(tp) && tp->rx_opt.num_sacks > 0) { struct tcp_sack_block *sp = &tp->selective_acks[0]; int max_sack = sp[0].end_seq; int this_sack; @@ -5732,12 +5732,9 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, } if (TCP_SKB_CB(skb)->seq == max_sack) - rst_seq_match = true; + goto reset; } - if (rst_seq_match) - goto reset; - /* Disable TFO if RST is out-of-order * and no data has been received * for current active TFO socket From patchwork Sat Apr 16 00:10:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815518 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 49C67C433F5 for ; Sat, 16 Apr 2022 00:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234790AbiDPANs (ORCPT ); Fri, 15 Apr 2022 20:13:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349273AbiDPANp (ORCPT ); Fri, 15 Apr 2022 20:13:45 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 167D842EF0 for ; Fri, 15 Apr 2022 17:11:13 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d15so8174550pll.10 for ; Fri, 15 Apr 2022 17:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DpO9Ix2mFS2OG61f0hih6hFxdr7S54fG/Ffisg0A5AI=; b=h58RfNiohXS54WjweSao5jCxuYQychtFyEW1I2G/vYf0GnFTcYpd9/EpSRJczm8CoI yRLMkscNK4syHtt5uzW7rrxKz+CTTAgK5Q81leyjV5NCHywj952krnmt9W+DoyURGN81 tjNtyl5IDpuspEpbU6y14GqkrZb5tCh5+wjswhcTUqYpYjQ/J942wc0NL9+kUGB64oO6 JJ4pDKTB8OCdx7+4UVgwtVRNeUOTkx1o0K5OLY2RMV0M8tx2A5APL1MAR9WT7mROhXlq 1UqyufAwtlxS4LhFtzjakAyAMAbvYn4AB5wglqBahgXhronQP1FzOUgit4ZbgDMPL6WC uSUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DpO9Ix2mFS2OG61f0hih6hFxdr7S54fG/Ffisg0A5AI=; b=IZnJOPs2s7jm8pGmHSr5p6so7Q588K7KcnEFhT8T61VKU7IBGnl1zKlSueRbelQ6PH HsGkjic9DuS8R3cVMSDkAmu5kHoQI8BM5Cu8yW76jCoMzVmkp8S2PAjETLSy+wikzckN UMDtT6W33cEmG85nQbeuvg5iLl/kb0XHbNFniQtfRBDY1zpkNuJVYVElGWBZZ4AyJ9WW xCI7zCE5Cz/R283NuknlT9M5V+9OobAPEtM8p2GYhcbtKI8xXCpD7Ax5KQR/WZqCvbAw I9W0NSCiMpdQ5ErbhDBPoZZtjmdNYu+3N6lnlwqyUVDiIs/MWsGVDZAfhkIF5xki3tDL YkYg== X-Gm-Message-State: AOAM530WSUHWhDSQseQU4CggKABlGA3aVaw/HIbuB3XjrPVQs7u7JsZ3 ZkHeibx1cVhatO+t2U9fI2kyl9Y2bK8= X-Google-Smtp-Source: ABdhPJxC8Xydr4NcDZ1yqiRpf3h5lGKKfH+n0Pi3Y1suGJg0bbfpt9tv1IvZWgpIVbCuwb7fA4hZMQ== X-Received: by 2002:a17:903:d3:b0:158:bffa:b8d1 with SMTP id x19-20020a17090300d300b00158bffab8d1mr1460728plc.26.1650067872527; Fri, 15 Apr 2022 17:11:12 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:12 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 03/10] tcp: add drop reason support to tcp_validate_incoming() Date: Fri, 15 Apr 2022 17:10:41 -0700 Message-Id: <20220416001048.2218911-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Creates four new drop reasons for the following cases: 1) packet being rejected by RFC 7323 PAWS check 2) packet being rejected by SEQUENCE check 3) Invalid RST packet 4) Invalid SYN packet Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 6 ++++++ include/trace/events/skb.h | 5 +++++ net/ipv4/tcp_input.c | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 0ef11df1bc67f26a454a809396bd93299ce787ad..a903da1fa0ed897ba65a3edf6d74d7e5dc575b2e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -381,6 +381,12 @@ enum skb_drop_reason { * the ofo queue, corresponding to * LINUX_MIB_TCPOFOMERGE */ + SKB_DROP_REASON_TCP_RFC7323_PAWS, /* PAWS check, corresponding to + * LINUX_MIB_PAWSESTABREJECTED + */ + SKB_DROP_REASON_TCP_INVALID_SEQUENCE, /* Not acceptable SEQ field */ + SKB_DROP_REASON_TCP_RESET, /* Invalid RST packet */ + SKB_DROP_REASON_TCP_INVALID_SYN, /* Incoming packet has unexpected SYN flag */ SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by * BPF_PROG_TYPE_CGROUP_SKB diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 2da72a9a576462bee9f3415141dfffd2eec8c258..820dacd14bad9ecb2b8ff6206cb33b392c0c442c 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -37,6 +37,11 @@ EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ + EM(SKB_DROP_REASON_TCP_RFC7323_PAWS, TCP_RFC7323_PAWS) \ + EM(SKB_DROP_REASON_TCP_INVALID_SEQUENCE, \ + TCP_INVALID_SEQUENCE) \ + EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET) \ + EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN) \ EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ BPF_CGROUP_EGRESS) \ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index b2d5fbef6ce3baa9426b3c9750002317a8915596..9a1cb3f48c3fb26beac4283001d38828ca15a4d9 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5667,6 +5667,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, const struct tcphdr *th, int syn_inerr) { struct tcp_sock *tp = tcp_sk(sk); + SKB_DR(reason); /* RFC1323: H1. Apply PAWS check first. */ if (tcp_fast_parse_options(sock_net(sk), skb, th, tp) && @@ -5678,6 +5679,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, LINUX_MIB_TCPACKSKIPPEDPAWS, &tp->last_oow_ack_time)) tcp_send_dupack(sk, skb); + SKB_DR_SET(reason, TCP_RFC7323_PAWS); goto discard; } /* Reset is accepted even if it did not pass PAWS. */ @@ -5701,6 +5703,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, } else if (tcp_reset_check(sk, skb)) { goto reset; } + SKB_DR_SET(reason, TCP_INVALID_SEQUENCE); goto discard; } @@ -5743,6 +5746,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, sk->sk_state == TCP_ESTABLISHED) tcp_fastopen_active_disable(sk); tcp_send_challenge_ack(sk); + SKB_DR_SET(reason, TCP_RESET); goto discard; } @@ -5757,6 +5761,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNCHALLENGE); tcp_send_challenge_ack(sk); + SKB_DR_SET(reason, TCP_INVALID_SYN); goto discard; } @@ -5765,7 +5770,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, return true; discard: - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, reason); return false; reset: From patchwork Sat Apr 16 00:10:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815517 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 064F8C433F5 for ; Sat, 16 Apr 2022 00:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238655AbiDPANr (ORCPT ); Fri, 15 Apr 2022 20:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234790AbiDPANq (ORCPT ); Fri, 15 Apr 2022 20:13:46 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6418745522 for ; Fri, 15 Apr 2022 17:11:15 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id mm4-20020a17090b358400b001cb93d8b137so12872166pjb.2 for ; Fri, 15 Apr 2022 17:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ALmzQ9Q+8X6XJAsK0gGaBbMoAKqVtAapFOiAAHKn22A=; b=WZQQ65R3dnkZiL3jdvUIwRtrsDpT2ootgOEUwcfxhgZp8RBPu4h61CKP/M/3F66FlG Tl0vxQ1gyJA+/OXeezFiDYOoyfo6PNfVmDzmvWlLpIp//WxznG5/AlJpzZZDMmYM717R 8UMFGsKuq2uOr3kqT2r0II9rvMJKJ1jdjh4rMZwA6WK9AvhMBMP0kq9LHhneNLTN1+Fy NtemCXI9AvS3oGXFNdyMN1wyRrLmZCEftcf7KjwyB2oPTAGOAi//E2dyC+wjJsNuuNMb hEjN77Dw8V8bleBfwzvEHvyrd1cdAOigcFQfk+NA/0qTTKsGHGJ2gKhJONGKQLgnMJ9R SWcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ALmzQ9Q+8X6XJAsK0gGaBbMoAKqVtAapFOiAAHKn22A=; b=74ss2RE/FzMUScPDjfbyKGaPOAvr++IRaOPCKbelfKdl6vje0s6Hp7TFTtdzeNy5NS LYHJ35WRAgtW7N6TDhn7JTO0EY+20gSKkiDyTOl05pFaHkRdsHQem49RQGZ1hytsMlpr 9gqi8YfTZ22/VG7br1piHPoJgvSlegL0oXlWUudvNWXDoOK2V5T4qUTe8QlXHtIJBFGm cjXYSeGudUNVoun/fBdFrHcs6W3VY7Ftcf2Ur2WM4LeACRxrNS2jTXdZiUdm8oOYoEaq DwOIkJAZa2/J1ijx2F8Vuqr7zloax9jVEBxCaLBYjZEQlnZiy7+MIJCbCDmBMTy02yL0 Gc0g== X-Gm-Message-State: AOAM533vHas9NgtPmuyCiHwxi3lXttVteB07qDs6TgwjSwO65Sv0x6Uv EGJb1BbJB1a31Rs46qjQU6E= X-Google-Smtp-Source: ABdhPJy60xWV+CB9xH2cUFeoGTxgRUkoh3u+C3BNlE/tXU4MoI2LA1vBPlk8u4dWzdU1g2eCGASjxQ== X-Received: by 2002:a17:903:2445:b0:158:85bb:35f2 with SMTP id l5-20020a170903244500b0015885bb35f2mr1364329pls.123.1650067874971; Fri, 15 Apr 2022 17:11:14 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:14 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 04/10] tcp: make tcp_rcv_state_process() drop monitor friendly Date: Fri, 15 Apr 2022 17:10:42 -0700 Message-Id: <20220416001048.2218911-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet tcp_rcv_state_process() incorrectly drops packets instead of consuming it, making drop monitor very noisy, if not unusable. Calling tcp_time_wait() or tcp_done() is part of standard behavior, packets triggering these actions were not dropped. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 9a1cb3f48c3fb26beac4283001d38828ca15a4d9..f95a8368981d319400d0f46b81ced954d941f718 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6580,7 +6580,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) inet_csk_reset_keepalive_timer(sk, tmo); } else { tcp_time_wait(sk, TCP_FIN_WAIT2, tmo); - goto discard; + goto consume; } break; } @@ -6588,7 +6588,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) case TCP_CLOSING: if (tp->snd_una == tp->write_seq) { tcp_time_wait(sk, TCP_TIME_WAIT, 0); - goto discard; + goto consume; } break; @@ -6596,7 +6596,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (tp->snd_una == tp->write_seq) { tcp_update_metrics(sk); tcp_done(sk); - goto discard; + goto consume; } break; } @@ -6650,6 +6650,10 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) tcp_drop(sk, skb); } return 0; + +consume: + __kfree_skb(skb); + return 0; } EXPORT_SYMBOL(tcp_rcv_state_process); From patchwork Sat Apr 16 00:10:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815520 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 182B1C433EF for ; Sat, 16 Apr 2022 00:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbiDPANx (ORCPT ); Fri, 15 Apr 2022 20:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240560AbiDPANr (ORCPT ); Fri, 15 Apr 2022 20:13:47 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A5841F8B for ; Fri, 15 Apr 2022 17:11:17 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id t13so9030627pgn.8 for ; Fri, 15 Apr 2022 17:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jWTuTUE3yyARlgiYfWaqvvo/xhUSDcrqasLcQQqKlEI=; b=R3V7h4zdbh3AYQn/tVWTYfv5S+1V6VBCdn/zWviXBdQqC2NGjIwvvHEsV3tOsVKTu7 +T+alenCeO3rpTqJpGknaYQoFqYoiK64l0CVPfeRh4GeDYTByC0zq+Yf6KokL33NlAuE XXiRzOMvifXgX1Jb6LaK+HAMaOiQwNA+jtfAcbFQaSD25ysrl2cmQwyGxGeTwpv5RD4n WeLWUn9ibfec+ENvERG3PVYaXN3d7HKMVyem45LCwbBnPbe8LnqAOztyUdVDM7hilDQa CyUw5BYSbZqPO+fh4pnChbcef/mFqDldcrlyMse5hvEP5uBboVAk7hEtlXRTUmbJe6Ee X65w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jWTuTUE3yyARlgiYfWaqvvo/xhUSDcrqasLcQQqKlEI=; b=siIfY8R+4sQvoLifECROtLDRjpN+l+LtzvOtKtoAu7/si8awxI+RzmxkmY834YqfpX e8KgJGMEFbvtRN6aiT7pQpnN6wEdWK+7fHzS6jdCWyUE2lNnUiPpoK3eVqJF/uSy+x8n wZv/MIsDFWmniDtjg1AqABSRXdwHyVIeVC4pi8Yaqw8qFV1tPUigOdZEeV+MFpq8LQJ1 ZbuN5gahlwJlSUXsIKhzN0kni247OfgEmbWam3Q1f/K1PAw+PFb1wmqD8CprQ5KKJwNM GTKjmSdGvX3lA1plfZHa4ILZm9/Oh/Ew5UddPHyDMBGhXg0nhJUThPzWvVrscCsh2+pk PR4Q== X-Gm-Message-State: AOAM532H7mub1KQp7CrlL/93IsB5XTTenXFkIjOFv9Oiuu2DVlPWIa5/ XbJ9bnvc5gNJSKsVVlTuaY8= X-Google-Smtp-Source: ABdhPJyiVJb0ukcy0n2SSjxFFR5CE7QZjgJuzOLL2CnHU64cgmcNOnpOBhq+cRVjYvir1FqUPzncaA== X-Received: by 2002:aa7:8241:0:b0:509:979d:c760 with SMTP id e1-20020aa78241000000b00509979dc760mr1281596pfn.84.1650067877329; Fri, 15 Apr 2022 17:11:17 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:17 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 05/10] tcp: add drop reasons to tcp_rcv_state_process() Date: Fri, 15 Apr 2022 17:10:43 -0700 Message-Id: <20220416001048.2218911-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Add basic support for drop reasons in tcp_rcv_state_process() Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 3 +++ net/ipv4/tcp_input.c | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a903da1fa0ed897ba65a3edf6d74d7e5dc575b2e..6f1410b5ff1372d9e1f7a75c303f8d7876c83ef0 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -387,6 +387,9 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_INVALID_SEQUENCE, /* Not acceptable SEQ field */ SKB_DROP_REASON_TCP_RESET, /* Invalid RST packet */ SKB_DROP_REASON_TCP_INVALID_SYN, /* Incoming packet has unexpected SYN flag */ + SKB_DROP_REASON_TCP_CLOSE, /* TCP socket in CLOSE state */ + SKB_DROP_REASON_TCP_FASTOPEN, /* dropped by FASTOPEN request socket */ + SKB_DROP_REASON_TCP_OLD_ACK, /* TCP ACK is old, but in window */ SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by * BPF_PROG_TYPE_CGROUP_SKB diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 820dacd14bad9ecb2b8ff6206cb33b392c0c442c..fbe21ad038bc6701ed04cb6be417c544de0dae84 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -42,6 +42,9 @@ TCP_INVALID_SEQUENCE) \ EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET) \ EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN) \ + EM(SKB_DROP_REASON_TCP_CLOSE, TCP_CLOSE) \ + EM(SKB_DROP_REASON_TCP_FASTOPEN, TCP_FASTOPEN) \ + EM(SKB_DROP_REASON_TCP_OLD_ACK, TCP_OLD_ACK) \ EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ BPF_CGROUP_EGRESS) \ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index f95a8368981d319400d0f46b81ced954d941f718..85fae79c894d4b96820747c658bb4d884981c49e 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6413,21 +6413,26 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) struct request_sock *req; int queued = 0; bool acceptable; + SKB_DR(reason); switch (sk->sk_state) { case TCP_CLOSE: + SKB_DR_SET(reason, TCP_CLOSE); goto discard; case TCP_LISTEN: if (th->ack) return 1; - if (th->rst) + if (th->rst) { + SKB_DR_SET(reason, TCP_RESET); goto discard; - + } if (th->syn) { - if (th->fin) + if (th->fin) { + SKB_DR_SET(reason, TCP_FLAGS); goto discard; + } /* It is possible that we process SYN packets from backlog, * so we need to make sure to disable BH and RCU right there. */ @@ -6442,6 +6447,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) consume_skb(skb); return 0; } + SKB_DR_SET(reason, TCP_FLAGS); goto discard; case TCP_SYN_SENT: @@ -6468,13 +6474,16 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && sk->sk_state != TCP_FIN_WAIT1); - if (!tcp_check_req(sk, skb, req, true, &req_stolen)) + if (!tcp_check_req(sk, skb, req, true, &req_stolen)) { + SKB_DR_SET(reason, TCP_FASTOPEN); goto discard; + } } - if (!th->ack && !th->rst && !th->syn) + if (!th->ack && !th->rst && !th->syn) { + SKB_DR_SET(reason, TCP_FLAGS); goto discard; - + } if (!tcp_validate_incoming(sk, skb, th, 0)) return 0; @@ -6487,6 +6496,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (sk->sk_state == TCP_SYN_RECV) return 1; /* send one RST */ tcp_send_challenge_ack(sk); + SKB_DR_SET(reason, TCP_OLD_ACK); goto discard; } switch (sk->sk_state) { @@ -6647,7 +6657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (!queued) { discard: - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, reason); } return 0; From patchwork Sat Apr 16 00:10:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815521 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 00741C433FE for ; Sat, 16 Apr 2022 00:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348687AbiDPANz (ORCPT ); Fri, 15 Apr 2022 20:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231308AbiDPANv (ORCPT ); Fri, 15 Apr 2022 20:13:51 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D19AB4163A for ; Fri, 15 Apr 2022 17:11:20 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id n8so8209166plh.1 for ; Fri, 15 Apr 2022 17:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=voz66caexxFz/vB6IlDaiR7ZhtSqXFLJ+ZGvJbrFV5A=; b=SOTFGlzRziukjfc4y2wAXpERNAyn7O1fKk6FNoFFa4moDUK6FqiB3OI3lJbgrHCgPm ocLR7PnzrnUtu0Xr/FpfuXO9SYJmv+PSdFUL1CRQsh51ouAG5hpXewUNe29fx3L/LSMn HXKhPfibIudu1NIRtt393zTBWo4yvzT62qwmxORc99GGpX7tmWBfPkYdl5qdQRGjV/g7 6kFrited3mDT9XGmUWa2cP5OmQMrE115xHtHgvMN5LI66UebtATCLhIEWgiT7+sXpELh jTlQK2VnGEJSqyVR7HR4s++8NJrdS9G4FkMw+3ZuvEuF5moXjlKg/rpfKmozKrwOinTg gbfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=voz66caexxFz/vB6IlDaiR7ZhtSqXFLJ+ZGvJbrFV5A=; b=Cg12kFbJBxbQbgLYBAVWgkJKRWsxUQYT5CnONVIgrZfuzpav730D7QdN8L8ik+2wCg MR59u4Ok6IYyBsO63dztubNSMoQAFJMmQ+e/imIpJFtXRYZn6qPMYpvogE9lv1abc221 DlUU5Y6HDDEU6YCTa/40WXUREUY+2x6i4dGzaDtbZ8rIQk6s2/LC1TCNPXFX+tZEJMb/ 3XWB6wkuk++RHt2byX6hAxT0D/8852sKlYOtuWYBIWY87oIOhxpUq4waJXqs06mEAMRD VmRnnwzr/qeUXqjncQf5RioB5TvvOMmDf4FbYIeCg49fGdis3VpxJ6eya8g39cOchwDq x+wg== X-Gm-Message-State: AOAM533g+u43L6m0hFA3l1zaRHvfhLLfoVfltSzDareJYZiiRXWWl1J/ w7b9gQWzPZHkcR2APHKuRz0= X-Google-Smtp-Source: ABdhPJxISntoSBtL0AOhw3ZmQrmZGxKv/drJgfByNnfy7Nn6u+GBaYrWD4WjCfrslbtgEeYLSjySCA== X-Received: by 2002:a17:902:8698:b0:158:99d4:6256 with SMTP id g24-20020a170902869800b0015899d46256mr1464799plo.104.1650067880004; Fri, 15 Apr 2022 17:11:20 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:19 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 06/10] tcp: add two drop reasons for tcp_ack() Date: Fri, 15 Apr 2022 17:10:44 -0700 Message-Id: <20220416001048.2218911-7-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Add TCP_TOO_OLD_ACK and TCP_ACK_UNSENT_DATA drop reasons so that tcp_rcv_established() can report them. Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 2 ++ include/trace/events/skb.h | 3 +++ net/ipv4/tcp_input.c | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 6f1410b5ff1372d9e1f7a75c303f8d7876c83ef0..9ff5557b190905f716a25f67113c1db822707959 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -390,6 +390,8 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_CLOSE, /* TCP socket in CLOSE state */ SKB_DROP_REASON_TCP_FASTOPEN, /* dropped by FASTOPEN request socket */ SKB_DROP_REASON_TCP_OLD_ACK, /* TCP ACK is old, but in window */ + SKB_DROP_REASON_TCP_TOO_OLD_ACK, /* TCP ACK is too old */ + SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, /* TCP ACK for data we haven't sent yet */ SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by * BPF_PROG_TYPE_CGROUP_SKB diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index fbe21ad038bc6701ed04cb6be417c544de0dae84..eab0b09223f3c66255f930d44be61d45e83ca6e8 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -45,6 +45,9 @@ EM(SKB_DROP_REASON_TCP_CLOSE, TCP_CLOSE) \ EM(SKB_DROP_REASON_TCP_FASTOPEN, TCP_FASTOPEN) \ EM(SKB_DROP_REASON_TCP_OLD_ACK, TCP_OLD_ACK) \ + EM(SKB_DROP_REASON_TCP_TOO_OLD_ACK, TCP_TOO_OLD_ACK) \ + EM(SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, \ + TCP_ACK_UNSENT_DATA) \ EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ BPF_CGROUP_EGRESS) \ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 85fae79c894d4b96820747c658bb4d884981c49e..8a68785b04053b8e622404035284920e51cd953c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -3766,7 +3766,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) if (before(ack, prior_snd_una - tp->max_window)) { if (!(flag & FLAG_NO_CHALLENGE_ACK)) tcp_send_challenge_ack(sk); - return -1; + return -SKB_DROP_REASON_TCP_TOO_OLD_ACK; } goto old_ack; } @@ -3775,7 +3775,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) * this segment (RFC793 Section 3.9). */ if (after(ack, tp->snd_nxt)) - return -1; + return -SKB_DROP_REASON_TCP_ACK_UNSENT_DATA; if (after(ack, prior_snd_una)) { flag |= FLAG_SND_UNA_ADVANCED; @@ -5962,7 +5962,8 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) return; step5: - if (tcp_ack(sk, skb, FLAG_SLOWPATH | FLAG_UPDATE_TS_RECENT) < 0) + reason = tcp_ack(sk, skb, FLAG_SLOWPATH | FLAG_UPDATE_TS_RECENT); + if (reason < 0) goto discard; tcp_rcv_rtt_measure_ts(sk, skb); From patchwork Sat Apr 16 00:10:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815522 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 4E45AC433EF for ; Sat, 16 Apr 2022 00:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbiDPAOE (ORCPT ); Fri, 15 Apr 2022 20:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245694AbiDPANx (ORCPT ); Fri, 15 Apr 2022 20:13:53 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D722E3FDBD for ; Fri, 15 Apr 2022 17:11:22 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id k29so9016513pgm.12 for ; Fri, 15 Apr 2022 17:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/7G1zqgFMYnJTf2aCFq6rD8OeLxfrar8r80T2W3ZAYQ=; b=eaEbwoKsDc6V9mKSxYrPqwjC9sUQzcLXMZJDN+fgugsrmy+000CVQD5xov4I3KpMXz zOd6AtXGrM4zRBsdtrYaMnGn0ApNZ5ma6pHr2Qaoqo7WOyhn6JXAGasp29Typz1WHp9w FH0LB7NTcz3311cL6ZQLRsIo0tBb+3KM9EVTHomg/Cg8Eqy9hxAmXHhLymuRKXTl599P RnlgiS1KM5pR1qCmSPZPp5eEpTrgNNiFooXUYQkk5cRQR6uI8T1qsIulZXpYMCoTK9zl xcV2R1iZWjQZD4iTf3UiBk5drYX4fa1gQvgdacH/JrKQwanCUt3ljc6xmkzbwFSGRTbK PzPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/7G1zqgFMYnJTf2aCFq6rD8OeLxfrar8r80T2W3ZAYQ=; b=RiisMERYcktK9bORTzkefTBw11vFzFDvVoGWVbaXqi+uSuKPPHY6BgC6YTWgy4U5Qi DHxFOddKWMVCXQoSjk4NMJD5YIYW0DqdeA59eO3SxIdcBKS+s1shZ6LT16tSBNDJlhgQ qUANrNYL8wVdPC+/WsmrQFMWl4+U6fX3cz1+Prjx2L5jIwobxbUd8fJVwOK7//sVsnfK VWMLdb2wF8CcMU42QbxBwCh+C2f8urGd9fntKPWF/vvzcMgeJciZ+ojGGurlUcMxyeTu HNk4z8NZSX3ci7mCfJ8DuGyXc/4JlCaKxCFHNul64BQrEUubcwqQOHbySBqSsT8+JV63 FsNQ== X-Gm-Message-State: AOAM533nKl2gIvfVJYGeTY20WPnWv+VFUBccKr+DhHksxdMIwKt2VtsC WEL/3I9i08AO/FaCakUs0yc= X-Google-Smtp-Source: ABdhPJyKVrpqTw2Q5YKWQJhP3AmXLiUPMGTfJh33YWN3aEZ5W5pd6uwV9lU+Itjghwp9fVfJSHmd3w== X-Received: by 2002:aa7:82d9:0:b0:4fa:2c7f:41e with SMTP id f25-20020aa782d9000000b004fa2c7f041emr1285650pfn.1.1650067882193; Fri, 15 Apr 2022 17:11:22 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:21 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 07/10] tcp: add drop reason support to tcp_prune_ofo_queue() Date: Fri, 15 Apr 2022 17:10:45 -0700 Message-Id: <20220416001048.2218911-8-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Add one reason for packets dropped from OFO queue because of memory pressure. Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 2 ++ net/ipv4/tcp_input.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9ff5557b190905f716a25f67113c1db822707959..ad15ad208b5612357546f23dfe4feaa1535f4982 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -392,6 +392,7 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_OLD_ACK, /* TCP ACK is old, but in window */ SKB_DROP_REASON_TCP_TOO_OLD_ACK, /* TCP ACK is too old */ SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, /* TCP ACK for data we haven't sent yet */ + SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE, /* pruned from TCP OFO queue */ SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by * BPF_PROG_TYPE_CGROUP_SKB diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index eab0b09223f3c66255f930d44be61d45e83ca6e8..73d7a6e594cbc6884148afa473bc08d12d783079 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -48,6 +48,8 @@ EM(SKB_DROP_REASON_TCP_TOO_OLD_ACK, TCP_TOO_OLD_ACK) \ EM(SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, \ TCP_ACK_UNSENT_DATA) \ + EM(SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE, \ + TCP_OFO_QUEUE_PRUNE) \ EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ BPF_CGROUP_EGRESS) \ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 8a68785b04053b8e622404035284920e51cd953c..a1077adeb1b62d74b5f1c9a6fc34def44ae07790 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5334,7 +5334,8 @@ static bool tcp_prune_ofo_queue(struct sock *sk) prev = rb_prev(node); rb_erase(node, &tp->out_of_order_queue); goal -= rb_to_skb(node)->truesize; - tcp_drop(sk, rb_to_skb(node)); + tcp_drop_reason(sk, rb_to_skb(node), + SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE); if (!prev || goal <= 0) { sk_mem_reclaim(sk); if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && From patchwork Sat Apr 16 00:10:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815523 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 D1CA9C433FE for ; Sat, 16 Apr 2022 00:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236112AbiDPAOE (ORCPT ); Fri, 15 Apr 2022 20:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344642AbiDPANy (ORCPT ); Fri, 15 Apr 2022 20:13:54 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF03944757 for ; Fri, 15 Apr 2022 17:11:24 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id z6-20020a17090a398600b001cb9fca3210so9442087pjb.1 for ; Fri, 15 Apr 2022 17:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hyYI31OehZRxF2H7hGB/TdSjORPpzBCzrIj/L2J8n/Q=; b=Rw8f1WJLYfkd0hC8RIfS4HdzpFRPvMVNl/Ke3deLI8fA7NRDz0e7ZeZK/lgPN6C6L3 3d5NlNSuda4/aI0JEJafWuGXK64Gmx5Jb+wX2upr7AajAi8v4+N5R5TkkjDKtCzrQH5j SQSwpJNGp/KHkbMZCxyE7j3iiQFEWmyTL5VDJ/KQ3I8ID8yd/3gIwbhrv8jgaFYcF+Iw UkWusElS6Ey+IVsUxWBeP393v9NGC1G9+yAoPMJ2ppo0/lA6sc1gbu6+OfHEa2GnIHBu 6Eq9ODrfNUCweQKNzLC1vFsvlx3/8Z/NsoHrGI8qNJmXca2rVrwC24adz6tUri/34hw3 N6rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hyYI31OehZRxF2H7hGB/TdSjORPpzBCzrIj/L2J8n/Q=; b=kmmTnTGgpFYp+ucSH67tdmMdxQk7pz2DV2L7tq2YnhHO9wE98MHY8EvERMQ/bVYkh2 sVvwUe2BVxTnA8x0DQ1QK5EbhWjDGQDk+27SCfwWfhn46OxlWNAyjkc/yn0o7Hx6Y3Bo o4KCy0RrvMZfRRrWsceKRZFO1skNIzHTPzwNO0kfh2D0Hgcs0yu63uZnnbkVbxKIrljc n+VJVl7lf0RzFBHTjoh1mJuMvMBcT6Qf4MPU80ls0llHYEmoAjqhxW3CyRAAeZAUwZhW 5GoXb8o4du6nzYfYrzimuKJOYIJIUwBzrzCGJtqvCHdTCpJw/i+JMuqCc7UG8xDBH+0S avSA== X-Gm-Message-State: AOAM533x9kt+vdrwUkvx9jDRQONd8fXs7SmAuNHYu1+okBNxFIuYmh1S VAuOkUvXCcFd40ueqI37Bq4= X-Google-Smtp-Source: ABdhPJwgcne68sLyvVsbZ43x0VQkGwSnqqgQjL/7Zdhv7OccBGchkJDfil50eStmAheIfQnrzvhERg== X-Received: by 2002:a17:903:240c:b0:153:c8df:7207 with SMTP id e12-20020a170903240c00b00153c8df7207mr1366617plo.44.1650067884438; Fri, 15 Apr 2022 17:11:24 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:24 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 08/10] tcp: make tcp_rcv_synsent_state_process() drop monitor friend Date: Fri, 15 Apr 2022 17:10:46 -0700 Message-Id: <20220416001048.2218911-9-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet 1) A valid RST packet should be consumed, to not confuse drop monitor. 2) Same remark for packet validating cross syn setup, even if we might ignore part of it. 3) When third packet of 3WHS is delayed, do not pretend the SYNACK was dropped. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index a1077adeb1b62d74b5f1c9a6fc34def44ae07790..cd9f5c39f85a042751ef78132860a2a6cc96bccc 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6186,7 +6186,9 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, if (th->rst) { tcp_reset(sk, skb); - goto discard; +consume: + __kfree_skb(skb); + return 0; } /* rfc793: @@ -6275,13 +6277,9 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, tcp_enter_quickack_mode(sk, TCP_MAX_QUICKACKS); inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, TCP_DELACK_MAX, TCP_RTO_MAX); - -discard: - tcp_drop(sk, skb); - return 0; - } else { - tcp_send_ack(sk); + goto consume; } + tcp_send_ack(sk); return -1; } @@ -6350,7 +6348,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, */ return -1; #else - goto discard; + goto consume; #endif } /* "fifth, if neither of the SYN or RST bits is set then @@ -6360,7 +6358,8 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, discard_and_undo: tcp_clear_options(&tp->rx_opt); tp->rx_opt.mss_clamp = saved_clamp; - goto discard; + tcp_drop(sk, skb); + return 0; reset_and_undo: tcp_clear_options(&tp->rx_opt); From patchwork Sat Apr 16 00:10:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815524 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 97D58C433EF for ; Sat, 16 Apr 2022 00:11:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231319AbiDPAOL (ORCPT ); Fri, 15 Apr 2022 20:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231308AbiDPAN5 (ORCPT ); Fri, 15 Apr 2022 20:13:57 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 417E54163A for ; Fri, 15 Apr 2022 17:11:27 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so9463521pja.0 for ; Fri, 15 Apr 2022 17:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VFPB/o/p02yEpoXVsNv474y8sumijZGgXHbx6Fsoz20=; b=Kybh6ZK/VBSagT+7FD/wihHbyht6DSqd8yvB43FHAY6Mf460TUhcKpZyS0FKmRlqKt JuTdWTiwYdtRLZp5WukxFNoAW+SSuMzd2nyMI1yT2pXPtH9hujpwWttUaFuC83EfxqWq Gd9R92Hi61i+nj9COIL4fQMnw9DPw6gs6+gJUBlE0VCQl3r9QqeyAzE+fhCmtgPVOIGI kqp7QgJsJIqbefqVljIWYFVOzdYhf/msVBs2Vw8jBYigtxRqBNEUK3ZpzBuqP1jNqLiD 3EVfyuTGVU4WgwEMdEE5geG9QTrnrmbZyRXVJ74sXFmxrIr+NdZyKvbbEpuy8ycpmOEt dq+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VFPB/o/p02yEpoXVsNv474y8sumijZGgXHbx6Fsoz20=; b=A16bukj+UmFNsYHEBWg9h1kCwuq9NQqSJoBgJ5tqMKPUPFt1lvnqBjvXMzBQgvtytF 58jYfFwYq5KAr0BYHmJsLQJELC11fDw6EO0YTDsvk+mVSm3RflGCTEX26kla3uRMEbF4 cHTwKKT2RV3aY1VOydmRb25e7/GnuPE8W3FzxaK4e54dXD2cUJXr190gYH4aXbXYKHLy UEh2O/UxREQuB8g6LW+F2/BgBi42T4VIVWHR4tau8/Cv1xhUAV94Cj/R6UW/kntmE5wz o1Hkz/WJSJqpV8xl1XXWZYe4rAa2i5qYfihjLF8YxfWx8XzxmLjDu+ogsp7tqzYo/Ydp WhkA== X-Gm-Message-State: AOAM532lj7eZ1JCiWY1iG1HqSvoX2+CmCmMgt7EWT6P1pHzn6FvCH+tv ERdUdS/QPhPCAih5Cd8asYyON8XRfdg= X-Google-Smtp-Source: ABdhPJwrbKAbpq4FBP2fihXnNpRnvzBoWnxuMONmjhrKu7FuurJmGb/ndknnMWrritArJ4hGtGLf0A== X-Received: by 2002:a17:902:f68e:b0:154:6518:69ba with SMTP id l14-20020a170902f68e00b00154651869bamr1479430plg.60.1650067886585; Fri, 15 Apr 2022 17:11:26 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:26 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 09/10] tcp: add drop reasons to tcp_rcv_synsent_state_process() Date: Fri, 15 Apr 2022 17:10:47 -0700 Message-Id: <20220416001048.2218911-10-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Re-use existing reasons. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index cd9f5c39f85a042751ef78132860a2a6cc96bccc..339cc3d40745a0ea2a9f66b03dfda5aa6800d4a2 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6144,6 +6144,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, struct tcp_fastopen_cookie foc = { .len = -1 }; int saved_clamp = tp->rx_opt.mss_clamp; bool fastopen_fail; + SKB_DR(reason); tcp_parse_options(sock_net(sk), skb, &tp->rx_opt, 0, &foc); if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) @@ -6198,9 +6199,10 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, * See note below! * --ANK(990513) */ - if (!th->syn) + if (!th->syn) { + SKB_DR_SET(reason, TCP_FLAGS); goto discard_and_undo; - + } /* rfc793: * "If the SYN bit is on ... * are acceptable then ... @@ -6291,15 +6293,16 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, * * Otherwise (no ACK) drop the segment and return." */ - + SKB_DR_SET(reason, TCP_RESET); goto discard_and_undo; } /* PAWS check. */ if (tp->rx_opt.ts_recent_stamp && tp->rx_opt.saw_tstamp && - tcp_paws_reject(&tp->rx_opt, 0)) + tcp_paws_reject(&tp->rx_opt, 0)) { + SKB_DR_SET(reason, TCP_RFC7323_PAWS); goto discard_and_undo; - + } if (th->syn) { /* We see SYN without ACK. It is attempt of * simultaneous connect with crossed SYNs. @@ -6358,7 +6361,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, discard_and_undo: tcp_clear_options(&tp->rx_opt); tp->rx_opt.mss_clamp = saved_clamp; - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, reason); return 0; reset_and_undo: From patchwork Sat Apr 16 00:10:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12815525 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 4D221C433F5 for ; Sat, 16 Apr 2022 00:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237845AbiDPAOM (ORCPT ); Fri, 15 Apr 2022 20:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232211AbiDPAN7 (ORCPT ); Fri, 15 Apr 2022 20:13:59 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6256E48E77 for ; Fri, 15 Apr 2022 17:11:29 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id bx5so8661708pjb.3 for ; Fri, 15 Apr 2022 17:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZIDCzIQbVqISNHr7nFXqJpdxyPN74kyCes1OzRawTFw=; b=Kr3lwbr7sc5z/5oTAodMArZvUtvE1ecQRWF6u7gx+rajpt3rBm2NVQ9RLzoOGtMCax f0Gu0vKhNdPoLV3AZHOTJhS758TurmURXYKNo3CQs6pThMUUPdnYJ7bf+NMV4sLL8t2/ DoE2qA0k4uxmChpOvxD8A93ca44TFNpF+Qk8j50CrGrahwXtyIyK9ruNzAIkpLuiFeGk 4RoA1TbVVSZEPc3yVD8KrZR8UTjUW8kcSU9roGZDI97akIgQ/TDhSQWDsLOlG1NLvlgb LFsKhL1l/jr8vSMzIAevXYda2NFy8+ZfqQCQNZMbUZGT8zHnqyx6yl/n4FK3Kwtkrxuk e7QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZIDCzIQbVqISNHr7nFXqJpdxyPN74kyCes1OzRawTFw=; b=r2EzHSffq6cObnYWnC44c9Z+GnkQNNdcztpCmAhddtMsZaiv2VWgTjXi/emyNE5CRv MMzRUm4Ahc6sdZi89Ty57AbJuX/UTnX83dUeiwnluHOMNV4yJ46f3XA8SNVds4KZio6+ LWBgDlUSLnULP1eNBTsf7WVLp2GNukj6Sl+EfgzRXHa24wAi9Sx0gwAHvEeRMLvYjRHN ZthDrn1/rZ4xpWXmlFpkolnTusZyTdn3BwJKx4YZNlvz68Jo4UBHkfCovTEvHiLwlTvS 4hUOE01yVywPAK05Z/cZODL/O4hepN2io/FnUeo9/whXqpi+cccFLbuiGeSxW8GnOKkX UTrA== X-Gm-Message-State: AOAM533A7GtWIsZCkbtjOcg2czj13uUkdImbxHdPoh6231f8xWGWDl6+ w/ucB0Y9ZsudujzOA9fhHInpLRO4SbQ= X-Google-Smtp-Source: ABdhPJyXYymKi010dhKwZe3Yj6rgD9dAzM+D1d09EjVosmo3G08o+TyTtd4dfoCbI37D5ZnOnVxxAA== X-Received: by 2002:a17:90a:3e48:b0:1cd:34ec:c72f with SMTP id t8-20020a17090a3e4800b001cd34ecc72fmr6754237pjm.65.1650067888791; Fri, 15 Apr 2022 17:11:28 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:147b:581d:7b9d:b092]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b001cb87502e32sm5729514pjf.23.2022.04.15.17.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:11:28 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 10/10] tcp: add drop reason support to tcp_ofo_queue() Date: Fri, 15 Apr 2022 17:10:48 -0700 Message-Id: <20220416001048.2218911-11-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220416001048.2218911-1-eric.dumazet@gmail.com> References: <20220416001048.2218911-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet packets in OFO queue might be redundant, and dropped. tcp_drop() is no longer needed. Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 9 ++------- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index ad15ad208b5612357546f23dfe4feaa1535f4982..84d78df60453955a8eaf05847f6e2145176a727a 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -393,6 +393,7 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_TOO_OLD_ACK, /* TCP ACK is too old */ SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, /* TCP ACK for data we haven't sent yet */ SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE, /* pruned from TCP OFO queue */ + SKB_DROP_REASON_TCP_OFO_DROP, /* data already in receive queue */ SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by * BPF_PROG_TYPE_CGROUP_SKB diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 73d7a6e594cbc6884148afa473bc08d12d783079..a477bf9074982cde8d1025ed18086fecafae8807 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -37,6 +37,7 @@ EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ + EM(SKB_DROP_REASON_TCP_OFO_DROP, TCP_OFO_DROP) \ EM(SKB_DROP_REASON_TCP_RFC7323_PAWS, TCP_RFC7323_PAWS) \ EM(SKB_DROP_REASON_TCP_INVALID_SEQUENCE, \ TCP_INVALID_SEQUENCE) \ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 339cc3d40745a0ea2a9f66b03dfda5aa6800d4a2..cf2dc19bb8c766c1d33406053fd61c0873f15489 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4674,7 +4674,7 @@ static bool tcp_ooo_try_coalesce(struct sock *sk, { bool res = tcp_try_coalesce(sk, to, from, fragstolen); - /* In case tcp_drop() is called later, update to->gso_segs */ + /* In case tcp_drop_reason() is called later, update to->gso_segs */ if (res) { u32 gso_segs = max_t(u16, 1, skb_shinfo(to)->gso_segs) + max_t(u16, 1, skb_shinfo(from)->gso_segs); @@ -4691,11 +4691,6 @@ static void tcp_drop_reason(struct sock *sk, struct sk_buff *skb, kfree_skb_reason(skb, reason); } -static void tcp_drop(struct sock *sk, struct sk_buff *skb) -{ - tcp_drop_reason(sk, skb, SKB_DROP_REASON_NOT_SPECIFIED); -} - /* This one checks to see if we can put data from the * out_of_order queue into the receive_queue. */ @@ -4723,7 +4718,7 @@ static void tcp_ofo_queue(struct sock *sk) rb_erase(&skb->rbnode, &tp->out_of_order_queue); if (unlikely(!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt))) { - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, SKB_DROP_REASON_TCP_OFO_DROP); continue; }