From d64f05e8bf1277132b648bda2e1175ad8c1d2d5c Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 6 Feb 2017 21:48:00 +0100 Subject: ipcpd: Revise PCI manipulation in normal The pci function will store offsets to avoid having to recalculate them every time. TTL handling is removed from the fmgr, the TTL is automatically decreased when deserializing the PCI (or set to 1 if there is no TTL present so the PDU will be forwarded). The deserialisation function now takes a pointer to a struct pci as input to avoid memory allocation and release each time a PDU is processed. Some checks have been replaced with assert() and return values replaced with void where it makes sense. --- src/ipcpd/normal/fmgr.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'src/ipcpd/normal/fmgr.c') diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index 6b21cdbf..b79d20b4 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -129,13 +129,15 @@ void * fmgr_nm1_sdu_reader(void * o) { struct timespec timeout = {0, FD_UPDATE_TIMEOUT}; struct shm_du_buff * sdb; - struct pci * pci; + struct pci pci; int fd; int i = 0; int ret; (void) o; + memset(&pci, 0, sizeof(pci)); + while (true) { /* FIXME: replace with scheduling policy call */ i = (i + 1) % QOS_CUBE_MAX; @@ -157,30 +159,15 @@ void * fmgr_nm1_sdu_reader(void * o) continue; } - pci = shm_pci_des(sdb); - if (pci == NULL) { - LOG_ERR("Failed to get PCI."); - ipcp_flow_del(sdb); - continue; - } + shm_pci_des(sdb, &pci); - if (pci->dst_addr != ipcpi.address) { + if (pci.dst_addr != ipcpi.address) { LOG_DBG("PDU needs to be forwarded."); - if (pci->has_ttl) { - if (pci->ttl == 0) { - LOG_DBG("TTL was zero."); - ipcp_flow_del(sdb); - free(pci); - continue; - } - - if (shm_pci_dec_ttl(sdb)) { - LOG_ERR("Failed to dec TTL."); - ipcp_flow_del(sdb); - free(pci); - continue; - } + if (pci.ttl == 0) { + LOG_DBG("TTL was zero."); + ipcp_flow_del(sdb); + continue; } /* @@ -188,21 +175,14 @@ void * fmgr_nm1_sdu_reader(void * o) * we don't have a PFF yet */ ipcp_flow_del(sdb); - free(pci); continue; } - if (shm_pci_shrink(sdb)) { - LOG_ERR("Failed to shrink PDU."); - ipcp_flow_del(sdb); - free(pci); - continue; - } + shm_pci_shrink(sdb); - if (frct_nm1_post_sdu(pci, sdb)) { + if (frct_nm1_post_sdu(&pci, sdb)) { LOG_ERR("Failed to hand PDU to FRCT."); ipcp_flow_del(sdb); - free(pci); continue; } } -- cgit v1.2.3