- get_interface_by_address() added - HTTP server initials added - code added to strip away padding on processing the IP layer by shrinking overall packet size - load of TCP fixes and improvements - TCP stream interface added - TCP window destroy() added and some bugs fixed
126 lines
4.5 KiB
C
126 lines
4.5 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, struct EthInterface_ * intf);
|
|
|
|
#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;
|
|
|
|
// special processing function returns
|
|
#define PROC_FN_RET_OK (0) // OK, go ahead!
|
|
#define PROC_FN_RET_ABORT (1) // abort further processing
|
|
#define PROC_FN_RET_REPRST (2) // replace packet and restart packet processing
|
|
|
|
#define PROC_FN_FLAG_STRIP_PAD (1 << 16) // Remove padding from the end of the packet
|
|
|
|
#define MASK_PROC_FN_RET(a) ((a) & 0xFFFF)
|
|
#define MASK_PROC_FN_FLAGS(a) ((a) & 0xFFFF0000)
|
|
|
|
typedef struct {
|
|
void * p;
|
|
uint32_t u;
|
|
int32_t i;
|
|
bool8_t b;
|
|
} PcktProcFnPassbackData;
|
|
|
|
/**
|
|
* @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 one of the special processing function return values
|
|
*/
|
|
typedef int (*PcktProcFn)(const uint8_t *hdr, uint32_t size, struct PcktHeaderElement_ * pcktHdrLe, struct EthInterface_ * intf, PcktProcFnPassbackData * pb);
|
|
|
|
/**
|
|
* @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
|
|
// -------------------
|
|
uint16_t cacheSize; ///< Allocated cache size
|
|
uint8_t * cacheArea; ///< Allocated area for packet header (used as cache area when processing headers)
|
|
} 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
|
|
*/
|
|
PcktClassDesc *packreg_get_by_class(PcktRegistry *packReg, uint16_t ownClass, uint16_t containerClass);
|
|
|
|
|
|
|
|
#endif //ETHERLIB_PACKET_REGISTRY_H
|