mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-11-02 16:03:45 +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));
|
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (listener->mptcp == 1) {
|
if (listener->mptcp > 1) {
|
||||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
ERROR("failed to enable multipath TCP");
|
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
|
// Setup
|
||||||
|
|||||||
+3
-5
@@ -46,13 +46,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#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
|
#ifndef MPTCP_ENABLED
|
||||||
#ifdef TCP_CC_INFO
|
static const char mptcp_enabled_values[] = { 42, 26, 0 };
|
||||||
#define MPTCP_ENABLED 42
|
|
||||||
#else
|
#else
|
||||||
#define MPTCP_ENABLED 26
|
static const char mptcp_enabled_values[] = { MPTCP_ENABLED, 0 };
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UPDATE_INTERVAL
|
#ifndef UPDATE_INTERVAL
|
||||||
|
|||||||
+14
-2
@@ -784,11 +784,23 @@ accept_cb(EV_P_ ev_io *w, int revents)
|
|||||||
setnonblocking(remotefd);
|
setnonblocking(remotefd);
|
||||||
|
|
||||||
// Enable MPTCP
|
// Enable MPTCP
|
||||||
if (listener->mptcp == 1) {
|
if (listener->mptcp > 1) {
|
||||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
ERROR("failed to enable multipath TCP");
|
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);
|
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) {
|
if (mptcp == 1) {
|
||||||
int err = setsockopt(listen_sock, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
int i = 0;
|
||||||
if (err == -1) {
|
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");
|
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));
|
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (listener->mptcp == 1) {
|
if (listener->mptcp > 1) {
|
||||||
int err = setsockopt(remotefd, SOL_TCP, MPTCP_ENABLED, &opt, sizeof(opt));
|
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
ERROR("failed to enable multipath TCP");
|
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
|
// Setup
|
||||||
|
|||||||
Reference in New Issue
Block a user