diff options
-rw-r--r-- | include/ouroboros/flow.h | 54 | ||||
-rw-r--r-- | include/ouroboros/ipcp.h | 49 | ||||
-rw-r--r-- | include/ouroboros/irm.h | 17 | ||||
-rw-r--r-- | src/ipcpd/broadcast/main.c | 7 | ||||
-rw-r--r-- | src/ipcpd/eth/eth.c | 2 | ||||
-rw-r--r-- | src/ipcpd/ipcp.h | 8 | ||||
-rw-r--r-- | src/ipcpd/local/main.c | 2 | ||||
-rw-r--r-- | src/ipcpd/udp/main.c | 3 | ||||
-rw-r--r-- | src/ipcpd/unicast/main.c | 4 | ||||
-rw-r--r-- | src/irmd/main.c | 24 | ||||
-rw-r--r-- | src/irmd/reg/flow.c | 1 | ||||
-rw-r--r-- | src/irmd/reg/flow.h | 9 | ||||
-rw-r--r-- | src/irmd/reg/ipcp.c | 2 | ||||
-rw-r--r-- | src/irmd/reg/ipcp.h | 6 | ||||
-rw-r--r-- | src/irmd/tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/lib/dev.c | 24 |
16 files changed, 125 insertions, 91 deletions
diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h new file mode 100644 index 00000000..e8c1dfdf --- /dev/null +++ b/include/ouroboros/flow.h @@ -0,0 +1,54 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Flows + * + * 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_FLOW_H +#define OUROBOROS_LIB_FLOW_H + +#include <ouroboros/qos.h> + +#include <sys/types.h> + + enum flow_state { /* DO NOT CHANGE ORDER! */ + FLOW_INIT = 0, + FLOW_ALLOC_PENDING, + FLOW_ALLOC_REQ_PENDING, + FLOW_ALLOCATED, + FLOW_DEALLOC_PENDING, + FLOW_DEALLOCATED, + FLOW_DESTROY, + FLOW_NULL +}; + +struct flow_info { + int id; + + pid_t n_pid; + pid_t n_1_pid; + + time_t mpl; + + struct qos_spec qs; + + enum flow_state state; +}; + +#endif /* OUROBOROS_LIB_FLOW_H */
\ No newline at end of file diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index a2c7720a..eb7d1670 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -26,17 +26,21 @@ #include <stdint.h> #include <unistd.h> #include <stdbool.h> +#include <sys/types.h> #define IPCP_NAME_SIZE 255 #define LAYER_NAME_SIZE 255 #define DEV_NAME_SIZE 255 -/* Unicast IPCP components. */ -#define DT_COMP "Data Transfer" -#define MGMT_COMP "Management" +enum ipcp_state { + IPCP_INIT = 0, + IPCP_BOOT, + IPCP_OPERATIONAL, + IPCP_SHUTDOWN, + IPCP_NULL +}; -/* NOTE: The IRMd uses this order to select an IPCP for flow allocation. */ -enum ipcp_type { +enum ipcp_type { /* IRMd uses order to select an IPCP for flow allocation. */ IPCP_LOCAL = 0, IPCP_UNICAST, IPCP_BROADCAST, @@ -46,6 +50,17 @@ enum ipcp_type { IPCP_INVALID }; +struct ipcp_info { + enum ipcp_type type; + pid_t pid; + char name[IPCP_NAME_SIZE + 1]; + enum ipcp_state state; +}; + +/* Unicast IPCP components. */ +#define DT_COMP "Data Transfer" +#define MGMT_COMP "Management" + /* Unicast IPCP policies */ enum pol_addr_auth { ADDR_AUTH_FLAT_RANDOM = 0, @@ -65,14 +80,6 @@ enum pol_cong_avoid { CA_INVALID }; -enum pol_dir_hash { - DIR_HASH_SHA3_224, - DIR_HASH_SHA3_256, - DIR_HASH_SHA3_384, - DIR_HASH_SHA3_512, - DIR_HASH_INVALID -}; - struct dt_config { uint8_t addr_size; uint8_t eid_size; @@ -98,16 +105,18 @@ struct udp_config { uint16_t port; }; -/* Info about the IPCP */ -struct ipcp_info { - enum ipcp_type type; - char name[IPCP_NAME_SIZE + 1]; +/* Layers */ +enum pol_dir_hash { + DIR_HASH_SHA3_224, + DIR_HASH_SHA3_256, + DIR_HASH_SHA3_384, + DIR_HASH_SHA3_512, + DIR_HASH_INVALID }; -/* Info reported back to the IRMd about the layer on enrollment */ struct layer_info { - char name[LAYER_NAME_SIZE + 1]; - int dir_hash_algo; + char name[LAYER_NAME_SIZE + 1]; + enum pol_dir_hash dir_hash_algo; }; /* Structure to configure the first IPCP */ diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index 9d55ebd4..30d461ab 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -31,27 +31,24 @@ /* Name binding options. */ #define BIND_AUTO 0x01 +#define NAME_SIZE 255 -#define NAME_SIZE 256 -#define LAYER_SIZE LAYER_NAME_SIZE - -/* Load balancing policy for incoming flows. */ 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; char name[NAME_SIZE]; - char layer[LAYER_SIZE]; -}; - -struct name_info { - char name[NAME_SIZE]; - enum pol_balance pol_lb; + char layer[LAYER_NAME_SIZE]; }; __BEGIN_DECLS diff --git a/src/ipcpd/broadcast/main.c b/src/ipcpd/broadcast/main.c index dbe64559..55d14b31 100644 --- a/src/ipcpd/broadcast/main.c +++ b/src/ipcpd/broadcast/main.c @@ -57,7 +57,7 @@ struct ipcp ipcpi; static int initialize_components(const struct ipcp_config * conf) { strcpy(ipcpi.layer_name, conf->layer_info.name); - ipcpi.dir_hash_algo = conf->layer_info.dir_hash_algo; + ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo; assert(ipcp_dir_hash_len() != 0); @@ -146,7 +146,7 @@ static int broadcast_ipcp_enroll(const char * dst, log_info_id(id, "Enrolled with %s.", dst); - info->dir_hash_algo = ipcpi.dir_hash_algo; + info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo; strcpy(info->name, ipcpi.layer_name); return 0; @@ -163,7 +163,8 @@ static int broadcast_ipcp_bootstrap(const struct ipcp_config * conf) { assert(conf); assert(conf->type == THIS_TYPE); - ((struct ipcp_config *) conf)->layer_info.dir_hash_algo = HASH_SHA3_256; + ((struct ipcp_config *) conf)->layer_info.dir_hash_algo = + DIR_HASH_SHA3_256; enroll_bootstrap(conf); diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c index 52525c38..6bac6c76 100644 --- a/src/ipcpd/eth/eth.c +++ b/src/ipcpd/eth/eth.c @@ -1247,7 +1247,7 @@ static int eth_ipcp_bootstrap(const struct ipcp_config * conf) assert(conf); assert(conf->type == THIS_TYPE); - ipcpi.dir_hash_algo = conf->layer_info.dir_hash_algo; + ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo; strcpy(ipcpi.layer_name, conf->layer_info.name); if (strlen(conf->eth.dev) >= IFNAMSIZ) { diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 0fcd8d8d..1ce07c57 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -34,14 +34,6 @@ #include <pthread.h> #include <time.h> -enum ipcp_state { - IPCP_NULL = 0, - IPCP_INIT, - /* Layer name must be set for states below. */ - IPCP_OPERATIONAL, - IPCP_SHUTDOWN -}; - struct ipcp_ops { int (* ipcp_bootstrap)(const struct ipcp_config * conf); diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 213b6538..717e35ce 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -144,7 +144,7 @@ static int local_ipcp_bootstrap(const struct ipcp_config * conf) assert(conf); assert(conf->type == THIS_TYPE); - ipcpi.dir_hash_algo = conf->layer_info.dir_hash_algo; + ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo; strcpy(ipcpi.layer_name,conf->layer_info.name); if (pthread_create(&local_data.packet_loop, NULL, diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index 2e500d24..c6181984 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -592,9 +592,8 @@ static int udp_ipcp_bootstrap(const struct ipcp_config * conf) assert(conf); assert(conf->type == THIS_TYPE); - ((struct ipcp_config *) conf)->layer_info.dir_hash_algo = HASH_MD5; - ipcpi.dir_hash_algo = conf->layer_info.dir_hash_algo; + ipcpi.dir_hash_algo = HASH_MD5; strcpy(ipcpi.layer_name, conf->layer_info.name); if (inet4_ntop(&conf->udp.ip_addr, ipstr) == NULL) { diff --git a/src/ipcpd/unicast/main.c b/src/ipcpd/unicast/main.c index f849e485..fed08d93 100644 --- a/src/ipcpd/unicast/main.c +++ b/src/ipcpd/unicast/main.c @@ -60,7 +60,7 @@ struct ipcp ipcpi; static int initialize_components(const struct ipcp_config * conf) { strcpy(ipcpi.layer_name, conf->layer_info.name); - ipcpi.dir_hash_algo = conf->layer_info.dir_hash_algo; + ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo; assert(ipcp_dir_hash_len() != 0); @@ -227,7 +227,7 @@ static int unicast_ipcp_enroll(const char * dst, log_info_id(id, "Enrolled with %s.", dst); - info->dir_hash_algo = ipcpi.dir_hash_algo; + info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo; strcpy(info->name, ipcpi.layer_name); return 0; diff --git a/src/irmd/main.c b/src/irmd/main.c index 20b70a60..31ac5edc 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -30,23 +30,23 @@ #define OUROBOROS_PREFIX "irmd" +#include <ouroboros/bitmap.h> #include <ouroboros/crypt.h> -#include <ouroboros/hash.h> #include <ouroboros/errno.h> -#include <ouroboros/sockets.h> -#include <ouroboros/list.h> -#include <ouroboros/utils.h> +#include <ouroboros/flow.h> +#include <ouroboros/hash.h> #include <ouroboros/irm.h> +#include <ouroboros/list.h> #include <ouroboros/lockfile.h> +#include <ouroboros/logs.h> +#include <ouroboros/pthread.h> #include <ouroboros/shm_rbuff.h> #include <ouroboros/shm_rdrbuff.h> -#include <ouroboros/bitmap.h> -#include <ouroboros/qos.h> +#include <ouroboros/sockets.h> #include <ouroboros/time_utils.h> #include <ouroboros/tpm.h> -#include <ouroboros/logs.h> +#include <ouroboros/utils.h> #include <ouroboros/version.h> -#include <ouroboros/pthread.h> #include "irmd.h" #include "ipcp.h" @@ -586,7 +586,9 @@ static int create_ipcp_r(pid_t pid, list_for_each(p, &irmd.ipcps) { struct reg_ipcp * e = list_entry(p, struct reg_ipcp, next); if (e->pid == pid) { - reg_ipcp_set_state(e, result ? IPCP_NULL : IPCP_LIVE); + enum ipcp_state state; + state = result ? IPCP_NULL : IPCP_OPERATIONAL; + reg_ipcp_set_state(e, state); break; } } @@ -660,7 +662,7 @@ int bootstrap_ipcp(pid_t pid, return -ENOMEM; } - ipcp->dir_hash_algo = info.dir_hash_algo; + ipcp->dir_hash_algo = (enum hash_algo) info.dir_hash_algo; pthread_rwlock_unlock(&irmd.reg_lock); @@ -714,7 +716,7 @@ int enroll_ipcp(pid_t pid, return -ENOMEM; } - ipcp->dir_hash_algo = info.dir_hash_algo; + ipcp->dir_hash_algo = (enum hash_algo) info.dir_hash_algo; pthread_rwlock_unlock(&irmd.reg_lock); diff --git a/src/irmd/reg/flow.c b/src/irmd/reg/flow.c index 43d6cb3a..66bd25a3 100644 --- a/src/irmd/reg/flow.c +++ b/src/irmd/reg/flow.c @@ -27,6 +27,7 @@ #define OUROBOROS_PREFIX "reg-flow" #include <ouroboros/errno.h> +#include <ouroboros/flow.h> #include <ouroboros/logs.h> #include <ouroboros/time_utils.h> #include <ouroboros/pthread.h> diff --git a/src/irmd/reg/flow.h b/src/irmd/reg/flow.h index 76266228..22e191be 100644 --- a/src/irmd/reg/flow.h +++ b/src/irmd/reg/flow.h @@ -32,15 +32,6 @@ #include <pthread.h> #include <time.h> -enum flow_state { - FLOW_NULL = 0, - FLOW_ALLOC_PENDING, - FLOW_ALLOC_REQ_PENDING, - FLOW_ALLOCATED, - FLOW_DEALLOC_PENDING, - FLOW_DESTROY -}; - struct reg_flow { struct list_head next; diff --git a/src/irmd/reg/ipcp.c b/src/irmd/reg/ipcp.c index de4b2f1e..c1d06d94 100644 --- a/src/irmd/reg/ipcp.c +++ b/src/irmd/reg/ipcp.c @@ -134,7 +134,7 @@ int reg_ipcp_wait_boot(struct reg_ipcp * ipcp) pthread_cond_signal(&ipcp->cond); } - if (ipcp->state != IPCP_LIVE) { + if (ipcp->state != IPCP_OPERATIONAL) { pthread_mutex_unlock(&ipcp->mtx); return -1; } diff --git a/src/irmd/reg/ipcp.h b/src/irmd/reg/ipcp.h index c669a0e1..6dfdfb6b 100644 --- a/src/irmd/reg/ipcp.h +++ b/src/irmd/reg/ipcp.h @@ -25,12 +25,6 @@ #include <ouroboros/list.h> -enum ipcp_state { - IPCP_NULL = 0, - IPCP_BOOT, - IPCP_LIVE -}; - struct reg_ipcp { struct list_head next; diff --git a/src/irmd/tests/CMakeLists.txt b/src/irmd/tests/CMakeLists.txt index 68bd762d..e1fd2f21 100644 --- a/src/irmd/tests/CMakeLists.txt +++ b/src/irmd/tests/CMakeLists.txt @@ -2,11 +2,11 @@ get_filename_component(tmp ".." ABSOLUTE) get_filename_component(src_folder "${tmp}" NAME) create_test_sourcelist(${src_folder}_tests test_suite.c - # Add new tests here + # Add new tests here ) add_executable(${src_folder}_test EXCLUDE_FROM_ALL ${${src_folder}_tests}) -target_link_libraries(${src_folder}_test ouroboros) +target_link_libraries(${src_folder}_test ouroboros-common) add_dependencies(check ${src_folder}_test) diff --git a/src/lib/dev.c b/src/lib/dev.c index 303becd5..216bf670 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -33,6 +33,8 @@ #include <ouroboros/crypt.h> #include <ouroboros/errno.h> #include <ouroboros/dev.h> +#include <ouroboros/flow.h> +#include <ouroboros/ipcp.h> #include <ouroboros/ipcp-dev.h> #include <ouroboros/list.h> #include <ouroboros/local-dev.h> @@ -74,14 +76,6 @@ #define SECMEMSZ 16384 #define MSGBUFSZ 2048 -enum flow_state { - FLOW_NULL = 0, - FLOW_INIT, - FLOW_ID_PENDING, - FLOW_ID_ASSIGNED, - FLOW_DESTROY -}; - /* map flow_ids to flow descriptors; track state of the flow */ struct fmap { int fd; @@ -157,7 +151,7 @@ static void flow_destroy(struct fmap * p) return; } - if (p->state == FLOW_ID_PENDING) + if (p->state == FLOW_ALLOC_PENDING) p->state = FLOW_DESTROY; else p->state = FLOW_NULL; @@ -200,17 +194,17 @@ static enum flow_state flow_wait_assign(int flow_id) pthread_mutex_lock(&ai.mtx); - if (p->state == FLOW_ID_ASSIGNED) { + if (p->state == FLOW_ALLOCATED) { pthread_mutex_unlock(&ai.mtx); - return FLOW_ID_ASSIGNED; + return FLOW_ALLOCATED; } if (p->state == FLOW_INIT) - p->state = FLOW_ID_PENDING; + p->state = FLOW_ALLOC_PENDING; pthread_cleanup_push(__cleanup_mutex_unlock, &ai.mtx); - while (p->state == FLOW_ID_PENDING) + while (p->state == FLOW_ALLOC_PENDING) pthread_cond_wait(&ai.cond, &ai.mtx); if (p->state == FLOW_DESTROY) { @@ -503,7 +497,7 @@ static int flow_init(int flow_id, ai.id_to_fd[flow_id].fd = fd; - flow_set_state(&ai.id_to_fd[flow_id], FLOW_ID_ASSIGNED); + flow_set_state(&ai.id_to_fd[flow_id], FLOW_ALLOCATED); pthread_rwlock_unlock(&ai.lock); @@ -1795,7 +1789,7 @@ int np1_flow_resp(int flow_id) { int fd; - if (flow_wait_assign(flow_id) != FLOW_ID_ASSIGNED) + if (flow_wait_assign(flow_id) != FLOW_ALLOCATED) return -1; pthread_rwlock_rdlock(&ai.lock); |