From: Neil Horman Date: Fri, 15 Nov 2024 18:55:05 +0000 (-0500) Subject: Allow packetizer to accept an arg to set protocol version X-Git-Tag: openssl-3.5.0-alpha1~322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fdd623df3ab5a4ed7dff0719851345b2de45d9d;p=thirdparty%2Fopenssl.git Allow packetizer to accept an arg to set protocol version In preparation for doing version negotiation, expose the ability to have the packetiser for QUIC set a configured protocol version. We only set it to QUIC_VERSION_1 for now, but it allows for us to set different protocols in the future. Reviewed-by: Tomas Mraz Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/25968) --- diff --git a/include/internal/quic_txp.h b/include/internal/quic_txp.h index 607cefc0109..f165134e17d 100644 --- a/include/internal/quic_txp.h +++ b/include/internal/quic_txp.h @@ -52,6 +52,7 @@ typedef struct ossl_quic_tx_packetiser_args_st { void *now_arg; QLOG *(*get_qlog_cb)(void *arg); /* Optional QLOG retrieval func */ void *get_qlog_cb_arg; + uint32_t protocol_version; /* The protocol version to try negotiating */ /* * Injected dependencies - crypto streams. @@ -124,6 +125,13 @@ int ossl_quic_tx_packetiser_set_initial_token(OSSL_QUIC_TX_PACKETISER *txp, ossl_quic_initial_token_free_fn *free_cb, void *free_cb_arg); +/* + * Set the protocol version used when generating packets. Currently should + * only ever be set to QUIC_VERSION_1 + */ +int ossl_quic_tx_packetiser_set_protocol_version(OSSL_QUIC_TX_PACKETISER *txp, + uint32_t protocol_version); + /* Change the DCID the TXP uses to send outgoing packets. */ int ossl_quic_tx_packetiser_set_cur_dcid(OSSL_QUIC_TX_PACKETISER *txp, const QUIC_CONN_ID *dcid); diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index 72155b079ed..6d5504acb61 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -280,6 +280,7 @@ static int ch_init(QUIC_CHANNEL *ch) txp_args.now_arg = ch; txp_args.get_qlog_cb = ch_get_qlog_cb; txp_args.get_qlog_cb_arg = ch; + txp_args.protocol_version = QUIC_VERSION_1; for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space) { ch->crypto_send[pn_space] = ossl_quic_sstream_new(INIT_CRYPTO_SEND_BUF_LEN); diff --git a/ssl/quic/quic_txp.c b/ssl/quic/quic_txp.c index b764de2e486..1456b8f7416 100644 --- a/ssl/quic/quic_txp.c +++ b/ssl/quic/quic_txp.c @@ -464,7 +464,8 @@ OSSL_QUIC_TX_PACKETISER *ossl_quic_tx_packetiser_new(const OSSL_QUIC_TX_PACKETIS || args->conn_txfc == NULL || args->conn_rxfc == NULL || args->max_streams_bidi_rxfc == NULL - || args->max_streams_uni_rxfc == NULL) { + || args->max_streams_uni_rxfc == NULL + || args->protocol_version == 0) { ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_NULL_PARAMETER); return NULL; } @@ -580,6 +581,13 @@ int ossl_quic_tx_packetiser_set_initial_token(OSSL_QUIC_TX_PACKETISER *txp, return 1; } +int ossl_quic_tx_packetiser_set_protocol_version(OSSL_QUIC_TX_PACKETISER *txp, + uint32_t protocol_version) +{ + txp->args.protocol_version = protocol_version; + return 1; +} + int ossl_quic_tx_packetiser_set_cur_dcid(OSSL_QUIC_TX_PACKETISER *txp, const QUIC_CONN_ID *dcid) { @@ -1224,7 +1232,7 @@ static int txp_determine_geometry(OSSL_QUIC_TX_PACKETISER *txp, phdr->partial = 0; phdr->fixed = 1; phdr->reserved = 0; - phdr->version = QUIC_VERSION_1; + phdr->version = txp->args.protocol_version; phdr->dst_conn_id = txp->args.cur_dcid; phdr->src_conn_id = txp->args.cur_scid; diff --git a/test/quic_txp_test.c b/test/quic_txp_test.c index f234fb683ac..6c646f239b3 100644 --- a/test/quic_txp_test.c +++ b/test/quic_txp_test.c @@ -207,6 +207,7 @@ static int helper_init(struct helper *h) h->args.cc_method = h->cc_method; h->args.cc_data = h->cc_data; h->args.now = fake_now; + h->args.protocol_version = QUIC_VERSION_1; if (!TEST_ptr(h->txp = ossl_quic_tx_packetiser_new(&h->args))) goto err;