[FFmpeg-devel] [PATCH] avformat/rtpproto: add support for RTP/UDP socket reuse

Rémi Denis-Courmont remi at remlab.net
Tue Jan 3 18:03:00 EET 2023


Le tiistaina 3. tammikuuta 2023, 11.03.30 EET Camille Oudot a écrit :
> Hi, I'm back on the topic. Thanks to all of you for your comments.
> 
> > So I agree that SO_REUSEADDR is "absolutely not a hack"... if you use
> > it to recycle IP/port pair without waiting for the time-out. But
> > that's mainly of interest of listening/receiving sockets.
> 
> That is indeed the case for TCP sockets, but as far as I know this does
> not apply to UDP as there is no TIME_WAIT state associated to datagram
> sockets.
> 
> The classical use of this option would be for having a process binding
> on udp:0.0.0.0:1234 then another one binding on e.g.
> udp:192.168.1.10:1234 without triggering a "address in use" error. This
> is indeed a matter of listening socket.

Sure. But then that does not solve the problem of RTCP mux and SDP bundle, 
which normally would use the exact same IP address and port number on the 
local end (and also on the far end, if set).

> > If you use it to bind two concurrent sockets on the same IP/port
> > pair, then it is absolutely not just a hack but a platform-dependent
> > non-portable hack and a latent vulnerability in the OS (since one
> > process can hijack datagrams for another).
> 
> The use of REUSEPORT instead of REUSEADDR is meant to mitigate this
> risk (but it's far from perfect).

It's not that simple. The semantics of REUSEPORT varies between Linux and BSD. 
IIRC, REUSEPORT was originally meant by BSD to allow multiple processes to 
listen on the same multicast group, but then Linux redefined it with radically 
different semantics, for receive load-balancing purpose.

> I definitely agree that using these options instead of refactoring or
> rewriting the RTP protocol to support RTP bundle and RTCP mux is a
> hack. I should take some time in the future to look into a proper
> solution. In the meantime, several people are looking for this feature:
> 
> - http://ffmpeg.org/pipermail/ffmpeg-user/2018-September/041393.html
> - https://trac.ffmpeg.org/ticket/1774

Repeating myself, but I don't see how that solves the problem. You don't need 
REUSEADDR for two sockets to send to the same remote IP/port, and you cannot 
rely on it to send from the same local IP/port.

-- 
レミ・デニ-クールモン
http://www.remlab.net/





More information about the ffmpeg-devel mailing list