File 2932-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/doc/src/socket.xml b/lib/kernel/doc/src/socket.xml
index 690087e3b3..839bec289a 100644
--- a/lib/kernel/doc/src/socket.xml
+++ b/lib/kernel/doc/src/socket.xml
@@ -468,6 +468,11 @@
 	  <item>
 	    <c>IPPROTO_TCP</c> with options named <c>TCP_</c>*.
 	  </item>
+	  <tag><c>mptcp</c></tag>
+	  <item>
+	    <c>IPPROTO_MPTCP</c> with a few options named <c>MPTCP_</c>*.
+	    Most <c>TCP_</c>* options apply which is the purpose of Multi-Path TCP.
+	  </item>
 	  <tag><c>udp</c></tag>
 	  <item>
 	    <c>IPPROTO_UDP</c> with options named <c>UDP_</c>*.
-- 
2.51.0

openSUSE Build Service is sponsored by