Skip to content

Commit

Permalink
Reformat all files in the repository
Browse files Browse the repository at this point in the history
In this commit, we perform a comprehensive code reformatting across the entire repository. The goal is to ensure consistent and uniform code formatting for all files.

The reformatting process covers all `.cpp` and `.hpp` files. By applying these formatting changes, we aim to improve code readability, maintainability, and overall code quality.
  • Loading branch information
SiskaPavel committed Oct 24, 2023
1 parent c60c919 commit c73b4dc
Show file tree
Hide file tree
Showing 121 changed files with 17,433 additions and 16,440 deletions.
330 changes: 158 additions & 172 deletions include/ipfixprobe/flowifc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
#include <sys/time.h>

#ifdef WITH_NEMEA
#include <unirec/unirec.h>
#include "fields.h"
#include <unirec/unirec.h>
#else
#define UR_FIELDS(...)
#endif

#include <arpa/inet.h>
#include "ipaddr.hpp"
#include <arpa/inet.h>

namespace ipxp {

Expand All @@ -60,215 +60,201 @@ int get_extension_cnt();
* \brief Flow record extension base struct.
*/
struct RecordExt {
RecordExt *m_next; /**< Pointer to next extension */
int m_ext_id; /**< Identifier of extension. */
RecordExt* m_next; /**< Pointer to next extension */
int m_ext_id; /**< Identifier of extension. */

/**
* \brief Constructor.
* \param [in] id ID of extension.
*/
RecordExt(int id) : m_next(nullptr), m_ext_id(id)
{
}
/**
* \brief Constructor.
* \param [in] id ID of extension.
*/
RecordExt(int id)
: m_next(nullptr)
, m_ext_id(id)
{
}

#ifdef WITH_NEMEA
/**
* \brief Fill unirec record with stored extension data.
* \param [in] tmplt Unirec template.
* \param [out] record Pointer to the unirec record.
*/
virtual void fill_unirec(ur_template_t *tmplt, void *record)
{
}
/**
* \brief Fill unirec record with stored extension data.
* \param [in] tmplt Unirec template.
* \param [out] record Pointer to the unirec record.
*/
virtual void fill_unirec(ur_template_t* tmplt, void* record) {}

/**
* \brief Get unirec template string.
* \return Unirec template string.
*/
virtual const char *get_unirec_tmplt() const
{
return "";
}
/**
* \brief Get unirec template string.
* \return Unirec template string.
*/
virtual const char* get_unirec_tmplt() const { return ""; }
#endif

/**
* \brief Fill IPFIX record with stored extension data.
* \param [out] buffer IPFIX template record buffer.
* \param [in] size IPFIX template record buffer size.
* \return Number of bytes written to buffer or -1 if data cannot be written.
*/
virtual int fill_ipfix(uint8_t *buffer, int size)
{
return 0;
}
/**
* \brief Fill IPFIX record with stored extension data.
* \param [out] buffer IPFIX template record buffer.
* \param [in] size IPFIX template record buffer size.
* \return Number of bytes written to buffer or -1 if data cannot be written.
*/
virtual int fill_ipfix(uint8_t* buffer, int size) { return 0; }

/**
* \brief Get ipfix string fields.
* \return Return ipfix fields array.
*/
virtual const char **get_ipfix_tmplt() const
{
return nullptr;
}
/**
* \brief Get ipfix string fields.
* \return Return ipfix fields array.
*/
virtual const char** get_ipfix_tmplt() const { return nullptr; }

/**
* \brief Get text representation of exported elements
* \return Return fields converted to text
*/
virtual std::string get_text() const
{
return "";
}
/**
* \brief Get text representation of exported elements
* \return Return fields converted to text
*/
virtual std::string get_text() const { return ""; }

/**
* \brief Add extension at the end of linked list.
* \param [in] ext Extension to add.
*/
void add_extension(RecordExt *ext)
{
RecordExt **tmp = &m_next;
while (*tmp) {
tmp = &(*tmp)->m_next;
}
*tmp = ext;
}
/**
* \brief Add extension at the end of linked list.
* \param [in] ext Extension to add.
*/
void add_extension(RecordExt* ext)
{
RecordExt** tmp = &m_next;
while (*tmp) {
tmp = &(*tmp)->m_next;
}
*tmp = ext;
}

/**
* \brief Virtual destructor.
*/
virtual ~RecordExt()
{
if (m_next != nullptr) {
delete m_next;
}
}
/**
* \brief Virtual destructor.
*/
virtual ~RecordExt()
{
if (m_next != nullptr) {
delete m_next;
}
}
};

struct Record {
RecordExt *m_exts; /**< Extension headers. */
RecordExt* m_exts; /**< Extension headers. */

/**
* \brief Add new extension header.
* \param [in] ext Pointer to the extension header.
*/
void add_extension(RecordExt* ext)
{
if (m_exts == nullptr) {
m_exts = ext;
} else {
RecordExt *ext_ptr = m_exts;
while (ext_ptr->m_next != nullptr) {
ext_ptr = ext_ptr->m_next;
}
ext_ptr->m_next = ext;
}
}
/**
* \brief Add new extension header.
* \param [in] ext Pointer to the extension header.
*/
void add_extension(RecordExt* ext)
{
if (m_exts == nullptr) {
m_exts = ext;
} else {
RecordExt* ext_ptr = m_exts;
while (ext_ptr->m_next != nullptr) {
ext_ptr = ext_ptr->m_next;
}
ext_ptr->m_next = ext;
}
}

/**
* \brief Get given extension.
* \param [in] id Type of extension.
* \return Pointer to the requested extension or nullptr if extension is not present.
*/
RecordExt *get_extension(int id) const
{
RecordExt *ext = m_exts;
while (ext != nullptr) {
if (ext->m_ext_id == id) {
return ext;
}
ext = ext->m_next;
}
return nullptr;
}
/**
* \brief Get given extension.
* \param [in] id Type of extension.
* \return Pointer to the requested extension or nullptr if extension is not present.
*/
RecordExt* get_extension(int id) const
{
RecordExt* ext = m_exts;
while (ext != nullptr) {
if (ext->m_ext_id == id) {
return ext;
}
ext = ext->m_next;
}
return nullptr;
}
/**
* \brief Remove given extension.
* \param [in] id Type of extension.
* \return True when successfully removed
*/
bool remove_extension(int id)
{
RecordExt *ext = m_exts;
RecordExt *prev_ext = nullptr;
RecordExt* ext = m_exts;
RecordExt* prev_ext = nullptr;

while (ext != nullptr) {
if (ext->m_ext_id == id) {
if (prev_ext == nullptr) { // at beginning
m_exts = ext->m_next;
} else if (ext->m_next == nullptr) { // at end
prev_ext->m_next = nullptr;
} else { // in middle
prev_ext->m_next = ext->m_next;
}
ext->m_next = nullptr;
delete ext;
return true;
}
prev_ext = ext;
ext = ext->m_next;
}
return false;
while (ext != nullptr) {
if (ext->m_ext_id == id) {
if (prev_ext == nullptr) { // at beginning
m_exts = ext->m_next;
} else if (ext->m_next == nullptr) { // at end
prev_ext->m_next = nullptr;
} else { // in middle
prev_ext->m_next = ext->m_next;
}
ext->m_next = nullptr;
delete ext;
return true;
}
prev_ext = ext;
ext = ext->m_next;
}
return false;
}

/**
* \brief Remove extension headers.
*/
void remove_extensions()
{
if (m_exts != nullptr) {
delete m_exts;
m_exts = nullptr;
}
}
/**
* \brief Remove extension headers.
*/
void remove_extensions()
{
if (m_exts != nullptr) {
delete m_exts;
m_exts = nullptr;
}
}

/**
* \brief Constructor.
*/
Record() : m_exts(nullptr)
{
}
/**
* \brief Constructor.
*/
Record()
: m_exts(nullptr)
{
}

/**
* \brief Destructor.
*/
virtual ~Record()
{
remove_extensions();
}
/**
* \brief Destructor.
*/
virtual ~Record() { remove_extensions(); }
};

#define FLOW_END_INACTIVE 0x01
#define FLOW_END_ACTIVE 0x02
#define FLOW_END_EOF 0x03
#define FLOW_END_FORCED 0x04
#define FLOW_END_NO_RES 0x05
#define FLOW_END_ACTIVE 0x02
#define FLOW_END_EOF 0x03
#define FLOW_END_FORCED 0x04
#define FLOW_END_NO_RES 0x05

/**
* \brief Flow record struct constaining basic flow record data and extension headers.
*/
struct Flow : public Record {
uint64_t flow_hash;
uint64_t flow_hash;

struct timeval time_first;
struct timeval time_last;
uint64_t src_bytes;
uint64_t dst_bytes;
uint32_t src_packets;
uint32_t dst_packets;
uint8_t src_tcp_flags;
uint8_t dst_tcp_flags;
struct timeval time_first;
struct timeval time_last;
uint64_t src_bytes;
uint64_t dst_bytes;
uint32_t src_packets;
uint32_t dst_packets;
uint8_t src_tcp_flags;
uint8_t dst_tcp_flags;

uint8_t ip_version;
uint8_t ip_version;

uint8_t ip_proto;
uint16_t src_port;
uint16_t dst_port;
ipaddr_t src_ip;
ipaddr_t dst_ip;
uint8_t ip_proto;
uint16_t src_port;
uint16_t dst_port;
ipaddr_t src_ip;
ipaddr_t dst_ip;

uint8_t src_mac[6];
uint8_t dst_mac[6];
uint8_t end_reason;
uint8_t src_mac[6];
uint8_t dst_mac[6];
uint8_t end_reason;
};

}
} // namespace ipxp
#endif /* IPXP_FLOWIFC_HPP */
Loading

0 comments on commit c73b4dc

Please sign in to comment.