From fc10a7587b1a642748ae0fd69f08d92b4a902248 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 12 Apr 2017 16:57:48 +0200 Subject: lib, ipcpd, irmd: Register hash instead of name All information passed over the IRMd/IPCP boundary for using IPC services (flow allocation, registration) is now hashed. This effectively fixes the shared namespace between DIFs and the IRMDs. This PR also fixes some API issues (adding const identifiers), shuffles the include headers a bit and some small bugs. --- src/lib/rib.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/lib/rib.c') diff --git a/src/lib/rib.c b/src/lib/rib.c index d39a17d2..2645e90b 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -29,9 +29,8 @@ #include #include #include - -#include "sha3.h" -#include "btree.h" +#include +#include #include "ro.pb-c.h" typedef RoMsg ro_msg_t; @@ -94,7 +93,7 @@ struct rnode { uint8_t * data; size_t len; - uint8_t sha3[sha3_256_hash_size]; + uint8_t sha3[SHA3_256_HASH_LEN]; struct rnode * parent; @@ -142,7 +141,7 @@ static void rnode_hash(struct rnode * node) list_for_each(p, &node->children) { struct child * c = list_entry(p, struct child, next); - rhash_sha3_update(&ctx, c->node->sha3, sha3_256_hash_size); + rhash_sha3_update(&ctx, c->node->sha3, SHA3_256_HASH_LEN); } rhash_sha3_final(&ctx, node->sha3); @@ -654,7 +653,7 @@ int rib_write(const char * path, uint8_t * cdata; - if (path == NULL) + if (path == NULL || data == NULL || len == 0) return -EINVAL; cdata = malloc(len); @@ -666,8 +665,13 @@ int rib_write(const char * path, pthread_rwlock_rdlock(&rib.lock); node = find_rnode_by_path(path); - if (node != NULL) - rnode_update(node, cdata, len); + if (node == NULL) { + pthread_rwlock_unlock(&rib.lock); + free(cdata); + return -1; + } + + rnode_update(node, cdata, len); pthread_rwlock_unlock(&rib.lock); @@ -1226,7 +1230,7 @@ static ro_msg_t * rnode_pack(struct rnode * node, (flags & PACK_HASH_ALL)) { msg->has_hash = true; msg->hash.data = node->sha3; - msg->hash.len = sha3_256_hash_size; + msg->hash.len = SHA3_256_HASH_LEN; } if (node->data != NULL) { @@ -1407,7 +1411,7 @@ int rib_unpack(uint8_t * packed, if (ret == 0 && msg->has_hash) { root = rnode_get_child(root, msg->name); - if (memcmp(msg->hash.data, root->sha3, sha3_256_hash_size)) { + if (memcmp(msg->hash.data, root->sha3, SHA3_256_HASH_LEN)) { ro_msg__free_unpacked(msg, NULL); return -EFAULT; } -- cgit v1.2.3