EtherLib/packet_registry.h
Wiesner András 51696f7341 - MemoryPool allocation-deallocation bug fixed
- generic Queue implemented
- PacketRegistry allocation bug fixed
- TCP implementation initials
- ALIGN to type macros added
2023-01-17 08:19:29 +01:00

108 lines
3.8 KiB
C

#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 kept so by extending
* as well. (The size of the packet is divisible by 4.)
*/
//struct PcktClassDesc_;
struct EthInterface_;
struct PcktHeaderElement_;
/**
* @typedef void (*PcktHeaderInsertFn)(uint8_t * hdr, const struct PcktHeaderElement_ * pcktHdrLe)
* @brief Packet header insert function prototype.
* @param hdr buffer to insert header into
* @param pcktHdrLe linked list of packet headers
*/
typedef void (*PcktHeaderInsertFn)(uint8_t * hdr, const struct PcktHeaderElement_ * pcktHdrLe);
#define PcktPropsHeader \
PcktHeaderInsertFn hdrInsFn; /**< Header insert function pointer (used only on transmission) */ \
uint16_t propSize; /**< Size of this property object */ \
uint16_t headerSize; /**< Header size in bytes */ \
uint16_t containedPacketClass; /**< Class of contained packet. Zero if no packet contained. */ \
uint16_t ownPacketClass; /**< Our own packet class */ \
uint16_t accumulatedOffset; /** Accumulated offset from the beginning of the packet */ \
uint16_t bytesToEnd; /** Remaining bytes to the end of payload */ \
bool8_t validityOK; /**< Indicates that checksum is OK. */ \
typedef struct {
PcktPropsHeader
} PcktProps;
/**
* @typedef int (*PcktProcFn)(const uint8_t *pHdr, uint32_t size, uint8_t *pPcktProps);
* @brief Pckt processing function template.
* @param hdr: pointer to the packet header
* @param size: remaining packet size counted from pHdr
* @param props: pointer to existing structure to store
* packet properties to (e.g. source address, port etc.)
* @param intf associeated Ethernet interface
* @return packet class 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 *hdr, uint32_t size, struct PcktHeaderElement_ * pcktHdrLe, struct EthInterface_ * intf);
/**
* @struct PcktClassDesc
* Pckt class descriptor. Pckt parsers can be registered
* using PcktClassDesc assignments.
*/
typedef struct PcktClassDesc_ {
uint16_t class; ///< Type identification of the packet 'class' (unique!)
uint16_t containerClass; ///< Type of container packet packet (e.g.: IPv4 in case of UDP)
PcktProcFn procFun; ///< Pckt processing function
PcktHeaderInsertFn hdrInsFn; ///< Header insert function
uint16_t propertySize; ///< Size of property structure
} PcktClassDesc;
/**
* @struct PcktRegistry
* Packet registry sturcture.
*/
typedef struct {
PcktClassDesc *ents; ///< Packet registry entries
uint16_t entCnt; ///< Number of registry entries
uint16_t reservedCnt; ///< Buffer reservation in elements.
} PcktRegistry;
// ---------------------
/**
* Create new packet registry
*/
PcktRegistry *packreg_new();
/**
* Add new packet class. (e.g. UDP, IP...)
* @param classDesc Packet class descriptor
*/
void packreg_add_class(PcktRegistry *packReg, const PcktClassDesc *classDesc);
/**
* Get packet descriptor by own class and container class.
* @param packReg pointer to Packet Registry object
* @param ownClass packet's own class
* @param containerClass container packet's class (if 0, then search by container class is not considered)
* @return pointer to descriptor on success or NULL on failure
*/
const PcktClassDesc *packreg_get_by_class(const PcktRegistry *packReg, uint16_t ownClass, uint16_t containerClass);
#endif //ETHERLIB_PACKET_REGISTRY_H