From: Hugo Landau Date: Wed, 9 Aug 2023 16:46:32 +0000 (+0100) Subject: QUIC CHANNEL: Introduce concept of (non-)addressed mode X-Git-Tag: openssl-3.2.0-alpha1~87 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=617b459ddfabe5c2fbfc28808126999d936218fe;p=thirdparty%2Fopenssl.git QUIC CHANNEL: Introduce concept of (non-)addressed mode Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21715) --- diff --git a/include/internal/quic_txp.h b/include/internal/quic_txp.h index 09d552ef043..b2dbb85f924 100644 --- a/include/internal/quic_txp.h +++ b/include/internal/quic_txp.h @@ -128,7 +128,10 @@ int ossl_quic_tx_packetiser_set_cur_dcid(OSSL_QUIC_TX_PACKETISER *txp, int ossl_quic_tx_packetiser_set_cur_scid(OSSL_QUIC_TX_PACKETISER *txp, const QUIC_CONN_ID *scid); -/* Change the destination L4 address the TXP uses to send datagrams. */ +/* + * Change the destination L4 address the TXP uses to send datagrams. Specify + * NULL (or AF_UNSPEC) to disable use of addressed mode. + */ int ossl_quic_tx_packetiser_set_peer(OSSL_QUIC_TX_PACKETISER *txp, const BIO_ADDR *peer); diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index 275d5f576be..efbe1c16604 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -584,13 +584,26 @@ int ossl_quic_channel_set_mutator(QUIC_CHANNEL *ch, int ossl_quic_channel_get_peer_addr(QUIC_CHANNEL *ch, BIO_ADDR *peer_addr) { + if (!ch->addressed_mode) + return 0; + *peer_addr = ch->cur_peer_addr; return 1; } int ossl_quic_channel_set_peer_addr(QUIC_CHANNEL *ch, const BIO_ADDR *peer_addr) { - ch->cur_peer_addr = *peer_addr; + if (ch->state != QUIC_CHANNEL_STATE_IDLE) + return 0; + + if (peer_addr == NULL || BIO_ADDR_family(peer_addr) == AF_UNSPEC) { + BIO_ADDR_clear(&ch->cur_peer_addr); + ch->addressed_mode = 0; + return 1; + } + + ch->cur_peer_addr = *peer_addr; + ch->addressed_mode = 1; return 1; } diff --git a/ssl/quic/quic_channel_local.h b/ssl/quic/quic_channel_local.h index a60a539f9bb..8b2edc647a0 100644 --- a/ssl/quic/quic_channel_local.h +++ b/ssl/quic/quic_channel_local.h @@ -456,6 +456,9 @@ struct quic_channel_st { /* Inhibit tick for testing purposes? */ unsigned int inhibit_tick : 1; + /* Are we using addressed mode? */ + unsigned int addressed_mode : 1; + /* Saved error stack in case permanent error was encountered */ ERR_STATE *err_state; }; diff --git a/ssl/quic/quic_txp.c b/ssl/quic/quic_txp.c index 51802ba7b61..97cba812e76 100644 --- a/ssl/quic/quic_txp.c +++ b/ssl/quic/quic_txp.c @@ -555,8 +555,8 @@ int ossl_quic_tx_packetiser_set_peer(OSSL_QUIC_TX_PACKETISER *txp, const BIO_ADDR *peer) { if (peer == NULL) { - ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_NULL_PARAMETER); - return 0; + BIO_ADDR_clear(&txp->args.peer); + return 1; } txp->args.peer = *peer;