From: Willy Tarreau Date: Fri, 2 Sep 2022 14:11:28 +0000 (+0200) Subject: MINOR: mux-h1: split "show_fd" into connection and stream X-Git-Tag: v2.7-dev5~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7079c0fbbd15481dc44f1002804427798aaa45be;p=thirdparty%2Fhaproxy.git MINOR: mux-h1: split "show_fd" into connection and stream We now have two functions, one for dumping connections and the other one for dumping the streams. This will permit to use it from show_sd. A few optional line breaks were inserted where relevant to keep lines homogenous when a prefix is passed. --- diff --git a/src/mux_h1.c b/src/mux_h1.c index 36103e721e..06c8e5b0c2 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -3901,53 +3901,92 @@ static int h1_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *outp } } -/* for debugging with CLI's "show fd" command */ -static int h1_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. + * May emit multiple lines, each new one being prefixed with , if is + * not NULL, otherwise a single line is used. + */ +static int h1_dump_h1c_info(struct buffer *msg, struct h1c *h1c, const char *pfx) { - struct h1c *h1c = conn->ctx; - struct h1s *h1s = h1c->h1s; int ret = 0; + if (!h1c) + return ret; + chunk_appendf(msg, " h1c.flg=0x%x .sub=%d .ibuf=%u@%p+%u/%u .obuf=%u@%p+%u/%u", h1c->flags, h1c->wait_event.events, (unsigned int)b_data(&h1c->ibuf), b_orig(&h1c->ibuf), (unsigned int)b_head_ofs(&h1c->ibuf), (unsigned int)b_size(&h1c->ibuf), - (unsigned int)b_data(&h1c->obuf), b_orig(&h1c->obuf), + (unsigned int)b_data(&h1c->obuf), b_orig(&h1c->obuf), (unsigned int)b_head_ofs(&h1c->obuf), (unsigned int)b_size(&h1c->obuf)); + return ret; +} - if (h1s) { - char *method; +/* appends some info about stream to buffer , or does nothing if + * is NULL. Returns non-zero if the stream is considered suspicious. May + * emit multiple lines, each new one being prefixed with , if is not + * NULL, otherwise a single line is used. + */ +static int h1_dump_h1s_info(struct buffer *msg, const struct h1s *h1s, const char *pfx) +{ + const char *method; + int ret = 0; - if (h1s->meth < HTTP_METH_OTHER) - method = http_known_methods[h1s->meth].ptr; - else - method = "UNKNOWN"; - chunk_appendf(msg, " h1s=%p h1s.flg=0x%x .sd.flg=0x%x .req.state=%s .res.state=%s" - " .meth=%s status=%d", - h1s, h1s->flags, se_fl_get(h1s->sd), - h1m_state_str(h1s->req.state), - h1m_state_str(h1s->res.state), method, h1s->status); - - chunk_appendf(msg, " .sd.flg=0x%08x", se_fl_get(h1s->sd)); - if (!se_fl_test(h1s->sd, SE_FL_ORPHAN)) - chunk_appendf(msg, " .sc.flg=0x%08x .sc.app=%p", - h1s_sc(h1s)->flags, h1s_sc(h1s)->app); - - chunk_appendf(msg, " .subs=%p", h1s->subs); - if (h1s->subs) { - chunk_appendf(msg, "(ev=%d tl=%p", h1s->subs->events, h1s->subs->tasklet); - chunk_appendf(msg, " tl.calls=%d tl.ctx=%p tl.fct=", - h1s->subs->tasklet->calls, - h1s->subs->tasklet->context); - if (h1s->subs->tasklet->calls >= 1000000) - ret = 1; - resolve_sym_name(msg, NULL, h1s->subs->tasklet->process); - chunk_appendf(msg, ")"); - } + if (!h1s) + return ret; + + if (h1s->meth < HTTP_METH_OTHER) + method = http_known_methods[h1s->meth].ptr; + else + method = "UNKNOWN"; + + chunk_appendf(msg, " h1s=%p h1s.flg=0x%x .sd.flg=0x%x .req.state=%s .res.state=%s", + h1s, h1s->flags, se_fl_get(h1s->sd), + h1m_state_str(h1s->req.state), h1m_state_str(h1s->res.state)); + + if (pfx) + chunk_appendf(msg, "\n%s", pfx); + + chunk_appendf(msg, " .meth=%s status=%d", + method, h1s->status); + + chunk_appendf(msg, " .sd.flg=0x%08x", se_fl_get(h1s->sd)); + if (!se_fl_test(h1s->sd, SE_FL_ORPHAN)) + chunk_appendf(msg, " .sc.flg=0x%08x .sc.app=%p", + h1s_sc(h1s)->flags, h1s_sc(h1s)->app); + + if (pfx && h1s->subs) + chunk_appendf(msg, "\n%s", pfx); + + chunk_appendf(msg, " .subs=%p", h1s->subs); + if (h1s->subs) { + chunk_appendf(msg, "(ev=%d tl=%p", h1s->subs->events, h1s->subs->tasklet); + chunk_appendf(msg, " tl.calls=%d tl.ctx=%p tl.fct=", + h1s->subs->tasklet->calls, + h1s->subs->tasklet->context); + if (h1s->subs->tasklet->calls >= 1000000) + ret = 1; + resolve_sym_name(msg, NULL, h1s->subs->tasklet->process); + chunk_appendf(msg, ")"); } return ret; } +/* for debugging with CLI's "show fd" command */ +static int h1_show_fd(struct buffer *msg, struct connection *conn) +{ + struct h1c *h1c = conn->ctx; + struct h1s *h1s = h1c->h1s; + int ret = 0; + + ret |= h1_dump_h1c_info(msg, h1c, NULL); + + if (h1s) + ret |= h1_dump_h1s_info(msg, h1s, NULL); + + return ret; +} + /* Add an entry in the headers map. Returns -1 on error and 0 on success. */ static int add_hdr_case_adjust(const char *from, const char *to, char **err)