From bb617311f4fc4ece5bf963d3f445e73e09a9cdaa Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 25 Feb 2024 12:00:11 +0100 Subject: lib: Rename CACEP to CEP and set conngmr timeout The Common Application Connection Establishment Protocol (CACEP) is a RINA construct associated with the Common Distributed Application Protocol (CDAP). We dropped CDAP as O7s sees connection establishment as common to all applications (though it can be a nop). The wiki already refers to this as (O7s) Connection Establishment Protocol (CEP). The connection manager will now timeout waiting for CEP messages to avoid hanging forever, configurable at build time via CONNMGR_RCV_TIMEOUT. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- CMakeLists.txt | 2 +- include/ouroboros/CMakeLists.txt | 2 +- include/ouroboros/cacep.h | 54 ----------------- include/ouroboros/cep.h | 53 ++++++++++++++++ src/ipcpd/CMakeLists.txt | 2 + src/ipcpd/common/comp.h | 2 +- src/ipcpd/common/connmgr.c | 69 ++++++++++++--------- src/ipcpd/common/connmgr.h | 2 +- src/ipcpd/config.h.in | 1 + src/lib/CMakeLists.txt | 8 +-- src/lib/cacep.c | 126 --------------------------------------- src/lib/cep.c | 120 +++++++++++++++++++++++++++++++++++++ src/lib/dev.c | 14 ++--- src/lib/pb/cacep.proto | 39 ------------ src/lib/pb/cep.proto | 39 ++++++++++++ 15 files changed, 270 insertions(+), 263 deletions(-) delete mode 100644 include/ouroboros/cacep.h create mode 100644 include/ouroboros/cep.h delete mode 100644 src/lib/cacep.c create mode 100644 src/lib/cep.c delete mode 100644 src/lib/pb/cacep.proto create mode 100644 src/lib/pb/cep.proto diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc79b05..397cfdad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ include(GNUInstallDirs) set(PACKAGE_VERSION_MAJOR 0) set(PACKAGE_VERSION_MINOR 21) -set(PACKAGE_VERSION_PATCH 1) +set(PACKAGE_VERSION_PATCH 2) set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}") set(PACKAGE_DESCRIPTION "The Ouroboros prototype") diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index cac1b8d9..4e90bc59 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -8,7 +8,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sockets.h.in" "${CMAKE_CURRENT_BINARY_DIR}/sockets.h" @ONLY) set(HEADER_FILES - cacep.h + cep.h cdefs.h dev.h errno.h diff --git a/include/ouroboros/cacep.h b/include/ouroboros/cacep.h deleted file mode 100644 index e33654a9..00000000 --- a/include/ouroboros/cacep.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2024 - * - * The Common Application Connection Establishment Protocol - * - * Dimitri Staessens - * Sander Vrijders - * - * 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_CACEP_H -#define OUROBOROS_CACEP_H - -#include -#include - -#include -#include - -#define CACEP_BUF_STRLEN 64 - -struct conn_info { - char comp_name[CACEP_BUF_STRLEN + 1]; - char protocol[CACEP_BUF_STRLEN + 1]; - uint32_t pref_version; - enum proto_concrete_syntax pref_syntax; - struct proto_field fixed_conc_syntax[PROTO_MAX_FIELDS]; - size_t num_fields; - uint64_t addr; -}; - -__BEGIN_DECLS - -int cacep_snd(int fd, - const struct conn_info * in); - -int cacep_rcv(int fd, - struct conn_info * out); - -__END_DECLS - -#endif /* OUROBOROS_CACEP_H */ diff --git a/include/ouroboros/cep.h b/include/ouroboros/cep.h new file mode 100644 index 00000000..4c1737f0 --- /dev/null +++ b/include/ouroboros/cep.h @@ -0,0 +1,53 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * The Ouroboros Connection Establishment Protocol + * + * Dimitri Staessens + * Sander Vrijders + * + * 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_CEP_H +#define OUROBOROS_CEP_H + +#include +#include + +#include + +#define OCEP_BUF_STRLEN 128 + +struct conn_info { + char comp_name[OCEP_BUF_STRLEN + 1]; + char protocol[OCEP_BUF_STRLEN + 1]; + uint32_t pref_version; + enum proto_concrete_syntax pref_syntax; + struct proto_field fixed_conc_syntax[PROTO_MAX_FIELDS]; + size_t num_fields; + uint64_t addr; +}; + +__BEGIN_DECLS + +int cep_snd(int fd, + const struct conn_info * in); + +int cep_rcv(int fd, + struct conn_info * out); + +__END_DECLS + +#endif /* OUROBOROS_CEP_H */ 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 +#include #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 #include -#include #include +#include #include #include #include @@ -33,9 +34,9 @@ #include "connmgr.h" #include "ipcp.h" -#include -#include #include +#include +#include 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 +#include #include #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/cacep.c deleted file mode 100644 index da1c2e2c..00000000 --- a/src/lib/cacep.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2024 - * - * The Common Application Connection Establishment Protocol - * - * Dimitri Staessens - * Sander Vrijders - * - * 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/. - */ - -#define _POSIX_C_SOURCE 199309L - -#include -#include -#include - -#include -#include - -#include "cacep.pb-c.h" -typedef CacepMsg cacep_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; - - len = flow_read(fd, buf, BUF_SIZE); - if (len < 0) - return -1; - - msg = cacep_msg__unpack(NULL, len, buf); - if (msg == NULL) - return -1; - - if (strlen(msg->comp_name) > CACEP_BUF_STRLEN) { - cacep_msg__free_unpacked(msg, NULL); - return -1; - } - - strcpy(info->comp_name, msg->comp_name); - strcpy(info->protocol, msg->protocol); - - info->pref_version = msg->pref_version; - info->pref_syntax = msg->pref_syntax; - info->addr = msg->address; - - cacep_msg__free_unpacked(msg, NULL); - - return 0; -} - -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; - - msg.comp_name = (char *) info->comp_name; - msg.protocol = (char *) info->protocol; - msg.address = info->addr; - msg.pref_version = info->pref_version; - msg.pref_syntax = info->pref_syntax; - if (msg.pref_syntax < 0) - return -1; - - len = cacep_msg__get_packed_size(&msg); - if (len == 0) - return -1; - - data = malloc(len); - if (data == NULL) - return -ENOMEM; - - cacep_msg__pack(&msg, data); - - if (flow_write(fd, data, len) < 0) { - free(data); - return -1; - } - - free(data); - - return 0; -} - -int cacep_snd(int fd, - const struct conn_info * in) -{ - if (in == NULL) - return -EINVAL; - - if (send_msg(fd, in)) - return -1; - - return 0; -} - -int cacep_rcv(int fd, - struct conn_info * out) -{ - if (out == NULL) - return -EINVAL; - - if (read_msg(fd, out)) - return -1; - - return 0; -} diff --git a/src/lib/cep.c b/src/lib/cep.c new file mode 100644 index 00000000..ba238023 --- /dev/null +++ b/src/lib/cep.c @@ -0,0 +1,120 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * The Ouroboros Connection Establishment Protocol + * + * Dimitri Staessens + * Sander Vrijders + * + * 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/. + */ + +#define _POSIX_C_SOURCE 199309L + +#include +#include +#include + +#include +#include + +#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]; + cep_msg_t * msg; + ssize_t len; + + len = flow_read(fd, buf, BUF_SIZE); + if (len < 0) + return (int) len; + + msg = cep_msg__unpack(NULL, len, buf); + if (msg == NULL) + return -1; + + if (strlen(msg->comp_name) > OCEP_BUF_STRLEN) { + cep_msg__free_unpacked(msg, NULL); + return -1; + } + + strcpy(info->comp_name, msg->comp_name); + strcpy(info->protocol, msg->protocol); + + info->pref_version = msg->pref_version; + info->pref_syntax = msg->pref_syntax; + info->addr = msg->address; + + cep_msg__free_unpacked(msg, NULL); + + return 0; +} + +static int send_msg(int fd, + const struct conn_info * info) +{ + 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; + msg.address = info->addr; + msg.pref_version = info->pref_version; + msg.pref_syntax = info->pref_syntax; + if (msg.pref_syntax < 0) + return -1; + + len = cep_msg__get_packed_size(&msg); + if (len == 0) + return -1; + + data = malloc(len); + if (data == NULL) + return -ENOMEM; + + cep_msg__pack(&msg, data); + + if (flow_write(fd, data, len) < 0) { + free(data); + return -1; + } + + free(data); + + return 0; +} + +int cep_snd(int fd, + const struct conn_info * in) +{ + if (in == NULL) + return -EINVAL; + + return send_msg(fd, in); +} + +int cep_rcv(int fd, + struct conn_info * out) +{ + if (out == NULL) + return -EINVAL; + + 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 -#include +#include +#include #include -#include #include +#include +#include #include +#include +#include #include #include #include #include -#include -#include -#include #include #include #include @@ -48,8 +48,8 @@ #include #include #include +#include #include -#include #ifdef PROC_FLOW_STATS #include #endif diff --git a/src/lib/pb/cacep.proto b/src/lib/pb/cacep.proto deleted file mode 100644 index 166e261d..00000000 --- a/src/lib/pb/cacep.proto +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2024 - * - * Message for Connection Information in CACEP - * - * Dimitri Staessens - * Sander Vrijders - * - * 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/. - */ - -syntax = "proto2"; - -message fixed_conc_syntax_msg { - repeated uint32 fids = 1; - repeated uint32 lens = 2; -} - -message cacep_msg { - required string comp_name = 1; - required string protocol = 2; - required int32 pref_version = 3; - repeated int32 supp_version = 4; - required int32 pref_syntax = 5; - repeated int32 supp_syntax = 6; - optional fixed_conc_syntax_msg syntax_spec = 7; - required uint64 address = 8; -} diff --git a/src/lib/pb/cep.proto b/src/lib/pb/cep.proto new file mode 100644 index 00000000..d31cf4f7 --- /dev/null +++ b/src/lib/pb/cep.proto @@ -0,0 +1,39 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Message for Connection Information in OCEP + * + * Dimitri Staessens + * Sander Vrijders + * + * 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/. + */ + +syntax = "proto2"; + +message fixed_conc_syntax_msg { + repeated uint32 fids = 1; + repeated uint32 lens = 2; +} + +message cep_msg { + required string comp_name = 1; + required string protocol = 2; + required int32 pref_version = 3; + repeated int32 supp_version = 4; + required int32 pref_syntax = 5; + repeated int32 supp_syntax = 6; + optional fixed_conc_syntax_msg syntax_spec = 7; + required uint64 address = 8; +} -- cgit v1.2.3