summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-23 07:38:24 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-23 07:38:24 +0000
commitce5ad7a0697853e7d23030c823c3381ca3f71fef (patch)
tree850aee07707ef019e717a660ee3a334c7da4469b /src
parentb3913bd7d7c1fb4cc82de750990d2111df2d9b2d (diff)
parent3c43bb7b6f56f709a2098955726fdc8d4baa75f4 (diff)
downloadouroboros-ce5ad7a0697853e7d23030c823c3381ca3f71fef.tar.gz
ouroboros-ce5ad7a0697853e7d23030c823c3381ca3f71fef.zip
Merged in dstaesse/ouroboros/testing-bootstrap (pull request #389)
irmd: Check IPCP type before bootstrap
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/normal/main.c6
-rw-r--r--src/irmd/main.c35
2 files changed, 34 insertions, 7 deletions
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index e3955ff2..c41b6187 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -344,10 +344,8 @@ static int normal_ipcp_bootstrap(struct dif_config * conf)
(void) pol;
- if (conf == NULL || conf->type != THIS_TYPE) {
- log_err("Bad DIF configuration.");
- return -EINVAL;
- }
+ assert(conf);
+ assert(conf->type == THIS_TYPE);
pthread_rwlock_wrlock(&ipcpi.state_lock);
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 7f20faf4..f6328979 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -181,6 +181,19 @@ static struct ipcp_entry * get_ipcp_entry_by_api(pid_t api)
return NULL;
}
+static struct ipcp_entry * get_ipcp_entry_by_name(const char * name)
+{
+ struct list_head * p = NULL;
+
+ list_for_each(p, &irmd->ipcps) {
+ struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
+ if (strcmp(name, e->name))
+ return e;
+ }
+
+ return NULL;
+}
+
/* Check if the name exists anywhere in a DIF. */
static pid_t get_ipcp_by_dst_name(char * dst_name)
{
@@ -228,9 +241,10 @@ static pid_t get_ipcp_by_dst_name(char * dst_name)
static pid_t create_ipcp(char * name,
enum ipcp_type ipcp_type)
{
- struct pid_el * api = NULL;
- struct ipcp_entry * tmp = NULL;
- struct list_head * p = NULL;
+ struct pid_el * api = NULL;
+ struct ipcp_entry * tmp = NULL;
+ struct list_head * p = NULL;
+ struct ipcp_entry * entry = NULL;
api = malloc(sizeof(*api));
if (api == NULL)
@@ -245,6 +259,14 @@ static pid_t create_ipcp(char * name,
pthread_rwlock_wrlock(&irmd->reg_lock);
+ entry = get_ipcp_entry_by_name(name);
+ if (entry != NULL) {
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ log_err("IPCP by that name already exists.");
+ return -1;
+ }
+
api->pid = ipcp_create(name, ipcp_type);
if (api->pid == -1) {
pthread_rwlock_unlock(&irmd->reg_lock);
@@ -397,6 +419,13 @@ static int bootstrap_ipcp(pid_t api,
return -1;
}
+ if (entry->type != (enum ipcp_type) conf->ipcp_type) {
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ log_err("Configuration does not match IPCP type.");
+ return -1;
+ }
+
if (ipcp_bootstrap(entry->api, conf)) {
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);