diff options
author | Luca Muscariello <lumuscar@cisco.com> | 2022-03-30 22:29:28 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-03-31 19:51:47 +0200 |
commit | c46e5df56b67bb8ea7a068d39324c640084ead2b (patch) | |
tree | eddeb17785938e09bc42eec98ee09b8a28846de6 /libtransport/includes/hicn/transport/core/packet.h | |
parent | 18fa668f25d3cc5463417ce7df6637e31578e898 (diff) |
feat: boostrap hicn 22.02
The current patch provides several new features, improvements,
bug fixes and also complete rewrite of entire components.
- lib
The hicn packet parser has been improved with a new packet
format fully based on UDP. The TCP header is still temporarily
supported but the UDP header will replace completely the new hicn
packet format. Improvements have been made to make sure every
packet parsing operation is made via this library. The current
new header can be used as header between the payload and the
UDP header or as trailer in the UDP surplus area to be tested
when UDP options will start to be used.
- hicn-light
The portable packet forwarder has been completely rewritten from
scratch with the twofold objective to improve performance and
code size but also to drop dependencies such as libparc which is
now removed by the current implementation.
- hicn control
the control library is the agent that is used to program the
packet forwarders via their binary API. This component has
benefited from significant improvements in terms of interaction
model which is now event driven and more robust to failures.
- VPP plugin has been updated to support VPP 22.02
- transport
Major improvement have been made to the RTC protocol, to the
support of IO modules and to the security sub system. Signed
manifests are the default data authenticity and integrity framework.
Confidentiality can be enabled by sharing the encryption key to the
prod/cons layer. The library has been tested with group key based
applications such as broadcast/multicast and real-time on-line
meetings with trusted server keys or MLS.
- testing
Unit testing has been introduced using GoogleTest. One third of
the code base is covered by unit testing with priority on
critical features. Functional testing has also been introduce
using Docker, linux bridging and Robot Framework to define
test with Less Code techniques to facilitate the extension
of the coverage.
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Angelo Mantellini <manangel@cisco.com>
Co-authored-by: Jacques Samain <jsamain@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Enrico Loparco <eloparco@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
Change-Id: I75d0ef70f86d921e3ef503c99271216ff583c215
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/includes/hicn/transport/core/packet.h')
-rw-r--r-- | libtransport/includes/hicn/transport/core/packet.h | 218 |
1 files changed, 65 insertions, 153 deletions
diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index 269a1571a..059430f1d 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -30,11 +30,7 @@ namespace transport { namespace auth { class Signer; -class AsymmetricSigner; -class SymmetricSigner; class Verifier; -class AsymmetricVerifier; -class SymmetricVerifier; } // namespace auth namespace core { @@ -51,16 +47,13 @@ namespace core { class Packet : public utils::MemBuf, public std::enable_shared_from_this<Packet> { friend class auth::Signer; - friend class auth::SymmetricSigner; - friend class auth::AsymmetricSigner; friend class auth::Verifier; - friend class auth::AsymmetricVerifier; - friend class auth::SymmetricVerifier; public: using Ptr = std::shared_ptr<Packet>; using MemBufPtr = std::shared_ptr<utils::MemBuf>; using Format = hicn_format_t; + static constexpr size_t default_mtu = 1500; /** @@ -68,146 +61,73 @@ class Packet : public utils::MemBuf, * the eventual payload will be added by prepending the payload buffer * to the buffer chain whose the fist buffer is the header itself. */ - Packet(Format format = HF_INET6_TCP, std::size_t additional_header_size = 0); - - /** - * Create new IP packet using raw buffer. - */ - + Packet(Format format, std::size_t additional_header_size = 0); /* Copy buffer */ Packet(CopyBufferOp, const uint8_t *buffer, std::size_t size); /* Wrap buffer */ Packet(WrapBufferOp, uint8_t *buffer, std::size_t length, std::size_t size); /* Create new using pre-allocated buffer */ Packet(CreateOp, uint8_t *buffer, std::size_t length, std::size_t size, - Format format = HF_INET6_TCP, std::size_t additional_header_size = 0); - /* Move MemBuf */ - Packet(MemBuf &&buffer); + Format format, std::size_t additional_header_size = 0); + Packet(MemBuf &&buffer); Packet(Packet &&other); - - /* - * Copy constructor and assignemnt operators. - */ Packet(const Packet &other); - Packet &operator=(const Packet &other); - - friend bool operator==(const Packet &l_packet, const Packet &r_packet); + // Destructor virtual ~Packet(); - static std::size_t getHeaderSizeFromFormat(Format format, - std::size_t signature_size = 0) { - std::size_t header_length; - hicn_packet_get_header_length_from_format(format, &header_length); - int is_ah = _is_ah(format); - return is_ah * (header_length + signature_size) + (!is_ah) * header_length; - } - - static std::size_t getHeaderSizeFromBuffer(Format format, - const uint8_t *buffer); - - static std::size_t getPayloadSizeFromBuffer(Format format, - const uint8_t *buffer); - - static bool isInterest(const uint8_t *buffer); - - bool isInterest(); - - static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length) { - Format format = HF_UNSPEC; - hicn_packet_get_format((const hicn_header_t *)buffer, &format); - return format; - } - - void reset() { - clear(); - packet_start_ = reinterpret_cast<hicn_header_t *>(writableData()); - header_offset_ = 0; - format_ = HF_UNSPEC; - payload_type_ = PayloadType::UNSPECIFIED; - name_.clear(); - - if (isChained()) { - separateChain(next(), prev()); - } - } - - void setFormat(Packet::Format format = HF_INET6_TCP, - std::size_t additional_header_size = 0); - - std::size_t payloadSize() const; - - std::size_t headerSize() const; + // Operators + Packet &operator=(const Packet &other); + friend bool operator==(const Packet &l_packet, const Packet &r_packet); + // Cast to MemBuf std::shared_ptr<utils::MemBuf> acquireMemBufReference(); - virtual const Name &getName() const = 0; + // Format + Format getFormat() const; + void setFormat(Packet::Format format, std::size_t additional_header_size = 0); + // Name + virtual const Name &getName() const = 0; virtual Name &getWritableName() = 0; - virtual void setName(const Name &name) = 0; + // Lifetime virtual void setLifetime(uint32_t lifetime) = 0; - virtual uint32_t getLifetime() const = 0; - Packet &appendPayload(const uint8_t *buffer, std::size_t length); - - Packet &appendPayload(std::unique_ptr<utils::MemBuf> &&payload); - - std::unique_ptr<utils::MemBuf> getPayload() const; - - Packet &updateLength(std::size_t length = 0); - - PayloadType getPayloadType() const; - - Packet &setPayloadType(PayloadType payload_type); - - Format getFormat() const; - - void dump() const; - - static void dump(uint8_t *buffer, std::size_t length); - + // Locator virtual void setLocator(const ip_address_t &locator) = 0; - virtual ip_address_t getLocator() const = 0; - /** - * @brief Set signature timestamp, in milliseconds. - */ - void setSignatureTimestamp(const uint64_t ×tamp_milliseconds); - - uint64_t getSignatureTimestamp() const; - - void setValidationAlgorithm(const auth::CryptoSuite &validation_algorithm); - - auth::CryptoSuite getValidationAlgorithm() const; - - void setKeyId(const auth::KeyId &key_id); + // Payload type + PayloadType getPayloadType() const; + Packet &setPayloadType(PayloadType payload_type); - auth::KeyId getKeyId() const; + // Payload + std::unique_ptr<utils::MemBuf> getPayload() const; + Packet &appendPayload(std::unique_ptr<utils::MemBuf> &&payload); + Packet &appendPayload(const uint8_t *buffer, std::size_t length); - virtual auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const; + // Sizes + std::size_t headerSize() const; + std::size_t payloadSize() const; - void setChecksum() { - uint16_t partial_csum = - csum(data() + HICN_V6_TCP_HDRLEN, length() - HICN_V6_TCP_HDRLEN, 0); + // Digest + auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const; - for (utils::MemBuf *current = next(); current != this; - current = current->next()) { - partial_csum = csum(current->data(), current->length(), ~partial_csum); - } + // Reset packet + void reset(); - if (hicn_packet_compute_header_checksum(format_, packet_start_, - partial_csum) < 0) { - throw errors::MalformedPacketException(); - } - } + // Utils + bool isInterest(); + Packet &updateLength(std::size_t length = 0); + void dump() const; + // TCP methods + void setChecksum(); bool checkIntegrity() const; - Packet &setSyn(); Packet &resetSyn(); bool testSyn() const; @@ -222,53 +142,45 @@ class Packet : public utils::MemBuf, bool testFin() const; Packet &resetFlags(); std::string printFlags() const; - Packet &setSrcPort(uint16_t srcPort); Packet &setDstPort(uint16_t dstPort); uint16_t getSrcPort() const; uint16_t getDstPort() const; - Packet &setTTL(uint8_t hops); uint8_t getTTL() const; + // Authentication Header methods + bool hasAH() const; + std::vector<uint8_t> getSignature() const; + std::size_t getSignatureFieldSize() const; + std::size_t getSignatureSize() const; + uint64_t getSignatureTimestamp() const; + auth::KeyId getKeyId() const; + auth::CryptoSuite getValidationAlgorithm() const; + void setSignature(const std::vector<uint8_t> &signature); + void setSignatureFieldSize(std::size_t size); + void setSignatureSize(std::size_t size); + void setSignatureTimestamp(const uint64_t ×tamp_ms); + void setKeyId(const auth::KeyId &key_id); + void setValidationAlgorithm(const auth::CryptoSuite &algo); + + // Static methods + static Format toAHFormat(const Format &format); + static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length); + static std::size_t getHeaderSizeFromFormat(Format format, + std::size_t signature_size = 0); + static std::size_t getHeaderSizeFromBuffer(Format format, + const uint8_t *buffer); + static std::size_t getPayloadSizeFromBuffer(Format format, + const uint8_t *buffer); + static bool isInterest(const uint8_t *buffer, + Format format = Format::HF_UNSPEC); + static void dump(uint8_t *buffer, std::size_t length); + private: virtual void resetForHash() = 0; - void setSignatureSize(std::size_t size_bytes); - void setSignatureSizeGap(std::size_t size_bytes); void prependPayload(const uint8_t **buffer, std::size_t *size); - bool authenticationHeader() const { return _is_ah(format_); } - - std::size_t getSignatureSize() const { - size_t size_bytes; - int ret = - hicn_packet_get_signature_size(format_, packet_start_, &size_bytes); - - if (ret < 0) { - throw errors::RuntimeException("Packet without Authentication Header."); - } - - return size_bytes; - } - - std::size_t getSignatureSizeGap() const { - uint8_t size_bytes; - int ret = - hicn_packet_get_signature_gap(format_, packet_start_, &size_bytes); - - if (ret < 0) { - throw errors::RuntimeException("Packet without Authentication Header."); - } - - return (size_t)size_bytes; - } - - std::size_t getSignatureSizeReal() const { - return getSignatureSize() - getSignatureSizeGap(); - } - - uint8_t *getSignature() const; - protected: hicn_header_t *packet_start_; std::size_t header_offset_; |