]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC POLLING: Add support for polling listeners
authorHugo Landau <hlandau@openssl.org>
Mon, 13 May 2024 19:20:23 +0000 (20:20 +0100)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:33 +0000 (11:27 -0500)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25416)

ssl/quic/quic_impl.c
ssl/rio/poll_immediate.c

index 0b4252eae3faa0e8d9c1b11eb1c80bd5aac2a31a..3b9da246691b8876d3ced2ae7104f023779dbbdd 100644 (file)
@@ -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;
index 9154acd064821af90d2ba9589bcd90b3cbebb8e9..7bc454537d9a259a61a66462ce2595f50d1301d1 100644 (file)
@@ -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: