]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h1: split "show_fd" into connection and stream
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Sep 2022 14:11:28 +0000 (16:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Sep 2022 14:43:25 +0000 (16:43 +0200)
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.

src/mux_h1.c

index 36103e721e729835cf76fe44776fcbced4bde7b8..06c8e5b0c275f6e4675ad6c6296bdde99eba1e3c 100644 (file)
@@ -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 <h1c> to buffer <msg>, or does nothing if
+ * <h1c> is NULL. Returns non-zero if the connection is considered suspicious.
+ * May emit multiple lines, each new one being prefixed with <pfx>, if <pfx> 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 <h1s> to buffer <msg>, or does nothing if
+ * <h1s> is NULL. Returns non-zero if the stream is considered suspicious. May
+ * emit multiple lines, each new one being prefixed with <pfx>, if <pfx> 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)