Skip to content

Commit d5948b7

Browse files
Merge pull request #1015 from melpon/sctp-zero-checksum
Set SCTP zero checksum
2 parents 75f921a + b450b76 commit d5948b7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/impl/sctptransport.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ SctpTransport::InstancesSet *SctpTransport::Instances = new InstancesSet;
102102

103103
void SctpTransport::Init() {
104104
usrsctp_init(0, SctpTransport::WriteCallback, SctpTransport::DebugCallback);
105-
usrsctp_enable_crc32c_offload(); // We'll compute CRC32 only for outgoing packets
106105
usrsctp_sysctl_set_sctp_pr_enable(1); // Enable Partial Reliability Extension (RFC 3758)
107106
usrsctp_sysctl_set_sctp_ecn_enable(0); // Disable Explicit Congestion Notification
108107
#ifdef SCTP_DEBUG
@@ -284,6 +283,14 @@ SctpTransport::SctpTransport(shared_ptr<Transport> lower, const Configuration &c
284283
throw std::runtime_error("Could not disable SCTP fragmented interleave, errno=" +
285284
std::to_string(errno));
286285

286+
// When using SCTP over DTLS, the data integrity is ensured by DTLS. Therefore, there's no need
287+
// to check CRC32c additionally when receiving.
288+
// See https://datatracker.ietf.org/doc/html/draft-ietf-tsvwg-sctp-zero-checksum
289+
int edmid = SCTP_EDMID_LOWER_LAYER_DTLS;
290+
if (usrsctp_setsockopt(mSock, IPPROTO_SCTP, SCTP_ACCEPT_ZERO_CHECKSUM, &edmid, sizeof(edmid)))
291+
throw std::runtime_error("Could set socket option SCTP_ACCEPT_ZERO_CHECKSUM, errno=" +
292+
std::to_string(errno));
293+
287294
int rcvBuf = 0;
288295
socklen_t rcvBufLen = sizeof(rcvBuf);
289296
if (usrsctp_getsockopt(mSock, SOL_SOCKET, SO_RCVBUF, &rcvBuf, &rcvBufLen))
@@ -960,13 +967,6 @@ void SctpTransport::UpcallCallback(struct socket *, void *arg, int /* flags */)
960967
int SctpTransport::WriteCallback(void *ptr, void *data, size_t len, uint8_t tos, uint8_t set_df) {
961968
auto *transport = static_cast<SctpTransport *>(ptr);
962969

963-
// Set the CRC32 ourselves as we have enabled CRC32 offloading
964-
if (len >= 12) {
965-
uint32_t *checksum = reinterpret_cast<uint32_t *>(data) + 2;
966-
*checksum = 0;
967-
*checksum = usrsctp_crc32c(data, len);
968-
}
969-
970970
// Workaround for sctplab/usrsctp#405: Send callback is invoked on already closed socket
971971
// https://github.com/sctplab/usrsctp/issues/405
972972
if (auto locked = Instances->lock(transport))

0 commit comments

Comments
 (0)