blob: c0cc067f4c51a8d49e9fe545669492d3b2b0f893 [file] [log] [blame]
Willy Tarreau074d65b2015-12-20 23:21:57 +01001#include <stdio.h>
2#include <stdlib.h>
3
Willy Tarreauf1d32c42020-06-04 21:07:02 +02004#include <haproxy/channel-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +02005#include <haproxy/connection-t.h>
Willy Tarreau799e5412022-09-12 18:53:06 +02006#include <haproxy/fd-t.h>
Willy Tarreauc2b1ff02020-06-04 21:21:03 +02007#include <haproxy/http_ana-t.h>
Willy Tarreau53497792022-09-09 16:59:29 +02008#include <haproxy/htx-t.h>
Willy Tarreau439be582022-09-12 19:20:23 +02009#include <haproxy/mux_h2-t.h>
Christopher Faulet7c4b2ec2022-09-15 10:54:36 +020010#include <haproxy/mux_h1-t.h>
Willy Tarreau799e5412022-09-12 18:53:06 +020011#include <haproxy/stconn-t.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020012#include <haproxy/stream-t.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020013#include <haproxy/task-t.h>
Willy Tarreau074d65b2015-12-20 23:21:57 +010014
Willy Tarreau354b6f52020-02-06 08:33:08 +010015// 1 bit per flag, no hole permitted here
16#define SHOW_AS_ANA 0x00000001
17#define SHOW_AS_CHN 0x00000002
18#define SHOW_AS_CONN 0x00000004
Willy Tarreau79775fa2022-05-27 09:57:31 +020019#define SHOW_AS_SC 0x00000008
Christopher Faulet09b3c552022-04-04 11:28:27 +020020#define SHOW_AS_SET 0x00000010
21#define SHOW_AS_STRM 0x00000020
22#define SHOW_AS_TASK 0x00000040
23#define SHOW_AS_TXN 0x00000080
Willy Tarreau2bacf4e2022-05-27 16:29:30 +020024#define SHOW_AS_SD 0x00000100
Willy Tarreau53497792022-09-09 16:59:29 +020025#define SHOW_AS_HSL 0x00000200
26#define SHOW_AS_HTX 0x00000400
Willy Tarreau6edae6f2022-09-09 17:18:57 +020027#define SHOW_AS_HMSG 0x00000800
Willy Tarreau799e5412022-09-12 18:53:06 +020028#define SHOW_AS_FD 0x00001000
Willy Tarreau439be582022-09-12 19:20:23 +020029#define SHOW_AS_H2C 0x00002000
30#define SHOW_AS_H2S 0x00004000
Christopher Faulet7c4b2ec2022-09-15 10:54:36 +020031#define SHOW_AS_H1C 0x00008000
32#define SHOW_AS_H1S 0x00010000
Willy Tarreau354b6f52020-02-06 08:33:08 +010033
34// command line names, must be in exact same order as the SHOW_AS_* flags above
35// so that show_as_words[i] matches flag 1U<<i.
Christopher Faulet7c4b2ec2022-09-15 10:54:36 +020036const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", "h2c", "h2s", "h1c", "h1s", };
Willy Tarreau354b6f52020-02-06 08:33:08 +010037
Willy Tarreaucdc9ddc2022-09-09 14:51:57 +020038/* will be sufficient for even largest flag names */
Willy Tarreaucdefa802022-09-09 16:47:43 +020039static char buf[4096];
40static size_t bsz = sizeof(buf);
Willy Tarreaucdc9ddc2022-09-09 14:51:57 +020041
Willy Tarreau354b6f52020-02-06 08:33:08 +010042unsigned int get_show_as(const char *word)
43{
44 int w = 0;
45
46 while (1) {
47 if (w == sizeof(show_as_words) / sizeof(*show_as_words))
48 return 0;
49 if (strcmp(word, show_as_words[w]) == 0)
50 return 1U << w;
51 w++;
52 }
53}
54
Willy Tarreau354b6f52020-02-06 08:33:08 +010055void usage_exit(const char *name)
56{
Willy Tarreauc7ac1742022-09-09 14:16:49 +020057 int word, nbword;
58
59 fprintf(stderr, "Usage: %s [", name);
60
61 nbword = sizeof(show_as_words) / sizeof(*show_as_words);
62 for (word = 0; word < nbword; word++)
63 fprintf(stderr, "%s%s", word ? "|" : "", show_as_words[word]);
64 fprintf(stderr, "]* { [+-][0x]value* | - }\n");
Willy Tarreau354b6f52020-02-06 08:33:08 +010065 exit(1);
66}
67
Willy Tarreau074d65b2015-12-20 23:21:57 +010068int main(int argc, char **argv)
69{
70 unsigned int flags;
Willy Tarreau354b6f52020-02-06 08:33:08 +010071 unsigned int show_as = 0;
72 unsigned int f;
73 const char *name = argv[0];
Willy Tarreaue4f80a02020-02-06 18:17:50 +010074 char line[20];
75 char *value;
Willy Tarreaubde76f02020-02-06 08:48:16 +010076 int multi = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +010077 int use_stdin = 0;
Willy Tarreau354b6f52020-02-06 08:33:08 +010078 char *err;
79
80 while (argc > 0) {
81 argv++; argc--;
82 if (argc < 1)
83 usage_exit(name);
Willy Tarreau074d65b2015-12-20 23:21:57 +010084
Willy Tarreau354b6f52020-02-06 08:33:08 +010085 f = get_show_as(argv[0]);
Willy Tarreaubde76f02020-02-06 08:48:16 +010086 if (!f)
87 break;
Willy Tarreau354b6f52020-02-06 08:33:08 +010088 show_as |= f;
Willy Tarreau074d65b2015-12-20 23:21:57 +010089 }
90
Willy Tarreau354b6f52020-02-06 08:33:08 +010091 if (!show_as)
92 show_as = ~0U;
Willy Tarreau074d65b2015-12-20 23:21:57 +010093
Willy Tarreaubde76f02020-02-06 08:48:16 +010094 if (argc > 1)
95 multi = 1;
Willy Tarreau074d65b2015-12-20 23:21:57 +010096
Willy Tarreaue4f80a02020-02-06 18:17:50 +010097 if (strcmp(argv[0], "-") == 0)
98 use_stdin = 1;
99
Willy Tarreaubde76f02020-02-06 08:48:16 +0100100 while (argc > 0) {
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100101 if (use_stdin) {
102 value = fgets(line, sizeof(line), stdin);
103 if (!value)
104 break;
105
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500106 /* skip common leading delimiters that slip from copy-paste */
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100107 while (*value == ' ' || *value == '\t' || *value == ':' || *value == '=')
108 value++;
109
110 /* stop at the end of the number and trim any C suffix like "UL" */
111 err = value;
112 while (*err == '-' || *err == '+' ||
Willy Tarreaub00c00e2021-04-02 17:47:21 +0200113 (isalnum((unsigned char)*err) && toupper((unsigned char)*err) != 'U' && toupper((unsigned char)*err) != 'L'))
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100114 err++;
Willy Tarreaucd430b92021-04-03 15:26:56 +0200115 *err = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100116 } else {
117 value = argv[0];
118 argv++; argc--;
119 }
120
121 flags = strtoul(value, &err, 0);
122 if (!*value || *err) {
123 fprintf(stderr, "Unparsable value: <%s>\n", value);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100124 usage_exit(name);
125 }
126
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100127 if (multi || use_stdin)
Willy Tarreaubde76f02020-02-06 08:48:16 +0100128 printf("### 0x%08x:\n", flags);
129
Willy Tarreaucdefa802022-09-09 16:47:43 +0200130 if (show_as & SHOW_AS_ANA) printf("chn->ana = %s\n", (chn_show_analysers(buf, bsz, " | ", flags), buf));
131 if (show_as & SHOW_AS_CHN) printf("chn->flags = %s\n", (chn_show_flags (buf, bsz, " | ", flags), buf));
132 if (show_as & SHOW_AS_CONN) printf("conn->flags = %s\n", (conn_show_flags (buf, bsz, " | ", flags), buf));
133 if (show_as & SHOW_AS_SC) printf("sc->flags = %s\n", (sc_show_flags (buf, bsz, " | ", flags), buf));
134 if (show_as & SHOW_AS_SD) printf("sd->flags = %s\n", (se_show_flags (buf, bsz, " | ", flags), buf));
135 if (show_as & SHOW_AS_SET) printf("strm->et = %s\n", (strm_et_show_flags(buf, bsz, " | ", flags), buf));
136 if (show_as & SHOW_AS_STRM) printf("strm->flags = %s\n", (strm_show_flags (buf, bsz, " | ", flags), buf));
137 if (show_as & SHOW_AS_TASK) printf("task->state = %s\n", (task_show_state (buf, bsz, " | ", flags), buf));
138 if (show_as & SHOW_AS_TXN) printf("txn->flags = %s\n", (txn_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreau53497792022-09-09 16:59:29 +0200139 if (show_as & SHOW_AS_HSL) printf("sl->flags = %s\n", (hsl_show_flags (buf, bsz, " | ", flags), buf));
140 if (show_as & SHOW_AS_HTX) printf("htx->flags = %s\n", (htx_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreau6edae6f2022-09-09 17:18:57 +0200141 if (show_as & SHOW_AS_HMSG) printf("hmsg->flags = %s\n", (hmsg_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreau799e5412022-09-12 18:53:06 +0200142 if (show_as & SHOW_AS_FD) printf("fd->flags = %s\n", (fd_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreau439be582022-09-12 19:20:23 +0200143 if (show_as & SHOW_AS_H2C) printf("h2c->flags = %s\n", (h2c_show_flags (buf, bsz, " | ", flags), buf));
144 if (show_as & SHOW_AS_H2S) printf("h2s->flags = %s\n", (h2s_show_flags (buf, bsz, " | ", flags), buf));
Christopher Faulet7c4b2ec2022-09-15 10:54:36 +0200145 if (show_as & SHOW_AS_H1C) printf("h1c->flags = %s\n", (h1c_show_flags (buf, bsz, " | ", flags), buf));
146 if (show_as & SHOW_AS_H1S) printf("h1s->flags = %s\n", (h1s_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreaubde76f02020-02-06 08:48:16 +0100147 }
Willy Tarreau074d65b2015-12-20 23:21:57 +0100148 return 0;
149}