From patchwork Fri Jan 28 07:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728039 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 B4005C433F5 for ; Fri, 28 Jan 2022 07:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346825AbiA1Hdw (ORCPT ); Fri, 28 Jan 2022 02:33:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346819AbiA1Hdw (ORCPT ); Fri, 28 Jan 2022 02:33:52 -0500 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF774C061714; Thu, 27 Jan 2022 23:33:51 -0800 (PST) Received: by mail-pj1-x1044.google.com with SMTP id l24-20020a17090aec1800b001b55738f633so6747551pjy.1; Thu, 27 Jan 2022 23:33:51 -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=Fbpl4iiTcLCx3Uuz7lt489tee85dcatKLG2kCO2VOAg=; b=Hnx5mSacFF1TfYpEmVBkDNCwrSnX9GxO9njbZxylQ0sYgbQX+YuZ2k2VWhtjWAY2qn 8JJNdDXVQkgUGG7KpYdltzD0esaYKh+Zaxz9f8UQOpDTl+TCWJZOMdSzJnEmGV91rfAK MaX0W/j8pxJ1uEH3cFToBNE41H4FAujbBNuDeI9E5QVfRLWNJVYndjblv0/M2OR82PDr YDKYnIj0gfqq4S4x4i/RcnptIGYx+6Gz1fPK0HmLXIZ1ziEOCcefPwhdbRdh24BfYcm2 8PCleyws2JEqbwJYY4xIcnKgMm3HtpLCeC7/xc5Y1ITJTaiHvkfNEAy+WlpHF16KxBkF n3fQ== 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=Fbpl4iiTcLCx3Uuz7lt489tee85dcatKLG2kCO2VOAg=; b=CcZp9TIN2NllAwWze5P40UL4KbH4Xr1Iyg+A905fdNQ1UH6gHhyaXqqIcRqheBqimZ yYCqMaO52brbJFTawjCUgsBNVNyg6pa8C1gXihP8d+fLBRY6kZvSIjQQzeij5c2toZkZ wVUzlPhNssJsYdS0ncLQDsZN8KhQadiQu+VO3JlmgU61jNKUtb0iefiQRXia8sr83wg4 Mvr3on64X0UHs+9396bluAg4T2i4UVelrd4x/bTLk7FoaPE4y/ity2jexEXGGA5c36og 3vAAs8JPxmOGLAG6Zo7gtPqAKRlm9YdFP3e9VxkTF527Aft4WnDsye3bKZ3g9DHXjbgo Nqgg== X-Gm-Message-State: AOAM530vxLaRTsrqyY06pFXOpqqJkaw1zVKBEz+WMx9ceLIoWLtG8CTi TAo069Enkl1oYSz72JB3rXs= X-Google-Smtp-Source: ABdhPJyXggEqjtjWfpxOYUYLfiM4yWGWbSYQF/CGzP4gk7mbpgmIO+j/2Y8YVlYQ2OxO69eTN9l1PA== X-Received: by 2002:a17:902:ecd2:: with SMTP id a18mr7179069plh.84.1643355231584; Thu, 27 Jan 2022 23:33:51 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:33:50 -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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 1/7] net: skb_drop_reason: add document for drop reasons Date: Fri, 28 Jan 2022 15:33:13 +0800 Message-Id: <20220128073319.1017084-2-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 8a636e678902..5c5615a487e7 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 Fri Jan 28 07:33:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728040 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 DB715C433EF for ; Fri, 28 Jan 2022 07:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346834AbiA1Hd6 (ORCPT ); Fri, 28 Jan 2022 02:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346823AbiA1Hd5 (ORCPT ); Fri, 28 Jan 2022 02:33:57 -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 669D7C061714; Thu, 27 Jan 2022 23:33:57 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id d18so5148869plg.2; Thu, 27 Jan 2022 23:33:57 -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=A51w6brukyQ4/JOO9YY7pEYG7W9fZTomsnU/EMNXcRRsUQ3uC0gKgk0jXMHSK4Ff1Y knHTRConLJa4UM5sVQBXsL/It2YNTDFJsqH8sFuuUAlAtLr1y8+NMt/rMjhaa8C9jLmu quDYJRA+fw0KrSga5501g220oYiqi5SI6oLK6+16PhWAkUbzKAimfwlGtZHfQNEofWzT LPPmWS7UrdAiD+FuKSke+A98FgEbSiSAqi7JlCvjc8TrtkBHQENalLXQtaKXqKfHVKYQ WL3r4QJMtjjyLfMHzIc3xoGpXTkVEFsC7H3wKpc624PAJcrUS7rY7E0awQ/2P6stSEEk Z1Hw== 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=oyOcpKNwCVI12HtmN9mev+m2SbreLvDinTR21jz81iPTXwem9etqjV/k/ftw/6dfFj 9s+KKoUxzXQ5bBgKBPZW4PiB5PHzjp8bJlplailoqG5Wzp3kBh8Lqv3ZuT9SFMB8gMC9 N1Hd2pzWV2gOtACdlMBJd/bfQcoKAsJXeTOze6hclm2BcnHEH4Ijizd8zimc7zTvnZUG FJHwbMXVRiFSM+zfD8jhH/0G0gdDczTsuRwp6OJ1OKKk+nBZ+5DXwFWnBJOtUfrnZBMq 3QBbbbo53AZXP/h4LkFwFuKxFBhxVLJFJqfCOVjPryyZDXOL6NzFzzo5ZEMDj793myyt ZynQ== X-Gm-Message-State: AOAM532UoQQTs5Si0vVDW7zgdg4BmzFipOMVAs7JsXKUPrlDfQtyGl4T raciZ5KjQwh8g+6CTgyt5C4= X-Google-Smtp-Source: ABdhPJzen6GbyG5Hj9xj0f5UIHVBNzYusLx/GOWAooc4fha5g5Z8xsPHIeDAMtQvQGC2tCh00CA9yw== X-Received: by 2002:a17:903:41c6:: with SMTP id u6mr1885132ple.6.1643355237000; Thu, 27 Jan 2022 23:33:57 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:33:56 -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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 2/7] net: netfilter: use kfree_drop_reason() for NF_DROP Date: Fri, 28 Jan 2022 15:33:14 +0800 Message-Id: <20220128073319.1017084-3-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 Fri Jan 28 07:33:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728041 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 D3FD9C433FE for ; Fri, 28 Jan 2022 07:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346849AbiA1HeE (ORCPT ); Fri, 28 Jan 2022 02:34:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346837AbiA1HeD (ORCPT ); Fri, 28 Jan 2022 02:34:03 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80401C061714; Thu, 27 Jan 2022 23:34:03 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id d187so5374687pfa.10; Thu, 27 Jan 2022 23:34:03 -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=mOTKGJo2ptZmxhh20F6vP7nFZ10swZHTBsqufq2gJow=; b=kzwius+Joffqz2Xy6JtuZk2V+ZOZ0aW5vrxJY8Sgg2ovC/Bbc/1ec3ClZSBl0RI1UA N8yRgvMBENE8Q9DxgsQCfnBK5yPl1hplDWBI33STrj1XhUlwIflmc3cZb6/NLF8kKRLA Mq5iKwpVB4fvDIz7p58gxt9ijhUbNXyHFNF+hVwZpf6g+pEMIxRf5YSeRY9DUHMtUaxr pqoqrXHHnoP7eNumVL1H7/aqcSTobwi3LKYwB79TJXVdnaTBwcrfbuHvzIEt8g0OOYAL Y0QSQoPL6hDKAoMx+do/2TXSZYHX7rGASLqwl+xfjZWaDSmnERR/V2GG08kmtgdRPFwv sezg== 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=mOTKGJo2ptZmxhh20F6vP7nFZ10swZHTBsqufq2gJow=; b=ut7Yj4eZVmBYodoGw+0IFJXvTjIe//Hgy+0GNkA2wZzW33jf5GdSB+RmPmRtz/1wgM 3cGVKSaTyorSDbUnlMQrSmi0sZfWblObaJDDPMLWOEVkTbvJnTFVKlXeOQlP+bwYuNV9 ldE0fRTFvKEiwZJoWnwps87qjhz+86QVejq59M5dSUvdzhUeIjFly6E+SAS5936VTAf2 ZrF1UCaL+1h7BM6kdZl0B04Gl78fvm+tTjj+H1S3+/MAeA/YAhFLFGxLQbl0wWGLA0at NwQRhWj4S2fsN3MD0Fr+mzGWRFM+IBPz0TMuxTdoS3NxDQMuPjteFWZ2mf03vkUDTUt9 oYIw== X-Gm-Message-State: AOAM531X96Dsv4BSt9y67V8RFyCnWAUswQQJU3pRr5WQNt25fgjgEHB8 fqwZ99LSpfCrP2s85umHW/A= X-Google-Smtp-Source: ABdhPJztFBRkOdErwXtueSld+b1Ha9wpg+AmPCC6X4YvuwYN0POPKKW23rqX93/XTAdgN4aCnNBObw== X-Received: by 2002:a63:2021:: with SMTP id g33mr5565011pgg.51.1643355243067; Thu, 27 Jan 2022 23:34:03 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:34:02 -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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 3/7] net: ipv4: use kfree_skb_reason() in ip_rcv_core() Date: Fri, 28 Jan 2022 15:33:15 +0800 Message-Id: <20220128073319.1017084-4-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 --- 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 786ea2c2334e..2e87da91424f 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..627fad437593 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -436,13 +436,18 @@ 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; + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + /* 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); @@ -488,6 +493,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 +522,13 @@ 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: + drop_reason = 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 Fri Jan 28 07:33:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728042 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 47356C433F5 for ; Fri, 28 Jan 2022 07:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346786AbiA1HeL (ORCPT ); Fri, 28 Jan 2022 02:34:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346790AbiA1HeK (ORCPT ); Fri, 28 Jan 2022 02:34:10 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6384EC061747; Thu, 27 Jan 2022 23:34:10 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id i17so5357875pfq.13; Thu, 27 Jan 2022 23:34: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=w3YfXYwf6leAIb9pOlV8H4EpsmXCP8MCeqEUbaPVjyc=; b=mdWPKm3PPciue7TUvewktVp3exqSTPPeDNPw+2pRa4TJjOmROeZK8lE8SIsn2IKT1a ARFyzZlS0Y3c7TfM+pynqFuDcEpCZViKjABznxaFO/pp+qStDMunMTkEC6a9/bq9hxCq 57j8P7Fg0yqJkZdWkrUP4qpsfT2bQtuVsKs0Us91NqarEFR68/xIX8LKkWTyKIX8aNgR EA3jlpra1fEaEp1uNnKK+QVdFN40RMwZaqnIpAR/OAnkC8bHr63a3OP3i2lt0ufQTTjx 2epUzReNtS/Gwa4KuRVi6KRuxp3pGGgtxlJRXkO09p9FrPWSCBDSU8y9f+jm0ktBlF0U ASgQ== 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=w3YfXYwf6leAIb9pOlV8H4EpsmXCP8MCeqEUbaPVjyc=; b=Hjmj89DeTKriika/dGoxYeD0LVyQdci+9Su1M79hhCtiiL+FbgN5CadNcKptK8hx5j +9nsVzGbYvoMqR388wPJxIJdcQ4QjY11T2Scjc4yD0kCA+yiJMcLu0v2JRAUo57hU9Lr 7eaiCCgyrBLb44T81iwH2jTm4yqvhRuQhJ1ipktDgUyjW4cB8gw1kLLpJ4Qz04hvVxYC ByU6LEIpErJsr3dKshrwEv/KQHs9P25rBc21lWbb3bmRwWJdlHhXxmVx5RbntUqaf0XQ 8rLldgsQoceyOiPjQ7p5Z6tSFbquZfuAFOmMBtW9Csy/qlDm1pJ4D8IJh+D3EgdGXS/S sqIg== X-Gm-Message-State: AOAM530ISzNoHFn5qQErGRBq0K/JtYOb2tVZcuvNBOo89V8WMBiQNUR2 IBh2dvemlhiXt266/1k6HuI= X-Google-Smtp-Source: ABdhPJxH9nVgQPXkPNkg28Ic0BZeAfAE6HJ28QzhhAbwHs8S4YRrwRwRgWrsgwQjvBAmXlhG6E3YbA== X-Received: by 2002:a05:6a00:218b:: with SMTP id h11mr7147821pfi.29.1643355250002; Thu, 27 Jan 2022 23:34:10 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:34: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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 4/7] net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core() Date: Fri, 28 Jan 2022 15:33:16 +0800 Message-Id: <20220128073319.1017084-5-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 2e87da91424f..2d712459d564 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 7f64c5432cba..184decb1c8eb 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 Fri Jan 28 07:33:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728043 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 D23E3C433EF for ; Fri, 28 Jan 2022 07:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346859AbiA1HeR (ORCPT ); Fri, 28 Jan 2022 02:34:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346862AbiA1HeQ (ORCPT ); Fri, 28 Jan 2022 02:34:16 -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 E9318C06173B; Thu, 27 Jan 2022 23:34:15 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id j16so5135197plx.4; Thu, 27 Jan 2022 23:34: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=AAC7L6aHlRQtxgtk8rcpxBhloOR2RlrXxvp2Txw/5xE=; b=qnM3arX6oZNhV6fsJDc/1y/fWTl7N8rL1qSWOu48nxtHtpyxNmPHCKRK+WtyFYuQTJ QygsDVWYkn6j3l4AmQCB4Jc1xhtG5WADCFKvLKdonaMMn0vfstZmxufRIt/6oKnOlh0b W3bi0R3EISpQbql+THIS/pizjVh4fiWqJd4DTrHvnQkRp1JMvOFzNIrYGXNlZ0vv69vI FQqj1Hwde9+6ZRFGTxxRCANFOQfRLY1FLAcftzC3crWV89Td2G89bO3VIUETAndfkmkW u+q4BlJQdqJzlHJDZZodiXdAelXlmc6N6bbXp0bt28+2z9QM86JQoN42Xb70VWlmFFr3 J2Jg== 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=AAC7L6aHlRQtxgtk8rcpxBhloOR2RlrXxvp2Txw/5xE=; b=VM48NjZXoQUAWQYrdolXKGJhjIqT+5S9exathw1gsQvzf3ORoBqjQ4JjsJnDCqt16+ XXGVDQ6hOdznfjdkJmkNz4tneF6lTcEe9c2i5D/1NYNfMPLlhc16e3TaTJkCmRAK3klw EAPoAIo9c+XdoQIKwst3vCZCLdrTGSybeFjljP3/w/RTYurg03ACrZRB+Lqytq9DkO17 7hMvnWBlPhCfQKEoBLXonq2dXCxjOdT6z2AGGfmtmU9a6WH36T5NoA2nETO8sMSNrkXh pKUmFYIFbXw2K64Oj5aQs913dP4Fu416V+0nbcS0fUAlF5v/2A5OyRCxNLXL3lToktUO dM4A== X-Gm-Message-State: AOAM530Rp3u9dFoI+Q9Z3o82ZSV31qiRKWVeGglQcTVwNtDG30ypVvhk b3YQCLoTOhjCop4JQZXzRVM= X-Google-Smtp-Source: ABdhPJwm2Uhq/CQRAF92urwcv6L88GUNudhEcyLu0B+U5S/w5xyex2JL2hdhIH3QE1zKZQPNIsD8yQ== X-Received: by 2002:a17:90a:1b0d:: with SMTP id q13mr18355261pjq.14.1643355255539; Thu, 27 Jan 2022 23:34:15 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:34:14 -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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 5/7] net: ipv4: use kfree_skb_reason() in ip_protocol_deliver_rcu() Date: Fri, 28 Jan 2022 15:33:17 +0800 Message-Id: <20220128073319.1017084-6-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 2d712459d564..4e55321e2fc2 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 184decb1c8eb..74c090f6eb9d 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 Fri Jan 28 07:33:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728044 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 20CF8C433FE for ; Fri, 28 Jan 2022 07:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346863AbiA1HeX (ORCPT ); Fri, 28 Jan 2022 02:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346864AbiA1HeV (ORCPT ); Fri, 28 Jan 2022 02:34:21 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5131DC061714; Thu, 27 Jan 2022 23:34:21 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id p125so4520899pga.2; Thu, 27 Jan 2022 23:34: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=QEz/fR/kaAPRecC/ASB8IHjUXrfH/nHr4967v0vTry4=; b=bVawaxhlDmF7c5DXcKiqKXJwHskxaWW7d3rf1xBobbidvTqNQvbo/bOwcXzETjx3Yg cD4+RcKE8vE0BdYFQ/vc9dePLLnLhzdUOStNfk00qj1huE/Fy2ra9NCOvvIGPGtO8QZb Cwx0+gW+VXczlD3tnDXgPdy74IBSVPJirvHR18CcebSAOBG6UKYA3Lazuon0aethEjAX GuPn0g9T+GAmt+Fyj6ORpRdEoERIdQ6pWNEviRc7pw6Z2haLkUU2HimOR89Qe3yv7A3I Gdk+nv9p5wCHu0Uf66hVyP6ZnJNvwKekMH/wWrkJvhePo8bLvhp62XmKYGQBhGTecYQ9 g+7w== 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=QEz/fR/kaAPRecC/ASB8IHjUXrfH/nHr4967v0vTry4=; b=uQciThMf4JzR7jRlONUJ4wYBAdXSHxAUPpTJ0oSG2yO8/GUskHi0grGZMwA6n4IkHi KjIJQ0MP/69MlSbG3Jkjw1OsAFl8g6bs+2IYGbJBZNYFceio1HKd6GchP+kROQqRir4N u0qxzZK0/woiax5zfANVf32t54THmldA8HAB30rg8l7LsBYf9kl3nRtNcFKpzI1Ztge3 czBk6gcSXjYahNUlHnOXMx/kW4w3MxjGJor1J+jvWcmKikxJOe27k8VgOWjw46sA5MaD G2z9bnO4mwPaNCFyWX937KsusaYko2LzaoWmEG0NMW2NX0DP0m/KWKwqDh1c8o3tMY6H MBIw== X-Gm-Message-State: AOAM531qpgIBE3IgSjdNsIyJy8/AH6Nhebq1reBB4CpL4rh70gP7t8M/ Ojo3c6OIrnQnamK+cjWoWqM= X-Google-Smtp-Source: ABdhPJypfmnJSTGgY9+fR+xJEIZx5K/DVOCyEwhRg88ClziyvjdGXoAIH8S9kNYYlQCq1iLIKL/yBA== X-Received: by 2002:a65:4584:: with SMTP id o4mr5698621pgq.38.1643355260871; Thu, 27 Jan 2022 23:34:20 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:34: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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 6/7] net: udp: use kfree_skb_reason() in udp_queue_rcv_one_skb() Date: Fri, 28 Jan 2022 15:33:18 +0800 Message-Id: <20220128073319.1017084-7-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 464590ea922e..9e28e76e95b8 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 Fri Jan 28 07:33:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12728045 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 E145EC433EF for ; Fri, 28 Jan 2022 07:34:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346879AbiA1He1 (ORCPT ); Fri, 28 Jan 2022 02:34:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346875AbiA1He0 (ORCPT ); Fri, 28 Jan 2022 02:34:26 -0500 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 9451AC061714; Thu, 27 Jan 2022 23:34:26 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id o64so5739971pjo.2; Thu, 27 Jan 2022 23:34:26 -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=SyLy03L5E+1xwc8EXhn4C+jar44ebU6XLc4ynxHGN9A=; b=hs0ZieHX3P+Ur5/kTsSmPWc89YJS76x2Xe8NYGWDN42s3r3hatnAXzyhC6OlelmxKm +Zze13DIudgceBjft27kPy1d7D7FkojbV+bqxR/QFDA97JNquJGy6XxjcfJZX6kZKcpf WiH4JG19XI6xi276Op0qAlFst8dFTVa5oGEF1Pt6ccAsNu+OPODcCE8bcrCQ1y97unji mh7C3BQUvVsW7WYzuqu/jzJK8YjhJtUcCHpvCbM8gLXaVxY/vgKDH4KIs1LCqi6Nao2t S57+xncbg2MVKUAyrHXYilaFuRUmlXXzIIYF/WIe4UaibIf1ZJQAzb/k2fn7SzQlmMkQ lUog== 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=SyLy03L5E+1xwc8EXhn4C+jar44ebU6XLc4ynxHGN9A=; b=qBP0TW7lD35BHLpkP125QUl7SrXmhVfKTyiuSWR71shVOfQLg0y7LfpxpGHTDyaR1b 0XrCgOYXDFQgyeRDSFivKx+qAhDyk1/aKnWaJy8IWh9600mNc6ovf7CXe5cGSBvZ1lsN VeIwZ7UdCo3EUaIyIal0cHXgF8FP3XMsITdyD5WmsIiFIZ5aTx+gxiQtkeea2dWEhP49 jWCV+oDSPGaxEi0h6XyRJOMHxIaEk2TSFBeo2gruHM7JGGp9YdYHJazZH9NuU9ZG3LWa A60D5WTLGfLZ8nMNpEGdIVBN4Wxv4rhWjtjLGaa1wKjMi+L2Ql4CGiuIFOdK8jVNOXAv NBXg== X-Gm-Message-State: AOAM530ezODD604rfakCawd5lEo8MhoTH4LepZTKCNENgCJFo3bj9QJ1 POqQBVHfb+bRwlD55U1noXI= X-Google-Smtp-Source: ABdhPJxvcDEt15uVKbvRMB+R9pm2JYVGpkpqB9V8hVegbJbYZJKACnh87ITvYs0yF8GDZTmHWNtGyQ== X-Received: by 2002:a17:90b:118d:: with SMTP id gk13mr8553381pjb.119.1643355266232; Thu, 27 Jan 2022 23:34:26 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id q17sm8548846pfu.160.2022.01.27.23.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 23:34:25 -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, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, keescook@chromium.org, talalahmad@google.com, haokexin@gmail.com, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com, mengensun@tencent.com Subject: [PATCH v3 net-next 7/7] net: udp: use kfree_skb_reason() in __udp_queue_rcv_skb() Date: Fri, 28 Jan 2022 15:33:19 +0800 Message-Id: <20220128073319.1017084-8-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220128073319.1017084-1-imagedong@tencent.com> References: <20220128073319.1017084-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 4e55321e2fc2..2390f6e230fb 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 e295f7f38398..1f756bb0bb1f 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; }