From: Hugo Landau Date: Thu, 9 Nov 2023 10:27:13 +0000 (+0000) Subject: QUIC DEMUX: Allow parsed DCID to be learnt in default packet handler X-Git-Tag: openssl-3.3.0-alpha1~427 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d743afe7e83df9473058d68a7fa89649741e6814;p=thirdparty%2Fopenssl.git QUIC DEMUX: Allow parsed DCID to be learnt in default packet handler Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/22674) --- diff --git a/include/internal/quic_demux.h b/include/internal/quic_demux.h index 444249e7288..354d408c854 100644 --- a/include/internal/quic_demux.h +++ b/include/internal/quic_demux.h @@ -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. diff --git a/ssl/quic/quic_demux.c b/ssl/quic/quic_demux.c index 88135fe5b9e..376c0888114 100644 --- a/ssl/quic/quic_demux.c +++ b/ssl/quic/quic_demux.c @@ -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; } diff --git a/ssl/quic/quic_port.c b/ssl/quic/quic_port.c index 64cee54c8b4..91240c3c0e1 100644 --- a/ssl/quic/quic_port.c +++ b/ssl/quic/quic_port.c @@ -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; diff --git a/ssl/quic/quic_record_rx.c b/ssl/quic/quic_record_rx.c index 4d0493baff6..d35264e7a27 100644 --- a/ssl/quic/quic_record_rx.c +++ b/ssl/quic/quic_record_rx.c @@ -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;