summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-13 09:55:31 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-13 09:55:31 +0000
commit72c28d6173ade511e9dc6969e0fc66db2dbba38a (patch)
tree12756b89d8f4ce421c70d5cf05850b4968e76412 /src/irmd
parent2cc9c8d742e037c8a6ddc3eea4c05f4a905183d3 (diff)
parentfc10a7587b1a642748ae0fd69f08d92b4a902248 (diff)
downloadouroboros-72c28d6173ade511e9dc6969e0fc66db2dbba38a.tar.gz
ouroboros-72c28d6173ade511e9dc6969e0fc66db2dbba38a.zip
Merged in dstaesse/ouroboros/be-hashes (pull request #479)
lib, ipcpd, irmd: Register hash instead of name
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/apn_table.c2
-rw-r--r--src/irmd/ipcp.c113
-rw-r--r--src/irmd/ipcp.h42
-rw-r--r--src/irmd/main.c188
-rw-r--r--src/irmd/registry.c57
-rw-r--r--src/irmd/registry.h22
6 files changed, 253 insertions, 171 deletions
diff --git a/src/irmd/apn_table.c b/src/irmd/apn_table.c
index d265e2f0..c77e7128 100644
--- a/src/irmd/apn_table.c
+++ b/src/irmd/apn_table.c
@@ -21,7 +21,7 @@
*/
#include <ouroboros/errno.h>
-#include <ouroboros/irm_config.h>
+#include <ouroboros/irm.h>
#include "apn_table.h"
#include "utils.h"
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index eb0c2de0..f0e57dc8 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -104,15 +104,15 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
return recv_msg;
}
-pid_t ipcp_create(char * name,
+pid_t ipcp_create(const char * name,
enum ipcp_type ipcp_type)
{
- pid_t api = -1;
- char irmd_api[10];
- size_t len = 0;
- char * ipcp_dir = "/sbin/";
+ pid_t api = -1;
+ size_t len = 0;
+ char * ipcp_dir = "/sbin/";
char * full_name = NULL;
char * exec_name = NULL;
+ char irmd_api[10];
char * argv[5];
sprintf(irmd_api, "%u", getpid());
@@ -157,13 +157,11 @@ pid_t ipcp_create(char * name,
/* log_file to be placed at the end */
argv[0] = full_name;
argv[1] = irmd_api;
- argv[2] = name;
- if (log_syslog) {
+ argv[2] = (char *) name;
+ if (log_syslog)
argv[3] = "1";
- argv[4] = NULL;
- } else {
+ else
argv[3] = NULL;
- }
argv[4] = NULL;
@@ -187,7 +185,7 @@ int ipcp_destroy(pid_t api)
}
int ipcp_bootstrap(pid_t api,
- dif_config_msg_t * conf)
+ ipcp_config_msg_t * conf)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
@@ -201,11 +199,11 @@ int ipcp_bootstrap(pid_t api,
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -214,26 +212,26 @@ int ipcp_bootstrap(pid_t api,
return ret;
}
-int ipcp_enroll(pid_t api,
- char * dif_name)
+int ipcp_enroll(pid_t api,
+ const char * dst)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
- if (dif_name == NULL)
+ if (dst == NULL)
return -EINVAL;
- msg.code = IPCP_MSG_CODE__IPCP_ENROLL;
- msg.dif_name = dif_name;
+ msg.code = IPCP_MSG_CODE__IPCP_ENROLL;
+ msg.dst_name = (char *) dst;
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -242,26 +240,28 @@ int ipcp_enroll(pid_t api,
return ret;
}
-int ipcp_name_reg(pid_t api,
- char * name)
+int ipcp_reg(pid_t api,
+ const uint8_t * hash,
+ size_t len)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL)
- return -1;
+ assert(hash);
- msg.code = IPCP_MSG_CODE__IPCP_NAME_REG;
- msg.name = name;
+ msg.code = IPCP_MSG_CODE__IPCP_REG;
+ msg.has_hash = true;
+ msg.hash.len = len;
+ msg.hash.data = (uint8_t *)hash;
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -270,23 +270,26 @@ int ipcp_name_reg(pid_t api,
return ret;
}
-int ipcp_name_unreg(pid_t api,
- char * name)
+int ipcp_unreg(pid_t api,
+ const uint8_t * hash,
+ size_t len)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
- msg.code = IPCP_MSG_CODE__IPCP_NAME_UNREG;
- msg.name = name;
+ msg.code = IPCP_MSG_CODE__IPCP_UNREG;
+ msg.has_hash = true;
+ msg.hash.len = len;
+ msg.hash.data = (uint8_t *) hash;
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -295,23 +298,26 @@ int ipcp_name_unreg(pid_t api,
return ret;
}
-int ipcp_name_query(pid_t api,
- char * name)
+int ipcp_query(pid_t api,
+ const uint8_t * hash,
+ size_t len)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
- msg.code = IPCP_MSG_CODE__IPCP_NAME_QUERY;
- msg.name = name;
+ msg.code = IPCP_MSG_CODE__IPCP_QUERY;
+ msg.has_hash = true;
+ msg.hash.len = len;
+ msg.hash.data = (uint8_t *) hash;
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -320,35 +326,37 @@ int ipcp_name_query(pid_t api,
return ret;
}
-int ipcp_flow_alloc(pid_t api,
- int port_id,
- pid_t n_api,
- char * dst_name,
- qoscube_t cube)
+int ipcp_flow_alloc(pid_t api,
+ int port_id,
+ pid_t n_api,
+ const uint8_t * dst,
+ size_t len,
+ qoscube_t cube)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
- if (dst_name == NULL)
- return -EINVAL;
+ assert(dst);
msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC;
msg.has_port_id = true;
msg.port_id = port_id;
msg.has_api = true;
msg.api = n_api;
- msg.dst_name = dst_name;
+ msg.has_hash = true;
+ msg.hash.len = len;
+ msg.hash.data = (uint8_t *) dst;
msg.has_qoscube = true;
msg.qoscube = cube;
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (!recv_msg->has_result) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -376,11 +384,11 @@ int ipcp_flow_alloc_resp(pid_t api,
recv_msg = send_recv_ipcp_msg(api, &msg);
if (recv_msg == NULL)
- return -1;
+ return -EIPCP;
if (recv_msg->has_result == false) {
ipcp_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIPCP;
}
ret = recv_msg->result;
@@ -392,7 +400,6 @@ int ipcp_flow_alloc_resp(pid_t api,
int ipcp_flow_dealloc(pid_t api,
int port_id)
{
-
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
diff --git a/src/irmd/ipcp.h b/src/irmd/ipcp.h
index bb868191..11adad7d 100644
--- a/src/irmd/ipcp.h
+++ b/src/irmd/ipcp.h
@@ -20,40 +20,44 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <ouroboros/irm_config.h>
+#include <ouroboros/ipcp.h>
#include <ouroboros/sockets.h>
#include <ouroboros/shared.h>
#include <sys/types.h>
-#ifndef OUROBOROS_IPCP_H
-#define OUROBOROS_IPCP_H
+#ifndef OUROBOROS_IRMD_IPCP_H
+#define OUROBOROS_IRMD_IPCP_H
-pid_t ipcp_create(char * name,
+pid_t ipcp_create(const char * name,
enum ipcp_type ipcp_type);
int ipcp_destroy(pid_t api);
-int ipcp_enroll(pid_t api,
- char * dif_name);
+int ipcp_enroll(pid_t api,
+ const char * dst);
int ipcp_bootstrap(pid_t api,
- dif_config_msg_t * conf);
+ ipcp_config_msg_t * conf);
-int ipcp_name_reg(pid_t api,
- char * name);
+int ipcp_reg(pid_t api,
+ const uint8_t * hash,
+ size_t len);
-int ipcp_name_unreg(pid_t api,
- char * name);
+int ipcp_unreg(pid_t api,
+ const uint8_t * hash,
+ size_t len);
-int ipcp_name_query(pid_t api,
- char * name);
+int ipcp_query(pid_t api,
+ const uint8_t * hash,
+ size_t len);
-int ipcp_flow_alloc(pid_t api,
- int port_id,
- pid_t n_api,
- char * dst_name,
- qoscube_t qos);
+int ipcp_flow_alloc(pid_t api,
+ int port_id,
+ pid_t n_api,
+ const uint8_t * dst,
+ size_t len,
+ qoscube_t qos);
int ipcp_flow_alloc_resp(pid_t api,
int port_id,
@@ -63,4 +67,4 @@ int ipcp_flow_alloc_resp(pid_t api,
int ipcp_flow_dealloc(pid_t api,
int port_id);
-#endif /* OUROBOROS_IPCP_H */
+#endif /* OUROBOROS_IRMD_IPCP_H */
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 23acfcee..d24c0ba1 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -27,7 +27,8 @@
#include <ouroboros/sockets.h>
#include <ouroboros/list.h>
#include <ouroboros/utils.h>
-#include <ouroboros/irm_config.h>
+#include <ouroboros/hash.h>
+#include <ouroboros/irm.h>
#include <ouroboros/lockfile.h>
#include <ouroboros/shm_flow_set.h>
#include <ouroboros/shm_rbuff.h>
@@ -36,6 +37,7 @@
#include <ouroboros/qos.h>
#include <ouroboros/time_utils.h>
#include <ouroboros/logs.h>
+#include <ouroboros/sha3.h>
#include "utils.h"
#include "registry.h"
@@ -62,6 +64,8 @@ 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 */
char * dif_name;
pthread_cond_t init_cond;
@@ -223,48 +227,33 @@ static struct ipcp_entry * get_ipcp_entry_by_name(const char * name)
return NULL;
}
-/* Check if the name exists anywhere in a DIF. */
-static pid_t get_ipcp_by_dst_name(char * dst_name)
+/*
+ * 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->type == IPCP_LOCAL) {
- if (ipcp_name_query(e->api, dst_name) == 0)
- return e->api;
- }
- }
+ hash = malloc(e->dir_hash_len);
+ if (hash == NULL)
+ return NULL;
- list_for_each(p, &irmd.ipcps) {
- struct ipcp_entry * e =
- list_entry(p, struct ipcp_entry, next);
- if (e->type == IPCP_NORMAL) {
- if (ipcp_name_query(e->api, dst_name) == 0)
- return e->api;
- }
- }
+ get_hash(hash, name);
- list_for_each(p, &irmd.ipcps) {
- struct ipcp_entry * e =
- list_entry(p, struct ipcp_entry, next);
- if (e->type == IPCP_SHIM_ETH_LLC) {
- if (ipcp_name_query(e->api, dst_name) == 0)
- return e->api;
+ if (ipcp_query(e->api, hash, e->dir_hash_len) == 0) {
+ free(hash);
+ return e;
}
- }
- list_for_each(p, &irmd.ipcps) {
- struct ipcp_entry * e =
- list_entry(p, struct ipcp_entry, next);
- if (e->type == IPCP_SHIM_UDP) {
- if (ipcp_name_query(e->api, dst_name) == 0)
- return e->api;
- }
+ free(hash);
}
- return -1;
+ return NULL;
}
static pid_t create_ipcp(char * name,
@@ -317,14 +306,16 @@ 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;
list_for_each(p, &irmd.ipcps) {
struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
- if (e->type < ipcp_type)
+ if (e->type > ipcp_type)
break;
}
- list_add(&tmp->next, &irmd.ipcps);
+ list_add_tail(&tmp->next, &irmd.ipcps);
list_add(&api->next, &irmd.spawned_apis);
@@ -411,7 +402,7 @@ static int destroy_ipcp(pid_t api)
}
static int bootstrap_ipcp(pid_t api,
- dif_config_msg_t * conf)
+ ipcp_config_msg_t * conf)
{
struct ipcp_entry * entry = NULL;
@@ -709,16 +700,18 @@ static ssize_t list_ipcps(char * name,
return count;
}
-static int name_reg(char * name,
- char ** difs,
- size_t len)
+static int name_reg(const char * name,
+ char ** difs,
+ size_t len)
{
size_t i;
int ret = 0;
struct list_head * p = NULL;
- if (name == NULL || difs == NULL || len == 0 || difs[0] == NULL)
- return -EINVAL;
+ assert(name);
+ assert(len);
+ assert(difs);
+ assert(difs[0]);
pthread_rwlock_wrlock(&irmd.reg_lock);
@@ -729,7 +722,7 @@ static int name_reg(char * name,
if (!registry_has_name(&irmd.registry, name)) {
struct reg_entry * re =
- registry_add_name(&irmd.registry, strdup(name));
+ registry_add_name(&irmd.registry, name);
if (re == NULL) {
log_err("Failed creating registry entry for %s.", name);
pthread_rwlock_unlock(&irmd.reg_lock);
@@ -768,12 +761,21 @@ static int name_reg(char * name,
continue;
for (i = 0; i < len; ++i) {
+ uint8_t * hash;
+
if (wildcard_match(difs[i], e->dif_name))
continue;
- if (ipcp_name_reg(e->api, name)) {
- log_err("Could not register %s in DIF %s.",
- name, e->dif_name);
+ hash = malloc(e->dir_hash_len);
+ if (hash == NULL)
+ break;
+
+ get_hash(hash, name);
+
+ if (ipcp_reg(e->api, hash, e->dir_hash_len)) {
+ log_err("Could not register " HASH_FMT
+ " in DIF %s.",
+ HASH_VAL(hash), e->dif_name);
} else {
if (registry_add_name_to_dif(&irmd.registry,
name,
@@ -782,10 +784,12 @@ static int name_reg(char * name,
log_warn("Registered unbound name %s. "
"Registry may be corrupt.",
name);
- log_info("Registered %s in %s as %s.",
- name, e->dif_name, name);
+ log_info("Registered %s in %s as " HASH_FMT ".",
+ name, e->dif_name, HASH_VAL(hash));
++ret;
}
+
+ free(hash);
}
}
@@ -794,16 +798,18 @@ static int name_reg(char * name,
return (ret > 0 ? 0 : -1);
}
-static int name_unreg(char * name,
- char ** difs,
- size_t len)
+static int name_unreg(const char * name,
+ char ** difs,
+ size_t len)
{
size_t i;
int ret = 0;
struct list_head * pos = NULL;
- if (name == NULL || len == 0 || difs == NULL || difs[0] == NULL)
- return -1;
+ assert(name);
+ assert(len);
+ assert(difs);
+ assert(difs[0]);
pthread_rwlock_wrlock(&irmd.reg_lock);
@@ -815,10 +821,18 @@ static int name_unreg(char * name,
continue;
for (i = 0; i < len; ++i) {
+ uint8_t * hash;
+
if (wildcard_match(difs[i], e->dif_name))
continue;
- if (ipcp_name_unreg(e->api, name)) {
+ hash = malloc(e->dir_hash_len);
+ if (hash == NULL)
+ break;
+
+ get_hash(hash, name);
+
+ if (ipcp_unreg(e->api, hash, e->dir_hash_len)) {
log_err("Could not unregister %s in DIF %s.",
name, e->dif_name);
} else {
@@ -829,6 +843,8 @@ static int name_unreg(char * name,
name, e->dif_name);
++ret;
}
+
+ free(hash);
}
}
@@ -1038,22 +1054,23 @@ static int flow_accept(pid_t api,
}
static int flow_alloc(pid_t api,
- char * dst_name,
+ const char * dst,
qoscube_t cube,
struct timespec * timeo,
struct irm_flow ** e)
{
- struct irm_flow * f;
- pid_t ipcp;
- int port_id;
- int state;
+ struct irm_flow * f;
+ struct ipcp_entry * ipcp;
+ int port_id;
+ int state;
+ uint8_t * hash;
pthread_rwlock_rdlock(&irmd.reg_lock);
- ipcp = get_ipcp_by_dst_name(dst_name);
- if (ipcp == -1) {
+ ipcp = get_ipcp_by_dst_name(dst);
+ if (ipcp == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
- log_info("Destination unreachable.");
+ log_info("Destination %s unreachable.", dst);
return -1;
}
@@ -1066,7 +1083,7 @@ static int flow_alloc(pid_t api,
return -EBADF;
}
- f = irm_flow_create(api, ipcp, port_id, cube);
+ f = irm_flow_create(api, ipcp->api, port_id, cube);
if (f == NULL) {
bmp_release(irmd.port_ids, port_id);
pthread_rwlock_unlock(&irmd.flows_lock);
@@ -1080,12 +1097,24 @@ static int flow_alloc(pid_t api,
assert(irm_flow_get_state(f) == FLOW_ALLOC_PENDING);
- if (ipcp_flow_alloc(ipcp, port_id, api, dst_name, cube)) {
+ hash = malloc(ipcp->dir_hash_len);
+ if (hash == NULL) {
+ /* sanitizer cleans this */
+ return -ENOMEM;
+ }
+
+ get_hash(hash, dst);
+
+ if (ipcp_flow_alloc(ipcp->api, port_id, api, hash,
+ ipcp->dir_hash_len, cube)) {
/* sanitizer cleans this */
log_info("Flow_allocation failed.");
+ free(hash);
return -EAGAIN;
}
+ free(hash);
+
state = irm_flow_wait_state(f, FLOW_ALLOCATED, timeo);
if (state != FLOW_ALLOCATED) {
if (state == -ETIMEDOUT) {
@@ -1093,7 +1122,7 @@ static int flow_alloc(pid_t api,
return -ETIMEDOUT;
}
- log_info("Pending flow to %s torn down.", dst_name);
+ log_info("Pending flow to %s torn down.", dst);
return -EPIPE;
}
@@ -1191,38 +1220,49 @@ static pid_t auto_execute(char ** argv)
exit(EXIT_FAILURE);
}
-static struct irm_flow * flow_req_arr(pid_t api,
- char * dst_name,
- qoscube_t cube)
+static struct irm_flow * flow_req_arr(pid_t api,
+ const uint8_t * hash,
+ qoscube_t cube)
{
struct reg_entry * re = NULL;
struct apn_entry * a = NULL;
struct api_entry * e = NULL;
struct irm_flow * f = NULL;
- struct pid_el * c_api;
- pid_t h_api = -1;
- int port_id = -1;
+ struct pid_el * c_api;
+ struct ipcp_entry * ipcp;
+ pid_t h_api = -1;
+ int port_id = -1;
struct timespec wt = {IRMD_REQ_ARR_TIMEOUT / 1000,
(IRMD_REQ_ARR_TIMEOUT % 1000) * MILLION};
- log_dbg("Flow req arrived from IPCP %d for %s.", api, dst_name);
+ log_dbg("Flow req arrived from IPCP %d for " HASH_FMT ".",
+ api, HASH_VAL(hash));
pthread_rwlock_rdlock(&irmd.reg_lock);
- re = registry_get_entry(&irmd.registry, dst_name);
+ ipcp = get_ipcp_entry_by_api(api);
+ if (ipcp == NULL) {
+ log_err("IPCP died.");
+ return NULL;
+ }
+
+ re = registry_get_entry_by_hash(&irmd.registry, hash,
+ ipcp->dir_hash_len);
if (re == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
- log_err("Unknown name: %s.", dst_name);
+ log_err("Unknown hash: " HASH_FMT ".", HASH_VAL(hash));
return NULL;
}
+ log_info("Flow request arrived for %s.", re->name);
+
pthread_rwlock_unlock(&irmd.reg_lock);
/* Give the AP a bit of slop time to call accept */
if (reg_entry_leave_state(re, REG_NAME_IDLE, &wt) == -1) {
- log_err("No APs for %s.", dst_name);
+ log_err("No APs for " HASH_FMT ".", HASH_VAL(hash));
return NULL;
}
@@ -1231,7 +1271,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
switch (reg_entry_get_state(re)) {
case REG_NAME_IDLE:
pthread_rwlock_unlock(&irmd.reg_lock);
- log_err("No APs for %s.", dst_name);
+ log_err("No APs for " HASH_FMT ".", HASH_VAL(hash));
return NULL;
case REG_NAME_AUTO_ACCEPT:
c_api = malloc(sizeof(*c_api));
@@ -1830,7 +1870,7 @@ void * mainloop(void * o)
break;
case IRM_MSG_CODE__IPCP_FLOW_REQ_ARR:
e = flow_req_arr(msg->api,
- msg->dst_name,
+ msg->hash.data,
msg->qoscube);
ret_msg.has_result = true;
if (e == NULL) {
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index 53be77cd..71e6ea8a 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -25,8 +25,9 @@
#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/logs.h>
-#include <ouroboros/irm_config.h>
+#include <ouroboros/irm.h>
#include <ouroboros/time_utils.h>
+#include <ouroboros/hash.h>
#include "registry.h"
#include "utils.h"
@@ -145,7 +146,8 @@ static void reg_entry_destroy(struct reg_entry * e)
free(e);
}
-static bool reg_entry_is_local_in_dif(struct reg_entry * e, char * dif_name)
+static bool reg_entry_is_local_in_dif(struct reg_entry * e,
+ const char * dif_name)
{
struct list_head * p = NULL;
@@ -159,7 +161,7 @@ static bool reg_entry_is_local_in_dif(struct reg_entry * e, char * dif_name)
}
static int reg_entry_add_local_in_dif(struct reg_entry * e,
- char * dif_name,
+ const char * dif_name,
enum ipcp_type type)
{
if (!reg_entry_is_local_in_dif(e, dif_name)) {
@@ -176,7 +178,7 @@ static int reg_entry_add_local_in_dif(struct reg_entry * e,
}
static void reg_entry_del_local_from_dif(struct reg_entry * e,
- char * dif_name)
+ const char * dif_name)
{
struct list_head * p = NULL;
struct list_head * h = NULL;
@@ -192,7 +194,7 @@ static void reg_entry_del_local_from_dif(struct reg_entry * e,
}
static bool reg_entry_has_apn(struct reg_entry * e,
- char * apn)
+ const char * apn)
{
struct list_head * p;
@@ -242,7 +244,7 @@ int reg_entry_add_apn(struct reg_entry * e,
}
void reg_entry_del_apn(struct reg_entry * e,
- char * apn)
+ const char * apn)
{
struct list_head * p = NULL;
struct list_head * h = NULL;
@@ -504,9 +506,9 @@ int reg_entry_wait_state(struct reg_entry * e,
}
struct reg_entry * registry_get_entry(struct list_head * registry,
- char * name)
+ const char * name)
{
- struct list_head * p = NULL;
+ struct list_head * p = NULL;
assert(registry);
@@ -519,8 +521,33 @@ struct reg_entry * registry_get_entry(struct list_head * registry,
return NULL;
}
+struct reg_entry * registry_get_entry_by_hash(struct list_head * registry,
+ const uint8_t * hash,
+ size_t len)
+{
+ struct list_head * p = NULL;
+ uint8_t * thash;
+
+ thash = malloc(len);
+ if (thash == NULL)
+ return NULL;
+
+ assert(registry);
+
+ list_for_each(p, registry) {
+ struct reg_entry * e = list_entry(p, struct reg_entry, next);
+ get_hash(thash, e->name);
+ if (memcmp(thash, hash, len) == 0) {
+ free(thash);
+ return e;
+ }
+ }
+
+ return NULL;
+}
+
struct reg_entry * registry_add_name(struct list_head * registry,
- char * name)
+ const char * name)
{
struct reg_entry * e = NULL;
@@ -538,7 +565,7 @@ struct reg_entry * registry_add_name(struct list_head * registry,
return NULL;
}
- e = reg_entry_init(e, name);
+ e = reg_entry_init(e, strdup(name));
if (e == NULL) {
log_dbg("Could not initialize registry entry.");
reg_entry_destroy(e);
@@ -551,7 +578,7 @@ struct reg_entry * registry_add_name(struct list_head * registry,
}
void registry_del_name(struct list_head * registry,
- char * name)
+ const char * name)
{
struct reg_entry * e = registry_get_entry(registry, name);
if (e == NULL)
@@ -583,8 +610,8 @@ void registry_del_api(struct list_head * registry,
}
int registry_add_name_to_dif(struct list_head * registry,
- char * name,
- char * dif_name,
+ const char * name,
+ const char * dif_name,
enum ipcp_type type)
{
struct reg_entry * re = registry_get_entry(registry, name);
@@ -595,8 +622,8 @@ int registry_add_name_to_dif(struct list_head * registry,
}
void registry_del_name_from_dif(struct list_head * registry,
- char * name,
- char * dif_name)
+ const char * name,
+ const char * dif_name)
{
struct reg_entry * re = registry_get_entry(registry, name);
if (re == NULL)
diff --git a/src/irmd/registry.h b/src/irmd/registry.h
index 08e78019..771ca83c 100644
--- a/src/irmd/registry.h
+++ b/src/irmd/registry.h
@@ -24,8 +24,8 @@
#define OUROBOROS_IRMD_REGISTRY_H
#include <ouroboros/config.h>
+#include <ouroboros/ipcp.h>
#include <ouroboros/list.h>
-#include <ouroboros/irm_config.h>
#include <ouroboros/shared.h>
#include "api_table.h"
@@ -71,7 +71,7 @@ int reg_entry_add_apn(struct reg_entry * e,
struct apn_entry * a);
void reg_entry_del_apn(struct reg_entry * e,
- char * apn);
+ const char * apn);
char * reg_entry_get_apn(struct reg_entry * e);
@@ -101,10 +101,10 @@ int reg_entry_wait_state(struct reg_entry * e,
struct timespec * timeout);
struct reg_entry * registry_add_name(struct list_head * registry,
- char * name);
+ const char * name);
void registry_del_name(struct list_head * registry,
- char * name);
+ const char * name);
void registry_del_api(struct list_head * registry,
pid_t api);
@@ -112,16 +112,20 @@ void registry_del_api(struct list_head * registry,
void registry_sanitize_apis(struct list_head * registry);
struct reg_entry * registry_get_entry(struct list_head * registry,
- char * name);
+ const char * name);
+
+struct reg_entry * registry_get_entry_by_hash(struct list_head * registry,
+ const uint8_t * hash,
+ size_t len);
int registry_add_name_to_dif(struct list_head * registry,
- char * name,
- char * dif_name,
+ const char * name,
+ const char * dif_name,
enum ipcp_type type);
void registry_del_name_from_dif(struct list_head * registry,
- char * name,
- char * dif_name);
+ const char * name,
+ const char * dif_name);
void registry_destroy(struct list_head * registry);