A portable SCTP userland stack

(github.com)

41 points | by mococa a day ago ago

45 comments

  • Sean-Der a day ago ago

    I have a huge soft spot for SCTP, I think it's a wonderful protocol.

    It's such a fun/clever hack that you can run it over UDP as well. It felt the best case for both worlds.

    I wrote a little bit about it here[0] I am still hoping to interview one of the protocol authors. It would be cool to hear the motivations, hopes and compromises it took to make it happen.

    [0] https://webrtcforthecurious.com/docs/07-data-communication

    • tptacek a day ago ago

      Is it a hack, or is it an attempt to correct the fatal mistake of the protocol? Running SCTP directly off the top of IP was such a weird decision. This is literally the reason UDP exists: to make it possible to create arbitrary new IP protocols! And they eschewed it, and it became undeployable.

      • cryptonector 20 hours ago ago

        No, that's not why UDP exists. Transport protocols _in principle_ should be the next layer after IP, but too many middleboxes drop packets for transport protocols they don't support. SCTP over UDP exists because of that. The fact that one can run anything over UDP merely proves that middleboxes really have no business dropping packets for ULPs they don't recognize/support. In fact, middleboxes are expected to pass these things through!

        • tptacek 19 hours ago ago

          My source for this is David Reed, which is pretty dispositive.

          • cryptonector an hour ago ago

            That's not entirely dispositive, and I'd have to see exactly what he had to say because it's likely that there's nuance. I'd be specifically interested in whether he says that at the time he intended UDP to what one builds other ULPs on, or merely application protocols; the latter would make what he says absolutely not dispositive here.

            IP has an 8-bit next protocol field. UDP has things other potential ULPs may simply not care about (checksum, port numbers). What Reed wanted UDP for and what his contemporaries wanted it for, and why IP has an 8-bit next protocol number, need not all be in agreement. There have been a fair number of ULPs, including ICMP, TCP, UDP, ESP/AH, UDP-Lite, EGP, IGP, EIGRP, OSPF, DCCP, SCTP, RSVP, PIM, VRRP, HIP, IP-in-IP, etc.

            Middleboxes should really stop filtering unknown ULPs. Such filtering is pointless. That UDP exists is not license to filter other ULPs.

      • Sean-Der a day ago ago

        Very small overhead putting it inside of UDP, doesn't really matter though.

        You also have to double checksum, that can be disabled with SCTP selectively now!

        ----

        I am just a hobbyist though. I would be curious to hear the take of a big network operator.

        • kev009 21 hours ago ago

          SCTP is widely used in telecom, i.e. SIGTRAN and the way your cell phone interoperates on the backend. The telecom industry is a parallel universe, they aren't really bothered by complexity sometimes for better sometime for worse.

      • kevin_thibedeau a day ago ago

        > such a weird decision

        IP is designed to handle more than two data transport protocols. It's such a weird decision that the power that be won't let us use the internet as intended.

        • tptacek a day ago ago

          What is the virtue of a protocol running directly on top of IP, versus on top of UDP? Avoiding a checksum?

          • Veserv a day ago ago

            What is the virtue of wasting throughput? You need to actually characterize why there is a technical benefit to the cost rather than demanding others prove the negative.

            And just to clarify a potential line of argument, arguing that we have ossification and thus running over UDP is the only practical solution for adoption, while correct, is not a benefit to disallowing other protocols to run directly on top of IP. It is a consequence.

            • tptacek a day ago ago

              What wasted throughput? You could say the same thing about any number of fields in the IP header itself. The question is "what does direct IP get you that UDP doesn't get you". This was, as I keep saying, the original design purpose of UDP.

              Arguably, TCP should have been built atop UDP.

              The thing to notice is that, apart from the checksum field --- which SCTP has as well, albeit with a different checksum --- UDP doesn't do anything but multiplex. It has no practically no mechanism that IP itself lacks, and vice versa.

              • Veserv a day ago ago

                Again, the backwards question. The actual question is: “What does UDP get you that IP does not get you?”

                UDP is just a length, checksum, source, and destination application routing address. IPv4 has a length, checksum, source, and destination machine routing address. IPv6 has a length, source, and destination machine routing address (having determined computing the checksum at this layer is a waste).

                They hold the same class of information except that layering UDP gives you a additional 16-bits of routing on top of your IP routing which is somewhat relevant for IPv4, but meaningless for IPv6. And the additional routing bits for IPv4 should have always been resolved at the IP routing layer anyways which is exactly what IPv6 did (though done poorly in my opinion, but at least solved the need for more bits).

                Flexible usage of UDP for higher level protocols effectively uses the destination port as the “Next Header” field present in IP protocols. The only advantage there is it is a 16-bit format identifier instead of 8-bit, but now the field is doing double duty as a application-level routing address and a format identifier. Placing a subsequent format identifier in the UDP payload then extends your format identifier further, but at least mostly preserves the application-level routing model of the destination port. If you actually need the extra formats then IP can easily reserve a few format values to indicate a even wider format identifier immediately afterward.

                • tptacek 21 hours ago ago

                  I feel like you're making my case for me. You lose nothing by building on top of UDP. You gain (marginally) flexibility, since UDP has a larger multiplexing ID (and since userland on mainstream operating systems can program it directly), and you gain (massively) deployability --- which is why we have mainstream HTTP/3 deployments, and virtually no SCTP at all outside of private telecom use cases.

                  • Veserv 19 hours ago ago

                    Only if you think that spending 8 extra bytes to get 1 extra byte of format identifier is making your case for you. Just to make it really, really obvious, doing it directly on top of IP would cost like 1, maybe 2 extra bytes to get 1 extra byte of format identifier. Strictly inferior to the alternative on a technical level. And that is ignoring the extra cost of adding a extra checksum, a cost so not worth it that IPv6 decided to remove it from the header format even though it was present in IPv4.

                    The only compelling argument is deployability, but, as I clearly pointed out above, that is a invalid argument because it is a consequence of the decision to ban anything other than TCP and UDP. Arguing that using UDP is the best choice because using anything else is banned is circular reasoning at its finest. As I also acknowledged above it is the state of the world right now and it is what you need to do to get deployed, but it is not a technical argument in favor of that technical decision. It is a terrible technical decision being propped up by ossification.

                    • tptacek 19 hours ago ago

                      You're just saying the same things over again. I especially like the accounting you did with the header bytes to avoid acknowledging UDP has 32 bits of multiplexing ID to IP's 8. I don't grant the premise that these are meaningful size differences to begin with, but if we're playing that game, we can golf a bunch of stuff out of the IP header too.

                      You also skated past half the deployability argument. It's not just that basically every middlebox on the Internet, old and new, will refuse to forward martian IPPROTO datagrams. It's also that every mainstream operating system prevents normal programs from programming IP directly.

                      All this drama... to save, like, 3-6 bytes? Yeah, seems like a pretty bad trade.

                      • garaetjjte 5 hours ago ago

                        >It's also that every mainstream operating system prevents normal programs from programming IP directly.

                        Well yes, because transport is typically handled by the kernel. Do you think UDP should be the only protocol handled by kernel and kernel TCP stack shouldn't exist?

                      • Veserv 17 hours ago ago

                        It is clear that you have no interest is making a technical argument about protocol design. Have a nice day.

                        • mahemm 3 hours ago ago

                          It seems like `tptacek's argument is something along the lines of 'maybe you can save bytes, but the cost of doing so is making your protocol basically impossible to deploy on the open internet', which to me is a perfectly reasonable technical argument.

                        • tptacek 17 hours ago ago

                          You get how that's a weird thing to say to someone who is golfing the IP header in the very comment you responded to, right? It's ok to just disagree with people.

              • pwdisswordfishq a day ago ago

                Arguably, UDP should have not been invented.

                • cryptonector 20 hours ago ago

                  Sure. It was a safety valve. It's worked really well as such.

      • xorcist a day ago ago

        Is it TCP over IP, or TCP over UDP over IP? There's the answer.

        • tptacek 19 hours ago ago

          TCP over UDP over IP would have been a much better design. Unfortunately, TCP preceded UDP, by several years, so we missed that opportunity.

    • atribecalledqst a day ago ago

      It prominently appears in W. Richard Stevens' "UNIX Network Programming" which I learned C and sockets programming from. So I have exercises written using SCTP - I forget what libraries I used at the time. Most of my work was on a FreeBSD VM, I think - and I might have installed a userland Linux library for it.

      I can't be the only one who knows it for this exact reason...

  • valorzard a day ago ago

    This library is a bit outdated when it comes to keeping up with the newer specs.

    I’d recommend Pion’s SCTP library instead if you okay with Go, since they try to incorporate the latest research as best they can: https://github.com/pion/sctp

    If rust is more your speed, there is also SCTP-proto that’s used by a couple of other WebRTC implementations , but that lacks some of more recent RFCs for SCTP: https://github.com/webrtc/dcsctp

    There is also an official Google rewrite in rust for their SCTP library that will eventually be included in libwebrtc (though I don’t think anyone actually uses it yet): https://github.com/webrtc/dcsctp

    • Orphis a day ago ago

      You linked dcsctp twice!

      Also, fair warning for those wanting to use dcsctp for regular SCTP purposes, the library aims to only implement the WebRTC focused subset. It's a great library for that purpose, whether you use the original C++ version or newer experimental Rust version.

  • joshuanapoli a day ago ago

    I was wondering what SCTP is for:

    > SCTP was originally designed to transport Public Switched Telephone Network (PSTN) signaling messages over IP networks. It is also suited to be used for other applications, for example, WebRTC.

    https://www.rfc-editor.org/info/rfc9260/

    It looks meant for applications that don’t need TCP’s strict in-order delivery and want to avoid its head-of-line blocking.

    • tptacek a day ago ago

      The problem it has now is that QUIC also eliminates head-of-line blocking problems, and has become "normal" and deployable in ways SCTP won't be.

      • commandersaki 9 hours ago ago

        Yeah I was wondering why would want to use SCTP over QUIC. But of course such a stack is helpful when interoperating with all that telco crap.

    • kevin_nisbet a day ago ago

      There is a bit more to it than that. There are a few properties that had telecoms drive SCTP standards and adoption. The head of line blocking you mentioned iirc is optional. So the application can control in order delivery. Another one is binding to more than one network. Many telecoms for essential equipment have two networks and the hosts can fail on one and retry on another. TCP has mTCP but still with blocking and doesn’t have wide availability to be exposed to applications.

  • throw0101d a day ago ago

    Sadly middlebox ossification (FW, NAT, LB, DPI) has generally set it with the Internet.

    * https://en.wikipedia.org/wiki/Protocol_ossification

    • commandersaki 9 hours ago ago

      Yeah SCTP has mostly found a home with telcos in their backends. This stack would probably benefit those working in that space.

    • Sean-Der a day ago ago

      You can run it over UDP still!

      I am curious if QUIC will hit a wall with requiring UDP. You have some network operators that refuse to support anything but TCP on set ports.

      • throw0101c a day ago ago
      • gspr a day ago ago

        I see the same thing as you, so please forgive the naive question: why are so many trying to turn the internet into TCP with some UDP at best, TCP/443 only at worst? Like, what's to gain? I understand that the owners of popular websites have a lot to gain by turning the internet into cable television, but what do the network operators stand to gain?

        • cryptonector 20 hours ago ago

          First of all, TCP has problems (much complexity, poor window management, poor congestion control / ramp up in modern networks, etc). Second of all, if you want to optimize the number of messages needed to start protocols like TLS over TCP then you need a new protocol, and that's what QUIC is. So, yes, there are reasons to build replacements for TCP.

          • kbolino 20 hours ago ago

            I would suggest that you (and the downvoters) re-read the comment more carefully. It's not asking why other protocols exist, it's asking why network operators don't want to support them.

        • kbolino 19 hours ago ago

          Large corporate/institutional IT departments don't need to support anything outside of "web browsing", and have to answer to insurance/regulatory requirements for things like "terminate unknown traffic at the security boundary" and "monitor all users for suspicious activities". They buy drop-in security appliances so they can easily check the compliance boxes. These appliances are slow to evolve and the people involved have little incentive to allow protocol flexibility, since it just complicates their lives. This isn't the only reason, but it is one of the bigger ones.

          • gspr 13 hours ago ago

            Why don't they "have to support anything outside of web browsing"? Unless you take "have to" to mean literally have to – having the ability to use different protocols can be a productivity boost to some. Ok, the IT department don't "have to" support productivity boosting things, but it's a good idea.

            • kbolino 5 hours ago ago

              If nobody (who matters) complains, then nothing's broken.

              IT answers to the management of the organization, not to the IETF. Most orgs are not IT shops, and their management considers IT to be an unfortunately necessary burden, not a valuable enhancer of productivity. They hire and manage IT accordingly.

              Internet engineers who want to improve things could decide to leave these organizations behind, using more aggressive changes to protocols that break the stagnant middleboxes. But then they would be fighting an uphill battle for adoption. This is precisely the issue which prevented the widespread use of native SCTP; Microsoft, in particular, never adopted it, because they (probably correctly) felt that most of their enterprise customers didn't want it and would just disable it as a "security precaution".

            • adinisom 9 hours ago ago

              I'm familiar with companies hit by ransomware and other attacks so hard and frequently that everything is locked down. It's a significant hit to engineering productivity, but acceptable to them in light of the alternative. And the IT groups involved keep their jobs by avoiding these problems, not by making engineering more productive.

      • ronsor a day ago ago

        And soon they will refuse to provide Internet service at all.

        Just deploy and let them whine.

  • happyPersonR a day ago ago

    Over ipv6 with some tweaks Sctp has a chance … sadly most of the use cases for SCTP and the people that have them have this bizarre definition of “dual-stack” that I’ve never actually seen work on anything other than a router.

    maybe we’ve rolled out enough ipv6 to make this work?

    This is particularly a challenge in public cloud hosted Kubernetes environments, CNI's with ipv4 just arent SCTP friendly.

    Interestingly though ... there may be some applicability for it as a part of LLM.

  • boguscoder a day ago ago

    Manual link seems to be dead

  • heyamitkumar5 a day ago ago

    SCTP has great transport properties—message framing, multiple independent streams without head-of-line blocking across streams, and multihoming—but getting it deployed reliably in the wild has always hit two walls: inconsistent kernel support across OSes/containers and middleboxes/NATs that don't treat raw IP protocol 132 kindly.

    Running a portable userland stack like usrsctp (and encapsulating over UDP/DTLS, as WebRTC data channels popularized) solves both problems without needing kernel modules or root privileges. For anyone who has run userland transport stacks in production: how painful are timers, congestion-control tuning, and event-loop integration compared to letting the OS kernel manage socket buffers and timers?