Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3521056pxb; Mon, 24 Jan 2022 11:17:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxef1wrAwB+HJfABSt6tMuuhAyYMGKt/aytfAF5JDx4JVlcvWp82NfjvDE5xh+qTa0q/fGC X-Received: by 2002:a17:902:7d8f:b0:14a:b712:bbfb with SMTP id a15-20020a1709027d8f00b0014ab712bbfbmr15858891plm.63.1643051876360; Mon, 24 Jan 2022 11:17:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643051876; cv=none; d=google.com; s=arc-20160816; b=X7YMfwyPa0yC8jhfmF499I80lVpfrLaSYYELXynCHJGTvvTLmxsNW/tn2k647hKwhL 0oAay5KOqs+FBuzNUItEhaxPKbMTVX5QtuufSLBonRRLGBhxfSrWxZkRxlYdrJCmwAO6 p/7+iNUSVaYZI7A0M3U8RdoBB3T8Bs5qFkwVD4X/DlW4tEMlZUdHvU/g9O2PDDI6eOrW a68i9IZ1f5oudtoo057hTTE0s/AMi/ODSAfBmI4RpbYxgDAe10cL4FAKUA55v6o7y75O TZ4rimOnRchfNT5l09PjFa6O/MokT7APYiAB+m6HUCP5wkXNQrzwFTbMyrkm9kv6XlJc 6/nw== 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=O88eKXAZyfDbUImGdIOspl+p31sKA6IRKKmfTf5yIqs=; b=XriUxikW/X2g1B+p7fSa0uGLbR9cb6Qlxx3B2aRuqbnTJUqFgUkRb6Ie+AIFiWub0z rlfm6KzjD2XldG1QHaEEkj1Uvu7d4qJrprs7yBk9HnpvF8b6nlVbO53s3XERa8lQQGdp tTBuRgZUeTPrMIDAd0VyaTpIwLAcNmAHYNUIyhFeuZGU3U+lbQyYQULJM7iyGYtoOHLi xx99PIPEiKViAE7yhg0fg/A5XwmbRvsR9Qkq/1x0pnPeV1WEM942YIwEjOEbFsq5sB5F X3CzMIN951YbMxX+ZVFCDg8B2+mfyQeFIDgZQij0liEpNuoituP2keOcQ82FY5SFGH/0 RI3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=E8W5K8vR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e70si14578311pgc.806.2022.01.24.11.17.44; Mon, 24 Jan 2022 11:17:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=E8W5K8vR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S243073AbiAXNQC (ORCPT + 99 others); Mon, 24 Jan 2022 08:16:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243069AbiAXNQA (ORCPT ); Mon, 24 Jan 2022 08:16:00 -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 6719DC061748; Mon, 24 Jan 2022 05:16:00 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id y17so5061049plg.7; Mon, 24 Jan 2022 05:16:00 -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=O88eKXAZyfDbUImGdIOspl+p31sKA6IRKKmfTf5yIqs=; b=E8W5K8vRb2LRLnX2+E+Ey1GWeDfcRPgBRijAMK7lGIH8dVCG/exxweu6oRR4+YFZIV haLSlmPafJFAw2h6C57D62+k7hmXE3VSSfjkIuqz8QIOqB4nn8YAO8j+Xmykcmcgmf/N rDpsaEHpwSnLDiAzRaFb9aRt8YHodLT02g1G0BkdNJjLEd6YBEbf31CqWQ5QMQIWRQ1T SPtBLfXgwfWvRK1Lb9feotDT3z+pUQ8RwKzOtgvpQ2AwsQHWx/czvIWIg7eJkySpXKnZ HFODSbaYvC0oxmunYN2rNIi1pReWeHepWZ2bGGqBIBJjsuPMWoH9FlbtQaRNpD+8QM1b NzbA== 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=O88eKXAZyfDbUImGdIOspl+p31sKA6IRKKmfTf5yIqs=; b=F8v3/BV57UzYb+ferEKEzcFl62/5TrKYznojHQRuSisH2Ez/FlHPRYCHFdkZHti2ij DZKAvBrueps/jactx4rhI7t84/ua56TQPP+nfGSQw6y8c3f169tEDnZSGXEFyrtL4Adl 7mzgXlLqGA6rr11+n7L9lvlzgvQRILGItUQfbzGZFmbWsESa9qr/Q5C+lKvzBAUMw91x 7SEXQOUdvex/8RLtfqJNsz6/kZUW9wkZ9ApneYqno/yxJW0QHdxrFPtkNVvIdyNS7vw+ 7PQLOl6JoTgb/VRkE0wCHGuzYckZ+qn5SZEJQddogffnEqBqyjRnRVu9Xy2Z2fXsUIlg NblA== X-Gm-Message-State: AOAM531pYJj3S26ykMhcT1CrBVog7fqiomDJOeeNTV9SgEuVsIS6Am6U k3+VXidloqFuqgs0ZdM3rGPxrg38Wm4= X-Received: by 2002:a17:90b:1801:: with SMTP id lw1mr1811740pjb.215.1643030160025; Mon, 24 Jan 2022 05:16:00 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:15:59 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 2/6] net: ipv4: use kfree_skb_reason() in ip_rcv_core() Date: Mon, 24 Jan 2022 21:15:34 +0800 Message-Id: <20220124131538.1453657-3-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1bcd690b8ae1..f3028028b83e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -321,6 +321,9 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_FILTER, SKB_DROP_REASON_UDP_CSUM, SKB_DROP_REASON_NETFILTER_DROP, + SKB_DROP_REASON_OTHERHOST, + SKB_DROP_REASON_IP_CSUM, + SKB_DROP_REASON_IP_INHDR, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index beed7bb2bc0e..d1b0d9690e62 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -17,6 +17,9 @@ EM(SKB_DROP_REASON_TCP_FILTER, TCP_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..ab9bee4bbf0a 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); @@ -478,7 +483,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) IPSTATS_MIB_NOECTPKTS + (iph->tos & INET_ECN_MASK), max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs)); - if (!pskb_may_pull(skb, iph->ihl*4)) + if (!pskb_may_pull(skb, iph->ihl * 4)) goto inhdr_error; iph = ip_hdr(skb); @@ -490,7 +495,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) if (skb->len < len) { __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; - } else if (len < (iph->ihl*4)) + } else if (len < (iph->ihl * 4)) goto inhdr_error; /* Our transport medium may have padded the buffer out. Now we know it @@ -516,11 +521,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; } -- 2.34.1