From 7c9d522ede2c38fbd4e9b7f21e4d443698d8819e Mon Sep 17 00:00:00 2001 From: Jesper Schmitz Mouridsen Date: Thu, 25 Mar 2021 16:59:24 +0100 Subject: [PATCH] FreeBSD support (#2508) --- README.md | 11 +++++++ configure.ac | 31 ++++++++++++++++---- plugins/janus_audiobridge.c | 4 +++ postprocessing/janus-pp-rec.c | 2 +- postprocessing/mjr2pcap.c | 2 +- postprocessing/pp-av1.c | 2 +- postprocessing/pp-binary.c | 2 +- postprocessing/pp-g711.c | 2 +- postprocessing/pp-g722.c | 2 +- postprocessing/pp-h264.c | 2 +- postprocessing/pp-h265.c | 2 +- postprocessing/pp-opus.c | 2 +- postprocessing/pp-rtp.h | 2 +- postprocessing/pp-srt.c | 2 +- postprocessing/pp-webm.c | 2 +- rtcp.h | 2 ++ rtp.h | 2 +- text2pcap.c | 5 ++++ transports/janus_websockets.c | 55 +++++++++++++++++++++++++++++++++-- 19 files changed, 114 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index eb508ffbff..3c86cac1a6 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,17 @@ If Doxygen and graphviz are available, the process can also build the documentat You can also selectively enable/disable other features (e.g., specific plugins you don't care about, or whether or not you want to build the recordings post-processor). Use the --help option when configuring for more info. +### Building on FreeBSD +* *Note*: rtp_forward of streams only works streaming to IPv6, +because of #2051 and thus the feature is not supported on FreeBSD at the moment. + +When building on FreeBSD you can install the depencencies from ports or packages, here only pkg method is used. You also need to use `gmake` instead of `make`, +since it is a GNU makefile. `./configure` can be run without arguments since the default prefix is `/usr/local` which is your default `LOCALBASE`. +Note that the `configure.ac` is coded to use openssl in base. If you wish to use openssl from ports or any other ssl you must change `configure.ac` accordingly. + + pkg install libsrtp2 libusrsctp jansson libnice libmicrohttpd libwebsockets curl opus sofia-sip libogg jansson libnice libconfig \ + libtool gmake autoconf autoconf-wrapper glib gengetopt + ### Building on MacOS While most of the above instructions will work when compiling Janus on MacOS as well, there are a few aspects to highlight when doing that. diff --git a/configure.ac b/configure.ac index f305d52759..5bc18a7181 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,11 @@ clang*) -Wno-cast-align \ -Wno-initializer-overrides" ;; +cc*) + CFLAGS="$CFLAGS \ + -Wno-cast-align \ + -Wno-initializer-overrides" +;; *) # Specific gcc flags CFLAGS="$CFLAGS \ @@ -83,6 +88,12 @@ darwin*) LDFLAGS="$LDFLAGS -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/opt/local/lib -L/usr/local/libsrtp/lib" AM_CONDITIONAL([DARWIN_OS], true) ;; +freebsd*) + CFLAGS="$CFLAGS -I/usr/include/openssl" + LDFLAGS="$LDFLAGS -Xlinker --export-dynamic" + LDFLAGS="$LDFLAGS -L/usr/lib/openssl -lcrypto -lssl -L/usr/local/lib" + AM_CONDITIONAL([DARWIN_OS], false) +;; *) LDFLAGS="$LDFLAGS -Wl,--export-dynamic" AM_CONDITIONAL([DARWIN_OS], false) @@ -337,17 +348,27 @@ AC_ARG_ENABLE([systemd-sockets], [], [enable_systemd_sockets=no]) -PKG_CHECK_MODULES([JANUS], - [ - glib-2.0 >= $glib_version +case "$host_os" in +freebsd*) + PKGCHECKMODULES="glib-2.0 >= $glib_version + gio-2.0 >= $glib_version + libconfig + nice + jansson >= $jansson_version + zlib" +;; +*) + PKGCHECKMODULES="glib-2.0 >= $glib_version gio-2.0 >= $glib_version libconfig nice jansson >= $jansson_version libssl >= $ssl_version libcrypto - zlib - ]) + zlib" +esac +PKG_CHECK_MODULES([JANUS],"$PKGCHECKMODULES") + JANUS_MANUAL_LIBS="${JANUS_MANUAL_LIBS} -lm" AC_SUBST(JANUS_MANUAL_LIBS) diff --git a/plugins/janus_audiobridge.c b/plugins/janus_audiobridge.c index f92c5d4a3f..763c8d96ba 100644 --- a/plugins/janus_audiobridge.c +++ b/plugins/janus_audiobridge.c @@ -857,6 +857,10 @@ room-: { */ #include "plugin.h" +#ifdef __FreeBSD__ +#include +#include +#endif #include #include diff --git a/postprocessing/janus-pp-rec.c b/postprocessing/janus-pp-rec.c index b2c3688746..aa11ba1e48 100644 --- a/postprocessing/janus-pp-rec.c +++ b/postprocessing/janus-pp-rec.c @@ -88,7 +88,7 @@ Usage: janus-pp-rec [OPTIONS] source.mjr [destination.[opus|wav|webm|mp4|srt]] */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/mjr2pcap.c b/postprocessing/mjr2pcap.c index 3b5997fea9..7d9e7cce89 100644 --- a/postprocessing/mjr2pcap.c +++ b/postprocessing/mjr2pcap.c @@ -25,7 +25,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-av1.c b/postprocessing/pp-av1.c index 4b7493eb5b..b2139c7b60 100644 --- a/postprocessing/pp-av1.c +++ b/postprocessing/pp-av1.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-binary.c b/postprocessing/pp-binary.c index 4bc4c62e5b..ae52eece63 100644 --- a/postprocessing/pp-binary.c +++ b/postprocessing/pp-binary.c @@ -12,7 +12,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-g711.c b/postprocessing/pp-g711.c index d6d78aee99..073cfe67dc 100644 --- a/postprocessing/pp-g711.c +++ b/postprocessing/pp-g711.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-g722.c b/postprocessing/pp-g722.c index b03670d697..d85506e8fc 100644 --- a/postprocessing/pp-g722.c +++ b/postprocessing/pp-g722.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined (__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-h264.c b/postprocessing/pp-h264.c index dfa639193e..bd02cb32aa 100644 --- a/postprocessing/pp-h264.c +++ b/postprocessing/pp-h264.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-h265.c b/postprocessing/pp-h265.c index 4e704b8110..d12aee8bfa 100644 --- a/postprocessing/pp-h265.c +++ b/postprocessing/pp-h265.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-opus.c b/postprocessing/pp-opus.c index 5dede3ef42..4eef9952e1 100644 --- a/postprocessing/pp-opus.c +++ b/postprocessing/pp-opus.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-rtp.h b/postprocessing/pp-rtp.h index 121fa739b9..6880592b02 100644 --- a/postprocessing/pp-rtp.h +++ b/postprocessing/pp-rtp.h @@ -13,7 +13,7 @@ #ifndef JANUS_PP_RTP #define JANUS_PP_RTP -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #define __BYTE_ORDER BYTE_ORDER #define __BIG_ENDIAN BIG_ENDIAN diff --git a/postprocessing/pp-srt.c b/postprocessing/pp-srt.c index cb8d2859e2..5eeed71b8c 100644 --- a/postprocessing/pp-srt.c +++ b/postprocessing/pp-srt.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/postprocessing/pp-webm.c b/postprocessing/pp-webm.c index cbf88f979c..17a394758f 100644 --- a/postprocessing/pp-webm.c +++ b/postprocessing/pp-webm.c @@ -10,7 +10,7 @@ */ #include -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #include #else #include diff --git a/rtcp.h b/rtcp.h index 95862f5137..f9a3aba7ca 100644 --- a/rtcp.h +++ b/rtcp.h @@ -19,6 +19,8 @@ #include #ifdef __MACH__ #include +#elif defined(__FreeBSD__) +#include #else #include #endif diff --git a/rtp.h b/rtp.h index 92284e779d..97fa1d6c0e 100644 --- a/rtp.h +++ b/rtp.h @@ -14,7 +14,7 @@ #define JANUS_RTP_H #include -#ifdef __MACH__ +#if defined (__MACH__) || defined(__FreeBSD__) #include #define __BYTE_ORDER BYTE_ORDER #define __BIG_ENDIAN BIG_ENDIAN diff --git a/text2pcap.c b/text2pcap.c index 06680c1d0a..4ab04adf91 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -41,6 +41,11 @@ #define __BYTE_ORDER BYTE_ORDER #define __BIG_ENDIAN BIG_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN +#elif defined(__FreeBSD__) +#include +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +#define __LITTLE_ENDIAN LITTLE_ENDIAN #else #include #endif diff --git a/transports/janus_websockets.c b/transports/janus_websockets.c index 4d2b8e3486..4784c32845 100644 --- a/transports/janus_websockets.c +++ b/transports/janus_websockets.c @@ -386,6 +386,9 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi JANUS_LOG(LOG_WARN, "libwebsockets has been built without IPv6 support, will bind to IPv4 only\n"); #endif +#ifdef __FreeBSD__ + int ipv4_only = 0; +#endif /* This is the callback we'll need to invoke to contact the Janus core */ gateway = callback; @@ -618,6 +621,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi item = janus_config_get(config, config_general, janus_config_type_item, "ws_ip"); if(item && item->value) { ip = (char *)item->value; +#ifdef __FreeBSD__ + struct in_addr addr; + if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0) + ipv4_only = 1; +#endif char *iface = janus_websockets_get_interface_name(ip); if(iface == NULL) { JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip); @@ -636,8 +644,16 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi info.ssl_private_key_password = NULL; info.gid = -1; info.uid = -1; + info.options = 0; +#ifdef __FreeBSD__ + if (ipv4_only) { + info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; + ipv4_only = 0; + } +#endif #if (LWS_LIBRARY_VERSION_MAJOR == 3 && LWS_LIBRARY_VERSION_MINOR >= 2) || (LWS_LIBRARY_VERSION_MAJOR > 3) - info.options = LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; + info.options |= LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; + #endif /* Create the WebSocket context */ wss = lws_create_vhost(wsc, &info); @@ -666,6 +682,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi item = janus_config_get(config, config_general, janus_config_type_item, "wss_ip"); if(item && item->value) { ip = (char *)item->value; +#ifdef __FreeBSD__ + struct in_addr addr; + if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0) + ipv4_only = 1; +#endif char *iface = janus_websockets_get_interface_name(ip); if(iface == NULL) { JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip); @@ -707,6 +728,12 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; #elif LWS_LIBRARY_VERSION_MAJOR >= 2 info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif +#ifdef __FreeBSD__ + if(ipv4_only) { + info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; + ipv4_only = 0; + } #endif /* Create the secure WebSocket context */ swss = lws_create_vhost(wsc, &info); @@ -737,6 +764,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi item = janus_config_get(config, config_admin, janus_config_type_item, "admin_ws_ip"); if(item && item->value) { ip = (char *)item->value; +#ifdef __FreeBSD__ + struct in_addr addr; + if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0) + ipv4_only = 1; +#endif char *iface = janus_websockets_get_interface_name(ip); if(iface == NULL) { JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip); @@ -755,8 +787,16 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi info.ssl_private_key_password = NULL; info.gid = -1; info.uid = -1; + info.options = 0; +#ifdef __FreeBSD__ + if (ipv4_only) { + info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; + ipv4_only = 0; + } +#endif #if (LWS_LIBRARY_VERSION_MAJOR == 3 && LWS_LIBRARY_VERSION_MINOR >= 2) || (LWS_LIBRARY_VERSION_MAJOR > 3) - info.options = LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; + info.options |= LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; + #endif /* Create the WebSocket context */ admin_wss = lws_create_vhost(wsc, &info); @@ -785,6 +825,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi item = janus_config_get(config, config_admin, janus_config_type_item, "admin_wss_ip"); if(item && item->value) { ip = (char *)item->value; +#ifdef __FreeBSD__ + struct in_addr addr; + if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0) + ipv4_only = 1; +#endif char *iface = janus_websockets_get_interface_name(ip); if(iface == NULL) { JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip); @@ -826,6 +871,12 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND; #elif LWS_LIBRARY_VERSION_MAJOR >= 2 info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif +#ifdef __FreeBSD__ + if (ipv4_only) { + info.options |= LWS_SERVER_OPTION_DISABLE_IPV6; + ipv4_only = 0; + } #endif /* Create the secure WebSocket context */ admin_swss = lws_create_vhost(wsc, &info);