diff mbox series

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

Message ID 20211111133530.2156478-2-imagedong@tencent.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: snmp: tracepoint support for snmp | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 2 this patch: 5
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang fail Errors and warnings before: 22 this patch: 24
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 6 this patch: 9
netdev/checkpatch warning CHECK: Alignment should match open parenthesis CHECK: Lines should not end with a '(' WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Menglong Dong Nov. 11, 2021, 1:35 p.m. UTC
From: Menglong Dong <imagedong@tencent.com>

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 <imagedong@tencent.com>
---
 include/trace/events/snmp.h | 45 +++++++++++++++++++++++++++++++++++++
 net/core/net-traces.c       |  1 +
 2 files changed, 46 insertions(+)
 create mode 100644 include/trace/events/snmp.h

Comments

Steven Rostedt Nov. 16, 2021, 9:34 p.m. UTC | #1
On Thu, 11 Nov 2021 21:35:29 +0800
menglong8.dong@gmail.com wrote:

> +#define DEFINE_SNMP_EVENT(proto)				\
> +DEFINE_EVENT(snmp_template, snmp_##proto,			\
> +	TP_PROTO(struct sk_buff *skb, int field, int val),	\
> +	TP_ARGS(skb, field, val)				\
> +)
> +
> +#define TRACE_SNMP(skb, proto, field, val) \
> +	trace_snmp_##proto(skb, field, val)
> +
> +#endif

Why make a separate trace event for each protocol, and not just create an
enum that gets passed to the trace event? Then you could just filter on
what you want.

-- Steve
Menglong Dong Nov. 17, 2021, 1:55 p.m. UTC | #2
On Wed, Nov 17, 2021 at 5:34 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 11 Nov 2021 21:35:29 +0800
> menglong8.dong@gmail.com wrote:
>
> > +#define DEFINE_SNMP_EVENT(proto)                             \
> > +DEFINE_EVENT(snmp_template, snmp_##proto,                    \
> > +     TP_PROTO(struct sk_buff *skb, int field, int val),      \
> > +     TP_ARGS(skb, field, val)                                \
> > +)
> > +
> > +#define TRACE_SNMP(skb, proto, field, val) \
> > +     trace_snmp_##proto(skb, field, val)
> > +
> > +#endif
>
> Why make a separate trace event for each protocol, and not just create an
> enum that gets passed to the trace event? Then you could just filter on
> what you want.

enn....I'm not sure, just feel comfortable to create a separate trace event for
each protocol. Maybe it is easier to use? However, making them together
seems more fridently to users who want to do statistics for all protocols. I'll
think over it~~~

Thanks!
Menglong Dong

>
> -- Steve
diff mbox series

Patch

diff --git a/include/trace/events/snmp.h b/include/trace/events/snmp.h
new file mode 100644
index 000000000000..9dbd630306dd
--- /dev/null
+++ b/include/trace/events/snmp.h
@@ -0,0 +1,45 @@ 
+/* 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 field, int val),
+
+	TP_ARGS(skb, field, val),
+
+	TP_STRUCT__entry(
+		__field(void *, skbaddr)
+		__field(int, field)
+		__field(int, val)
+	),
+
+	TP_fast_assign(
+		__entry->skbaddr = skb;
+		__entry->field = field;
+		__entry->val = val;
+	),
+
+	TP_printk("skbaddr=%p, field=%d, val=%d", __entry->skbaddr,
+		  __entry->field, __entry->val)
+);
+
+#define DEFINE_SNMP_EVENT(proto)				\
+DEFINE_EVENT(snmp_template, snmp_##proto,			\
+	TP_PROTO(struct sk_buff *skb, int field, int val),	\
+	TP_ARGS(skb, field, val)				\
+)
+
+#define TRACE_SNMP(skb, proto, field, val) \
+	trace_snmp_##proto(skb, field, val)
+
+#endif
+
+#include <trace/define_trace.h>
diff --git a/net/core/net-traces.c b/net/core/net-traces.c
index c40cd8dd75c7..15ff40b83ca7 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);