summaryrefslogtreecommitdiff
path: root/src/lib/shm_flow_set.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2022-03-26 09:39:49 +0100
committerSander Vrijders <sander@ouroboros.rocks>2022-03-30 15:05:05 +0200
commit63dde087796bfcd730508b069ebae7c79b7cebe8 (patch)
treee5e338b9583d023c5895ed0d3a20b679fae76ddf /src/lib/shm_flow_set.c
parent0b45e1e5363f61febc7033f1b9bda14689c88644 (diff)
downloadouroboros-63dde087796bfcd730508b069ebae7c79b7cebe8.tar.gz
ouroboros-63dde087796bfcd730508b069ebae7c79b7cebe8.zip
lib: Refactor reading packet from rbuff
Reading packets from the rbuff and checking their validity (non-zero size, pass crc check, pass decryption) is now extracted into a function. Also adds a function to get the length of an sdu_du_buff instead of subtracting the tail and head pointers. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/shm_flow_set.c')
-rw-r--r--src/lib/shm_flow_set.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index 5a9bee6c..d325a253 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -96,10 +96,8 @@ static struct shm_flow_set * flow_set_create(pid_t pid,
if (shm_fd == -1)
goto fail_shm_open;
- if (ftruncate(shm_fd, SHM_FLOW_SET_FILE_SIZE - 1) < 0) {
- close(shm_fd);
- goto fail_shm_open;
- }
+ if (ftruncate(shm_fd, SHM_FLOW_SET_FILE_SIZE - 1) < 0)
+ goto fail_truncate;
shm_base = mmap(NULL,
SHM_FLOW_SET_FILE_SIZE,
@@ -108,11 +106,11 @@ static struct shm_flow_set * flow_set_create(pid_t pid,
shm_fd,
0);
- close(shm_fd);
-
if (shm_base == MAP_FAILED)
goto fail_mmap;
+ close(shm_fd);
+
set->mtable = shm_base;
set->heads = (size_t *) (set->mtable + SYS_MAX_FLOWS);
set->conds = (pthread_cond_t *)(set->heads + PROG_MAX_FQUEUES);
@@ -125,6 +123,8 @@ static struct shm_flow_set * flow_set_create(pid_t pid,
fail_mmap:
if (flags & O_CREAT)
shm_unlink(fn);
+ fail_truncate:
+ close(shm_fd);
fail_shm_open:
free(set);
fail_malloc: