summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.c
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 /src/ipcpd/ipcp.c
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 'src/ipcpd/ipcp.c')
-rw-r--r--src/ipcpd/ipcp.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 312c4a79..0215cdaa 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -35,21 +35,21 @@
#define OUROBOROS_PREFIX "ipcpd/ipcp"
#define IPCP_INFO "info"
-#define ALLOC_TIMEOUT 10 * MILLION /* 10 ms */
+#define ALLOC_TIMEOUT 50 /* ms */
-#include <ouroboros/hash.h>
-#include <ouroboros/logs.h>
-#include <ouroboros/time_utils.h>
-#include <ouroboros/utils.h>
-#include <ouroboros/sockets.h>
-#include <ouroboros/errno.h>
+#include <ouroboros/bitmap.h>
#include <ouroboros/dev.h>
+#include <ouroboros/errno.h>
+#include <ouroboros/hash.h>
#include <ouroboros/ipcp-dev.h>
-#include <ouroboros/bitmap.h>
+#include <ouroboros/logs.h>
#include <ouroboros/np1_flow.h>
-#include <ouroboros/rib.h>
#include <ouroboros/protobuf.h>
#include <ouroboros/pthread.h>
+#include <ouroboros/rib.h>
+#include <ouroboros/sockets.h>
+#include <ouroboros/time.h>
+#include <ouroboros/utils.h>
#include "ipcp.h"
@@ -267,7 +267,7 @@ int ipcp_wait_flow_req_arr(const uint8_t * dst,
const void * data,
size_t len)
{
- struct timespec ts = {0, ALLOC_TIMEOUT};
+ struct timespec ts = TIMESPEC_INIT_MS(ALLOC_TIMEOUT);
struct timespec abstime;
int fd;
@@ -294,7 +294,7 @@ int ipcp_wait_flow_req_arr(const uint8_t * dst,
if (fd < 0) {
pthread_mutex_unlock(&ipcpi.alloc_lock);
log_err("Failed to get fd for flow.");
- return -ENOTALLOC;
+ return fd;
}
ipcpi.alloc_id = fd;
@@ -308,7 +308,7 @@ int ipcp_wait_flow_req_arr(const uint8_t * dst,
int ipcp_wait_flow_resp(const int fd)
{
- struct timespec ts = {0, ALLOC_TIMEOUT};
+ struct timespec ts = TIMESPEC_INIT_MS(ALLOC_TIMEOUT);
struct timespec abstime;
clock_gettime(PTHREAD_COND_CLOCK, &abstime);
@@ -502,8 +502,8 @@ static void do_flow_alloc(pid_t pid,
{
int fd;
- log_info("Allocating flow %d to " HASH_FMT32 ".",
- flow_id, HASH_VAL32(dst));
+ log_info("Allocating flow %d for %d to " HASH_FMT32 ".",
+ flow_id, pid, HASH_VAL32(dst));
if (ipcpi.ops->ipcp_flow_alloc == NULL) {
log_err("Flow allocation unsupported.");
@@ -519,7 +519,8 @@ static void do_flow_alloc(pid_t pid,
fd = np1_flow_alloc(pid, flow_id);
if (fd < 0) {
- log_err("Failed allocating n + 1 fd on flow_id %d.", flow_id);
+ log_err("Failed allocating n + 1 fd on flow_id %d: %d",
+ flow_id, fd);
ret_msg->result = -EFLOWDOWN;
goto finish;
}
@@ -635,7 +636,6 @@ static void do_flow_dealloc(int flow_id,
flow_id, ret_msg->result);
}
-
static void * mainloop(void * o)
{
int sfd;
@@ -929,7 +929,9 @@ int ipcp_init(int argc,
int ipcp_start(void)
{
- sigset_t sigset;
+ sigset_t sigset;
+ struct ipcp_info info;
+
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigaddset(&sigset, SIGQUIT);
@@ -938,6 +940,11 @@ int ipcp_start(void)
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+ info.pid = getpid();
+ info.type = ipcpi.type;
+ strcpy(info.name, ipcpi.name);
+ info.state = IPCP_OPERATIONAL;
+
if (tpm_start(ipcpi.tpm))
goto fail_tpm_start;
@@ -946,7 +953,9 @@ int ipcp_start(void)
goto fail_acceptor;
}
- if (ipcp_create_r(0)) {
+ info.state = IPCP_OPERATIONAL;
+
+ if (ipcp_create_r(&info)) {
log_err("Failed to notify IRMd we are initialized.");
goto fail_create_r;
}
@@ -957,11 +966,12 @@ int ipcp_start(void)
pthread_cancel(ipcpi.acceptor);
pthread_join(ipcpi.acceptor, NULL);
fail_acceptor:
- ipcp_set_state(IPCP_NULL);
tpm_stop(ipcpi.tpm);
fail_tpm_start:
tpm_destroy(ipcpi.tpm);
- ipcp_create_r(-1);
+ ipcp_set_state(IPCP_NULL);
+ info.state = IPCP_NULL;
+ ipcp_create_r(&info);
return -1;
}