summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/dir.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-12-30 09:15:39 +0100
committerdimitri staessens <[email protected]>2017-01-04 11:18:24 +0100
commitf3fbf2c6093b293f995c4d784509577695e052b1 (patch)
tree41eb2920ea1bc831db241a7accc1e5389c772542 /src/ipcpd/normal/dir.c
parente8d6e91203b0521572b0ae32202e69944dde8f04 (diff)
downloadouroboros-f3fbf2c6093b293f995c4d784509577695e052b1.tar.gz
ouroboros-f3fbf2c6093b293f995c4d784509577695e052b1.zip
ipcpd: Refactor of normal IPCP
Reorganizes the normal IPCP a bit to make sure internal components do not need to access the state of the IPCP. The IPCP has now a thread calling accept and delegating it to the correct component based on the AE name (this used to be in the fmgr). Internal components are initialized upon enrollment or bootstrap of the IPCP. If a step fails, the IPCP goes back to the INIT state, if all components boot correctly, it goes to the operational state. RIB synchronization is still done by sending a CDAP start/stop and syncing with a ribmgr state, but needs revision later on.
Diffstat (limited to 'src/ipcpd/normal/dir.c')
-rw-r--r--src/ipcpd/normal/dir.c49
1 files changed, 5 insertions, 44 deletions
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index 47fb1f6e..c5bb03dd 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -1,5 +1,5 @@
/*
- * Ouroboros - Copyright (C) 2016
+ * Ouroboros - Copyright (C) 2016 - 2017
*
* DIF directory
*
@@ -26,7 +26,6 @@
#include <ouroboros/errno.h>
#include "dir.h"
-#include "ipcp.h"
#include "ro.h"
#include "pathname.h"
#include "ribmgr.h"
@@ -95,41 +94,27 @@ int dir_name_reg(char * name)
char * path;
uint64_t * addr;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP is not in RUNNING state.");
- return -1;
- }
-
ro_attr_init(&attr);
attr.enrol_sync = true;
attr.recv_set = ALL_MEMBERS;
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
+ if (path == NULL)
return -ENOMEM;
- }
addr = malloc(sizeof(*addr));
if (addr == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
return -ENOMEM;
}
*addr = ribmgr_address();
if (ro_create(path, &attr, (uint8_t *) addr, sizeof(*addr))) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
LOG_ERR("Failed to create RIB object.");
return -1;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
LOG_DBG("Registered %s.", name);
pathname_destroy(path);
@@ -140,29 +125,16 @@ int dir_name_unreg(char * name)
{
char * path;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP is not in RUNNING state.");
- return -1;
- }
-
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
+ if (path == NULL)
return -ENOMEM;
- }
if (ro_delete(path)) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
LOG_ERR("No such RIB object exists.");
return -1;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
pathname_destroy(path);
return 0;
@@ -176,18 +148,9 @@ int dir_name_query(char * name)
uint64_t addr;
struct dt_const * dtc;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- return -1;
- }
-
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- return -1;
- }
+ if (path == NULL)
+ return -ENOMEM;
if (ro_exists(path)) {
if (ro_read(path, &ro_data) < 0) {
@@ -206,8 +169,6 @@ int dir_name_query(char * name)
ret = (addr == ribmgr_address()) ? -1 : 0;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
pathname_destroy(path);
return ret;