Packet header linked list initially implemented

This commit is contained in:
Wiesner András 2022-11-04 07:54:57 +01:00
parent 0f3c8ca601
commit 49fa57b63e
2 changed files with 30 additions and 12 deletions

View File

@ -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

View File

@ -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