]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC: Immediate-Mode Polling various fixups
authorTomas Mraz <tomas@openssl.org>
Tue, 10 Sep 2024 06:53:20 +0000 (08:53 +0200)
committerNeil Horman <nhorman@openssl.org>
Sat, 11 Jan 2025 21:02:29 +0000 (16:02 -0500)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25416)

doc/man3/SSL_poll.pod
include/internal/quic_reactor_wait_ctx.h
ssl/rio/build.info
ssl/rio/poll_builder.c
ssl/rio/poll_builder.h
ssl/rio/poll_immediate.c
test/radix/quic_ops.c
test/radix/quic_tests.c

index 3b3767421518d5f1af27577d54d92afac9958324..ce9ef5ff73e2d6e30beb8afeec3b68df150cbce1 100644 (file)
@@ -326,7 +326,7 @@ SSL_poll() as presently implemented has the following limitation:
 =item
 
 Only B<BIO_POLL_DESCRIPTOR> structures with type
-B<BIO_POLL_DESCRIPTOR_TYPE_SSL>, referencing QUIC connection SSL objects or QUIC
+B<BIO_POLL_DESCRIPTOR_TYPE_SSL>, referencing QUIC listener, connection or
 stream SSL objects, are supported.
 
 =back
index 62df11be9dd57695633bf5202ff462b89baeefa0..552af41e47887963a3c6ef8cd4fa0d19b3be8fb3 100644 (file)
  * 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.
  *
index 58b0f8bc93585d75b44b7d4072dc4c78e4d4e565..8e8ebaba46867d8eecad9fcffd3482a61482ab7f 100644 (file)
@@ -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
index bd0979ad375f609ca752f5354d82f3c6d07a8120..166905d4a88819ee065d5a87ce396fef2744e160 100644 (file)
@@ -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 <assert.h>
+#include <errno.h>
+#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);
index 456e4048430073b01bee517ad00b91e18d59d3af..650b0b868c3fed788172e81d34b3e5a1e44140c3 100644 (file)
@@ -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
index d62943386a907f10840421bc950f6333928564dc..e1bc2391177233aceb26fd6be9b3f72ad71aa6b2 100644 (file)
@@ -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 */
index 3ff063f5d6d0f051b825ef992f1af8ce2d55df36..3396bcf30fc06c7e3aeaba8348f93d055f4ce340 100644 (file)
@@ -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;
index 71ae0c8638fc5386c3a0fde4cad86c24d42ca858..91efd2ee88f515d9a657fcf48de22041abbda639 100644 (file)
@@ -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: