This commit is contained in:
Wiesner András 2022-10-27 21:03:58 +02:00
commit 1d80cebbce
9 changed files with 2830 additions and 0 deletions

2662
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

5
common_types.c Normal file
View File

@ -0,0 +1,5 @@
//
// Created by epagris on 2022.10.17..
//
#include "common_types.h"

31
common_types.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef ETHERLIB_COMMON_TYPES_H
#define ETHERLIB_COMMON_TYPES_H
#include <stdint.h>
/**
* \struct RawPckt
* \brief Raw packet received on wire
*/
typedef struct {
uint8_t * payload; ///> Pointer to raw packet payload.
uint32_t size; ///> Raw packet size.
} RawPckt;
/**
* \struct Pckt
* \brief Generic packet
*
* Fields have been reordered so that fields are aligned.
*/
typedef struct {
uint64_t time_s; ///< Timestamp seconds part.
uint32_t time_ns; ///< Timestamp nanoseconds part.
uint8_t * header; ///< Pointer to packet header. Points to the outmost header (e.g. Ethernet-header in case of a UDP-packet)
uint8_t * payload; ///< Pointer to (innermost) payload.
uint16_t headerSize; ///< Packet header size in bytes.
uint16_t payloadSize; ///< Payload size in bytes.
uint16_t type; ///< Packet type indicator (e.g. UDP, TCP, IPv4 etc.)
} Pckt;
#endif //ETHERLIB_COMMON_TYPES_H

5
memory_pool.c Normal file
View File

@ -0,0 +1,5 @@
//
// Created by epagris on 2022.10.20..
//
#include "memory_pool.h"

60
memory_pool.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef ETHERLIB_MEMORY_POOL_H
#define ETHERLIB_MEMORY_POOL_H
#include <etherlib_options.h>
#include <stdint.h>
/**
* Memory pool state structure.
*/
typedef struct {
uint8_t * p; ///< Pointer to contiguous memory block the pool operates on.
uint32_t totalSize; ///< Total size of the memory pool.
uint32_t blockSize; ///< Single block size.
uint8_t * blockRegistry; ///< Bitfield array in which block allocations are maintained.
uint32_t totalBlocks; ///< Total number of blocks.
uint32_t freeBlocks; ///< Number of free blocks.
} MemoryPool;
/**
* Header inserted at the beginning of each block when allocated. Blocks can
* be forward-chained with this structure used as singly-linked list elements.
*/
typedef struct MemoryPoolBlockHeader_ {
struct MemoryPoolBlockHeader_ * next; ///< Next block in the chain. Zero if chain's last block.
uint8_t * block; ///< Pointer to the data block.
} MemoryPoolBlockHeader;
/**
* Block chain header placed after the first memory block's header.
* Contains fast-accessable information about the full chain.
*/
typedef struct MemoryPoolBlockChainHead_ {
uint32_t totalChainSize; ///< Total memory size allocated in the full chain.
uint16_t chainCntr; ///< Number of chain elements linked together.
uint16_t _spaceholder;
} MemoryPoolBlockChainHead;
/**
* Initialize a new memory pool. MemoryPool object is allocated at the beginning of the given
* area (p).
* @param p memory block the pool is based on
* @param blockSize allocation block size
* @param blockCnt number of available blocks
* @return Pointer to the MemoryPool object handling the newly allocated memory pool, or NULL
* on failure.
*/
MemoryPool * mp_init(uint8_t * p, uint32_t blockSize, uint32_t blockCnt);
/**
* Allocate a memory block chain from memory pool.
* @param mp memory pool the allocation is made from
* @param size requested memory size
* @return pointer to head of allocated memory block chain or NULL on failure
*/
MemoryPoolBlockHeader * mp_alloc(MemoryPool * mp, uint32_t size);
void mp_free(MemoryPool * mp, MemoryPoolBlockHeader )
#endif //ETHERLIB_MEMORY_POOL_H

5
packet_input.c Normal file
View File

@ -0,0 +1,5 @@
//
// Created by epagris on 2022.10.20..
//
#include "packet_input.h"

6
packet_input.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef ETHERLIB_PACKET_INPUT_H
#define ETHERLIB_PACKET_INPUT_H
void input_packet()
#endif //ETHERLIB_PACKET_INPUT_H

5
packet_registry.c Normal file
View File

@ -0,0 +1,5 @@
//
// Created by epagris on 2022.10.18..
//
#include "packet_registry.h"

51
packet_registry.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef ETHERLIB_PACKET_REGISTRY_H
#define ETHERLIB_PACKET_REGISTRY_H
#include <stdint.h>
/**
* Boolean on 8-bits, not full machine-word size.
*/
typedef uint8_t bool8_t;
/**
* \typedef PcktProps
* \brief Packet properties
*
* Every packet property structure must extend this base structure,
* so that, must begin with fields defined here. PcktProps is guaranteed
* to be aligned to 32-bit boundary and so must be guaranteed by extending
* as well. (The size of the packet is divisible by 4.)
*/
typedef struct {
uint16_t headerSize; ///< Header size in bytes
uint16_t containedPacketID; ///< ID of contained packet. Zero if no packet contained.
bool8_t checksumOK; ///< Indicates that checksum is OK.
} PcktProps;
/**
* @typedef int (*PcktProcFn)(const uint8_t *pHdr, uint32_t size, uint8_t *pPcktProps);
* @brief Pckt processing function template.
* @param pHdr: pointer to the packet header
* @param size: remaining packet size counted from pHdr
* @param pPcktProps: pointer to existing structure to store
* packet properties to (e.g. source address, port etc.)
* @return packet type of contained packet, or -1 on failure or
* 0 if no more standard packet contained (e.g. UDP packet contains
* user data)
*/
typedef int (*PcktProcFn)(const uint8_t *pHdr, uint32_t size, uint8_t *pProps);
/**
* @struct PcktTypeDesc
* Pckt type descriptor. Pckt parsers can be registered
* using PcktTypeDesc assignments.
*
*/
typedef struct {
uint16_t type; ///< Type identification the packet (unique!)
uint16_t containerType; ///< Type of container packet packet (e.g.: IPv4 in case of UDP)
PcktProcFn procFun; ///< Pckt processing function
} PcktTypeDesc;
#endif //ETHERLIB_PACKET_REGISTRY_H