aboutgitcodelistschat:MatrixIRC
path: root/tests
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-03-30 11:02:47 +0200
committerAlice Frosi <afrosi@redhat.com>2023-03-30 11:07:12 +0200
commitfa00aa6b11a9a773bdb0b11c306d2e6936ba5862 (patch)
tree8852eebf58339d9bbce563022a754d4204411c26 /tests
parent6a850dfce709751292a136d76060c97b57435ef1 (diff)
downloadseitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar.gz
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar.bz2
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar.lz
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar.xz
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.tar.zst
seitan-fa00aa6b11a9a773bdb0b11c306d2e6936ba5862.zip
Create common function to install the BPF filter
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Makefile4
-rw-r--r--tests/unit/test_operations.c17
2 files changed, 5 insertions, 16 deletions
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
index bdd419b..aad8549 100644
--- a/tests/unit/Makefile
+++ b/tests/unit/Makefile
@@ -7,8 +7,8 @@ OP_DIR := ../../
COOKER_DIR := ../../cooker
DBG_DIR := ../../debug
-SRCS_FILTER := $(COOKER_DIR)/filter.c $(DBG_DIR)/disasm.c
-HEADERS_FILTER := $(COOKER_DIR)/filter.h $(DBG_DIR)/disasm.h
+SRCS_FILTER := $(COOKER_DIR)/filter.c $(DBG_DIR)/disasm.c $(COMMON_DIR)/common.c
+HEADERS_FILTER := $(COOKER_DIR)/filter.h $(DBG_DIR)/disasm.h $(COMMON_DIR)/common.h
HEADERS_OP_CALL := $(COMMON_DIR)/gluten.h $(OP_DIR)/operations.h
SRCS_OP_CALL := $(OP_DIR)/operations.c
diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c
index a743aa4..c60fa4f 100644
--- a/tests/unit/test_operations.c
+++ b/tests/unit/test_operations.c
@@ -28,6 +28,7 @@
#include "gluten.h"
#include "operations.h"
#include "common.h"
+#include "util.h"
#define MAX_TEST_PATH 250
@@ -64,20 +65,8 @@ static int install_notification_filter(int nr)
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_USER_NOTIF),
BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW),
};
- struct sock_fprog prog;
-
- prog.filter = filter;
- prog.len = (unsigned short)(sizeof(filter) / sizeof(filter[0]));
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
- perror("prctl");
- return -1;
- }
- if ((fd = syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER,
- SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog)) < 0) {
- perror("seccomp");
- return -1;
- }
- return fd;
+ return install_filter(
+ &filter, (unsigned short)(sizeof(filter) / sizeof(filter[0])));
}
static int create_test_fd()