summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2014-01-24 05:58:53 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2014-01-24 05:58:53 +0000
commit15fd61e3d466038f2ee008ec30c74144f7fe1511 (patch)
tree36f5bec114993e37d0b94e6912844252d8a11f8e /sbin
parent317952e76ef192bf159dfbbe0a607758bfc8e4d8 (diff)
use a bit saner timer api
Diffstat (limited to 'sbin')
-rw-r--r--sbin/iked/config.c4
-rw-r--r--sbin/iked/iked.h9
-rw-r--r--sbin/iked/ikev2.c30
-rw-r--r--sbin/iked/ikev2_msg.c18
-rw-r--r--sbin/iked/ikev2_pld.c7
-rw-r--r--sbin/iked/timer.c21
6 files changed, 39 insertions, 50 deletions
diff --git a/sbin/iked/config.c b/sbin/iked/config.c
index b144a713652..22b1669a07d 100644
--- a/sbin/iked/config.c
+++ b/sbin/iked/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.23 2013/12/03 13:55:39 markus Exp $ */
+/* $OpenBSD: config.c,v 1.24 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -80,7 +80,7 @@ config_free_sa(struct iked *env, struct iked_sa *sa)
{
(void)RB_REMOVE(iked_sas, &env->sc_sas, sa);
- timer_deregister(env, &sa->sa_timer);
+ timer_del(env, &sa->sa_timer);
config_free_proposals(&sa->sa_proposals, 0);
config_free_childsas(env, &sa->sa_childsas, NULL, NULL);
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index 5da7f835795..86ff845c1fa 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.63 2014/01/22 09:25:41 markus Exp $ */
+/* $OpenBSD: iked.h,v 1.64 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -790,11 +790,10 @@ char *ca_asn1_name(u_int8_t *, size_t);
char *ca_x509_name(void *);
/* timer.c */
-void timer_initialize(struct iked *, struct iked_timer *,
+void timer_set(struct iked *, struct iked_timer *,
void (*)(struct iked *, void *), void *);
-int timer_initialized(struct iked *, struct iked_timer *);
-void timer_register(struct iked *, struct iked_timer *, int);
-void timer_deregister(struct iked *, struct iked_timer *);
+void timer_add(struct iked *, struct iked_timer *, int);
+void timer_del(struct iked *, struct iked_timer *);
/* proc.c */
void proc_init(struct privsep *, struct privsep_proc *, u_int);
diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c
index 5b2150b39ea..7ee9a008729 100644
--- a/sbin/iked/ikev2.c
+++ b/sbin/iked/ikev2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2.c,v 1.89 2014/01/22 09:25:41 markus Exp $ */
+/* $OpenBSD: ikev2.c,v 1.90 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -131,9 +131,9 @@ ikev2_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_CTL_PASSIVE:
if (config_getmode(env, imsg->hdr.type) == -1)
return (0); /* ignore error */
- timer_initialize(env, &env->sc_inittmr, ikev2_init_ike_sa,
+ timer_set(env, &env->sc_inittmr, ikev2_init_ike_sa,
NULL);
- timer_register(env, &env->sc_inittmr, IKED_INITIATOR_INITIAL);
+ timer_add(env, &env->sc_inittmr, IKED_INITIATOR_INITIAL);
return (0);
case IMSG_UDP_SOCKET:
return (config_getsocket(env, imsg, ikev2_msg_cb));
@@ -699,8 +699,8 @@ ikev2_init_ike_sa(struct iked *env, void *arg)
NULL, 0));
}
- timer_initialize(env, &env->sc_inittmr, ikev2_init_ike_sa, NULL);
- timer_register(env, &env->sc_inittmr, IKED_INITIATOR_INTERVAL);
+ timer_set(env, &env->sc_inittmr, ikev2_init_ike_sa, NULL);
+ timer_add(env, &env->sc_inittmr, IKED_INITIATOR_INTERVAL);
}
int
@@ -1020,8 +1020,8 @@ ikev2_init_done(struct iked *env, struct iked_sa *sa)
ret = ikev2_childsa_enable(env, sa);
if (ret == 0) {
sa_state(env, sa, IKEV2_STATE_ESTABLISHED);
- timer_initialize(env, &sa->sa_timer, ikev2_ike_sa_alive, sa);
- timer_register(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
+ timer_set(env, &sa->sa_timer, ikev2_ike_sa_alive, sa);
+ timer_add(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
}
if (ret)
@@ -2070,8 +2070,8 @@ ikev2_resp_ike_auth(struct iked *env, struct iked_sa *sa)
ret = ikev2_childsa_enable(env, sa);
if (ret == 0) {
sa_state(env, sa, IKEV2_STATE_ESTABLISHED);
- timer_initialize(env, &sa->sa_timer, ikev2_ike_sa_alive, sa);
- timer_register(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
+ timer_set(env, &sa->sa_timer, ikev2_ike_sa_alive, sa);
+ timer_add(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
}
done:
@@ -2625,15 +2625,15 @@ ikev2_resp_create_child_sa(struct iked *env, struct iked_message *msg)
log_debug("%s: activating new IKE SA", __func__);
sa_state(env, nsa, IKEV2_STATE_ESTABLISHED);
- timer_initialize(env, &nsa->sa_timer, ikev2_ike_sa_alive, nsa);
- timer_register(env, &nsa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
+ timer_set(env, &nsa->sa_timer, ikev2_ike_sa_alive, nsa);
+ timer_add(env, &nsa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
nsa->sa_stateflags = sa->sa_statevalid; /* XXX */
/* unregister DPD keep alive timer first */
if (sa->sa_state == IKEV2_STATE_ESTABLISHED)
- timer_deregister(env, &sa->sa_timer);
- timer_initialize(env, &sa->sa_timer, ikev2_ike_sa_timeout, sa);
- timer_register(env, &sa->sa_timer, IKED_IKE_SA_REKEY_TIMEOUT);
+ timer_del(env, &sa->sa_timer);
+ timer_set(env, &sa->sa_timer, ikev2_ike_sa_timeout, sa);
+ timer_add(env, &sa->sa_timer, IKED_IKE_SA_REKEY_TIMEOUT);
} else
ret = ikev2_childsa_enable(env, sa);
@@ -2691,7 +2691,7 @@ ikev2_ike_sa_alive(struct iked *env, void *arg)
}
/* re-register */
- timer_register(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
+ timer_add(env, &sa->sa_timer, IKED_IKE_SA_ALIVE_TIMEOUT);
}
int
diff --git a/sbin/iked/ikev2_msg.c b/sbin/iked/ikev2_msg.c
index 19c167b2747..cd606802e7a 100644
--- a/sbin/iked/ikev2_msg.c
+++ b/sbin/iked/ikev2_msg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2_msg.c,v 1.27 2013/12/03 13:55:39 markus Exp $ */
+/* $OpenBSD: ikev2_msg.c,v 1.28 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -300,14 +300,12 @@ ikev2_msg_send(struct iked *env, struct iked_message *msg)
if (flags & IKEV2_FLAG_RESPONSE) {
TAILQ_INSERT_TAIL(&sa->sa_responses, m, msg_entry);
- timer_initialize(env, &m->msg_timer,
- ikev2_msg_response_timeout, m);
- timer_register(env, &m->msg_timer, IKED_RESPONSE_TIMEOUT);
+ timer_set(env, &m->msg_timer, ikev2_msg_response_timeout, m);
+ timer_add(env, &m->msg_timer, IKED_RESPONSE_TIMEOUT);
} else {
TAILQ_INSERT_TAIL(&sa->sa_requests, m, msg_entry);
- timer_initialize(env, &m->msg_timer,
- ikev2_msg_retransmit_timeout, m);
- timer_register(env, &m->msg_timer, IKED_RETRANSMIT_TIMEOUT);
+ timer_set(env, &m->msg_timer, ikev2_msg_retransmit_timeout, m);
+ timer_add(env, &m->msg_timer, IKED_RETRANSMIT_TIMEOUT);
}
return (0);
@@ -907,7 +905,7 @@ ikev2_msg_dispose(struct iked *env, struct iked_msgqueue *queue,
struct iked_message *msg)
{
TAILQ_REMOVE(queue, msg, msg_entry);
- timer_deregister(env, &msg->msg_timer);
+ timer_del(env, &msg->msg_timer);
ikev2_msg_cleanup(env, msg);
free(msg);
}
@@ -948,7 +946,7 @@ ikev2_msg_retransmit_response(struct iked *env, struct iked_sa *sa,
return (-1);
}
- timer_register(env, &msg->msg_timer, IKED_RESPONSE_TIMEOUT);
+ timer_add(env, &msg->msg_timer, IKED_RESPONSE_TIMEOUT);
return (0);
}
@@ -977,7 +975,7 @@ ikev2_msg_retransmit_timeout(struct iked *env, void *arg)
return;
}
/* Exponential timeout */
- timer_register(env, &msg->msg_timer,
+ timer_add(env, &msg->msg_timer,
IKED_RETRANSMIT_TIMEOUT * (2 << (msg->msg_tries++)));
} else {
log_debug("%s: retransmit limit reached", __func__);
diff --git a/sbin/iked/ikev2_pld.c b/sbin/iked/ikev2_pld.c
index f5180db199e..208cfa37f3f 100644
--- a/sbin/iked/ikev2_pld.c
+++ b/sbin/iked/ikev2_pld.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ikev2_pld.c,v 1.34 2014/01/22 09:25:41 markus Exp $ */
+/* $OpenBSD: ikev2_pld.c,v 1.35 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -711,9 +711,8 @@ ikev2_pld_notify(struct iked *env, struct ikev2_payload *pld,
group);
sa_free(env, msg->msg_sa);
msg->msg_sa = NULL;
- timer_initialize(env, &env->sc_inittmr, ikev2_init_ike_sa,
- NULL);
- timer_register(env, &env->sc_inittmr, IKED_INITIATOR_INITIAL);
+ timer_set(env, &env->sc_inittmr, ikev2_init_ike_sa, NULL);
+ timer_add(env, &env->sc_inittmr, IKED_INITIATOR_INITIAL);
break;
case IKEV2_N_NO_ADDITIONAL_SAS:
/* This makes sense for Child SAs only atm */
diff --git a/sbin/iked/timer.c b/sbin/iked/timer.c
index 2ad7ef229a2..0ffa21cb8fd 100644
--- a/sbin/iked/timer.c
+++ b/sbin/iked/timer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timer.c,v 1.10 2013/01/08 10:38:19 reyk Exp $ */
+/* $OpenBSD: timer.c,v 1.11 2014/01/24 05:58:52 mikeb Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -35,7 +35,7 @@
void timer_callback(int, short, void *);
void
-timer_initialize(struct iked *env, struct iked_timer *tmr,
+timer_set(struct iked *env, struct iked_timer *tmr,
void (*cb)(struct iked *, void *), void *arg)
{
tmr->tmr_env = env;
@@ -44,17 +44,8 @@ timer_initialize(struct iked *env, struct iked_timer *tmr,
evtimer_set(&tmr->tmr_ev, timer_callback, tmr);
}
-int
-timer_initialized(struct iked *env, struct iked_timer *tmr)
-{
- if (tmr && tmr->tmr_env == env && tmr->tmr_cb &&
- evtimer_initialized(&tmr->tmr_ev))
- return (1);
- return (0);
-}
-
void
-timer_register(struct iked *env, struct iked_timer *tmr, int timeout)
+timer_add(struct iked *env, struct iked_timer *tmr, int timeout)
{
struct timeval tv = { timeout };
@@ -66,9 +57,11 @@ timer_register(struct iked *env, struct iked_timer *tmr, int timeout)
}
void
-timer_deregister(struct iked *env, struct iked_timer *tmr)
+timer_del(struct iked *env, struct iked_timer *tmr)
{
- evtimer_del(&tmr->tmr_ev);
+ if (tmr->tmr_env == env && tmr->tmr_cb &&
+ evtimer_initialized(&tmr->tmr_ev))
+ evtimer_del(&tmr->tmr_ev);
}
void