mptcp: make shadowsocks kernel independant

This commit is contained in:
Sebastien DUPONCHEEL
2017-03-16 13:06:09 +08:00
committed by Max Lv
parent ea947db74d
commit efbd488890
5 changed files with 54 additions and 13 deletions
+14 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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