Add IP/port information to UDP drop tracepoint
Subsystems (5)
v3 cover Add IP/port information to UDP drop tracepoint
Hi,
In our use-case we would like to recover the properties of dropped UDP packets. Unfortunately the current udp_fail_queue_rcv_skb tracepoint only exposes the port number of the receiving socket.
This patch-set will add the source/dest ip/port to the tracepoint, while keeping the socket's local port as well for compatibility.
Thanks for the review comments by Jason and Kuniyuki, they helped me a lot and I tried to address all of their comments in this new iteration.
v4 updates:
* fixed checkpatch.pl warnings
* rebased against latest net-next
v3 updates:
* Dropped "lport" as suggested by Jason Xing <[email protected]>
* Clear saddr/daddr fields using memset() before populating the fields as suggested by Jason Xing.
v2 updates:
* Addressed review notes by Kuniyuki Iwashima <[email protected]>
Balazs Scheidler (2):
net: port TP_STORE_ADDR_PORTS_SKB macro to be tcp/udp independent
net: udp: add IP/port data to the tracepoint
udp/udp_fail_queue_rcv_skb
include/trace/events/net_probe_common.h | 40 ++++++++++++++++++++++ include/trace/events/tcp.h | 45 ++----------------------- include/trace/events/udp.h | 29 +++++++++++++--- net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 3 +- 5 files changed, 69 insertions(+), 50 deletions(-)
Signature · 1 line
2.40.1
PATCH v4 1/2 net: port TP_STORE_ADDR_PORTS_SKB macro to be tcp/udp independent
This patch moves TP_STORE_ADDR_PORTS_SKB() to a common header and removes the TCP specific implementation details.
Previously the macro assumed the skb passed as an argument is a TCP packet, the implementation now uses an argument to the L4 header and uses that to extract the source/destination ports, which happen to be named the same in "struct tcphdr" and "struct udphdr"
--- include/trace/events/net_probe_common.h | 40 ++++++++++++++++++++++ include/trace/events/tcp.h | 45 ++----------------------- 2 files changed, 42 insertions(+), 43 deletions(-)
include/trace/events/net_probe_common.h +40 -0
@@ -70,4 +70,44 @@ TP_STORE_V4MAPPED(__entry, saddr, daddr)#endif +#define TP_STORE_ADDR_PORTS_SKB_V4 (__entry, skb, protoh) \ + do { \ + struct sockaddr_in *v4 = (void *)__entry->saddr; \ + \ + v4->sin_family = AF_INET; \ + v4->sin_port = protoh->source; \ + v4->sin_addr.s_addr = ip_hdr(skb)->saddr; \ + v4 = (void *)__entry->daddr; \ + v4->sin_family = AF_INET; \ + v4->sin_port = protoh->dest; \ + v4->sin_addr.s_addr = ip_hdr(skb)->daddr; \ + } while (0) + +#if IS_ENABLED (CONFIG_IPV6 ) + +#define TP_STORE_ADDR_PORTS_SKB (__entry, skb, protoh) \ + do { \ + const struct iphdr *iph = ip_hdr(skb); \ + \ + if (iph->version == 6) { \ + struct sockaddr_in6 *v6 = (void *)__entry->saddr; \ + \ + v6->sin6_family = AF_INET6; \ + v6->sin6_port = protoh->source; \ + v6->sin6_addr = ipv6_hdr(skb)->saddr; \ + v6 = (void *)__entry->daddr; \ + v6->sin6_family = AF_INET6; \ + v6->sin6_port = protoh->dest; \ + v6->sin6_addr = ipv6_hdr(skb)->daddr; \ + } else \ + TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb, protoh); \ + } while (0) + +#else + +#define TP_STORE_ADDR_PORTS_SKB (__entry, skb, protoh) \ + TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb, protoh) + +#endif +#endif
include/trace/events/tcp.h +2 -43
62 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 2/2 net: udp: add IP/port data to the tracepoint udp/udp_fail_queue_rcv_skb
In reply to Balazs ScheidlerThe udp_fail_queue_rcv_skb() tracepoint lacks any details on the source and destination IP/port whereas this information can be critical in case of UDP/syslog.
--- include/trace/events/udp.h | 29 ++++++++++++++++++++++++----- net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 3 ++- 3 files changed, 27 insertions(+), 7 deletions(-)
include/trace/events/udp.h +24 -5
@@ -7,24 +7,43 @@#include <linux/udp.h> #include <linux/tracepoint.h> +#include <trace/events/net_probe_common.h> TRACE_EVENT (udp_fail_queue_rcv_skb, - TP_PROTO(int rc, struct sock *sk), + TP_PROTO(int rc, struct sock *sk, struct sk_buff *skb), -TP_ARGS (rc, sk), +TP_ARGS (rc, sk, skb),TP_STRUCT__entry ( __field(int, rc) -__field (__u16, lport) + + __field(__u16, sport) + __field(__u16, dport) + __field(__u16, family) + __array(__u8, saddr, sizeof(struct sockaddr_in6)) +__array (__u8, daddr,sizeof (struct sockaddr_in6 )) ),TP_fast_assign ( + const struct udphdr *uh = (const struct udphdr *)udp_hdr(skb); + __entry->rc = rc; - __entry->lport = inet_sk(sk)->inet_num; + +/* for filtering use */ + __entry->sport = ntohs(uh->source); + __entry->dport = ntohs(uh->dest); + __entry->family = sk->sk_family; + + memset(__entry->saddr, 0, sizeof(struct sockaddr_in6)); + memset(__entry->daddr, 0, sizeof(struct sockaddr_in6)); + + TP_STORE_ADDR_PORTS_SKB(__entry, skb, uh); ), -TP_printk ("rc=%d port=%hu" , __entry->rc, __entry->lport) +TP_printk ("rc=%d family=%s src=%pISpc dest=%pISpc" , __entry->rc, +show_family_name (__entry->family), + __entry->saddr, __entry->daddr) );#endif /* _TRACE_UDP_H */
net/ipv4/udp.c +1 -1
@@ -2049,8 +2049,8 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) drop_reason =SKB_DROP_REASON_PROTO_MEM ; }UDP_INC_STATS (sock_net (sk),UDP_MIB_INERRORS , is_udplite); +trace_udp_fail_queue_rcv_skb (rc, sk, skb);kfree_skb_reason (skb, drop_reason); -trace_udp_fail_queue_rcv_skb (rc, sk);return -1 ; }
net/ipv6/udp.c +2 -1
@@ -34,6 +34,7 @@#include <linux/slab.h> #include <linux/uaccess.h> #include <linux/indirect_call_wrapper.h> +#include <trace/events/udp.h> #include <net/addrconf.h> #include <net/ndisc.h>
@@ -658,8 +659,8 @@ static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) drop_reason =SKB_DROP_REASON_PROTO_MEM ; }UDP6_INC_STATS (sock_net (sk),UDP_MIB_INERRORS , is_udplite); +trace_udp_fail_queue_rcv_skb (rc, sk, skb);kfree_skb_reason (skb, drop_reason); -trace_udp_fail_queue_rcv_skb (rc, sk);return -1 ; }
Signature · 1 line
2.40.1
Re: [PATCH net-next v4 2/2] net: udp: add IP/port data to the tracepoint udp/udp_fail_queue_rcv_skb
Quoted 6 lines · Balazs Scheidler
The
udp_fail_queue_rcv_skb()tracepoint lacks any details on the source and destination IP/port whereas this information can be critical in case of UDP/syslog.Signed-off-by Balazs Scheidler <[email protected]>
Looks good to me, thanks!
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Tue, 26 Mar 2024 19:05:45 +0100 you wrote:
Hi,
In our use-case we would like to recover the properties of dropped UDP packets. Unfortunately the current
udp_fail_queue_rcv_skbtracepoint only exposes the port number of the receiving socket.This patch-set will add the source/dest ip/port to the tracepoint, while keeping the socket's local port as well for compatibility.
[...]
Here is the summary with links:
- [net-next,v4,1/2] net: port TP_STORE_ADDR_PORTS_SKB macro to be tcp/udp independent
https://git.kernel.org/netdev/net-next/c/a0ad11fc2632 - [net-next,v4,2/2] net: udp: add IP/port data to the tracepoint udp/udp_fail_queue_rcv_skb https://git.kernel.org/netdev/net-next/c/e9669a00bba7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html