netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Dauchy <wdauchy@gmail.com>
To: netdev@vger.kernel.org
Cc: William Dauchy <wdauchy@gmail.com>,
	Eric Dumazet <eric.dumazet@gmail.com>
Subject: [PATCH v2] tcp: add timestamp options fetcher
Date: Sat, 26 Oct 2019 20:45:54 +0200	[thread overview]
Message-ID: <20191026184554.32648-1-wdauchy@gmail.com> (raw)
In-Reply-To: <20191002221017.2085-1-wdauchy@gmail.com>

tsval and tsecr are useful in some cases to diagnose TCP issues from the
sender point of view where unexplained RTT values are seen. Getting the
the timestamps from both ends will help understand those issues more
easily.
It can be mostly use in some specific cases, e.g a http server where
requests are tagged with such informations, which later helps to
diagnose some issues and create some useful metrics to give a general
signal.

Signed-off-by: William Dauchy <wdauchy@gmail.com>

---

Changes in v2:
- change from tcp_info to a new getsockopt() to avoid making tcp_info
  bigger for everyone
---
 include/uapi/linux/tcp.h |  6 ++++++
 net/ipv4/tcp.c           | 30 ++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h
index 81e697978e8b..2a9685216aef 100644
--- a/include/uapi/linux/tcp.h
+++ b/include/uapi/linux/tcp.h
@@ -128,12 +128,18 @@ enum {
 #define TCP_CM_INQ		TCP_INQ
 
 #define TCP_TX_DELAY		37	/* delay outgoing packets by XX usec */
+#define TCP_TIMESTAMP_OPT	38	/* timestamps option with tsval and tsecr values */
 
 
 #define TCP_REPAIR_ON		1
 #define TCP_REPAIR_OFF		0
 #define TCP_REPAIR_OFF_NO_WP	-1	/* Turn off without window probes */
 
+struct tcp_timestamp_opt {
+	__u32	tcp_tsval;
+	__u32	tcp_tsecr;
+};
+
 struct tcp_repair_opt {
 	__u32	opt_code;
 	__u32	opt_val;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 42187a3b82f4..b9c34a5477dd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3309,6 +3309,21 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
 }
 EXPORT_SYMBOL_GPL(tcp_get_info);
 
+/* Return timestamps option of tcp endpoint. */
+static void tcp_get_tsopt(struct sock *sk, struct tcp_timestamp_opt *tsopt)
+{
+	const struct tcp_sock *tp = tcp_sk(sk);
+
+	memset(tsopt, 0, sizeof(*tsopt));
+	if (sk->sk_type != SOCK_STREAM)
+		return;
+
+	if (tp->rx_opt.tstamp_ok) {
+		tsopt->tcp_tsval = tp->rx_opt.rcv_tsval;
+		tsopt->tcp_tsecr = tp->rx_opt.rcv_tsecr;
+	}
+}
+
 static size_t tcp_opt_stats_get_size(void)
 {
 	return
@@ -3668,6 +3683,21 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
 		return err;
 	}
 #endif
+	case TCP_TIMESTAMP_OPT: {
+		struct tcp_timestamp_opt tsopt;
+
+		if (get_user(len, optlen))
+			return -EFAULT;
+
+		tcp_get_tsopt(sk, &tsopt);
+
+		len = min_t(unsigned int, len, sizeof(tsopt));
+		if (put_user(len, optlen))
+			return -EFAULT;
+		if (copy_to_user(optval, &tsopt, len))
+			return -EFAULT;
+		return 0;
+	}
 	default:
 		return -ENOPROTOOPT;
 	}
-- 
2.23.0


  parent reply	other threads:[~2019-10-26 18:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02 22:10 [PATCH] tcp: add tsval and tsecr to TCP_INFO William Dauchy
2019-10-02 22:33 ` Eric Dumazet
2019-10-02 22:54   ` William Dauchy
2019-10-02 23:14     ` Eric Dumazet
2019-10-03  5:47       ` William Dauchy
2019-10-26 18:45 ` William Dauchy [this message]
2019-10-26 20:42   ` [PATCH v2] tcp: add timestamp options fetcher Eric Dumazet

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=20191026184554.32648-1-wdauchy@gmail.com \
    --to=wdauchy@gmail.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.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).