packet header processing cache added
This commit is contained in:
parent
57d41a823f
commit
30af96f4c9
@ -33,11 +33,15 @@ void packreg_add_class(PcktRegistry * packReg, const PcktClassDesc * classDesc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append new item
|
// append new item
|
||||||
packReg->ents[packReg->entCnt] = *classDesc;
|
PcktClassDesc * newEntry = packReg->ents + packReg->entCnt;
|
||||||
|
*newEntry = *classDesc;
|
||||||
|
newEntry->cacheSize = 0; // initialize cache
|
||||||
|
newEntry->cacheArea = NULL;
|
||||||
|
|
||||||
packReg->entCnt++;
|
packReg->entCnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PcktClassDesc * packreg_get_by_class(const PcktRegistry * packReg, uint16_t ownClass, uint16_t containerClass) {
|
PcktClassDesc * packreg_get_by_class(const PcktRegistry * packReg, uint16_t ownClass, uint16_t containerClass) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for (i = 0; i < packReg->entCnt; i++) {
|
for (i = 0; i < packReg->entCnt; i++) {
|
||||||
const PcktClassDesc * cdesc = packReg->ents + i;
|
const PcktClassDesc * cdesc = packReg->ents + i;
|
||||||
|
@ -78,6 +78,9 @@ typedef struct PcktClassDesc_ {
|
|||||||
PcktProcFn procFun; ///< Pckt processing function
|
PcktProcFn procFun; ///< Pckt processing function
|
||||||
PcktHeaderInsertFn hdrInsFn; ///< Header insert function
|
PcktHeaderInsertFn hdrInsFn; ///< Header insert function
|
||||||
uint16_t propertySize; ///< Size of property structure
|
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;
|
} PcktClassDesc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +113,7 @@ void packreg_add_class(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);
|
PcktClassDesc *packreg_get_by_class(const PcktRegistry *packReg, uint16_t ownClass, uint16_t containerClass);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,14 +39,26 @@ void packsieve_input(PcktSieve *sieve, const RawPckt *rawPckt) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
// get packet descriptor
|
// get packet descriptor
|
||||||
const PcktClassDesc *cdesc = packreg_get_by_class(E.pcktReg, ownClass, containerClass);
|
PcktClassDesc *cdesc = packreg_get_by_class(E.pcktReg, ownClass, containerClass);
|
||||||
if (cdesc == NULL) {
|
if (cdesc == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate property object
|
// allocate property object
|
||||||
uint32_t hdrSize = ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE + cdesc->propertySize;
|
uint32_t hdrSize = ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE + cdesc->propertySize;
|
||||||
PcktHeaderElement *header = (PcktHeaderElement *) dynmem_alloc(hdrSize);
|
// look for possible former allocated cache area
|
||||||
|
PcktHeaderElement *header = NULL;
|
||||||
|
if (cdesc->cacheSize <= hdrSize) { // allocate cache area
|
||||||
|
if (cdesc->cacheArea != NULL) {
|
||||||
|
dynmem_free(cdesc->cacheArea);
|
||||||
|
}
|
||||||
|
cdesc->cacheArea = (uint8_t *)dynmem_alloc(hdrSize);
|
||||||
|
ASSERT_NULL(cdesc->cacheArea);
|
||||||
|
cdesc->cacheSize = hdrSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
header = (PcktHeaderElement *)cdesc->cacheArea;
|
||||||
|
|
||||||
memset(header, 0, hdrSize);
|
memset(header, 0, hdrSize);
|
||||||
header->props.ownPacketClass = ownClass;
|
header->props.ownPacketClass = ownClass;
|
||||||
header->props.propSize = cdesc->propertySize;
|
header->props.propSize = cdesc->propertySize;
|
||||||
@ -147,12 +159,12 @@ void packsieve_input(PcktSieve *sieve, const RawPckt *rawPckt) {
|
|||||||
|
|
||||||
// release header chain blocks
|
// release header chain blocks
|
||||||
header_release:; // empty line, solely for label placement
|
header_release:; // empty line, solely for label placement
|
||||||
PcktHeaderElement *iter = outermostHeader;
|
// PcktHeaderElement *iter = outermostHeader;
|
||||||
while (iter != NULL) {
|
// while (iter != NULL) {
|
||||||
PcktHeaderElement *next = iter->next;
|
// PcktHeaderElement *next = iter->next;
|
||||||
dynmem_free(iter);
|
// dynmem_free(iter);
|
||||||
iter = next;
|
// iter = next;
|
||||||
}
|
// }
|
||||||
if (procRet == PROC_FN_RET_REPRST) { // if a restart was requested, then run everything again!
|
if (procRet == PROC_FN_RET_REPRST) { // if a restart was requested, then run everything again!
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user