]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: extract the code to send preface+settings into its own function
authorWilly Tarreau <w@1wt.eu>
Wed, 29 Oct 2025 16:28:57 +0000 (17:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Oct 2025 17:16:54 +0000 (18:16 +0100)
The code that deals with sending preface + settings and changing the
state currently is in h2_process_mux(), but we'll want to do it as
well from h2_snd_buf(), so let's move it to a dedicate function first.
At this point there is no functional change.

src/mux_h2.c

index f8b1ca661cbc1a0ba23c1ecd9a5f528aabdf7f41..03937dc336d05d596b4e4fdbaef7fe9aca1af926 100644 (file)
@@ -4643,6 +4643,23 @@ static inline void h2_remove_from_list(struct h2s *h2s)
        }
 }
 
+/* Sends the preface and the settings on a backend connection, and updates the
+ * connection's state to H2_CS_SETTINGS1. May only be called when the state is
+ * below H2_CS_SETTINGS1. It returns < 0 on error with the error set, otherwise
+ * >= 0.
+ */
+static int h2c_bck_send_preface_and_settings(struct h2c *h2c)
+{
+       if (unlikely(h2c_bck_send_preface(h2c) <= 0)) {
+               /* RFC7540#3.5: a GOAWAY frame MAY be omitted */
+               if (h2c->st0 == H2_CS_ERROR)
+                       h2c->st0 = H2_CS_ERROR2;
+               return -1;
+       }
+       h2c->st0 = H2_CS_SETTINGS1;
+       return 0;
+}
+
 /* process Tx frames from streams to be multiplexed. Returns > 0 if it reached
  * the end.
  */
@@ -4652,13 +4669,8 @@ static int h2_process_mux(struct h2c *h2c)
 
        if (unlikely(h2c->st0 < (h2c->flags & H2_CF_SETTINGS_NEEDED ? H2_CS_FRAME_H : H2_CS_SETTINGS1))) {
                if (unlikely(h2c->st0 == H2_CS_PREFACE && (h2c->flags & H2_CF_IS_BACK))) {
-                       if (unlikely(h2c_bck_send_preface(h2c) <= 0)) {
-                               /* RFC7540#3.5: a GOAWAY frame MAY be omitted */
-                               if (h2c->st0 == H2_CS_ERROR)
-                                       h2c->st0 = H2_CS_ERROR2;
+                       if (h2c_bck_send_preface_and_settings(h2c) < 0)
                                goto fail;
-                       }
-                       h2c->st0 = H2_CS_SETTINGS1;
                }
                /* need to wait for the other side */
                if (h2c->st0 < (h2c->flags & H2_CF_SETTINGS_NEEDED ? H2_CS_FRAME_H : H2_CS_SETTINGS1))