diff options
author | dimitri staessens <[email protected]> | 2017-04-26 20:31:39 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2017-04-27 17:59:01 +0200 |
commit | b398dbe5cfd12b928e00f9a22cd6826bbdfb18d7 (patch) | |
tree | 137c34f79897b5f371a65dd14208b77201d1e907 /src/irmd | |
parent | 6d6a4a488d7b631f519b1cf462ffbb44d399e1ce (diff) | |
download | ouroboros-b398dbe5cfd12b928e00f9a22cd6826bbdfb18d7.tar.gz ouroboros-b398dbe5cfd12b928e00f9a22cd6826bbdfb18d7.zip |
ipcpd: Add capability reporting
The IPCP will now report the DIF name and the hash value to the IRMd
as a dif_info struct. This can later be extended to add further
capability reporting. Some bugfixes in normal.
Fixes #24
Diffstat (limited to 'src/irmd')
-rw-r--r-- | src/irmd/ipcp.c | 26 | ||||
-rw-r--r-- | src/irmd/ipcp.h | 7 | ||||
-rw-r--r-- | src/irmd/main.c | 64 |
3 files changed, 61 insertions, 36 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index 7a32dd88..182970b1 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -212,13 +212,13 @@ int ipcp_bootstrap(pid_t api, return ret; } -/* return the hash algorithm */ -int ipcp_enroll(pid_t api, - const char * dst) +int ipcp_enroll(pid_t api, + const char * dst, + struct dif_info * info) { - ipcp_msg_t msg = IPCP_MSG__INIT; + ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; if (dst == NULL) return -EINVAL; @@ -236,9 +236,23 @@ int ipcp_enroll(pid_t api, } ret = recv_msg->result; + if (ret != 0) { + ipcp_msg__free_unpacked(recv_msg, NULL); + return ret; + } + + if (!recv_msg->has_dir_hash_algo || recv_msg->dif_name == NULL) { + ipcp_msg__free_unpacked(recv_msg, NULL); + return -EIPCP; + } + + info->algo = recv_msg->dir_hash_algo; + + strcpy(info->dif_name, recv_msg->dif_name); + ipcp_msg__free_unpacked(recv_msg, NULL); - return ret; + return 0; } int ipcp_reg(pid_t api, diff --git a/src/irmd/ipcp.h b/src/irmd/ipcp.h index 11adad7d..74175f97 100644 --- a/src/irmd/ipcp.h +++ b/src/irmd/ipcp.h @@ -34,10 +34,11 @@ pid_t ipcp_create(const char * name, int ipcp_destroy(pid_t api); -int ipcp_enroll(pid_t api, - const char * dst); +int ipcp_enroll(pid_t api, + const char * dst, + struct dif_info * info); -int ipcp_bootstrap(pid_t api, +int ipcp_bootstrap(pid_t api, ipcp_config_msg_t * conf); int ipcp_reg(pid_t api, diff --git a/src/irmd/main.c b/src/irmd/main.c index 45a348ae..67c2ad60 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -56,7 +56,7 @@ #define IRMD_CLEANUP_TIMER ((IRMD_FLOW_TIMEOUT / 20) * MILLION) /* ns */ #define SHM_SAN_HOLDOFF 1000 /* ms */ -#define IPCP_HASH_LEN(e) (hash_len(e->dir_hash_algo)) +#define IPCP_HASH_LEN(e) hash_len(e->dir_hash_algo) struct ipcp_entry { struct list_head next; @@ -226,27 +226,26 @@ static struct ipcp_entry * get_ipcp_entry_by_name(const char * name) return NULL; } -/* - * Check if the hash is reachable anywhere in a DIF. - * FIXME: specify algorithm used - */ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name) { struct list_head * p = NULL; uint8_t * hash; list_for_each(p, &irmd.ipcps) { - struct ipcp_entry * e = - list_entry(p, struct ipcp_entry, next); - if (e->dir_hash_algo < 0) + struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next); + if (e->dif_name == NULL) continue; + + log_dbg("IPCP %s found for name %s with hash enum %d.", + e->dif_name, name, e->dir_hash_algo); + hash = malloc(IPCP_HASH_LEN(e)); if (hash == NULL) return NULL; str_hash(e->dir_hash_algo, hash, name); - if (ipcp_query(e->api, hash, hash_len(e->dir_hash_algo)) == 0) { + if (ipcp_query(e->api, hash, IPCP_HASH_LEN(e)) == 0) { free(hash); return e; } @@ -319,10 +318,10 @@ static pid_t create_ipcp(char * name, list_add(&api->next, &irmd.spawned_apis); - pthread_mutex_lock(&tmp->init_lock); - pthread_rwlock_unlock(&irmd.reg_lock); + pthread_mutex_lock(&tmp->init_lock); + while (tmp->init == false) pthread_cond_wait(&tmp->init_cond, &tmp->init_lock); @@ -401,7 +400,7 @@ static int destroy_ipcp(pid_t api) return 0; } -static int bootstrap_ipcp(pid_t api, +static int bootstrap_ipcp(pid_t api, ipcp_config_msg_t * conf) { struct ipcp_entry * entry = NULL; @@ -445,9 +444,10 @@ static int bootstrap_ipcp(pid_t api, } static int enroll_ipcp(pid_t api, - char * dif_name) + char * dst_name) { struct ipcp_entry * entry = NULL; + struct dif_info info; pthread_rwlock_wrlock(&irmd.reg_lock); @@ -464,27 +464,35 @@ static int enroll_ipcp(pid_t api, return -1; } - entry->dif_name = strdup(dif_name); - if (entry->dif_name == NULL) { - pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Failed to strdup."); + pthread_rwlock_unlock(&irmd.reg_lock); + + if (ipcp_enroll(api, dst_name, &info) < 0) { + log_err("Could not enroll IPCP."); return -1; } - pthread_rwlock_unlock(&irmd.reg_lock); + pthread_rwlock_wrlock(&irmd.reg_lock); - entry->dir_hash_algo = ipcp_enroll(api, dif_name); - if (entry->dir_hash_algo < 0) { - pthread_rwlock_wrlock(&irmd.reg_lock); - free(entry->dif_name); - entry->dif_name = NULL; + entry = get_ipcp_entry_by_api(api); + if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Could not enroll IPCP."); + log_err("No such IPCP."); return -1; } + entry->dif_name = strdup(info.dif_name); + if (entry->dif_name == NULL) { + pthread_rwlock_unlock(&irmd.reg_lock); + log_err("Failed to strdup dif_name."); + return -ENOMEM; + } + + entry->dir_hash_algo = info.algo; + + pthread_rwlock_unlock(&irmd.reg_lock); + log_info("Enrolled IPCP %d in DIF %s.", - api, dif_name); + api, info.dif_name); return 0; } @@ -769,6 +777,9 @@ static int name_reg(const char * name, if (wildcard_match(difs[i], e->dif_name)) continue; + log_dbg("gonna register %s in dif %s.", + name, e->dif_name); + hash = malloc(IPCP_HASH_LEN(e)); if (hash == NULL) break; @@ -1101,10 +1112,9 @@ static int flow_alloc(pid_t api, assert(irm_flow_get_state(f) == FLOW_ALLOC_PENDING); hash = malloc(IPCP_HASH_LEN(ipcp)); - if (hash == NULL) { + if (hash == NULL) /* sanitizer cleans this */ return -ENOMEM; - } str_hash(ipcp->dir_hash_algo, hash, dst); |