]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: extract the connection dump function out of h2_show_fd()
authorWilly Tarreau <w@1wt.eu>
Thu, 1 Sep 2022 17:25:57 +0000 (19:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Sep 2022 13:48:10 +0000 (15:48 +0200)
The function will be reusable to dump connections, so let's extract it.

src/mux_h2.c

index cf6a6ab8d2dcd6f880e758414e9efad1b9f401ca..4d2a5a9bc6e78f43e6e821275774fd524061cc68 100644 (file)
@@ -6773,17 +6773,18 @@ static int h2_dump_h2s_info(struct buffer *msg, const struct h2s *h2s)
        return ret;
 }
 
-/* for debugging with CLI's "show fd" command */
-static int h2_show_fd(struct buffer *msg, struct connection *conn)
+/* appends some info about connection <h2c> to buffer <msg>, or does nothing if
+ * <h2c> is NULL. Returns non-zero if the connection is considered suspicious.
+ */
+static int h2_dump_h2c_info(struct buffer *msg, struct h2c *h2c)
 {
-       struct h2c *h2c = conn->ctx;
-       struct h2s *h2s = NULL;
+       const struct buffer *hmbuf, *tmbuf;
+       const struct h2s *h2s = NULL;
        struct eb32_node *node;
        int fctl_cnt = 0;
        int send_cnt = 0;
        int tree_cnt = 0;
        int orph_cnt = 0;
-       struct buffer *hmbuf, *tmbuf;
        int ret = 0;
 
        if (!h2c)
@@ -6795,7 +6796,6 @@ static int h2_show_fd(struct buffer *msg, struct connection *conn)
        list_for_each_entry(h2s, &h2c->send_list, list)
                send_cnt++;
 
-       h2s = NULL;
        node = eb32_first(&h2c->streams_by_id);
        while (node) {
                h2s = container_of(node, struct h2s, by_id);
@@ -6823,10 +6823,29 @@ static int h2_show_fd(struct buffer *msg, struct connection *conn)
                      (unsigned int)b_data(tmbuf), b_orig(tmbuf),
                      (unsigned int)b_head_ofs(tmbuf), (unsigned int)b_size(tmbuf));
 
-       if (h2s) {
+       return ret;
+}
+
+/* for debugging with CLI's "show fd" command */
+static int h2_show_fd(struct buffer *msg, struct connection *conn)
+{
+       struct h2c *h2c = conn->ctx;
+       const struct h2s *h2s;
+       struct eb32_node *node;
+       int ret = 0;
+
+       if (!h2c)
+               return ret;
+
+       ret |= h2_dump_h2c_info(msg, h2c);
+
+       node = eb32_last(&h2c->streams_by_id);
+       if (node) {
+               h2s = container_of(node, struct h2s, by_id);
                chunk_appendf(msg, " last_h2s=%p", h2s);
                ret |= h2_dump_h2s_info(msg, h2s);
        }
+
        return ret;
 }