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 | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 9 | #include <haproxy/stconn-t.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 10 | #include <haproxy/stream-t.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 11 | #include <haproxy/task-t.h> |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 12 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 13 | // 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 Tarreau | 79775fa | 2022-05-27 09:57:31 +0200 | [diff] [blame] | 17 | #define SHOW_AS_SC 0x00000008 |
Christopher Faulet | 09b3c55 | 2022-04-04 11:28:27 +0200 | [diff] [blame] | 18 | #define SHOW_AS_SET 0x00000010 |
| 19 | #define SHOW_AS_STRM 0x00000020 |
| 20 | #define SHOW_AS_TASK 0x00000040 |
| 21 | #define SHOW_AS_TXN 0x00000080 |
Willy Tarreau | 2bacf4e | 2022-05-27 16:29:30 +0200 | [diff] [blame] | 22 | #define SHOW_AS_SD 0x00000100 |
Willy Tarreau | 5349779 | 2022-09-09 16:59:29 +0200 | [diff] [blame] | 23 | #define SHOW_AS_HSL 0x00000200 |
| 24 | #define SHOW_AS_HTX 0x00000400 |
Willy Tarreau | 6edae6f | 2022-09-09 17:18:57 +0200 | [diff] [blame] | 25 | #define SHOW_AS_HMSG 0x00000800 |
Willy Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 26 | #define SHOW_AS_FD 0x00001000 |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 27 | |
| 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 Tarreau | 799e541 | 2022-09-12 18:53:06 +0200 | [diff] [blame] | 30 | const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", }; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 31 | |
Willy Tarreau | cdc9ddc | 2022-09-09 14:51:57 +0200 | [diff] [blame] | 32 | /* will be sufficient for even largest flag names */ |
Willy Tarreau | cdefa80 | 2022-09-09 16:47:43 +0200 | [diff] [blame] | 33 | static char buf[4096]; |
| 34 | static size_t bsz = sizeof(buf); |
Willy Tarreau | cdc9ddc | 2022-09-09 14:51:57 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 36 | unsigned 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 Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 49 | void usage_exit(const char *name) |
| 50 | { |
Willy Tarreau | c7ac174 | 2022-09-09 14:16:49 +0200 | [diff] [blame] | 51 | 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 Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 59 | exit(1); |
| 60 | } |
| 61 | |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 62 | int main(int argc, char **argv) |
| 63 | { |
| 64 | unsigned int flags; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 65 | unsigned int show_as = 0; |
| 66 | unsigned int f; |
| 67 | const char *name = argv[0]; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 68 | char line[20]; |
| 69 | char *value; |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 70 | int multi = 0; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 71 | int use_stdin = 0; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 72 | char *err; |
| 73 | |
| 74 | while (argc > 0) { |
| 75 | argv++; argc--; |
| 76 | if (argc < 1) |
| 77 | usage_exit(name); |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 78 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 79 | f = get_show_as(argv[0]); |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 80 | if (!f) |
| 81 | break; |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 82 | show_as |= f; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Willy Tarreau | 354b6f5 | 2020-02-06 08:33:08 +0100 | [diff] [blame] | 85 | if (!show_as) |
| 86 | show_as = ~0U; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 87 | |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 88 | if (argc > 1) |
| 89 | multi = 1; |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 90 | |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 91 | if (strcmp(argv[0], "-") == 0) |
| 92 | use_stdin = 1; |
| 93 | |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 94 | while (argc > 0) { |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 95 | if (use_stdin) { |
| 96 | value = fgets(line, sizeof(line), stdin); |
| 97 | if (!value) |
| 98 | break; |
| 99 | |
Ilya Shipitsin | 6fb0f21 | 2020-04-02 15:25:26 +0500 | [diff] [blame] | 100 | /* skip common leading delimiters that slip from copy-paste */ |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 101 | 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 Tarreau | b00c00e | 2021-04-02 17:47:21 +0200 | [diff] [blame] | 107 | (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] | 108 | err++; |
Willy Tarreau | cd430b9 | 2021-04-03 15:26:56 +0200 | [diff] [blame] | 109 | *err = 0; |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 110 | } 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 Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 118 | usage_exit(name); |
| 119 | } |
| 120 | |
Willy Tarreau | e4f80a0 | 2020-02-06 18:17:50 +0100 | [diff] [blame] | 121 | if (multi || use_stdin) |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 122 | printf("### 0x%08x:\n", flags); |
| 123 | |
Willy Tarreau | cdefa80 | 2022-09-09 16:47:43 +0200 | [diff] [blame] | 124 | 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 Tarreau | 5349779 | 2022-09-09 16:59:29 +0200 | [diff] [blame] | 133 | 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 Tarreau | 6edae6f | 2022-09-09 17:18:57 +0200 | [diff] [blame] | 135 | 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] | 136 | if (show_as & SHOW_AS_FD) printf("fd->flags = %s\n", (fd_show_flags (buf, bsz, " | ", flags), buf)); |
Willy Tarreau | bde76f0 | 2020-02-06 08:48:16 +0100 | [diff] [blame] | 137 | } |
Willy Tarreau | 074d65b | 2015-12-20 23:21:57 +0100 | [diff] [blame] | 138 | return 0; |
| 139 | } |