From 31fcedc12e4de69c1c9bae09333c01efe2ddf662 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sun, 25 Sep 2022 16:42:46 +0900 Subject: [PATCH] Follow-up on #1770 --- lib/core/ogs-time.c | 10 +++++----- lib/core/ogs-uuid.c | 2 +- src/upf/context.c | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/core/ogs-time.c b/lib/core/ogs-time.c index a679001bd..5edaccc5e 100644 --- a/lib/core/ogs-time.c +++ b/lib/core/ogs-time.c @@ -125,7 +125,7 @@ ogs_time_t ogs_time_now(void) rc = ogs_gettimeofday(&tv); ogs_assert(rc == 0); - return tv.tv_sec * OGS_USEC_PER_SEC + tv.tv_usec; + return ogs_time_from_sec(tv.tv_sec) + tv.tv_usec; } /* The following code is stolen from APR library */ @@ -188,13 +188,13 @@ uint32_t ogs_time_ntp32_now(void) rc = ogs_gettimeofday(&tv); ogs_assert(rc == 0); - return ogs_time_to_ntp32(tv.tv_sec * OGS_USEC_PER_SEC + tv.tv_usec); + return ogs_time_to_ntp32(ogs_time_from_sec(tv.tv_sec) + tv.tv_usec); } ogs_time_t ogs_time_from_ntp32(uint32_t ntp_timestamp) { if (ntp_timestamp < OGS_1970_1900_SEC_DIFF) return 0; - return (ntp_timestamp - OGS_1970_1900_SEC_DIFF) * OGS_USEC_PER_SEC; + return ogs_time_from_sec(ntp_timestamp - OGS_1970_1900_SEC_DIFF); } uint32_t ogs_time_to_ntp32(ogs_time_t time) { @@ -242,7 +242,7 @@ ogs_time_t ogs_get_monotonic_time(void) #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (((int64_t) ts.tv_sec * 1000000UL) + (ts.tv_nsec / 1000UL)); + return ogs_time_from_sec(ts.tv_sec) + ts.tv_nsec / 1000UL; #elif defined(__APPLE__) static mach_timebase_info_data_t info = {0}; static double ratio = 0.0; @@ -268,7 +268,7 @@ ogs_time_t ogs_get_monotonic_time(void) struct timeval tv; ogs_gettimeofday(&tv); - return (tv.tv_sec * 1000000UL) + tv.tv_usec; + return ogs_time_from_sec(tv.tv_sec) + tv.tv_usec; #endif } diff --git a/lib/core/ogs-uuid.c b/lib/core/ogs-uuid.c index 3ade274a6..07cd862ee 100644 --- a/lib/core/ogs-uuid.c +++ b/lib/core/ogs-uuid.c @@ -80,7 +80,7 @@ static void get_system_time(uint64_t *uuid_time) /* ### fix this call to be more portable? */ ogs_gettimeofday(&tv); - *uuid_time = tv.tv_sec * OGS_USEC_PER_SEC + tv.tv_usec; + *uuid_time = ogs_time_from_sec(tv.tv_sec) + tv.tv_usec; /* Offset between UUID formatted times and Unix formatted times. UUID UTC base time is October 15, 1582. diff --git a/src/upf/context.c b/src/upf/context.c index 94d38fa99..819b37fc4 100644 --- a/src/upf/context.c +++ b/src/upf/context.c @@ -547,7 +547,8 @@ static void upf_sess_urr_acc_validity_time_setup(upf_sess_t *sess, ogs_pfcp_urr_ if (!urr_acc->t_validity_time) urr_acc->t_validity_time = ogs_timer_add(ogs_app()->timer_mgr, upf_sess_urr_acc_timers_cb, urr); - ogs_timer_start(urr_acc->t_validity_time, urr->quota_validity_time * OGS_USEC_PER_SEC); + ogs_timer_start(urr_acc->t_validity_time, + ogs_time_from_sec(urr->quota_validity_time)); } static void upf_sess_urr_acc_time_quota_setup(upf_sess_t *sess, ogs_pfcp_urr_t *urr) { @@ -558,7 +559,7 @@ static void upf_sess_urr_acc_time_quota_setup(upf_sess_t *sess, ogs_pfcp_urr_t * if (!urr_acc->t_time_quota) urr_acc->t_time_quota = ogs_timer_add(ogs_app()->timer_mgr, upf_sess_urr_acc_timers_cb, urr); - ogs_timer_start(urr_acc->t_time_quota, urr->time_quota * OGS_USEC_PER_SEC); + ogs_timer_start(urr_acc->t_time_quota, ogs_time_from_sec(urr->time_quota)); } static void upf_sess_urr_acc_time_threshold_setup(upf_sess_t *sess, ogs_pfcp_urr_t *urr) { @@ -569,7 +570,8 @@ static void upf_sess_urr_acc_time_threshold_setup(upf_sess_t *sess, ogs_pfcp_urr if (!urr_acc->t_time_threshold) urr_acc->t_time_threshold = ogs_timer_add(ogs_app()->timer_mgr, upf_sess_urr_acc_timers_cb, urr); - ogs_timer_start(urr_acc->t_time_threshold, urr->time_threshold * OGS_USEC_PER_SEC); + ogs_timer_start(urr_acc->t_time_threshold, + ogs_time_from_sec(urr->time_threshold)); } void upf_sess_urr_acc_timers_setup(upf_sess_t *sess, ogs_pfcp_urr_t *urr)