From: Willy Tarreau Date: Fri, 9 Sep 2022 14:31:37 +0000 (+0200) Subject: MINOR: flags/http_ana: use flag dumping for txn flags X-Git-Tag: v2.7-dev6~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e2afad0af4924b9c79532e03587fcc9694be8e9e;p=thirdparty%2Fhaproxy.git MINOR: flags/http_ana: use flag dumping for txn flags The new function is txn_show_flags(). It dumps the TXN flags as well as the client and server cookie types. --- diff --git a/dev/flags/flags.c b/dev/flags/flags.c index c24bde889a..9c6a71bab0 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -90,55 +90,8 @@ void show_task_state(unsigned int f) void show_txn_flags(unsigned int f) { - printf("txn->flags = "); - - if (!f) { - printf("0\n"); - return; - } - - SHOW_FLAG(f, TX_L7_RETRY); - SHOW_FLAG(f, TX_D_L7_RETRY); - SHOW_FLAG(f, TX_NOT_FIRST); - SHOW_FLAG(f, TX_USE_PX_CONN); - SHOW_FLAG(f, TX_CACHE_HAS_SEC_KEY); - SHOW_FLAG(f, TX_CON_WANT_TUN); - - SHOW_FLAG(f, TX_CACHE_IGNORE); - SHOW_FLAG(f, TX_CACHE_COOK); - SHOW_FLAG(f, TX_CACHEABLE); - SHOW_FLAG(f, TX_SCK_PRESENT); - - //printf("%s", f ? "" : " | "); - switch (f & TX_SCK_MASK) { - case TX_SCK_NONE: f &= ~TX_SCK_MASK ; /*printf("TX_SCK_NONE%s", f ? " | " : "");*/ break; - case TX_SCK_FOUND: f &= ~TX_SCK_MASK ; printf("TX_SCK_FOUND%s", f ? " | " : ""); break; - case TX_SCK_DELETED: f &= ~TX_SCK_MASK ; printf("TX_SCK_DELETED%s", f ? " | " : ""); break; - case TX_SCK_INSERTED: f &= ~TX_SCK_MASK ; printf("TX_SCK_INSERTED%s", f ? " | " : ""); break; - case TX_SCK_REPLACED: f &= ~TX_SCK_MASK ; printf("TX_SCK_REPLACED%s", f ? " | " : ""); break; - case TX_SCK_UPDATED: f &= ~TX_SCK_MASK ; printf("TX_SCK_UPDATED%s", f ? " | " : ""); break; - default: printf("TX_SCK_MASK(%02x)", f); f &= ~TX_SCK_MASK ; printf("%s", f ? " | " : ""); break; - } - - //printf("%s", f ? "" : " | "); - switch (f & TX_CK_MASK) { - case TX_CK_NONE: f &= ~TX_CK_MASK ; /*printf("TX_CK_NONE%s", f ? " | " : "");*/ break; - case TX_CK_INVALID: f &= ~TX_CK_MASK ; printf("TX_CK_INVALID%s", f ? " | " : ""); break; - case TX_CK_DOWN: f &= ~TX_CK_MASK ; printf("TX_CK_DOWN%s", f ? " | " : ""); break; - case TX_CK_VALID: f &= ~TX_CK_MASK ; printf("TX_CK_VALID%s", f ? " | " : ""); break; - case TX_CK_EXPIRED: f &= ~TX_CK_MASK ; printf("TX_CK_EXPIRED%s", f ? " | " : ""); break; - case TX_CK_OLD: f &= ~TX_CK_MASK ; printf("TX_CK_OLD%s", f ? " | " : ""); break; - case TX_CK_UNUSED: f &= ~TX_CK_MASK ; printf("TX_CK_UNUSED%s", f ? " | " : ""); break; - default: printf("TX_CK_MASK(%02x)", f); f &= ~TX_CK_MASK ; printf("%s", f ? " | " : ""); break; - } - - SHOW_FLAG(f, TX_CLTARPIT); - SHOW_FLAG(f, TX_CONST_REPLY); - - if (f) { - printf("EXTRA(0x%08x)", f); - } - putchar('\n'); + txn_show_flags(tmpbuf, sizeof(tmpbuf), " | ", f); + printf("txn->flags = %s\n", tmpbuf); } void show_strm_flags(unsigned int f) diff --git a/include/haproxy/http_ana-t.h b/include/haproxy/http_ana-t.h index b267ebebda..735a2fbaa4 100644 --- a/include/haproxy/http_ana-t.h +++ b/include/haproxy/http_ana-t.h @@ -28,7 +28,9 @@ /* These are the flags that are found in txn->flags */ -/* action flags */ +/* action flags. + * Please also update the txn_show_flags() function below in case of changes. + */ /* Unusued: 0x00000001..0x00000004 */ #define TX_CONST_REPLY 0x00000008 /* The http reply must not be rewritten (don't eval after-response ruleset) */ #define TX_CLTARPIT 0x00000010 /* the transaction is tarpitted (anti-dos) */ @@ -73,6 +75,40 @@ #define TX_L7_RETRY 0x000800000 /* The transaction may attempt L7 retries */ #define TX_D_L7_RETRY 0x001000000 /* Disable L7 retries on this transaction, even if configured to do it */ + +/* 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 *txn_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 */ + _(TX_SCK_PRESENT, _(TX_CACHEABLE, _(TX_CACHE_COOK, _(TX_CACHE_IGNORE, + _(TX_CON_WANT_TUN, _(TX_CACHE_HAS_SEC_KEY, _(TX_USE_PX_CONN, + _(TX_NOT_FIRST, _(TX_L7_RETRY, _(TX_D_L7_RETRY)))))))))); + + _e(TX_SCK_MASK, TX_SCK_FOUND, _e(TX_SCK_MASK, TX_SCK_DELETED, + _e(TX_SCK_MASK, TX_SCK_INSERTED, _e(TX_SCK_MASK, TX_SCK_REPLACED, + _e(TX_SCK_MASK, TX_SCK_UPDATED))))); + + _e(TX_CK_MASK, TX_CK_INVALID, _e(TX_CK_MASK, TX_CK_DOWN, + _e(TX_CK_MASK, TX_CK_VALID, _e(TX_CK_MASK, TX_CK_EXPIRED, + _e(TX_CK_MASK, TX_CK_OLD, _e(TX_CK_MASK, TX_CK_UNUSED)))))); + + _(TX_CONST_REPLY, _(TX_CLTARPIT)); + /* epilogue */ + _(~0U); + return buf; +#undef _e +#undef _ +} + + /* * HTTP message status flags (msg->flags) */