Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Trick to multipath TCP
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3477

PostPosted: Wed May 08, 2024 8:01 pm    Post subject: Trick to multipath TCP Reply with quote

MPTCP recently caught my eye, and it seems to be a pretty cool and underappreciated feature, since it allows migrating TCP connection between ISPs and allegedly (haven't tested) link aggregation, yet nobody seems to be actually using it even though RFC 6824 introduced the idea in January 2013 (obsoleted by RFC 8684 dated March 2020 ).

The best part is that it maintains backwards compatibility with plain TCP, so there doesn't seem to be any downside to enabling it.
Gentoo wiki even has an article regarding required kernel configuration: https://wiki.gentoo.org/wiki/MultiPath_TCP
Very convenient; kernel's support for MPTCP must be enabled for any of the following methods to work.

Alright, how to make it work?
Well, I found a few ways with different downsides
- Systemtap described here https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/getting-started-with-multipath-tcp_configuring-and-managing-networking#preparing-rhel-to-enable-mptcp-support_getting-started-with-multipath-tcp ( failed on my system, and enabling debug info for kernel made 4GB kernel build explode to 15GB, but provided useful information)
- mptcpize https://mptcp-apps.github.io/mptcp-doc/mptcp-linux.html - the wrapper script is provided in Gentoo by package net-misc/mptcpd - this actually works, but running stiff on per-applcation basis is a lot of work
- ebpf https://ebpf.io/what-is-ebpf/#how-are-ebpf-programs-written - looks interesting but also difficult to start with. Haven't tried, but certainly deserves a special mention.

Altright, so how to make it actually work?
Well, we're on Gentoo, so exploiting emerge to patch kernel sources.

Code:
mkdir -p /etc/portage/patches/sys-kernel/gentoo-sources
base64 -d > /etc/portage/patches/sys-kernel/gentoo-sources/force_mptcp.patch << eof
LS0tIHNvY2tldC5ia3AJMjAyNC0wNS0wNyAyMjo1MTowMy42ODYzNzgyOTUgKzAyMDAKKysrIGxp
bnV4L25ldC9zb2NrZXQuYwkyMDI0LTA1LTA3IDIzOjUzOjIyLjMzOTg1NTUzNyArMDIwMApAQCAt
MTcwNiw5ICsxNzA2LDE2IEBACiB7CiAJc3RydWN0IHNvY2tldCAqc29jazsKIAlpbnQgZmxhZ3M7
Ci0KKwkKKwlpZiAoICggZmFtaWx5ID09IEFGX0lORVQgfHwgZmFtaWx5ID09IEFGX0lORVQ2KSAm
JiB0eXBlID09IFNPQ0tfU1RSRUFNICYmIChwcm90b2NvbCA9PSBJUFBST1RPX1RDUCB8fCBwcm90
b2NvbCA9PSAwICkgKSB7CisJCXNvY2sgPSBfX3N5c19zb2NrZXRfY3JlYXRlKGZhbWlseSwgdHlw
ZSwKKwkJCQkgICB1cGRhdGVfc29ja2V0X3Byb3RvY29sKGZhbWlseSwgdHlwZSwgSVBQUk9UT19N
UFRDUCkpOworCX0KKwllbHNlIHsKIAlzb2NrID0gX19zeXNfc29ja2V0X2NyZWF0ZShmYW1pbHks
IHR5cGUsCiAJCQkJICAgdXBkYXRlX3NvY2tldF9wcm90b2NvbChmYW1pbHksIHR5cGUsIHByb3Rv
Y29sKSk7CisJfQorCiAJaWYgKElTX0VSUihzb2NrKSkKIAkJcmV0dXJuIFBUUl9FUlIoc29jayk7
CiAK
eof

Above snippet creates a patch that will be applied to all versions of gentoo-sources:
Code:
cat /etc/portage/patches/sys-kernel/gentoo-sources/force_mptcp.patch
--- socket.bkp   2024-05-07 22:51:03.686378295 +0200
+++ linux/net/socket.c   2024-05-07 23:53:22.339855537 +0200
@@ -1706,9 +1706,16 @@
 {
    struct socket *sock;
    int flags;
-
+   
+   if ( ( family == AF_INET || family == AF_INET6) && type == SOCK_STREAM && (protocol == IPPROTO_TCP || protocol == 0 ) ) {
+      sock = __sys_socket_create(family, type,
+               update_socket_protocol(family, type, IPPROTO_MPTCP));
+   }
+   else {
    sock = __sys_socket_create(family, type,
                update_socket_protocol(family, type, protocol));
+   }
+
    if (IS_ERR(sock))
       return PTR_ERR(sock);
 

Yes, it is a bit hackish, but you should be fine as long as you don't disable mptcp via sysctl (which will prevent all programs from opening any TCP sockets).

Apply the patch to kernel source or install/update gentoo-sources and let emerge do it for you. Build kernel as usual, reboot and enjoy!
You can verify settings with ip mptcp, and see a bunch of event counters with nstat MPTcp\*

Finally, I checked how it interacts with wireguard: it didn't leak. Connections opened inside wg tunnel stay inside, connections opened outside stay outside. I haven't noticed any cross-talk between those two worlds (which is obviously a good thing).
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum