]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC FC: Modify RXFC to support use for enforcing MAX_STREAMS
authorHugo Landau <hlandau@openssl.org>
Tue, 18 Apr 2023 18:30:55 +0000 (19:30 +0100)
committerHugo Landau <hlandau@openssl.org>
Fri, 12 May 2023 13:47:12 +0000 (14:47 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20765)

include/internal/quic_fc.h
ssl/quic/quic_fc.c

index b07326ddf426b5873570c0f91bc5a52405fb009d..78398c724275e1e3c47e7af00b0afe5d33bf9613 100644 (file)
@@ -137,7 +137,7 @@ struct quic_rxfc_st {
     OSSL_TIME       (*now)(void *arg);
     void            *now_arg;
     QUIC_RXFC       *parent;
-    unsigned char   error_code, has_cwm_changed, is_fin;
+    unsigned char   error_code, has_cwm_changed, is_fin, stream_count_mode;
 };
 
 /*
@@ -147,6 +147,9 @@ struct quic_rxfc_st {
  * and absolute maximum window sizes, respectively. Window size values are
  * expressed in bytes and determine how much credit the RXFC extends to the peer
  * to transmit more data at a time.
+ *
+ * If stream_count_mode is 1, this RXFC is for use tracking maximum stream count
+ * enforcement. In this case conn_rxfc must be NULL.
  */
 int ossl_quic_rxfc_init(QUIC_RXFC *rxfc, QUIC_RXFC *conn_rxfc,
                         uint64_t initial_window_size,
@@ -154,6 +157,14 @@ int ossl_quic_rxfc_init(QUIC_RXFC *rxfc, QUIC_RXFC *conn_rxfc,
                         OSSL_TIME (*now)(void *arg),
                         void *now_arg);
 
+/*
+ * Initialises an RX flow controller for stream count enforcement.
+ */
+int ossl_quic_rxfc_init_for_stream_count(QUIC_RXFC *rxfc,
+                                         uint64_t initial_window_size,
+                                         OSSL_TIME (*now)(void *arg),
+                                         void *now_arg);
+
 /*
  * Gets the parent (i.e., connection-level) RXFC. Returns NULL if called on a
  * connection-level RXFC.
index 40bdd9909f2f793ae2110b56adde84887e367c49..b016c021514b036787d4dde53ec0e1168b75784c 100644 (file)
@@ -146,6 +146,21 @@ int ossl_quic_rxfc_init(QUIC_RXFC *rxfc, QUIC_RXFC *conn_rxfc,
     rxfc->now               = now;
     rxfc->now_arg           = now_arg;
     rxfc->is_fin            = 0;
+    rxfc->stream_count_mode = 0;
+    return 1;
+}
+
+int ossl_quic_rxfc_init_for_stream_count(QUIC_RXFC *rxfc,
+                                         uint64_t initial_window_size,
+                                         OSSL_TIME (*now)(void *arg),
+                                         void *now_arg)
+{
+    if (!ossl_quic_rxfc_init(rxfc, NULL,
+                             initial_window_size, initial_window_size,
+                             now, now_arg))
+        return 0;
+
+    rxfc->stream_count_mode = 1;
     return 1;
 }
 
@@ -185,7 +200,7 @@ int ossl_quic_rxfc_on_rx_stream_frame(QUIC_RXFC *rxfc, uint64_t end, int is_fin)
 {
     uint64_t delta;
 
-    if (rxfc->parent == NULL)
+    if (!rxfc->stream_count_mode && rxfc->parent == NULL)
         return 0;
 
     if (rxfc->is_fin && ((is_fin && rxfc->hwm != end) || end > rxfc->hwm)) {
@@ -201,8 +216,9 @@ int ossl_quic_rxfc_on_rx_stream_frame(QUIC_RXFC *rxfc, uint64_t end, int is_fin)
         delta = end - rxfc->hwm;
         rxfc->hwm = end;
 
-        on_rx_controlled_bytes(rxfc, delta);           /* result ignored */
-        on_rx_controlled_bytes(rxfc->parent, delta);   /* result ignored */
+        on_rx_controlled_bytes(rxfc, delta);             /* result ignored */
+        if (rxfc->parent != NULL)
+            on_rx_controlled_bytes(rxfc->parent, delta); /* result ignored */
     } else if (end < rxfc->hwm && is_fin) {
         rxfc->error_code = QUIC_ERR_FINAL_SIZE_ERROR;
         return 1; /* not a caller error */