1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-22 18:25:57 +01:00

Add parsing of well known IPv6 extension headers (#287)

* Add parsing of well known IPv6 extension headers

Add classes for IPv6 extension headers defined in the IPv6 protocol
specification (RFC 2460) as well as functions for creating them from
the IPv6 class' ext_header type.

The currently known extension headers are Hop-By-Hop Option,
Destination Routing, Routing and Fragment.

* Cleanup after PR #287 comments

Pull in stuff from the std namespace with "using" instead of
qualifying with std::.

Keep starting braces on the same line.

Avoid potential copy when appending to vector.
This commit is contained in:
Kasper Laudrup
2018-03-29 06:05:01 +02:00
committed by Matias Fontanini
parent 342e2c77a7
commit fa79582b89
4 changed files with 180 additions and 0 deletions

View File

@@ -204,6 +204,15 @@ public:
option_payload_too_large() : exception_base("Option payload too large") { }
};
/**
* \brief Exception thrown when an IPv6 extension header is being
* created from invalid data
*/
class invalid_ipv6_extension_header : public exception_base {
public:
invalid_ipv6_extension_header() : exception_base("Invalid IPv6 extension header") { }
};
/**
* \brief Generic pcap error
*/

View File

@@ -73,6 +73,11 @@ public:
*/
typedef std::vector<ext_header> headers_type;
/**
* The type used to store an extension header option.
*/
typedef std::pair<uint8_t, std::vector<uint8_t> > header_option_type;
/**
* The values used to identify extension headers.
*/
@@ -105,6 +110,46 @@ public:
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/*
* \brief The type used to store Hop-By-Hop Extension Headers
*/
struct hop_by_hop_header {
std::vector<header_option_type> options;
static hop_by_hop_header from_extension_header(const ext_header& hdr);
};
/*
* \brief The type used to store Destination Routing Extension Headers
*/
struct destination_routing_header {
std::vector<header_option_type> options;
static destination_routing_header from_extension_header(const ext_header& hdr);
};
/**
* \brief The type used to store Routing Extension headers
*/
struct routing_header {
uint8_t routing_type;
uint8_t segments_left;
std::vector<uint8_t> data;
static routing_header from_extension_header(const ext_header& hdr);
};
/**
* \brief The type used to store Fragment Extension headers
*/
struct fragment_header {
uint16_t fragment_offset;
bool more_fragments;
uint32_t identification;
static fragment_header from_extension_header(const ext_header& hdr);
};
/**
* \brief Constructs an IPv6 object.
*
@@ -365,6 +410,7 @@ private:
static void write_header(const ext_header& header, Memory::OutputMemoryStream& stream);
static bool is_extension_header(uint8_t header_id);
static uint32_t get_padding_size(const ext_header& header);
static std::vector<header_option_type> parse_header_options(const uint8_t* data, size_t size);
TINS_BEGIN_PACK
struct ipv6_header {