diff options
author | Martin Willi <martin@strongswan.org> | 2009-08-31 15:25:03 +0200 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2009-08-31 15:25:03 +0200 |
commit | de5784452b31af3c7342269127a12d352edc0b4e (patch) | |
tree | 04fc6c8bcb9ca117a5d09171651c4e91fae70666 | |
parent | 3d5818ec38c464b24f382d88c70b10df6c04b160 (diff) | |
download | strongswan-de5784452b31af3c7342269127a12d352edc0b4e.tar.bz2 strongswan-de5784452b31af3c7342269127a12d352edc0b4e.tar.xz |
use time_monotonic() instead of gettimeofday() for time difference calculations
-rw-r--r-- | src/charon/plugins/eap_aka/eap_aka.c | 5 | ||||
-rw-r--r-- | src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c | 1 | ||||
-rw-r--r-- | src/charon/plugins/kernel_netlink/kernel_netlink_net.c | 25 | ||||
-rw-r--r-- | src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c | 24 | ||||
-rw-r--r-- | src/charon/plugins/unit_tester/tests/test_pool.c | 1 | ||||
-rw-r--r-- | src/charon/processing/scheduler.h | 2 | ||||
-rw-r--r-- | src/charon/sa/ike_sa.c | 1 | ||||
-rw-r--r-- | src/libstrongswan/utils/mutex.c | 1 | ||||
-rw-r--r-- | src/pluto/ipsec_doi.c | 1 |
9 files changed, 24 insertions, 37 deletions
diff --git a/src/charon/plugins/eap_aka/eap_aka.c b/src/charon/plugins/eap_aka/eap_aka.c index 82ee6c3f0..ebef74404 100644 --- a/src/charon/plugins/eap_aka/eap_aka.c +++ b/src/charon/plugins/eap_aka/eap_aka.c @@ -36,8 +36,6 @@ #include <limits.h> #include <string.h> #include <unistd.h> -#include <sys/time.h> -#include <time.h> #include <gmp.h> #include "eap_aka.h" @@ -272,7 +270,8 @@ static chunk_t peer_sqn = chunk_from_buf(peer_sqn_buf); static void update_sqn(u_int8_t *sqn, time_t offset) { timeval_t time; - gettimeofday(&time, NULL); + + time_monotonic(&time); /* set sqb_sqn to an integer containing seconds followed by most * significant useconds */ time.tv_sec = htonl(time.tv_sec + offset); diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c index e4d31bc53..63a968371 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c @@ -20,7 +20,6 @@ #include <sys/types.h> #include <sys/socket.h> -#include <sys/time.h> #include <stdint.h> #include <linux/ipsec.h> #include <linux/netlink.h> diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_net.c b/src/charon/plugins/kernel_netlink/kernel_netlink_net.c index e5c0b5da7..fd79f0781 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_net.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_net.c @@ -17,7 +17,6 @@ #include <sys/socket.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> -#include <sys/time.h> #include <pthread.h> #include <unistd.h> #include <errno.h> @@ -145,7 +144,7 @@ struct private_kernel_netlink_net_t { /** * time of the last roam_job */ - struct timeval last_roam; + timeval_t last_roam; /** * routing table to install routes @@ -208,22 +207,20 @@ static int get_vip_refcount(private_kernel_netlink_net_t *this, host_t* ip) */ static void fire_roam_job(private_kernel_netlink_net_t *this, bool address) { - struct timeval now; + timeval_t now; - if (gettimeofday(&now, NULL) == 0) + time_monotonic(&now); + if (timercmp(&now, &this->last_roam, >)) { - if (timercmp(&now, &this->last_roam, >)) + now.tv_usec += ROAM_DELAY * 1000; + while (now.tv_usec > 1000000) { - now.tv_usec += ROAM_DELAY * 1000; - while (now.tv_usec > 1000000) - { - now.tv_sec++; - now.tv_usec -= 1000000; - } - this->last_roam = now; - charon->scheduler->schedule_job_ms(charon->scheduler, - (job_t*)roam_job_create(address), ROAM_DELAY); + now.tv_sec++; + now.tv_usec -= 1000000; } + this->last_roam = now; + charon->scheduler->schedule_job_ms(charon->scheduler, + (job_t*)roam_job_create(address), ROAM_DELAY); } } diff --git a/src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c b/src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c index d5a864b1c..da97fcd83 100644 --- a/src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c +++ b/src/charon/plugins/kernel_pfroute/kernel_pfroute_net.c @@ -147,7 +147,7 @@ struct private_kernel_pfroute_net_t /** * time of last roam job */ - struct timeval last_roam; + timeval_t last_roam; }; /** @@ -156,22 +156,20 @@ struct private_kernel_pfroute_net_t */ static void fire_roam_job(private_kernel_pfroute_net_t *this, bool address) { - struct timeval now; + timeval_t now; - if (gettimeofday(&now, NULL) == 0) + time_monotonic(&now); + if (timercmp(&now, &this->last_roam, >)) { - if (timercmp(&now, &this->last_roam, >)) + now.tv_usec += ROAM_DELAY * 1000; + while (now.tv_usec > 1000000) { - now.tv_usec += ROAM_DELAY * 1000; - while (now.tv_usec > 1000000) - { - now.tv_sec++; - now.tv_usec -= 1000000; - } - this->last_roam = now; - charon->scheduler->schedule_job_ms(charon->scheduler, - (job_t*)roam_job_create(address), ROAM_DELAY); + now.tv_sec++; + now.tv_usec -= 1000000; } + this->last_roam = now; + charon->scheduler->schedule_job_ms(charon->scheduler, + (job_t*)roam_job_create(address), ROAM_DELAY); } } diff --git a/src/charon/plugins/unit_tester/tests/test_pool.c b/src/charon/plugins/unit_tester/tests/test_pool.c index ba5330fd9..f32cd5820 100644 --- a/src/charon/plugins/unit_tester/tests/test_pool.c +++ b/src/charon/plugins/unit_tester/tests/test_pool.c @@ -13,7 +13,6 @@ * for more details. */ -#include <sys/time.h> #include <time.h> #include <pthread.h> diff --git a/src/charon/processing/scheduler.h b/src/charon/processing/scheduler.h index 927b561bb..2bb85e4e6 100644 --- a/src/charon/processing/scheduler.h +++ b/src/charon/processing/scheduler.h @@ -25,8 +25,6 @@ typedef struct scheduler_t scheduler_t; -#include <sys/time.h> - #include <library.h> #include <processing/jobs/job.h> diff --git a/src/charon/sa/ike_sa.c b/src/charon/sa/ike_sa.c index be973a2ce..d2ab41e0b 100644 --- a/src/charon/sa/ike_sa.c +++ b/src/charon/sa/ike_sa.c @@ -16,7 +16,6 @@ * for more details. */ -#include <sys/time.h> #include <string.h> #include <sys/stat.h> #include <errno.h> diff --git a/src/libstrongswan/utils/mutex.c b/src/libstrongswan/utils/mutex.c index fef25706d..83dde442a 100644 --- a/src/libstrongswan/utils/mutex.c +++ b/src/libstrongswan/utils/mutex.c @@ -16,7 +16,6 @@ #define _GNU_SOURCE #include <pthread.h> -#include <sys/time.h> #include <stdint.h> #include <time.h> #include <errno.h> diff --git a/src/pluto/ipsec_doi.c b/src/pluto/ipsec_doi.c index d293037dd..f728065ae 100644 --- a/src/pluto/ipsec_doi.c +++ b/src/pluto/ipsec_doi.c @@ -25,7 +25,6 @@ #include <resolv.h> #include <arpa/nameser.h> /* missing from <resolv.h> on old systems */ #include <sys/queue.h> -#include <sys/time.h> /* for gettimeofday */ #include <freeswan.h> |