diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/libwebrtc/net/dcsctp/packet | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/net/dcsctp/packet')
5 files changed, 69 insertions, 24 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.cc index 75f7d3c487..a846d6dff3 100644 --- a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.cc +++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.cc @@ -15,32 +15,44 @@ #include "absl/types/optional.h" #include "api/array_view.h" +#include "rtc_base/strings/string_builder.h" namespace dcsctp { // https://www.ietf.org/archive/id/draft-tuexen-tsvwg-sctp-zero-checksum-00.html#section-3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type = 0x8001 | Length = 4 | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type = 0x8001 (suggested) | Length = 8 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Error Detection Method Identifier (EDMID) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ constexpr int ZeroChecksumAcceptableChunkParameter::kType; absl::optional<ZeroChecksumAcceptableChunkParameter> ZeroChecksumAcceptableChunkParameter::Parse( rtc::ArrayView<const uint8_t> data) { - if (!ParseTLV(data).has_value()) { + absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data); + if (!reader.has_value()) { return absl::nullopt; } - return ZeroChecksumAcceptableChunkParameter(); + + ZeroChecksumAlternateErrorDetectionMethod method(reader->Load32<4>()); + if (method == ZeroChecksumAlternateErrorDetectionMethod::None()) { + return absl::nullopt; + } + return ZeroChecksumAcceptableChunkParameter(method); } void ZeroChecksumAcceptableChunkParameter::SerializeTo( std::vector<uint8_t>& out) const { - AllocateTLV(out); + BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out); + writer.Store32<4>(*error_detection_method_); } std::string ZeroChecksumAcceptableChunkParameter::ToString() const { - return "Zero Checksum Acceptable"; + rtc::StringBuilder sb; + sb << "Zero Checksum Acceptable (" << *error_detection_method_ << ")"; + return sb.Release(); } } // namespace dcsctp diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h index 9ae2ec8280..18c98c95c6 100644 --- a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h +++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h @@ -19,13 +19,14 @@ #include "api/array_view.h" #include "net/dcsctp/packet/parameter/parameter.h" #include "net/dcsctp/packet/tlv_trait.h" +#include "net/dcsctp/public/types.h" namespace dcsctp { -// https://datatracker.ietf.org/doc/draft-tuexen-tsvwg-sctp-zero-checksum/ +// https://datatracker.ietf.org/doc/draft-ietf-tsvwg-sctp-zero-checksum/ struct ZeroChecksumAcceptableChunkParameterConfig : ParameterConfig { static constexpr int kType = 0x8001; - static constexpr size_t kHeaderSize = 4; + static constexpr size_t kHeaderSize = 8; static constexpr size_t kVariableLengthAlignment = 0; }; @@ -36,13 +37,22 @@ class ZeroChecksumAcceptableChunkParameter static constexpr int kType = ZeroChecksumAcceptableChunkParameterConfig::kType; - ZeroChecksumAcceptableChunkParameter() {} + explicit ZeroChecksumAcceptableChunkParameter( + ZeroChecksumAlternateErrorDetectionMethod error_detection_method) + : error_detection_method_(error_detection_method) {} static absl::optional<ZeroChecksumAcceptableChunkParameter> Parse( rtc::ArrayView<const uint8_t> data); void SerializeTo(std::vector<uint8_t>& out) const override; std::string ToString() const override; + + ZeroChecksumAlternateErrorDetectionMethod error_detection_method() const { + return error_detection_method_; + } + + private: + ZeroChecksumAlternateErrorDetectionMethod error_detection_method_; }; } // namespace dcsctp diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter_test.cc index 8a004e1788..861fa4d785 100644 --- a/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter_test.cc +++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter_test.cc @@ -24,18 +24,28 @@ namespace { using ::testing::ElementsAre; TEST(ZeroChecksumAcceptableChunkParameterTest, SerializeAndDeserialize) { - ZeroChecksumAcceptableChunkParameter parameter; + ZeroChecksumAcceptableChunkParameter parameter( + ZeroChecksumAlternateErrorDetectionMethod::LowerLayerDtls()); std::vector<uint8_t> serialized; parameter.SerializeTo(serialized); - EXPECT_THAT(serialized, ElementsAre(0x80, 0x01, 0x00, 0x04)); + EXPECT_THAT(serialized, + ElementsAre(0x80, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01)); ASSERT_HAS_VALUE_AND_ASSIGN( ZeroChecksumAcceptableChunkParameter deserialized, ZeroChecksumAcceptableChunkParameter::Parse(serialized)); } +TEST(ZeroChecksumAcceptableChunkParameterTest, FailToDeserializePrevVersion) { + // This is how the draft described the chunk as, in version 00. + std::vector<uint8_t> invalid = {0x80, 0x01, 0x00, 0x04}; + + EXPECT_FALSE( + ZeroChecksumAcceptableChunkParameter::Parse(invalid).has_value()); +} + TEST(ZeroChecksumAcceptableChunkParameterTest, FailToDeserialize) { std::vector<uint8_t> invalid = {0x00, 0x00, 0x00, 0x00}; @@ -44,9 +54,10 @@ TEST(ZeroChecksumAcceptableChunkParameterTest, FailToDeserialize) { } TEST(ZeroChecksumAcceptableChunkParameterTest, HasToString) { - ZeroChecksumAcceptableChunkParameter parameter; + ZeroChecksumAcceptableChunkParameter parameter( + ZeroChecksumAlternateErrorDetectionMethod::LowerLayerDtls()); - EXPECT_EQ(parameter.ToString(), "Zero Checksum Acceptable"); + EXPECT_EQ(parameter.ToString(), "Zero Checksum Acceptable (1)"); } } // namespace diff --git a/third_party/libwebrtc/net/dcsctp/packet/sctp_packet.cc b/third_party/libwebrtc/net/dcsctp/packet/sctp_packet.cc index de407bb4c7..978181fc2a 100644 --- a/third_party/libwebrtc/net/dcsctp/packet/sctp_packet.cc +++ b/third_party/libwebrtc/net/dcsctp/packet/sctp_packet.cc @@ -126,7 +126,9 @@ absl::optional<SctpPacket> SctpPacket::Parse(rtc::ArrayView<const uint8_t> data, std::vector<uint8_t>(data.begin(), data.end()); if (options.disable_checksum_verification || - (options.enable_zero_checksum && common_header.checksum == 0u)) { + (options.zero_checksum_alternate_error_detection_method != + ZeroChecksumAlternateErrorDetectionMethod::None() && + common_header.checksum == 0u)) { // https://www.ietf.org/archive/id/draft-tuexen-tsvwg-sctp-zero-checksum-01.html#section-4.3: // If an end point has sent the Zero Checksum Acceptable Chunk Parameter in // an INIT or INIT ACK chunk, it MUST accept SCTP packets using an incorrect diff --git a/third_party/libwebrtc/net/dcsctp/packet/sctp_packet_test.cc b/third_party/libwebrtc/net/dcsctp/packet/sctp_packet_test.cc index fcdd161c0d..aab01df19c 100644 --- a/third_party/libwebrtc/net/dcsctp/packet/sctp_packet_test.cc +++ b/third_party/libwebrtc/net/dcsctp/packet/sctp_packet_test.cc @@ -38,7 +38,8 @@ using ::testing::SizeIs; constexpr VerificationTag kVerificationTag = VerificationTag(0x12345678); constexpr DcSctpOptions kVerifyChecksumOptions = DcSctpOptions{.disable_checksum_verification = false, - .enable_zero_checksum = false}; + .zero_checksum_alternate_error_detection_method = + ZeroChecksumAlternateErrorDetectionMethod::None()}; TEST(SctpPacketTest, DeserializeSimplePacketFromCapture) { /* @@ -208,8 +209,10 @@ TEST(SctpPacketTest, DeserializePacketDontValidateChecksum) { ASSERT_HAS_VALUE_AND_ASSIGN( SctpPacket packet, - SctpPacket::Parse(data, {.disable_checksum_verification = true, - .enable_zero_checksum = false})); + SctpPacket::Parse( + data, {.disable_checksum_verification = true, + .zero_checksum_alternate_error_detection_method = + ZeroChecksumAlternateErrorDetectionMethod::None()})); EXPECT_EQ(packet.common_header().source_port, 5000); EXPECT_EQ(packet.common_header().destination_port, 5000); EXPECT_EQ(packet.common_header().verification_tag, @@ -375,8 +378,11 @@ TEST(SctpPacketTest, AcceptsZeroSetZeroChecksum) { ASSERT_HAS_VALUE_AND_ASSIGN( SctpPacket packet, - SctpPacket::Parse(data, {.disable_checksum_verification = false, - .enable_zero_checksum = true})); + SctpPacket::Parse( + data, + {.disable_checksum_verification = false, + .zero_checksum_alternate_error_detection_method = + ZeroChecksumAlternateErrorDetectionMethod::LowerLayerDtls()})); EXPECT_EQ(packet.common_header().source_port, 5000); EXPECT_EQ(packet.common_header().destination_port, 5000); EXPECT_EQ(packet.common_header().verification_tag, @@ -409,9 +415,13 @@ TEST(SctpPacketTest, RejectsNonZeroIncorrectChecksumWhenZeroChecksumIsActive) { 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x55, 0x08, 0x36, 0x40, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - EXPECT_FALSE(SctpPacket::Parse(data, {.disable_checksum_verification = false, - .enable_zero_checksum = true}) - .has_value()); + EXPECT_FALSE( + SctpPacket::Parse( + data, + {.disable_checksum_verification = false, + .zero_checksum_alternate_error_detection_method = + ZeroChecksumAlternateErrorDetectionMethod::LowerLayerDtls()}) + .has_value()); } TEST(SctpPacketTest, WritePacketWithCalculatedChecksum) { |