66 * Based on mbed TLS, https://tls.mbed.org.
77 *
88 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
9- * Copyright (C) 2015-2024 Tempesta Technologies, Inc.
9+ * Copyright (C) 2015-2025 Tempesta Technologies, Inc.
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -71,11 +71,23 @@ const char *ticket_key_name_iv =
7171static inline unsigned long
7272ttls_ticket_get_time (unsigned long lifetime )
7373{
74- unsigned long ts = tfw_current_timestamp ();
74+ struct timespec64 ts ;
75+ unsigned long ts_sec ;
7576
76- ts -= ts % lifetime ;
77+ /*
78+ * This function is called from both process context
79+ * (ttls_tickets_configure) and softirq context
80+ * (ttls_ticket_rotate_keys timer callback).
81+ */
82+ if (in_softirq ()) {
83+ tfw_current_timestamp_ts64 (& ts );
84+ } else {
85+ tfw_current_timestamp_real (& ts );
86+ }
87+ ts_sec = ts .tv_sec ;
88+ ts_sec -= ts_sec % lifetime ;
7789
78- return ts ;
90+ return ts_sec ;
7991}
8092
8193/**
@@ -177,6 +189,7 @@ static void
177189ttls_ticket_rotate_keys (struct timer_list * t )
178190{
179191 TlsTicketPeerCfg * tcfg = from_timer (tcfg , t , timer );
192+ struct timespec64 ts ;
180193 unsigned long secs ;
181194
182195 T_DBG ("TLS: Rotate keys for ticket configuration [%pK]\n" , tcfg );
@@ -192,7 +205,8 @@ ttls_ticket_rotate_keys(struct timer_list *t)
192205 * and callback will fire at different time on different Tempesta
193206 * nodes. To avoid it need to recalculate timer every time.
194207 */
195- secs = tcfg -> lifetime - (tfw_current_timestamp () % tcfg -> lifetime );
208+ tfw_current_timestamp_ts64 (& ts );
209+ secs = tcfg -> lifetime - (ts .tv_sec % tcfg -> lifetime );
196210 mod_timer (& tcfg -> timer , jiffies + msecs_to_jiffies (secs * 1000 ));
197211}
198212
@@ -280,6 +294,7 @@ ttls_tickets_configure(TlsPeerCfg *cfg, unsigned long lifetime,
280294 const char * md_ctx_key = secret_str ;
281295 size_t md_ctx_key_len = len ;
282296 TlsMdCtx md_ctx ;
297+ struct timespec64 ts ;
283298 unsigned long secs ;
284299
285300 tcfg -> active_key = 0 ;
@@ -351,7 +366,8 @@ ttls_tickets_configure(TlsPeerCfg *cfg, unsigned long lifetime,
351366 }
352367
353368 timer_setup (& tcfg -> timer , ttls_ticket_rotate_keys , 0 );
354- secs = tcfg -> lifetime - (tfw_current_timestamp () % tcfg -> lifetime );
369+ tfw_current_timestamp_real (& ts );
370+ secs = tcfg -> lifetime - (ts .tv_sec % tcfg -> lifetime );
355371 mod_timer (& tcfg -> timer , jiffies + msecs_to_jiffies (secs * 1000 ));
356372
357373err :
@@ -479,7 +495,7 @@ ttls_ticket_sess_save(const TlsSess *sess, TlsState *state, size_t buf_len)
479495static int
480496ttls_ticket_sess_load (TlsState * state , size_t len , unsigned long lifetime )
481497{
482- long time_pass = ttls_time () - state -> sess .start ;
498+ long time_pass = tfw_current_timestamp () - state -> sess .start ;
483499
484500 if ((time_pass < 0 ) || (unsigned long )time_pass > lifetime )
485501 return TTLS_ERR_SESSION_TICKET_EXPIRED ;
0 commit comments