diff options
author | Hugo Landau <hlandau@openssl.org> | 2023-05-23 12:23:06 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-06-16 09:26:28 +1000 |
commit | e3e9794aa49f61e5b034608488034daa01125c85 (patch) | |
tree | 1e49edb14740080d29ecab8175ed9269ff6180c0 /ssl | |
parent | 754d2282cd50fef14971605d7151623bb11e3fd6 (diff) |
QUIC APL: Correct implementation of time callback override
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21029)
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/quic/quic_impl.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index d00f4455b0..9cfc253bdc 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -59,6 +59,21 @@ static int block_until_pred(QUIC_CONNECTION *qc, qc->mutex); } +static OSSL_TIME get_time(QUIC_CONNECTION *qc) +{ + if (qc->override_now_cb != NULL) + return qc->override_now_cb(qc->override_now_cb_arg); + else + return ossl_time_now(); +} + +static OSSL_TIME get_time_cb(void *arg) +{ + QUIC_CONNECTION *qc = arg; + + return get_time(qc); +} + /* * QCTX is a utility structure which provides information we commonly wish to * unwrap upon an API call being dispatched to us, namely: @@ -490,17 +505,22 @@ int ossl_quic_clear(SSL *s) return 1; } -void ossl_quic_conn_set_override_now_cb(SSL *s, - OSSL_TIME (*now_cb)(void *arg), - void *now_cb_arg) +int ossl_quic_conn_set_override_now_cb(SSL *s, + OSSL_TIME (*now_cb)(void *arg), + void *now_cb_arg) { QCTX ctx; if (!expect_quic(s, &ctx)) - return; + return 0; + + quic_lock(ctx.qc); ctx.qc->override_now_cb = now_cb; ctx.qc->override_now_cb_arg = now_cb_arg; + + quic_unlock(ctx.qc); + return 1; } void ossl_quic_conn_force_assist_thread_wake(SSL *s) @@ -889,7 +909,7 @@ int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv, int *is_infinite) return 1; } - *tv = ossl_time_to_timeval(ossl_time_subtract(deadline, ossl_time_now())); + *tv = ossl_time_to_timeval(ossl_time_subtract(deadline, get_time(ctx.qc))); *is_infinite = 0; quic_unlock(ctx.qc); return 1; @@ -1146,8 +1166,8 @@ static int create_channel(QUIC_CONNECTION *qc) args.is_server = qc->as_server; args.tls = qc->tls; args.mutex = qc->mutex; - args.now_cb = qc->override_now_cb; - args.now_cb_arg = qc->override_now_cb_arg; + args.now_cb = get_time_cb; + args.now_cb_arg = qc; qc->ch = ossl_quic_channel_new(&args); if (qc->ch == NULL) |