From 02739d52dd4f297ba343652b1bfb6a6853f21a2f Mon Sep 17 00:00:00 2001 From: melpon Date: Tue, 24 Oct 2023 15:44:11 +0900 Subject: [PATCH] Implements SCTP zero checksum --- include/rtc/configuration.hpp | 3 +++ src/impl/sctptransport.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/rtc/configuration.hpp b/include/rtc/configuration.hpp index feb34abbe..8ad694aa8 100644 --- a/include/rtc/configuration.hpp +++ b/include/rtc/configuration.hpp @@ -86,6 +86,9 @@ struct RTC_CPP_EXPORT Configuration { // Local maximum message size for Data Channels optional maxMessageSize; + + // SCTP settings + bool sctpZeroChecksum = false; }; } // namespace rtc diff --git a/src/impl/sctptransport.cpp b/src/impl/sctptransport.cpp index de3865d2b..2f476b202 100644 --- a/src/impl/sctptransport.cpp +++ b/src/impl/sctptransport.cpp @@ -284,6 +284,16 @@ SctpTransport::SctpTransport(shared_ptr lower, const Configuration &c throw std::runtime_error("Could not disable SCTP fragmented interleave, errno=" + std::to_string(errno)); + // When using SCTP over DTLS, the data integrity is ensured by DTLS, so there's no + // need to additionally compute CRC32c. + // See https://datatracker.ietf.org/doc/html/draft-ietf-tsvwg-sctp-zero-checksum + if (config.sctpZeroChecksum) { + int on = 1; + if (usrsctp_setsockopt(mSock, IPPROTO_SCTP, SCTP_ACCEPT_ZERO_CHECKSUM, &on, sizeof(on))) + throw std::runtime_error("Could set socket option SCTP_ACCEPT_ZERO_CHECKSUM, errno=" + + std::to_string(errno)); + } + int rcvBuf = 0; socklen_t rcvBufLen = sizeof(rcvBuf); if (usrsctp_getsockopt(mSock, SOL_SOCKET, SO_RCVBUF, &rcvBuf, &rcvBufLen))