blob: 3bcbb7f2872308adce0211258cb72c1aa48406d3 [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>
Christopher Fauletdb90f2a2022-03-22 16:06:25 +01006#include <haproxy/conn_stream-t.h>
Willy Tarreauc2b1ff02020-06-04 21:21:03 +02007#include <haproxy/http_ana-t.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +02008#include <haproxy/stream-t.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +02009#include <haproxy/task-t.h>
Willy Tarreau074d65b2015-12-20 23:21:57 +010010
Willy Tarreau354b6f52020-02-06 08:33:08 +010011// 1 bit per flag, no hole permitted here
12#define SHOW_AS_ANA 0x00000001
13#define SHOW_AS_CHN 0x00000002
14#define SHOW_AS_CONN 0x00000004
15#define SHOW_AS_CS 0x00000008
Christopher Faulet09b3c552022-04-04 11:28:27 +020016#define SHOW_AS_SET 0x00000010
17#define SHOW_AS_STRM 0x00000020
18#define SHOW_AS_TASK 0x00000040
19#define SHOW_AS_TXN 0x00000080
20#define SHOW_AS_ENDP 0x00000100
Willy Tarreau354b6f52020-02-06 08:33:08 +010021
22// command line names, must be in exact same order as the SHOW_AS_* flags above
23// so that show_as_words[i] matches flag 1U<<i.
Christopher Faulet09b3c552022-04-04 11:28:27 +020024const char *show_as_words[] = { "ana", "chn", "conn", "cs", "siet", "strm", "task", "txn", "endp", };
Willy Tarreau354b6f52020-02-06 08:33:08 +010025
Willy Tarreau074d65b2015-12-20 23:21:57 +010026#define SHOW_FLAG(f,n) \
27 do { \
28 if (!((f) & (n))) break; \
29 (f) &= ~(n); \
30 printf(#n"%s", (f) ? " | " : ""); \
31 } while (0)
32
Willy Tarreau354b6f52020-02-06 08:33:08 +010033unsigned int get_show_as(const char *word)
34{
35 int w = 0;
36
37 while (1) {
38 if (w == sizeof(show_as_words) / sizeof(*show_as_words))
39 return 0;
40 if (strcmp(word, show_as_words[w]) == 0)
41 return 1U << w;
42 w++;
43 }
44}
45
Willy Tarreau074d65b2015-12-20 23:21:57 +010046void show_chn_ana(unsigned int f)
47{
48 printf("chn->ana = ");
49
50 if (!f) {
51 printf("0\n");
52 return;
53 }
54
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010055 SHOW_FLAG(f, AN_REQ_FLT_START_FE);
Willy Tarreau074d65b2015-12-20 23:21:57 +010056 SHOW_FLAG(f, AN_REQ_INSPECT_FE);
57 SHOW_FLAG(f, AN_REQ_WAIT_HTTP);
58 SHOW_FLAG(f, AN_REQ_HTTP_BODY);
59 SHOW_FLAG(f, AN_REQ_HTTP_PROCESS_FE);
60 SHOW_FLAG(f, AN_REQ_SWITCHING_RULES);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010061 SHOW_FLAG(f, AN_REQ_FLT_START_BE);
Willy Tarreau074d65b2015-12-20 23:21:57 +010062 SHOW_FLAG(f, AN_REQ_INSPECT_BE);
63 SHOW_FLAG(f, AN_REQ_HTTP_PROCESS_BE);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010064 SHOW_FLAG(f, AN_REQ_HTTP_TARPIT);
Willy Tarreau074d65b2015-12-20 23:21:57 +010065 SHOW_FLAG(f, AN_REQ_SRV_RULES);
66 SHOW_FLAG(f, AN_REQ_HTTP_INNER);
Willy Tarreau074d65b2015-12-20 23:21:57 +010067 SHOW_FLAG(f, AN_REQ_PRST_RDP_COOKIE);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010068 SHOW_FLAG(f, AN_REQ_STICKING_RULES);
69 SHOW_FLAG(f, AN_REQ_FLT_HTTP_HDRS);
Willy Tarreau074d65b2015-12-20 23:21:57 +010070 SHOW_FLAG(f, AN_REQ_HTTP_XFER_BODY);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +010071 SHOW_FLAG(f, AN_REQ_WAIT_CLI);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010072 SHOW_FLAG(f, AN_REQ_FLT_XFER_DATA);
73 SHOW_FLAG(f, AN_REQ_FLT_END);
74
Willy Tarreau260bf5c2018-01-15 18:59:16 +010075 SHOW_FLAG(f, AN_RES_FLT_START_FE);
76 SHOW_FLAG(f, AN_RES_FLT_START_BE);
Willy Tarreau074d65b2015-12-20 23:21:57 +010077 SHOW_FLAG(f, AN_RES_INSPECT);
78 SHOW_FLAG(f, AN_RES_WAIT_HTTP);
Willy Tarreau074d65b2015-12-20 23:21:57 +010079 SHOW_FLAG(f, AN_RES_STORE_RULES);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010080 SHOW_FLAG(f, AN_RES_HTTP_PROCESS_FE);
81 SHOW_FLAG(f, AN_RES_HTTP_PROCESS_BE);
82 SHOW_FLAG(f, AN_RES_FLT_HTTP_HDRS);
Willy Tarreau074d65b2015-12-20 23:21:57 +010083 SHOW_FLAG(f, AN_RES_HTTP_XFER_BODY);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +010084 SHOW_FLAG(f, AN_RES_WAIT_CLI);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010085 SHOW_FLAG(f, AN_RES_FLT_XFER_DATA);
86 SHOW_FLAG(f, AN_RES_FLT_END);
Willy Tarreau074d65b2015-12-20 23:21:57 +010087
88 if (f) {
89 printf("EXTRA(0x%08x)", f);
90 }
91 putchar('\n');
92}
93
94void show_chn_flags(unsigned int f)
95{
96 printf("chn->flags = ");
97
98 if (!f) {
99 printf("0\n");
100 return;
101 }
102
103 SHOW_FLAG(f, CF_ISRESP);
Willy Tarreauf882a852019-03-25 18:34:28 +0100104 SHOW_FLAG(f, CF_EOI);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100105 SHOW_FLAG(f, CF_FLT_ANALYZE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100106 SHOW_FLAG(f, CF_WAKE_ONCE);
107 SHOW_FLAG(f, CF_NEVER_WAIT);
108 SHOW_FLAG(f, CF_SEND_DONTWAIT);
109 SHOW_FLAG(f, CF_EXPECT_MORE);
110 SHOW_FLAG(f, CF_DONT_READ);
111 SHOW_FLAG(f, CF_AUTO_CONNECT);
112 SHOW_FLAG(f, CF_READ_DONTWAIT);
113 SHOW_FLAG(f, CF_KERN_SPLICING);
114 SHOW_FLAG(f, CF_READ_ATTACHED);
115 SHOW_FLAG(f, CF_ANA_TIMEOUT);
116 SHOW_FLAG(f, CF_WROTE_DATA);
117 SHOW_FLAG(f, CF_STREAMER_FAST);
118 SHOW_FLAG(f, CF_STREAMER);
119 SHOW_FLAG(f, CF_AUTO_CLOSE);
120 SHOW_FLAG(f, CF_SHUTW_NOW);
121 SHOW_FLAG(f, CF_SHUTW);
122 SHOW_FLAG(f, CF_WAKE_WRITE);
123 SHOW_FLAG(f, CF_WRITE_ERROR);
124 SHOW_FLAG(f, CF_WRITE_TIMEOUT);
125 SHOW_FLAG(f, CF_WRITE_PARTIAL);
126 SHOW_FLAG(f, CF_WRITE_NULL);
127 SHOW_FLAG(f, CF_READ_NOEXP);
128 SHOW_FLAG(f, CF_SHUTR_NOW);
129 SHOW_FLAG(f, CF_SHUTR);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100130 SHOW_FLAG(f, CF_READ_ERROR);
131 SHOW_FLAG(f, CF_READ_TIMEOUT);
132 SHOW_FLAG(f, CF_READ_PARTIAL);
133 SHOW_FLAG(f, CF_READ_NULL);
134
135 if (f) {
136 printf("EXTRA(0x%08x)", f);
137 }
138 putchar('\n');
139}
140
141void show_conn_flags(unsigned int f)
142{
143 printf("conn->flags = ");
144 if (!f) {
145 printf("0\n");
146 return;
147 }
148
149 SHOW_FLAG(f, CO_FL_XPRT_TRACKED);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100150 SHOW_FLAG(f, CO_FL_SESS_IDLE);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100151 SHOW_FLAG(f, CO_FL_RCVD_PROXY);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100152 SHOW_FLAG(f, CO_FL_PRIVATE);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100153 SHOW_FLAG(f, CO_FL_SSL_WAIT_HS);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100154 SHOW_FLAG(f, CO_FL_ACCEPT_CIP);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100155 SHOW_FLAG(f, CO_FL_ACCEPT_PROXY);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100156 SHOW_FLAG(f, CO_FL_SEND_PROXY);
157 SHOW_FLAG(f, CO_FL_WAIT_L6_CONN);
158 SHOW_FLAG(f, CO_FL_WAIT_L4_CONN);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100159 SHOW_FLAG(f, CO_FL_ERROR);
160 SHOW_FLAG(f, CO_FL_SOCK_WR_SH);
161 SHOW_FLAG(f, CO_FL_SOCK_RD_SH);
Willy Tarreaudb207502019-06-03 14:26:54 +0200162 SHOW_FLAG(f, CO_FL_SOCKS4_RECV);
163 SHOW_FLAG(f, CO_FL_SOCKS4_SEND);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100164 SHOW_FLAG(f, CO_FL_EARLY_DATA);
165 SHOW_FLAG(f, CO_FL_EARLY_SSL_HS);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100166 SHOW_FLAG(f, CO_FL_WAIT_ROOM);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100167 SHOW_FLAG(f, CO_FL_WANT_DRAIN);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100168 SHOW_FLAG(f, CO_FL_XPRT_READY);
169 SHOW_FLAG(f, CO_FL_CTRL_READY);
Willy Tarreau54067e92020-06-19 08:47:30 +0200170 SHOW_FLAG(f, CO_FL_IDLE_LIST);
171 SHOW_FLAG(f, CO_FL_SAFE_LIST);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100172
173 if (f) {
174 printf("EXTRA(0x%08x)", f);
175 }
176 putchar('\n');
177}
Christopher Fauletdb90f2a2022-03-22 16:06:25 +0100178
179void show_endp_flags(unsigned int f)
180{
181 printf("endp->flags = ");
182 if (!f) {
183 printf("0\n");
184 return;
185 }
Christopher Fauleta0bdec32022-04-04 07:51:21 +0200186
187 SHOW_FLAG(f, CS_EP_RXBLK_CHAN);
188 SHOW_FLAG(f, CS_EP_RXBLK_BUFF);
189 SHOW_FLAG(f, CS_EP_RXBLK_ROOM);
190 SHOW_FLAG(f, CS_EP_RXBLK_SHUT);
191 SHOW_FLAG(f, CS_EP_RXBLK_CONN);
192 SHOW_FLAG(f, CS_EP_RX_WAIT_EP);
193 SHOW_FLAG(f, CS_EP_WANT_GET);
194 SHOW_FLAG(f, CS_EP_WAIT_DATA);
Christopher Faulete9e48202022-03-22 18:13:29 +0100195 SHOW_FLAG(f, CS_EP_KILL_CONN);
196 SHOW_FLAG(f, CS_EP_WAIT_FOR_HS);
Christopher Fauletb041b232022-03-24 10:27:02 +0100197 SHOW_FLAG(f, CS_EP_WANT_ROOM);
198 SHOW_FLAG(f, CS_EP_ERROR);
199 SHOW_FLAG(f, CS_EP_ERR_PENDING);
200 SHOW_FLAG(f, CS_EP_EOS);
201 SHOW_FLAG(f, CS_EP_EOI);
202 SHOW_FLAG(f, CS_EP_RCV_MORE);
Christopher Faulete9e48202022-03-22 18:13:29 +0100203 SHOW_FLAG(f, CS_EP_MAY_SPLICE);
204 SHOW_FLAG(f, CS_EP_WEBSOCKET);
205 SHOW_FLAG(f, CS_EP_NOT_FIRST);
206 SHOW_FLAG(f, CS_EP_SHWS);
207 SHOW_FLAG(f, CS_EP_SHWN);
208 SHOW_FLAG(f, CS_EP_SHRR);
209 SHOW_FLAG(f, CS_EP_SHRD);
Christopher Faulet9ec2f4d2022-03-23 15:15:29 +0100210 SHOW_FLAG(f, CS_EP_ORPHAN);
211 SHOW_FLAG(f, CS_EP_DETACHED);
Christopher Fauletdb90f2a2022-03-22 16:06:25 +0100212 SHOW_FLAG(f, CS_EP_T_APPLET);
213 SHOW_FLAG(f, CS_EP_T_MUX);
214
215 if (f) {
216 printf("EXTRA(0x%08x)", f);
217 }
218 putchar('\n');
219}
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100220void show_cs_flags(unsigned int f)
221{
222 printf("cs->flags = ");
223 if (!f) {
224 printf("0\n");
225 return;
226 }
Christopher Fauleta7285182022-03-30 15:43:23 +0200227 SHOW_FLAG(f, CS_FL_INDEP_STR);
Christopher Faulet974da9f2022-03-30 15:30:03 +0200228 SHOW_FLAG(f, CS_FL_DONT_WAKE);
Christopher Faulet8abe7122022-03-30 15:10:18 +0200229 SHOW_FLAG(f, CS_FL_NOLINGER);
230 SHOW_FLAG(f, CS_FL_NOHALF);
Christopher Faulet30995112022-03-25 15:32:38 +0100231 SHOW_FLAG(f, CS_FL_ISBACK);
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100232
233 if (f) {
234 printf("EXTRA(0x%08x)", f);
235 }
236 putchar('\n');
237}
Willy Tarreau074d65b2015-12-20 23:21:57 +0100238
Christopher Faulet50264b42022-03-30 19:39:30 +0200239void show_strm_et(unsigned int f)
Willy Tarreau074d65b2015-12-20 23:21:57 +0100240{
Christopher Faulet50264b42022-03-30 19:39:30 +0200241 printf("strm->et = ");
Willy Tarreau074d65b2015-12-20 23:21:57 +0100242 if (!f) {
Christopher Faulet50264b42022-03-30 19:39:30 +0200243 printf("STRM_ET_NONE\n");
Willy Tarreau074d65b2015-12-20 23:21:57 +0100244 return;
245 }
246
Christopher Faulet50264b42022-03-30 19:39:30 +0200247 SHOW_FLAG(f, STRM_ET_QUEUE_TO);
248 SHOW_FLAG(f, STRM_ET_QUEUE_ERR);
249 SHOW_FLAG(f, STRM_ET_QUEUE_ABRT);
250 SHOW_FLAG(f, STRM_ET_CONN_TO);
251 SHOW_FLAG(f, STRM_ET_CONN_ERR);
252 SHOW_FLAG(f, STRM_ET_CONN_ABRT);
253 SHOW_FLAG(f, STRM_ET_CONN_RES);
254 SHOW_FLAG(f, STRM_ET_CONN_OTHER);
255 SHOW_FLAG(f, STRM_ET_DATA_TO);
256 SHOW_FLAG(f, STRM_ET_DATA_ERR);
257 SHOW_FLAG(f, STRM_ET_DATA_ABRT);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100258
259 if (f) {
260 printf("EXTRA(0x%08x)", f);
261 }
262 putchar('\n');
263}
264
Willy Tarreau074d65b2015-12-20 23:21:57 +0100265void show_task_state(unsigned int f)
266{
267 printf("task->state = ");
268
269 if (!f) {
270 printf("TASK_SLEEPING\n");
271 return;
272 }
273
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100274 SHOW_FLAG(f, TASK_F_USR1);
275 SHOW_FLAG(f, TASK_F_TASKLET);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100276 SHOW_FLAG(f, TASK_WOKEN_OTHER);
277 SHOW_FLAG(f, TASK_WOKEN_RES);
278 SHOW_FLAG(f, TASK_WOKEN_MSG);
279 SHOW_FLAG(f, TASK_WOKEN_SIGNAL);
280 SHOW_FLAG(f, TASK_WOKEN_IO);
281 SHOW_FLAG(f, TASK_WOKEN_TIMER);
282 SHOW_FLAG(f, TASK_WOKEN_INIT);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100283 SHOW_FLAG(f, TASK_HEAVY);
284 SHOW_FLAG(f, TASK_IN_LIST);
285 SHOW_FLAG(f, TASK_KILLED);
286 SHOW_FLAG(f, TASK_SELF_WAKING);
287 SHOW_FLAG(f, TASK_SHARED_WQ);
288 SHOW_FLAG(f, TASK_QUEUED);
289 SHOW_FLAG(f, TASK_GLOBAL);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100290 SHOW_FLAG(f, TASK_RUNNING);
291
292 if (f) {
293 printf("EXTRA(0x%08x)", f);
294 }
295 putchar('\n');
296}
297
298void show_txn_flags(unsigned int f)
299{
300 printf("txn->flags = ");
301
302 if (!f) {
303 printf("0\n");
304 return;
305 }
306
Christopher Faulete05bf9e2022-03-29 15:23:40 +0200307 SHOW_FLAG(f, TX_L7_RETRY);
308 SHOW_FLAG(f, TX_D_L7_RETRY);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100309 SHOW_FLAG(f, TX_NOT_FIRST);
310 SHOW_FLAG(f, TX_USE_PX_CONN);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100311 SHOW_FLAG(f, TX_CACHE_HAS_SEC_KEY);
Christopher Fauletc41547b2019-07-16 14:32:23 +0200312 SHOW_FLAG(f, TX_CON_WANT_TUN);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100313
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100314 SHOW_FLAG(f, TX_CACHE_IGNORE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100315 SHOW_FLAG(f, TX_CACHE_COOK);
316 SHOW_FLAG(f, TX_CACHEABLE);
317 SHOW_FLAG(f, TX_SCK_PRESENT);
318
319 //printf("%s", f ? "" : " | ");
320 switch (f & TX_SCK_MASK) {
321 case TX_SCK_NONE: f &= ~TX_SCK_MASK ; /*printf("TX_SCK_NONE%s", f ? " | " : "");*/ break;
322 case TX_SCK_FOUND: f &= ~TX_SCK_MASK ; printf("TX_SCK_FOUND%s", f ? " | " : ""); break;
323 case TX_SCK_DELETED: f &= ~TX_SCK_MASK ; printf("TX_SCK_DELETED%s", f ? " | " : ""); break;
324 case TX_SCK_INSERTED: f &= ~TX_SCK_MASK ; printf("TX_SCK_INSERTED%s", f ? " | " : ""); break;
325 case TX_SCK_REPLACED: f &= ~TX_SCK_MASK ; printf("TX_SCK_REPLACED%s", f ? " | " : ""); break;
326 case TX_SCK_UPDATED: f &= ~TX_SCK_MASK ; printf("TX_SCK_UPDATED%s", f ? " | " : ""); break;
327 default: printf("TX_SCK_MASK(%02x)", f); f &= ~TX_SCK_MASK ; printf("%s", f ? " | " : ""); break;
328 }
329
330 //printf("%s", f ? "" : " | ");
331 switch (f & TX_CK_MASK) {
332 case TX_CK_NONE: f &= ~TX_CK_MASK ; /*printf("TX_CK_NONE%s", f ? " | " : "");*/ break;
333 case TX_CK_INVALID: f &= ~TX_CK_MASK ; printf("TX_CK_INVALID%s", f ? " | " : ""); break;
334 case TX_CK_DOWN: f &= ~TX_CK_MASK ; printf("TX_CK_DOWN%s", f ? " | " : ""); break;
335 case TX_CK_VALID: f &= ~TX_CK_MASK ; printf("TX_CK_VALID%s", f ? " | " : ""); break;
336 case TX_CK_EXPIRED: f &= ~TX_CK_MASK ; printf("TX_CK_EXPIRED%s", f ? " | " : ""); break;
337 case TX_CK_OLD: f &= ~TX_CK_MASK ; printf("TX_CK_OLD%s", f ? " | " : ""); break;
338 case TX_CK_UNUSED: f &= ~TX_CK_MASK ; printf("TX_CK_UNUSED%s", f ? " | " : ""); break;
339 default: printf("TX_CK_MASK(%02x)", f); f &= ~TX_CK_MASK ; printf("%s", f ? " | " : ""); break;
340 }
341
342 SHOW_FLAG(f, TX_CLTARPIT);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100343 SHOW_FLAG(f, TX_CONST_REPLY);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100344
345 if (f) {
346 printf("EXTRA(0x%08x)", f);
347 }
348 putchar('\n');
349}
350
351void show_strm_flags(unsigned int f)
352{
353 printf("strm->flags = ");
354
355 if (!f) {
356 printf("0\n");
357 return;
358 }
359
Christopher Fauletd1391382022-03-30 16:26:39 +0200360 SHOW_FLAG(f, SF_SRC_ADDR);
Christopher Fauletc2b7fa82022-01-18 10:46:10 +0100361 SHOW_FLAG(f, SF_WEBSOCKET);
362 SHOW_FLAG(f, SF_SRV_REUSED_ANTICIPATED);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100363 SHOW_FLAG(f, SF_SRV_REUSED);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100364 SHOW_FLAG(f, SF_IGNORE_PRST);
365
366 //printf("%s", f ? "" : " | ");
367 switch (f & SF_FINST_MASK) {
368 case SF_FINST_R: f &= ~SF_FINST_MASK ; printf("SF_FINST_R%s", f ? " | " : ""); break;
369 case SF_FINST_C: f &= ~SF_FINST_MASK ; printf("SF_FINST_C%s", f ? " | " : ""); break;
370 case SF_FINST_H: f &= ~SF_FINST_MASK ; printf("SF_FINST_H%s", f ? " | " : ""); break;
371 case SF_FINST_D: f &= ~SF_FINST_MASK ; printf("SF_FINST_D%s", f ? " | " : ""); break;
372 case SF_FINST_L: f &= ~SF_FINST_MASK ; printf("SF_FINST_L%s", f ? " | " : ""); break;
373 case SF_FINST_Q: f &= ~SF_FINST_MASK ; printf("SF_FINST_Q%s", f ? " | " : ""); break;
374 case SF_FINST_T: f &= ~SF_FINST_MASK ; printf("SF_FINST_T%s", f ? " | " : ""); break;
375 }
376
377 switch (f & SF_ERR_MASK) {
378 case SF_ERR_LOCAL: f &= ~SF_ERR_MASK ; printf("SF_ERR_LOCAL%s", f ? " | " : ""); break;
379 case SF_ERR_CLITO: f &= ~SF_ERR_MASK ; printf("SF_ERR_CLITO%s", f ? " | " : ""); break;
380 case SF_ERR_CLICL: f &= ~SF_ERR_MASK ; printf("SF_ERR_CLICL%s", f ? " | " : ""); break;
381 case SF_ERR_SRVTO: f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVTO%s", f ? " | " : ""); break;
382 case SF_ERR_SRVCL: f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVCL%s", f ? " | " : ""); break;
383 case SF_ERR_PRXCOND: f &= ~SF_ERR_MASK ; printf("SF_ERR_PRXCOND%s", f ? " | " : ""); break;
384 case SF_ERR_RESOURCE: f &= ~SF_ERR_MASK ; printf("SF_ERR_RESOURCE%s", f ? " | " : ""); break;
385 case SF_ERR_INTERNAL: f &= ~SF_ERR_MASK ; printf("SF_ERR_INTERNAL%s", f ? " | " : ""); break;
386 case SF_ERR_DOWN: f &= ~SF_ERR_MASK ; printf("SF_ERR_DOWN%s", f ? " | " : ""); break;
387 case SF_ERR_KILLED: f &= ~SF_ERR_MASK ; printf("SF_ERR_KILLED%s", f ? " | " : ""); break;
388 case SF_ERR_UP: f &= ~SF_ERR_MASK ; printf("SF_ERR_UP%s", f ? " | " : ""); break;
Willy Tarreaua7da4d22016-11-11 08:05:34 +0100389 case SF_ERR_CHK_PORT: f &= ~SF_ERR_MASK ; printf("SF_ERR_CHK_PORT%s", f ? " | " : ""); break;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100390 }
391
Willy Tarreau8a0eabd2020-02-06 07:57:36 +0100392 SHOW_FLAG(f, SF_HTX);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100393 SHOW_FLAG(f, SF_REDIRECTABLE);
Willy Tarreau8a0eabd2020-02-06 07:57:36 +0100394 SHOW_FLAG(f, SF_IGNORE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100395 SHOW_FLAG(f, SF_REDISP);
Christopher Fauletae024ce2022-03-29 19:02:31 +0200396 SHOW_FLAG(f, SF_CONN_EXP);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100397 SHOW_FLAG(f, SF_CURR_SESS);
398 SHOW_FLAG(f, SF_MONITOR);
399 SHOW_FLAG(f, SF_FORCE_PRST);
400 SHOW_FLAG(f, SF_BE_ASSIGNED);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100401 SHOW_FLAG(f, SF_ASSIGNED);
402 SHOW_FLAG(f, SF_DIRECT);
403
404 if (f) {
405 printf("EXTRA(0x%08x)", f);
406 }
407 putchar('\n');
408}
409
Willy Tarreau354b6f52020-02-06 08:33:08 +0100410void usage_exit(const char *name)
411{
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100412 fprintf(stderr, "Usage: %s [ana|chn|conn|cs|si|sierr|strm|task|txn]* { [+-][0x]value* | - }\n", name);
Willy Tarreau354b6f52020-02-06 08:33:08 +0100413 exit(1);
414}
415
Willy Tarreau074d65b2015-12-20 23:21:57 +0100416int main(int argc, char **argv)
417{
418 unsigned int flags;
Willy Tarreau354b6f52020-02-06 08:33:08 +0100419 unsigned int show_as = 0;
420 unsigned int f;
421 const char *name = argv[0];
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100422 char line[20];
423 char *value;
Willy Tarreaubde76f02020-02-06 08:48:16 +0100424 int multi = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100425 int use_stdin = 0;
Willy Tarreau354b6f52020-02-06 08:33:08 +0100426 char *err;
427
428 while (argc > 0) {
429 argv++; argc--;
430 if (argc < 1)
431 usage_exit(name);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100432
Willy Tarreau354b6f52020-02-06 08:33:08 +0100433 f = get_show_as(argv[0]);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100434 if (!f)
435 break;
Willy Tarreau354b6f52020-02-06 08:33:08 +0100436 show_as |= f;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100437 }
438
Willy Tarreau354b6f52020-02-06 08:33:08 +0100439 if (!show_as)
440 show_as = ~0U;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100441
Willy Tarreaubde76f02020-02-06 08:48:16 +0100442 if (argc > 1)
443 multi = 1;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100444
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100445 if (strcmp(argv[0], "-") == 0)
446 use_stdin = 1;
447
Willy Tarreaubde76f02020-02-06 08:48:16 +0100448 while (argc > 0) {
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100449 if (use_stdin) {
450 value = fgets(line, sizeof(line), stdin);
451 if (!value)
452 break;
453
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500454 /* skip common leading delimiters that slip from copy-paste */
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100455 while (*value == ' ' || *value == '\t' || *value == ':' || *value == '=')
456 value++;
457
458 /* stop at the end of the number and trim any C suffix like "UL" */
459 err = value;
460 while (*err == '-' || *err == '+' ||
Willy Tarreaub00c00e2021-04-02 17:47:21 +0200461 (isalnum((unsigned char)*err) && toupper((unsigned char)*err) != 'U' && toupper((unsigned char)*err) != 'L'))
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100462 err++;
Willy Tarreaucd430b92021-04-03 15:26:56 +0200463 *err = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100464 } else {
465 value = argv[0];
466 argv++; argc--;
467 }
468
469 flags = strtoul(value, &err, 0);
470 if (!*value || *err) {
471 fprintf(stderr, "Unparsable value: <%s>\n", value);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100472 usage_exit(name);
473 }
474
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100475 if (multi || use_stdin)
Willy Tarreaubde76f02020-02-06 08:48:16 +0100476 printf("### 0x%08x:\n", flags);
477
478 if (show_as & SHOW_AS_ANA) show_chn_ana(flags);
479 if (show_as & SHOW_AS_CHN) show_chn_flags(flags);
480 if (show_as & SHOW_AS_CONN) show_conn_flags(flags);
481 if (show_as & SHOW_AS_CS) show_cs_flags(flags);
Christopher Fauletdb90f2a2022-03-22 16:06:25 +0100482 if (show_as & SHOW_AS_ENDP) show_endp_flags(flags);
Christopher Faulet50264b42022-03-30 19:39:30 +0200483 if (show_as & SHOW_AS_SET) show_strm_et(flags);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100484 if (show_as & SHOW_AS_STRM) show_strm_flags(flags);
485 if (show_as & SHOW_AS_TASK) show_task_state(flags);
486 if (show_as & SHOW_AS_TXN) show_txn_flags(flags);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100487 }
Willy Tarreau074d65b2015-12-20 23:21:57 +0100488 return 0;
489}