Skip to content

Latest commit

 

History

History
96 lines (76 loc) · 2.94 KB

implementation.md

File metadata and controls

96 lines (76 loc) · 2.94 KB
layout title nav_order nav_titles titles_max_depth
home
Implementation guide (Devs)
5
true
2

This guide is for application developers working to add native MPTCP support when running on Linux. End-users can also force some apps to use MPTCP, but that's more of a workaround, because the app will not notice a different socket type is being used.

MPTCP socket

On Linux, MPTCP can be used by selecting MPTCP instead of TCP when creating the socket:

socket(AF_INET(6), SOCK_STREAM, IPPROTO_MPTCP)

That's it!

{: .note} Note that IPPROTO_MPTCP{: .color-green} is defined as 262{: .text-yellow-300}. It can be manually defined if it is not already handled in your system headers.

If MPTCP is not supported, errno{: .text-red-200} will be set to:

  • EINVAL{: .text-red-200}: (Invalid argument): MPTCP is not available, on kernels < 5.6.
  • EPROTONOSUPPORT{: .text-red-200} (Protocol not supported): MPTCP has not been compiled, on kernels >= v5.6.
  • ENOPROTOOPT{: .text-red-200} (Protocol not available): MPTCP has been disabled using net.mptcp.enabled sysctl knob.
  • Even if it is unlikely, MPTCP can also be blocked using different techniques (SELinux, eBPF, etc.). In this case, check with your sysadmin.

Examples in different languages

For more detailed examples, please see this Git repository. Do not hesitate to contribute here and there!

Example in C

IPPROTO_MPTCP has been added in GNU C library (glibc) in version 2.32

#include <sys/socket.h>
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP)
if (s < 0) /* fallback to TCP */
    s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
{: .ctsm}
Example in Python

socket.IPPROTO_MPTCP has been added in CPython 3.10.

import socket
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_MPTCP)
except:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
{: .ctsm}
Example in Go

SetMultipathTCP support has been added in GoLang 1.21.

import ("net" "context")

// Client
d := &net.Dialer{}
d.SetMultipathTCP(true)
c, err := d.Dial("tcp", *addr)

// Server
lc := &ListenConfig{}
lc.SetMultipathTCP(true)
ln, err := lc.Listen(context.Background(), "tcp", *addr)
defer ln.Close()
{: .ctsm}