diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ipcpd/common/comp.h | 2 | ||||
-rw-r--r-- | src/ipcpd/common/connmgr.c | 69 | ||||
-rw-r--r-- | src/ipcpd/common/connmgr.h | 2 | ||||
-rw-r--r-- | src/ipcpd/config.h.in | 1 | ||||
-rw-r--r-- | src/lib/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/lib/cep.c (renamed from src/lib/cacep.c) | 52 | ||||
-rw-r--r-- | src/lib/dev.c | 14 | ||||
-rw-r--r-- | src/lib/pb/cep.proto (renamed from src/lib/pb/cacep.proto) | 4 |
9 files changed, 81 insertions, 73 deletions
diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt index cd81949e..54294f11 100644 --- a/src/ipcpd/CMakeLists.txt +++ b/src/ipcpd/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CONNMGR_RCV_TIMEOUT 1000 CACHE STRING + "Timeout for the connection manager to wait for OCEP info (ms).") set(IPCP_DEBUG_LOCAL FALSE CACHE BOOL "Use PID as address for local debugging") set(IPCP_QOS_CUBE_BE_PRIO 50 CACHE STRING diff --git a/src/ipcpd/common/comp.h b/src/ipcpd/common/comp.h index 1130a163..f3790d9c 100644 --- a/src/ipcpd/common/comp.h +++ b/src/ipcpd/common/comp.h @@ -23,7 +23,7 @@ #ifndef OUROBOROS_IPCPD_COMMON_COMP_H #define OUROBOROS_IPCPD_COMMON_COMP_H -#include <ouroboros/cacep.h> +#include <ouroboros/cep.h> #define DST_MAX_STRLEN 64 diff --git a/src/ipcpd/common/connmgr.c b/src/ipcpd/common/connmgr.c index 71b114aa..4b5fd420 100644 --- a/src/ipcpd/common/connmgr.c +++ b/src/ipcpd/common/connmgr.c @@ -22,9 +22,10 @@ #define OUROBOROS_PREFIX "connection-manager" +#include <ouroboros/cep.h> #include <ouroboros/dev.h> -#include <ouroboros/cacep.h> #include <ouroboros/errno.h> +#include <ouroboros/fccntl.h> #include <ouroboros/list.h> #include <ouroboros/logs.h> #include <ouroboros/notifier.h> @@ -33,9 +34,9 @@ #include "connmgr.h" #include "ipcp.h" -#include <string.h> -#include <stdlib.h> #include <assert.h> +#include <stdlib.h> +#include <string.h> enum connmgr_state { CONNMGR_NULL = 0, @@ -128,10 +129,12 @@ static int add_comp_conn(enum comp_id id, static void * flow_acceptor(void * o) { - int fd; - qosspec_t qs; - struct conn_info rcv_info; - struct conn_info fail_info; + int fd; + qosspec_t qs; + struct conn_info rcv_info; + struct conn_info fail_info; + struct timespec timeo = TIMESPEC_INIT_MS(CONNMGR_RCV_TIMEOUT); + int err; (void) o; @@ -147,10 +150,13 @@ static void * flow_acceptor(void * o) continue; } - log_info("Handling incoming flow %d",fd); + log_info("Handling incoming flow %d.",fd); - if (cacep_rcv(fd, &rcv_info)) { - log_err("Error receiving CACEP info."); + fccntl(fd, FLOWSRCVTIMEO, &timeo); + + err = cep_rcv(fd, &rcv_info); + if (err < 0) { + log_err("Error receiving OCEP info: %d.", err); flow_dealloc(fd); continue; } @@ -161,24 +167,26 @@ static void * flow_acceptor(void * o) if (id < 0) { log_err("Connection request for unknown component %s.", rcv_info.comp_name); - cacep_snd(fd, &fail_info); + cep_snd(fd, &fail_info); flow_dealloc(fd); continue; } - if (cacep_snd(fd, &connmgr.comps[id].info)) { - log_err("Failed to respond to CACEP request."); + err = cep_snd(fd, &connmgr.comps[id].info); + if (err < 0) { + log_err("Failed responding to OCEP request: %d.", err); flow_dealloc(fd); continue; } - if (add_comp_conn(id, fd, qs, &rcv_info)) { - log_err("Failed to add new connection."); + err = add_comp_conn(id, fd, qs, &rcv_info); + if (err < 0) { + log_err("Failed to add new connection: %d.", err); flow_dealloc(fd); continue; } - log_info("Finished handling incoming flow %d for %s: 0.", + log_info("Finished handling incoming flow %d for %s.", fd, rcv_info.comp_name); } @@ -422,8 +430,9 @@ int connmgr_alloc(enum comp_id id, qosspec_t * qs, struct conn * conn) { - struct comp * comp; - int fd; + struct comp * comp; + int fd; + struct timespec timeo = TIMESPEC_INIT_MS(CONNMGR_RCV_TIMEOUT); assert(id >= 0 && id < COMPID_MAX); assert(dst); @@ -443,34 +452,36 @@ int connmgr_alloc(enum comp_id id, else memset(&conn->flow_info.qs, 0, sizeof(conn->flow_info.qs)); - log_dbg("Sending cacep info for protocol %s to fd %d.", + log_dbg("Sending OCEP info for protocol %s to fd %d.", comp->info.protocol, conn->flow_info.fd); - if (cacep_snd(fd, &comp->info)) { - log_err("Failed to send CACEP info."); - goto fail_cacep; + fccntl(fd, FLOWSRCVTIMEO, &timeo); + + if (cep_snd(fd, &comp->info)) { + log_err("Failed to send OCEP info."); + goto fail_cep; } - if (cacep_rcv(fd, &conn->conn_info)) { - log_err("Failed to receive CACEP info."); - goto fail_cacep; + if (cep_rcv(fd, &conn->conn_info)) { + log_err("Failed to receive OCEP info."); + goto fail_cep; } if (strcmp(comp->info.protocol, conn->conn_info.protocol)) { log_err("Unknown protocol (requested %s, got %s).", comp->info.protocol, conn->conn_info.protocol); - goto fail_cacep; + goto fail_cep; } if (comp->info.pref_version != conn->conn_info.pref_version) { log_err("Unknown protocol version %d.", conn->conn_info.pref_version); - goto fail_cacep; + goto fail_cep; } if (comp->info.pref_syntax != conn->conn_info.pref_syntax) { log_err("Unknown protocol syntax."); - goto fail_cacep; + goto fail_cep; } switch (id) { @@ -489,7 +500,7 @@ int connmgr_alloc(enum comp_id id, return 0; - fail_cacep: + fail_cep: flow_dealloc(conn->flow_info.fd); fail_alloc: return -1; diff --git a/src/ipcpd/common/connmgr.h b/src/ipcpd/common/connmgr.h index 21dc8ba3..0710dbbf 100644 --- a/src/ipcpd/common/connmgr.h +++ b/src/ipcpd/common/connmgr.h @@ -23,7 +23,7 @@ #ifndef OUROBOROS_IPCPD_COMMON_CONNMGR_H #define OUROBOROS_IPCPD_COMMON_CONNMGR_H -#include <ouroboros/cacep.h> +#include <ouroboros/cep.h> #include <ouroboros/qos.h> #include "comp.h" diff --git a/src/ipcpd/config.h.in b/src/ipcpd/config.h.in index af0658d6..fe4f5fd2 100644 --- a/src/ipcpd/config.h.in +++ b/src/ipcpd/config.h.in @@ -51,6 +51,7 @@ #define PFT_SIZE @PFT_SIZE@ #define DHT_ENROLL_SLACK @DHT_ENROLL_SLACK@ #define IPCP_UNICAST_MPL @IPCP_UNICAST_MPL@ +#define CONNMGR_RCV_TIMEOUT @CONNMGR_RCV_TIMEOUT@ #cmakedefine IPCP_CONN_WAIT_DIR #cmakedefine DISABLE_CORE_LOCK diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 66f26125..a6d7ac98 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -10,8 +10,8 @@ protobuf_generate_c(IPCP_CONFIG_PROTO_SRCS IPCP_CONFIG_PROTO_HDRS pb/ipcp_config.proto) protobuf_generate_c(ENROLL_PROTO_SRCS ENROLL_PROTO_HDRS pb/enroll.proto) -protobuf_generate_c(CACEP_PROTO_SRCS CACEP_PROTO_HDRS - pb/cacep.proto) +protobuf_generate_c(CEP_PROTO_SRCS CEP_PROTO_HDRS + pb/cep.proto) protobuf_generate_c(IRM_PROTO_SRCS IRM_PROTO_HDRS pb/irm.proto) protobuf_generate_c(IPCP_PROTO_SRCS IPCP_PROTO_HDRS @@ -241,7 +241,7 @@ endif () set(SOURCE_FILES_DEV # Add source files here - cacep.c + cep.c dev.c ) @@ -282,7 +282,7 @@ add_library(ouroboros-common SHARED ${SOURCE_FILES_COMMON} ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS} ${IPCP_CONFIG_PROTO_SRCS} ${MODEL_PROTO_SRCS} ${ENROLL_PROTO_SRCS}) -add_library(ouroboros-dev SHARED ${SOURCE_FILES_DEV} ${CACEP_PROTO_SRCS}) +add_library(ouroboros-dev SHARED ${SOURCE_FILES_DEV} ${CEP_PROTO_SRCS}) add_library(ouroboros-irm SHARED ${SOURCE_FILES_IRM}) diff --git a/src/lib/cacep.c b/src/lib/cep.c index da1c2e2c..ba238023 100644 --- a/src/lib/cacep.c +++ b/src/lib/cep.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2024 * - * The Common Application Connection Establishment Protocol + * The Ouroboros Connection Establishment Protocol * * Dimitri Staessens <dimitri@ouroboros.rocks> * Sander Vrijders <sander@ouroboros.rocks> @@ -22,35 +22,35 @@ #define _POSIX_C_SOURCE 199309L -#include <ouroboros/cacep.h> +#include <ouroboros/cep.h> #include <ouroboros/dev.h> #include <ouroboros/errno.h> #include <stdlib.h> #include <string.h> -#include "cacep.pb-c.h" -typedef CacepMsg cacep_msg_t; +#include "cep.pb-c.h" +typedef CepMsg cep_msg_t; #define BUF_SIZE 128 static int read_msg(int fd, struct conn_info * info) { - uint8_t buf[BUF_SIZE]; - cacep_msg_t * msg; - ssize_t len; + uint8_t buf[BUF_SIZE]; + cep_msg_t * msg; + ssize_t len; len = flow_read(fd, buf, BUF_SIZE); if (len < 0) - return -1; + return (int) len; - msg = cacep_msg__unpack(NULL, len, buf); + msg = cep_msg__unpack(NULL, len, buf); if (msg == NULL) return -1; - if (strlen(msg->comp_name) > CACEP_BUF_STRLEN) { - cacep_msg__free_unpacked(msg, NULL); + if (strlen(msg->comp_name) > OCEP_BUF_STRLEN) { + cep_msg__free_unpacked(msg, NULL); return -1; } @@ -61,7 +61,7 @@ static int read_msg(int fd, info->pref_syntax = msg->pref_syntax; info->addr = msg->address; - cacep_msg__free_unpacked(msg, NULL); + cep_msg__free_unpacked(msg, NULL); return 0; } @@ -69,9 +69,9 @@ static int read_msg(int fd, static int send_msg(int fd, const struct conn_info * info) { - cacep_msg_t msg = CACEP_MSG__INIT; - uint8_t * data = NULL; - size_t len = 0; + cep_msg_t msg = CEP_MSG__INIT; + uint8_t * data = NULL; + size_t len = 0; msg.comp_name = (char *) info->comp_name; msg.protocol = (char *) info->protocol; @@ -81,7 +81,7 @@ static int send_msg(int fd, if (msg.pref_syntax < 0) return -1; - len = cacep_msg__get_packed_size(&msg); + len = cep_msg__get_packed_size(&msg); if (len == 0) return -1; @@ -89,7 +89,7 @@ static int send_msg(int fd, if (data == NULL) return -ENOMEM; - cacep_msg__pack(&msg, data); + cep_msg__pack(&msg, data); if (flow_write(fd, data, len) < 0) { free(data); @@ -101,26 +101,20 @@ static int send_msg(int fd, return 0; } -int cacep_snd(int fd, - const struct conn_info * in) +int cep_snd(int fd, + const struct conn_info * in) { if (in == NULL) return -EINVAL; - if (send_msg(fd, in)) - return -1; - - return 0; + return send_msg(fd, in); } -int cacep_rcv(int fd, - struct conn_info * out) +int cep_rcv(int fd, + struct conn_info * out) { if (out == NULL) return -EINVAL; - if (read_msg(fd, out)) - return -1; - - return 0; + return read_msg(fd, out); } diff --git a/src/lib/dev.c b/src/lib/dev.c index a7f20e88..92310b9e 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -28,19 +28,19 @@ #include "config.h" -#include <ouroboros/hash.h> -#include <ouroboros/cacep.h> +#include <ouroboros/bitmap.h> +#include <ouroboros/cep.h> #include <ouroboros/crypt.h> -#include <ouroboros/errno.h> #include <ouroboros/dev.h> +#include <ouroboros/errno.h> +#include <ouroboros/fccntl.h> #include <ouroboros/flow.h> +#include <ouroboros/fqueue.h> +#include <ouroboros/hash.h> #include <ouroboros/ipcp.h> #include <ouroboros/ipcp-dev.h> #include <ouroboros/list.h> #include <ouroboros/local-dev.h> -#include <ouroboros/sockets.h> -#include <ouroboros/fccntl.h> -#include <ouroboros/bitmap.h> #include <ouroboros/np1_flow.h> #include <ouroboros/pthread.h> #include <ouroboros/random.h> @@ -48,8 +48,8 @@ #include <ouroboros/shm_flow_set.h> #include <ouroboros/shm_rdrbuff.h> #include <ouroboros/shm_rbuff.h> +#include <ouroboros/sockets.h> #include <ouroboros/utils.h> -#include <ouroboros/fqueue.h> #ifdef PROC_FLOW_STATS #include <ouroboros/rib.h> #endif diff --git a/src/lib/pb/cacep.proto b/src/lib/pb/cep.proto index 166e261d..d31cf4f7 100644 --- a/src/lib/pb/cacep.proto +++ b/src/lib/pb/cep.proto @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2024 * - * Message for Connection Information in CACEP + * Message for Connection Information in OCEP * * Dimitri Staessens <dimitri@ouroboros.rocks> * Sander Vrijders <sander@ouroboros.rocks> @@ -27,7 +27,7 @@ message fixed_conc_syntax_msg { repeated uint32 lens = 2; } -message cacep_msg { +message cep_msg { required string comp_name = 1; required string protocol = 2; required int32 pref_version = 3; |