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: 12700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1341837wru; Sat, 29 Oct 2022 06:12:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qaIF63lrm7/cCDTsT40JJm5taIEZvsjJcGuKMJpJaqAgTwtld4PKItZDCqMePeSur5nLF X-Received: by 2002:a17:902:8bc9:b0:186:e151:6b29 with SMTP id r9-20020a1709028bc900b00186e1516b29mr4428667plo.8.1667049162317; Sat, 29 Oct 2022 06:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049162; cv=none; d=google.com; s=arc-20160816; b=WrfXAypboP5RHrI1aakXzN/kGOBEfum/2VKndNdUaDFlRp6tu82nh7lepEaY8x9FeD wqfmZJNrFMcjIPGlBDET3D9baFP40fCahAMftkP3WWA0NHg5ZZmEQ4haskeqQVJYwPWC PnkSTve5vrsmpP8P6t0GAYu/D+IW7HJ27wyBvZCCBbIgmOFS3FKyMI9MIcXietjIxIx8 dawRyRDMn3liOPDxMrnYHcinlxHL4rOTRWbh0vVjUEQk3BWft5fH6HvRF76YjUtebE7z R+1X3nFpgXZTkyEhY4t+TfIuD/xIOHfTfhaZuKdS07Tp7EkI+xqw3uXK+0ZDTtP3i6Tp CeJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/X4FUMErTbSXHi7NztKKgHeZBiz/PANDAO+0/r0jpSo=; b=ygGjsz9Rlnui6zi01jmeZELgF2poubHf3HfJQ6SbTRCe1hDL6B07kbUqn4CUtJmm0z nWZHS7cr8GC8tetw/7JeXCK23MsvbexyE2AoM6PwWtoc3B0IB61Vkiv3lPbbWi7suCcw 77crSDTMi5XQdUZCOPhqbdqVZe04/M5WQDMGaibUyul8LDVcY31PEFI87YwnCxbzio/r CbGX5m5Ud+4ejnIyYa9epIRUPW0Iwk191+oNbduzMiXhEPZ+ALwgBXR0HbZzByqq5ziI xdCGy8a/PoCx4/TJcoCQRxXDq8aWwuxTgWdSq2t3qqjlTbF066FincKlkkKM/GUxnz9p OSFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FwtcjpMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y38-20020a056a00182600b0053652e1c0b6si2178936pfa.12.2022.10.29.06.12.29; Sat, 29 Oct 2022 06:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FwtcjpMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiJ2NLT (ORCPT + 99 others); Sat, 29 Oct 2022 09:11:19 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027742732250902?= X-GMAIL-MSGID: =?utf-8?q?1748027742732250902?= 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: 12699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1341728wru; Sat, 29 Oct 2022 06:12:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7E+OtxazOTQhWLKx6eothyVEvVE14numEiHboD5VcI/bzJdLGfg8+jAADQCkCNsZTHpl85 X-Received: by 2002:a17:90b:4d84:b0:212:c78f:8d6e with SMTP id oj4-20020a17090b4d8400b00212c78f8d6emr4559552pjb.201.1667049147315; Sat, 29 Oct 2022 06:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049147; cv=none; d=google.com; s=arc-20160816; b=OJaiLy9F4luNnlD25tS7Csb1IN9MxJvmUahkec4lkBqHaIS+dQ2agDYUvFRjFC/lr4 zVsc8nGQJUwyHT1qS2zZO86ZeJefjPDUR2c28rHFwyUow9TYaUuwUSwJ/Lc270befpUR S1S74D86i4rCS/k4weEI1VDCNdjSl5Qp6HoMQ6BlQI9sZhlV+v1XLrtX89si+1NAh0js eai/F/2aGExwydD1VA7WZod229XYqhQvKLQSPjjhtOW3BmSHgroqhJ5DsjXkTMn0ESnb YU5J1H85GeRy61saz59bcZDWuDxeZ11xd/at1/9lEBRoEQfOn9nDsPhc33ONU5sZsXlP +H5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DZK5NQKMxu7Q7E+ji+/bWQancP2wJOHTkQ/B4KtPPIU=; b=VwBG9+SPtNvZwJyOzhemUod2Dg+XjZHyONBpy38YeykSoryWF0Ni3qQqUbbrMuXnkL WOVDJ0wWg36BmC+UeSFK8ds7zoFdcyp6MdTdsq/tKH4cYCa+OvrcYhb6L4ZauBCzFXeq Ugrr3klcYfsm7ycwEbiT9MYCU4NXG3ub++56W7ARrNA+Mq9XTbPdk4zNCCsAPpwHD61H 4+ZcRcw4SJIM8m1TXJPSUcgh6xVLiBafE/RSujT9DMeSS1sY25AWjyqr3QVjlZ0kDBkj Nn9HMxEuI3s2+l6blAU8NCuRqFGVkE+wZV3Q0BZuivDMsXJO8JUJmMb6vo6MZ9TgK9uf 4x/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FJ7o32Gl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a170902d4c400b0017e6e415520si2450644plg.292.2022.10.29.06.12.14; Sat, 29 Oct 2022 06:12:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FJ7o32Gl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbiJ2NLY (ORCPT + 99 others); Sat, 29 Oct 2022 09:11:24 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027726406669136?= X-GMAIL-MSGID: =?utf-8?q?1748027726406669136?= 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: 12703 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1342154wru; Sat, 29 Oct 2022 06:13:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rEvVfsSce6U/+y0SM/fYWRig8nwHSQP+dI5m0baaO82Epj1wPYz7ZO5w60re7jPIc1I3C X-Received: by 2002:a63:2318:0:b0:452:598a:92de with SMTP id j24-20020a632318000000b00452598a92demr4061977pgj.73.1667049205149; Sat, 29 Oct 2022 06:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049205; cv=none; d=google.com; s=arc-20160816; b=RwOAQ9FX0M2815hPC0/1A2/poW/r8/uSQg0pp5gceqdmxaSmkAdTPzYA8zr1sz4fzY NF0I157dLUQk0cVLD9Dg/hol86OBu/peVNV3MLOA6L2W5ynwTkWjf6YIbPU3YLWpAiDy 4+CZIRTPrjWUuKTCwCzR+e59W2H6vogeEDuv8T2IMnnfRP9nMiyJi+vw+KCVbdvRHXty U5V24Ef+OWIdWX/MYPeU8XXRmLgJdHirN8DQrdtH/EHYsiZag9/GnOhtexONK9G4OvVS 0MsiOY/LONWxDx7w3GuXCEcBmC3IurP5cXmMpoDTzajk4sJSRC6rqbrQ2Z9jvnqToG8s qElw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VA5WMUBCQaBZijA3RMGledp+Muz3yfsvc2v9AgiacX4=; b=hGieDp5AtsXom5g9j0H4At9luOYlN0ISM5nzJv7ypWMJOd1iBD0IyY07en7SmGDAhi va08Qt9U/3MOdHd+pWRlB5Ghx5q/EazYZ9z3J7vuWAfzDfsf6Id6zNwM9bahJFuPWdej FKpkivh68bwFeBc4zn2/IhJxC7i4YwzKIXKnA+kc1AARbkgiuDx031rliaasYgGiNksF P7jwGFfH6OMfHiDL3dgg1xb/NtP4lvWXB0bAQ2Ty03oFDWowERpXYkVyGiIyqa669/A2 uhf0bzEQKjQSDEsZ1Cq5ubgqTTpn4fmG0lq+V41QP1XXq7u4ZnrYivHS7Fa2ym4uAnAW 9zhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QjKTulxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc7-20020a056a0035c700b00562617987a1si1528622pfb.264.2022.10.29.06.13.12; Sat, 29 Oct 2022 06:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QjKTulxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229916AbiJ2NLh (ORCPT + 99 others); Sat, 29 Oct 2022 09:11:37 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027787135169619?= X-GMAIL-MSGID: =?utf-8?q?1748027787135169619?= 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: 12702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1341970wru; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4G9kBSRDx2oOD2SN9YWeKW9IIIxvr6KI1l+hPJQsTTr6F2LwwZHFsKQyChW2SaJXPambDp X-Received: by 2002:a17:90b:1252:b0:213:beea:80c0 with SMTP id gx18-20020a17090b125200b00213beea80c0mr564906pjb.169.1667049177665; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049177; cv=none; d=google.com; s=arc-20160816; b=JBb2Mk29jDkw4TJ5Dsvz4upViQyy3pmgMZxZd5FdzuduWnNNdF1b2QAV2gqJX4ng5e Mc6/Jh9+Jim38QcQJgkt5HyYoqZeJHdOis8UE34ezmVxX4ZbDxh3xbw84ktysNBNVxGV CfsMRGFGcgkp+4J1aMBBBnzuQXqxxxjrZIRgmr8kpp8VDYjQWuv178BSdlBzD9RXOw7o /QxZHAPgYSjvERNtYHj9j3In5ZZcW0b668LM60KDnUEG4lPWIRWFDaqTz3B6RKmy+lVM lcAEK34Fpi6MuYs3fg1P+i2FyOOekTmsQydOsnpDUxUPI0v6GQt7cAQnAT8k4qN3CPP1 vLBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QT7TXRUVve09bvGpQVooCnQqDIlFLDJNPk73T/NQyZ4=; b=rs2efTnCs6LwwgFXjKgF3Y7DeoHAkQ0BBqFe6ok6Z9hDAuWm1VszN8FB8aU8sVNAC2 lYi+DtroBvXjiE2rXicPgyWnNywsaijp8BHja2COuGKmhVs1n1WewNIs6bfyIKwGfN2y ZKd3yp0l4Wu2LbVx4IOfLMVnrXzlKaXFrM6S6uBwUZfyLsrwlPpqMZHUCXT5RSSYEA37 ctRu3n/Wtko/1A/DmjyKyD2gx5hHu5jvaNJqwF7U4ded3d17mXlxCimAioChScxf5JaC YqZxcYBj2HXWmWdnfKNLeJPMNnl9RDgLwZWSo1HKi0UQrPF19u6IfXAfv3OzpVXNrw3s misQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EILN7IQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my8-20020a17090b4c8800b00213566a9fa9si2241429pjb.25.2022.10.29.06.12.44; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EILN7IQF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbiJ2NLo (ORCPT + 99 others); Sat, 29 Oct 2022 09:11:44 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027758813220494?= X-GMAIL-MSGID: =?utf-8?q?1748027758813220494?= 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: 12704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1342300wru; Sat, 29 Oct 2022 06:13:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BPCT1tenbRjULHOzeYb73LJoCRI/L8qu+e+BCsZ0Op/sm6AdRIoTI5rDX73WHV+bnhTJg X-Received: by 2002:a17:903:cd:b0:186:878e:3b08 with SMTP id x13-20020a17090300cd00b00186878e3b08mr4236409plc.93.1667049224982; Sat, 29 Oct 2022 06:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049224; cv=none; d=google.com; s=arc-20160816; b=Wu/2VwcuFLMeJn3tcyXGZULn6w9uHjRKRSav2ewX1PjRKGqF6krMVJh7eW93yDps4g DSALJpcv/Bg4rIvWJyVGKsRXe+PzIL3uHilPpaGVEuaUjZR0+JR1zSwCSvFZO6g2sz9Q nlP8glAxqctZW2Ab26fEYpmKzr1OMwaN4tHXFAp8RemxDzsw4OBGBpkE8rj2Fflo9IUJ mQh42F5zN6EAmtLD4heqmtiWKrgxOBKpQyPDxKpw2drSBPzlkLRrXM/TrD6t/bbq65fM X6mFSOyEXXZHJTOxZNL3f4sMctpUvNJR800Q58qLfEq8QLQ8VD5/S7HcWjL/E2ZgWQmZ Gv/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EJ08uRmM1fk/kBxamD2GYhMoonJypcExaYdhAS5+vYY=; b=xJTK9geq1lPy7Z2nhve28xdRxgwwrR5+s5g+AMEYgSwqTzn2GGvqf4NCs3rswPXVXj DFS+g69hIVdZGxus3SjYrSOBAcH+7Lhk1XqaItDhWl6+l9G1zKaJK0d1vtwQmexU4Wvy AakVt2Exfu3megp2etSjEHCMPkbgNydJjmyYUFggjv/xRq4nqTZaBnx323Pt1Wqsj+pW kj2s8wRFCjyrtDzL18VTVl/ySFldlreyBpscF7zjML7vv1+YXK3iCqTF44+Xg8zeVg7p T2YcqilYgIQ5zA+wLeOFL3mm5ZShjjMPVNNeV3a32+djeT1zVZPFLO5hhzsfa+YxoPDI swag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gQKasM9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i18-20020a63cd12000000b0046ec38975f7si2105206pgg.49.2022.10.29.06.13.31; Sat, 29 Oct 2022 06:13:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gQKasM9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiJ2NLt (ORCPT + 99 others); Sat, 29 Oct 2022 09:11:49 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027808048690074?= X-GMAIL-MSGID: =?utf-8?q?1748027808048690074?= 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: 12701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1341967wru; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FzHp3zQYguI3D1qmfwuIqp7hz5/63yW55EasFyZp5PYGr+OH5ExJC+hxX349zm5sdvBvi X-Received: by 2002:aa7:810a:0:b0:55b:674d:d123 with SMTP id b10-20020aa7810a000000b0055b674dd123mr4499658pfi.52.1667049177352; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049177; cv=none; d=google.com; s=arc-20160816; b=rsf+Bn59GptZGiNDHpYGJj1D7YEtNTeJ481vUKInDbL4fq1ONFfkd2P5PKYzZhePWn AfpSiliDZnN6qouCk9gXZvIo63N5aFkiXxBg5EHiqwfggvSSYGEouk9SL8ViI+W90A2P SDlw+7B23beuMfk5s3ZFQMGDoSE4d7qOMIaN5isAlw69+YrymCX9eh+wMmpzzIwvV9hv +CKR8zzf9b2AbxFLm/zyplhqwpJP5Y5Q3zRdIk6YbeLfFqEMI9KYuPVXBY5uPtmlKKXl Sscdv8nBRlsQlD5NhiSmc7WydEzyAj2p3MDYRriptf7MFnCqFcDlW1o87Zb8djkZatX7 SlqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e72HAxh6P1H/A+cQtAP2/BT2cWTj2acR1HBaWNLsTXA=; b=mOYJMPNK1AMKsn7l07uhlTyH/hi0o0RTDp8sv807rKPO5FCFeP6Kjh1BoFEciFodnG ry/HQYbgBmdurkL90Ub9xR0pjGe6Mkmok8XVD3UEIF9+F1+gEz47rvU+3DrdkbmokLIe XdHVn8SjJVO1CCrZnByV8VoGutzGSgAp+fyRY/4tHU0ewyGjXJR4N/fuPEZsThDoe7NG tIq+lhHqesBaXxMR2EKbrVKYIgTHmjrDz3boO2bRsz9UxA4Al6caqKm0A+iNofAaX7U8 gwv+9DSkflKRqQt90F8JWY1oCvcpHZnV07ceM1ZGVplig2/hHDlr9zmhj40WuVXUUbLC r0Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VZh6IoGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a170902c94700b00186b76f4655si2260856pla.358.2022.10.29.06.12.43; Sat, 29 Oct 2022 06:12:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VZh6IoGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbiJ2NMI (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027758229044331?= X-GMAIL-MSGID: =?utf-8?q?1748027758229044331?= 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: 12706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1342577wru; Sat, 29 Oct 2022 06:14:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4l7Jlygk+srCKlCIMfnxH/KvUFg3X6M80cCScA0KBlznriCd8hOyfgHV1umOjjY8S4Enhu X-Received: by 2002:a17:902:e902:b0:186:9c03:5f27 with SMTP id k2-20020a170902e90200b001869c035f27mr4339544pld.16.1667049264591; Sat, 29 Oct 2022 06:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049264; cv=none; d=google.com; s=arc-20160816; b=WueBNYO4wVxVHNBiRn4wN23cfj1NJpCyh40klTtDDfewxkO4lwroycbdQmtNvUijOT gxuZsLh9oG/eZMtMuNsKst8cAYuh39UlLnvdaRKPDzAdwYT6AMl0TQ8Ejwj/sBWKW5c0 D2VzWdxXI4MujJFIolAUNPmVDxcmVUtccYeE4njxxTEocHp2wYXSnUKhQbhrdHVlYzHy c4QApskTPbM6EAIKuLt7QuaM2iaKphxet3MnR2bXp8X6dxPU4RC0bbDpzjZrlCWncCTo i9oleG9NzHXJP73Sfq4kOsN0gN2TEcqPaUwM4yGrIvuafiJAGTqnr/nSg0+dSyqTfnic JVmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vssy2QIzKmHydtkjFhF+7Vo85h49gdfydYy5+cmw3Ec=; b=ooruIrA0wT5QnNExdjtO3Xm4azf9wBQEXbgigne0U48f3+nok/nRJOAS3iqaG5r+Tp 2Fx/ceafd3p0XnRpz3go8WS5ycNKXe5+khhc/PjC4rpT/40I/RyAwgdLBkhEvVxMAIyY 2k0thqHknYLKWNIlA2+c1iAsFQ7jZVworgkxkuS52+vcDBibzcSiWAuYO84iNmwB8QTM tkEWnma0G+1gCimeVR3fp3FqoHMnRL6KRSwoD6gAuCS8/7+dmDMpA5nCdexPFjb5YeY9 XYkZCXU1cs5VXA6UAXXmQdZp0HX+FOLbGr+vJA5TZN/oISW1aMreTFdjmOehmkoFbAcM GgBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VecOJpnf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 198-20020a6217cf000000b0056349604a6bsi1541517pfx.334.2022.10.29.06.14.10; Sat, 29 Oct 2022 06:14:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VecOJpnf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbiJ2NML (ORCPT + 99 others); Sat, 29 Oct 2022 09:12:11 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027849680034056?= X-GMAIL-MSGID: =?utf-8?q?1748027849680034056?= 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: 12705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1342490wru; Sat, 29 Oct 2022 06:14:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM432fcD8n9p/maZ0w8A95AhrhA+khN8WyVmflA3K8eWtPiAq1e7lPC/1dyPWK9iuCYDjAk0 X-Received: by 2002:a17:90b:17c8:b0:213:7de4:8eb0 with SMTP id me8-20020a17090b17c800b002137de48eb0mr4686471pjb.125.1667049250552; Sat, 29 Oct 2022 06:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049250; cv=none; d=google.com; s=arc-20160816; b=dlUTSpBbOxM9kuH5Wp7pctrxpc88fXyHV7FRdLvrhytHzB7vPA/78XdQVUvugUda71 0Xsu3PJJ3kgRUchQLelFKCgOYw28z13ajj1WL6w8ipmrPJONUfocRlJs4pb7McoEvKet nSVBa2uE+qDEzuaLRR8h0jgtDfNX3x1R6yX9BQYgBNfeLxj1Sb7WAUDhnwYMtD/wodpc SPsq1drfOoiPGWOL6bbbozW+XUlpCJ2Gk7ALZ96udRXJoQ7wI7WXr14kfCM7fmr+vRuU rmcOy3G8CoA2byGgWfb22RWGegjz5XaMAO25/o4gRU7ozIG84TJ49ZS+iGZlYChI0U9t oy8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GL2gYlQkLzPoDIZWhMbnN0oVuFwh4pQ+nvuIXIbJr+k=; b=lwcwt9iCH4q2ulG07vj/XmKCdITOGXI5vtIzTvFQ1h3oZg2Hi3LfwRu8JZUM21Pv6c 7zy83tYKVc98kzfRBfC1BdWYlTCAxf/Lyuh/+GSxV0qEeaWQo9LOx9tQPjDYtTPKPS+d HGopBdUxaVrJCVEGwuPhkAyFRFWP740CG92DIYNxDtaxk0qN6/Km1plJYdwICDIVIM9I +NsNl+q5APQ8k0Ti6HYUI2lrc8gRFVSW/p9MX3j3eii+1gjmbnveoKmpnsqieyZTnJa6 xXMKKx0DEL829dxO8Gr69lil2R7i3CCMcUkK5/pQPIeXXwekurLgS8Fi3JCnrNSp+Zo9 6AdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PeaKicSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a170902c94700b00186b76f4655si2260856pla.358.2022.10.29.06.13.57; Sat, 29 Oct 2022 06:14:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PeaKicSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiJ2NMc (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748027835104078859?= X-GMAIL-MSGID: =?utf-8?q?1748027835104078859?= 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: 12707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1344003wru; Sat, 29 Oct 2022 06:18:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/z1ffKgRKdsOlmlFSbvwTe1YMtDF410016jq3ovDzzC3g3IcTjzejj/rgbndm66ZFnBtn X-Received: by 2002:a17:903:228f:b0:186:d89e:c073 with SMTP id b15-20020a170903228f00b00186d89ec073mr4240105plh.48.1667049483556; Sat, 29 Oct 2022 06:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049483; cv=none; d=google.com; s=arc-20160816; b=NfQxsXkAwQCDJqtuOfcikz5FQMFpoy7qsZoW2kSqamwvqq9YYQ/JcRSvEcwpCrj9W1 YpW/5Gpb7bnxkJNh5Qq5o2cwnI/NOWjeAOJXdp8hd+Jmoo1iqXXZ6jO5FOUxSHJJjUTV fYFqUZVphY2HIjciH0dzgYd9biulrWg1y/kvHBK4xnOxEi0MciWY+wjnVn7D0Ewm5FTg V27JaN+28nGk5aOg3zxrt0UYdkaWROfoEI6WLdoDqUDQznMtFbhNBnJqwBcyb7yYvQEv hCqUz+p7dRAo42qC6k7+YEokgWpm4f1BkI265v80EPOklhLpPC0k3YF+5+S/Zxae54/L 4N7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1JJILX3ZbsEa361mIUD+wzD0iIrs7toiHw6XLt3BD9E=; b=rfsWUY13/SljLh9BaQyR9ZLVBlUcL1RuYIc+xAqn+sAzOfpqounmct0PUfIfHgShhI VWyledfrjZiqYyXizR1u2byp4vOuzRFVLHpUKS/OsJpZ6UMfeHXtjf50K8RMPRmaFTWW +jJDoF2VFE9XjRCoRJOZ0jd6m2f/AeSeNidYcL/r0EpoVnwqD2w4c+ZeSlteADmpK/oy yqUAS/MeP2QM5LG0CCXeNus2C2KnKucnufkf4a6dX6hC/HvDdAk9qTWBNFFsQ81CPmUW lzjm2o8GWlwfrzrL1tIizDsUn3O2DUv/n4ilKaDDB4O0BZ+ughNu0xcraPXJTpeqdJ2e wD4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qvYUTBXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f9-20020a639c09000000b0046f6d7b3fd0si1889940pge.748.2022.10.29.06.17.49; Sat, 29 Oct 2022 06:18:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qvYUTBXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbiJ2NMm (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748028079083463333?= X-GMAIL-MSGID: =?utf-8?q?1748028079083463333?= 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; }