Use TCP Fast Open for client sockets

Set the TCP_FASTOPEN_CONNECT option on client sockets to signal desire to use TCP Fast Open.

See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=19f6d3f3c8422d65b5e3d2162e30ef07c6e21ea2
This commit is contained in:
Craig Andrews 2019-03-09 21:13:12 -05:00
parent 5a213c9650
commit 0a880ea607
No known key found for this signature in database
GPG Key ID: 4589B16C461AB092
2 changed files with 9 additions and 1 deletions

View File

@ -277,6 +277,11 @@ int connect_addr(struct connection *cnx, int fd_from)
log_message(LOG_ERR, "forward to %s failed:socket: %s\n",
cnx->proto->name, strerror(errno));
} else {
one = 1;
// indicate desire to use TCP Fast Open
setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &one, sizeof(one));
// no need to check return value; if it's not supported, that's okay
if (cfg.transparent) {
res = bind_peer(fd, fd_from);
CHECK_RES_RETURN(res, "bind_peer");
@ -288,7 +293,6 @@ int connect_addr(struct connection *cnx, int fd_from)
close(fd);
} else {
if (cnx->proto->keepalive) {
one = 1;
res = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&one, sizeof(one));
CHECK_RES_RETURN(res, "setsockopt(SO_KEEPALIVE)");
}

View File

@ -67,6 +67,10 @@
#define IP_FREEBIND 0
#endif
#ifndef TCP_FASTOPEN_CONNECT
#define TCP_FASTOPEN_CONNECT 30 /* Attempt FastOpen with connect. */
#endif
enum connection_state {
ST_PROBING=1, /* Waiting for timeout to find where to forward */
ST_SHOVELING /* Connexion is established */