This patch extends the socket creation functionality to support Multipath
TCP (MPTCP) by adding a new 'mptcp' parameter to the native socket0 method.
When enabled, the socket will be created with the IPPROTO_MPTCP protocol
for stream sockets.
The changes include:
1. Added the 'mptcp' parameter to socket0 method declarations in Net.java
2. Modified the native implementations in both Unix and Windows Net.c files
to handle the new parameter and set the appropriate protocol
3. Updated all call sites to pass 'false' for the new parameter to maintain
existing behavior (MPTCP disabled by default)
Co-Developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <geliang@kernel.org>
---
src/java.base/share/classes/sun/nio/ch/Net.java | 6 +++---
src/java.base/unix/native/libnio/ch/Net.c | 5 +++--
src/java.base/windows/native/libnio/ch/Net.c | 2 +-
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/java.base/share/classes/sun/nio/ch/Net.java b/src/java.base/share/classes/sun/nio/ch/Net.java
index 9ec7975a35c..c086429380b 100644
--- a/src/java.base/share/classes/sun/nio/ch/Net.java
+++ b/src/java.base/share/classes/sun/nio/ch/Net.java
@@ -488,7 +488,7 @@ static FileDescriptor socket() throws IOException {
static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException {
boolean preferIPv6 = isIPv6Available() &&
(family != StandardProtocolFamily.INET);
- return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK));
+ return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, false));
}
static FileDescriptor serverSocket() {
@@ -498,12 +498,12 @@ static FileDescriptor serverSocket() {
static FileDescriptor serverSocket(ProtocolFamily family) {
boolean preferIPv6 = isIPv6Available() &&
(family != StandardProtocolFamily.INET);
- return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK));
+ return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false));
}
// Due to oddities SO_REUSEADDR on Windows reuse is ignored
private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
- boolean fastLoopback);
+ boolean fastLoopback, boolean mptcp);
public static void bind(FileDescriptor fd, InetAddress addr, int port)
throws IOException
diff --git a/src/java.base/unix/native/libnio/ch/Net.c b/src/java.base/unix/native/libnio/ch/Net.c
index 28c1814f422..1b08539873f 100644
--- a/src/java.base/unix/native/libnio/ch/Net.c
+++ b/src/java.base/unix/native/libnio/ch/Net.c
@@ -255,13 +255,14 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c
JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
- jboolean stream, jboolean reuse, jboolean ignored)
+ jboolean stream, jboolean reuse, jboolean ignored, jboolean mptcp)
{
int fd;
int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET;
+ int protocol = (stream && mptcp) ? IPPROTO_MPTCP : 0;
- fd = socket(domain, type, 0);
+ fd = socket(domain, type, protocol);
if (fd < 0) {
return handleSocketError(env, errno);
}
diff --git a/src/java.base/windows/native/libnio/ch/Net.c b/src/java.base/windows/native/libnio/ch/Net.c
index 814f502c48a..c563aa9f031 100644
--- a/src/java.base/windows/native/libnio/ch/Net.c
+++ b/src/java.base/windows/native/libnio/ch/Net.c
@@ -152,7 +152,7 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c
JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
- jboolean stream, jboolean reuse, jboolean fastLoopback)
+ jboolean stream, jboolean reuse, jboolean fastLoopback, jboolean mptcp)
{
SOCKET s;
int domain = (preferIPv6) ? AF_INET6 : AF_INET;
--
2.48.1
Hi Geliang, On 23/07/2025 07:16, Geliang Tang wrote: > This patch extends the socket creation functionality to support Multipath > TCP (MPTCP) by adding a new 'mptcp' parameter to the native socket0 method. > When enabled, the socket will be created with the IPPROTO_MPTCP protocol > for stream sockets. > > The changes include: > 1. Added the 'mptcp' parameter to socket0 method declarations in Net.java > 2. Modified the native implementations in both Unix and Windows Net.c files > to handle the new parameter and set the appropriate protocol > 3. Updated all call sites to pass 'false' for the new parameter to maintain > existing behavior (MPTCP disabled by default) > > Co-Developed-by: Gang Yan <yangang@kylinos.cn> > Signed-off-by: Gang Yan <yangang@kylinos.cn> > Signed-off-by: Geliang Tang <geliang@kernel.org> > --- > src/java.base/share/classes/sun/nio/ch/Net.java | 6 +++--- > src/java.base/unix/native/libnio/ch/Net.c | 5 +++-- > src/java.base/windows/native/libnio/ch/Net.c | 2 +- > 3 files changed, 7 insertions(+), 6 deletions(-) > > diff --git a/src/java.base/share/classes/sun/nio/ch/Net.java b/src/java.base/share/classes/sun/nio/ch/Net.java > index 9ec7975a35c..c086429380b 100644 > --- a/src/java.base/share/classes/sun/nio/ch/Net.java > +++ b/src/java.base/share/classes/sun/nio/ch/Net.java > @@ -488,7 +488,7 @@ static FileDescriptor socket() throws IOException { > static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { > boolean preferIPv6 = isIPv6Available() && > (family != StandardProtocolFamily.INET); > - return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK)); > + return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, false)); > } > > static FileDescriptor serverSocket() { > @@ -498,12 +498,12 @@ static FileDescriptor serverSocket() { > static FileDescriptor serverSocket(ProtocolFamily family) { > boolean preferIPv6 = isIPv6Available() && > (family != StandardProtocolFamily.INET); > - return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK)); > + return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false)); > } > > // Due to oddities SO_REUSEADDR on Windows reuse is ignored > private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, > - boolean fastLoopback); > + boolean fastLoopback, boolean mptcp); > > public static void bind(FileDescriptor fd, InetAddress addr, int port) > throws IOException > diff --git a/src/java.base/unix/native/libnio/ch/Net.c b/src/java.base/unix/native/libnio/ch/Net.c > index 28c1814f422..1b08539873f 100644 > --- a/src/java.base/unix/native/libnio/ch/Net.c > +++ b/src/java.base/unix/native/libnio/ch/Net.c > @@ -255,13 +255,14 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c > > JNIEXPORT jint JNICALL > Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, > - jboolean stream, jboolean reuse, jboolean ignored) > + jboolean stream, jboolean reuse, jboolean ignored, jboolean mptcp) (I don't know if there is a limit for the number of chars per lines, maybe you need to go to the next line?) > { > int fd; > int type = (stream ? SOCK_STREAM : SOCK_DGRAM); > int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; > + int protocol = (stream && mptcp) ? IPPROTO_MPTCP : 0; I guess you will still need to check if IPPROTO_MPTCP is defined for old systems, or the ones not using Linux. Something like that: int protocol = #ifdef IPPROTO_MPTCP (stream && mptcp) ? IPPROTO_MPTCP : #endif 0; (or another style, I don't know what is usually being used here.) > > - fd = socket(domain, type, 0); > + fd = socket(domain, type, protocol); > if (fd < 0) { > return handleSocketError(env, errno); > } > diff --git a/src/java.base/windows/native/libnio/ch/Net.c b/src/java.base/windows/native/libnio/ch/Net.c > index 814f502c48a..c563aa9f031 100644 > --- a/src/java.base/windows/native/libnio/ch/Net.c > +++ b/src/java.base/windows/native/libnio/ch/Net.c > @@ -152,7 +152,7 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c > > JNIEXPORT jint JNICALL > Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, > - jboolean stream, jboolean reuse, jboolean fastLoopback) > + jboolean stream, jboolean reuse, jboolean fastLoopback, jboolean mptcp) > { > SOCKET s; > int domain = (preferIPv6) ? AF_INET6 : AF_INET; Cheers, Matt -- Sponsored by the NGI0 Core fund.
© 2016 - 2025 Red Hat, Inc.