summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-21 15:26:04 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-21 15:30:33 +0100
commit933a7b93a679b994214c49540d891a901c7d5458 (patch)
tree23ebcbec3857b3322a9b6cb6f36463ae4157ee15 /src/ipcpd/normal
parent3bb7ed41f8c96a15f16281f3c9f282e6690aed38 (diff)
downloadouroboros-933a7b93a679b994214c49540d891a901c7d5458.tar.gz
ouroboros-933a7b93a679b994214c49540d891a901c7d5458.zip
ipcpd: normal: Split fmgr init into init and start
This split the initialization of the flow manager into an init part and a start part. This avoids the usage of data structures that have not been properly initialized yet.
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/fmgr.c82
-rw-r--r--src/ipcpd/normal/fmgr.h4
-rw-r--r--src/ipcpd/normal/main.c36
-rw-r--r--src/ipcpd/normal/neighbors.c4
-rw-r--r--src/ipcpd/normal/routing.c4
5 files changed, 78 insertions, 52 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index 184baf82..790b34dd 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -87,10 +87,12 @@ static int fmgr_neighbor_event(enum nb_event event,
case NEIGHBOR_ADDED:
ipcp_flow_get_qoscube(conn.flow_info.fd, &cube);
flow_set_add(fmgr.nm1_set[cube], conn.flow_info.fd);
+ log_dbg("Added fd %d to flow set.", conn.flow_info.fd);
break;
case NEIGHBOR_REMOVED:
ipcp_flow_get_qoscube(conn.flow_info.fd, &cube);
flow_set_del(fmgr.nm1_set[cube], conn.flow_info.fd);
+ log_dbg("Removed fd %d from flow set.", conn.flow_info.fd);
break;
default:
break;
@@ -251,7 +253,6 @@ static void fmgr_destroy_pff(void)
int fmgr_init(void)
{
- enum pol_gam pg;
int i;
int j;
struct conn_info info;
@@ -288,13 +289,6 @@ int fmgr_init(void)
}
}
- if (rib_read(BOOT_PATH "/dt/gam/type", &pg, sizeof(pg))
- != sizeof(pg)) {
- log_err("Failed to read policy for ribmgr gam.");
- fmgr_destroy_flows();
- return -1;
- }
-
strcpy(info.ae_name, DT_AE);
strcpy(info.protocol, FRCT_PROTO);
info.pref_version = 1;
@@ -316,18 +310,18 @@ int fmgr_init(void)
return -1;
}
- if (routing_init(fmgr.nbs)) {
- log_err("Failed to init routing.");
+ fmgr.nb_notifier.notify_call = fmgr_neighbor_event;
+ if (nbs_reg_notifier(fmgr.nbs, &fmgr.nb_notifier)) {
+ log_err("Failed to register notifier.");
nbs_destroy(fmgr.nbs);
fmgr_destroy_flows();
connmgr_ae_destroy(fmgr.ae);
return -1;
}
- fmgr.nb_notifier.notify_call = fmgr_neighbor_event;
- if (nbs_reg_notifier(fmgr.nbs, &fmgr.nb_notifier)) {
- log_err("Failed to register notifier.");
- routing_fini();
+ if (routing_init(fmgr.nbs)) {
+ log_err("Failed to init routing.");
+ nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
nbs_destroy(fmgr.nbs);
fmgr_destroy_flows();
connmgr_ae_destroy(fmgr.ae);
@@ -335,9 +329,8 @@ int fmgr_init(void)
}
if (pthread_rwlock_init(&fmgr.np1_flows_lock, NULL)) {
- gam_destroy(fmgr.gam);
- nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
routing_fini();
+ nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
nbs_destroy(fmgr.nbs);
fmgr_destroy_flows();
connmgr_ae_destroy(fmgr.ae);
@@ -350,8 +343,8 @@ int fmgr_init(void)
for (j = 0; j < i; ++j)
pff_destroy(fmgr.pff[j]);
pthread_rwlock_destroy(&fmgr.np1_flows_lock);
- nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
routing_fini();
+ nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
nbs_destroy(fmgr.nbs);
fmgr_destroy_flows();
connmgr_ae_destroy(fmgr.ae);
@@ -364,8 +357,8 @@ int fmgr_init(void)
routing_i_destroy(fmgr.routing[j]);
fmgr_destroy_pff();
pthread_rwlock_destroy(&fmgr.np1_flows_lock);
- nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
routing_fini();
+ nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
nbs_destroy(fmgr.nbs);
fmgr_destroy_flows();
connmgr_ae_destroy(fmgr.ae);
@@ -373,17 +366,40 @@ int fmgr_init(void)
}
}
+ return 0;
+}
+
+void fmgr_fini()
+{
+ nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
+
+ fmgr_destroy_routing();
+
+ fmgr_destroy_pff();
+
+ routing_fini();
+
+ fmgr_destroy_flows();
+
+ connmgr_ae_destroy(fmgr.ae);
+
+ nbs_destroy(fmgr.nbs);
+}
+
+int fmgr_start(void)
+{
+ enum pol_gam pg;
+
+ if (rib_read(BOOT_PATH "/dt/gam/type", &pg, sizeof(pg))
+ != sizeof(pg)) {
+ log_err("Failed to read policy for ribmgr gam.");
+ return -1;
+ }
+
fmgr.gam = gam_create(pg, fmgr.nbs, fmgr.ae);
if (fmgr.gam == NULL) {
log_err("Failed to init dt graph adjacency manager.");
- fmgr_destroy_routing();
- fmgr_destroy_pff();
- pthread_rwlock_destroy(&fmgr.np1_flows_lock);
nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
- routing_fini();
- nbs_destroy(fmgr.nbs);
- fmgr_destroy_flows();
- connmgr_ae_destroy(fmgr.ae);
return -1;
}
@@ -393,7 +409,7 @@ int fmgr_init(void)
return 0;
}
-void fmgr_fini()
+void fmgr_stop(void)
{
pthread_cancel(fmgr.np1_sdu_reader);
pthread_cancel(fmgr.nm1_sdu_reader);
@@ -401,21 +417,7 @@ void fmgr_fini()
pthread_join(fmgr.np1_sdu_reader, NULL);
pthread_join(fmgr.nm1_sdu_reader, NULL);
- nbs_unreg_notifier(fmgr.nbs, &fmgr.nb_notifier);
-
gam_destroy(fmgr.gam);
-
- fmgr_destroy_routing();
-
- fmgr_destroy_pff();
-
- routing_fini();
-
- fmgr_destroy_flows();
-
- connmgr_ae_destroy(fmgr.ae);
-
- nbs_destroy(fmgr.nbs);
}
int fmgr_np1_alloc(int fd,
diff --git a/src/ipcpd/normal/fmgr.h b/src/ipcpd/normal/fmgr.h
index f5076eab..b4d0b65a 100644
--- a/src/ipcpd/normal/fmgr.h
+++ b/src/ipcpd/normal/fmgr.h
@@ -33,6 +33,10 @@ int fmgr_init(void);
void fmgr_fini(void);
+int fmgr_start(void);
+
+void fmgr_stop(void);
+
int fmgr_np1_alloc(int fd,
char * dst_ap_name,
qoscube_t qos);
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 398d6ee3..7acf3046 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -143,25 +143,27 @@ static int boot_components(void)
log_dbg("Ribmgr started.");
- if (fmgr_init()) {
+ if (frct_init()) {
dir_fini();
ribmgr_fini();
addr_auth_fini();
- log_err("Failed to start flow manager.");
+ log_err("Failed to initialize FRCT.");
return -1;
}
- if (frct_init()) {
- fmgr_fini();
+ if (fmgr_start()) {
+ frct_fini();
dir_fini();
ribmgr_fini();
addr_auth_fini();
- log_err("Failed to initialize FRCT.");
+ log_err("Failed to start flow manager.");
return -1;
}
+
if (enroll_start()) {
- fmgr_fini();
+ fmgr_stop();
+ frct_fini();
dir_fini();
ribmgr_fini();
addr_auth_fini();
@@ -174,8 +176,8 @@ static int boot_components(void)
if (connmgr_start()) {
ipcp_set_state(IPCP_INIT);
enroll_stop();
+ fmgr_stop();
frct_fini();
- fmgr_fini();
dir_fini();
ribmgr_fini();
addr_auth_fini();
@@ -194,7 +196,7 @@ void shutdown_components(void)
frct_fini();
- fmgr_fini();
+ fmgr_stop();
dir_fini();
@@ -418,7 +420,6 @@ int main(int argc,
exit(EXIT_FAILURE);
}
-
if (connmgr_init()) {
log_err("Failed to initialize connection manager.");
ipcp_create_r(getpid(), -1);
@@ -438,11 +439,23 @@ int main(int argc,
exit(EXIT_FAILURE);
}
+ if (fmgr_init()) {
+ log_err("Failed to initialize flow manager component.");
+ ipcp_create_r(getpid(), -1);
+ enroll_fini();
+ connmgr_fini();
+ rib_fini();
+ irm_unbind_api(getpid(), ipcpi.name);
+ ipcp_fini();
+ exit(EXIT_FAILURE);
+ }
+
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ipcp_boot() < 0) {
log_err("Failed to boot IPCP.");
ipcp_create_r(getpid(), -1);
+ fmgr_fini();
enroll_fini();
connmgr_fini();
rib_fini();
@@ -457,6 +470,7 @@ int main(int argc,
log_err("Failed to notify IRMd we are initialized.");
ipcp_set_state(IPCP_NULL);
ipcp_shutdown();
+ fmgr_fini();
enroll_fini();
connmgr_fini();
rib_fini();
@@ -470,12 +484,14 @@ int main(int argc,
if (ipcp_get_state() == IPCP_SHUTDOWN)
shutdown_components();
- rib_fini();
+ fmgr_fini();
enroll_fini();
connmgr_fini();
+ rib_fini();
+
irm_unbind_api(getpid(), ipcpi.name);
ipcp_fini();
diff --git a/src/ipcpd/normal/neighbors.c b/src/ipcpd/normal/neighbors.c
index 1c399145..66da0462 100644
--- a/src/ipcpd/normal/neighbors.c
+++ b/src/ipcpd/normal/neighbors.c
@@ -114,8 +114,8 @@ int nbs_add(struct nbs * nbs,
pthread_mutex_unlock(&nbs->list_lock);
- log_info("Added neighbor with address %" PRIu64 " to list.",
- conn.conn_info.addr);
+ log_info("Added neighbor with fd %d and address %" PRIu64 " to list.",
+ conn.flow_info.fd, conn.conn_info.addr);
return 0;
}
diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c
index 745d1812..0b82b70d 100644
--- a/src/ipcpd/normal/routing.c
+++ b/src/ipcpd/normal/routing.c
@@ -129,6 +129,8 @@ static int routing_neighbor_event(enum nb_event event,
return -1;
}
+ log_dbg("Added %s to RIB.", path);
+
break;
case NEIGHBOR_REMOVED:
if (rib_del(path)) {
@@ -136,6 +138,8 @@ static int routing_neighbor_event(enum nb_event event,
return -1;
}
+ log_dbg("Removed %s from RIB.", path);
+
break;
case NEIGHBOR_QOS_CHANGE:
log_info("Not currently supported.");