diff options
author | Mauro Sardara <msardara@cisco.com> | 2021-02-10 14:26:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2021-02-10 14:26:52 +0000 |
commit | 71a5c399d8064e2aa97a047e23174bb784eea399 (patch) | |
tree | 740bae933895ab6c40db1eb14fcd84a67536df06 /libtransport | |
parent | db76bbc76c8d2cb2d817df8c9233937d230a1ff2 (diff) | |
parent | 8d08f8dd79ac12874ba0da6b26973f5a33163131 (diff) |
Merge "[HICN-679] Do not throw exception when receiving corrupted/not-hicn packet from network layer"v21.01-rc0
Diffstat (limited to 'libtransport')
-rw-r--r-- | libtransport/includes/hicn/transport/core/packet.h | 11 | ||||
-rw-r--r-- | libtransport/src/core/packet.cc | 9 | ||||
-rw-r--r-- | libtransport/src/core/portal.h | 13 | ||||
-rw-r--r-- | libtransport/src/core/tcp_socket_connector.cc | 3 |
4 files changed, 22 insertions, 14 deletions
diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index 2efd7439d..91f957964 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -23,6 +23,7 @@ #include <hicn/transport/security/crypto_suite.h> #include <hicn/transport/security/key_id.h> #include <hicn/transport/utils/branch_prediction.h> +#include <hicn/transport/utils/log.h> #include <hicn/transport/utils/membuf.h> #include <hicn/transport/utils/object_pool.h> @@ -97,13 +98,16 @@ class Packet : public std::enable_shared_from_this<Packet> { static bool isInterest(const uint8_t *buffer); - static Format getFormatFromBuffer(const uint8_t *buffer) { + static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length) { Format format = HF_UNSPEC; if (TRANSPORT_EXPECT_FALSE( hicn_packet_get_format((const hicn_header_t *)buffer, &format) < 0)) { - throw errors::MalformedPacketException(); + TRANSPORT_LOGE( + "Error while getting format from packet buffer. Packet will be " + "discarded."); + hicn_packet_dump(buffer, length); } return format; @@ -114,7 +118,8 @@ class Packet : public std::enable_shared_from_this<Packet> { packet_start_ = reinterpret_cast<hicn_header_t *>(packet_->writableData()); header_head_ = packet_.get(); payload_head_ = nullptr; - format_ = getFormatFromBuffer(reinterpret_cast<uint8_t *>(packet_start_)); + format_ = getFormatFromBuffer(reinterpret_cast<uint8_t *>(packet_start_), + packet_->length()); name_.clear(); } diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 6815868f0..cd2c5aa69 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -50,7 +50,8 @@ Packet::Packet(MemBufPtr &&buffer) packet_start_(reinterpret_cast<hicn_header_t *>(packet_->writableData())), header_head_(packet_.get()), payload_head_(nullptr), - format_(getFormatFromBuffer(packet_->writableData())) {} + format_(getFormatFromBuffer(packet_->writableData(), packet_->length())) { +} Packet::Packet(const uint8_t *buffer, std::size_t size) : Packet(MemBufPtr(utils::MemBuf::copyBuffer(buffer, size).release())) {} @@ -210,13 +211,13 @@ const std::shared_ptr<utils::MemBuf> Packet::acquireMemBufReference() const { void Packet::dump() const { const_cast<Packet *>(this)->separateHeaderPayload(); - std::cout << "HEADER -- Length: " << headerSize() << std::endl; + TRANSPORT_LOGI("HEADER -- Length: %zu", headerSize()); hicn_packet_dump((uint8_t *)header_head_->data(), headerSize()); - std::cout << std::endl << "PAYLOAD -- Length: " << payloadSize() << std::endl; + TRANSPORT_LOGI("PAYLOAD -- Length: %zu", payloadSize()); for (utils::MemBuf *current = payload_head_; current && current != header_head_; current = current->next()) { - std::cout << "MemBuf Length: " << current->length() << std::endl; + TRANSPORT_LOGI("MemBuf Length: %zu", current->length()); hicn_packet_dump((uint8_t *)current->data(), current->length()); } } diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h index 364a36577..b63eab3af 100644 --- a/libtransport/src/core/portal.h +++ b/libtransport/src/core/portal.h @@ -96,13 +96,13 @@ class HandlerAllocator { HandlerAllocator(const HandlerAllocator<U> &other) noexcept : memory_(other.memory_) {} - TRANSPORT_ALWAYS_INLINE bool operator==(const HandlerAllocator &other) const - noexcept { + TRANSPORT_ALWAYS_INLINE bool operator==( + const HandlerAllocator &other) const noexcept { return &memory_ == &other.memory_; } - TRANSPORT_ALWAYS_INLINE bool operator!=(const HandlerAllocator &other) const - noexcept { + TRANSPORT_ALWAYS_INLINE bool operator!=( + const HandlerAllocator &other) const noexcept { return &memory_ != &other.memory_; } @@ -139,7 +139,7 @@ class CustomAllocatorHandler { } template <typename... Args> - void operator()(Args &&... args) { + void operator()(Args &&...args) { handler_(std::forward<Args>(args)...); } @@ -548,7 +548,8 @@ class Portal { return; } - Packet::Format format = Packet::getFormatFromBuffer(packet_buffer->data()); + Packet::Format format = Packet::getFormatFromBuffer( + packet_buffer->data(), packet_buffer->length()); if (TRANSPORT_EXPECT_TRUE(_is_tcp(format))) { if (!Packet::isInterest(packet_buffer->data())) { diff --git a/libtransport/src/core/tcp_socket_connector.cc b/libtransport/src/core/tcp_socket_connector.cc index f38bd2bef..fa029c6fc 100644 --- a/libtransport/src/core/tcp_socket_connector.cc +++ b/libtransport/src/core/tcp_socket_connector.cc @@ -46,7 +46,8 @@ class NetworkMessage { // Get packet length return ccnx_packet_length; } else if (TRANSPORT_EXPECT_TRUE(ip_format == 6 || ip_format == 4)) { - Packet::Format format = Packet::getFormatFromBuffer(packet); + Packet::Format format = + Packet::getFormatFromBuffer(packet, fixed_header_length); return Packet::getHeaderSizeFromBuffer(format, packet) + Packet::getPayloadSizeFromBuffer(format, packet); } |