[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 101/116: connect: add support for new TCP Fast Open
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 101/116: connect: add support for new TCP Fast Open API on Linux |
Date: |
Tue, 05 Dec 2017 14:52:11 +0100 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 979b012eeb1908e7e3ad13c736fb1dbc73187780
Author: Alessandro Ghedini <address@hidden>
AuthorDate: Sun Nov 5 23:59:55 2017 +0000
connect: add support for new TCP Fast Open API on Linux
The new API added in Linux 4.11 only requires setting a socket option
before connecting, without the whole sento() machinery.
Notably, this makes it possible to use TFO with SSL connections on Linux
as well, without the need to mess around with OpenSSL (or whatever other
SSL library) internals.
Closes #2056
---
configure.ac | 1 +
lib/connect.c | 19 ++++++++++++++++---
lib/sendf.c | 6 +++++-
lib/setopt.c | 7 ++++++-
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index c15ff4e4c..a72a612fb 100755
--- a/configure.ac
+++ b/configure.ac
@@ -3275,6 +3275,7 @@ AC_CHECK_HEADERS(
net/if.h \
netinet/in.h \
sys/un.h \
+ linux/tcp.h \
netinet/tcp.h \
netdb.h \
sys/sockio.h \
diff --git a/lib/connect.c b/lib/connect.c
index 45e18bc07..3edb71eb7 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -28,8 +28,10 @@
#ifdef HAVE_SYS_UN_H
#include <sys/un.h> /* for sockaddr_un */
#endif
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h> /* for TCP_NODELAY */
+#ifdef HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#elif defined(HAVE_NETINET_TCP_H)
+#include <netinet/tcp.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
@@ -989,6 +991,9 @@ static CURLcode singleipconnect(struct connectdata *conn,
char ipaddress[MAX_IPADR_LEN];
long port;
bool is_tcp;
+#ifdef TCP_FASTOPEN_CONNECT
+ int optval = 1;
+#endif
*sockp = CURL_SOCKET_BAD;
@@ -1092,7 +1097,15 @@ static CURLcode singleipconnect(struct connectdata *conn,
# else
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
# endif /* HAVE_BUILTIN_AVAILABLE */
-#elif defined(MSG_FASTOPEN) /* Linux */
+#elif defined(TCP_FASTOPEN_CONNECT) /* Linux >= 4.11 */
+ if(setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
+ (void *)&optval, sizeof(optval)) < 0)
+ infof(data, "Failed to enable TCP Fast Open on fd %d\n", sockfd);
+ else
+ infof(data, "TCP_FASTOPEN_CONNECT set\n");
+
+ rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
+#elif defined(MSG_FASTOPEN) /* old Linux */
if(conn->given->flags & PROTOPT_SSL)
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
else
diff --git a/lib/sendf.c b/lib/sendf.c
index cbdb233fd..a1cb8e478 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -22,6 +22,10 @@
#include "curl_setup.h"
+#ifdef HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#endif
+
#include <curl/curl.h>
#include "urldata.h"
@@ -360,7 +364,7 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
available. */
pre_receive_plain(conn, num);
-#ifdef MSG_FASTOPEN /* Linux */
+#if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */
if(conn->bits.tcp_fastopen) {
bytes_written = sendto(sockfd, mem, len, MSG_FASTOPEN,
conn->ip_addr->ai_addr, conn->ip_addr->ai_addrlen);
diff --git a/lib/setopt.c b/lib/setopt.c
index 200bfc5ab..70466bffb 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -26,6 +26,10 @@
#include <limits.h>
#endif
+#ifdef HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#endif
+
#include "urldata.h"
#include "url.h"
#include "progress.h"
@@ -2450,7 +2454,8 @@ static CURLcode setopt(struct Curl_easy *data, CURLoption
option,
data->set.tcp_keepintvl = arg;
break;
case CURLOPT_TCP_FASTOPEN:
-#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN)
+#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \
+ defined(TCP_FASTOPEN_CONNECT)
data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
#else
result = CURLE_NOT_BUILT_IN;
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 75/116: README.md: fixed layout, (continued)
- [GNUnet-SVN] [gnurl] 75/116: README.md: fixed layout, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 77/116: SMB: fix uninitialized local variable, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 27/116: RELEASE-NOTES: synced with f20cbac97, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 68/116: curl_share_setopt.3: document CURL_LOCK_DATA_CONNECT, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 52/116: HTTP: support multiple Content-Encodings, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 69/116: --interface: add support for Linux VRF, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 106/116: ssh: remove check for a NULL pointer (!), gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 92/116: http2: fix "Value stored to 'hdbuf' is never read" scan-build error, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 66/116: test1554: verify connection cache sharing, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 67/116: examples: add shared-connection-cache, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 101/116: connect: add support for new TCP Fast Open API on Linux,
gnunet <=
- [GNUnet-SVN] [gnurl] 58/116: url: remove unncessary NULL-check, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 79/116: INTERNALS: we may use libidn2 now, not libidn, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 96/116: test1264: verify URL with space in host name being rejected, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 26/116: auth: Added test cases for RFC7616, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 95/116: url: reject ASCII control characters and space in host names, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 78/116: zlib/brotli: only include header files in modules needing them, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 103/116: URL: update "file:" URL handling, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 83/116: openssl: fix too broad use of HAVE_OPAQUE_EVP_PKEY, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 70/116: RELEASE-NOTES: synced with 32828cc4f, gnunet, 2017/12/05
- [GNUnet-SVN] [gnurl] 98/116: connect: improve the bind error message, gnunet, 2017/12/05