From: Hugo Landau Date: Wed, 26 Jul 2023 17:10:16 +0000 (+0100) Subject: QUIC TEST: Ensure PING causes ACK generation X-Git-Tag: openssl-3.2.0-alpha1~255 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17340e87855fb785a986f09208af4279f74a201f;p=thirdparty%2Fopenssl.git QUIC TEST: Ensure PING causes ACK generation Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21565) --- diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h index f9f2e30e233..0a033fa67ea 100644 --- a/include/internal/quic_channel.h +++ b/include/internal/quic_channel.h @@ -384,6 +384,12 @@ int ossl_quic_channel_ping(QUIC_CHANNEL *ch); /* For testing use. While enabled, ticking is not performed. */ void ossl_quic_channel_set_inhibit_tick(QUIC_CHANNEL *ch, int inhibit); +/* + * These queries exist for diagnostic purposes only. They may roll over. + * Do not rely on them for non-testing purposes. + */ +uint16_t ossl_quic_channel_get_diag_num_rx_ack(QUIC_CHANNEL *ch); + # endif #endif diff --git a/include/internal/quic_tserver.h b/include/internal/quic_tserver.h index 3cbbc279a60..9520deb0c17 100644 --- a/include/internal/quic_tserver.h +++ b/include/internal/quic_tserver.h @@ -195,6 +195,12 @@ void ossl_quic_tserver_set_msg_callback(QUIC_TSERVER *srv, SSL *ssl, void *arg), void *arg); +/* + * This is similar to ossl_quic_conn_get_channel; it should be used for test + * instrumentation only and not to bypass QUIC_TSERVER for 'normal' operations. + */ +QUIC_CHANNEL *ossl_quic_tserver_get_channel(QUIC_TSERVER *srv); + # endif #endif diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index af3a1d051a5..52ec3d749e1 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -3332,3 +3332,8 @@ void ossl_quic_channel_set_inhibit_tick(QUIC_CHANNEL *ch, int inhibit) { ch->inhibit_tick = (inhibit != 0); } + +uint16_t ossl_quic_channel_get_diag_num_rx_ack(QUIC_CHANNEL *ch) +{ + return ch->diag_num_rx_ack; +} diff --git a/ssl/quic/quic_channel_local.h b/ssl/quic/quic_channel_local.h index ba129d9db3b..dd86f390be5 100644 --- a/ssl/quic/quic_channel_local.h +++ b/ssl/quic/quic_channel_local.h @@ -202,7 +202,10 @@ struct quic_channel_st { */ uint64_t txku_threshold_override; - /* Valid if we are in the TERMINATING or TERMINATED states. */ + /* Diagnostic counters for testing purposes only. May roll over. */ + uint16_t diag_num_rx_ack; /* Number of ACK frames received */ + + /* Valid if we are in the TERMINATING or TERMINATED states. */ QUIC_TERMINATE_CAUSE terminate_cause; /* diff --git a/ssl/quic/quic_rx_depack.c b/ssl/quic/quic_rx_depack.c index a20aac61bfb..1b2b81e7f82 100644 --- a/ssl/quic/quic_rx_depack.c +++ b/ssl/quic/quic_rx_depack.c @@ -117,6 +117,7 @@ static int depack_do_frame_ack(PACKET *pkt, QUIC_CHANNEL *ch, packet_space, received)) goto malformed; + ++ch->diag_num_rx_ack; OPENSSL_free(ack_ranges); return 1; diff --git a/ssl/quic/quic_tserver.c b/ssl/quic/quic_tserver.c index 9bd32146c30..15444ecc5bc 100644 --- a/ssl/quic/quic_tserver.c +++ b/ssl/quic/quic_tserver.c @@ -512,6 +512,11 @@ int ossl_quic_tserver_ping(QUIC_TSERVER *srv) return 1; } +QUIC_CHANNEL *ossl_quic_tserver_get_channel(QUIC_TSERVER *srv) +{ + return srv->ch; +} + void ossl_quic_tserver_set_msg_callback(QUIC_TSERVER *srv, void (*f)(int write_p, int version, int content_type, diff --git a/test/quic_multistream_test.c b/test/quic_multistream_test.c index 84acfe0ceea..7fb0de1817f 100644 --- a/test/quic_multistream_test.c +++ b/test/quic_multistream_test.c @@ -3157,6 +3157,55 @@ static const struct script_op script_44[] = { OP_END }; +/* 45. PING must generate ACK */ +static int force_ping(struct helper *h, const struct script_op *op) +{ + QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(h->s); + + h->scratch0 = ossl_quic_channel_get_diag_num_rx_ack(ch); + + if (!TEST_true(ossl_quic_tserver_ping(h->s))) + return 0; + + return 1; +} + +static int wait_incoming_acks_increased(struct helper *h, const struct script_op *op) +{ + QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(h->s); + uint16_t count; + + count = ossl_quic_channel_get_diag_num_rx_ack(ch); + + if (count == h->scratch0) { + h->check_spin_again = 1; + return 0; + } + + return 1; +} + +static const struct script_op script_45[] = { + OP_C_SET_ALPN ("ossltest") + OP_C_CONNECT_WAIT () + + OP_C_WRITE (DEFAULT, "apple", 5) + OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) + OP_S_READ_EXPECT (a, "apple", 5) + + OP_BEGIN_REPEAT (2) + + OP_CHECK (force_ping, 0) + OP_CHECK (wait_incoming_acks_increased, 0) + + OP_END_REPEAT () + + OP_S_WRITE (a, "Strawberry", 10) + OP_C_READ_EXPECT (DEFAULT, "Strawberry", 10) + + OP_END +}; + static const struct script_op *const scripts[] = { script_1, script_2, @@ -3202,6 +3251,7 @@ static const struct script_op *const scripts[] = { script_42, script_43, script_44, + script_45, }; static int test_script(int idx)