]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/stream: use flag dumping for stream flags
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:10:40 +0000 (16:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:52:09 +0000 (16:52 +0200)
The new function is strm_show_flags(). It dumps the stream flags
as well as the err type under SF_ERR_MASK and the final state under
SF_FINST_MASK.

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

index fbcbe692808ab092d1e5c5c82311127c65e16fc9..46936a385a33cd78e58c601b36e7857caed87e17 100644 (file)
@@ -168,61 +168,9 @@ void show_txn_flags(unsigned int f)
 
 void show_strm_flags(unsigned int f)
 {
-       printf("strm->flags = ");
-
-       if (!f) {
-               printf("0\n");
-               return;
-       }
-
-       SHOW_FLAG(f, SF_SRC_ADDR);
-       SHOW_FLAG(f, SF_WEBSOCKET);
-       SHOW_FLAG(f, SF_SRV_REUSED_ANTICIPATED);
-       SHOW_FLAG(f, SF_SRV_REUSED);
-       SHOW_FLAG(f, SF_IGNORE_PRST);
-
-       //printf("%s", f ? "" : " | ");
-       switch (f & SF_FINST_MASK) {
-       case SF_FINST_R: f &= ~SF_FINST_MASK ; printf("SF_FINST_R%s", f ? " | " : ""); break;
-       case SF_FINST_C: f &= ~SF_FINST_MASK ; printf("SF_FINST_C%s", f ? " | " : ""); break;
-       case SF_FINST_H: f &= ~SF_FINST_MASK ; printf("SF_FINST_H%s", f ? " | " : ""); break;
-       case SF_FINST_D: f &= ~SF_FINST_MASK ; printf("SF_FINST_D%s", f ? " | " : ""); break;
-       case SF_FINST_L: f &= ~SF_FINST_MASK ; printf("SF_FINST_L%s", f ? " | " : ""); break;
-       case SF_FINST_Q: f &= ~SF_FINST_MASK ; printf("SF_FINST_Q%s", f ? " | " : ""); break;
-       case SF_FINST_T: f &= ~SF_FINST_MASK ; printf("SF_FINST_T%s", f ? " | " : ""); break;
-       }
-
-       switch (f & SF_ERR_MASK) {
-       case SF_ERR_LOCAL:    f &= ~SF_ERR_MASK ; printf("SF_ERR_LOCAL%s",    f ? " | " : ""); break;
-       case SF_ERR_CLITO:    f &= ~SF_ERR_MASK ; printf("SF_ERR_CLITO%s",    f ? " | " : ""); break;
-       case SF_ERR_CLICL:    f &= ~SF_ERR_MASK ; printf("SF_ERR_CLICL%s",    f ? " | " : ""); break;
-       case SF_ERR_SRVTO:    f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVTO%s",    f ? " | " : ""); break;
-       case SF_ERR_SRVCL:    f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVCL%s",    f ? " | " : ""); break;
-       case SF_ERR_PRXCOND:  f &= ~SF_ERR_MASK ; printf("SF_ERR_PRXCOND%s",  f ? " | " : ""); break;
-       case SF_ERR_RESOURCE: f &= ~SF_ERR_MASK ; printf("SF_ERR_RESOURCE%s", f ? " | " : ""); break;
-       case SF_ERR_INTERNAL: f &= ~SF_ERR_MASK ; printf("SF_ERR_INTERNAL%s", f ? " | " : ""); break;
-       case SF_ERR_DOWN:     f &= ~SF_ERR_MASK ; printf("SF_ERR_DOWN%s",     f ? " | " : ""); break;
-       case SF_ERR_KILLED:   f &= ~SF_ERR_MASK ; printf("SF_ERR_KILLED%s",   f ? " | " : ""); break;
-       case SF_ERR_UP:       f &= ~SF_ERR_MASK ; printf("SF_ERR_UP%s",       f ? " | " : ""); break;
-       case SF_ERR_CHK_PORT: f &= ~SF_ERR_MASK ; printf("SF_ERR_CHK_PORT%s",       f ? " | " : ""); break;
-       }
-
-       SHOW_FLAG(f, SF_HTX);
-       SHOW_FLAG(f, SF_REDIRECTABLE);
-       SHOW_FLAG(f, SF_IGNORE);
-       SHOW_FLAG(f, SF_REDISP);
-       SHOW_FLAG(f, SF_CONN_EXP);
-       SHOW_FLAG(f, SF_CURR_SESS);
-       SHOW_FLAG(f, SF_MONITOR);
-       SHOW_FLAG(f, SF_FORCE_PRST);
-       SHOW_FLAG(f, SF_BE_ASSIGNED);
-       SHOW_FLAG(f, SF_ASSIGNED);
-       SHOW_FLAG(f, SF_DIRECT);
-
-       if (f) {
-               printf("EXTRA(0x%08x)", f);
-       }
-       putchar('\n');
+       strm_show_flags(tmpbuf, sizeof(tmpbuf), " | ", f);
+       printf("strm->flags = %s\n", tmpbuf);
+       return;
 }
 
 void usage_exit(const char *name)
index 2d5e540b34821d62442453db1a7776e18308da4c..0d4c691c889dc840543068feaa8758c11d154d89 100644 (file)
@@ -35,7 +35,9 @@
 #include <haproxy/vars-t.h>
 
 
-/* Various Stream Flags, bits values 0x01 to 0x100 (shift 0) */
+/* Various Stream Flags, bits values 0x01 to 0x100 (shift 0).
+ * Please also update the txn_show_flags() function below in case of changes.
+ */
 #define SF_DIRECT      0x00000001      /* connection made on the server matching the client cookie */
 #define SF_ASSIGNED    0x00000002      /* no need to assign a server to this stream */
 /* unused: 0x00000004 */
 #define SF_WEBSOCKET    0x00400000     /* websocket stream */ // TODO: must be removed
 #define SF_SRC_ADDR     0x00800000     /* get the source ip/port with getsockname */
 
+/* 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 and __APPEND_ENUM macros. The new end of the buffer is
+ * returned.
+ */
+static forceinline char *strm_show_flags(char *buf, size_t len, const char *delim, uint flg)
+{
+#define _(f, ...)     __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__)
+#define _e(m, e, ...) __APPEND_ENUM(buf, len, delim, flg, m, e, #e, __VA_ARGS__)
+       /* prologue */
+       _(0);
+       /* flags & enums */
+       _(SF_IGNORE_PRST, _(SF_SRV_REUSED, _(SF_SRV_REUSED_ANTICIPATED,
+       _(SF_WEBSOCKET, _(SF_SRC_ADDR)))));
+
+       _e(SF_FINST_MASK, SF_FINST_R,    _e(SF_FINST_MASK, SF_FINST_C,
+       _e(SF_FINST_MASK, SF_FINST_H,    _e(SF_FINST_MASK, SF_FINST_D,
+       _e(SF_FINST_MASK, SF_FINST_L,    _e(SF_FINST_MASK, SF_FINST_Q,
+       _e(SF_FINST_MASK, SF_FINST_T)))))));
+
+       _e(SF_ERR_MASK, SF_ERR_LOCAL,    _e(SF_ERR_MASK, SF_ERR_CLITO,
+       _e(SF_ERR_MASK, SF_ERR_CLICL,    _e(SF_ERR_MASK, SF_ERR_SRVTO,
+       _e(SF_ERR_MASK, SF_ERR_SRVCL,    _e(SF_ERR_MASK, SF_ERR_PRXCOND,
+       _e(SF_ERR_MASK, SF_ERR_RESOURCE, _e(SF_ERR_MASK, SF_ERR_INTERNAL,
+       _e(SF_ERR_MASK, SF_ERR_DOWN,     _e(SF_ERR_MASK, SF_ERR_KILLED,
+       _e(SF_ERR_MASK, SF_ERR_UP,       _e(SF_ERR_MASK, SF_ERR_CHK_PORT))))))))))));
+
+       _(SF_DIRECT, _(SF_ASSIGNED, _(SF_BE_ASSIGNED, _(SF_FORCE_PRST,
+       _(SF_MONITOR, _(SF_CURR_SESS, _(SF_CONN_EXP, _(SF_REDISP,
+       _(SF_IGNORE, _(SF_REDIRECTABLE, _(SF_HTX)))))))))));
+
+       /* epilogue */
+       _(~0U);
+       return buf;
+#undef _e
+#undef _
+}
+
+
 /* flags for the proxy of the master CLI */
 /* 0x0001.. to 0x8000 are reserved for ACCESS_* flags from cli-t.h */