summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/fmgr.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-28 17:23:42 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-01 11:12:14 +0200
commitcf719963be2e42026012e152ae49f4c764dd9b4f (patch)
tree102b5d165aa246fa601cd565646db2ddb7e6d0b0 /src/ipcpd/normal/fmgr.c
parent0fdc2c081b63cc3ca38bd97703c113245075aa18 (diff)
downloadouroboros-cf719963be2e42026012e152ae49f4c764dd9b4f.tar.gz
ouroboros-cf719963be2e42026012e152ae49f4c764dd9b4f.zip
ipcpd: normal: Allow initiating enrollment
This will add more functionality for enrolling two normal IPCPs with each other. Some bugs were fixed in CDAP. Now on enrolling, an IPCP will send a START message to the other IPCP. Next step is syncing the RIBs.
Diffstat (limited to 'src/ipcpd/normal/fmgr.c')
-rw-r--r--src/ipcpd/normal/fmgr.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index 4b3c49e6..a539b289 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -35,6 +35,9 @@
#include "fmgr.h"
#include "ribmgr.h"
#include "frct.h"
+#include "ipcp.h"
+
+extern struct ipcp * _ipcp;
struct n_1_flow {
int fd;
@@ -77,28 +80,37 @@ static void * fmgr_listen(void * o)
int fd;
char * ae_name;
- /* FIXME: Only start to listen once we are enrolled */
+ /* FIXME: Avoid busy wait and react to pthread_cond_t */
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ while (_ipcp->state != IPCP_ENROLLED ||
+ _ipcp->state != IPCP_SHUTDOWN) {
+ pthread_rwlock_unlock(&_ipcp->state_lock);
+ sched_yield();
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
+ }
- while (true) {
+ while (_ipcp->state != IPCP_SHUTDOWN) {
+ pthread_rwlock_unlock(&_ipcp->state_lock);
fd = flow_accept(&ae_name);
if (fd < 0) {
LOG_ERR("Failed to accept flow.");
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
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))
LOG_ERR("Failed to reply to flow allocation.");
flow_dealloc(fd);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
continue;
}
if (flow_alloc_resp(fd, 0)) {
LOG_ERR("Failed to reply to flow allocation.");
flow_dealloc(fd);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
continue;
}
@@ -106,9 +118,10 @@ static void * fmgr_listen(void * o)
ae_name);
if (strcmp(ae_name, MGMT_AE) == 0) {
- if (ribmgr_mgmt_flow(fd)) {
+ if (ribmgr_add_flow(fd)) {
LOG_ERR("Failed to hand fd to RIB.");
flow_dealloc(fd);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
continue;
}
}
@@ -117,6 +130,7 @@ static void * fmgr_listen(void * o)
if (frct_dt_flow(fd)) {
LOG_ERR("Failed to hand fd to FRCT.");
flow_dealloc(fd);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
continue;
}
}
@@ -124,8 +138,11 @@ static void * fmgr_listen(void * o)
if (add_n_1_fd(fd, ae_name)) {
LOG_ERR("Failed to add file descriptor to list.");
flow_dealloc(fd);
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
continue;
}
+
+ pthread_rwlock_rdlock(&_ipcp->state_lock);
}
return (void *) 0;
@@ -134,9 +151,8 @@ static void * fmgr_listen(void * o)
int fmgr_init()
{
fmgr = malloc(sizeof(*fmgr));
- if (fmgr == NULL) {
+ if (fmgr == NULL)
return -1;
- }
INIT_LIST_HEAD(&fmgr->n_1_flows);
@@ -164,7 +180,8 @@ int fmgr_fini()
list_entry(pos, struct n_1_flow, next);
if (e->ae_name != NULL)
free(e->ae_name);
- flow_dealloc(e->fd);
+ if (ribmgr_remove_flow(e->fd))
+ LOG_ERR("Failed to remove management flow.");
}
free(fmgr);
@@ -191,7 +208,7 @@ int fmgr_mgmt_flow(char * dst_name)
return -1;
}
- if (ribmgr_mgmt_flow(fd)) {
+ if (ribmgr_add_flow(fd)) {
LOG_ERR("Failed to hand file descriptor to RIB manager");
flow_dealloc(fd);
return -1;
@@ -239,10 +256,3 @@ int fmgr_flow_dealloc(int port_id)
return -1;
}
-
-int fmgr_flow_msg()
-{
- LOG_MISSING;
-
- return -1;
-}