QUIC APL: Add internal call to allow changing send buffer size
authorHugo Landau <hlandau@openssl.org>
Tue, 18 Jul 2023 15:12:44 +0000 (16:12 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 31 Jul 2023 13:03:25 +0000 (14:03 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21484)

include/internal/quic_ssl.h
ssl/quic/quic_impl.c

index 37a29419c86228faeb2de3ae87d419569d838d4e..6bddc8a67880ce65645b6a66d7b8fd970106681f 100644 (file)
@@ -99,6 +99,9 @@ uint64_t ossl_quic_set_options(SSL *s, uint64_t opts);
 uint64_t ossl_quic_clear_options(SSL *s, uint64_t opts);
 uint64_t ossl_quic_get_options(const SSL *s);
 
+/* Modifies write buffer size for a stream. */
+__owur int ossl_quic_set_write_buffer_size(SSL *s, size_t size);
+
 /*
  * Used to override ossl_time_now() for debug purposes. While this may be
  * overridden at any time, expect strange results if you change it after
index d9bdf74efe7a0d66a032d0b87be616aa54769cdb..2775a4b938ebd4fcc5c6128d5b1ee15a9a5a3b23 100644 (file)
@@ -2898,6 +2898,41 @@ int ossl_quic_get_stream_write_error_code(SSL *ssl, uint64_t *app_error_code)
     return quic_get_stream_error_code(ssl, /*is_write=*/1, app_error_code);
 }
 
+/*
+ * Write buffer size mutation
+ * --------------------------
+ */
+int ossl_quic_set_write_buffer_size(SSL *ssl, size_t size)
+{
+    int ret = 0;
+    QCTX ctx;
+
+    if (!expect_quic_with_stream_lock(ssl, /*remote_init=*/-1, &ctx))
+        return 0;
+
+    if (!ossl_quic_stream_has_send(ctx.xso->stream))
+        /* Called on a unidirectional receive-only stream - error. */
+        goto out;
+
+    if (!ossl_quic_stream_has_send_buffer(ctx.xso->stream)) {
+        /*
+         * If the stream has a send part but we have disposed of it because we
+         * no longer need it, this is a no-op.
+         */
+        ret = 1;
+        goto out;
+    }
+
+    if (!ossl_quic_sstream_set_buffer_size(ctx.xso->stream->sstream, size))
+        goto out;
+
+    ret = 1;
+
+out:
+    quic_unlock(ctx.qc);
+    return ret;
+}
+
 /*
  * SSL_get_conn_close_info
  * -----------------------