Skip to content

Commit

Permalink
SCTP support for FreeBSD
Browse files Browse the repository at this point in the history
On BSD, only build SCTP support on FreeBSD

* Exclude SCTP implementation classes on OpenBSD and NetBSD, not BSD
  overall.
* Keep MacOS X, AIX and BSD excluded from SCTP support overall, but
  specifically include it on FreeBSD.
* Add appropriate libraries for BSD to the libsctp build.
* Add a FreeBSD section in Sctp.h with the appropriate includes.
* Don't do dynamic SCTP loading on FreeBSD as SCTP functionality is not
  in a separate library.  Instead just use it directly.

Source changes are a forward port from JDK 8.
  • Loading branch information
battleblow committed Mar 29, 2019
1 parent 546f854 commit 6df23da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 5 additions & 1 deletion make/CompileJavaModules.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ ifeq ($(OPENJDK_TARGET_OS),aix)
jdk.sctp_EXCLUDE_FILES += $(SCTP_IMPL_CLASSES)
endif

ifeq ($(OPENJDK_TARGET_OS), bsd)
ifeq ($(OPENJDK_TARGET_OS_ENV), bsd.openbsd)
jdk.sctp_EXCLUDE_FILES += $(SCTP_IMPL_CLASSES)
endif

ifeq ($(OPENJDK_TARGET_OS_ENV), bsd.netbsd)
jdk.sctp_EXCLUDE_FILES += $(SCTP_IMPL_CLASSES)
endif

Expand Down
10 changes: 10 additions & 0 deletions make/lib/Lib-jdk.sctp.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ include LibCommon.gmk

ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)

# This feels like it should be detected by autoconf
SCTP_SUPPORTED=
ifeq ($(filter $(OPENJDK_TARGET_OS), macosx aix bsd), )
SCTP_SUPPORTED=true
endif
ifeq ($(OPENJDK_TARGET_OS_ENV), bsd.freebsd)
SCTP_SUPPORTED=true
endif

ifeq ($(SCTP_SUPPORTED), true)
$(eval $(call SetupJdkLibrary, BUILD_LIBSCTP, \
NAME := sctp, \
OPTIMIZATION := LOW, \
Expand All @@ -44,6 +53,7 @@ ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)
$(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS_unix := -lnio -lnet -ljava -ljvm, \
LIBS_linux := -lpthread $(LIBDL), \
LIBS_bsd := -pthread $(LIBDL), \
LIBS_solaris := -lsocket, \
))

Expand Down
24 changes: 23 additions & 1 deletion src/jdk.sctp/unix/native/libsctp/Sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef int sctp_peeloff_func(int sock, sctp_assoc_t id);



#else /* __linux__ */
#elif defined(__linux__)
#include <stdint.h>
#include <linux/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -319,16 +319,38 @@ typedef int sctp_freepaddrs_func(struct sockaddr *addrs);
typedef int sctp_bindx_func(int sd, struct sockaddr *addrs, int addrcnt, int flags);
typedef int sctp_peeloff_func(int sock, sctp_assoc_t id);

#elif defined(__FreeBSD__)

#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>
#include <netinet/sctp_peeloff.h>
#include <netinet/sctp_uio.h>
#include "jni.h"

#endif /* __linux__ */

#ifndef __FreeBSD__

sctp_getladdrs_func* nio_sctp_getladdrs;
sctp_freeladdrs_func* nio_sctp_freeladdrs;
sctp_getpaddrs_func* nio_sctp_getpaddrs;
sctp_freepaddrs_func* nio_sctp_freepaddrs;
sctp_bindx_func* nio_sctp_bindx;
sctp_peeloff_func* nio_sctp_peeloff;

#else

#define nio_sctp_getladdrs sctp_getladdrs
#define nio_sctp_freeladdrs sctp_freeladdrs
#define nio_sctp_getpaddrs sctp_getpaddrs
#define nio_sctp_freepaddrs sctp_freepaddrs
#define nio_sctp_bindx sctp_bindx
#define nio_sctp_peeloff sctp_peeloff

#endif

jboolean loadSocketExtensionFuncs(JNIEnv* env);

#endif /* !SUN_NIO_CH_SCTP_H */
2 changes: 2 additions & 0 deletions src/jdk.sctp/unix/native/libsctp/SctpNet.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static int preCloseFD = -1; /* File descriptor to which we dup other fd's
*/
jboolean loadSocketExtensionFuncs
(JNIEnv* env) {
#ifndef __FreeBSD__
if (dlopen(nativeSctpLib, RTLD_GLOBAL | RTLD_LAZY) == NULL) {
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
dlerror());
Expand Down Expand Up @@ -105,6 +106,7 @@ jboolean loadSocketExtensionFuncs
dlerror());
return JNI_FALSE;
}
#endif

funcsLoaded = JNI_TRUE;
return JNI_TRUE;
Expand Down

0 comments on commit 6df23da

Please sign in to comment.