From: Hugo Landau Date: Mon, 13 May 2024 19:20:23 +0000 (+0100) Subject: QUIC POLLING: Add support for polling listeners X-Git-Tag: openssl-3.5.0-alpha1~346 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2fff144d722d80af640ed2ef4ca9119cc35f459;p=thirdparty%2Fopenssl.git QUIC POLLING: Add support for polling listeners Reviewed-by: Matt Caswell Reviewed-by: Saša Nedvědický Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/25416) --- diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 0b4252eae3f..3b9da246691 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -4757,6 +4757,20 @@ static int test_poll_event_os(QUIC_CONNECTION *qc, int is_uni) && ossl_quic_channel_get_local_stream_count_avail(qc->ch, is_uni) > 0; } +/* Do we have the EL (exception: listener) condition? */ +QUIC_NEEDS_LOCK +static int test_poll_event_el(QUIC_LISTENER *ql) +{ + return !ossl_quic_port_is_running(ql->port); +} + +/* Do we have the IC (incoming: connection) condition? */ +QUIC_NEEDS_LOCK +static int test_poll_event_ic(QUIC_LISTENER *ql) +{ + return ossl_quic_port_get_num_incoming_channels(ql->port) > 0; +} + QUIC_TAKES_LOCK int ossl_quic_conn_poll_events(SSL *ssl, uint64_t events, int do_tick, uint64_t *p_revents) @@ -4764,22 +4778,21 @@ int ossl_quic_conn_poll_events(SSL *ssl, uint64_t events, int do_tick, QCTX ctx; uint64_t revents = 0; - /* TODO(QUIC SERVER): Support listeners */ - if (!expect_quic_cs(ssl, &ctx)) + if (!expect_quic_csl(ssl, &ctx)) return 0; qctx_lock(&ctx); - if (do_tick) - ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(ctx.qc->ch), 0); - - if (!ctx.qc->started) { + if (ctx.qc != NULL && !ctx.qc->started) { /* We can only try to write on non-started connection. */ if ((events & SSL_POLL_EVENT_W) != 0) revents |= SSL_POLL_EVENT_W; goto end; } + if (do_tick) + ossl_quic_reactor_tick(ossl_quic_obj_get0_reactor(ctx.obj), 0); + if (ctx.xso != NULL) { /* SSL object has a stream component. */ @@ -4800,7 +4813,7 @@ int ossl_quic_conn_poll_events(SSL *ssl, uint64_t events, int do_tick, revents |= SSL_POLL_EVENT_EW; } - if (!ctx.is_stream) { + if (ctx.qc != NULL && !ctx.is_stream) { if ((events & SSL_POLL_EVENT_EC) != 0 && test_poll_event_ec(ctx.qc)) revents |= SSL_POLL_EVENT_EC; @@ -4826,6 +4839,16 @@ int ossl_quic_conn_poll_events(SSL *ssl, uint64_t events, int do_tick, revents |= SSL_POLL_EVENT_OSU; } + if (ctx.is_listener) { + if ((events & SSL_POLL_EVENT_EL) != 0 + && test_poll_event_el(ctx.ql)) + revents |= SSL_POLL_EVENT_EL; + + if ((events & SSL_POLL_EVENT_IC) != 0 + && test_poll_event_ic(ctx.ql)) + revents |= SSL_POLL_EVENT_IC; + } + end: qctx_unlock(&ctx); *p_revents = revents; diff --git a/ssl/rio/poll_immediate.c b/ssl/rio/poll_immediate.c index 9154acd0648..7bc454537d9 100644 --- a/ssl/rio/poll_immediate.c +++ b/ssl/rio/poll_immediate.c @@ -124,6 +124,7 @@ static int poll_translate(SSL_POLL_ITEM *items, switch (ssl->type) { #ifndef OPENSSL_NO_QUIC + case SSL_TYPE_QUIC_LISTENER: case SSL_TYPE_QUIC_CONNECTION: case SSL_TYPE_QUIC_XSO: if (!poll_translate_ssl_quic(ssl, rpb)) @@ -221,6 +222,7 @@ static int poll_readout(SSL_POLL_ITEM *items, switch (ssl->type) { #ifndef OPENSSL_NO_QUIC + case SSL_TYPE_QUIC_LISTENER: case SSL_TYPE_QUIC_CONNECTION: case SSL_TYPE_QUIC_XSO: if (!ossl_quic_conn_poll_events(ssl, events, do_tick, &revents)) @@ -316,7 +318,6 @@ int SSL_poll(SSL_POLL_ITEM *items, } } - /* TODO(QUIC POLLING): Support for polling listeners */ /* TODO(QUIC POLLING): Support for polling FDs */ out: