Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2225?usp=email
to review the following change.
Change subject: Add --mptcp option for Multipath TCP transport on Linux
......................................................................
Add --mptcp option for Multipath TCP transport on Linux
With --mptcp, the TCP transport socket is created as Multipath TCP
(IPPROTO_MPTCP), falling back to plain TCP if the kernel lacks MPTCP
support. The flag lives in sockflags and only the TCP path honors it,
so in a multisocket setup only the TCP --local entries become MPTCP.
The SOCKS control connection and the management interface stay plain
TCP. IPPROTO_MPTCP is defined when the libc headers lack it
(glibc < 2.32).
MPTCP rejects IP(V6)_MTU_DISCOVER and IP(V6)_RECVERR with EOPNOTSUPP,
so that error is ignored on MPTCP sockets: a connection that fell back
to plain TCP during the handshake still gets these options, and
--mtu-disc has no effect on a real MPTCP connection.
The kernel ovpn module cannot attach to an MPTCP socket, so --mptcp
disables data channel offload when a TCP transport is used.
Change-Id: I81fffc46c574cda873eba8864444e5c9972549f5
Signed-off-by: Gianmarco De Gregori <[email protected]>
---
M doc/man-sections/link-options.rst
M src/openvpn/dco.c
M src/openvpn/manage.c
M src/openvpn/mtu.c
M src/openvpn/options.c
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/socket_util.h
M src/openvpn/syshead.h
9 files changed, 107 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/2225/1
diff --git a/doc/man-sections/link-options.rst
b/doc/man-sections/link-options.rst
index bbdcf7f..ffc8fdd 100644
--- a/doc/man-sections/link-options.rst
+++ b/doc/man-sections/link-options.rst
@@ -146,6 +146,21 @@
(:code:`p2p`). OpenVPN 2.0 introduces a new mode (:code:`server`) which
implements a multi-client server capability.
+--mptcp
+ Create the TCP transport sockets as Multipath TCP (MPTCP) sockets. UDP
+ sockets are not affected, so in a multisocket setup only the TCP
+ ``--local`` entries use MPTCP. An MPTCP listening socket still accepts
+ plain TCP clients.
+
+ Additional subflows require MPTCP endpoints to be configured in the
+ kernel (``ip mptcp endpoint``); without them the connection uses a
+ single subflow.
+
+ This option is only supported on Linux. If an MPTCP socket cannot be
+ created, OpenVPN logs a warning and falls back to plain TCP. ``--mptcp``
+ disables data channel offload, and ``--mtu-disc`` has no effect on MPTCP
+ connections.
+
--mssfix args
Valid syntax:
diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
index 236be93..d5e89a7 100644
--- a/src/openvpn/dco.c
+++ b/src/openvpn/dco.c
@@ -255,8 +255,26 @@
}
static bool
-dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int
mode)
+dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int
mode,
+ unsigned int sockflags)
{
+#if defined(TARGET_LINUX)
+ /* the kernel ovpn module cannot attach to an MPTCP socket */
+ if (sockflags & SF_MPTCP)
+ {
+ bool tcp = !proto_is_dgram(ce->proto);
+ for (int i = 0; ce->local_list && i < ce->local_list->len; i++)
+ {
+ tcp = tcp || !proto_is_dgram(ce->local_list->array[i]->proto);
+ }
+ if (tcp)
+ {
+ msg(msglevel, "Note: --mptcp disables data channel offload.");
+ return false;
+ }
+ }
+#endif
+
if (ce->fragment)
{
msg(msglevel, "Note: --fragment disables data channel offload.");
@@ -356,7 +374,7 @@
const struct connection_list *l = o->connection_list;
for (int i = 0; i < l->len; ++i)
{
- if (!dco_check_option_ce(l->array[i], msglevel, o->mode))
+ if (!dco_check_option_ce(l->array[i], msglevel, o->mode,
o->sockflags))
{
return false;
}
@@ -364,7 +382,7 @@
}
else
{
- if (!dco_check_option_ce(&o->ce, msglevel, o->mode))
+ if (!dco_check_option_ce(&o->ce, msglevel, o->mode, o->sockflags))
{
return false;
}
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 86c498e..4984c4a 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -2103,7 +2103,7 @@
else
#endif
{
- man->connection.sd_top = create_socket_tcp(man->settings.local);
+ man->connection.sd_top = create_socket_tcp(man->settings.local, 0);
socket_bind(man->connection.sd_top, man->settings.local,
man->settings.local->ai_family,
"MANAGEMENT", false);
}
@@ -2184,7 +2184,7 @@
else
#endif
{
- man->connection.sd_cli = create_socket_tcp(man->settings.local);
+ man->connection.sd_cli = create_socket_tcp(man->settings.local, 0);
status = openvpn_connect(man->connection.sd_cli,
man->settings.local->ai_addr, 5,
&signal_received);
}
diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c
index 7892935..6f4dc08 100644
--- a/src/openvpn/mtu.c
+++ b/src/openvpn/mtu.c
@@ -31,6 +31,7 @@
#include "error.h"
#include "integer.h"
#include "mtu.h"
+#include "socket_util.h"
#include "options.h"
#include "crypto.h"
@@ -222,7 +223,8 @@
#if defined(IP_MTU_DISCOVER)
case AF_INET:
if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, (void
*)&mtu_type,
- sizeof(mtu_type)))
+ sizeof(mtu_type))
+ && !(openvpn_errno() == EOPNOTSUPP && socket_is_mptcp(sd)))
{
msg(M_ERR, "Error setting IP_MTU_DISCOVER type=%d on
TCP/UDP socket", mtu_type);
}
@@ -232,7 +234,8 @@
#if defined(IPV6_MTU_DISCOVER)
case AF_INET6:
if (setsockopt(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void
*)&mtu_type,
- sizeof(mtu_type)))
+ sizeof(mtu_type))
+ && !(openvpn_errno() == EOPNOTSUPP && socket_is_mptcp(sd)))
{
msg(M_ERR, "Error setting IPV6_MTU_DISCOVER type=%d on
TCP6/UDP6 socket",
mtu_type);
@@ -399,7 +402,8 @@
/* see "man 7 ip" (on Linux)
* this works on IPv4 and IPv6(-dual-stack) sockets (v4-mapped)
*/
- if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *)&on, sizeof(on)) != 0)
+ if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *)&on, sizeof(on)) != 0
+ && !(openvpn_errno() == EOPNOTSUPP && socket_is_mptcp(sd)))
{
msg(M_WARN | M_ERRNO,
"Note: enable extended error passing on TCP/UDP socket failed
(IP_RECVERR)");
@@ -408,7 +412,8 @@
* this only works on IPv6 sockets
*/
if (proto_af == AF_INET6
- && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (void *)&on, sizeof(on))
!= 0)
+ && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (void *)&on, sizeof(on))
!= 0
+ && !(openvpn_errno() == EOPNOTSUPP && socket_is_mptcp(sd)))
{
msg(M_WARN | M_ERRNO,
"Note: enable extended error passing on TCP/UDP socket failed
(IPV6_RECVERR)");
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 947439d..0bbfa03 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -332,6 +332,7 @@
"--bind-dev dev : Bind to the given device when making connection to a
peer or\n"
" listening for connections. This allows sending
encrypted packets\n"
" via a VRF present on the system.\n"
+ "--mptcp : Create the TCP transport sockets as Multipath TCP
sockets.\n"
#endif
"--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n"
"--mlock : Disable Paging -- ensures key material and tunnel\n"
@@ -5530,6 +5531,15 @@
VERIFY_PERMISSION(OPT_P_GENERAL);
options->sockflags |= SF_HOST_RANDOMIZE;
}
+ else if (streq(p[0], "mptcp") && !p[1])
+ {
+ VERIFY_PERMISSION(OPT_P_GENERAL);
+#if defined(TARGET_LINUX)
+ options->sockflags |= SF_MPTCP;
+#else
+ msg(M_WARN, "Note: --mptcp is not supported by this build, ignoring");
+#endif
+ }
else if (streq(p[0], "setenv") && p[1] && !p[3])
{
VERIFY_PERMISSION(OPT_P_GENERAL);
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index c07ef60..142a85b 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -174,15 +174,36 @@
*/
socket_descriptor_t
-create_socket_tcp(struct addrinfo *addrinfo)
+create_socket_tcp(struct addrinfo *addrinfo, unsigned int flags)
{
socket_descriptor_t sd;
ASSERT(addrinfo);
ASSERT(addrinfo->ai_socktype == SOCK_STREAM);
- if ((sd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
addrinfo->ai_protocol))
- == SOCKET_UNDEFINED)
+ int protocol = addrinfo->ai_protocol;
+
+#if defined(TARGET_LINUX)
+ if (flags & SF_MPTCP)
+ {
+ protocol = IPPROTO_MPTCP;
+ }
+#endif
+
+ sd = socket(addrinfo->ai_family, addrinfo->ai_socktype, protocol);
+
+#if defined(TARGET_LINUX)
+ if (sd == SOCKET_UNDEFINED && protocol == IPPROTO_MPTCP
+ && (errno == EINVAL || errno == EPROTONOSUPPORT || errno ==
ENOPROTOOPT))
+ {
+ msg(M_WARN | M_ERRNO,
+ "MPTCP: cannot create MPTCP socket, falling back to plain TCP "
+ "(check kernel support and net.mptcp.enabled)");
+ sd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
addrinfo->ai_protocol);
+ }
+#endif
+
+ if (sd == SOCKET_UNDEFINED)
{
msg(M_ERR, "Cannot create TCP socket");
}
@@ -354,13 +375,13 @@
struct addrinfo addrinfo_tmp = *addr;
addrinfo_tmp.ai_socktype = SOCK_STREAM;
addrinfo_tmp.ai_protocol = IPPROTO_TCP;
- sock->ctrl_sd = create_socket_tcp(&addrinfo_tmp);
+ sock->ctrl_sd = create_socket_tcp(&addrinfo_tmp, 0);
bind_local(sock);
}
}
else if (addr->ai_protocol == IPPROTO_TCP || addr->ai_socktype ==
SOCK_STREAM)
{
- sock->sd = create_socket_tcp(addr);
+ sock->sd = create_socket_tcp(addr, sock->sockflags);
socket_apply_options(sock->sd, &sock->socket_buffer_sizes, sock->mark,
sock->bind_dev);
bind_local(sock);
}
@@ -1240,7 +1261,7 @@
if (proxy_retry)
{
openvpn_close_socket(sock->sd);
- sock->sd = create_socket_tcp(sock->info.lsa->current_remote);
+ sock->sd = create_socket_tcp(sock->info.lsa->current_remote,
sock->sockflags);
}
} while (proxy_retry);
diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h
index 2210bfe..48de3e0 100644
--- a/src/openvpn/socket.h
+++ b/src/openvpn/socket.h
@@ -204,6 +204,7 @@
#define SF_DCO_WIN (1 << 5)
#define SF_PREPEND_SA (1 << 6)
#define SF_PKTINFO_COPY_IIF (1 << 7)
+#define SF_MPTCP (1 << 8)
unsigned int sockflags;
int mark;
const char *bind_dev;
@@ -395,7 +396,7 @@
* Low-level functions
*/
-socket_descriptor_t create_socket_tcp(struct addrinfo *);
+socket_descriptor_t create_socket_tcp(struct addrinfo *, unsigned int flags);
/**
* Create a UDP socket for @p af set up the way a link socket is:
--sndbuf/--rcvbuf,
diff --git a/src/openvpn/socket_util.h b/src/openvpn/socket_util.h
index a1a61af..7575cf8 100644
--- a/src/openvpn/socket_util.h
+++ b/src/openvpn/socket_util.h
@@ -180,6 +180,23 @@
return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER;
}
+/**
+ * @brief Returns true if the socket is an MPTCP socket
+ */
+static inline bool
+socket_is_mptcp(socket_descriptor_t sd)
+{
+#if defined(TARGET_LINUX)
+ int protocol = 0;
+ socklen_t len = sizeof(protocol);
+
+ return getsockopt(sd, SOL_SOCKET, SO_PROTOCOL, &protocol, &len) == 0
+ && protocol == IPPROTO_MPTCP;
+#else
+ return false;
+#endif
+}
+
int ascii2proto(const char *proto_name);
sa_family_t ascii2af(const char *proto_name);
diff --git a/src/openvpn/syshead.h b/src/openvpn/syshead.h
index 8f27436..12741f1 100644
--- a/src/openvpn/syshead.h
+++ b/src/openvpn/syshead.h
@@ -398,6 +398,10 @@
#define SOL_IP IPPROTO_IP
#endif
+#if defined(TARGET_LINUX) && !defined(IPPROTO_MPTCP)
+#define IPPROTO_MPTCP 262
+#endif
+
/*
* Define type sa_family_t if it isn't defined in the socket headers
*/
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2225?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81fffc46c574cda873eba8864444e5c9972549f5
Gerrit-Change-Number: 2225
Gerrit-PatchSet: 1
Gerrit-Owner: Gianmarco De Gregori <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel