From patchwork Thu Nov 18 12:48:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12626879 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F888C433F5 for ; Thu, 18 Nov 2021 12:49:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1769E60F9B for ; Thu, 18 Nov 2021 12:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344952AbhKRMwf (ORCPT ); Thu, 18 Nov 2021 07:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344833AbhKRMv7 (ORCPT ); Thu, 18 Nov 2021 07:51:59 -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 A6D0EC0613B9; Thu, 18 Nov 2021 04:48:35 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id x131so5873292pfc.12; Thu, 18 Nov 2021 04:48:35 -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=NdeR00iS1+q0mlw4CfCMEaptDLpQYaSCzyT4H3XBiJA=; b=h3AKM1BtFV8aGLzwBa0e0XaAnsMedbBvzhHy8vBkpq8NSJU3/74KBm3YP80rN9i3P9 PKZc9fhiyISa5f6+bnZ1xBSeznjJftdh0fa7K5Me6IseNPOKD7MOExvV7RxQqXuGtLas 4p0RGK6IJyyKzZ+50aSEs/nw9oRfc+MIgL2ky5Cexx4k1C7ahDVKpbq4LqWkAUzrTBPx eWCawHIyZx0NKGdLioCWwXhW+i2Wr/LMKs3ImarQ8RwOBLj/G6mgUVNdLrUPM/ebdMUp WyC7MkwzIW+krd1D41KbcomIHmB75wtEt+ZzDjn2ZEWH/EPJ4zzCwY0hC1usW+y+m0eU 2YPQ== 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=NdeR00iS1+q0mlw4CfCMEaptDLpQYaSCzyT4H3XBiJA=; b=64pomvE19mhZ2I1yHGz1zys4P7gs9KzzonlKtJ7ifAWfzfmbjqHiNUbijPxOIHYjCS nNsUYOAYCrbN4SAEsPpLKAHYbEZdST168VFnXKlFgdVkzeW/WAMwkLpRvLRYjpeeWF4T sPA+doILrs3E3QJJuAPMlGn1I5ZzrNLtLDCl3z/aiurAog1a+pZH5xRLG17DzyJEb+af Cf99wRc2FMc1Gz+4tQYwpRcY2GM7MoJ9QcshXM2DPy/YRW9kLgAi86/dfPsHbBAgPZXv K2GJI1qyGXeDi3sOn64W3Hj/IOMfd+3IjjXpOW8TgOLSPHOOhArr38WT48N4SqfV2nnc 6+DA== X-Gm-Message-State: AOAM530VUPT3mympVQnqIqDBEpnOQu7VcOdC1pUQgTY6cIvAqFC+pfFE khDJ/i0ndaf3z0Gch9I3f+M= X-Google-Smtp-Source: ABdhPJwtTsJFPuKfKAQTCe5MwglX1daGYQJzoZ01Y4fl7KzNims7s0H7HZobtzk7kFQBTRHkDgHjYg== X-Received: by 2002:a63:f611:: with SMTP id m17mr10989154pgh.259.1637239715247; Thu, 18 Nov 2021 04:48:35 -0800 (PST) Received: from desktop.cluster.local ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j16sm3679404pfj.16.2021.11.18.04.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 04:48:34 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org, rostedt@goodmis.org Cc: davem@davemloft.net, mingo@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, ycheng@google.com, kuniyu@amazon.co.jp, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next 1/2] net: snmp: add tracepoint support for snmp Date: Thu, 18 Nov 2021 20:48:11 +0800 Message-Id: <20211118124812.106538-2-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211118124812.106538-1-imagedong@tencent.com> References: <20211118124812.106538-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 snmp is the network package statistics module in kernel, and it is useful in network issue diagnosis, such as packet drop. However, it is hard to get the detail information about the packet. For example, we can know that there is something wrong with the checksum of udp packet though 'InCsumErrors' of UDP protocol in /proc/net/snmp, but we can't figure out the ip and port of the packet that this error is happening on. Add tracepoint for snmp. Therefor, users can use some tools (such as eBPF) to get the information of the exceptional packet. Signed-off-by: Menglong Dong v2: - use a single event, instead of creating events for every protocols --- include/trace/events/snmp.h | 44 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/snmp.h | 21 ++++++++++++++++++ net/core/net-traces.c | 3 +++ 3 files changed, 68 insertions(+) create mode 100644 include/trace/events/snmp.h diff --git a/include/trace/events/snmp.h b/include/trace/events/snmp.h new file mode 100644 index 000000000000..1fa2e31056e0 --- /dev/null +++ b/include/trace/events/snmp.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM snmp + +#if !defined(_TRACE_SNMP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_SNMP_H + +#include +#include +#include + +DECLARE_EVENT_CLASS(snmp_template, + + TP_PROTO(struct sk_buff *skb, int type, int field, int val), + + TP_ARGS(skb, type, field, val), + + TP_STRUCT__entry( + __field(void *, skbaddr) + __field(int, type) + __field(int, field) + __field(int, val) + ), + + TP_fast_assign( + __entry->skbaddr = skb; + __entry->type = type; + __entry->field = field; + __entry->val = val; + ), + + TP_printk("skbaddr=%p, type=%d, field=%d, val=%d", + __entry->skbaddr, __entry->type, + __entry->field, __entry->val) +); + +DEFINE_EVENT(snmp_template, snmp, + TP_PROTO(struct sk_buff *skb, int type, int field, int val), + TP_ARGS(skb, type, field, val) +); + +#endif + +#include diff --git a/include/uapi/linux/snmp.h b/include/uapi/linux/snmp.h index 904909d020e2..b96077e09a58 100644 --- a/include/uapi/linux/snmp.h +++ b/include/uapi/linux/snmp.h @@ -347,4 +347,25 @@ enum __LINUX_MIB_TLSMAX }; +/* mib type definitions for trace event */ +enum { + TRACE_MIB_NUM = 0, + TRACE_MIB_IP, + TRACE_MIB_IPV6, + TRACE_MIB_TCP, + TRACE_MIB_NET, + TRACE_MIB_ICMP, + TRACE_MIB_ICMPV6, + TRACE_MIB_ICMPMSG, + TRACE_MIB_ICMPV6MSG, + TRACE_MIB_UDP, + TRACE_MIB_UDPV6, + TRACE_MIB_UDPLITE, + TRACE_MIB_UDPV6LITE, + TRACE_MIB_XFRM, + TRACE_MIB_TLS, + TRACE_MIB_MPTCP, + __TRACE_MIB_MAX +}; + #endif /* _LINUX_SNMP_H */ diff --git a/net/core/net-traces.c b/net/core/net-traces.c index c40cd8dd75c7..e291c0974438 100644 --- a/net/core/net-traces.c +++ b/net/core/net-traces.c @@ -35,6 +35,7 @@ #include #include #include +#include #if IS_ENABLED(CONFIG_BRIDGE) #include EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_add); @@ -61,3 +62,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(napi_poll); EXPORT_TRACEPOINT_SYMBOL_GPL(tcp_send_reset); EXPORT_TRACEPOINT_SYMBOL_GPL(tcp_bad_csum); + +EXPORT_TRACEPOINT_SYMBOL_GPL(snmp); From patchwork Thu Nov 18 12:48:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12626881 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90C4DC433F5 for ; Thu, 18 Nov 2021 12:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7993860F9B for ; Thu, 18 Nov 2021 12:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344859AbhKRMwh (ORCPT ); Thu, 18 Nov 2021 07:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244060AbhKRMv7 (ORCPT ); Thu, 18 Nov 2021 07:51:59 -0500 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 BBD62C061200; Thu, 18 Nov 2021 04:48:41 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id u11so5151345plf.3; Thu, 18 Nov 2021 04:48:41 -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=ksWSGJgeVNus0Ooytt9o/CsyB2300W+L01WiAzLLh2c=; b=XGKT2t+CF9UWugQ5eGgQWulZA3YZspw9sydRG1jnBqMgdzMfnVxupNQ0/jBaBlmqiB 42fKBj3zuZ0iO981eJnTriYA8diM9lMy94Yi9nFGiWVQD2X24yvGX4TVpUspoiLuQhpn e0HwblkwFfQDU8WYRC3BaFFeiF94ky1e+/tgrhnFhPe8BaGnlcmw0qi3LNI6yU33gCIy Dhb1YM1QSf68eS7hgatgjh15wLqc578cB2ouP9cWgV3dv4F3zb2FrveC6jhc7YDzK2I6 wCbi4YgVm5sM3vjUrzat5BjTgxxI76yjdd4ISVNXRK2pELiLlfmhYBUxY9lTrEDPy50C pMUg== 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=ksWSGJgeVNus0Ooytt9o/CsyB2300W+L01WiAzLLh2c=; b=rEF6XU4jhu8D9hduj2eRzdudd47vEewoyo/lGjxp19QueSZI4EtnGwRCPpBHkHeBY+ ncuLhjnuEZOBrIVIjKMYFnllWlsjosvoawfS1fQNAXk2+DcfnOKmCJ5L5rasfuJw5yTd 7jXprTI7GCHeeM/IDdmzZPgiKXu4avzvTFX2jB16VzI85UHzYTAG54PD+2KundgUHTK8 x7vSqAxXLLfTwu6UdiayznxuUf9eLwNlZmYvPuj0jO5PhfVAqIR0CrTVMMIxaPGtEjlT OxhgUqR0yHxDQ6TP7mKK1288xymvBMN6FHGeCN+Aqm1WPvp/YFVa8yzDjudVYYTwJ0kv Aejg== X-Gm-Message-State: AOAM530cfWmkr3KXpzAyPRQqYBtJG9hbSRvO+PZoJZOyxIRqFkltguB4 LZ+Nw/hyTT9ASHM5BjjAgsI= X-Google-Smtp-Source: ABdhPJwq4N9iEx2sodE0IM5PxTgHLmb388G0DCf0P/puykZEVAyzbZB94eBGceDKvwOPMN2m6jFHhw== X-Received: by 2002:a17:90b:1d0f:: with SMTP id on15mr10380734pjb.144.1637239721346; Thu, 18 Nov 2021 04:48:41 -0800 (PST) Received: from desktop.cluster.local ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j16sm3679404pfj.16.2021.11.18.04.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 04:48:40 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org, rostedt@goodmis.org Cc: davem@davemloft.net, mingo@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, ycheng@google.com, kuniyu@amazon.co.jp, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next 2/2] net: snmp: add snmp tracepoint support for udp Date: Thu, 18 Nov 2021 20:48:12 +0800 Message-Id: <20211118124812.106538-3-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211118124812.106538-1-imagedong@tencent.com> References: <20211118124812.106538-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 snmp tracepoint support for udp. Signed-off-by: Menglong Dong --- include/net/udp.h | 25 +++++++++++++++++++------ net/ipv4/udp.c | 28 +++++++++++++++++----------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/net/udp.h b/include/net/udp.h index f1c2a88c9005..6cf11e0d75b0 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -28,6 +28,7 @@ #include #include #include +#include /** * struct udp_skb_cb - UDP(-Lite) private variables @@ -384,12 +385,24 @@ static inline int copy_linear_skb(struct sk_buff *skb, int len, int off, /* * SNMP statistics for UDP and UDP-Lite */ -#define UDP_INC_STATS(net, field, is_udplite) do { \ - if (is_udplite) SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ - else SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) -#define __UDP_INC_STATS(net, field, is_udplite) do { \ - if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ - else __SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) +#define UDP_INC_STATS(net, field, is_udplite) do { \ + if (is_udplite) { \ + SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ + trace_snmp(skb, TRACE_MIB_UDPLITE, field, 1); \ + } else { \ + SNMP_INC_STATS((net)->mib.udp_statistics, field); \ + trace_snmp(skb, TRACE_MIB_UDP, field, 1); \ + } \ +} while (0) +#define __UDP_INC_STATS(net, skb, field, is_udplite) do { \ + if (is_udplite) { \ + __SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ + trace_snmp(skb, TRACE_MIB_UDPLITE, field, 1); \ + } else { \ + __SNMP_INC_STATS((net)->mib.udp_statistics, field); \ + trace_snmp(skb, TRACE_MIB_UDP, field, 1); \ + } \ +} while (0) #define __UDP6_INC_STATS(net, field, is_udplite) do { \ if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_stats_in6, field);\ diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 7101e6d892d6..66ae9eea65c7 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1648,9 +1648,11 @@ static struct sk_buff *__first_packet_length(struct sock *sk, while ((skb = skb_peek(rcvq)) != NULL) { if (udp_lib_checksum_complete(skb)) { - __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, + __UDP_INC_STATS(sock_net(sk), skb, + UDP_MIB_CSUMERRORS, IS_UDPLITE(sk)); - __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, + __UDP_INC_STATS(sock_net(sk), skb, + UDP_MIB_INERRORS, IS_UDPLITE(sk)); atomic_inc(&sk->sk_drops); __skb_unlink(skb, rcvq); @@ -2143,7 +2145,7 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) ret = encap_rcv(sk, skb); if (ret <= 0) { - __UDP_INC_STATS(sock_net(sk), + __UDP_INC_STATS(sock_net(sk), skb, UDP_MIB_INDATAGRAMS, is_udplite); return -ret; @@ -2201,9 +2203,10 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) return __udp_queue_rcv_skb(sk, skb); csum_error: - __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); + __UDP_INC_STATS(sock_net(sk), skb, UDP_MIB_CSUMERRORS, + is_udplite); drop: - __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); + __UDP_INC_STATS(sock_net(sk), skb, UDP_MIB_INERRORS, is_udplite); atomic_inc(&sk->sk_drops); kfree_skb(skb); return -1; @@ -2290,9 +2293,9 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb, if (unlikely(!nskb)) { atomic_inc(&sk->sk_drops); - __UDP_INC_STATS(net, UDP_MIB_RCVBUFERRORS, + __UDP_INC_STATS(net, skb, UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk)); - __UDP_INC_STATS(net, UDP_MIB_INERRORS, + __UDP_INC_STATS(net, skb, UDP_MIB_INERRORS, IS_UDPLITE(sk)); continue; } @@ -2311,7 +2314,7 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb, consume_skb(skb); } else { kfree_skb(skb); - __UDP_INC_STATS(net, UDP_MIB_IGNOREDMULTI, + __UDP_INC_STATS(net, skb, UDP_MIB_IGNOREDMULTI, proto == IPPROTO_UDPLITE); } return 0; @@ -2454,7 +2457,8 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, if (udp_lib_checksum_complete(skb)) goto csum_error; - __UDP_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE); + __UDP_INC_STATS(net, skb, UDP_MIB_NOPORTS, + proto == IPPROTO_UDPLITE); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); /* @@ -2481,9 +2485,11 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, proto == IPPROTO_UDPLITE ? "Lite" : "", &saddr, ntohs(uh->source), &daddr, ntohs(uh->dest), ulen); - __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); + __UDP_INC_STATS(net, skb, UDP_MIB_CSUMERRORS, + proto == IPPROTO_UDPLITE); drop: - __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); + __UDP_INC_STATS(net, skb, UDP_MIB_INERRORS, + proto == IPPROTO_UDPLITE); kfree_skb(skb); return 0; }