summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2024-02-17 10:19:46 +0100
committerSander Vrijders <sander@ouroboros.rocks>2024-02-19 11:49:07 +0100
commit06ee3370998f965b469d1c2859e3e34159c71e20 (patch)
tree93881747a4f1e99f6932231b0cb2358941cb9741 /include
parent7bb8aed15c7f29de4d9719acf8db7fdf73731af5 (diff)
downloadouroboros-06ee3370998f965b469d1c2859e3e34159c71e20.tar.gz
ouroboros-06ee3370998f965b469d1c2859e3e34159c71e20.zip
irmd: Revise IRMd internals
This is a full revision of the IRMd internal implementation. The registry is now a proper subcomponent managing its own internal lock (a single mutex). Some tests are added for the registry and its data structures. Some macros for tests are added in <ouroboros/test.h>. Flow allocation is now more symmetric between the client side (alloc) and server size (accept). Each will create a flow in pending state (ALLOC_PENDING/ACCEPT_PENDING) that is potentially fulfilled by an IPCP using respond_alloc and respond_accept primitives. Deallocation is split in flow_dealloc (application side) and ipcp_flow_dealloc (IPCP side) to get the flow in DEALLOC_PENDING and DEALLOCATED state. Cleanup of failed flow allocation is now properly handled instead of relying on the sanitizer thread. The new sanitizer only needs to monitor crashed processes. On shutdown, the IRMd will now detect hanging processes and SIGKILL them and clean up their fuse mountpoints if needed. A lot of other things have been cleaned up and shuffled around a bit. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'include')
-rw-r--r--include/ouroboros/CMakeLists.txt1
-rw-r--r--include/ouroboros/crypt.h4
-rw-r--r--include/ouroboros/flow.h4
-rw-r--r--include/ouroboros/hash.h16
-rw-r--r--include/ouroboros/ipcp-dev.h5
-rw-r--r--include/ouroboros/ipcp.h2
-rw-r--r--include/ouroboros/irm.h14
-rw-r--r--include/ouroboros/list.h2
-rw-r--r--include/ouroboros/name.h40
-rw-r--r--include/ouroboros/proc.h44
-rw-r--r--include/ouroboros/rib.h4
-rw-r--r--include/ouroboros/shm_rdrbuff.h4
-rw-r--r--include/ouroboros/test.h79
-rw-r--r--include/ouroboros/time.h (renamed from include/ouroboros/time_utils.h)15
-rw-r--r--include/ouroboros/utils.h7
15 files changed, 209 insertions, 32 deletions
diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt
index 8f248710..cac1b8d9 100644
--- a/include/ouroboros/CMakeLists.txt
+++ b/include/ouroboros/CMakeLists.txt
@@ -16,6 +16,7 @@ set(HEADER_FILES
fqueue.h
ipcp.h
irm.h
+ name.h
proto.h
qos.h
${CMAKE_CURRENT_BINARY_DIR}/version.h
diff --git a/include/ouroboros/crypt.h b/include/ouroboros/crypt.h
index c6e89a47..f0521c5a 100644
--- a/include/ouroboros/crypt.h
+++ b/include/ouroboros/crypt.h
@@ -24,6 +24,7 @@
#define OUROBOROS_LIB_CRYPT_H
#include <ouroboros/shm_du_buff.h>
+#include <ouroboros/utils.h>
#define SYMMKEYSZ 32
@@ -39,8 +40,7 @@ int crypt_dh_pkp_create(void ** pkp,
void crypt_dh_pkp_destroy(void * pkp);
int crypt_dh_derive(void * pkp,
- uint8_t * pk,
- size_t len,
+ buffer_t pk,
uint8_t * s);
int crypt_encrypt(struct crypt_info * info,
diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h
index e8c1dfdf..e10e987c 100644
--- a/include/ouroboros/flow.h
+++ b/include/ouroboros/flow.h
@@ -30,11 +30,11 @@
enum flow_state { /* DO NOT CHANGE ORDER! */
FLOW_INIT = 0,
FLOW_ALLOC_PENDING,
- FLOW_ALLOC_REQ_PENDING,
+ FLOW_ACCEPT_PENDING,
FLOW_ALLOCATED,
FLOW_DEALLOC_PENDING,
FLOW_DEALLOCATED,
- FLOW_DESTROY,
+ FLOW_DESTROY, /* TODO: REMOVE! */
FLOW_NULL
};
diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h
index c7168238..6b0087ce 100644
--- a/include/ouroboros/hash.h
+++ b/include/ouroboros/hash.h
@@ -72,13 +72,13 @@ enum hash_algo {
uint16_t hash_len(enum hash_algo algo);
-void mem_hash(enum hash_algo algo,
- void * dst,
- const uint8_t * buf,
- size_t len);
-
-void str_hash(enum hash_algo algo,
- void * dst,
- const char * str);
+void mem_hash(enum hash_algo algo,
+ void * dst,
+ const uint8_t * buf,
+ size_t len);
+
+void str_hash(enum hash_algo algo,
+ void * dst,
+ const char * str);
#endif /* OUROBOROS_LIB_HASH_H */
diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h
index a7075dc4..5ee78905 100644
--- a/include/ouroboros/ipcp-dev.h
+++ b/include/ouroboros/ipcp-dev.h
@@ -22,11 +22,12 @@
#include <ouroboros/shm_rdrbuff.h>
#include <ouroboros/qoscube.h>
+#include <ouroboros/ipcp.h>
#ifndef OUROBOROS_LIB_IPCP_DEV_H
#define OUROBOROS_LIB_IPCP_DEV_H
-int ipcp_create_r(int result);
+int ipcp_create_r(const struct ipcp_info * info);
int ipcp_flow_req_arr(const uint8_t * dst,
size_t len,
@@ -53,6 +54,8 @@ int np1_flow_read(int fd,
int np1_flow_write(int fd,
struct shm_du_buff * sdb);
+int ipcp_flow_dealloc(int fd);
+
int ipcp_flow_fini(int fd);
int ipcp_flow_get_qoscube(int fd,
diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h
index eb7d1670..42c4dfa4 100644
--- a/include/ouroboros/ipcp.h
+++ b/include/ouroboros/ipcp.h
@@ -36,6 +36,8 @@ enum ipcp_state {
IPCP_INIT = 0,
IPCP_BOOT,
IPCP_OPERATIONAL,
+ IPCP_BOOTSTRAPPED,
+ IPCP_ENROLLED,
IPCP_SHUTDOWN,
IPCP_NULL
};
diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h
index 30d461ab..b27343e8 100644
--- a/include/ouroboros/irm.h
+++ b/include/ouroboros/irm.h
@@ -25,25 +25,15 @@
#include <ouroboros/cdefs.h>
#include <ouroboros/ipcp.h>
+#include <ouroboros/name.h>
#include <ouroboros/qos.h>
#include <sys/types.h>
/* Name binding options. */
-#define BIND_AUTO 0x01
+#define BIND_AUTO 0x01
#define NAME_SIZE 255
-enum pol_balance {
- LB_RR = 0,
- LB_SPILL,
- LB_INVALID
-};
-
-struct name_info {
- char name[NAME_SIZE + 1];
- enum pol_balance pol_lb;
-};
-
struct ipcp_list_info {
pid_t pid;
enum ipcp_type type;
diff --git a/include/ouroboros/list.h b/include/ouroboros/list.h
index dc408649..f3ea0e46 100644
--- a/include/ouroboros/list.h
+++ b/include/ouroboros/list.h
@@ -61,6 +61,6 @@ void list_del(struct list_head * e);
void list_move(struct list_head * dst,
struct list_head * src);
-bool list_is_empty(struct list_head * h);
+bool list_is_empty(const struct list_head * h);
#endif /* OUROBOROS_LIB_LIST_H */
diff --git a/include/ouroboros/name.h b/include/ouroboros/name.h
new file mode 100644
index 00000000..0f71e63d
--- /dev/null
+++ b/include/ouroboros/name.h
@@ -0,0 +1,40 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2024
+ *
+ * Names
+ *
+ * Dimitri Staessens <dimitri@ouroboros.rocks>
+ * Sander Vrijders <sander@ouroboros.rocks>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., http://www.fsf.org/about/contact/.
+ */
+
+#ifndef OUROBOROS_NAME_H
+#define OUROBOROS_NAME_H
+
+#define NAME_SIZE 255
+#define BIND_AUTO 0x01
+
+enum pol_balance {
+ LB_RR = 0,
+ LB_SPILL,
+ LB_INVALID
+};
+
+struct name_info {
+ char name[NAME_SIZE + 1];
+ enum pol_balance pol_lb;
+};
+
+#endif /* OUROBOROS_NAME_H */ \ No newline at end of file
diff --git a/include/ouroboros/proc.h b/include/ouroboros/proc.h
new file mode 100644
index 00000000..d0b010bb
--- /dev/null
+++ b/include/ouroboros/proc.h
@@ -0,0 +1,44 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2024
+ *
+ * Processes and Programs
+ *
+ * Dimitri Staessens <dimitri@ouroboros.rocks>
+ * Sander Vrijders <sander@ouroboros.rocks>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., http://www.fsf.org/about/contact/.
+ */
+
+#ifndef OUROBOROS_LIB_PROC_H
+#define OUROBOROS_LIB_PROC_H
+
+#include <sys/types.h>
+
+#define PROG_NAME_SIZE 255
+#define PROG_PATH_SIZE 255
+
+/* Processes */
+struct proc_info {
+ pid_t pid;
+ char prog[PROG_NAME_SIZE + 1]; /* program instantiated */
+
+};
+
+/* Programs */
+struct prog_info {
+ char name[PROG_NAME_SIZE + 1];
+ char path[PROG_PATH_SIZE + 1];
+};
+
+#endif /* OUROBOROS_LIB_PROC_H */ \ No newline at end of file
diff --git a/include/ouroboros/rib.h b/include/ouroboros/rib.h
index 94bb5b85..6aabe8f7 100644
--- a/include/ouroboros/rib.h
+++ b/include/ouroboros/rib.h
@@ -23,7 +23,7 @@
#ifndef OUROBOROS_LIB_RIB_H
#define OUROBOROS_LIB_RIB_H
-#define RIB_PATH_LEN 128
+#define RIB_PATH_LEN 300
#define RIB_SEPARATOR "/"
#include <sys/types.h>
@@ -53,4 +53,6 @@ int rib_reg(const char * path,
void rib_unreg(const char * path);
+void rib_cleanup(const char * mnt);
+
#endif /* OUROBOROS_LIB_RIB_H */
diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h
index 93846132..4f9a215a 100644
--- a/include/ouroboros/shm_rdrbuff.h
+++ b/include/ouroboros/shm_rdrbuff.h
@@ -24,10 +24,10 @@
#define OUROBOROS_LIB_SHM_RDRBUFF_H
#include <ouroboros/shm_du_buff.h>
-#include <ouroboros/time_utils.h>
+#include <ouroboros/time.h>
-#include <stdint.h>
#include <pthread.h>
+#include <stdint.h>
#include <sys/types.h>
struct shm_rdrbuff;
diff --git a/include/ouroboros/test.h b/include/ouroboros/test.h
new file mode 100644
index 00000000..56c92137
--- /dev/null
+++ b/include/ouroboros/test.h
@@ -0,0 +1,79 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2024
+ *
+ * Test macros
+ *
+ * Dimitri Staessens <dimitri@ouroboros.rocks>
+ * Sander Vrijders <sander@ouroboros.rocks>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., http://www.fsf.org/about/contact/.
+ */
+
+#ifndef OUROBOROS_LIB_TEST_H
+#define OUROBOROS_LIB_TEST_H
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#define TEST_START() \
+ do { \
+ printf("%s started.\n", __func__); \
+ fflush(stdout); \
+ } while(0)
+#define TEST_SUCCESS() \
+ do { \
+ printf("%s succeeded.\n", __func__); \
+ fflush(stdout); \
+ } while(0)
+
+#define TEST_FAIL() \
+ do { \
+ printf("%s failed.\n", __func__); \
+ fflush(stdout); \
+ } while(0)
+
+static int __attribute__((unused)) test_assert_fail(int(* testfunc)(void))
+{
+ pid_t pid;
+ int wstatus;
+
+ pid = fork();
+ if (pid == -1) {
+ printf("Failed to fork: %s.\n", strerror(errno));
+ return -1;
+ }
+
+ if (pid == 0)
+ return testfunc(); /* should abort */
+
+ waitpid(pid, &wstatus, 0);
+#ifdef CONFIG_OUROBOROS_DEBUG
+ if (WIFSIGNALED(wstatus) && wstatus == 134)
+ return 0;
+
+ printf("Process did not abort, status: %d.\n", wstatus);
+#else
+ if (WIFEXITED(wstatus) && wstatus == 0)
+ return 0;
+
+ printf("Process did not exit, status: %d.\n", wstatus);
+#endif
+
+ return -1;
+}
+
+#endif /* OUROBOROS_LIB_TEST_H */ \ No newline at end of file
diff --git a/include/ouroboros/time_utils.h b/include/ouroboros/time.h
index 872c9963..b274c35b 100644
--- a/include/ouroboros/time_utils.h
+++ b/include/ouroboros/time.h
@@ -20,8 +20,8 @@
* Foundation, Inc., http://www.fsf.org/about/contact/.
*/
-#ifndef OUROBOROS_LIB_TIME_UTILS_H
-#define OUROBOROS_LIB_TIME_UTILS_H
+#ifndef OUROBOROS_LIB_TIME_H
+#define OUROBOROS_LIB_TIME_H
#ifdef MILLION
#undef MILLION
@@ -37,6 +37,15 @@
#include <time.h>
#include <sys/time.h>
+#define TIMESPEC_INIT_S(s) {(s), 0}
+#define TIMESPEC_INIT_MS(ms) {(ms) / 1000, ((ms) % 1000) * MILLION}
+#define TIMESPEC_INIT_US(us) {(us) / MILLION, ((us) % MILLION) * 1000}
+#define TIMESPEC_INIT_NS(ns) {(ns) / BILLION, ((ns) % BILLION)}
+
+#define TIMEVAL_INIT_S(s) {(s), 0}
+#define TIMEVAL_INIT_MS(ms) {(ms) / 1000, ((ms) % 1000) * 1000}
+#define TIMEVAL_INIT_US(us) {(us) / MILLION, ((us) % MILLION)}
+
/* functions for timespecs */
#define ts_diff_ns(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \
+ ((tx)->tv_nsec - (t0)->tv_nsec))
@@ -118,4 +127,4 @@
(tv)->tv_usec = (ts)->tv_nsec / 1000L; \
} while (0);
-#endif /* OUROBOROS_LIB_TIME_UTILS_H */
+#endif /* OUROBOROS_LIB_TIME_H */
diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h
index 2dff6e67..93fbf402 100644
--- a/include/ouroboros/utils.h
+++ b/include/ouroboros/utils.h
@@ -47,6 +47,13 @@ int n_digits(unsigned i);
/* gets the application name */
char * path_strip(const char * src);
+/* functions for copying and destroying arguments list */
+size_t argvlen(const char ** argv);
+
+char ** argvdup(char ** argv);
+
+void argvfree(char ** argv);
+
/* destroy a ** */
#define freepp(type, ptr, len) \
do { \