[PATCH net-next] udp: Add tracepoint for udp_sendmsg()

Breno Leitao
2025-04-16T19:23:22Z

Add a lightweight tracepoint to monitor UDP send message operations,
similar to the recently introduced tcp_sendmsg_locked() trace event in
commit 0f08335ade712 ("trace: tcp: Add tracepoint for
tcp_sendmsg_locked()")

This implementation uses DECLARE_TRACE instead of TRACE_EVENT to avoid
creating extensive trace event infrastructure and exporting to tracefs,
keeping it minimal and efficient.

Since this patch creates a rawtracepoint, it can be accessed using
standard tracing tools like bpftrace:

rawtracepoint:udp_sendmsg_tp {
...
}

Signed-off-by: Breno Leitao <leitao@debian.org>
---
include/trace/events/udp.h | 5 +++++
net/ipv4/udp.c | 2 ++
2 files changed, 7 insertions(+)

diff --git a/include/trace/events/udp.h b/include/trace/events/udp.h
index 6142be4068e29..38ab24053b6ff 100644
--- a/include/trace/events/udp.h
+++ b/include/trace/events/udp.h
@@ -46,6 +46,11 @@ TRACE_EVENT(udp_fail_queue_rcv_skb,
__entry->saddr, __entry->daddr)
);

+DECLARE_TRACE(udp_sendmsg_tp,
+ TP_PROTO(const struct sock *sk, const struct msghdr *msg),
+ TP_ARGS(sk, msg)
+);
+
#endif /* _TRACE_UDP_H */

/* This part must be outside protection */
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index f9f5b92cf4b61..8c2902504a399 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1345,6 +1345,8 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
connected = 1;
}

+ trace_udp_sendmsg_tp(sk, msg);
+
ipcm_init_sk(&ipc, inet);
ipc.gso_size = READ_ONCE(up->gso_size);

---
base-commit: 1d6f4861027b451e064896f34dd0beada8871bfe
change-id: 20250416-udp_sendmsg-084a32657a56

Best regards,
--
Breno Leitao <leitao@debian.org>