From patchwork Sat Feb 5 07:47:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12735997 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 13DC9C433F5 for ; Sat, 5 Feb 2022 07:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357817AbiBEHsA (ORCPT ); Sat, 5 Feb 2022 02:48:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376747AbiBEHr7 (ORCPT ); Sat, 5 Feb 2022 02:47:59 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FF94C061346; Fri, 4 Feb 2022 23:47:58 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id d1so7042146plh.10; Fri, 04 Feb 2022 23:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7aNq4Io0f+ovfgZjS8ukIPYbhQ5JQpnNQv4Yb+umENQ=; b=eiVvXZA3R6xizP9DOVtbqcGyWkGtZEHLMkyIcROJqAE6BILikZC+V4f4VYUZwyWKBw Og8C80WEohXu5tnKHfnR725eD51pFiQzRABc3XoX4BpBUXLLh5XVaEDxpo8vL8U5u4nW eYSGcYPT4pw+fv8O3nvpXvvgyL3JmU9kXRw/jyBLWtv7MKNSsmf5ICVZN3iQjwnmfeXV DkwGJDzcj5D9fkJEz4XjiE3fAOArk/tKyoriJRHV7UG08wNMN2bk2+r92FjerRdkRj9J jXyXSmmw1i0y6uep3N/1PHSaZviw/bL0IKYeqxiLFcu/HYCSUBwcyCfKl4WCjNgSM938 WK5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7aNq4Io0f+ovfgZjS8ukIPYbhQ5JQpnNQv4Yb+umENQ=; b=OetL/GMxU+vw/sytpeoIH5oUQ6D7jwx4RwgOqdflnKopJvuRk7eWkW1ojDjScj+e2G 3hwB+8aSF+zed70ukxlMUe2YdpWKIL08P5Ix3kM5tBpXEZG9lfTv2ySLPNoZMPSKIRHW 3bd2mD11ZY6Xx3+xqaoD+mr8TdGeL64DoAFQkGpybWkv08+zSA9JOFVGU/VYcT20kU3n YhvHxAn0zSe7xrxOg4ZClCZJSlRA3bW03InIQLQ99Q1rRtgUdA7pIlJbbh/hy+ruAxOQ N65PV7WjXr5Zf0UeWUoVR2FcratE0TX/MYVbjEhbo+6akFP8xCxSjzy3ZR/HRtPHVu/h LKXg== X-Gm-Message-State: AOAM532Ei+Sg6FBBxVM3GT0aU34DWnDt28flzt+FKi3EzrSx7/MMb/+q GOhEu52sOTlC4fSwaD/zUsk= X-Google-Smtp-Source: ABdhPJxugEhSn86ivfT4KVWRB1svVRQJryEMEu3bemq6VMcKwPL3JLcdVmNzSICLUjcPFie1yBYMBA== X-Received: by 2002:a17:90a:f198:: with SMTP id bv24mr7534005pjb.32.1644047278189; Fri, 04 Feb 2022 23:47:58 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:47:57 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 1/7] net: skb_drop_reason: add document for drop reasons Date: Sat, 5 Feb 2022 15:47:33 +0800 Message-Id: <20220205074739.543606-2-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 document for following existing drop reasons: SKB_DROP_REASON_NOT_SPECIFIED SKB_DROP_REASON_NO_SOCKET SKB_DROP_REASON_PKT_TOO_SMALL SKB_DROP_REASON_TCP_CSUM SKB_DROP_REASON_SOCKET_FILTER SKB_DROP_REASON_UDP_CSUM Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- include/linux/skbuff.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a27bcc4f7e9a..f04e3a1f4455 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -314,12 +314,12 @@ struct sk_buff; * used to translate the reason to string. */ enum skb_drop_reason { - SKB_DROP_REASON_NOT_SPECIFIED, - SKB_DROP_REASON_NO_SOCKET, - SKB_DROP_REASON_PKT_TOO_SMALL, - SKB_DROP_REASON_TCP_CSUM, - SKB_DROP_REASON_SOCKET_FILTER, - SKB_DROP_REASON_UDP_CSUM, + SKB_DROP_REASON_NOT_SPECIFIED, /* drop reason is not specified */ + SKB_DROP_REASON_NO_SOCKET, /* socket not found */ + SKB_DROP_REASON_PKT_TOO_SMALL, /* packet size is too small */ + SKB_DROP_REASON_TCP_CSUM, /* TCP checksum error */ + SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ + SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ SKB_DROP_REASON_MAX, }; From patchwork Sat Feb 5 07:47:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12735998 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 8A1F7C433EF for ; Sat, 5 Feb 2022 07:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376747AbiBEHsK (ORCPT ); Sat, 5 Feb 2022 02:48:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379623AbiBEHsI (ORCPT ); Sat, 5 Feb 2022 02:48:08 -0500 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 67A74C043180; Fri, 4 Feb 2022 23:48:04 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id g15-20020a17090a67cf00b001b7d5b6bedaso8238399pjm.4; Fri, 04 Feb 2022 23:48:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rmUqM+JYtP9hKEr5gUjT2LuBcGNasQZbfimvB5akS00=; b=bVnW1ILz5WJbdtR3mf7RSwTPUsLjCHL9XeEA2kcpIu7QkO+EgQ+tYHedySRYPMGMJp Z3R0NX1tr1ZRS3DNDyy+x6+7hst6dLzmaGYUYVF3eYg+E0P5CV4wx0A0m6GtwiP5PoqP HUqw0rIDos+bB6COQVe+Zv0x8ZNAY5o1r+RW6MmI+gOv1xyf6IvLMqH79/bmM1mPSwJe fmqFjtMVamOYhml13eem2cfUz55bOPGUZcWZPonaztmw+MU/WK/mRZu8AJlLqtGP2wF7 JaSfzUIqlxoYoN7HruDrjsZsXBjmo1R5BZoz41itbISF4KVmXWGFDptDMpuTc5Q0D2Mt ZF8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rmUqM+JYtP9hKEr5gUjT2LuBcGNasQZbfimvB5akS00=; b=HkfZkha0W1Y0vAE9hfN0BqBoTOjX7cg1Laf2koQg4mfVM4k756Ct7zRkloSgY9g8Og KX2vqqxWiHY3Cv3lekKDDD3KjwBSfmnK2JTuYE/94Orj7P9gQzONl8HywI/8JP09o0eh 6c9Mofv86RNmT0sny8ZN8n9QV/L2jGZWMcJAh7FQVHrBLWXk7h2DyAJkTFTZZ6Q1s/vH d1OxOwsSUsdOH/HYfpZdbq30l25oL20hBQoDWBkssRhWWsSEjmZeZ/71BK4prOuuqqg1 vNPuz+JNUefj9nCL/xfccCbA4ORoIHBp5TRPjJieHkirWrB1GquAl+KcGKAuqzbobx5q zGGQ== X-Gm-Message-State: AOAM533SHCeresHycfRypodUoBeFFWxUJJzE/agyjcxavj9tcAZ38xYO Ch+ErKLw6S8vfvn2ii5/fdM= X-Google-Smtp-Source: ABdhPJzMlxmlw8YH91GcLyV34WOI1xXzkODCQvuPtu9ZdLRfbSUUBhOWPfWc0+73AFMCHNRZuFeSlg== X-Received: by 2002:a17:90b:3e8e:: with SMTP id rj14mr3110941pjb.35.1644047283967; Fri, 04 Feb 2022 23:48:03 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:03 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 2/7] net: netfilter: use kfree_drop_reason() for NF_DROP Date: Sat, 5 Feb 2022 15:47:34 +0800 Message-Id: <20220205074739.543606-3-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in nf_hook_slow() when skb is dropped by reason of NF_DROP. Following new drop reasons are introduced: SKB_DROP_REASON_NETFILTER_DROP Signed-off-by: Menglong Dong --- v2: - add document for SKB_DROP_REASON_NETFILTER_DROP --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/netfilter/core.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 5c5615a487e7..786ea2c2334e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -320,6 +320,7 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_CSUM, /* TCP checksum error */ SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ + SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a8a64b97504d..3d89f7b09a43 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -16,6 +16,7 @@ EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ + EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 354cb472f386..d1c9dfbb11fa 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -621,7 +621,8 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, case NF_ACCEPT: break; case NF_DROP: - kfree_skb(skb); + kfree_skb_reason(skb, + SKB_DROP_REASON_NETFILTER_DROP); ret = NF_DROP_GETERR(verdict); if (ret == 0) ret = -EPERM; From patchwork Sat Feb 5 07:47:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12735999 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 6C50DC433EF for ; Sat, 5 Feb 2022 07:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379626AbiBEHsN (ORCPT ); Sat, 5 Feb 2022 02:48:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379616AbiBEHsK (ORCPT ); Sat, 5 Feb 2022 02:48:10 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E25C061346; Fri, 4 Feb 2022 23:48:10 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id 132so6957985pga.5; Fri, 04 Feb 2022 23:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sFiIBBP1Guui5oRSHFXqQ0kp8WoqnfYPGN8qeO2nDPI=; b=DQ99ihcLC8cBdBgbZQSM0PkCxeuitr5MJsirC0PzI97NWQxdEQNzwiTQVI2FhHB4GV HYIEGDVOj21dMueNW+QjsgJm/PSZ2hZDBxtUfy5lGS40XA9urs082YX9APrU0wnJ0edy 4jSWThygzinO0iFkx5RfrhBC/Gnq+sTfvn5FyRjQDu9i4/pxQ1yugnTspwB18a3jX4D5 WnrQ1nXw5Ap0N5pVonRIksi6gWT+LzYiU16P8Ek+vBVj10Cwdy2vP3ZiO3Y+XvP5FCDr MEHNWdQDm41h+2b0pKl2LsIpocMqTEP35HeJh5CfOavQbjfpQI97mh9OGSY8Kqqh3/fB Edag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sFiIBBP1Guui5oRSHFXqQ0kp8WoqnfYPGN8qeO2nDPI=; b=dGn3v1T+2zOiS9JJd4D81/iNT9ArhXxFUrUOyzPdI5n2sj64TeXd+Bcf43+OW7Km+F Pr+/0ShK1ZcOmXHWtS5HhtjhbHw71HoFKhGH9h0ZjNsM3yzTqpAvdV62zQY9Tw1YtrZC Yg2jtWYnh1Rmd0RyWXYnK5OkAso0+RuCwtbcrE9kkwFB+W4QP2hffZ3nVshpE5MVAGJN A2mCiGjGY46w97T/x/XLbPWismHhiZ1orNVQeZuPMit+ADXXq2ZQmocIT6ccmKLb1UJd X3wdHAsiTKyLJ4/YEbTAwEqBWxHSAGJaRXpQtw7RJ5GVrkRsshzmajnHbOA4+J9uhXBI gmVQ== X-Gm-Message-State: AOAM533qok4/FhfvdKUZgsKaX25b26GqPudnZ09H5yjK6lGvUvENlUyV 96ZMNo0O1QnV62metb+XKQM= X-Google-Smtp-Source: ABdhPJy6YuvWmffNaucuXUNOerDuDJ2/JIIG75tQEAluYEG2WQYH2r9XmaR4U/bZqbeTO6kazRRUcw== X-Received: by 2002:a65:6e07:: with SMTP id bd7mr2140187pgb.457.1644047289645; Fri, 04 Feb 2022 23:48:09 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:09 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 3/7] net: ipv4: use kfree_skb_reason() in ip_rcv_core() Date: Sat, 5 Feb 2022 15:47:35 +0800 Message-Id: <20220205074739.543606-4-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in ip_rcv_core(). Three new drop reasons are introduced: SKB_DROP_REASON_OTHERHOST SKB_DROP_REASON_IP_CSUM SKB_DROP_REASON_IP_INHDR Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- v4: - stop making assumptions about the value of SKB_DROP_REASON_NOT_SPECIFIED v3: - add a path to SKB_DROP_REASON_PKT_TOO_SMALL v2: - remove unrelated cleanup - add document for introduced drop reasons --- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9060159b4375..8e82130b3c52 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -321,6 +321,15 @@ enum skb_drop_reason { SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */ + SKB_DROP_REASON_OTHERHOST, /* packet don't belong to current + * host (interface is in promisc + * mode) + */ + SKB_DROP_REASON_IP_CSUM, /* IP checksum error */ + SKB_DROP_REASON_IP_INHDR, /* there is something wrong with + * IP header (see + * IPSTATS_MIB_INHDRERRORS) + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 3d89f7b09a43..f2b1778485f0 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -17,6 +17,9 @@ EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ + EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ + EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ + EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 3a025c011971..7be18de32e16 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -436,13 +436,16 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) { const struct iphdr *iph; + int drop_reason; u32 len; /* When the interface is in promisc. mode, drop all the crap * that it receives, do not try to analyse it. */ - if (skb->pkt_type == PACKET_OTHERHOST) + if (skb->pkt_type == PACKET_OTHERHOST) { + drop_reason = SKB_DROP_REASON_OTHERHOST; goto drop; + } __IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len); @@ -452,6 +455,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) goto out; } + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (!pskb_may_pull(skb, sizeof(struct iphdr))) goto inhdr_error; @@ -488,6 +492,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) len = ntohs(iph->tot_len); if (skb->len < len) { + drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL; __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; } else if (len < (iph->ihl*4)) @@ -516,11 +521,14 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) return skb; csum_error: + drop_reason = SKB_DROP_REASON_IP_CSUM; __IP_INC_STATS(net, IPSTATS_MIB_CSUMERRORS); inhdr_error: + if (drop_reason == SKB_DROP_REASON_NOT_SPECIFIED) + drop_reason = SKB_DROP_REASON_IP_INHDR; __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); out: return NULL; } From patchwork Sat Feb 5 07:47:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12736000 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 8BDA6C433FE for ; Sat, 5 Feb 2022 07:48:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379638AbiBEHsX (ORCPT ); Sat, 5 Feb 2022 02:48:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379616AbiBEHsQ (ORCPT ); Sat, 5 Feb 2022 02:48:16 -0500 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 E73B0C061353; Fri, 4 Feb 2022 23:48:15 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id h12so7774267pjq.3; Fri, 04 Feb 2022 23:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R5oxeTlCZV+XvE1sgbFLa3xKvlTQGz9d/BNh7vx4mzs=; b=K+aMofl2ew/1XakIwJhloWcROFsb169W2ch0QziGgzH+PeqFB9juea5hoMmb7aPPId K0QBdSrWnAgcs6J5JT0JIcudmSqu1NuC7ZXHs7u6arlelsmWJeZRvqtzQt1kagFJgJA0 gzWoeqbhnCUPIshqosYyLIC2xnTe7b07y0s7GkKh4eQZ7jLUicgHLrtsQLP9JpeYy9lt +yZgOXE/LsRvxFfCiPY7joJplFKsHockOmEx5ZwHXqUXzoTZoB7LEfTD/B8cp4lC/7hd OLGYougD7xg082mADLQ4eWL/4jfQCfzDWeik35q7eugGjonNijoOpszaE0LCs3MkK34u UqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R5oxeTlCZV+XvE1sgbFLa3xKvlTQGz9d/BNh7vx4mzs=; b=R0bt14VOgqCrQ+NjCW+8R+CXHSpy2snpcaAQpOv+PtsWFPwZfqOJffkkuPJdyvb6wz tlSOd0zk2HoEH18h8C9ZObQnm+XBqOeVnH9TlnKVzzk/E00aDGZ34jFLUPYQLk12ANWA x04K3Xta1OzvVBau1oudQhgmB5nOHggawa/bdTTwJyiPJj2Fw9/gJY8Qw+IjRKypGCTJ yaCkNiOvRmssXpwbhwv42XnmM2uovQ5nxyo5GmLvlfLQP5G+F2n6PGabgWOOHsziuZu4 W+cf1JWcvJ06DmovN5TZZoKh654Djq6m6CFNMs+qjIllVAs8+i+AY0lJNahhwo88iYSJ A50g== X-Gm-Message-State: AOAM533sI+G63Fbj27+UaVaZGPm7qnlsM65qwZrppXJMom9eJNaI6M3T zgdQ+DZkBm1J82xTP7HY8+A= X-Google-Smtp-Source: ABdhPJwRCYzWWTnsyxsrvlmycYJjW5Lp1/rbAh8gSQgHZ+kg7cpt4lXhljpi4MZcLdB0zUu1knqRcA== X-Received: by 2002:a17:90b:164a:: with SMTP id il10mr3081560pjb.117.1644047295489; Fri, 04 Feb 2022 23:48:15 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:15 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 4/7] net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core() Date: Sat, 5 Feb 2022 15:47:36 +0800 Message-Id: <20220205074739.543606-5-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in ip_rcv_finish_core(), following drop reasons are introduced: SKB_DROP_REASON_IP_RPFILTER SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- v2: - remove SKB_DROP_REASON_EARLY_DEMUX and SKB_DROP_REASON_IP_ROUTE_INPUT - add document for SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST and SKB_DROP_REASON_IP_RPFILTER --- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 14 ++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8e82130b3c52..4baba45f223d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -330,6 +330,15 @@ enum skb_drop_reason { * IP header (see * IPSTATS_MIB_INHDRERRORS) */ + SKB_DROP_REASON_IP_RPFILTER, /* IP rpfilter validate failed. + * see the document for rp_filter + * in ip-sysctl.rst for more + * information + */ + SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, /* destination address of L2 + * is multicast, but L3 is + * unicast. + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index f2b1778485f0..485a1d3034a4 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -20,6 +20,9 @@ EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ + EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \ + EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ + UNICAST_IN_L2_MULTICAST) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 7be18de32e16..d5222c0fa87c 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, { const struct iphdr *iph = ip_hdr(skb); int (*edemux)(struct sk_buff *skb); + int err, drop_reason; struct rtable *rt; - int err; + + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (ip_can_use_hint(skb, iph, hint)) { err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos, @@ -396,19 +398,23 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, * so-called "hole-196" attack) so do it for both. */ if (in_dev && - IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) + IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) { + drop_reason = SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST; goto drop; + } } return NET_RX_SUCCESS; drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return NET_RX_DROP; drop_error: - if (err == -EXDEV) + if (err == -EXDEV) { + drop_reason = SKB_DROP_REASON_IP_RPFILTER; __NET_INC_STATS(net, LINUX_MIB_IPRPFILTER); + } goto drop; } From patchwork Sat Feb 5 07:47:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12736001 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 8BA8BC433FE for ; Sat, 5 Feb 2022 07:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379660AbiBEHs0 (ORCPT ); Sat, 5 Feb 2022 02:48:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379624AbiBEHsW (ORCPT ); Sat, 5 Feb 2022 02:48:22 -0500 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 F2799C061347; Fri, 4 Feb 2022 23:48:21 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id x3so7073886pll.3; Fri, 04 Feb 2022 23:48:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9BmxrMHdsxTVTtMUopIY8p4Hr0XxhRFGz/KMlExKtGA=; b=afPBOLrpEdRPwhZ/1UjBJl+6+uH6cRdp0zy2uU05sPEzGfdC86irsfBYWpziIwRRZv Nr0zJv0IOEI+GAXA+4m9WEivE3SmudoDG7u0Ihn5j/hAEM4bYFXTqNBXNHqau7nc8+OD bf/zrRkdnd2K8XzWoTEo7fQUJerkeKctVy7u1OmCMjQfhSI1VDf0CXiWXdkwqBz2HQRb JM/BEY1cOUBzCoJth4kb2uEmhyEpUNxgh2U45sHiPBAuWOyfJxjVnoLqQGtNpqmBCDLB 8M5U3Dn8/WM7/qMfIHXEY4jwfc2Az1u2Q2rcLlu8017o8aRNMNe326rMhgHub0FCj+7I 26HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9BmxrMHdsxTVTtMUopIY8p4Hr0XxhRFGz/KMlExKtGA=; b=AOZy4Usn5E+H/HqT1qm5IZ8rfT53uMHuHNl0C3AokhhZIref3R+fs1QrydRiltdJNb Q+uDsJKwGPneESy2otkobpEa8i4TP+nhnQ7oPs/NHgwj+mI3Z2dbZIBekx61ZvBMlSMK kiavoLX4Sur7/bzQWTo84YzsbZueLFEwZcKrtOE99Vj26PuCgxAmIkWxrWjliUwYPlfj Y09AhF5+AmNninnf+r47xFvoJULw12f2gP7BRPpmKf/Q+xWdip5bjNzipb3rs9VHekBa y4Cfno2WgYBZuiV+KmZiN5plDuEF96hvm8QhBpbjW3ElT8cXywRuFJxzvu2S9stwehVS zf7A== X-Gm-Message-State: AOAM533uuxBpzeJQtyKw6gPpn2/1skaQ7fTpRtizUhiQk+eX0mnd+T32 UondulOFHaj4xL8BaUoH8PU= X-Google-Smtp-Source: ABdhPJzFXlYTP5IPYJSOe/hYmDd9uwpUtlyBRWWoMwRa3tvdQzczSnAD2WE1dtuXPzcDtxYfEtQpKA== X-Received: by 2002:a17:903:2446:: with SMTP id l6mr7302518pls.48.1644047301439; Fri, 04 Feb 2022 23:48:21 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:20 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 5/7] net: ipv4: use kfree_skb_reason() in ip_protocol_deliver_rcu() Date: Sat, 5 Feb 2022 15:47:37 +0800 Message-Id: <20220205074739.543606-6-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in ip_protocol_deliver_rcu(). Following new drop reasons are introduced: SKB_DROP_REASON_XFRM_POLICY SKB_DROP_REASON_IP_NOPROTO Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- v2: - add document for the introduced drop reasons --- include/linux/skbuff.h | 2 ++ include/trace/events/skb.h | 2 ++ net/ipv4/ip_input.c | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 4baba45f223d..2a64afa97910 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -339,6 +339,8 @@ enum skb_drop_reason { * is multicast, but L3 is * unicast. */ + SKB_DROP_REASON_XFRM_POLICY, /* xfrm policy check failed */ + SKB_DROP_REASON_IP_NOPROTO, /* no support for IP protocol */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 485a1d3034a4..985e481c092d 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -23,6 +23,8 @@ EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \ EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ UNICAST_IN_L2_MULTICAST) \ + EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ + EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index d5222c0fa87c..d94f9f7e60c3 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -196,7 +196,8 @@ void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) if (ipprot) { if (!ipprot->no_policy) { if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { - kfree_skb(skb); + kfree_skb_reason(skb, + SKB_DROP_REASON_XFRM_POLICY); return; } nf_reset_ct(skb); @@ -215,7 +216,7 @@ void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0); } - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_NOPROTO); } else { __IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS); consume_skb(skb); From patchwork Sat Feb 5 07:47:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12736003 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 49BB7C433F5 for ; Sat, 5 Feb 2022 07:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379623AbiBEHsj (ORCPT ); Sat, 5 Feb 2022 02:48:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379675AbiBEHsc (ORCPT ); Sat, 5 Feb 2022 02:48:32 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0016DC043181; Fri, 4 Feb 2022 23:48:27 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id d186so6942900pgc.9; Fri, 04 Feb 2022 23:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vuMg5gP1AvDBwmfdMA51t/vA+B/PiJBXh2REFxOfw54=; b=lOqSxAbSrVgG5tb3MddjDKLiXN5VTHlx11l34pBRQGCCdeJdTRCngGVEHOPp06IISc lfx0brfLsrYFF5KB+jvPjgQbaW3HHY9RB1xy/Ko4TQWNpGt7w2Z2jVc490rInD3gVU8X lQ0rLRl1n7C3oX+fBYjP23RiLGd+snvhYoZr1y1+phZWWB5DCrhg0yKVjNirxK8XYvmt XZDyx5LBpg3VAYuu9k9TNva6ExU4JjjvVtxIFSEBk1cxI0lXXT6mtzAi9A3qby0nV1K+ aWnjA9XAMGCK1gYBN8roX+e+Yo3kAlzCGA08mgM5DiUwcuJMS3iii2Ug2afE3HMkRetA R9mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vuMg5gP1AvDBwmfdMA51t/vA+B/PiJBXh2REFxOfw54=; b=AywERpslPmBFYHF8q9twZpkwytovfP7NOyuneaV1TA5vBKz4m8EuGreCfNSb/DcvCF qFS8YosCfpAgjxzlQOu1iKS8+AfGrOGSmzzKSuKG5UWyMJ+hRYbddYSIfMLzK8xIIn7E 2W1qa9DS/pdXbsXh98emOSqg4xC4P3P/+6KsLSyQ5eENW/atcGGyDdMyDo4WojWTzQ7H el2FacAa80tAddSXM+iziTn8fZCBt5ZffneqOTvYUWfwLEHMGRAbOFHt6+k8OeLtMnsa tmeT6Vc89YNjgJfH34TD/THbnHPHovR8dz3O7JlgCM7G5bkGADOpb/TlZPE0UlWR6fiQ upyg== X-Gm-Message-State: AOAM532nCpnP38izuFLlhcC1TYYkBLAxqRfU8yF06g+tnSETlOYxgrUb wPswEmLy4Xkh8ULOu+6+apk= X-Google-Smtp-Source: ABdhPJyAEWQL3GK2BBmvcFJucPpj4coI+RHrzYxEplUC57XpedYMnAhKgn7wVRPS+nkK7nG2mdbPQA== X-Received: by 2002:a63:e302:: with SMTP id f2mr2142691pgh.451.1644047307553; Fri, 04 Feb 2022 23:48:27 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:26 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 6/7] net: udp: use kfree_skb_reason() in udp_queue_rcv_one_skb() Date: Sat, 5 Feb 2022 15:47:38 +0800 Message-Id: <20220205074739.543606-7-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in udp_queue_rcv_one_skb(). Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- v2: - use SKB_DROP_REASON_SOCKET_FILTER instead of SKB_DROP_REASON_UDP_FILTER --- net/ipv4/udp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 090360939401..952f5bf108a5 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2120,14 +2120,17 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) */ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) { + int drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; struct udp_sock *up = udp_sk(sk); int is_udplite = IS_UDPLITE(sk); /* * Charge it to the socket, dropping if the queue is full. */ - if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) + if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) { + drop_reason = SKB_DROP_REASON_XFRM_POLICY; goto drop; + } nf_reset_ct(skb); if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) { @@ -2204,8 +2207,10 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) udp_lib_checksum_complete(skb)) goto csum_error; - if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr))) + if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr))) { + drop_reason = SKB_DROP_REASON_SOCKET_FILTER; goto drop; + } udp_csum_pull_header(skb); @@ -2213,11 +2218,12 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) return __udp_queue_rcv_skb(sk, skb); csum_error: + drop_reason = SKB_DROP_REASON_UDP_CSUM; __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); drop: __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); atomic_inc(&sk->sk_drops); - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return -1; } From patchwork Sat Feb 5 07:47:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12736002 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 59F17C4332F for ; Sat, 5 Feb 2022 07:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379662AbiBEHsk (ORCPT ); Sat, 5 Feb 2022 02:48:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379619AbiBEHse (ORCPT ); Sat, 5 Feb 2022 02:48:34 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F24C061347; Fri, 4 Feb 2022 23:48:34 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id s6so7033460plg.12; Fri, 04 Feb 2022 23:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9pvmS13AHWSjRM47Jhdp6MkeVnK13IvKcbnz13xDaLE=; b=lSIJtl9jKVNqlSJP68ZtPIvJXK7FivpbvUb8I7KHPx3pk45QxppS+wOjpoi1dApI/q 0jmTU+VWeGpxPKbU2Z5Yy/J+b/blH4IrVfLCd5B3rVf1bRFEBRmMTforC1MvE3IaLHya BAXO0rFzSlwGqtYmhfDsfHvktj5xXU+wgiBkYLgbW3So4SMphCi/1pA1e8lCB8dBJO0M SU/biRDERDB0vZ9aED6tDpZ8/LH535441Ch0qkhZYKfX96RpkZ5TH176CrEPa20wmGcS fA5FSVsYh7c0jXn5vo0Hsw/woZ4mQsuRVchROTGHOFj1Xga89CgS7t/jqQRE2QKoOHs8 wHhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9pvmS13AHWSjRM47Jhdp6MkeVnK13IvKcbnz13xDaLE=; b=ajg5sN+A14Ye5l9luGoRPEbk4Vn7LwoqtcNst5nBHuXxe8n7JbHens+ZAOX39znRiz uo+dxvnWbPgtzSZJD8RegXo2J3kSgiTMVDBEsvc4zSaT9/i4o5Nq85zndckDZE3bxThI XjnnSS8OBMMPY7p6oXXC5mBGGcQQtU/HBlGIwrhN3lKdbHADChHbaKSfrExs3ZnI2A6b wBcKuV+tC1/dwkgKN6cmiKE07/e1hzpjRVeieqEcVzDvHfg8zui5AVPmT2IGnTe6wIoD fNM6v3mHfJs6+kRnif+AenpdI1TOJ6PGxf/c+I0KxtENphJrJlVRanarPr0giwvqHI1a jO6g== X-Gm-Message-State: AOAM5319N7cOdeNq7PAE+ra0RNLfMhPvFFBJn3KoPVD4gqymWHaauvrU w3IZV2In2jAjZ5knj6OR6p8= X-Google-Smtp-Source: ABdhPJxhsnjGiJZF8PGXfpb97dgdLRQSe/8+NXuxEr2/Qmygq/RV+nnomhFmEY4MOTq91nNRfBtISA== X-Received: by 2002:a17:902:e812:: with SMTP id u18mr7196603plg.12.1644047313617; Fri, 04 Feb 2022 23:48:33 -0800 (PST) Received: from localhost.localdomain ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id p21sm5165844pfh.89.2022.02.04.23.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 23:48:33 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, edumazet@google.com, alobakin@pm.me, ast@kernel.org, imagedong@tencent.com, pabeni@redhat.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, ilias.apalodimas@linaro.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, paulb@nvidia.com, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v4 net-next 7/7] net: udp: use kfree_skb_reason() in __udp_queue_rcv_skb() Date: Sat, 5 Feb 2022 15:47:39 +0800 Message-Id: <20220205074739.543606-8-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220205074739.543606-1-imagedong@tencent.com> References: <20220205074739.543606-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 Replace kfree_skb() with kfree_skb_reason() in __udp_queue_rcv_skb(). Following new drop reasons are introduced: SKB_DROP_REASON_SOCKET_RCVBUFF SKB_DROP_REASON_PROTO_MEM Signed-off-by: Menglong Dong Reviewed-by: David Ahern --- include/linux/skbuff.h | 5 +++++ include/trace/events/skb.h | 2 ++ net/ipv4/udp.c | 10 +++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 2a64afa97910..a5adbf6b51e8 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -341,6 +341,11 @@ enum skb_drop_reason { */ SKB_DROP_REASON_XFRM_POLICY, /* xfrm policy check failed */ SKB_DROP_REASON_IP_NOPROTO, /* no support for IP protocol */ + SKB_DROP_REASON_SOCKET_RCVBUFF, /* socket receive buff is full */ + SKB_DROP_REASON_PROTO_MEM, /* proto memory limition, such as + * udp packet drop out of + * udp_memory_allocated. + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 985e481c092d..cfcfd26399f7 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -25,6 +25,8 @@ UNICAST_IN_L2_MULTICAST) \ EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ + EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF) \ + EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 952f5bf108a5..6b4d8361560f 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2093,16 +2093,20 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) rc = __udp_enqueue_schedule_skb(sk, skb); if (rc < 0) { int is_udplite = IS_UDPLITE(sk); + int drop_reason; /* Note that an ENOMEM error is charged twice */ - if (rc == -ENOMEM) + if (rc == -ENOMEM) { UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS, is_udplite); - else + drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF; + } else { UDP_INC_STATS(sock_net(sk), UDP_MIB_MEMERRORS, is_udplite); + drop_reason = SKB_DROP_REASON_PROTO_MEM; + } UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); trace_udp_fail_queue_rcv_skb(rc, sk); return -1; }