From d5aa3e19cc8722ff3f28d9a63ffe41366c3fec79 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 29 Oct 2025 17:28:57 +0100 Subject: [PATCH] MINOR: mux-h2: extract the code to send preface+settings into its own function 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 | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mux_h2.c b/src/mux_h2.c index f8b1ca661..03937dc33 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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)) -- 2.47.3