summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ouroboros/utils.h4
-rw-r--r--src/ipcpd/broadcast/main.c27
-rw-r--r--src/ipcpd/common/enroll.c8
-rw-r--r--src/ipcpd/eth/eth.c5
-rw-r--r--src/ipcpd/ipcp.c311
-rw-r--r--src/ipcpd/ipcp.h48
-rw-r--r--src/ipcpd/local/main.c6
-rw-r--r--src/ipcpd/udp/main.c8
-rw-r--r--src/ipcpd/unicast/addr-auth/flat.c22
-rw-r--r--src/ipcpd/unicast/dir/dht.c8
-rw-r--r--src/ipcpd/unicast/dt.c23
-rw-r--r--src/ipcpd/unicast/fa.c3
-rw-r--r--src/ipcpd/unicast/main.c27
-rw-r--r--src/ipcpd/unicast/routing/link-state.c17
-rw-r--r--src/irmd/main.c2
-rw-r--r--src/irmd/reg/tests/flow_test.c2
-rw-r--r--src/irmd/reg/tests/reg_test.c12
-rw-r--r--src/lib/dev.c20
18 files changed, 292 insertions, 261 deletions
diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h
index 9c48b039..e1f0ca0e 100644
--- a/include/ouroboros/utils.h
+++ b/include/ouroboros/utils.h
@@ -33,11 +33,11 @@
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define clrbuf(buf) do { memset(&(buf), 0, sizeof(buf)); } while (0);
#define freebuf(buf) do { free((buf).data); clrbuf(buf); } while (0);
-#define BUF_INIT { NULL, 0 }
+#define BUF_INIT { 0, NULL }
typedef struct {
- uint8_t * data;
size_t len;
+ uint8_t * data;
} buffer_t;
/*
diff --git a/src/ipcpd/broadcast/main.c b/src/ipcpd/broadcast/main.c
index f51fc629..0f2bf26c 100644
--- a/src/ipcpd/broadcast/main.c
+++ b/src/ipcpd/broadcast/main.c
@@ -52,13 +52,8 @@
#include <assert.h>
#include <inttypes.h>
-struct ipcp ipcpi;
-
-static int initialize_components(const struct ipcp_config * conf)
+static int initialize_components(void)
{
- strcpy(ipcpi.layer_name, conf->layer_info.name);
- ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo;
-
assert(ipcp_dir_hash_len() != 0);
if (dt_init() < 0) {
@@ -107,6 +102,7 @@ static void stop_components(void)
static int broadcast_ipcp_enroll(const char * dst,
struct layer_info * info)
{
+ struct ipcp_config * conf;
struct conn conn;
uint8_t id[ENROLL_ID_LEN];
@@ -128,7 +124,10 @@ static int broadcast_ipcp_enroll(const char * dst,
goto fail_enroll_boot;
}
- if (initialize_components(enroll_get_conf()) < 0) {
+ conf = enroll_get_conf();
+ *info = conf->layer_info;
+
+ if (initialize_components() < 0) {
log_err_id(id, "Failed to initialize components.");
goto fail_enroll_boot;
}
@@ -146,9 +145,6 @@ static int broadcast_ipcp_enroll(const char * dst,
log_info_id(id, "Enrolled with %s.", dst);
- info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo;
- strcpy(info->name, ipcpi.layer_name);
-
return 0;
fail_start_comp:
@@ -163,12 +159,11 @@ static int broadcast_ipcp_bootstrap(const struct ipcp_config * conf)
{
assert(conf);
assert(conf->type == THIS_TYPE);
- ((struct ipcp_config *) conf)->layer_info.dir_hash_algo =
- DIR_HASH_SHA3_256;
+ assert(conf->layer_info.dir_hash_algo == DIR_HASH_SHA3_256);
enroll_bootstrap(conf);
- if (initialize_components(conf)) {
+ if (initialize_components()) {
log_err("Failed to init IPCP components.");
goto fail_init;
}
@@ -192,12 +187,12 @@ static int name_check(const uint8_t * dst)
size_t len;
int ret;
- len = hash_len(ipcpi.dir_hash_algo);
+ len = ipcp_dir_hash_len();
buf = malloc(len);
if (buf == NULL)
return -ENOMEM;
- str_hash(ipcpi.dir_hash_algo, buf, ipcpi.layer_name);
+ str_hash(HASH_SHA3_256, buf, ipcp_get_name());
ret = memcmp(buf, dst, len);
@@ -212,7 +207,7 @@ static int broadcast_ipcp_join(int fd,
{
struct conn conn;
time_t mpl = IPCP_BROADCAST_MPL;
- buffer_t data = {NULL, 0};
+ buffer_t data = {0, NULL};
(void) qs;
diff --git a/src/ipcpd/common/enroll.c b/src/ipcpd/common/enroll.c
index 5e35ce37..3fc999af 100644
--- a/src/ipcpd/common/enroll.c
+++ b/src/ipcpd/common/enroll.c
@@ -227,12 +227,14 @@ int enroll_boot(struct conn * conn,
return -1;
}
- if (resp.conf.type != ipcpi.type) {
+ if (resp.conf.type != ipcp_get_type()) {
log_err_id(id, "Wrong type in enrollment response %d (%d).",
- resp.conf.type, ipcpi.type);
+ resp.conf.type, ipcp_get_type());
return -1;
}
+ enroll.conf = resp.conf;
+
clock_gettime(CLOCK_REALTIME, &rtt);
delta_t = ts_diff_ms(&t0, &rtt);
@@ -243,8 +245,6 @@ int enroll_boot(struct conn * conn,
if (labs(ts_diff_ms(&t0, &rtt)) - delta_t > ENROLL_WARN_TIME_OFFSET)
log_warn_id(id, "Clock offset above threshold.");
- enroll.conf = resp.conf;
-
return 0;
}
diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c
index c0e6d0ce..e8c0d497 100644
--- a/src/ipcpd/eth/eth.c
+++ b/src/ipcpd/eth/eth.c
@@ -145,8 +145,6 @@
#define NAME_QUERY_REQ 2
#define NAME_QUERY_REPLY 3
-struct ipcp ipcpi;
-
struct mgmt_msg {
#if defined(BUILD_ETH_DIX)
uint16_t seid;
@@ -1247,9 +1245,6 @@ static int eth_ipcp_bootstrap(const struct ipcp_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo;
- strcpy(ipcpi.layer_name, conf->layer_info.name);
-
if (strlen(conf->eth.dev) >= IFNAMSIZ) {
log_err("Invalid device name: %s.", conf->eth.dev);
return -1;
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 39b053d6..bc16e2f0 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -68,6 +68,40 @@
#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
#endif
+struct {
+ pid_t irmd_pid;
+ char * name;
+
+ enum ipcp_type type;
+ char layer_name[LAYER_NAME_SIZE + 1];
+
+ uint64_t dt_addr;
+
+ enum hash_algo dir_hash_algo;
+
+ struct ipcp_ops * ops;
+ int irmd_fd;
+
+ enum ipcp_state state;
+ pthread_cond_t state_cond;
+ pthread_mutex_t state_mtx;
+
+ int sockfd;
+ char * sock_path;
+
+ struct list_head cmds;
+ pthread_cond_t cmd_cond;
+ pthread_mutex_t cmd_lock;
+
+ int alloc_id;
+ pthread_cond_t alloc_cond;
+ pthread_mutex_t alloc_lock;
+
+ struct tpm * tpm;
+
+ pthread_t acceptor;
+} ipcpd;
+
char * info[LAYER_NAME_SIZE + 1] = {
"_state",
"_type",
@@ -83,9 +117,24 @@ struct cmd {
int fd;
};
+enum ipcp_type ipcp_get_type(void)
+{
+ return ipcpd.type;
+}
+
+const char * ipcp_get_name(void)
+{
+ return ipcpd.name;
+}
+
+size_t ipcp_dir_hash_len(void)
+{
+ return hash_len(ipcpd.dir_hash_algo);
+}
+
uint8_t * ipcp_hash_dup(const uint8_t * hash)
{
- uint8_t * dup = malloc(hash_len(ipcpi.dir_hash_algo));
+ uint8_t * dup = malloc(hash_len(ipcpd.dir_hash_algo));
if (dup == NULL)
return NULL;
@@ -136,17 +185,17 @@ static int ipcp_rib_read(const char * path,
}
if (strcmp(entry, info[1]) == 0) { /* _type */
- if (ipcpi.type == IPCP_LOCAL)
+ if (ipcpd.type == IPCP_LOCAL)
strcpy(buf, "local\n");
- else if (ipcpi.type == IPCP_UNICAST)
+ else if (ipcpd.type == IPCP_UNICAST)
strcpy(buf, "unicast\n");
- else if (ipcpi.type == IPCP_BROADCAST)
+ else if (ipcpd.type == IPCP_BROADCAST)
strcpy(buf, "broadcast\n");
- else if (ipcpi.type == IPCP_ETH_LLC)
+ else if (ipcpd.type == IPCP_ETH_LLC)
strcpy(buf, "eth-llc\n");
- else if (ipcpi.type == IPCP_ETH_DIX)
+ else if (ipcpd.type == IPCP_ETH_DIX)
strcpy(buf, "eth-dix\n");
- else if (ipcpi.type == IPCP_UDP)
+ else if (ipcpd.type == IPCP_UDP)
strcpy(buf, "udp\n");
else
strcpy(buf, "bug\n");
@@ -157,7 +206,7 @@ static int ipcp_rib_read(const char * path,
if (ipcp_get_state() < IPCP_OPERATIONAL)
strcpy(buf, "(null)");
else
- strcpy(buf, ipcpi.layer_name);
+ strcpy(buf, ipcpd.layer_name);
buf[strlen(buf)] = '\n';
}
@@ -225,7 +274,7 @@ static void * acceptloop(void * o)
ipcp_get_state() != IPCP_NULL) {
struct cmd * cmd;
- csockfd = accept(ipcpi.sockfd, 0, 0);
+ csockfd = accept(ipcpd.sockfd, 0, 0);
if (csockfd < 0)
continue;
@@ -253,13 +302,13 @@ static void * acceptloop(void * o)
cmd->fd = csockfd;
- pthread_mutex_lock(&ipcpi.cmd_lock);
+ pthread_mutex_lock(&ipcpd.cmd_lock);
- list_add(&cmd->next, &ipcpi.cmds);
+ list_add(&cmd->next, &ipcpd.cmds);
- pthread_cond_signal(&ipcpi.cmd_cond);
+ pthread_cond_signal(&ipcpd.cmd_cond);
- pthread_mutex_unlock(&ipcpi.cmd_lock);
+ pthread_mutex_unlock(&ipcpd.cmd_lock);
}
return (void *) 0;
@@ -280,34 +329,34 @@ int ipcp_wait_flow_req_arr(const uint8_t * dst,
clock_gettime(PTHREAD_COND_CLOCK, &abstime);
- pthread_mutex_lock(&ipcpi.alloc_lock);
+ pthread_mutex_lock(&ipcpd.alloc_lock);
- while (ipcpi.alloc_id != -1 && ipcp_get_state() == IPCP_OPERATIONAL) {
+ while (ipcpd.alloc_id != -1 && ipcp_get_state() == IPCP_OPERATIONAL) {
ts_add(&abstime, &ts, &abstime);
- pthread_cond_timedwait(&ipcpi.alloc_cond,
- &ipcpi.alloc_lock,
+ pthread_cond_timedwait(&ipcpd.alloc_cond,
+ &ipcpd.alloc_lock,
&abstime);
}
if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_mutex_unlock(&ipcpi.alloc_lock);
+ pthread_mutex_unlock(&ipcpd.alloc_lock);
log_err("Won't allocate over non-operational IPCP.");
return -EIPCPSTATE;
}
- assert(ipcpi.alloc_id == -1);
+ assert(ipcpd.alloc_id == -1);
fd = ipcp_flow_req_arr(&hash, qs, mpl, data);
if (fd < 0) {
- pthread_mutex_unlock(&ipcpi.alloc_lock);
+ pthread_mutex_unlock(&ipcpd.alloc_lock);
log_err("Failed to get fd for flow.");
return fd;
}
- ipcpi.alloc_id = fd;
- pthread_cond_broadcast(&ipcpi.alloc_cond);
+ ipcpd.alloc_id = fd;
+ pthread_cond_broadcast(&ipcpd.alloc_cond);
- pthread_mutex_unlock(&ipcpi.alloc_lock);
+ pthread_mutex_unlock(&ipcpd.alloc_lock);
return fd;
@@ -320,26 +369,26 @@ int ipcp_wait_flow_resp(const int fd)
clock_gettime(PTHREAD_COND_CLOCK, &abstime);
- pthread_mutex_lock(&ipcpi.alloc_lock);
+ pthread_mutex_lock(&ipcpd.alloc_lock);
- while (ipcpi.alloc_id != fd && ipcp_get_state() == IPCP_OPERATIONAL) {
+ while (ipcpd.alloc_id != fd && ipcp_get_state() == IPCP_OPERATIONAL) {
ts_add(&abstime, &ts, &abstime);
- pthread_cond_timedwait(&ipcpi.alloc_cond,
- &ipcpi.alloc_lock,
+ pthread_cond_timedwait(&ipcpd.alloc_cond,
+ &ipcpd.alloc_lock,
&abstime);
}
if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_mutex_unlock(&ipcpi.alloc_lock);
+ pthread_mutex_unlock(&ipcpd.alloc_lock);
return -1;
}
- assert(ipcpi.alloc_id == fd);
+ assert(ipcpd.alloc_id == fd);
- ipcpi.alloc_id = -1;
- pthread_cond_broadcast(&ipcpi.alloc_cond);
+ ipcpd.alloc_id = -1;
+ pthread_cond_broadcast(&ipcpd.alloc_cond);
- pthread_mutex_unlock(&ipcpi.alloc_lock);
+ pthread_mutex_unlock(&ipcpd.alloc_lock);
return 0;
}
@@ -357,7 +406,7 @@ static void do_bootstrap(ipcp_config_msg_t * conf_msg,
log_info("Bootstrapping...");
- if (ipcpi.ops->ipcp_bootstrap == NULL) {
+ if (ipcpd.ops->ipcp_bootstrap == NULL) {
log_err("Bootstrap unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -370,8 +419,22 @@ static void do_bootstrap(ipcp_config_msg_t * conf_msg,
}
conf = ipcp_config_msg_to_s(conf_msg);
- ret_msg->result = ipcpi.ops->ipcp_bootstrap(&conf);
+ switch(conf.type) { /* FIXED algorithms */
+ case IPCP_UDP:
+ conf.layer_info.dir_hash_algo = (enum pol_dir_hash) HASH_MD5;
+ break;
+ case IPCP_BROADCAST:
+ conf.layer_info.dir_hash_algo = DIR_HASH_SHA3_256;
+ break;
+ default:
+ break;
+ }
+
+ ret_msg->result = ipcpd.ops->ipcp_bootstrap(&conf);
if (ret_msg->result == 0) {
+ enum pol_dir_hash algo = conf.layer_info.dir_hash_algo;
+ strcpy(ipcpd.layer_name, conf.layer_info.name);
+ ipcpd.dir_hash_algo = (enum hash_algo) algo;
ret_msg->layer_info = layer_info_s_to_msg(&conf.layer_info);
ipcp_set_state(IPCP_OPERATIONAL);
}
@@ -386,7 +449,7 @@ static void do_enroll(const char * dst,
log_info("Enrolling with %s...", dst);
- if (ipcpi.ops->ipcp_enroll == NULL) {
+ if (ipcpd.ops->ipcp_enroll == NULL) {
log_err("Enroll unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -398,8 +461,10 @@ static void do_enroll(const char * dst,
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_enroll(dst, &info);
+ ret_msg->result = ipcpd.ops->ipcp_enroll(dst, &info);
if (ret_msg->result == 0) {
+ strcpy(ipcpd.layer_name, info.name);
+ ipcpd.dir_hash_algo = (enum hash_algo) info.dir_hash_algo;
ret_msg->layer_info = layer_info_s_to_msg(&info);
ipcp_set_state(IPCP_OPERATIONAL);
}
@@ -414,13 +479,13 @@ static void do_connect(const char * dst,
{
log_info("Connecting %s to %s...", comp, dst);
- if (ipcpi.ops->ipcp_connect == NULL) {
+ if (ipcpd.ops->ipcp_connect == NULL) {
log_err("Connect unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_connect(dst, comp, qs);
+ ret_msg->result = ipcpd.ops->ipcp_connect(dst, comp, qs);
finish:
log_info("Finished connecting: %d.", ret_msg->result);
}
@@ -431,13 +496,13 @@ static void do_disconnect(const char * dst,
{
log_info("Disconnecting %s from %s...", comp, dst);
- if (ipcpi.ops->ipcp_disconnect == NULL) {
+ if (ipcpd.ops->ipcp_disconnect == NULL) {
log_err("Disconnect unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_disconnect(dst, comp);
+ ret_msg->result = ipcpd.ops->ipcp_disconnect(dst, comp);
finish:
log_info("Finished disconnecting %s from %s: %d.",
@@ -450,13 +515,13 @@ static void do_reg(const uint8_t * hash,
log_info("Registering " HASH_FMT32 "...", HASH_VAL32(hash));
- if (ipcpi.ops->ipcp_reg == NULL) {
+ if (ipcpd.ops->ipcp_reg == NULL) {
log_err("Registration unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_reg(hash);
+ ret_msg->result = ipcpd.ops->ipcp_reg(hash);
finish:
log_info("Finished registering " HASH_FMT32 " : %d.",
HASH_VAL32(hash), ret_msg->result);
@@ -467,13 +532,13 @@ static void do_unreg(const uint8_t * hash,
{
log_info("Unregistering " HASH_FMT32 "...", HASH_VAL32(hash));
- if (ipcpi.ops->ipcp_unreg == NULL) {
+ if (ipcpd.ops->ipcp_unreg == NULL) {
log_err("Unregistration unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_unreg(hash);
+ ret_msg->result = ipcpd.ops->ipcp_unreg(hash);
finish:
log_info("Finished unregistering " HASH_FMT32 ": %d.",
HASH_VAL32(hash), ret_msg->result);
@@ -484,7 +549,7 @@ static void do_query(const uint8_t * hash,
{
/* TODO: Log this operation when IRMd has internal caches. */
- if (ipcpi.ops->ipcp_query == NULL) {
+ if (ipcpd.ops->ipcp_query == NULL) {
log_err("Directory query unsupported.");
ret_msg->result = -ENOTSUP;
return;
@@ -496,7 +561,7 @@ static void do_query(const uint8_t * hash,
return;
}
- ret_msg->result = ipcpi.ops->ipcp_query(hash);
+ ret_msg->result = ipcpd.ops->ipcp_query(hash);
}
static void do_flow_alloc(pid_t pid,
@@ -511,7 +576,7 @@ static void do_flow_alloc(pid_t pid,
log_info("Allocating flow %d for %d to " HASH_FMT32 ".",
flow_id, pid, HASH_VAL32(dst));
- if (ipcpi.ops->ipcp_flow_alloc == NULL) {
+ if (ipcpd.ops->ipcp_flow_alloc == NULL) {
log_err("Flow allocation unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -531,7 +596,7 @@ static void do_flow_alloc(pid_t pid,
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_flow_alloc(fd, dst, qs, data);
+ ret_msg->result = ipcpd.ops->ipcp_flow_alloc(fd, dst, qs, data);
finish:
log_info("Finished allocating flow %d to " HASH_FMT32 ": %d.",
flow_id, HASH_VAL32(dst), ret_msg->result);
@@ -548,7 +613,7 @@ static void do_flow_join(pid_t pid,
log_info("Joining layer " HASH_FMT32 ".", HASH_VAL32(dst));
- if (ipcpi.ops->ipcp_flow_join == NULL) {
+ if (ipcpd.ops->ipcp_flow_join == NULL) {
log_err("Broadcast unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -567,7 +632,7 @@ static void do_flow_join(pid_t pid,
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_flow_join(fd, dst, qs);
+ ret_msg->result = ipcpd.ops->ipcp_flow_join(fd, dst, qs);
finish:
log_info("Finished joining layer " HASH_FMT32 ".", HASH_VAL32(dst));
}
@@ -581,7 +646,7 @@ static void do_flow_alloc_resp(int resp,
log_info("Responding %d to alloc on flow_id %d.", resp, flow_id);
- if (ipcpi.ops->ipcp_flow_alloc_resp == NULL) {
+ if (ipcpd.ops->ipcp_flow_alloc_resp == NULL) {
log_err("Flow_alloc_resp unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -602,7 +667,7 @@ static void do_flow_alloc_resp(int resp,
}
}
- ret_msg->result = ipcpi.ops->ipcp_flow_alloc_resp(fd, resp, data);
+ ret_msg->result = ipcpd.ops->ipcp_flow_alloc_resp(fd, resp, data);
finish:
log_info("Finished responding to allocation request: %d",
ret_msg->result);
@@ -616,7 +681,7 @@ static void do_flow_dealloc(int flow_id,
log_info("Deallocating flow %d.", flow_id);
- if (ipcpi.ops->ipcp_flow_dealloc == NULL) {
+ if (ipcpd.ops->ipcp_flow_dealloc == NULL) {
log_err("Flow deallocation unsupported.");
ret_msg->result = -ENOTSUP;
goto finish;
@@ -635,7 +700,7 @@ static void do_flow_dealloc(int flow_id,
goto finish;
}
- ret_msg->result = ipcpi.ops->ipcp_flow_dealloc(fd);
+ ret_msg->result = ipcpd.ops->ipcp_flow_dealloc(fd);
finish:
log_info("Finished deallocating flow %d: %d.",
flow_id, ret_msg->result);
@@ -657,14 +722,14 @@ static void * mainloop(void * o)
ret_msg.code = IPCP_MSG_CODE__IPCP_REPLY;
- pthread_mutex_lock(&ipcpi.cmd_lock);
+ pthread_mutex_lock(&ipcpd.cmd_lock);
- pthread_cleanup_push(__cleanup_mutex_unlock, &ipcpi.cmd_lock);
+ pthread_cleanup_push(__cleanup_mutex_unlock, &ipcpd.cmd_lock);
- while (list_is_empty(&ipcpi.cmds))
- pthread_cond_wait(&ipcpi.cmd_cond, &ipcpi.cmd_lock);
+ while (list_is_empty(&ipcpd.cmds))
+ pthread_cond_wait(&ipcpd.cmd_cond, &ipcpd.cmd_lock);
- cmd = list_last_entry(&ipcpi.cmds, struct cmd, next);
+ cmd = list_last_entry(&ipcpd.cmds, struct cmd, next);
list_del(&cmd->next);
pthread_cleanup_pop(true);
@@ -679,7 +744,7 @@ static void * mainloop(void * o)
continue;
}
- tpm_begin_work(ipcpi.tpm);
+ tpm_begin_work(ipcpd.tpm);
pthread_cleanup_push(__cleanup_close_ptr, &sfd);
pthread_cleanup_push(free_msg, msg);
@@ -753,7 +818,7 @@ static void * mainloop(void * o)
if (buffer.len == 0) {
log_err("Failed to pack reply message");
close(sfd);
- tpm_end_work(ipcpi.tpm);
+ tpm_end_work(ipcpd.tpm);
continue;
}
@@ -761,7 +826,7 @@ static void * mainloop(void * o)
if (buffer.data == NULL) {
log_err("Failed to create reply buffer.");
close(sfd);
- tpm_end_work(ipcpi.tpm);
+ tpm_end_work(ipcpd.tpm);
continue;
}
@@ -779,7 +844,7 @@ static void * mainloop(void * o)
pthread_cleanup_pop(true); /* close sfd */
pthread_cleanup_pop(true); /* free buffer.data */
- tpm_end_work(ipcpi.tpm);
+ tpm_end_work(ipcpd.tpm);
}
return (void *) 0;
@@ -798,10 +863,10 @@ static int parse_args(int argc,
if (atoi(argv[1]) == 0)
return -1;
- ipcpi.irmd_pid = atoi(argv[1]);
+ ipcpd.irmd_pid = atoi(argv[1]);
/* argument 2: IPCP name */
- ipcpi.name = argv[2];
+ ipcpd.name = argv[2];
/* argument 3: syslog */
if (argv[3] != NULL)
@@ -823,26 +888,26 @@ int ipcp_init(int argc,
log_init(log);
- ipcpi.state = IPCP_NULL;
- ipcpi.type = type;
+ ipcpd.state = IPCP_NULL;
+ ipcpd.type = type;
#if defined (__linux__)
prctl(PR_SET_TIMERSLACK, IPCP_LINUX_SLACK_NS, 0, 0, 0);
#endif
- ipcpi.sock_path = sock_path(getpid(), IPCP_SOCK_PATH_PREFIX);
- if (ipcpi.sock_path == NULL)
+ ipcpd.sock_path = sock_path(getpid(), IPCP_SOCK_PATH_PREFIX);
+ if (ipcpd.sock_path == NULL)
goto fail_sock_path;
- ipcpi.sockfd = server_socket_open(ipcpi.sock_path);
- if (ipcpi.sockfd < 0) {
+ ipcpd.sockfd = server_socket_open(ipcpd.sock_path);
+ if (ipcpd.sockfd < 0) {
log_err("Failed to open server socket at %s.",
- ipcpi.sock_path);
+ ipcpd.sock_path);
goto fail_serv_sock;
}
- ipcpi.ops = ops;
+ ipcpd.ops = ops;
- if (pthread_mutex_init(&ipcpi.state_mtx, NULL)) {
+ if (pthread_mutex_init(&ipcpd.state_mtx, NULL)) {
log_err("Failed to create mutex.");
goto fail_state_mtx;
}
@@ -855,32 +920,32 @@ int ipcp_init(int argc,
#ifndef __APPLE__
pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
#endif
- if (pthread_cond_init(&ipcpi.state_cond, &cattr)) {
+ if (pthread_cond_init(&ipcpd.state_cond, &cattr)) {
log_err("Failed to init condvar.");
goto fail_state_cond;
}
- if (pthread_mutex_init(&ipcpi.alloc_lock, NULL)) {
+ if (pthread_mutex_init(&ipcpd.alloc_lock, NULL)) {
log_err("Failed to init mutex.");
goto fail_alloc_lock;
}
- if (pthread_cond_init(&ipcpi.alloc_cond, &cattr)) {
+ if (pthread_cond_init(&ipcpd.alloc_cond, &cattr)) {
log_err("Failed to init convar.");
goto fail_alloc_cond;
}
- if (pthread_mutex_init(&ipcpi.cmd_lock, NULL)) {
+ if (pthread_mutex_init(&ipcpd.cmd_lock, NULL)) {
log_err("Failed to init mutex.");
goto fail_cmd_lock;
}
- if (pthread_cond_init(&ipcpi.cmd_cond, &cattr)) {
+ if (pthread_cond_init(&ipcpd.cmd_cond, &cattr)) {
log_err("Failed to init convar.");
goto fail_cmd_cond;
}
- if (rib_init(ipcpi.name)) {
+ if (rib_init(ipcpd.name)) {
log_err("Failed to initialize RIB.");
goto fail_rib_init;
}
@@ -890,16 +955,16 @@ int ipcp_init(int argc,
goto fail_rib_reg;
}
- list_head_init(&ipcpi.cmds);
+ list_head_init(&ipcpd.cmds);
- ipcpi.tpm = tpm_create(IPCP_MIN_THREADS, IPCP_ADD_THREADS,
+ ipcpd.tpm = tpm_create(IPCP_MIN_THREADS, IPCP_ADD_THREADS,
mainloop, NULL);
- if (ipcpi.tpm == NULL) {
+ if (ipcpd.tpm == NULL) {
log_err("Failed to create threadpool manager.");
goto fail_tpm_create;
}
- ipcpi.alloc_id = -1;
+ ipcpd.alloc_id = -1;
pthread_condattr_destroy(&cattr);
@@ -912,23 +977,23 @@ int ipcp_init(int argc,
fail_rib_reg:
rib_fini();
fail_rib_init:
- pthread_cond_destroy(&ipcpi.cmd_cond);
+ pthread_cond_destroy(&ipcpd.cmd_cond);
fail_cmd_cond:
- pthread_mutex_destroy(&ipcpi.cmd_lock);
+ pthread_mutex_destroy(&ipcpd.cmd_lock);
fail_cmd_lock:
- pthread_cond_destroy(&ipcpi.alloc_cond);
+ pthread_cond_destroy(&ipcpd.alloc_cond);
fail_alloc_cond:
- pthread_mutex_destroy(&ipcpi.alloc_lock);
+ pthread_mutex_destroy(&ipcpd.alloc_lock);
fail_alloc_lock:
- pthread_cond_destroy(&ipcpi.state_cond);
+ pthread_cond_destroy(&ipcpd.state_cond);
fail_state_cond:
pthread_condattr_destroy(&cattr);
fail_cond_attr:
- pthread_mutex_destroy(&ipcpi.state_mtx);
+ pthread_mutex_destroy(&ipcpd.state_mtx);
fail_state_mtx:
- close(ipcpi.sockfd);
+ close(ipcpd.sockfd);
fail_serv_sock:
- free(ipcpi.sock_path);
+ free(ipcpd.sock_path);
fail_sock_path:
return -1;
}
@@ -947,16 +1012,16 @@ int ipcp_start(void)
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
info.pid = getpid();
- info.type = ipcpi.type;
- strcpy(info.name, ipcpi.name);
+ info.type = ipcpd.type;
+ strcpy(info.name, ipcpd.name);
info.state = IPCP_OPERATIONAL;
- if (tpm_start(ipcpi.tpm)) {
+ if (tpm_start(ipcpd.tpm)) {
log_err("Failed to start threadpool manager.");
goto fail_tpm_start;
}
- if (pthread_create(&ipcpi.acceptor, NULL, acceptloop, NULL)) {
+ if (pthread_create(&ipcpd.acceptor, NULL, acceptloop, NULL)) {
log_err("Failed to create acceptor thread.");
goto fail_acceptor;
}
@@ -971,12 +1036,12 @@ int ipcp_start(void)
return 0;
fail_create_r:
- pthread_cancel(ipcpi.acceptor);
- pthread_join(ipcpi.acceptor, NULL);
+ pthread_cancel(ipcpd.acceptor);
+ pthread_join(ipcpd.acceptor, NULL);
fail_acceptor:
- tpm_stop(ipcpi.tpm);
+ tpm_stop(ipcpd.tpm);
fail_tpm_start:
- tpm_destroy(ipcpi.tpm);
+ tpm_destroy(ipcpd.tpm);
ipcp_set_state(IPCP_NULL);
info.state = IPCP_NULL;
ipcp_create_r(&info);
@@ -1012,7 +1077,7 @@ void ipcp_sigwait(void)
#ifdef __APPLE__
memset(&info, 0, sizeof(info));
info.si_signo = sig;
- info.si_pid = ipcpi.irmd_pid;
+ info.si_pid = ipcpd.irmd_pid;
#endif
switch(info.si_signo) {
case SIGINT:
@@ -1022,7 +1087,7 @@ void ipcp_sigwait(void)
case SIGHUP:
/* FALLTHRU */
case SIGQUIT:
- if (info.si_pid == ipcpi.irmd_pid) {
+ if (info.si_pid == ipcpd.irmd_pid) {
if (ipcp_get_state() == IPCP_INIT)
ipcp_set_state(IPCP_NULL);
@@ -1043,33 +1108,33 @@ void ipcp_stop(void)
{
log_info("IPCP %d shutting down.", getpid());
- pthread_cancel(ipcpi.acceptor);
- pthread_join(ipcpi.acceptor, NULL);
+ pthread_cancel(ipcpd.acceptor);
+ pthread_join(ipcpd.acceptor, NULL);
- tpm_stop(ipcpi.tpm);
+ tpm_stop(ipcpd.tpm);
}
void ipcp_fini(void)
{
- tpm_destroy(ipcpi.tpm);
+ tpm_destroy(ipcpd.tpm);
rib_unreg(IPCP_INFO);
rib_fini();
- close(ipcpi.sockfd);
- if (unlink(ipcpi.sock_path))
- log_warn("Could not unlink %s.", ipcpi.sock_path);
+ close(ipcpd.sockfd);
+ if (unlink(ipcpd.sock_path))
+ log_warn("Could not unlink %s.", ipcpd.sock_path);
- free(ipcpi.sock_path);
+ free(ipcpd.sock_path);
- pthread_cond_destroy(&ipcpi.state_cond);
- pthread_mutex_destroy(&ipcpi.state_mtx);
- pthread_cond_destroy(&ipcpi.alloc_cond);
- pthread_mutex_destroy(&ipcpi.alloc_lock);
- pthread_cond_destroy(&ipcpi.cmd_cond);
- pthread_mutex_destroy(&ipcpi.cmd_lock);
+ pthread_cond_destroy(&ipcpd.state_cond);
+ pthread_mutex_destroy(&ipcpd.state_mtx);
+ pthread_cond_destroy(&ipcpd.alloc_cond);
+ pthread_mutex_destroy(&ipcpd.alloc_lock);
+ pthread_cond_destroy(&ipcpd.cmd_cond);
+ pthread_mutex_destroy(&ipcpd.cmd_lock);
log_info("IPCP %d out.", getpid());
@@ -1078,23 +1143,23 @@ void ipcp_fini(void)
void ipcp_set_state(enum ipcp_state state)
{
- pthread_mutex_lock(&ipcpi.state_mtx);
+ pthread_mutex_lock(&ipcpd.state_mtx);
- ipcpi.state = state;
+ ipcpd.state = state;
- pthread_cond_broadcast(&ipcpi.state_cond);
- pthread_mutex_unlock(&ipcpi.state_mtx);
+ pthread_cond_broadcast(&ipcpd.state_cond);
+ pthread_mutex_unlock(&ipcpd.state_mtx);
}
enum ipcp_state ipcp_get_state(void)
{
enum ipcp_state state;
- pthread_mutex_lock(&ipcpi.state_mtx);
+ pthread_mutex_lock(&ipcpd.state_mtx);
- state = ipcpi.state;
+ state = ipcpd.state;
- pthread_mutex_unlock(&ipcpi.state_mtx);
+ pthread_mutex_unlock(&ipcpd.state_mtx);
return state;
}
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index b29f0bf4..3ec6401b 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -34,6 +34,8 @@
#include <pthread.h>
#include <time.h>
+#define ipcp_dir_hash_strlen() (ipcp_dir_hash_len() * 2)
+
struct ipcp_ops {
int (* ipcp_bootstrap)(const struct ipcp_config * conf);
@@ -69,43 +71,6 @@ struct ipcp_ops {
int (* ipcp_flow_dealloc)(int fd);
};
-#define ipcp_dir_hash_strlen() (hash_len(ipcpi.dir_hash_algo) * 2)
-#define ipcp_dir_hash_len() (hash_len(ipcpi.dir_hash_algo))
-
-extern struct ipcp {
- pid_t irmd_pid;
- char * name;
-
- enum ipcp_type type;
- char layer_name[LAYER_NAME_SIZE + 1];
-
- uint64_t dt_addr;
-
- enum hash_algo dir_hash_algo;
-
- struct ipcp_ops * ops;
- int irmd_fd;
-
- enum ipcp_state state;
- pthread_cond_t state_cond;
- pthread_mutex_t state_mtx;
-
- int sockfd;
- char * sock_path;
-
- struct list_head cmds;
- pthread_cond_t cmd_cond;
- pthread_mutex_t cmd_lock;
-
- int alloc_id;
- pthread_cond_t alloc_cond;
- pthread_mutex_t alloc_lock;
-
- struct tpm * tpm;
-
- pthread_t acceptor;
-} ipcpi;
-
int ipcp_init(int argc,
char ** argv,
struct ipcp_ops * ops,
@@ -119,10 +84,16 @@ void ipcp_stop(void);
void ipcp_fini(void);
+enum ipcp_type ipcp_get_type(void);
+
+const char * ipcp_get_name(void);
+
void ipcp_set_state(enum ipcp_state state);
enum ipcp_state ipcp_get_state(void);
+int ipcp_set_layer_info(const struct layer_info * info);
+
/* Helper functions to handle races during flow allocation */
int ipcp_wait_flow_req_arr(const uint8_t * dst,
qosspec_t qs,
@@ -131,7 +102,10 @@ int ipcp_wait_flow_req_arr(const uint8_t * dst,
int ipcp_wait_flow_resp(const int fd);
+
/* Helper functions for directory entries, could be moved */
+size_t ipcp_dir_hash_len(void);
+
uint8_t * ipcp_hash_dup(const uint8_t * hash);
void ipcp_hash_str(char buf[],
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 160e07e0..054602e5 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -50,8 +50,6 @@
#define THIS_TYPE IPCP_LOCAL
-struct ipcp ipcpi;
-
struct {
struct shim_data * shim_data;
@@ -141,11 +139,11 @@ static void * local_ipcp_packet_loop(void * o)
static int local_ipcp_bootstrap(const struct ipcp_config * conf)
{
+
assert(conf);
assert(conf->type == THIS_TYPE);
- ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo;
- strcpy(ipcpi.layer_name,conf->layer_info.name);
+ (void) conf;
if (pthread_create(&local_data.packet_loop, NULL,
local_ipcp_packet_loop, NULL)) {
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index 2e8d84ce..3cfcf2cc 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -81,8 +81,6 @@
#define SENDTO_FLAGS 0
#endif
-struct ipcp ipcpi;
-
/* Keep order for alignment. */
struct mgmt_msg {
uint32_t eid;
@@ -592,11 +590,9 @@ static int udp_ipcp_bootstrap(const struct ipcp_config * conf)
char dnsstr[INET_ADDRSTRLEN];
int i = 1;
- assert(conf);
+ assert(conf != NULL);
assert(conf->type == THIS_TYPE);
-
- ipcpi.dir_hash_algo = HASH_MD5;
- strcpy(ipcpi.layer_name, conf->layer_info.name);
+ assert(conf->layer_info.dir_hash_algo == (enum pol_dir_hash) HASH_MD5);
if (inet4_ntop(&conf->udp.ip_addr, ipstr) == NULL) {
log_err("Failed to convert IP address.");
diff --git a/src/ipcpd/unicast/addr-auth/flat.c b/src/ipcpd/unicast/addr-auth/flat.c
index c4562935..dfdeccd6 100644
--- a/src/ipcpd/unicast/addr-auth/flat.c
+++ b/src/ipcpd/unicast/addr-auth/flat.c
@@ -35,13 +35,13 @@
#include "flat.h"
#define NAME_LEN 8
+#define INVALID_ADDRESS 0
struct {
- uint8_t addr_size;
+ uint8_t addr_size;
+ uint32_t addr;
} flat;
-#define INVALID_ADDRESS 0
-
struct addr_auth_ops flat_ops = {
.init = flat_init,
.fini = flat_fini,
@@ -57,6 +57,12 @@ int flat_init(const void * info)
return -1;
}
+#if defined (CONFIG_OUROBOROS_DEBUG) && defined (IPCP_DEBUG_LOCAL)
+ flat.addr = getpid();
+#else
+ while (flat.addr == INVALID_ADDRESS)
+ random_buffer(&flat.addr,sizeof(flat.addr));
+#endif
return 0;
}
@@ -67,13 +73,5 @@ int flat_fini(void)
uint64_t flat_address(void)
{
- uint32_t addr = INVALID_ADDRESS;
-
-#if defined (CONFIG_OUROBOROS_DEBUG) && defined (IPCP_DEBUG_LOCAL)
- addr = getpid();
-#else
- while (addr == INVALID_ADDRESS)
- random_buffer(&addr,sizeof(addr));
-#endif
- return addr;
+ return (uint64_t) flat.addr;
}
diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c
index 483570e8..da39e567 100644
--- a/src/ipcpd/unicast/dir/dht.c
+++ b/src/ipcpd/unicast/dir/dht.c
@@ -45,6 +45,7 @@
#include <ouroboros/utils.h>
#include <ouroboros/pthread.h>
+#include "addr-auth.h"
#include "common/connmgr.h"
#include "dht.h"
#include "dt.h"
@@ -2258,7 +2259,7 @@ int dht_bootstrap(void * dir)
pthread_rwlock_wrlock(&dht->lock);
#ifndef __DHT_TEST__
- dht->b = hash_len(ipcpi.dir_hash_algo);
+ dht->b = ipcp_dir_hash_len();
#else
dht->b = DHT_TEST_KEY_LEN;
#endif
@@ -2845,7 +2846,10 @@ void * dht_create(void)
dht->b = 0;
dht->id = NULL;
#ifndef __DHT_TEST__
- dht->addr = ipcpi.dt_addr;
+ dht->addr = addr_auth_address();
+ if (dht->addr == INVALID_ADDR)
+ goto fail_bmp;
+
dht->tpm = tpm_create(2, 1, dht_handle_packet, dht);
if (dht->tpm == NULL)
goto fail_tpm_create;
diff --git a/src/ipcpd/unicast/dt.c b/src/ipcpd/unicast/dt.c
index 2bb5ed2f..14eaac09 100644
--- a/src/ipcpd/unicast/dt.c
+++ b/src/ipcpd/unicast/dt.c
@@ -41,6 +41,7 @@
#include <ouroboros/fccntl.h>
#endif
+#include "addr-auth.h"
#include "common/comp.h"
#include "common/connmgr.h"
#include "ca.h"
@@ -144,6 +145,8 @@ static void dt_pci_shrink(struct shm_du_buff * sdb)
struct {
struct psched * psched;
+ uint64_t addr;
+
struct pff * pff[QOS_CUBE_MAX];
struct routing_i * routing[QOS_CUBE_MAX];
#ifdef IPCP_FLOW_STATS
@@ -209,7 +212,7 @@ static int dt_rib_read(const char * path,
return 0;
}
- if (dt.stat[fd].addr == ipcpi.dt_addr)
+ if (dt.stat[fd].addr == dt.addr)
sprintf(addrstr, "%s", dt.comps[fd].name);
else
sprintf(addrstr, "%" PRIu64, dt.stat[fd].addr);
@@ -454,7 +457,7 @@ static void packet_handler(int fd,
head = shm_du_buff_head(sdb);
dt_pci_des(head, &dt_pci);
- if (dt_pci.dst_addr != ipcpi.dt_addr) {
+ if (dt_pci.dst_addr != dt.addr) {
if (dt_pci.ttl == 0) {
log_dbg("TTL was zero.");
ipcp_sdb_release(sdb);
@@ -575,11 +578,17 @@ int dt_init(struct dt_config cfg)
memset(&info, 0, sizeof(info));
+ dt.addr = addr_auth_address();
+ if (dt.addr == INVALID_ADDR) {
+ log_err("Failed to get address");
+ return -1;
+ }
+
strcpy(info.comp_name, DT_COMP);
strcpy(info.protocol, DT_PROTO);
info.pref_version = 1;
info.pref_syntax = PROTO_FIXED;
- info.addr = ipcpi.dt_addr;
+ info.addr = dt.addr;
if (cfg.eid_size != 8) { /* only support 64 bits from now */
log_warn("Invalid EID size. Only 64 bit is supported.");
@@ -647,7 +656,7 @@ int dt_init(struct dt_config cfg)
dt.n_flows = 0;
#endif
- sprintf(dtstr, "%s.%" PRIu64, DT, ipcpi.dt_addr);
+ sprintf(dtstr, "%s.%" PRIu64, DT, dt.addr);
if (rib_reg(dtstr, &r_ops)) {
log_err("Failed to register RIB.");
goto fail_rib_reg;
@@ -683,7 +692,7 @@ void dt_fini(void)
char dtstr[RIB_NAME_STRLEN + 1];
int i;
- sprintf(dtstr, "%s.%" PRIu64, DT, ipcpi.dt_addr);
+ sprintf(dtstr, "%s.%" PRIu64, DT, dt.addr);
rib_unreg(dtstr);
#ifdef IPCP_FLOW_STATS
for (i = 0; i < PROG_MAX_FLOWS; ++i)
@@ -769,7 +778,7 @@ int dt_reg_comp(void * comp,
pthread_rwlock_unlock(&dt.lock);
#ifdef IPCP_FLOW_STATS
- stat_used(eid, ipcpi.dt_addr);
+ stat_used(eid, dt.addr);
#endif
return eid;
}
@@ -786,7 +795,7 @@ int dt_write_packet(uint64_t dst_addr,
size_t len;
assert(sdb);
- assert(dst_addr != ipcpi.dt_addr);
+ assert(dst_addr != dt.addr);
len = shm_du_buff_len(sdb);
diff --git a/src/ipcpd/unicast/fa.c b/src/ipcpd/unicast/fa.c
index 3631fd7b..ecc3894e 100644
--- a/src/ipcpd/unicast/fa.c
+++ b/src/ipcpd/unicast/fa.c
@@ -41,6 +41,7 @@
#include <ouroboros/random.h>
#include <ouroboros/pthread.h>
+#include "addr-auth.h"
#include "dir.h"
#include "fa.h"
#include "psched.h"
@@ -765,7 +766,7 @@ int fa_alloc(int fd,
msg->code = FLOW_REQ;
msg->s_eid = hton64(eid);
- msg->s_addr = hton64(ipcpi.dt_addr);
+ msg->s_addr = hton64(addr_auth_address());
msg->delay = hton32(qs.delay);
msg->bandwidth = hton64(qs.bandwidth);
msg->availability = qs.availability;
diff --git a/src/ipcpd/unicast/main.c b/src/ipcpd/unicast/main.c
index e6cb2994..bd1fee51 100644
--- a/src/ipcpd/unicast/main.c
+++ b/src/ipcpd/unicast/main.c
@@ -55,13 +55,8 @@
#include <assert.h>
#include <inttypes.h>
-struct ipcp ipcpi;
-
static int initialize_components(const struct ipcp_config * conf)
{
- strcpy(ipcpi.layer_name, conf->layer_info.name);
- ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo;
-
assert(ipcp_dir_hash_len() != 0);
if (addr_auth_init(conf->unicast.addr_auth_type,
@@ -70,13 +65,7 @@ static int initialize_components(const struct ipcp_config * conf)
goto fail_addr_auth;
}
- ipcpi.dt_addr = addr_auth_address();
- if (ipcpi.dt_addr == 0) {
- log_err("Failed to get a valid address.");
- goto fail_addr_auth;
- }
-
- log_info("IPCP got address %" PRIu64 ".", ipcpi.dt_addr);
+ log_info("IPCP got address %" PRIu64 ".", addr_auth_address());
if (ca_init(conf->unicast.cong_avoid)) {
log_err("Failed to initialize congestion avoidance.");
@@ -188,8 +177,9 @@ static int bootstrap_components(void)
static int unicast_ipcp_enroll(const char * dst,
struct layer_info * info)
{
- struct conn conn;
- uint8_t id[ENROLL_ID_LEN];
+ struct ipcp_config * conf;
+ struct conn conn;
+ uint8_t id[ENROLL_ID_LEN];
if (random_buffer(id, ENROLL_ID_LEN) < 0) {
log_err("Failed to generate enrollment ID.");
@@ -209,7 +199,11 @@ static int unicast_ipcp_enroll(const char * dst,
goto fail_enroll_boot;
}
- if (initialize_components(enroll_get_conf()) < 0) {
+ conf = enroll_get_conf();
+
+ *info = conf->layer_info;
+
+ if (initialize_components(conf) < 0) {
log_err_id(id, "Failed to initialize components.");
goto fail_enroll_boot;
}
@@ -227,9 +221,6 @@ static int unicast_ipcp_enroll(const char * dst,
log_info_id(id, "Enrolled with %s.", dst);
- info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo;
- strcpy(info->name, ipcpi.layer_name);
-
return 0;
fail_start_comp:
diff --git a/src/ipcpd/unicast/routing/link-state.c b/src/ipcpd/unicast/routing/link-state.c
index 57c0c7cb..0bc6a852 100644
--- a/src/ipcpd/unicast/routing/link-state.c
+++ b/src/ipcpd/unicast/routing/link-state.c
@@ -42,6 +42,7 @@
#include <ouroboros/rib.h>
#include <ouroboros/utils.h>
+#include "addr-auth.h"
#include "common/comp.h"
#include "common/connmgr.h"
#include "graph.h"
@@ -106,6 +107,8 @@ struct nb {
};
struct {
+ uint64_t addr;
+
struct list_head nbs;
size_t nbs_len;
fset_t * mgmt_set;
@@ -418,7 +421,7 @@ static void calculate_pff(struct routing_i * instance)
assert(instance);
if (graph_routing_table(ls.graph, ls.routing_algo,
- ipcpi.dt_addr, &table))
+ ls.addr, &table))
return;
pff_lock(instance->pff);
@@ -667,7 +670,7 @@ static void * lsupdate(void * o)
continue;
}
- if (adj->src == ipcpi.dt_addr) {
+ if (adj->src == ls.addr) {
adj->seqno++;
send_lsm(adj->src, adj->dst, adj->seqno);
adj->stamp = now.tv_sec;
@@ -820,13 +823,13 @@ static void handle_event(void * self,
pthread_cleanup_push(__cleanup_rwlock_unlock, &ls.db_lock);
- send_lsm(ipcpi.dt_addr, c->conn_info.addr, 0);
+ send_lsm(ls.addr, c->conn_info.addr, 0);
pthread_cleanup_pop(true);
if (lsdb_add_nb(c->conn_info.addr, c->flow_info.fd, NB_DT))
log_dbg("Failed to add neighbor to LSDB.");
- if (lsdb_add_link(ipcpi.dt_addr, c->conn_info.addr, 0, &qs))
+ if (lsdb_add_link(ls.addr, c->conn_info.addr, 0, &qs))
log_dbg("Failed to add new adjacency to LSDB.");
break;
case NOTIFY_DT_CONN_DEL:
@@ -835,7 +838,7 @@ static void handle_event(void * self,
if (lsdb_del_nb(c->conn_info.addr, c->flow_info.fd))
log_dbg("Failed to delete neighbor from LSDB.");
- if (lsdb_del_link(ipcpi.dt_addr, c->conn_info.addr))
+ if (lsdb_del_link(ls.addr, c->conn_info.addr))
log_dbg("Local link was not in LSDB.");
break;
case NOTIFY_DT_CONN_QOS:
@@ -927,11 +930,13 @@ int link_state_init(enum pol_routing pr)
memset(&info, 0, sizeof(info));
+ ls.addr = addr_auth_address();
+
strcpy(info.comp_name, LS_COMP);
strcpy(info.protocol, LS_PROTO);
info.pref_version = 1;
info.pref_syntax = PROTO_GPB;
- info.addr = ipcpi.dt_addr;
+ info.addr = ls.addr;
switch (pr) {
case ROUTING_LINK_STATE:
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 3a1a7225..e0be8a01 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -920,7 +920,7 @@ static int flow_join(struct flow_info * flow,
struct ipcp_info ipcp;
struct layer_info layer;
buffer_t hash;
- buffer_t pbuf = {NULL, 0}; /* nothing to piggyback */
+ buffer_t pbuf = {0, NULL}; /* nothing to piggyback */
int err;
log_info("Allocating flow for %d to %s.", flow->n_pid, dst);
diff --git a/src/irmd/reg/tests/flow_test.c b/src/irmd/reg/tests/flow_test.c
index 3e586341..27fd61b0 100644
--- a/src/irmd/reg/tests/flow_test.c
+++ b/src/irmd/reg/tests/flow_test.c
@@ -232,7 +232,7 @@ static int test_flow_data(void)
char * data;
buffer_t buf;
- buffer_t rcv = {NULL, 0};
+ buffer_t rcv = {0, NULL};
TEST_START();
diff --git a/src/irmd/reg/tests/reg_test.c b/src/irmd/reg/tests/reg_test.c
index b69cf476..7f3ba32d 100644
--- a/src/irmd/reg/tests/reg_test.c
+++ b/src/irmd/reg/tests/reg_test.c
@@ -115,7 +115,7 @@ static int test_reg_allocate_flow_timeout(void)
{
struct timespec abstime;
struct timespec timeo = TIMESPEC_INIT_MS(1);
- buffer_t rbuf = {NULL, 0};
+ buffer_t rbuf = {0, NULL};
struct flow_info info = {
.n_pid = TEST_PID,
@@ -173,7 +173,7 @@ static int test_reg_allocate_flow_timeout(void)
static void * test_flow_respond_alloc(void * o)
{
struct flow_info * info = (struct flow_info *) o;
- buffer_t pbuf = {NULL, 0};
+ buffer_t pbuf = {0, NULL};
if (info->state == FLOW_ALLOCATED) {
pbuf.data = (uint8_t *) strdup(TEST_DATA2);
@@ -215,7 +215,7 @@ static int test_reg_accept_flow_success(void)
pthread_t thr;
struct timespec abstime;
struct timespec timeo = TIMESPEC_INIT_S(1);
- buffer_t rbuf = {NULL, 0};
+ buffer_t rbuf = {0, NULL};
struct flow_info info = {
.n_pid = TEST_PID,
@@ -309,7 +309,7 @@ static int test_reg_accept_flow_success_no_crypt(void)
pthread_t thr;
struct timespec abstime;
struct timespec timeo = TIMESPEC_INIT_S(1);
- buffer_t rbuf = {NULL, 0};
+ buffer_t rbuf = {0, NULL};
struct flow_info info = {
.n_pid = TEST_PID,
@@ -398,7 +398,7 @@ static int test_reg_accept_flow_success_no_crypt(void)
static int test_reg_allocate_flow_fail(void)
{
- buffer_t buf = {NULL, 0};
+ buffer_t buf = {0, NULL};
pthread_t thr;
struct timespec abstime;
struct timespec timeo = TIMESPEC_INIT_S(1);
@@ -1118,7 +1118,7 @@ static void * test_call_flow_accept(void * o)
{
struct timespec abstime;
struct timespec timeo = TIMESPEC_INIT_MS(1);
- buffer_t pbuf = {NULL, 0};
+ buffer_t pbuf = {0, NULL};
struct proc_info pinfo = {
.pid = TEST_PID,
diff --git a/src/lib/dev.c b/src/lib/dev.c
index c22b4f06..9df5fd46 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -227,7 +227,7 @@ static enum flow_state flow_wait_assign(int flow_id)
static int proc_announce(const char * prog)
{
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
int err;
if (proc_announce__irm_req_ser(&msg, prog) < 0)
@@ -244,7 +244,7 @@ static int proc_announce(const char * prog)
static void proc_exit(void)
{
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
if (proc_exit__irm_req_ser(&msg) < 0)
return;
@@ -826,7 +826,7 @@ int flow_accept(qosspec_t * qs,
{
struct flow_info flow;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
buffer_t sk;
int fd;
int err;
@@ -867,7 +867,7 @@ int flow_alloc(const char * dst,
{
struct flow_info flow;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
buffer_t sk; /* symmetric key */
int fd;
int err;
@@ -909,7 +909,7 @@ int flow_join(const char * dst,
{
struct flow_info flow;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
int fd;
int err;
@@ -950,7 +950,7 @@ int flow_dealloc(int fd)
struct flow_info info;
uint8_t pkt[PKT_BUF_LEN];
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
struct timespec tic = TIMESPEC_INIT_NS(TICTIME);
struct timespec timeo = TIMESPEC_INIT_S(0);
struct flow * flow;
@@ -1024,7 +1024,7 @@ int ipcp_flow_dealloc(int fd)
{
struct flow_info info;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
struct flow * flow;
int err;
@@ -1849,7 +1849,7 @@ int np1_flow_resp(int flow_id)
int ipcp_create_r(const struct ipcp_info * info)
{
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
int err;
if (ipcp_create_r__irm_req_ser(&msg,info) < 0)
@@ -1869,7 +1869,7 @@ int ipcp_flow_req_arr(const buffer_t * dst,
{
struct flow_info flow;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
int err;
memset(&flow, 0, sizeof(flow));
@@ -1906,7 +1906,7 @@ int ipcp_flow_alloc_reply(int fd,
{
struct flow_info flow;
uint8_t buf[SOCK_BUF_SIZE];
- buffer_t msg = {buf, SOCK_BUF_SIZE};
+ buffer_t msg = {SOCK_BUF_SIZE, buf};
int err;
assert(fd >= 0 && fd < SYS_MAX_FLOWS);