1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Add extract_metadata to main PDU classes

This commit is contained in:
Matias Fontanini
2016-02-20 22:19:12 -08:00
parent dae25b3381
commit 17da10d76e
32 changed files with 318 additions and 12 deletions

View File

@@ -72,6 +72,14 @@ public:
REPLY = 0x0002
};
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Constructs an ARP object using the provided addresses.
*

View File

@@ -333,7 +333,7 @@ protected:
vend_type& vend() { return vend_; }
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
private:
/**
* Struct that represents the Bootp datagram.
*/
@@ -355,6 +355,7 @@ private:
uint8_t file[128];
} TINS_END_PACK;
private:
bootp_header bootp_;
vend_type vend_;
};

View File

@@ -172,6 +172,14 @@ public:
*/
typedef std::list<option> options_type;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Creates an instance of DHCP.
*

View File

@@ -412,6 +412,14 @@ public:
*/
typedef std::vector<uint8_t> interface_id_type;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* Default constructor.
*/

View File

@@ -589,6 +589,14 @@ public:
typedef IPv4Address address_type;
typedef IPv6Address address_v6_type;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Default constructor.
*

View File

@@ -48,6 +48,14 @@ public:
*/
static const PDU::PDUType pdu_flag = PDU::DOT1Q;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* Default constructor
*/
@@ -192,7 +200,7 @@ private:
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
TINS_BEGIN_PACK
struct dot1q_hdr {
struct dot1q_header {
#if TINS_IS_BIG_ENDIAN
uint16_t priority:3,
cfi:1,
@@ -207,9 +215,9 @@ private:
#endif
} TINS_END_PACK;
static uint16_t get_id(const dot1q_hdr* hdr);
static uint16_t get_id(const dot1q_header* hdr);
dot1q_hdr header_;
dot1q_header header_;
bool append_padding_;
};
}

View File

@@ -60,6 +60,14 @@ public:
*/
static const address_type BROADCAST;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Constructor for creating an Dot3 PDU
*
@@ -71,7 +79,7 @@ public:
* \param child The PDU which will be set as the inner PDU.
*/
Dot3(const address_type& dst_hw_addr = address_type(),
const address_type& src_hw_addr = address_type());
const address_type& src_hw_addr = address_type());
/**
* \brief Constructs a Dot3 object from a buffer and adds a

View File

@@ -69,6 +69,14 @@ public:
EAPOL_WPA = 254
};
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Static method to instantiate the correct EAPOL subclass
* based on a raw buffer.

View File

@@ -60,6 +60,14 @@ public:
*/
static const address_type BROADCAST;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Constructs an ethernet II PDU.
*

View File

@@ -92,6 +92,14 @@ public:
ADDRESS_MASK_REPLY = 18
};
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Creates an instance of ICMP.
*

View File

@@ -128,7 +128,9 @@ PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer,
PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size);
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag);
Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag);
PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag);
uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment);
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream,

View File

@@ -246,6 +246,14 @@ public:
*/
typedef std::list<option> options_type;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Constructor for building the IP PDU.
*

View File

@@ -89,6 +89,14 @@ public:
NO_NEXT_HEADER = 59
};
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Constructs an IPv6 object.
*

View File

@@ -179,6 +179,7 @@ public:
IPSEC_ESP,
PKTAP,
MPLS,
UNKNOWN = 999,
USER_DEFINED_PDU = 1000
};
@@ -188,6 +189,37 @@ public:
*/
static const endian_type endianness = BE;
/**
* \brief Type used to store a PDU header's data.
*/
struct metadata {
/**
* \brief Default constructor
*/
metadata();
/**
* \brief Constructs an instance of metadata using the given values
*/
metadata(uint32_t header_size, PDUType current_type, PDUType next_type);
/**
* The total header size for the current protocol
*/
uint32_t header_size;
/**
* The current PDU type
*/
PDUType current_pdu_type;
/**
* The next PDU type
*/
PDUType next_pdu_type;
};
/**
* \brief Default constructor.
*/

View File

@@ -139,6 +139,14 @@ public:
*/
typedef std::vector<uint32_t> sack_type;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief TCP constructor.
*

View File

@@ -74,5 +74,6 @@
#include "ipsec.h"
#include "ip_reassembler.h"
#include "ppi.h"
#include "packet_view.h"
#endif // TINS_TINS_H

View File

@@ -67,6 +67,14 @@ public:
*/
static const PDU::PDUType pdu_flag = PDU::UDP;
/**
* \brief Extracts metadata for this protocol based on the buffer provided
*
* \param buffer Pointer to a buffer
* \param total_sz Size of the buffer pointed by buffer
*/
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief UDP constructor.
*