diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-28 17:56:02 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-28 17:56:44 +0200 |
commit | 41b73370dba4105ae183babe8f89480e8c9d038a (patch) | |
tree | 50e15983363c163164362851d91c3b6f9511e408 | |
parent | 72e8f778024ece5c8025be4767ce89eae349f4b5 (diff) | |
download | ouroboros-41b73370dba4105ae183babe8f89480e8c9d038a.tar.gz ouroboros-41b73370dba4105ae183babe8f89480e8c9d038a.zip |
ipcpd: Fix some bugs for the normal split
-rw-r--r-- | src/ipcpd/normal/dt.c | 11 | ||||
-rw-r--r-- | src/ipcpd/normal/dt_pci.c | 14 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.c | 15 | ||||
-rw-r--r-- | src/ipcpd/normal/pff.c | 45 |
4 files changed, 46 insertions, 39 deletions
diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c index 361af6b4..0816ec10 100644 --- a/src/ipcpd/normal/dt.c +++ b/src/ipcpd/normal/dt.c @@ -98,18 +98,13 @@ static int sdu_handler(int fd, return 0; } - pff_lock(dt.pff[qc]); - fd = pff_nhop(dt.pff[qc], dt_pci.dst_addr); if (fd < 0) { - pff_unlock(dt.pff[qc]); log_err("No next hop for %" PRIu64, dt_pci.dst_addr); ipcp_sdb_release(sdb); return -1; } - pff_unlock(dt.pff[qc]); - if (ipcp_flow_write(fd, sdb)) { log_err("Failed to write SDU to fd %d.", fd); ipcp_sdb_release(sdb); @@ -136,7 +131,6 @@ static int sdu_handler(int fd, ipcp_sdb_release(sdb); return -1; } - } return 0; @@ -279,17 +273,12 @@ int dt_write_sdu(uint64_t dst_addr, assert(sdb); - pff_lock(dt.pff[qc]); - fd = pff_nhop(dt.pff[qc], dst_addr); if (fd < 0) { - pff_unlock(dt.pff[qc]); log_err("Could not get nhop for address %" PRIu64, dst_addr); return -1; } - pff_unlock(dt.pff[qc]); - dt_pci.dst_addr = dst_addr; dt_pci.qc = qc; dt_pci.pdu_type = pdu_type; diff --git a/src/ipcpd/normal/dt_pci.c b/src/ipcpd/normal/dt_pci.c index 0e596803..39dde46b 100644 --- a/src/ipcpd/normal/dt_pci.c +++ b/src/ipcpd/normal/dt_pci.c @@ -47,7 +47,7 @@ struct { /* offsets */ size_t qc_o; size_t ttl_o; - size_t pdu_type_o; + size_t type_o; } dt_pci_info; int dt_pci_init(void) @@ -66,12 +66,12 @@ int dt_pci_init(void) dt_pci_info.qc_o = dt_pci_info.dtc.addr_size; dt_pci_info.ttl_o = dt_pci_info.qc_o + QC_SIZE; - - dt_pci_info.head_size = dt_pci_info.ttl_o + PDU_TYPE_SIZE; - if (dt_pci_info.dtc.has_ttl) - dt_pci_info.head_size += TTL_SIZE; + dt_pci_info.type_o = dt_pci_info.ttl_o + TTL_SIZE; + else + dt_pci_info.type_o = dt_pci_info.ttl_o; + dt_pci_info.head_size = dt_pci_info.type_o + PDU_TYPE_SIZE; dt_pci_info.tail_size = dt_pci_info.dtc.has_chk ? CHK_SIZE : 0; return 0; @@ -100,7 +100,7 @@ int dt_pci_ser(struct shm_du_buff * sdb, memcpy(head + dt_pci_info.qc_o, &dt_pci->qc, QC_SIZE); if (dt_pci_info.dtc.has_ttl) memcpy(head + dt_pci_info.ttl_o, &ttl, TTL_SIZE); - memcpy(head + dt_pci_info.pdu_type_o, &dt_pci->pdu_type, PDU_TYPE_SIZE); + memcpy(head + dt_pci_info.type_o, &dt_pci->pdu_type, PDU_TYPE_SIZE); if (dt_pci_info.dtc.has_chk) { tail = shm_du_buff_tail_alloc(sdb, dt_pci_info.tail_size); @@ -137,7 +137,7 @@ void dt_pci_des(struct shm_du_buff * sdb, dt_pci->ttl = 1; } - memcpy(&dt_pci->pdu_type, head + dt_pci_info.pdu_type_o, PDU_TYPE_SIZE); + memcpy(&dt_pci->pdu_type, head + dt_pci_info.type_o, PDU_TYPE_SIZE); } void dt_pci_shrink(struct shm_du_buff * sdb) diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c index 1adcb299..010b9761 100644 --- a/src/ipcpd/normal/frct.c +++ b/src/ipcpd/normal/frct.c @@ -37,6 +37,7 @@ #include <stdlib.h> #include <stdbool.h> #include <pthread.h> +#include <string.h> #include <assert.h> enum conn_state { @@ -128,9 +129,11 @@ int frct_init() int frct_fini() { + size_t len = IRMD_MAX_FLOWS; + pthread_mutex_destroy(&frct.instances_lock); - free(frct.instances); + freepp(struct frct_i, frct.instances, len); bmp_destroy(frct.cep_ids); @@ -139,8 +142,8 @@ int frct_fini() return 0; } -cep_id_t frct_i_create(uint64_t address, - qoscube_t cube) +cep_id_t frct_i_create(uint64_t address, + qoscube_t qc) { struct frct_i * instance; cep_id_t id; @@ -161,7 +164,7 @@ cep_id_t frct_i_create(uint64_t address, instance->cep_id = id; instance->state = CONN_PENDING; instance->seqno = 0; - instance->cube = cube; + instance->cube = qc; frct.instances[id] = instance; @@ -170,7 +173,7 @@ cep_id_t frct_i_create(uint64_t address, return id; } -int frct_i_destroy(cep_id_t cep_id) +int frct_i_destroy(cep_id_t cep_id) { struct frct_i * instance; @@ -262,6 +265,8 @@ int frct_post_sdu(struct shm_du_buff * sdb) assert(sdb); + memset(&frct_pci, 0, sizeof(frct_pci)); + frct_pci_des(sdb, &frct_pci); /* Known cep-ids are delivered to FA (minimal DTP) */ diff --git a/src/ipcpd/normal/pff.c b/src/ipcpd/normal/pff.c index c26c2263..38ca7232 100644 --- a/src/ipcpd/normal/pff.c +++ b/src/ipcpd/normal/pff.c @@ -33,8 +33,8 @@ #include "pff.h" struct pff { - struct htable * table; - pthread_mutex_t lock; + struct htable * table; + pthread_rwlock_t lock; }; struct pff * pff_create(void) @@ -45,14 +45,18 @@ struct pff * pff_create(void) if (tmp == NULL) return NULL; + if (pthread_rwlock_init(&tmp->lock, NULL)) { + free(tmp); + return NULL; + } + tmp->table = htable_create(PFT_SIZE, false); if (tmp->table == NULL) { + pthread_rwlock_destroy(&tmp->lock); free(tmp); return NULL; } - pthread_mutex_init(&tmp->lock, NULL); - return tmp; } @@ -62,21 +66,23 @@ void pff_destroy(struct pff * instance) htable_destroy(instance->table); - pthread_mutex_destroy(&instance->lock); + pthread_rwlock_destroy(&instance->lock); free(instance); } void pff_lock(struct pff * instance) { - pthread_mutex_lock(&instance->lock); + pthread_rwlock_wrlock(&instance->lock); } void pff_unlock(struct pff * instance) { - pthread_mutex_unlock(&instance->lock); + pthread_rwlock_unlock(&instance->lock); } -int pff_add(struct pff * instance, uint64_t addr, int fd) +int pff_add(struct pff * instance, + uint64_t addr, + int fd) { int * val; @@ -85,6 +91,7 @@ int pff_add(struct pff * instance, uint64_t addr, int fd) val = malloc(sizeof(*val)); if (val == NULL) return -ENOMEM; + *val = fd; if (htable_insert(instance->table, addr, val)) { @@ -95,7 +102,9 @@ int pff_add(struct pff * instance, uint64_t addr, int fd) return 0; } -int pff_update(struct pff * instance, uint64_t addr, int fd) +int pff_update(struct pff * instance, + uint64_t addr, + int fd) { int * val; @@ -119,7 +128,8 @@ int pff_update(struct pff * instance, uint64_t addr, int fd) return 0; } -int pff_remove(struct pff * instance, uint64_t addr) +int pff_remove(struct pff * instance, + uint64_t addr) { assert(instance); @@ -136,18 +146,21 @@ void pff_flush(struct pff * instance) htable_flush(instance->table); } -int pff_nhop(struct pff * instance, uint64_t addr) +int pff_nhop(struct pff * instance, + uint64_t addr) { int * j; - int fd; + int fd = -1; assert(instance); + pthread_rwlock_rdlock(&instance->lock); + j = (int *) htable_lookup(instance->table, addr); - if (j == NULL) { - return -1; - } - fd = *j; + if (j != NULL) + fd = *j; + + pthread_rwlock_unlock(&instance->lock); return fd; } |