-
Notifications
You must be signed in to change notification settings - Fork 280
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
Add new method to init the stack with threads but no UDP encapsulation #532
base: master
Are you sure you want to change the base?
Conversation
So you don't want the usrsctp library to process incoming SCTP/UPD/IP packets. But what is about SCTP/IP packets? I guess in WebRTC you are only interested in AF_CONN sockets or am I missing something? |
Thanks for the quick answer @tuexen! In WebRTC, we only do SCTP over DTLS, which means we only exchange buffers around, and use DTLS as the encapsulation protocol for that at an application level. So we never do any SCTP over IP or UDP. The code was based on the |
To answer your other question, yes, we use |
So you don't want to process SCTP/UDP/IP and don't want to process SCTP/IP packets. Let me think... However, I it is a bug that when providing 0 as the UDP port number in |
I fixed in f15553f that UDP encapsulation is not disabled, when providing 0 as the UDP port. What about adding a function |
Thanks for the commit! We were not using the "ephemeral ports as a feature", so it's fine by me. On your other question:
I almost always launch the stack as non-root (Janus doesn't require it) on my laptop, but in several deployments we do use root instead (as do others). I think a |
Here is the way for you: Just compile the library without INET and INET6 being defined. Then you get no support for SCTP/IP and SCTP/UDP/IP at all. Including the threads not getting started. Does this resolve you problem? |
I think that would work too. I was just wondering if there was an easy way to disable things programmatically, as in principle the same library may be used by different projects on the same machine, and so disabling things at compile time may break features that some other application needs. Shouldn't be an issue in the vast majority of cases, though. |
I have no idea how people use the library. I was assuming that they build it within their application and do not install them system wide. I'll add such a function, but you can just compile without INET and INET6 to get what you want right now. |
I can confirm compiling with |
If you compile without INET and INET6, everything should be fine. If you compile with INET or INET6 and run as root, raw sockets would be opened. The library would process SCTP/IP packets as long as you don't have SCTP kernel support enabled. On linux this means if the sctp kernel module is loaded.
|
Hi all,
I recently found out that when the stack is initialized with
usrsctp_init
, a dedicated thread for SCTP over UDP encapsulation is started too, which binds to ports on both IPv4 and IPv6. In my case ports are random because I'm passing0
to the init method. Since I'm using usrsctp as a stack in a WebRTC server, I don't need that encapsulation: I'm actually wondering if it might be "dangerous" to have in the first place, as I'm not sure what happens in my code if someone starts sending SCTP messages to those ports via UDP (possibly a risk of highjacking existing associations?).Looking at the code, apparently the only way to prevent those sockets from being created is calling
usrsctp_init_nothreads
, that stopsrecv_thread_init
from being called (which is where those sockets are created and managed). This also forces us to handle the usrsctp stack in our own event loop, which increases the complexity on our end. As such, I prepared this simple PR that adds a new init method, calledusrsctp_init_noudpthread
, that still allows the stack to create threads, but preventsrecv_thread_init
from being called.This seems to do the trick, even though I'm not sure this is the right way to integrate it in the existing codebase. In fact, I'm "abusing" the
start_threads
argument passed to the internalsctp_init
for my purposes. In the existing code:usrsctp_init
passesstart_threads=1
usrsctp_init_nothreads
passesstart_threads=0
My PR adds code so that all the above still is true, and
usrsctp_init_noudpthread
passesstart_threads=2
This means that all checks that do something like
if(start_threads)
still resolve toTRUE
as they should. To make sure the UDP encapsulation code is not started, I modified one of those checks to an explicitstart_threads == 1
instead, so that it doesn't kick in if I pass2
. More precisely:As
sctp_pcb_init
is what invokesrecv_thread_init
if thestart_threads
it is aware of is not0
.Please let me know if that makes sense and is acceptable as it is, or if it can have implications on other areas of the code. I still think we need a way to allow stacks not to create that UDP encapsulation stuff, as I believe it might be a vector of attacks in unsuspecting applications.
Thanks!