All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack
@ 2017-10-23 16:20 Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 1/6] tcp: add trace event class tcp_event_sk_skb Song Liu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

Changes from v1:

Fix build error (with ipv6 as ko) by adding EXPORT_TRACEPOINT_SYMBOL_GPL
for trace_tcp_send_reset.

These patches add the following tracepoints to tcp stack.

tcp_send_reset
tcp_receive_reset
tcp_destroy_sock
tcp_set_state

These tracepoints can be used to track TCP state changes. Such state
changes include but are not limited to: connection establish,
connection termination, tx and rx of RST, various retransmits.

Currently, we use the following kprobes to trace these events:

int kprobe__tcp_validate_incoming
int kprobe__tcp_send_active_reset
int kprobe__tcp_v4_send_reset
int kprobe__tcp_v6_send_reset
int kprobe__tcp_v4_destroy_sock
int kprobe__tcp_set_state
int kprobe__tcp_retransmit_skb

These tracepoints will help us simplify this work.

Thanks,
Song

Song Liu (6):
  tcp: add trace event class tcp_event_sk_skb
  tcp: mark trace event arguments sk and skb as const
  tcp: add tracepoint trace_tcp_send_reset
  tcp: add tracepoint trace_tcp_receive_reset
  tcp: add tracepoint trace_tcp_destroy_sock
  tcp: add tracepoint trace_tcp_set_state()

 include/trace/events/tcp.h | 181 ++++++++++++++++++++++++++++++++++++++++++++-
 net/core/net-traces.c      |   2 +
 net/ipv4/tcp.c             |   4 +
 net/ipv4/tcp_input.c       |   3 +
 net/ipv4/tcp_ipv4.c        |   8 +-
 net/ipv4/tcp_output.c      |   5 ++
 net/ipv6/tcp_ipv6.c        |  10 ++-
 7 files changed, 206 insertions(+), 7 deletions(-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 1/6] tcp: add trace event class tcp_event_sk_skb
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 2/6] tcp: mark trace event arguments sk and skb as const Song Liu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

Introduce event class tcp_event_sk_skb for tcp tracepoints that
have arguments sk and skb.

Existing tracepoint trace_tcp_retransmit_skb() falls into this class.
This patch rewrites the definition of trace_tcp_retransmit_skb() with
tcp_event_sk_skb.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index c3220d9..14b0a708 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -9,7 +9,13 @@
 #include <linux/tracepoint.h>
 #include <net/ipv6.h>
 
-TRACE_EVENT(tcp_retransmit_skb,
+/*
+ * tcp event with arguments sk and skb
+ *
+ * Note: this class requires a valid sk pointer; while skb pointer could
+ *       be NULL.
+ */
+DECLARE_EVENT_CLASS(tcp_event_sk_skb,
 
 	TP_PROTO(struct sock *sk, struct sk_buff *skb),
 
@@ -64,6 +70,13 @@ TRACE_EVENT(tcp_retransmit_skb,
 		  __entry->saddr_v6, __entry->daddr_v6)
 );
 
+DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
+
+	TP_PROTO(struct sock *sk, struct sk_buff *skb),
+
+	TP_ARGS(sk, skb)
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 2/6] tcp: mark trace event arguments sk and skb as const
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 1/6] tcp: add trace event class tcp_event_sk_skb Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 3/6] tcp: add tracepoint trace_tcp_send_reset Song Liu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

Some functions that we plan to add trace points require const sk
and/or skb. So we mark these fields as const in the tracepoint.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 14b0a708..2b6fe72 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -17,13 +17,13 @@
  */
 DECLARE_EVENT_CLASS(tcp_event_sk_skb,
 
-	TP_PROTO(struct sock *sk, struct sk_buff *skb),
+	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
 
 	TP_ARGS(sk, skb),
 
 	TP_STRUCT__entry(
-		__field(void *, skbaddr)
-		__field(void *, skaddr)
+		__field(const void *, skbaddr)
+		__field(const void *, skaddr)
 		__field(__u16, sport)
 		__field(__u16, dport)
 		__array(__u8, saddr, 4)
@@ -72,7 +72,7 @@ DECLARE_EVENT_CLASS(tcp_event_sk_skb,
 
 DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
 
-	TP_PROTO(struct sock *sk, struct sk_buff *skb),
+	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
 
 	TP_ARGS(sk, skb)
 );
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 3/6] tcp: add tracepoint trace_tcp_send_reset
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 1/6] tcp: add trace event class tcp_event_sk_skb Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 2/6] tcp: mark trace event arguments sk and skb as const Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 4/6] tcp: add tracepoint trace_tcp_receive_reset Song Liu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

New tracepoint trace_tcp_send_reset is added and called from
tcp_v4_send_reset(), tcp_v6_send_reset() and tcp_send_active_reset().

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 11 +++++++++++
 net/core/net-traces.c      |  2 ++
 net/ipv4/tcp_ipv4.c        |  6 +++++-
 net/ipv4/tcp_output.c      |  5 +++++
 net/ipv6/tcp_ipv6.c        | 10 ++++++++--
 5 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 2b6fe72..3e57e1a 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -77,6 +77,17 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
 	TP_ARGS(sk, skb)
 );
 
+/*
+ * skb of trace_tcp_send_reset is the skb that caused RST. In case of
+ * active reset, skb should be NULL
+ */
+DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
+
+	TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
+
+	TP_ARGS(sk, skb)
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
diff --git a/net/core/net-traces.c b/net/core/net-traces.c
index f4e4fa2..8dcd9b0 100644
--- a/net/core/net-traces.c
+++ b/net/core/net-traces.c
@@ -49,3 +49,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(br_fdb_update);
 EXPORT_TRACEPOINT_SYMBOL_GPL(kfree_skb);
 
 EXPORT_TRACEPOINT_SYMBOL_GPL(napi_poll);
+
+EXPORT_TRACEPOINT_SYMBOL_GPL(tcp_send_reset);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index e22439f..eb3f3b8 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -85,6 +85,8 @@
 #include <crypto/hash.h>
 #include <linux/scatterlist.h>
 
+#include <trace/events/tcp.h>
+
 #ifdef CONFIG_TCP_MD5SIG
 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
 			       __be32 daddr, __be32 saddr, const struct tcphdr *th);
@@ -701,8 +703,10 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
 	 * routing might fail in this case. No choice here, if we choose to force
 	 * input interface, we will misroute in case of asymmetric route.
 	 */
-	if (sk)
+	if (sk) {
 		arg.bound_dev_if = sk->sk_bound_dev_if;
+		trace_tcp_send_reset(sk, skb);
+	}
 
 	BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
 		     offsetof(struct inet_timewait_sock, tw_bound_dev_if));
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 988733f..1f01f4c 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3084,6 +3084,11 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)
 	/* Send it off. */
 	if (tcp_transmit_skb(sk, skb, 0, priority))
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTFAILED);
+
+	/* skb of trace_tcp_send_reset() keeps the skb that caused RST,
+	 * skb here is different to the troublesome skb, so use NULL
+	 */
+	trace_tcp_send_reset(sk, NULL);
 }
 
 /* Send a crossed SYN-ACK during socket establishment.
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index ae83615..0e25299 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -69,6 +69,8 @@
 #include <crypto/hash.h>
 #include <linux/scatterlist.h>
 
+#include <trace/events/tcp.h>
+
 static void	tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb);
 static void	tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
 				      struct request_sock *req);
@@ -890,7 +892,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
 	int genhash;
 	struct sock *sk1 = NULL;
 #endif
-	int oif;
+	int oif = 0;
 
 	if (th->rst)
 		return;
@@ -939,7 +941,11 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
 		ack_seq = ntohl(th->seq) + th->syn + th->fin + skb->len -
 			  (th->doff << 2);
 
-	oif = sk ? sk->sk_bound_dev_if : 0;
+	if (sk) {
+		oif = sk->sk_bound_dev_if;
+		trace_tcp_send_reset(sk, skb);
+	}
+
 	tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, key, 1, 0, 0);
 
 #ifdef CONFIG_TCP_MD5SIG
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 4/6] tcp: add tracepoint trace_tcp_receive_reset
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
                   ` (2 preceding siblings ...)
  2017-10-23 16:20 ` [PATCH v2 net-next 3/6] tcp: add tracepoint trace_tcp_send_reset Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 5/6] tcp: add tracepoint trace_tcp_destroy_sock Song Liu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

New tracepoint trace_tcp_receive_reset is added and called from
tcp_reset(). This tracepoint is define with a new class tcp_event_sk.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_input.c       |  3 +++
 2 files changed, 69 insertions(+)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 3e57e1a..c83c711 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -88,6 +88,72 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
 	TP_ARGS(sk, skb)
 );
 
+/*
+ * tcp event with arguments sk
+ *
+ * Note: this class requires a valid sk pointer.
+ */
+DECLARE_EVENT_CLASS(tcp_event_sk,
+
+	TP_PROTO(const struct sock *sk),
+
+	TP_ARGS(sk),
+
+	TP_STRUCT__entry(
+		__field(const void *, skaddr)
+		__field(__u16, sport)
+		__field(__u16, dport)
+		__array(__u8, saddr, 4)
+		__array(__u8, daddr, 4)
+		__array(__u8, saddr_v6, 16)
+		__array(__u8, daddr_v6, 16)
+	),
+
+	TP_fast_assign(
+		struct inet_sock *inet = inet_sk(sk);
+		struct in6_addr *pin6;
+		__be32 *p32;
+
+		__entry->skaddr = sk;
+
+		__entry->sport = ntohs(inet->inet_sport);
+		__entry->dport = ntohs(inet->inet_dport);
+
+		p32 = (__be32 *) __entry->saddr;
+		*p32 = inet->inet_saddr;
+
+		p32 = (__be32 *) __entry->daddr;
+		*p32 =  inet->inet_daddr;
+
+#if IS_ENABLED(CONFIG_IPV6)
+		if (sk->sk_family == AF_INET6) {
+			pin6 = (struct in6_addr *)__entry->saddr_v6;
+			*pin6 = sk->sk_v6_rcv_saddr;
+			pin6 = (struct in6_addr *)__entry->daddr_v6;
+			*pin6 = sk->sk_v6_daddr;
+		} else
+#endif
+		{
+			pin6 = (struct in6_addr *)__entry->saddr_v6;
+			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
+			pin6 = (struct in6_addr *)__entry->daddr_v6;
+			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
+		}
+	),
+
+	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
+		  __entry->sport, __entry->dport,
+		  __entry->saddr, __entry->daddr,
+		  __entry->saddr_v6, __entry->daddr_v6)
+);
+
+DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
+
+	TP_PROTO(const struct sock *sk),
+
+	TP_ARGS(sk)
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index ab3f128..c5e64d4 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -75,6 +75,7 @@
 #include <linux/ipsec.h>
 #include <asm/unaligned.h>
 #include <linux/errqueue.h>
+#include <trace/events/tcp.h>
 
 int sysctl_tcp_fack __read_mostly;
 int sysctl_tcp_max_reordering __read_mostly = 300;
@@ -4010,6 +4011,8 @@ static inline bool tcp_sequence(const struct tcp_sock *tp, u32 seq, u32 end_seq)
 /* When we get a reset we do this. */
 void tcp_reset(struct sock *sk)
 {
+	trace_tcp_receive_reset(sk);
+
 	/* We want the right error as BSD sees it (and indeed as we do). */
 	switch (sk->sk_state) {
 	case TCP_SYN_SENT:
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 5/6] tcp: add tracepoint trace_tcp_destroy_sock
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
                   ` (3 preceding siblings ...)
  2017-10-23 16:20 ` [PATCH v2 net-next 4/6] tcp: add tracepoint trace_tcp_receive_reset Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:20 ` [PATCH v2 net-next 6/6] tcp: add tracepoint trace_tcp_set_state() Song Liu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

This patch adds trace event trace_tcp_destroy_sock.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 7 +++++++
 net/ipv4/tcp_ipv4.c        | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index c83c711..1724c12 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -154,6 +154,13 @@ DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
 	TP_ARGS(sk)
 );
 
+DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
+
+	TP_PROTO(const struct sock *sk),
+
+	TP_ARGS(sk)
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index eb3f3b8..23a8100 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1869,6 +1869,8 @@ void tcp_v4_destroy_sock(struct sock *sk)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 
+	trace_tcp_destroy_sock(sk);
+
 	tcp_clear_xmit_timers(sk);
 
 	tcp_cleanup_congestion_control(sk);
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 net-next 6/6] tcp: add tracepoint trace_tcp_set_state()
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
                   ` (4 preceding siblings ...)
  2017-10-23 16:20 ` [PATCH v2 net-next 5/6] tcp: add tracepoint trace_tcp_destroy_sock Song Liu
@ 2017-10-23 16:20 ` Song Liu
  2017-10-23 16:26 ` [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
  2017-10-24  0:25 ` David Miller
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:20 UTC (permalink / raw)
  To: netdev, davem; +Cc: alexei.starovoitov, liu.song.a23, Song Liu

This patch adds tracepoint trace_tcp_set_state. Besides usual fields
(s/d ports, IP addresses), old and new state of the socket is also
printed with TP_printk, with __print_symbolic().

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/trace/events/tcp.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp.c             |  4 +++
 2 files changed, 80 insertions(+)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 1724c12..03699ba 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -9,6 +9,22 @@
 #include <linux/tracepoint.h>
 #include <net/ipv6.h>
 
+#define tcp_state_name(state)	{ state, #state }
+#define show_tcp_state_name(val)			\
+	__print_symbolic(val,				\
+		tcp_state_name(TCP_ESTABLISHED),	\
+		tcp_state_name(TCP_SYN_SENT),		\
+		tcp_state_name(TCP_SYN_RECV),		\
+		tcp_state_name(TCP_FIN_WAIT1),		\
+		tcp_state_name(TCP_FIN_WAIT2),		\
+		tcp_state_name(TCP_TIME_WAIT),		\
+		tcp_state_name(TCP_CLOSE),		\
+		tcp_state_name(TCP_CLOSE_WAIT),		\
+		tcp_state_name(TCP_LAST_ACK),		\
+		tcp_state_name(TCP_LISTEN),		\
+		tcp_state_name(TCP_CLOSING),		\
+		tcp_state_name(TCP_NEW_SYN_RECV))
+
 /*
  * tcp event with arguments sk and skb
  *
@@ -161,6 +177,66 @@ DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
 	TP_ARGS(sk)
 );
 
+TRACE_EVENT(tcp_set_state,
+
+	TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
+
+	TP_ARGS(sk, oldstate, newstate),
+
+	TP_STRUCT__entry(
+		__field(const void *, skaddr)
+		__field(int, oldstate)
+		__field(int, newstate)
+		__field(__u16, sport)
+		__field(__u16, dport)
+		__array(__u8, saddr, 4)
+		__array(__u8, daddr, 4)
+		__array(__u8, saddr_v6, 16)
+		__array(__u8, daddr_v6, 16)
+	),
+
+	TP_fast_assign(
+		struct inet_sock *inet = inet_sk(sk);
+		struct in6_addr *pin6;
+		__be32 *p32;
+
+		__entry->skaddr = sk;
+		__entry->oldstate = oldstate;
+		__entry->newstate = newstate;
+
+		__entry->sport = ntohs(inet->inet_sport);
+		__entry->dport = ntohs(inet->inet_dport);
+
+		p32 = (__be32 *) __entry->saddr;
+		*p32 = inet->inet_saddr;
+
+		p32 = (__be32 *) __entry->daddr;
+		*p32 =  inet->inet_daddr;
+
+#if IS_ENABLED(CONFIG_IPV6)
+		if (sk->sk_family == AF_INET6) {
+			pin6 = (struct in6_addr *)__entry->saddr_v6;
+			*pin6 = sk->sk_v6_rcv_saddr;
+			pin6 = (struct in6_addr *)__entry->daddr_v6;
+			*pin6 = sk->sk_v6_daddr;
+		} else
+#endif
+		{
+			pin6 = (struct in6_addr *)__entry->saddr_v6;
+			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
+			pin6 = (struct in6_addr *)__entry->daddr_v6;
+			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
+		}
+	),
+
+	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
+		  __entry->sport, __entry->dport,
+		  __entry->saddr, __entry->daddr,
+		  __entry->saddr_v6, __entry->daddr_v6,
+		  show_tcp_state_name(__entry->oldstate),
+		  show_tcp_state_name(__entry->newstate))
+);
+
 #endif /* _TRACE_TCP_H */
 
 /* This part must be outside protection */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8b1fa4d..be07e9b 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -282,6 +282,8 @@
 #include <asm/ioctls.h>
 #include <net/busy_poll.h>
 
+#include <trace/events/tcp.h>
+
 int sysctl_tcp_min_tso_segs __read_mostly = 2;
 
 int sysctl_tcp_autocorking __read_mostly = 1;
@@ -2040,6 +2042,8 @@ void tcp_set_state(struct sock *sk, int state)
 {
 	int oldstate = sk->sk_state;
 
+	trace_tcp_set_state(sk, oldstate, state);
+
 	switch (state) {
 	case TCP_ESTABLISHED:
 		if (oldstate != TCP_ESTABLISHED)
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
                   ` (5 preceding siblings ...)
  2017-10-23 16:20 ` [PATCH v2 net-next 6/6] tcp: add tracepoint trace_tcp_set_state() Song Liu
@ 2017-10-23 16:26 ` Song Liu
  2017-10-24  0:25 ` David Miller
  7 siblings, 0 replies; 9+ messages in thread
From: Song Liu @ 2017-10-23 16:26 UTC (permalink / raw)
  To: netdev, davem
  Cc: alexei.starovoitov, liu.song.a23, Eric Dumazet, hannes,
	brendan.d.gregg, ncardwell, David Ahern, Kernel Team,
	xiyou.wangcong

CCing key audience of these patches.

Thanks,
Song

> On Oct 23, 2017, at 9:20 AM, Song Liu <songliubraving@fb.com> wrote:
> 
> Changes from v1:
> 
> Fix build error (with ipv6 as ko) by adding EXPORT_TRACEPOINT_SYMBOL_GPL
> for trace_tcp_send_reset.
> 
> These patches add the following tracepoints to tcp stack.
> 
> tcp_send_reset
> tcp_receive_reset
> tcp_destroy_sock
> tcp_set_state
> 
> These tracepoints can be used to track TCP state changes. Such state
> changes include but are not limited to: connection establish,
> connection termination, tx and rx of RST, various retransmits.
> 
> Currently, we use the following kprobes to trace these events:
> 
> int kprobe__tcp_validate_incoming
> int kprobe__tcp_send_active_reset
> int kprobe__tcp_v4_send_reset
> int kprobe__tcp_v6_send_reset
> int kprobe__tcp_v4_destroy_sock
> int kprobe__tcp_set_state
> int kprobe__tcp_retransmit_skb
> 
> These tracepoints will help us simplify this work.
> 
> Thanks,
> Song
> 
> Song Liu (6):
>  tcp: add trace event class tcp_event_sk_skb
>  tcp: mark trace event arguments sk and skb as const
>  tcp: add tracepoint trace_tcp_send_reset
>  tcp: add tracepoint trace_tcp_receive_reset
>  tcp: add tracepoint trace_tcp_destroy_sock
>  tcp: add tracepoint trace_tcp_set_state()
> 
> include/trace/events/tcp.h | 181 ++++++++++++++++++++++++++++++++++++++++++++-
> net/core/net-traces.c      |   2 +
> net/ipv4/tcp.c             |   4 +
> net/ipv4/tcp_input.c       |   3 +
> net/ipv4/tcp_ipv4.c        |   8 +-
> net/ipv4/tcp_output.c      |   5 ++
> net/ipv6/tcp_ipv6.c        |  10 ++-
> 7 files changed, 206 insertions(+), 7 deletions(-)
> 
> --
> 2.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack
  2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
                   ` (6 preceding siblings ...)
  2017-10-23 16:26 ` [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
@ 2017-10-24  0:25 ` David Miller
  7 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2017-10-24  0:25 UTC (permalink / raw)
  To: songliubraving; +Cc: netdev, alexei.starovoitov, liu.song.a23

From: Song Liu <songliubraving@fb.com>
Date: Mon, 23 Oct 2017 09:20:21 -0700

> Changes from v1:
> 
> Fix build error (with ipv6 as ko) by adding EXPORT_TRACEPOINT_SYMBOL_GPL
> for trace_tcp_send_reset.

Series applied.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-10-24  0:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-23 16:20 [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 1/6] tcp: add trace event class tcp_event_sk_skb Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 2/6] tcp: mark trace event arguments sk and skb as const Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 3/6] tcp: add tracepoint trace_tcp_send_reset Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 4/6] tcp: add tracepoint trace_tcp_receive_reset Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 5/6] tcp: add tracepoint trace_tcp_destroy_sock Song Liu
2017-10-23 16:20 ` [PATCH v2 net-next 6/6] tcp: add tracepoint trace_tcp_set_state() Song Liu
2017-10-23 16:26 ` [PATCH v2 net-next 0/6] add a set of tracepoints to tcp stack Song Liu
2017-10-24  0:25 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.