Skip to content

Commit 51c78f9

Browse files
committed
rstreason: make it work in trace world
JIRA: https://issues.redhat.com/browse/RHEL-48648 Upstream Status: linux.git commit b533fb9 Author: Jason Xing <kernelxing@tencent.com> Date: Thu Apr 25 11:13:40 2024 +0800 rstreason: make it work in trace world At last, we should let it work by introducing this reset reason in trace world. One of the possible expected outputs is: ... tcp_send_reset: skbaddr=xxx skaddr=xxx src=xxx dest=xxx state=TCP_ESTABLISHED reason=NOT_SPECIFIED Signed-off-by: Jason Xing <kernelxing@tencent.com> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent 289cc4c commit 51c78f9

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

include/trace/events/tcp.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <net/ipv6.h>
1212
#include <net/tcp.h>
1313
#include <linux/sock_diag.h>
14+
#include <net/rstreason.h>
1415

1516
/*
1617
* tcp event with arguments sk and skb
@@ -73,20 +74,32 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
7374
TP_ARGS(sk, skb)
7475
);
7576

77+
#undef FN
78+
#define FN(reason) TRACE_DEFINE_ENUM(SK_RST_REASON_##reason);
79+
DEFINE_RST_REASON(FN, FN)
80+
81+
#undef FN
82+
#undef FNe
83+
#define FN(reason) { SK_RST_REASON_##reason, #reason },
84+
#define FNe(reason) { SK_RST_REASON_##reason, #reason }
85+
7686
/*
7787
* skb of trace_tcp_send_reset is the skb that caused RST. In case of
7888
* active reset, skb should be NULL
7989
*/
8090
TRACE_EVENT(tcp_send_reset,
8191

82-
TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
92+
TP_PROTO(const struct sock *sk,
93+
const struct sk_buff *skb,
94+
const enum sk_rst_reason reason),
8395

84-
TP_ARGS(sk, skb),
96+
TP_ARGS(sk, skb, reason),
8597

8698
TP_STRUCT__entry(
8799
__field(const void *, skbaddr)
88100
__field(const void *, skaddr)
89101
__field(int, state)
102+
__field(enum sk_rst_reason, reason)
90103
__array(__u8, saddr, sizeof(struct sockaddr_in6))
91104
__array(__u8, daddr, sizeof(struct sockaddr_in6))
92105
),
@@ -112,14 +125,19 @@ TRACE_EVENT(tcp_send_reset,
112125
*/
113126
TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr);
114127
}
128+
__entry->reason = reason;
115129
),
116130

117-
TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
131+
TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s",
118132
__entry->skbaddr, __entry->skaddr,
119133
__entry->saddr, __entry->daddr,
120-
__entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN")
134+
__entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN",
135+
__print_symbolic(__entry->reason, DEFINE_RST_REASON(FN, FNe)))
121136
);
122137

138+
#undef FN
139+
#undef FNe
140+
123141
/*
124142
* tcp event with arguments sk
125143
*

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb,
811811
if (sk)
812812
arg.bound_dev_if = sk->sk_bound_dev_if;
813813

814-
trace_tcp_send_reset(sk, skb);
814+
trace_tcp_send_reset(sk, skb, reason);
815815

816816
BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
817817
offsetof(struct inet_timewait_sock, tw_bound_dev_if));

net/ipv4/tcp_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3532,7 +3532,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority,
35323532
/* skb of trace_tcp_send_reset() keeps the skb that caused RST,
35333533
* skb here is different to the troublesome skb, so use NULL
35343534
*/
3535-
trace_tcp_send_reset(sk, NULL);
3535+
trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED);
35363536
}
35373537

35383538
/* Send a crossed SYN-ACK during socket establishment.

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
10701070
label = ip6_flowlabel(ipv6h);
10711071
}
10721072

1073-
trace_tcp_send_reset(sk, skb);
1073+
trace_tcp_send_reset(sk, skb, reason);
10741074

10751075
tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, key, 1,
10761076
ipv6_get_dsfield(ipv6h), label, priority, txhash);

0 commit comments

Comments
 (0)