QUIC DEMUX: Allow parsed DCID to be learnt in default packet handler
authorHugo Landau <hlandau@openssl.org>
Thu, 9 Nov 2023 10:27:13 +0000 (10:27 +0000)
committerHugo Landau <hlandau@openssl.org>
Thu, 21 Dec 2023 08:11:59 +0000 (08:11 +0000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22674)

include/internal/quic_demux.h
ssl/quic/quic_demux.c
ssl/quic/quic_port.c
ssl/quic/quic_record_rx.c

index 444249e728881df336be539403548024bc1f5203..354d408c8543baa12ad09e1016580e971e90f2b2 100644 (file)
@@ -169,6 +169,9 @@ typedef struct quic_demux_st QUIC_DEMUX;
  * to mutate this buffer; once the demuxer calls this callback, it will never
  * read the buffer again.
  *
+ * If a DCID was identified for the datagram, dcid is non-NULL; otherwise
+ * it is NULL.
+ *
  * The callee must arrange for ossl_quic_demux_release_urxe or
  * ossl_quic_demux_reinject_urxe to be called on the URXE at some point in the
  * future (this need not be before the callback returns).
@@ -176,7 +179,8 @@ typedef struct quic_demux_st QUIC_DEMUX;
  * At the time the callback is made, the URXE will not be in any queue,
  * therefore the callee can use the prev and next fields as it wishes.
  */
-typedef void (ossl_quic_demux_cb_fn)(QUIC_URXE *e, void *arg);
+typedef void (ossl_quic_demux_cb_fn)(QUIC_URXE *e, void *arg,
+                                     const QUIC_CONN_ID *dcid);
 
 /*
  * Called when a datagram is received.
index 88135fe5b9e444a2b9b8aa590d17f5ce6be37b86..376c0888114b9a13deffbb953b8eed0517318f6b 100644 (file)
@@ -481,18 +481,19 @@ static int demux_identify_conn_id(QUIC_DEMUX *demux,
 }
 
 /* Identify the connection structure corresponding to a given URXE. */
-static QUIC_DEMUX_CONN *demux_identify_conn(QUIC_DEMUX *demux, QUIC_URXE *e)
+static QUIC_DEMUX_CONN *demux_identify_conn(QUIC_DEMUX *demux, QUIC_URXE *e,
+                                            QUIC_CONN_ID *dst_conn_id,
+                                            int *dst_conn_id_ok)
 {
-    QUIC_CONN_ID dst_conn_id;
-
-    if (!demux_identify_conn_id(demux, e, &dst_conn_id))
+    if (!demux_identify_conn_id(demux, e, dst_conn_id))
         /*
          * Datagram is so badly malformed we can't get the DCID from the first
          * packet in it, so just give up.
          */
         return NULL;
 
-    return demux_get_by_conn_id(demux, &dst_conn_id);
+    *dst_conn_id_ok = 1;
+    return demux_get_by_conn_id(demux, dst_conn_id);
 }
 
 /*
@@ -502,7 +503,8 @@ static QUIC_DEMUX_CONN *demux_identify_conn(QUIC_DEMUX *demux, QUIC_URXE *e)
 static int demux_process_pending_urxe(QUIC_DEMUX *demux, QUIC_URXE *e)
 {
     QUIC_DEMUX_CONN *conn;
-    int r;
+    QUIC_CONN_ID dst_conn_id;
+    int r, dst_conn_id_ok = 0;
 
     /* The next URXE we process should be at the head of the pending list. */
     if (!ossl_assert(e == ossl_list_urxe_head(&demux->urx_pending)))
@@ -533,7 +535,7 @@ static int demux_process_pending_urxe(QUIC_DEMUX *demux, QUIC_URXE *e)
             return 0;
     }
 
-    conn = demux_identify_conn(demux, e);
+    conn = demux_identify_conn(demux, e, &dst_conn_id, &dst_conn_id_ok);
     if (conn == NULL) {
         /*
          * We could not identify a connection. If we have a default packet
@@ -544,7 +546,8 @@ static int demux_process_pending_urxe(QUIC_DEMUX *demux, QUIC_URXE *e)
         if (demux->default_cb != NULL) {
             /* Pass to default handler. */
             e->demux_state = URXE_DEMUX_STATE_ISSUED;
-            demux->default_cb(e, demux->default_cb_arg);
+            demux->default_cb(e, demux->default_cb_arg,
+                              dst_conn_id_ok ? &dst_conn_id : NULL);
         } else {
             /* Discard. */
             ossl_list_urxe_insert_tail(&demux->urx_free, e);
@@ -559,7 +562,7 @@ static int demux_process_pending_urxe(QUIC_DEMUX *demux, QUIC_URXE *e)
      */
     ossl_list_urxe_remove(&demux->urx_pending, e);
     e->demux_state = URXE_DEMUX_STATE_ISSUED;
-    conn->cb(e, conn->cb_arg);
+    conn->cb(e, conn->cb_arg, dst_conn_id_ok ? &dst_conn_id : NULL);
     return 1;
 }
 
index 64cee54c8b410ea648339d875b9a067f41530ddf..91240c3c0e193210c9c00258a6a54bf7ed571156 100644 (file)
@@ -25,7 +25,8 @@ static int port_init(QUIC_PORT *port);
 static void port_cleanup(QUIC_PORT *port);
 static OSSL_TIME get_time(void *arg);
 static void port_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags);
-static void port_default_packet_handler(QUIC_URXE *e, void *arg);
+static void port_default_packet_handler(QUIC_URXE *e, void *arg,
+                                        const QUIC_CONN_ID *dcid);
 static void port_rx_pre(QUIC_PORT *port);
 
 DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
@@ -437,7 +438,8 @@ static int port_try_handle_stateless_reset(QUIC_PORT *port, const QUIC_URXE *e)
  * This is called by the demux when we get a packet not destined for any known
  * DCID.
  */
-static void port_default_packet_handler(QUIC_URXE *e, void *arg)
+static void port_default_packet_handler(QUIC_URXE *e, void *arg,
+                                        const QUIC_CONN_ID *dcid)
 {
     QUIC_PORT *port = arg;
     PACKET pkt;
index 4d0493baff6e8e640a9c2602da8ca6efc2e93e7e..d35264e7a27af1c9c0e1364bf0463e4e2446e17e 100644 (file)
@@ -167,7 +167,7 @@ struct ossl_qrx_st {
     SSL *msg_callback_ssl;
 };
 
-static void qrx_on_rx(QUIC_URXE *urxe, void *arg);
+static void qrx_on_rx(QUIC_URXE *urxe, void *arg, const QUIC_CONN_ID *dcid);
 
 OSSL_QRX *ossl_qrx_new(const OSSL_QRX_ARGS *args)
 {
@@ -252,7 +252,7 @@ void ossl_qrx_inject_urxe(OSSL_QRX *qrx, QUIC_URXE *urxe)
                           qrx->msg_callback_arg);
 }
 
-static void qrx_on_rx(QUIC_URXE *urxe, void *arg)
+static void qrx_on_rx(QUIC_URXE *urxe, void *arg, const QUIC_CONN_ID *dcid)
 {
     OSSL_QRX *qrx = arg;