From patchwork Sat Oct 29 13:09:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024634 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 B6020C433FE for ; Sat, 29 Oct 2022 13:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbiJ2NLS (ORCPT ); Sat, 29 Oct 2022 09:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbiJ2NLJ (ORCPT ); Sat, 29 Oct 2022 09:11:09 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF2C68CE7; Sat, 29 Oct 2022 06:11:06 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso12202759pjg.5; Sat, 29 Oct 2022 06:11:06 -0700 (PDT) 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=/X4FUMErTbSXHi7NztKKgHeZBiz/PANDAO+0/r0jpSo=; b=FwtcjpMMhXktv2Q5T+BzKd+LQYO2JAIc77TSXa7VNqsJyPNQ9vUMasTrM2hj/vM8/3 x/1LAtjeS7rcyhPhBFP4z3fmNE6Es2lGxSAJnGZq2P+EPb3UFsTkyTHXUrZbxImwcK6A 4pBl5A8Z0+mBeN3smBxLaOC4ZrKoyEeg98pjsQz0pEl/6RrLlqcfjl2vaH3X1quacz22 uxF3EbA5GPE9L9b2MVGJrK4u41ukNP/9cH0yz/RxozSW6x2qJO9SgikuYp48sb8fxiPt 4TQwYOqi44QjtIszjY9cZdggfeM0HDNb3308fQBbnqgRb+kQuba0nbumU3ildGccdl9N +xZw== 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=/X4FUMErTbSXHi7NztKKgHeZBiz/PANDAO+0/r0jpSo=; b=jN5QkKEGl9rrAn3TPhu1qbJZX312Wo5GeGyqjns+fqkQdNv2X9juALWVsbJ0xDcUFP BJ9seZJZc3VUvspqU4HqlaSUhM6e0srj1PDNoDT7meqah0jTJQg61znYzeRNHnjs51Pe ZRdzKhF4O9wekKZOy6ZL1rt4f8Vxn1tKWRYXhmKYUYeNXbEgWnoe6Cyd+TG+6v/kJuSX NlNvbICjjEeuM7Z+h6JB23sA21BfTtNTXLfhsNv9J2ONxw2xxHy9uyuAbXJ6Dl6MWIDm OA24KGwl44J6tOOvkMw9SClJU+DAfoJ9PuGBAOp1CXSETk6oxraWeEfF0OAWDxL9DuTs 3zIA== X-Gm-Message-State: ACrzQf2sgasB/yBS7c7qikvwFy8Nw46fEyFoKCWnVREiGmcNavMhmc+V yCxe+d4aa8FdSooUXmHz2FU= X-Google-Smtp-Source: AMsMyM5xEF5e1zevoBBWI+C+FJ5nVIKRCTu27WL4xS7HzsRQkE0S7pnLzLpzxDFiUDqUfcI5pXiw6A== X-Received: by 2002:a17:903:50e:b0:182:631b:df6f with SMTP id jn14-20020a170903050e00b00182631bdf6fmr4297256plb.66.1667049066487; Sat, 29 Oct 2022 06:11:06 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:05 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 1/9] net: skb: introduce try_kfree_skb() Date: Sat, 29 Oct 2022 21:09:49 +0800 Message-Id: <20221029130957.1292060-2-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong In order to simply the code, introduce try_kfree_skb(), which allow SKB_NOT_DROPPED_YET to be passed. When the reason is SKB_NOT_DROPPED_YET, consume_skb() will be called to free the skb normally. Otherwise, kfree_skb_reason() will be called. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 59c9fd55699d..f722accc054e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1236,6 +1236,15 @@ static inline void consume_skb(struct sk_buff *skb) } #endif +static inline void try_kfree_skb(struct sk_buff *skb, + enum skb_drop_reason reason) +{ + if (reason != SKB_NOT_DROPPED_YET) + kfree_skb_reason(skb, reason); + else + consume_skb(skb); +} + void __consume_stateless_skb(struct sk_buff *skb); void __kfree_skb(struct sk_buff *skb); extern struct kmem_cache *skbuff_head_cache; From patchwork Sat Oct 29 13:09:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024635 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 2FE2CC38A02 for ; Sat, 29 Oct 2022 13:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbiJ2NLU (ORCPT ); Sat, 29 Oct 2022 09:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiJ2NLS (ORCPT ); Sat, 29 Oct 2022 09:11:18 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C51C46918F; Sat, 29 Oct 2022 06:11:11 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id h2so7076622pgp.4; Sat, 29 Oct 2022 06:11:11 -0700 (PDT) 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=DZK5NQKMxu7Q7E+ji+/bWQancP2wJOHTkQ/B4KtPPIU=; b=FJ7o32Gllk7KI9sdfQ2eYONOatmIj1khojCKJVqftg8E5DWx6Ty8537rzVV2hveavq v6SF1dVE4KOC38S/3jV7BjoKPuHcSN3NhrmjaaS0BS+ri8Y0a86jh7nxZJdQ4FMCsVBV FB6wKOOSWUaJ4rsPjRmIK0LXT3JGJ70D7vC1osZbAcVn6teIGyUZHkNXIozn5NkK6Hun Yuq0xdxiG2yLaEbkcS+HR5SArtJj1dH58kUSyvWNIY8rWHsydHO3c0tyiQ6g0Ut8711j ZDeiw+iIrJhIzXBAjAgXIt5wuzoy2ZBfiuUN9uwYLmNIjtAe9VcAp64hPHc86iikMlR2 hkIw== 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=DZK5NQKMxu7Q7E+ji+/bWQancP2wJOHTkQ/B4KtPPIU=; b=6xx+DfBzK7bBsxM6QV4hz1bmEkdrHmmDUp8VFjGXWoqgCiglnx66lHNTyTa9DnbsYV UEZKcUffy82E1q0tFsMHtuJCIEmwyIW9qbSh5TfzTHgQQAJu0YQqbvm1GssXi9pkKuVY CCUazm+yqe1cpmJ7fLG2w4SVG38/5zbauHV7dw6L+nMSqkr4NgKpzV6harqDbZ6ONMzH ESnqjS9UCbD8tB9bHCiqKrjxsf+McEHPuavUznn/UrmS45xU2SbNleJPmwbW8cj9bpZz r6KRzRwyTqldAO/5BIwfGVALErHDMIdHv7AWlNjZ0OuTfAbIZ5V6NPiqqXSHG3Yj7Yv/ GB2Q== X-Gm-Message-State: ACrzQf1KG5atgFFVu6XimgS8wU0IpKZKou11u890LVLIixbDAic5Ksck sinEgkMYE02OVHjJ8peAmoY= X-Google-Smtp-Source: AMsMyM73K1AEIikHJOwXjIXlHiTHy6r83LgmB8Ser1SvqGSb/X4kqUfikm3y15sA15v5mJxWjdkI/g== X-Received: by 2002:a62:19cd:0:b0:56b:6a55:ffba with SMTP id 196-20020a6219cd000000b0056b6a55ffbamr4259598pfz.85.1667049071233; Sat, 29 Oct 2022 06:11:11 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:10 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 2/9] net: tcp: add 'drop_reason' field to struct tcp_skb_cb Date: Sat, 29 Oct 2022 21:09:50 +0800 Message-Id: <20221029130957.1292060-3-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Because of the long call chain on processing skb in TCP protocol, it's hard to pass the drop reason to the code where the skb is freed. Therefore, we can store the drop reason to skb->cb, and pass it to kfree_skb_reason(). I'm lucky, the struct tcp_skb_cb still has 4 bytes spare space for this purpose. Signed-off-by: Menglong Dong --- include/net/tcp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/net/tcp.h b/include/net/tcp.h index 14d45661a84d..0b6e39ca83b4 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -888,6 +888,7 @@ struct tcp_skb_cb { has_rxtstamp:1, /* SKB has a RX timestamp */ unused:5; __u32 ack_seq; /* Sequence number ACK'd */ + enum skb_drop_reason drop_reason; /* Why skb is dropped */ union { struct { #define TCPCB_DELIVERED_CE_MASK ((1U<<20) - 1) @@ -912,6 +913,8 @@ struct tcp_skb_cb { }; #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) +#define TCP_SKB_DR(__skb, reason) \ + (TCP_SKB_CB(__skb)->drop_reason = SKB_DROP_REASON_##reason) extern const struct inet_connection_sock_af_ops ipv4_specific; From patchwork Sat Oct 29 13:09:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024636 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 3764CC433FE for ; Sat, 29 Oct 2022 13:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbiJ2NLf (ORCPT ); Sat, 29 Oct 2022 09:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiJ2NLT (ORCPT ); Sat, 29 Oct 2022 09:11:19 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E417169BCB; Sat, 29 Oct 2022 06:11:15 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id j7so3216988pjn.5; Sat, 29 Oct 2022 06:11:15 -0700 (PDT) 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=VA5WMUBCQaBZijA3RMGledp+Muz3yfsvc2v9AgiacX4=; b=QjKTulxLRb6ErdePNpnKf9PX+RWzvw401FPFW3Tgj/6RuI1XABe2/zwFGihp7UYK8A qFEuuVlidaP5GEOhjd/2VLagU2MjcEu6nPICwQp7lTdIspZjHTuWpXvrIpiSFBaU16Xq AmBsWOH2sMoViJO0LuN7Dn2mDISNUmQZoKfKkdp5Xzq2f1a/ORizRU4SVHnAGROTkdXs F2kXghADcFEHLAQd7loWmzAYMqOBFvJGZ631mTxqtYFUJKaLypUumx2/shnq9VjzAVSx Pbqv+wsh/r5FkT+z5WxSLq0soyEAtyrPuEDVF7zvEZ0fqi8p5vQFjMPdhwC+8+cba9aL J5kQ== 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=VA5WMUBCQaBZijA3RMGledp+Muz3yfsvc2v9AgiacX4=; b=oM6Ffb1LM6PkmsmcdRFSpT3hlGwX8w7kUkKT5g/tbeNPV6J0H/Y+2qEpEiVLYg+F8z vObYVxCzaetbcGVl9UmSt7HiVm65GMbul8t0CwSkfhtSp9WX0ciWzCUe3Qn6Yy2CvwFj 4ckJPdhW679We0PrFEEL/wA8xVYzOZlnGTUuOLbm72B/g7gD2i3PneYAoD7CnX8OOYOx y6HRnNL9dJD3er7O5MxN5wrVUfux1NH0qdmcTtpetRyXNQyJR9NcQWZO0jij03Llmehf UxUs8SvinZjzfgQpkUWYK+jIEvpyl035CfBz6Uh/mko/DgS6yvBtwAiHZ1FYNR6hARp/ bDDw== X-Gm-Message-State: ACrzQf1GDDuJnzfw3LCFTlz8SB75ppEC0ukCHgGVGoEiaXH+y2Htub7F kCBMo8mScOf5nji+ffc1PaM= X-Google-Smtp-Source: AMsMyM6EV8jn2uSgK1bSR6HgJx7ts1FVPy3sfB/SZy7ostAo0TGJha8waZYasKthJLX9G7+emrggug== X-Received: by 2002:a17:902:c745:b0:186:b287:7d02 with SMTP id q5-20020a170902c74500b00186b2877d02mr4349931plq.87.1667049074934; Sat, 29 Oct 2022 06:11:14 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:14 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 3/9] net: tcp: use the drop reasons stored in tcp_skb_cb Date: Sat, 29 Oct 2022 21:09:51 +0800 Message-Id: <20221029130957.1292060-4-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong The drop reasons for skb can be stored in tcp_skb_cb in some function when it needs to be dropped. The following functions will do it in the latter commits: tcp_rcv_state_process tcp_conn_request tcp_rcv_state_process tcp_timewait_state_process tcp_rcv_synsent_state_process Now, we initialize the drop_reason in tcp_skb_cb to SKB_DROP_REASON_NOT_SPECIFIED. try_kfree_skb() should be used if any code path makes the drop_reason to SKB_NOT_DROPPED_YET. Don't try to set it to SKB_NOT_DROPPED_YET if the skb has any posibility to be dropped later. Signed-off-by: Menglong Dong --- net/ipv4/tcp_ipv4.c | 15 +++++++++++++-- net/ipv6/tcp_ipv6.c | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 87d440f47a70..a85bc7483c5a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1693,6 +1693,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) goto discard; if (nsk != sk) { if (tcp_child_process(sk, nsk, skb)) { + reason = TCP_SKB_CB(skb)->drop_reason; rsk = nsk; goto reset; } @@ -1702,6 +1703,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) sock_rps_save_rxhash(sk, skb); if (tcp_rcv_state_process(sk, skb)) { + reason = TCP_SKB_CB(skb)->drop_reason; rsk = sk; goto reset; } @@ -1945,6 +1947,7 @@ int tcp_v4_rcv(struct sk_buff *skb) int ret; drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + TCP_SKB_DR(skb, NOT_SPECIFIED); if (skb->pkt_type != PACKET_HOST) goto discard_it; @@ -2050,6 +2053,7 @@ int tcp_v4_rcv(struct sk_buff *skb) reqsk_put(req); tcp_v4_restore_cb(skb); } else if (tcp_child_process(sk, nsk, skb)) { + drop_reason = TCP_SKB_CB(skb)->drop_reason; tcp_v4_send_reset(nsk, skb); goto discard_and_relse; } else { @@ -2136,6 +2140,11 @@ int tcp_v4_rcv(struct sk_buff *skb) kfree_skb_reason(skb, drop_reason); return 0; +free_it: + drop_reason = TCP_SKB_CB(skb)->drop_reason; + try_kfree_skb(skb, drop_reason); + return 0; + discard_and_relse: sk_drops_add(sk, skb); if (refcounted) @@ -2171,6 +2180,8 @@ int tcp_v4_rcv(struct sk_buff *skb) refcounted = false; goto process; } + /* TCP_FLAGS or NO_SOCKET? */ + TCP_SKB_DR(skb, TCP_FLAGS); } /* to ACK */ fallthrough; @@ -2180,10 +2191,10 @@ int tcp_v4_rcv(struct sk_buff *skb) case TCP_TW_RST: tcp_v4_send_reset(sk, skb); inet_twsk_deschedule_put(inet_twsk(sk)); - goto discard_it; + goto free_it; case TCP_TW_SUCCESS:; } - goto discard_it; + goto free_it; } static struct timewait_sock_ops tcp_timewait_sock_ops = { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index f676be14e6b6..2c2048832714 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1515,8 +1515,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) goto discard; if (nsk != sk) { - if (tcp_child_process(sk, nsk, skb)) + if (tcp_child_process(sk, nsk, skb)) { + reason = TCP_SKB_CB(skb)->drop_reason; goto reset; + } if (opt_skb) __kfree_skb(opt_skb); return 0; @@ -1524,8 +1526,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) } else sock_rps_save_rxhash(sk, skb); - if (tcp_rcv_state_process(sk, skb)) + if (tcp_rcv_state_process(sk, skb)) { + reason = TCP_SKB_CB(skb)->drop_reason; goto reset; + } if (opt_skb) goto ipv6_pktoptions; return 0; @@ -1615,6 +1619,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) struct net *net = dev_net(skb->dev); drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + TCP_SKB_DR(skb, NOT_SPECIFIED); if (skb->pkt_type != PACKET_HOST) goto discard_it; @@ -1711,6 +1716,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) reqsk_put(req); tcp_v6_restore_cb(skb); } else if (tcp_child_process(sk, nsk, skb)) { + drop_reason = TCP_SKB_CB(skb)->drop_reason; tcp_v6_send_reset(nsk, skb); goto discard_and_relse; } else { @@ -1792,6 +1798,11 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) kfree_skb_reason(skb, drop_reason); return 0; +free_it: + drop_reason = TCP_SKB_CB(skb)->drop_reason; + try_kfree_skb(skb, drop_reason); + return 0; + discard_and_relse: sk_drops_add(sk, skb); if (refcounted) @@ -1832,6 +1843,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) refcounted = false; goto process; } + TCP_SKB_DR(skb, TCP_FLAGS); } /* to ACK */ fallthrough; @@ -1841,11 +1853,11 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) case TCP_TW_RST: tcp_v6_send_reset(sk, skb); inet_twsk_deschedule_put(inet_twsk(sk)); - goto discard_it; + goto free_it; case TCP_TW_SUCCESS: ; } - goto discard_it; + goto free_it; } void tcp_v6_early_demux(struct sk_buff *skb) From patchwork Sat Oct 29 13:09:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024637 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 67690C433FE for ; Sat, 29 Oct 2022 13:11:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbiJ2NLi (ORCPT ); Sat, 29 Oct 2022 09:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbiJ2NLV (ORCPT ); Sat, 29 Oct 2022 09:11:21 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A4EA691A6; Sat, 29 Oct 2022 06:11:19 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id q1so7042962pgl.11; Sat, 29 Oct 2022 06:11:19 -0700 (PDT) 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=QT7TXRUVve09bvGpQVooCnQqDIlFLDJNPk73T/NQyZ4=; b=EILN7IQF8JSD9YT6/do0bu89xzeyB6mPrqpeWmgf5nalrduu8cHcaQRbRv1V7daZLE itAt/7YgcG19WXbhHwzw6UNg/aqKI6zANd34a4BPYnyt94wK4OalEpkbu5g3AKXFSHcK SsYowF0i+LUsHEK4J+hYxVPghXzGcadS98G+2ZoYHK/WWIOtTzWQnwqUfABgny3rrcgA NJwY/Q9gVW91jwUkng0O5zeF9EEtueUbSvK2OVI0RtBpv7IJ4PDQwZIQ0DTLqV6RbGPq BpY1iKI3DebgFY7zIlkVWXp7MAfxzl0PH2XmiHoChg3PNINpUPENLHKvlEqFeL9KtA7a Tu+A== 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=QT7TXRUVve09bvGpQVooCnQqDIlFLDJNPk73T/NQyZ4=; b=JduD5/QUJ42mbBeol8QQBQi87E1IyzwAVzq00hYupPgd1hxl3/c0ymMp6XSeQME6lP TdNWPMVTZb6OuysBXAyRdtZkdkH4w4tkU6hNs9/feuk73EW7r++W8G66SufIp41qb/Sh FNsObUhJ6QDgsvfABymzItMHpwLaSzu6/hUZK6K1RYqso8TqfXrDSmll33a4BeCtlZsG iDHzbWT+qIav6trXN580AT9SnrBWbn8IJRUX4dzuQve010QduEBsuE4MGNjm+uJ7L+IR 4wZIvD5v90V+r9sVmhg7+gcXSFREWICWp/3YTehNlRF884SSxlyfNBa9JgD2UrrDdASQ T15g== X-Gm-Message-State: ACrzQf2F7Kxv547C9NwP2o5Yalew4AX/BvBtkbaT1pfQjghGR2ev/te8 2b2JtSVwB5jYbEZdkHXT7Lg= X-Google-Smtp-Source: AMsMyM4/KOUewUvEFkgE0q22q1nulfsnLiVxM0ZidWFBY6mUxV8vTGFXMIiXlbOjSTXJvELNZECpAw== X-Received: by 2002:a65:5583:0:b0:461:25fe:e982 with SMTP id j3-20020a655583000000b0046125fee982mr4005524pgs.4.1667049078560; Sat, 29 Oct 2022 06:11:18 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:18 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 4/9] net: tcp: store drop reasons in tcp_rcv_synsent_state_process() Date: Sat, 29 Oct 2022 21:09:52 +0800 Message-Id: <20221029130957.1292060-5-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong The skb drop reasons for the 'reset' code path in tcp_rcv_synsent_state_process() is not handled yet. Now, we can store the drop reason to tcp_skb_cb for such case. The new reason 'TCP_PAWSACTIVEREJECTED' is added, which is corresponding to LINUX_MIB_PAWSACTIVEREJECTED. Signed-off-by: Menglong Dong --- include/net/dropreason.h | 7 +++++++ net/ipv4/tcp_input.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index c1cbcdbaf149..0f0edcd5f95f 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -68,6 +68,7 @@ FN(IP_INADDRERRORS) \ FN(IP_INNOROUTES) \ FN(PKT_TOO_BIG) \ + FN(TCP_PAWSACTIVEREJECTED) \ FNe(MAX) /** @@ -298,6 +299,12 @@ enum skb_drop_reason { * MTU) */ SKB_DROP_REASON_PKT_TOO_BIG, + /** + * @SKB_DROP_REASON_TCP_PAWSACTIVEREJECTED: PAWS check failed for + * active TCP connection, corresponding to + * LINUX_MIB_PAWSACTIVEREJECTED + */ + SKB_DROP_REASON_TCP_PAWSACTIVEREJECTED, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0640453fce54..c0e5c4a29a4e 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6195,6 +6195,10 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, TCP_TIMEOUT_MIN, TCP_RTO_MAX); + if (after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) + TCP_SKB_DR(skb, TCP_ACK_UNSENT_DATA); + else + TCP_SKB_DR(skb, TCP_TOO_OLD_ACK); goto reset_and_undo; } @@ -6203,6 +6207,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, tcp_time_stamp(tp))) { NET_INC_STATS(sock_net(sk), LINUX_MIB_PAWSACTIVEREJECTED); + TCP_SKB_DR(skb, TCP_PAWSACTIVEREJECTED); goto reset_and_undo; } From patchwork Sat Oct 29 13:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024638 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 0B302C38A02 for ; Sat, 29 Oct 2022 13:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiJ2NLm (ORCPT ); Sat, 29 Oct 2022 09:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbiJ2NLf (ORCPT ); Sat, 29 Oct 2022 09:11:35 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C038E69ED9; Sat, 29 Oct 2022 06:11:22 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id y4so7127583plb.2; Sat, 29 Oct 2022 06:11:22 -0700 (PDT) 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=EJ08uRmM1fk/kBxamD2GYhMoonJypcExaYdhAS5+vYY=; b=gQKasM9QfgTopmhCKxXkRzTulCfogWPr90HNVnkgnOIkOhfqdXLH/Fc3jYFRQ//Ah1 jEcGUQGAxoNaJk9Kw5jSJqdsKSbV4nu1R+A4SBTM3lRUDx5VYrPE4T0UlQ8bPT/krtCN FPq7Wt0xrHFx2NpQcAIHdDgs/hTayfP11UBUZnEqz1KnMhZsGO4G1LNpgOB613YGdsW4 1fcTyLekvGLTKNz5Ki3x65HyTyu5b8BkkFrLyxiTXsf9nFTwCtJuHjKKtoUUQpWZWwr1 /rLEw25C6TE5/Y5MecROd6FvvF7pmBc/uFea+/wMI5E8ZC5uXpoZu7FAHXG7Sb0Hbtts R2Kg== 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=EJ08uRmM1fk/kBxamD2GYhMoonJypcExaYdhAS5+vYY=; b=C9IkDKhv6sorzzCn+PFzwPkpBu9/hw+6mDqUmnPI1ZmqTrOhL7i9Wy31q3e2ep3EoJ WatV3O0RYQXSaur1QFpH/avqkAcGdFa2XDBo0b+9evqUdE4YlzzL4DlFcwlJDBAt8BSJ 4HNp30LPNIqggHshpG4z+jYhF6CF66G48GTF4txhlKFjxkGAw8FwOr+npzbLEnzo3etq iKDblmPzuHN5aukgidcgQCXgiil18SVy6D7paDGm7Seag0mfnAJoBtw47ZKSoH6Vj1bk 9VTrmcZAWD91n+2ak3phURwWr2zBgiIIf1iWlwPAYJ3Eil1L9QXvA9sHvEmgjATcH0hJ RiMw== X-Gm-Message-State: ACrzQf3sb1+lkLYITJNI4Te7emq9KesugY7QVzoHIzHODwqk3YgulyhY OeMz0P5R21ttd+ge4sEDZsoeE01OsdM= X-Google-Smtp-Source: AMsMyM5R6pNxRLjYxw2yNEDVPMkwLmqPgIDtbt6yMk7E4UHdwd9eGL3yF3Fy9DvKzcEyG209tfJoeg== X-Received: by 2002:a17:902:b598:b0:184:e49d:3042 with SMTP id a24-20020a170902b59800b00184e49d3042mr4361859pls.16.1667049082221; Sat, 29 Oct 2022 06:11:22 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:21 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 5/9] net: tcp: store drop reasons in tcp_timewait_state_process() Date: Sat, 29 Oct 2022 21:09:53 +0800 Message-Id: <20221029130957.1292060-6-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Store the drop reason to the tcp_skb_cb in tcp_timewait_state_process() when the skb is going to be dropped. The new drop reason 'TIMEWAIT' is added. Signed-off-by: Menglong Dong --- include/net/dropreason.h | 7 +++++++ net/ipv4/tcp_minisocks.c | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 0f0edcd5f95f..cbfd88493ef2 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -69,6 +69,7 @@ FN(IP_INNOROUTES) \ FN(PKT_TOO_BIG) \ FN(TCP_PAWSACTIVEREJECTED) \ + FN(TIMEWAIT) \ FNe(MAX) /** @@ -305,6 +306,12 @@ enum skb_drop_reason { * LINUX_MIB_PAWSACTIVEREJECTED */ SKB_DROP_REASON_TCP_PAWSACTIVEREJECTED, + /** + * @SKB_DROP_REASON_TIMEWAIT: socket is in time-wait state and all + * packet that received will be treated as 'drop', except a good + * 'SYN' packet + */ + SKB_DROP_REASON_TIMEWAIT, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index c375f603a16c..e1963394dc4a 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -113,11 +113,16 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDFINWAIT2); - if (th->rst) + if (th->rst) { + TCP_SKB_DR(skb, TCP_RESET); goto kill; + } - if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt)) + if (th->syn && !before(TCP_SKB_CB(skb)->seq, + tcptw->tw_rcv_nxt)) { + TCP_SKB_DR(skb, TCP_FLAGS); return TCP_TW_RST; + } /* Dup ACK? */ if (!th->ack || @@ -143,6 +148,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, } inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + + /* skb should be free normally on this case. */ + TCP_SKB_CB(skb)->drop_reason = SKB_NOT_DROPPED_YET; return TCP_TW_ACK; } @@ -174,6 +182,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, * protocol bug yet. */ if (!READ_ONCE(twsk_net(tw)->ipv4.sysctl_tcp_rfc1337)) { + TCP_SKB_DR(skb, TCP_RESET); kill: inet_twsk_deschedule_put(tw); return TCP_TW_SUCCESS; @@ -232,9 +241,11 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, if (paws_reject || th->ack) inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + TCP_SKB_DR(skb, TIMEWAIT); return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT); } + TCP_SKB_DR(skb, TCP_RESET); inet_twsk_put(tw); return TCP_TW_SUCCESS; } From patchwork Sat Oct 29 13:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024639 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 6367EC433FE for ; Sat, 29 Oct 2022 13:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiJ2NMI (ORCPT ); Sat, 29 Oct 2022 09:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiJ2NLg (ORCPT ); Sat, 29 Oct 2022 09:11:36 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B926969F55; Sat, 29 Oct 2022 06:11:26 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d24so7119258pls.4; Sat, 29 Oct 2022 06:11:26 -0700 (PDT) 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=e72HAxh6P1H/A+cQtAP2/BT2cWTj2acR1HBaWNLsTXA=; b=VZh6IoGsSJ9GAYWi9Zk0dr97OxI3Vz3zTfp1PMZvYKSN/yx/b5KS1OVwQt1XtVBqiR O5lt41RqRL89Q+k4OyGmGtIuaoHh7C5MqXVNIqvHorQXpTTMUWXXpG6Qnb24pKS1y1YU 2lg18XhZnWrf2tLMQpPuhrYEsF2S6ND6Eyq26EROoGxA3fxi/Ei9YaDqvgz+60An5SRt ltKetpBK2Wu0FUdGgKxhNrSEhL+Z55W9OYnORaOIrZ/JTo1rYX5BhikzFGOvEPHKncds n178NpTfNG+QMppI7dX9Vr4DyWyr256PyJy1qETGe7Na6eJ5pVvx9AI8M44Z91vNz/D6 Gv/A== 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=e72HAxh6P1H/A+cQtAP2/BT2cWTj2acR1HBaWNLsTXA=; b=QG/5UuezcVQy9cJDxh1/b3EgqXp5Kf8MVFf90QZAQNcKyK/+igNj/Eqk897xtXY1oG SQlOF+mAqf6DAdFMEwOta+W979VVR6d1nu14JuOCrA3hzbl/z6mGjw2ZzF6KY4mAyXpT 0fsWlTNHdIx+tya8ZUwCxj0PNGtrsnonsQ5aNQ6aid95FSI+rt2PncAArxChfwN0/aMG 4NE6T9mgojgXVkeECRaQCia5cOnsbEko5tv/4p5zbHXg1dcBL77PZw9SmryfLoXvT9lp F3unrT32+XvzB21qAC0gm+fXKi5SEZoUNoHIMDU2YcR91Snyw6ft/Riy2knfl5nwbjpm X1TQ== X-Gm-Message-State: ACrzQf2yq5yu5IdZIUneUcQP30g2T+2S1lRHE4lMjGNCA0f38LYS3WDS XkPWqoKpq6ByeM78AQjNBYo= X-Google-Smtp-Source: AMsMyM5IfK8MomSFw/Cm2DxK/QnTTJcaBS+TxB/kKEmJilFvMU0LIdbOgUbS5Q551CHTE52LvEE7qw== X-Received: by 2002:a17:902:f789:b0:17f:8cb6:7da3 with SMTP id q9-20020a170902f78900b0017f8cb67da3mr4225755pln.167.1667049086249; Sat, 29 Oct 2022 06:11:26 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:25 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 6/9] net: tcp: store drop reasons in tcp_conn_request() Date: Sat, 29 Oct 2022 21:09:54 +0800 Message-Id: <20221029130957.1292060-7-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Store the skb drop reasons to tcp_skb_cb for tcp_conn_request(). When the skb should be freed normally, 'TCP_SKB_CB(skb)->drop_reason' will be set to SKB_NOT_DROPPED_YET, which means consume_skb() will be called for the skb. Now, we can replace the consume_skb() with try_kfree_skb() in tcp_rcv_state_process() if the skb needs to be dropped. The new drop reasons 'LISTENOVERFLOWS' and 'TCP_REQQFULLDROP' are added, which are used for 'accept queue' and 'request queue' full. Signed-off-by: Menglong Dong --- --- include/net/dropreason.h | 12 ++++++++++++ net/ipv4/tcp_input.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index cbfd88493ef2..633a05c95026 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -70,6 +70,8 @@ FN(PKT_TOO_BIG) \ FN(TCP_PAWSACTIVEREJECTED) \ FN(TIMEWAIT) \ + FN(LISTENOVERFLOWS) \ + FN(TCP_REQQFULLDROP) \ FNe(MAX) /** @@ -312,6 +314,16 @@ enum skb_drop_reason { * 'SYN' packet */ SKB_DROP_REASON_TIMEWAIT, + /** + * @SKB_DROP_REASON_LISTENOVERFLOWS: accept queue of the listen + * socket is full, corresponding to LINUX_MIB_LISTENOVERFLOWS + */ + SKB_DROP_REASON_LISTENOVERFLOWS, + /** + * @SKB_DROP_REASON_TCP_REQQFULLDROP: request queue of the listen + * socket is full, corresponding to LINUX_MIB_TCPREQQFULLDROP + */ + SKB_DROP_REASON_TCP_REQQFULLDROP, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index c0e5c4a29a4e..ad088e228b1e 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6482,7 +6482,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (!acceptable) return 1; - consume_skb(skb); + + reason = TCP_SKB_CB(skb)->drop_reason; + try_kfree_skb(skb, reason); return 0; } SKB_DR_SET(reason, TCP_FLAGS); @@ -6928,12 +6930,15 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, */ if ((syncookies == 2 || inet_csk_reqsk_queue_is_full(sk)) && !isn) { want_cookie = tcp_syn_flood_action(sk, rsk_ops->slab_name); - if (!want_cookie) + if (!want_cookie) { + TCP_SKB_DR(skb, TCP_REQQFULLDROP); goto drop; + } } if (sk_acceptq_is_full(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); + TCP_SKB_DR(skb, LISTENOVERFLOWS); goto drop; } @@ -6991,6 +6996,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, */ pr_drop_req(req, ntohs(tcp_hdr(skb)->source), rsk_ops->family); + TCP_SKB_DR(skb, TCP_REQQFULLDROP); goto drop_and_release; } @@ -7005,6 +7011,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, inet_rsk(req)->ecn_ok = 0; } + TCP_SKB_CB(skb)->drop_reason = SKB_NOT_DROPPED_YET; tcp_rsk(req)->snt_isn = isn; tcp_rsk(req)->txhash = net_tx_rndhash(); tcp_rsk(req)->syn_tos = TCP_SKB_CB(skb)->ip_dsfield; From patchwork Sat Oct 29 13:09:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024640 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 137E7C38A02 for ; Sat, 29 Oct 2022 13:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiJ2NMK (ORCPT ); Sat, 29 Oct 2022 09:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbiJ2NLo (ORCPT ); Sat, 29 Oct 2022 09:11:44 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A4816A486; Sat, 29 Oct 2022 06:11:30 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id f193so7107760pgc.0; Sat, 29 Oct 2022 06:11:30 -0700 (PDT) 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=vssy2QIzKmHydtkjFhF+7Vo85h49gdfydYy5+cmw3Ec=; b=VecOJpnfnlcWgbsOAt8v7vlGdj9AvfBevtzjZeCqGGjrUrzbs0IEPmeJcf94/m72S1 hiWqVPJQFsFjNAMuIKjoXmhq9OFFVhPkdS/DcnzNPIzxdclHeET0prVMIaNTT4cdnCVN S8ciX2rdIZsRkCgsb9heNWDw0jQXc31HV15n/3Ab75dinK7L5sjpeTA1slH3TyE5UoAU TWLyj2gNWNr1/iH/w9qyEf3PJF75Jba/53NLjI+orO093uZtVlPI5Odb0LthCBWZlKAP XLcFdqS37qUqI57NVYABzR0pK1BQfOSvCjKbFseNzm0oWOHgwCTDUIRtpmSH5mqQKpOF AJMg== 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=vssy2QIzKmHydtkjFhF+7Vo85h49gdfydYy5+cmw3Ec=; b=3KKSx75o6TT/WXwthy+8sOViF4Kh4qRQteUYt+RnqTZxFb0Vdc41gP2mQxmEnbnd6z 6cI0qLTkADKtcRZ9VQ2Wl7f4uj1NQ5e1+QOuoTyISccMv2ETLBqR8vqER5USUvI7p1iH kqlEqCHaC8Hgb2/AhPOOOa8YGlbhJztOkgC+JyD3zwZlfEwNJIF3ivkGIu4bSPcF2CEW SIO/MNwyNgFrPMzV5IaBxBpDlyraRPIIDQtwo3oEebbUAOy6jBCQ3/chMuHEVwgnbQ1i Rs1BFgqRFqIkHOCINCcP97+Wnk58MAqzQbqx0wphepXfMfsAVvR0J7F50GUc2EGkQz4J sVxg== X-Gm-Message-State: ACrzQf0ASv8TsLUQ5hKQ7mDIWnHI8/ynLU/YrzIswCto7PKwyFPI73hn /N79GyP7PaoLLCz9v20XXJw= X-Google-Smtp-Source: AMsMyM5c3oETS+dPiczxlxdCcqwqIW8zxQfJnhFRazM6YX5nC1ITTX09MohQzVgA0rT4DTU91M0hyg== X-Received: by 2002:a05:6a00:1912:b0:564:f6be:11fd with SMTP id y18-20020a056a00191200b00564f6be11fdmr4492077pfi.32.1667049089869; Sat, 29 Oct 2022 06:11:29 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:29 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 7/9] net: tcp: store drop reasons in tcp_rcv_state_process() Date: Sat, 29 Oct 2022 21:09:55 +0800 Message-Id: <20221029130957.1292060-8-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Store the drop reasons for skb to the tcp_skb_cb in tcp_rcv_state_process() when it returns non-zero, which means that the skb need to be dropped. The new drop reasons 'TCP_ABORTONDATA' and 'TCP_ABORTONLINGER' are added. Signed-off-by: Menglong Dong --- include/net/dropreason.h | 12 ++++++++++++ net/ipv4/tcp_input.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 633a05c95026..364811bce63f 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -72,6 +72,8 @@ FN(TIMEWAIT) \ FN(LISTENOVERFLOWS) \ FN(TCP_REQQFULLDROP) \ + FN(TCP_ABORTONDATA) \ + FN(TCP_ABORTONLINGER) \ FNe(MAX) /** @@ -324,6 +326,16 @@ enum skb_drop_reason { * socket is full, corresponding to LINUX_MIB_TCPREQQFULLDROP */ SKB_DROP_REASON_TCP_REQQFULLDROP, + /** + * @SKB_DROP_REASON_TCP_ABORTONDATA: corresponding to + * LINUX_MIB_TCPABORTONDATA + */ + SKB_DROP_REASON_TCP_ABORTONDATA, + /** + * @SKB_DROP_REASON_TCP_ABORTONLINGER: corresponding to + * LINUX_MIB_TCPABORTONLINGER + */ + SKB_DROP_REASON_TCP_ABORTONLINGER, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ad088e228b1e..e08842f999f8 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6459,8 +6459,10 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) goto discard; case TCP_LISTEN: - if (th->ack) + if (th->ack) { + TCP_SKB_DR(skb, TCP_FLAGS); return 1; + } if (th->rst) { SKB_DR_SET(reason, TCP_RESET); @@ -6533,8 +6535,10 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) FLAG_NO_CHALLENGE_ACK) > 0; if (!acceptable) { - if (sk->sk_state == TCP_SYN_RECV) + if (sk->sk_state == TCP_SYN_RECV) { + TCP_SKB_DR(skb, TCP_FLAGS); return 1; /* send one RST */ + } tcp_send_challenge_ack(sk); SKB_DR_SET(reason, TCP_OLD_ACK); goto discard; @@ -6605,6 +6609,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (tp->linger2 < 0) { tcp_done(sk); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); + TCP_SKB_DR(skb, TCP_ABORTONLINGER); return 1; } if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && @@ -6614,6 +6619,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) tcp_fastopen_active_disable(sk); tcp_done(sk); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); + TCP_SKB_DR(skb, TCP_ABORTONDATA); return 1; } @@ -6678,6 +6684,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); + TCP_SKB_DR(skb, TCP_ABORTONDATA); tcp_reset(sk, skb); return 1; } From patchwork Sat Oct 29 13:09:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024641 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 A84B5C38A02 for ; Sat, 29 Oct 2022 13:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbiJ2NMc (ORCPT ); Sat, 29 Oct 2022 09:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbiJ2NMF (ORCPT ); Sat, 29 Oct 2022 09:12:05 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FA14696F9; Sat, 29 Oct 2022 06:11:34 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id r18so7043032pgr.12; Sat, 29 Oct 2022 06:11:34 -0700 (PDT) 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=GL2gYlQkLzPoDIZWhMbnN0oVuFwh4pQ+nvuIXIbJr+k=; b=PeaKicSueNNwluthUUpLsFaq4Oj21LPmkC/i5Gdlq5zEE9BT0YDTR8Kqi/fnm1F5sV +8uDPDHqoBVfdOT4zMA/pSVNMf9OYraBUZ+xXf5gGgJr8prnuTMs30zyNATc7ziJhAE5 ujEcqWO0hCaFV0bDBxbFoxzlKyZuFM9je8Btqzt/4ls/bvwU/h8IipaXmX3TRj2yWtZr FWpacKnidQtvv7lLjc49Ahfj8J5KFIyZlwDSVHnXacJbmN8wIf9gAQUN5y6GYBVFOnKd G5dOrhmqUZRZT5/mNW2W5//Mph8u5/foYXEj1dguhFJHxNt7JTyUBMC31MAuaYMrvbmK u1Cg== 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=GL2gYlQkLzPoDIZWhMbnN0oVuFwh4pQ+nvuIXIbJr+k=; b=2IOIhz9q8VmjEG0Xy253nQvueqI0gKcVZxpVAe0KxbmCmNWVKjy7QjKTWf+aK9Z2xq T7ma7N1kwJDDNNY/Ya9wWD8CG+VXiADKOZdSQPoU23I0ElyKnLUof8pTRL+vgo972t2P QIvU5wcO3mn7J5AMOYPELCXFzgcZjARYFx6ykfoc5TzSR3XdnE4+rwkwKXPsgg7iKxdw UfO00IbH0hE/JEcf0AVvczHIohsuZjXA0AiA62CQFlXRHkXvG/KNbjjEsPMveCDrVzLs s1oaXHMd08YolxDQDdavUXAjGuf8SnGTZqOZVl5NQ07aui+cyq2L5tUitpK/87QDOIzT zCNw== X-Gm-Message-State: ACrzQf0A4kXmJYowwMVuJX4ZMbl7rCEAMtBb68ZGaGJVxuKG3cS4kovy Qk3IOw19mL8trCGHK+LLSR8= X-Google-Smtp-Source: AMsMyM639daYTjQLLAVsASBpP5PG4tJO8nJOAJTvEFIdJkFHmhZrejqjpXA68+/YdvBAvqcDSqdWMQ== X-Received: by 2002:a65:5184:0:b0:439:14cb:fbe4 with SMTP id h4-20020a655184000000b0043914cbfbe4mr3956186pgq.166.1667049094003; Sat, 29 Oct 2022 06:11:34 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:33 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 8/9] net: tcp: store drop reasons in route_req Date: Sat, 29 Oct 2022 21:09:56 +0800 Message-Id: <20221029130957.1292060-9-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Add skb drop reasons to tcp_v4_route_req() and tcp_v6_route_req(). And the new reason SKB_DROP_REASON_LSM is added, which is used when skb is dropped by LSM. Signed-off-by: Menglong Dong --- include/net/dropreason.h | 5 +++++ net/ipv4/tcp_ipv4.c | 11 +++++++++-- net/ipv6/tcp_ipv6.c | 11 +++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 364811bce63f..a5de00d02213 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -74,6 +74,7 @@ FN(TCP_REQQFULLDROP) \ FN(TCP_ABORTONDATA) \ FN(TCP_ABORTONLINGER) \ + FN(LSM) \ FNe(MAX) /** @@ -336,6 +337,10 @@ enum skb_drop_reason { * LINUX_MIB_TCPABORTONLINGER */ SKB_DROP_REASON_TCP_ABORTONLINGER, + /** + * @SKB_DROP_REASON_LSM: dropped by LSM + */ + SKB_DROP_REASON_LSM, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a85bc7483c5a..8fdea8e6207f 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1447,12 +1447,19 @@ static struct dst_entry *tcp_v4_route_req(const struct sock *sk, struct flowi *fl, struct request_sock *req) { + struct dst_entry *dst; + tcp_v4_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + TCP_SKB_DR(skb, LSM); return NULL; + } - return inet_csk_route_req(sk, &fl->u.ip4, req); + dst = inet_csk_route_req(sk, &fl->u.ip4, req); + if (!dst) + TCP_SKB_DR(skb, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp_request_sock_ops __read_mostly = { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 2c2048832714..44c4aa2789d6 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -823,12 +823,19 @@ static struct dst_entry *tcp_v6_route_req(const struct sock *sk, struct flowi *fl, struct request_sock *req) { + struct dst_entry *dst; + tcp_v6_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + TCP_SKB_DR(skb, LSM); return NULL; + } - return inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + dst = inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + if (!dst) + TCP_SKB_DR(skb, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp6_request_sock_ops __read_mostly = { From patchwork Sat Oct 29 13:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13024642 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 94874C38A02 for ; Sat, 29 Oct 2022 13:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbiJ2NMm (ORCPT ); Sat, 29 Oct 2022 09:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbiJ2NMH (ORCPT ); Sat, 29 Oct 2022 09:12:07 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FAD6A528; Sat, 29 Oct 2022 06:11:39 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id s196so7078163pgs.3; Sat, 29 Oct 2022 06:11:39 -0700 (PDT) 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=1JJILX3ZbsEa361mIUD+wzD0iIrs7toiHw6XLt3BD9E=; b=qvYUTBXcXhBSZYb5Vsmt4UtsvcK4CfKtaeyCVNyMOxHcFos8BM09MT91GxuuJ/eZJ+ xGP4CXooZLTZNvl7vT+3D6F92zVURH3EQ3qqAtqsa4tjAkcn6pwGaRZgLEpEcFD3m0Fx 6qrsge+dqIDX35qqiQem0Nnch2Hm1DL51MwPysC533Nmd0MNaIo14e4NoSoXXL3LayrZ UrGTecy6IQyDLpV2gWe7SV91nMdF/Jk6we6PM7Vh7sA3oJN+MFtG14zdrLKlfO3RWa6b kQ+8cKQJ7P35HicspVCL7IRE3rUX72J41W7I/YI4K8584JAQEBYtJAlX1Mh45k/tVwoD wbpA== 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=1JJILX3ZbsEa361mIUD+wzD0iIrs7toiHw6XLt3BD9E=; b=xtFBTaeQYrZpJzCDbD04ohVvJLo9NXXORmiuV7SZaNEswxrLiAB22YOMmFKnz5bAS1 ZGZyf6DGdWY/cg1NqNK1pUuLG+IAkt4FagXZY293+caYHgJffqYzqCLwdR36BVpYhhZ9 cdNunjTcKsI9SvB35Yv4wpkvXex6E2V9hC8e1djeuLn8n6dh6Sm7z0pJ51+qH8x11Q/g tEKy95bzon/pQYG7+bRCfN3PDDmahGE4oqS1dUDRZ9Lp75qC6dGzfxhwbf6Ft85KUyYz NR3Vn0iK3sSKFSJDmPCAAq9JQERUVYSH6grIy5t0B+/wzAKyB/OJ/eGUZHcUidYlZkLS cRfg== X-Gm-Message-State: ACrzQf27VXBR8Rde9E0A6tQEAvR4etTgPAIqIm9JlLP7Wf1wB/R8a/YO 9XvvMCTfHmH1u4UultTXeC0= X-Google-Smtp-Source: AMsMyM76qICTm97A178uDAF6502Rdci2c5qRflRjgvcIKTN3xfTp98+5kiQl9jBPYbnYHziukUCAPw== X-Received: by 2002:a05:6a00:1145:b0:52b:78c:fa26 with SMTP id b5-20020a056a00114500b0052b078cfa26mr4243643pfm.27.1667049098803; Sat, 29 Oct 2022 06:11:38 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.21]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b001811a197797sm1244069plp.194.2022.10.29.06.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 06:11:37 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, asml.silence@gmail.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 9/9] net: tcp: use LINUX_MIB_TCPABORTONLINGER in tcp_rcv_state_process() Date: Sat, 29 Oct 2022 21:09:57 +0800 Message-Id: <20221029130957.1292060-10-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221029130957.1292060-1-imagedong@tencent.com> References: <20221029130957.1292060-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong The statistics for 'tp->linger2 < 0' in tcp_rcv_state_process() seems more accurate to be LINUX_MIB_TCPABORTONLINGER. Signed-off-by: Menglong Dong --- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e08842f999f8..e8623cea1633 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6608,7 +6608,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (tp->linger2 < 0) { tcp_done(sk); - NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); + NET_INC_STATS(sock_net(sk), SKB_DROP_REASON_TCP_ABORTONLINGER); TCP_SKB_DR(skb, TCP_ABORTONLINGER); return 1; }