]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Allow packetizer to accept an arg to set protocol version
authorNeil Horman <nhorman@openssl.org>
Fri, 15 Nov 2024 18:55:05 +0000 (13:55 -0500)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:33 +0000 (11:27 -0500)
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 <tomas@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25968)

include/internal/quic_txp.h
ssl/quic/quic_channel.c
ssl/quic/quic_txp.c
test/quic_txp_test.c

index 607cefc0109c29f93de1d9fcf12cb980e2960ba6..f165134e17daea25e9592736cbe29e6f9b90902c 100644 (file)
@@ -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);
index 72155b079ed5e699d5490f2493c4c55e202d81d0..6d5504acb61e323eadae1f7d2e17e33b74faf2d4 100644 (file)
@@ -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);
index b764de2e486dbbb786bffd61c2d94791b9a19085..1456b8f7416fc7e7da70f73232052a2c2aa79c47 100644 (file)
@@ -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;
 
index f234fb683ac9199d4d3c449ae849a838d5357b62..6c646f239b33c1140484bfca1df355086df86a9e 100644 (file)
@@ -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;