aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_fastopen.c
diff options
context:
space:
mode:
authorWei Wang <weiwan@google.com>2017-01-23 13:59:22 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-25 14:04:38 -0500
commit19f6d3f3c8422d65b5e3d2162e30ef07c6e21ea2 (patch)
tree87a4399e42ae6b0ae622718952d66e666e64d3ef /net/ipv4/tcp_fastopen.c
parent25776aa943401662617437841b3d3ea4693ee98a (diff)
net/tcp-fastopen: Add new API support
This patch adds a new socket option, TCP_FASTOPEN_CONNECT, as an alternative way to perform Fast Open on the active side (client). Prior to this patch, a client needs to replace the connect() call with sendto(MSG_FASTOPEN). This can be cumbersome for applications who want to use Fast Open: these socket operations are often done in lower layer libraries used by many other applications. Changing these libraries and/or the socket call sequences are not trivial. A more convenient approach is to perform Fast Open by simply enabling a socket option when the socket is created w/o changing other socket calls sequence: s = socket() create a new socket setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN_CONNECT …); newly introduced sockopt If set, new functionality described below will be used. Return ENOTSUPP if TFO is not supported or not enabled in the kernel. connect() With cookie present, return 0 immediately. With no cookie, initiate 3WHS with TFO cookie-request option and return -1 with errno = EINPROGRESS. write()/sendmsg() With cookie present, send out SYN with data and return the number of bytes buffered. With no cookie, and 3WHS not yet completed, return -1 with errno = EINPROGRESS. No MSG_FASTOPEN flag is needed. read() Return -1 with errno = EWOULDBLOCK/EAGAIN if connect() is called but write() is not called yet. Return -1 with errno = EWOULDBLOCK/EAGAIN if connection is established but no msg is received yet. Return number of bytes read if socket is established and there is msg received. The new API simplifies life for applications that always perform a write() immediately after a successful connect(). Such applications can now take advantage of Fast Open by merely making one new setsockopt() call at the time of creating the socket. Nothing else about the application's socket call sequence needs to change. Signed-off-by: Wei Wang <weiwan@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_fastopen.c')
-rw-r--r--net/ipv4/tcp_fastopen.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index f90e09e1ff4c..9674bec4a0f8 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -346,3 +346,36 @@ bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss,
346 } 346 }
347 return cookie->len > 0; 347 return cookie->len > 0;
348} 348}
349
350/* This function checks if we want to defer sending SYN until the first
351 * write(). We defer under the following conditions:
352 * 1. fastopen_connect sockopt is set
353 * 2. we have a valid cookie
354 * Return value: return true if we want to defer until application writes data
355 * return false if we want to send out SYN immediately
356 */
357bool tcp_fastopen_defer_connect(struct sock *sk, int *err)
358{
359 struct tcp_fastopen_cookie cookie = { .len = 0 };
360 struct tcp_sock *tp = tcp_sk(sk);
361 u16 mss;
362
363 if (tp->fastopen_connect && !tp->fastopen_req) {
364 if (tcp_fastopen_cookie_check(sk, &mss, &cookie)) {
365 inet_sk(sk)->defer_connect = 1;
366 return true;
367 }
368
369 /* Alloc fastopen_req in order for FO option to be included
370 * in SYN
371 */
372 tp->fastopen_req = kzalloc(sizeof(*tp->fastopen_req),
373 sk->sk_allocation);
374 if (tp->fastopen_req)
375 tp->fastopen_req->cookie = cookie;
376 else
377 *err = -ENOBUFS;
378 }
379 return false;
380}
381EXPORT_SYMBOL(tcp_fastopen_defer_connect);