Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD support #2508

Merged
merged 13 commits into from
Mar 25, 2021
Merged

FreeBSD support #2508

merged 13 commits into from
Mar 25, 2021

Conversation

jsm222
Copy link
Contributor

@jsm222 jsm222 commented Dec 28, 2020

I mostly corrected endianness includes and defines.
Most notable change is in transports/janus_websockets.c
There I set LWS_SERVER_OPTION_DISABLE_IPV6, because of
warmcat/libwebsockets#1947.
This is probably a FreeBSD only issue, and perhaps it should be in preprocessor macros.
I also did comment ip = iface out, since ws_ip is supposed to only bind to the ws_ip set.
This might be a bug common to all systems though. I have only tested build on FreeBSD.
Also see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219444
See also #2232

@januscla
Copy link

Thanks for your contribution, @jsm222! Please make sure you sign our CLA, as it's a required step before we can merge this.

Copy link
Member

@atoppi atoppi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the effort @jsm222 !
I don't have a FreeBSD machine and I don't know much about the OS, so I can't comment about the endiannes and macro stuff.
Anyway I noticed some minor points I'd be glad to discuss.

configure.ac Outdated Show resolved Hide resolved
janus.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
Add LWS_SERVER_OPTION_DISABLE_IPV6
only for FreeBSD.
Copy link
Member

@atoppi atoppi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've added some more notes.

configure.ac Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
configure.ac Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
transports/janus_websockets.c Show resolved Hide resolved
transports/janus_websockets.c Show resolved Hide resolved
transports/janus_websockets.c Show resolved Hide resolved
transports/janus_websockets.c Outdated Show resolved Hide resolved
Copy link
Member

@atoppi atoppi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're almost there, just some more empty lines to fix here and there!

configure.ac Outdated Show resolved Hide resolved
configure.ac Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
transports/janus_websockets.c Show resolved Hide resolved
@@ -706,6 +726,13 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
#else
info.options = 0;
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot this one

@@ -818,10 +865,18 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
info.ssl_cipher_list = ciphers;
info.gid = -1;
info.uid = -1;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot these

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 6, 2021

The empty lines should be fixed now..

@atoppi
Copy link
Member

atoppi commented Jan 6, 2021

lgtm 👍
Thanks again!

@lminiero
Copy link
Member

lminiero commented Jan 6, 2021

I'll need a few days to review, as I'm still on my holiday break. Thanks for the effort!

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this effort, and apologies for the late review: I've only recently come back to work after the holidays. I see Alessandro already provided good notes, so I've just added a few myself that are mostly related to form.

As a side note, is the ipv4/ipv6 libwebsockets issue on FreeBSD going to be an issue in Streaming plugin as well, as I think we always binding using an IPv6 struct by default, unless explicitly specifying IPv4 there? There may be issues with RTP forwarders too (VideoRoom and AudioBridge), as IIRC we do the same.

@@ -207,6 +207,30 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some more descriptive description here too, as we do for MacOs. The pkg line should be "compacted" a bit too (like what we do above for yum and apt-get), as there's too many lines now I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

README.md Outdated
sh autogen.sh
./configure
gmake
gmake install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a gmake here? I don't think the lines from autogen.sh on are needed at all, as they're shared for all systems (they're not there for the MacOS instructions for instance).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gmake is for GNU make. BSDs has its own make

@@ -618,6 +621,12 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: there should be spaces before and after the > comparator.
Besides, since the action is simple, I don't think it's needed to wrap it in curly brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -664,6 +679,12 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -735,6 +762,12 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -781,6 +820,12 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 14, 2021

As a side note, is the ipv4/ipv6 libwebsockets issue on FreeBSD going to be an issue in Streaming plugin as well, as I think we always binding using an IPv6 struct by default, unless explicitly specifying IPv4 there? There may be issues with RTP forwarders too (VideoRoom and AudioBridge), as IIRC we do the same.

Videoroom seem to work. I did not test audiobridge.. The issue with listening (lib)websockets is that it does not listen on both Ipv4 and IPv6 when ipv6 is enabled it is ipv6 only.. Can you provide more details of what you think might not work, and how to test it?

@lminiero
Copy link
Member

Can you provide more details of what you think might not work, and how to test it?

What I'm thinking about is what is described in #2051. I just noticed you actually already commented there, at the time.

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 14, 2021

What I'm thinking about is what is described in #2051. I just noticed you actually already commented there, at the time.

I get the following errors trying to rtp_forward from videoroom:
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c7 --> v=1, level=71
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c8 --> v=1, level=72
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c9 --> v=1, level=73
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
But that might be an endian issue, I will look into it..

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 14, 2021

But that might be an endian issue, I will look into it..

specifyi

What I'm thinking about is what is described in #2051. I just noticed you actually already commented there, at the time.

I get the following errors trying to rtp_forward from videoroom:
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c7 --> v=1, level=71
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c8 --> v=1, level=72
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
[rtp.c:janus_rtp_header_extension_parse_audio_level:184] c9 --> v=1, level=73
Error forwarding RTP audio packet for laptop... Invalid argument (len=101)...
But that might be an endian issue, I will look into it..

    struct sockaddr *address = (rtp_forward->serv_addr.sin_family == AF_INET ?
                                        (struct sockaddr *)&rtp_forward->serv_addr : (struct sockaddr *)&rtp_forward->serv_addr6);
                                size_t addrlen = (rtp_forward->serv_addr.sin_family == AF_INET ? sizeof(rtp_forward->serv_addr) : sizeof(rtp_forward->serv_addr6));
                                if(sendto(participant->udp_sock, buf, len, 0, address, addrlen) < 0) {
                                        JANUS_LOG(LOG_HUGE, "Error forwarding RTP %s packet for %s... %s (len=%d)...\n",
                                                (video ? "video" : "audio"), participant->display, strerror(errno), len);
                                }

I can send to ipv6 but i do not manage to read from it..

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 14, 2021

I can send to ipv6 but i do not manage to read from it..

ffmeg can read it my vlc cannot.. well it works over ipv6 so issue #2051 applies.

@lminiero
Copy link
Member

lminiero commented Jan 20, 2021

I get the following errors trying to rtp_forward from videoroom:

This may be because we always open an AF_INET6 socket when creating forwarders, even when we're only going to send to IPv4. This is because we only create a single socket per publisher, and we may have to send to different family address (e.g., RTP forward to both an IPv4 and an IPv6 address). An IPv6 socket with IPV6_V6ONLY disabled can send to both, on Linux, but apparently caused issues on MacOS, and maybe on FreeBSD too?

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 20, 2021

and maybe on FreeBSD too?

man inet6
Interaction between IPv4/v6 sockets
By default, FreeBSD does not route IPv4 traffic to AF_INET6 sockets. The
default behavior intentionally violates RFC2553 for security reasons.
Listen to two sockets if you want to accept both IPv4 and IPv6 traffic.

So yes.

@lminiero
Copy link
Member

For the time being this feature should be considered unsupported in FreeBSD then. We don't plan to revisit the implementation until the multistream branch is merged.

@jsm222
Copy link
Contributor Author

jsm222 commented Jan 20, 2021

I agree. Should it be added in README?

@lminiero
Copy link
Member

That's probably a good idea, thanks!

@@ -14,7 +14,7 @@
#define JANUS_RTP_H

#include <arpa/inet.h>
#ifdef __MACH__
#if defined (__MACH__) || defined(__FreeBSD__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same definition in pp-rtp.h, which is in the post-processor code. Have you checked if postprocessing MJR recordings does indeed work as expected on FreeBSD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I could not find the docs to acutally do a test, but I did change pp-rtp.h

@jsm222
Copy link
Contributor Author

jsm222 commented Feb 14, 2021

I tested with /usr/local/bin/janus-pp-rec /usr/local/share/janus/recordings/rec-sample-audio.mjr test.opus

@jsm222
Copy link
Contributor Author

jsm222 commented Mar 21, 2021

Hi, any reason not to merge this? Thanks :-)

@lminiero
Copy link
Member

@jsm222 no reason beyond the fact it's a lot of changes that I need to review again, and test to make sure there's no regression, so entirely my fault, sorry. I've been very busy these past few weeks, I'll try to do that in the next few days. Thanks!

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some more small notes on the PR: nothing major, just small nits. I'll make some tests as well to see the parts that have changed the most still work (which I expect to do, since it's all happening in #ifdefs)

README.md Outdated
@@ -207,6 +207,19 @@ 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](https://github.com/meetecho/janus-gateway/issues/2051) and thus the feature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just put #2051 as text, and it should create a link to the issue automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* *Note*: rtp_forward of streams only works streaming to IPv6,
because of [2051](https://github.com/meetecho/janus-gateway/issues/2051) and thus the feature
is not supported on FreeBSD at the moment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note: missing full stop at the end of the sentence? Also, extra empty line can be removed (I see two).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

README.md Outdated

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ./configure, make, gmake, /usr/local, LOCALBASE and configure.ac texts should be in inverted quotes, to follow the style we use in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if (ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems broken? Spaces are used, but we use tabs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Add missing gengetopt to dependencies pkg install
@lminiero
Copy link
Member

Thanks for the quick fixes! I'll make a couple of tests after lunch, and if all looks fine, I'll finally merge 👍

@lminiero
Copy link
Member

I made a few checks and all seems to be working. Of course the actual checks should be made on FreeBSD, to ensure Janus does work there now, but I assume you've made all these tests already. This looks good to me, so I'll merge, thanks again!

@lminiero
Copy link
Member

@jsm222 FYI, I got rid of the inet_net_pton check you added, to use inet_pton instead. Not sure why you chose the former in your patch initially, so in case it was for a specific reason that FreeBSD needed (and for which inet_pton is not enough) you may want to be aware of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants