summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-08-22 15:42:23 +0000
committerdimitri staessens <dimitri.staessens@ugent.be>2017-08-22 15:42:23 +0000
commit49eeec30ebc8b050dd69926047c2baebebe7f550 (patch)
tree5cd831f6a777d9be5d14e8aff1a66897d8163e19 /src
parentfb771c0cf876ad58c50551b90dacc0b5689dae05 (diff)
parent743c2f69744fe3f0dac11e467a92ff5e4d80280b (diff)
downloadouroboros-49eeec30ebc8b050dd69926047c2baebebe7f550.tar.gz
ouroboros-49eeec30ebc8b050dd69926047c2baebebe7f550.zip
Merged in sandervrijders/ouroboros/be-crc (pull request #561)
lib: Fix CRC check and add frct_clear
Diffstat (limited to 'src')
-rw-r--r--src/lib/CMakeLists.txt2
-rw-r--r--src/lib/dev.c43
-rw-r--r--src/lib/frct_pci.c12
3 files changed, 41 insertions, 16 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 4522613b..9d8fbf9c 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -123,7 +123,7 @@ set(AP_MAX_FQUEUES 32 CACHE STRING
"Maximum number of flow sets per application")
set(DU_BUFF_HEADSPACE 128 CACHE STRING
"Bytes of headspace to reserve for future headers")
-set(DU_BUFF_TAILSPACE 0 CACHE STRING
+set(DU_BUFF_TAILSPACE 16 CACHE STRING
"Bytes of tailspace to reserve for future tails")
if (NOT APPLE)
set(PTHREAD_COND_CLOCK "CLOCK_MONOTONIC" CACHE STRING
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 52a56097..a5caad3c 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -247,26 +247,41 @@ static int finalize_write(int fd,
static int frcti_init(int fd)
{
- ai.frcti[fd].used = true;
+ struct frcti * frcti;
+
+ frcti = &(ai.frcti[fd]);
- ai.frcti[fd].snd_drf = true;
- ai.frcti[fd].snd_lwe = 0;
- ai.frcti[fd].snd_rwe = 0;
+ frcti->used = true;
- ai.frcti[fd].rcv_drf = true;
- ai.frcti[fd].rcv_lwe = 0;
- ai.frcti[fd].rcv_rwe = 0;
+ frcti->snd_drf = true;
+ frcti->snd_lwe = 0;
+ frcti->snd_rwe = 0;
+
+ frcti->rcv_drf = true;
+ frcti->rcv_lwe = 0;
+ frcti->rcv_rwe = 0;
+
+ frcti->conf_flags = CONF_ERROR_CHECK;
return 0;
}
-static void frcti_fini(int fd)
+static void frcti_clear(int fd)
{
struct frcti * frcti;
frcti = &(ai.frcti[fd]);
frcti->used = false;
+ frcti->snd_inact = NULL;
+ frcti->rcv_inact = NULL;
+}
+
+static void frcti_fini(int fd)
+{
+ struct frcti * frcti;
+
+ frcti = &(ai.frcti[fd]);
/* FIXME: We actually need to wait until these timers become NULL. */
if (frcti->snd_inact != NULL)
@@ -274,6 +289,8 @@ static void frcti_fini(int fd)
if (frcti->rcv_inact != NULL)
timerwheel_stop(ai.tw, frcti->rcv_inact);
+
+ frcti_clear(fd);
}
static int frcti_configure(int fd,
@@ -405,14 +422,14 @@ static ssize_t frcti_read(int fd)
if (frct_pci_des(sdb, &pci, frcti->conf_flags & CONF_ERROR_CHECK)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
/* We don't accept packets when there is no inactivity timer. */
if (frcti->rcv_drf && !(pci.flags & FLAG_DATA_RUN)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
/*
@@ -436,7 +453,7 @@ static ssize_t frcti_read(int fd)
if (frcti->rcv_inact == NULL) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
frcti->rcv_drf = false;
@@ -444,7 +461,7 @@ static ssize_t frcti_read(int fd)
if (timerwheel_restart(ai.tw, frcti->rcv_inact, 3 * MPL)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
}
@@ -507,7 +524,7 @@ static void flow_fini(int fd)
shm_flow_set_close(ai.flows[fd].set);
if (ai.frcti[fd].used)
- frcti_fini(fd);
+ frcti_clear(fd);
flow_clear(fd);
}
diff --git a/src/lib/frct_pci.c b/src/lib/frct_pci.c
index 392e11c6..5ee14829 100644
--- a/src/lib/frct_pci.c
+++ b/src/lib/frct_pci.c
@@ -24,6 +24,9 @@
#include <ouroboros/hash.h>
#include <ouroboros/errno.h>
+#define OUROBOROS_PREFIX "frct-pci"
+#include <ouroboros/logs.h>
+
#include <assert.h>
#include <string.h>
@@ -73,6 +76,7 @@ int frct_pci_des(struct shm_du_buff * sdb,
uint8_t * head;
uint8_t * tail;
uint32_t crc;
+ uint32_t crc2;
assert(sdb);
assert(pci);
@@ -89,10 +93,14 @@ int frct_pci_des(struct shm_du_buff * sdb,
if (tail == NULL)
return -EPERM;
- mem_hash(HASH_CRC32, &crc, head, tail - head);
+ mem_hash(HASH_CRC32, &crc, head,
+ tail - head - hash_len(HASH_CRC32));
+
+ memcpy(&crc2, tail - hash_len(HASH_CRC32),
+ hash_len(HASH_CRC32));
/* Corrupted SDU */
- if (crc != 0)
+ if (crc != crc2)
return -1;
shm_du_buff_tail_release(sdb, hash_len(HASH_CRC32));