33#include <tins/macros.h>
34#include <tins/cxxstd.h>
36#include <tins/endianness.h>
37#include <tins/small_uint.h>
38#include <tins/pdu_option.h>
39#include <tins/ipv6_address.h>
44class OutputMemoryStream;
86 DESTINATION_ROUTING_OPTIONS = 60,
90 SECURITY_ENCAPSULATION = 50,
91 DESTINATION_OPTIONS = 60,
102 JUMBO_PAYLOAD = 0xC2,
111 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
117 std::vector<header_option_type> options;
126 std::vector<header_option_type> options;
135 uint8_t routing_type;
136 uint8_t segments_left;
137 std::vector<uint8_t> data;
146 uint16_t fragment_offset;
148 uint32_t identification;
175 IPv6(
const uint8_t* buffer, uint32_t total_sz);
184 return header_.version;
192 #if TINS_IS_LITTLE_ENDIAN
193 return ((header_.traffic_class << 4) & 0xf0) |
194 ((header_.flow_label[0] >> 4) & 0x0f);
196 return header_.traffic_class;
205 #if TINS_IS_LITTLE_ENDIAN
206 return ((header_.flow_label[0] & 0x0f) << 16)
207 | (header_.flow_label[1] << 8)
208 | (header_.flow_label[2]);
210 return header_.flow_label;
219 return Endian::be_to_host(header_.payload_length);
227 return header_.next_header;
235 return header_.hop_limit;
243 return header_.src_addr;
251 return header_.dst_addr;
274 void traffic_class(uint8_t new_traffic_class);
286 void payload_length(uint16_t new_payload_length);
292 void next_header(uint8_t new_next_header);
298 void hop_limit(uint8_t new_hop_limit);
304 void src_addr(
const address_type& new_src_addr);
310 void dst_addr(
const address_type& new_dst_addr);
317 uint32_t header_size()
const;
326 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
332 return new IPv6(*
this);
380 ext_headers_.emplace_back(std::move(header));
388 template <
typename... Args>
390 ext_headers_.emplace_back(std::forward<Args>(args)...);
405 const ext_header* search_header(ExtensionHeader
id)
const;
407 void write_serialization(uint8_t* buffer, uint32_t total_sz);
408 void set_last_next_header(uint8_t value);
409 uint32_t calculate_headers_size()
const;
410 static void write_header(
const ext_header& header, Memory::OutputMemoryStream& stream);
411 static bool is_extension_header(uint8_t header_id);
412 static uint32_t get_padding_size(
const ext_header& header);
413 static std::vector<header_option_type> parse_header_options(
const uint8_t* data,
size_t size);
417 #if TINS_IS_BIG_ENDIAN
421 uint32_t payload_length:16,
425 uint8_t traffic_class:4,
427 uint8_t flow_label[3];
428 uint16_t payload_length;
432 uint8_t src_addr[16], dst_addr[16];
436 headers_type ext_headers_;
437 uint8_t next_header_;
Definition ipv6_address.h:45
address_type src_addr() const
Getter for the src_addr field.
Definition ipv6.h:242
uint16_t payload_length() const
Getter for the payload_length field.
Definition ipv6.h:218
IPv6Address address_type
Definition ipv6.h:64
PDUType pdu_type() const
Getter for the PDU's type.
Definition ipv6.h:339
uint8_t hop_limit() const
Getter for the hop_limit field.
Definition ipv6.h:234
address_type dst_addr() const
Getter for the dst_addr field.
Definition ipv6.h:250
uint8_t next_header() const
Getter for the next_header field.
Definition ipv6.h:226
std::pair< uint8_t, std::vector< uint8_t > > header_option_type
Definition ipv6.h:79
uint8_t traffic_class() const
Getter for the traffic_class field.
Definition ipv6.h:191
PDUOption< uint8_t, IPv6 > ext_header
Definition ipv6.h:69
small_uint< 20 > flow_label() const
Getter for the flow_label field.
Definition ipv6.h:204
ExtensionHeader
Definition ipv6.h:84
TINS_DEPRECATED(void add_ext_header(const ext_header &header))
const headers_type & headers() const
Getter for the IPv6 extension headers.
Definition ipv6.h:258
IPv6 * clone() const
Definition ipv6.h:331
std::vector< ext_header > headers_type
Definition ipv6.h:74
void add_header(ext_header &&header)
Definition ipv6.h:379
void add_header(Args &&... args)
Definition ipv6.h:389
OptionType
Definition ipv6.h:99
small_uint< 4 > version() const
Getter for the version field.
Definition ipv6.h:183
Abstraction of a network interface.
Definition network_interface.h:47
Represents a PDU option field.
Definition rsn_information.h:43
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Sends packets through a network interface.
Definition packet_sender.h:118
Represents a field of n bits.
Definition small_uint.h:52
The Tins namespace.
Definition address_range.h:38