From: Tomas Mraz Date: Tue, 10 Sep 2024 06:53:20 +0000 (+0200) Subject: QUIC: Immediate-Mode Polling various fixups X-Git-Tag: openssl-3.5.0-alpha1~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84dbca4df00ccc08ac7917d7dde05e58e85efd60;p=thirdparty%2Fopenssl.git QUIC: Immediate-Mode Polling various fixups Reviewed-by: Matt Caswell Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/25416) --- diff --git a/doc/man3/SSL_poll.pod b/doc/man3/SSL_poll.pod index 3b376742151..ce9ef5ff73e 100644 --- a/doc/man3/SSL_poll.pod +++ b/doc/man3/SSL_poll.pod @@ -326,7 +326,7 @@ SSL_poll() as presently implemented has the following limitation: =item Only B structures with type -B, referencing QUIC connection SSL objects or QUIC +B, referencing QUIC listener, connection or stream SSL objects, are supported. =back diff --git a/include/internal/quic_reactor_wait_ctx.h b/include/internal/quic_reactor_wait_ctx.h index 62df11be9dd..552af41e478 100644 --- a/include/internal/quic_reactor_wait_ctx.h +++ b/include/internal/quic_reactor_wait_ctx.h @@ -43,12 +43,12 @@ * it natural for us to implement it simply by registering a blocking call per * SSL object passed in. Since multiple SSL objects may be passed to an SSL_poll * call, and some SSL objects may correspond to the same reactor, and other SSL - * objects may correspond toa different reactor, we need to be able to determine - * when a SSL_poll call has finished with all of the SSL objects *corresponding - * to a given reactor*. + * objects may correspond to a different reactor, we need to be able to + * determine when a SSL_poll() call has finished with all of the SSL objects + * *corresponding to a given reactor*. * - * Doing this requires some ephemeral state tracking as a SSL_poll call may map - * to an arbitrarily large set of reactor objects. For now, we track this + * Doing this requires some ephemeral state tracking as a SSL_poll() call may + * map to an arbitrarily large set of reactor objects. For now, we track this * separately from the reactor code as the state needed is only ephemeral and * this keeps the reactor internals simple. * diff --git a/ssl/rio/build.info b/ssl/rio/build.info index 58b0f8bc935..8e8ebaba468 100644 --- a/ssl/rio/build.info +++ b/ssl/rio/build.info @@ -2,6 +2,5 @@ $LIBSSL=../../libssl SOURCE[$LIBSSL]=poll_immediate.c IF[{- !$disabled{quic} -}] - SOURCE[$LIBSSL]=rio_notifier.c + SOURCE[$LIBSSL]=rio_notifier.c poll_builder.c ENDIF -SOURCE[$LIBSSL]=poll_builder.c diff --git a/ssl/rio/poll_builder.c b/ssl/rio/poll_builder.c index bd0979ad375..166905d4a88 100644 --- a/ssl/rio/poll_builder.c +++ b/ssl/rio/poll_builder.c @@ -1,6 +1,16 @@ -#include "poll_builder.h" -#include "internal/safe_math.h" +/* + * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + #include +#include +#include "internal/safe_math.h" +#include "poll_builder.h" OSSL_SAFE_MATH_UNSIGNED(size_t, size_t) @@ -56,6 +66,10 @@ static int rpb_ensure_alloc(RIO_POLL_BUILDER *rpb, size_t alloc) int ossl_rio_poll_builder_add_fd(RIO_POLL_BUILDER *rpb, int fd, int want_read, int want_write) { +#if RIO_POLL_METHOD == RIO_POLL_METHOD_POLL + size_t num_loop; +#endif + if (fd < 0) return 0; @@ -83,8 +97,6 @@ int ossl_rio_poll_builder_add_fd(RIO_POLL_BUILDER *rpb, int fd, return 1; #elif RIO_POLL_METHOD == RIO_POLL_METHOD_POLL - size_t num_loop; - for (num_loop = 0;; ++num_loop) { size_t i; struct pollfd *pfds = (rpb->pfd_heap != NULL ? rpb->pfd_heap : rpb->pfds); diff --git a/ssl/rio/poll_builder.h b/ssl/rio/poll_builder.h index 456e4048430..650b0b868c3 100644 --- a/ssl/rio/poll_builder.h +++ b/ssl/rio/poll_builder.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy diff --git a/ssl/rio/poll_immediate.c b/ssl/rio/poll_immediate.c index d62943386a9..e1bc2391177 100644 --- a/ssl/rio/poll_immediate.c +++ b/ssl/rio/poll_immediate.c @@ -37,6 +37,7 @@ FAIL_FROM(idx_ + 1); \ } while (0) +#ifndef OPENSSL_NO_QUIC static int poll_translate_ssl_quic(SSL *ssl, QUIC_REACTOR_WAIT_CTX *wctx, RIO_POLL_BUILDER *rpb, @@ -75,7 +76,7 @@ static int poll_translate_ssl_quic(SSL *ssl, return 0; } - if (rd.type != BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD) { + if (wd.type != BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD) { ERR_raise_data(ERR_LIB_SSL, SSL_R_POLL_REQUEST_NOT_SUPPORTED, "SSL_poll requires the poll descriptors of the " "network BIOs underlying a QUIC SSL object be " @@ -166,13 +167,13 @@ static void postpoll_translation_cleanup(SSL_POLL_ITEM *items, break; switch (ssl->type) { -#ifndef OPENSSL_NO_QUIC +# ifndef OPENSSL_NO_QUIC case SSL_TYPE_QUIC_LISTENER: case SSL_TYPE_QUIC_CONNECTION: case SSL_TYPE_QUIC_XSO: postpoll_translation_cleanup_ssl_quic(ssl, wctx); break; -#endif +# endif default: break; } @@ -211,7 +212,7 @@ static int poll_translate(SSL_POLL_ITEM *items, break; switch (ssl->type) { -#ifndef OPENSSL_NO_QUIC +# ifndef OPENSSL_NO_QUIC case SSL_TYPE_QUIC_LISTENER: case SSL_TYPE_QUIC_CONNECTION: case SSL_TYPE_QUIC_XSO: @@ -232,7 +233,7 @@ static int poll_translate(SSL_POLL_ITEM *items, ossl_time_from_timeval(timeout))); break; -#endif +# endif default: ERR_raise_data(ERR_LIB_SSL, SSL_R_POLL_REQUEST_NOT_SUPPORTED, @@ -318,6 +319,7 @@ out: ossl_quic_reactor_wait_ctx_cleanup(&wctx); return ok; } +#endif static int poll_readout(SSL_POLL_ITEM *items, size_t num_items, @@ -329,11 +331,16 @@ static int poll_readout(SSL_POLL_ITEM *items, size_t i, result_count = 0; SSL_POLL_ITEM *item; SSL *ssl; - uint64_t events, revents; +#ifndef OPENSSL_NO_QUIC + uint64_t events; +#endif + uint64_t revents; for (i = 0; i < num_items; ++i) { item = &ITEM_N(items, stride, i); +#ifndef OPENSSL_NO_QUIC events = item->events; +#endif revents = 0; switch (item->desc.type) { @@ -435,10 +442,12 @@ int SSL_poll(SSL_POLL_ITEM *items, * point onwards. */ do_tick = 1; - if (!poll_block(items, num_items, stride, deadline)) { +#ifndef OPENSSL_NO_QUIC + if (!poll_block(items, num_items, stride, deadline, &result_count)) { ok = 0; goto out; } +#endif } /* TODO(QUIC POLLING): Support for polling FDs */ diff --git a/test/radix/quic_ops.c b/test/radix/quic_ops.c index 3ff063f5d6d..3396bcf30fc 100644 --- a/test/radix/quic_ops.c +++ b/test/radix/quic_ops.c @@ -150,10 +150,12 @@ DEF_FUNC(hf_new_ssl) if (!TEST_ptr(ctx = SSL_CTX_new(method))) goto err; +#if defined(OPENSSL_THREADS) if (!TEST_true(SSL_CTX_set_domain_flags(ctx, SSL_DOMAIN_FLAG_MULTI_THREAD | SSL_DOMAIN_FLAG_BLOCKING))) goto err; +#endif if (!TEST_true(ssl_ctx_configure(ctx, is_server))) goto err; diff --git a/test/radix/quic_tests.c b/test/radix/quic_tests.c index 71ae0c8638f..91efd2ee88f 100644 --- a/test/radix/quic_tests.c +++ b/test/radix/quic_tests.c @@ -123,7 +123,7 @@ DEF_FUNC(ssl_poll_check) break; case 4: /* Listener test */ expected_result_count = 1; - items[5].events |= SSL_POLL_EVENT_IC; + items[5].events = SSL_POLL_EVENT_IC; expected_items[5].revents = SSL_POLL_EVENT_IC; break; default: