summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-02-08 17:09:55 +0100
committerdimitri staessens <[email protected]>2017-02-08 18:04:13 +0100
commit742d01a4f9a32f17561104ee7da8971c1bcdd703 (patch)
tree26a9c0b622b5bf875b783692837d1069799f8fcc /src/ipcpd/normal
parent9117f7f6fec70f2da24e8e77256747d11d67bf8d (diff)
downloadouroboros-742d01a4f9a32f17561104ee7da8971c1bcdd703.tar.gz
ouroboros-742d01a4f9a32f17561104ee7da8971c1bcdd703.zip
lib: Log to the logging system
This removes the logfile and outputs log messages to the logging system. The creation of the logfiles (as well as the ap_init() call) were moved into ipcp_init() to simplify the IPCP creation and shutdown. Fixes #25 Fixes #27
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/addr_auth.c6
-rw-r--r--src/ipcpd/normal/enroll.c56
-rw-r--r--src/ipcpd/normal/fmgr.c42
-rw-r--r--src/ipcpd/normal/frct.c18
-rw-r--r--src/ipcpd/normal/gam.c22
-rw-r--r--src/ipcpd/normal/main.c141
-rw-r--r--src/ipcpd/normal/pol/flat.c14
-rw-r--r--src/ipcpd/normal/ribmgr.c10
8 files changed, 150 insertions, 159 deletions
diff --git a/src/ipcpd/normal/addr_auth.c b/src/ipcpd/normal/addr_auth.c
index c41ffcd2..210744af 100644
--- a/src/ipcpd/normal/addr_auth.c
+++ b/src/ipcpd/normal/addr_auth.c
@@ -36,7 +36,7 @@ struct addr_auth * addr_auth_create(enum pol_addr_auth type)
tmp = malloc(sizeof(*tmp));
if (tmp == NULL) {
- LOG_ERR("Failed to malloc addr auth.");
+ log_err("Failed to malloc addr auth.");
return NULL;
}
@@ -46,7 +46,7 @@ struct addr_auth * addr_auth_create(enum pol_addr_auth type)
tmp->type = type;
break;
default:
- LOG_ERR("Unknown address authority type.");
+ log_err("Unknown address authority type.");
free(tmp);
return NULL;
}
@@ -62,7 +62,7 @@ int addr_auth_destroy(struct addr_auth * instance)
case FLAT_RANDOM:
break;
default:
- LOG_ERR("Unknown address authority type.");
+ log_err("Unknown address authority type.");
}
free(instance);
diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c
index 695ceb1d..fb4ff3c3 100644
--- a/src/ipcpd/normal/enroll.c
+++ b/src/ipcpd/normal/enroll.c
@@ -58,14 +58,14 @@ int enroll_handle(int fd)
if (flow_alloc_resp(fd, 0) < 0) {
flow_dealloc(fd);
- LOG_ERR("Could not respond to request.");
+ log_err("Could not respond to request.");
return -1;
}
ci = cdap_create(fd);
if (ci == NULL) {
flow_dealloc(fd);
- LOG_ERR("Failed to create CDAP instance.");
+ log_err("Failed to create CDAP instance.");
return -1;
}
@@ -78,11 +78,11 @@ int enroll_handle(int fd)
if (data != NULL) {
free(data);
- LOG_WARN("Received data with enrollment request.");
+ log_warn("Received data with enrollment request.");
}
if (oc != CDAP_READ) {
- LOG_WARN("Invalid request.");
+ log_warn("Invalid request.");
cdap_reply_send(ci, key, -1, NULL, 0);
cdap_destroy(ci);
flow_dealloc(fd);
@@ -97,7 +97,7 @@ int enroll_handle(int fd)
} else if (strcmp(name, dif_ro) == 0) {
dif_name_r = true;
} else {
- LOG_WARN("Illegal read: %s.", name);
+ log_warn("Illegal read: %s.", name);
cdap_reply_send(ci, key, -1, NULL, 0);
cdap_destroy(ci);
flow_dealloc(fd);
@@ -107,7 +107,7 @@ int enroll_handle(int fd)
len = rib_pack(name, &buf, PACK_HASH_ROOT);
if (len < 0) {
- LOG_ERR("Failed to pack %s.", name);
+ log_err("Failed to pack %s.", name);
cdap_reply_send(ci, key, -1, NULL, 0);
cdap_destroy(ci);
flow_dealloc(fd);
@@ -115,12 +115,12 @@ int enroll_handle(int fd)
return -1;
}
- LOG_DBG("Packed %s (%lu bytes).", name, len);
+ log_dbg("Packed %s (%lu bytes).", name, len);
free(name);
if (cdap_reply_send(ci, key, 0, buf, len)) {
- LOG_ERR("Failed to send CDAP reply.");
+ log_err("Failed to send CDAP reply.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
@@ -129,7 +129,7 @@ int enroll_handle(int fd)
free(buf);
}
- LOG_DBG("Sent boot info to new member.");
+ log_dbg("Sent boot info to new member.");
cdap_destroy(ci);
@@ -152,44 +152,44 @@ int enroll_boot(char * dst_name)
fd = flow_alloc(dst_name, ENROLL_AE, NULL);
if (fd < 0) {
- LOG_ERR("Failed to allocate flow.");
+ log_err("Failed to allocate flow.");
return -1;
}
if (flow_alloc_res(fd)) {
- LOG_ERR("Flow allocation failed.");
+ log_err("Flow allocation failed.");
flow_dealloc(fd);
return -1;
}
ci = cdap_create(fd);
if (ci == NULL) {
- LOG_ERR("Failed to create CDAP instance.");
+ log_err("Failed to create CDAP instance.");
flow_dealloc(fd);
return -1;
}
- LOG_DBG("Getting boot information from %s.", dst_name);
+ log_dbg("Getting boot information from %s.", dst_name);
key = cdap_request_send(ci, CDAP_READ, boot_ro, NULL, 0, 0);
if (key < 0) {
- LOG_ERR("Failed to send CDAP request.");
+ log_err("Failed to send CDAP request.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
if (cdap_reply_wait(ci, key, &data, &len)) {
- LOG_ERR("Failed to get CDAP reply.");
+ log_err("Failed to get CDAP reply.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
- LOG_DBG("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%lu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
- LOG_WARN("Error unpacking RIB data.");
+ log_warn("Error unpacking RIB data.");
rib_del(boot_ro);
free(data);
cdap_destroy(ci);
@@ -197,27 +197,27 @@ int enroll_boot(char * dst_name)
return -1;
}
- LOG_DBG("Packed information inserted into RIB.");
+ log_dbg("Packed information inserted into RIB.");
key = cdap_request_send(ci, CDAP_READ, members_ro, NULL, 0, 0);
if (key < 0) {
- LOG_ERR("Failed to send CDAP request.");
+ log_err("Failed to send CDAP request.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
if (cdap_reply_wait(ci, key, &data, &len)) {
- LOG_ERR("Failed to get CDAP reply.");
+ log_err("Failed to get CDAP reply.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
- LOG_DBG("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%lu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
- LOG_WARN("Error unpacking RIB data.");
+ log_warn("Error unpacking RIB data.");
rib_del(boot_ro);
free(data);
cdap_destroy(ci);
@@ -225,27 +225,27 @@ int enroll_boot(char * dst_name)
return -1;
}
- LOG_DBG("Packed information inserted into RIB.");
+ log_dbg("Packed information inserted into RIB.");
key = cdap_request_send(ci, CDAP_READ, dif_ro, NULL, 0, 0);
if (key < 0) {
- LOG_ERR("Failed to send CDAP request.");
+ log_err("Failed to send CDAP request.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
if (cdap_reply_wait(ci, key, &data, &len)) {
- LOG_ERR("Failed to get CDAP reply.");
+ log_err("Failed to get CDAP reply.");
cdap_destroy(ci);
flow_dealloc(fd);
return -1;
}
- LOG_DBG("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%lu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
- LOG_WARN("Error unpacking RIB data.");
+ log_warn("Error unpacking RIB data.");
rib_del(boot_ro);
free(data);
cdap_destroy(ci);
@@ -253,7 +253,7 @@ int enroll_boot(char * dst_name)
return -1;
}
- LOG_DBG("Packed information inserted into RIB.");
+ log_dbg("Packed information inserted into RIB.");
cdap_destroy(ci);
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c
index b79d20b4..b958abfa 100644
--- a/src/ipcpd/normal/fmgr.c
+++ b/src/ipcpd/normal/fmgr.c
@@ -98,13 +98,13 @@ static void * fmgr_np1_sdu_reader(void * o)
continue;
if (ret < 0) {
- LOG_WARN("Event error: %d.", ret);
+ log_warn("Event error: %d.", ret);
continue;
}
while ((fd = fqueue_next(fmgr.np1_fqs[i])) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
- LOG_WARN("Failed to read SDU from fd %d.", fd);
+ log_warn("Failed to read SDU from fd %d.", fd);
continue;
}
@@ -113,7 +113,7 @@ static void * fmgr_np1_sdu_reader(void * o)
if (frct_i_write_sdu(fmgr.np1_fd_to_cep_id[fd], sdb)) {
pthread_rwlock_unlock(&fmgr.np1_flows_lock);
ipcp_flow_del(sdb);
- LOG_WARN("Failed to hand SDU to FRCT.");
+ log_warn("Failed to hand SDU to FRCT.");
continue;
}
@@ -149,23 +149,23 @@ void * fmgr_nm1_sdu_reader(void * o)
continue;
if (ret < 0) {
- LOG_ERR("Event error: %d.", ret);
+ log_err("Event error: %d.", ret);
continue;
}
while ((fd = fqueue_next(fmgr.nm1_fqs[i])) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
- LOG_ERR("Failed to read SDU from fd %d.", fd);
+ log_err("Failed to read SDU from fd %d.", fd);
continue;
}
shm_pci_des(sdb, &pci);
if (pci.dst_addr != ipcpi.address) {
- LOG_DBG("PDU needs to be forwarded.");
+ log_dbg("PDU needs to be forwarded.");
if (pci.ttl == 0) {
- LOG_DBG("TTL was zero.");
+ log_dbg("TTL was zero.");
ipcp_flow_del(sdb);
continue;
}
@@ -181,7 +181,7 @@ void * fmgr_nm1_sdu_reader(void * o)
shm_pci_shrink(sdb);
if (frct_nm1_post_sdu(&pci, sdb)) {
- LOG_ERR("Failed to hand PDU to FRCT.");
+ log_err("Failed to hand PDU to FRCT.");
ipcp_flow_del(sdb);
continue;
}
@@ -203,7 +203,7 @@ static void * fmgr_nm1_flow_wait(void * o)
while (true) {
if (gam_flow_wait(fmgr.gam, &fd, &info, &qs)) {
- LOG_ERR("Failed to get next flow descriptor.");
+ log_err("Failed to get next flow descriptor.");
continue;
}
@@ -287,13 +287,13 @@ int fmgr_init(void)
if (rib_read("/" BOOT_NAME "/dt/gam/type", &pg, sizeof(pg))
!= sizeof(pg)) {
- LOG_ERR("Failed to read policy for ribmgr gam.");
+ log_err("Failed to read policy for ribmgr gam.");
return -1;
}
if (rib_read("/" BOOT_NAME "/dt/gam/cacep", &pc, sizeof(pc))
!= sizeof(pc)) {
- LOG_ERR("Failed to read CACEP policy for ribmgr gam.");
+ log_err("Failed to read CACEP policy for ribmgr gam.");
return -1;
}
@@ -302,7 +302,7 @@ int fmgr_init(void)
fmgr.gam = gam_create(pg, DT_AE);
if (fmgr.gam == NULL) {
- LOG_ERR("Failed to create graph adjacency manager.");
+ log_err("Failed to create graph adjacency manager.");
fmgr_destroy_flows();
return -1;
}
@@ -536,7 +536,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id,
msg = flow_alloc_msg__unpack(NULL, buf->len, buf->data);
if (msg == NULL) {
- LOG_ERR("Failed to unpack flow alloc message");
+ log_err("Failed to unpack flow alloc message");
return -1;
}
@@ -548,7 +548,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id,
msg->qoscube);
if (fd < 0) {
flow_alloc_msg__free_unpacked(msg, NULL);
- LOG_ERR("Failed to get fd for flow.");
+ log_err("Failed to get fd for flow.");
return -1;
}
@@ -584,7 +584,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id,
ret = flow_dealloc(fd);
break;
default:
- LOG_ERR("Got an unknown flow allocation message.");
+ log_err("Got an unknown flow allocation message.");
ret = -1;
break;
}
@@ -604,7 +604,7 @@ int fmgr_np1_post_sdu(cep_id_t cep_id,
fd = fmgr.np1_cep_id_to_fd[cep_id];
if (ipcp_flow_write(fd, sdb)) {
pthread_rwlock_unlock(&fmgr.np1_flows_lock);
- LOG_ERR("Failed to hand SDU to N flow.");
+ log_err("Failed to hand SDU to N flow.");
return -1;
}
@@ -619,7 +619,7 @@ int fmgr_nm1_flow_arr(int fd,
assert(fmgr.gam);
if (gam_flow_arr(fmgr.gam, fd, qs)) {
- LOG_ERR("Failed to hand to graph adjacency manager.");
+ log_err("Failed to hand to graph adjacency manager.");
return -1;
}
@@ -633,13 +633,13 @@ int fmgr_nm1_write_sdu(struct pci * pci,
return -1;
if (shm_pci_ser(sdb, pci)) {
- LOG_ERR("Failed to serialize PDU.");
+ log_err("Failed to serialize PDU.");
ipcp_flow_del(sdb);
return -1;
}
if (ipcp_flow_write(fmgr.fd, sdb)) {
- LOG_ERR("Failed to write SDU to fd %d.", fmgr.fd);
+ log_err("Failed to write SDU to fd %d.", fmgr.fd);
ipcp_flow_del(sdb);
return -1;
}
@@ -657,13 +657,13 @@ int fmgr_nm1_write_buf(struct pci * pci,
buffer = shm_pci_ser_buf(buf, pci);
if (buffer == NULL) {
- LOG_ERR("Failed to serialize buffer.");
+ log_err("Failed to serialize buffer.");
free(buf->data);
return -1;
}
if (flow_write(fmgr.fd, buffer->data, buffer->len) == -1) {
- LOG_ERR("Failed to write buffer to fd.");
+ log_err("Failed to write buffer to fd.");
free(buffer);
return -1;
}
diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c
index ce316ca2..915feaf8 100644
--- a/src/ipcpd/normal/frct.c
+++ b/src/ipcpd/normal/frct.c
@@ -225,7 +225,7 @@ int frct_nm1_post_sdu(struct pci * pci,
buf.data = shm_du_buff_head(sdb);
if (fmgr_np1_post_buf(id, &buf)) {
- LOG_ERR("Failed to hand buffer to FMGR.");
+ log_err("Failed to hand buffer to FMGR.");
free(pci);
return -1;
}
@@ -244,14 +244,14 @@ int frct_nm1_post_sdu(struct pci * pci,
buf.data = shm_du_buff_head(sdb);
if (fmgr_np1_post_buf(pci->dst_cep_id, &buf)) {
- LOG_ERR("Failed to hand buffer to Flow Manager.");
+ log_err("Failed to hand buffer to Flow Manager.");
free(pci);
return -1;
}
} else {
/* FIXME: Known cep-ids are delivered to FMGR (minimal DTP) */
if (fmgr_np1_post_sdu(pci->dst_cep_id, sdb)) {
- LOG_ERR("Failed to hand SDU to FMGR.");
+ log_err("Failed to hand SDU to FMGR.");
free(pci);
return -1;
}
@@ -293,7 +293,7 @@ cep_id_t frct_i_create(uint64_t address,
if (fmgr_nm1_write_buf(&pci, buf)) {
free(instance);
- LOG_ERR("Failed to hand PDU to FMGR.");
+ log_err("Failed to hand PDU to FMGR.");
return INVALID_CEP_ID;
}
@@ -315,7 +315,7 @@ int frct_i_accept(cep_id_t id,
instance = frct.instances[id];
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- LOG_ERR("Invalid instance.");
+ log_err("Invalid instance.");
return -1;
}
@@ -355,7 +355,7 @@ int frct_i_destroy(cep_id_t id,
instance = frct.instances[id];
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- LOG_ERR("Invalid instance.");
+ log_err("Invalid instance.");
return -1;
}
@@ -401,13 +401,13 @@ int frct_i_write_sdu(cep_id_t id,
instance = frct.instances[id];
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- LOG_ERR("Invalid instance.");
+ log_err("Invalid instance.");
return -1;
}
if (instance->state != CONN_ESTABLISHED) {
pthread_mutex_unlock(&frct.instances_lock);
- LOG_ERR("Connection is not established.");
+ log_err("Connection is not established.");
return -1;
}
@@ -421,7 +421,7 @@ int frct_i_write_sdu(cep_id_t id,
if (fmgr_nm1_write_sdu(&pci, sdb)) {
pthread_mutex_unlock(&frct.instances_lock);
- LOG_ERR("Failed to hand SDU to FMGR.");
+ log_err("Failed to hand SDU to FMGR.");
return -1;
}
diff --git a/src/ipcpd/normal/gam.c b/src/ipcpd/normal/gam.c
index c337afd0..fae34dfe 100644
--- a/src/ipcpd/normal/gam.c
+++ b/src/ipcpd/normal/gam.c
@@ -72,7 +72,7 @@ struct gam * gam_create(enum pol_gam gam_type,
tmp->ops = &complete_ops;
break;
default:
- LOG_ERR("Unknown gam policy: %d.", gam_type);
+ log_err("Unknown gam policy: %d.", gam_type);
free(tmp);
return NULL;
}
@@ -169,7 +169,7 @@ static int add_ga(struct gam * instance,
pthread_cond_signal(&instance->gas_cond);
pthread_mutex_unlock(&instance->gas_lock);
- LOG_INFO("Added %s flow to %s.", instance->ae_name, info->name);
+ log_info("Added %s flow to %s.", instance->ae_name, info->name);
return 0;
}
@@ -183,19 +183,19 @@ int gam_flow_arr(struct gam * instance,
if (flow_alloc_resp(fd, instance->ops->accept_new_flow(instance->ops_o))
< 0) {
- LOG_ERR("Could not respond to new flow.");
+ log_err("Could not respond to new flow.");
return -1;
}
cacep = cacep_create(fd, ipcpi.name, ipcpi.address);
if (cacep == NULL) {
- LOG_ERR("Failed to create CACEP instance.");
+ log_err("Failed to create CACEP instance.");
return -1;
}
info = cacep_auth_wait(cacep);
if (info == NULL) {
- LOG_ERR("Other side failed to authenticate.");
+ log_err("Other side failed to authenticate.");
cacep_destroy(cacep);
return -1;
}
@@ -210,7 +210,7 @@ int gam_flow_arr(struct gam * instance,
}
if (add_ga(instance, fd, qs, info)) {
- LOG_ERR("Failed to add ga to graph adjacency manager list.");
+ log_err("Failed to add ga to graph adjacency manager list.");
free(info->name);
free(info);
return -1;
@@ -230,25 +230,25 @@ int gam_flow_alloc(struct gam * instance,
fd = flow_alloc(dst_name, instance->ae_name, NULL);
if (fd < 0) {
- LOG_ERR("Failed to allocate flow to %s.", dst_name);
+ log_err("Failed to allocate flow to %s.", dst_name);
return -1;
}
if (flow_alloc_res(fd)) {
- LOG_ERR("Flow allocation to %s failed.", dst_name);
+ log_err("Flow allocation to %s failed.", dst_name);
flow_dealloc(fd);
return -1;
}
cacep = cacep_create(fd, ipcpi.name, ipcpi.address);
if (cacep == NULL) {
- LOG_ERR("Failed to create CACEP instance.");
+ log_err("Failed to create CACEP instance.");
return -1;
}
info = cacep_auth(cacep);
if (info == NULL) {
- LOG_ERR("Failed to authenticate.");
+ log_err("Failed to authenticate.");
cacep_destroy(cacep);
return -1;
}
@@ -262,7 +262,7 @@ int gam_flow_alloc(struct gam * instance,
}
if (add_ga(instance, fd, qs, info)) {
- LOG_ERR("Failed to add GA to graph adjacency manager list.");
+ log_err("Failed to add GA to graph adjacency manager list.");
free(info);
return -1;
}
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 97484958..5d8af688 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -99,7 +99,7 @@ static void * flow_acceptor(void * o)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Shutting down flow acceptor.");
+ log_info("Shutting down flow acceptor.");
return 0;
}
@@ -107,11 +107,11 @@ static void * flow_acceptor(void * o)
fd = flow_accept(&ae_name, &qs);
if (fd < 0) {
- LOG_WARN("Flow accept failed.");
+ log_warn("Flow accept failed.");
continue;
}
- LOG_DBG("New flow allocation request for AE %s.", ae_name);
+ log_dbg("New flow allocation request for AE %s.", ae_name);
if (strcmp(ae_name, ENROLL_AE) == 0) {
enroll_handle(fd);
@@ -120,10 +120,10 @@ static void * flow_acceptor(void * o)
} else if (strcmp(ae_name, DT_AE) == 0) {
fmgr_nm1_flow_arr(fd, qs);
} else {
- LOG_DBG("Flow allocation request for unknown AE %s.",
+ log_dbg("Flow allocation request for unknown AE %s.",
ae_name);
if (flow_alloc_resp(fd, -1))
- LOG_WARN("Failed to reply to flow allocation.");
+ log_warn("Failed to reply to flow allocation.");
flow_dealloc(fd);
}
@@ -146,66 +146,66 @@ static int boot_components(void)
len = rib_read(DIF_PATH, &buf, 256);
if (len < 0) {
- LOG_ERR("Failed to read DIF name: %ld.", len);
+ log_err("Failed to read DIF name: %ld.", len);
return -1;
}
ipcpi.dif_name = strdup(buf);
if (ipcpi.dif_name == NULL) {
- LOG_ERR("Failed to set DIF name.");
+ log_err("Failed to set DIF name.");
return -1;
}
if (rib_add(MEMBERS_PATH, ipcpi.name)) {
- LOG_WARN("Failed to add name to " MEMBERS_PATH);
+ log_warn("Failed to add name to " MEMBERS_PATH);
return -1;
}
- LOG_DBG("Starting components.");
+ log_dbg("Starting components.");
if (rib_read(BOOT_PATH "/addr_auth/type", &pa, sizeof(pa))
!= sizeof(pa)) {
- LOG_ERR("Failed to read policy for address authority.");
+ log_err("Failed to read policy for address authority.");
return -1;
}
normal.auth = addr_auth_create(pa);
if (normal.auth == NULL) {
- LOG_ERR("Failed to init address authority.");
+ log_err("Failed to init address authority.");
return -1;
}
ipcpi.address = normal.auth->address();
if (ipcpi.address == 0) {
- LOG_ERR("Failed to get a valid address.");
+ log_err("Failed to get a valid address.");
addr_auth_destroy(normal.auth);
return -1;
}
- LOG_DBG("IPCP got address %lu.", ipcpi.address);
+ log_dbg("IPCP got address %lu.", ipcpi.address);
- LOG_DBG("Starting ribmgr.");
+ log_dbg("Starting ribmgr.");
if (ribmgr_init()) {
- LOG_ERR("Failed to initialize RIB manager.");
+ log_err("Failed to initialize RIB manager.");
addr_auth_destroy(normal.auth);
return -1;
}
if (dir_init()) {
- LOG_ERR("Failed to initialize directory.");
+ log_err("Failed to initialize directory.");
ribmgr_fini();
addr_auth_destroy(normal.auth);
return -1;
}
- LOG_DBG("Ribmgr started.");
+ log_dbg("Ribmgr started.");
if (fmgr_init()) {
dir_fini();
ribmgr_fini();
addr_auth_destroy(normal.auth);
- LOG_ERR("Failed to start flow manager.");
+ log_err("Failed to start flow manager.");
return -1;
}
@@ -214,7 +214,7 @@ static int boot_components(void)
dir_fini();
ribmgr_fini();
addr_auth_destroy(normal.auth);
- LOG_ERR("Failed to initialize FRCT.");
+ log_err("Failed to initialize FRCT.");
return -1;
}
@@ -226,45 +226,61 @@ static int boot_components(void)
dir_fini();
ribmgr_fini();
addr_auth_destroy(normal.auth);
- LOG_ERR("Failed to create acceptor thread.");
+ log_err("Failed to create acceptor thread.");
return -1;
}
return 0;
}
+void shutdown_components(void)
+{
+ pthread_cancel(normal.acceptor);
+ pthread_join(normal.acceptor, NULL);
+
+ frct_fini();
+
+ fmgr_fini();
+
+ dir_fini();
+
+ ribmgr_fini();
+
+ addr_auth_destroy(normal.auth);
+}
+
static int normal_ipcp_enroll(char * dst_name)
{
pthread_rwlock_wrlock(&ipcpi.state_lock);
if (ipcp_get_state() != IPCP_INIT) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP in wrong state.");
+ log_err("IPCP in wrong state.");
return -1; /* -ENOTINIT */
}
if (rib_add(RIB_ROOT, MEMBERS_NAME)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to create members.");
+ log_err("Failed to create members.");
return -1;
}
/* Get boot state from peer */
if (enroll_boot(dst_name)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to boot IPCP components.");
+ log_err("Failed to boot IPCP components.");
return -1;
}
if (boot_components()) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to boot IPCP components.");
+ log_err("Failed to boot IPCP components.");
return -1;
}
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Enrolled with %s.", dst_name);
+ log_dbg("Enrolled with %s.", dst_name);
return 0;
}
@@ -314,7 +330,7 @@ int normal_rib_init(void)
for (r = (struct ros *) ros; r->parent; ++r) {
if (rib_add(r->parent, r->child)) {
- LOG_ERR("Failed to create %s/%s",
+ log_err("Failed to create %s/%s",
r->parent, r->child);
return -1;
}
@@ -331,7 +347,7 @@ static int normal_ipcp_bootstrap(struct dif_config * conf)
(void) pol;
if (conf == NULL || conf->type != THIS_TYPE) {
- LOG_ERR("Bad DIF configuration.");
+ log_err("Bad DIF configuration.");
return -EINVAL;
}
@@ -339,13 +355,13 @@ static int normal_ipcp_bootstrap(struct dif_config * conf)
if (ipcp_get_state() != IPCP_INIT) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP in wrong state.");
+ log_err("IPCP in wrong state.");
return -1; /* -ENOTINIT */
}
if (normal_rib_init()) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to write initial structure to the RIB.");
+ log_err("Failed to write initial structure to the RIB.");
return -1;
}
@@ -388,20 +404,20 @@ static int normal_ipcp_bootstrap(struct dif_config * conf)
rib_write(BOOT_PATH "/addr_auth/type",
&conf->addr_auth_type,
sizeof(conf->addr_auth_type))) {
- LOG_ERR("Failed to write boot info to RIB.");
+ log_err("Failed to write boot info to RIB.");
pthread_rwlock_unlock(&ipcpi.state_lock);
return -1;
}
if (boot_components()) {
- LOG_ERR("Failed to boot IPCP components.");
+ log_err("Failed to boot IPCP components.");
pthread_rwlock_unlock(&ipcpi.state_lock);
return -1;
}
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Bootstrapped in DIF %s.", conf->dif_name);
+ log_dbg("Bootstrapped in DIF %s.", conf->dif_name);
return 0;
}
@@ -423,28 +439,12 @@ int main(int argc,
struct sigaction sig_act;
sigset_t sigset;
- if (ap_init(argv[0])) {
- LOG_ERR("Failed to init AP");
- exit(EXIT_FAILURE);
- }
-
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigaddset(&sigset, SIGQUIT);
sigaddset(&sigset, SIGHUP);
sigaddset(&sigset, SIGPIPE);
- if (ipcp_parse_arg(argc, argv)) {
- LOG_ERR("Failed to parse arguments.");
- exit(EXIT_FAILURE);
- }
-
- if (irm_bind_api(getpid(), ipcpi.name)) {
- LOG_ERR("Failed to bind AP name.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
/* init sig_act */
memset(&sig_act, 0, sizeof(sig_act));
@@ -457,59 +457,50 @@ int main(int argc,
sigaction(SIGHUP, &sig_act, NULL);
sigaction(SIGPIPE, &sig_act, NULL);
- if (rib_init()) {
- LOG_ERR("Failed to initialize RIB.");
- close_logfile();
+ if (irm_bind_api(getpid(), ipcpi.name)) {
+ log_err("Failed to bind AP name.");
exit(EXIT_FAILURE);
}
- if (ipcp_init(THIS_TYPE, &normal_ops) < 0) {
- LOG_ERR("Failed to create instance.");
- rib_fini();
- close_logfile();
+ if (ipcp_init(argc, argv, THIS_TYPE, &normal_ops) < 0) {
+ log_err("Failed to create instance.");
+ exit(EXIT_FAILURE);
+ }
+
+ if (rib_init()) {
+ log_err("Failed to initialize RIB.");
+ ipcp_fini();
exit(EXIT_FAILURE);
}
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ipcp_boot() < 0) {
- LOG_ERR("Failed to boot IPCP.");
- ipcp_fini();
+ log_err("Failed to boot IPCP.");
rib_fini();
- close_logfile();
+ ipcp_fini();
exit(EXIT_FAILURE);
}
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
if (ipcp_create_r(getpid())) {
- LOG_ERR("Failed to notify IRMd we are initialized.");
- ipcp_fini();
+ log_err("Failed to notify IRMd we are initialized.");
+ ipcp_set_state(IPCP_NULL);
+ ipcp_shutdown();
rib_fini();
- close_logfile();
+ ipcp_fini();
exit(EXIT_FAILURE);
}
ipcp_shutdown();
- if (ipcp_get_state() == IPCP_SHUTDOWN) {
- pthread_cancel(normal.acceptor);
- pthread_join(normal.acceptor, NULL);
- }
-
- ribmgr_fini();
-
- dir_fini();
-
- addr_auth_destroy(normal.auth);
+ if (ipcp_get_state() == IPCP_SHUTDOWN)
+ shutdown_components();
rib_fini();
ipcp_fini();
- close_logfile();
-
- ap_fini();
-
exit(EXIT_SUCCESS);
}
diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c
index 31fcd4e8..9ffeb5c7 100644
--- a/src/ipcpd/normal/pol/flat.c
+++ b/src/ipcpd/normal/pol/flat.c
@@ -102,29 +102,29 @@ uint64_t flat_address(void)
strcpy(path, "/" MEMBERS_NAME);
if (!rib_has(path)) {
- LOG_ERR("Could not read members from RIB.");
+ log_err("Could not read members from RIB.");
return INVALID_ADDRESS;
}
if (rib_read("/" BOOT_NAME "/dt/const/addr_size",
&addr_size, sizeof(addr_size)) != sizeof(addr_size)) {
- LOG_ERR("Failed to read address size.");
+ log_err("Failed to read address size.");
return INVALID_ADDRESS;
}
if (addr_size != 4) {
- LOG_ERR("Flat address policy mandates 4 byte addresses.");
+ log_err("Flat address policy mandates 4 byte addresses.");
return INVALID_ADDRESS;
}
n_members = rib_children(path, &members);
if (n_members > REC_DIF_SIZE)
- LOG_WARN("DIF exceeding recommended size for flat addresses.");
+ log_warn("DIF exceeding recommended size for flat addresses.");
rib_path_append(path, ipcpi.name);
if (!rib_has(path)) {
- LOG_ERR("This ipcp is not a member.");
+ log_err("This ipcp is not a member.");
freepp(char, members, n_members);
return INVALID_ADDRESS;
}
@@ -142,12 +142,12 @@ uint64_t flat_address(void)
freepp(char, members, n_members);
if (rib_add(path, name)) {
- LOG_ERR("Failed to add address to RIB.");
+ log_err("Failed to add address to RIB.");
return INVALID_ADDRESS;
}
if (rib_write(path, &addr, sizeof(addr))) {
- LOG_ERR("Failed to write address in RIB.");
+ log_err("Failed to write address in RIB.");
return INVALID_ADDRESS;
}
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 4ff316dc..05d881ea 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -60,13 +60,13 @@ int ribmgr_init(void)
if (rib_read(BOOT_PATH "/rm/gam/type", &pg, sizeof(pg))
!= sizeof(pg)) {
- LOG_ERR("Failed to read policy for ribmgr gam.");
+ log_err("Failed to read policy for ribmgr gam.");
return -1;
}
if (rib_read(BOOT_PATH "/rm/gam/cacep", &pc, sizeof(pc))
!= sizeof(pc)) {
- LOG_ERR("Failed to read CACEP policy for ribmgr gam.");
+ log_err("Failed to read CACEP policy for ribmgr gam.");
return -1;
}
@@ -75,20 +75,20 @@ int ribmgr_init(void)
ribmgr.gam = gam_create(pg, MGMT_AE);
if (ribmgr.gam == NULL) {
- LOG_ERR("Failed to create gam.");
+ log_err("Failed to create gam.");
return -1;
}
ribmgr.fs = flow_set_create();
if (ribmgr.fs == NULL) {
- LOG_ERR("Failed to create flow set.");
+ log_err("Failed to create flow set.");
gam_destroy(ribmgr.gam);
return -1;
}
ribmgr.fq = fqueue_create();
if (ribmgr.fq == NULL) {
- LOG_ERR("Failed to create fq.");
+ log_err("Failed to create fq.");
flow_set_destroy(ribmgr.fs);
gam_destroy(ribmgr.gam);
return -1;