diff options
Diffstat (limited to 'src/ipcpd/common/enroll.c')
-rw-r--r-- | src/ipcpd/common/enroll.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/ipcpd/common/enroll.c b/src/ipcpd/common/enroll.c index 5e35ce37..8e5384a5 100644 --- a/src/ipcpd/common/enroll.c +++ b/src/ipcpd/common/enroll.c @@ -43,20 +43,19 @@ #include <string.h> #include <pthread.h> +#ifdef __APPLE__ +#define llabs labs +#endif + #define ENROLL_COMP "Enrollment" #define ENROLL_PROTO "OEP" /* Ouroboros enrollment protocol */ #define ENROLL_WARN_TIME_OFFSET 20 #define ENROLL_BUF_LEN 1024 -enum enroll_state { - ENROLL_NULL = 0, - ENROLL_INIT, - ENROLL_RUNNING -}; struct { struct ipcp_config conf; - enum enroll_state state; + pthread_t listener; } enroll; @@ -107,8 +106,6 @@ static void * enroll_handle(void * o) log_info_id(req.id, "Handling incoming enrollment."); - /* TODO: authentication, timezone handling (UTC). */ - ack.result = -100; clock_gettime(CLOCK_REALTIME, &resp.t); @@ -227,12 +224,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); @@ -240,11 +239,9 @@ int enroll_boot(struct conn * conn, rtt.tv_sec = resp.t.tv_sec; rtt.tv_nsec = resp.t.tv_nsec; - if (labs(ts_diff_ms(&t0, &rtt)) - delta_t > ENROLL_WARN_TIME_OFFSET) + if (llabs(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; } @@ -307,16 +304,11 @@ int enroll_init(void) return -1; } - enroll.state = ENROLL_INIT; - return 0; } void enroll_fini(void) { - if (enroll.state == ENROLL_RUNNING) - pthread_join(enroll.listener, NULL); - connmgr_comp_fini(COMPID_ENROLL); } @@ -325,13 +317,11 @@ int enroll_start(void) if (pthread_create(&enroll.listener, NULL, enroll_handle, NULL)) return -1; - enroll.state = ENROLL_RUNNING; - return 0; } void enroll_stop(void) { - if (enroll.state == ENROLL_RUNNING) - pthread_cancel(enroll.listener); + pthread_cancel(enroll.listener); + pthread_join(enroll.listener, NULL); } |