Paul-Louis Ageneau před 4 roky
rodič
revize
56dbcaad97
1 změnil soubory, kde provedl 15 přidání a 12 odebrání
  1. 15 12
      src/sctptransport.cpp

+ 15 - 12
src/sctptransport.cpp

@@ -25,10 +25,19 @@
 #include <thread>
 #include <vector>
 
+// RFC 8261 5. DTLS considerations:
+// If path MTU discovery is performed by the SCTP layer and IPv4 is used as the network-layer
+// protocol, the DTLS implementation SHOULD allow the DTLS user to enforce that the
+// corresponding IPv4 packet is sent with the Don't Fragment (DF) bit set. If controlling the DF
+// bit is not possible (for example, due to implementation restrictions), a safe value for the
+// path MTU has to be used by the SCTP stack. It is RECOMMENDED that the safe value not exceed
+// 1200 bytes.
+// See https://tools.ietf.org/html/rfc8261#section-5
+#define DEFAULT_MTU 1200
+
 // The IETF draft says:
 // SCTP MUST support performing Path MTU discovery without relying on ICMP or ICMPv6 as specified in
-// [RFC4821] using probing messages specified in [RFC4820]. The initial Path MTU at the IP layer
-// SHOULD NOT exceed 1200 bytes for IPv4 and 1280 for IPv6.
+// [RFC4821] using probing messages specified in [RFC4820].
 // See https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-5
 //
 // However, usrsctp does not implement Path MTU discovery, so we need to disable it for now.
@@ -51,6 +60,7 @@
 #endif
 */
 
+
 using namespace std::chrono_literals;
 using namespace std::chrono;
 
@@ -170,22 +180,15 @@ SctpTransport::SctpTransport(std::shared_ptr<Transport> lower, uint16_t port,
 	struct sctp_paddrparams spp = {};
 	// Enable SCTP heartbeats
 	spp.spp_flags = SPP_HB_ENABLE;
-
-	// RFC 8261 5. DTLS considerations:
-	// If path MTU discovery is performed by the SCTP layer and IPv4 is used as the network-layer
-	// protocol, the DTLS implementation SHOULD allow the DTLS user to enforce that the
-	// corresponding IPv4 packet is sent with the Don't Fragment (DF) bit set. If controlling the DF
-	// bit is not possible (for example, due to implementation restrictions), a safe value for the
-	// path MTU has to be used by the SCTP stack. It is RECOMMENDED that the safe value not exceed
-	// 1200 bytes.
-	// See https://tools.ietf.org/html/rfc8261#section-5
 #if USE_PMTUD
 	// Enable SCTP path MTU discovery
 	spp.spp_flags |= SPP_PMTUD_ENABLE;
 #else
 	// Fall back to a safe MTU value.
 	spp.spp_flags |= SPP_PMTUD_DISABLE;
-	spp.spp_pathmtu = 1200;
+	// The MTU value provided specifies the space available for chunks in the
+	// packet, so we also subtract the SCTP header size.
+	spp.spp_pathmtu = DEFAULT_MTU - 12 - 37 - 8 - 20; // SCTP/DTLS/UDP/IPv4
 #endif
 	if (usrsctp_setsockopt(mSock, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &spp, sizeof(spp)))
 		throw std::runtime_error("Could not set socket option SCTP_PEER_ADDR_PARAMS, errno=" +