summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-04-16 12:04:59 +0200
committerdimitri staessens <[email protected]>2017-04-16 13:40:12 +0200
commit97ef24340da7d3f55a39ba16b400d13f9bbe9e60 (patch)
treee13656c267343db47a4f79d2098222909222736d /src/irmd
parentc884fb9d6b3d3ea59f5fc7c5d709bfff4fcf1849 (diff)
downloadouroboros-97ef24340da7d3f55a39ba16b400d13f9bbe9e60.tar.gz
ouroboros-97ef24340da7d3f55a39ba16b400d13f9bbe9e60.zip
ipcpd: Allow specifying the hash algorithm to use
Currently CRC32, MD5, and SHA3 (224, 256, 384 and 512 bit) are supported.
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/ipcp.c1
-rw-r--r--src/irmd/main.c43
-rw-r--r--src/irmd/registry.c4
-rw-r--r--src/irmd/registry.h2
4 files changed, 28 insertions, 22 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index f0e57dc8..7a32dd88 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -212,6 +212,7 @@ int ipcp_bootstrap(pid_t api,
return ret;
}
+/* return the hash algorithm */
int ipcp_enroll(pid_t api,
const char * dst)
{
diff --git a/src/irmd/main.c b/src/irmd/main.c
index bdc03ef8..7e118f81 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -37,7 +37,6 @@
#include <ouroboros/qos.h>
#include <ouroboros/time_utils.h>
#include <ouroboros/logs.h>
-#include <ouroboros/sha3.h>
#include "utils.h"
#include "registry.h"
@@ -57,6 +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))
struct ipcp_entry {
struct list_head next;
@@ -64,8 +64,7 @@ struct ipcp_entry {
char * name;
pid_t api;
enum ipcp_type type;
- uint16_t dir_hash_len;
- /* FIXME: add an enum to specify hash algo */
+ enum hash_algo dir_hash_algo;
char * dif_name;
pthread_cond_t init_cond;
@@ -239,13 +238,15 @@ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name)
list_for_each(p, &irmd.ipcps) {
struct ipcp_entry * e =
list_entry(p, struct ipcp_entry, next);
- hash = malloc(e->dir_hash_len);
+ if (e->dir_hash_algo < 0)
+ continue;
+ hash = malloc(IPCP_HASH_LEN(e));
if (hash == NULL)
return NULL;
- get_hash(hash, name);
+ str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_query(e->api, hash, e->dir_hash_len) == 0) {
+ if (ipcp_query(e->api, hash, hash_len(e->dir_hash_algo)) == 0) {
free(hash);
return e;
}
@@ -306,8 +307,7 @@ static pid_t create_ipcp(char * name,
tmp->dif_name = NULL;
tmp->type = ipcp_type;
tmp->init = false;
- /* FIXME: ipcp dir_hash_len should be configurable */
- tmp->dir_hash_len = SHA3_256_HASH_LEN;
+ tmp->dir_hash_algo = -1;
list_for_each(p, &irmd.ipcps) {
struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
@@ -434,6 +434,8 @@ static int bootstrap_ipcp(pid_t api,
return -ENOMEM;
}
+ entry->dir_hash_algo = conf->dir_hash_algo;
+
pthread_rwlock_unlock(&irmd.reg_lock);
log_info("Bootstrapped IPCP %d in DIF %s.",
@@ -471,7 +473,8 @@ static int enroll_ipcp(pid_t api,
pthread_rwlock_unlock(&irmd.reg_lock);
- if (ipcp_enroll(api, dif_name)) {
+ 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;
@@ -766,13 +769,13 @@ static int name_reg(const char * name,
if (wildcard_match(difs[i], e->dif_name))
continue;
- hash = malloc(e->dir_hash_len);
+ hash = malloc(IPCP_HASH_LEN(e));
if (hash == NULL)
break;
- get_hash(hash, name);
+ str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_reg(e->api, hash, e->dir_hash_len)) {
+ if (ipcp_reg(e->api, hash, IPCP_HASH_LEN(e))) {
log_err("Could not register " HASH_FMT
" in DIF %s.",
HASH_VAL(hash), e->dif_name);
@@ -826,13 +829,13 @@ static int name_unreg(const char * name,
if (wildcard_match(difs[i], e->dif_name))
continue;
- hash = malloc(e->dir_hash_len);
+ hash = malloc(IPCP_HASH_LEN(e));
if (hash == NULL)
break;
- get_hash(hash, name);
+ str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_unreg(e->api, hash, e->dir_hash_len)) {
+ if (ipcp_unreg(e->api, hash, IPCP_HASH_LEN(e))) {
log_err("Could not unregister %s in DIF %s.",
name, e->dif_name);
} else {
@@ -1097,16 +1100,16 @@ static int flow_alloc(pid_t api,
assert(irm_flow_get_state(f) == FLOW_ALLOC_PENDING);
- hash = malloc(ipcp->dir_hash_len);
+ hash = malloc(IPCP_HASH_LEN(ipcp));
if (hash == NULL) {
/* sanitizer cleans this */
return -ENOMEM;
}
- get_hash(hash, dst);
+ str_hash(ipcp->dir_hash_algo, hash, dst);
if (ipcp_flow_alloc(ipcp->api, port_id, api, hash,
- ipcp->dir_hash_len, cube)) {
+ IPCP_HASH_LEN(ipcp), cube)) {
/* sanitizer cleans this */
log_info("Flow_allocation failed.");
free(hash);
@@ -1248,8 +1251,8 @@ static struct irm_flow * flow_req_arr(pid_t api,
return NULL;
}
- re = registry_get_entry_by_hash(&irmd.registry, hash,
- ipcp->dir_hash_len);
+ re = registry_get_entry_by_hash(&irmd.registry, ipcp->dir_hash_algo,
+ hash, IPCP_HASH_LEN(ipcp));
if (re == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("Unknown hash: " HASH_FMT ".", HASH_VAL(hash));
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index 71e6ea8a..e6571564 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -27,7 +27,6 @@
#include <ouroboros/logs.h>
#include <ouroboros/irm.h>
#include <ouroboros/time_utils.h>
-#include <ouroboros/hash.h>
#include "registry.h"
#include "utils.h"
@@ -522,6 +521,7 @@ struct reg_entry * registry_get_entry(struct list_head * registry,
}
struct reg_entry * registry_get_entry_by_hash(struct list_head * registry,
+ enum hash_algo algo,
const uint8_t * hash,
size_t len)
{
@@ -536,7 +536,7 @@ struct reg_entry * registry_get_entry_by_hash(struct list_head * registry,
list_for_each(p, registry) {
struct reg_entry * e = list_entry(p, struct reg_entry, next);
- get_hash(thash, e->name);
+ str_hash(algo, thash, e->name);
if (memcmp(thash, hash, len) == 0) {
free(thash);
return e;
diff --git a/src/irmd/registry.h b/src/irmd/registry.h
index 771ca83c..29cefc02 100644
--- a/src/irmd/registry.h
+++ b/src/irmd/registry.h
@@ -24,6 +24,7 @@
#define OUROBOROS_IRMD_REGISTRY_H
#include <ouroboros/config.h>
+#include <ouroboros/hash.h>
#include <ouroboros/ipcp.h>
#include <ouroboros/list.h>
#include <ouroboros/shared.h>
@@ -115,6 +116,7 @@ struct reg_entry * registry_get_entry(struct list_head * registry,
const char * name);
struct reg_entry * registry_get_entry_by_hash(struct list_head * registry,
+ enum hash_algo algo,
const uint8_t * hash,
size_t len);