]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/connection: use flag dumping for connection flags
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 13:04:32 +0000 (15:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:15:10 +0000 (16:15 +0200)
The new function is conn_show_flags(), it only deals with flags. Nothing
is planned for connection error types at the moment.

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

index fe72eab16b48194836daa47e1f54abfce80f287a..ede3510ed722b10ebe2da7efc3a34aa59bf3590c 100644 (file)
@@ -60,41 +60,8 @@ void show_chn_flags(unsigned int f)
 
 void show_conn_flags(unsigned int f)
 {
-       printf("conn->flags = ");
-       if (!f) {
-               printf("0\n");
-               return;
-       }
-
-       SHOW_FLAG(f, CO_FL_XPRT_TRACKED);
-       SHOW_FLAG(f, CO_FL_SESS_IDLE);
-       SHOW_FLAG(f, CO_FL_RCVD_PROXY);
-       SHOW_FLAG(f, CO_FL_PRIVATE);
-       SHOW_FLAG(f, CO_FL_SSL_WAIT_HS);
-       SHOW_FLAG(f, CO_FL_ACCEPT_CIP);
-       SHOW_FLAG(f, CO_FL_ACCEPT_PROXY);
-       SHOW_FLAG(f, CO_FL_SEND_PROXY);
-       SHOW_FLAG(f, CO_FL_WAIT_L6_CONN);
-       SHOW_FLAG(f, CO_FL_WAIT_L4_CONN);
-       SHOW_FLAG(f, CO_FL_FDLESS);
-       SHOW_FLAG(f, CO_FL_ERROR);
-       SHOW_FLAG(f, CO_FL_SOCK_WR_SH);
-       SHOW_FLAG(f, CO_FL_SOCK_RD_SH);
-       SHOW_FLAG(f, CO_FL_SOCKS4_RECV);
-       SHOW_FLAG(f, CO_FL_SOCKS4_SEND);
-       SHOW_FLAG(f, CO_FL_EARLY_DATA);
-       SHOW_FLAG(f, CO_FL_EARLY_SSL_HS);
-       SHOW_FLAG(f, CO_FL_WAIT_ROOM);
-       SHOW_FLAG(f, CO_FL_WANT_DRAIN);
-       SHOW_FLAG(f, CO_FL_XPRT_READY);
-       SHOW_FLAG(f, CO_FL_CTRL_READY);
-       SHOW_FLAG(f, CO_FL_IDLE_LIST);
-       SHOW_FLAG(f, CO_FL_SAFE_LIST);
-
-       if (f) {
-               printf("EXTRA(0x%08x)", f);
-       }
-       putchar('\n');
+       conn_show_flags(tmpbuf, sizeof(tmpbuf), " | ", f);
+       printf("conn->flags = %s\n", tmpbuf);
 }
 
 void show_sd_flags(unsigned int f)
index 4222d3bd306757e99545f1359a24e153e99ee54d..1de43356da2ed647e01a7ce2b56749f164f8ac5c 100644 (file)
@@ -36,6 +36,7 @@
 #include <haproxy/obj_type-t.h>
 #include <haproxy/port_range-t.h>
 #include <haproxy/protocol-t.h>
+#include <haproxy/show_flags-t.h>
 #include <haproxy/thread-t.h>
 
 /* referenced below */
@@ -73,7 +74,9 @@ enum sub_event_type {
  * conn_cond_update_polling().
  */
 
-/* flags for use in connection->flags */
+/* flags for use in connection->flags. Please also update the conn_show_flags()
+ * function below in case of changes.
+ */
 enum {
        CO_FL_NONE          = 0x00000000,  /* Just for initialization purposes */
 
@@ -157,6 +160,29 @@ enum {
        CO_FL_SOCKS4        = CO_FL_SOCKS4_SEND | CO_FL_SOCKS4_RECV,
 };
 
+/* 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 *conn_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 */
+       _(CO_FL_SAFE_LIST, _(CO_FL_IDLE_LIST, _(CO_FL_CTRL_READY, _(CO_FL_XPRT_READY,
+       _(CO_FL_WANT_DRAIN, _(CO_FL_WAIT_ROOM, _(CO_FL_EARLY_SSL_HS, _(CO_FL_EARLY_DATA,
+       _(CO_FL_SOCKS4_SEND, _(CO_FL_SOCKS4_RECV, _(CO_FL_SOCK_RD_SH, _(CO_FL_SOCK_WR_SH,
+       _(CO_FL_ERROR, _(CO_FL_FDLESS, _(CO_FL_WAIT_L4_CONN, _(CO_FL_WAIT_L6_CONN,
+       _(CO_FL_SEND_PROXY, _(CO_FL_ACCEPT_PROXY, _(CO_FL_ACCEPT_CIP, _(CO_FL_SSL_WAIT_HS,
+       _(CO_FL_PRIVATE, _(CO_FL_RCVD_PROXY, _(CO_FL_SESS_IDLE, _(CO_FL_XPRT_TRACKED
+       ))))))))))))))))))))))));
+       /* epilogue */
+       _(~0U);
+       return buf;
+#undef _
+}
+
 /* Possible connection error codes.
  * Warning: Do not reorder the codes, they are fetchable through the
  * "fc_err" sample fetch. If a new code is added, please add an error label