summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-27 11:53:20 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-28 10:25:46 +0200
commit9e3dffb25570fc12dd43f8fad721be40374ea35b (patch)
tree9865b01cd1d946e4657ce3d459440ea15bcc3bc8
parent8fd39fd9e1cc65147a6f1a3fa5027c9ab2cb4a68 (diff)
downloadouroboros-9e3dffb25570fc12dd43f8fad721be40374ea35b.tar.gz
ouroboros-9e3dffb25570fc12dd43f8fad721be40374ea35b.zip
ipcpd: normal: Fix locking of PFF
This adds fixes the locking of the PFF which was externalized, but not yet correctly updated within the PFF component itself and within the flow manager.
-rw-r--r--src/ipcpd/normal/fmgr.c9
-rw-r--r--src/ipcpd/normal/pff.c20
2 files changed, 10 insertions, 19 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index a8a9ba58..f78d390a 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -198,13 +198,16 @@ void * fmgr_nm1_sdu_reader(void * o)
continue;
}
+ pff_lock(fmgr.pff[i]);
fd = pff_nhop(fmgr.pff[i], pci.dst_addr);
if (fd < 0) {
+ pff_unlock(fmgr.pff[i]);
log_err("No next hop for %lu",
pci.dst_addr);
ipcp_flow_del(sdb);
continue;
}
+ pff_unlock(fmgr.pff[i]);
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.",
@@ -689,12 +692,15 @@ int fmgr_nm1_write_sdu(struct pci * pci,
if (pci == NULL || sdb == NULL)
return -EINVAL;
+ pff_lock(fmgr.pff[pci->qos_id]);
fd = pff_nhop(fmgr.pff[pci->qos_id], pci->dst_addr);
if (fd < 0) {
+ pff_unlock(fmgr.pff[pci->qos_id]);
log_err("Could not get nhop for address %lu", pci->dst_addr);
ipcp_flow_del(sdb);
return -1;
}
+ pff_unlock(fmgr.pff[pci->qos_id]);
if (shm_pci_ser(sdb, pci)) {
log_err("Failed to serialize PDU.");
@@ -720,11 +726,14 @@ int fmgr_nm1_write_buf(struct pci * pci,
if (pci == NULL || buf == NULL || buf->data == NULL)
return -EINVAL;
+ pff_lock(fmgr.pff[pci->qos_id]);
fd = pff_nhop(fmgr.pff[pci->qos_id], pci->dst_addr);
if (fd < 0) {
+ pff_unlock(fmgr.pff[pci->qos_id]);
log_err("Could not get nhop for address %lu", pci->dst_addr);
return -1;
}
+ pff_unlock(fmgr.pff[pci->qos_id]);
buffer = shm_pci_ser_buf(buf, pci);
if (buffer == NULL) {
diff --git a/src/ipcpd/normal/pff.c b/src/ipcpd/normal/pff.c
index 77c2c551..c26c2263 100644
--- a/src/ipcpd/normal/pff.c
+++ b/src/ipcpd/normal/pff.c
@@ -60,9 +60,7 @@ void pff_destroy(struct pff * instance)
{
assert(instance);
- pthread_mutex_lock(&instance->lock);
htable_destroy(instance->table);
- pthread_mutex_unlock(&instance->lock);
pthread_mutex_destroy(&instance->lock);
free(instance);
@@ -89,13 +87,10 @@ int pff_add(struct pff * instance, uint64_t addr, int fd)
return -ENOMEM;
*val = fd;
- pthread_mutex_lock(&instance->lock);
if (htable_insert(instance->table, addr, val)) {
- pthread_mutex_unlock(&instance->lock);
free(val);
return -1;
}
- pthread_mutex_unlock(&instance->lock);
return 0;
}
@@ -111,19 +106,15 @@ int pff_update(struct pff * instance, uint64_t addr, int fd)
return -ENOMEM;
*val = fd;
- pthread_mutex_lock(&instance->lock);
if (htable_delete(instance->table, addr)) {
- pthread_mutex_unlock(&instance->lock);
free(val);
return -1;
}
if (htable_insert(instance->table, addr, val)) {
- pthread_mutex_unlock(&instance->lock);
free(val);
return -1;
}
- pthread_mutex_unlock(&instance->lock);
return 0;
}
@@ -132,12 +123,8 @@ int pff_remove(struct pff * instance, uint64_t addr)
{
assert(instance);
- pthread_mutex_lock(&instance->lock);
- if (htable_delete(instance->table, addr)) {
- pthread_mutex_unlock(&instance->lock);
+ if (htable_delete(instance->table, addr))
return -1;
- }
- pthread_mutex_unlock(&instance->lock);
return 0;
}
@@ -146,9 +133,7 @@ void pff_flush(struct pff * instance)
{
assert(instance);
- pthread_mutex_lock(&instance->lock);
htable_flush(instance->table);
- pthread_mutex_unlock(&instance->lock);
}
int pff_nhop(struct pff * instance, uint64_t addr)
@@ -158,14 +143,11 @@ int pff_nhop(struct pff * instance, uint64_t addr)
assert(instance);
- pthread_mutex_lock(&instance->lock);
j = (int *) htable_lookup(instance->table, addr);
if (j == NULL) {
- pthread_mutex_unlock(&instance->lock);
return -1;
}
fd = *j;
- pthread_mutex_unlock(&instance->lock);
return fd;
}