Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket: add MPTCP support #13278

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/spellcheck.words
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ monospace
MorphOS
MPE
MPL
MPTCP
mprintf
MQTT
mqtt
Expand All @@ -523,6 +524,7 @@ mTLS
MUA
multicwd
multiparts
multipath
MultiSSL
mumbo
musedev
Expand Down
1 change: 1 addition & 0 deletions docs/cmdline-opts/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ DPAGES = \
max-redirs.md \
max-time.md \
metalink.md \
mptcp.md \
negotiate.md \
netrc-file.md \
netrc-optional.md \
Expand Down
41 changes: 41 additions & 0 deletions docs/cmdline-opts/mptcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
c: Copyright (C) Dorian Craps, <dorian.craps@student.vinci.be>
SPDX-License-Identifier: curl
Long: mptcp
Added: 8.9.0
Help: Enable Multipath TCP
Category: connection
Multi: boolean
See-also:
- tcp-fastopen
Example:
- --mptcp $URL
---

# `--mptcp`

Enables the use of Multipath TCP (MPTCP) for connections. MPTCP is an extension
to the standard TCP that allows multiple TCP streams over different network
paths between the same source and destination. This can enhance bandwidth and
improve reliability by using multiple paths simultaneously.

MPTCP is beneficial in networks where multiple paths exist between clients and
servers, such as mobile networks where a device may switch between WiFi and
cellular data or in wired networks with multiple Internet Service Providers.

## Usage

To use MPTCP for your connections, add the `--mptcp` option when using `curl'.

## Requirements

This feature is currently only supported on Linux starting from kernel 5.6. Only
TCP connections are modified, hence this option does not effect HTTP/3 (QUIC)
connections.

The server you are connecting to must also support MPTCP. If not, the connection
seamlessly falls back to TCP.
bagder marked this conversation as resolved.
Show resolved Hide resolved

## Availability

The `--mptcp` option is available starting from `curl` version 8.9.0.
1 change: 1 addition & 0 deletions docs/options-in-versions
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
--max-redirs 7.5
--max-time (-m) 4.0
--metalink 7.27.0
--mptcp 8.9.0
--negotiate 7.10.6
--netrc (-n) 4.6
--netrc-file 7.21.5
Expand Down
1 change: 1 addition & 0 deletions packages/vms/gnv_link_curl.com
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ $ link'ldebug'/exe=[.src]curl.exe/dsf=[.src]curl.dsf -
[.src]curl-tool_bname.o, [.src]curl-tool_cb_dbg.o, -
[.src]curl-tool_cb_hdr.o, [.src]curl-tool_cb_prg.o, -
[.src]curl-tool_cb_rea.o, [.src]curl-tool_cb_see.o, -
[.src]curl-tool_cb_soc.o, -
[.src]curl-tool_cb_wrt.o, [.src]curl-tool_cfgable.o, -
[.src]curl-tool_convert.o, [.src]curl-tool_dirhie.o, -
[.src]curl-tool_doswin.o, [.src]curl-tool_easysrc.o, -
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ CURL_CFILES = \
tool_cb_prg.c \
tool_cb_rea.c \
tool_cb_see.c \
tool_cb_soc.c \
tool_cb_wrt.c \
tool_cfgable.c \
tool_dirhie.c \
Expand Down Expand Up @@ -112,6 +113,7 @@ CURL_HFILES = \
tool_cb_prg.h \
tool_cb_rea.h \
tool_cb_see.h \
tool_cb_soc.h \
tool_cb_wrt.h \
tool_cfgable.h \
tool_dirhie.h \
Expand Down
58 changes: 58 additions & 0 deletions src/tool_cb_soc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***************************************************************************
* _ _ ____ _
* 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);
}
36 changes: 36 additions & 0 deletions src/tool_cb_soc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef HEADER_CURL_TOOL_CB_SOC_H
#define HEADER_CURL_TOOL_CB_SOC_H
/***************************************************************************
* _ _ ____ _
* 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"

/*
** callback for CURLOPT_OPENSOCKETFUNCTION
*/

curl_socket_t tool_socket_open_mptcp_cb(void *clientp,
curlsocktype purpose,
struct curl_sockaddr *addr);

#endif /* HEADER_CURL_TOOL_CB_SOC_H */
1 change: 1 addition & 0 deletions src/tool_cfgable.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ struct OperationConfig {
CLOBBER_NEVER, /* If the file exists, always fail */
CLOBBER_ALWAYS /* If the file exists, always overwrite it */
} file_clobber_mode;
bool mptcp; /* enable MPTCP support */
struct GlobalConfig *global;
struct OperationConfig *prev;
struct OperationConfig *next; /* Always last in the struct */
Expand Down
5 changes: 5 additions & 0 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ typedef enum {
C_MAX_REDIRS,
C_MAX_TIME,
C_METALINK,
C_MPTCP,
C_NEGOTIATE,
C_NETRC,
C_NETRC_FILE,
Expand Down Expand Up @@ -482,6 +483,7 @@ static const struct LongShort aliases[]= {
{"max-redirs", ARG_STRG, ' ', C_MAX_REDIRS},
{"max-time", ARG_STRG, 'm', C_MAX_TIME},
{"metalink", ARG_BOOL, ' ', C_METALINK},
{"mptcp", ARG_BOOL, ' ', C_MPTCP},
{"negotiate", ARG_BOOL, ' ', C_NEGOTIATE},
{"netrc", ARG_BOOL, 'n', C_NETRC},
{"netrc-file", ARG_FILE, ' ', C_NETRC_FILE},
Expand Down Expand Up @@ -2793,6 +2795,9 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
}
}
break;
case C_MPTCP: /* --mptcp */
config->mptcp = TRUE;
break;
default: /* unknown flag */
err = PARAM_OPTION_UNKNOWN;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/tool_listhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ const struct helptxt helptext[] = {
{" --metalink",
"Process given URLs as metalink XML file",
CURLHELP_MISC},
{" --mptcp",
"Enable Multipath TCP",
CURLHELP_CONNECTION},
{" --negotiate",
"Use HTTP Negotiate (SPNEGO) authentication",
CURLHELP_AUTH | CURLHELP_HTTP},
Expand Down
5 changes: 5 additions & 0 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "tool_cb_prg.h"
#include "tool_cb_rea.h"
#include "tool_cb_see.h"
#include "tool_cb_soc.h"
#include "tool_cb_wrt.h"
#include "tool_dirhie.h"
#include "tool_doswin.h"
Expand Down Expand Up @@ -1289,6 +1290,10 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->tcp_fastopen)
my_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L);

if(config->mptcp)
my_setopt(curl, CURLOPT_OPENSOCKETFUNCTION,
tool_socket_open_mptcp_cb);

/* where to store */
my_setopt(curl, CURLOPT_WRITEDATA, per);
my_setopt(curl, CURLOPT_INTERLEAVEDATA, per);
Expand Down