summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-10-21 12:44:00 +0000
committerSander Vrijders <[email protected]>2016-10-21 12:44:00 +0000
commit482c44232d4deda3f89a7d85fbad99c1c64e80ec (patch)
treef3fb790d93da3cbe198b0f0c58d9c7513b0eff23 /src/irmd
parent680017a72c7a15b90f223bafcea80fd3e264e984 (diff)
parent02976060919566d1a217b818ca8f33297700d56d (diff)
downloadouroboros-482c44232d4deda3f89a7d85fbad99c1c64e80ec.tar.gz
ouroboros-482c44232d4deda3f89a7d85fbad99c1c64e80ec.zip
Merged in dstaesse/ouroboros/be-demux (pull request #267)
lib: Demultiplex the fast path
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/ipcp.c13
-rw-r--r--src/irmd/irm_flow.c6
-rw-r--r--src/irmd/irm_flow.h20
-rw-r--r--src/irmd/main.c67
4 files changed, 75 insertions, 31 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c
index f79e6caf..33f7650a 100644
--- a/src/irmd/ipcp.c
+++ b/src/irmd/ipcp.c
@@ -111,6 +111,7 @@ pid_t ipcp_create(enum ipcp_type ipcp_type)
char * full_name = NULL;
char * exec_name = NULL;
char * log_file = NULL;
+ char * argv[4];
sprintf(irmd_api, "%u", getpid());
@@ -161,14 +162,12 @@ pid_t ipcp_create(enum ipcp_type ipcp_type)
}
/* log_file to be placed at the end */
- char * argv[] = {full_name,
- irmd_api,
- log_file,
- 0};
+ argv[0] = full_name;
+ argv[1] = irmd_api;
+ argv[2] = log_file;
+ argv[3] = NULL;
- char * envp[] = {0};
-
- execve(argv[0], &argv[0], envp);
+ execv(argv[0], &argv[0]);
LOG_DBG("%s", strerror(errno));
LOG_ERR("Failed to load IPCP daemon");
diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c
index df1302b4..dc5d22d8 100644
--- a/src/irmd/irm_flow.c
+++ b/src/irmd/irm_flow.c
@@ -36,6 +36,9 @@ struct irm_flow * irm_flow_create()
f->n_api = -1;
f->n_1_api = -1;
f->port_id = -1;
+ f->n_rb = NULL;
+ f->n_1_rb = NULL;
+
f->state = FLOW_NULL;
if (pthread_cond_init(&f->state_cond, NULL)) {
@@ -78,6 +81,9 @@ void irm_flow_destroy(struct irm_flow * f)
pthread_cond_destroy(&f->state_cond);
pthread_mutex_destroy(&f->state_lock);
+ shm_rbuff_destroy(f->n_rb);
+ shm_rbuff_destroy(f->n_1_rb);
+
free(f);
}
diff --git a/src/irmd/irm_flow.h b/src/irmd/irm_flow.h
index 5ec6d90e..507295bd 100644
--- a/src/irmd/irm_flow.h
+++ b/src/irmd/irm_flow.h
@@ -24,6 +24,7 @@
#define OUROBOROS_IRMD_IRM_FLOW_H
#include <ouroboros/list.h>
+#include <ouroboros/shm_rbuff.h>
#include <sys/types.h>
#include <pthread.h>
@@ -38,18 +39,21 @@ enum flow_state {
};
struct irm_flow {
- struct list_head next;
+ struct list_head next;
- int port_id;
+ int port_id;
- pid_t n_api;
- pid_t n_1_api;
+ pid_t n_api;
+ pid_t n_1_api;
- struct timespec t0;
+ struct shm_rbuff * n_rb;
+ struct shm_rbuff * n_1_rb;
- enum flow_state state;
- pthread_cond_t state_cond;
- pthread_mutex_t state_lock;
+ struct timespec t0;
+
+ enum flow_state state;
+ pthread_cond_t state_cond;
+ pthread_mutex_t state_lock;
};
struct irm_flow * irm_flow_create();
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 157fd8eb..8d9d04ac 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -28,7 +28,7 @@
#include <ouroboros/utils.h>
#include <ouroboros/irm_config.h>
#include <ouroboros/lockfile.h>
-#include <ouroboros/shm_ap_rbuff.h>
+#include <ouroboros/shm_rbuff.h>
#include <ouroboros/shm_rdrbuff.h>
#include <ouroboros/bitmap.h>
#include <ouroboros/qos.h>
@@ -1164,6 +1164,24 @@ static struct irm_flow * flow_alloc(pid_t api,
port_id = f->port_id = bmp_allocate(irmd->port_ids);
f->n_1_api = ipcp;
+ f->n_rb = shm_rbuff_create(api, port_id);
+ if (f->n_rb == NULL) {
+ pthread_rwlock_unlock(&irmd->flows_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", api);
+ irm_flow_destroy(f);
+ return NULL;
+ }
+
+ f->n_1_rb = shm_rbuff_create(ipcp, port_id);
+ if (f->n_1_rb == NULL) {
+ pthread_rwlock_unlock(&irmd->flows_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", ipcp);
+ irm_flow_destroy(f);
+ return NULL;
+ }
+
list_add(&f->next, &irmd->irm_flows);
pthread_rwlock_unlock(&irmd->flows_lock);
@@ -1346,7 +1364,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Unknown name: %s.", dst_name);
- free(f);
+ irm_flow_destroy(f);
return NULL;
}
@@ -1359,14 +1377,14 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("No AP's for %s.", dst_name);
- free(f);
+ irm_flow_destroy(f);
return NULL;
case REG_NAME_AUTO_ACCEPT:
c_api = malloc(sizeof(*c_api));
if (c_api == NULL) {
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
- free(f);
+ irm_flow_destroy(f);
return NULL;
}
@@ -1384,7 +1402,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Could not get start apn for reg_entry %s.",
re->name);
- free(f);
+ irm_flow_destroy(f);
free(c_api);
return NULL;
}
@@ -1411,6 +1429,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_mutex_unlock(&re->state_lock);
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
+ irm_flow_destroy(f);
return NULL;
}
@@ -1424,6 +1443,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Invalid api returned.");
+ irm_flow_destroy(f);
return NULL;
}
@@ -1432,7 +1452,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("IRMd in wrong state.");
- free(f);
+ irm_flow_destroy(f);
return NULL;
}
@@ -1441,6 +1461,26 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_wrlock(&irmd->flows_lock);
f->port_id = bmp_allocate(irmd->port_ids);
+ f->n_rb = shm_rbuff_create(f->n_api, f->port_id);
+ if (f->n_rb == NULL) {
+ bmp_release(irmd->port_ids, f->port_id);
+ pthread_rwlock_unlock(&irmd->flows_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", f->n_api);
+ irm_flow_destroy(f);
+ return NULL;
+ }
+
+ f->n_1_rb = shm_rbuff_create(f->n_1_api, f->port_id);
+ if (f->n_1_rb == NULL) {
+ bmp_release(irmd->port_ids, f->port_id);
+ pthread_rwlock_unlock(&irmd->flows_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", f->n_1_api);
+ irm_flow_destroy(f);
+ return NULL;
+ }
+
list_add(&f->next, &irmd->irm_flows);
pthread_rwlock_unlock(&irmd->flows_lock);
@@ -1455,10 +1495,13 @@ static struct irm_flow * flow_req_arr(pid_t api,
e = api_table_get(&irmd->api_table, h_api);
if (e == NULL) {
- LOG_ERR("Could not get api table entry for %d.", h_api);
pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_wrlock(&irmd->flows_lock);
+ bmp_release(irmd->port_ids, f->port_id);
+ pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
- free(f);
+ LOG_ERR("Could not get api table entry for %d.", h_api);
+ irm_flow_destroy(f);
return NULL;
}
@@ -1692,26 +1735,18 @@ void * irm_sanitize()
}
if (kill(f->n_api, 0) < 0) {
- struct shm_ap_rbuff * rb =
- shm_ap_rbuff_open(f->n_api);
bmp_release(irmd->port_ids, f->port_id);
list_del(&f->next);
LOG_INFO("AP-I %d gone, flow %d deallocated.",
f->n_api, f->port_id);
ipcp_flow_dealloc(f->n_1_api, f->port_id);
- if (rb != NULL)
- shm_ap_rbuff_destroy(rb);
irm_flow_destroy(f);
continue;
}
if (kill(f->n_1_api, 0) < 0) {
- struct shm_ap_rbuff * rb =
- shm_ap_rbuff_open(f->n_1_api);
list_del(&f->next);
LOG_ERR("IPCP %d gone, flow %d removed.",
f->n_1_api, f->port_id);
- if (rb != NULL)
- shm_ap_rbuff_destroy(rb);
irm_flow_destroy(f);
}
}