summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2023-11-27 14:43:11 +0100
committerSander Vrijders <sander@ouroboros.rocks>2023-11-29 09:57:29 +0100
commit346b054ee32a9f7b8491f842709f72cc8d1f3f2e (patch)
tree5a406924ca94a03460e9b1e14d50cd1fca7c5c61 /src/irmd
parent3f24301fff9c544dfe2b89c5737bc3cdf94ef9a9 (diff)
downloadouroboros-346b054ee32a9f7b8491f842709f72cc8d1f3f2e.tar.gz
ouroboros-346b054ee32a9f7b8491f842709f72cc8d1f3f2e.zip
include: Store IPCP name and type in info struct
The information for an IPCP is now stored in an ipcp_info struct, containing name and type. The IRM public API is not changed. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/configfile.c32
-rw-r--r--src/irmd/ipcp.c11
-rw-r--r--src/irmd/ipcp.h3
-rw-r--r--src/irmd/irmd.h3
-rw-r--r--src/irmd/main.c95
-rw-r--r--src/irmd/reg/ipcp.c11
-rw-r--r--src/irmd/reg/ipcp.h7
7 files changed, 89 insertions, 73 deletions
diff --git a/src/irmd/configfile.c b/src/irmd/configfile.c
index 07f31ccf..af2a37c8 100644
--- a/src/irmd/configfile.c
+++ b/src/irmd/configfile.c
@@ -422,20 +422,20 @@ static int toml_connect(toml_table_t * table,
return ret;
}
-static int toml_ipcp(toml_table_t * table,
- const char * name,
- struct ipcp_config * conf)
+static int toml_ipcp(toml_table_t * table,
+ const struct ipcp_info * info,
+ struct ipcp_config * conf)
{
toml_datum_t bootstrap;
toml_datum_t enrol;
pid_t pid;
int ret;
- log_dbg("Found IPCP %s in configuration file.", name);
+ log_dbg("Found IPCP %s in configuration file.", info->name);
- pid = create_ipcp(name, conf->type);
+ pid = create_ipcp(info);
if (pid < 0) {
- log_err("Failed to create IPCP %s.", name);
+ log_err("Failed to create IPCP %s.", info->name);
return -1;
}
@@ -443,13 +443,13 @@ static int toml_ipcp(toml_table_t * table,
enrol = toml_string_in(table, "enrol");
if (bootstrap.ok && enrol.ok) {
- log_err("Ignoring bootstrap for IPCP %s.", name);
+ log_err("Ignoring bootstrap for IPCP %s.", info->name);
free(bootstrap.u.s);
bootstrap.ok = false;
}
if (!bootstrap.ok && !enrol.ok) {
- log_dbg("Nothing more to do for %s.", name);
+ log_dbg("Nothing more to do for %s.", info->name);
return 0;
}
@@ -458,14 +458,14 @@ static int toml_ipcp(toml_table_t * table,
ret = enroll_ipcp(pid, enrol.u.s);
free(enrol.u.s);
if (ret < 0) {
- log_err("Failed to enrol %s.", name);
+ log_err("Failed to enrol %s.", info->name);
return -1;
}
if (get_layer_for_ipcp(pid, layer) < 0)
return -1;
- if (toml_autobind(table, pid, name, layer))
+ if (toml_autobind(table, pid, info->name, layer))
return -1;
if (toml_register(table, pid) < 0) {
@@ -522,7 +522,7 @@ static int toml_ipcp(toml_table_t * table,
if (bootstrap_ipcp(pid, conf) < 0)
return -1;
- if (toml_autobind(table, pid, name, conf->layer_info.name) < 0)
+ if (toml_autobind(table, pid, info->name, conf->layer_info.name) < 0)
return -1;
if (toml_register(table, pid) < 0) {
@@ -541,17 +541,25 @@ static int toml_ipcp_list(toml_table_t * table,
for (i = 0; ret == 0; i++) {
const char * key;
+ struct ipcp_info info;
struct ipcp_config conf;
key = toml_key_in(table, i);
if (key == NULL)
break;
+ if (strlen(key) > IPCP_NAME_SIZE) {
+ log_err("IPCP name too long: %s,", key);
+ return -1;
+ }
+
memset(&conf, 0, sizeof(conf));
+ info.type = type;
+ strcpy(info.name,key);
conf.type = type;
- ret = toml_ipcp(toml_table_in(table, key), key, &conf);
+ ret = toml_ipcp(toml_table_in(table, key), &info, &conf);
}
return ret;
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index b0d95b44..281c7176 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -122,16 +122,15 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,
return recv_msg;
}
-pid_t ipcp_create(const char * name,
- enum ipcp_type ipcp_type)
+pid_t ipcp_create(const struct ipcp_info * info)
{
pid_t pid;
- char * exec_name;
+ char * exec_name = NULL;
char irmd_pid[10];
char full_name[256];
char * argv[5];
- switch(ipcp_type) {
+ switch(info->type) {
case IPCP_UNICAST:
exec_name = IPCP_UNICAST_EXEC;
break;
@@ -154,7 +153,7 @@ pid_t ipcp_create(const char * name,
return -1;
}
- if (strlen(exec_name) == 0) {
+ if (exec_name == NULL) {
log_err("IPCP type not installed.");
return -1;
}
@@ -167,7 +166,7 @@ pid_t ipcp_create(const char * name,
/* log_file to be placed at the end */
argv[0] = full_name;
argv[1] = irmd_pid;
- argv[2] = (char *) name;
+ argv[2] = (char *) info->name;
if (log_syslog)
argv[3] = "1";
else
diff --git a/src/irmd/ipcp.h b/src/irmd/ipcp.h
index bedbfe01..f59e7090 100644
--- a/src/irmd/ipcp.h
+++ b/src/irmd/ipcp.h
@@ -29,8 +29,7 @@
#ifndef OUROBOROS_IRMD_IPCP_H
#define OUROBOROS_IRMD_IPCP_H
-pid_t ipcp_create(const char * name,
- enum ipcp_type ipcp_type);
+pid_t ipcp_create(const struct ipcp_info * info);
int ipcp_destroy(pid_t pid);
diff --git a/src/irmd/irmd.h b/src/irmd/irmd.h
index a225a2dd..fcf4d1fb 100644
--- a/src/irmd/irmd.h
+++ b/src/irmd/irmd.h
@@ -26,8 +26,7 @@
#include <ouroboros/ipcp.h>
#include <ouroboros/irm.h>
-int create_ipcp(const char * name,
- enum ipcp_type type);
+int create_ipcp(const struct ipcp_info * info);
int bootstrap_ipcp(pid_t pid,
struct ipcp_config * conf);
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 131bd468..f1e0e203 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -205,7 +205,9 @@ static int registry_add_ipcp(struct reg_ipcp * ipcp)
assert(ipcp);
list_for_each(p, &irmd.ipcps) {
- if (list_entry(p, struct reg_ipcp, next)->type > ipcp->type)
+ struct reg_ipcp * i;
+ i = list_entry(p, struct reg_ipcp, next);
+ if (i->info.type > ipcp->info.type)
break;
}
@@ -220,9 +222,10 @@ static struct reg_ipcp * registry_get_ipcp_by_pid(pid_t pid)
struct list_head * p;
list_for_each(p, &irmd.ipcps) {
- struct reg_ipcp * e = list_entry(p, struct reg_ipcp, next);
- if (e->pid == pid)
- return e;
+ struct reg_ipcp * ipcp;
+ ipcp = list_entry(p, struct reg_ipcp, next);
+ if (ipcp->pid == pid)
+ return ipcp;
}
return NULL;
@@ -246,9 +249,10 @@ static struct reg_ipcp * registry_get_ipcp_by_name(const char * name)
struct list_head * p;
list_for_each(p, &irmd.ipcps) {
- struct reg_ipcp * e = list_entry(p, struct reg_ipcp, next);
- if (strcmp(name, e->name) == 0)
- return e;
+ struct reg_ipcp * ipcp;
+ ipcp = list_entry(p, struct reg_ipcp, next);
+ if (strcmp(name, ipcp->info.name) == 0)
+ return ipcp;
}
return NULL;
@@ -259,9 +263,10 @@ static struct reg_ipcp * registry_get_ipcp_by_layer(const char * layer)
struct list_head * p;
list_for_each(p, &irmd.ipcps) {
- struct reg_ipcp * e = list_entry(p, struct reg_ipcp, next);
- if (strcmp(layer, e->layer) == 0)
- return e;
+ struct reg_ipcp * ipcp;
+ ipcp = list_entry(p, struct reg_ipcp, next);
+ if (strcmp(layer, ipcp->layer) == 0)
+ return ipcp;
}
return NULL;
@@ -279,11 +284,18 @@ static struct reg_ipcp * registry_get_ipcp_by_dst_name(const char * name,
pthread_rwlock_rdlock(&irmd.reg_lock);
list_for_each_safe(p, h, &irmd.ipcps) {
- struct reg_ipcp * e = list_entry(p, struct reg_ipcp, next);
- if (e->layer == NULL || e->pid == src || e->type == IPCP_BROADCAST)
+ struct reg_ipcp * ipcp;
+ ipcp = list_entry(p, struct reg_ipcp, next);
+ if (ipcp->layer == NULL)
continue;
- len = IPCP_HASH_LEN(e);
+ if (ipcp->pid == src)
+ continue;
+
+ if (ipcp->info.type == IPCP_BROADCAST)
+ continue;
+
+ len = IPCP_HASH_LEN(ipcp);
hash = malloc(len);
if (hash == NULL) {
@@ -291,15 +303,15 @@ static struct reg_ipcp * registry_get_ipcp_by_dst_name(const char * name,
return NULL;
}
- str_hash(e->dir_hash_algo, hash, name);
+ str_hash(ipcp->dir_hash_algo, hash, name);
- pid = e->pid;
+ pid = ipcp->pid;
pthread_rwlock_unlock(&irmd.reg_lock);
if (ipcp_query(pid, hash, len) == 0) {
free(hash);
- return e;
+ return ipcp;
}
free(hash);
@@ -500,8 +512,7 @@ static struct reg_proc * registry_get_proc(pid_t pid)
return NULL;
}
-pid_t create_ipcp(const char * name,
- enum ipcp_type type)
+pid_t create_ipcp(const struct ipcp_info * info)
{
struct pid_el * ppid;
struct reg_ipcp * ipcp;
@@ -509,7 +520,7 @@ pid_t create_ipcp(const char * name,
pthread_rwlock_rdlock(&irmd.reg_lock);
- ipcp = registry_get_ipcp_by_name(name);
+ ipcp = registry_get_ipcp_by_name(info->name);
if (ipcp != NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("IPCP by that name already exists.");
@@ -522,13 +533,13 @@ pid_t create_ipcp(const char * name,
if (ppid == NULL)
goto fail_ppid;
- ipcp = reg_ipcp_create(name, type);
+ ipcp = reg_ipcp_create(info);
if (ipcp == NULL) {
log_err("Failed to create IPCP entry.");
goto fail_reg_ipcp;
}
- pid = ipcp_create(name, type);
+ pid = ipcp_create(info);
if (pid == -1) {
log_err("Failed to create IPCP.");
goto fail_ipcp;
@@ -616,38 +627,38 @@ static int destroy_ipcp(pid_t pid)
int bootstrap_ipcp(pid_t pid,
struct ipcp_config * conf)
{
- struct reg_ipcp * entry;
- struct layer_info info;
+ struct reg_ipcp * ipcp;
+ struct layer_info info;
pthread_rwlock_wrlock(&irmd.reg_lock);
- entry = registry_get_ipcp_by_pid(pid);
- if (entry == NULL) {
+ ipcp = registry_get_ipcp_by_pid(pid);
+ if (ipcp == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
- log_err("No such IPCP.");
+ log_err("No such IPCP: %d.", pid);
return -1;
}
- if (entry->type != conf->type) {
+ if (ipcp->info.type != conf->type) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("Configuration does not match IPCP type.");
return -1;
}
- if (ipcp_bootstrap(entry->pid, conf, &info)) {
+ if (ipcp_bootstrap(ipcp->pid, conf, &info)) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("Could not bootstrap IPCP.");
return -1;
}
- entry->layer = strdup(info.name);
- if (entry->layer == NULL) {
+ ipcp->layer = strdup(info.name);
+ if (ipcp->layer == NULL) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_warn("Failed to set name of layer.");
return -ENOMEM;
}
- entry->dir_hash_algo = info.dir_hash_algo;
+ ipcp->dir_hash_algo = info.dir_hash_algo;
pthread_rwlock_unlock(&irmd.reg_lock);
@@ -716,7 +727,8 @@ int connect_ipcp(pid_t pid,
const char * component,
qosspec_t qs)
{
- struct reg_ipcp * ipcp;
+ struct reg_ipcp * ipcp;
+ struct ipcp_info * info;
pthread_rwlock_rdlock(&irmd.reg_lock);
@@ -727,7 +739,9 @@ int connect_ipcp(pid_t pid,
return -EIPCP;
}
- if (ipcp->type != IPCP_UNICAST && ipcp->type != IPCP_BROADCAST) {
+ info = &ipcp->info;
+
+ if (info->type != IPCP_UNICAST && info->type != IPCP_BROADCAST) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("Cannot establish connections for this IPCP type.");
return -EIPCP;
@@ -752,7 +766,8 @@ static int disconnect_ipcp(pid_t pid,
const char * dst,
const char * component)
{
- struct reg_ipcp * ipcp;
+ struct reg_ipcp * ipcp;
+ struct ipcp_info * info;
pthread_rwlock_rdlock(&irmd.reg_lock);
@@ -763,7 +778,9 @@ static int disconnect_ipcp(pid_t pid,
return -EIPCP;
}
- if (ipcp->type != IPCP_UNICAST && ipcp->type != IPCP_BROADCAST) {
+ info = &ipcp->info;
+
+ if (info->type != IPCP_UNICAST && info->type != IPCP_BROADCAST) {
pthread_rwlock_unlock(&irmd.reg_lock);
log_err("Cannot tear down connections for this IPCP type.");
return -EIPCP;
@@ -949,7 +966,7 @@ static int get_ipcp_info(ipcp_list_msg_t ** msg,
ipcp_list_msg__init(*msg);
- (*msg)->name = strdup(ipcp->name);
+ (*msg)->name = strdup(ipcp->info.name);
if ((*msg)->name == NULL)
goto fail_name;
@@ -959,7 +976,7 @@ static int get_ipcp_info(ipcp_list_msg_t ** msg,
goto fail_layer;
(*msg)->pid = ipcp->pid;
- (*msg)->type = ipcp->type;
+ (*msg)->type = ipcp->info.type;
return 0;
@@ -2057,6 +2074,7 @@ static void free_msg(void * o)
static irm_msg_t * do_command_msg(irm_msg_t * msg)
{
struct ipcp_config conf;
+ struct ipcp_info info;
irm_msg_t * ret_msg;
buffer_t data;
struct reg_flow f;
@@ -2094,7 +2112,8 @@ static irm_msg_t * do_command_msg(irm_msg_t * msg)
switch (msg->code) {
case IRM_MSG_CODE__IRM_CREATE_IPCP:
- res = create_ipcp(msg->name, msg->ipcp_type);
+ info = ipcp_info_msg_to_s(msg->ipcp_info);
+ res = create_ipcp(&info);
break;
case IRM_MSG_CODE__IPCP_CREATE_R:
res = create_ipcp_r(msg->pid, msg->result);
diff --git a/src/irmd/reg/ipcp.c b/src/irmd/reg/ipcp.c
index 62505871..f64bb5a4 100644
--- a/src/irmd/reg/ipcp.c
+++ b/src/irmd/reg/ipcp.c
@@ -42,8 +42,7 @@
#include <stdlib.h>
#include <string.h>
-struct reg_ipcp * reg_ipcp_create(const char * name,
- enum ipcp_type type)
+struct reg_ipcp * reg_ipcp_create(const struct ipcp_info * info)
{
struct reg_ipcp * ipcp;
pthread_condattr_t cattr;
@@ -63,22 +62,17 @@ struct reg_ipcp * reg_ipcp_create(const char * name,
if (pthread_cond_init(&ipcp->cond, &cattr))
goto fail_cond;
- ipcp->name = strdup(name);
- if (ipcp->name == NULL)
- goto fail_name;
+ memcpy(&ipcp->info, info, sizeof(*info));
pthread_condattr_destroy(&cattr);
ipcp->layer = NULL;
- ipcp->type = type;
ipcp->state = IPCP_BOOT;
list_head_init(&ipcp->next);
return ipcp;
- fail_name:
- pthread_cond_destroy(&ipcp->cond);
fail_cond:
pthread_condattr_destroy(&cattr);
fail_cattr:
@@ -99,7 +93,6 @@ void reg_ipcp_destroy(struct reg_ipcp * ipcp)
pthread_cond_wait(&ipcp->cond, &ipcp->mtx);
free(ipcp->layer);
- free(ipcp->name);
pthread_mutex_unlock(&ipcp->mtx);
diff --git a/src/irmd/reg/ipcp.h b/src/irmd/reg/ipcp.h
index 8ad334cf..3757aff4 100644
--- a/src/irmd/reg/ipcp.h
+++ b/src/irmd/reg/ipcp.h
@@ -34,9 +34,9 @@ enum ipcp_state {
struct reg_ipcp {
struct list_head next;
- char * name;
+ struct ipcp_info info;
+
pid_t pid;
- enum ipcp_type type;
enum hash_algo dir_hash_algo;
char * layer;
@@ -45,8 +45,7 @@ struct reg_ipcp {
pthread_mutex_t mtx;
};
-struct reg_ipcp * reg_ipcp_create(const char * name,
- enum ipcp_type type);
+struct reg_ipcp * reg_ipcp_create(const struct ipcp_info * info);
void reg_ipcp_destroy(struct reg_ipcp * i);