sip icon indicating copy to clipboard operation
sip copied to clipboard

TCP/TLS support for SIP signaling

Open justin0mcateer opened this issue 1 year ago • 9 comments

It appears that the SIP adapter/service is currently hard coded to use UDP for SIP signaling. However, it appears the upstream library has support for TCP and TLS.

https://github.com/livekit/sip/blob/1ce2ec84ebf08f23d97febddb507f63d4cc21c6d/pkg/sip/server.go#L172

Would there be any aversion to adding optional configuration options to support other SIP signaling transports such as TCP and/or TLS?

justin0mcateer avatar Mar 05 '24 23:03 justin0mcateer

There's definitely a plan to support more protocols eventually (especially TLS!). But for now I want to focus on supporting one protocol and getting all core features in (DTMF in LK, better audio codecs, to name a few).

In the meantime, you could help out by making the PoC with these changes to check how invasive (or not) it will be. I will gladly review it!

It seems like we need a config option for choosing which protocols to listen on (for inbound), plus Trunks will need to accept addresses with a protocol in them (for outbound). Both should default to UDP if not specified.

dennwc avatar Mar 06 '24 13:03 dennwc

I've looked at it a couple of times and it looks fairly simple. Sipgo is already loading support for all possible transports, it looks like the config and doing some branching on which listener configuration to use is the key thing to be handled.

However, we don't have anyone on our team who has any meaningful Go experience and we are pretty swamped with other work right now. We would be willing to sponsor this work if anyone is interested.

justin0mcateer avatar May 14 '24 15:05 justin0mcateer

Started working on TCP support.

dennwc avatar May 21 '24 13:05 dennwc

With UDP we are also experiencing issues with UDP fragmentation for SIP REFERs as sipgo limits to 1300 Bytes – which leads to issues with bigger SIP headers. TCP support would resolve this limitation / challenge as well.

maik-parloa avatar May 23 '24 15:05 maik-parloa

@maik-parloa We had the same issue recently, but unrelated to sipgo. SIP INVITE became larger than MTU and got dropped somewhere along the path. This is exactly why we want to prioritize TCP support now.

If it helps, as a workaround we made hostnames shorter and removed one code from SDP to fit packets inside MTU (while TCP is in progress).

dennwc avatar May 23 '24 16:05 dennwc

Initial support for TCP: #99.

dennwc avatar May 23 '24 17:05 dennwc

@dennwc If you look at the outgoing traffic from LiveKit SIP GW, you can see that the fragmentation prohibition flag is set (1.. .... = Don't fragment: Set). Probably this is configured somewhere in the libraries used.

Internet Protocol Version 4, Src: 10.10.10.10, Dst: 10.10.10.11
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
        0000 00.. = Differentiated Services Codepoint: Default (0)
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    Total Length: 939
    Identification: 0xafb4 (44980)
    010. .... = Flags: 0x2, Don't fragment
        0... .... = Reserved bit: Not set
        .1.. .... = Don't fragment: Set
        ..0. .... = More fragments: Not set
    ...0 0000 0000 0000 = Fragment Offset: 0
    Time to Live: 63
    Protocol: UDP (17)
 

denyspozniak avatar May 24 '24 09:05 denyspozniak

@dennwc Is there a timeline to support TLS, and can we support it somehow?

maik-parloa avatar Oct 10 '24 15:10 maik-parloa

this is on the roadmap for this month. :)

davidzhao avatar Oct 10 '24 15:10 davidzhao

Thanks for merging! When can I expect to have TLS functionality in the livekit cloud environment ?

alexHerrmio avatar Oct 25 '24 12:10 alexHerrmio

Yes, we are working on it!

dennwc avatar Oct 25 '24 16:10 dennwc

Thank you for the quick response, @dennwc! Could you provide us with a rough timeline for this? We’d like to conduct some latency tests using the LiveKit Cloud environment (with TLS) and have opted not to host an additional instance ourselves.

alexHerrmio avatar Oct 28 '24 08:10 alexHerrmio