netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Wang <tracywwnj@gmail.com>
To: netdev@vger.kernel.org, David Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>,
	Yuchung Cheng <ycheng@google.com>, Wei Wang <weiwan@google.com>
Subject: [PATCH net-next 1/3] net/tcp-fastopen: refactor cookie check logic
Date: Mon, 23 Jan 2017 10:59:20 -0800	[thread overview]
Message-ID: <20170123185922.48046-2-tracywwnj@gmail.com> (raw)
In-Reply-To: <20170123185922.48046-1-tracywwnj@gmail.com>

From: Wei Wang <weiwan@google.com>

Refactor the cookie check logic in tcp_send_syn_data() into a function.
This function will be called else where in later changes.

Signed-off-by: Wei Wang <weiwan@google.com>
---
 include/net/tcp.h       |  2 ++
 net/ipv4/tcp_fastopen.c | 21 +++++++++++++++++++++
 net/ipv4/tcp_output.c   | 16 ++--------------
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index c55d65f74f7f..de67541d7adf 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1493,6 +1493,8 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
 			      struct tcp_fastopen_cookie *foc,
 			      struct dst_entry *dst);
 void tcp_fastopen_init_key_once(bool publish);
+bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss,
+			     struct tcp_fastopen_cookie *cookie);
 #define TCP_FASTOPEN_KEY_LENGTH 16
 
 /* Fastopen key context */
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index f51919535ca7..f90e09e1ff4c 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -325,3 +325,24 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
 	*foc = valid_foc;
 	return NULL;
 }
+
+bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss,
+			       struct tcp_fastopen_cookie *cookie)
+{
+	unsigned long last_syn_loss = 0;
+	int syn_loss = 0;
+
+	tcp_fastopen_cache_get(sk, mss, cookie, &syn_loss, &last_syn_loss);
+
+	/* Recurring FO SYN losses: no cookie or data in SYN */
+	if (syn_loss > 1 &&
+	    time_before(jiffies, last_syn_loss + (60*HZ << syn_loss))) {
+		cookie->len = -1;
+		return false;
+	}
+	if (sysctl_tcp_fastopen & TFO_CLIENT_NO_COOKIE) {
+		cookie->len = -1;
+		return true;
+	}
+	return cookie->len > 0;
+}
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 9a1a1494b9dd..671c69535671 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3267,23 +3267,11 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct tcp_fastopen_request *fo = tp->fastopen_req;
-	int syn_loss = 0, space, err = 0;
-	unsigned long last_syn_loss = 0;
+	int space, err = 0;
 	struct sk_buff *syn_data;
 
 	tp->rx_opt.mss_clamp = tp->advmss;  /* If MSS is not cached */
-	tcp_fastopen_cache_get(sk, &tp->rx_opt.mss_clamp, &fo->cookie,
-			       &syn_loss, &last_syn_loss);
-	/* Recurring FO SYN losses: revert to regular handshake temporarily */
-	if (syn_loss > 1 &&
-	    time_before(jiffies, last_syn_loss + (60*HZ << syn_loss))) {
-		fo->cookie.len = -1;
-		goto fallback;
-	}
-
-	if (sysctl_tcp_fastopen & TFO_CLIENT_NO_COOKIE)
-		fo->cookie.len = -1;
-	else if (fo->cookie.len <= 0)
+	if (!tcp_fastopen_cookie_check(sk, &tp->rx_opt.mss_clamp, &fo->cookie))
 		goto fallback;
 
 	/* MSS for SYN-data is based on cached MSS and bounded by PMTU and
-- 
2.11.0.483.g087da7b7c-goog

  reply	other threads:[~2017-01-23 19:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-23 18:59 [PATCH net-next 0/3] net/tcp-fastopen: Add new userspace API support Wei Wang
2017-01-23 18:59 ` Wei Wang [this message]
2017-01-23 19:13   ` [PATCH net-next 1/3] net/tcp-fastopen: refactor cookie check logic Eric Dumazet
2017-01-23 20:51   ` Yuchung Cheng
2017-01-23 18:59 ` [PATCH net-next 2/3] net: Remove __sk_dst_reset() in tcp_v6_connect() Wei Wang
2017-01-23 19:14   ` Eric Dumazet
2017-01-23 18:59 ` [PATCH net-next 3/3] net/tcp-fastopen: Add new API support Wei Wang
2017-01-23 19:15   ` Eric Dumazet
2017-01-23 20:55   ` Yuchung Cheng
2017-01-23 21:16   ` Willy Tarreau
     [not found]     ` <CAEA6p_DxVMAry1PCz_idmk=TGpnnTib3WpWso03FB1oMVXN+sg@mail.gmail.com>
2017-01-23 21:37       ` Willy Tarreau
2017-01-23 22:01         ` Willy Tarreau
2017-01-23 22:33           ` Willy Tarreau
     [not found]             ` <CAC15z3g8OxZNET+OnvcyYwHYuHq7QBamgGmjkBHzDr-XnUSGDQ@mail.gmail.com>
2017-01-23 23:01               ` Willy Tarreau
2017-01-24 17:44     ` Eric Dumazet
2017-01-24 18:34       ` Willy Tarreau
2017-01-24 18:51         ` Eric Dumazet
2017-01-24 19:11           ` Willy Tarreau
     [not found]             ` <CAC15z3izWNh7th_yxA_a90vgLnU5XzVDm6vyojq3cMDgQZ71YA@mail.gmail.com>
2017-01-25 17:22               ` David Miller
2017-01-25 17:54                 ` Willy Tarreau
2017-01-25 18:54                   ` Wei Wang
2017-01-25 19:03                     ` Eric Dumazet
2017-01-25 19:03                     ` David Miller
2017-01-25 19:30                       ` Wei Wang
2017-01-25 17:53               ` Willy Tarreau
2017-01-24  7:30   ` Willy Tarreau
2017-01-24 17:26     ` Yuchung Cheng
2017-01-24 17:42       ` Eric Dumazet
2017-01-24 18:43         ` Willy Tarreau
2017-01-25 19:09 ` [PATCH net-next 0/3] net/tcp-fastopen: Add new userspace " David Miller

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=20170123185922.48046-2-tracywwnj@gmail.com \
    --to=tracywwnj@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=weiwan@google.com \
    --cc=ycheng@google.com \
    /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).