-/* $OpenBSD: connection.c,v 1.38 2017/08/06 13:54:04 mpi Exp $ */
+/* $OpenBSD: connection.c,v 1.39 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: connection.c,v 1.28 2000/11/23 12:21:18 niklas Exp $ */
/*
*/
#include <sys/queue.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
/* XXX Potential additions to 'connection_passive'. */
char *isakmp_peer;
struct sa *sa; /* XXX "Soft" ref to active sa? */
- struct timeval sa_expiration; /* XXX *sa may expire. */
+ struct timespec sa_expiration; /* XXX *sa may expire. */
#endif
};
static void
connection_checker(void *vconn)
{
- struct timeval now;
+ struct timespec now;
struct connection *conn = vconn;
char *name;
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
now.tv_sec += conf_get_num("General", "check-interval",
CHECK_INTERVAL);
conn->ev = timer_add_event("connection_checker",
connection_setup(char *name)
{
struct connection *conn = 0;
- struct timeval now;
+ struct timespec now;
/* Check for trials to add duplicate connections. */
if (connection_lookup(name)) {
log_error("connection_setup: strdup (\"%s\") failed", name);
goto fail;
}
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
conn->ev = timer_add_event("connection_checker", connection_checker,
conn, &now);
if (!conn->ev) {
connection_report(void)
{
struct connection *conn;
- struct timeval now;
+ struct timespec now;
struct connection_passive *pconn;
struct doi *doi = doi_lookup(ISAKMP_DOI_ISAKMP);
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
for (conn = TAILQ_FIRST(&connections); conn;
conn = TAILQ_NEXT(conn, link))
LOG_DBG((LOG_REPORT, 0,
-/* $OpenBSD: dpd.c,v 1.19 2015/12/10 17:27:00 mmcc Exp $ */
+/* $OpenBSD: dpd.c,v 1.20 2017/12/05 20:31:45 jca Exp $ */
/*
* Copyright (c) 2004 Håkan Olsson. All rights reserved.
static void
dpd_timer_reset(struct sa *sa, u_int32_t time_passed, enum dpd_tstate mode)
{
- struct timeval tv;
+ struct timespec ts;
if (sa->dpd_event)
timer_remove_event(sa->dpd_event);
- gettimeofday(&tv, 0);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
switch (mode) {
case DPD_TIMER_NORMAL:
sa->dpd_failcount = 0;
- tv.tv_sec += dpd_timer_interval(time_passed);
+ ts.tv_sec += dpd_timer_interval(time_passed);
sa->dpd_event = timer_add_event("dpd_event", dpd_event, sa,
- &tv);
+ &ts);
break;
case DPD_TIMER_CHECK:
- tv.tv_sec += DPD_RETRANS_WAIT;
+ ts.tv_sec += DPD_RETRANS_WAIT;
sa->dpd_event = timer_add_event("dpd_check_event",
- dpd_check_event, sa, &tv);
+ dpd_check_event, sa, &ts);
break;
default:
break;
struct sockaddr *dst;
struct proto *proto;
struct sa_kinfo *ksa;
- struct timeval tv;
+ struct timespec ts;
if (sa->phase == 1 || (args->isakmp_sa->flags & SA_FLAG_DPD) == 0 ||
dpd_find_sa(sa, args->isakmp_sa) == 0)
return 0;
sa->transport->vtbl->get_src(sa->transport, &dst);
- gettimeofday(&tv, 0);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
ksa = pf_key_v2_get_kernel_sa(proto->spi[1], proto->spi_sz[1],
proto->proto, dst);
LOG_DBG((LOG_MESSAGE, 80, "dpd_check_time: "
"SA %p last use %u second(s) ago", sa,
- (u_int32_t)(tv.tv_sec - ksa->last_used)));
+ (u_int32_t)(ts.tv_sec - ksa->last_used)));
- if ((u_int32_t)(tv.tv_sec - ksa->last_used) < args->interval) {
- args->interval = (u_int32_t)(tv.tv_sec - ksa->last_used);
+ if ((u_int32_t)(ts.tv_sec - ksa->last_used) < args->interval) {
+ args->interval = (u_int32_t)(ts.tv_sec - ksa->last_used);
return 1;
}
return 0;
-/* $OpenBSD: exchange.c,v 1.139 2017/09/18 07:42:52 mpi Exp $ */
+/* $OpenBSD: exchange.c,v 1.140 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: exchange.c,v 1.143 2000/12/04 00:02:25 angelos Exp $ */
/*
exchange_create(int phase, int initiator, int doi, int type)
{
struct exchange *exchange;
- struct timeval expiration;
+ struct timespec expiration;
int delta;
/*
return 0;
}
}
- gettimeofday(&expiration, 0);
+ clock_gettime(CLOCK_MONOTONIC, &expiration);
delta = conf_get_num("General", "Exchange-max-time",
EXCHANGE_MAX_TIME);
expiration.tv_sec += delta;
-/* $OpenBSD: isakmpd.c,v 1.104 2016/04/02 14:37:42 krw Exp $ */
+/* $OpenBSD: isakmpd.c,v 1.105 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: isakmpd.c,v 1.54 2000/10/05 09:28:22 niklas Exp $ */
/*
fd_set *rfds, *wfds;
int n, m;
size_t mask_size;
- struct timeval tv, *timeout;
+ struct timespec ts, *timeout;
closefrom(STDERR_FILENO + 1);
n = m;
/* Find out when the next timed event is. */
- timeout = &tv;
+ timeout = &ts;
timer_next_event(&timeout);
- n = select(n, rfds, wfds, 0, timeout);
+ n = pselect(n, rfds, wfds, NULL, timeout, NULL);
if (n == -1) {
if (errno != EINTR) {
log_error("main: select");
-/* $OpenBSD: nat_traversal.c,v 1.24 2015/08/20 22:05:51 deraadt Exp $ */
+/* $OpenBSD: nat_traversal.c,v 1.25 2017/12/05 20:31:45 jca Exp $ */
/*
* Copyright (c) 2004 Håkan Olsson. All rights reserved.
{
struct sa *sa = (struct sa *)v_arg;
struct transport *t;
- struct timeval now;
+ struct timespec now;
int interval;
/* Send the keepalive message. */
interval = conf_get_num("General", "NAT-T-Keepalive", 0);
if (interval < 1)
interval = NAT_T_KEEPALIVE_INTERVAL;
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
now.tv_sec += interval;
sa->nat_t_keepalive = timer_add_event("nat_t_send_keepalive",
nat_t_setup_keepalive(struct sa *sa)
{
struct sockaddr *src;
- struct timeval now;
+ struct timespec now;
if (sa->initiator)
sa->transport->vtbl->get_src(sa->transport, &src);
if (!virtual_listen_lookup(src))
return;
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
now.tv_sec += NAT_T_KEEPALIVE_INTERVAL;
sa->nat_t_keepalive = timer_add_event("nat_t_send_keepalive",
-/* $OpenBSD: pf_key_v2.c,v 1.199 2017/08/06 13:54:04 mpi Exp $ */
+/* $OpenBSD: pf_key_v2.c,v 1.200 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: pf_key_v2.c,v 1.79 2000/12/12 00:33:19 niklas Exp $ */
/*
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/socket.h>
-#include <sys/time.h>
#include <sys/uio.h>
#include <net/pfkeyv2.h>
struct sadb_msg *msg;
struct sadb_msg hdr;
struct sadb_ext *ext;
- struct timeval tv;
+ struct timespec ts;
struct pollfd pfd[1];
pfd[0].fd = pf_key_v2_socket;
*/
if (seq && (msg->sadb_msg_pid != (u_int32_t) getpid() ||
msg->sadb_msg_seq != seq)) {
- gettimeofday(&tv, 0);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
timer_add_event("pf_key_v2_notify",
- (void (*) (void *)) pf_key_v2_notify, ret, &tv);
+ (void (*) (void *)) pf_key_v2_notify, ret, &ts);
ret = 0;
continue;
}
-/* $OpenBSD: sa.c,v 1.123 2015/12/09 21:41:50 naddy Exp $ */
+/* $OpenBSD: sa.c,v 1.124 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: sa.c,v 1.112 2000/12/12 00:22:52 niklas Exp $ */
/*
int
sa_setup_expirations(struct sa *sa)
{
- struct timeval expiration;
+ struct timespec expiration;
u_int64_t seconds = sa->seconds;
/*
* XXX Better scheme to come?
*/
if (!sa->soft_death) {
- gettimeofday(&expiration, 0);
+ clock_gettime(CLOCK_MONOTONIC, &expiration);
/*
* XXX This should probably be configuration controlled
* somehow.
sa_reference(sa);
}
if (!sa->death) {
- gettimeofday(&expiration, 0);
+ clock_gettime(CLOCK_MONOTONIC, &expiration);
LOG_DBG((LOG_TIMER, 95,
"sa_setup_expirations: SA %p hard timeout in %llu seconds",
sa, sa->seconds));
-/* $OpenBSD: timer.c,v 1.17 2015/08/20 22:02:21 deraadt Exp $ */
+/* $OpenBSD: timer.c,v 1.18 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: timer.c,v 1.13 2000/02/20 19:58:42 niklas Exp $ */
/*
*/
#include <sys/queue.h>
+#include <sys/time.h>
+
#include <stdlib.h>
#include <string.h>
}
void
-timer_next_event(struct timeval **timeout)
+timer_next_event(struct timespec **timeout)
{
- struct timeval now;
+ struct timespec now;
if (TAILQ_FIRST(&events)) {
- gettimeofday(&now, 0);
- if (timercmp(&now, &TAILQ_FIRST(&events)->expiration, >=))
- timerclear(*timeout);
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&now, &TAILQ_FIRST(&events)->expiration, >=))
+ timespecclear(*timeout);
else
- timersub(&TAILQ_FIRST(&events)->expiration, &now,
+ timespecsub(&TAILQ_FIRST(&events)->expiration, &now,
*timeout);
} else
*timeout = 0;
void
timer_handle_expirations(void)
{
- struct timeval now;
+ struct timespec now;
struct event *n;
- gettimeofday(&now, 0);
- for (n = TAILQ_FIRST(&events); n && timercmp(&now, &n->expiration, >=);
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ for (n = TAILQ_FIRST(&events);
+ n && timespeccmp(&now, &n->expiration, >=);
n = TAILQ_FIRST(&events)) {
LOG_DBG((LOG_TIMER, 10,
"timer_handle_expirations: event %s(%p)", n->name,
struct event *
timer_add_event(char *name, void (*func)(void *), void *arg,
- struct timeval *expiration)
+ struct timespec *expiration)
{
struct event *ev = malloc(sizeof *ev);
struct event *n;
- struct timeval now;
+ struct timespec now;
if (!ev)
return 0;
ev->name = name;
ev->func = func;
ev->arg = arg;
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
memcpy(&ev->expiration, expiration, sizeof *expiration);
for (n = TAILQ_FIRST(&events);
- n && timercmp(expiration, &n->expiration, >=);
+ n && timespeccmp(expiration, &n->expiration, >=);
n = TAILQ_NEXT(n, link))
;
if (n) {
timer_report(void)
{
struct event *ev;
- struct timeval now;
+ struct timespec now;
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC, &now);
for (ev = TAILQ_FIRST(&events); ev; ev = TAILQ_NEXT(ev, link))
LOG_DBG((LOG_REPORT, 0,
-/* $OpenBSD: timer.h,v 1.8 2015/01/16 06:39:59 deraadt Exp $ */
+/* $OpenBSD: timer.h,v 1.9 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: timer.h,v 1.6 1999/04/11 22:35:55 ho Exp $ */
/*
#define _TIMER_H_
#include <sys/queue.h>
-#include <sys/time.h>
+
+#include <time.h>
struct event {
TAILQ_ENTRY(event) link;
char *name;
void (*func) (void *);
void *arg;
- struct timeval expiration;
+ struct timespec expiration;
};
extern void timer_init(void);
-extern void timer_next_event(struct timeval **);
+extern void timer_next_event(struct timespec **);
extern void timer_handle_expirations(void);
extern struct event *timer_add_event(char *, void (*) (void *), void *,
- struct timeval *);
+ struct timespec *);
extern void timer_remove_event(struct event *);
extern void timer_report(void);
-/* $OpenBSD: transport.c,v 1.37 2016/03/10 07:32:16 yasuoka Exp $ */
+/* $OpenBSD: transport.c,v 1.38 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: transport.c,v 1.43 2000/10/10 12:36:39 provos Exp $ */
/*
struct message *msg;
struct exchange *exchange;
struct sockaddr *dst;
- struct timeval expiration;
+ struct timespec expiration;
int expiry, ok_to_drop_message;
char peer[NI_MAXHOST], peersv[NI_MAXSERV];
exchange = 0;
#endif
} else {
- gettimeofday(&expiration, 0);
+ clock_gettime(CLOCK_MONOTONIC,
+ &expiration);
/*
* XXX Calculate from round trip
-/* $OpenBSD: ui.c,v 1.56 2014/12/01 23:05:18 tedu Exp $ */
+/* $OpenBSD: ui.c,v 1.57 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: ui.c,v 1.43 2000/10/05 09:25:12 niklas Exp $ */
/*
static void
ui_conn_reinit(void)
{
- struct timeval tv;
+ struct timespec ts;
if (ui_cr_event)
timer_remove_event(ui_cr_event);
- gettimeofday(&tv, 0);
- tv.tv_sec += 5;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ ts.tv_sec += 5;
ui_cr_event = timer_add_event("ui_conn_reinit", ui_conn_reinit_event,
- 0, &tv);
+ 0, &ts);
if (!ui_cr_event)
log_print("ui_conn_reinit: timer_add_event() failed. "
"Connections will not be updated.");
-/* $OpenBSD: util.c,v 1.69 2015/08/20 22:02:21 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.70 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: util.c,v 1.23 2000/11/23 12:22:08 niklas Exp $ */
/*
/* Calculate timeout. Returns -1 on error. */
long
-get_timeout(struct timeval *timeout)
+get_timeout(struct timespec *timeout)
{
- struct timeval now, result;
+ struct timespec now, result;
- if (gettimeofday(&now, NULL) < 0)
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
return -1;
-
- timersub(timeout, &now, &result);
-
+ timespecsub(timeout, &now, &result);
return result.tv_sec;
}
-/* $OpenBSD: util.h,v 1.32 2014/01/23 01:04:28 deraadt Exp $ */
+/* $OpenBSD: util.h,v 1.33 2017/12/05 20:31:45 jca Exp $ */
/* $EOM: util.h,v 1.10 2000/10/24 13:33:39 niklas Exp $ */
/*
sa_family_t, int);
extern void util_ntoa(char **, int, u_int8_t *);
extern int zero_test(const u_int8_t *, size_t);
-extern long get_timeout(struct timeval *);
+extern long get_timeout(struct timespec *);
extern int expand_string(char *, size_t, const char *, const char *);
#endif /* _UTIL_H_ */