blob: 0a2fccf02233aef16f7e2aedfa70b2d4b08b3ed3 [file] [log] [blame]
Willy Tarreau074d65b2015-12-20 23:21:57 +01001#include <stdio.h>
2#include <stdlib.h>
3
4#include <types/channel.h>
5#include <types/connection.h>
6#include <types/proto_http.h>
7#include <types/stream.h>
8#include <types/stream_interface.h>
9#include <types/task.h>
10
Willy Tarreaucb5738c2020-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
16#define SHOW_AS_SI 0x00000010
17#define SHOW_AS_SIET 0x00000020
18#define SHOW_AS_STRM 0x00000040
19#define SHOW_AS_TASK 0x00000080
20#define SHOW_AS_TXN 0x00000100
21
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.
24const char *show_as_words[] = { "ana", "chn", "conn", "cs", "si", "siet", "strm", "task", "txn", };
25
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 Tarreaucb5738c2020-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 Fauletf4cfcf92017-11-10 14:10:35 +010071 SHOW_FLAG(f, AN_REQ_FLT_XFER_DATA);
72 SHOW_FLAG(f, AN_REQ_FLT_END);
73
Willy Tarreau260bf5c2018-01-15 18:59:16 +010074 SHOW_FLAG(f, AN_RES_FLT_START_FE);
75 SHOW_FLAG(f, AN_RES_FLT_START_BE);
Willy Tarreau074d65b2015-12-20 23:21:57 +010076 SHOW_FLAG(f, AN_RES_INSPECT);
77 SHOW_FLAG(f, AN_RES_WAIT_HTTP);
Willy Tarreau074d65b2015-12-20 23:21:57 +010078 SHOW_FLAG(f, AN_RES_STORE_RULES);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010079 SHOW_FLAG(f, AN_RES_HTTP_PROCESS_FE);
80 SHOW_FLAG(f, AN_RES_HTTP_PROCESS_BE);
81 SHOW_FLAG(f, AN_RES_FLT_HTTP_HDRS);
Willy Tarreau074d65b2015-12-20 23:21:57 +010082 SHOW_FLAG(f, AN_RES_HTTP_XFER_BODY);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +010083 SHOW_FLAG(f, AN_RES_FLT_XFER_DATA);
84 SHOW_FLAG(f, AN_RES_FLT_END);
Willy Tarreau074d65b2015-12-20 23:21:57 +010085
86 if (f) {
87 printf("EXTRA(0x%08x)", f);
88 }
89 putchar('\n');
90}
91
92void show_chn_flags(unsigned int f)
93{
94 printf("chn->flags = ");
95
96 if (!f) {
97 printf("0\n");
98 return;
99 }
100
101 SHOW_FLAG(f, CF_ISRESP);
Willy Tarreauf882a852019-03-25 18:34:28 +0100102 SHOW_FLAG(f, CF_EOI);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100103 SHOW_FLAG(f, CF_FLT_ANALYZE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100104 SHOW_FLAG(f, CF_WAKE_ONCE);
105 SHOW_FLAG(f, CF_NEVER_WAIT);
106 SHOW_FLAG(f, CF_SEND_DONTWAIT);
107 SHOW_FLAG(f, CF_EXPECT_MORE);
108 SHOW_FLAG(f, CF_DONT_READ);
109 SHOW_FLAG(f, CF_AUTO_CONNECT);
110 SHOW_FLAG(f, CF_READ_DONTWAIT);
111 SHOW_FLAG(f, CF_KERN_SPLICING);
112 SHOW_FLAG(f, CF_READ_ATTACHED);
113 SHOW_FLAG(f, CF_ANA_TIMEOUT);
114 SHOW_FLAG(f, CF_WROTE_DATA);
115 SHOW_FLAG(f, CF_STREAMER_FAST);
116 SHOW_FLAG(f, CF_STREAMER);
117 SHOW_FLAG(f, CF_AUTO_CLOSE);
118 SHOW_FLAG(f, CF_SHUTW_NOW);
119 SHOW_FLAG(f, CF_SHUTW);
120 SHOW_FLAG(f, CF_WAKE_WRITE);
121 SHOW_FLAG(f, CF_WRITE_ERROR);
122 SHOW_FLAG(f, CF_WRITE_TIMEOUT);
123 SHOW_FLAG(f, CF_WRITE_PARTIAL);
124 SHOW_FLAG(f, CF_WRITE_NULL);
125 SHOW_FLAG(f, CF_READ_NOEXP);
126 SHOW_FLAG(f, CF_SHUTR_NOW);
127 SHOW_FLAG(f, CF_SHUTR);
128 SHOW_FLAG(f, CF_WAKE_CONNECT);
129 SHOW_FLAG(f, CF_READ_ERROR);
130 SHOW_FLAG(f, CF_READ_TIMEOUT);
131 SHOW_FLAG(f, CF_READ_PARTIAL);
132 SHOW_FLAG(f, CF_READ_NULL);
133
134 if (f) {
135 printf("EXTRA(0x%08x)", f);
136 }
137 putchar('\n');
138}
139
140void show_conn_flags(unsigned int f)
141{
142 printf("conn->flags = ");
143 if (!f) {
144 printf("0\n");
145 return;
146 }
147
148 SHOW_FLAG(f, CO_FL_XPRT_TRACKED);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100149 SHOW_FLAG(f, CO_FL_RCVD_PROXY);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100150 SHOW_FLAG(f, CO_FL_PRIVATE);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100151 SHOW_FLAG(f, CO_FL_ACCEPT_CIP);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100152 SHOW_FLAG(f, CO_FL_ACCEPT_PROXY);
153 SHOW_FLAG(f, CO_FL_SSL_WAIT_HS);
154 SHOW_FLAG(f, CO_FL_SEND_PROXY);
155 SHOW_FLAG(f, CO_FL_WAIT_L6_CONN);
156 SHOW_FLAG(f, CO_FL_WAIT_L4_CONN);
157 SHOW_FLAG(f, CO_FL_CONNECTED);
158 SHOW_FLAG(f, CO_FL_ERROR);
159 SHOW_FLAG(f, CO_FL_SOCK_WR_SH);
160 SHOW_FLAG(f, CO_FL_SOCK_RD_SH);
Willy Tarreaudb207502019-06-03 14:26:54 +0200161 SHOW_FLAG(f, CO_FL_SOCKS4_RECV);
162 SHOW_FLAG(f, CO_FL_SOCKS4_SEND);
Christopher Fauletf4cfcf92017-11-10 14:10:35 +0100163 SHOW_FLAG(f, CO_FL_EARLY_DATA);
164 SHOW_FLAG(f, CO_FL_EARLY_SSL_HS);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100165 SHOW_FLAG(f, CO_FL_ADDR_TO_SET);
166 SHOW_FLAG(f, CO_FL_ADDR_FROM_SET);
167 SHOW_FLAG(f, CO_FL_WAIT_ROOM);
Christopher Fauletaff93282018-02-27 15:41:10 +0100168 SHOW_FLAG(f, CO_FL_WILL_UPDATE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100169 SHOW_FLAG(f, CO_FL_XPRT_READY);
170 SHOW_FLAG(f, CO_FL_CTRL_READY);
171 SHOW_FLAG(f, CO_FL_CURR_WR_ENA);
Olivier Houchard1a0545f2017-09-13 18:30:23 +0200172 SHOW_FLAG(f, CO_FL_XPRT_WR_ENA);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100173 SHOW_FLAG(f, CO_FL_CURR_RD_ENA);
Olivier Houchard1a0545f2017-09-13 18:30:23 +0200174 SHOW_FLAG(f, CO_FL_XPRT_RD_ENA);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100175
176 if (f) {
177 printf("EXTRA(0x%08x)", f);
178 }
179 putchar('\n');
180}
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100181void show_cs_flags(unsigned int f)
182{
183 printf("cs->flags = ");
184 if (!f) {
185 printf("0\n");
186 return;
187 }
Willy Tarreaudb207502019-06-03 14:26:54 +0200188 SHOW_FLAG(f, CS_FL_READ_PARTIAL);
Willy Tarreaud5016462018-11-16 10:37:20 +0100189 SHOW_FLAG(f, CS_FL_NOT_FIRST);
Willy Tarreaudb207502019-06-03 14:26:54 +0200190 SHOW_FLAG(f, CS_FL_KILL_CONN);
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100191 SHOW_FLAG(f, CS_FL_WAIT_FOR_HS);
Willy Tarreauf882a852019-03-25 18:34:28 +0100192 SHOW_FLAG(f, CS_FL_EOI);
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100193 SHOW_FLAG(f, CS_FL_EOS);
Willy Tarreau121c4e02018-12-17 21:58:03 +0100194 SHOW_FLAG(f, CS_FL_ERR_PENDING);
195 SHOW_FLAG(f, CS_FL_WANT_ROOM);
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100196 SHOW_FLAG(f, CS_FL_RCV_MORE);
197 SHOW_FLAG(f, CS_FL_ERROR);
198 SHOW_FLAG(f, CS_FL_SHWS);
199 SHOW_FLAG(f, CS_FL_SHWN);
200 SHOW_FLAG(f, CS_FL_SHRR);
201 SHOW_FLAG(f, CS_FL_SHRD);
Christopher Faulet5f8ef132018-03-01 08:55:21 +0100202
203 if (f) {
204 printf("EXTRA(0x%08x)", f);
205 }
206 putchar('\n');
207}
Willy Tarreau074d65b2015-12-20 23:21:57 +0100208
209void show_si_et(unsigned int f)
210{
211 printf("si->et = ");
212 if (!f) {
213 printf("SI_ET_NONE\n");
214 return;
215 }
216
217 SHOW_FLAG(f, SI_ET_QUEUE_TO);
218 SHOW_FLAG(f, SI_ET_QUEUE_ERR);
219 SHOW_FLAG(f, SI_ET_QUEUE_ABRT);
220 SHOW_FLAG(f, SI_ET_CONN_TO);
221 SHOW_FLAG(f, SI_ET_CONN_ERR);
222 SHOW_FLAG(f, SI_ET_CONN_ABRT);
223 SHOW_FLAG(f, SI_ET_CONN_RES);
224 SHOW_FLAG(f, SI_ET_CONN_OTHER);
225 SHOW_FLAG(f, SI_ET_DATA_TO);
226 SHOW_FLAG(f, SI_ET_DATA_ERR);
227 SHOW_FLAG(f, SI_ET_DATA_ABRT);
228
229 if (f) {
230 printf("EXTRA(0x%08x)", f);
231 }
232 putchar('\n');
233}
234
235void show_si_flags(unsigned int f)
236{
Willy Tarreau074d65b2015-12-20 23:21:57 +0100237 printf("si->flags = ");
238 if (!f) {
239 printf("SI_FL_NONE\n");
240 return;
241 }
242
243 SHOW_FLAG(f, SI_FL_EXP);
244 SHOW_FLAG(f, SI_FL_ERR);
Willy Tarreaud0f5bbc2018-11-14 11:10:26 +0100245 SHOW_FLAG(f, SI_FL_RXBLK_ROOM);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100246 SHOW_FLAG(f, SI_FL_WAIT_DATA);
247 SHOW_FLAG(f, SI_FL_ISBACK);
248 SHOW_FLAG(f, SI_FL_DONT_WAKE);
249 SHOW_FLAG(f, SI_FL_INDEP_STR);
250 SHOW_FLAG(f, SI_FL_NOLINGER);
251 SHOW_FLAG(f, SI_FL_NOHALF);
252 SHOW_FLAG(f, SI_FL_SRC_ADDR);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100253 SHOW_FLAG(f, SI_FL_WANT_GET);
Willy Tarreauf2ddd872018-12-18 09:54:22 +0100254 SHOW_FLAG(f, SI_FL_CLEAN_ABRT);
Willy Tarreau94f79072018-11-14 11:24:08 +0100255 SHOW_FLAG(f, SI_FL_RXBLK_CHAN);
256 SHOW_FLAG(f, SI_FL_RXBLK_BUFF);
257 SHOW_FLAG(f, SI_FL_RXBLK_ROOM);
258 SHOW_FLAG(f, SI_FL_RXBLK_SHUT);
259 SHOW_FLAG(f, SI_FL_RX_WAIT_EP);
260
Willy Tarreau074d65b2015-12-20 23:21:57 +0100261 if (f) {
Willy Tarreau94f79072018-11-14 11:24:08 +0100262 printf("EXTRA(0x%08x)", f);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100263 }
264 putchar('\n');
265}
266
267void show_task_state(unsigned int f)
268{
269 printf("task->state = ");
270
271 if (!f) {
272 printf("TASK_SLEEPING\n");
273 return;
274 }
275
276 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);
283 SHOW_FLAG(f, TASK_RUNNING);
284
285 if (f) {
286 printf("EXTRA(0x%08x)", f);
287 }
288 putchar('\n');
289}
290
291void show_txn_flags(unsigned int f)
292{
293 printf("txn->flags = ");
294
295 if (!f) {
296 printf("0\n");
297 return;
298 }
299
300 SHOW_FLAG(f, TX_NOT_FIRST);
301 SHOW_FLAG(f, TX_USE_PX_CONN);
302 SHOW_FLAG(f, TX_HDR_CONN_KAL);
303 SHOW_FLAG(f, TX_HDR_CONN_CLO);
304 SHOW_FLAG(f, TX_HDR_CONN_PRS);
305 SHOW_FLAG(f, TX_WAIT_NEXT_RQ);
306 SHOW_FLAG(f, TX_HDR_CONN_UPG);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100307 SHOW_FLAG(f, TX_CON_KAL_SET);
308 SHOW_FLAG(f, TX_CON_CLO_SET);
309
310 //printf("%s", f ? "" : " | ");
311 switch (f & TX_CON_WANT_MSK) {
312 case TX_CON_WANT_KAL: /*f &= ~TX_CON_WANT_MSK ; printf("TX_CON_WANT_KAL%s", f ? " | " : "");*/ break;
313 case TX_CON_WANT_TUN: f &= ~TX_CON_WANT_MSK ; printf("TX_CON_WANT_TUN%s", f ? " | " : ""); break;
314 case TX_CON_WANT_SCL: f &= ~TX_CON_WANT_MSK ; printf("TX_CON_WANT_SCL%s", f ? " | " : ""); break;
315 case TX_CON_WANT_CLO: f &= ~TX_CON_WANT_MSK ; printf("TX_CON_WANT_CLO%s", f ? " | " : ""); break;
316 }
317
318 SHOW_FLAG(f, TX_CACHE_COOK);
319 SHOW_FLAG(f, TX_CACHEABLE);
320 SHOW_FLAG(f, TX_SCK_PRESENT);
321
322 //printf("%s", f ? "" : " | ");
323 switch (f & TX_SCK_MASK) {
324 case TX_SCK_NONE: f &= ~TX_SCK_MASK ; /*printf("TX_SCK_NONE%s", f ? " | " : "");*/ break;
325 case TX_SCK_FOUND: f &= ~TX_SCK_MASK ; printf("TX_SCK_FOUND%s", f ? " | " : ""); break;
326 case TX_SCK_DELETED: f &= ~TX_SCK_MASK ; printf("TX_SCK_DELETED%s", f ? " | " : ""); break;
327 case TX_SCK_INSERTED: f &= ~TX_SCK_MASK ; printf("TX_SCK_INSERTED%s", f ? " | " : ""); break;
328 case TX_SCK_REPLACED: f &= ~TX_SCK_MASK ; printf("TX_SCK_REPLACED%s", f ? " | " : ""); break;
329 case TX_SCK_UPDATED: f &= ~TX_SCK_MASK ; printf("TX_SCK_UPDATED%s", f ? " | " : ""); break;
330 default: printf("TX_SCK_MASK(%02x)", f); f &= ~TX_SCK_MASK ; printf("%s", f ? " | " : ""); break;
331 }
332
333 //printf("%s", f ? "" : " | ");
334 switch (f & TX_CK_MASK) {
335 case TX_CK_NONE: f &= ~TX_CK_MASK ; /*printf("TX_CK_NONE%s", f ? " | " : "");*/ break;
336 case TX_CK_INVALID: f &= ~TX_CK_MASK ; printf("TX_CK_INVALID%s", f ? " | " : ""); break;
337 case TX_CK_DOWN: f &= ~TX_CK_MASK ; printf("TX_CK_DOWN%s", f ? " | " : ""); break;
338 case TX_CK_VALID: f &= ~TX_CK_MASK ; printf("TX_CK_VALID%s", f ? " | " : ""); break;
339 case TX_CK_EXPIRED: f &= ~TX_CK_MASK ; printf("TX_CK_EXPIRED%s", f ? " | " : ""); break;
340 case TX_CK_OLD: f &= ~TX_CK_MASK ; printf("TX_CK_OLD%s", f ? " | " : ""); break;
341 case TX_CK_UNUSED: f &= ~TX_CK_MASK ; printf("TX_CK_UNUSED%s", f ? " | " : ""); break;
342 default: printf("TX_CK_MASK(%02x)", f); f &= ~TX_CK_MASK ; printf("%s", f ? " | " : ""); break;
343 }
344
345 SHOW_FLAG(f, TX_CLTARPIT);
346 SHOW_FLAG(f, TX_SVALLOW);
347 SHOW_FLAG(f, TX_SVDENY);
348 SHOW_FLAG(f, TX_CLALLOW);
349 SHOW_FLAG(f, TX_CLDENY);
350
351 if (f) {
352 printf("EXTRA(0x%08x)", f);
353 }
354 putchar('\n');
355}
356
357void show_strm_flags(unsigned int f)
358{
359 printf("strm->flags = ");
360
361 if (!f) {
362 printf("0\n");
363 return;
364 }
365
366 SHOW_FLAG(f, SF_SRV_REUSED);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100367 SHOW_FLAG(f, SF_IGNORE_PRST);
368
369 //printf("%s", f ? "" : " | ");
370 switch (f & SF_FINST_MASK) {
371 case SF_FINST_R: f &= ~SF_FINST_MASK ; printf("SF_FINST_R%s", f ? " | " : ""); break;
372 case SF_FINST_C: f &= ~SF_FINST_MASK ; printf("SF_FINST_C%s", f ? " | " : ""); break;
373 case SF_FINST_H: f &= ~SF_FINST_MASK ; printf("SF_FINST_H%s", f ? " | " : ""); break;
374 case SF_FINST_D: f &= ~SF_FINST_MASK ; printf("SF_FINST_D%s", f ? " | " : ""); break;
375 case SF_FINST_L: f &= ~SF_FINST_MASK ; printf("SF_FINST_L%s", f ? " | " : ""); break;
376 case SF_FINST_Q: f &= ~SF_FINST_MASK ; printf("SF_FINST_Q%s", f ? " | " : ""); break;
377 case SF_FINST_T: f &= ~SF_FINST_MASK ; printf("SF_FINST_T%s", f ? " | " : ""); break;
378 }
379
380 switch (f & SF_ERR_MASK) {
381 case SF_ERR_LOCAL: f &= ~SF_ERR_MASK ; printf("SF_ERR_LOCAL%s", f ? " | " : ""); break;
382 case SF_ERR_CLITO: f &= ~SF_ERR_MASK ; printf("SF_ERR_CLITO%s", f ? " | " : ""); break;
383 case SF_ERR_CLICL: f &= ~SF_ERR_MASK ; printf("SF_ERR_CLICL%s", f ? " | " : ""); break;
384 case SF_ERR_SRVTO: f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVTO%s", f ? " | " : ""); break;
385 case SF_ERR_SRVCL: f &= ~SF_ERR_MASK ; printf("SF_ERR_SRVCL%s", f ? " | " : ""); break;
386 case SF_ERR_PRXCOND: f &= ~SF_ERR_MASK ; printf("SF_ERR_PRXCOND%s", f ? " | " : ""); break;
387 case SF_ERR_RESOURCE: f &= ~SF_ERR_MASK ; printf("SF_ERR_RESOURCE%s", f ? " | " : ""); break;
388 case SF_ERR_INTERNAL: f &= ~SF_ERR_MASK ; printf("SF_ERR_INTERNAL%s", f ? " | " : ""); break;
389 case SF_ERR_DOWN: f &= ~SF_ERR_MASK ; printf("SF_ERR_DOWN%s", f ? " | " : ""); break;
390 case SF_ERR_KILLED: f &= ~SF_ERR_MASK ; printf("SF_ERR_KILLED%s", f ? " | " : ""); break;
391 case SF_ERR_UP: f &= ~SF_ERR_MASK ; printf("SF_ERR_UP%s", f ? " | " : ""); break;
Willy Tarreaua7da4d22016-11-11 08:05:34 +0100392 case SF_ERR_CHK_PORT: f &= ~SF_ERR_MASK ; printf("SF_ERR_CHK_PORT%s", f ? " | " : ""); break;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100393 }
394
Willy Tarreau465b35d2020-02-06 07:57:36 +0100395 SHOW_FLAG(f, SF_HTX);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100396 SHOW_FLAG(f, SF_REDIRECTABLE);
Willy Tarreau465b35d2020-02-06 07:57:36 +0100397 SHOW_FLAG(f, SF_IGNORE);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100398 SHOW_FLAG(f, SF_REDISP);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100399 SHOW_FLAG(f, SF_CURR_SESS);
400 SHOW_FLAG(f, SF_MONITOR);
401 SHOW_FLAG(f, SF_FORCE_PRST);
402 SHOW_FLAG(f, SF_BE_ASSIGNED);
403 SHOW_FLAG(f, SF_ADDR_SET);
404 SHOW_FLAG(f, SF_ASSIGNED);
405 SHOW_FLAG(f, SF_DIRECT);
406
407 if (f) {
408 printf("EXTRA(0x%08x)", f);
409 }
410 putchar('\n');
411}
412
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100413void usage_exit(const char *name)
414{
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100415 fprintf(stderr, "Usage: %s [ana|chn|conn|cs|si|sierr|strm|task|txn]* { [+-][0x]value* | - }\n", name);
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100416 exit(1);
417}
418
Willy Tarreau074d65b2015-12-20 23:21:57 +0100419int main(int argc, char **argv)
420{
421 unsigned int flags;
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100422 unsigned int show_as = 0;
423 unsigned int f;
424 const char *name = argv[0];
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100425 char line[20];
426 char *value;
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100427 int multi = 0;
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100428 int use_stdin = 0;
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100429 char *err;
430
431 while (argc > 0) {
432 argv++; argc--;
433 if (argc < 1)
434 usage_exit(name);
Willy Tarreau074d65b2015-12-20 23:21:57 +0100435
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100436 f = get_show_as(argv[0]);
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100437 if (!f)
438 break;
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100439 show_as |= f;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100440 }
441
Willy Tarreaucb5738c2020-02-06 08:33:08 +0100442 if (!show_as)
443 show_as = ~0U;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100444
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100445 if (argc > 1)
446 multi = 1;
Willy Tarreau074d65b2015-12-20 23:21:57 +0100447
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100448 if (strcmp(argv[0], "-") == 0)
449 use_stdin = 1;
450
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100451 while (argc > 0) {
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100452 if (use_stdin) {
453 value = fgets(line, sizeof(line), stdin);
454 if (!value)
455 break;
456
457 /* skip common leading delimitors that slip from copy-paste */
458 while (*value == ' ' || *value == '\t' || *value == ':' || *value == '=')
459 value++;
460
461 /* stop at the end of the number and trim any C suffix like "UL" */
462 err = value;
463 while (*err == '-' || *err == '+' ||
464 (isalnum(*err) && toupper(*err) != 'U' && toupper(*err) != 'L'))
465 err++;
466 if (err)
467 *err = 0;
468 } else {
469 value = argv[0];
470 argv++; argc--;
471 }
472
473 flags = strtoul(value, &err, 0);
474 if (!*value || *err) {
475 fprintf(stderr, "Unparsable value: <%s>\n", value);
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100476 usage_exit(name);
477 }
478
Willy Tarreau9cd0ad92020-02-06 18:17:50 +0100479 if (multi || use_stdin)
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100480 printf("### 0x%08x:\n", flags);
481
482 if (show_as & SHOW_AS_ANA) show_chn_ana(flags);
483 if (show_as & SHOW_AS_CHN) show_chn_flags(flags);
484 if (show_as & SHOW_AS_CONN) show_conn_flags(flags);
485 if (show_as & SHOW_AS_CS) show_cs_flags(flags);
486 if (show_as & SHOW_AS_SI) show_si_flags(flags);
487 if (show_as & SHOW_AS_SIET) show_si_et(flags);
488 if (show_as & SHOW_AS_STRM) show_strm_flags(flags);
489 if (show_as & SHOW_AS_TASK) show_task_state(flags);
490 if (show_as & SHOW_AS_TXN) show_txn_flags(flags);
Willy Tarreaub85b14b2020-02-06 08:48:16 +0100491 }
Willy Tarreau074d65b2015-12-20 23:21:57 +0100492 return 0;
493}