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 | { |
| 292 | px->last_change = now.tv_sec; |
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 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 321 | /* if stopping was requested, close immediately */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 322 | if (unlikely(stopping)) |
| 323 | goto close; |
| 324 | |
| 325 | /* for rex because it seems reset to timeout |
| 326 | * and we don't want expire on this case |
| 327 | * with a syslog server |
| 328 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 329 | sc_oc(sc)->rex = TICK_ETERNITY; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 330 | /* rto should not change but it seems the case */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 331 | sc_oc(sc)->rto = TICK_ETERNITY; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 332 | |
| 333 | /* an error was detected */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 334 | if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 335 | goto close; |
| 336 | |
| 337 | /* con closed by server side */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 338 | if ((sc_oc(sc)->flags & CF_SHUTW)) |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 339 | goto close; |
| 340 | |
| 341 | /* if the connection is not established, inform the stream that we want |
| 342 | * to be notified whenever the connection completes. |
| 343 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 344 | if (sc_opposite(sc)->state < SC_ST_EST) { |
Willy Tarreau | 90e8b45 | 2022-05-25 18:21:43 +0200 | [diff] [blame] | 345 | applet_need_more_data(appctx); |
Willy Tarreau | b23edc8 | 2022-05-24 16:49:03 +0200 | [diff] [blame] | 346 | se_need_remote_conn(appctx->sedesc); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 347 | applet_have_more_data(appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 348 | return; |
| 349 | } |
| 350 | |
| 351 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 352 | if (appctx != sft->appctx) { |
| 353 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 354 | goto close; |
| 355 | } |
| 356 | ofs = sft->ofs; |
| 357 | |
| 358 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
| 359 | LIST_DEL_INIT(&appctx->wait_entry); |
| 360 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 361 | |
| 362 | HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); |
| 363 | |
| 364 | /* explanation for the initialization below: it would be better to do |
| 365 | * this in the parsing function but this would occasionally result in |
| 366 | * dropped events because we'd take a reference on the oldest message |
| 367 | * and keep it while being scheduled. Thus instead let's take it the |
| 368 | * first time we enter here so that we have a chance to pass many |
| 369 | * existing messages before grabbing a reference to a location. This |
| 370 | * value cannot be produced after initialization. |
| 371 | */ |
| 372 | if (unlikely(ofs == ~0)) { |
| 373 | ofs = 0; |
| 374 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 375 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 376 | ofs += ring->ofs; |
| 377 | } |
| 378 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 379 | /* in this loop, ofs always points to the counter byte that precedes |
| 380 | * the message so that we can take our reference there if we have to |
| 381 | * stop before the end (ret=0). |
| 382 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 383 | if (sc_opposite(sc)->state == SC_ST_EST) { |
Emeric Brun | fdabf49 | 2020-12-02 17:02:09 +0100 | [diff] [blame] | 384 | /* we were already there, adjust the offset to be relative to |
| 385 | * the buffer's head and remove us from the counter. |
| 386 | */ |
| 387 | ofs -= ring->ofs; |
| 388 | BUG_ON(ofs >= buf->size); |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 389 | HA_ATOMIC_DEC(b_peek(buf, ofs)); |
Emeric Brun | fdabf49 | 2020-12-02 17:02:09 +0100 | [diff] [blame] | 390 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 391 | ret = 1; |
| 392 | while (ofs + 1 < b_data(buf)) { |
| 393 | cnt = 1; |
| 394 | len = b_peek_varint(buf, ofs + cnt, &msg_len); |
| 395 | if (!len) |
| 396 | break; |
| 397 | cnt += len; |
| 398 | BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf)); |
| 399 | |
| 400 | if (unlikely(msg_len + 1 > b_size(&trash))) { |
| 401 | /* too large a message to ever fit, let's skip it */ |
| 402 | ofs += cnt + msg_len; |
| 403 | continue; |
| 404 | } |
| 405 | |
| 406 | chunk_reset(&trash); |
| 407 | len = b_getblk(buf, trash.area, msg_len, ofs + cnt); |
| 408 | trash.data += len; |
| 409 | trash.area[trash.data++] = '\n'; |
| 410 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 411 | if (applet_putchk(appctx, &trash) == -1) { |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 412 | ret = 0; |
| 413 | break; |
| 414 | } |
| 415 | ofs += cnt + msg_len; |
| 416 | } |
| 417 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 418 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 419 | ofs += ring->ofs; |
| 420 | sft->ofs = ofs; |
Willy Tarreau | 53bfab0 | 2022-08-04 17:18:54 +0200 | [diff] [blame] | 421 | last_ofs = ring->ofs; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 422 | } |
| 423 | HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 424 | |
| 425 | if (ret) { |
| 426 | /* let's be woken up once new data arrive */ |
| 427 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 428 | LIST_APPEND(&ring->waiters, &appctx->wait_entry); |
Willy Tarreau | 53bfab0 | 2022-08-04 17:18:54 +0200 | [diff] [blame] | 429 | ofs = ring->ofs; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 430 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 53bfab0 | 2022-08-04 17:18:54 +0200 | [diff] [blame] | 431 | if (ofs != last_ofs) { |
| 432 | /* more data was added into the ring between the |
| 433 | * unlock and the lock, and the writer might not |
| 434 | * have seen us. We need to reschedule a read. |
| 435 | */ |
| 436 | applet_have_more_data(appctx); |
| 437 | } else |
| 438 | applet_have_no_more_data(appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 439 | } |
| 440 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 441 | |
| 442 | /* always drain data from server */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 443 | co_skip(sc_oc(sc), sc_oc(sc)->output); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | close: |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 447 | sc_shutw(sc); |
| 448 | sc_shutr(sc); |
| 449 | sc_ic(sc)->flags |= CF_READ_NULL; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 450 | } |
| 451 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 452 | /* |
| 453 | * IO Handler to handle message push to syslog tcp server |
| 454 | * using octet counting frames |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 455 | * It takes its context from appctx->svcctx. |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 456 | */ |
| 457 | static void sink_forward_oc_io_handler(struct appctx *appctx) |
| 458 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 459 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 460 | struct stream *s = __sc_strm(sc); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 461 | struct sink *sink = strm_fe(s)->parent; |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 462 | struct sink_forward_target *sft = appctx->svcctx; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 463 | struct ring *ring = sink->ctx.ring; |
| 464 | struct buffer *buf = &ring->buf; |
| 465 | uint64_t msg_len; |
| 466 | size_t len, cnt, ofs; |
| 467 | int ret = 0; |
| 468 | char *p; |
| 469 | |
Ilya Shipitsin | 47d1718 | 2020-06-21 21:42:57 +0500 | [diff] [blame] | 470 | /* if stopping was requested, close immediately */ |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 471 | if (unlikely(stopping)) |
| 472 | goto close; |
| 473 | |
| 474 | /* for rex because it seems reset to timeout |
| 475 | * and we don't want expire on this case |
| 476 | * with a syslog server |
| 477 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 478 | sc_oc(sc)->rex = TICK_ETERNITY; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 479 | /* rto should not change but it seems the case */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 480 | sc_oc(sc)->rto = TICK_ETERNITY; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 481 | |
| 482 | /* an error was detected */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 483 | if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 484 | goto close; |
| 485 | |
| 486 | /* con closed by server side */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 487 | if ((sc_oc(sc)->flags & CF_SHUTW)) |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 488 | goto close; |
| 489 | |
| 490 | /* if the connection is not established, inform the stream that we want |
| 491 | * to be notified whenever the connection completes. |
| 492 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 493 | if (sc_opposite(sc)->state < SC_ST_EST) { |
Willy Tarreau | 90e8b45 | 2022-05-25 18:21:43 +0200 | [diff] [blame] | 494 | applet_need_more_data(appctx); |
Willy Tarreau | b23edc8 | 2022-05-24 16:49:03 +0200 | [diff] [blame] | 495 | se_need_remote_conn(appctx->sedesc); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 496 | applet_have_more_data(appctx); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
| 500 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 501 | if (appctx != sft->appctx) { |
| 502 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 503 | goto close; |
| 504 | } |
| 505 | ofs = sft->ofs; |
| 506 | |
| 507 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
| 508 | LIST_DEL_INIT(&appctx->wait_entry); |
| 509 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 510 | |
| 511 | HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); |
| 512 | |
| 513 | /* explanation for the initialization below: it would be better to do |
| 514 | * this in the parsing function but this would occasionally result in |
| 515 | * dropped events because we'd take a reference on the oldest message |
| 516 | * and keep it while being scheduled. Thus instead let's take it the |
| 517 | * first time we enter here so that we have a chance to pass many |
| 518 | * existing messages before grabbing a reference to a location. This |
| 519 | * value cannot be produced after initialization. |
| 520 | */ |
| 521 | if (unlikely(ofs == ~0)) { |
| 522 | ofs = 0; |
| 523 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 524 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 525 | ofs += ring->ofs; |
| 526 | } |
| 527 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 528 | /* in this loop, ofs always points to the counter byte that precedes |
| 529 | * the message so that we can take our reference there if we have to |
| 530 | * stop before the end (ret=0). |
| 531 | */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 532 | if (sc_opposite(sc)->state == SC_ST_EST) { |
Emeric Brun | fdabf49 | 2020-12-02 17:02:09 +0100 | [diff] [blame] | 533 | /* we were already there, adjust the offset to be relative to |
| 534 | * the buffer's head and remove us from the counter. |
| 535 | */ |
| 536 | ofs -= ring->ofs; |
| 537 | BUG_ON(ofs >= buf->size); |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 538 | HA_ATOMIC_DEC(b_peek(buf, ofs)); |
Emeric Brun | fdabf49 | 2020-12-02 17:02:09 +0100 | [diff] [blame] | 539 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 540 | ret = 1; |
| 541 | while (ofs + 1 < b_data(buf)) { |
| 542 | cnt = 1; |
| 543 | len = b_peek_varint(buf, ofs + cnt, &msg_len); |
| 544 | if (!len) |
| 545 | break; |
| 546 | cnt += len; |
| 547 | BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf)); |
| 548 | |
| 549 | chunk_reset(&trash); |
| 550 | p = ulltoa(msg_len, trash.area, b_size(&trash)); |
| 551 | if (p) { |
| 552 | trash.data = (p - trash.area) + 1; |
| 553 | *p = ' '; |
| 554 | } |
| 555 | |
| 556 | if (!p || (trash.data + msg_len > b_size(&trash))) { |
| 557 | /* too large a message to ever fit, let's skip it */ |
| 558 | ofs += cnt + msg_len; |
| 559 | continue; |
| 560 | } |
| 561 | |
| 562 | trash.data += b_getblk(buf, p + 1, msg_len, ofs + cnt); |
| 563 | |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 564 | if (applet_putchk(appctx, &trash) == -1) { |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 565 | ret = 0; |
| 566 | break; |
| 567 | } |
| 568 | ofs += cnt + msg_len; |
| 569 | } |
| 570 | |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 571 | HA_ATOMIC_INC(b_peek(buf, ofs)); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 572 | ofs += ring->ofs; |
| 573 | sft->ofs = ofs; |
| 574 | } |
| 575 | HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); |
| 576 | |
| 577 | if (ret) { |
| 578 | /* let's be woken up once new data arrive */ |
| 579 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 580 | LIST_APPEND(&ring->waiters, &appctx->wait_entry); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 581 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); |
Willy Tarreau | 4164eb9 | 2022-05-25 15:42:03 +0200 | [diff] [blame] | 582 | applet_have_no_more_data(appctx); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 583 | } |
| 584 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 585 | |
| 586 | /* always drain data from server */ |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 587 | co_skip(sc_oc(sc), sc_oc(sc)->output); |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 588 | return; |
| 589 | |
| 590 | close: |
Willy Tarreau | 0eca539 | 2022-05-27 10:44:25 +0200 | [diff] [blame] | 591 | sc_shutw(sc); |
| 592 | sc_shutr(sc); |
| 593 | sc_ic(sc)->flags |= CF_READ_NULL; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 596 | void __sink_forward_session_deinit(struct sink_forward_target *sft) |
| 597 | { |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 598 | struct stream *s = appctx_strm(sft->appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 599 | struct sink *sink; |
| 600 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 601 | sink = strm_fe(s)->parent; |
| 602 | if (!sink) |
| 603 | return; |
| 604 | |
| 605 | HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); |
| 606 | LIST_DEL_INIT(&sft->appctx->wait_entry); |
| 607 | HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); |
| 608 | |
| 609 | sft->appctx = NULL; |
| 610 | task_wakeup(sink->forward_task, TASK_WOKEN_MSG); |
| 611 | } |
| 612 | |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 613 | static int sink_forward_session_init(struct appctx *appctx) |
| 614 | { |
| 615 | struct sink_forward_target *sft = appctx->svcctx; |
| 616 | struct stream *s; |
| 617 | struct sockaddr_storage *addr = NULL; |
| 618 | |
| 619 | if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr))) |
| 620 | goto out_error; |
| 621 | |
| 622 | if (appctx_finalize_startup(appctx, sft->sink->forward_px, &BUF_NULL) == -1) |
| 623 | goto out_free_addr; |
| 624 | |
| 625 | s = appctx_strm(appctx); |
Willy Tarreau | 7cb9e6c | 2022-05-17 19:40:40 +0200 | [diff] [blame] | 626 | s->scb->dst = addr; |
Willy Tarreau | cb04166 | 2022-05-17 19:44:42 +0200 | [diff] [blame] | 627 | s->scb->flags |= SC_FL_NOLINGER; |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 628 | |
| 629 | s->target = &sft->srv->obj_type; |
| 630 | s->flags = SF_ASSIGNED; |
| 631 | |
| 632 | s->do_log = NULL; |
| 633 | s->uniq_id = 0; |
| 634 | |
| 635 | s->res.flags |= CF_READ_DONTWAIT; |
| 636 | /* for rto and rex to eternity to not expire on idle recv: |
| 637 | * We are using a syslog server. |
| 638 | */ |
| 639 | s->res.rto = TICK_ETERNITY; |
| 640 | s->res.rex = TICK_ETERNITY; |
| 641 | sft->appctx = appctx; |
| 642 | |
| 643 | return 0; |
| 644 | |
| 645 | out_free_addr: |
| 646 | sockaddr_free(&addr); |
| 647 | out_error: |
| 648 | return -1; |
| 649 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 650 | |
| 651 | static void sink_forward_session_release(struct appctx *appctx) |
| 652 | { |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 653 | struct sink_forward_target *sft = appctx->svcctx; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 654 | |
| 655 | if (!sft) |
| 656 | return; |
| 657 | |
| 658 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 659 | if (sft->appctx == appctx) |
| 660 | __sink_forward_session_deinit(sft); |
| 661 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 662 | } |
| 663 | |
| 664 | static struct applet sink_forward_applet = { |
| 665 | .obj_type = OBJ_TYPE_APPLET, |
| 666 | .name = "<SINKFWD>", /* used for logging */ |
| 667 | .fct = sink_forward_io_handler, |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 668 | .init = sink_forward_session_init, |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 669 | .release = sink_forward_session_release, |
| 670 | }; |
| 671 | |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 672 | static struct applet sink_forward_oc_applet = { |
| 673 | .obj_type = OBJ_TYPE_APPLET, |
| 674 | .name = "<SINKFWDOC>", /* used for logging */ |
| 675 | .fct = sink_forward_oc_io_handler, |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 676 | .init = sink_forward_session_init, |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 677 | .release = sink_forward_session_release, |
| 678 | }; |
| 679 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 680 | /* |
| 681 | * Create a new peer session in assigned state (connect will start automatically) |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 682 | * It sets its context into appctx->svcctx. |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 683 | */ |
| 684 | static struct appctx *sink_forward_session_create(struct sink *sink, struct sink_forward_target *sft) |
| 685 | { |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 686 | struct appctx *appctx; |
Emeric Brun | 9755647 | 2020-05-30 01:42:45 +0200 | [diff] [blame] | 687 | struct applet *applet = &sink_forward_applet; |
| 688 | |
| 689 | if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING) |
| 690 | applet = &sink_forward_oc_applet; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 691 | |
Christopher Faulet | 6095d57 | 2022-05-16 17:09:48 +0200 | [diff] [blame] | 692 | appctx = appctx_new_here(applet, NULL); |
Christopher Faulet | 2479e5f | 2022-01-19 14:50:11 +0100 | [diff] [blame] | 693 | if (!appctx) |
Christopher Faulet | a9e8b39 | 2022-03-23 11:01:09 +0100 | [diff] [blame] | 694 | goto out_close; |
Willy Tarreau | 42cc831 | 2022-05-04 20:42:23 +0200 | [diff] [blame] | 695 | appctx->svcctx = (void *)sft; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 696 | |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 697 | if (appctx_init(appctx) == -1) |
Christopher Faulet | 92202da | 2022-05-11 12:22:10 +0200 | [diff] [blame] | 698 | goto out_free_appctx; |
Christopher Faulet | 13a35e5 | 2021-12-20 15:34:16 +0100 | [diff] [blame] | 699 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 700 | return appctx; |
| 701 | |
| 702 | /* Error unrolling */ |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 703 | out_free_appctx: |
Christopher Faulet | aee57fc | 2022-05-12 15:34:48 +0200 | [diff] [blame] | 704 | appctx_free_on_early_error(appctx); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 705 | out_close: |
| 706 | return NULL; |
| 707 | } |
| 708 | |
| 709 | /* |
| 710 | * Task to handle connctions to forward servers |
| 711 | */ |
Willy Tarreau | 144f84a | 2021-03-02 16:09:26 +0100 | [diff] [blame] | 712 | 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] | 713 | { |
| 714 | struct sink *sink = (struct sink *)context; |
| 715 | struct sink_forward_target *sft = sink->sft; |
| 716 | |
| 717 | task->expire = TICK_ETERNITY; |
| 718 | |
| 719 | if (!stopping) { |
| 720 | while (sft) { |
| 721 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 722 | /* if appctx is NULL, start a new session */ |
| 723 | if (!sft->appctx) |
| 724 | sft->appctx = sink_forward_session_create(sink, sft); |
| 725 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 726 | sft = sft->next; |
| 727 | } |
| 728 | } |
| 729 | else { |
| 730 | while (sft) { |
| 731 | HA_SPIN_LOCK(SFT_LOCK, &sft->lock); |
| 732 | /* awake applet to perform a clean close */ |
| 733 | if (sft->appctx) |
| 734 | appctx_wakeup(sft->appctx); |
| 735 | HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); |
| 736 | sft = sft->next; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return task; |
| 741 | } |
| 742 | /* |
| 743 | * Init task to manage connctions to forward servers |
| 744 | * |
| 745 | * returns 0 in case of error. |
| 746 | */ |
| 747 | int sink_init_forward(struct sink *sink) |
| 748 | { |
Willy Tarreau | beeabf5 | 2021-10-01 18:23:30 +0200 | [diff] [blame] | 749 | sink->forward_task = task_new_anywhere(); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 750 | if (!sink->forward_task) |
| 751 | return 0; |
| 752 | |
| 753 | sink->forward_task->process = process_sink_forward; |
| 754 | sink->forward_task->context = (void *)sink; |
| 755 | sink->forward_sighandler = signal_register_task(0, sink->forward_task, 0); |
| 756 | task_wakeup(sink->forward_task, TASK_WOKEN_INIT); |
| 757 | return 1; |
| 758 | } |
Willy Tarreau | 32872db | 2022-08-31 18:52:17 +0200 | [diff] [blame] | 759 | |
| 760 | /* This tries to rotate a file-backed ring, but only if it contains contents. |
| 761 | * This way empty rings will not cause backups to be overwritten and it's safe |
| 762 | * to reload multiple times. That's only best effort, failures are silently |
| 763 | * ignored. |
| 764 | */ |
| 765 | void sink_rotate_file_backed_ring(const char *name) |
| 766 | { |
| 767 | struct ring ring; |
| 768 | char *oldback; |
| 769 | int ret; |
| 770 | int fd; |
| 771 | |
| 772 | fd = open(name, O_RDONLY); |
| 773 | if (fd < 0) |
| 774 | return; |
| 775 | |
| 776 | /* check for contents validity */ |
| 777 | ret = read(fd, &ring, sizeof(ring)); |
| 778 | close(fd); |
| 779 | |
| 780 | if (ret != sizeof(ring)) |
| 781 | goto rotate; |
| 782 | |
| 783 | /* contents are present, we want to keep them => rotate. Note that |
| 784 | * an empty ring buffer has one byte (the marker). |
| 785 | */ |
| 786 | if (ring.buf.data > 1) |
| 787 | goto rotate; |
| 788 | |
| 789 | /* nothing to keep, let's scratch the file and preserve the backup */ |
| 790 | return; |
| 791 | |
| 792 | rotate: |
| 793 | oldback = NULL; |
| 794 | memprintf(&oldback, "%s.bak", name); |
| 795 | if (oldback) { |
| 796 | /* try to rename any possibly existing ring file to |
| 797 | * ".bak" and delete remains of older ones. This will |
| 798 | * ensure we don't wipe useful debug info upon restart. |
| 799 | */ |
| 800 | unlink(oldback); |
| 801 | if (rename(name, oldback) < 0) |
| 802 | unlink(oldback); |
| 803 | ha_free(&oldback); |
| 804 | } |
| 805 | } |
| 806 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 807 | /* |
| 808 | * Parse "ring" section and create corresponding sink buffer. |
| 809 | * |
| 810 | * The function returns 0 in success case, otherwise, it returns error |
| 811 | * flags. |
| 812 | */ |
| 813 | int cfg_parse_ring(const char *file, int linenum, char **args, int kwm) |
| 814 | { |
| 815 | int err_code = 0; |
| 816 | const char *inv; |
| 817 | size_t size = BUFSIZE; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 818 | struct proxy *p; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 819 | |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 820 | if (strcmp(args[0], "ring") == 0) { /* new ring section */ |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 821 | if (!*args[1]) { |
| 822 | ha_alert("parsing [%s:%d] : missing ring name.\n", file, linenum); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | goto err; |
| 825 | } |
| 826 | |
| 827 | inv = invalid_char(args[1]); |
| 828 | if (inv) { |
| 829 | ha_alert("parsing [%s:%d] : invalid ring name '%s' (character '%c' is not permitted).\n", file, linenum, args[1], *inv); |
| 830 | err_code |= ERR_ALERT | ERR_FATAL; |
| 831 | goto err; |
| 832 | } |
| 833 | |
| 834 | if (sink_find(args[1])) { |
| 835 | ha_alert("parsing [%s:%d] : sink named '%s' already exists.\n", file, linenum, args[1]); |
| 836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 837 | goto err; |
| 838 | } |
| 839 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 840 | 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] | 841 | if (!cfg_sink || cfg_sink->type != SINK_TYPE_BUFFER) { |
| 842 | ha_alert("parsing [%s:%d] : unable to create a new sink buffer for ring '%s'.\n", file, linenum, args[1]); |
| 843 | err_code |= ERR_ALERT | ERR_FATAL; |
| 844 | goto err; |
| 845 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 846 | |
| 847 | /* allocate new proxy to handle forwards */ |
| 848 | p = calloc(1, sizeof *p); |
| 849 | if (!p) { |
| 850 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 851 | err_code |= ERR_ALERT | ERR_FATAL; |
| 852 | goto err; |
| 853 | } |
| 854 | |
| 855 | init_new_proxy(p); |
| 856 | sink_setup_proxy(p); |
| 857 | p->parent = cfg_sink; |
| 858 | p->id = strdup(args[1]); |
| 859 | p->conf.args.file = p->conf.file = strdup(file); |
| 860 | p->conf.args.line = p->conf.line = linenum; |
| 861 | cfg_sink->forward_px = p; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 862 | } |
| 863 | else if (strcmp(args[0], "size") == 0) { |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 864 | if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) { |
| 865 | ha_alert("parsing [%s:%d] : 'size' directive not usable with this type of sink.\n", file, linenum); |
| 866 | err_code |= ERR_ALERT | ERR_FATAL; |
| 867 | goto err; |
| 868 | } |
| 869 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 870 | size = atol(args[1]); |
| 871 | if (!size) { |
| 872 | ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]); |
| 873 | err_code |= ERR_ALERT | ERR_FATAL; |
| 874 | goto err; |
| 875 | } |
| 876 | |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 877 | if (cfg_sink->store) { |
| 878 | ha_alert("parsing [%s:%d] : cannot resize an already mapped file, please specify 'size' before 'backing-file'.\n", file, linenum); |
| 879 | err_code |= ERR_ALERT | ERR_FATAL; |
| 880 | goto err; |
| 881 | } |
| 882 | |
Willy Tarreau | 18d1306 | 2022-08-11 16:12:11 +0200 | [diff] [blame] | 883 | if (size < cfg_sink->ctx.ring->buf.size) { |
| 884 | ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than current size '%llu' for ring '%s'.\n", |
| 885 | file, linenum, (ullong)size, (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name); |
| 886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 887 | goto err; |
| 888 | } |
| 889 | |
| 890 | if (!ring_resize(cfg_sink->ctx.ring, size)) { |
| 891 | ha_alert("parsing [%s:%d] : fail to set sink buffer size '%llu' for ring '%s'.\n", file, linenum, |
| 892 | (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto err; |
| 895 | } |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 896 | } |
| 897 | else if (strcmp(args[0], "backing-file") == 0) { |
| 898 | /* This tries to mmap file <file> for size <size> and to use it as a backing store |
| 899 | * for ring <ring>. Existing data are delete. NULL is returned on error. |
| 900 | */ |
| 901 | const char *backing = args[1]; |
| 902 | size_t size; |
| 903 | void *area; |
| 904 | int fd; |
| 905 | |
| 906 | if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) { |
| 907 | ha_alert("parsing [%s:%d] : 'backing-file' only usable with existing rings.\n", file, linenum); |
| 908 | err_code |= ERR_ALERT | ERR_FATAL; |
| 909 | goto err; |
| 910 | } |
| 911 | |
| 912 | if (cfg_sink->store) { |
| 913 | ha_alert("parsing [%s:%d] : 'backing-file' already specified for ring '%s' (was '%s').\n", file, linenum, cfg_sink->name, cfg_sink->store); |
| 914 | err_code |= ERR_ALERT | ERR_FATAL; |
| 915 | goto err; |
| 916 | } |
| 917 | |
Willy Tarreau | 32872db | 2022-08-31 18:52:17 +0200 | [diff] [blame] | 918 | /* let's check if the file exists and is not empty. That's the |
| 919 | * only condition under which we'll trigger a rotate, so that |
| 920 | * config checks, reloads, or restarts that don't emit anything |
| 921 | * do not rotate it again. |
| 922 | */ |
| 923 | sink_rotate_file_backed_ring(backing); |
Willy Tarreau | ded77cc | 2022-08-12 15:38:20 +0200 | [diff] [blame] | 924 | |
Willy Tarreau | 8e87705 | 2022-08-12 15:03:12 +0200 | [diff] [blame] | 925 | fd = open(backing, O_RDWR | O_CREAT, 0600); |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 926 | if (fd < 0) { |
| 927 | ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno)); |
| 928 | err_code |= ERR_ALERT | ERR_FATAL; |
| 929 | goto err; |
| 930 | } |
| 931 | |
| 932 | size = (cfg_sink->ctx.ring->buf.size + 4095UL) & -4096UL; |
| 933 | if (ftruncate(fd, size) != 0) { |
| 934 | close(fd); |
| 935 | ha_alert("parsing [%s:%d] : could not adjust size of backing-file for ring '%s': %s.\n", file, linenum, cfg_sink->name, strerror(errno)); |
| 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto err; |
| 938 | } |
| 939 | |
| 940 | area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 941 | if (area == MAP_FAILED) { |
| 942 | close(fd); |
| 943 | 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)); |
| 944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 945 | goto err; |
| 946 | } |
| 947 | |
| 948 | /* we don't need the file anymore */ |
| 949 | close(fd); |
| 950 | cfg_sink->store = strdup(backing); |
| 951 | |
| 952 | /* never fails */ |
| 953 | ring_free(cfg_sink->ctx.ring); |
| 954 | cfg_sink->ctx.ring = ring_make_from_area(area, size); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 955 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 956 | else if (strcmp(args[0],"server") == 0) { |
Amaury Denoyelle | 30c0537 | 2021-03-08 16:36:46 +0100 | [diff] [blame] | 957 | err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL, |
| 958 | SRV_PARSE_PARSE_ADDR|SRV_PARSE_INITIAL_RESOLVE); |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 959 | } |
| 960 | else if (strcmp(args[0],"timeout") == 0) { |
| 961 | if (!cfg_sink || !cfg_sink->forward_px) { |
| 962 | ha_alert("parsing [%s:%d] : unable to set timeout '%s'.\n", file, linenum, args[1]); |
| 963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 964 | goto err; |
| 965 | } |
| 966 | |
| 967 | if (strcmp(args[1], "connect") == 0 || |
| 968 | strcmp(args[1], "server") == 0) { |
| 969 | const char *res; |
| 970 | unsigned int tout; |
| 971 | |
| 972 | if (!*args[2]) { |
| 973 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
| 974 | file, linenum, args[0], args[1]); |
| 975 | err_code |= ERR_ALERT | ERR_FATAL; |
| 976 | goto err; |
| 977 | } |
| 978 | res = parse_time_err(args[2], &tout, TIME_UNIT_MS); |
| 979 | if (res == PARSE_TIME_OVER) { |
| 980 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 981 | file, linenum, args[2], args[0], args[1]); |
| 982 | err_code |= ERR_ALERT | ERR_FATAL; |
| 983 | goto err; |
| 984 | } |
| 985 | else if (res == PARSE_TIME_UNDER) { |
| 986 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n", |
| 987 | file, linenum, args[2], args[0], args[1]); |
| 988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 989 | goto err; |
| 990 | } |
| 991 | else if (res) { |
| 992 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
| 993 | file, linenum, *res, args[0], args[1]); |
| 994 | err_code |= ERR_ALERT | ERR_FATAL; |
| 995 | goto err; |
| 996 | } |
Christopher Faulet | 321d100 | 2022-10-19 16:26:21 +0200 | [diff] [blame] | 997 | if (args[1][0] == 'c') |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 998 | cfg_sink->forward_px->timeout.connect = tout; |
| 999 | else |
| 1000 | cfg_sink->forward_px->timeout.server = tout; |
| 1001 | } |
| 1002 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1003 | else if (strcmp(args[0],"format") == 0) { |
| 1004 | if (!cfg_sink) { |
| 1005 | ha_alert("parsing [%s:%d] : unable to set format '%s'.\n", file, linenum, args[1]); |
| 1006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1007 | goto err; |
| 1008 | } |
| 1009 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 1010 | cfg_sink->fmt = get_log_format(args[1]); |
| 1011 | if (cfg_sink->fmt == LOG_FORMAT_UNSPEC) { |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1012 | ha_alert("parsing [%s:%d] : unknown format '%s'.\n", file, linenum, args[1]); |
| 1013 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1014 | goto err; |
| 1015 | } |
| 1016 | } |
| 1017 | else if (strcmp(args[0],"maxlen") == 0) { |
| 1018 | if (!cfg_sink) { |
| 1019 | ha_alert("parsing [%s:%d] : unable to set event max length '%s'.\n", file, linenum, args[1]); |
| 1020 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1021 | goto err; |
| 1022 | } |
| 1023 | |
| 1024 | cfg_sink->maxlen = atol(args[1]); |
| 1025 | if (!cfg_sink->maxlen) { |
| 1026 | ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]); |
| 1027 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1028 | goto err; |
| 1029 | } |
| 1030 | } |
| 1031 | else if (strcmp(args[0],"description") == 0) { |
| 1032 | if (!cfg_sink) { |
| 1033 | ha_alert("parsing [%s:%d] : unable to set description '%s'.\n", file, linenum, args[1]); |
| 1034 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1035 | goto err; |
| 1036 | } |
| 1037 | |
| 1038 | if (!*args[1]) { |
| 1039 | ha_alert("parsing [%s:%d] : missing ring description text.\n", file, linenum); |
| 1040 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1041 | goto err; |
| 1042 | } |
| 1043 | |
| 1044 | free(cfg_sink->desc); |
| 1045 | |
| 1046 | cfg_sink->desc = strdup(args[1]); |
| 1047 | if (!cfg_sink->desc) { |
| 1048 | ha_alert("parsing [%s:%d] : fail to set description '%s'.\n", file, linenum, args[1]); |
| 1049 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1050 | goto err; |
| 1051 | } |
| 1052 | } |
Emeric Brun | 9f2ff3a | 2020-05-29 15:47:52 +0200 | [diff] [blame] | 1053 | else { |
| 1054 | ha_alert("parsing [%s:%d] : unknown statement '%s'.\n", file, linenum, args[0]); |
| 1055 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1056 | goto err; |
| 1057 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1058 | |
| 1059 | err: |
| 1060 | return err_code; |
| 1061 | } |
| 1062 | |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1063 | /* Creates an new sink buffer from a log server. |
| 1064 | * |
| 1065 | * It uses the logsrvaddress to declare a forward |
| 1066 | * server for this buffer. And it initializes the |
| 1067 | * forwarding. |
| 1068 | * |
| 1069 | * The function returns a pointer on the |
| 1070 | * allocated struct sink if allocate |
| 1071 | * and initialize succeed, else if it fails |
| 1072 | * it returns NULL. |
| 1073 | * |
| 1074 | * Note: the sink is created using the name |
Ilya Shipitsin | b2be9a1 | 2021-04-24 13:25:42 +0500 | [diff] [blame] | 1075 | * specified into logsrv->ring_name |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1076 | */ |
| 1077 | struct sink *sink_new_from_logsrv(struct logsrv *logsrv) |
| 1078 | { |
| 1079 | struct proxy *p = NULL; |
| 1080 | struct sink *sink = NULL; |
| 1081 | struct server *srv = NULL; |
| 1082 | struct sink_forward_target *sft = NULL; |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1083 | |
| 1084 | /* allocate new proxy to handle |
| 1085 | * forward to a stream server |
| 1086 | */ |
| 1087 | p = calloc(1, sizeof *p); |
| 1088 | if (!p) { |
| 1089 | goto error; |
| 1090 | } |
| 1091 | |
| 1092 | init_new_proxy(p); |
| 1093 | sink_setup_proxy(p); |
| 1094 | p->id = strdup(logsrv->ring_name); |
| 1095 | p->conf.args.file = p->conf.file = strdup(logsrv->conf.file); |
| 1096 | p->conf.args.line = p->conf.line = logsrv->conf.line; |
| 1097 | |
| 1098 | /* allocate a new server to forward messages |
| 1099 | * from ring buffer |
| 1100 | */ |
| 1101 | srv = new_server(p); |
| 1102 | if (!srv) |
| 1103 | goto error; |
| 1104 | |
| 1105 | /* init server */ |
| 1106 | srv->id = strdup(logsrv->ring_name); |
| 1107 | srv->conf.file = strdup(logsrv->conf.file); |
| 1108 | srv->conf.line = logsrv->conf.line; |
| 1109 | srv->addr = logsrv->addr; |
| 1110 | srv->svc_port = get_host_port(&logsrv->addr); |
| 1111 | HA_SPIN_INIT(&srv->lock); |
| 1112 | |
| 1113 | /* process per thread init */ |
Miroslav Zagorac | 8a8f270 | 2021-06-15 15:33:20 +0200 | [diff] [blame] | 1114 | if (srv_init_per_thr(srv) == -1) |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1115 | goto error; |
| 1116 | |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1117 | /* the servers are linked backwards |
| 1118 | * first into proxy |
| 1119 | */ |
| 1120 | p->srv = srv; |
| 1121 | srv->next = p->srv; |
| 1122 | |
| 1123 | /* allocate sink_forward_target descriptor */ |
| 1124 | sft = calloc(1, sizeof(*sft)); |
| 1125 | if (!sft) |
| 1126 | goto error; |
| 1127 | |
| 1128 | /* init sink_forward_target offset */ |
| 1129 | sft->srv = srv; |
| 1130 | sft->appctx = NULL; |
| 1131 | sft->ofs = ~0; |
| 1132 | HA_SPIN_INIT(&sft->lock); |
| 1133 | |
Ilya Shipitsin | b2be9a1 | 2021-04-24 13:25:42 +0500 | [diff] [blame] | 1134 | /* prepare description for the sink */ |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1135 | chunk_reset(&trash); |
| 1136 | chunk_printf(&trash, "created from logserver declared into '%s' at line %d", logsrv->conf.file, logsrv->conf.line); |
| 1137 | |
| 1138 | /* allocate a new sink buffer */ |
| 1139 | sink = sink_new_buf(logsrv->ring_name, trash.area, logsrv->format, BUFSIZE); |
| 1140 | if (!sink || sink->type != SINK_TYPE_BUFFER) { |
| 1141 | goto error; |
| 1142 | } |
| 1143 | |
| 1144 | /* link sink_forward_target to proxy */ |
| 1145 | sink->forward_px = p; |
| 1146 | p->parent = sink; |
| 1147 | |
| 1148 | /* insert into sink_forward_targets |
| 1149 | * list into sink |
| 1150 | */ |
Christopher Faulet | 2ae25ea | 2022-05-12 14:50:09 +0200 | [diff] [blame] | 1151 | sft->sink = sink; |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1152 | sft->next = sink->sft; |
| 1153 | sink->sft = sft; |
| 1154 | |
| 1155 | /* mark server as an attached reader to the ring */ |
| 1156 | if (!ring_attach(sink->ctx.ring)) { |
| 1157 | /* should never fail since there is |
| 1158 | * only one reader |
| 1159 | */ |
| 1160 | goto error; |
| 1161 | } |
| 1162 | |
| 1163 | /* initialize sink buffer forwarding */ |
| 1164 | if (!sink_init_forward(sink)) |
| 1165 | goto error; |
| 1166 | |
| 1167 | /* reset familyt of logsrv to consider the ring buffer target */ |
| 1168 | logsrv->addr.ss_family = AF_UNSPEC; |
| 1169 | |
| 1170 | return sink; |
| 1171 | error: |
| 1172 | if (p) { |
| 1173 | if (p->id) |
| 1174 | free(p->id); |
| 1175 | if (p->conf.file) |
| 1176 | free(p->conf.file); |
| 1177 | |
| 1178 | free(p); |
| 1179 | } |
| 1180 | |
| 1181 | if (srv) { |
| 1182 | if (srv->id) |
| 1183 | free(srv->id); |
| 1184 | if (srv->conf.file) |
| 1185 | free((void *)srv->conf.file); |
| 1186 | if (srv->per_thr) |
| 1187 | free(srv->per_thr); |
| 1188 | free(srv); |
| 1189 | } |
| 1190 | |
| 1191 | if (sft) |
| 1192 | free(sft); |
| 1193 | |
| 1194 | if (sink) { |
| 1195 | if (sink->ctx.ring) |
| 1196 | ring_free(sink->ctx.ring); |
| 1197 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1198 | LIST_DELETE(&sink->sink_list); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1199 | free(sink->name); |
| 1200 | free(sink->desc); |
| 1201 | free(sink); |
| 1202 | } |
| 1203 | |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1207 | /* |
| 1208 | * Post parsing "ring" section. |
| 1209 | * |
| 1210 | * The function returns 0 in success case, otherwise, it returns error |
| 1211 | * flags. |
| 1212 | */ |
| 1213 | int cfg_post_parse_ring() |
| 1214 | { |
| 1215 | int err_code = 0; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1216 | struct server *srv; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1217 | |
| 1218 | if (cfg_sink && (cfg_sink->type == SINK_TYPE_BUFFER)) { |
| 1219 | if (cfg_sink->maxlen > b_size(&cfg_sink->ctx.ring->buf)) { |
| 1220 | 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] | 1221 | 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] | 1222 | cfg_sink->maxlen = b_size(&cfg_sink->ctx.ring->buf); |
| 1223 | err_code |= ERR_ALERT; |
| 1224 | } |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1225 | |
| 1226 | /* prepare forward server descriptors */ |
| 1227 | if (cfg_sink->forward_px) { |
| 1228 | srv = cfg_sink->forward_px->srv; |
| 1229 | while (srv) { |
| 1230 | struct sink_forward_target *sft; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1231 | |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1232 | /* allocate sink_forward_target descriptor */ |
| 1233 | sft = calloc(1, sizeof(*sft)); |
| 1234 | if (!sft) { |
| 1235 | ha_alert("memory allocation error initializing server '%s' in ring '%s'.\n",srv->id, cfg_sink->name); |
| 1236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1237 | break; |
| 1238 | } |
| 1239 | sft->srv = srv; |
| 1240 | sft->appctx = NULL; |
| 1241 | sft->ofs = ~0; /* init ring offset */ |
Christopher Faulet | 96417f3 | 2022-08-04 16:00:13 +0200 | [diff] [blame] | 1242 | sft->sink = cfg_sink; |
Emeric Brun | 494c505 | 2020-05-28 11:13:15 +0200 | [diff] [blame] | 1243 | sft->next = cfg_sink->sft; |
| 1244 | HA_SPIN_INIT(&sft->lock); |
| 1245 | |
| 1246 | /* mark server attached to the ring */ |
| 1247 | if (!ring_attach(cfg_sink->ctx.ring)) { |
| 1248 | ha_alert("server '%s' sets too many watchers > 255 on ring '%s'.\n", srv->id, cfg_sink->name); |
| 1249 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1250 | } |
| 1251 | cfg_sink->sft = sft; |
| 1252 | srv = srv->next; |
| 1253 | } |
| 1254 | sink_init_forward(cfg_sink); |
| 1255 | } |
| 1256 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1257 | cfg_sink = NULL; |
| 1258 | |
| 1259 | return err_code; |
| 1260 | } |
| 1261 | |
| 1262 | /* resolve sink names at end of config. Returns 0 on success otherwise error |
| 1263 | * flags. |
| 1264 | */ |
| 1265 | int post_sink_resolve() |
| 1266 | { |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1267 | int err_code = ERR_NONE; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1268 | struct logsrv *logsrv, *logb; |
| 1269 | struct sink *sink; |
| 1270 | struct proxy *px; |
| 1271 | |
| 1272 | list_for_each_entry_safe(logsrv, logb, &global.logsrvs, list) { |
| 1273 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1274 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1275 | if (!sink) { |
| 1276 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1277 | * means we must allocate a sink |
| 1278 | * buffer to send messages to this logsrv |
| 1279 | */ |
| 1280 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1281 | sink = sink_new_from_logsrv(logsrv); |
| 1282 | if (!sink) { |
| 1283 | ha_alert("global stream log server declared in file '%s' at line %d cannot be initialized'.\n", |
| 1284 | logsrv->conf.file, logsrv->conf.line); |
| 1285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1286 | } |
| 1287 | } |
| 1288 | else { |
| 1289 | ha_alert("global log server declared in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1290 | logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1291 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1292 | } |
| 1293 | } |
| 1294 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1295 | ha_alert("global log server declared in file '%s' at line %d uses incompatible ring '%s'.\n", |
| 1296 | logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1297 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1298 | } |
| 1299 | logsrv->sink = sink; |
| 1300 | } |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1301 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | for (px = proxies_list; px; px = px->next) { |
| 1305 | list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) { |
| 1306 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1307 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1308 | if (!sink) { |
| 1309 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1310 | * means we must allocate a sink |
| 1311 | * buffer to send messages to this logsrv |
| 1312 | */ |
| 1313 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1314 | sink = sink_new_from_logsrv(logsrv); |
| 1315 | if (!sink) { |
| 1316 | ha_alert("log server declared in proxy section '%s' file '%s' at line %d cannot be initialized'.\n", |
| 1317 | px->id, logsrv->conf.file, logsrv->conf.line); |
| 1318 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1319 | } |
| 1320 | } |
| 1321 | else { |
| 1322 | ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1323 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1324 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1325 | } |
| 1326 | } |
| 1327 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1328 | ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses incomatible ring named '%s'.\n", |
| 1329 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1330 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1331 | } |
| 1332 | logsrv->sink = sink; |
| 1333 | } |
| 1334 | } |
| 1335 | } |
Emeric Brun | 12941c8 | 2020-07-07 14:19:42 +0200 | [diff] [blame] | 1336 | |
| 1337 | for (px = cfg_log_forward; px; px = px->next) { |
| 1338 | list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) { |
| 1339 | if (logsrv->type == LOG_TARGET_BUFFER) { |
| 1340 | sink = sink_find(logsrv->ring_name); |
Emeric Brun | 94aab06 | 2021-04-02 10:41:36 +0200 | [diff] [blame] | 1341 | if (!sink) { |
| 1342 | /* LOG_TARGET_BUFFER but !AF_UNSPEC |
| 1343 | * means we must allocate a sink |
| 1344 | * buffer to send messages to this logsrv |
| 1345 | */ |
| 1346 | if (logsrv->addr.ss_family != AF_UNSPEC) { |
| 1347 | sink = sink_new_from_logsrv(logsrv); |
| 1348 | if (!sink) { |
| 1349 | ha_alert("log server declared in log-forward section '%s' file '%s' at line %d cannot be initialized'.\n", |
| 1350 | px->id, logsrv->conf.file, logsrv->conf.line); |
| 1351 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1352 | } |
| 1353 | } |
| 1354 | else { |
| 1355 | ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1356 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
| 1357 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1358 | } |
| 1359 | } |
| 1360 | else if (sink->type != SINK_TYPE_BUFFER) { |
| 1361 | ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", |
| 1362 | px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name); |
Emeric Brun | 12941c8 | 2020-07-07 14:19:42 +0200 | [diff] [blame] | 1363 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1364 | } |
| 1365 | logsrv->sink = sink; |
| 1366 | } |
| 1367 | } |
| 1368 | } |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1369 | return err_code; |
| 1370 | } |
| 1371 | |
| 1372 | |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1373 | static void sink_init() |
| 1374 | { |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 1375 | sink_new_fd("stdout", "standard output (fd#1)", LOG_FORMAT_RAW, 1); |
| 1376 | sink_new_fd("stderr", "standard output (fd#2)", LOG_FORMAT_RAW, 2); |
| 1377 | sink_new_buf("buf0", "in-memory ring buffer", LOG_FORMAT_TIMED, 1048576); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | static void sink_deinit() |
| 1381 | { |
| 1382 | struct sink *sink, *sb; |
| 1383 | |
| 1384 | list_for_each_entry_safe(sink, sb, &sink_list, sink_list) { |
Willy Tarreau | 0b8e9ce | 2022-08-11 16:38:20 +0200 | [diff] [blame] | 1385 | if (sink->type == SINK_TYPE_BUFFER) { |
| 1386 | if (sink->store) |
| 1387 | munmap(sink->ctx.ring->buf.area, sink->ctx.ring->buf.size); |
| 1388 | else |
| 1389 | ring_free(sink->ctx.ring); |
| 1390 | } |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1391 | LIST_DELETE(&sink->sink_list); |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1392 | free(sink->name); |
| 1393 | free(sink->desc); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1394 | free(sink); |
| 1395 | } |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | INITCALL0(STG_REGISTER, sink_init); |
Willy Tarreau | 4ed23ca | 2019-08-23 15:47:49 +0200 | [diff] [blame] | 1399 | REGISTER_POST_DEINIT(sink_deinit); |
Willy Tarreau | 973e662 | 2019-08-20 11:57:52 +0200 | [diff] [blame] | 1400 | |
Willy Tarreau | 9f830d7 | 2019-08-26 18:17:04 +0200 | [diff] [blame] | 1401 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 1402 | { { "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] | 1403 | {{},} |
| 1404 | }}; |
| 1405 | |
| 1406 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 1407 | |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 1408 | /* config parsers for this section */ |
| 1409 | REGISTER_CONFIG_SECTION("ring", cfg_parse_ring, cfg_post_parse_ring); |
| 1410 | REGISTER_POST_CHECK(post_sink_resolve); |
| 1411 | |
Willy Tarreau | 67b5a16 | 2019-08-11 16:38:56 +0200 | [diff] [blame] | 1412 | /* |
| 1413 | * Local variables: |
| 1414 | * c-indent-level: 8 |
| 1415 | * c-basic-offset: 8 |
| 1416 | * End: |
| 1417 | */ |