blob: d867ba247fdad037c0fa2cce8b71db8c875a1141 [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 Tarreau799e5412022-09-12 18:53:06 +02009#include <haproxy/stconn-t.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020010#include <haproxy/stream-t.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020011#include <haproxy/task-t.h>
Willy Tarreau074d65b2015-12-20 23:21:57 +010012
Willy Tarreau354b6f52020-02-06 08:33:08 +010013// 1 bit per flag, no hole permitted here
14#define SHOW_AS_ANA 0x00000001
15#define SHOW_AS_CHN 0x00000002
16#define SHOW_AS_CONN 0x00000004
Willy Tarreau79775fa2022-05-27 09:57:31 +020017#define SHOW_AS_SC 0x00000008
Christopher Faulet09b3c552022-04-04 11:28:27 +020018#define SHOW_AS_SET 0x00000010
19#define SHOW_AS_STRM 0x00000020
20#define SHOW_AS_TASK 0x00000040
21#define SHOW_AS_TXN 0x00000080
Willy Tarreau2bacf4e2022-05-27 16:29:30 +020022#define SHOW_AS_SD 0x00000100
Willy Tarreau53497792022-09-09 16:59:29 +020023#define SHOW_AS_HSL 0x00000200
24#define SHOW_AS_HTX 0x00000400
Willy Tarreau6edae6f2022-09-09 17:18:57 +020025#define SHOW_AS_HMSG 0x00000800
Willy Tarreau799e5412022-09-12 18:53:06 +020026#define SHOW_AS_FD 0x00001000
Willy Tarreau354b6f52020-02-06 08:33:08 +010027
28// command line names, must be in exact same order as the SHOW_AS_* flags above
29// so that show_as_words[i] matches flag 1U<<i.
Willy Tarreau799e5412022-09-12 18:53:06 +020030const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", };
Willy Tarreau354b6f52020-02-06 08:33:08 +010031
Willy Tarreaucdc9ddc2022-09-09 14:51:57 +020032/* will be sufficient for even largest flag names */
Willy Tarreaucdefa802022-09-09 16:47:43 +020033static char buf[4096];
34static size_t bsz = sizeof(buf);
Willy Tarreaucdc9ddc2022-09-09 14:51:57 +020035
Willy Tarreau354b6f52020-02-06 08:33:08 +010036unsigned int get_show_as(const char *word)
37{
38 int w = 0;
39
40 while (1) {
41 if (w == sizeof(show_as_words) / sizeof(*show_as_words))
42 return 0;
43 if (strcmp(word, show_as_words[w]) == 0)
44 return 1U << w;
45 w++;
46 }
47}
48
Willy Tarreau354b6f52020-02-06 08:33:08 +010049void usage_exit(const char *name)
50{
Willy Tarreauc7ac1742022-09-09 14:16:49 +020051 int word, nbword;
52
53 fprintf(stderr, "Usage: %s [", name);
54
55 nbword = sizeof(show_as_words) / sizeof(*show_as_words);
56 for (word = 0; word < nbword; word++)
57 fprintf(stderr, "%s%s", word ? "|" : "", show_as_words[word]);
58 fprintf(stderr, "]* { [+-][0x]value* | - }\n");
Willy Tarreau354b6f52020-02-06 08:33:08 +010059 exit(1);
60}
61
Willy Tarreau074d65b2015-12-20 23:21:57 +010062int main(int argc, char **argv)
63{
64 unsigned int flags;
Willy Tarreau354b6f52020-02-06 08:33:08 +010065 unsigned int show_as = 0;
66 unsigned int f;
67 const char *name = argv[0];
Willy Tarreaue4f80a02020-02-06 18:17:50 +010068 char line[20];
69 char *value;
Willy Tarreaubde76f02020-02-06 08:48:16 +010070 int multi = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +010071 int use_stdin = 0;
Willy Tarreau354b6f52020-02-06 08:33:08 +010072 char *err;
73
74 while (argc > 0) {
75 argv++; argc--;
76 if (argc < 1)
77 usage_exit(name);
Willy Tarreau074d65b2015-12-20 23:21:57 +010078
Willy Tarreau354b6f52020-02-06 08:33:08 +010079 f = get_show_as(argv[0]);
Willy Tarreaubde76f02020-02-06 08:48:16 +010080 if (!f)
81 break;
Willy Tarreau354b6f52020-02-06 08:33:08 +010082 show_as |= f;
Willy Tarreau074d65b2015-12-20 23:21:57 +010083 }
84
Willy Tarreau354b6f52020-02-06 08:33:08 +010085 if (!show_as)
86 show_as = ~0U;
Willy Tarreau074d65b2015-12-20 23:21:57 +010087
Willy Tarreaubde76f02020-02-06 08:48:16 +010088 if (argc > 1)
89 multi = 1;
Willy Tarreau074d65b2015-12-20 23:21:57 +010090
Willy Tarreaue4f80a02020-02-06 18:17:50 +010091 if (strcmp(argv[0], "-") == 0)
92 use_stdin = 1;
93
Willy Tarreaubde76f02020-02-06 08:48:16 +010094 while (argc > 0) {
Willy Tarreaue4f80a02020-02-06 18:17:50 +010095 if (use_stdin) {
96 value = fgets(line, sizeof(line), stdin);
97 if (!value)
98 break;
99
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +0500100 /* skip common leading delimiters that slip from copy-paste */
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100101 while (*value == ' ' || *value == '\t' || *value == ':' || *value == '=')
102 value++;
103
104 /* stop at the end of the number and trim any C suffix like "UL" */
105 err = value;
106 while (*err == '-' || *err == '+' ||
Willy Tarreaub00c00e2021-04-02 17:47:21 +0200107 (isalnum((unsigned char)*err) && toupper((unsigned char)*err) != 'U' && toupper((unsigned char)*err) != 'L'))
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100108 err++;
Willy Tarreaucd430b92021-04-03 15:26:56 +0200109 *err = 0;
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100110 } else {
111 value = argv[0];
112 argv++; argc--;
113 }
114
115 flags = strtoul(value, &err, 0);
116 if (!*value || *err) {
117 fprintf(stderr, "Unparsable value: <%s>\n", value);
Willy Tarreaubde76f02020-02-06 08:48:16 +0100118 usage_exit(name);
119 }
120
Willy Tarreaue4f80a02020-02-06 18:17:50 +0100121 if (multi || use_stdin)
Willy Tarreaubde76f02020-02-06 08:48:16 +0100122 printf("### 0x%08x:\n", flags);
123
Willy Tarreaucdefa802022-09-09 16:47:43 +0200124 if (show_as & SHOW_AS_ANA) printf("chn->ana = %s\n", (chn_show_analysers(buf, bsz, " | ", flags), buf));
125 if (show_as & SHOW_AS_CHN) printf("chn->flags = %s\n", (chn_show_flags (buf, bsz, " | ", flags), buf));
126 if (show_as & SHOW_AS_CONN) printf("conn->flags = %s\n", (conn_show_flags (buf, bsz, " | ", flags), buf));
127 if (show_as & SHOW_AS_SC) printf("sc->flags = %s\n", (sc_show_flags (buf, bsz, " | ", flags), buf));
128 if (show_as & SHOW_AS_SD) printf("sd->flags = %s\n", (se_show_flags (buf, bsz, " | ", flags), buf));
129 if (show_as & SHOW_AS_SET) printf("strm->et = %s\n", (strm_et_show_flags(buf, bsz, " | ", flags), buf));
130 if (show_as & SHOW_AS_STRM) printf("strm->flags = %s\n", (strm_show_flags (buf, bsz, " | ", flags), buf));
131 if (show_as & SHOW_AS_TASK) printf("task->state = %s\n", (task_show_state (buf, bsz, " | ", flags), buf));
132 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 +0200133 if (show_as & SHOW_AS_HSL) printf("sl->flags = %s\n", (hsl_show_flags (buf, bsz, " | ", flags), buf));
134 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 +0200135 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 +0200136 if (show_as & SHOW_AS_FD) printf("fd->flags = %s\n", (fd_show_flags (buf, bsz, " | ", flags), buf));
Willy Tarreaubde76f02020-02-06 08:48:16 +0100137 }
Willy Tarreau074d65b2015-12-20 23:21:57 +0100138 return 0;
139}