]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/channel: use flag dumping for channel flags and analysers
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 12:51:57 +0000 (14:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:15:10 +0000 (16:15 +0200)
The two new functions are chn_show_analysers() and chn_show_flags().
They work on an existing buffer so one was declared in flags.c for this
purpose. File flags.c does not have to know about channel flags anymore.

dev/flags/flags.c
include/haproxy/channel-t.h

index de7127d3f178a8212229b741ecfe5318825c9a4a..fe72eab16b48194836daa47e1f54abfce80f287a 100644 (file)
@@ -30,6 +30,9 @@ const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "tas
                printf(#n"%s", (f) ? " | " : "");       \
        } while (0)
 
+/* will be sufficient for even largest flag names */
+static char tmpbuf[4096];
+
 unsigned int get_show_as(const char *word)
 {
        int w = 0;
@@ -45,97 +48,14 @@ unsigned int get_show_as(const char *word)
 
 void show_chn_ana(unsigned int f)
 {
-       printf("chn->ana    = ");
-
-       if (!f) {
-               printf("0\n");
-               return;
-       }
-
-       SHOW_FLAG(f, AN_REQ_FLT_START_FE);
-       SHOW_FLAG(f, AN_REQ_INSPECT_FE);
-       SHOW_FLAG(f, AN_REQ_WAIT_HTTP);
-       SHOW_FLAG(f, AN_REQ_HTTP_BODY);
-       SHOW_FLAG(f, AN_REQ_HTTP_PROCESS_FE);
-       SHOW_FLAG(f, AN_REQ_SWITCHING_RULES);
-       SHOW_FLAG(f, AN_REQ_FLT_START_BE);
-       SHOW_FLAG(f, AN_REQ_INSPECT_BE);
-       SHOW_FLAG(f, AN_REQ_HTTP_PROCESS_BE);
-       SHOW_FLAG(f, AN_REQ_HTTP_TARPIT);
-       SHOW_FLAG(f, AN_REQ_SRV_RULES);
-       SHOW_FLAG(f, AN_REQ_HTTP_INNER);
-       SHOW_FLAG(f, AN_REQ_PRST_RDP_COOKIE);
-       SHOW_FLAG(f, AN_REQ_STICKING_RULES);
-       SHOW_FLAG(f, AN_REQ_FLT_HTTP_HDRS);
-       SHOW_FLAG(f, AN_REQ_HTTP_XFER_BODY);
-       SHOW_FLAG(f, AN_REQ_WAIT_CLI);
-       SHOW_FLAG(f, AN_REQ_FLT_XFER_DATA);
-       SHOW_FLAG(f, AN_REQ_FLT_END);
-
-       SHOW_FLAG(f, AN_RES_FLT_START_FE);
-       SHOW_FLAG(f, AN_RES_FLT_START_BE);
-       SHOW_FLAG(f, AN_RES_INSPECT);
-       SHOW_FLAG(f, AN_RES_WAIT_HTTP);
-       SHOW_FLAG(f, AN_RES_STORE_RULES);
-       SHOW_FLAG(f, AN_RES_HTTP_PROCESS_FE);
-       SHOW_FLAG(f, AN_RES_HTTP_PROCESS_BE);
-       SHOW_FLAG(f, AN_RES_FLT_HTTP_HDRS);
-       SHOW_FLAG(f, AN_RES_HTTP_XFER_BODY);
-       SHOW_FLAG(f, AN_RES_WAIT_CLI);
-       SHOW_FLAG(f, AN_RES_FLT_XFER_DATA);
-       SHOW_FLAG(f, AN_RES_FLT_END);
-
-       if (f) {
-               printf("EXTRA(0x%08x)", f);
-       }
-       putchar('\n');
+       chn_show_analysers(tmpbuf, sizeof(tmpbuf), " | ", f);
+       printf("chn->ana    = %s\n", tmpbuf);
 }
 
 void show_chn_flags(unsigned int f)
 {
-       printf("chn->flags  = ");
-
-       if (!f) {
-               printf("0\n");
-               return;
-       }
-
-       SHOW_FLAG(f, CF_ISRESP);
-       SHOW_FLAG(f, CF_EOI);
-       SHOW_FLAG(f, CF_FLT_ANALYZE);
-       SHOW_FLAG(f, CF_WAKE_ONCE);
-       SHOW_FLAG(f, CF_NEVER_WAIT);
-       SHOW_FLAG(f, CF_SEND_DONTWAIT);
-       SHOW_FLAG(f, CF_EXPECT_MORE);
-       SHOW_FLAG(f, CF_DONT_READ);
-       SHOW_FLAG(f, CF_AUTO_CONNECT);
-       SHOW_FLAG(f, CF_READ_DONTWAIT);
-       SHOW_FLAG(f, CF_KERN_SPLICING);
-       SHOW_FLAG(f, CF_READ_ATTACHED);
-       SHOW_FLAG(f, CF_ANA_TIMEOUT);
-       SHOW_FLAG(f, CF_WROTE_DATA);
-       SHOW_FLAG(f, CF_STREAMER_FAST);
-       SHOW_FLAG(f, CF_STREAMER);
-       SHOW_FLAG(f, CF_AUTO_CLOSE);
-       SHOW_FLAG(f, CF_SHUTW_NOW);
-       SHOW_FLAG(f, CF_SHUTW);
-       SHOW_FLAG(f, CF_WAKE_WRITE);
-       SHOW_FLAG(f, CF_WRITE_ERROR);
-       SHOW_FLAG(f, CF_WRITE_TIMEOUT);
-       SHOW_FLAG(f, CF_WRITE_PARTIAL);
-       SHOW_FLAG(f, CF_WRITE_NULL);
-       SHOW_FLAG(f, CF_READ_NOEXP);
-       SHOW_FLAG(f, CF_SHUTR_NOW);
-       SHOW_FLAG(f, CF_SHUTR);
-       SHOW_FLAG(f, CF_READ_ERROR);
-       SHOW_FLAG(f, CF_READ_TIMEOUT);
-       SHOW_FLAG(f, CF_READ_PARTIAL);
-       SHOW_FLAG(f, CF_READ_NULL);
-
-       if (f) {
-               printf("EXTRA(0x%08x)", f);
-       }
-       putchar('\n');
+       chn_show_flags(tmpbuf, sizeof(tmpbuf), " | ", f);
+       printf("chn->flags  = %s\n", tmpbuf);
 }
 
 void show_conn_flags(unsigned int f)
index 75c4c96e352d7feb23afe77e6a7271a9cad1e51a..5cfd54f6155e6a28b3f8edfc8a083d3bde6ed892 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/buf-t.h>
+#include <haproxy/show_flags-t.h>
 
 /* The CF_* macros designate Channel Flags, which may be ORed in the bit field
  * member 'flags' in struct channel. Here we have several types of flags :
@@ -49,6 +50,7 @@
  * bits have the same position in a byte (read being the lower byte and write
  * the second one). All flag names are relative to the channel. For instance,
  * 'write' indicates the direction from the channel to the stream connector.
+ * Please also update the chn_show_flags() function below in case of changes.
  */
 
 #define CF_READ_NULL      0x00000001  /* last read detected on producer side */
 /* Mask for static flags which cause analysers to be woken up when they change */
 #define CF_MASK_STATIC    (CF_SHUTR|CF_SHUTW|CF_SHUTR_NOW|CF_SHUTW_NOW)
 
+/* This function is used to report flags in debugging tools. Please reflect
+ * below any single-bit flag addition above in the same order via the
+ * __APPEND_FLAG macro. The new end of the buffer is returned.
+ */
+static forceinline char *chn_show_flags(char *buf, size_t len, const char *delim, uint flg)
+{
+#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__)
+       /* prologue */
+       _(0);
+       /* flags */
+       _(CF_READ_NULL, _(CF_READ_PARTIAL, _(CF_READ_TIMEOUT, _(CF_READ_ERROR,
+       _(CF_SHUTR, _(CF_SHUTR_NOW, _(CF_READ_NOEXP, _(CF_WRITE_NULL,
+       _(CF_WRITE_PARTIAL, _(CF_WRITE_TIMEOUT, _(CF_WRITE_ERROR,
+       _(CF_WAKE_WRITE, _(CF_SHUTW, _(CF_SHUTW_NOW, _(CF_AUTO_CLOSE,
+       _(CF_STREAMER, _(CF_STREAMER_FAST, _(CF_WROTE_DATA, _(CF_ANA_TIMEOUT,
+       _(CF_READ_ATTACHED, _(CF_KERN_SPLICING, _(CF_READ_DONTWAIT,
+       _(CF_AUTO_CONNECT, _(CF_DONT_READ, _(CF_EXPECT_MORE,
+       _(CF_SEND_DONTWAIT, _(CF_NEVER_WAIT, _(CF_WAKE_ONCE, _(CF_FLT_ANALYZE,
+       _(CF_EOI, _(CF_ISRESP)))))))))))))))))))))))))))))));
+       /* epilogue */
+       _(~0U);
+       return buf;
+#undef _
+}
 
 /* Analysers (channel->analysers).
  * Those bits indicate that there are some processing to do on the buffer
  * analysers could be compared to higher level processors.
  * The field is blanked by channel_init() and only by analysers themselves
  * afterwards.
+ * Please also update the chn_show_analysers() function below in case of changes.
  */
 /* AN_REQ_FLT_START_FE:         0x00000001 */
 #define AN_REQ_INSPECT_FE       0x00000002  /* inspect request contents in the frontend */
 #define AN_RES_FLT_XFER_DATA    0x10000000
 #define AN_RES_FLT_END          0x20000000
 
+/* This function is used to report flags in debugging tools. Please reflect
+ * below any single-bit flag addition above in the same order via the
+ * __APPEND_FLAG macro. The new end of the buffer is returned.
+ */
+static forceinline char *chn_show_analysers(char *buf, size_t len, const char *delim, uint flg)
+{
+#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__)
+       /* prologue */
+       _(0);
+       /* request flags */
+       _(AN_REQ_FLT_START_FE, _(AN_REQ_INSPECT_FE, _(AN_REQ_WAIT_HTTP,
+       _(AN_REQ_HTTP_BODY, _(AN_REQ_HTTP_PROCESS_FE, _(AN_REQ_SWITCHING_RULES,
+       _(AN_REQ_FLT_START_BE, _(AN_REQ_INSPECT_BE, _(AN_REQ_HTTP_PROCESS_BE,
+       _(AN_REQ_HTTP_TARPIT, _(AN_REQ_SRV_RULES, _(AN_REQ_HTTP_INNER,
+       _(AN_REQ_PRST_RDP_COOKIE, _(AN_REQ_STICKING_RULES,
+       _(AN_REQ_FLT_HTTP_HDRS, _(AN_REQ_HTTP_XFER_BODY, _(AN_REQ_WAIT_CLI,
+       _(AN_REQ_FLT_XFER_DATA, _(AN_REQ_FLT_END,
+       /* response flags */
+       _(AN_RES_FLT_START_FE, _(AN_RES_FLT_START_BE, _(AN_RES_INSPECT,
+       _(AN_RES_WAIT_HTTP, _(AN_RES_STORE_RULES, _(AN_RES_HTTP_PROCESS_FE,
+       _(AN_RES_HTTP_PROCESS_BE, _(AN_RES_FLT_HTTP_HDRS,
+       _(AN_RES_HTTP_XFER_BODY, _(AN_RES_WAIT_CLI, _(AN_RES_FLT_XFER_DATA,
+       _(AN_RES_FLT_END)))))))))))))))))))))))))))))));
+       /* epilogue */
+       _(~0U);
+       return buf;
+#undef _
+}
+
 /* Magic value to forward infinite size (TCP, ...), used with ->to_forward */
 #define CHN_INFINITE_FORWARD    MAX_RANGE(unsigned int)