summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-16 12:04:59 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-04-16 13:40:12 +0200
commit97ef24340da7d3f55a39ba16b400d13f9bbe9e60 (patch)
treee13656c267343db47a4f79d2098222909222736d /src/ipcpd
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/ipcpd')
-rw-r--r--src/ipcpd/ipcp.c18
-rw-r--r--src/ipcpd/ipcp.h7
-rw-r--r--src/ipcpd/local/main.c4
-rw-r--r--src/ipcpd/normal/dir.c6
-rw-r--r--src/ipcpd/normal/fmgr.c6
-rw-r--r--src/ipcpd/normal/main.c24
-rw-r--r--src/ipcpd/shim-data.c6
-rw-r--r--src/ipcpd/shim-eth-llc/main.c12
-rw-r--r--src/ipcpd/shim-udp/main.c12
9 files changed, 49 insertions, 46 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 47c951f1..19607ee1 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -63,23 +63,23 @@ void ipcp_sig_handler(int sig,
uint8_t * ipcp_hash_dup(const uint8_t * hash)
{
- uint8_t * dup = malloc(ipcpi.dir_hash_len);
+ uint8_t * dup = malloc(hash_len(ipcpi.dir_hash_algo));
if (dup == NULL)
return NULL;
- memcpy(dup, hash, ipcpi.dir_hash_len);
+ memcpy(dup, hash, ipcp_dir_hash_len());
return dup;
}
-void ipcp_hash_str(char buf[DIR_HASH_STRLEN + 1],
+void ipcp_hash_str(char * buf,
const uint8_t * hash)
{
size_t i;
char * HEX = "0123456789abcdef";
- for (i = 0; i < ipcpi.dir_hash_len; ++i) {
+ for (i = 0; i < ipcp_dir_hash_len(); ++i) {
buf[i * 2] = HEX[(hash[i] & 0xF0) >> 4];
buf[i * 2 + 1] = HEX[hash[i] & 0x0F];
}
@@ -212,7 +212,7 @@ static void * ipcp_main_loop(void * o)
conf_msg = msg->conf;
conf.type = conf_msg->ipcp_type;
- conf.dir_hash_len = conf_msg->dir_hash_len;
+ conf.dir_hash_algo = conf_msg->dir_hash_algo;
conf.dif_name = conf_msg->dif_name;
if (conf.dif_name == NULL) {
ret_msg.has_result = true;
@@ -270,7 +270,7 @@ static void * ipcp_main_loop(void * o)
break;
}
- assert(msg->hash.len == ipcpi.dir_hash_len);
+ assert(msg->hash.len == ipcp_dir_hash_len());
ret_msg.result =
ipcpi.ops->ipcp_reg(msg->hash.data);
@@ -284,7 +284,7 @@ static void * ipcp_main_loop(void * o)
break;
}
- assert(msg->hash.len == ipcpi.dir_hash_len);
+ assert(msg->hash.len == ipcp_dir_hash_len());
ret_msg.result =
ipcpi.ops->ipcp_unreg(msg->hash.data);
@@ -298,7 +298,7 @@ static void * ipcp_main_loop(void * o)
break;
}
- assert(msg->hash.len == ipcpi.dir_hash_len);
+ assert(msg->hash.len == ipcp_dir_hash_len());
if (ipcp_get_state() != IPCP_OPERATIONAL) {
log_err("IPCP in wrong state.");
@@ -318,7 +318,7 @@ static void * ipcp_main_loop(void * o)
break;
}
- assert(msg->hash.len == ipcpi.dir_hash_len);
+ assert(msg->hash.len == ipcp_dir_hash_len());
if (ipcp_get_state() != IPCP_OPERATIONAL) {
log_err("IPCP in wrong state.");
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index d6e2aa7c..c78aa5a6 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -24,6 +24,7 @@
#define IPCPD_IPCP_H
#include <ouroboros/config.h>
+#include <ouroboros/hash.h>
#include <ouroboros/ipcp.h>
#include "shim-data.h"
@@ -60,7 +61,8 @@ struct ipcp_ops {
int (* ipcp_flow_dealloc)(int fd);
};
-#define DIR_HASH_STRLEN (ipcpi.dir_hash_len * 2)
+#define ipcp_dir_hash_strlen() (hash_len(ipcpi.dir_hash_algo) * 2)
+#define ipcp_dir_hash_len() (hash_len(ipcpi.dir_hash_algo))
struct ipcp {
int irmd_api;
@@ -70,7 +72,8 @@ struct ipcp {
char * dif_name;
uint64_t dt_addr;
- uint16_t dir_hash_len;
+
+ enum hash_algo dir_hash_algo;
struct ipcp_ops * ops;
int irmd_fd;
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 21ca7400..162ce4d9 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -119,7 +119,7 @@ static int ipcp_local_bootstrap(const struct ipcp_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- ipcpi.dir_hash_len = conf->dir_hash_len;
+ ipcpi.dir_hash_algo = conf->dir_hash_algo;
ipcp_set_state(IPCP_OPERATIONAL);
@@ -198,7 +198,7 @@ static int ipcp_local_flow_alloc(int fd,
assert(ipcpi.alloc_id == -1);
- out_fd = ipcp_flow_req_arr(getpid(), dst, ipcpi.dir_hash_len, cube);
+ out_fd = ipcp_flow_req_arr(getpid(), dst, ipcp_dir_hash_len(), cube);
if (out_fd < 0) {
pthread_mutex_unlock(&ipcpi.alloc_lock);
log_dbg("Flow allocation failed: %d", out_fd);
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index 0249ba06..5ea8a300 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -62,7 +62,7 @@ int dir_fini(void)
int dir_reg(const uint8_t * hash)
{
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
int ret;
assert(hash);
@@ -91,7 +91,7 @@ int dir_reg(const uint8_t * hash)
int dir_unreg(const uint8_t * hash)
{
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
size_t len;
assert(hash);
@@ -121,7 +121,7 @@ int dir_unreg(const uint8_t * hash)
int dir_query(const uint8_t * hash)
{
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
size_t len;
dir_path_reset();
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index 5166cc5d..ba36812f 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -439,7 +439,7 @@ int fmgr_np1_alloc(int fd,
ssize_t ch;
ssize_t i;
char ** children;
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
char * dst_ipcp = NULL;
ipcp_hash_str(hashstr, dst);
@@ -477,7 +477,7 @@ int fmgr_np1_alloc(int fd,
msg.code = FLOW_ALLOC_CODE__FLOW_REQ;
msg.has_hash = true;
- msg.hash.len = ipcpi.dir_hash_len;
+ msg.hash.len = ipcp_dir_hash_len();
msg.hash.data = (uint8_t *) dst;
msg.has_qoscube = true;
msg.qoscube = cube;
@@ -663,7 +663,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id,
fd = ipcp_flow_req_arr(getpid(),
msg->hash.data,
- ipcpi.dir_hash_len,
+ ipcp_dir_hash_len(),
msg->qoscube);
if (fd < 0) {
pthread_mutex_unlock(&ipcpi.alloc_lock);
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index e37a0fbc..67424914 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -69,16 +69,16 @@ static int boot_components(void)
return -1;
}
- len = rib_read(BOOT_PATH "/general/dir_hash_len",
- &ipcpi.dir_hash_len, sizeof(ipcpi.dir_hash_len));
+ len = rib_read(BOOT_PATH "/general/dir_hash_algo",
+ &ipcpi.dir_hash_algo, sizeof(ipcpi.dir_hash_algo));
if (len < 0) {
log_err("Failed to read hash length: %zd.", len);
return -1;
}
- ipcpi.dir_hash_len = ntoh16(ipcpi.dir_hash_len);
+ ipcpi.dir_hash_algo = ntoh32(ipcpi.dir_hash_algo);
- assert(ipcpi.dir_hash_len != 0);
+ assert(ipcp_dir_hash_len() != 0);
if (rib_add(MEMBERS_PATH, ipcpi.name)) {
log_err("Failed to add name to " MEMBERS_PATH);
@@ -229,7 +229,7 @@ static int normal_ipcp_enroll(const char * dst)
log_dbg("Enrolled with " HASH_FMT, HASH_VAL(dst));
- return 0;
+ return ipcpi.dir_hash_algo;
}
const struct ros {
@@ -245,7 +245,7 @@ const struct ros {
{BOOT_PATH, "general"},
{BOOT_PATH "/general", "dif_name"},
- {BOOT_PATH "/general", "dir_hash_len"},
+ {BOOT_PATH "/general", "dir_hash_algo"},
/* DT COMPONENT */
{BOOT_PATH, "dt"},
@@ -293,14 +293,14 @@ int normal_rib_init(void)
static int normal_ipcp_bootstrap(const struct ipcp_config * conf)
{
- uint16_t hash_len;
+ uint32_t hash_algo;
assert(conf);
assert(conf->type == THIS_TYPE);
- hash_len = hton16((uint16_t) conf->dir_hash_len);
+ hash_algo = hton32((uint32_t) conf->dir_hash_algo);
- assert(ntoh16(hash_len) != 0);
+ assert(ntoh32(hash_algo) != 0);
if (normal_rib_init()) {
log_err("Failed to write initial structure to the RIB.");
@@ -310,9 +310,9 @@ static int normal_ipcp_bootstrap(const struct ipcp_config * conf)
if (rib_write(BOOT_PATH "/general/dif_name",
conf->dif_name,
strlen(conf->dif_name) + 1) ||
- rib_write(BOOT_PATH "/general/dir_hash_len",
- &hash_len,
- sizeof(hash_len)) ||
+ rib_write(BOOT_PATH "/general/dir_hash_algo",
+ &hash_algo,
+ sizeof(hash_algo)) ||
rib_write(BOOT_PATH "/dt/const/addr_size",
&conf->addr_size,
sizeof(conf->addr_size)) ||
diff --git a/src/ipcpd/shim-data.c b/src/ipcpd/shim-data.c
index 4459837d..2ef48cb0 100644
--- a/src/ipcpd/shim-data.c
+++ b/src/ipcpd/shim-data.c
@@ -187,7 +187,7 @@ static struct reg_entry * find_reg_entry_by_hash(struct shim_data * data,
list_for_each(h, &data->registry) {
struct reg_entry * e = list_entry(h, struct reg_entry, list);
- if (!memcmp(e->hash, hash, ipcpi.dir_hash_len))
+ if (!memcmp(e->hash, hash, ipcp_dir_hash_len()))
return e;
}
@@ -202,7 +202,7 @@ static struct dir_entry * find_dir_entry(struct shim_data * data,
list_for_each(h, &data->directory) {
struct dir_entry * e = list_entry(h, struct dir_entry, list);
if (e->addr == addr &&
- !memcmp(e->hash, hash, ipcpi.dir_hash_len))
+ !memcmp(e->hash, hash, ipcp_dir_hash_len()))
return e;
}
@@ -215,7 +215,7 @@ static struct dir_entry * find_dir_entry_any(struct shim_data * data,
struct list_head * h;
list_for_each(h, &data->directory) {
struct dir_entry * e = list_entry(h, struct dir_entry, list);
- if (!memcmp(e->hash, hash, ipcpi.dir_hash_len))
+ if (!memcmp(e->hash, hash, ipcp_dir_hash_len()))
return e;
}
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 5ac3bb6f..36cb12c4 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -350,7 +350,7 @@ static int eth_llc_ipcp_sap_alloc(const uint8_t * dst_addr,
msg.has_ssap = true;
msg.ssap = ssap;
msg.has_hash = true;
- msg.hash.len = ipcpi.dir_hash_len;
+ msg.hash.len = ipcp_dir_hash_len();
msg.hash.data = (uint8_t *) hash;
msg.has_qoscube = true;
msg.qoscube = cube;
@@ -398,7 +398,7 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap,
}
/* reply to IRM, called under lock to prevent race */
- fd = ipcp_flow_req_arr(getpid(), dst, ipcpi.dir_hash_len, cube);
+ fd = ipcp_flow_req_arr(getpid(), dst, ipcp_dir_hash_len(), cube);
if (fd < 0) {
pthread_mutex_unlock(&ipcpi.alloc_lock);
log_err("Could not get new flow from IRMd.");
@@ -464,7 +464,7 @@ static int eth_llc_ipcp_name_query_req(const uint8_t * hash,
if (shim_data_reg_has(ipcpi.shim_data, hash)) {
msg.code = SHIM_ETH_LLC_MSG_CODE__NAME_QUERY_REPLY;
msg.has_hash = true;
- msg.hash.len = ipcpi.dir_hash_len;
+ msg.hash.len = ipcp_dir_hash_len();
msg.hash.data = (uint8_t *) hash;
eth_llc_ipcp_send_mgmt_frame(&msg, r_addr);
@@ -487,7 +487,7 @@ static int eth_llc_ipcp_name_query_reply(const uint8_t * hash,
list_for_each(pos, &ipcpi.shim_data->dir_queries) {
struct dir_query * e =
list_entry(pos, struct dir_query, next);
- if (memcmp(e->hash, hash, ipcpi.dir_hash_len) == 0) {
+ if (memcmp(e->hash, hash, ipcp_dir_hash_len()) == 0) {
shim_data_dir_query_respond(e);
}
}
@@ -758,7 +758,7 @@ static int eth_llc_ipcp_bootstrap(const struct ipcp_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- ipcpi.dir_hash_len = conf->dir_hash_len;
+ ipcpi.dir_hash_algo = conf->dir_hash_algo;
if (conf->if_name == NULL) {
log_err("Interface name is NULL.");
@@ -942,7 +942,7 @@ static int eth_llc_ipcp_query(const uint8_t * hash)
msg.code = SHIM_ETH_LLC_MSG_CODE__NAME_QUERY_REQ;
msg.has_hash = true;
- msg.hash.len = ipcpi.dir_hash_len;
+ msg.hash.len = ipcp_dir_hash_len();
msg.hash.data = (uint8_t *) hash;
memset(r_addr, 0xff, MAC_SIZE);
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index e1fe5c7c..20e9b272 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -206,7 +206,7 @@ static int ipcp_udp_port_alloc(uint32_t dst_ip_addr,
msg.code = SHIM_UDP_MSG_CODE__FLOW_REQ;
msg.src_udp_port = src_udp_port;
msg.has_hash = true;
- msg.hash.len = ipcpi.dir_hash_len;
+ msg.hash.len = ipcp_dir_hash_len();
msg.hash.data = (uint8_t *) dst;
msg.has_qoscube = true;
msg.qoscube = cube;
@@ -286,7 +286,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
}
/* reply to IRM */
- fd = ipcp_flow_req_arr(getpid(), dst, ipcpi.dir_hash_len, cube);
+ fd = ipcp_flow_req_arr(getpid(), dst, ipcp_dir_hash_len(), cube);
if (fd < 0) {
pthread_mutex_unlock(&ipcpi.alloc_lock);
log_err("Could not get new flow from IRMd.");
@@ -534,7 +534,7 @@ static int ipcp_udp_bootstrap(const struct ipcp_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- ipcpi.dir_hash_len = conf->dir_hash_len;
+ ipcpi.dir_hash_algo = conf->dir_hash_algo;
if (inet_ntop(AF_INET,
&conf->ip_addr,
@@ -749,7 +749,7 @@ static int ipcp_udp_reg(const uint8_t * hash)
uint32_t dns_addr;
uint32_t ip_addr;
#endif
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
uint8_t * hash_dup;
assert(hash);
@@ -809,7 +809,7 @@ static int ipcp_udp_unreg(const uint8_t * hash)
char cmd[100];
uint32_t dns_addr;
#endif
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
assert(hash);
@@ -846,7 +846,7 @@ static int ipcp_udp_query(const uint8_t * hash)
#ifdef CONFIG_OUROBOROS_ENABLE_DNS
uint32_t dns_addr = 0;
#endif
- char hashstr[DIR_HASH_STRLEN + 1];
+ char hashstr[ipcp_dir_hash_strlen() + 1];
assert(hash);