summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/irm_flow.c6
-rw-r--r--src/irmd/irm_flow.h20
-rw-r--r--src/irmd/main.c65
3 files changed, 68 insertions, 23 deletions
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 67941e41..8d9d04ac 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -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_rbuff * rb =
- shm_rbuff_open(f->n_api, f->port_id);
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_rbuff_destroy(rb);
irm_flow_destroy(f);
continue;
}
if (kill(f->n_1_api, 0) < 0) {
- struct shm_rbuff * rb =
- shm_rbuff_open(f->n_1_api, f->port_id);
list_del(&f->next);
LOG_ERR("IPCP %d gone, flow %d removed.",
f->n_1_api, f->port_id);
- if (rb != NULL)
- shm_rbuff_destroy(rb);
irm_flow_destroy(f);
}
}