summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/ipcp.h3
-rw-r--r--src/ipcpd/local/main.c10
-rw-r--r--src/ipcpd/normal/dir.c6
-rw-r--r--src/ipcpd/normal/fmgr.c10
-rw-r--r--src/ipcpd/normal/main.c7
-rw-r--r--src/ipcpd/normal/pol/flat.c18
-rw-r--r--src/ipcpd/normal/ribmgr.c11
-rw-r--r--src/ipcpd/shim-eth-llc/main.c10
-rw-r--r--src/ipcpd/shim-udp/main.c14
9 files changed, 45 insertions, 44 deletions
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index 58cb6309..9378f468 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -36,8 +36,7 @@ enum ipcp_state {
IPCP_INIT,
IPCP_CONFIG,
IPCP_BOOTING,
- IPCP_RUNNING,
- IPCP_DISCONNECTED,
+ IPCP_OPERATIONAL,
IPCP_SHUTDOWN
};
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index d8614afb..30d2d2bd 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -94,7 +94,7 @@ static void * ipcp_local_sdu_loop(void * o)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
return (void *) 1; /* -ENOTENROLLED */
}
@@ -137,7 +137,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
if (ipcp_get_state() == IPCP_INIT)
ipcp_set_state(IPCP_NULL);
- if (ipcp_get_state() == IPCP_RUNNING)
+ if (ipcp_get_state() == IPCP_OPERATIONAL)
ipcp_set_state(IPCP_SHUTDOWN);
pthread_rwlock_unlock(&ipcpi.state_lock);
@@ -163,7 +163,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
/* this IPCP doesn't need to maintain its dif_name */
free(conf->dif_name);
- ipcp_set_state(IPCP_RUNNING);
+ ipcp_set_state(IPCP_OPERATIONAL);
pthread_create(&local_data.sduloop, NULL, ipcp_local_sdu_loop, NULL);
@@ -234,7 +234,7 @@ static int ipcp_local_flow_alloc(int fd,
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
@@ -296,7 +296,7 @@ static int ipcp_local_flow_dealloc(int fd)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index 2b3742d9..2a0f112a 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -98,7 +98,7 @@ int dir_name_reg(char * name)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_ERR("IPCP is not in RUNNING state.");
return -1;
@@ -143,7 +143,7 @@ int dir_name_unreg(char * name)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_ERR("IPCP is not in RUNNING state.");
return -1;
@@ -179,7 +179,7 @@ int dir_name_query(char * name)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
return -1;
}
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index 82163aef..41785ae4 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -130,7 +130,7 @@ static void * fmgr_nm1_acceptor(void * o)
(void) o;
while (true) {
- ipcp_wait_state(IPCP_RUNNING, NULL);
+ ipcp_wait_state(IPCP_OPERATIONAL, NULL);
pthread_rwlock_rdlock(&ipcpi.state_lock);
@@ -143,7 +143,7 @@ static void * fmgr_nm1_acceptor(void * o)
fd = flow_accept(&ae_name, &qs);
if (fd < 0) {
- LOG_ERR("Failed to accept flow.");
+ LOG_WARN("Flow accept failed.");
continue;
}
@@ -390,8 +390,8 @@ int fmgr_fini()
for (i = 0; i < IRMD_MAX_FLOWS; i++) {
if (fmgr.nm1_flows[i] == NULL)
continue;
- if (ribmgr_remove_flow(fmgr.nm1_flows[i]->fd))
- LOG_ERR("Failed to remove management flow.");
+ flow_dealloc(fmgr.nm1_flows[i]->fd);
+ free(fmgr.nm1_flows[i]);
}
pthread_rwlock_destroy(&fmgr.nm1_flows_lock);
@@ -420,7 +420,7 @@ int fmgr_np1_alloc(int fd,
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_ERR("IPCP is not enrolled yet.");
return -1; /* -ENOTINIT */
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 64138838..b06d3e7a 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -108,7 +108,7 @@ static int normal_ipcp_enroll(char * dif_name)
}
pthread_rwlock_wrlock(&ipcpi.state_lock);
- ipcp_set_state(IPCP_RUNNING);
+ ipcp_set_state(IPCP_OPERATIONAL);
pthread_rwlock_unlock(&ipcpi.state_lock);
/* FIXME: Remove once we obtain neighbors during enrollment */
@@ -149,7 +149,7 @@ static int normal_ipcp_bootstrap(struct dif_config * conf)
pthread_rwlock_wrlock(&ipcpi.state_lock);
- ipcp_set_state(IPCP_RUNNING);
+ ipcp_set_state(IPCP_OPERATIONAL);
ipcpi.data->dif_name = conf->dif_name;
pthread_rwlock_unlock(&ipcpi.state_lock);
@@ -248,9 +248,6 @@ int main(int argc, char * argv[])
if (frct_fini())
LOG_ERR("Failed to finalize FRCT.");
- if (dir_fini())
- LOG_ERR("Failed to finalize directory.");
-
close_logfile();
ap_fini();
diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c
index 06958222..7d489dd5 100644
--- a/src/ipcpd/normal/pol/flat.c
+++ b/src/ipcpd/normal/pol/flat.c
@@ -163,15 +163,17 @@ int flat_init(void)
return -1;
}
- if (ro_create(name, &rattr, NULL, 0)) {
- LOG_ERR("Could not create RO.");
- pathname_destroy(name);
- pthread_cond_destroy(&flat.cond);
- pthread_mutex_destroy(&flat.lock);
- ro_unsubscribe(flat.sid);
- return -1;
+ if (!ro_exists(name)) {
+ rattr.enrol_sync = true;
+ if (ro_create(name, &rattr, NULL, 0)) {
+ LOG_ERR("Could not create RO.");
+ pathname_destroy(name);
+ pthread_cond_destroy(&flat.cond);
+ pthread_mutex_destroy(&flat.lock);
+ ro_unsubscribe(flat.sid);
+ return -1;
+ }
}
-
pathname_destroy(name);
return 0;
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 02cbbbfd..b0738a0c 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -937,7 +937,7 @@ static int ribmgr_cdap_start(struct cdap * instance,
int iid = 0;
pthread_rwlock_wrlock(&ipcpi.state_lock);
- if (ipcp_get_state() == IPCP_RUNNING &&
+ if (ipcp_get_state() == IPCP_OPERATIONAL &&
strcmp(name, ENROLLMENT) == 0) {
LOG_DBG("New enrollment request.");
@@ -1644,6 +1644,7 @@ int ro_subscribe(const char * name,
struct ro_sub_ops * ops)
{
struct ro_sub * sub;
+ int sid;
assert(name);
assert(ops);
@@ -1664,19 +1665,21 @@ int ro_subscribe(const char * name,
pthread_mutex_lock(&rib.subs_lock);
- sub->sid = bmp_allocate(rib.sids);
- if (sub->sid < 0) {
+ sid = bmp_allocate(rib.sids);
+ if (sid < 0) {
pthread_mutex_unlock(&rib.subs_lock);
free(sub->name);
free(sub);
LOG_ERR("Failed to get sub id.");
+ return -1;
}
+ sub->sid = sid;
list_add(&sub->next, &rib.subs);
pthread_mutex_unlock(&rib.subs_lock);
- return 0;
+ return sid;
}
int ro_unsubscribe(int sid)
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index fe2c3336..c7e17ff6 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -629,7 +629,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
&timeout)) {
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
return (void *) -1; /* -ENOTENROLLED */
}
@@ -680,7 +680,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
if (ipcp_get_state() == IPCP_INIT)
ipcp_set_state(IPCP_NULL);
- if (ipcp_get_state() == IPCP_RUNNING)
+ if (ipcp_get_state() == IPCP_OPERATIONAL)
ipcp_set_state(IPCP_SHUTDOWN);
pthread_rwlock_unlock(&ipcpi.state_lock);
@@ -845,7 +845,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
eth_llc_data.tx_offset = 0;
#endif
- ipcp_set_state(IPCP_RUNNING);
+ ipcp_set_state(IPCP_OPERATIONAL);
pthread_create(&eth_llc_data.sdu_reader,
NULL,
@@ -951,7 +951,7 @@ static int eth_llc_ipcp_flow_alloc(int fd,
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't allocate flow with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
@@ -1051,7 +1051,7 @@ static int eth_llc_ipcp_flow_dealloc(int fd)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 67161d90..fd321780 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -486,7 +486,7 @@ static void * ipcp_udp_sdu_loop(void * o)
while (flow_event_wait(udp_data.np1_flows, udp_data.fq, &timeout)) {
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
return (void *) -1; /* -ENOTENROLLED */
}
@@ -531,7 +531,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
if (ipcp_get_state() == IPCP_INIT)
ipcp_set_state(IPCP_NULL);
- if (ipcp_get_state() == IPCP_RUNNING)
+ if (ipcp_get_state() == IPCP_OPERATIONAL)
ipcp_set_state(IPCP_SHUTDOWN);
pthread_rwlock_unlock(&ipcpi.state_lock);
@@ -616,7 +616,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
FD_CLR(udp_data.s_fd, &udp_data.flow_fd_s);
- ipcp_set_state(IPCP_RUNNING);
+ ipcp_set_state(IPCP_OPERATIONAL);
pthread_create(&udp_data.handler,
NULL,
@@ -890,7 +890,7 @@ static int ipcp_udp_name_query(char * name)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't query a name on a non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
@@ -915,7 +915,7 @@ static int ipcp_udp_name_query(char * name)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't add name to the directory.");
return -1; /* -ENOTENROLLED */
@@ -991,7 +991,7 @@ static int ipcp_udp_flow_alloc(int fd,
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't allocate flow with non-enrolled IPCP.");
close(skfd);
@@ -1113,7 +1113,7 @@ static int ipcp_udp_flow_dealloc(int fd)
pthread_rwlock_rdlock(&ipcpi.state_lock);
- if (ipcp_get_state() != IPCP_RUNNING) {
+ if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_DBG("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */