summaryrefslogtreecommitdiff
path: root/src/ipcpd/broadcast
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd/broadcast')
-rw-r--r--src/ipcpd/broadcast/main.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/src/ipcpd/broadcast/main.c b/src/ipcpd/broadcast/main.c
index f51fc629..151b38c8 100644
--- a/src/ipcpd/broadcast/main.c
+++ b/src/ipcpd/broadcast/main.c
@@ -36,6 +36,7 @@
#include <ouroboros/ipcp-dev.h>
#include <ouroboros/logs.h>
#include <ouroboros/notifier.h>
+#include <ouroboros/np1_flow.h>
#include <ouroboros/random.h>
#include <ouroboros/rib.h>
#include <ouroboros/time.h>
@@ -52,13 +53,8 @@
#include <assert.h>
#include <inttypes.h>
-struct ipcp ipcpi;
-
-static int initialize_components(const struct ipcp_config * conf)
+static int initialize_components(void)
{
- strcpy(ipcpi.layer_name, conf->layer_info.name);
- ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo;
-
assert(ipcp_dir_hash_len() != 0);
if (dt_init() < 0) {
@@ -107,6 +103,7 @@ static void stop_components(void)
static int broadcast_ipcp_enroll(const char * dst,
struct layer_info * info)
{
+ struct ipcp_config * conf;
struct conn conn;
uint8_t id[ENROLL_ID_LEN];
@@ -128,7 +125,10 @@ static int broadcast_ipcp_enroll(const char * dst,
goto fail_enroll_boot;
}
- if (initialize_components(enroll_get_conf()) < 0) {
+ conf = enroll_get_conf();
+ *info = conf->layer_info;
+
+ if (initialize_components() < 0) {
log_err_id(id, "Failed to initialize components.");
goto fail_enroll_boot;
}
@@ -146,9 +146,6 @@ static int broadcast_ipcp_enroll(const char * dst,
log_info_id(id, "Enrolled with %s.", dst);
- info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo;
- strcpy(info->name, ipcpi.layer_name);
-
return 0;
fail_start_comp:
@@ -159,16 +156,15 @@ static int broadcast_ipcp_enroll(const char * dst,
return -1;
}
-static int broadcast_ipcp_bootstrap(const struct ipcp_config * conf)
+static int broadcast_ipcp_bootstrap(struct ipcp_config * conf)
{
assert(conf);
assert(conf->type == THIS_TYPE);
- ((struct ipcp_config *) conf)->layer_info.dir_hash_algo =
- DIR_HASH_SHA3_256;
+ assert(conf->layer_info.dir_hash_algo == DIR_HASH_SHA3_256);
enroll_bootstrap(conf);
- if (initialize_components(conf)) {
+ if (initialize_components()) {
log_err("Failed to init IPCP components.");
goto fail_init;
}
@@ -190,39 +186,58 @@ static int name_check(const uint8_t * dst)
{
uint8_t * buf;
size_t len;
- int ret;
+ int err;
+ char layer[LAYER_NAME_SIZE + 1];
- len = hash_len(ipcpi.dir_hash_algo);
+ len = ipcp_dir_hash_len();
buf = malloc(len);
- if (buf == NULL)
- return -ENOMEM;
+ if (buf == NULL) {
+ log_err("Failed to malloc buffer.");
+ err = -ENOMEM;
+ goto fail_buf;
+ }
- str_hash(ipcpi.dir_hash_algo, buf, ipcpi.layer_name);
+ err = ipcp_get_layer_name(layer);
+ if (err < 0) {
+ log_err("Failed to get layer name.");
+ goto fail_layer;
+ }
- ret = memcmp(buf, dst, len);
+ str_hash(HASH_SHA3_256, buf, layer);
+
+ if (memcmp(buf, dst, len) < 0) {
+ log_err("Hash mismatch for layer %s.", layer);
+ err = -ENAME;
+ goto fail_layer;
+ }
free(buf);
- return ret;
+ return 0;
+
+ fail_layer:
+ free(buf);
+ fail_buf:
+ return err;
}
static int broadcast_ipcp_join(int fd,
- const uint8_t * dst,
- qosspec_t qs)
+ const uint8_t * dst)
{
+ int err;
struct conn conn;
time_t mpl = IPCP_BROADCAST_MPL;
- buffer_t data = {NULL, 0};
-
- (void) qs;
+ buffer_t data = BUF_INIT;
memset(&conn, 0, sizeof(conn));
conn.flow_info.fd = fd;
+ conn.flow_info.qs = qos_np1;
- if (name_check(dst) != 0) {
+ err = name_check(dst);
+ if (err < 0) {
log_err("Failed to check name.");
- return -1;
+ return err;
}
notifier_event(NOTIFY_DT_CONN_ADD, &conn);