netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: davem@davemloft.net
Cc: kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org,
	rostedt@goodmis.org, mingo@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH net-next 2/2] tcp: handle TCP_TIME_WAIT/TCP_NEW_SYN_RECV in tcp_set_state tracepoint
Date: Thu,  9 Nov 2017 14:26:04 +0000	[thread overview]
Message-ID: <1510237564-6013-2-git-send-email-laoar.shao@gmail.com> (raw)
In-Reply-To: <1510237564-6013-1-git-send-email-laoar.shao@gmail.com>

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 <laoar.shao@gmail.com>
---
 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

  reply	other threads:[~2017-11-09 14:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09 14:26 [PATCH net-next 1/2] net/tcp: track all TCP/IP state transition in tcp_set_state Yafang Shao
2017-11-09 14:26 ` Yafang Shao [this message]
2017-11-09 14:52   ` [PATCH net-next 2/2] tcp: handle TCP_TIME_WAIT/TCP_NEW_SYN_RECV in tcp_set_state tracepoint Eric Dumazet
2017-11-09 14:58     ` Eric Dumazet
2017-11-09 15:11       ` Yafang Shao
2017-11-09 15:18         ` Eric Dumazet
2017-11-12 14:15   ` kbuild test robot
2017-11-12 15:40   ` kbuild test robot
2017-11-12 13:46 ` [PATCH net-next 1/2] net/tcp: track all TCP/IP state transition in tcp_set_state kbuild test robot
2017-11-12 15:10 ` kbuild test robot
2017-11-12 17:15 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1510237564-6013-2-git-send-email-laoar.shao@gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).