#ifndef ETHERLIB_PACKET_REGISTRY_H #define ETHERLIB_PACKET_REGISTRY_H #include /** * 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.) */ struct PcktClassDesc_; #define PcktPropsHeader \ 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 */ \ 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.) * @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, PcktProps *props); /** * @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 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(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