mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-29 13:26:33 +01:00
dcsctp: add zero checksum acceptable chunk parameter
This will be included in INIT/INIT_ACK if the socket has configured the "accept zero checksum" parameter, that will be added in follow-up CLs. Bug: webrtc:14997 Change-Id: I1a2823fbc77cfea8fe746b07c1c77593bc15efe9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/298480 Commit-Queue: Victor Boivie <boivie@webrtc.org> Reviewed-by: Florent Castelli <orphis@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39702}
This commit is contained in:
parent
e08f9a94fa
commit
d7510fe1e4
4 changed files with 152 additions and 0 deletions
|
@ -98,6 +98,8 @@ rtc_library("parameter") {
|
|||
"parameter/state_cookie_parameter.h",
|
||||
"parameter/supported_extensions_parameter.cc",
|
||||
"parameter/supported_extensions_parameter.h",
|
||||
"parameter/zero_checksum_acceptable_chunk_parameter.cc",
|
||||
"parameter/zero_checksum_acceptable_chunk_parameter.h",
|
||||
]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||
|
@ -323,6 +325,7 @@ if (rtc_include_tests) {
|
|||
"parameter/ssn_tsn_reset_request_parameter_test.cc",
|
||||
"parameter/state_cookie_parameter_test.cc",
|
||||
"parameter/supported_extensions_parameter_test.cc",
|
||||
"parameter/zero_checksum_acceptable_chunk_parameter_test.cc",
|
||||
"sctp_packet_test.cc",
|
||||
"tlv_trait_test.cc",
|
||||
]
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.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 |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
constexpr int ZeroChecksumAcceptableChunkParameter::kType;
|
||||
|
||||
absl::optional<ZeroChecksumAcceptableChunkParameter>
|
||||
ZeroChecksumAcceptableChunkParameter::Parse(
|
||||
rtc::ArrayView<const uint8_t> data) {
|
||||
if (!ParseTLV(data).has_value()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
return ZeroChecksumAcceptableChunkParameter();
|
||||
}
|
||||
|
||||
void ZeroChecksumAcceptableChunkParameter::SerializeTo(
|
||||
std::vector<uint8_t>& out) const {
|
||||
AllocateTLV(out);
|
||||
}
|
||||
|
||||
std::string ZeroChecksumAcceptableChunkParameter::ToString() const {
|
||||
return "Zero Checksum Acceptable";
|
||||
}
|
||||
} // namespace dcsctp
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_
|
||||
#define NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/array_view.h"
|
||||
#include "net/dcsctp/packet/parameter/parameter.h"
|
||||
#include "net/dcsctp/packet/tlv_trait.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
||||
// https://datatracker.ietf.org/doc/draft-tuexen-tsvwg-sctp-zero-checksum/
|
||||
struct ZeroChecksumAcceptableChunkParameterConfig : ParameterConfig {
|
||||
static constexpr int kType = 0x8001;
|
||||
static constexpr size_t kHeaderSize = 4;
|
||||
static constexpr size_t kVariableLengthAlignment = 0;
|
||||
};
|
||||
|
||||
class ZeroChecksumAcceptableChunkParameter
|
||||
: public Parameter,
|
||||
public TLVTrait<ZeroChecksumAcceptableChunkParameterConfig> {
|
||||
public:
|
||||
static constexpr int kType =
|
||||
ZeroChecksumAcceptableChunkParameterConfig::kType;
|
||||
|
||||
ZeroChecksumAcceptableChunkParameter() {}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace dcsctp
|
||||
|
||||
#endif // NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "net/dcsctp/testing/testing_macros.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace dcsctp {
|
||||
namespace {
|
||||
using ::testing::ElementsAre;
|
||||
|
||||
TEST(ZeroChecksumAcceptableChunkParameterTest, SerializeAndDeserialize) {
|
||||
ZeroChecksumAcceptableChunkParameter parameter;
|
||||
|
||||
std::vector<uint8_t> serialized;
|
||||
parameter.SerializeTo(serialized);
|
||||
|
||||
EXPECT_THAT(serialized, ElementsAre(0x80, 0x01, 0x00, 0x04));
|
||||
|
||||
ASSERT_HAS_VALUE_AND_ASSIGN(
|
||||
ZeroChecksumAcceptableChunkParameter deserialized,
|
||||
ZeroChecksumAcceptableChunkParameter::Parse(serialized));
|
||||
}
|
||||
|
||||
TEST(ZeroChecksumAcceptableChunkParameterTest, FailToDeserialize) {
|
||||
std::vector<uint8_t> invalid = {0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
EXPECT_FALSE(
|
||||
ZeroChecksumAcceptableChunkParameter::Parse(invalid).has_value());
|
||||
}
|
||||
|
||||
TEST(ZeroChecksumAcceptableChunkParameterTest, HasToString) {
|
||||
ZeroChecksumAcceptableChunkParameter parameter;
|
||||
|
||||
EXPECT_EQ(parameter.ToString(), "Zero Checksum Acceptable");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace dcsctp
|
Loading…
Reference in a new issue