mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 14:33:55 +00:00
mptcp: make shadowsocks kernel independant
This commit is contained in:
committed by
Max Lv
parent
ea947db74d
commit
efbd488890
+14
-2
@@ -1112,11 +1112,23 @@ create_remote(listen_ctx_t *listener,
|
||||
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
|
||||
#endif
|
||||
|
||||
if (listener->mptcp == 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
||||
if (listener->mptcp > 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err == -1) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
} else if (listener->mptcp == 1) {
|
||||
int i = 0;
|
||||
while((listener->mptcp = mptcp_enabled_values[i]) > 0) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err != -1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (listener->mptcp == 0) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
}
|
||||
|
||||
// Setup
|
||||
|
||||
+3
-5
@@ -46,13 +46,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Backward compatibility for MPTCP_ENABLED between kernel 3 & 4 */
|
||||
/* 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
|
||||
#ifdef TCP_CC_INFO
|
||||
#define MPTCP_ENABLED 42
|
||||
static const char mptcp_enabled_values[] = { 42, 26, 0 };
|
||||
#else
|
||||
#define MPTCP_ENABLED 26
|
||||
#endif
|
||||
static const char mptcp_enabled_values[] = { MPTCP_ENABLED, 0 };
|
||||
#endif
|
||||
|
||||
#ifndef UPDATE_INTERVAL
|
||||
|
||||
+14
-2
@@ -784,11 +784,23 @@ accept_cb(EV_P_ ev_io *w, int revents)
|
||||
setnonblocking(remotefd);
|
||||
|
||||
// Enable MPTCP
|
||||
if (listener->mptcp == 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
||||
if (listener->mptcp > 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err == -1) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
} else if (listener->mptcp == 1) {
|
||||
int i = 0;
|
||||
while((listener->mptcp = mptcp_enabled_values[i]) > 0) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err != -1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (listener->mptcp == 0) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
}
|
||||
|
||||
server_t *server = new_server(serverfd);
|
||||
|
||||
+9
-2
@@ -388,8 +388,15 @@ create_and_bind(const char *host, const char *port, int mptcp)
|
||||
}
|
||||
|
||||
if (mptcp == 1) {
|
||||
int err = setsockopt(listen_sock, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
||||
if (err == -1) {
|
||||
int i = 0;
|
||||
while((mptcp = mptcp_enabled_values[i]) > 0) {
|
||||
int err = setsockopt(listen_sock, IPPROTO_TCP, mptcp, &opt, sizeof(opt));
|
||||
if (err != -1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (mptcp == 0) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -659,11 +659,23 @@ accept_cb(EV_P_ ev_io *w, int revents)
|
||||
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
|
||||
#endif
|
||||
|
||||
if (listener->mptcp == 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
||||
if (listener->mptcp > 1) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err == -1) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
} else if (listener->mptcp == 1) {
|
||||
int i = 0;
|
||||
while((listener->mptcp = mptcp_enabled_values[i]) > 0) {
|
||||
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||
if (err != -1) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (listener->mptcp == 0) {
|
||||
ERROR("failed to enable multipath TCP");
|
||||
}
|
||||
}
|
||||
|
||||
// Setup
|
||||
|
||||
Reference in New Issue
Block a user