From e8b9f63235e82403b7e144ff9a1a3985d44f1c4e Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Tue, 18 Apr 2023 19:30:55 +0100 Subject: [PATCH] QUIC QSM: Clean up SEND_STREAM/RECV_STREAM handling Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20765) --- include/internal/quic_stream_map.h | 32 ++++++++++--------- ssl/quic/quic_channel.c | 6 ++-- ssl/quic/quic_stream_map.c | 50 ++++++++++++------------------ test/quic_txp_test.c | 6 ++-- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/include/internal/quic_stream_map.h b/include/internal/quic_stream_map.h index 2be73286ea..51e175ffb8 100644 --- a/include/internal/quic_stream_map.h +++ b/include/internal/quic_stream_map.h @@ -107,18 +107,6 @@ struct quic_stream_st { unsigned int deleted : 1; }; -/* - * Marks a stream for STOP_SENDING. aec is the application error code (AEC). - * This can only fail if it has already been called. - */ -int ossl_quic_stream_stop_sending(QUIC_STREAM *s, uint64_t aec); - -/* - * Marks a stream for reset. aec is the application error code (AEC). - * This can only fail if it has already been called. - */ -int ossl_quic_stream_reset(QUIC_STREAM *s, uint64_t aec); - /* * QUIC Stream Map * =============== @@ -239,10 +227,24 @@ void ossl_quic_stream_map_set_rr_stepping(QUIC_STREAM_MAP *qsm, size_t stepping) /* * Resets the sending part of a stream. + * + * Returns 1 if the sending part of a stream was not already reset. + * Returns 0 otherwise, which need not be considered an error. + */ +int ossl_quic_stream_map_reset_stream_send_part(QUIC_STREAM_MAP *qsm, + QUIC_STREAM *qs, + uint64_t aec); + +/* + * Marks the receiving part of a stream for STOP_SENDING. + * + * Returns 1 if the receiving part of a stream was not already marked for + * STOP_SENDING. + * Returns 0 otherwise, which need not be considered an error. */ -void ossl_quic_stream_map_reset_stream_send_part(QUIC_STREAM_MAP *qsm, - QUIC_STREAM *qs, - uint64_t aec); +int ossl_quic_stream_map_stop_sending_recv_part(QUIC_STREAM_MAP *qsm, + QUIC_STREAM *qs, + uint64_t aec); /* * Adds a stream to the accept queue. diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index da2436b3c6..ec0364ee68 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -2380,9 +2380,11 @@ void ossl_quic_channel_set_incoming_stream_auto_reject(QUIC_CHANNEL *ch, void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs) { - ossl_quic_stream_stop_sending(qs, ch->incoming_stream_auto_reject_aec); - ossl_quic_stream_reset(qs, ch->incoming_stream_auto_reject_aec); + ossl_quic_stream_map_stop_sending_recv_part(&ch->qsm, qs, + ch->incoming_stream_auto_reject_aec); + ossl_quic_stream_map_reset_stream_send_part(&ch->qsm, qs, + ch->incoming_stream_auto_reject_aec); qs->deleted = 1; ossl_quic_stream_map_update_state(&ch->qsm, qs); diff --git a/ssl/quic/quic_stream_map.c b/ssl/quic/quic_stream_map.c index 2f58b2a51a..cbc947398f 100644 --- a/ssl/quic/quic_stream_map.c +++ b/ssl/quic/quic_stream_map.c @@ -10,32 +10,6 @@ #include "internal/quic_stream_map.h" #include "internal/nelem.h" -/* QUIC Stream - * =========== - */ - -int ossl_quic_stream_stop_sending(QUIC_STREAM *s, uint64_t aec) -{ - if (s->stop_sending) - return 0; - - s->stop_sending_aec = aec; - s->stop_sending = 1; - s->want_stop_sending = 1; - return 1; -} - -int ossl_quic_stream_reset(QUIC_STREAM *s, uint64_t aec) -{ - if (s->reset_stream) - return 0; - - s->reset_stream_aec = aec; - s->reset_stream = 1; - s->want_reset_stream = 1; - return 1; -} - /* * QUIC Stream Map * =============== @@ -284,18 +258,34 @@ void ossl_quic_stream_map_update_state(QUIC_STREAM_MAP *qsm, QUIC_STREAM *s) stream_map_mark_inactive(qsm, s); } -void ossl_quic_stream_map_reset_stream_send_part(QUIC_STREAM_MAP *qsm, - QUIC_STREAM *qs, - uint64_t aec) +int ossl_quic_stream_map_reset_stream_send_part(QUIC_STREAM_MAP *qsm, + QUIC_STREAM *qs, + uint64_t aec) { if (qs->reset_stream) - return; + return 0; qs->reset_stream = 1; qs->reset_stream_aec = aec; qs->want_reset_stream = 1; ossl_quic_stream_map_update_state(qsm, qs); + return 1; +} + +int ossl_quic_stream_map_stop_sending_recv_part(QUIC_STREAM_MAP *qsm, + QUIC_STREAM *qs, + uint64_t aec) +{ + if (qs->stop_sending) + return 0; + + qs->stop_sending = 1; + qs->stop_sending_aec = aec; + qs->want_stop_sending = 1; + + ossl_quic_stream_map_update_state(qsm, qs); + return 1; } QUIC_STREAM *ossl_quic_stream_map_peek_accept_queue(QUIC_STREAM_MAP *qsm) diff --git a/test/quic_txp_test.c b/test/quic_txp_test.c index dca8c71398..1d71721a6c 100644 --- a/test/quic_txp_test.c +++ b/test/quic_txp_test.c @@ -1470,7 +1470,8 @@ static int run_script(const struct script_op *script) op->arg0))) goto err; - if (!TEST_true(ossl_quic_stream_stop_sending(s, op->arg1))) + if (!TEST_true(ossl_quic_stream_map_stop_sending_recv_part(h.args.qsm, + s, op->arg1))) goto err; ossl_quic_stream_map_update_state(h.args.qsm, s); @@ -1487,7 +1488,8 @@ static int run_script(const struct script_op *script) op->arg0))) goto err; - if (!TEST_true(ossl_quic_stream_reset(s, op->arg1))) + if (!TEST_true(ossl_quic_stream_map_reset_stream_send_part(h.args.qsm, + s, op->arg1))) goto err; ossl_quic_stream_map_update_state(h.args.qsm, s); -- 2.34.1