Browse Source

Fix --mptcp on kernels with mainlined MPTCP.

Mainlined MPTCP on Linux 5.6+ is enabled with IPPROTO_MPTCP rather than setsockopt.
pull/2903/head
Tristan Schmelcher 2 years ago
committed by Max Lv
parent
commit
1630764b02
5 changed files with 38 additions and 4 deletions
  1. 10
      src/local.c
  2. 2
      src/netutils.h
  3. 10
      src/redir.c
  4. 10
      src/server.c
  5. 10
      src/tunnel.c

10
src/local.c

@ -1272,7 +1272,13 @@ create_remote(listen_ctx_t *listener,
remote_addr = addr;
}
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
int protocol = IPPROTO_TCP;
#ifdef IPPROTO_MPTCP
if (listener->mptcp > 0) {
protocol = IPPROTO_MPTCP;
}
#endif
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, protocol);
if (remotefd == -1) {
ERROR("socket");
@ -1285,6 +1291,7 @@ create_remote(listen_ctx_t *listener,
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
#ifndef IPPROTO_MPTCP
if (listener->mptcp > 1) {
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
if (err == -1) {
@ -1303,6 +1310,7 @@ create_remote(listen_ctx_t *listener,
ERROR("failed to enable multipath TCP");
}
}
#endif
if (tcp_outgoing_sndbuf > 0) {
setsockopt(remotefd, SOL_SOCKET, SO_SNDBUF, &tcp_outgoing_sndbuf, sizeof(int));

2
src/netutils.h

@ -60,12 +60,14 @@ typedef struct {
char *port;
} ss_addr_t;
#ifndef IPPROTO_MPTCP
/* 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 };
#else
static const char mptcp_enabled_values[] = { MPTCP_ENABLED, 0 };
#endif
#endif
#ifndef UPDATE_INTERVAL
#define UPDATE_INTERVAL 5

10
src/redir.c

@ -770,7 +770,13 @@ accept_cb(EV_P_ ev_io *w, int revents)
int index = rand() % listener->remote_num;
struct sockaddr *remote_addr = listener->remote_addr[index];
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
int protocol = IPPROTO_TCP;
#ifdef IPPROTO_MPTCP
if (listener->mptcp > 0) {
protocol = IPPROTO_MPTCP;
}
#endif
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, protocol);
if (remotefd == -1) {
ERROR("socket");
return;
@ -808,6 +814,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
#endif
}
#ifndef IPPROTO_MPTCP
// Enable MPTCP
if (listener->mptcp > 1) {
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
@ -827,6 +834,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
ERROR("failed to enable multipath TCP");
}
}
#endif
if (tcp_outgoing_sndbuf > 0) {
setsockopt(remotefd, SOL_SOCKET, SO_SNDBUF, &tcp_outgoing_sndbuf, sizeof(int));

10
src/server.c

@ -594,7 +594,13 @@ create_and_bind(const char *host, const char *port, int mptcp)
}
for (/*rp = result*/; rp != NULL; rp = rp->ai_next) {
listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
int protocol = rp->ai_protocol;
#ifdef IPPROTO_MPTCP
if (mptcp == 1) {
protocol = IPPROTO_MPTCP;
}
#endif
listen_sock = socket(rp->ai_family, rp->ai_socktype, protocol);
if (listen_sock == -1) {
continue;
}
@ -616,6 +622,7 @@ create_and_bind(const char *host, const char *port, int mptcp)
}
}
#ifndef IPPROTO_MPTCP
if (mptcp == 1) {
int i = 0;
while ((mptcp = mptcp_enabled_values[i]) > 0) {
@ -629,6 +636,7 @@ create_and_bind(const char *host, const char *port, int mptcp)
ERROR("failed to enable multipath TCP");
}
}
#endif
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {

10
src/tunnel.c

@ -736,7 +736,13 @@ accept_cb(EV_P_ ev_io *w, int revents)
int index = rand() % listener->remote_num;
struct sockaddr *remote_addr = listener->remote_addr[index];
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
int protocol = IPPROTO_TCP;
#ifdef IPPROTO_MPTCP
if (listener->mptcp > 0) {
protocol = IPPROTO_MPTCP;
}
#endif
int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, protocol);
if (remotefd == -1) {
ERROR("socket");
return;
@ -767,6 +773,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
#ifndef IPPROTO_MPTCP
if (listener->mptcp > 1) {
int err = setsockopt(remotefd, SOL_TCP, listener->mptcp, &opt, sizeof(opt));
if (err == -1) {
@ -785,6 +792,7 @@ accept_cb(EV_P_ ev_io *w, int revents)
ERROR("failed to enable multipath TCP");
}
}
#endif
if (tcp_outgoing_sndbuf > 0) {
setsockopt(remotefd, SOL_SOCKET, SO_SNDBUF, &tcp_outgoing_sndbuf, sizeof(int));

Loading…
Cancel
Save