diff options
author | Dimitri Staessens <[email protected]> | 2024-01-21 10:59:17 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2024-01-31 10:27:56 +0100 |
commit | 02f68ff5ccc637b2177f832a4f7ddf4f9f737d22 (patch) | |
tree | eeef68d751d4feb0c95b3831b3e325d45ca9bc9b /src | |
parent | 396c311842ae7d138c13a6d054e1978d95af4c63 (diff) | |
download | ouroboros-02f68ff5ccc637b2177f832a4f7ddf4f9f737d22.tar.gz ouroboros-02f68ff5ccc637b2177f832a4f7ddf4f9f737d22.zip |
include: Use common definition between lib and IRMd
Some definitions/enums were different between the library and IRMd
(flow_state, ipcp_state). This moves them to common ground.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src')
-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 |
13 files changed, 35 insertions, 61 deletions
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); |