diff --git a/common.c b/common.c index bc405b6..71c8076 100644 --- a/common.c +++ b/common.c @@ -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)"); } diff --git a/common.h b/common.h index be3183d..ae00fdf 100644 --- a/common.h +++ b/common.h @@ -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 */