summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-08 17:07:45 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-08 17:07:45 +0000
commit6ade491f770904d8244863904359c449b5aeb5f7 (patch)
tree26a9c0b622b5bf875b783692837d1069799f8fcc /src/ipcpd
parent9117f7f6fec70f2da24e8e77256747d11d67bf8d (diff)
parent742d01a4f9a32f17561104ee7da8971c1bcdd703 (diff)
downloadouroboros-6ade491f770904d8244863904359c449b5aeb5f7.tar.gz
ouroboros-6ade491f770904d8244863904359c449b5aeb5f7.zip
Merged in dstaesse/ouroboros/be-syslog (pull request #364)
lib: Log to the logging system
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/ipcp.c137
-rw-r--r--src/ipcpd/ipcp.h4
-rw-r--r--src/ipcpd/local/main.c72
-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
-rw-r--r--src/ipcpd/shim-eth-llc/main.c127
-rw-r--r--src/ipcpd/shim-udp/main.c165
-rw-r--r--src/ipcpd/shim-udp/tests/shim_udp_test.c14
-rw-r--r--src/ipcpd/timerwheel.c10
15 files changed, 402 insertions, 436 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 53213c39..42720867 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -85,11 +85,11 @@ static void * ipcp_main_loop(void * o)
if (setsockopt(lsockfd, SOL_SOCKET, SO_RCVTIMEO,
(void *) &ltv, sizeof(ltv)))
- LOG_WARN("Failed to set timeout on socket.");
+ log_warn("Failed to set timeout on socket.");
count = read(lsockfd, buf, IPCP_MSG_BUF_SIZE);
if (count <= 0) {
- LOG_ERR("Failed to read from socket");
+ log_err("Failed to read from socket");
close(lsockfd);
continue;
}
@@ -103,7 +103,7 @@ static void * ipcp_main_loop(void * o)
switch (msg->code) {
case IPCP_MSG_CODE__IPCP_BOOTSTRAP:
if (ipcpi.ops->ipcp_bootstrap == NULL) {
- LOG_ERR("Bootstrap unsupported.");
+ log_err("Bootstrap unsupported.");
break;
}
conf_msg = msg->conf;
@@ -140,7 +140,7 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_ENROLL:
if (ipcpi.ops->ipcp_enroll == NULL) {
- LOG_ERR("Enroll unsupported.");
+ log_err("Enroll unsupported.");
break;
}
ret_msg.has_result = true;
@@ -149,7 +149,7 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_NAME_REG:
if (ipcpi.ops->ipcp_name_reg == NULL) {
- LOG_ERR("Ap_reg unsupported.");
+ log_err("Ap_reg unsupported.");
break;
}
ret_msg.has_result = true;
@@ -158,7 +158,7 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_NAME_UNREG:
if (ipcpi.ops->ipcp_name_unreg == NULL) {
- LOG_ERR("Ap_unreg unsupported.");
+ log_err("Ap_unreg unsupported.");
break;
}
ret_msg.has_result = true;
@@ -167,7 +167,7 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_NAME_QUERY:
if (ipcpi.ops->ipcp_name_query == NULL) {
- LOG_ERR("Ap_query unsupported.");
+ log_err("Ap_query unsupported.");
break;
}
ret_msg.has_result = true;
@@ -176,12 +176,12 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_FLOW_ALLOC:
if (ipcpi.ops->ipcp_flow_alloc == NULL) {
- LOG_ERR("Flow_alloc unsupported.");
+ log_err("Flow_alloc unsupported.");
break;
}
fd = np1_flow_alloc(msg->api, msg->port_id);
if (fd < 0) {
- LOG_ERR("Failed allocating fd on port_id %d.",
+ log_err("Failed allocating fd on port_id %d.",
msg->port_id);
ret_msg.has_result = true;
ret_msg.result = -1;
@@ -197,14 +197,14 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP:
if (ipcpi.ops->ipcp_flow_alloc_resp == NULL) {
- LOG_ERR("Flow_alloc_resp unsupported.");
+ log_err("Flow_alloc_resp unsupported.");
break;
}
if (!msg->response) {
fd = np1_flow_resp(msg->port_id);
if (fd < 0) {
- LOG_WARN("Port_id %d is not known.",
+ log_warn("Port_id %d is not known.",
msg->port_id);
ret_msg.has_result = true;
ret_msg.result = -1;
@@ -218,13 +218,13 @@ static void * ipcp_main_loop(void * o)
break;
case IPCP_MSG_CODE__IPCP_FLOW_DEALLOC:
if (ipcpi.ops->ipcp_flow_dealloc == NULL) {
- LOG_ERR("Flow_dealloc unsupported.");
+ log_err("Flow_dealloc unsupported.");
break;
}
fd = np1_flow_dealloc(msg->port_id);
if (fd < 0) {
- LOG_WARN("Could not deallocate port_id %d.",
+ log_warn("Could not deallocate port_id %d.",
msg->port_id);
ret_msg.has_result = true;
ret_msg.result = -1;
@@ -236,7 +236,7 @@ static void * ipcp_main_loop(void * o)
ipcpi.ops->ipcp_flow_dealloc(fd);
break;
default:
- LOG_ERR("Don't know that message code");
+ log_err("Don't know that message code");
break;
}
@@ -244,7 +244,7 @@ static void * ipcp_main_loop(void * o)
buffer.len = ipcp_msg__get_packed_size(&ret_msg);
if (buffer.len == 0) {
- LOG_ERR("Failed to send reply message");
+ log_err("Failed to send reply message");
close(lsockfd);
continue;
}
@@ -270,14 +270,61 @@ static void * ipcp_main_loop(void * o)
return (void *) 0;
}
-int ipcp_init(enum ipcp_type type,
+static int parse_args(int argc,
+ char * argv[],
+ bool * log)
+{
+ *log = false;
+
+ if (!(argc == 4 || argc == 3))
+ return -1;
+
+ /* argument 1: api of irmd */
+ if (atoi(argv[1]) == 0)
+ return -1;
+
+ ipcpi.irmd_api = atoi(argv[1]);
+
+ /* argument 2: IPCP name */
+ ipcpi.name = argv[2];
+
+ /* argument 3: syslog */
+ if (argv[3] != NULL)
+ *log = true;
+
+ return 0;
+}
+
+int ipcp_init(int argc,
+ char ** argv,
+ enum ipcp_type type,
struct ipcp_ops * ops)
{
+ bool log;
pthread_condattr_t cattr;
struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000),
(IPCP_ACCEPT_TIMEOUT % 1000) * 1000};
+ if (parse_args(argc, argv, &log)) {
+ log_err("Failed to parse arguments.");
+ return -1;
+ }
+
+ log_init(log);
+
+ if (type == IPCP_NORMAL) {
+ if (ap_init(argv[0])) {
+ log_err("Failed to init normal IPCP.");
+ return -1;
+ }
+ } else {
+ if (ap_init(NULL)) {
+ log_err("Failed to init shim IPCP.");
+ return -1;
+ }
+ }
+
ipcpi.irmd_fd = -1;
ipcpi.state = IPCP_NULL;
ipcpi.shim_data = NULL;
@@ -295,7 +342,7 @@ int ipcp_init(enum ipcp_type type,
ipcpi.sockfd = server_socket_open(ipcpi.sock_path);
if (ipcpi.sockfd < 0) {
- LOG_ERR("Could not open server socket.");
+ log_err("Could not open server socket.");
free(ipcpi.threadpool);
free(ipcpi.sock_path);
return -1;
@@ -303,7 +350,7 @@ int ipcp_init(enum ipcp_type type,
if (setsockopt(ipcpi.sockfd, SOL_SOCKET, SO_RCVTIMEO,
(void *) &tv, sizeof(tv)))
- LOG_WARN("Failed to set timeout on socket.");
+ log_warn("Failed to set timeout on socket.");
ipcpi.ops = ops;
@@ -338,7 +385,7 @@ int ipcp_boot()
if (pthread_create(&ipcpi.threadpool[t], NULL,
ipcp_main_loop, NULL)) {
int i;
- LOG_ERR("Failed to create main thread.");
+ log_err("Failed to create main thread.");
ipcp_set_state(IPCP_NULL);
for (i = 0; i < t; ++i)
pthread_join(ipcpi.threadpool[i], NULL);
@@ -355,14 +402,14 @@ void ipcp_shutdown()
for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t)
pthread_join(ipcpi.threadpool[t], NULL);
- LOG_DBG("IPCP %d shutting down. Bye.", getpid());
+ log_info("IPCP %d shutting down. Bye.", getpid());
}
void ipcp_fini()
{
close(ipcpi.sockfd);
if (unlink(ipcpi.sock_path))
- LOG_DBG("Could not unlink %s.", ipcpi.sock_path);
+ log_warn("Could not unlink %s.", ipcpi.sock_path);
free(ipcpi.sock_path);
free(ipcpi.threadpool);
@@ -372,6 +419,10 @@ void ipcp_fini()
pthread_cond_destroy(&ipcpi.state_cond);
pthread_mutex_destroy(&ipcpi.state_mtx);
pthread_rwlock_destroy(&ipcpi.state_lock);
+
+ log_fini();
+
+ ap_fini();
}
void ipcp_set_state(enum ipcp_state state)
@@ -424,47 +475,3 @@ int ipcp_wait_state(enum ipcp_state state,
return ret;
}
-
-int ipcp_parse_arg(int argc,
- char * argv[])
-{
- char * log_file;
- size_t len = 0;
-
- if (!(argc == 3 || argc == 2))
- return -1;
-
- /* argument 1: api of irmd */
- if (atoi(argv[1]) == 0)
- return -1;
-
- ipcpi.irmd_api = atoi(argv[1]);
-
- /* argument 2: IPCP name */
- ipcpi.name = argv[2];
-
- /* argument 3: logfile name (if any) */
- if (argv[3] == NULL)
- return 0;
-
- len += strlen(INSTALL_PREFIX);
- len += strlen(LOG_DIR);
- len += strlen(argv[3]);
-
- log_file = malloc(len + 1);
- if (log_file == NULL)
- return -1;
-
- strcpy(log_file, INSTALL_PREFIX);
- strcat(log_file, LOG_DIR);
- strcat(log_file, argv[3]);
- log_file[len] = '\0';
-
- if (set_logfile(log_file))
- LOG_ERR("Cannot open %s, falling back to stdout for logs.",
- log_file);
-
- free(log_file);
-
- return 0;
-}
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index 9a4d272a..de7d72b0 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -83,7 +83,9 @@ struct ipcp {
pthread_t * threadpool;
} ipcpi;
-int ipcp_init(enum ipcp_type type,
+int ipcp_init(int argc,
+ char ** argv,
+ enum ipcp_type type,
struct ipcp_ops * ops);
int ipcp_boot(void);
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 2cba053a..b49e1612 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define OUROBOROS_PREFIX "ipcpd/local"
+#define OUROBOROS_PREFIX "ipcpd-local"
#include <ouroboros/config.h>
#include <ouroboros/logs.h>
@@ -153,7 +153,7 @@ static int ipcp_local_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;
}
@@ -163,7 +163,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Bootstrapped local IPCP with api %d.", getpid());
+ log_info("Bootstrapped local IPCP with api %d.", getpid());
return 0;
}
@@ -172,7 +172,7 @@ static int ipcp_local_name_reg(char * name)
{
char * name_dup = strdup(name);
if (name_dup == NULL) {
- LOG_ERR("Failed to duplicate name.");
+ log_err("Failed to duplicate name.");
return -ENOMEM;
}
@@ -180,14 +180,14 @@ static int ipcp_local_name_reg(char * name)
if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Failed to add %s to local registry.", name);
+ log_dbg("Failed to add %s to local registry.", name);
free(name_dup);
return -1;
}
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Registered %s.", name);
+ log_info("Registered %s.", name);
return 0;
}
@@ -200,7 +200,7 @@ static int ipcp_local_name_unreg(char * name)
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Unregistered %s.", name);
+ log_info("Unregistered %s.", name);
return 0;
}
@@ -225,7 +225,7 @@ static int ipcp_local_flow_alloc(int fd,
{
int out_fd = -1;
- LOG_DBG("Allocating flow to %s on fd %d.", dst_name, fd);
+ log_dbg("Allocating flow to %s on fd %d.", dst_name, fd);
assert(dst_name);
assert(src_ae_name);
@@ -234,7 +234,7 @@ static int ipcp_local_flow_alloc(int fd,
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't register with non-enrolled IPCP.");
+ log_dbg("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -250,7 +250,7 @@ static int ipcp_local_flow_alloc(int fd,
pthread_rwlock_unlock(&local_data.lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Pending local allocation request on fd %d.", fd);
+ log_info("Pending local allocation request on fd %d.", fd);
return 0;
}
@@ -282,7 +282,7 @@ static int ipcp_local_flow_alloc_resp(int fd,
if ((ret = ipcp_flow_alloc_reply(out_fd, response)) < 0)
return -1;
- LOG_INFO("Flow allocation completed, fds (%d, %d).", out_fd, fd);
+ log_info("Flow allocation completed, fds (%d, %d).", out_fd, fd);
return ret;
}
@@ -297,7 +297,7 @@ static int ipcp_local_flow_dealloc(int fd)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't register with non-enrolled IPCP.");
+ log_dbg("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -312,7 +312,7 @@ static int ipcp_local_flow_dealloc(int fd)
pthread_rwlock_unlock(&local_data.lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_INFO("Flow with fd %d deallocated.", fd);
+ log_info("Flow with fd %d deallocated.", fd);
return 0;
}
@@ -339,23 +339,6 @@ int main(int argc,
sigaddset(&sigset, SIGHUP);
sigaddset(&sigset, SIGPIPE);
- if (ipcp_parse_arg(argc, argv)) {
- LOG_ERR("Failed to parse arguments.");
- exit(EXIT_FAILURE);
- }
-
- if (ap_init(NULL) < 0) {
- LOG_ERR("Failed to init application.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
- if (local_data_init() < 0) {
- LOG_ERR("Failed to init local data.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
/* init sig_act */
memset(&sig_act, 0, sizeof(sig_act));
@@ -368,25 +351,34 @@ int main(int argc,
sigaction(SIGHUP, &sig_act, NULL);
sigaction(SIGPIPE, &sig_act, NULL);
- if (ipcp_init(THIS_TYPE, &local_ops) < 0) {
- LOG_ERR("Failed to init IPCP.");
- close_logfile();
+ if (ipcp_init(argc, argv, THIS_TYPE, &local_ops) < 0) {
+ log_err("Failed to init IPCP.");
+ exit(EXIT_FAILURE);
+ }
+
+ if (local_data_init() < 0) {
+ log_err("Failed to init local data.");
+ ipcp_fini();
exit(EXIT_FAILURE);
}
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ipcp_boot() < 0) {
- LOG_ERR("Failed to boot IPCP.");
- close_logfile();
+ log_err("Failed to boot IPCP.");
+ local_data_fini();
+ 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.");
- close_logfile();
+ log_err("Failed to notify IRMd we are initialized.");
+ ipcp_set_state(IPCP_NULL);
+ ipcp_shutdown();
+ local_data_fini();
+ ipcp_fini();
exit(EXIT_FAILURE);
}
@@ -397,13 +389,9 @@ int main(int argc,
pthread_join(local_data.sduloop, NULL);
}
- ipcp_fini();
-
local_data_fini();
- ap_fini();
-
- close_logfile();
+ ipcp_fini();
exit(EXIT_SUCCESS);
}
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;
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index fba4f5f3..35ec0297 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -207,7 +207,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr,
struct eth_llc_frame * llc_frame;
if (payload == NULL) {
- LOG_ERR("Payload was NULL.");
+ log_err("Payload was NULL.");
return -1;
}
@@ -224,7 +224,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr,
pfd.events = POLLIN | POLLRDNORM | POLLERR;
if (poll(&pfd, 1, -1) <= 0) {
- LOG_ERR("Failed to poll.");
+ log_err("Failed to poll.");
continue;
}
@@ -261,7 +261,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr,
header->tp_status = TP_STATUS_SEND_REQUEST;
if (send(eth_llc_data.s_fd, NULL, 0, MSG_DONTWAIT) < 0) {
- LOG_ERR("Failed to write frame into TX_RING.");
+ log_err("Failed to write frame into TX_RING.");
return -1;
}
@@ -274,7 +274,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr,
0,
(struct sockaddr *) &eth_llc_data.device,
sizeof(eth_llc_data.device)) <= 0) {
- LOG_ERR("Failed to send message.");
+ log_err("Failed to send message.");
return -1;
}
#endif
@@ -299,7 +299,7 @@ static int eth_llc_ipcp_send_mgmt_frame(shim_eth_llc_msg_t * msg,
if (eth_llc_ipcp_send_frame(dst_addr, reverse_bits(MGMT_SAP),
reverse_bits(MGMT_SAP), buf, len)) {
- LOG_ERR("Failed to send management frame.");
+ log_err("Failed to send management frame.");
free(buf);
return -1;
}
@@ -362,7 +362,7 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap,
if (fd < 0) {
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Could not get new flow from IRMd.");
+ log_err("Could not get new flow from IRMd.");
return -1;
}
@@ -372,7 +372,7 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap,
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("New flow request, fd %d, remote SAP %d.", fd, r_sap);
+ log_dbg("New flow request, fd %d, remote SAP %d.", fd, r_sap);
return 0;
}
@@ -392,7 +392,7 @@ static int eth_llc_ipcp_sap_alloc_reply(uint8_t ssap,
if (fd < 0) {
pthread_rwlock_unlock(& eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("No flow found with that SAP.");
+ log_err("No flow found with that SAP.");
return -1; /* -EFLOWNOTFOUND */
}
@@ -406,7 +406,7 @@ static int eth_llc_ipcp_sap_alloc_reply(uint8_t ssap,
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Flow reply, fd %d, SSAP %d, DSAP %d.", fd, ssap, dsap);
+ log_dbg("Flow reply, fd %d, SSAP %d, DSAP %d.", fd, ssap, dsap);
if ((ret = ipcp_flow_alloc_reply(fd, response)) < 0)
return -1;
@@ -459,7 +459,7 @@ static int eth_llc_ipcp_mgmt_frame(uint8_t * buf,
{
shim_eth_llc_msg_t * msg = shim_eth_llc_msg__unpack(NULL, len, buf);
if (msg == NULL) {
- LOG_ERR("Failed to unpack.");
+ log_err("Failed to unpack.");
return -1;
}
@@ -486,7 +486,7 @@ static int eth_llc_ipcp_mgmt_frame(uint8_t * buf,
eth_llc_ipcp_name_query_reply(msg->dst_name, r_addr);
break;
default:
- LOG_ERR("Unknown message received %d.", msg->code);
+ log_err("Unknown message received %d.", msg->code);
shim_eth_llc_msg__free_unpacked(msg, NULL);
return -1;
}
@@ -527,7 +527,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
pfd.events = POLLIN | POLLRDNORM | POLLERR;
if (poll(&pfd, 1, -1) <= 0) {
- LOG_ERR("Failed to poll.");
+ log_err("Failed to poll.");
continue;
}
@@ -540,7 +540,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o)
frame_len = recv(eth_llc_data.s_fd, buf,
SHIM_ETH_LLC_MAX_SDU_SIZE, 0);
if (frame_len < 0) {
- LOG_ERR("Failed to receive frame.");
+ log_err("Failed to receive frame.");
continue;
}
#endif
@@ -641,7 +641,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
while ((fd = fqueue_next(eth_llc_data.fq)) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
- LOG_ERR("Bad read from fd %d.", fd);
+ log_err("Bad read from fd %d.", fd);
continue;
}
@@ -715,7 +715,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
assert(conf->type == THIS_TYPE);
if (conf->if_name == NULL) {
- LOG_ERR("Interface name is NULL.");
+ log_err("Interface name is NULL.");
return -1;
}
@@ -725,20 +725,20 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
#ifdef __FreeBSD__
if (getifaddrs(&ifaddr) < 0) {
- LOG_ERR("Could not get interfaces.");
+ log_err("Could not get interfaces.");
return -1;
}
for (ifa = ifaddr, idx = 0; ifa != NULL; ifa = ifa->ifa_next, ++idx) {
if (strcmp(ifa->ifa_name, conf->if_name))
continue;
- LOG_DBG("Interface %s found.", conf->if_name);
+ log_dbg("Interface %s found.", conf->if_name);
memcpy(&ifr.ifr_addr, ifa->ifa_addr, sizeof(*ifa->ifa_addr));
break;
}
if (ifa == NULL) {
- LOG_ERR("Interface not found.");
+ log_err("Interface not found.");
freeifaddrs(ifaddr);
return -1;
}
@@ -747,12 +747,12 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
#else
skfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (skfd < 0) {
- LOG_ERR("Failed to open socket.");
+ log_err("Failed to open socket.");
return -1;
}
if (ioctl(skfd, SIOCGIFHWADDR, &ifr)) {
- LOG_ERR("Failed to ioctl.");
+ log_err("Failed to ioctl.");
close(skfd);
return -1;
}
@@ -761,7 +761,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
idx = if_nametoindex(conf->if_name);
if (idx == 0) {
- LOG_ERR("Failed to retrieve interface index.");
+ log_err("Failed to retrieve interface index.");
close(skfd);
return -1;
}
@@ -785,13 +785,13 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
skfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_802_2));
#endif
if (skfd < 0) {
- LOG_ERR("Failed to create socket.");
+ log_err("Failed to create socket.");
return -1;
}
#if defined(PACKET_RX_RING) && defined(PACKET_TX_RING)
if (SHIM_ETH_LLC_MAX_SDU_SIZE > SHM_RDRB_BLOCK_SIZE) {
- LOG_ERR("Max SDU size is bigger than DU map block size.");
+ log_err("Max SDU size is bigger than DU map block size.");
close(skfd);
return -1;
}
@@ -803,20 +803,20 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
if (setsockopt(skfd, SOL_PACKET, PACKET_RX_RING,
(void *) &req, sizeof(req))) {
- LOG_ERR("Failed to set sockopt PACKET_RX_RING");
+ log_err("Failed to set sockopt PACKET_RX_RING");
close(skfd);
return -1;
}
if (setsockopt(skfd, SOL_PACKET, PACKET_TX_RING,
(void *) &req, sizeof(req))) {
- LOG_ERR("Failed to set sockopt PACKET_TX_RING");
+ log_err("Failed to set sockopt PACKET_TX_RING");
close(skfd);
return -1;
}
#endif
if (bind(skfd, (struct sockaddr *) &device, sizeof(device))) {
- LOG_ERR("Failed to bind socket to interface");
+ log_err("Failed to bind socket to interface");
close(skfd);
return -1;
}
@@ -827,7 +827,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
PROT_READ | PROT_WRITE, MAP_SHARED,
skfd, 0);
if (eth_llc_data.rx_ring == NULL) {
- LOG_ERR("Failed to mmap");
+ log_err("Failed to mmap");
close(skfd);
return -1;
}
@@ -839,7 +839,7 @@ static int eth_llc_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;
}
@@ -863,7 +863,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with api %d.",
+ log_dbg("Bootstrapped shim IPCP over Ethernet with LLC with api %d.",
getpid());
return 0;
@@ -873,7 +873,7 @@ static int eth_llc_ipcp_name_reg(char * name)
{
char * name_dup = strdup(name);
if (name_dup == NULL) {
- LOG_ERR("Failed to duplicate name.");
+ log_err("Failed to duplicate name.");
return -ENOMEM;
}
@@ -881,14 +881,14 @@ static int eth_llc_ipcp_name_reg(char * name)
if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to add %s to local registry.", name);
+ log_err("Failed to add %s to local registry.", name);
free(name_dup);
return -1;
}
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Registered %s.", name);
+ log_dbg("Registered %s.", name);
return 0;
}
@@ -949,13 +949,13 @@ static int eth_llc_ipcp_flow_alloc(int fd,
uint8_t r_addr[MAC_SIZE];
uint64_t addr = 0;
- LOG_DBG("Allocating flow to %s.", dst_name);
+ log_dbg("Allocating flow to %s.", dst_name);
if (dst_name == NULL || src_ae_name == NULL)
return -1;
if (cube != QOS_CUBE_BE && cube != QOS_CUBE_FRC) {
- LOG_DBG("Unsupported QoS requested.");
+ log_dbg("Unsupported QoS requested.");
return -1;
}
@@ -963,13 +963,13 @@ static int eth_llc_ipcp_flow_alloc(int fd,
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't allocate flow with non-enrolled IPCP.");
+ log_dbg("Won't allocate flow with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Destination unreachable.");
+ log_err("Destination unreachable.");
return -1;
}
addr = shim_data_dir_get_addr(ipcpi.shim_data, dst_name);
@@ -1008,7 +1008,7 @@ static int eth_llc_ipcp_flow_alloc(int fd,
flow_set_add(eth_llc_data.np1_flows, fd);
- LOG_DBG("Pending flow with fd %d on SAP %d.", fd, ssap);
+ log_dbg("Pending flow with fd %d on SAP %d.", fd, ssap);
return 0;
}
@@ -1049,7 +1049,7 @@ static int eth_llc_ipcp_flow_alloc_resp(int fd,
flow_set_add(eth_llc_data.np1_flows, fd);
- LOG_DBG("Accepted flow, fd %d, SAP %d.", fd, (uint8_t)ssap);
+ log_dbg("Accepted flow, fd %d, SAP %d.", fd, (uint8_t)ssap);
return 0;
}
@@ -1065,7 +1065,7 @@ static int eth_llc_ipcp_flow_dealloc(int fd)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't register with non-enrolled IPCP.");
+ log_dbg("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -1087,7 +1087,7 @@ static int eth_llc_ipcp_flow_dealloc(int fd)
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Flow with fd %d deallocated.", fd);
+ log_dbg("Flow with fd %d deallocated.", fd);
return 0;
}
@@ -1115,23 +1115,6 @@ int main(int argc,
sigaddset(&sigset, SIGHUP);
sigaddset(&sigset, SIGPIPE);
- if (ipcp_parse_arg(argc, argv)) {
- LOG_ERR("Failed to parse arguments.");
- exit(EXIT_FAILURE);
- }
-
- if (ap_init(NULL) < 0) {
- LOG_ERR("Failed to init application.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
- if (eth_llc_data_init() < 0) {
- LOG_ERR("Failed to init shim-eth-llc data.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
/* init sig_act */
memset(&sig_act, 0, sizeof(sig_act));
@@ -1144,25 +1127,35 @@ int main(int argc,
sigaction(SIGHUP, &sig_act, NULL);
sigaction(SIGPIPE, &sig_act, NULL);
- if (ipcp_init(THIS_TYPE, &eth_llc_ops) < 0) {
- LOG_ERR("Failed to init IPCP.");
- close_logfile();
+ if (ipcp_init(argc, argv, THIS_TYPE, &eth_llc_ops) < 0) {
+ log_err("Failed to init IPCP.");
exit(EXIT_FAILURE);
}
+ if (eth_llc_data_init() < 0) {
+ log_err("Failed to init shim-eth-llc data.");
+ ipcp_fini();
+ exit(EXIT_FAILURE);
+ }
+
+
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ipcp_boot() < 0) {
- LOG_ERR("Failed to boot IPCP.");
- close_logfile();
+ log_err("Failed to boot IPCP.");
+ eth_llc_data_fini();
+ 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.");
- close_logfile();
+ log_err("Failed to notify IRMd we are initialized.");
+ ipcp_set_state(IPCP_NULL);
+ ipcp_shutdown();
+ eth_llc_data_fini();
+ ipcp_fini();
exit(EXIT_FAILURE);
}
@@ -1175,13 +1168,9 @@ int main(int argc,
pthread_join(eth_llc_data.sdu_reader, NULL);
}
- ipcp_fini();
-
eth_llc_data_fini();
- ap_fini();
-
- close_logfile();
+ ipcp_fini();
exit(EXIT_SUCCESS);
}
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index a7c4254a..2a73077c 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -184,7 +184,7 @@ static int send_shim_udp_msg(shim_udp_msg_t * msg,
0,
(struct sockaddr *) &r_saddr,
sizeof(r_saddr)) == -1) {
- LOG_ERR("Failed to send message.");
+ log_err("Failed to send message.");
free(buf.data);
return -1;
}
@@ -240,11 +240,11 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
struct sockaddr_in f_saddr;
socklen_t f_saddr_len = sizeof(f_saddr);
- LOG_DBG("Port request arrived from UDP port %d",
+ log_dbg("Port request arrived from UDP port %d",
ntohs(c_saddr->sin_port));
if ((skfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- LOG_ERR("Could not create UDP socket.");
+ log_err("Could not create UDP socket.");
return -1;
}
@@ -254,19 +254,19 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
f_saddr.sin_port = 0;
if (bind(skfd, (struct sockaddr *) &f_saddr, sizeof(f_saddr)) < 0) {
- LOG_ERR("Could not bind to socket.");
+ log_err("Could not bind to socket.");
close(skfd);
return -1;
}
if (getsockname(skfd, (struct sockaddr *) &f_saddr, &f_saddr_len) < 0) {
- LOG_ERR("Could not get address from fd.");
+ log_err("Could not get address from fd.");
return -1;
}
/* connect stores the remote address in the file descriptor */
if (connect(skfd, (struct sockaddr *) c_saddr, sizeof(*c_saddr)) < 0) {
- LOG_ERR("Could not connect to remote UDP client.");
+ log_err("Could not connect to remote UDP client.");
close(skfd);
return -1;
}
@@ -279,7 +279,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
if (fd < 0) {
pthread_rwlock_unlock(&udp_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Could not get new flow from IRMd.");
+ log_err("Could not get new flow from IRMd.");
close(skfd);
return -1;
}
@@ -291,7 +291,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
pthread_rwlock_unlock(&udp_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Pending allocation request, fd %d, UDP port (%d, %d).",
+ log_dbg("Pending allocation request, fd %d, UDP port (%d, %d).",
fd, ntohs(f_saddr.sin_port), ntohs(c_saddr->sin_port));
return 0;
@@ -320,7 +320,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port,
struct sockaddr_in t_saddr;
socklen_t t_saddr_len = sizeof(t_saddr);
- LOG_DBG("Received reply for flow on udp port %d.",
+ log_dbg("Received reply for flow on udp port %d.",
ntohs(dst_udp_port));
pthread_rwlock_rdlock(&ipcpi.state_lock);
@@ -334,7 +334,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port,
/* get the original address with the LISTEN PORT */
if (getpeername(skfd, (struct sockaddr *) &t_saddr, &t_saddr_len) < 0) {
- LOG_DBG("Flow with fd %d has no peer.", fd);
+ log_dbg("Flow with fd %d has no peer.", fd);
return -1;
}
@@ -357,7 +357,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port,
if (ipcp_flow_alloc_reply(fd, response) < 0)
return -1;
- LOG_DBG("Flow allocation completed, UDP ports: (%d, %d).",
+ log_dbg("Flow allocation completed, UDP ports: (%d, %d).",
ntohs(dst_udp_port), ntohs(src_udp_port));
return ret;
@@ -406,7 +406,7 @@ static void * ipcp_udp_listener(void * o)
msg->response);
break;
default:
- LOG_ERR("Unknown message received %d.", msg->code);
+ log_err("Unknown message received %d.", msg->code);
shim_udp_msg__free_unpacked(msg, NULL);
continue;
}
@@ -498,7 +498,7 @@ static void * ipcp_udp_sdu_loop(void * o)
while ((fd = fqueue_next(udp_data.fq)) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
- LOG_ERR("Bad read from fd %d.", fd);
+ log_err("Bad read from fd %d.", fd);
continue;
}
@@ -506,7 +506,7 @@ static void * ipcp_udp_sdu_loop(void * o)
shm_du_buff_head(sdb),
shm_du_buff_tail(sdb) - shm_du_buff_head(sdb),
0) < 0)
- LOG_ERR("Failed to send SDU.");
+ log_err("Failed to send SDU.");
ipcp_flow_del(sdb);
}
@@ -560,7 +560,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
&conf->ip_addr,
ipstr,
INET_ADDRSTRLEN) == NULL) {
- LOG_ERR("Failed to convert IP address");
+ log_err("Failed to convert IP address");
return -1;
}
@@ -569,11 +569,11 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
&conf->dns_addr,
dnsstr,
INET_ADDRSTRLEN) == NULL) {
- LOG_ERR("Failed to convert DNS address");
+ log_err("Failed to convert DNS address");
return -1;
}
#ifndef CONFIG_OUROBOROS_ENABLE_DNS
- LOG_WARN("DNS disabled at compile time, address ignored");
+ log_warn("DNS disabled at compile time, address ignored");
#endif
} else {
strcpy(dnsstr, "not set");
@@ -581,7 +581,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
/* UDP listen server */
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
- LOG_ERR("Can't create socket.");
+ log_err("Can't create socket.");
return -1;
}
@@ -590,7 +590,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
SO_REUSEADDR,
&enable,
sizeof(int)) < 0)
- LOG_WARN("Failed to set SO_REUSEADDR.");
+ log_warn("Failed to set SO_REUSEADDR.");
memset((char *) &s_saddr, 0, sizeof(s_saddr));
udp_data.s_saddr.sin_family = AF_INET;
@@ -600,7 +600,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
if (bind(fd,
(struct sockaddr *) &udp_data.s_saddr,
sizeof(udp_data.s_saddr)) < 0) {
- LOG_ERR("Couldn't bind to %s.", ipstr);
+ log_err("Couldn't bind to %s.", ipstr);
close(fd);
return -1;
}
@@ -609,7 +609,7 @@ static int ipcp_udp_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.");
close(fd);
return -1;
}
@@ -638,9 +638,9 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Bootstrapped shim IPCP over UDP with api %d.", getpid());
- LOG_DBG("Bound to IP address %s.", ipstr);
- LOG_DBG("DNS server address is %s.", dnsstr);
+ log_dbg("Bootstrapped shim IPCP over UDP with api %d.", getpid());
+ log_dbg("Bound to IP address %s.", ipstr);
+ log_dbg("DNS server address is %s.", dnsstr);
return 0;
}
@@ -657,13 +657,13 @@ static int ddns_send(char * cmd)
char * envp[] = {0};
if (pipe(pipe_fd)) {
- LOG_ERR("Failed to create pipe.");
+ log_err("Failed to create pipe.");
return -1;
}
api = fork();
if (api == -1) {
- LOG_ERR("Failed to fork.");
+ log_err("Failed to fork.");
return -1;
}
@@ -676,7 +676,7 @@ static int ddns_send(char * cmd)
close(pipe_fd[0]);
if (write(pipe_fd[1], cmd, strlen(cmd)) == -1) {
- LOG_ERR("Failed to communicate with nsupdate.");
+ log_err("Failed to communicate with nsupdate.");
close(pipe_fd[1]);
return -1;
}
@@ -684,9 +684,9 @@ static int ddns_send(char * cmd)
waitpid(api, &wstatus, 0);
if (WIFEXITED(wstatus) == true &&
WEXITSTATUS(wstatus) == 0)
- LOG_DBG("Succesfully communicated with DNS server.");
+ log_dbg("Succesfully communicated with DNS server.");
else
- LOG_ERR("Failed to register with DNS server.");
+ log_err("Failed to register with DNS server.");
close(pipe_fd[1]);
return 0;
@@ -712,13 +712,13 @@ static uint32_t ddns_resolve(char * name,
if (pipe(pipe_fd)) {
- LOG_ERR("Failed to create pipe.");
+ log_err("Failed to create pipe.");
return 0;
}
api = fork();
if (api == -1) {
- LOG_ERR("Failed to fork.");
+ log_err("Failed to fork.");
return 0;
}
@@ -735,7 +735,7 @@ static uint32_t ddns_resolve(char * name,
count = read(pipe_fd[0], buf, SHIM_UDP_BUF_SIZE);
if (count <= 0) {
- LOG_ERR("Failed to communicate with nslookup.");
+ log_err("Failed to communicate with nslookup.");
close(pipe_fd[0]);
return 0;
}
@@ -745,9 +745,9 @@ static uint32_t ddns_resolve(char * name,
waitpid(api, &wstatus, 0);
if (WIFEXITED(wstatus) == true &&
WEXITSTATUS(wstatus) == 0)
- LOG_DBG("Succesfully communicated with nslookup.");
+ log_dbg("Succesfully communicated with nslookup.");
else
- LOG_ERR("Failed to resolve DNS address.");
+ log_err("Failed to resolve DNS address.");
buf[count] = '\0';
substr = strtok(buf, "\n");
@@ -757,12 +757,12 @@ static uint32_t ddns_resolve(char * name,
}
if (strstr(substr2, addr_str) == NULL) {
- LOG_ERR("Failed to resolve DNS address.");
+ log_err("Failed to resolve DNS address.");
return 0;
}
if (inet_pton(AF_INET, substr2 + strlen(addr_str) + 1, &ip_addr) != 1) {
- LOG_ERR("Failed to resolve DNS address.");
+ log_err("Failed to resolve DNS address.");
return 0;
}
@@ -783,13 +783,13 @@ static int ipcp_udp_name_reg(char * name)
char * name_dup;
if (strlen(name) > 24) {
- LOG_ERR("DNS names cannot be longer than 24 chars.");
+ log_err("DNS names cannot be longer than 24 chars.");
return -1;
}
name_dup = strdup(name);
if (name_dup == NULL) {
- LOG_ERR("Failed to duplicate name.");
+ log_err("Failed to duplicate name.");
return -ENOMEM;
}
@@ -797,7 +797,7 @@ static int ipcp_udp_name_reg(char * name)
if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to add %s to local registry.", name);
+ log_err("Failed to add %s to local registry.", name);
free(name_dup);
return -1;
}
@@ -835,7 +835,7 @@ static int ipcp_udp_name_reg(char * name)
#else
pthread_rwlock_unlock(&ipcpi.state_lock);
#endif
- LOG_DBG("Registered %s.", name);
+ log_dbg("Registered %s.", name);
return 0;
}
@@ -849,7 +849,7 @@ static int ipcp_udp_name_unreg(char * name)
uint32_t dns_addr;
#endif
if (strlen(name) > 24) {
- LOG_ERR("DNS names cannot be longer than 24 chars.");
+ log_err("DNS names cannot be longer than 24 chars.");
return -1;
}
@@ -894,7 +894,7 @@ static int ipcp_udp_name_query(char * name)
assert(name);
if (strlen(name) > 24) {
- LOG_ERR("DNS names cannot be longer than 24 chars.");
+ log_err("DNS names cannot be longer than 24 chars.");
return -1;
}
@@ -902,7 +902,7 @@ static int ipcp_udp_name_query(char * name)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't query a name on a non-enrolled IPCP.");
+ log_dbg("Won't query a name on a non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -919,7 +919,7 @@ static int ipcp_udp_name_query(char * name)
ip_addr = ddns_resolve(name, dns_addr);
if (ip_addr == 0) {
- LOG_DBG("Could not resolve %s.", name);
+ log_dbg("Could not resolve %s.", name);
return -1;
}
@@ -927,7 +927,7 @@ static int ipcp_udp_name_query(char * name)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't add name to the directory.");
+ log_dbg("Won't add name to the directory.");
return -1; /* -ENOTENROLLED */
}
} else {
@@ -935,7 +935,7 @@ static int ipcp_udp_name_query(char * name)
h = gethostbyname(name);
if (h == NULL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Could not resolve %s.", name);
+ log_dbg("Could not resolve %s.", name);
return -1;
}
@@ -946,7 +946,7 @@ static int ipcp_udp_name_query(char * name)
if (shim_data_dir_add_entry(ipcpi.shim_data, name, ip_addr)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("Failed to add directory entry.");
+ log_err("Failed to add directory entry.");
return -1;
}
@@ -966,19 +966,19 @@ static int ipcp_udp_flow_alloc(int fd,
int skfd;
uint32_t ip_addr = 0;
- LOG_DBG("Allocating flow to %s.", dst_name);
+ log_dbg("Allocating flow to %s.", dst_name);
assert(dst_name);
assert(src_ae_name);
if (strlen(dst_name) > 255
|| strlen(src_ae_name) > 255) {
- LOG_ERR("Name too long for this shim.");
+ log_err("Name too long for this shim.");
return -1;
}
if (cube != QOS_CUBE_BE && cube != QOS_CUBE_FRC) {
- LOG_DBG("Unsupported QoS requested.");
+ log_dbg("Unsupported QoS requested.");
return -1;
}
@@ -996,7 +996,7 @@ static int ipcp_udp_flow_alloc(int fd,
}
if (getsockname(skfd, (struct sockaddr *) &f_saddr, &f_saddr_len) < 0) {
- LOG_ERR("Could not get address from fd.");
+ log_err("Could not get address from fd.");
close(skfd);
return -1;
}
@@ -1005,14 +1005,14 @@ static int ipcp_udp_flow_alloc(int fd,
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't allocate flow with non-enrolled IPCP.");
+ log_dbg("Won't allocate flow with non-enrolled IPCP.");
close(skfd);
return -1; /* -ENOTENROLLED */
}
if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Could not resolve destination.");
+ log_dbg("Could not resolve destination.");
close(skfd);
return -1;
}
@@ -1058,7 +1058,7 @@ static int ipcp_udp_flow_alloc(int fd,
return -1;
}
- LOG_DBG("Flow pending on fd %d, UDP port %d.",
+ log_dbg("Flow pending on fd %d, UDP port %d.",
fd, ntohs(f_saddr.sin_port));
return fd;
@@ -1081,12 +1081,12 @@ static int ipcp_udp_flow_alloc_resp(int fd,
skfd = udp_data.fd_to_uf[fd].skfd;
if (getsockname(skfd, (struct sockaddr *) &f_saddr, &len) < 0) {
- LOG_DBG("Socket with fd %d has no address.", skfd);
+ log_dbg("Socket with fd %d has no address.", skfd);
return -1;
}
if (getpeername(skfd, (struct sockaddr *) &r_saddr, &len) < 0) {
- LOG_DBG("Socket with fd %d has no peer.", skfd);
+ log_dbg("Socket with fd %d has no peer.", skfd);
return -1;
}
@@ -1113,7 +1113,7 @@ static int ipcp_udp_flow_alloc_resp(int fd,
return -1;
}
- LOG_DBG("Accepted flow, fd %d on UDP port %d.",
+ log_dbg("Accepted flow, fd %d on UDP port %d.",
fd, ntohs(f_saddr.sin_port));
return 0;
@@ -1129,7 +1129,7 @@ static int ipcp_udp_flow_dealloc(int fd)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Won't register with non-enrolled IPCP.");
+ log_dbg("Won't register with non-enrolled IPCP.");
return -1; /* -ENOTENROLLED */
}
@@ -1155,7 +1155,7 @@ static int ipcp_udp_flow_dealloc(int fd)
pthread_rwlock_unlock(&udp_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_DBG("Flow with fd %d deallocated.", fd);
+ log_dbg("Flow with fd %d deallocated.", fd);
return 0;
}
@@ -1182,23 +1182,6 @@ int main(int argc,
sigaddset(&sigset, SIGHUP);
sigaddset(&sigset, SIGPIPE);
- if (ipcp_parse_arg(argc, argv)) {
- LOG_ERR("Failed to parse arguments.");
- exit(EXIT_FAILURE);
- }
-
- if (ap_init(NULL) < 0) {
- LOG_ERR("Failed to init application.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
- if (udp_data_init() < 0) {
- LOG_ERR("Failed to init shim-udp data.");
- close_logfile();
- exit(EXIT_FAILURE);
- }
-
/* init sig_act */
memset(&sig_act, 0, sizeof(sig_act));
@@ -1211,25 +1194,35 @@ int main(int argc,
sigaction(SIGHUP, &sig_act, NULL);
sigaction(SIGPIPE, &sig_act, NULL);
- if (ipcp_init(THIS_TYPE, &udp_ops) < 0) {
- LOG_ERR("Failed to init IPCP.");
- close_logfile();
+ if (ipcp_init(argc, argv, THIS_TYPE, &udp_ops) < 0) {
+ log_err("Failed to init IPCP.");
exit(EXIT_FAILURE);
}
+ if (udp_data_init() < 0) {
+ log_err("Failed to init shim-udp data.");
+ ipcp_fini();
+ exit(EXIT_FAILURE);
+ }
+
+
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ipcp_boot() < 0) {
- LOG_ERR("Failed to boot IPCP.");
- close_logfile();
+ log_err("Failed to boot IPCP.");
+ udp_data_fini();
+ 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.");
- close_logfile();
+ log_err("Failed to notify IRMd we are initialized.");
+ ipcp_set_state(IPCP_NULL);
+ ipcp_shutdown();
+ udp_data_fini();
+ ipcp_fini();
exit(EXIT_FAILURE);
}
@@ -1244,13 +1237,9 @@ int main(int argc,
pthread_join(udp_data.sdu_reader, NULL);
}
- ipcp_fini();
-
udp_data_fini();
- ap_fini();
-
- close_logfile();
+ ipcp_fini();
exit(EXIT_SUCCESS);
}
diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c
index a342712e..d4a5d8ed 100644
--- a/src/ipcpd/shim-udp/tests/shim_udp_test.c
+++ b/src/ipcpd/shim-udp/tests/shim_udp_test.c
@@ -48,29 +48,29 @@ int shim_udp_test(int argc, char ** argv)
dum = shm_du_map_create();
if (dum == NULL) {
- LOG_ERR("Failed to create shared memory.");
+ log_err("Failed to create shared memory.");
exit(1);
}
_ipcp = ipcp_udp_create(ipcp_name);
if (_ipcp == NULL) {
- LOG_ERR("Could not instantiate shim IPCP.");
+ log_err("Could not instantiate shim IPCP.");
shm_du_map_destroy(dum);
exit(1);
}
if (ipcp_udp_bootstrap(&conf)) {
- LOG_ERR("Could not bootstrap.");
+ log_err("Could not bootstrap.");
}
if (ipcp_udp_name_reg("bogus name")) {
- LOG_ERR("Failed to register application.");
+ log_err("Failed to register application.");
shm_du_map_destroy(dum);
exit(1);
}
if (ipcp_udp_name_unreg("bogus name")) {
- LOG_ERR("Failed to unregister application.");
+ log_err("Failed to unregister application.");
shm_du_map_destroy(dum);
exit(1);
}
@@ -78,7 +78,7 @@ int shim_udp_test(int argc, char ** argv)
for (i = 0; i < 1000; ++i) {
sprintf(bogus, "bogus name %4d", i);
if (ipcp_udp_name_reg(bogus)) {
- LOG_ERR("Failed to register application %s.", bogus);
+ log_err("Failed to register application %s.", bogus);
shm_du_map_destroy(dum);
exit(1);
}
@@ -87,7 +87,7 @@ int shim_udp_test(int argc, char ** argv)
for (i = 0; i < 1000; ++i) {
sprintf(bogus, "bogus name %4d", i);
if(ipcp_udp_name_unreg(bogus)) {
- LOG_ERR("Failed to unregister application %s.", bogus);
+ log_err("Failed to unregister application %s.", bogus);
shm_du_map_destroy(dum);
exit(1);
}
diff --git a/src/ipcpd/timerwheel.c b/src/ipcpd/timerwheel.c
index bb61bd91..6e5b7da9 100644
--- a/src/ipcpd/timerwheel.c
+++ b/src/ipcpd/timerwheel.c
@@ -235,14 +235,14 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
list_head_init(&tw->wq);
if (pthread_mutex_init(&tw->lock, NULL)) {
- LOG_DBG("Could not init mutex.");
+ log_dbg("Could not init mutex.");
free(tw->wheel);
free(tw);
return NULL;
}
if (pthread_mutex_init(&tw->s_lock, NULL)) {
- LOG_DBG("Could not init mutex.");
+ log_dbg("Could not init mutex.");
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
free(tw);
@@ -250,7 +250,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_cond_init(&tw->work, NULL)) {
- LOG_DBG("Could not init cond.");
+ log_dbg("Could not init cond.");
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
@@ -271,7 +271,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->worker, NULL, worker, (void *) tw)) {
- LOG_DBG("Could not create worker.");
+ log_dbg("Could not create worker.");
pthread_cond_destroy(&tw->work);
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
@@ -281,7 +281,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->ticker, NULL, movement, (void *) tw)) {
- LOG_DBG("Could not create timer.");
+ log_dbg("Could not create timer.");
tw_set_state(tw, TW_DESTROY);
pthread_join(tw->worker, NULL);
pthread_cond_destroy(&tw->work);