From 9d9e1016894f77f056f140bb6ba11aef98ebe629 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 9 Sep 2022 15:04:32 +0200 Subject: [PATCH] MINOR: flags/connection: use flag dumping for connection flags 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 | 37 ++-------------------------------- include/haproxy/connection-t.h | 28 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/dev/flags/flags.c b/dev/flags/flags.c index fe72eab16..ede3510ed 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -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) diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h index 4222d3bd3..1de43356d 100644 --- a/include/haproxy/connection-t.h +++ b/include/haproxy/connection-t.h @@ -36,6 +36,7 @@ #include #include #include +#include #include /* 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