When TCP connetion in TCP_TIME_WAIT or TCP_NEW_SYN_RECV state, it can't
get the sport/dport/saddr/daddr from inet_sock.
trace_tcp_set_state may be called when the oldstate in these two states.
Signed-off-by: Yafang Shao <[email protected]>
---
include/trace/events/tcp.h | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 07cccca..1982a71 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -196,7 +196,6 @@
),
TP_fast_assign(
- struct inet_sock *inet = inet_sk(sk);
struct in6_addr *pin6;
__be32 *p32;
@@ -204,14 +203,34 @@
__entry->oldstate = oldstate;
__entry->newstate = newstate;
- __entry->sport = ntohs(inet->inet_sport);
- __entry->dport = ntohs(inet->inet_dport);
+ if (oldstate == TCP_TIME_WAIT) {
+ __entry->sport = ntohs(inet_twsk(sk)->tw_sport);
+ __entry->dport = ntohs(inet_twsk(sk)->tw_dport);
- p32 = (__be32 *) __entry->saddr;
- *p32 = inet->inet_saddr;
+ p32 = (__be32 *) __entry->saddr;
+ *p32 = inet_twsk(sk)->tw_rcv_saddr;
- p32 = (__be32 *) __entry->daddr;
- *p32 = inet->inet_daddr;
+ p32 = (__be32 *) __entry->daddr;
+ *p32 = inet_twsk(sk)->tw_daddr;
+ } else if (oldstate == TCP_NEW_SYN_RECV) {
+ __entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
+ __entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
+
+ p32 = (__be32 *) __entry->saddr;
+ *p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
+
+ p32 = (__be32 *) __entry->daddr;
+ *p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
+ } else {
+ __entry->sport = ntohs(inet_sk(sk)->inet_sport);
+ __entry->dport = ntohs(inet_sk(sk)->inet_dport);
+
+ p32 = (__be32 *) __entry->saddr;
+ *p32 = inet_sk(sk)->inet_saddr;
+
+ p32 = (__be32 *) __entry->daddr;
+ *p32 = inet_sk(sk)->inet_daddr;
+ }
#if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == AF_INET6) {
--
1.8.3.1
From 1583749300694223771@xxx Sat Nov 11 06:17:11 +0000 2017
X-GM-THRID: 1583749300694223771
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread