From patchwork Wed Apr 13 08:15:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811733 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 C9E50C433F5 for ; Wed, 13 Apr 2022 08:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234004AbiDMIqT (ORCPT ); Wed, 13 Apr 2022 04:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234007AbiDMIqN (ORCPT ); Wed, 13 Apr 2022 04:46:13 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F45E50065; Wed, 13 Apr 2022 01:43:53 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id i24-20020a17090adc1800b001cd5529465aso897413pjv.0; Wed, 13 Apr 2022 01:43:53 -0700 (PDT) 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=TjCHnWvl8314BhFvZchJFv9nGn+6Q04JfjDjral41gY=; b=cuC34s3QX+NGa/jd5bEQk/CusqHzpL4LfM+Vr+iVdL3ofwFP9iJrGp1YRLkNEV6quh TWC5pkh8J8wu84JYWV+g+gTLIG+xHJFkibo+3QXI48gaozhONnFAhMeSOZNOdDC/k+tB YZfzKgP8iYR65v4Sb2cERt2+YPpYsm6FoxSXiIuiYuKD3/QYpZJ+VdxwVXVUDpAQBpEA w/RMSSIm4T6gauVxzrJa+4UfMt3aKgMvOOSJaf40hkrURb4GLDtkk5B7GFZWki/0eBCd r9/y4Tc9LnWv3xSjxcazBEZnUvGYehUT92rVNNz0tn1TIOKM5AHd4y626R1RmS90IdpB 9DoQ== 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=TjCHnWvl8314BhFvZchJFv9nGn+6Q04JfjDjral41gY=; b=gwtudifP0w0Miq/xQczRg1U3aKcOiI2h6cYGJZsXcocH7+PUPNmGJOWfizcU7U5Dpd ttp0lXcJJ1l/WjIPxdiNdpzylo7izoJ4CbyltXGClWyRgPesP1xt4XTbEyeliIL3/eZC FknY8ynJpOhXnjkSEylPOEwDId84m0XcXhCCGtPJPdAv0ZO6GdFcEHv2iCHmqZQMNvVT sW6e377qL58c8H+M3Q8LiDm+8p0UVi2aVqNMPIU0cX7AFLKWwKXrGCl0CNwkILwSETfC UP/rkocBF1CXXirEo/YgQurI0smPIGxnVTC6iwkPEpKb23yuX5LJbXZLwWoZQAfIgpFs LkSg== X-Gm-Message-State: AOAM5329tOhlpyOgOAd0trvK0uttdahnBveREQAyPcn1OdSjgG8jP87E K+pdBhslci6xn2DAMY9srjc= X-Google-Smtp-Source: ABdhPJx2SA8KHzlAA6LuVC8RBDF9+4OXOIS80+Ua1E1Af8cUa5OrW7bik6gDEnHUFyse5JRFv9/8Vg== X-Received: by 2002:a17:90a:a78d:b0:1bc:d11c:ad40 with SMTP id f13-20020a17090aa78d00b001bcd11cad40mr9526152pjq.246.1649839432713; Wed, 13 Apr 2022 01:43:52 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:43:52 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 1/9] skb: add some helpers for skb drop reasons Date: Wed, 13 Apr 2022 16:15:52 +0800 Message-Id: <20220413081600.187339-2-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong In order to simply the definition and assignment for 'enum skb_drop_reason', introduce some helpers. SKB_DR() is used to define a variable of type 'enum skb_drop_reason' with the 'SKB_DROP_REASON_NOT_SPECIFIED' initial value. SKB_DR_SET() is used to set the value of the variable. Seems it is a little useless? But it makes the code shorter. SKB_DR_OR() is used to set the value of the variable if it is not set yet, which means its value is SKB_DROP_REASON_NOT_SPECIFIED. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- include/linux/skbuff.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9b81ba497665..0cbd6ada957c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -450,6 +450,18 @@ enum skb_drop_reason { SKB_DROP_REASON_MAX, }; +#define SKB_DR_INIT(name, reason) \ + enum skb_drop_reason name = SKB_DROP_REASON_##reason +#define SKB_DR(name) \ + SKB_DR_INIT(name, NOT_SPECIFIED) +#define SKB_DR_SET(name, reason) \ + (name = SKB_DROP_REASON_##reason) +#define SKB_DR_OR(name, reason) \ + do { \ + if (name == SKB_DROP_REASON_NOT_SPECIFIED) \ + SKB_DR_SET(name, reason); \ + } while (0) + /* To allow 64K frame to be packed as single skb without frag_list we * require 64K/PAGE_SIZE pages plus 1 additional page to allow for * buffers which do not start on a page boundary. From patchwork Wed Apr 13 08:15:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811734 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 5C428C433FE for ; Wed, 13 Apr 2022 08:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234019AbiDMIqU (ORCPT ); Wed, 13 Apr 2022 04:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234018AbiDMIqS (ORCPT ); Wed, 13 Apr 2022 04:46:18 -0400 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 8627750447; Wed, 13 Apr 2022 01:43:57 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id j8so1350986pll.11; Wed, 13 Apr 2022 01:43:57 -0700 (PDT) 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=/WNILOdnKVUcQWRps0HdDCOJ2Ayw4wZcEI2cZi5xPjA=; b=En4zjQhdSiB0UMqHwU7grNsvnTv94MzrlMNTZCz0VLP2sZZN/cXkBzbeKpoi24nrUS 6sJo4MpCqBLa9P37patLwBt/Fa4mw5UU4LA3y+vHqnrHKRVEApR24/HItSzYnSPaEL/w E+z80EzdxF68OIY7ESQI5iCKBa++y6RCGaldeRvdgkLYbupd5LuWjUs/FiJWqCgesYux 5YwUmP0SH4rNFBT5OALUyaB0wFqLtH00QioNGPxnouPbEJwCHZmNVRb8bDKqScPkyMJb CDj920k6LwCSPuGs1AxB4jYp9yQPkJSx3QvPq/ea+gt6nCPvkywwV5TCnHdAvWok0pGL HQAw== 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=/WNILOdnKVUcQWRps0HdDCOJ2Ayw4wZcEI2cZi5xPjA=; b=2Mdss6QKHXEWqVjRoE88Sxnfl6yWxm0CZQ11KXzEqBy5qiq3Dtaizsd4L8St3k1tk/ XFUEOFsNHkCLXcfsalKhnknyF6xbwThpt87P6zem/Ci+igNsNWrqg0OQ6Y692RjS9+It u8C87DGyp5W4LOdU0euBbZ1BbiPXcES0b70A7Doh46I0RVv0INYQLPcVoVtIAxuUxNnu 0A5Ctb8Nyx23Ifyy2NsFPMOEcxLtgbzwqfmtbneGDXtIwjkJXvchec/ajdc5u0cGVLkV 0q67X+AZnhssmIcT9IUvFa0X9I9loJmCrNyYQBAciXB288kUxITW6dYxuRDkjQkb9sIw 4ycA== X-Gm-Message-State: AOAM531FpfBFTAVJcxs0ZJFPq2bLvvzEueAFTN2QGv0Xwo0bYKhamInW Af2UdTgnAD5OdSLB4q8UaOhlZ/VtsmY= X-Google-Smtp-Source: ABdhPJy9BDgQBpeVXDbGKV1+S82yXRVfb2x4Rxx4IgVLBs9XktLF7OduwJvhB5vzsmlhZkes0HHegw== X-Received: by 2002:a17:902:ce8a:b0:158:7b10:980b with SMTP id f10-20020a170902ce8a00b001587b10980bmr10220024plg.122.1649839437125; Wed, 13 Apr 2022 01:43:57 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:43:56 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 2/9] net: ipv4: add skb drop reasons to ip_error() Date: Wed, 13 Apr 2022 16:15:53 +0800 Message-Id: <20220413081600.187339-3-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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 Eventually, I find out the handler function for inputting route lookup fail: ip_error(). The drop reasons we used in ip_error() are almost corresponding to IPSTATS_MIB_*, and following new reasons are introduced: SKB_DROP_REASON_IP_INADDRERRORS SKB_DROP_REASON_IP_INNOROUTES Isn't the name SKB_DROP_REASON_IP_HOSTUNREACH and SKB_DROP_REASON_IP_NETUNREACH more accurate? To make them corresponding to IPSTATS_MIB_*, we keep their name still. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- include/linux/skbuff.h | 6 ++++++ include/trace/events/skb.h | 2 ++ net/ipv4/route.c | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 0cbd6ada957c..886e83ac4b70 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -447,6 +447,12 @@ enum skb_drop_reason { * 2211, such as a broadcasts * ICMP_TIMESTAMP */ + SKB_DROP_REASON_IP_INADDRERRORS, /* host unreachable, corresponding + * to IPSTATS_MIB_INADDRERRORS + */ + SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding + * to IPSTATS_MIB_INADDRERRORS + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 42647114fffe..0acac7e5a019 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -63,6 +63,8 @@ EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \ EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM) \ EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO) \ + EM(SKB_DROP_REASON_IP_INADDRERRORS, IP_INADDRERRORS) \ + EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 98c6f3429593..0b581ee5c000 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -945,6 +945,7 @@ static int ip_error(struct sk_buff *skb) struct inet_peer *peer; unsigned long now; struct net *net; + SKB_DR(reason); bool send; int code; @@ -964,10 +965,12 @@ static int ip_error(struct sk_buff *skb) if (!IN_DEV_FORWARD(in_dev)) { switch (rt->dst.error) { case EHOSTUNREACH: + SKB_DR_SET(reason, IP_INADDRERRORS); __IP_INC_STATS(net, IPSTATS_MIB_INADDRERRORS); break; case ENETUNREACH: + SKB_DR_SET(reason, IP_INNOROUTES); __IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES); break; } @@ -983,6 +986,7 @@ static int ip_error(struct sk_buff *skb) break; case ENETUNREACH: code = ICMP_NET_UNREACH; + SKB_DR_SET(reason, IP_INNOROUTES); __IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES); break; case EACCES: @@ -1009,7 +1013,7 @@ static int ip_error(struct sk_buff *skb) if (send) icmp_send(skb, ICMP_DEST_UNREACH, code, 0); -out: kfree_skb(skb); +out: kfree_skb_reason(skb, reason); return 0; } From patchwork Wed Apr 13 08:15:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811735 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 64E61C433EF for ; Wed, 13 Apr 2022 08:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234066AbiDMIqe (ORCPT ); Wed, 13 Apr 2022 04:46:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234030AbiDMIqW (ORCPT ); Wed, 13 Apr 2022 04:46:22 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38C050451; Wed, 13 Apr 2022 01:44:01 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id bo5so1400883pfb.4; Wed, 13 Apr 2022 01:44:01 -0700 (PDT) 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=4o5EcjhV1ntEcnMfw6o2JdoUkLMHz1SETARxygG+inQ=; b=KVz8cgc3YDNrRA0ZTjAV9MopFjQyAe4MAoEAX0TfcoQLlX8UgjSxubDBxK/gk2hCGm TCq+lqj1a1rKFgqgv6MHJMq/pOJm/1bC5ur14LZyoocPqImthkavYdbCkOT5lhPnZ+V+ E8SfYfMGhnN311ep8JcC+OliD7Wkmp0kWDUn4MqCN+tDWgRGibArCFo9GbR8vk2hLxKA 3U7PIEAmv8uYHMsvaYX3jUHKc8gajGmm5ZKfOvXa4hGMSySE7WzjohAWap2+kg1doq9y nGQso623acNpcPOCcNIxyvhCf/7eg5Xp7LZuDmz2oHIXzLcNvYgLOpqPaRU7VzQ9EhL3 /c9w== 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=4o5EcjhV1ntEcnMfw6o2JdoUkLMHz1SETARxygG+inQ=; b=ylC5z+jJ21o3ixpywQnePavftxxG22aWtk/ZUTp77tYBZdTcK7JetQ2WaTe7ATAqjM 3tHXvDndJtwCumI1C0k1MSmFUOvpaI1YhKV8GfHmJGnTqzlK3frZ4gQ2bQOWS5ujo35T LIiDlsZ+XfOcJCLqQMmjDRe/1qpGSXj37TvEzCQyqtnuEV/XEw2vmiAlufJZHi3u8TX8 hMG8FAYoFJUCkq8tJgXZpWAMYcRRRY5mvputV+9q9FyEZMt7RnJ5rPycPiwFIjl8dENQ 7WGEy0uLfRgbHgPJMozF+h9cr1nuG7shQKEQAbtrcmKAyXGTLku+4mwUh1Iq8z/vBtfP RpRw== X-Gm-Message-State: AOAM530djTYOmAZgJ2vpzUpFGehEDQDgKL17Tci2nqXRurn40Ac4G1fn y1IUHd1u9B2aPpQy0aKqDNo= X-Google-Smtp-Source: ABdhPJzWt1ssM6+YxN1n7evbSBKW+yeV//8jQPxQfwQ8OSWECmKMvfdeb/sQYW5feDXYKgGtiTljnA== X-Received: by 2002:a62:3341:0:b0:505:a1d2:fbe6 with SMTP id z62-20020a623341000000b00505a1d2fbe6mr19849327pfz.9.1649839441521; Wed, 13 Apr 2022 01:44:01 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:01 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 3/9] net: ipv6: add skb drop reasons to ip6_pkt_drop() Date: Wed, 13 Apr 2022 16:15:54 +0800 Message-Id: <20220413081600.187339-4-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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() used in ip6_pkt_drop() with kfree_skb_reason(). No new reason is added. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- net/ipv6/route.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 169e9df6d172..9471ab4421c8 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4482,6 +4482,7 @@ static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes) struct dst_entry *dst = skb_dst(skb); struct net *net = dev_net(dst->dev); struct inet6_dev *idev; + SKB_DR(reason); int type; if (netif_is_l3_master(skb->dev) || @@ -4494,11 +4495,14 @@ static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes) case IPSTATS_MIB_INNOROUTES: type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); if (type == IPV6_ADDR_ANY) { + SKB_DR_SET(reason, IP_INADDRERRORS); IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS); break; } + SKB_DR_SET(reason, IP_INNOROUTES); fallthrough; case IPSTATS_MIB_OUTNOROUTES: + SKB_DR_OR(reason, IP_OUTNOROUTES); IP6_INC_STATS(net, idev, ipstats_mib_noroutes); break; } @@ -4508,7 +4512,7 @@ static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes) skb_dst_drop(skb); icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0); - kfree_skb(skb); + kfree_skb_reason(skb, reason); return 0; } From patchwork Wed Apr 13 08:15:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811736 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 0CEDCC433EF for ; Wed, 13 Apr 2022 08:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229502AbiDMIqr (ORCPT ); Wed, 13 Apr 2022 04:46:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234048AbiDMIqd (ORCPT ); Wed, 13 Apr 2022 04:46:33 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D6450E32; Wed, 13 Apr 2022 01:44:06 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 32so1186381pgl.4; Wed, 13 Apr 2022 01:44:06 -0700 (PDT) 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=g2uGX3AJpOqUTdBgIa4AzRYdxv6dc20RcbYbquov+3M=; b=j7Vp2QiBGWmgO/BsTPDq/NWAuOPlBJHVPcw+bnEH9wgsVb9etOZJiFGArTYdCLPW2D xv836atZIdezpmT/5ZKc7NrQZDoEgTC2wtrQn6TC7+CMCBAOOva1S2tLciuuv7xiyBbG AUyuKHDgJePte3lwB3bL1AhzC7LGiJmfWc9uL5tRO1wtoClQnGH1jLsDUsXhHdoE9zF7 smg32EtM5qQXc3CbT6quKgn/vYcmVtZC6tGyr4Yg+99+TEjMYP9fqFjMd4G9iH9qU8/X RFcNMm3XEJ3xTrkGToYF1/JafDqhIry0qBHkdKmv8BqrP3MSRD2x8z9Ky7bOfFpntDpD D43A== 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=g2uGX3AJpOqUTdBgIa4AzRYdxv6dc20RcbYbquov+3M=; b=ZjfmY9zxU7TS7c0wzuci4kKAu7uUFTSlhAkWMYli/91iw7ZQJcsE3VqZ5nXcgmp4PO 9prwyxRr0Hy2VNarKt/MfpBbZk9Clhm80nZZ6ZwaGjjKH+Dz9iHckOCYP9PU6oqvbHYF LVxMgYztNdNP4aCKHNPmICN+QM1tnw6+++j+mO0pG91ky8MwURTYD7WY73kVvCZgLzqR ZXE92yQluZw0tjdxLCvLCp6qRFLxT/hu4njqFvPytXM9t5BEm1JQSxXP/aidcO5k5UkJ dG48pTOBGCXlt28+/lR2LmtfEAiTu3+ZZWD/Io828gkUTOKxWKXgES8BJeIul9fnMcsQ eLaQ== X-Gm-Message-State: AOAM5319vI1KQMtVM89+eyBNfhWWtlHjs9OTHDgol3V8BFz3wFA3DZkG 6ph8ad55Sk2EGQbjMZBEYKU= X-Google-Smtp-Source: ABdhPJzfcEMfKn1etm+JcZXu/yPxcVNR6LpMlsMmyd+4wyYNsYAMIMnNyOaw7oKkBYSTBhcuOg/qZw== X-Received: by 2002:a63:fe45:0:b0:39c:e41e:b7d4 with SMTP id x5-20020a63fe45000000b0039ce41eb7d4mr23235014pgj.226.1649839445934; Wed, 13 Apr 2022 01:44:05 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:05 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 4/9] net: ip: add skb drop reasons to ip forwarding Date: Wed, 13 Apr 2022 16:15:55 +0800 Message-Id: <20220413081600.187339-5-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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() which is used in ip6_forward() and ip_forward() with kfree_skb_reason(). The new drop reason 'SKB_DROP_REASON_PKT_TOO_BIG' is introduced for the case that the length of the packet exceeds MTU and can't fragment. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 1 + net/ipv4/ip_forward.c | 13 ++++++++++--- net/ipv6/ip6_output.c | 9 ++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 886e83ac4b70..0ef11df1bc67 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -453,6 +453,9 @@ enum skb_drop_reason { SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding * to IPSTATS_MIB_INADDRERRORS */ + SKB_DROP_REASON_PKT_TOO_BIG, /* packet size is too big (maybe exceed + * the MTU) + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 0acac7e5a019..2da72a9a5764 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -65,6 +65,7 @@ EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO) \ EM(SKB_DROP_REASON_IP_INADDRERRORS, IP_INADDRERRORS) \ EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \ + EM(SKB_DROP_REASON_PKT_TOO_BIG, PKT_TOO_BIG) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index 92ba3350274b..e3aa436a1bdf 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c @@ -90,6 +90,7 @@ int ip_forward(struct sk_buff *skb) struct rtable *rt; /* Route we use */ struct ip_options *opt = &(IPCB(skb)->opt); struct net *net; + SKB_DR(reason); /* that should never happen */ if (skb->pkt_type != PACKET_HOST) @@ -101,8 +102,10 @@ int ip_forward(struct sk_buff *skb) if (skb_warn_if_lro(skb)) goto drop; - if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb)) + if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb)) { + SKB_DR_SET(reason, XFRM_POLICY); goto drop; + } if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb)) return NET_RX_SUCCESS; @@ -118,8 +121,10 @@ int ip_forward(struct sk_buff *skb) if (ip_hdr(skb)->ttl <= 1) goto too_many_hops; - if (!xfrm4_route_forward(skb)) + if (!xfrm4_route_forward(skb)) { + SKB_DR_SET(reason, XFRM_POLICY); goto drop; + } rt = skb_rtable(skb); @@ -132,6 +137,7 @@ int ip_forward(struct sk_buff *skb) IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); + SKB_DR_SET(reason, PKT_TOO_BIG); goto drop; } @@ -169,7 +175,8 @@ int ip_forward(struct sk_buff *skb) /* Tell the sender its packet died... */ __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); + SKB_DR_SET(reason, IP_INHDR); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return NET_RX_DROP; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index e23f058166af..3e729cee6486 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -469,6 +469,7 @@ int ip6_forward(struct sk_buff *skb) struct inet6_skb_parm *opt = IP6CB(skb); struct net *net = dev_net(dst->dev); struct inet6_dev *idev; + SKB_DR(reason); u32 mtu; idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); @@ -518,7 +519,7 @@ int ip6_forward(struct sk_buff *skb) icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); return -ETIMEDOUT; } @@ -537,6 +538,7 @@ int ip6_forward(struct sk_buff *skb) if (!xfrm6_route_forward(skb)) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); + SKB_DR_SET(reason, XFRM_POLICY); goto drop; } dst = skb_dst(skb); @@ -596,7 +598,7 @@ int ip6_forward(struct sk_buff *skb) __IP6_INC_STATS(net, idev, IPSTATS_MIB_INTOOBIGERRORS); __IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_FRAGFAILS); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG); return -EMSGSIZE; } @@ -618,8 +620,9 @@ int ip6_forward(struct sk_buff *skb) error: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS); + SKB_DR_SET(reason, IP_INADDRERRORS); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return -EINVAL; } From patchwork Wed Apr 13 08:15:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811737 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 66002C433EF for ; Wed, 13 Apr 2022 08:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234116AbiDMIq6 (ORCPT ); Wed, 13 Apr 2022 04:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234056AbiDMIqh (ORCPT ); Wed, 13 Apr 2022 04:46:37 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 789D651E4E; Wed, 13 Apr 2022 01:44:11 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id 12so1347604pll.12; Wed, 13 Apr 2022 01:44:11 -0700 (PDT) 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=nn5ehz1JljjQt7PVKp4W3PCmW0VJQ3wpLAJidr2EZYs=; b=PlFjF35CJhi08uwawPP8dRPtW+tR+6lJc9E+xeHa/Cf6Zt9FjNUFK8weQHJx79koic AAZ43x2AkSDzQNPoJMC/HUT8ay0QWLwbg07AI/L2Bqb2ZvPmSR01MQdxhGOZg1eLR57z MvUhe0ebNoEr0Kf36pSluApG9Fw0YEE9ChE8mgz/IUo97nQcAKbwa6B1TMV4D3F1pqoa VxB5i5F/CpLw9oKzitSD0OaO17V71Pub4qzMku17CiyTf8aNqD3u4yEA3v9ueKjnr+RS CzTd9lBzZa9G6yKC7eDmEX/uLIRFfVH0LNRtPci2maQDPKXOuLz1ErkoUOa/mclF0su/ e42A== 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=nn5ehz1JljjQt7PVKp4W3PCmW0VJQ3wpLAJidr2EZYs=; b=tHJobACOLg6nVXL585qGxST1e9Rg64iLwCZsOQSKOCWk53Xf4Q1p0VUcq0WZEsZYdP Lc5vZAod+VHRfpz7guDIKP8+RJePQDOrP2eEnSWXzpW1UZCvOG7OhxBl5Bbk0rT6mly1 f++JaNN4R7/s+XM2iEw9BSTee6PFJWASeSH0cC3kZkW5RqvfS7tcfoOqKv1y+QPmo3rk BR+QPDKFgFwnzRkvG7/ytW+3pIkPx0F6swZz0HRJ7kxJQ6hMg65xzDyh1279N1OAH5To qWaXmr/vmNFcFDKqrJ3YoeLWbfC402RdJquMQ23OaFa4friOiBlWAvGHz9OdtUc4vnvr 5GwQ== X-Gm-Message-State: AOAM532A2IOyyWu5QlwvffxDiF5OodsXO/+JHAXS4u39UEH8wEpPlVly IwWROiZQh4ya8aHNCTueGZw= X-Google-Smtp-Source: ABdhPJypLUHh89foqY9qeVvhHumtO4WjZ7j/ZWCWVVQCnp7lvugij82PIvDmTN6s0div6fPSJCjVTw== X-Received: by 2002:a17:902:d88a:b0:156:1609:1e62 with SMTP id b10-20020a170902d88a00b0015616091e62mr41577476plz.143.1649839450332; Wed, 13 Apr 2022 01:44:10 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:09 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 5/9] net: icmp: introduce function icmpv6_param_prob_reason() Date: Wed, 13 Apr 2022 16:15:56 +0800 Message-Id: <20220413081600.187339-6-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong In order to add the skb drop reasons support to icmpv6_param_prob(), introduce the function icmpv6_param_prob_reason() and make icmpv6_param_prob() an inline call to it. This new function will be used in the following patches. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- include/linux/icmpv6.h | 11 +++++++++-- net/ipv6/icmp.c | 7 ++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/icmpv6.h b/include/linux/icmpv6.h index 9055cb380ee2..db0f4fcfdaf4 100644 --- a/include/linux/icmpv6.h +++ b/include/linux/icmpv6.h @@ -79,8 +79,9 @@ extern int icmpv6_init(void); extern int icmpv6_err_convert(u8 type, u8 code, int *err); extern void icmpv6_cleanup(void); -extern void icmpv6_param_prob(struct sk_buff *skb, - u8 code, int pos); +extern void icmpv6_param_prob_reason(struct sk_buff *skb, + u8 code, int pos, + enum skb_drop_reason reason); struct flowi6; struct in6_addr; @@ -91,6 +92,12 @@ extern void icmpv6_flow_init(struct sock *sk, const struct in6_addr *daddr, int oif); +static inline void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos) +{ + icmpv6_param_prob_reason(skb, code, pos, + SKB_DROP_REASON_NOT_SPECIFIED); +} + static inline bool icmpv6_is_err(int type) { switch (type) { diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 01c8003c9fc9..61770220774e 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -629,12 +629,13 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, } EXPORT_SYMBOL(icmp6_send); -/* Slightly more convenient version of icmp6_send. +/* Slightly more convenient version of icmp6_send with drop reasons. */ -void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos) +void icmpv6_param_prob_reason(struct sk_buff *skb, u8 code, int pos, + enum skb_drop_reason reason) { icmp6_send(skb, ICMPV6_PARAMPROB, code, pos, NULL, IP6CB(skb)); - kfree_skb(skb); + kfree_skb_reason(skb, reason); } /* Generate icmpv6 with type/code ICMPV6_DEST_UNREACH/ICMPV6_ADDR_UNREACH From patchwork Wed Apr 13 08:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811738 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 8305BC433F5 for ; Wed, 13 Apr 2022 08:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234152AbiDMIrA (ORCPT ); Wed, 13 Apr 2022 04:47:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234077AbiDMIql (ORCPT ); Wed, 13 Apr 2022 04:46:41 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 366BCB03; Wed, 13 Apr 2022 01:44:15 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id i184so706675pgc.2; Wed, 13 Apr 2022 01:44:15 -0700 (PDT) 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=MVbrPBlxN8h17y1KsP/PN+Nejk6/bRtqjvJZhHhRwMs=; b=XJHs72Fp3OyZEueuBD6LQUSPFpvkPqZAPZs4YzL9ZahWRvFn2XFuf+b3JRw8N2yESm +RhBGRoqZ2DjwNid4WdcR5uwBa8AgkCfyzj/iBhtbKd/3D/C9h9c8LbYh0aKVfPRypPP dhJyL5TVlhDrNiwJlAkrCDqBKCyzel8TxKA/c84DM7g5/x9gGfoIEBtEnH1x4SroLaBo +mqnXBVuwHUXWH7BsO4vqV+s/o6tOquoRqa8Lic2TuN866Vz0EdDYIgUDhVx3KYJQYFZ 12w3hMRzWL2k5GLMyBa1FGpQ2ZCtE6Bk/mVk/uvOltT5FcMNo41nh50sjowHa5j462/D fYGQ== 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=MVbrPBlxN8h17y1KsP/PN+Nejk6/bRtqjvJZhHhRwMs=; b=u8ne8Vnqm/MkbNg4bMvYL3TRcZVC+J11yxRWYAv4mEe5JrEfGmFdiinm9qx7PKvfef 7mCtoeD567Fa+RR7kaZPLKyvgj2rutCVqrmyg6WPiZQ07pHlH8L939vTkoEupwuW6CrJ zdQT+QQkeVwJWsIGH0VCPtcKDd4omX6i1+EDCT7zi6P8KTk1bbNaaQVHb2zxL8w5RTR8 OTPFDqj5p7MS5zttLVeyYTZwU+IeotvaiEQt2Li0FJDG4UGnIH2JV0EquSQuqRJ+cG09 Feqk8mY7UNrZrYu1G39jQwj92BB9wQQ8/RPaDU+yJPtya4aqgaT8A1xK8j1eTFmOzdr7 Su/g== X-Gm-Message-State: AOAM533+gULWxjxbnoodqxxpdCU0gqa/m/GvZGY/x9h9Dz7D8ctIrnKG qvNr2+yaAUCxx+Z7bWwhJw8= X-Google-Smtp-Source: ABdhPJwUM1suuPOtUWt4lxBcbo++OrJB9f5Qc59Wfi9t5epfJ/wuwAkZ/Uc9i9ENyN1/uSd9EF36RA== X-Received: by 2002:a63:bd49:0:b0:39d:a2d3:94a2 with SMTP id d9-20020a63bd49000000b0039da2d394a2mr4495387pgp.242.1649839454726; Wed, 13 Apr 2022 01:44:14 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:14 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 6/9] net: ipv6: remove redundant statistics in ipv6_hop_jumbo() Date: Wed, 13 Apr 2022 16:15:57 +0800 Message-Id: <20220413081600.187339-7-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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 There are two call chains for ipv6_hop_jumbo(). The first one is: ipv6_destopt_rcv() -> ip6_parse_tlv() -> ipv6_hop_jumbo() On this call chain, the drop statistics will be done in ipv6_destopt_rcv() with 'IPSTATS_MIB_INHDRERRORS' if ipv6_hop_jumbo() returns false. The second call chain is: ip6_rcv_core() -> ipv6_parse_hopopts() -> ip6_parse_tlv() And the drop statistics will also be done in ip6_rcv_core() with 'IPSTATS_MIB_INHDRERRORS' if ipv6_hop_jumbo() returns false. Therefore, the statistics in ipv6_hop_jumbo() is redundant, which means the drop is counted twice. The statistics in ipv6_hop_jumbo() is almost the same as the outside, except the 'IPSTATS_MIB_INTRUNCATEDPKTS', which seems that we have to ignore it. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- net/ipv6/exthdrs.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 658d5eabaf7e..31318ee62d29 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -997,33 +997,26 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff) { const unsigned char *nh = skb_network_header(skb); - struct inet6_dev *idev = __in6_dev_get_safely(skb->dev); - struct net *net = ipv6_skb_net(skb); u32 pkt_len; if (nh[optoff + 1] != 4 || (optoff & 3) != 2) { net_dbg_ratelimited("ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n", nh[optoff+1]); - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); goto drop; } pkt_len = ntohl(*(__be32 *)(nh + optoff + 2)); if (pkt_len <= IPV6_MAXPLEN) { - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2); return false; } if (ipv6_hdr(skb)->payload_len) { - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff); return false; } - if (pkt_len > skb->len - sizeof(struct ipv6hdr)) { - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INTRUNCATEDPKTS); + if (pkt_len > skb->len - sizeof(struct ipv6hdr)) goto drop; - } if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) goto drop; From patchwork Wed Apr 13 08:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811739 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 CF6A3C433FE for ; Wed, 13 Apr 2022 08:44:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbiDMIrC (ORCPT ); Wed, 13 Apr 2022 04:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234095AbiDMIql (ORCPT ); Wed, 13 Apr 2022 04:46:41 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A439ABC16; Wed, 13 Apr 2022 01:44:19 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id mm4-20020a17090b358400b001cb93d8b137so5612959pjb.2; Wed, 13 Apr 2022 01:44:19 -0700 (PDT) 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=b14oDzmADLnQU0iBJxS2XBsLb3tdT7kefJ5hMiFLNcI=; b=hI+f1rG27+qJMi49u/tnSWDrnWOUHvZJCtMugo7el9sl7sH6yGt45i6ip4XrgOT3Hq qpKvSxvExKDpSIOR5/mKF+/f/r/c8IELVw21Q/dIxnDbv8QXzgmrEVUj1xGg30jBiGC8 MR28i8h6h8NRhNJaWzuKt1Hitn0ceGeQSad0DxhlX5j+IYyAOfUBWrQvT80OwHw7JhWr t7lNyF95h21M49VBFGXGa9zaQA/NaoeJH2OpCU+WJhHUUKNAOle5kaeSc9fuvxqlRzk9 CQG+ovzQ8mNkFFFbqAQsl/osG5W4bC3IHMPtTC3rh4IYXnTQGc0DYrCRhDDJNyAtjsWF AN/g== 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=b14oDzmADLnQU0iBJxS2XBsLb3tdT7kefJ5hMiFLNcI=; b=3cYjm9JA8NvjQGugoX9efXHYHynO5i+aBRK38crqCeGRCX9TmCUvNbh9s9HzuVwo7A xrYwTbQUd7kB2T9If7iGhDxTLPkRdSTreFOxkTPFuiUpL30uQI4qFP0MIVTwosa9UCjX 86E39azAgQ+d1A2QcKxG8nnZA2vJpmVIn4w+E3+QwtyYka89ZTsL2fq5/s5wfbzoFkLI biixwoZPRxLX120m9TKtzmPrmaVVWLzxZeNt21zjzR4IUaoXST1maSWSRbeLKdXrPibi wnejY9VbrEiklbTVh8QtOYPULYrOltIbQhDp6n4BLjXeAt8us2/pru/qaJ3iVcOmv9FV 8f+Q== X-Gm-Message-State: AOAM532MPrbkEIu2iM6OwVRaWujrINVNIZhZHTWpEjb7QT5lvH7+lo9x s8jyfGUwCVrgR+2RKhCZ9bc= X-Google-Smtp-Source: ABdhPJwRUcYPIeZqzrrcSKdRmAml0um0S/cgQN1UijpYsiiP+gASuihj5Uk6CoS8CA+PmoufOE4g7w== X-Received: by 2002:a17:902:c2d8:b0:154:2946:4ff with SMTP id c24-20020a170902c2d800b00154294604ffmr41555931pla.99.1649839459225; Wed, 13 Apr 2022 01:44:19 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:18 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 7/9] net: ipv6: add skb drop reasons to TLV parse Date: Wed, 13 Apr 2022 16:15:58 +0800 Message-Id: <20220413081600.187339-8-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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() used in TLV encoded option header parsing with kfree_skb_reason(). Following functions are involved: ip6_parse_tlv() ipv6_hop_ra() ipv6_hop_ioam() ipv6_hop_jumbo() ipv6_hop_calipso() ipv6_dest_hao() Most skb drops during this process are regarded as 'InHdrErrors', as 'IPSTATS_MIB_INHDRERRORS' is used when ip6_parse_tlv() fails, which make we use 'SKB_DROP_REASON_IP_INHDR' correspondingly. However, 'IP_INHDR' is a relatively general reason. Therefore, we can use other reasons with higher priority in some cases. For example, 'SKB_DROP_REASON_UNHANDLED_PROTO' is used for unknown TLV options. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- net/ipv6/exthdrs.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 31318ee62d29..e670cf2fe85d 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -90,12 +90,13 @@ static bool ip6_tlvopt_unknown(struct sk_buff *skb, int optoff, break; fallthrough; case 2: /* send ICMP PARM PROB regardless and drop packet */ - icmpv6_param_prob(skb, ICMPV6_UNK_OPTION, optoff); + icmpv6_param_prob_reason(skb, ICMPV6_UNK_OPTION, optoff, + SKB_DROP_REASON_UNHANDLED_PROTO); return false; } drop: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_UNHANDLED_PROTO); return false; } @@ -218,7 +219,7 @@ static bool ip6_parse_tlv(bool hopbyhop, if (len == 0) return true; bad: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); return false; } @@ -232,6 +233,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) struct ipv6_destopt_hao *hao; struct inet6_skb_parm *opt = IP6CB(skb); struct ipv6hdr *ipv6h = ipv6_hdr(skb); + SKB_DR(reason); int ret; if (opt->dsthao) { @@ -246,19 +248,23 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) if (hao->length != 16) { net_dbg_ratelimited("hao invalid option length = %d\n", hao->length); + SKB_DR_SET(reason, IP_INHDR); goto discard; } if (!(ipv6_addr_type(&hao->addr) & IPV6_ADDR_UNICAST)) { net_dbg_ratelimited("hao is not an unicast addr: %pI6\n", &hao->addr); + SKB_DR_SET(reason, INVALID_PROTO); goto discard; } ret = xfrm6_input_addr(skb, (xfrm_address_t *)&ipv6h->daddr, (xfrm_address_t *)&hao->addr, IPPROTO_DSTOPTS); - if (unlikely(ret < 0)) + if (unlikely(ret < 0)) { + SKB_DR_SET(reason, XFRM_POLICY); goto discard; + } if (skb_cloned(skb)) { if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) @@ -281,7 +287,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) return true; discard: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return false; } #endif @@ -934,7 +940,7 @@ static bool ipv6_hop_ra(struct sk_buff *skb, int optoff) } net_dbg_ratelimited("ipv6_hop_ra: wrong RA length %d\n", nh[optoff + 1]); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); return false; } @@ -988,7 +994,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) return true; drop: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); return false; } @@ -997,26 +1003,32 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff) { const unsigned char *nh = skb_network_header(skb); + SKB_DR(reason); u32 pkt_len; if (nh[optoff + 1] != 4 || (optoff & 3) != 2) { net_dbg_ratelimited("ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n", nh[optoff+1]); + SKB_DR_SET(reason, IP_INHDR); goto drop; } pkt_len = ntohl(*(__be32 *)(nh + optoff + 2)); if (pkt_len <= IPV6_MAXPLEN) { - icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2); + icmpv6_param_prob_reason(skb, ICMPV6_HDR_FIELD, optoff + 2, + SKB_DROP_REASON_IP_INHDR); return false; } if (ipv6_hdr(skb)->payload_len) { - icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff); + icmpv6_param_prob_reason(skb, ICMPV6_HDR_FIELD, optoff, + SKB_DROP_REASON_IP_INHDR); return false; } - if (pkt_len > skb->len - sizeof(struct ipv6hdr)) + if (pkt_len > skb->len - sizeof(struct ipv6hdr)) { + SKB_DR_SET(reason, PKT_TOO_SMALL); goto drop; + } if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) goto drop; @@ -1025,7 +1037,7 @@ static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff) return true; drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return false; } @@ -1047,7 +1059,7 @@ static bool ipv6_hop_calipso(struct sk_buff *skb, int optoff) return true; drop: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR); return false; } From patchwork Wed Apr 13 08:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811741 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 D7E8BC433EF for ; Wed, 13 Apr 2022 08:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234101AbiDMIrP (ORCPT ); Wed, 13 Apr 2022 04:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234103AbiDMIq4 (ORCPT ); Wed, 13 Apr 2022 04:46:56 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE0F340D9; Wed, 13 Apr 2022 01:44:24 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id q19so1180413pgm.6; Wed, 13 Apr 2022 01:44:24 -0700 (PDT) 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=C1EWK9eoSuI/9QQ/ZExq3hXbMv6fm1L8pBD1vk2oFeY=; b=A3ObKFOxl+0/AdK6Yu014z7zSB1v0SxjLRHcyy9i9VFwliZvTtzPwVlwD/rozFZ7ru HGR/Nv2GU3Uru0f9FdjJZfhEV/BvO74JLc3oe7usbkHyQLdxGsM4In++pCessoUJZ5YY NyS58xtquQCon4krYZLbr0xvf2w3eer1U7eidcYVMxH2P5s5niwNm8E1iLUYN9ctJDxr olpM2UX0sLWcrwuFgMnUkuhBBit6mY1SYqyLbk5y3O9Y+f+D6WogUKQnDPYSgDJ/ZvTt ZKNI0HWYDEA7UjGO2wTD1L3RF+d4otUicX93ZBEakZrkea41BBtNOyC+nP/GO1EC5xam T/6A== 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=C1EWK9eoSuI/9QQ/ZExq3hXbMv6fm1L8pBD1vk2oFeY=; b=R8Or/QAopY5FjFcxtrSgAsAm2pu5TxTBzQ4vFPTiUkZWqTt6/A065IWnctdR++nNDl E/iy3h6YegFmGkbAE7qnrZT4119fAXwCvirx/zuMsB/yQVcSzxYRrTheC1BKUU/gTdJv nAzamf/Q9fBFgG3hrJYm0DC5aQD6mMiTF4/7AI+cmcPaV3aI38mNztfx3Bzmks4wXwtB +/Dng7qW8vHaXKMuQ7uQUtdlheThLNIu/v5S6XpHOtcdI5beP1BrRjrCUpmqTB7BlHvr VE6EuuIPGDVps0wk6Y4J5d/yUFFy6pb493wnsnjgNnEWO2LK2LT1lQyv64WN7Y3DWdBY Az/A== X-Gm-Message-State: AOAM530nxIs/VO7+zv1vfkm2PGJn++VYp0ceU69z6kJKNKKtWnXFNjHL paws4RPyWYUSOmucn43woWg= X-Google-Smtp-Source: ABdhPJwNrvCsBiuZrgYEZtLt4IyLJj7imWGi1XpO3h/5S1QQqlHK8fnSKx/djmMh/1rhPopkcATzNw== X-Received: by 2002:a63:5061:0:b0:39c:d0da:677b with SMTP id q33-20020a635061000000b0039cd0da677bmr24063625pgl.599.1649839463724; Wed, 13 Apr 2022 01:44:23 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:23 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 8/9] net: ipv6: add skb drop reasons to ip6_rcv_core() Date: Wed, 13 Apr 2022 16:15:59 +0800 Message-Id: <20220413081600.187339-9-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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() used in ip6_rcv_core() with kfree_skb_reason(). No new drop reasons are added. Seems now we use 'SKB_DROP_REASON_IP_INHDR' for too many case during ipv6 header parse or check, just like what 'IPSTATS_MIB_INHDRERRORS' do. Will it be too general and hard to know what happened? Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- net/ipv6/ip6_input.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index b4880c7c84eb..1b925ecb26e9 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -145,13 +145,14 @@ static void ip6_list_rcv_finish(struct net *net, struct sock *sk, static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, struct net *net) { + enum skb_drop_reason reason; const struct ipv6hdr *hdr; u32 pkt_len; struct inet6_dev *idev; if (skb->pkt_type == PACKET_OTHERHOST) { dev_core_stats_rx_otherhost_dropped_inc(skb->dev); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_OTHERHOST); return NULL; } @@ -161,9 +162,12 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, __IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len); + SKB_DR_SET(reason, NOT_SPECIFIED); if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL || !idev || unlikely(idev->cnf.disable_ipv6)) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); + if (unlikely(idev->cnf.disable_ipv6)) + SKB_DR_SET(reason, IPV6DISABLED); goto drop; } @@ -187,8 +191,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, hdr = ipv6_hdr(skb); - if (hdr->version != 6) + if (hdr->version != 6) { + SKB_DR_SET(reason, UNHANDLED_PROTO); goto err; + } __IP6_ADD_STATS(net, idev, IPSTATS_MIB_NOECTPKTS + @@ -226,8 +232,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, if (!ipv6_addr_is_multicast(&hdr->daddr) && (skb->pkt_type == PACKET_BROADCAST || skb->pkt_type == PACKET_MULTICAST) && - idev->cnf.drop_unicast_in_l2_multicast) + idev->cnf.drop_unicast_in_l2_multicast) { + SKB_DR_SET(reason, UNICAST_IN_L2_MULTICAST); goto err; + } /* RFC4291 2.7 * Nodes must not originate a packet to a multicast address whose scope @@ -256,12 +264,11 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, if (pkt_len + sizeof(struct ipv6hdr) > skb->len) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INTRUNCATEDPKTS); + SKB_DR_SET(reason, PKT_TOO_SMALL); goto drop; } - if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) { - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); - goto drop; - } + if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) + goto err; hdr = ipv6_hdr(skb); } @@ -282,9 +289,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, return skb; err: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); + SKB_DR_OR(reason, IP_INHDR); drop: rcu_read_unlock(); - kfree_skb(skb); + kfree_skb_reason(skb, reason); return NULL; } From patchwork Wed Apr 13 08:16:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12811740 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 E98E0C433EF for ; Wed, 13 Apr 2022 08:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234127AbiDMIrO (ORCPT ); Wed, 13 Apr 2022 04:47:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234123AbiDMIq6 (ORCPT ); Wed, 13 Apr 2022 04:46:58 -0400 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 A52874AE2C; Wed, 13 Apr 2022 01:44:28 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id u2so1168614pgq.10; Wed, 13 Apr 2022 01:44:28 -0700 (PDT) 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=Q3CF2CYyk/KU/cKIRGIDMOGHVL/2+I9I23VjG1uUJC8=; b=CSMXfbjUMzMQUSHDlcY6940ReprM7qI7VMrvYmu6L+uFOM7DoT5aUGa8icSjL4eGYv wCdwhr7PYc5HtsEDZGHhJ2MePSWgmgg8qtGdp2rin2Zm8pN6Cl41cEQ+66wVpHFk/PPD QN9cQe+XT2w7+4QBaMZtRvt7czuI/YwA0obZfwfN72e2mk1l7F7BIsewf7nCo5ZCcdRq 4wpofjJIDIaiGdEDMOpX/PsqZN7FpAlKtlOafykU0F28edsB4JzoovC1RkgfkYkq3PDl AknCMLvf3Fpnn4AoiuO+5g1hVkfspoTf7B4oZO2Hp1xxQVdl79Qfqn+xclZrezquJXjI fAPg== 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=Q3CF2CYyk/KU/cKIRGIDMOGHVL/2+I9I23VjG1uUJC8=; b=bscO76cCV6d2iZXUkgG6ahrMCriC0593Vy60dBWdKwLex4QCPpCkbFRs1ofeDoJ75V i4vnaGoxdotrXVAmTvQx31QWP8e/RXLEs1uU1JKSXd58VYykY94CECao5jH9+YtdnFqS 9VSvM2tW+ulNK24lwLAzX7DcR9/Nk+GuL2IqglXh8NNurS+XbJIW1vJ6AEYHryqpTJ5k IKzoSXpcmnz8bGqy7LqJqon+Du9fczsHv8gwhoChtS9lDR8O011jhBtohk7LiKG1vWCd PAXWShIDcevXWVOz0cU23A9Juc4cK/iCVI1iOz6ncsPoBd5pCRv1l/yBDueVBtuf91EF lGRA== X-Gm-Message-State: AOAM530f9914tkoSY9KchLTDQifalUqZoISoS2e+tofLzgNhI8nzrIFp qauFFm82r56Nia2JNa0LTuY= X-Google-Smtp-Source: ABdhPJwHcdm+jreTHfL7OfNFwhm+bX5jRBwz/tWPt6br+WjRQnxT3R65fOAW2S0C/jOsToIKS7ehGg== X-Received: by 2002:a05:6a00:2354:b0:505:c6c3:af87 with SMTP id j20-20020a056a00235400b00505c6c3af87mr14012849pfj.78.1649839468233; Wed, 13 Apr 2022 01:44:28 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.119]) by smtp.gmail.com with ESMTPSA id l5-20020a63f305000000b0039daaa10a1fsm2410335pgh.65.2022.04.13.01.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 01:44:27 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com, benbjiang@tencent.com, flyingpeng@tencent.com, imagedong@tencent.com, edumazet@google.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, mengensun@tencent.com, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next 9/9] net: ipv6: add skb drop reasons to ip6_protocol_deliver_rcu() Date: Wed, 13 Apr 2022 16:16:00 +0800 Message-Id: <20220413081600.187339-10-imagedong@tencent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220413081600.187339-1-imagedong@tencent.com> References: <20220413081600.187339-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() used in ip6_protocol_deliver_rcu() with kfree_skb_reason(). No new reasons are added. Some paths are ignored, as they are not common, such as encapsulation on non-final protocol. Signed-off-by: Menglong Dong Reviewed-by: Jiang Biao Reviewed-by: Hao Peng --- net/ipv6/ip6_input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 1b925ecb26e9..126ae3aa67e1 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -362,6 +362,7 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, const struct inet6_protocol *ipprot; struct inet6_dev *idev; unsigned int nhoff; + SKB_DR(reason); bool raw; /* @@ -421,12 +422,16 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, if (ipv6_addr_is_multicast(&hdr->daddr) && !ipv6_chk_mcast_addr(dev, &hdr->daddr, &hdr->saddr) && - !ipv6_is_mld(skb, nexthdr, skb_network_header_len(skb))) + !ipv6_is_mld(skb, nexthdr, skb_network_header_len(skb))) { + SKB_DR_SET(reason, IP_INADDRERRORS); goto discard; + } } if (!(ipprot->flags & INET6_PROTO_NOPOLICY) && - !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) + !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { + SKB_DR_SET(reason, XFRM_POLICY); goto discard; + } ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv, skb); @@ -452,8 +457,11 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, IPSTATS_MIB_INUNKNOWNPROTOS); icmpv6_send(skb, ICMPV6_PARAMPROB, ICMPV6_UNK_NEXTHDR, nhoff); + SKB_DR_SET(reason, IP_NOPROTO); + } else { + SKB_DR_SET(reason, XFRM_POLICY); } - kfree_skb(skb); + kfree_skb_reason(skb, reason); } else { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDELIVERS); consume_skb(skb); @@ -463,7 +471,7 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, discard: __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); - kfree_skb(skb); + kfree_skb_reason(skb, reason); } static int ip6_input_finish(struct net *net, struct sock *sk, struct sk_buff *skb)