William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output and the stats socket |
| 3 | * |
| 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
| 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
| 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 27 | #include <net/if.h> |
| 28 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 29 | #include <common/cfgparse.h> |
| 30 | #include <common/compat.h> |
| 31 | #include <common/config.h> |
| 32 | #include <common/debug.h> |
| 33 | #include <common/memory.h> |
| 34 | #include <common/mini-clist.h> |
| 35 | #include <common/standard.h> |
| 36 | #include <common/ticks.h> |
| 37 | #include <common/time.h> |
| 38 | #include <common/uri_auth.h> |
| 39 | #include <common/version.h> |
| 40 | #include <common/base64.h> |
| 41 | |
| 42 | #include <types/applet.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 43 | #include <types/cli.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 44 | #include <types/global.h> |
| 45 | #include <types/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 46 | #include <types/stats.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 47 | |
| 48 | #include <proto/backend.h> |
| 49 | #include <proto/channel.h> |
| 50 | #include <proto/checks.h> |
| 51 | #include <proto/compression.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 52 | #include <proto/stats.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 53 | #include <proto/fd.h> |
| 54 | #include <proto/freq_ctr.h> |
| 55 | #include <proto/frontend.h> |
| 56 | #include <proto/log.h> |
| 57 | #include <proto/pattern.h> |
| 58 | #include <proto/pipe.h> |
| 59 | #include <proto/listener.h> |
| 60 | #include <proto/map.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 61 | #include <proto/proxy.h> |
| 62 | #include <proto/sample.h> |
| 63 | #include <proto/session.h> |
| 64 | #include <proto/stream.h> |
| 65 | #include <proto/server.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 66 | #include <proto/stream_interface.h> |
| 67 | #include <proto/task.h> |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 68 | #include <proto/proto_udp.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 69 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 70 | #define PAYLOAD_PATTERN "<<" |
| 71 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 72 | static struct applet cli_applet; |
| 73 | |
| 74 | static const char stats_sock_usage_msg[] = |
| 75 | "Unknown command. Please enter one of the following commands only :\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 76 | " help : this message\n" |
| 77 | " prompt : toggle interactive mode with prompt\n" |
| 78 | " quit : disconnect\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 79 | ""; |
| 80 | |
| 81 | static const char stats_permission_denied_msg[] = |
| 82 | "Permission denied\n" |
| 83 | ""; |
| 84 | |
| 85 | |
Christopher Faulet | 1bc04c7 | 2017-10-29 20:14:08 +0100 | [diff] [blame] | 86 | static THREAD_LOCAL char *dynamic_usage_msg = NULL; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 87 | |
| 88 | /* List head of cli keywords */ |
| 89 | static struct cli_kw_list cli_keywords = { |
| 90 | .list = LIST_HEAD_INIT(cli_keywords.list) |
| 91 | }; |
| 92 | |
| 93 | extern const char *stat_status_codes[]; |
| 94 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 95 | static char *cli_gen_usage_msg(struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 96 | { |
| 97 | struct cli_kw_list *kw_list; |
| 98 | struct cli_kw *kw; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 99 | struct buffer *tmp = get_trash_chunk(); |
| 100 | struct buffer out; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 101 | |
| 102 | free(dynamic_usage_msg); |
| 103 | dynamic_usage_msg = NULL; |
| 104 | |
| 105 | if (LIST_ISEMPTY(&cli_keywords.list)) |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 106 | goto end; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 107 | |
| 108 | chunk_reset(tmp); |
| 109 | chunk_strcat(tmp, stats_sock_usage_msg); |
| 110 | list_for_each_entry(kw_list, &cli_keywords.list, list) { |
| 111 | kw = &kw_list->kw[0]; |
William Lallemand | 0154edc | 2018-05-15 11:50:04 +0200 | [diff] [blame] | 112 | while (kw->str_kw[0]) { |
| 113 | if (kw->usage) |
| 114 | chunk_appendf(tmp, " %s\n", kw->usage); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 115 | kw++; |
| 116 | } |
| 117 | } |
| 118 | chunk_init(&out, NULL, 0); |
| 119 | chunk_dup(&out, tmp); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 120 | dynamic_usage_msg = out.area; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 121 | |
| 122 | end: |
| 123 | if (dynamic_usage_msg) { |
| 124 | appctx->ctx.cli.severity = LOG_INFO; |
| 125 | appctx->ctx.cli.msg = dynamic_usage_msg; |
| 126 | } |
| 127 | else { |
| 128 | appctx->ctx.cli.severity = LOG_INFO; |
| 129 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 130 | } |
| 131 | appctx->st0 = CLI_ST_PRINT; |
| 132 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 133 | return dynamic_usage_msg; |
| 134 | } |
| 135 | |
| 136 | struct cli_kw* cli_find_kw(char **args) |
| 137 | { |
| 138 | struct cli_kw_list *kw_list; |
| 139 | struct cli_kw *kw;/* current cli_kw */ |
| 140 | char **tmp_args; |
| 141 | const char **tmp_str_kw; |
| 142 | int found = 0; |
| 143 | |
| 144 | if (LIST_ISEMPTY(&cli_keywords.list)) |
| 145 | return NULL; |
| 146 | |
| 147 | list_for_each_entry(kw_list, &cli_keywords.list, list) { |
| 148 | kw = &kw_list->kw[0]; |
| 149 | while (*kw->str_kw) { |
| 150 | tmp_args = args; |
| 151 | tmp_str_kw = kw->str_kw; |
| 152 | while (*tmp_str_kw) { |
| 153 | if (strcmp(*tmp_str_kw, *tmp_args) == 0) { |
| 154 | found = 1; |
| 155 | } else { |
| 156 | found = 0; |
| 157 | break; |
| 158 | } |
| 159 | tmp_args++; |
| 160 | tmp_str_kw++; |
| 161 | } |
| 162 | if (found) |
| 163 | return (kw); |
| 164 | kw++; |
| 165 | } |
| 166 | } |
| 167 | return NULL; |
| 168 | } |
| 169 | |
| 170 | void cli_register_kw(struct cli_kw_list *kw_list) |
| 171 | { |
| 172 | LIST_ADDQ(&cli_keywords.list, &kw_list->list); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | /* allocate a new stats frontend named <name>, and return it |
| 177 | * (or NULL in case of lack of memory). |
| 178 | */ |
| 179 | static struct proxy *alloc_stats_fe(const char *name, const char *file, int line) |
| 180 | { |
| 181 | struct proxy *fe; |
| 182 | |
| 183 | fe = calloc(1, sizeof(*fe)); |
| 184 | if (!fe) |
| 185 | return NULL; |
| 186 | |
| 187 | init_new_proxy(fe); |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 188 | fe->next = proxies_list; |
| 189 | proxies_list = fe; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 190 | fe->last_change = now.tv_sec; |
| 191 | fe->id = strdup("GLOBAL"); |
| 192 | fe->cap = PR_CAP_FE; |
| 193 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 194 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
| 195 | fe->conf.file = strdup(file); |
| 196 | fe->conf.line = line; |
| 197 | fe->accept = frontend_accept; |
| 198 | fe->default_target = &cli_applet.obj_type; |
| 199 | |
| 200 | /* the stats frontend is the only one able to assign ID #0 */ |
| 201 | fe->conf.id.key = fe->uuid = 0; |
| 202 | eb32_insert(&used_proxy_id, &fe->conf.id); |
| 203 | return fe; |
| 204 | } |
| 205 | |
| 206 | /* This function parses a "stats" statement in the "global" section. It returns |
| 207 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 208 | * error message into the <err> buffer which will be preallocated. The trailing |
| 209 | * '\n' must not be written. The function must be called with <args> pointing to |
| 210 | * the first word after "stats". |
| 211 | */ |
| 212 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
| 213 | struct proxy *defpx, const char *file, int line, |
| 214 | char **err) |
| 215 | { |
| 216 | struct bind_conf *bind_conf; |
| 217 | struct listener *l; |
| 218 | |
| 219 | if (!strcmp(args[1], "socket")) { |
| 220 | int cur_arg; |
| 221 | |
| 222 | if (*args[2] == 0) { |
| 223 | memprintf(err, "'%s %s' in global section expects an address or a path to a UNIX socket", args[0], args[1]); |
| 224 | return -1; |
| 225 | } |
| 226 | |
| 227 | if (!global.stats_fe) { |
| 228 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 229 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 230 | return -1; |
| 231 | } |
| 232 | } |
| 233 | |
Willy Tarreau | a261e9b | 2016-12-22 20:44:00 +0100 | [diff] [blame] | 234 | bind_conf = bind_conf_alloc(global.stats_fe, file, line, args[2], xprt_get(XPRT_RAW)); |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 235 | bind_conf->level &= ~ACCESS_LVL_MASK; |
| 236 | bind_conf->level |= ACCESS_LVL_OPER; /* default access level */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 237 | |
| 238 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 239 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 240 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | cur_arg = 3; |
| 245 | while (*args[cur_arg]) { |
| 246 | static int bind_dumped; |
| 247 | struct bind_kw *kw; |
| 248 | |
| 249 | kw = bind_find_kw(args[cur_arg]); |
| 250 | if (kw) { |
| 251 | if (!kw->parse) { |
| 252 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 253 | args[0], args[1], args[cur_arg]); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { |
| 258 | if (err && *err) |
| 259 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 260 | else |
| 261 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 262 | args[0], args[1], args[cur_arg]); |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | cur_arg += 1 + kw->skip; |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | if (!bind_dumped) { |
| 271 | bind_dump_kws(err); |
| 272 | indent_msg(err, 4); |
| 273 | bind_dumped = 1; |
| 274 | } |
| 275 | |
| 276 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 277 | args[0], args[1], args[cur_arg], |
| 278 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 279 | return -1; |
| 280 | } |
| 281 | |
| 282 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 283 | l->maxconn = global.stats_fe->maxconn; |
| 284 | l->backlog = global.stats_fe->backlog; |
| 285 | l->accept = session_accept_fd; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 286 | l->default_target = global.stats_fe->default_target; |
| 287 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 288 | l->nice = -64; /* we want to boost priority for local stats */ |
| 289 | global.maxsock += l->maxconn; |
| 290 | } |
| 291 | } |
| 292 | else if (!strcmp(args[1], "timeout")) { |
| 293 | unsigned timeout; |
| 294 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
| 295 | |
| 296 | if (res) { |
| 297 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | if (!timeout) { |
| 302 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
| 303 | return -1; |
| 304 | } |
| 305 | if (!global.stats_fe) { |
| 306 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 307 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 308 | return -1; |
| 309 | } |
| 310 | } |
| 311 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
| 312 | } |
| 313 | else if (!strcmp(args[1], "maxconn")) { |
| 314 | int maxconn = atol(args[2]); |
| 315 | |
| 316 | if (maxconn <= 0) { |
| 317 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
| 318 | return -1; |
| 319 | } |
| 320 | |
| 321 | if (!global.stats_fe) { |
| 322 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 323 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 324 | return -1; |
| 325 | } |
| 326 | } |
| 327 | global.stats_fe->maxconn = maxconn; |
| 328 | } |
| 329 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 330 | int cur_arg = 2; |
| 331 | unsigned long set = 0; |
| 332 | |
| 333 | if (!global.stats_fe) { |
| 334 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 335 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 336 | return -1; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | while (*args[cur_arg]) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 341 | if (strcmp(args[cur_arg], "all") == 0) { |
| 342 | set = 0; |
| 343 | break; |
| 344 | } |
Christopher Faulet | 26028f6 | 2017-11-22 15:01:51 +0100 | [diff] [blame] | 345 | if (parse_process_number(args[cur_arg], &set, NULL, err)) { |
Christopher Faulet | f1f0c5f | 2017-11-22 12:06:43 +0100 | [diff] [blame] | 346 | memprintf(err, "'%s %s' : %s", args[0], args[1], *err); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 347 | return -1; |
| 348 | } |
| 349 | cur_arg++; |
| 350 | } |
| 351 | global.stats_fe->bind_proc = set; |
| 352 | } |
| 353 | else { |
| 354 | memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); |
| 355 | return -1; |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
Willy Tarreau | de57a57 | 2016-11-23 17:01:39 +0100 | [diff] [blame] | 360 | /* Verifies that the CLI at least has a level at least as high as <level> |
| 361 | * (typically ACCESS_LVL_ADMIN). Returns 1 if OK, otherwise 0. In case of |
| 362 | * failure, an error message is prepared and the appctx's state is adjusted |
| 363 | * to print it so that a return 1 is enough to abort any processing. |
| 364 | */ |
| 365 | int cli_has_level(struct appctx *appctx, int level) |
| 366 | { |
| 367 | struct stream_interface *si = appctx->owner; |
| 368 | struct stream *s = si_strm(si); |
| 369 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 370 | if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < level) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 371 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | de57a57 | 2016-11-23 17:01:39 +0100 | [diff] [blame] | 372 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 373 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | de57a57 | 2016-11-23 17:01:39 +0100 | [diff] [blame] | 374 | return 0; |
| 375 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 376 | return 1; |
| 377 | } |
| 378 | |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 379 | /* Returns severity_output for the current session if set, or default for the socket */ |
| 380 | static int cli_get_severity_output(struct appctx *appctx) |
| 381 | { |
| 382 | if (appctx->cli_severity_output) |
| 383 | return appctx->cli_severity_output; |
| 384 | return strm_li(si_strm(appctx->owner))->bind_conf->severity_output; |
| 385 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 386 | |
Willy Tarreau | 4190856 | 2016-11-24 16:23:38 +0100 | [diff] [blame] | 387 | /* Processes the CLI interpreter on the stats socket. This function is called |
| 388 | * from the CLI's IO handler running in an appctx context. The function returns 1 |
| 389 | * if the request was understood, otherwise zero. It is called with appctx->st0 |
| 390 | * set to CLI_ST_GETREQ and presets ->st2 to 0 so that parsers don't have to do |
| 391 | * it. It will possilbly leave st0 to CLI_ST_CALLBACK if the keyword needs to |
| 392 | * have its own I/O handler called again. Most of the time, parsers will only |
| 393 | * set st0 to CLI_ST_PRINT and put their message to be displayed into cli.msg. |
Willy Tarreau | eaffde3 | 2016-12-16 17:59:25 +0100 | [diff] [blame] | 394 | * If a keyword parser is NULL and an I/O handler is declared, the I/O handler |
| 395 | * will automatically be used. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 396 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 397 | static int cli_parse_request(struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 398 | { |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 399 | char *args[MAX_STATS_ARGS + 1], *p, *end, *payload = NULL; |
| 400 | int i = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 401 | struct cli_kw *kw; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 402 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 403 | appctx->st2 = 0; |
| 404 | memset(&appctx->ctx.cli, 0, sizeof(appctx->ctx.cli)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 405 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 406 | p = appctx->chunk->area; |
| 407 | end = p + appctx->chunk->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 408 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 409 | /* |
| 410 | * Get the payload start if there is one. |
| 411 | * For the sake of simplicity, the payload pattern is looked up |
| 412 | * everywhere from the start of the input but it can only be found |
| 413 | * at the end of the first line if APPCTX_CLI_ST1_PAYLOAD is set. |
| 414 | * |
| 415 | * The input string was zero terminated so it is safe to use |
| 416 | * the str*() functions throughout the parsing |
| 417 | */ |
| 418 | if (appctx->st1 & APPCTX_CLI_ST1_PAYLOAD) { |
| 419 | payload = strstr(p, PAYLOAD_PATTERN); |
| 420 | end = payload; |
| 421 | /* skip the pattern */ |
| 422 | payload += strlen(PAYLOAD_PATTERN); |
| 423 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 424 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 425 | /* |
| 426 | * Get pointers on words. |
| 427 | * One extra slot is reserved to store a pointer on a null byte. |
| 428 | */ |
| 429 | while (i < MAX_STATS_ARGS && p < end) { |
| 430 | int j, k; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 431 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 432 | /* skip leading spaces/tabs */ |
| 433 | p += strspn(p, " \t"); |
| 434 | if (!*p) |
| 435 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 436 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 437 | args[i] = p; |
| 438 | p += strcspn(p, " \t"); |
| 439 | *p++ = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 440 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 441 | /* unescape backslashes (\) */ |
| 442 | for (j = 0, k = 0; args[i][k]; k++) { |
| 443 | if (args[i][k] == '\\') { |
| 444 | if (args[i][k + 1] == '\\') |
| 445 | k++; |
Dragan Dosen | a1c35ab | 2016-11-24 11:33:12 +0100 | [diff] [blame] | 446 | else |
| 447 | continue; |
| 448 | } |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 449 | args[i][j] = args[i][k]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 450 | j++; |
| 451 | } |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 452 | args[i][j] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 453 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 454 | i++; |
| 455 | } |
| 456 | /* fill unused slots */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 457 | p = appctx->chunk->area + appctx->chunk->data; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 458 | for (; i < MAX_STATS_ARGS + 1; i++) |
| 459 | args[i] = p; |
Willy Tarreau | 4190856 | 2016-11-24 16:23:38 +0100 | [diff] [blame] | 460 | |
| 461 | kw = cli_find_kw(args); |
Willy Tarreau | eaffde3 | 2016-12-16 17:59:25 +0100 | [diff] [blame] | 462 | if (!kw) |
Willy Tarreau | 4190856 | 2016-11-24 16:23:38 +0100 | [diff] [blame] | 463 | return 0; |
| 464 | |
| 465 | appctx->io_handler = kw->io_handler; |
Emeric Brun | d6871f7 | 2017-06-29 19:54:13 +0200 | [diff] [blame] | 466 | appctx->io_release = kw->io_release; |
| 467 | /* kw->parse could set its own io_handler or ip_release handler */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 468 | if ((!kw->parse || kw->parse(args, payload, appctx, kw->private) == 0) && appctx->io_handler) { |
Willy Tarreau | 4190856 | 2016-11-24 16:23:38 +0100 | [diff] [blame] | 469 | appctx->st0 = CLI_ST_CALLBACK; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 470 | } |
Willy Tarreau | 4190856 | 2016-11-24 16:23:38 +0100 | [diff] [blame] | 471 | return 1; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 474 | /* prepends then outputs the argument msg with a syslog-type severity depending on severity_output value */ |
| 475 | static int cli_output_msg(struct channel *chn, const char *msg, int severity, int severity_output) |
| 476 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 477 | struct buffer *tmp; |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 478 | |
| 479 | if (likely(severity_output == CLI_SEVERITY_NONE)) |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 480 | return ci_putblk(chn, msg, strlen(msg)); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 481 | |
| 482 | tmp = get_trash_chunk(); |
| 483 | chunk_reset(tmp); |
| 484 | |
| 485 | if (severity < 0 || severity > 7) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 486 | ha_warning("socket command feedback with invalid severity %d", severity); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 487 | chunk_printf(tmp, "[%d]: ", severity); |
| 488 | } |
| 489 | else { |
| 490 | switch (severity_output) { |
| 491 | case CLI_SEVERITY_NUMBER: |
| 492 | chunk_printf(tmp, "[%d]: ", severity); |
| 493 | break; |
| 494 | case CLI_SEVERITY_STRING: |
| 495 | chunk_printf(tmp, "[%s]: ", log_levels[severity]); |
| 496 | break; |
| 497 | default: |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 498 | ha_warning("Unrecognized severity output %d", severity_output); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | chunk_appendf(tmp, "%s", msg); |
| 502 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 503 | return ci_putblk(chn, tmp->area, strlen(tmp->area)); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 504 | } |
| 505 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 506 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 507 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 508 | * state machine handling requests and various responses. We read a request, |
| 509 | * then we process it and send the response, and we possibly display a prompt. |
| 510 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 511 | * CLI_ST_* constants. appctx->st1 is used to indicate whether prompt is enabled |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 512 | * or not. |
| 513 | */ |
| 514 | static void cli_io_handler(struct appctx *appctx) |
| 515 | { |
| 516 | struct stream_interface *si = appctx->owner; |
| 517 | struct channel *req = si_oc(si); |
| 518 | struct channel *res = si_ic(si); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 519 | struct bind_conf *bind_conf = strm_li(si_strm(si))->bind_conf; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 520 | int reql; |
| 521 | int len; |
| 522 | |
| 523 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 524 | goto out; |
| 525 | |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 526 | /* Check if the input buffer is avalaible. */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 527 | if (res->buf.size == 0) { |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 528 | si_applet_cant_put(si); |
| 529 | goto out; |
| 530 | } |
| 531 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 532 | while (1) { |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 533 | if (appctx->st0 == CLI_ST_INIT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 534 | /* Stats output not initialized yet */ |
| 535 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 536 | /* reset severity to default at init */ |
| 537 | appctx->cli_severity_output = bind_conf->severity_output; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 538 | appctx->st0 = CLI_ST_GETREQ; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 539 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 540 | else if (appctx->st0 == CLI_ST_END) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 541 | /* Let's close for real now. We just close the request |
| 542 | * side, the conditions below will complete if needed. |
| 543 | */ |
| 544 | si_shutw(si); |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 545 | free_trash_chunk(appctx->chunk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 546 | break; |
| 547 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 548 | else if (appctx->st0 == CLI_ST_GETREQ) { |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 549 | char *str; |
| 550 | |
| 551 | /* use a trash chunk to store received data */ |
| 552 | if (!appctx->chunk) { |
| 553 | appctx->chunk = alloc_trash_chunk(); |
| 554 | if (!appctx->chunk) { |
| 555 | appctx->st0 = CLI_ST_END; |
| 556 | continue; |
| 557 | } |
| 558 | } |
| 559 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 560 | str = appctx->chunk->area + appctx->chunk->data; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 561 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 562 | /* ensure we have some output room left in the event we |
| 563 | * would want to return some info right after parsing. |
| 564 | */ |
| 565 | if (buffer_almost_full(si_ib(si))) { |
| 566 | si_applet_cant_put(si); |
| 567 | break; |
| 568 | } |
| 569 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 570 | /* '- 1' is to ensure a null byte can always be inserted at the end */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 571 | reql = co_getline(si_oc(si), str, |
| 572 | appctx->chunk->size - appctx->chunk->data - 1); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 573 | if (reql <= 0) { /* closed or EOL not found */ |
| 574 | if (reql == 0) |
| 575 | break; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 576 | appctx->st0 = CLI_ST_END; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 577 | continue; |
| 578 | } |
| 579 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 580 | if (!(appctx->st1 & APPCTX_CLI_ST1_PAYLOAD)) { |
| 581 | /* seek for a possible unescaped semi-colon. If we find |
| 582 | * one, we replace it with an LF and skip only this part. |
| 583 | */ |
| 584 | for (len = 0; len < reql; len++) { |
| 585 | if (str[len] == '\\') { |
| 586 | len++; |
| 587 | continue; |
| 588 | } |
| 589 | if (str[len] == ';') { |
| 590 | str[len] = '\n'; |
| 591 | reql = len + 1; |
| 592 | break; |
| 593 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | /* now it is time to check that we have a full line, |
| 598 | * remove the trailing \n and possibly \r, then cut the |
| 599 | * line. |
| 600 | */ |
| 601 | len = reql - 1; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 602 | if (str[len] != '\n') { |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 603 | appctx->st0 = CLI_ST_END; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 604 | continue; |
| 605 | } |
| 606 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 607 | if (len && str[len-1] == '\r') |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 608 | len--; |
| 609 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 610 | str[len] = '\0'; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 611 | appctx->chunk->data += len; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 612 | |
| 613 | if (appctx->st1 & APPCTX_CLI_ST1_PAYLOAD) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 614 | appctx->chunk->area[appctx->chunk->data] = '\n'; |
| 615 | appctx->chunk->area[appctx->chunk->data + 1] = 0; |
| 616 | appctx->chunk->data++; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 617 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 618 | |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 619 | appctx->st0 = CLI_ST_PROMPT; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 620 | |
| 621 | if (appctx->st1 & APPCTX_CLI_ST1_PAYLOAD) { |
| 622 | /* empty line */ |
| 623 | if (!len) { |
| 624 | /* remove the last two \n */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 625 | appctx->chunk->data -= 2; |
| 626 | appctx->chunk->area[appctx->chunk->data] = 0; |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 627 | |
| 628 | if (!cli_parse_request(appctx)) |
| 629 | cli_gen_usage_msg(appctx); |
| 630 | |
| 631 | chunk_reset(appctx->chunk); |
| 632 | /* NB: cli_sock_parse_request() may have put |
| 633 | * another CLI_ST_O_* into appctx->st0. |
| 634 | */ |
| 635 | |
| 636 | appctx->st1 &= ~APPCTX_CLI_ST1_PAYLOAD; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 637 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 638 | } |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 639 | else { |
| 640 | /* |
| 641 | * Look for the "payload start" pattern at the end of a line |
| 642 | * Its location is not remembered here, this is just to switch |
| 643 | * to a gathering mode. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 644 | */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 645 | if (!strcmp(appctx->chunk->area + appctx->chunk->data - strlen(PAYLOAD_PATTERN), PAYLOAD_PATTERN)) |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 646 | appctx->st1 |= APPCTX_CLI_ST1_PAYLOAD; |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 647 | else { |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 648 | /* no payload, the command is complete: parse the request */ |
| 649 | if (!cli_parse_request(appctx)) |
| 650 | cli_gen_usage_msg(appctx); |
| 651 | |
| 652 | chunk_reset(appctx->chunk); |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 653 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* re-adjust req buffer */ |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 657 | co_skip(si_oc(si), reql); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 658 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
| 659 | } |
| 660 | else { /* output functions */ |
| 661 | switch (appctx->st0) { |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 662 | case CLI_ST_PROMPT: |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 663 | break; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 664 | case CLI_ST_PRINT: |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 665 | if (cli_output_msg(res, appctx->ctx.cli.msg, appctx->ctx.cli.severity, |
| 666 | cli_get_severity_output(appctx)) != -1) |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 667 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 668 | else |
| 669 | si_applet_cant_put(si); |
| 670 | break; |
Aurélien Nephtali | c511b7c | 2018-04-16 18:50:19 +0200 | [diff] [blame] | 671 | case CLI_ST_PRINT_FREE: { |
| 672 | const char *msg = appctx->ctx.cli.err; |
| 673 | |
| 674 | if (!msg) |
| 675 | msg = "Out of memory.\n"; |
| 676 | |
| 677 | if (cli_output_msg(res, msg, LOG_ERR, cli_get_severity_output(appctx)) != -1) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 678 | free(appctx->ctx.cli.err); |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 679 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 680 | } |
| 681 | else |
| 682 | si_applet_cant_put(si); |
| 683 | break; |
Aurélien Nephtali | c511b7c | 2018-04-16 18:50:19 +0200 | [diff] [blame] | 684 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 685 | case CLI_ST_CALLBACK: /* use custom pointer */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 686 | if (appctx->io_handler) |
| 687 | if (appctx->io_handler(appctx)) { |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 688 | appctx->st0 = CLI_ST_PROMPT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 689 | if (appctx->io_release) { |
| 690 | appctx->io_release(appctx); |
| 691 | appctx->io_release = NULL; |
| 692 | } |
| 693 | } |
| 694 | break; |
| 695 | default: /* abnormal state */ |
| 696 | si->flags |= SI_FL_ERR; |
| 697 | break; |
| 698 | } |
| 699 | |
| 700 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 701 | if (appctx->st0 == CLI_ST_PROMPT) { |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 702 | const char *prompt = ""; |
| 703 | |
| 704 | if (appctx->st1 & APPCTX_CLI_ST1_PROMPT) { |
| 705 | /* |
| 706 | * when entering a payload with interactive mode, change the prompt |
| 707 | * to emphasize that more data can still be sent |
| 708 | */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 709 | if (appctx->chunk->data && appctx->st1 & APPCTX_CLI_ST1_PAYLOAD) |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 710 | prompt = "+ "; |
| 711 | else |
| 712 | prompt = "\n> "; |
| 713 | } |
| 714 | else { |
| 715 | if (!(appctx->st1 & APPCTX_CLI_ST1_PAYLOAD)) |
| 716 | prompt = "\n"; |
| 717 | } |
| 718 | |
| 719 | if (ci_putstr(si_ic(si), prompt) != -1) |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 720 | appctx->st0 = CLI_ST_GETREQ; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 721 | else |
| 722 | si_applet_cant_put(si); |
| 723 | } |
| 724 | |
| 725 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 726 | if (appctx->st0 >= CLI_ST_OUTPUT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | /* Now we close the output if one of the writers did so, |
| 730 | * or if we're not in interactive mode and the request |
| 731 | * buffer is empty. This still allows pipelined requests |
| 732 | * to be sent in non-interactive mode. |
| 733 | */ |
Willy Tarreau | 851d12c | 2018-06-19 07:01:36 +0200 | [diff] [blame] | 734 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!(appctx->st1 & APPCTX_CLI_ST1_PROMPT) && !co_data(req))) { |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 735 | appctx->st0 = CLI_ST_END; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 736 | continue; |
| 737 | } |
| 738 | |
| 739 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 740 | appctx->st0 = CLI_ST_GETREQ; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
| 745 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 746 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 747 | /* Other side has closed, let's abort if we have no more processing to do |
| 748 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 749 | * we forward the close to the request side so that it flows upstream to |
| 750 | * the client. |
| 751 | */ |
| 752 | si_shutw(si); |
| 753 | } |
| 754 | |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 755 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < CLI_ST_OUTPUT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 756 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 757 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 758 | /* We have no more processing to do, and nothing more to send, and |
| 759 | * the client side has closed. So we'll forward this state downstream |
| 760 | * on the response buffer. |
| 761 | */ |
| 762 | si_shutr(si); |
| 763 | res->flags |= CF_READ_NULL; |
| 764 | } |
| 765 | |
| 766 | out: |
Christopher Faulet | 4507351 | 2018-07-20 10:16:29 +0200 | [diff] [blame] | 767 | DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rqh=%lu, rqs=%lu, rh=%lu, rs=%lu\n", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 768 | __FUNCTION__, __LINE__, |
Christopher Faulet | 4507351 | 2018-07-20 10:16:29 +0200 | [diff] [blame] | 769 | si->state, req->flags, res->flags, ci_data(req), co_data(req), ci_data(res), co_data(res)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 770 | } |
| 771 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 772 | /* This is called when the stream interface is closed. For instance, upon an |
| 773 | * external abort, we won't call the i/o handler anymore so we may need to |
| 774 | * remove back references to the stream currently being dumped. |
| 775 | */ |
| 776 | static void cli_release_handler(struct appctx *appctx) |
| 777 | { |
| 778 | if (appctx->io_release) { |
| 779 | appctx->io_release(appctx); |
| 780 | appctx->io_release = NULL; |
| 781 | } |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 782 | else if (appctx->st0 == CLI_ST_PRINT_FREE) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 783 | free(appctx->ctx.cli.err); |
| 784 | appctx->ctx.cli.err = NULL; |
| 785 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 789 | * if the output buffer is full and it needs to be called again, otherwise |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 790 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. It uses cli.p0 as the |
| 791 | * pointer to the current variable. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 792 | */ |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 793 | static int cli_io_handler_show_env(struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 794 | { |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 795 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 796 | char **var = appctx->ctx.cli.p0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 797 | |
| 798 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 799 | return 1; |
| 800 | |
| 801 | chunk_reset(&trash); |
| 802 | |
| 803 | /* we have two inner loops here, one for the proxy, the other one for |
| 804 | * the buffer. |
| 805 | */ |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 806 | while (*var) { |
| 807 | chunk_printf(&trash, "%s\n", *var); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 808 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 809 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 810 | si_applet_cant_put(si); |
| 811 | return 0; |
| 812 | } |
| 813 | if (appctx->st2 == STAT_ST_END) |
| 814 | break; |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 815 | var++; |
| 816 | appctx->ctx.cli.p0 = var; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | /* dump complete */ |
| 820 | return 1; |
| 821 | } |
| 822 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 823 | /* This function dumps all file descriptors states (or the requested one) to |
| 824 | * the buffer. It returns 0 if the output buffer is full and it needs to be |
| 825 | * called again, otherwise non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 826 | * It uses cli.i0 as the fd number to restart from. |
| 827 | */ |
| 828 | static int cli_io_handler_show_fd(struct appctx *appctx) |
| 829 | { |
| 830 | struct stream_interface *si = appctx->owner; |
| 831 | int fd = appctx->ctx.cli.i0; |
| 832 | |
| 833 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 834 | return 1; |
| 835 | |
| 836 | chunk_reset(&trash); |
| 837 | |
| 838 | /* we have two inner loops here, one for the proxy, the other one for |
| 839 | * the buffer. |
| 840 | */ |
Aurélien Nephtali | 498a115 | 2018-03-09 18:51:16 +0100 | [diff] [blame] | 841 | while (fd >= 0 && fd < global.maxsock) { |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 842 | struct fdtab fdt; |
Willy Tarreau | 286ec68 | 2017-08-09 16:35:44 +0200 | [diff] [blame] | 843 | struct listener *li = NULL; |
| 844 | struct server *sv = NULL; |
| 845 | struct proxy *px = NULL; |
Willy Tarreau | a833cd9 | 2018-03-29 13:19:37 +0200 | [diff] [blame] | 846 | const struct mux_ops *mux = NULL; |
Willy Tarreau | 35b1b48 | 2018-03-28 18:41:30 +0200 | [diff] [blame] | 847 | void *ctx = NULL; |
Willy Tarreau | 286ec68 | 2017-08-09 16:35:44 +0200 | [diff] [blame] | 848 | uint32_t conn_flags = 0; |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 849 | |
Willy Tarreau | bf9fd65 | 2018-08-02 11:05:48 +0200 | [diff] [blame] | 850 | thread_isolate(); |
| 851 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 852 | fdt = fdtab[fd]; |
| 853 | |
Willy Tarreau | bf9fd65 | 2018-08-02 11:05:48 +0200 | [diff] [blame] | 854 | if (!fdt.owner) { |
| 855 | thread_release(); |
Willy Tarreau | 017af24 | 2017-10-04 20:24:54 +0200 | [diff] [blame] | 856 | goto skip; // closed |
Willy Tarreau | bf9fd65 | 2018-08-02 11:05:48 +0200 | [diff] [blame] | 857 | } |
Willy Tarreau | 017af24 | 2017-10-04 20:24:54 +0200 | [diff] [blame] | 858 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 859 | if (fdt.iocb == conn_fd_handler) { |
| 860 | conn_flags = ((struct connection *)fdt.owner)->flags; |
Willy Tarreau | 35b1b48 | 2018-03-28 18:41:30 +0200 | [diff] [blame] | 861 | mux = ((struct connection *)fdt.owner)->mux; |
| 862 | ctx = ((struct connection *)fdt.owner)->mux_ctx; |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 863 | li = objt_listener(((struct connection *)fdt.owner)->target); |
| 864 | sv = objt_server(((struct connection *)fdt.owner)->target); |
| 865 | px = objt_proxy(((struct connection *)fdt.owner)->target); |
| 866 | } |
| 867 | else if (fdt.iocb == listener_accept) |
| 868 | li = fdt.owner; |
| 869 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 870 | chunk_printf(&trash, |
Willy Tarreau | c754b34 | 2018-03-30 15:00:15 +0200 | [diff] [blame] | 871 | " %5d : st=0x%02x(R:%c%c%c W:%c%c%c) ev=0x%02x(%c%c%c%c%c) [%c%c] cnext=%d cprev=%d tmask=0x%lx umask=0x%lx owner=%p iocb=%p(%s)", |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 872 | fd, |
| 873 | fdt.state, |
| 874 | (fdt.state & FD_EV_POLLED_R) ? 'P' : 'p', |
| 875 | (fdt.state & FD_EV_READY_R) ? 'R' : 'r', |
| 876 | (fdt.state & FD_EV_ACTIVE_R) ? 'A' : 'a', |
| 877 | (fdt.state & FD_EV_POLLED_W) ? 'P' : 'p', |
| 878 | (fdt.state & FD_EV_READY_W) ? 'R' : 'r', |
| 879 | (fdt.state & FD_EV_ACTIVE_W) ? 'A' : 'a', |
| 880 | fdt.ev, |
| 881 | (fdt.ev & FD_POLL_HUP) ? 'H' : 'h', |
| 882 | (fdt.ev & FD_POLL_ERR) ? 'E' : 'e', |
| 883 | (fdt.ev & FD_POLL_OUT) ? 'O' : 'o', |
| 884 | (fdt.ev & FD_POLL_PRI) ? 'P' : 'p', |
| 885 | (fdt.ev & FD_POLL_IN) ? 'I' : 'i', |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 886 | fdt.linger_risk ? 'L' : 'l', |
| 887 | fdt.cloned ? 'C' : 'c', |
Willy Tarreau | c754b34 | 2018-03-30 15:00:15 +0200 | [diff] [blame] | 888 | fdt.cache.next, |
| 889 | fdt.cache.prev, |
| 890 | fdt.thread_mask, fdt.update_mask, |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 891 | fdt.owner, |
| 892 | fdt.iocb, |
| 893 | (fdt.iocb == conn_fd_handler) ? "conn_fd_handler" : |
| 894 | (fdt.iocb == dgram_fd_handler) ? "dgram_fd_handler" : |
| 895 | (fdt.iocb == listener_accept) ? "listener_accept" : |
Olivier Houchard | 79321b9 | 2018-07-26 17:55:11 +0200 | [diff] [blame] | 896 | (fdt.iocb == poller_pipe_io_handler) ? "poller_pipe_io_handler" : |
Willy Tarreau | c754b34 | 2018-03-30 15:00:15 +0200 | [diff] [blame] | 897 | "unknown"); |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 898 | |
| 899 | if (fdt.iocb == conn_fd_handler) { |
| 900 | chunk_appendf(&trash, " cflg=0x%08x", conn_flags); |
| 901 | if (px) |
| 902 | chunk_appendf(&trash, " px=%s", px->id); |
| 903 | else if (sv) |
| 904 | chunk_appendf(&trash, " sv=%s/%s", sv->id, sv->proxy->id); |
| 905 | else if (li) |
| 906 | chunk_appendf(&trash, " fe=%s", li->bind_conf->frontend->id); |
Willy Tarreau | 35b1b48 | 2018-03-28 18:41:30 +0200 | [diff] [blame] | 907 | |
Willy Tarreau | b011d8f | 2018-03-30 14:41:19 +0200 | [diff] [blame] | 908 | if (mux) { |
Willy Tarreau | 35b1b48 | 2018-03-28 18:41:30 +0200 | [diff] [blame] | 909 | chunk_appendf(&trash, " mux=%s mux_ctx=%p", mux->name, ctx); |
Willy Tarreau | b011d8f | 2018-03-30 14:41:19 +0200 | [diff] [blame] | 910 | if (mux->show_fd) |
| 911 | mux->show_fd(&trash, fdt.owner); |
| 912 | } |
Willy Tarreau | 35b1b48 | 2018-03-28 18:41:30 +0200 | [diff] [blame] | 913 | else |
| 914 | chunk_appendf(&trash, " nomux"); |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 915 | } |
| 916 | else if (fdt.iocb == listener_accept) { |
| 917 | chunk_appendf(&trash, " l.st=%s fe=%s", |
| 918 | listener_state_str(li), |
| 919 | li->bind_conf->frontend->id); |
| 920 | } |
| 921 | |
Willy Tarreau | bf9fd65 | 2018-08-02 11:05:48 +0200 | [diff] [blame] | 922 | thread_release(); |
| 923 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 924 | chunk_appendf(&trash, "\n"); |
| 925 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 926 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 927 | si_applet_cant_put(si); |
| 928 | return 0; |
| 929 | } |
| 930 | skip: |
| 931 | if (appctx->st2 == STAT_ST_END) |
| 932 | break; |
| 933 | |
| 934 | fd++; |
| 935 | appctx->ctx.cli.i0 = fd; |
| 936 | } |
| 937 | |
| 938 | /* dump complete */ |
| 939 | return 1; |
| 940 | } |
| 941 | |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 942 | /* This function dumps some activity counters used by developers and support to |
| 943 | * rule out some hypothesis during bug reports. It returns 0 if the output |
| 944 | * buffer is full and it needs to be called again, otherwise non-zero. It dumps |
| 945 | * everything at once in the buffer and is not designed to do it in multiple |
| 946 | * passes. |
| 947 | */ |
| 948 | static int cli_io_handler_show_activity(struct appctx *appctx) |
| 949 | { |
| 950 | struct stream_interface *si = appctx->owner; |
| 951 | int thr; |
| 952 | |
| 953 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 954 | return 1; |
| 955 | |
| 956 | chunk_reset(&trash); |
| 957 | |
| 958 | chunk_appendf(&trash, "thread_id: %u", tid); |
| 959 | chunk_appendf(&trash, "\ndate_now: %lu.%06lu", (long)now.tv_sec, (long)now.tv_usec); |
| 960 | chunk_appendf(&trash, "\nloops:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].loops); |
| 961 | chunk_appendf(&trash, "\nwake_cache:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].wake_cache); |
| 962 | chunk_appendf(&trash, "\nwake_tasks:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].wake_tasks); |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 963 | chunk_appendf(&trash, "\nwake_signal:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].wake_signal); |
| 964 | chunk_appendf(&trash, "\npoll_exp:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].poll_exp); |
| 965 | chunk_appendf(&trash, "\npoll_drop:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].poll_drop); |
| 966 | chunk_appendf(&trash, "\npoll_dead:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].poll_dead); |
| 967 | chunk_appendf(&trash, "\npoll_skip:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].poll_skip); |
| 968 | chunk_appendf(&trash, "\nfd_skip:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].fd_skip); |
| 969 | chunk_appendf(&trash, "\nfd_lock:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].fd_lock); |
| 970 | chunk_appendf(&trash, "\nfd_del:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].fd_del); |
| 971 | chunk_appendf(&trash, "\nconn_dead:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].conn_dead); |
| 972 | chunk_appendf(&trash, "\nstream:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].stream); |
| 973 | chunk_appendf(&trash, "\nempty_rq:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].empty_rq); |
| 974 | chunk_appendf(&trash, "\nlong_rq:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].long_rq); |
Willy Tarreau | ed72d82 | 2018-10-17 19:01:24 +0200 | [diff] [blame] | 975 | chunk_appendf(&trash, "\ncpust_tot:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", activity[thr].cpust_total/2); |
| 976 | chunk_appendf(&trash, "\ncpust_1s:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", read_freq_ctr(&activity[thr].cpust_1s)/2); |
| 977 | chunk_appendf(&trash, "\ncpust_15s:"); for (thr = 0; thr < global.nbthread; thr++) chunk_appendf(&trash, " %u", read_freq_ctr_period(&activity[thr].cpust_15s, 15000)/2); |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 978 | |
| 979 | chunk_appendf(&trash, "\n"); |
| 980 | |
| 981 | if (ci_putchk(si_ic(si), &trash) == -1) { |
| 982 | chunk_reset(&trash); |
| 983 | chunk_printf(&trash, "[output too large, cannot dump]\n"); |
| 984 | si_applet_cant_put(si); |
| 985 | } |
| 986 | |
| 987 | /* dump complete */ |
| 988 | return 1; |
| 989 | } |
| 990 | |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 991 | /* |
Willy Tarreau | 3af9d83 | 2016-12-16 12:58:09 +0100 | [diff] [blame] | 992 | * CLI IO handler for `show cli sockets`. |
| 993 | * Uses ctx.cli.p0 to store the restart pointer. |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 994 | */ |
| 995 | static int cli_io_handler_show_cli_sock(struct appctx *appctx) |
| 996 | { |
| 997 | struct bind_conf *bind_conf; |
| 998 | struct stream_interface *si = appctx->owner; |
| 999 | |
| 1000 | chunk_reset(&trash); |
| 1001 | |
| 1002 | switch (appctx->st2) { |
| 1003 | case STAT_ST_INIT: |
| 1004 | chunk_printf(&trash, "# socket lvl processes\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1005 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1006 | si_applet_cant_put(si); |
| 1007 | return 0; |
| 1008 | } |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1009 | appctx->st2 = STAT_ST_LIST; |
| 1010 | |
| 1011 | case STAT_ST_LIST: |
| 1012 | if (global.stats_fe) { |
| 1013 | list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { |
| 1014 | struct listener *l; |
| 1015 | |
| 1016 | /* |
Willy Tarreau | 3af9d83 | 2016-12-16 12:58:09 +0100 | [diff] [blame] | 1017 | * get the latest dumped node in appctx->ctx.cli.p0 |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1018 | * if the current node is the first of the list |
| 1019 | */ |
| 1020 | |
Willy Tarreau | 3af9d83 | 2016-12-16 12:58:09 +0100 | [diff] [blame] | 1021 | if (appctx->ctx.cli.p0 && |
| 1022 | &bind_conf->by_fe == (&global.stats_fe->conf.bind)->n) { |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1023 | /* change the current node to the latest dumped and continue the loop */ |
Willy Tarreau | 3af9d83 | 2016-12-16 12:58:09 +0100 | [diff] [blame] | 1024 | bind_conf = LIST_ELEM(appctx->ctx.cli.p0, typeof(bind_conf), by_fe); |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1025 | continue; |
| 1026 | } |
| 1027 | |
| 1028 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 1029 | |
| 1030 | char addr[46]; |
| 1031 | char port[6]; |
| 1032 | |
| 1033 | if (l->addr.ss_family == AF_UNIX) { |
| 1034 | const struct sockaddr_un *un; |
| 1035 | |
| 1036 | un = (struct sockaddr_un *)&l->addr; |
| 1037 | chunk_appendf(&trash, "%s ", un->sun_path); |
| 1038 | } else if (l->addr.ss_family == AF_INET) { |
| 1039 | addr_to_str(&l->addr, addr, sizeof(addr)); |
| 1040 | port_to_str(&l->addr, port, sizeof(port)); |
| 1041 | chunk_appendf(&trash, "%s:%s ", addr, port); |
| 1042 | } else if (l->addr.ss_family == AF_INET6) { |
| 1043 | addr_to_str(&l->addr, addr, sizeof(addr)); |
| 1044 | port_to_str(&l->addr, port, sizeof(port)); |
| 1045 | chunk_appendf(&trash, "[%s]:%s ", addr, port); |
| 1046 | } else |
| 1047 | continue; |
| 1048 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 1049 | if ((bind_conf->level & ACCESS_LVL_MASK) == ACCESS_LVL_ADMIN) |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1050 | chunk_appendf(&trash, "admin "); |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 1051 | else if ((bind_conf->level & ACCESS_LVL_MASK) == ACCESS_LVL_OPER) |
| 1052 | chunk_appendf(&trash, "operator "); |
| 1053 | else if ((bind_conf->level & ACCESS_LVL_MASK) == ACCESS_LVL_USER) |
| 1054 | chunk_appendf(&trash, "user "); |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1055 | else |
| 1056 | chunk_appendf(&trash, " "); |
| 1057 | |
| 1058 | if (bind_conf->bind_proc != 0) { |
| 1059 | int pos; |
Willy Tarreau | 20c5e52 | 2016-12-16 12:50:55 +0100 | [diff] [blame] | 1060 | for (pos = 0; pos < 8 * sizeof(bind_conf->bind_proc); pos++) { |
Willy Tarreau | 4305ac7 | 2016-12-16 12:56:31 +0100 | [diff] [blame] | 1061 | if (bind_conf->bind_proc & (1UL << pos)) { |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1062 | chunk_appendf(&trash, "%d,", pos+1); |
| 1063 | } |
| 1064 | } |
| 1065 | /* replace the latest comma by a newline */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 1066 | trash.area[trash.data-1] = '\n'; |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1067 | |
| 1068 | } else { |
| 1069 | chunk_appendf(&trash, "all\n"); |
| 1070 | } |
| 1071 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 1072 | if (ci_putchk(si_ic(si), &trash) == -1) { |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1073 | si_applet_cant_put(si); |
| 1074 | return 0; |
| 1075 | } |
| 1076 | } |
Willy Tarreau | 3af9d83 | 2016-12-16 12:58:09 +0100 | [diff] [blame] | 1077 | appctx->ctx.cli.p0 = &bind_conf->by_fe; /* store the latest list node dumped */ |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | default: |
| 1081 | appctx->st2 = STAT_ST_FIN; |
| 1082 | return 1; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1087 | /* parse a "show env" CLI request. Returns 0 if it needs to continue, 1 if it |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1088 | * wants to stop here. It puts the variable to be dumped into cli.p0 if a single |
| 1089 | * variable is requested otherwise puts environ there. |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1090 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1091 | static int cli_parse_show_env(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1092 | { |
| 1093 | extern char **environ; |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1094 | char **var; |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1095 | |
| 1096 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 1097 | return 1; |
| 1098 | |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1099 | var = environ; |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1100 | |
| 1101 | if (*args[2]) { |
| 1102 | int len = strlen(args[2]); |
| 1103 | |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1104 | for (; *var; var++) { |
| 1105 | if (strncmp(*var, args[2], len) == 0 && |
| 1106 | (*var)[len] == '=') |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1107 | break; |
| 1108 | } |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1109 | if (!*var) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1110 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1111 | appctx->ctx.cli.msg = "Variable not found\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1112 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1113 | return 1; |
| 1114 | } |
| 1115 | appctx->st2 = STAT_ST_END; |
| 1116 | } |
Willy Tarreau | f6710f8 | 2016-12-16 17:45:44 +0100 | [diff] [blame] | 1117 | appctx->ctx.cli.p0 = var; |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1118 | return 0; |
| 1119 | } |
| 1120 | |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 1121 | /* parse a "show fd" CLI request. Returns 0 if it needs to continue, 1 if it |
| 1122 | * wants to stop here. It puts the FD number into cli.i0 if a specific FD is |
| 1123 | * requested and sets st2 to STAT_ST_END, otherwise leaves 0 in i0. |
| 1124 | */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1125 | static int cli_parse_show_fd(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 1126 | { |
| 1127 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 1128 | return 1; |
| 1129 | |
| 1130 | appctx->ctx.cli.i0 = 0; |
| 1131 | |
| 1132 | if (*args[2]) { |
| 1133 | appctx->ctx.cli.i0 = atoi(args[2]); |
| 1134 | appctx->st2 = STAT_ST_END; |
| 1135 | } |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1139 | /* parse a "set timeout" CLI request. It always returns 1. */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1140 | static int cli_parse_set_timeout(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1141 | { |
| 1142 | struct stream_interface *si = appctx->owner; |
| 1143 | struct stream *s = si_strm(si); |
| 1144 | |
| 1145 | if (strcmp(args[2], "cli") == 0) { |
| 1146 | unsigned timeout; |
| 1147 | const char *res; |
| 1148 | |
| 1149 | if (!*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1150 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1151 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1152 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1153 | return 1; |
| 1154 | } |
| 1155 | |
| 1156 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1157 | if (res || timeout < 1) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1158 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1159 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1160 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1161 | return 1; |
| 1162 | } |
| 1163 | |
| 1164 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1165 | task_wakeup(s->task, TASK_WOKEN_MSG); // recompute timeouts |
| 1166 | return 1; |
| 1167 | } |
| 1168 | else { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1169 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1170 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1171 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1172 | return 1; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1176 | /* parse a "set maxconn global" command. It always returns 1. */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1177 | static int cli_parse_set_maxconn_global(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1178 | { |
| 1179 | int v; |
| 1180 | |
| 1181 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1182 | return 1; |
| 1183 | |
| 1184 | if (!*args[3]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1185 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1186 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1187 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1188 | return 1; |
| 1189 | } |
| 1190 | |
| 1191 | v = atoi(args[3]); |
| 1192 | if (v > global.hardmaxconn) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1193 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1194 | appctx->ctx.cli.msg = "Value out of range.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1195 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1196 | return 1; |
| 1197 | } |
| 1198 | |
| 1199 | /* check for unlimited values */ |
| 1200 | if (v <= 0) |
| 1201 | v = global.hardmaxconn; |
| 1202 | |
| 1203 | global.maxconn = v; |
| 1204 | |
| 1205 | /* Dequeues all of the listeners waiting for a resource */ |
| 1206 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1207 | dequeue_all_listeners(&global_listener_queue); |
| 1208 | |
| 1209 | return 1; |
| 1210 | } |
| 1211 | |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1212 | static int set_severity_output(int *target, char *argument) |
| 1213 | { |
| 1214 | if (!strcmp(argument, "none")) { |
| 1215 | *target = CLI_SEVERITY_NONE; |
| 1216 | return 1; |
| 1217 | } |
| 1218 | else if (!strcmp(argument, "number")) { |
| 1219 | *target = CLI_SEVERITY_NUMBER; |
| 1220 | return 1; |
| 1221 | } |
| 1222 | else if (!strcmp(argument, "string")) { |
| 1223 | *target = CLI_SEVERITY_STRING; |
| 1224 | return 1; |
| 1225 | } |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | /* parse a "set severity-output" command. */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1230 | static int cli_parse_set_severity_output(char **args, char *payload, struct appctx *appctx, void *private) |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1231 | { |
| 1232 | if (*args[2] && set_severity_output(&appctx->cli_severity_output, args[2])) |
| 1233 | return 0; |
| 1234 | |
| 1235 | appctx->ctx.cli.severity = LOG_ERR; |
Aurélien Nephtali | 6e8a41d | 2018-03-15 21:48:50 +0100 | [diff] [blame] | 1236 | appctx->ctx.cli.msg = "one of 'none', 'number', 'string' is a required argument\n"; |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1237 | appctx->st0 = CLI_ST_PRINT; |
| 1238 | return 1; |
| 1239 | } |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1240 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1241 | int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private) |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1242 | { |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1246 | /* parse a "set rate-limit" command. It always returns 1. */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1247 | static int cli_parse_set_ratelimit(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1248 | { |
| 1249 | int v; |
| 1250 | int *res; |
| 1251 | int mul = 1; |
| 1252 | |
| 1253 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 1254 | return 1; |
| 1255 | |
| 1256 | if (strcmp(args[2], "connections") == 0 && strcmp(args[3], "global") == 0) |
| 1257 | res = &global.cps_lim; |
| 1258 | else if (strcmp(args[2], "sessions") == 0 && strcmp(args[3], "global") == 0) |
| 1259 | res = &global.sps_lim; |
| 1260 | #ifdef USE_OPENSSL |
| 1261 | else if (strcmp(args[2], "ssl-sessions") == 0 && strcmp(args[3], "global") == 0) |
| 1262 | res = &global.ssl_lim; |
| 1263 | #endif |
| 1264 | else if (strcmp(args[2], "http-compression") == 0 && strcmp(args[3], "global") == 0) { |
| 1265 | res = &global.comp_rate_lim; |
| 1266 | mul = 1024; |
| 1267 | } |
| 1268 | else { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1269 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1270 | appctx->ctx.cli.msg = |
| 1271 | "'set rate-limit' only supports :\n" |
| 1272 | " - 'connections global' to set the per-process maximum connection rate\n" |
| 1273 | " - 'sessions global' to set the per-process maximum session rate\n" |
| 1274 | #ifdef USE_OPENSSL |
Aurélien Nephtali | b53e208 | 2018-03-11 16:55:02 +0100 | [diff] [blame] | 1275 | " - 'ssl-sessions global' to set the per-process maximum SSL session rate\n" |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1276 | #endif |
| 1277 | " - 'http-compression global' to set the per-process maximum compression speed in kB/s\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1278 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1279 | return 1; |
| 1280 | } |
| 1281 | |
| 1282 | if (!*args[4]) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1283 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1284 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1285 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1286 | return 1; |
| 1287 | } |
| 1288 | |
| 1289 | v = atoi(args[4]); |
| 1290 | if (v < 0) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 1291 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1292 | appctx->ctx.cli.msg = "Value out of range.\n"; |
Willy Tarreau | 3b6e547 | 2016-11-24 15:53:53 +0100 | [diff] [blame] | 1293 | appctx->st0 = CLI_ST_PRINT; |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1294 | return 1; |
| 1295 | } |
| 1296 | |
| 1297 | *res = v * mul; |
| 1298 | |
| 1299 | /* Dequeues all of the listeners waiting for a resource */ |
| 1300 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1301 | dequeue_all_listeners(&global_listener_queue); |
| 1302 | |
| 1303 | return 1; |
| 1304 | } |
| 1305 | |
William Lallemand | f6975e9 | 2017-05-26 17:42:10 +0200 | [diff] [blame] | 1306 | /* parse the "expose-fd" argument on the bind lines */ |
| 1307 | static int bind_parse_expose_fd(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 1308 | { |
| 1309 | if (!*args[cur_arg + 1]) { |
| 1310 | memprintf(err, "'%s' : missing fd type", args[cur_arg]); |
| 1311 | return ERR_ALERT | ERR_FATAL; |
| 1312 | } |
| 1313 | if (!strcmp(args[cur_arg+1], "listeners")) { |
| 1314 | conf->level |= ACCESS_FD_LISTENERS; |
| 1315 | } else { |
| 1316 | memprintf(err, "'%s' only supports 'listeners' (got '%s')", |
| 1317 | args[cur_arg], args[cur_arg+1]); |
| 1318 | return ERR_ALERT | ERR_FATAL; |
| 1319 | } |
| 1320 | |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1324 | /* parse the "level" argument on the bind lines */ |
| 1325 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 1326 | { |
| 1327 | if (!*args[cur_arg + 1]) { |
| 1328 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 1329 | return ERR_ALERT | ERR_FATAL; |
| 1330 | } |
| 1331 | |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 1332 | if (!strcmp(args[cur_arg+1], "user")) { |
| 1333 | conf->level &= ~ACCESS_LVL_MASK; |
| 1334 | conf->level |= ACCESS_LVL_USER; |
| 1335 | } else if (!strcmp(args[cur_arg+1], "operator")) { |
| 1336 | conf->level &= ~ACCESS_LVL_MASK; |
| 1337 | conf->level |= ACCESS_LVL_OPER; |
| 1338 | } else if (!strcmp(args[cur_arg+1], "admin")) { |
| 1339 | conf->level &= ~ACCESS_LVL_MASK; |
| 1340 | conf->level |= ACCESS_LVL_ADMIN; |
| 1341 | } else { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1342 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 1343 | args[cur_arg], args[cur_arg+1]); |
| 1344 | return ERR_ALERT | ERR_FATAL; |
| 1345 | } |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1350 | static int bind_parse_severity_output(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 1351 | { |
| 1352 | if (!*args[cur_arg + 1]) { |
| 1353 | memprintf(err, "'%s' : missing severity format", args[cur_arg]); |
| 1354 | return ERR_ALERT | ERR_FATAL; |
| 1355 | } |
| 1356 | |
| 1357 | if (set_severity_output(&conf->severity_output, args[cur_arg+1])) |
| 1358 | return 0; |
| 1359 | else { |
| 1360 | memprintf(err, "'%s' only supports 'none', 'number', and 'string' (got '%s')", |
| 1361 | args[cur_arg], args[cur_arg+1]); |
| 1362 | return ERR_ALERT | ERR_FATAL; |
| 1363 | } |
| 1364 | } |
| 1365 | |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1366 | /* Send all the bound sockets, always returns 1 */ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1367 | static int _getsocks(char **args, char *payload, struct appctx *appctx, void *private) |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1368 | { |
| 1369 | char *cmsgbuf = NULL; |
| 1370 | unsigned char *tmpbuf = NULL; |
| 1371 | struct cmsghdr *cmsg; |
| 1372 | struct stream_interface *si = appctx->owner; |
William Lallemand | f6975e9 | 2017-05-26 17:42:10 +0200 | [diff] [blame] | 1373 | struct stream *s = si_strm(si); |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 1374 | struct connection *remote = cs_conn(objt_cs(si_opposite(si)->end)); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1375 | struct msghdr msghdr; |
| 1376 | struct iovec iov; |
Olivier Houchard | 5474087 | 2017-04-06 14:45:14 +0200 | [diff] [blame] | 1377 | struct timeval tv = { .tv_sec = 1, .tv_usec = 0 }; |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1378 | int *tmpfd; |
| 1379 | int tot_fd_nb = 0; |
| 1380 | struct proxy *px; |
| 1381 | int i = 0; |
Willy Tarreau | c2b7f80 | 2018-09-20 11:22:29 +0200 | [diff] [blame] | 1382 | int fd = -1; |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1383 | int curoff = 0; |
Willy Tarreau | c2b7f80 | 2018-09-20 11:22:29 +0200 | [diff] [blame] | 1384 | int old_fcntl = -1; |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1385 | int ret; |
| 1386 | |
Willy Tarreau | c2b7f80 | 2018-09-20 11:22:29 +0200 | [diff] [blame] | 1387 | if (!remote) { |
| 1388 | ha_warning("Only works on real connections\n"); |
| 1389 | goto out; |
| 1390 | } |
| 1391 | |
| 1392 | fd = remote->handle.fd; |
| 1393 | |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1394 | /* Temporary set the FD in blocking mode, that will make our life easier */ |
| 1395 | old_fcntl = fcntl(fd, F_GETFL); |
| 1396 | if (old_fcntl < 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1397 | ha_warning("Couldn't get the flags for the unix socket\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1398 | goto out; |
| 1399 | } |
| 1400 | cmsgbuf = malloc(CMSG_SPACE(sizeof(int) * MAX_SEND_FD)); |
| 1401 | if (!cmsgbuf) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1402 | ha_warning("Failed to allocate memory to send sockets\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1403 | goto out; |
| 1404 | } |
| 1405 | if (fcntl(fd, F_SETFL, old_fcntl &~ O_NONBLOCK) == -1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1406 | ha_warning("Cannot make the unix socket blocking\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1407 | goto out; |
| 1408 | } |
Olivier Houchard | 5474087 | 2017-04-06 14:45:14 +0200 | [diff] [blame] | 1409 | setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1410 | iov.iov_base = &tot_fd_nb; |
| 1411 | iov.iov_len = sizeof(tot_fd_nb); |
William Lallemand | f6975e9 | 2017-05-26 17:42:10 +0200 | [diff] [blame] | 1412 | if (!(strm_li(s)->bind_conf->level & ACCESS_FD_LISTENERS)) |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1413 | goto out; |
| 1414 | memset(&msghdr, 0, sizeof(msghdr)); |
| 1415 | /* |
| 1416 | * First, calculates the total number of FD, so that we can let |
| 1417 | * the caller know how much he should expects. |
| 1418 | */ |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1419 | px = proxies_list; |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1420 | while (px) { |
| 1421 | struct listener *l; |
| 1422 | |
| 1423 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Olivier Houchard | 1fc0516 | 2017-04-06 01:05:05 +0200 | [diff] [blame] | 1424 | /* Only transfer IPv4/IPv6/UNIX sockets */ |
| 1425 | if (l->state >= LI_ZOMBIE && |
| 1426 | (l->proto->sock_family == AF_INET || |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1427 | l->proto->sock_family == AF_INET6 || |
Olivier Houchard | 1fc0516 | 2017-04-06 01:05:05 +0200 | [diff] [blame] | 1428 | l->proto->sock_family == AF_UNIX)) |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1429 | tot_fd_nb++; |
| 1430 | } |
| 1431 | px = px->next; |
| 1432 | } |
| 1433 | if (tot_fd_nb == 0) |
| 1434 | goto out; |
| 1435 | |
| 1436 | /* First send the total number of file descriptors, so that the |
| 1437 | * receiving end knows what to expect. |
| 1438 | */ |
| 1439 | msghdr.msg_iov = &iov; |
| 1440 | msghdr.msg_iovlen = 1; |
| 1441 | ret = sendmsg(fd, &msghdr, 0); |
| 1442 | if (ret != sizeof(tot_fd_nb)) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1443 | ha_warning("Failed to send the number of sockets to send\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1444 | goto out; |
| 1445 | } |
| 1446 | |
| 1447 | /* Now send the fds */ |
| 1448 | msghdr.msg_control = cmsgbuf; |
| 1449 | msghdr.msg_controllen = CMSG_SPACE(sizeof(int) * MAX_SEND_FD); |
| 1450 | cmsg = CMSG_FIRSTHDR(&msghdr); |
| 1451 | cmsg->cmsg_len = CMSG_LEN(MAX_SEND_FD * sizeof(int)); |
| 1452 | cmsg->cmsg_level = SOL_SOCKET; |
| 1453 | cmsg->cmsg_type = SCM_RIGHTS; |
| 1454 | tmpfd = (int *)CMSG_DATA(cmsg); |
| 1455 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 1456 | px = proxies_list; |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1457 | /* For each socket, e message is sent, containing the following : |
| 1458 | * Size of the namespace name (or 0 if none), as an unsigned char. |
| 1459 | * The namespace name, if any |
| 1460 | * Size of the interface name (or 0 if none), as an unsigned char |
| 1461 | * The interface name, if any |
| 1462 | * Listener options, as an int. |
| 1463 | */ |
| 1464 | /* We will send sockets MAX_SEND_FD per MAX_SEND_FD, allocate a |
| 1465 | * buffer big enough to store the socket informations. |
| 1466 | */ |
Olivier Houchard | f143b80 | 2017-11-04 15:13:01 +0100 | [diff] [blame] | 1467 | tmpbuf = malloc(MAX_SEND_FD * (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int))); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1468 | if (tmpbuf == NULL) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1469 | ha_warning("Failed to allocate memory to transfer socket informations\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1470 | goto out; |
| 1471 | } |
| 1472 | iov.iov_base = tmpbuf; |
| 1473 | while (px) { |
| 1474 | struct listener *l; |
| 1475 | |
| 1476 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
| 1477 | int ret; |
| 1478 | /* Only transfer IPv4/IPv6 sockets */ |
Olivier Houchard | 1fc0516 | 2017-04-06 01:05:05 +0200 | [diff] [blame] | 1479 | if (l->state >= LI_ZOMBIE && |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1480 | (l->proto->sock_family == AF_INET || |
| 1481 | l->proto->sock_family == AF_INET6 || |
| 1482 | l->proto->sock_family == AF_UNIX)) { |
| 1483 | memcpy(&tmpfd[i % MAX_SEND_FD], &l->fd, sizeof(l->fd)); |
| 1484 | if (!l->netns) |
| 1485 | tmpbuf[curoff++] = 0; |
| 1486 | #ifdef CONFIG_HAP_NS |
| 1487 | else { |
| 1488 | char *name = l->netns->node.key; |
| 1489 | unsigned char len = l->netns->name_len; |
| 1490 | tmpbuf[curoff++] = len; |
| 1491 | memcpy(tmpbuf + curoff, name, len); |
| 1492 | curoff += len; |
| 1493 | } |
| 1494 | #endif |
| 1495 | if (l->interface) { |
| 1496 | unsigned char len = strlen(l->interface); |
| 1497 | tmpbuf[curoff++] = len; |
| 1498 | memcpy(tmpbuf + curoff, l->interface, len); |
| 1499 | curoff += len; |
| 1500 | } else |
| 1501 | tmpbuf[curoff++] = 0; |
| 1502 | memcpy(tmpbuf + curoff, &l->options, |
| 1503 | sizeof(l->options)); |
| 1504 | curoff += sizeof(l->options); |
| 1505 | |
| 1506 | |
| 1507 | i++; |
| 1508 | } else |
| 1509 | continue; |
| 1510 | if ((!(i % MAX_SEND_FD))) { |
| 1511 | iov.iov_len = curoff; |
| 1512 | if (sendmsg(fd, &msghdr, 0) != curoff) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1513 | ha_warning("Failed to transfer sockets\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1514 | goto out; |
| 1515 | } |
| 1516 | /* Wait for an ack */ |
| 1517 | do { |
| 1518 | ret = recv(fd, &tot_fd_nb, |
| 1519 | sizeof(tot_fd_nb), 0); |
| 1520 | } while (ret == -1 && errno == EINTR); |
| 1521 | if (ret <= 0) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1522 | ha_warning("Unexpected error while transferring sockets\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1523 | goto out; |
| 1524 | } |
| 1525 | curoff = 0; |
| 1526 | } |
| 1527 | |
| 1528 | } |
| 1529 | px = px->next; |
| 1530 | } |
| 1531 | if (i % MAX_SEND_FD) { |
| 1532 | iov.iov_len = curoff; |
| 1533 | cmsg->cmsg_len = CMSG_LEN((i % MAX_SEND_FD) * sizeof(int)); |
| 1534 | msghdr.msg_controllen = CMSG_SPACE(sizeof(int) * (i % MAX_SEND_FD)); |
| 1535 | if (sendmsg(fd, &msghdr, 0) != curoff) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1536 | ha_warning("Failed to transfer sockets\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1537 | goto out; |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | out: |
Willy Tarreau | c2b7f80 | 2018-09-20 11:22:29 +0200 | [diff] [blame] | 1542 | if (fd >= 0 && old_fcntl >= 0 && fcntl(fd, F_SETFL, old_fcntl) == -1) { |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 1543 | ha_warning("Cannot make the unix socket non-blocking\n"); |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1544 | goto out; |
| 1545 | } |
| 1546 | appctx->st0 = CLI_ST_END; |
| 1547 | free(cmsgbuf); |
| 1548 | free(tmpbuf); |
| 1549 | return 1; |
| 1550 | } |
| 1551 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1552 | static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, void *private) |
| 1553 | { |
| 1554 | if (*args[0] == 'h') |
| 1555 | /* help */ |
| 1556 | cli_gen_usage_msg(appctx); |
| 1557 | else if (*args[0] == 'p') |
| 1558 | /* prompt */ |
| 1559 | appctx->st1 ^= APPCTX_CLI_ST1_PROMPT; |
| 1560 | else if (*args[0] == 'q') |
| 1561 | /* quit */ |
| 1562 | appctx->st0 = CLI_ST_END; |
| 1563 | |
| 1564 | return 1; |
| 1565 | } |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1566 | |
| 1567 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1568 | static struct applet cli_applet = { |
| 1569 | .obj_type = OBJ_TYPE_APPLET, |
| 1570 | .name = "<CLI>", /* used for logging */ |
| 1571 | .fct = cli_io_handler, |
| 1572 | .release = cli_release_handler, |
| 1573 | }; |
| 1574 | |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1575 | /* register cli keywords */ |
| 1576 | static struct cli_kw_list cli_kws = {{ },{ |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 1577 | { { "help", NULL }, NULL, cli_parse_simple, NULL }, |
| 1578 | { { "prompt", NULL }, NULL, cli_parse_simple, NULL }, |
| 1579 | { { "quit", NULL }, NULL, cli_parse_simple, NULL }, |
Willy Tarreau | 2af9941 | 2016-11-23 11:10:59 +0100 | [diff] [blame] | 1580 | { { "set", "maxconn", "global", NULL }, "set maxconn global : change the per-process maxconn setting", cli_parse_set_maxconn_global, NULL }, |
Willy Tarreau | 45c742b | 2016-11-24 14:51:17 +0100 | [diff] [blame] | 1581 | { { "set", "rate-limit", NULL }, "set rate-limit : change a rate limiting value", cli_parse_set_ratelimit, NULL }, |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1582 | { { "set", "severity-output", NULL }, "set severity-output [none|number|string] : set presence of severity level in feedback information", cli_parse_set_severity_output, NULL, NULL }, |
Willy Tarreau | 599852e | 2016-11-22 20:33:32 +0100 | [diff] [blame] | 1583 | { { "set", "timeout", NULL }, "set timeout : change a timeout setting", cli_parse_set_timeout, NULL, NULL }, |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1584 | { { "show", "env", NULL }, "show env [var] : dump environment variables known to the process", cli_parse_show_env, cli_io_handler_show_env, NULL }, |
William Lallemand | eceddf7 | 2016-12-15 18:06:44 +0100 | [diff] [blame] | 1585 | { { "show", "cli", "sockets", NULL }, "show cli sockets : dump list of cli sockets", cli_parse_default, cli_io_handler_show_cli_sock, NULL }, |
Willy Tarreau | 7a4a0ac | 2017-07-25 19:32:50 +0200 | [diff] [blame] | 1586 | { { "show", "fd", NULL }, "show fd [num] : dump list of file descriptors in use", cli_parse_show_fd, cli_io_handler_show_fd, NULL }, |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 1587 | { { "show", "activity", NULL }, "show activity : show per-thread activity stats (for support/developers)", cli_parse_default, cli_io_handler_show_activity, NULL }, |
Olivier Houchard | f886e34 | 2017-04-05 22:24:59 +0200 | [diff] [blame] | 1588 | { { "_getsocks", NULL }, NULL, _getsocks, NULL }, |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1589 | {{},} |
| 1590 | }}; |
| 1591 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1592 | static struct cfg_kw_list cfg_kws = {ILH, { |
| 1593 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 1594 | { 0, NULL, NULL }, |
| 1595 | }}; |
| 1596 | |
| 1597 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
William Lallemand | f6975e9 | 2017-05-26 17:42:10 +0200 | [diff] [blame] | 1598 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 1599 | { "expose-fd", bind_parse_expose_fd, 1 }, /* set the unix socket expose fd rights */ |
Andjelko Iharos | c4df59e | 2017-07-20 11:59:48 +0200 | [diff] [blame] | 1600 | { "severity-output", bind_parse_severity_output, 1 }, /* set the severity output format */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1601 | { NULL, NULL, 0 }, |
| 1602 | }}; |
| 1603 | |
| 1604 | __attribute__((constructor)) |
| 1605 | static void __dumpstats_module_init(void) |
| 1606 | { |
| 1607 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | 0a73929 | 2016-11-22 20:21:23 +0100 | [diff] [blame] | 1608 | cli_register_kw(&cli_kws); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1609 | bind_register_keywords(&bind_kws); |
| 1610 | } |
| 1611 | |
| 1612 | /* |
| 1613 | * Local variables: |
| 1614 | * c-indent-level: 8 |
| 1615 | * c-basic-offset: 8 |
| 1616 | * End: |
| 1617 | */ |