Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Event sink management |
| 3 | * |
| 4 | * Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation, version 2.1 |
| 9 | * exclusively. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 21 | #include <sys/mman.h> |
| 22 | #include <errno.h> |
| 23 | #include <fcntl.h> |
| 24 | |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 25 | #include <import/ist.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 26 | #include <haproxy/api.h> |
Christopher Faulet | 6b0a0fb | 2022-04-04 11:29:28 +0200 | [diff] [blame] | 27 | #include <haproxy/applet.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 28 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 29 | #include <haproxy/cli.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 30 | #include <haproxy/errors.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 31 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 32 | #include <haproxy/log.h> |
Willy Tarreau | 817538e | 2021-05-08 20:20:21 +0200 | [diff] [blame] | 33 | #include <haproxy/proxy.h> |
Willy Tarreau | d2ad57c | 2020-06-03 19:43:35 +0200 | [diff] [blame] | 34 | #include <haproxy/ring.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 35 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 3727a8a | 2020-06-04 17:37:26 +0200 | [diff] [blame] | 36 | #include <haproxy/signal.h> |
Willy Tarreau | ba2f73d | 2020-06-03 20:02:28 +0200 | [diff] [blame] | 37 | #include <haproxy/sink.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 38 | #include <haproxy/stconn.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/time.h> |
Willy Tarreau | 4bad5e2 | 2021-05-08 13:05:30 +0200 | [diff] [blame] | 40 | #include <haproxy/tools.h> |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 41 | |
| 42 | struct list sink_list = LIST_HEAD_INIT(sink_list); |
| 43 | |
Emeric Brun | d6e581d | 2022-09-13 16:16:30 +0200 | [diff] [blame] | 44 | /* sink proxies list */ |
| 45 | struct proxy *sink_proxies_list; |
| 46 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 47 | struct sink *cfg_sink; |
| 48 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 49 | struct sink *sink_find(const char *name) |
| 50 | { |
| 51 | struct sink *sink; |
| 52 | |
| 53 | list_for_each_entry(sink, &sink_list, sink_list) |
| 54 | if (strcmp(sink->name, name) == 0) |
| 55 | return sink; |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | /* creates a new sink and adds it to the list, it's still generic and not fully |
| 60 | * initialized. Returns NULL on allocation failure. If another one already |
| 61 | * exists with the same name, it will be returned. The caller can detect it as |
| 62 | * a newly created one has type SINK_TYPE_NEW. |
| 63 | */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 64 | static struct sink *__sink_new(const char *name, const char *desc, int fmt) |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 65 | { |
| 66 | struct sink *sink; |
| 67 | |
| 68 | sink = sink_find(name); |
| 69 | if (sink) |
| 70 | goto end; |
| 71 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 72 | sink = calloc(1, sizeof(*sink)); |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 73 | if (!sink) |
| 74 | goto end; |
| 75 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 76 | sink->name = strdup(name); |
Tim Duesterhus | a7ebffe | 2021-01-03 19:54:11 +0100 | [diff] [blame] | 77 | if (!sink->name) |
| 78 | goto err; |
| 79 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 80 | sink->desc = strdup(desc); |
Tim Duesterhus | a7ebffe | 2021-01-03 19:54:11 +0100 | [diff] [blame] | 81 | if (!sink->desc) |
| 82 | goto err; |
| 83 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 84 | sink->fmt = fmt; |
| 85 | sink->type = SINK_TYPE_NEW; |
Christopher Faulet | a63a5c2 | 2019-11-15 15:10:12 +0100 | [diff] [blame] | 86 | sink->maxlen = BUFSIZE; |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 87 | /* address will be filled by the caller if needed */ |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 88 | sink->ctx.fd = -1; |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 89 | sink->ctx.dropped = 0; |
| 90 | HA_RWLOCK_INIT(&sink->ctx.lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 91 | LIST_APPEND(&sink_list, &sink->sink_list); |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 92 | end: |
| 93 | return sink; |
Tim Duesterhus | a7ebffe | 2021-01-03 19:54:11 +0100 | [diff] [blame] | 94 | |
| 95 | err: |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 96 | ha_free(&sink->name); |
| 97 | ha_free(&sink->desc); |
| 98 | ha_free(&sink); |
Tim Duesterhus | a7ebffe | 2021-01-03 19:54:11 +0100 | [diff] [blame] | 99 | |
| 100 | return NULL; |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 103 | /* creates a sink called <name> of type FD associated to fd <fd>, format <fmt>, |
| 104 | * and description <desc>. Returns NULL on allocation failure or conflict. |
| 105 | * Perfect duplicates are merged (same type, fd, and name). |
| 106 | */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 107 | struct sink *sink_new_fd(const char *name, const char *desc, enum log_fmt fmt, int fd) |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 108 | { |
| 109 | struct sink *sink; |
| 110 | |
| 111 | sink = __sink_new(name, desc, fmt); |
| 112 | if (!sink || (sink->type == SINK_TYPE_FD && sink->ctx.fd == fd)) |
| 113 | goto end; |
| 114 | |
| 115 | if (sink->type != SINK_TYPE_NEW) { |
| 116 | sink = NULL; |
| 117 | goto end; |
| 118 | } |
| 119 | |
| 120 | sink->type = SINK_TYPE_FD; |
| 121 | sink->ctx.fd = fd; |
| 122 | end: |
| 123 | return sink; |
| 124 | } |
| 125 | |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 126 | /* creates a sink called <name> of type BUF of size <size>, format <fmt>, |
| 127 | * and description <desc>. Returns NULL on allocation failure or conflict. |
| 128 | * Perfect duplicates are merged (same type and name). If sizes differ, the |
| 129 | * largest one is kept. |
| 130 | */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 131 | struct sink *sink_new_buf(const char *name, const char *desc, enum log_fmt fmt, size_t size) |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 132 | { |
| 133 | struct sink *sink; |
| 134 | |
| 135 | sink = __sink_new(name, desc, fmt); |
| 136 | if (!sink) |
| 137 | goto fail; |
| 138 | |
| 139 | if (sink->type == SINK_TYPE_BUFFER) { |
| 140 | /* such a buffer already exists, we may have to resize it */ |
| 141 | if (!ring_resize(sink->ctx.ring, size)) |
| 142 | goto fail; |
| 143 | goto end; |
| 144 | } |
| 145 | |
| 146 | if (sink->type != SINK_TYPE_NEW) { |
| 147 | /* already exists of another type */ |
| 148 | goto fail; |
| 149 | } |
| 150 | |
| 151 | sink->ctx.ring = ring_new(size); |
| 152 | if (!sink->ctx.ring) { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 153 | LIST_DELETE(&sink->sink_list); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 154 | free(sink->name); |
| 155 | free(sink->desc); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 156 | free(sink); |
| 157 | goto fail; |
| 158 | } |
| 159 | |
| 160 | sink->type = SINK_TYPE_BUFFER; |
| 161 | end: |
| 162 | return sink; |
| 163 | fail: |
| 164 | return NULL; |
| 165 | } |
| 166 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 167 | /* tries to send <nmsg> message parts (up to 8, ignored above) from message |
Ilya Shipitsin | 46a030c | 2020-07-05 16:36:08 +0500 | [diff] [blame] | 168 | * array <msg> to sink <sink>. Formatting according to the sink's preference is |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 169 | * done here. Lost messages are NOT accounted for. It is preferable to call |
| 170 | * sink_write() instead which will also try to emit the number of dropped |
| 171 | * messages when there are any. It returns >0 if it could write anything, |
| 172 | * <=0 otherwise. |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 173 | */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 174 | ssize_t __sink_write(struct sink *sink, const struct ist msg[], size_t nmsg, |
| 175 | int level, int facility, struct ist *metadata) |
| 176 | { |
| 177 | struct ist *pfx = NULL; |
Willy Tarreau | a1426de | 2019-08-27 14:21:02 +0200 | [diff] [blame] | 178 | size_t npfx = 0; |
Emeric Brun | bd16381 | 2020-05-06 14:33:46 +0200 | [diff] [blame] | 179 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 180 | if (sink->fmt == LOG_FORMAT_RAW) |
Emeric Brun | bd16381 | 2020-05-06 14:33:46 +0200 | [diff] [blame] | 181 | goto send; |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 182 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 183 | pfx = build_log_header(sink->fmt, level, facility, metadata, &npfx); |
Emeric Brun | bd16381 | 2020-05-06 14:33:46 +0200 | [diff] [blame] | 184 | |
| 185 | send: |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 186 | if (sink->type == SINK_TYPE_FD) { |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 187 | return fd_write_frag_line(sink->ctx.fd, sink->maxlen, pfx, npfx, msg, nmsg, 1); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 188 | } |
| 189 | else if (sink->type == SINK_TYPE_BUFFER) { |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 190 | return ring_write(sink->ctx.ring, sink->maxlen, pfx, npfx, msg, nmsg); |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 191 | } |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 192 | return 0; |
| 193 | } |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 194 | |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 195 | /* Tries to emit a message indicating the number of dropped events. In case of |
| 196 | * success, the amount of drops is reduced by as much. It's supposed to be |
| 197 | * called under an exclusive lock on the sink to avoid multiple produces doing |
| 198 | * the same. On success, >0 is returned, otherwise <=0 on failure. |
| 199 | */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 200 | int sink_announce_dropped(struct sink *sink, int facility) |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 201 | { |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 202 | static THREAD_LOCAL struct ist metadata[LOG_META_FIELDS]; |
| 203 | static THREAD_LOCAL pid_t curr_pid; |
| 204 | static THREAD_LOCAL char pidstr[16]; |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 205 | unsigned int dropped; |
| 206 | struct buffer msg; |
| 207 | struct ist msgvec[1]; |
| 208 | char logbuf[64]; |
| 209 | |
| 210 | while (unlikely((dropped = sink->ctx.dropped) > 0)) { |
| 211 | chunk_init(&msg, logbuf, sizeof(logbuf)); |
| 212 | chunk_printf(&msg, "%u event%s dropped", dropped, dropped > 1 ? "s" : ""); |
| 213 | msgvec[0] = ist2(msg.area, msg.data); |
Emeric Brun | bd16381 | 2020-05-06 14:33:46 +0200 | [diff] [blame] | 214 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 215 | if (!metadata[LOG_META_HOST].len) { |
| 216 | if (global.log_send_hostname) |
Tim Duesterhus | 7750850 | 2022-03-15 13:11:06 +0100 | [diff] [blame] | 217 | metadata[LOG_META_HOST] = ist(global.log_send_hostname); |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if (!metadata[LOG_META_TAG].len) |
| 221 | metadata[LOG_META_TAG] = ist2(global.log_tag.area, global.log_tag.data); |
| 222 | |
| 223 | if (unlikely(curr_pid != getpid())) |
| 224 | metadata[LOG_META_PID].len = 0; |
| 225 | |
| 226 | if (!metadata[LOG_META_PID].len) { |
| 227 | curr_pid = getpid(); |
| 228 | ltoa_o(curr_pid, pidstr, sizeof(pidstr)); |
| 229 | metadata[LOG_META_PID] = ist2(pidstr, strlen(pidstr)); |
| 230 | } |
| 231 | |
| 232 | if (__sink_write(sink, msgvec, 1, LOG_NOTICE, facility, metadata) <= 0) |
Willy Tarreau | 8f24023 | 2019-08-27 16:41:06 +0200 | [diff] [blame] | 233 | return 0; |
| 234 | /* success! */ |
| 235 | HA_ATOMIC_SUB(&sink->ctx.dropped, dropped); |
| 236 | } |
| 237 | return 1; |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 240 | /* parse the "show events" command, returns 1 if a message is returned, otherwise zero */ |
| 241 | static int cli_parse_show_events(char **args, char *payload, struct appctx *appctx, void *private) |
| 242 | { |
| 243 | struct sink *sink; |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 244 | uint ring_flags; |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 245 | int arg; |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 246 | |
| 247 | args++; // make args[1] the 1st arg |
| 248 | |
| 249 | if (!*args[1]) { |
| 250 | /* no arg => report the list of supported sink */ |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 251 | chunk_printf(&trash, "Supported events sinks are listed below. Add -w(wait), -n(new). Any key to stop\n"); |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 252 | list_for_each_entry(sink, &sink_list, sink_list) { |
| 253 | chunk_appendf(&trash, " %-10s : type=%s, %u dropped, %s\n", |
| 254 | sink->name, |
| 255 | sink->type == SINK_TYPE_NEW ? "init" : |
| 256 | sink->type == SINK_TYPE_FD ? "fd" : |
| 257 | sink->type == SINK_TYPE_BUFFER ? "buffer" : "?", |
| 258 | sink->ctx.dropped, sink->desc); |
| 259 | } |
| 260 | |
| 261 | trash.area[trash.data] = 0; |
| 262 | return cli_msg(appctx, LOG_WARNING, trash.area); |
| 263 | } |
| 264 | |
| 265 | if (!cli_has_level(appctx, ACCESS_LVL_OPER)) |
| 266 | return 1; |
| 267 | |
| 268 | sink = sink_find(args[1]); |
| 269 | if (!sink) |
| 270 | return cli_err(appctx, "No such event sink"); |
| 271 | |
| 272 | if (sink->type != SINK_TYPE_BUFFER) |
| 273 | return cli_msg(appctx, LOG_NOTICE, "Nothing to report for this sink"); |
| 274 | |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 275 | ring_flags = 0; |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 276 | for (arg = 2; *args[arg]; arg++) { |
| 277 | if (strcmp(args[arg], "-w") == 0) |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 278 | ring_flags |= RING_WF_WAIT_MODE; |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 279 | else if (strcmp(args[arg], "-n") == 0) |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 280 | ring_flags |= RING_WF_SEEK_NEW; |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 281 | else if (strcmp(args[arg], "-nw") == 0 || strcmp(args[arg], "-wn") == 0) |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 282 | ring_flags |= RING_WF_WAIT_MODE | RING_WF_SEEK_NEW; |
Willy Tarreau | 1d181e4 | 2019-08-30 11:17:01 +0200 | [diff] [blame] | 283 | else |
| 284 | return cli_err(appctx, "unknown option"); |
| 285 | } |
Willy Tarreau | cba8838 | 2022-05-05 15:18:57 +0200 | [diff] [blame] | 286 | return ring_attach_cli(sink->ctx.ring, appctx, ring_flags); |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 289 | /* Pre-configures a ring proxy to emit connections */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 290 | void sink_setup_proxy(struct proxy *px) |
| 291 | { |
Willy Tarreau | 69530f5 | 2023-04-28 09:16:15 +0200 | [diff] [blame] | 292 | px->last_change = ns_to_sec(now_ns); |
Christopher Faulet | 11a707a | 2022-10-24 15:10:18 +0200 | [diff] [blame] | 293 | px->cap = PR_CAP_BE; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 294 | px->maxconn = 0; |
| 295 | px->conn_retries = 1; |
| 296 | px->timeout.server = TICK_ETERNITY; |
| 297 | px->timeout.client = TICK_ETERNITY; |
| 298 | px->timeout.connect = TICK_ETERNITY; |
| 299 | px->accept = NULL; |
| 300 | px->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
Emeric Brun | d6e581d | 2022-09-13 16:16:30 +0200 | [diff] [blame] | 301 | px->next = sink_proxies_list; |
| 302 | sink_proxies_list = px; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 306 | * IO Handler to handle message push to syslog tcp server. |
| 307 | * It takes its context from appctx->svcctx. |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 308 | */ |
| 309 | static void sink_forward_io_handler(struct appctx *appctx) |
| 310 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 311 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 312 | struct stream *s = __sc_strm(sc); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 313 | struct sink *sink = strm_fe(s)->parent; |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 314 | struct sink_forward_target *sft = appctx->svcctx; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 315 | struct ring *ring = sink->ctx.ring; |
| 316 | struct buffer *buf = &ring->buf; |
| 317 | uint64_t msg_len; |
Willy Tarreau | 53bfab0 | 2022-08-04 17:18:54 +0200 | [diff] [blame] | 318 | size_t len, cnt, ofs, last_ofs; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 319 | int ret = 0; |
| 320 | |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 321 | if (unlikely(se_fl_test(appctx->sedesc, (SE_FL_EOS|SE_FL_ERROR|SE_FL_SHR|SE_FL_SHW)))) |
| 322 | goto out; |
| 323 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 324 | /* if stopping was requested, close immediately */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 325 | if (unlikely(stopping)) |
| 326 | goto close; |
| 327 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 328 | /* if the connection is not established, inform the stream that we want |
| 329 | * to be notified whenever the connection completes. |
| 330 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 331 | if (sc_opposite(sc)->state < SC_ST_EST) { |
Willy Tarreau | 90e8b45 | 2022-05-25 18:21:43 +0200 | [diff] [blame] | 332 | applet_need_more_data(appctx); |
Willy Tarreau | b23edc8 | 2022-05-24 16:49:03 +0200 | [diff] [blame] | 333 | se_need_remote_conn(appctx->sedesc); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 334 | applet_have_more_data(appctx); |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 335 | goto out; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 339 | if (appctx != sft->appctx) { |
| 340 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 341 | goto close; |
| 342 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 343 | |
| 344 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
| 345 | LIST_DEL_INIT(&appctx->wait_entry); |
| 346 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 347 | |
| 348 | HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); |
| 349 | |
| 350 | /* explanation for the initialization below: it would be better to do |
| 351 | * this in the parsing function but this would occasionally result in |
| 352 | * dropped events because we'd take a reference on the oldest message |
| 353 | * and keep it while being scheduled. Thus instead let's take it the |
| 354 | * first time we enter here so that we have a chance to pass many |
| 355 | * existing messages before grabbing a reference to a location. This |
| 356 | * value cannot be produced after initialization. |
| 357 | */ |
Aurelien DARRAGON | 2c98867 | 2023-03-07 16:09:33 +0100 | [diff] [blame] | 358 | if (unlikely(sft->ofs == ~0)) { |
| 359 | sft->ofs = b_peek_ofs(buf, 0); |
| 360 | HA_ATOMIC_INC(b_orig(buf) + sft->ofs); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 363 | /* we were already there, adjust the offset to be relative to |
| 364 | * the buffer's head and remove us from the counter. |
| 365 | */ |
| 366 | ofs = sft->ofs - b_head_ofs(buf); |
| 367 | if (sft->ofs < b_head_ofs(buf)) |
| 368 | ofs += b_size(buf); |
| 369 | BUG_ON(ofs >= buf->size); |
| 370 | HA_ATOMIC_DEC(b_peek(buf, ofs)); |
| 371 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 372 | /* in this loop, ofs always points to the counter byte that precedes |
| 373 | * the message so that we can take our reference there if we have to |
| 374 | * stop before the end (ret=0). |
| 375 | */ |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 376 | ret = 1; |
| 377 | while (ofs + 1 < b_data(buf)) { |
| 378 | cnt = 1; |
| 379 | len = b_peek_varint(buf, ofs + cnt, &msg_len); |
| 380 | if (!len) |
| 381 | break; |
| 382 | cnt += len; |
| 383 | BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf)); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 384 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 385 | if (unlikely(msg_len + 1 > b_size(&trash))) { |
| 386 | /* too large a message to ever fit, let's skip it */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 387 | ofs += cnt + msg_len; |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 388 | continue; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 391 | chunk_reset(&trash); |
| 392 | len = b_getblk(buf, trash.area, msg_len, ofs + cnt); |
| 393 | trash.data += len; |
| 394 | trash.area[trash.data++] = '\n'; |
| 395 | |
| 396 | if (applet_putchk(appctx, &trash) == -1) { |
| 397 | ret = 0; |
| 398 | break; |
| 399 | } |
| 400 | ofs += cnt + msg_len; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 401 | } |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 402 | |
| 403 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
| 404 | last_ofs = b_tail_ofs(buf); |
| 405 | sft->ofs = b_peek_ofs(buf, ofs); |
| 406 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 407 | HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 408 | |
| 409 | if (ret) { |
| 410 | /* let's be woken up once new data arrive */ |
| 411 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 412 | LIST_APPEND(&ring->waiters, &appctx->wait_entry); |
Willy Tarreau | d9c7188 | 2023-02-22 14:50:14 +0100 | [diff] [blame] | 413 | ofs = b_tail_ofs(buf); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 414 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 53bfab0 | 2022-08-04 17:18:54 +0200 | [diff] [blame] | 415 | if (ofs != last_ofs) { |
| 416 | /* more data was added into the ring between the |
| 417 | * unlock and the lock, and the writer might not |
| 418 | * have seen us. We need to reschedule a read. |
| 419 | */ |
| 420 | applet_have_more_data(appctx); |
| 421 | } else |
| 422 | applet_have_no_more_data(appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 423 | } |
| 424 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 425 | |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 426 | out: |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 427 | /* always drain data from server */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 428 | co_skip(sc_oc(sc), sc_oc(sc)->output); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 429 | return; |
| 430 | |
| 431 | close: |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 432 | se_fl_set(appctx->sedesc, SE_FL_EOS|SE_FL_EOI); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 435 | /* |
| 436 | * IO Handler to handle message push to syslog tcp server |
| 437 | * using octet counting frames |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 438 | * It takes its context from appctx->svcctx. |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 439 | */ |
| 440 | static void sink_forward_oc_io_handler(struct appctx *appctx) |
| 441 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 442 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 443 | struct stream *s = __sc_strm(sc); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 444 | struct sink *sink = strm_fe(s)->parent; |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 445 | struct sink_forward_target *sft = appctx->svcctx; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 446 | struct ring *ring = sink->ctx.ring; |
| 447 | struct buffer *buf = &ring->buf; |
| 448 | uint64_t msg_len; |
| 449 | size_t len, cnt, ofs; |
| 450 | int ret = 0; |
| 451 | char *p; |
| 452 | |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 453 | if (unlikely(se_fl_test(appctx->sedesc, (SE_FL_EOS|SE_FL_ERROR|SE_FL_SHR|SE_FL_SHW)))) |
| 454 | goto out; |
| 455 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 456 | /* if stopping was requested, close immediately */ |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 457 | if (unlikely(stopping)) |
| 458 | goto close; |
| 459 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 460 | /* if the connection is not established, inform the stream that we want |
| 461 | * to be notified whenever the connection completes. |
| 462 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 463 | if (sc_opposite(sc)->state < SC_ST_EST) { |
Willy Tarreau | 90e8b45 | 2022-05-25 18:21:43 +0200 | [diff] [blame] | 464 | applet_need_more_data(appctx); |
Willy Tarreau | b23edc8 | 2022-05-24 16:49:03 +0200 | [diff] [blame] | 465 | se_need_remote_conn(appctx->sedesc); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 466 | applet_have_more_data(appctx); |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 467 | goto out; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 471 | if (appctx != sft->appctx) { |
| 472 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 473 | goto close; |
| 474 | } |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 475 | |
| 476 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
| 477 | LIST_DEL_INIT(&appctx->wait_entry); |
| 478 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 479 | |
| 480 | HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); |
| 481 | |
| 482 | /* explanation for the initialization below: it would be better to do |
| 483 | * this in the parsing function but this would occasionally result in |
| 484 | * dropped events because we'd take a reference on the oldest message |
| 485 | * and keep it while being scheduled. Thus instead let's take it the |
| 486 | * first time we enter here so that we have a chance to pass many |
| 487 | * existing messages before grabbing a reference to a location. This |
| 488 | * value cannot be produced after initialization. |
| 489 | */ |
Aurelien DARRAGON | 2c98867 | 2023-03-07 16:09:33 +0100 | [diff] [blame] | 490 | if (unlikely(sft->ofs == ~0)) { |
| 491 | sft->ofs = b_peek_ofs(buf, 0); |
| 492 | HA_ATOMIC_INC(b_orig(buf) + sft->ofs); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 495 | /* we were already there, adjust the offset to be relative to |
| 496 | * the buffer's head and remove us from the counter. |
| 497 | */ |
| 498 | ofs = sft->ofs - b_head_ofs(buf); |
| 499 | if (sft->ofs < b_head_ofs(buf)) |
| 500 | ofs += b_size(buf); |
| 501 | BUG_ON(ofs >= buf->size); |
| 502 | HA_ATOMIC_DEC(b_peek(buf, ofs)); |
| 503 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 504 | /* in this loop, ofs always points to the counter byte that precedes |
| 505 | * the message so that we can take our reference there if we have to |
| 506 | * stop before the end (ret=0). |
| 507 | */ |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 508 | ret = 1; |
| 509 | while (ofs + 1 < b_data(buf)) { |
| 510 | cnt = 1; |
| 511 | len = b_peek_varint(buf, ofs + cnt, &msg_len); |
| 512 | if (!len) |
| 513 | break; |
| 514 | cnt += len; |
| 515 | BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf)); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 516 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 517 | chunk_reset(&trash); |
| 518 | p = ulltoa(msg_len, trash.area, b_size(&trash)); |
| 519 | if (p) { |
| 520 | trash.data = (p - trash.area) + 1; |
| 521 | *p = ' '; |
| 522 | } |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 523 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 524 | if (!p || (trash.data + msg_len > b_size(&trash))) { |
| 525 | /* too large a message to ever fit, let's skip it */ |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 526 | ofs += cnt + msg_len; |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 527 | continue; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 530 | trash.data += b_getblk(buf, p + 1, msg_len, ofs + cnt); |
| 531 | |
| 532 | if (applet_putchk(appctx, &trash) == -1) { |
| 533 | ret = 0; |
| 534 | break; |
| 535 | } |
| 536 | ofs += cnt + msg_len; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 537 | } |
Christopher Faulet | 4b86695 | 2023-03-31 11:24:48 +0200 | [diff] [blame] | 538 | |
| 539 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
| 540 | sft->ofs = b_peek_ofs(buf, ofs); |
| 541 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 542 | HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 543 | |
| 544 | if (ret) { |
| 545 | /* let's be woken up once new data arrive */ |
| 546 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 547 | LIST_APPEND(&ring->waiters, &appctx->wait_entry); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 548 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 549 | applet_have_no_more_data(appctx); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 550 | } |
| 551 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 552 | |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 553 | out: |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 554 | /* always drain data from server */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 555 | co_skip(sc_oc(sc), sc_oc(sc)->output); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 556 | return; |
| 557 | |
| 558 | close: |
Christopher Faulet | a739dc2 | 2023-03-31 11:25:55 +0200 | [diff] [blame] | 559 | se_fl_set(appctx->sedesc, SE_FL_EOS|SE_FL_EOI); |
| 560 | goto out; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 563 | void __sink_forward_session_deinit(struct sink_forward_target *sft) |
| 564 | { |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 565 | struct stream *s = appctx_strm(sft->appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 566 | struct sink *sink; |
| 567 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 568 | sink = strm_fe(s)->parent; |
| 569 | if (!sink) |
| 570 | return; |
| 571 | |
| 572 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); |
| 573 | LIST_DEL_INIT(&sft->appctx->wait_entry); |
| 574 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); |
| 575 | |
| 576 | sft->appctx = NULL; |
| 577 | task_wakeup(sink->forward_task, TASK_WOKEN_MSG); |
| 578 | } |
| 579 | |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 580 | static int sink_forward_session_init(struct appctx *appctx) |
| 581 | { |
| 582 | struct sink_forward_target *sft = appctx->svcctx; |
| 583 | struct stream *s; |
| 584 | struct sockaddr_storage *addr = NULL; |
| 585 | |
| 586 | if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr))) |
| 587 | goto out_error; |
| 588 | |
| 589 | if (appctx_finalize_startup(appctx, sft->sink->forward_px, &BUF_NULL) == -1) |
| 590 | goto out_free_addr; |
| 591 | |
| 592 | s = appctx_strm(appctx); |
Willy Tarreau | 7cb9e6c | 2022-05-17 19:40:40 +0200 | [diff] [blame] | 593 | s->scb->dst = addr; |
Christopher Faulet | 9a790f6 | 2023-03-16 14:40:03 +0100 | [diff] [blame] | 594 | s->scb->flags |= (SC_FL_RCV_ONCE|SC_FL_NOLINGER); |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 595 | |
| 596 | s->target = &sft->srv->obj_type; |
| 597 | s->flags = SF_ASSIGNED; |
| 598 | |
| 599 | s->do_log = NULL; |
| 600 | s->uniq_id = 0; |
| 601 | |
Christopher Faulet | 2ca4cc1 | 2023-02-22 14:22:56 +0100 | [diff] [blame] | 602 | applet_expect_no_data(appctx); |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 603 | sft->appctx = appctx; |
| 604 | |
| 605 | return 0; |
| 606 | |
| 607 | out_free_addr: |
| 608 | sockaddr_free(&addr); |
| 609 | out_error: |
| 610 | return -1; |
| 611 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 612 | |
| 613 | static void sink_forward_session_release(struct appctx *appctx) |
| 614 | { |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 615 | struct sink_forward_target *sft = appctx->svcctx; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 616 | |
| 617 | if (!sft) |
| 618 | return; |
| 619 | |
| 620 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 621 | if (sft->appctx == appctx) |
| 622 | __sink_forward_session_deinit(sft); |
| 623 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 624 | } |
| 625 | |
| 626 | static struct applet sink_forward_applet = { |
| 627 | .obj_type = OBJ_TYPE_APPLET, |
| 628 | .name = "<SINKFWD>", /* used for logging */ |
| 629 | .fct = sink_forward_io_handler, |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 630 | .init = sink_forward_session_init, |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 631 | .release = sink_forward_session_release, |
| 632 | }; |
| 633 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 634 | static struct applet sink_forward_oc_applet = { |
| 635 | .obj_type = OBJ_TYPE_APPLET, |
| 636 | .name = "<SINKFWDOC>", /* used for logging */ |
| 637 | .fct = sink_forward_oc_io_handler, |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 638 | .init = sink_forward_session_init, |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 639 | .release = sink_forward_session_release, |
| 640 | }; |
| 641 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 642 | /* |
| 643 | * Create a new peer session in assigned state (connect will start automatically) |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 644 | * It sets its context into appctx->svcctx. |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 645 | */ |
| 646 | static struct appctx *sink_forward_session_create(struct sink *sink, struct sink_forward_target *sft) |
| 647 | { |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 648 | struct appctx *appctx; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 649 | struct applet *applet = &sink_forward_applet; |
| 650 | |
| 651 | if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING) |
| 652 | applet = &sink_forward_oc_applet; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 653 | |
Christopher Faulet | 6095d57 | 2022-05-16 17:09:48 +0200 | [diff] [blame] | 654 | appctx = appctx_new_here(applet, NULL); |
Christopher Faulet | 2479e5f | 2022-01-19 14:50:11 +0100 | [diff] [blame] | 655 | if (!appctx) |
Christopher Faulet | a9e8b39 | 2022-03-23 11:01:09 +0100 | [diff] [blame] | 656 | goto out_close; |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 657 | appctx->svcctx = (void *)sft; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 658 | |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 659 | if (appctx_init(appctx) == -1) |
Christopher Faulet | 92202da | 2022-05-11 12:22:10 +0200 | [diff] [blame] | 660 | goto out_free_appctx; |
Christopher Faulet | 13a35e5 | 2021-12-20 15:34:16 +0100 | [diff] [blame] | 661 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 662 | return appctx; |
| 663 | |
| 664 | /* Error unrolling */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 665 | out_free_appctx: |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 666 | appctx_free_on_early_error(appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 667 | out_close: |
| 668 | return NULL; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * Task to handle connctions to forward servers |
| 673 | */ |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 674 | static struct task *process_sink_forward(struct task * task, void *context, unsigned int state) |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 675 | { |
| 676 | struct sink *sink = (struct sink *)context; |
| 677 | struct sink_forward_target *sft = sink->sft; |
| 678 | |
| 679 | task->expire = TICK_ETERNITY; |
| 680 | |
| 681 | if (!stopping) { |
| 682 | while (sft) { |
| 683 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 684 | /* if appctx is NULL, start a new session */ |
| 685 | if (!sft->appctx) |
| 686 | sft->appctx = sink_forward_session_create(sink, sft); |
| 687 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 688 | sft = sft->next; |
| 689 | } |
| 690 | } |
| 691 | else { |
| 692 | while (sft) { |
| 693 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 694 | /* awake applet to perform a clean close */ |
| 695 | if (sft->appctx) |
| 696 | appctx_wakeup(sft->appctx); |
| 697 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 698 | sft = sft->next; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return task; |
| 703 | } |
| 704 | /* |
| 705 | * Init task to manage connctions to forward servers |
| 706 | * |
| 707 | * returns 0 in case of error. |
| 708 | */ |
| 709 | int sink_init_forward(struct sink *sink) |
| 710 | { |
Willy Tarreau | beeabf5 | 2021-10-01 18:23:30 +0200 | [diff] [blame] | 711 | sink->forward_task = task_new_anywhere(); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 712 | if (!sink->forward_task) |
| 713 | return 0; |
| 714 | |
| 715 | sink->forward_task->process = process_sink_forward; |
| 716 | sink->forward_task->context = (void *)sink; |
| 717 | sink->forward_sighandler = signal_register_task(0, sink->forward_task, 0); |
| 718 | task_wakeup(sink->forward_task, TASK_WOKEN_INIT); |
| 719 | return 1; |
| 720 | } |
Willy Tarreau | 32872db | 2022-08-31 18:52:17 +0200 | [diff] [blame] | 721 | |
| 722 | /* This tries to rotate a file-backed ring, but only if it contains contents. |
| 723 | * This way empty rings will not cause backups to be overwritten and it's safe |
| 724 | * to reload multiple times. That's only best effort, failures are silently |
| 725 | * ignored. |
| 726 | */ |
| 727 | void sink_rotate_file_backed_ring(const char *name) |
| 728 | { |
| 729 | struct ring ring; |
| 730 | char *oldback; |
| 731 | int ret; |
| 732 | int fd; |
| 733 | |
| 734 | fd = open(name, O_RDONLY); |
| 735 | if (fd < 0) |
| 736 | return; |
| 737 | |
| 738 | /* check for contents validity */ |
| 739 | ret = read(fd, &ring, sizeof(ring)); |
| 740 | close(fd); |
| 741 | |
| 742 | if (ret != sizeof(ring)) |
| 743 | goto rotate; |
| 744 | |
| 745 | /* contents are present, we want to keep them => rotate. Note that |
| 746 | * an empty ring buffer has one byte (the marker). |
| 747 | */ |
| 748 | if (ring.buf.data > 1) |
| 749 | goto rotate; |
| 750 | |
| 751 | /* nothing to keep, let's scratch the file and preserve the backup */ |
| 752 | return; |
| 753 | |
| 754 | rotate: |
| 755 | oldback = NULL; |
| 756 | memprintf(&oldback, "%s.bak", name); |
| 757 | if (oldback) { |
| 758 | /* try to rename any possibly existing ring file to |
| 759 | * ".bak" and delete remains of older ones. This will |
| 760 | * ensure we don't wipe useful debug info upon restart. |
| 761 | */ |
| 762 | unlink(oldback); |
| 763 | if (rename(name, oldback) < 0) |
| 764 | unlink(oldback); |
| 765 | ha_free(&oldback); |
| 766 | } |
| 767 | } |
| 768 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 769 | /* |
| 770 | * Parse "ring" section and create corresponding sink buffer. |
| 771 | * |
| 772 | * The function returns 0 in success case, otherwise, it returns error |
| 773 | * flags. |
| 774 | */ |
| 775 | int cfg_parse_ring(const char *file, int linenum, char **args, int kwm) |
| 776 | { |
| 777 | int err_code = 0; |
| 778 | const char *inv; |
| 779 | size_t size = BUFSIZE; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 780 | struct proxy *p; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 781 | |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 782 | if (strcmp(args[0], "ring") == 0) { /* new ring section */ |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 783 | if (!*args[1]) { |
| 784 | ha_alert("parsing [%s:%d] : missing ring name.\n", file, linenum); |
| 785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 786 | goto err; |
| 787 | } |
| 788 | |
| 789 | inv = invalid_char(args[1]); |
| 790 | if (inv) { |
| 791 | ha_alert("parsing [%s:%d] : invalid ring name '%s' (character '%c' is not permitted).\n", file, linenum, args[1], *inv); |
| 792 | err_code |= ERR_ALERT | ERR_FATAL; |
| 793 | goto err; |
| 794 | } |
| 795 | |
| 796 | if (sink_find(args[1])) { |
| 797 | ha_alert("parsing [%s:%d] : sink named '%s' already exists.\n", file, linenum, args[1]); |
| 798 | err_code |= ERR_ALERT | ERR_FATAL; |
| 799 | goto err; |
| 800 | } |
| 801 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 802 | cfg_sink = sink_new_buf(args[1], args[1], LOG_FORMAT_RAW, size); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 803 | if (!cfg_sink || cfg_sink->type != SINK_TYPE_BUFFER) { |
| 804 | ha_alert("parsing [%s:%d] : unable to create a new sink buffer for ring '%s'.\n", file, linenum, args[1]); |
| 805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 806 | goto err; |
| 807 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 808 | |
| 809 | /* allocate new proxy to handle forwards */ |
| 810 | p = calloc(1, sizeof *p); |
| 811 | if (!p) { |
| 812 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 813 | err_code |= ERR_ALERT | ERR_FATAL; |
| 814 | goto err; |
| 815 | } |
| 816 | |
| 817 | init_new_proxy(p); |
| 818 | sink_setup_proxy(p); |
| 819 | p->parent = cfg_sink; |
| 820 | p->id = strdup(args[1]); |
| 821 | p->conf.args.file = p->conf.file = strdup(file); |
| 822 | p->conf.args.line = p->conf.line = linenum; |
| 823 | cfg_sink->forward_px = p; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 824 | } |
| 825 | else if (strcmp(args[0], "size") == 0) { |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 826 | if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) { |
| 827 | ha_alert("parsing [%s:%d] : 'size' directive not usable with this type of sink.\n", file, linenum); |
| 828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 829 | goto err; |
| 830 | } |
| 831 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 832 | size = atol(args[1]); |
| 833 | if (!size) { |
| 834 | ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]); |
| 835 | err_code |= ERR_ALERT | ERR_FATAL; |
| 836 | goto err; |
| 837 | } |
| 838 | |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 839 | if (cfg_sink->store) { |
| 840 | ha_alert("parsing [%s:%d] : cannot resize an already mapped file, please specify 'size' before 'backing-file'.\n", file, linenum); |
| 841 | err_code |= ERR_ALERT | ERR_FATAL; |
| 842 | goto err; |
| 843 | } |
| 844 | |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 845 | if (size < cfg_sink->ctx.ring->buf.size) { |
| 846 | ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than current size '%llu' for ring '%s'.\n", |
| 847 | file, linenum, (ullong)size, (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name); |
| 848 | err_code |= ERR_ALERT | ERR_FATAL; |
| 849 | goto err; |
| 850 | } |
| 851 | |
| 852 | if (!ring_resize(cfg_sink->ctx.ring, size)) { |
| 853 | ha_alert("parsing [%s:%d] : fail to set sink buffer size '%llu' for ring '%s'.\n", file, linenum, |
| 854 | (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 855 | err_code |= ERR_ALERT | ERR_FATAL; |
| 856 | goto err; |
| 857 | } |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 858 | } |
| 859 | else if (strcmp(args[0], "backing-file") == 0) { |
| 860 | /* This tries to mmap file <file> for size <size> and to use it as a backing store |
| 861 | * for ring <ring>. Existing data are delete. NULL is returned on error. |
| 862 | */ |
| 863 | const char *backing = args[1]; |
| 864 | size_t size; |
| 865 | void *area; |
| 866 | int fd; |
| 867 | |
| 868 | if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) { |
| 869 | ha_alert("parsing [%s:%d] : 'backing-file' only usable with existing rings.\n", file, linenum); |
| 870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 871 | goto err; |
| 872 | } |
| 873 | |
| 874 | if (cfg_sink->store) { |
| 875 | ha_alert("parsing [%s:%d] : 'backing-file' already specified for ring '%s' (was '%s').\n", file, linenum, cfg_sink->name, cfg_sink->store); |
| 876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 877 | goto err; |
| 878 | } |
| 879 | |
Willy Tarreau | 32872db | 2022-08-31 18:52:17 +0200 | [diff] [blame] | 880 | /* let's check if the file exists and is not empty. That's the |
| 881 | * only condition under which we'll trigger a rotate, so that |
| 882 | * config checks, reloads, or restarts that don't emit anything |
| 883 | * do not rotate it again. |
| 884 | */ |
| 885 | sink_rotate_file_backed_ring(backing); |
Willy Tarreau | ded77cc | 2022-08-12 15:38:20 +0200 | [diff] [blame] | 886 | |
Willy Tarreau | 8e87705 | 2022-08-12 15:03:12 +0200 | [diff] [blame] | 887 | fd = open(backing, O_RDWR | O_CREAT, 0600); |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 888 | if (fd < 0) { |
| 889 | ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno)); |
| 890 | err_code |= ERR_ALERT | ERR_FATAL; |
| 891 | goto err; |
| 892 | } |
| 893 | |
| 894 | size = (cfg_sink->ctx.ring->buf.size + 4095UL) & -4096UL; |
| 895 | if (ftruncate(fd, size) != 0) { |
| 896 | close(fd); |
| 897 | ha_alert("parsing [%s:%d] : could not adjust size of backing-file for ring '%s': %s.\n", file, linenum, cfg_sink->name, strerror(errno)); |
| 898 | err_code |= ERR_ALERT | ERR_FATAL; |
| 899 | goto err; |
| 900 | } |
| 901 | |
| 902 | area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 903 | if (area == MAP_FAILED) { |
| 904 | close(fd); |
| 905 | ha_alert("parsing [%s:%d] : failed to use '%s' as a backing file for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno)); |
| 906 | err_code |= ERR_ALERT | ERR_FATAL; |
| 907 | goto err; |
| 908 | } |
| 909 | |
| 910 | /* we don't need the file anymore */ |
| 911 | close(fd); |
| 912 | cfg_sink->store = strdup(backing); |
| 913 | |
| 914 | /* never fails */ |
| 915 | ring_free(cfg_sink->ctx.ring); |
| 916 | cfg_sink->ctx.ring = ring_make_from_area(area, size); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 917 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 918 | else if (strcmp(args[0],"server") == 0) { |
Willy Tarreau | 1b662aa | 2022-11-16 18:56:34 +0100 | [diff] [blame] | 919 | if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) { |
| 920 | ha_alert("parsing [%s:%d] : unable to create server '%s'.\n", file, linenum, args[1]); |
| 921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 922 | goto err; |
| 923 | } |
| 924 | |
Amaury Denoyelle | 30c0537 | 2021-03-08 16:36:46 +0100 | [diff] [blame] | 925 | err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL, |
| 926 | SRV_PARSE_PARSE_ADDR|SRV_PARSE_INITIAL_RESOLVE); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 927 | } |
| 928 | else if (strcmp(args[0],"timeout") == 0) { |
| 929 | if (!cfg_sink || !cfg_sink->forward_px) { |
| 930 | ha_alert("parsing [%s:%d] : unable to set timeout '%s'.\n", file, linenum, args[1]); |
| 931 | err_code |= ERR_ALERT | ERR_FATAL; |
| 932 | goto err; |
| 933 | } |
| 934 | |
| 935 | if (strcmp(args[1], "connect") == 0 || |
| 936 | strcmp(args[1], "server") == 0) { |
| 937 | const char *res; |
| 938 | unsigned int tout; |
| 939 | |
| 940 | if (!*args[2]) { |
| 941 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 942 | file, linenum, args[0], args[1]); |
| 943 | err_code |= ERR_ALERT | ERR_FATAL; |
| 944 | goto err; |
| 945 | } |
| 946 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
| 947 | if (res == PARSE_TIME_OVER) { |
| 948 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 949 | file, linenum, args[2], args[0], args[1]); |
| 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto err; |
| 952 | } |
| 953 | else if (res == PARSE_TIME_UNDER) { |
| 954 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n", |
| 955 | file, linenum, args[2], args[0], args[1]); |
| 956 | err_code |= ERR_ALERT | ERR_FATAL; |
| 957 | goto err; |
| 958 | } |
| 959 | else if (res) { |
| 960 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 961 | file, linenum, *res, args[0], args[1]); |
| 962 | err_code |= ERR_ALERT | ERR_FATAL; |
| 963 | goto err; |
| 964 | } |
Christopher Faulet | 321d100 | 2022-10-19 16:26:21 +0200 | [diff] [blame] | 965 | if (args[1][0] == 'c') |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 966 | cfg_sink->forward_px->timeout.connect = tout; |
| 967 | else |
| 968 | cfg_sink->forward_px->timeout.server = tout; |
| 969 | } |
| 970 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 971 | else if (strcmp(args[0],"format") == 0) { |
| 972 | if (!cfg_sink) { |
| 973 | ha_alert("parsing [%s:%d] : unable to set format '%s'.\n", file, linenum, args[1]); |
| 974 | err_code |= ERR_ALERT | ERR_FATAL; |
| 975 | goto err; |
| 976 | } |
| 977 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 978 | cfg_sink->fmt = get_log_format(args[1]); |
| 979 | if (cfg_sink->fmt == LOG_FORMAT_UNSPEC) { |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 980 | ha_alert("parsing [%s:%d] : unknown format '%s'.\n", file, linenum, args[1]); |
| 981 | err_code |= ERR_ALERT | ERR_FATAL; |
| 982 | goto err; |
| 983 | } |
| 984 | } |
| 985 | else if (strcmp(args[0],"maxlen") == 0) { |
| 986 | if (!cfg_sink) { |
| 987 | ha_alert("parsing [%s:%d] : unable to set event max length '%s'.\n", file, linenum, args[1]); |
| 988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 989 | goto err; |
| 990 | } |
| 991 | |
| 992 | cfg_sink->maxlen = atol(args[1]); |
| 993 | if (!cfg_sink->maxlen) { |
| 994 | ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]); |
| 995 | err_code |= ERR_ALERT | ERR_FATAL; |
| 996 | goto err; |
| 997 | } |
| 998 | } |
| 999 | else if (strcmp(args[0],"description") == 0) { |
| 1000 | if (!cfg_sink) { |
| 1001 | ha_alert("parsing [%s:%d] : unable to set description '%s'.\n", file, linenum, args[1]); |
| 1002 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1003 | goto err; |
| 1004 | } |
| 1005 | |
| 1006 | if (!*args[1]) { |
| 1007 | ha_alert("parsing [%s:%d] : missing ring description text.\n", file, linenum); |
| 1008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1009 | goto err; |
| 1010 | } |
| 1011 | |
| 1012 | free(cfg_sink->desc); |
| 1013 | |
| 1014 | cfg_sink->desc = strdup(args[1]); |
| 1015 | if (!cfg_sink->desc) { |
| 1016 | ha_alert("parsing [%s:%d] : fail to set description '%s'.\n", file, linenum, args[1]); |
| 1017 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1018 | goto err; |
| 1019 | } |
| 1020 | } |
Emeric Brun | 9f2ff3a | 2020-05-29 15:47:52 +0200 | [diff] [blame] | 1021 | else { |
| 1022 | ha_alert("parsing [%s:%d] : unknown statement '%s'.\n", file, linenum, args[0]); |
| 1023 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1024 | goto err; |
| 1025 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1026 | |
| 1027 | err: |
| 1028 | return err_code; |
| 1029 | } |
| 1030 | |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1031 | /* Creates an new sink buffer from a log server. |
| 1032 | * |
| 1033 | * It uses the logsrvaddress to declare a forward |
| 1034 | * server for this buffer. And it initializes the |
| 1035 | * forwarding. |
| 1036 | * |
| 1037 | * The function returns a pointer on the |
| 1038 | * allocated struct sink if allocate |
| 1039 | * and initialize succeed, else if it fails |
| 1040 | * it returns NULL. |
| 1041 | * |
| 1042 | * Note: the sink is created using the name |
Ilya Shipitsin | b2be9a1 | 2021-04-24 13:25:42 +0500 | [diff] [blame] | 1043 | * specified into logsrv->ring_name |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1044 | */ |
| 1045 | struct sink *sink_new_from_logsrv(struct logsrv *logsrv) |
| 1046 | { |
| 1047 | struct proxy *p = NULL; |
| 1048 | struct sink *sink = NULL; |
| 1049 | struct server *srv = NULL; |
| 1050 | struct sink_forward_target *sft = NULL; |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1051 | |
| 1052 | /* allocate new proxy to handle |
| 1053 | * forward to a stream server |
| 1054 | */ |
| 1055 | p = calloc(1, sizeof *p); |
| 1056 | if (!p) { |
| 1057 | goto error; |
| 1058 | } |
| 1059 | |
| 1060 | init_new_proxy(p); |
| 1061 | sink_setup_proxy(p); |
| 1062 | p->id = strdup(logsrv->ring_name); |
| 1063 | p->conf.args.file = p->conf.file = strdup(logsrv->conf.file); |
| 1064 | p->conf.args.line = p->conf.line = logsrv->conf.line; |
| 1065 | |
Christopher Faulet | d08a25b | 2022-10-24 15:53:01 +0200 | [diff] [blame] | 1066 | /* Set default connect and server timeout */ |
| 1067 | p->timeout.connect = MS_TO_TICKS(1000); |
| 1068 | p->timeout.server = MS_TO_TICKS(5000); |
| 1069 | |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1070 | /* allocate a new server to forward messages |
| 1071 | * from ring buffer |
| 1072 | */ |
| 1073 | srv = new_server(p); |
| 1074 | if (!srv) |
| 1075 | goto error; |
| 1076 | |
| 1077 | /* init server */ |
| 1078 | srv->id = strdup(logsrv->ring_name); |
| 1079 | srv->conf.file = strdup(logsrv->conf.file); |
| 1080 | srv->conf.line = logsrv->conf.line; |
| 1081 | srv->addr = logsrv->addr; |
| 1082 | srv->svc_port = get_host_port(&logsrv->addr); |
| 1083 | HA_SPIN_INIT(&srv->lock); |
| 1084 | |
| 1085 | /* process per thread init */ |
Miroslav Zagorac | 8a8f270 | 2021-06-15 15:33:20 +0200 | [diff] [blame] | 1086 | if (srv_init_per_thr(srv) == -1) |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1087 | goto error; |
| 1088 | |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1089 | /* the servers are linked backwards |
| 1090 | * first into proxy |
| 1091 | */ |
| 1092 | p->srv = srv; |
| 1093 | srv->next = p->srv; |
| 1094 | |
| 1095 | /* allocate sink_forward_target descriptor */ |
| 1096 | sft = calloc(1, sizeof(*sft)); |
| 1097 | if (!sft) |
| 1098 | goto error; |
| 1099 | |
| 1100 | /* init sink_forward_target offset */ |
| 1101 | sft->srv = srv; |
| 1102 | sft->appctx = NULL; |
| 1103 | sft->ofs = ~0; |
| 1104 | HA_SPIN_INIT(&sft->lock); |
| 1105 | |
Ilya Shipitsin | b2be9a1 | 2021-04-24 13:25:42 +0500 | [diff] [blame] | 1106 | /* prepare description for the sink */ |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1107 | chunk_reset(&trash); |
| 1108 | chunk_printf(&trash, "created from logserver declared into '%s' at line %d", logsrv->conf.file, logsrv->conf.line); |
| 1109 | |
| 1110 | /* allocate a new sink buffer */ |
| 1111 | sink = sink_new_buf(logsrv->ring_name, trash.area, logsrv->format, BUFSIZE); |
| 1112 | if (!sink || sink->type != SINK_TYPE_BUFFER) { |
| 1113 | goto error; |
| 1114 | } |
| 1115 | |
| 1116 | /* link sink_forward_target to proxy */ |
| 1117 | sink->forward_px = p; |
| 1118 | p->parent = sink; |
| 1119 | |
| 1120 | /* insert into sink_forward_targets |
| 1121 | * list into sink |
| 1122 | */ |
Christopher Faulet | 2ae25ea | 2022-05-12 14:50:09 +0200 | [diff] [blame] | 1123 | sft->sink = sink; |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1124 | sft->next = sink->sft; |
| 1125 | sink->sft = sft; |
| 1126 | |
| 1127 | /* mark server as an attached reader to the ring */ |
| 1128 | if (!ring_attach(sink->ctx.ring)) { |
| 1129 | /* should never fail since there is |
| 1130 | * only one reader |
| 1131 | */ |
| 1132 | goto error; |
| 1133 | } |
| 1134 | |
| 1135 | /* initialize sink buffer forwarding */ |
| 1136 | if (!sink_init_forward(sink)) |
| 1137 | goto error; |
| 1138 | |
| 1139 | /* reset familyt of logsrv to consider the ring buffer target */ |
| 1140 | logsrv->addr.ss_family = AF_UNSPEC; |
| 1141 | |
| 1142 | return sink; |
| 1143 | error: |
| 1144 | if (p) { |
| 1145 | if (p->id) |
| 1146 | free(p->id); |
| 1147 | if (p->conf.file) |
| 1148 | free(p->conf.file); |
| 1149 | |
| 1150 | free(p); |
| 1151 | } |
| 1152 | |
| 1153 | if (srv) { |
| 1154 | if (srv->id) |
| 1155 | free(srv->id); |
| 1156 | if (srv->conf.file) |
| 1157 | free((void *)srv->conf.file); |
| 1158 | if (srv->per_thr) |
| 1159 | free(srv->per_thr); |
| 1160 | free(srv); |
| 1161 | } |
| 1162 | |
| 1163 | if (sft) |
| 1164 | free(sft); |
| 1165 | |
| 1166 | if (sink) { |
Tim Duesterhus | 1307cd4 | 2023-04-22 17:47:35 +0200 | [diff] [blame] | 1167 | ring_free(sink->ctx.ring); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1168 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1169 | LIST_DELETE(&sink->sink_list); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1170 | free(sink->name); |
| 1171 | free(sink->desc); |
| 1172 | free(sink); |
| 1173 | } |
| 1174 | |
| 1175 | return NULL; |
| 1176 | } |
| 1177 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1178 | /* |
| 1179 | * Post parsing "ring" section. |
| 1180 | * |
| 1181 | * The function returns 0 in success case, otherwise, it returns error |
| 1182 | * flags. |
| 1183 | */ |
| 1184 | int cfg_post_parse_ring() |
| 1185 | { |
| 1186 | int err_code = 0; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1187 | struct server *srv; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1188 | |
| 1189 | if (cfg_sink && (cfg_sink->type == SINK_TYPE_BUFFER)) { |
| 1190 | if (cfg_sink->maxlen > b_size(&cfg_sink->ctx.ring->buf)) { |
| 1191 | ha_warning("ring '%s' event max length '%u' exceeds size, forced to size '%lu'.\n", |
Willy Tarreau | 570a22b | 2020-06-02 12:00:46 +0200 | [diff] [blame] | 1192 | cfg_sink->name, cfg_sink->maxlen, (unsigned long)b_size(&cfg_sink->ctx.ring->buf)); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1193 | cfg_sink->maxlen = b_size(&cfg_sink->ctx.ring->buf); |
| 1194 | err_code |= ERR_ALERT; |
| 1195 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1196 | |
| 1197 | /* prepare forward server descriptors */ |
| 1198 | if (cfg_sink->forward_px) { |
| 1199 | srv = cfg_sink->forward_px->srv; |
| 1200 | while (srv) { |
| 1201 | struct sink_forward_target *sft; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1202 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1203 | /* allocate sink_forward_target descriptor */ |
| 1204 | sft = calloc(1, sizeof(*sft)); |
| 1205 | if (!sft) { |
| 1206 | ha_alert("memory allocation error initializing server '%s' in ring '%s'.\n",srv->id, cfg_sink->name); |
| 1207 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1208 | break; |
| 1209 | } |
| 1210 | sft->srv = srv; |
| 1211 | sft->appctx = NULL; |
| 1212 | sft->ofs = ~0; /* init ring offset */ |
Christopher Faulet | 96417f3 | 2022-08-04 16:00:13 +0200 | [diff] [blame] | 1213 | sft->sink = cfg_sink; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1214 | sft->next = cfg_sink->sft; |
| 1215 | HA_SPIN_INIT(&sft->lock); |
| 1216 | |
| 1217 | /* mark server attached to the ring */ |
| 1218 | if (!ring_attach(cfg_sink->ctx.ring)) { |
| 1219 | ha_alert("server '%s' sets too many watchers > 255 on ring '%s'.\n", srv->id, cfg_sink->name); |
| 1220 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1221 | } |
| 1222 | cfg_sink->sft = sft; |
| 1223 | srv = srv->next; |
| 1224 | } |
| 1225 | sink_init_forward(cfg_sink); |
| 1226 | } |
| 1227 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1228 | cfg_sink = NULL; |
| 1229 | |
| 1230 | return err_code; |
| 1231 | } |
| 1232 | |
| 1233 | /* resolve sink names at end of config. Returns 0 on success otherwise error |
| 1234 | * flags. |
| 1235 | */ |
| 1236 | int post_sink_resolve() |
| 1237 | { |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1238 | int err_code = ERR_NONE; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1239 | struct logsrv *logsrv, *logb; |
| 1240 | struct sink *sink; |
| 1241 | struct proxy *px; |
| 1242 | |
| 1243 | list_for_each_entry_safe(logsrv, logb, &global.logsrvs, list) { |
| 1244 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1245 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1246 | if (!sink) { |
| 1247 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1248 | * means we must allocate a sink |
| 1249 | * buffer to send messages to this logsrv |
| 1250 | */ |
| 1251 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1252 | sink = sink_new_from_logsrv(logsrv); |
| 1253 | if (!sink) { |
| 1254 | ha_alert("global stream log server declared in file '%s' at line %d cannot be initialized'.\n", |
| 1255 | logsrv->conf.file, logsrv->conf.line); |
| 1256 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1257 | } |
| 1258 | } |
| 1259 | else { |
| 1260 | ha_alert("global log server declared in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1261 | logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1262 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1263 | } |
| 1264 | } |
| 1265 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1266 | ha_alert("global log server declared in file '%s' at line %d uses incompatible ring '%s'.\n", |
| 1267 | logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1269 | } |
| 1270 | logsrv->sink = sink; |
| 1271 | } |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1272 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | for (px = proxies_list; px; px = px->next) { |
| 1276 | list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) { |
| 1277 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1278 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1279 | if (!sink) { |
| 1280 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1281 | * means we must allocate a sink |
| 1282 | * buffer to send messages to this logsrv |
| 1283 | */ |
| 1284 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1285 | sink = sink_new_from_logsrv(logsrv); |
| 1286 | if (!sink) { |
| 1287 | ha_alert("log server declared in proxy section '%s' file '%s' at line %d cannot be initialized'.\n", |
| 1288 | px->id, logsrv->conf.file, logsrv->conf.line); |
| 1289 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1290 | } |
| 1291 | } |
| 1292 | else { |
| 1293 | ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1294 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1296 | } |
| 1297 | } |
| 1298 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1299 | ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses incomatible ring named '%s'.\n", |
| 1300 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1302 | } |
| 1303 | logsrv->sink = sink; |
| 1304 | } |
| 1305 | } |
| 1306 | } |
Emeric Brun | 12941c8 | 2020-07-07 14:19:42 +0200 | [diff] [blame] | 1307 | |
| 1308 | for (px = cfg_log_forward; px; px = px->next) { |
| 1309 | list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) { |
| 1310 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1311 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1312 | if (!sink) { |
| 1313 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1314 | * means we must allocate a sink |
| 1315 | * buffer to send messages to this logsrv |
| 1316 | */ |
| 1317 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1318 | sink = sink_new_from_logsrv(logsrv); |
| 1319 | if (!sink) { |
| 1320 | ha_alert("log server declared in log-forward section '%s' file '%s' at line %d cannot be initialized'.\n", |
| 1321 | px->id, logsrv->conf.file, logsrv->conf.line); |
| 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1323 | } |
| 1324 | } |
| 1325 | else { |
| 1326 | ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1327 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1328 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1329 | } |
| 1330 | } |
| 1331 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1332 | ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1333 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 12941c8 | 2020-07-07 14:19:42 +0200 | [diff] [blame] | 1334 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1335 | } |
| 1336 | logsrv->sink = sink; |
| 1337 | } |
| 1338 | } |
| 1339 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1340 | return err_code; |
| 1341 | } |
| 1342 | |
| 1343 | |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1344 | static void sink_init() |
| 1345 | { |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 1346 | sink_new_fd("stdout", "standard output (fd#1)", LOG_FORMAT_RAW, 1); |
| 1347 | sink_new_fd("stderr", "standard output (fd#2)", LOG_FORMAT_RAW, 2); |
| 1348 | sink_new_buf("buf0", "in-memory ring buffer", LOG_FORMAT_TIMED, 1048576); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | static void sink_deinit() |
| 1352 | { |
| 1353 | struct sink *sink, *sb; |
| 1354 | |
| 1355 | list_for_each_entry_safe(sink, sb, &sink_list, sink_list) { |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 1356 | if (sink->type == SINK_TYPE_BUFFER) { |
Willy Tarreau | fb9a476 | 2023-01-24 12:11:41 +0100 | [diff] [blame] | 1357 | if (sink->store) { |
| 1358 | size_t size = (sink->ctx.ring->buf.size + 4095UL) & -4096UL; |
| 1359 | void *area = (sink->ctx.ring->buf.area - sizeof(*sink->ctx.ring)); |
| 1360 | |
| 1361 | msync(area, size, MS_SYNC); |
| 1362 | munmap(area, size); |
Willy Tarreau | b919109 | 2023-01-26 15:34:31 +0100 | [diff] [blame] | 1363 | ha_free(&sink->store); |
Willy Tarreau | fb9a476 | 2023-01-24 12:11:41 +0100 | [diff] [blame] | 1364 | } |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 1365 | else |
| 1366 | ring_free(sink->ctx.ring); |
| 1367 | } |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1368 | LIST_DELETE(&sink->sink_list); |
Willy Tarreau | 09727ee | 2023-01-26 15:46:08 +0100 | [diff] [blame] | 1369 | task_destroy(sink->forward_task); |
Aurelien DARRAGON | 9b1d15f | 2023-03-09 12:07:09 +0100 | [diff] [blame] | 1370 | free_proxy(sink->forward_px); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1371 | free(sink->name); |
| 1372 | free(sink->desc); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1373 | free(sink); |
| 1374 | } |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | INITCALL0(STG_REGISTER, sink_init); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1378 | REGISTER_POST_DEINIT(sink_deinit); |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1379 | |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 1380 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1381 | { { "show", "events", NULL }, "show events [<sink>] [-w] [-n] : show event sink state", cli_parse_show_events, NULL, NULL }, |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 1382 | {{},} |
| 1383 | }}; |
| 1384 | |
| 1385 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 1386 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1387 | /* config parsers for this section */ |
| 1388 | REGISTER_CONFIG_SECTION("ring", cfg_parse_ring, cfg_post_parse_ring); |
| 1389 | REGISTER_POST_CHECK(post_sink_resolve); |
| 1390 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 1391 | /* |
| 1392 | * Local variables: |
| 1393 | * c-indent-level: 8 |
| 1394 | * c-basic-offset: 8 |
| 1395 | * End: |
| 1396 | */ |