Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 4 | #include <haproxy/channel-t.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 5 | #include <haproxy/connection-t.h> |
Willy Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 6 | #include <haproxy/fd-t.h> |
Willy Tarreau | c2b1ff0 | 2020-06-04 21:21:03 +0200 | [diff] [blame] | 7 | #include <haproxy/http_ana-t.h> |
Willy Tarreau | 5349779 | 2022-09-09 16:59:29 +0200 | [diff] [blame] | 8 | #include <haproxy/htx-t.h> |
Willy Tarreau | 439be58 | 2022-09-12 19:20:23 +0200 | [diff] [blame] | 9 | #include <haproxy/mux_h2-t.h> |
Christopher Faulet | 7c4b2ec | 2022-09-15 10:54:36 +0200 | [diff] [blame] | 10 | #include <haproxy/mux_h1-t.h> |
Willy Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 11 | #include <haproxy/stconn-t.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 12 | #include <haproxy/stream-t.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 13 | #include <haproxy/task-t.h> |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 14 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 15 | // 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 Tarreau | 79775fa | 2022-05-27 09:57:31 +0200 | [diff] [blame] | 19 | #define SHOW_AS_SC 0x00000008 |
Christopher Faulet | 09b3c55 | 2022-04-04 11:28:27 +0200 | [diff] [blame] | 20 | #define SHOW_AS_SET 0x00000010 |
| 21 | #define SHOW_AS_STRM 0x00000020 |
| 22 | #define SHOW_AS_TASK 0x00000040 |
| 23 | #define SHOW_AS_TXN 0x00000080 |
Willy Tarreau | 2bacf4e | 2022-05-27 16:29:30 +0200 | [diff] [blame] | 24 | #define SHOW_AS_SD 0x00000100 |
Willy Tarreau | 5349779 | 2022-09-09 16:59:29 +0200 | [diff] [blame] | 25 | #define SHOW_AS_HSL 0x00000200 |
| 26 | #define SHOW_AS_HTX 0x00000400 |
Willy Tarreau | 6edae6f | 2022-09-09 17:18:57 +0200 | [diff] [blame] | 27 | #define SHOW_AS_HMSG 0x00000800 |
Willy Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 28 | #define SHOW_AS_FD 0x00001000 |
Willy Tarreau | 439be58 | 2022-09-12 19:20:23 +0200 | [diff] [blame] | 29 | #define SHOW_AS_H2C 0x00002000 |
| 30 | #define SHOW_AS_H2S 0x00004000 |
Christopher Faulet | 7c4b2ec | 2022-09-15 10:54:36 +0200 | [diff] [blame] | 31 | #define SHOW_AS_H1C 0x00008000 |
| 32 | #define SHOW_AS_H1S 0x00010000 |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 33 | |
| 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 Faulet | 7c4b2ec | 2022-09-15 10:54:36 +0200 | [diff] [blame] | 36 | const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", "h2c", "h2s", "h1c", "h1s", }; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 37 | |
Willy Tarreau | cdc9ddc | 2022-09-09 14:51:57 +0200 | [diff] [blame] | 38 | /* will be sufficient for even largest flag names */ |
Willy Tarreau | cdefa80 | 2022-09-09 16:47:43 +0200 | [diff] [blame] | 39 | static char buf[4096]; |
| 40 | static size_t bsz = sizeof(buf); |
Willy Tarreau | cdc9ddc | 2022-09-09 14:51:57 +0200 | [diff] [blame] | 41 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 42 | unsigned 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 Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 55 | void usage_exit(const char *name) |
| 56 | { |
Willy Tarreau | c7ac174 | 2022-09-09 14:16:49 +0200 | [diff] [blame] | 57 | 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 Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 65 | exit(1); |
| 66 | } |
| 67 | |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 68 | int main(int argc, char **argv) |
| 69 | { |
| 70 | unsigned int flags; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 71 | unsigned int show_as = 0; |
| 72 | unsigned int f; |
| 73 | const char *name = argv[0]; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 74 | char line[20]; |
| 75 | char *value; |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 76 | int multi = 0; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 77 | int use_stdin = 0; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 78 | char *err; |
| 79 | |
| 80 | while (argc > 0) { |
| 81 | argv++; argc--; |
| 82 | if (argc < 1) |
| 83 | usage_exit(name); |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 84 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 85 | f = get_show_as(argv[0]); |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 86 | if (!f) |
| 87 | break; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 88 | show_as |= f; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 91 | if (!show_as) |
| 92 | show_as = ~0U; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 93 | |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 94 | if (argc > 1) |
| 95 | multi = 1; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 96 | |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 97 | if (strcmp(argv[0], "-") == 0) |
| 98 | use_stdin = 1; |
| 99 | |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 100 | while (argc > 0) { |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 101 | if (use_stdin) { |
| 102 | value = fgets(line, sizeof(line), stdin); |
| 103 | if (!value) |
| 104 | break; |
| 105 | |
Ilya Shipitsin | 6fb0f21 | 2020-04-02 15:25:26 +0500 | [diff] [blame] | 106 | /* skip common leading delimiters that slip from copy-paste */ |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 107 | 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 Tarreau | b00c00e | 2021-04-02 17:47:21 +0200 | [diff] [blame] | 113 | (isalnum((unsigned char)*err) && toupper((unsigned char)*err) != 'U' && toupper((unsigned char)*err) != 'L')) |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 114 | err++; |
Willy Tarreau | cd430b9 | 2021-04-03 15:26:56 +0200 | [diff] [blame] | 115 | *err = 0; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 116 | } 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 Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 124 | usage_exit(name); |
| 125 | } |
| 126 | |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 127 | if (multi || use_stdin) |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 128 | printf("### 0x%08x:\n", flags); |
| 129 | |
Willy Tarreau | cdefa80 | 2022-09-09 16:47:43 +0200 | [diff] [blame] | 130 | 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 Tarreau | 5349779 | 2022-09-09 16:59:29 +0200 | [diff] [blame] | 139 | 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 Tarreau | 6edae6f | 2022-09-09 17:18:57 +0200 | [diff] [blame] | 141 | if (show_as & SHOW_AS_HMSG) printf("hmsg->flags = %s\n", (hmsg_show_flags (buf, bsz, " | ", flags), buf)); |
Willy Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 142 | if (show_as & SHOW_AS_FD) printf("fd->flags = %s\n", (fd_show_flags (buf, bsz, " | ", flags), buf)); |
Willy Tarreau | 439be58 | 2022-09-12 19:20:23 +0200 | [diff] [blame] | 143 | 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 Faulet | 7c4b2ec | 2022-09-15 10:54:36 +0200 | [diff] [blame] | 145 | 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 Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 147 | } |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 148 | return 0; |
| 149 | } |