Thread (12 messages) flat view 12 messages, 3 authors, 2021-11-24
STALE1722d

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 net-next 1/2] net: snmp: add tracepoint support for snmp

From: <hidden>
Date: 2021-11-18 12:49:59
Also in: lkml
Subsystem: networking [general], the rest, tracing · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Steven Rostedt, Masami Hiramatsu

From: Menglong Dong <redacted>

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 <redacted>
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 <linux/tracepoint.h>
+#include <linux/skbuff.h>
+#include <linux/snmp.h>
+
+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 <trace/define_trace.h>
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 <trace/events/tcp.h>
 #include <trace/events/fib.h>
 #include <trace/events/qdisc.h>
+#include <trace/events/snmp.h>
 #if IS_ENABLED(CONFIG_BRIDGE)
 #include <trace/events/bridge.h>
 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);
-- 
2.27.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help