Skip to content

Commit

Permalink
QUIC DEMUX: Allow parsed DCID to be learnt in default packet handler
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22674)
  • Loading branch information
hlandau committed Dec 21, 2023
1 parent bbae4bb commit d743afe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
6 changes: 5 additions & 1 deletion include/internal/quic_demux.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,18 @@ 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).
*
* 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.
Expand Down
21 changes: 12 additions & 9 deletions ssl/quic/quic_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand All @@ -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)))
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions ssl/quic/quic_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ssl/quic/quic_record_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit d743afe

Please sign in to comment.