From: Willy Tarreau Date: Thu, 1 Sep 2022 17:25:57 +0000 (+0200) Subject: MINOR: mux-h2: extract the connection dump function out of h2_show_fd() X-Git-Tag: v2.7-dev5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e97bcc76b729830ace2e7aa70ebc4085a338d79;p=thirdparty%2Fhaproxy.git MINOR: mux-h2: extract the connection dump function out of h2_show_fd() The function will be reusable to dump connections, so let's extract it. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index cf6a6ab8d2..4d2a5a9bc6 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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 to buffer , or does nothing if + * 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; }