Skip to content

Commit db3efdc

Browse files
Peilin Hedavem330
authored andcommitted
net/ipv4: add tracepoint for icmp_send
Introduce a tracepoint for icmp_send, which can help users to get more detail information conveniently when icmp abnormal events happen. 1. Giving an usecase example: ============================= When an application experiences packet loss due to an unreachable UDP destination port, the kernel will send an exception message through the icmp_send function. By adding a trace point for icmp_send, developers or system administrators can obtain detailed information about the UDP packet loss, including the type, code, source address, destination address, source port, and destination port. This facilitates the trouble-shooting of UDP packet loss issues especially for those network-service applications. 2. Operation Instructions: ========================== Switch to the tracing directory. cd /sys/kernel/tracing Filter for destination port unreachable. echo "type==3 && code==3" > events/icmp/icmp_send/filter Enable trace event. echo 1 > events/icmp/icmp_send/enable 3. Result View: ================ udp_client_erro-11370 [002] ...s.12 124.728002: icmp_send: icmp_send: type=3, code=3. From 127.0.0.1:41895 to 127.0.0.1:6666 ulen=23 skbaddr=00000000589b167a Signed-off-by: Peilin He <he.peilin@zte.com.cn> Signed-off-by: xu xin <xu.xin16@zte.com.cn> Reviewed-by: Yunkai Zhang <zhang.yunkai@zte.com.cn> Cc: Yang Yang <yang.yang29@zte.com.cn> Cc: Liu Chun <liu.chun2@zte.com.cn> Cc: Xuexin Jiang <jiang.xuexin@zte.com.cn> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9f481ce commit db3efdc

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

include/trace/events/icmp.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#undef TRACE_SYSTEM
3+
#define TRACE_SYSTEM icmp
4+
5+
#if !defined(_TRACE_ICMP_H) || defined(TRACE_HEADER_MULTI_READ)
6+
#define _TRACE_ICMP_H
7+
8+
#include <linux/icmp.h>
9+
#include <linux/tracepoint.h>
10+
11+
TRACE_EVENT(icmp_send,
12+
13+
TP_PROTO(const struct sk_buff *skb, int type, int code),
14+
15+
TP_ARGS(skb, type, code),
16+
17+
TP_STRUCT__entry(
18+
__field(const void *, skbaddr)
19+
__field(int, type)
20+
__field(int, code)
21+
__array(__u8, saddr, 4)
22+
__array(__u8, daddr, 4)
23+
__field(__u16, sport)
24+
__field(__u16, dport)
25+
__field(unsigned short, ulen)
26+
),
27+
28+
TP_fast_assign(
29+
struct iphdr *iph = ip_hdr(skb);
30+
struct udphdr *uh = udp_hdr(skb);
31+
int proto_4 = iph->protocol;
32+
__be32 *p32;
33+
34+
__entry->skbaddr = skb;
35+
__entry->type = type;
36+
__entry->code = code;
37+
38+
if (proto_4 != IPPROTO_UDP || (u8 *)uh < skb->head ||
39+
(u8 *)uh + sizeof(struct udphdr)
40+
> skb_tail_pointer(skb)) {
41+
__entry->sport = 0;
42+
__entry->dport = 0;
43+
__entry->ulen = 0;
44+
} else {
45+
__entry->sport = ntohs(uh->source);
46+
__entry->dport = ntohs(uh->dest);
47+
__entry->ulen = ntohs(uh->len);
48+
}
49+
50+
p32 = (__be32 *) __entry->saddr;
51+
*p32 = iph->saddr;
52+
53+
p32 = (__be32 *) __entry->daddr;
54+
*p32 = iph->daddr;
55+
),
56+
57+
TP_printk("icmp_send: type=%d, code=%d. From %pI4:%u to %pI4:%u ulen=%d skbaddr=%p",
58+
__entry->type, __entry->code,
59+
__entry->saddr, __entry->sport, __entry->daddr,
60+
__entry->dport, __entry->ulen, __entry->skbaddr)
61+
);
62+
63+
#endif /* _TRACE_ICMP_H */
64+
65+
/* This part must be outside protection */
66+
#include <trace/define_trace.h>
67+

net/ipv4/icmp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
#include <net/ip_fib.h>
9494
#include <net/l3mdev.h>
9595
#include <net/addrconf.h>
96+
#define CREATE_TRACE_POINTS
97+
#include <trace/events/icmp.h>
9698

9799
/*
98100
* Build xmit assembly blocks
@@ -770,6 +772,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
770772
if (!fl4.saddr)
771773
fl4.saddr = htonl(INADDR_DUMMY);
772774

775+
trace_icmp_send(skb_in, type, code);
776+
773777
icmp_push_reply(sk, &icmp_param, &fl4, &ipc, &rt);
774778
ende:
775779
ip_rt_put(rt);

0 commit comments

Comments
 (0)