From 63dde087796bfcd730508b069ebae7c79b7cebe8 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 26 Mar 2022 09:39:49 +0100 Subject: 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 Signed-off-by: Sander Vrijders --- src/lib/shm_flow_set.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lib/shm_flow_set.c') 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: -- cgit v1.2.3