Packet header linked list initially implemented
This commit is contained in:
parent
0f3c8ca601
commit
49fa57b63e
@ -36,10 +36,17 @@ void ethlib_init() {
|
|||||||
register_packet_parsers(); // register packet parsers
|
register_packet_parsers(); // register packet parsers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct PcktHeaderElement_ {
|
||||||
|
struct PcktHeaderElement_ * next, * prev; ///< Next and previous header in the linked list
|
||||||
|
PcktProps props; ///< Properties (allocated to appropriate size)
|
||||||
|
} PcktHeaderElement;
|
||||||
|
|
||||||
|
#define ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE (2 * sizeof(PcktHeaderElement *))
|
||||||
|
|
||||||
void process_raw_packet(const uint8_t * data, uint32_t size) {
|
void process_raw_packet(const uint8_t * data, uint32_t size) {
|
||||||
uint16_t ownClass = 0, containerClass = 0; // Ethernet...
|
uint16_t ownClass = 0, containerClass = 0; // Ethernet...
|
||||||
uint16_t offset = 0;
|
uint16_t offset = 0;
|
||||||
PcktProps * props = NULL;
|
PcktHeaderElement * lastHeader = NULL;
|
||||||
do {
|
do {
|
||||||
// get packet descriptor
|
// get packet descriptor
|
||||||
const PcktClassDesc * cdesc = packreg_get_by_class(E.pcktReg, ownClass, containerClass);
|
const PcktClassDesc * cdesc = packreg_get_by_class(E.pcktReg, ownClass, containerClass);
|
||||||
@ -48,17 +55,24 @@ void process_raw_packet(const uint8_t * data, uint32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allocate property object
|
// allocate property object
|
||||||
props = (PcktProps *) dynmem_alloc(cdesc->propertySize);
|
PcktHeaderElement * header = (PcktHeaderElement *) dynmem_alloc(ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE + cdesc->propertySize);
|
||||||
|
header->props.ownPacketClass = ownClass;
|
||||||
|
header->props.propSize = cdesc->propertySize;
|
||||||
|
header->prev = lastHeader;
|
||||||
|
if (lastHeader) {
|
||||||
|
lastHeader->next = header;
|
||||||
|
}
|
||||||
|
|
||||||
// call parsing function
|
// call parsing function
|
||||||
cdesc->procFun(data + offset, size - offset, props);
|
cdesc->procFun(data + offset, size - offset, &header->props);
|
||||||
uint16_t containedClass = props->containedPacketClass;
|
uint16_t containedClass = header->props.containedPacketClass;
|
||||||
if (containedClass != 0) {
|
if (containedClass != 0) {
|
||||||
containerClass = ownClass;
|
containerClass = ownClass;
|
||||||
offset += props->headerSize;
|
offset += header->props.headerSize;
|
||||||
dynmem_free(props);
|
//dynmem_free(props);
|
||||||
}
|
}
|
||||||
ownClass = containedClass;
|
ownClass = containedClass;
|
||||||
|
lastHeader = header;
|
||||||
} while (ownClass != 0);
|
} while (ownClass != 0);
|
||||||
|
|
||||||
// TODO process innermost packet
|
// TODO process innermost packet
|
||||||
|
@ -18,9 +18,13 @@ typedef uint8_t bool8_t;
|
|||||||
* as well. (The size of the packet is divisible by 4.)
|
* as well. (The size of the packet is divisible by 4.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct PcktClassDesc_;
|
||||||
|
|
||||||
#define PcktPropsHeader \
|
#define PcktPropsHeader \
|
||||||
|
uint16_t propSize; /* Size of this property object */ \
|
||||||
uint16_t headerSize; /*< Header size in bytes */ \
|
uint16_t headerSize; /*< Header size in bytes */ \
|
||||||
uint16_t containedPacketClass; /*< ID of contained packet. Zero if no packet contained. */ \
|
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. */ \
|
bool8_t validityOK; /*< Indicates that checksum is OK. */ \
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ typedef int (*PcktProcFn)(const uint8_t *hdr, uint32_t size, PcktProps *props);
|
|||||||
* Pckt class descriptor. Pckt parsers can be registered
|
* Pckt class descriptor. Pckt parsers can be registered
|
||||||
* using PcktClassDesc assignments.
|
* using PcktClassDesc assignments.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct PcktClassDesc_ {
|
||||||
uint16_t class; ///< Type identification of the packet 'class' (unique!)
|
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)
|
uint16_t containerClass; ///< Type of container packet packet (e.g.: IPv4 in case of UDP)
|
||||||
PcktProcFn procFun; ///< Pckt processing function
|
PcktProcFn procFun; ///< Pckt processing function
|
||||||
@ -58,7 +62,7 @@ typedef struct {
|
|||||||
* Packet registry sturcture.
|
* Packet registry sturcture.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PcktClassDesc * ents; ///< Packet registry entries
|
PcktClassDesc *ents; ///< Packet registry entries
|
||||||
uint16_t entCnt; ///< Number of registry entries
|
uint16_t entCnt; ///< Number of registry entries
|
||||||
uint16_t reservedCnt; ///< Buffer reservation in elements.
|
uint16_t reservedCnt; ///< Buffer reservation in elements.
|
||||||
} PcktRegistry;
|
} PcktRegistry;
|
||||||
@ -68,13 +72,13 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Create new packet registry
|
* Create new packet registry
|
||||||
*/
|
*/
|
||||||
PcktRegistry * packreg_new();
|
PcktRegistry *packreg_new();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new packet class. (e.g. UDP, IP...)
|
* Add new packet class. (e.g. UDP, IP...)
|
||||||
* @param classDesc Packet class descriptor
|
* @param classDesc Packet class descriptor
|
||||||
*/
|
*/
|
||||||
void packreg_add(PcktRegistry * packReg, const PcktClassDesc * classDesc);
|
void packreg_add(PcktRegistry *packReg, const PcktClassDesc *classDesc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get packet descriptor by own class and container class.
|
* Get packet descriptor by own class and container class.
|
||||||
@ -83,6 +87,6 @@ void packreg_add(PcktRegistry * packReg, const PcktClassDesc * classDesc);
|
|||||||
* @param containerClass container packet's class (if 0, then search by container class is not considered)
|
* @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
|
* @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);
|
const PcktClassDesc *packreg_get_by_class(const PcktRegistry *packReg, uint16_t ownClass, uint16_t containerClass);
|
||||||
|
|
||||||
#endif //ETHERLIB_PACKET_REGISTRY_H
|
#endif //ETHERLIB_PACKET_REGISTRY_H
|
Loading…
x
Reference in New Issue
Block a user