git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* PATCH v2 [1/1]: MPTCP support for Git on Linux
@ 2025-05-17 17:02 Muhammad Nuzaihan
  2025-05-17 18:30 ` PATCH v3 " Muhammad Nuzaihan
  2025-05-17 18:46 ` PATCH v2 " Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Muhammad Nuzaihan @ 2025-05-17 17:02 UTC (permalink / raw)
  To: git; +Cc: phillip.wood, brian m. carlson

[-- Attachment #1: Type: text/plain, Size: 3620 bytes --]

Hi,

This patch is about Multi-Path TCP.

Multi-Path TCP (MPTCP) had been in development for the past 15 years
which started with MPTCP v0 (version 0) which initially had issues
for middleboxes and NAT Gateways.

The current iteration is MPTCP v1 which has a fallback mechanism to
regular
TCP to avoid issues with middleboxes and NAT Gateways.

Started to add this code change as a need as i have large git codebases
with around 50 gigabytes and i have multiple WAN links which i can
aggregate
bandwidth across and even when network one path (even in between my
CPE router
to internet) is down, i will not get interrupted.

Also i am using a Linux laptop that has WiFi and 5G module. So this kind
of adds my reason of adding support for git (on Linux)

To get MPTCP to be fully working, both ends of client and server must
implement
MPTCP.

My implementation adds support for the basic git protocol.

MPTCP helps in situations when one of my WAN links have a high latency
and
automatically choose a link with a path with less latency.

Also, MPTCP aggregates the MPTCP connection by using subflows where two
or more
links can be utilised with subflows. A single flow of data can have
multiple
subflows across different IP interfaces and thus increases network
throughput.

Apple for example had been using MPTCP for their cloud services since
MPTCP v0
which had issues with middleboxes (not MPTCP v1) since 2013.

The downside, even though i had never experienced it for other
applications
on Linux like Google Chromium[1], is that the fallback might induce
delays
in connectivity, if i've read it somewhere which i cannot recall where.

How this patch works:

This patch enables MPTCP protocol option only when it's built on Linux
with
IPPROTO_MPTCP support in netinet/in.h.

On Linux, if IPPROTO_MPTCP is not defined in netinet/in.h, it will
skipped.

IPPROTO_MPTCP should and never be enabled when it detects being built on
an OS other than Linux with defined(__linux__) check.

Another challenge is that although "getaddrinfo()" is a POSIX function,
not all glibc "getaddrinfo()" implementation is written with
IPPROTO_MPTCP support out of the box, especially on older glibc
versions.

getaddrinfo() IPPROTO_MPTCP support had only been added to recent glibc
in 2025 eventhough IPPROTO_MPTCP definition had been around for
much longer in netinet/in.h.

So we run getaddrinfo() which is a code in glibc and check for errors,
specifically "EAI_SOCKTYPE" return value which tells us that the socket
type
is not supported and fallback to regular TCP (IPPROTO_TCP)

Also we will also check that we are building on Linux and depending on
version number of Linux we will initialize the socket() accordingly and
if
there is an error return value (like
EINVAL/EPROTONOSUPPORT/ENOPROTOOPT),
we will fall back to regular TCP.

Enabling and disabling MPTCP:

By default on the client side, MPTCP will not be enabled in git client,
however MPTCP
can be enabled by setting an environment variable "GIT_ENABLE_MPTCP" to
any value.

Persisting the configuration can be done in your shell.

Also for server side git server (daemon.c), there is a flag to
optionally
enable mptcp with "--mptcp", example:

git-daemon --base-path=/all/my/repos --export-all --mptcp

This will tell the git server daemon to accept mptcp connections but
fallback to regular tcp when mptcp connection is not available.

PS: Can someone point me about having a "knob" in Makefile or is this
already sufficient?

[1] https://chromium-review.googlesource.com/c/chromium/src/+/6355767

Signed-off-by: Muhammad Nuzaihan Bin Kamal Luddin
<zaihan@unrealasia.net>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: git-mptcp-v2.diff --]
[-- Type: text/x-patch, Size: 5187 bytes --]

diff --git a/connect.c b/connect.c
index 3280435331..846fa31853 100644
--- a/connect.c
+++ b/connect.c
@@ -23,6 +23,9 @@
 #include "alias.h"
 #include "bundle-uri.h"
 #include "promisor-remote.h"
+#ifdef __linux__
+#include <linux/version.h>
+#endif
 
 static char *server_capabilities_v1;
 static struct strvec server_capabilities_v2 = STRVEC_INIT;
@@ -793,6 +796,16 @@ static void enable_keepalive(int sockfd)
 		error_errno(_("unable to set SO_KEEPALIVE on socket"));
 }
 
+static const char *git_enable_mptcp(void)
+{
+        const char *mptcp;
+
+        if ((mptcp = getenv("GIT_ENABLE_MPTCP")))
+                return mptcp;
+
+	return NULL;
+}
+
 #ifndef NO_IPV6
 
 static const char *ai_name(const struct addrinfo *ai)
@@ -816,6 +829,7 @@ static int git_tcp_connect_sock(char *host, int flags)
 	struct addrinfo hints, *ai0, *ai;
 	int gai;
 	int cnt = 0;
+	const char *enable_mptcp;
 
 	get_host_and_port(&host, &port);
 	if (!*port)
@@ -827,12 +841,28 @@ static int git_tcp_connect_sock(char *host, int flags)
 	else if (flags & CONNECT_IPV6)
 		hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_protocol = IPPROTO_TCP;
+#if defined(__linux__) && defined(IPPROTO_MPTCP)
+        enable_mptcp = git_enable_mptcp();
+	if (enable_mptcp)
+                hints.ai_protocol = IPPROTO_MPTCP;
+	else
+                hints.ai_protocol = IPPROTO_TCP;
+#else
+        hints.ai_protocol = IPPROTO_TCP;
+#endif
 
 	if (flags & CONNECT_VERBOSE)
 		fprintf(stderr, _("Looking up %s ... "), host);
 
-	gai = getaddrinfo(host, port, &hints, &ai);
+        gai = getaddrinfo(host, port, &hints, &ai);
+        // If system's glibc getaddrinfo() does not have
+        // IPPROTO_MPTCP as member type in struct (like older
+        // glibc and other libc), we fallback to IPPROTO_TCP
+        if (gai == EAI_SOCKTYPE) {
+                hints.ai_protocol = IPPROTO_TCP;
+                gai = getaddrinfo(host, port, &hints, &ai);
+        }
+	
 	if (gai)
 		die(_("unable to look up %s (port %s) (%s)"), host, port, gai_strerror(gai));
 
@@ -889,6 +919,7 @@ static int git_tcp_connect_sock(char *host, int flags)
 	char **ap;
 	unsigned int nport;
 	int cnt;
+	const char *enable_mptcp;
 
 	get_host_and_port(&host, &port);
 
@@ -917,6 +948,21 @@ static int git_tcp_connect_sock(char *host, int flags)
 		sa.sin_port = htons(nport);
 		memcpy(&sa.sin_addr, *ap, he->h_length);
 
+#ifdef __linux__
+		enable_mptcp = git_enable_mptcp(); 
+		if (enable_mptcp) {
+                        sockfd = socket(he->h_addrtype, SOCK_STREAM, IPPROTO_MPTCP);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
+                        // MPTCP check return value for Linux Kernel >= 5.6
+                        if (sockfd == EPROTONOSUPPORT || sockfd == ENOPROTOOPT)
+                                continue;
+#else
+                        // MPTCP check return value for Linux Kernel < 5.6
+                        if (sockfd == EINVAL || sockfd == ENOPROTOOPT)
+                                continue;
+#endif
+                }
+#endif
 		sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
 		if ((sockfd < 0) ||
 		    connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
diff --git a/daemon.c b/daemon.c
index d1be61fd57..793f8a4219 100644
--- a/daemon.c
+++ b/daemon.c
@@ -25,6 +25,7 @@ static enum log_destination {
 } log_destination = LOG_DESTINATION_UNSET;
 static int verbose;
 static int reuseaddr;
+static int mptcp;
 static int informative_errors;
 
 static const char daemon_usage[] =
@@ -38,6 +39,7 @@ static const char daemon_usage[] =
 "           [--access-hook=<path>]\n"
 "           [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
 "                      [--detach] [--user=<user> [--group=<group>]]\n"
+"           [--mptcp]\n"
 "           [--log-destination=(stderr|syslog|none)]\n"
 "           [<directory>...]";
 
@@ -975,10 +977,24 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_protocol = IPPROTO_TCP;
+#if defined(__linux__) && defined(IPPROTO_MPTCP)
+	if (mptcp)
+                hints.ai_protocol = IPPROTO_MPTCP;
+        else
+                hints.ai_protocol = IPPROTO_MPTCP;
+#else
+        hints.ai_protocol = IPPROTO_TCP;
+#endif
 	hints.ai_flags = AI_PASSIVE;
 
-	gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
+        gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
+        // If system's glibc getaddrinfo() does not have
+        // IPPROTO_MPTCP as member type in struct (like older
+        // glibc and other libc), we fallback to IPPROTO_TCP
+        if (gai == EAI_SOCKTYPE) {
+                hints.ai_protocol = IPPROTO_TCP;
+                gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
+        }
 	if (gai) {
 		logerror("getaddrinfo() for %s failed: %s", listen_addr, gai_strerror(gai));
 		return 0;
@@ -1342,6 +1358,10 @@ int cmd_main(int argc, const char **argv)
 			reuseaddr = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--mptcp")) {
+			mptcp = 1;
+			continue;
+		}
 		if (!strcmp(arg, "--user-path")) {
 			user_path = "";
 			continue;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: PATCH v3 [1/1]: MPTCP support for Git on Linux
  2025-05-17 17:02 PATCH v2 [1/1]: MPTCP support for Git on Linux Muhammad Nuzaihan
@ 2025-05-17 18:30 ` Muhammad Nuzaihan
  2025-05-17 18:46 ` PATCH v2 " Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Muhammad Nuzaihan @ 2025-05-17 18:30 UTC (permalink / raw)
  To: git; +Cc: phillip.wood, brian m. carlson

Hi,

This code below in v2:

+#if defined(__linux__) && defined(IPPROTO_MPTCP)
+ if (mptcp)
+ hints.ai_protocol = IPPROTO_MPTCP;
+ else
+ hints.ai_protocol = IPPROTO_MPTCP;
+#else
+ hints.ai_protocol = IPPROTO_TCP;
+#endif

Has a small bug, which i realised in the v2 patch while debugging the
traffic with wireshark.

So i'm correcting this minor mistake where the else statement
should fallback to regular TCP if flag is disabled in v3:

+#if defined(__linux__) && defined(IPPROTO_MPTCP)
+ if (mptcp)
+ hints.ai_protocol = IPPROTO_MPTCP;
+ else
+ hints.ai_protocol = IPPROTO_TCP;
+#else
+ hints.ai_protocol = IPPROTO_TCP;
+#endif

Changes in v3:
- fix a bug with regards to mptcp flag should switch to regular TCP if 
false.

Changes in v2:
- Check for whether git is being built for Linux and also if it's on 
Linux, check if
  IPPROTO_MPTCP exists in both connect.c (client) and daemon.c (server)
- Check for whether the glibc version support IPPROTO_MPTCP in 
getaddrinfo() function,
  old versions of glibc does not support this even though header 
definitions netinet/in.h
  had already for years. Running getaddinfo() will return EAI_SOCKTYPE 
error
  if IPPROTO_MPTCP is not supported and we fallback to regular TCP.
- In both client side (connect.c) and server side (daemon.c) check if 
socket() supports
  IPPROTO_MPTCP if the git is built in Linux including checks for 
version 5.6
  and above and below 5.6 for proper error return values,
  else skip and run regular TCP (IPPROTO_TCP)
- Add client side enable/diable environment variable option 
GIT_ENABLE_MPTCP
  for client side (connect.c) to enable/disable MPTCP on client side.
- Add git server side enable/disable flag "--mptcp" to enable or 
disable server/side MPTCP.

Link to v2: 
https://lore.kernel.org/git/6O0FWS.8JJP67DO2U1M1@unrealasia.net/T/#u
Link to v1: 
https://lore.kernel.org/git/a76dda61-f60c-4221-83db-5e165a2478b1@gmail.com/T/#t

Signed-off-by: Muhammad Nuzaihan Bin Kamal Luddin
<zaihan@unrealasia.net>

On Sun, May 18 2025 at 01:02:30 AM +0800, Muhammad Nuzaihan 
<zaihan@unrealasia.net> wrote:
> Hi,
> 
> This patch is about Multi-Path TCP.
> 
> Multi-Path TCP (MPTCP) had been in development for the past 15 years
> which started with MPTCP v0 (version 0) which initially had issues
> for middleboxes and NAT Gateways.
> 
> The current iteration is MPTCP v1 which has a fallback mechanism to
> regular
> TCP to avoid issues with middleboxes and NAT Gateways.
> 
> Started to add this code change as a need as i have large git 
> codebases
> with around 50 gigabytes and i have multiple WAN links which i can
> aggregate
> bandwidth across and even when network one path (even in between my
> CPE router
> to internet) is down, i will not get interrupted.
> 
> Also i am using a Linux laptop that has WiFi and 5G module. So this 
> kind
> of adds my reason of adding support for git (on Linux)
> 
> To get MPTCP to be fully working, both ends of client and server must
> implement
> MPTCP.
> 
> My implementation adds support for the basic git protocol.
> 
> MPTCP helps in situations when one of my WAN links have a high latency
> and
> automatically choose a link with a path with less latency.
> 
> Also, MPTCP aggregates the MPTCP connection by using subflows where 
> two
> or more
> links can be utilised with subflows. A single flow of data can have
> multiple
> subflows across different IP interfaces and thus increases network
> throughput.
> 
> Apple for example had been using MPTCP for their cloud services since
> MPTCP v0
> which had issues with middleboxes (not MPTCP v1) since 2013.
> 
> The downside, even though i had never experienced it for other
> applications
> on Linux like Google Chromium[1], is that the fallback might induce
> delays
> in connectivity, if i've read it somewhere which i cannot recall 
> where.
> 
> How this patch works:
> 
> This patch enables MPTCP protocol option only when it's built on Linux
> with
> IPPROTO_MPTCP support in netinet/in.h.
> 
> On Linux, if IPPROTO_MPTCP is not defined in netinet/in.h, it will
> skipped.
> 
> IPPROTO_MPTCP should and never be enabled when it detects being built 
> on
> an OS other than Linux with defined(__linux__) check.
> 
> Another challenge is that although "getaddrinfo()" is a POSIX 
> function,
> not all glibc "getaddrinfo()" implementation is written with
> IPPROTO_MPTCP support out of the box, especially on older glibc
> versions.
> 
> getaddrinfo() IPPROTO_MPTCP support had only been added to recent 
> glibc
> in 2025 eventhough IPPROTO_MPTCP definition had been around for
> much longer in netinet/in.h.
> 
> So we run getaddrinfo() which is a code in glibc and check for errors,
> specifically "EAI_SOCKTYPE" return value which tells us that the 
> socket
> type
> is not supported and fallback to regular TCP (IPPROTO_TCP)
> 
> Also we will also check that we are building on Linux and depending on
> version number of Linux we will initialize the socket() accordingly 
> and
> if
> there is an error return value (like
> EINVAL/EPROTONOSUPPORT/ENOPROTOOPT),
> we will fall back to regular TCP.
> 
> Enabling and disabling MPTCP:
> 
> By default on the client side, MPTCP will not be enabled in git 
> client,
> however MPTCP
> can be enabled by setting an environment variable "GIT_ENABLE_MPTCP" 
> to
> any value.
> 
> Persisting the configuration can be done in your shell.
> 
> Also for server side git server (daemon.c), there is a flag to
> optionally
> enable mptcp with "--mptcp", example:
> 
> git-daemon --base-path=/all/my/repos --export-all --mptcp
> 
> This will tell the git server daemon to accept mptcp connections but
> fallback to regular tcp when mptcp connection is not available.
> 
> PS: Can someone point me about having a "knob" in Makefile or is this
> already sufficient?
> 
> [1] https://chromium-review.googlesource.com/c/chromium/src/+/6355767
> 
> Signed-off-by: Muhammad Nuzaihan Bin Kamal Luddin
> <zaihan@unrealasia.net>
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH v2 [1/1]: MPTCP support for Git on Linux
  2025-05-17 17:02 PATCH v2 [1/1]: MPTCP support for Git on Linux Muhammad Nuzaihan
  2025-05-17 18:30 ` PATCH v3 " Muhammad Nuzaihan
@ 2025-05-17 18:46 ` Junio C Hamano
  2025-05-17 19:25   ` Muhammad Nuzaihan
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2025-05-17 18:46 UTC (permalink / raw)
  To: Muhammad Nuzaihan; +Cc: git, phillip.wood, brian m. carlson

Muhammad Nuzaihan <zaihan@unrealasia.net> writes:

> Hi,
>
> This patch is about Multi-Path TCP.

Perhaps reading and following Documentation/SubmittingPatches and
possibly MyFirstContribution is in order.

How widely is MPTCP adopted?  I somehow feel that it is a losing
proposition to _require_ that each and every _application_ to be
updated to support it, but say if we take a random set of widely
used application, how much of them have specific knowledge of how
to work with MPTCP these days?




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH v2 [1/1]: MPTCP support for Git on Linux
  2025-05-17 18:46 ` PATCH v2 " Junio C Hamano
@ 2025-05-17 19:25   ` Muhammad Nuzaihan
  0 siblings, 0 replies; 4+ messages in thread
From: Muhammad Nuzaihan @ 2025-05-17 19:25 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, phillip.wood, brian m. carlson

Hi Junio,

MPTCP has been in development for 15 years and only reached maturity
in v1 of the protocol.

Only recently in 2020 that this protocol (v1) was officially merged
into the Linux kernel mainline but before that Linux MPTCP was developed
out-of-tree.

Apple had been using MPTCP in production for the
past 12 years for their iOS[1] for Apple's cloud services.

It's no longer an experimental technology it's in the IETF standards 
track[2]
and no longer in experimental track.

I know it's cumbersome to implement MPTCP for every application out 
there,
the same with IPv6 which already had been around for more than 20 years 
and still
not that widely adopted, especially for enterprises.

But i think we have to start somewhere. I myself had been working on 
IPv6
since 2003 and i think the late Jun Ichiro Hagino probably did the 
right thing
even though people around him might think otherwise.

Anyway, back to git. I think it will benefit the server side more with
aggregation but i started to work on this after realising how bad my 
hotel's wifi
and i have a WWAN module and thought of aggregating my bandwidth.

Since Go is enabled MPTCP by default in 1.24, it makes sense
for me to add more MPTCP support, at least on the Linux side of things. 
Go
is really popular not just web services but also load balancers (which 
can
also be TCP load balancers).

I cannot vouch Linux kernel's MPTCP implementation as someone had 
mentioned
about the CVE because of backpressure but that CVE was in 2022, 3 years 
ago.

Go 1.24 with MPTCP by default is only released this year, so time will 
tell. :-)

I think eventually just like IPv6, people will have knowledge on how it
works.

[1]http://blog.multipath-tcp.org/blog/html/2018/12/15/apple_and_multipath_tcp.html
[2]https://datatracker.ietf.org/doc/html/rfc8684

Regards,
Zaihan

On Sat, May 17 2025 at 11:46:12 AM -0700, Junio C Hamano 
<gitster@pobox.com> wrote:
> Muhammad Nuzaihan <zaihan@unrealasia.net> writes:
> 
>>  Hi,
>> 
>>  This patch is about Multi-Path TCP.
> 
> Perhaps reading and following Documentation/SubmittingPatches and
> possibly MyFirstContribution is in order.
> 
> How widely is MPTCP adopted?  I somehow feel that it is a losing
> proposition to _require_ that each and every _application_ to be
> updated to support it, but say if we take a random set of widely
> used application, how much of them have specific knowledge of how
> to work with MPTCP these days?
> 
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-17 19:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-17 17:02 PATCH v2 [1/1]: MPTCP support for Git on Linux Muhammad Nuzaihan
2025-05-17 18:30 ` PATCH v3 " Muhammad Nuzaihan
2025-05-17 18:46 ` PATCH v2 " Junio C Hamano
2025-05-17 19:25   ` Muhammad Nuzaihan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).