Browse Source

mptcp: make shadowsocks kernel independant

pull/1327/head
Sebastien DUPONCHEEL 7 years ago
committed by Max Lv
parent
commit
5074cd336d
5 changed files with 54 additions and 13 deletions
  1. 16
      src/local.c
  2. 8
      src/netutils.h
  3. 16
      src/redir.c
  4. 11
      src/server.c
  5. 16
      src/tunnel.c

16
src/local.c

@ -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

8
src/netutils.h

@ -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

16
src/redir.c

@ -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);

11
src/server.c

@ -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");
}
}

16
src/tunnel.c

@ -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

Loading…
Cancel
Save