mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-29 20:43:44 +00:00
Refine TFO in redir and server mode
This commit is contained in:
+1
-1
@@ -139,7 +139,7 @@ AM_CONDITIONAL(BUILD_REDIRECTOR, test "$os_support" = "linux")
|
||||
AM_CONDITIONAL(BUILD_WINCOMPAT, test "$os_support" = "mingw")
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_CHECK_HEADERS([limits.h stdint.h inttypes.h arpa/inet.h fcntl.h langinfo.h locale.h netdb.h netinet/in.h stdlib.h string.h strings.h unistd.h sys/ioctl.h linux/random.h])
|
||||
AC_CHECK_HEADERS([limits.h stdint.h inttypes.h arpa/inet.h fcntl.h langinfo.h locale.h linux/tcp.h netinet/tcp.h netdb.h netinet/in.h stdlib.h string.h strings.h unistd.h sys/ioctl.h linux/random.h])
|
||||
|
||||
dnl A special check required for <net/if.h> on Darwin. See
|
||||
dnl http://www.gnu.org/software/autoconf/manual/html_node/Header-Portability.html.
|
||||
|
||||
+6
-3
@@ -25,13 +25,16 @@
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <netdb.h>
|
||||
#if HAVE_LINUX_TCP_H
|
||||
#include <linux/tcp.h>
|
||||
#else
|
||||
#elif defined(HAVE_NETINET_TCP_H)
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
/* MPTCP_ENABLED setsockopt values for kernel 4 & 3, best behaviour to be independant of kernel version is to test from newest to the latest values */
|
||||
#ifndef MPTCP_ENABLED
|
||||
static const char mptcp_enabled_values[] = { 42, 26, 0 };
|
||||
|
||||
+1
-1
@@ -558,7 +558,7 @@ remote_send_cb(EV_P_ ev_io *w, int revents)
|
||||
if(setsockopt(remote->fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
|
||||
(void *)&optval, sizeof(optval)) < 0)
|
||||
FATAL("failed to set TCP_FASTOPEN_CONNECT");
|
||||
s = connect(remote->fd, (struct sockaddr *)&(remote->addr), remote->addr_len);
|
||||
s = connect(remote->fd, remote->addr, get_sockaddr_len(remote->addr));
|
||||
if (s == 0)
|
||||
s = send(remote->fd, remote->buf->data, remote->buf->len, 0);
|
||||
#elif defined(MSG_FASTOPEN)
|
||||
|
||||
+15
-9
@@ -506,9 +506,19 @@ connect_to_remote(EV_P_ struct addrinfo *res,
|
||||
|
||||
remote_t *remote = new_remote(sockfd);
|
||||
|
||||
#ifdef TCP_FASTOPEN
|
||||
if (fast_open) {
|
||||
#ifdef __APPLE__
|
||||
#if defined(TCP_FASTOPEN_CONNECT)
|
||||
int optval = 1;
|
||||
if(setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
|
||||
(void *)&optval, sizeof(optval)) < 0)
|
||||
FATAL("failed to set TCP_FASTOPEN_CONNECT");
|
||||
int s = connect(sockfd, res->ai_addr, res->ai_addrlen);
|
||||
if (s == 0)
|
||||
s = send(sockfd, server->buf->data, server->buf->len, 0);
|
||||
#elif defined(MSG_FASTOPEN)
|
||||
ssize_t s = sendto(sockfd, server->buf->data, server->buf->len,
|
||||
MSG_FASTOPEN, res->ai_addr, res->ai_addrlen);
|
||||
#elif defined(CONNECT_DATA_IDEMPOTENT)
|
||||
((struct sockaddr_in *)(res->ai_addr))->sin_len = sizeof(struct sockaddr_in);
|
||||
sa_endpoints_t endpoints;
|
||||
memset((char *)&endpoints, 0, sizeof(endpoints));
|
||||
@@ -521,16 +531,13 @@ connect_to_remote(EV_P_ struct addrinfo *res,
|
||||
size_t len;
|
||||
int s = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY, CONNECT_DATA_IDEMPOTENT,
|
||||
&iov, 1, &len, NULL);
|
||||
if (s == 0) {
|
||||
if (s == 0)
|
||||
s = len;
|
||||
}
|
||||
#else
|
||||
ssize_t s = sendto(sockfd, server->buf->data, server->buf->len,
|
||||
MSG_FASTOPEN, res->ai_addr, res->ai_addrlen);
|
||||
FATAL("fast open is not enabled in this build");
|
||||
#endif
|
||||
if (s == -1) {
|
||||
if (errno == CONNECT_IN_PROGRESS || errno == EAGAIN
|
||||
|| errno == EWOULDBLOCK) {
|
||||
if (errno == CONNECT_IN_PROGRESS) {
|
||||
// The remote server doesn't support tfo or it's the first connection to the server.
|
||||
// It will automatically fall back to conventional TCP.
|
||||
} else if (errno == EOPNOTSUPP || errno == EPROTONOSUPPORT ||
|
||||
@@ -546,7 +553,6 @@ connect_to_remote(EV_P_ struct addrinfo *res,
|
||||
server->buf->len -= s;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!fast_open) {
|
||||
int r = connect(sockfd, res->ai_addr, res->ai_addrlen);
|
||||
|
||||
Reference in New Issue
Block a user