Skip to content

Commit b533fb9

Browse files
JasonXingPaolo Abeni
authored andcommitted
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>
1 parent 215d402 commit b533fb9

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
@@ -74,20 +75,32 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
7475
TP_ARGS(sk, skb)
7576
);
7677

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

83-
TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
93+
TP_PROTO(const struct sock *sk,
94+
const struct sk_buff *skb,
95+
const enum sk_rst_reason reason),
8496

85-
TP_ARGS(sk, skb),
97+
TP_ARGS(sk, skb, reason),
8698

8799
TP_STRUCT__entry(
88100
__field(const void *, skbaddr)
89101
__field(const void *, skaddr)
90102
__field(int, state)
103+
__field(enum sk_rst_reason, reason)
91104
__array(__u8, saddr, sizeof(struct sockaddr_in6))
92105
__array(__u8, daddr, sizeof(struct sockaddr_in6))
93106
),
@@ -113,14 +126,19 @@ TRACE_EVENT(tcp_send_reset,
113126
*/
114127
TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr);
115128
}
129+
__entry->reason = reason;
116130
),
117131

118-
TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
132+
TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s",
119133
__entry->skbaddr, __entry->skaddr,
120134
__entry->saddr, __entry->daddr,
121-
__entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN")
135+
__entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN",
136+
__print_symbolic(__entry->reason, DEFINE_RST_REASON(FN, FNe)))
122137
);
123138

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

net/ipv4/tcp_ipv4.c

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

874-
trace_tcp_send_reset(sk, skb);
874+
trace_tcp_send_reset(sk, skb, reason);
875875

876876
BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
877877
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
@@ -3641,7 +3641,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority,
36413641
/* skb of trace_tcp_send_reset() keeps the skb that caused RST,
36423642
* skb here is different to the troublesome skb, so use NULL
36433643
*/
3644-
trace_tcp_send_reset(sk, NULL);
3644+
trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED);
36453645
}
36463646

36473647
/* 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
@@ -1133,7 +1133,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
11331133
label = ip6_flowlabel(ipv6h);
11341134
}
11351135

1136-
trace_tcp_send_reset(sk, skb);
1136+
trace_tcp_send_reset(sk, skb, reason);
11371137

11381138
tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1,
11391139
ipv6_get_dsfield(ipv6h), label, priority, txhash,

0 commit comments

Comments
 (0)