From 6af7e5910f6cbc614eedf5b8c59a32ff6ef517ee Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 26 Jan 2017 20:21:57 +0000 Subject: [PATCH] TFO: remember setsockopt results, to condition non-transport client use. Bug 2027 --- src/src/daemon.c | 6 ++++++ src/src/globals.c | 1 + src/src/globals.h | 1 + src/src/ip.c | 3 ++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/src/daemon.c b/src/src/daemon.c index d799ea4e8..67ee6cb2e 100644 --- a/src/src/daemon.c +++ b/src/src/daemon.c @@ -1423,6 +1423,9 @@ if (daemon_listen && !inetd_wait_mode) necessary for (some release of) USAGI Linux; other IP stacks fail at the listen() stage instead. */ +#ifdef TCP_FASTOPEN + tcp_fastopen_ok = TRUE; +#endif for(;;) { uschar *msg, *addr; @@ -1459,7 +1462,10 @@ if (daemon_listen && !inetd_wait_mode) #ifdef TCP_FASTOPEN if (setsockopt(listen_sockets[sk], IPPROTO_TCP, TCP_FASTOPEN, &smtp_connect_backlog, sizeof(smtp_connect_backlog))) + { DEBUG(D_any) debug_printf("setsockopt FASTOPEN: %s\n", strerror(errno)); + tcp_fastopen_ok = FALSE; + } #endif /* Start listening on the bound socket, establishing the maximum backlog of diff --git a/src/src/globals.c b/src/src/globals.c index bb5acb6fc..86f7f5b20 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1400,6 +1400,7 @@ uid_t system_filter_uid = (uid_t)-1; BOOL system_filter_uid_set = FALSE; BOOL system_filtering = FALSE; +BOOL tcp_fastopen_ok = FALSE; BOOL tcp_nodelay = TRUE; #ifdef USE_TCP_WRAPPERS uschar *tcp_wrappers_daemon_name = US TCP_WRAPPERS_DAEMON_NAME; diff --git a/src/src/globals.h b/src/src/globals.h index 62bcb7a98..5adad7ba0 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -906,6 +906,7 @@ extern uid_t system_filter_uid; /* Uid for running system filter */ extern BOOL system_filter_uid_set; /* TRUE if uid set */ extern BOOL system_filtering; /* TRUE when running system filter */ +extern BOOL tcp_fastopen_ok; /* appears to be supported by kernel */ extern BOOL tcp_nodelay; /* Controls TCP_NODELAY on daemon */ #ifdef USE_TCP_WRAPPERS extern uschar *tcp_wrappers_daemon_name; /* tcpwrappers daemon lookup name */ diff --git a/src/src/ip.c b/src/src/ip.c index 8bb6bed1f..51bd74bcb 100644 --- a/src/src/ip.c +++ b/src/src/ip.c @@ -303,6 +303,7 @@ int namelen, port; host_item shost; host_item *h; int af = 0, fd, fd4 = -1, fd6 = -1; +BOOL fastopen = tcp_fastopen_ok && type == SOCK_STREAM; shost.next = NULL; shost.address = NULL; @@ -358,7 +359,7 @@ for (h = &shost; h; h = h->next) } for(port = portlo; port <= porthi; port++) - if (ip_connect(fd, af, h->address, port, timeout, type == SOCK_STREAM) == 0) + if (ip_connect(fd, af, h->address, port, timeout, fastopen) == 0) { if (fd != fd6) close(fd6); if (fd != fd4) close(fd4); -- 2.30.2