File 1812-Implement-socket-support-for-IPPROTO_MPTCP.patch of Package erlang

From edaf963fc0d2e4113529c440eacf452bc31e3f41 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Fri, 24 Oct 2025 16:19:04 +0200
Subject: [PATCH 2/3] Implement `socket` support for IPPROTO_MPTCP

---
 erts/emulator/nifs/common/prim_socket_nif.c | 20 ++++++++++++++++++--
 erts/emulator/nifs/common/socket_int.h      |  1 +
 lib/kernel/src/socket.erl                   | 12 ++++++++----
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/erts/emulator/nifs/common/prim_socket_nif.c b/erts/emulator/nifs/common/prim_socket_nif.c
index 654b44ef7a..05d44d1343 100644
--- a/erts/emulator/nifs/common/prim_socket_nif.c
+++ b/erts/emulator/nifs/common/prim_socket_nif.c
@@ -2147,6 +2147,7 @@ static const struct in6_addr in6addr_loopback =
     GLOBAL_ATOM_DECL(min_rtt);                         \
     GLOBAL_ATOM_DECL(monitor);			       \
     GLOBAL_ATOM_DECL(more);                            \
+    GLOBAL_ATOM_DECL(mptcp);                           \
     GLOBAL_ATOM_DECL(msfilter);                        \
     GLOBAL_ATOM_DECL(mss);                             \
     GLOBAL_ATOM_DECL(mtu);                             \
@@ -4904,6 +4905,13 @@ ERL_NIF_TERM esock_supports_protocols(ErlNifEnv* env)
           MKT2(env, MKL1(env, esock_atom_igmp), MKI(env, IPPROTO_IGMP)),
           protocols);
 
+#ifdef IPPROTO_MPTCP
+  protocols =
+      MKC(env,
+          MKT2(env, MKL1(env, esock_atom_mptcp), MKI(env, IPPROTO_MPTCP)),
+          protocols);
+#endif
+
   return protocols;
 }
 
@@ -12100,7 +12108,11 @@ void esock_dec_socket(int domain, int type, int protocol)
     /* *** Protocol counter *** */
     if (protocol == IPPROTO_IP)
         esock_cnt_dec(&data.numProtoIP, 1);
-    else if (protocol == IPPROTO_TCP)
+    else if (protocol == IPPROTO_TCP
+#ifdef IPPROTO_MPTCP
+             || protocol == IPPROTO_MPTCP
+#endif
+             )
         esock_cnt_dec(&data.numProtoTCP, 1);
     else if (protocol == IPPROTO_UDP)
         esock_cnt_dec(&data.numProtoUDP, 1);
@@ -12145,7 +12157,11 @@ void esock_inc_socket(int domain, int type, int protocol)
     /* *** Protocol counter *** */
     if (protocol == IPPROTO_IP)
         esock_cnt_inc(&data.numProtoIP, 1);
-    else if (protocol == IPPROTO_TCP)
+    else if (protocol == IPPROTO_TCP
+#ifdef IPPROTO_MPTCP
+             || protocol == IPPROTO_MPTCP
+#endif
+             )
         esock_cnt_inc(&data.numProtoTCP, 1);
     else if (protocol == IPPROTO_UDP)
         esock_cnt_inc(&data.numProtoUDP, 1);
diff --git a/erts/emulator/nifs/common/socket_int.h b/erts/emulator/nifs/common/socket_int.h
index 08dea79fe9..0c20aa86e2 100644
--- a/erts/emulator/nifs/common/socket_int.h
+++ b/erts/emulator/nifs/common/socket_int.h
@@ -425,6 +425,7 @@ typedef long ssize_t;
     GLOBAL_ATOM_DEF(min_rtt);                  \
     GLOBAL_ATOM_DEF(monitor);		       \
     GLOBAL_ATOM_DEF(more);                     \
+    GLOBAL_ATOM_DEF(mptcp);                    \
     GLOBAL_ATOM_DEF(msfilter);                 \
     GLOBAL_ATOM_DEF(mss);                      \
     GLOBAL_ATOM_DEF(mtu);                      \
diff --git a/lib/kernel/src/socket.erl b/lib/kernel/src/socket.erl
index 690087e3b3..839bec289a 100644
--- a/lib/kernel/src/socket.erl
+++ b/lib/kernel/src/socket.erl
@@ -492,6 +492,9 @@ They have the following names in the OS header files:
 
 - **`tcp`** - `IPPROTO_TCP` with options named `TCP_`\*.
 
+- **`mptcp`** - `IPPROTO_MPTCP` with a few options named `MPTCP_`\*.
+  Most `TCP_`\* options apply which is the purpose of Multi-Path TCP.
+
 - **`udp`** - `IPPROTO_UDP` with options named `UDP_`\*.
 
 - **`sctp`** - `IPPROTO_SCTP` with options named `SCTP_`\*.
@@ -504,10 +507,11 @@ through the `C` library call `getprotoent()`. See the OS man page for
 protocols(5). Those in the list above are valid if supported by the platform,
 even if they aren't enumerated.
 
-The calls [`is_supported(ipv6)` ](`is_supported/1`)
-and [`is_supported(sctp)` ](`is_supported/1`) can be used to find out
-if the protocols `ipv6` and `sctp` are supported on the platform
-as in appropriate header file and library exists.
+The calls [`is_supported(ipv6)` ](`is_supported/1`),
+[`is_supported(sctp)` ](`is_supported/1`) and
+[`is_supported(mptcp)` ](`is_supported/1`) can be used to find out
+if the protocols `ipv6`, `sctp` and `mptcp` are supported on the platform
+as in; appropriate header file and libraries exist.
 
 The call [`is_supported(protocols, Protocol)` ](`is_supported/2`)
 can only be used to find out if the platform knows the protocol number
-- 
2.51.0

openSUSE Build Service is sponsored by