summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/irmd/irm_flow.c38
-rw-r--r--src/irmd/irm_flow.h4
-rw-r--r--src/irmd/main.c92
3 files changed, 48 insertions, 86 deletions
diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c
index a228db06..2456f1e2 100644
--- a/src/irmd/irm_flow.c
+++ b/src/irmd/irm_flow.c
@@ -20,7 +20,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#define OUROBOROS_PREFIX "irm_flow"
+
#include <ouroboros/config.h>
+#include <ouroboros/logs.h>
#include "irm_flow.h"
@@ -28,20 +31,12 @@
#include <stdbool.h>
#include <assert.h>
-struct irm_flow * irm_flow_create()
+struct irm_flow * irm_flow_create(pid_t n_api, pid_t n_1_api, int port_id)
{
struct irm_flow * f = malloc(sizeof(*f));
if (f == NULL)
return NULL;
- 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)) {
free(f);
return NULL;
@@ -52,8 +47,29 @@ struct irm_flow * irm_flow_create()
return NULL;
}
- f->t0.tv_sec = 0;
- f->t0.tv_nsec = 0;
+
+ f->n_api = n_api;
+ f->n_1_api = n_1_api;
+ f->port_id = port_id;
+
+ f->n_rb = shm_rbuff_create(n_api, port_id);
+ if (f->n_rb == NULL) {
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", n_api);
+ free(f);
+ return NULL;
+ }
+
+ f->n_1_rb = shm_rbuff_create(n_1_api, port_id);
+ if (f->n_1_rb == NULL) {
+ LOG_ERR("Could not create ringbuffer for AP-I %d.", n_1_api);
+ free(f);
+ return NULL;
+ }
+
+ f->state = FLOW_ALLOC_PENDING;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0)
+ LOG_WARN("Failed to set timestamp.");
return f;
}
diff --git a/src/irmd/irm_flow.h b/src/irmd/irm_flow.h
index 40a6bb8d..9cbc657d 100644
--- a/src/irmd/irm_flow.h
+++ b/src/irmd/irm_flow.h
@@ -56,7 +56,9 @@ struct irm_flow {
pthread_mutex_t state_lock;
};
-struct irm_flow * irm_flow_create(void);
+struct irm_flow * irm_flow_create(pid_t n_api,
+ pid_t n_1_api,
+ int port_id);
void irm_flow_destroy(struct irm_flow * f);
diff --git a/src/irmd/main.c b/src/irmd/main.c
index e52ef4da..055e9d8f 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1141,49 +1141,21 @@ static struct irm_flow * flow_alloc(pid_t api,
}
pthread_rwlock_unlock(&irmd->reg_lock);
-
- f = irm_flow_create();
- if (f == NULL) {
- pthread_rwlock_unlock(&irmd->state_lock);
- LOG_ERR("Failed to create irm_flow.");
- return NULL;
- }
-
- f->n_api = api;
- f->state = FLOW_ALLOC_PENDING;
-
- if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0)
- LOG_WARN("Failed to set timestamp.");
-
pthread_rwlock_wrlock(&irmd->flows_lock);
-
- port_id = f->port_id = bmp_allocate(irmd->port_ids);
+ port_id = bmp_allocate(irmd->port_ids);
if (!bmp_is_id_valid(irmd->port_ids, port_id)) {
pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Could not allocate port_id.");
- irm_flow_destroy(f);
- return NULL;
- }
-
- f->n_1_api = ipcp;
- f->n_rb = shm_rbuff_create(api, port_id);
- if (f->n_rb == NULL) {
- bmp_release(irmd->port_ids, port_id);
- 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) {
+ f = irm_flow_create(api, ipcp, port_id);
+ if (f == NULL) {
bmp_release(irmd->port_ids, port_id);
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);
+ LOG_ERR("Could not allocate port_id.");
return NULL;
}
@@ -1268,7 +1240,7 @@ static int flow_dealloc(pid_t api, int port_id)
if (f == NULL) {
pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
- LOG_DBG("Deallocate called for unknown port.");
+ LOG_DBG("Deallocate unknown port %d by %d.", port_id, api);
return 0;
}
@@ -1297,11 +1269,12 @@ static int flow_dealloc(pid_t api, int port_id)
}
pthread_rwlock_unlock(&irmd->flows_lock);
- pthread_rwlock_unlock(&irmd->state_lock);
if (n_1_api != -1)
ret = ipcp_flow_dealloc(n_1_api, port_id);
+ pthread_rwlock_unlock(&irmd->state_lock);
+
return ret;
}
@@ -1351,21 +1324,11 @@ static struct irm_flow * flow_req_arr(pid_t api,
struct pid_el * c_api;
pid_t h_api = -1;
+ int port_id = -1;
LOG_DBGF("Flow req arrived from IPCP %d for %s on AE %s.",
api, dst_name, ae_name);
- f = irm_flow_create();
- if (f == NULL) {
- LOG_ERR("Failed to create irm_flow.");
- return NULL;
- }
-
- f->state = FLOW_ALLOC_PENDING;
- f->n_1_api = api;
- if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0)
- LOG_WARN("Failed to set timestamp.");
-
pthread_rwlock_rdlock(&irmd->state_lock);
pthread_rwlock_wrlock(&irmd->reg_lock);
@@ -1374,7 +1337,6 @@ 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);
- irm_flow_destroy(f);
return NULL;
}
@@ -1387,14 +1349,12 @@ 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);
- 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);
- irm_flow_destroy(f);
return NULL;
}
@@ -1412,7 +1372,6 @@ 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);
- irm_flow_destroy(f);
free(c_api);
return NULL;
}
@@ -1439,7 +1398,6 @@ 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;
}
@@ -1447,13 +1405,12 @@ static struct irm_flow * flow_req_arr(pid_t api,
case REG_NAME_FLOW_ACCEPT:
pthread_mutex_lock(&re->state_lock);
- h_api = f->n_api = reg_entry_get_api(re);
+ h_api = reg_entry_get_api(re);
pthread_mutex_unlock(&re->state_lock);
- if (f->n_api == -1) {
+ if (h_api == -1) {
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Invalid api returned.");
- irm_flow_destroy(f);
return NULL;
}
@@ -1462,39 +1419,25 @@ 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.");
- irm_flow_destroy(f);
return NULL;
}
- pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_wrlock(&irmd->flows_lock);
- f->port_id = bmp_allocate(irmd->port_ids);
- if (!bmp_is_id_valid(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_rb = shm_rbuff_create(f->n_api, f->port_id);
- if (f->n_rb == NULL) {
- bmp_release(irmd->port_ids, f->port_id);
+ port_id = bmp_allocate(irmd->port_ids);
+ if (!bmp_is_id_valid(irmd->port_ids, 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);
+ f = irm_flow_create(h_api, api, port_id);
+ if (f == NULL) {
+ bmp_release(irmd->port_ids, 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);
+ LOG_ERR("Could not allocate port_id.");
return NULL;
}
@@ -1515,6 +1458,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pthread_rwlock_unlock(&irmd->reg_lock);
pthread_rwlock_wrlock(&irmd->flows_lock);
bmp_release(irmd->port_ids, f->port_id);
+ list_del(&f->next);
pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
LOG_ERR("Could not get api table entry for %d.", h_api);