Multipath TCP (MPTCP), standardized in RFC8684 [1], is a TCP extension that enables a TCP connection to use different paths. Multipath TCP has been used for several use cases. On smartphones, MPTCP enables seamless handovers between cellular and Wi-Fi networks while preserving established connections. This use-case is what pushed Apple to use MPTCP since 2013 in multiple applications [2]. On dual-stack hosts, Multipath TCP enables the TCP connection to automatically use the best performing path, either IPv4 or IPv6. If one path fails, MPTCP automatically uses the other path. To benefit from MPTCP, both the client and the server have to support it. Multipath TCP is a backward-compatible TCP extension that is enabled by default on recent Linux distributions (Debian, Ubuntu, Redhat, ...). Multipath TCP is included in the Linux kernel since version 5.6 [3]. To use it on Linux, an application must explicitly enable it when creating the socket. No need to change anything else in the application. This attached patch adds an --mptcp option which allows the creation of an MPTCP socket instead of TCP on Linux. If Multipath TCP is not supported on the system, an error will be reported. It is important to note that if the end server doesn't support MPTCP, the connection will continue after a seamless fallback to TCP. Link: https://www.rfc-editor.org/rfc/rfc8684.html [1] Link: https://www.tessares.net/apples-mptcp-story-so-far/ [2] Link: https://www.mptcp.dev [3] Co-developed-by: Dorian Craps (@CrapsDorian) <doriancraps@gmail.com> Co-developed-by: Olivier Bonaventure (@obonaventure) <Olivier.Bonaventure@uclouvain.be> Co-developed-by: Matthieu Baerts (@matttbe) <matttbe@kernel.org> Signed-off-by: Dorian Craps <dorian.craps@student.vinci.be> Closes #13278
59 lines
1.7 KiB
C
59 lines
1.7 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "tool_setup.h"
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
#include <netinet/in.h> /* IPPROTO_TCP */
|
|
#endif
|
|
|
|
#include "tool_cb_soc.h"
|
|
|
|
/*
|
|
** callback for CURLOPT_OPENSOCKETFUNCTION
|
|
**
|
|
** Notice that only Linux is supported for the moment.
|
|
*/
|
|
|
|
curl_socket_t tool_socket_open_mptcp_cb(void *clientp,
|
|
curlsocktype purpose,
|
|
struct curl_sockaddr *addr)
|
|
{
|
|
int protocol = addr->protocol;
|
|
|
|
(void)clientp;
|
|
(void)purpose;
|
|
|
|
if(protocol == IPPROTO_TCP)
|
|
#if defined(__linux__)
|
|
# ifndef IPPROTO_MPTCP
|
|
# define IPPROTO_MPTCP 262
|
|
# endif
|
|
protocol = IPPROTO_MPTCP;
|
|
#else
|
|
return CURL_SOCKET_BAD;
|
|
#endif
|
|
|
|
return socket(addr->family, addr->socktype, protocol);
|
|
}
|