mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 07:38:49 -05:00
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
This commit is contained in:
parent
9f691be3d4
commit
979b012eeb
@ -3275,6 +3275,7 @@ AC_CHECK_HEADERS(
|
|||||||
net/if.h \
|
net/if.h \
|
||||||
netinet/in.h \
|
netinet/in.h \
|
||||||
sys/un.h \
|
sys/un.h \
|
||||||
|
linux/tcp.h \
|
||||||
netinet/tcp.h \
|
netinet/tcp.h \
|
||||||
netdb.h \
|
netdb.h \
|
||||||
sys/sockio.h \
|
sys/sockio.h \
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
#ifdef HAVE_SYS_UN_H
|
#ifdef HAVE_SYS_UN_H
|
||||||
#include <sys/un.h> /* for sockaddr_un */
|
#include <sys/un.h> /* for sockaddr_un */
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NETINET_TCP_H
|
#ifdef HAVE_LINUX_TCP_H
|
||||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
#include <linux/tcp.h>
|
||||||
|
#elif defined(HAVE_NETINET_TCP_H)
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
#ifdef HAVE_SYS_IOCTL_H
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -989,6 +991,9 @@ static CURLcode singleipconnect(struct connectdata *conn,
|
|||||||
char ipaddress[MAX_IPADR_LEN];
|
char ipaddress[MAX_IPADR_LEN];
|
||||||
long port;
|
long port;
|
||||||
bool is_tcp;
|
bool is_tcp;
|
||||||
|
#ifdef TCP_FASTOPEN_CONNECT
|
||||||
|
int optval = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
*sockp = CURL_SOCKET_BAD;
|
*sockp = CURL_SOCKET_BAD;
|
||||||
|
|
||||||
@ -1092,7 +1097,15 @@ static CURLcode singleipconnect(struct connectdata *conn,
|
|||||||
# else
|
# else
|
||||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||||
# endif /* HAVE_BUILTIN_AVAILABLE */
|
# 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)
|
if(conn->given->flags & PROTOPT_SSL)
|
||||||
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
|
||||||
else
|
else
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
|
|
||||||
#include "curl_setup.h"
|
#include "curl_setup.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX_TCP_H
|
||||||
|
#include <linux/tcp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
@ -360,7 +364,7 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
|
|||||||
available. */
|
available. */
|
||||||
pre_receive_plain(conn, num);
|
pre_receive_plain(conn, num);
|
||||||
|
|
||||||
#ifdef MSG_FASTOPEN /* Linux */
|
#if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */
|
||||||
if(conn->bits.tcp_fastopen) {
|
if(conn->bits.tcp_fastopen) {
|
||||||
bytes_written = sendto(sockfd, mem, len, MSG_FASTOPEN,
|
bytes_written = sendto(sockfd, mem, len, MSG_FASTOPEN,
|
||||||
conn->ip_addr->ai_addr, conn->ip_addr->ai_addrlen);
|
conn->ip_addr->ai_addr, conn->ip_addr->ai_addrlen);
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX_TCP_H
|
||||||
|
#include <linux/tcp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
@ -2450,7 +2454,8 @@ static CURLcode setopt(struct Curl_easy *data, CURLoption option,
|
|||||||
data->set.tcp_keepintvl = arg;
|
data->set.tcp_keepintvl = arg;
|
||||||
break;
|
break;
|
||||||
case CURLOPT_TCP_FASTOPEN:
|
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;
|
data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
|
||||||
#else
|
#else
|
||||||
result = CURLE_NOT_BUILT_IN;
|
result = CURLE_NOT_BUILT_IN;
|
||||||
|
Loading…
Reference in New Issue
Block a user