Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
FreeBSD/socket: user cookie socket option support.
Browse files Browse the repository at this point in the history
giving here an identifier to the socket for DTrace's context,
ipfw filter and so on.
  • Loading branch information
devnexen committed Jun 21, 2019
1 parent dd779fc commit 3fa820c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jdk.net/bsd/classes/jdk/net/BsdSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int getTcpKeepAliveIntvl(int fd) throws SocketException {
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;
private static native boolean keepAliveOptionsSupported0();
private static native void setUserCookie(int fd, int cookie) throws SocketException;
static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("extnet");
Expand Down
15 changes: 15 additions & 0 deletions src/jdk.net/bsd/native/libextnet/BsdSocketOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,18 @@ JNIEXPORT jint JNICALL Java_jdk_net_BsdSocketOptions_getTcpKeepAliveIntvl0
return optval;
#endif
}

JNIEXPORT void JNICALL Java_jdk_net_BsdSocketOptions_setUserCookie
(JNIEnv *env, jobject unused, jint fd, jint cookie) {
#ifndef __FreeBSD__
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
"unsupported socket option");
return -1;
#else
jint rv;
const uint32_t optval = (const uint32_t)cookie;
socklen_t sz = sizeof (optval);
rv = setsockopt(fd, IPPROTO_TCP, SO_USER_COOKIE, &optval, sz);
handleError(env, rv, "set option SO_USER_COOKIE failed");
#endif
}

0 comments on commit 3fa820c

Please sign in to comment.