From c8db114afca12eea3500a844511552b068f2d821 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 12 Oct 2022 17:00:13 +0200 Subject: [PATCH] MINOR: flags/mux-fcgi: Decode FCGI connection and stream flags The new functions fconn_show_flags() and fstrm_show_flags() decode the flags state into a string, and are used by dev/flags: $ /dev/flags/flags fconn 0x3100 fconn->flags = FCGI_CF_GET_VALUES | FCGI_CF_KEEP_CONN | FCGI_CF_MPXS_CONNS ./dev/flags/flags fstrm 0x3300 fstrm->flags = FCGI_SF_WANT_SHUTW | FCGI_SF_WANT_SHUTR | FCGI_SF_OUTGOING_DATA | FCGI_SF_BEGIN_SENT --- dev/flags/flags.c | 7 +++++- include/haproxy/mux_fcgi-t.h | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/dev/flags/flags.c b/dev/flags/flags.c index c0cc067f4..7ec34f4e9 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -30,10 +31,12 @@ #define SHOW_AS_H2S 0x00004000 #define SHOW_AS_H1C 0x00008000 #define SHOW_AS_H1S 0x00010000 +#define SHOW_AS_FCONN 0x00020000 +#define SHOW_AS_FSTRM 0x00040000 // command line names, must be in exact same order as the SHOW_AS_* flags above // so that show_as_words[i] matches flag 1U<flags = %s\n", (h2s_show_flags (buf, bsz, " | ", flags), buf)); if (show_as & SHOW_AS_H1C) printf("h1c->flags = %s\n", (h1c_show_flags (buf, bsz, " | ", flags), buf)); if (show_as & SHOW_AS_H1S) printf("h1s->flags = %s\n", (h1s_show_flags (buf, bsz, " | ", flags), buf)); + if (show_as & SHOW_AS_FCONN) printf("fconn->flags = %s\n",(fconn_show_flags (buf, bsz, " | ", flags), buf)); + if (show_as & SHOW_AS_FSTRM) printf("fstrm->flags = %s\n",(fstrm_show_flags (buf, bsz, " | ", flags), buf)); } return 0; } diff --git a/include/haproxy/mux_fcgi-t.h b/include/haproxy/mux_fcgi-t.h index 75b26d299..a321f62f5 100644 --- a/include/haproxy/mux_fcgi-t.h +++ b/include/haproxy/mux_fcgi-t.h @@ -23,6 +23,7 @@ #define _HAPROXY_MUX_FCGI_T_H #include +#include /**** FCGI connection flags (32 bit), in fcgi_conn->flags ****/ #define FCGI_CF_NONE 0x00000000 @@ -53,6 +54,27 @@ #define FCGI_CF_KEEP_CONN 0x00001000 /* HAProxy is responsible to close the connection */ #define FCGI_CF_GET_VALUES 0x00002000 /* retrieve settings */ +/* 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 *fconn_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 */ + _(FCGI_CF_MUX_MALLOC, _(FCGI_CF_MUX_MFULL, + _(FCGI_CF_DEM_DALLOC, _(FCGI_CF_DEM_DFULL, _(FCGI_CF_DEM_MROOM, + _(FCGI_CF_DEM_SALLOC, _(FCGI_CF_DEM_SFULL, _(FCGI_CF_DEM_TOOMANY, + _(FCGI_CF_MPXS_CONNS, _(FCGI_CF_ABRTS_SENT, _(FCGI_CF_ABRTS_FAILED, + _(FCGI_CF_WAIT_FOR_HS, _(FCGI_CF_KEEP_CONN, _(FCGI_CF_GET_VALUES)))))))))))))); + /* epilogue */ + _(~0U); + return buf; +#undef _ +} + /**** FCGI stream flags (32 bit), in fcgi_strm->flags ****/ #define FCGI_SF_NONE 0x00000000 #define FCGI_SF_ES_RCVD 0x00000001 /* end-of-stream received (empty STDOUT or EDN_REQUEST record) */ @@ -72,6 +94,26 @@ #define FCGI_SF_WANT_SHUTR 0x00001000 /* a stream couldn't shutr() (mux full/busy) */ #define FCGI_SF_WANT_SHUTW 0x00002000 /* a stream couldn't shutw() (mux full/busy) */ +/* 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 *fstrm_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 */ + _(FCGI_SF_ES_RCVD, _(FCGI_SF_ES_SENT, _(FCGI_SF_EP_SENT, _(FCGI_SF_ABRT_SENT, + _(FCGI_SF_BLK_MBUSY, _(FCGI_SF_BLK_MROOM, + _(FCGI_SF_BEGIN_SENT, _(FCGI_SF_OUTGOING_DATA, _(FCGI_SF_NOTIFIED, + _(FCGI_SF_WANT_SHUTR, _(FCGI_SF_WANT_SHUTW))))))))))); + /* epilogue */ + _(~0U); + return buf; +#undef _ +} + /* FCGI connection state (fcgi_conn->state) */ enum fcgi_conn_st { FCGI_CS_INIT = 0, /* init done, waiting for sending GET_VALUES record */