summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/fmgr.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-27 16:46:23 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-27 16:46:23 +0200
commit0c0508619959b5ac98b31b4389fcfadf5ee26d9b (patch)
tree08b53089bd819a215412041282776fb225b31395 /src/ipcpd/normal/fmgr.c
parentbee74baa8fa8ffa71dbb659496bc88df3e8ce6a5 (diff)
downloadouroboros-0c0508619959b5ac98b31b4389fcfadf5ee26d9b.tar.gz
ouroboros-0c0508619959b5ac98b31b4389fcfadf5ee26d9b.zip
ipcpd: normal: Provide initial steps for enrollment
This provides the normal IPCP with bootstrapping and the initial steps for enrollment. Next step is actually reacting to an enrollment request and sending the data transfer constants.
Diffstat (limited to 'src/ipcpd/normal/fmgr.c')
-rw-r--r--src/ipcpd/normal/fmgr.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index 9521805f..4b3c49e6 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -48,7 +48,7 @@ struct fmgr {
struct list_head n_1_flows;
pthread_mutex_t n_1_flows_lock;
-} * instance = NULL;
+} * fmgr = NULL;
static int add_n_1_fd(int fd,
char * ae_name)
@@ -65,9 +65,9 @@ static int add_n_1_fd(int fd,
tmp->fd = fd;
tmp->ae_name = ae_name;
- pthread_mutex_lock(&instance->n_1_flows_lock);
- list_add(&tmp->next, &instance->n_1_flows);
- pthread_mutex_unlock(&instance->n_1_flows_lock);
+ pthread_mutex_lock(&fmgr->n_1_flows_lock);
+ list_add(&tmp->next, &fmgr->n_1_flows);
+ pthread_mutex_unlock(&fmgr->n_1_flows_lock);
return 0;
}
@@ -77,6 +77,8 @@ static void * fmgr_listen(void * o)
int fd;
char * ae_name;
+ /* FIXME: Only start to listen once we are enrolled */
+
while (true) {
fd = flow_accept(&ae_name);
if (fd < 0) {
@@ -84,6 +86,8 @@ static void * fmgr_listen(void * o)
continue;
}
+ LOG_DBG("New flow alloc request for AE %s", ae_name);
+
if (!(strcmp(ae_name, MGMT_AE) == 0 ||
strcmp(ae_name, DT_AE) == 0)) {
if (flow_alloc_resp(fd, -1))
@@ -101,18 +105,20 @@ static void * fmgr_listen(void * o)
LOG_DBG("Accepted new flow allocation request for AE %s.",
ae_name);
- if (strcmp(ae_name, MGMT_AE) == 0 &&
- ribmgr_mgmt_flow(fd)) {
- LOG_ERR("Failed to hand file descriptor to RIB.");
- flow_dealloc(fd);
- continue;
+ if (strcmp(ae_name, MGMT_AE) == 0) {
+ if (ribmgr_mgmt_flow(fd)) {
+ LOG_ERR("Failed to hand fd to RIB.");
+ flow_dealloc(fd);
+ continue;
+ }
}
- if (strcmp(ae_name, DT_AE) == 0 &&
- frct_dt_flow(fd)) {
- LOG_ERR("Failed to hand file descriptor to FRCT.");
- flow_dealloc(fd);
- continue;
+ if (strcmp(ae_name, DT_AE) == 0) {
+ if (frct_dt_flow(fd)) {
+ LOG_ERR("Failed to hand fd to FRCT.");
+ flow_dealloc(fd);
+ continue;
+ }
}
if (add_n_1_fd(fd, ae_name)) {
@@ -127,16 +133,16 @@ static void * fmgr_listen(void * o)
int fmgr_init()
{
- instance = malloc(sizeof(*instance));
- if (instance == NULL) {
+ fmgr = malloc(sizeof(*fmgr));
+ if (fmgr == NULL) {
return -1;
}
- INIT_LIST_HEAD(&instance->n_1_flows);
+ INIT_LIST_HEAD(&fmgr->n_1_flows);
- pthread_mutex_init(&instance->n_1_flows_lock, NULL);
+ pthread_mutex_init(&fmgr->n_1_flows_lock, NULL);
- pthread_create(&instance->listen_thread,
+ pthread_create(&fmgr->listen_thread,
NULL,
fmgr_listen,
NULL);
@@ -148,12 +154,12 @@ int fmgr_fini()
{
struct list_head * pos = NULL;
- pthread_cancel(instance->listen_thread);
+ pthread_cancel(fmgr->listen_thread);
- pthread_join(instance->listen_thread,
+ pthread_join(fmgr->listen_thread,
NULL);
- list_for_each(pos, &instance->n_1_flows) {
+ list_for_each(pos, &fmgr->n_1_flows) {
struct n_1_flow * e =
list_entry(pos, struct n_1_flow, next);
if (e->ae_name != NULL)
@@ -161,7 +167,7 @@ int fmgr_fini()
flow_dealloc(e->fd);
}
- free(instance);
+ free(fmgr);
return 0;
}