summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-02-13 10:55:33 +0000
committerSander Vrijders <[email protected]>2017-02-13 10:55:33 +0000
commit5ea091f9cde6090c4829e78b7d2ac5a566ede8f1 (patch)
treed4926c7856344dcc4aba9838b734ad0c67acb4ce /src/ipcpd/normal
parent344f834e85e9c7afc47e19226157c8e834725d2e (diff)
parent5cc79cfeb7a33c93ae9ef5781f9b0ecd4a958bee (diff)
downloadouroboros-5ea091f9cde6090c4829e78b7d2ac5a566ede8f1.tar.gz
ouroboros-5ea091f9cde6090c4829e78b7d2ac5a566ede8f1.zip
Merged in dstaesse/ouroboros/be-endian (pull request #371)
Check time synchronization upon enrollment
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/dir.c18
-rw-r--r--src/ipcpd/normal/enroll.c53
-rw-r--r--src/ipcpd/normal/main.c5
3 files changed, 69 insertions, 7 deletions
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index d30b9ec0..703f4e79 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -31,21 +31,22 @@
#include <string.h>
#include <assert.h>
+#define DIR_PATH "/" DIR_NAME
+
static char dir_path[RIB_MAX_PATH_LEN + 1];
static void dir_path_reset(void) {
- dir_path[strlen("/" DIR_NAME)]= '\0';
- assert(strcmp("/" DIR_NAME, dir_path) == 0);
+ dir_path[strlen(DIR_PATH)]= '\0';
+ assert(strcmp(DIR_PATH, dir_path) == 0);
}
int dir_init(void)
{
/*FIXME: set ribmgr dissemination here */
-
if (rib_add(RIB_ROOT, DIR_NAME))
return -1;
- strcpy(dir_path, "/" DIR_NAME);
+ strcpy(dir_path, DIR_PATH);
return 0;
}
@@ -66,6 +67,9 @@ int dir_name_reg(char * name)
assert(name);
+ if (ipcp_get_state() != IPCP_OPERATIONAL)
+ return -EPERM;
+
dir_path_reset();
ret = rib_add(dir_path, name);
@@ -91,6 +95,9 @@ int dir_name_unreg(char * name)
assert(name);
+ if (ipcp_get_state() != IPCP_OPERATIONAL)
+ return -EPERM;
+
dir_path_reset();
rib_path_append(dir_path, name);
@@ -116,6 +123,9 @@ int dir_name_query(char * name)
{
size_t len;
+ if (ipcp_get_state() != IPCP_OPERATIONAL)
+ return -EPERM;
+
dir_path_reset();
rib_path_append(dir_path, name);
diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c
index 16bfc592..94e171c0 100644
--- a/src/ipcpd/normal/enroll.c
+++ b/src/ipcpd/normal/enroll.c
@@ -21,10 +21,12 @@
#define OUROBOROS_PREFIX "enrollment"
#include <ouroboros/config.h>
+#include <ouroboros/time_utils.h>
#include <ouroboros/cdap.h>
#include <ouroboros/dev.h>
#include <ouroboros/logs.h>
#include <ouroboros/rib.h>
+#include <ouroboros/endian.h>
#include "ae.h"
@@ -32,10 +34,15 @@
#include <stdlib.h>
#include <string.h>
+/* Symbolic, will return current time */
+#define TIME_NAME "localtime"
+#define ENROLL_WARN_TIME_OFFSET 20
+
#define DLR "/"
#define DIF_PATH DLR DIF_NAME
#define BOOT_PATH DLR BOOT_NAME
#define MEMBERS_PATH DLR MEMBERS_NAME
+#define TIME_PATH DLR TIME_NAME
int enroll_handle(int fd)
{
@@ -72,7 +79,6 @@ int enroll_handle(int fd)
while (!(boot_r && members_r && dif_name_r)) {
key = cdap_request_wait(ci, &oc, &name, &data,
(size_t *) &len , &flags);
-
assert(key >= 0);
assert(name);
@@ -96,6 +102,15 @@ int enroll_handle(int fd)
members_r = true;
} else if (strcmp(name, dif_ro) == 0) {
dif_name_r = true;
+ } else if (strcmp(name, TIME_PATH) == 0) {
+ struct timespec t;
+ uint64_t buf[2];
+ clock_gettime(CLOCK_REALTIME, &t);
+ buf[0] = hton64(t.tv_sec);
+ buf[1] = hton64(t.tv_nsec);
+ cdap_reply_send(ci, key, 0, buf, sizeof(buf));
+ free(name);
+ continue;
} else {
log_warn("Illegal read: %s.", name);
cdap_reply_send(ci, key, -1, NULL, 0);
@@ -146,6 +161,11 @@ int enroll_boot(char * dst_name)
size_t len;
int fd;
+ struct timespec t0;
+ struct timespec rtt;
+
+ ssize_t delta_t;
+
char * boot_ro = BOOT_PATH;
char * members_ro = MEMBERS_PATH;
char * dif_ro = DIF_PATH;
@@ -171,6 +191,37 @@ int enroll_boot(char * dst_name)
log_dbg("Getting boot information from %s.", dst_name);
+ clock_gettime(CLOCK_REALTIME, &t0);
+
+ key = cdap_request_send(ci, CDAP_READ, TIME_PATH, NULL, 0, 0);
+ if (key < 0) {
+ 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.");
+ cdap_destroy(ci);
+ flow_dealloc(fd);
+ return -1;
+ }
+
+ clock_gettime(CLOCK_REALTIME, &rtt);
+
+ delta_t = ts_diff_ms(&t0, &rtt);
+
+ assert (len == 2 * sizeof (uint64_t));
+
+ rtt.tv_sec = ntoh64(((uint64_t *) data)[0]);
+ rtt.tv_nsec = ntoh64(((uint64_t *) data)[1]);
+
+ if (abs(ts_diff_ms(&t0, &rtt)) - delta_t > ENROLL_WARN_TIME_OFFSET)
+ log_warn("Clock offset above threshold.");
+
+ free(data);
+
key = cdap_request_send(ci, CDAP_READ, boot_ro, NULL, 0, 0);
if (key < 0) {
log_err("Failed to send CDAP request.");
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 81912614..11ec0938 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -30,6 +30,7 @@
#include <ouroboros/irm.h>
#include <ouroboros/rib.h>
#include <ouroboros/irm_config.h>
+#include <ouroboros/errno.h>
#include "addr_auth.h"
#include "ae.h"
@@ -45,7 +46,6 @@
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
-#include <errno.h>
#include <assert.h>
#include <inttypes.h>
@@ -108,7 +108,8 @@ static void * flow_acceptor(void * o)
fd = flow_accept(&ae_name, &qs);
if (fd < 0) {
- log_warn("Flow accept failed.");
+ if (fd != -EIRMD)
+ log_warn("Flow accept failed: %d", fd);
continue;
}