blob: 58bcf81ef589e75f941d3a616bdeb0a033ef2a91 [file] [log] [blame]
Willy Tarreau67b5a162019-08-11 16:38:56 +02001/*
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 Tarreau0b8e9ce2022-08-11 16:38:20 +020021#include <sys/mman.h>
22#include <errno.h>
23#include <fcntl.h>
24
Willy Tarreau36979d92020-06-05 17:27:29 +020025#include <import/ist.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020026#include <haproxy/api.h>
Christopher Faulet6b0a0fb2022-04-04 11:29:28 +020027#include <haproxy/applet.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020028#include <haproxy/cfgparse.h>
Willy Tarreau83487a82020-06-04 20:19:54 +020029#include <haproxy/cli.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020030#include <haproxy/errors.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020031#include <haproxy/list.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020032#include <haproxy/log.h>
Willy Tarreau817538e2021-05-08 20:20:21 +020033#include <haproxy/proxy.h>
Willy Tarreaud2ad57c2020-06-03 19:43:35 +020034#include <haproxy/ring.h>
Willy Tarreau5edca2f2022-05-27 09:25:10 +020035#include <haproxy/sc_strm.h>
Willy Tarreau3727a8a2020-06-04 17:37:26 +020036#include <haproxy/signal.h>
Willy Tarreauba2f73d2020-06-03 20:02:28 +020037#include <haproxy/sink.h>
Willy Tarreaucb086c62022-05-27 09:47:12 +020038#include <haproxy/stconn.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020039#include <haproxy/time.h>
Willy Tarreau4bad5e22021-05-08 13:05:30 +020040#include <haproxy/tools.h>
Willy Tarreau67b5a162019-08-11 16:38:56 +020041
42struct list sink_list = LIST_HEAD_INIT(sink_list);
43
Emeric Brund6e581d2022-09-13 16:16:30 +020044/* sink proxies list */
45struct proxy *sink_proxies_list;
46
Emeric Brun99c453d2020-05-25 15:01:04 +020047struct sink *cfg_sink;
48
Willy Tarreau67b5a162019-08-11 16:38:56 +020049struct 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 Brun54648852020-07-06 15:54:06 +020064static struct sink *__sink_new(const char *name, const char *desc, int fmt)
Willy Tarreau67b5a162019-08-11 16:38:56 +020065{
66 struct sink *sink;
67
68 sink = sink_find(name);
69 if (sink)
70 goto end;
71
Emeric Brun494c5052020-05-28 11:13:15 +020072 sink = calloc(1, sizeof(*sink));
Willy Tarreau67b5a162019-08-11 16:38:56 +020073 if (!sink)
74 goto end;
75
Emeric Brun99c453d2020-05-25 15:01:04 +020076 sink->name = strdup(name);
Tim Duesterhusa7ebffe2021-01-03 19:54:11 +010077 if (!sink->name)
78 goto err;
79
Emeric Brun99c453d2020-05-25 15:01:04 +020080 sink->desc = strdup(desc);
Tim Duesterhusa7ebffe2021-01-03 19:54:11 +010081 if (!sink->desc)
82 goto err;
83
Willy Tarreau67b5a162019-08-11 16:38:56 +020084 sink->fmt = fmt;
85 sink->type = SINK_TYPE_NEW;
Christopher Fauleta63a5c22019-11-15 15:10:12 +010086 sink->maxlen = BUFSIZE;
Willy Tarreau67b5a162019-08-11 16:38:56 +020087 /* address will be filled by the caller if needed */
Willy Tarreau973e6622019-08-20 11:57:52 +020088 sink->ctx.fd = -1;
Willy Tarreau67b5a162019-08-11 16:38:56 +020089 sink->ctx.dropped = 0;
90 HA_RWLOCK_INIT(&sink->ctx.lock);
Willy Tarreau2b718102021-04-21 07:32:39 +020091 LIST_APPEND(&sink_list, &sink->sink_list);
Willy Tarreau67b5a162019-08-11 16:38:56 +020092 end:
93 return sink;
Tim Duesterhusa7ebffe2021-01-03 19:54:11 +010094
95 err:
Willy Tarreau61cfdf42021-02-20 10:46:51 +010096 ha_free(&sink->name);
97 ha_free(&sink->desc);
98 ha_free(&sink);
Tim Duesterhusa7ebffe2021-01-03 19:54:11 +010099
100 return NULL;
Willy Tarreau67b5a162019-08-11 16:38:56 +0200101}
102
Willy Tarreau973e6622019-08-20 11:57:52 +0200103/* 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 Brun54648852020-07-06 15:54:06 +0200107struct sink *sink_new_fd(const char *name, const char *desc, enum log_fmt fmt, int fd)
Willy Tarreau973e6622019-08-20 11:57:52 +0200108{
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 Tarreau4ed23ca2019-08-23 15:47:49 +0200126/* 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 Brun54648852020-07-06 15:54:06 +0200131struct sink *sink_new_buf(const char *name, const char *desc, enum log_fmt fmt, size_t size)
Willy Tarreau4ed23ca2019-08-23 15:47:49 +0200132{
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 Tarreau2b718102021-04-21 07:32:39 +0200153 LIST_DELETE(&sink->sink_list);
Emeric Brun99c453d2020-05-25 15:01:04 +0200154 free(sink->name);
155 free(sink->desc);
Willy Tarreau4ed23ca2019-08-23 15:47:49 +0200156 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 Tarreau67b5a162019-08-11 16:38:56 +0200167/* tries to send <nmsg> message parts (up to 8, ignored above) from message
Ilya Shipitsin46a030c2020-07-05 16:36:08 +0500168 * array <msg> to sink <sink>. Formatting according to the sink's preference is
Willy Tarreau8f240232019-08-27 16:41:06 +0200169 * 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 Tarreau67b5a162019-08-11 16:38:56 +0200173 */
Emeric Brun54648852020-07-06 15:54:06 +0200174 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 Tarreaua1426de2019-08-27 14:21:02 +0200178 size_t npfx = 0;
Emeric Brunbd163812020-05-06 14:33:46 +0200179
Emeric Brun54648852020-07-06 15:54:06 +0200180 if (sink->fmt == LOG_FORMAT_RAW)
Emeric Brunbd163812020-05-06 14:33:46 +0200181 goto send;
Willy Tarreau67b5a162019-08-11 16:38:56 +0200182
Emeric Brun54648852020-07-06 15:54:06 +0200183 pfx = build_log_header(sink->fmt, level, facility, metadata, &npfx);
Emeric Brunbd163812020-05-06 14:33:46 +0200184
185send:
Willy Tarreau973e6622019-08-20 11:57:52 +0200186 if (sink->type == SINK_TYPE_FD) {
Willy Tarreau8f240232019-08-27 16:41:06 +0200187 return fd_write_frag_line(sink->ctx.fd, sink->maxlen, pfx, npfx, msg, nmsg, 1);
Willy Tarreau4ed23ca2019-08-23 15:47:49 +0200188 }
189 else if (sink->type == SINK_TYPE_BUFFER) {
Willy Tarreau8f240232019-08-27 16:41:06 +0200190 return ring_write(sink->ctx.ring, sink->maxlen, pfx, npfx, msg, nmsg);
Willy Tarreau973e6622019-08-20 11:57:52 +0200191 }
Willy Tarreau8f240232019-08-27 16:41:06 +0200192 return 0;
193}
Willy Tarreau67b5a162019-08-11 16:38:56 +0200194
Willy Tarreau8f240232019-08-27 16:41:06 +0200195/* 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 Brun54648852020-07-06 15:54:06 +0200200int sink_announce_dropped(struct sink *sink, int facility)
Willy Tarreau8f240232019-08-27 16:41:06 +0200201{
Emeric Brun54648852020-07-06 15:54:06 +0200202 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 Tarreau8f240232019-08-27 16:41:06 +0200205 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 Brunbd163812020-05-06 14:33:46 +0200214
Emeric Brun54648852020-07-06 15:54:06 +0200215 if (!metadata[LOG_META_HOST].len) {
216 if (global.log_send_hostname)
Tim Duesterhus77508502022-03-15 13:11:06 +0100217 metadata[LOG_META_HOST] = ist(global.log_send_hostname);
Emeric Brun54648852020-07-06 15:54:06 +0200218 }
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 Tarreau8f240232019-08-27 16:41:06 +0200233 return 0;
234 /* success! */
235 HA_ATOMIC_SUB(&sink->ctx.dropped, dropped);
236 }
237 return 1;
Willy Tarreau67b5a162019-08-11 16:38:56 +0200238}
239
Willy Tarreau9f830d72019-08-26 18:17:04 +0200240/* parse the "show events" command, returns 1 if a message is returned, otherwise zero */
241static int cli_parse_show_events(char **args, char *payload, struct appctx *appctx, void *private)
242{
243 struct sink *sink;
Willy Tarreaucba88382022-05-05 15:18:57 +0200244 uint ring_flags;
Willy Tarreau1d181e42019-08-30 11:17:01 +0200245 int arg;
Willy Tarreau9f830d72019-08-26 18:17:04 +0200246
247 args++; // make args[1] the 1st arg
248
249 if (!*args[1]) {
250 /* no arg => report the list of supported sink */
Willy Tarreau1d181e42019-08-30 11:17:01 +0200251 chunk_printf(&trash, "Supported events sinks are listed below. Add -w(wait), -n(new). Any key to stop\n");
Willy Tarreau9f830d72019-08-26 18:17:04 +0200252 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 Tarreaucba88382022-05-05 15:18:57 +0200275 ring_flags = 0;
Willy Tarreau1d181e42019-08-30 11:17:01 +0200276 for (arg = 2; *args[arg]; arg++) {
277 if (strcmp(args[arg], "-w") == 0)
Willy Tarreaucba88382022-05-05 15:18:57 +0200278 ring_flags |= RING_WF_WAIT_MODE;
Willy Tarreau1d181e42019-08-30 11:17:01 +0200279 else if (strcmp(args[arg], "-n") == 0)
Willy Tarreaucba88382022-05-05 15:18:57 +0200280 ring_flags |= RING_WF_SEEK_NEW;
Willy Tarreau1d181e42019-08-30 11:17:01 +0200281 else if (strcmp(args[arg], "-nw") == 0 || strcmp(args[arg], "-wn") == 0)
Willy Tarreaucba88382022-05-05 15:18:57 +0200282 ring_flags |= RING_WF_WAIT_MODE | RING_WF_SEEK_NEW;
Willy Tarreau1d181e42019-08-30 11:17:01 +0200283 else
284 return cli_err(appctx, "unknown option");
285 }
Willy Tarreaucba88382022-05-05 15:18:57 +0200286 return ring_attach_cli(sink->ctx.ring, appctx, ring_flags);
Willy Tarreau9f830d72019-08-26 18:17:04 +0200287}
288
Ilya Shipitsin47d17182020-06-21 21:42:57 +0500289/* Pre-configures a ring proxy to emit connections */
Emeric Brun494c5052020-05-28 11:13:15 +0200290void sink_setup_proxy(struct proxy *px)
291{
292 px->last_change = now.tv_sec;
Christopher Faulet11a707a2022-10-24 15:10:18 +0200293 px->cap = PR_CAP_BE;
Emeric Brun494c5052020-05-28 11:13:15 +0200294 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 Brund6e581d2022-09-13 16:16:30 +0200301 px->next = sink_proxies_list;
302 sink_proxies_list = px;
Emeric Brun494c5052020-05-28 11:13:15 +0200303}
304
305/*
Willy Tarreau42cc8312022-05-04 20:42:23 +0200306 * IO Handler to handle message push to syslog tcp server.
307 * It takes its context from appctx->svcctx.
Emeric Brun494c5052020-05-28 11:13:15 +0200308 */
309static void sink_forward_io_handler(struct appctx *appctx)
310{
Willy Tarreauc12b3212022-05-27 11:08:15 +0200311 struct stconn *sc = appctx_sc(appctx);
Willy Tarreau0eca5392022-05-27 10:44:25 +0200312 struct stream *s = __sc_strm(sc);
Emeric Brun494c5052020-05-28 11:13:15 +0200313 struct sink *sink = strm_fe(s)->parent;
Willy Tarreau42cc8312022-05-04 20:42:23 +0200314 struct sink_forward_target *sft = appctx->svcctx;
Emeric Brun494c5052020-05-28 11:13:15 +0200315 struct ring *ring = sink->ctx.ring;
316 struct buffer *buf = &ring->buf;
317 uint64_t msg_len;
Willy Tarreau53bfab02022-08-04 17:18:54 +0200318 size_t len, cnt, ofs, last_ofs;
Emeric Brun494c5052020-05-28 11:13:15 +0200319 int ret = 0;
320
Ilya Shipitsin47d17182020-06-21 21:42:57 +0500321 /* if stopping was requested, close immediately */
Emeric Brun494c5052020-05-28 11:13:15 +0200322 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 Tarreau0eca5392022-05-27 10:44:25 +0200329 sc_oc(sc)->rex = TICK_ETERNITY;
Emeric Brun494c5052020-05-28 11:13:15 +0200330 /* rto should not change but it seems the case */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200331 sc_oc(sc)->rto = TICK_ETERNITY;
Emeric Brun494c5052020-05-28 11:13:15 +0200332
Christopher Fauletda89e9b2023-01-04 14:11:10 +0100333 if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
Emeric Brun494c5052020-05-28 11:13:15 +0200334 goto close;
335
336 /* con closed by server side */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200337 if ((sc_oc(sc)->flags & CF_SHUTW))
Emeric Brun494c5052020-05-28 11:13:15 +0200338 goto close;
339
340 /* if the connection is not established, inform the stream that we want
341 * to be notified whenever the connection completes.
342 */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200343 if (sc_opposite(sc)->state < SC_ST_EST) {
Willy Tarreau90e8b452022-05-25 18:21:43 +0200344 applet_need_more_data(appctx);
Willy Tarreaub23edc82022-05-24 16:49:03 +0200345 se_need_remote_conn(appctx->sedesc);
Willy Tarreau4164eb92022-05-25 15:42:03 +0200346 applet_have_more_data(appctx);
Emeric Brun494c5052020-05-28 11:13:15 +0200347 return;
348 }
349
350 HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
351 if (appctx != sft->appctx) {
352 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
353 goto close;
354 }
355 ofs = sft->ofs;
356
357 HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
358 LIST_DEL_INIT(&appctx->wait_entry);
359 HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
360
361 HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
362
363 /* explanation for the initialization below: it would be better to do
364 * this in the parsing function but this would occasionally result in
365 * dropped events because we'd take a reference on the oldest message
366 * and keep it while being scheduled. Thus instead let's take it the
367 * first time we enter here so that we have a chance to pass many
368 * existing messages before grabbing a reference to a location. This
369 * value cannot be produced after initialization.
370 */
371 if (unlikely(ofs == ~0)) {
372 ofs = 0;
373
Willy Tarreau4781b152021-04-06 13:53:36 +0200374 HA_ATOMIC_INC(b_peek(buf, ofs));
Emeric Brun494c5052020-05-28 11:13:15 +0200375 ofs += ring->ofs;
376 }
377
Emeric Brun494c5052020-05-28 11:13:15 +0200378 /* in this loop, ofs always points to the counter byte that precedes
379 * the message so that we can take our reference there if we have to
380 * stop before the end (ret=0).
381 */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200382 if (sc_opposite(sc)->state == SC_ST_EST) {
Emeric Brunfdabf492020-12-02 17:02:09 +0100383 /* we were already there, adjust the offset to be relative to
384 * the buffer's head and remove us from the counter.
385 */
386 ofs -= ring->ofs;
387 BUG_ON(ofs >= buf->size);
Willy Tarreau4781b152021-04-06 13:53:36 +0200388 HA_ATOMIC_DEC(b_peek(buf, ofs));
Emeric Brunfdabf492020-12-02 17:02:09 +0100389
Emeric Brun494c5052020-05-28 11:13:15 +0200390 ret = 1;
391 while (ofs + 1 < b_data(buf)) {
392 cnt = 1;
393 len = b_peek_varint(buf, ofs + cnt, &msg_len);
394 if (!len)
395 break;
396 cnt += len;
397 BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
398
399 if (unlikely(msg_len + 1 > b_size(&trash))) {
400 /* too large a message to ever fit, let's skip it */
401 ofs += cnt + msg_len;
402 continue;
403 }
404
405 chunk_reset(&trash);
406 len = b_getblk(buf, trash.area, msg_len, ofs + cnt);
407 trash.data += len;
408 trash.area[trash.data++] = '\n';
409
Willy Tarreaud0a06d52022-05-18 15:07:19 +0200410 if (applet_putchk(appctx, &trash) == -1) {
Emeric Brun494c5052020-05-28 11:13:15 +0200411 ret = 0;
412 break;
413 }
414 ofs += cnt + msg_len;
415 }
416
Willy Tarreau4781b152021-04-06 13:53:36 +0200417 HA_ATOMIC_INC(b_peek(buf, ofs));
Emeric Brun494c5052020-05-28 11:13:15 +0200418 ofs += ring->ofs;
419 sft->ofs = ofs;
Willy Tarreau53bfab02022-08-04 17:18:54 +0200420 last_ofs = ring->ofs;
Emeric Brun494c5052020-05-28 11:13:15 +0200421 }
422 HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
423
424 if (ret) {
425 /* let's be woken up once new data arrive */
426 HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
Willy Tarreau2b718102021-04-21 07:32:39 +0200427 LIST_APPEND(&ring->waiters, &appctx->wait_entry);
Willy Tarreau53bfab02022-08-04 17:18:54 +0200428 ofs = ring->ofs;
Emeric Brun494c5052020-05-28 11:13:15 +0200429 HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
Willy Tarreau53bfab02022-08-04 17:18:54 +0200430 if (ofs != last_ofs) {
431 /* more data was added into the ring between the
432 * unlock and the lock, and the writer might not
433 * have seen us. We need to reschedule a read.
434 */
435 applet_have_more_data(appctx);
436 } else
437 applet_have_no_more_data(appctx);
Emeric Brun494c5052020-05-28 11:13:15 +0200438 }
439 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
440
441 /* always drain data from server */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200442 co_skip(sc_oc(sc), sc_oc(sc)->output);
Emeric Brun494c5052020-05-28 11:13:15 +0200443 return;
444
445close:
Willy Tarreau0eca5392022-05-27 10:44:25 +0200446 sc_shutw(sc);
447 sc_shutr(sc);
Christopher Faulet6e1bbc42022-12-12 08:08:15 +0100448 sc_ic(sc)->flags |= CF_READ_EVENT;
Emeric Brun494c5052020-05-28 11:13:15 +0200449}
450
Emeric Brun97556472020-05-30 01:42:45 +0200451/*
452 * IO Handler to handle message push to syslog tcp server
453 * using octet counting frames
Willy Tarreau42cc8312022-05-04 20:42:23 +0200454 * It takes its context from appctx->svcctx.
Emeric Brun97556472020-05-30 01:42:45 +0200455 */
456static void sink_forward_oc_io_handler(struct appctx *appctx)
457{
Willy Tarreauc12b3212022-05-27 11:08:15 +0200458 struct stconn *sc = appctx_sc(appctx);
Willy Tarreau0eca5392022-05-27 10:44:25 +0200459 struct stream *s = __sc_strm(sc);
Emeric Brun97556472020-05-30 01:42:45 +0200460 struct sink *sink = strm_fe(s)->parent;
Willy Tarreau42cc8312022-05-04 20:42:23 +0200461 struct sink_forward_target *sft = appctx->svcctx;
Emeric Brun97556472020-05-30 01:42:45 +0200462 struct ring *ring = sink->ctx.ring;
463 struct buffer *buf = &ring->buf;
464 uint64_t msg_len;
465 size_t len, cnt, ofs;
466 int ret = 0;
467 char *p;
468
Ilya Shipitsin47d17182020-06-21 21:42:57 +0500469 /* if stopping was requested, close immediately */
Emeric Brun97556472020-05-30 01:42:45 +0200470 if (unlikely(stopping))
471 goto close;
472
473 /* for rex because it seems reset to timeout
474 * and we don't want expire on this case
475 * with a syslog server
476 */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200477 sc_oc(sc)->rex = TICK_ETERNITY;
Emeric Brun97556472020-05-30 01:42:45 +0200478 /* rto should not change but it seems the case */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200479 sc_oc(sc)->rto = TICK_ETERNITY;
Emeric Brun97556472020-05-30 01:42:45 +0200480
481 /* an error was detected */
Christopher Fauletda89e9b2023-01-04 14:11:10 +0100482 if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
Emeric Brun97556472020-05-30 01:42:45 +0200483 goto close;
484
485 /* con closed by server side */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200486 if ((sc_oc(sc)->flags & CF_SHUTW))
Emeric Brun97556472020-05-30 01:42:45 +0200487 goto close;
488
489 /* if the connection is not established, inform the stream that we want
490 * to be notified whenever the connection completes.
491 */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200492 if (sc_opposite(sc)->state < SC_ST_EST) {
Willy Tarreau90e8b452022-05-25 18:21:43 +0200493 applet_need_more_data(appctx);
Willy Tarreaub23edc82022-05-24 16:49:03 +0200494 se_need_remote_conn(appctx->sedesc);
Willy Tarreau4164eb92022-05-25 15:42:03 +0200495 applet_have_more_data(appctx);
Emeric Brun97556472020-05-30 01:42:45 +0200496 return;
497 }
498
499 HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
500 if (appctx != sft->appctx) {
501 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
502 goto close;
503 }
504 ofs = sft->ofs;
505
506 HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
507 LIST_DEL_INIT(&appctx->wait_entry);
508 HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
509
510 HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
511
512 /* explanation for the initialization below: it would be better to do
513 * this in the parsing function but this would occasionally result in
514 * dropped events because we'd take a reference on the oldest message
515 * and keep it while being scheduled. Thus instead let's take it the
516 * first time we enter here so that we have a chance to pass many
517 * existing messages before grabbing a reference to a location. This
518 * value cannot be produced after initialization.
519 */
520 if (unlikely(ofs == ~0)) {
521 ofs = 0;
522
Willy Tarreau4781b152021-04-06 13:53:36 +0200523 HA_ATOMIC_INC(b_peek(buf, ofs));
Emeric Brun97556472020-05-30 01:42:45 +0200524 ofs += ring->ofs;
525 }
526
Emeric Brun97556472020-05-30 01:42:45 +0200527 /* in this loop, ofs always points to the counter byte that precedes
528 * the message so that we can take our reference there if we have to
529 * stop before the end (ret=0).
530 */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200531 if (sc_opposite(sc)->state == SC_ST_EST) {
Emeric Brunfdabf492020-12-02 17:02:09 +0100532 /* we were already there, adjust the offset to be relative to
533 * the buffer's head and remove us from the counter.
534 */
535 ofs -= ring->ofs;
536 BUG_ON(ofs >= buf->size);
Willy Tarreau4781b152021-04-06 13:53:36 +0200537 HA_ATOMIC_DEC(b_peek(buf, ofs));
Emeric Brunfdabf492020-12-02 17:02:09 +0100538
Emeric Brun97556472020-05-30 01:42:45 +0200539 ret = 1;
540 while (ofs + 1 < b_data(buf)) {
541 cnt = 1;
542 len = b_peek_varint(buf, ofs + cnt, &msg_len);
543 if (!len)
544 break;
545 cnt += len;
546 BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
547
548 chunk_reset(&trash);
549 p = ulltoa(msg_len, trash.area, b_size(&trash));
550 if (p) {
551 trash.data = (p - trash.area) + 1;
552 *p = ' ';
553 }
554
555 if (!p || (trash.data + msg_len > b_size(&trash))) {
556 /* too large a message to ever fit, let's skip it */
557 ofs += cnt + msg_len;
558 continue;
559 }
560
561 trash.data += b_getblk(buf, p + 1, msg_len, ofs + cnt);
562
Willy Tarreaud0a06d52022-05-18 15:07:19 +0200563 if (applet_putchk(appctx, &trash) == -1) {
Emeric Brun97556472020-05-30 01:42:45 +0200564 ret = 0;
565 break;
566 }
567 ofs += cnt + msg_len;
568 }
569
Willy Tarreau4781b152021-04-06 13:53:36 +0200570 HA_ATOMIC_INC(b_peek(buf, ofs));
Emeric Brun97556472020-05-30 01:42:45 +0200571 ofs += ring->ofs;
572 sft->ofs = ofs;
573 }
574 HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
575
576 if (ret) {
577 /* let's be woken up once new data arrive */
578 HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
Willy Tarreau2b718102021-04-21 07:32:39 +0200579 LIST_APPEND(&ring->waiters, &appctx->wait_entry);
Emeric Brun97556472020-05-30 01:42:45 +0200580 HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
Willy Tarreau4164eb92022-05-25 15:42:03 +0200581 applet_have_no_more_data(appctx);
Emeric Brun97556472020-05-30 01:42:45 +0200582 }
583 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
584
585 /* always drain data from server */
Willy Tarreau0eca5392022-05-27 10:44:25 +0200586 co_skip(sc_oc(sc), sc_oc(sc)->output);
Emeric Brun97556472020-05-30 01:42:45 +0200587 return;
588
589close:
Willy Tarreau0eca5392022-05-27 10:44:25 +0200590 sc_shutw(sc);
591 sc_shutr(sc);
Christopher Faulet6e1bbc42022-12-12 08:08:15 +0100592 sc_ic(sc)->flags |= CF_READ_EVENT;
Emeric Brun97556472020-05-30 01:42:45 +0200593}
594
Emeric Brun494c5052020-05-28 11:13:15 +0200595void __sink_forward_session_deinit(struct sink_forward_target *sft)
596{
Willy Tarreau0698c802022-05-11 14:09:57 +0200597 struct stream *s = appctx_strm(sft->appctx);
Emeric Brun494c5052020-05-28 11:13:15 +0200598 struct sink *sink;
599
Emeric Brun494c5052020-05-28 11:13:15 +0200600 sink = strm_fe(s)->parent;
601 if (!sink)
602 return;
603
604 HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
605 LIST_DEL_INIT(&sft->appctx->wait_entry);
606 HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
607
608 sft->appctx = NULL;
609 task_wakeup(sink->forward_task, TASK_WOKEN_MSG);
610}
611
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200612static int sink_forward_session_init(struct appctx *appctx)
613{
614 struct sink_forward_target *sft = appctx->svcctx;
615 struct stream *s;
616 struct sockaddr_storage *addr = NULL;
617
618 if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
619 goto out_error;
620
621 if (appctx_finalize_startup(appctx, sft->sink->forward_px, &BUF_NULL) == -1)
622 goto out_free_addr;
623
624 s = appctx_strm(appctx);
Willy Tarreau7cb9e6c2022-05-17 19:40:40 +0200625 s->scb->dst = addr;
Willy Tarreaucb041662022-05-17 19:44:42 +0200626 s->scb->flags |= SC_FL_NOLINGER;
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200627
628 s->target = &sft->srv->obj_type;
629 s->flags = SF_ASSIGNED;
630
631 s->do_log = NULL;
632 s->uniq_id = 0;
633
634 s->res.flags |= CF_READ_DONTWAIT;
635 /* for rto and rex to eternity to not expire on idle recv:
636 * We are using a syslog server.
637 */
638 s->res.rto = TICK_ETERNITY;
639 s->res.rex = TICK_ETERNITY;
640 sft->appctx = appctx;
641
642 return 0;
643
644 out_free_addr:
645 sockaddr_free(&addr);
646 out_error:
647 return -1;
648}
Emeric Brun494c5052020-05-28 11:13:15 +0200649
650static void sink_forward_session_release(struct appctx *appctx)
651{
Willy Tarreau42cc8312022-05-04 20:42:23 +0200652 struct sink_forward_target *sft = appctx->svcctx;
Emeric Brun494c5052020-05-28 11:13:15 +0200653
654 if (!sft)
655 return;
656
657 HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
658 if (sft->appctx == appctx)
659 __sink_forward_session_deinit(sft);
660 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
661}
662
663static struct applet sink_forward_applet = {
664 .obj_type = OBJ_TYPE_APPLET,
665 .name = "<SINKFWD>", /* used for logging */
666 .fct = sink_forward_io_handler,
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200667 .init = sink_forward_session_init,
Emeric Brun494c5052020-05-28 11:13:15 +0200668 .release = sink_forward_session_release,
669};
670
Emeric Brun97556472020-05-30 01:42:45 +0200671static struct applet sink_forward_oc_applet = {
672 .obj_type = OBJ_TYPE_APPLET,
673 .name = "<SINKFWDOC>", /* used for logging */
674 .fct = sink_forward_oc_io_handler,
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200675 .init = sink_forward_session_init,
Emeric Brun97556472020-05-30 01:42:45 +0200676 .release = sink_forward_session_release,
677};
678
Emeric Brun494c5052020-05-28 11:13:15 +0200679/*
680 * Create a new peer session in assigned state (connect will start automatically)
Willy Tarreau42cc8312022-05-04 20:42:23 +0200681 * It sets its context into appctx->svcctx.
Emeric Brun494c5052020-05-28 11:13:15 +0200682 */
683static struct appctx *sink_forward_session_create(struct sink *sink, struct sink_forward_target *sft)
684{
Emeric Brun494c5052020-05-28 11:13:15 +0200685 struct appctx *appctx;
Emeric Brun97556472020-05-30 01:42:45 +0200686 struct applet *applet = &sink_forward_applet;
687
688 if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING)
689 applet = &sink_forward_oc_applet;
Emeric Brun494c5052020-05-28 11:13:15 +0200690
Christopher Faulet6095d572022-05-16 17:09:48 +0200691 appctx = appctx_new_here(applet, NULL);
Christopher Faulet2479e5f2022-01-19 14:50:11 +0100692 if (!appctx)
Christopher Fauleta9e8b392022-03-23 11:01:09 +0100693 goto out_close;
Willy Tarreau42cc8312022-05-04 20:42:23 +0200694 appctx->svcctx = (void *)sft;
Emeric Brun494c5052020-05-28 11:13:15 +0200695
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200696 if (appctx_init(appctx) == -1)
Christopher Faulet92202da2022-05-11 12:22:10 +0200697 goto out_free_appctx;
Christopher Faulet13a35e52021-12-20 15:34:16 +0100698
Emeric Brun494c5052020-05-28 11:13:15 +0200699 return appctx;
700
701 /* Error unrolling */
Emeric Brun494c5052020-05-28 11:13:15 +0200702 out_free_appctx:
Christopher Fauletaee57fc2022-05-12 15:34:48 +0200703 appctx_free_on_early_error(appctx);
Emeric Brun494c5052020-05-28 11:13:15 +0200704 out_close:
705 return NULL;
706}
707
708/*
709 * Task to handle connctions to forward servers
710 */
Willy Tarreau144f84a2021-03-02 16:09:26 +0100711static struct task *process_sink_forward(struct task * task, void *context, unsigned int state)
Emeric Brun494c5052020-05-28 11:13:15 +0200712{
713 struct sink *sink = (struct sink *)context;
714 struct sink_forward_target *sft = sink->sft;
715
716 task->expire = TICK_ETERNITY;
717
718 if (!stopping) {
719 while (sft) {
720 HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
721 /* if appctx is NULL, start a new session */
722 if (!sft->appctx)
723 sft->appctx = sink_forward_session_create(sink, sft);
724 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
725 sft = sft->next;
726 }
727 }
728 else {
729 while (sft) {
730 HA_SPIN_LOCK(SFT_LOCK, &sft->lock);
731 /* awake applet to perform a clean close */
732 if (sft->appctx)
733 appctx_wakeup(sft->appctx);
734 HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
735 sft = sft->next;
736 }
737 }
738
739 return task;
740}
741/*
742 * Init task to manage connctions to forward servers
743 *
744 * returns 0 in case of error.
745 */
746int sink_init_forward(struct sink *sink)
747{
Willy Tarreaubeeabf52021-10-01 18:23:30 +0200748 sink->forward_task = task_new_anywhere();
Emeric Brun494c5052020-05-28 11:13:15 +0200749 if (!sink->forward_task)
750 return 0;
751
752 sink->forward_task->process = process_sink_forward;
753 sink->forward_task->context = (void *)sink;
754 sink->forward_sighandler = signal_register_task(0, sink->forward_task, 0);
755 task_wakeup(sink->forward_task, TASK_WOKEN_INIT);
756 return 1;
757}
Willy Tarreau32872db2022-08-31 18:52:17 +0200758
759/* This tries to rotate a file-backed ring, but only if it contains contents.
760 * This way empty rings will not cause backups to be overwritten and it's safe
761 * to reload multiple times. That's only best effort, failures are silently
762 * ignored.
763 */
764void sink_rotate_file_backed_ring(const char *name)
765{
766 struct ring ring;
767 char *oldback;
768 int ret;
769 int fd;
770
771 fd = open(name, O_RDONLY);
772 if (fd < 0)
773 return;
774
775 /* check for contents validity */
776 ret = read(fd, &ring, sizeof(ring));
777 close(fd);
778
779 if (ret != sizeof(ring))
780 goto rotate;
781
782 /* contents are present, we want to keep them => rotate. Note that
783 * an empty ring buffer has one byte (the marker).
784 */
785 if (ring.buf.data > 1)
786 goto rotate;
787
788 /* nothing to keep, let's scratch the file and preserve the backup */
789 return;
790
791 rotate:
792 oldback = NULL;
793 memprintf(&oldback, "%s.bak", name);
794 if (oldback) {
795 /* try to rename any possibly existing ring file to
796 * ".bak" and delete remains of older ones. This will
797 * ensure we don't wipe useful debug info upon restart.
798 */
799 unlink(oldback);
800 if (rename(name, oldback) < 0)
801 unlink(oldback);
802 ha_free(&oldback);
803 }
804}
805
Emeric Brun99c453d2020-05-25 15:01:04 +0200806/*
807 * Parse "ring" section and create corresponding sink buffer.
808 *
809 * The function returns 0 in success case, otherwise, it returns error
810 * flags.
811 */
812int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
813{
814 int err_code = 0;
815 const char *inv;
816 size_t size = BUFSIZE;
Emeric Brun494c5052020-05-28 11:13:15 +0200817 struct proxy *p;
Emeric Brun99c453d2020-05-25 15:01:04 +0200818
Willy Tarreau18d13062022-08-11 16:12:11 +0200819 if (strcmp(args[0], "ring") == 0) { /* new ring section */
Emeric Brun99c453d2020-05-25 15:01:04 +0200820 if (!*args[1]) {
821 ha_alert("parsing [%s:%d] : missing ring name.\n", file, linenum);
822 err_code |= ERR_ALERT | ERR_FATAL;
823 goto err;
824 }
825
826 inv = invalid_char(args[1]);
827 if (inv) {
828 ha_alert("parsing [%s:%d] : invalid ring name '%s' (character '%c' is not permitted).\n", file, linenum, args[1], *inv);
829 err_code |= ERR_ALERT | ERR_FATAL;
830 goto err;
831 }
832
833 if (sink_find(args[1])) {
834 ha_alert("parsing [%s:%d] : sink named '%s' already exists.\n", file, linenum, args[1]);
835 err_code |= ERR_ALERT | ERR_FATAL;
836 goto err;
837 }
838
Emeric Brun54648852020-07-06 15:54:06 +0200839 cfg_sink = sink_new_buf(args[1], args[1], LOG_FORMAT_RAW, size);
Emeric Brun99c453d2020-05-25 15:01:04 +0200840 if (!cfg_sink || cfg_sink->type != SINK_TYPE_BUFFER) {
841 ha_alert("parsing [%s:%d] : unable to create a new sink buffer for ring '%s'.\n", file, linenum, args[1]);
842 err_code |= ERR_ALERT | ERR_FATAL;
843 goto err;
844 }
Emeric Brun494c5052020-05-28 11:13:15 +0200845
846 /* allocate new proxy to handle forwards */
847 p = calloc(1, sizeof *p);
848 if (!p) {
849 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
850 err_code |= ERR_ALERT | ERR_FATAL;
851 goto err;
852 }
853
854 init_new_proxy(p);
855 sink_setup_proxy(p);
856 p->parent = cfg_sink;
857 p->id = strdup(args[1]);
858 p->conf.args.file = p->conf.file = strdup(file);
859 p->conf.args.line = p->conf.line = linenum;
860 cfg_sink->forward_px = p;
Emeric Brun99c453d2020-05-25 15:01:04 +0200861 }
862 else if (strcmp(args[0], "size") == 0) {
Willy Tarreau18d13062022-08-11 16:12:11 +0200863 if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
864 ha_alert("parsing [%s:%d] : 'size' directive not usable with this type of sink.\n", file, linenum);
865 err_code |= ERR_ALERT | ERR_FATAL;
866 goto err;
867 }
868
Emeric Brun99c453d2020-05-25 15:01:04 +0200869 size = atol(args[1]);
870 if (!size) {
871 ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]);
872 err_code |= ERR_ALERT | ERR_FATAL;
873 goto err;
874 }
875
Willy Tarreau0b8e9ce2022-08-11 16:38:20 +0200876 if (cfg_sink->store) {
877 ha_alert("parsing [%s:%d] : cannot resize an already mapped file, please specify 'size' before 'backing-file'.\n", file, linenum);
878 err_code |= ERR_ALERT | ERR_FATAL;
879 goto err;
880 }
881
Willy Tarreau18d13062022-08-11 16:12:11 +0200882 if (size < cfg_sink->ctx.ring->buf.size) {
883 ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than current size '%llu' for ring '%s'.\n",
884 file, linenum, (ullong)size, (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name);
885 err_code |= ERR_ALERT | ERR_FATAL;
886 goto err;
887 }
888
889 if (!ring_resize(cfg_sink->ctx.ring, size)) {
890 ha_alert("parsing [%s:%d] : fail to set sink buffer size '%llu' for ring '%s'.\n", file, linenum,
891 (ullong)cfg_sink->ctx.ring->buf.size, cfg_sink->name);
Emeric Brun99c453d2020-05-25 15:01:04 +0200892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto err;
894 }
Willy Tarreau0b8e9ce2022-08-11 16:38:20 +0200895 }
896 else if (strcmp(args[0], "backing-file") == 0) {
897 /* This tries to mmap file <file> for size <size> and to use it as a backing store
898 * for ring <ring>. Existing data are delete. NULL is returned on error.
899 */
900 const char *backing = args[1];
901 size_t size;
902 void *area;
903 int fd;
904
905 if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
906 ha_alert("parsing [%s:%d] : 'backing-file' only usable with existing rings.\n", file, linenum);
907 err_code |= ERR_ALERT | ERR_FATAL;
908 goto err;
909 }
910
911 if (cfg_sink->store) {
912 ha_alert("parsing [%s:%d] : 'backing-file' already specified for ring '%s' (was '%s').\n", file, linenum, cfg_sink->name, cfg_sink->store);
913 err_code |= ERR_ALERT | ERR_FATAL;
914 goto err;
915 }
916
Willy Tarreau32872db2022-08-31 18:52:17 +0200917 /* let's check if the file exists and is not empty. That's the
918 * only condition under which we'll trigger a rotate, so that
919 * config checks, reloads, or restarts that don't emit anything
920 * do not rotate it again.
921 */
922 sink_rotate_file_backed_ring(backing);
Willy Tarreauded77cc2022-08-12 15:38:20 +0200923
Willy Tarreau8e877052022-08-12 15:03:12 +0200924 fd = open(backing, O_RDWR | O_CREAT, 0600);
Willy Tarreau0b8e9ce2022-08-11 16:38:20 +0200925 if (fd < 0) {
926 ha_alert("parsing [%s:%d] : cannot open backing-file '%s' for ring '%s': %s.\n", file, linenum, backing, cfg_sink->name, strerror(errno));
927 err_code |= ERR_ALERT | ERR_FATAL;
928 goto err;
929 }
930
931 size = (cfg_sink->ctx.ring->buf.size + 4095UL) & -4096UL;
932 if (ftruncate(fd, size) != 0) {
933 close(fd);
934 ha_alert("parsing [%s:%d] : could not adjust size of backing-file for ring '%s': %s.\n", file, linenum, cfg_sink->name, strerror(errno));
935 err_code |= ERR_ALERT | ERR_FATAL;
936 goto err;
937 }
938
939 area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
940 if (area == MAP_FAILED) {
941 close(fd);
942 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));
943 err_code |= ERR_ALERT | ERR_FATAL;
944 goto err;
945 }
946
947 /* we don't need the file anymore */
948 close(fd);
949 cfg_sink->store = strdup(backing);
950
951 /* never fails */
952 ring_free(cfg_sink->ctx.ring);
953 cfg_sink->ctx.ring = ring_make_from_area(area, size);
Emeric Brun99c453d2020-05-25 15:01:04 +0200954 }
Emeric Brun494c5052020-05-28 11:13:15 +0200955 else if (strcmp(args[0],"server") == 0) {
Willy Tarreau1b662aa2022-11-16 18:56:34 +0100956 if (!cfg_sink || (cfg_sink->type != SINK_TYPE_BUFFER)) {
957 ha_alert("parsing [%s:%d] : unable to create server '%s'.\n", file, linenum, args[1]);
958 err_code |= ERR_ALERT | ERR_FATAL;
959 goto err;
960 }
961
Amaury Denoyelle30c05372021-03-08 16:36:46 +0100962 err_code |= parse_server(file, linenum, args, cfg_sink->forward_px, NULL,
963 SRV_PARSE_PARSE_ADDR|SRV_PARSE_INITIAL_RESOLVE);
Emeric Brun494c5052020-05-28 11:13:15 +0200964 }
965 else if (strcmp(args[0],"timeout") == 0) {
966 if (!cfg_sink || !cfg_sink->forward_px) {
967 ha_alert("parsing [%s:%d] : unable to set timeout '%s'.\n", file, linenum, args[1]);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 goto err;
970 }
971
972 if (strcmp(args[1], "connect") == 0 ||
973 strcmp(args[1], "server") == 0) {
974 const char *res;
975 unsigned int tout;
976
977 if (!*args[2]) {
978 ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n",
979 file, linenum, args[0], args[1]);
980 err_code |= ERR_ALERT | ERR_FATAL;
981 goto err;
982 }
983 res = parse_time_err(args[2], &tout, TIME_UNIT_MS);
984 if (res == PARSE_TIME_OVER) {
985 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n",
986 file, linenum, args[2], args[0], args[1]);
987 err_code |= ERR_ALERT | ERR_FATAL;
988 goto err;
989 }
990 else if (res == PARSE_TIME_UNDER) {
991 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n",
992 file, linenum, args[2], args[0], args[1]);
993 err_code |= ERR_ALERT | ERR_FATAL;
994 goto err;
995 }
996 else if (res) {
997 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n",
998 file, linenum, *res, args[0], args[1]);
999 err_code |= ERR_ALERT | ERR_FATAL;
1000 goto err;
1001 }
Christopher Faulet321d1002022-10-19 16:26:21 +02001002 if (args[1][0] == 'c')
Emeric Brun494c5052020-05-28 11:13:15 +02001003 cfg_sink->forward_px->timeout.connect = tout;
1004 else
1005 cfg_sink->forward_px->timeout.server = tout;
1006 }
1007 }
Emeric Brun99c453d2020-05-25 15:01:04 +02001008 else if (strcmp(args[0],"format") == 0) {
1009 if (!cfg_sink) {
1010 ha_alert("parsing [%s:%d] : unable to set format '%s'.\n", file, linenum, args[1]);
1011 err_code |= ERR_ALERT | ERR_FATAL;
1012 goto err;
1013 }
1014
Emeric Brun54648852020-07-06 15:54:06 +02001015 cfg_sink->fmt = get_log_format(args[1]);
1016 if (cfg_sink->fmt == LOG_FORMAT_UNSPEC) {
Emeric Brun99c453d2020-05-25 15:01:04 +02001017 ha_alert("parsing [%s:%d] : unknown format '%s'.\n", file, linenum, args[1]);
1018 err_code |= ERR_ALERT | ERR_FATAL;
1019 goto err;
1020 }
1021 }
1022 else if (strcmp(args[0],"maxlen") == 0) {
1023 if (!cfg_sink) {
1024 ha_alert("parsing [%s:%d] : unable to set event max length '%s'.\n", file, linenum, args[1]);
1025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto err;
1027 }
1028
1029 cfg_sink->maxlen = atol(args[1]);
1030 if (!cfg_sink->maxlen) {
1031 ha_alert("parsing [%s:%d] : invalid size '%s' for new sink buffer.\n", file, linenum, args[1]);
1032 err_code |= ERR_ALERT | ERR_FATAL;
1033 goto err;
1034 }
1035 }
1036 else if (strcmp(args[0],"description") == 0) {
1037 if (!cfg_sink) {
1038 ha_alert("parsing [%s:%d] : unable to set description '%s'.\n", file, linenum, args[1]);
1039 err_code |= ERR_ALERT | ERR_FATAL;
1040 goto err;
1041 }
1042
1043 if (!*args[1]) {
1044 ha_alert("parsing [%s:%d] : missing ring description text.\n", file, linenum);
1045 err_code |= ERR_ALERT | ERR_FATAL;
1046 goto err;
1047 }
1048
1049 free(cfg_sink->desc);
1050
1051 cfg_sink->desc = strdup(args[1]);
1052 if (!cfg_sink->desc) {
1053 ha_alert("parsing [%s:%d] : fail to set description '%s'.\n", file, linenum, args[1]);
1054 err_code |= ERR_ALERT | ERR_FATAL;
1055 goto err;
1056 }
1057 }
Emeric Brun9f2ff3a2020-05-29 15:47:52 +02001058 else {
1059 ha_alert("parsing [%s:%d] : unknown statement '%s'.\n", file, linenum, args[0]);
1060 err_code |= ERR_ALERT | ERR_FATAL;
1061 goto err;
1062 }
Emeric Brun99c453d2020-05-25 15:01:04 +02001063
1064err:
1065 return err_code;
1066}
1067
Emeric Brun94aab062021-04-02 10:41:36 +02001068/* Creates an new sink buffer from a log server.
1069 *
1070 * It uses the logsrvaddress to declare a forward
1071 * server for this buffer. And it initializes the
1072 * forwarding.
1073 *
1074 * The function returns a pointer on the
1075 * allocated struct sink if allocate
1076 * and initialize succeed, else if it fails
1077 * it returns NULL.
1078 *
1079 * Note: the sink is created using the name
Ilya Shipitsinb2be9a12021-04-24 13:25:42 +05001080 * specified into logsrv->ring_name
Emeric Brun94aab062021-04-02 10:41:36 +02001081 */
1082struct sink *sink_new_from_logsrv(struct logsrv *logsrv)
1083{
1084 struct proxy *p = NULL;
1085 struct sink *sink = NULL;
1086 struct server *srv = NULL;
1087 struct sink_forward_target *sft = NULL;
Emeric Brun94aab062021-04-02 10:41:36 +02001088
1089 /* allocate new proxy to handle
1090 * forward to a stream server
1091 */
1092 p = calloc(1, sizeof *p);
1093 if (!p) {
1094 goto error;
1095 }
1096
1097 init_new_proxy(p);
1098 sink_setup_proxy(p);
1099 p->id = strdup(logsrv->ring_name);
1100 p->conf.args.file = p->conf.file = strdup(logsrv->conf.file);
1101 p->conf.args.line = p->conf.line = logsrv->conf.line;
1102
Christopher Fauletd08a25b2022-10-24 15:53:01 +02001103 /* Set default connect and server timeout */
1104 p->timeout.connect = MS_TO_TICKS(1000);
1105 p->timeout.server = MS_TO_TICKS(5000);
1106
Emeric Brun94aab062021-04-02 10:41:36 +02001107 /* allocate a new server to forward messages
1108 * from ring buffer
1109 */
1110 srv = new_server(p);
1111 if (!srv)
1112 goto error;
1113
1114 /* init server */
1115 srv->id = strdup(logsrv->ring_name);
1116 srv->conf.file = strdup(logsrv->conf.file);
1117 srv->conf.line = logsrv->conf.line;
1118 srv->addr = logsrv->addr;
1119 srv->svc_port = get_host_port(&logsrv->addr);
1120 HA_SPIN_INIT(&srv->lock);
1121
1122 /* process per thread init */
Miroslav Zagorac8a8f2702021-06-15 15:33:20 +02001123 if (srv_init_per_thr(srv) == -1)
Emeric Brun94aab062021-04-02 10:41:36 +02001124 goto error;
1125
Emeric Brun94aab062021-04-02 10:41:36 +02001126 /* the servers are linked backwards
1127 * first into proxy
1128 */
1129 p->srv = srv;
1130 srv->next = p->srv;
1131
1132 /* allocate sink_forward_target descriptor */
1133 sft = calloc(1, sizeof(*sft));
1134 if (!sft)
1135 goto error;
1136
1137 /* init sink_forward_target offset */
1138 sft->srv = srv;
1139 sft->appctx = NULL;
1140 sft->ofs = ~0;
1141 HA_SPIN_INIT(&sft->lock);
1142
Ilya Shipitsinb2be9a12021-04-24 13:25:42 +05001143 /* prepare description for the sink */
Emeric Brun94aab062021-04-02 10:41:36 +02001144 chunk_reset(&trash);
1145 chunk_printf(&trash, "created from logserver declared into '%s' at line %d", logsrv->conf.file, logsrv->conf.line);
1146
1147 /* allocate a new sink buffer */
1148 sink = sink_new_buf(logsrv->ring_name, trash.area, logsrv->format, BUFSIZE);
1149 if (!sink || sink->type != SINK_TYPE_BUFFER) {
1150 goto error;
1151 }
1152
1153 /* link sink_forward_target to proxy */
1154 sink->forward_px = p;
1155 p->parent = sink;
1156
1157 /* insert into sink_forward_targets
1158 * list into sink
1159 */
Christopher Faulet2ae25ea2022-05-12 14:50:09 +02001160 sft->sink = sink;
Emeric Brun94aab062021-04-02 10:41:36 +02001161 sft->next = sink->sft;
1162 sink->sft = sft;
1163
1164 /* mark server as an attached reader to the ring */
1165 if (!ring_attach(sink->ctx.ring)) {
1166 /* should never fail since there is
1167 * only one reader
1168 */
1169 goto error;
1170 }
1171
1172 /* initialize sink buffer forwarding */
1173 if (!sink_init_forward(sink))
1174 goto error;
1175
1176 /* reset familyt of logsrv to consider the ring buffer target */
1177 logsrv->addr.ss_family = AF_UNSPEC;
1178
1179 return sink;
1180error:
1181 if (p) {
1182 if (p->id)
1183 free(p->id);
1184 if (p->conf.file)
1185 free(p->conf.file);
1186
1187 free(p);
1188 }
1189
1190 if (srv) {
1191 if (srv->id)
1192 free(srv->id);
1193 if (srv->conf.file)
1194 free((void *)srv->conf.file);
1195 if (srv->per_thr)
1196 free(srv->per_thr);
1197 free(srv);
1198 }
1199
1200 if (sft)
1201 free(sft);
1202
1203 if (sink) {
1204 if (sink->ctx.ring)
1205 ring_free(sink->ctx.ring);
1206
Willy Tarreau2b718102021-04-21 07:32:39 +02001207 LIST_DELETE(&sink->sink_list);
Emeric Brun94aab062021-04-02 10:41:36 +02001208 free(sink->name);
1209 free(sink->desc);
1210 free(sink);
1211 }
1212
1213 return NULL;
1214}
1215
Emeric Brun99c453d2020-05-25 15:01:04 +02001216/*
1217 * Post parsing "ring" section.
1218 *
1219 * The function returns 0 in success case, otherwise, it returns error
1220 * flags.
1221 */
1222int cfg_post_parse_ring()
1223{
1224 int err_code = 0;
Emeric Brun494c5052020-05-28 11:13:15 +02001225 struct server *srv;
Emeric Brun99c453d2020-05-25 15:01:04 +02001226
1227 if (cfg_sink && (cfg_sink->type == SINK_TYPE_BUFFER)) {
1228 if (cfg_sink->maxlen > b_size(&cfg_sink->ctx.ring->buf)) {
1229 ha_warning("ring '%s' event max length '%u' exceeds size, forced to size '%lu'.\n",
Willy Tarreau570a22b2020-06-02 12:00:46 +02001230 cfg_sink->name, cfg_sink->maxlen, (unsigned long)b_size(&cfg_sink->ctx.ring->buf));
Emeric Brun99c453d2020-05-25 15:01:04 +02001231 cfg_sink->maxlen = b_size(&cfg_sink->ctx.ring->buf);
1232 err_code |= ERR_ALERT;
1233 }
Emeric Brun494c5052020-05-28 11:13:15 +02001234
1235 /* prepare forward server descriptors */
1236 if (cfg_sink->forward_px) {
1237 srv = cfg_sink->forward_px->srv;
1238 while (srv) {
1239 struct sink_forward_target *sft;
Emeric Brun99c453d2020-05-25 15:01:04 +02001240
Emeric Brun494c5052020-05-28 11:13:15 +02001241 /* allocate sink_forward_target descriptor */
1242 sft = calloc(1, sizeof(*sft));
1243 if (!sft) {
1244 ha_alert("memory allocation error initializing server '%s' in ring '%s'.\n",srv->id, cfg_sink->name);
1245 err_code |= ERR_ALERT | ERR_FATAL;
1246 break;
1247 }
1248 sft->srv = srv;
1249 sft->appctx = NULL;
1250 sft->ofs = ~0; /* init ring offset */
Christopher Faulet96417f32022-08-04 16:00:13 +02001251 sft->sink = cfg_sink;
Emeric Brun494c5052020-05-28 11:13:15 +02001252 sft->next = cfg_sink->sft;
1253 HA_SPIN_INIT(&sft->lock);
1254
1255 /* mark server attached to the ring */
1256 if (!ring_attach(cfg_sink->ctx.ring)) {
1257 ha_alert("server '%s' sets too many watchers > 255 on ring '%s'.\n", srv->id, cfg_sink->name);
1258 err_code |= ERR_ALERT | ERR_FATAL;
1259 }
1260 cfg_sink->sft = sft;
1261 srv = srv->next;
1262 }
1263 sink_init_forward(cfg_sink);
1264 }
1265 }
Emeric Brun99c453d2020-05-25 15:01:04 +02001266 cfg_sink = NULL;
1267
1268 return err_code;
1269}
1270
1271/* resolve sink names at end of config. Returns 0 on success otherwise error
1272 * flags.
1273*/
1274int post_sink_resolve()
1275{
Christopher Fauletfc633b62020-11-06 15:24:23 +01001276 int err_code = ERR_NONE;
Emeric Brun99c453d2020-05-25 15:01:04 +02001277 struct logsrv *logsrv, *logb;
1278 struct sink *sink;
1279 struct proxy *px;
1280
1281 list_for_each_entry_safe(logsrv, logb, &global.logsrvs, list) {
1282 if (logsrv->type == LOG_TARGET_BUFFER) {
1283 sink = sink_find(logsrv->ring_name);
Emeric Brun94aab062021-04-02 10:41:36 +02001284 if (!sink) {
1285 /* LOG_TARGET_BUFFER but !AF_UNSPEC
1286 * means we must allocate a sink
1287 * buffer to send messages to this logsrv
1288 */
1289 if (logsrv->addr.ss_family != AF_UNSPEC) {
1290 sink = sink_new_from_logsrv(logsrv);
1291 if (!sink) {
1292 ha_alert("global stream log server declared in file '%s' at line %d cannot be initialized'.\n",
1293 logsrv->conf.file, logsrv->conf.line);
1294 err_code |= ERR_ALERT | ERR_FATAL;
1295 }
1296 }
1297 else {
1298 ha_alert("global log server declared in file '%s' at line %d uses unknown ring named '%s'.\n",
1299 logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
1300 err_code |= ERR_ALERT | ERR_FATAL;
1301 }
1302 }
1303 else if (sink->type != SINK_TYPE_BUFFER) {
1304 ha_alert("global log server declared in file '%s' at line %d uses incompatible ring '%s'.\n",
1305 logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
Emeric Brun99c453d2020-05-25 15:01:04 +02001306 err_code |= ERR_ALERT | ERR_FATAL;
1307 }
1308 logsrv->sink = sink;
1309 }
Emeric Brun94aab062021-04-02 10:41:36 +02001310
Emeric Brun99c453d2020-05-25 15:01:04 +02001311 }
1312
1313 for (px = proxies_list; px; px = px->next) {
1314 list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) {
1315 if (logsrv->type == LOG_TARGET_BUFFER) {
1316 sink = sink_find(logsrv->ring_name);
Emeric Brun94aab062021-04-02 10:41:36 +02001317 if (!sink) {
1318 /* LOG_TARGET_BUFFER but !AF_UNSPEC
1319 * means we must allocate a sink
1320 * buffer to send messages to this logsrv
1321 */
1322 if (logsrv->addr.ss_family != AF_UNSPEC) {
1323 sink = sink_new_from_logsrv(logsrv);
1324 if (!sink) {
1325 ha_alert("log server declared in proxy section '%s' file '%s' at line %d cannot be initialized'.\n",
1326 px->id, logsrv->conf.file, logsrv->conf.line);
1327 err_code |= ERR_ALERT | ERR_FATAL;
1328 }
1329 }
1330 else {
1331 ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
1332 px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
1333 err_code |= ERR_ALERT | ERR_FATAL;
1334 }
1335 }
1336 else if (sink->type != SINK_TYPE_BUFFER) {
1337 ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses incomatible ring named '%s'.\n",
1338 px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
Emeric Brun99c453d2020-05-25 15:01:04 +02001339 err_code |= ERR_ALERT | ERR_FATAL;
1340 }
1341 logsrv->sink = sink;
1342 }
1343 }
1344 }
Emeric Brun12941c82020-07-07 14:19:42 +02001345
1346 for (px = cfg_log_forward; px; px = px->next) {
1347 list_for_each_entry_safe(logsrv, logb, &px->logsrvs, list) {
1348 if (logsrv->type == LOG_TARGET_BUFFER) {
1349 sink = sink_find(logsrv->ring_name);
Emeric Brun94aab062021-04-02 10:41:36 +02001350 if (!sink) {
1351 /* LOG_TARGET_BUFFER but !AF_UNSPEC
1352 * means we must allocate a sink
1353 * buffer to send messages to this logsrv
1354 */
1355 if (logsrv->addr.ss_family != AF_UNSPEC) {
1356 sink = sink_new_from_logsrv(logsrv);
1357 if (!sink) {
1358 ha_alert("log server declared in log-forward section '%s' file '%s' at line %d cannot be initialized'.\n",
1359 px->id, logsrv->conf.file, logsrv->conf.line);
1360 err_code |= ERR_ALERT | ERR_FATAL;
1361 }
1362 }
1363 else {
1364 ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
1365 px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
1366 err_code |= ERR_ALERT | ERR_FATAL;
1367 }
1368 }
1369 else if (sink->type != SINK_TYPE_BUFFER) {
1370 ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n",
1371 px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
Emeric Brun12941c82020-07-07 14:19:42 +02001372 err_code |= ERR_ALERT | ERR_FATAL;
1373 }
1374 logsrv->sink = sink;
1375 }
1376 }
1377 }
Emeric Brun99c453d2020-05-25 15:01:04 +02001378 return err_code;
1379}
1380
1381
Willy Tarreau973e6622019-08-20 11:57:52 +02001382static void sink_init()
1383{
Emeric Brun54648852020-07-06 15:54:06 +02001384 sink_new_fd("stdout", "standard output (fd#1)", LOG_FORMAT_RAW, 1);
1385 sink_new_fd("stderr", "standard output (fd#2)", LOG_FORMAT_RAW, 2);
1386 sink_new_buf("buf0", "in-memory ring buffer", LOG_FORMAT_TIMED, 1048576);
Willy Tarreau4ed23ca2019-08-23 15:47:49 +02001387}
1388
1389static void sink_deinit()
1390{
1391 struct sink *sink, *sb;
1392
1393 list_for_each_entry_safe(sink, sb, &sink_list, sink_list) {
Willy Tarreau0b8e9ce2022-08-11 16:38:20 +02001394 if (sink->type == SINK_TYPE_BUFFER) {
Willy Tarreaufb9a4762023-01-24 12:11:41 +01001395 if (sink->store) {
1396 size_t size = (sink->ctx.ring->buf.size + 4095UL) & -4096UL;
1397 void *area = (sink->ctx.ring->buf.area - sizeof(*sink->ctx.ring));
1398
1399 msync(area, size, MS_SYNC);
1400 munmap(area, size);
Willy Tarreaub9191092023-01-26 15:34:31 +01001401 ha_free(&sink->store);
Willy Tarreaufb9a4762023-01-24 12:11:41 +01001402 }
Willy Tarreau0b8e9ce2022-08-11 16:38:20 +02001403 else
1404 ring_free(sink->ctx.ring);
1405 }
Willy Tarreau2b718102021-04-21 07:32:39 +02001406 LIST_DELETE(&sink->sink_list);
Willy Tarreau09727ee2023-01-26 15:46:08 +01001407 task_destroy(sink->forward_task);
Emeric Brun99c453d2020-05-25 15:01:04 +02001408 free(sink->name);
1409 free(sink->desc);
Willy Tarreau4ed23ca2019-08-23 15:47:49 +02001410 free(sink);
1411 }
Willy Tarreau973e6622019-08-20 11:57:52 +02001412}
1413
1414INITCALL0(STG_REGISTER, sink_init);
Willy Tarreau4ed23ca2019-08-23 15:47:49 +02001415REGISTER_POST_DEINIT(sink_deinit);
Willy Tarreau973e6622019-08-20 11:57:52 +02001416
Willy Tarreau9f830d72019-08-26 18:17:04 +02001417static struct cli_kw_list cli_kws = {{ },{
Willy Tarreaub205bfd2021-05-07 11:38:37 +02001418 { { "show", "events", NULL }, "show events [<sink>] [-w] [-n] : show event sink state", cli_parse_show_events, NULL, NULL },
Willy Tarreau9f830d72019-08-26 18:17:04 +02001419 {{},}
1420}};
1421
1422INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
1423
Emeric Brun99c453d2020-05-25 15:01:04 +02001424/* config parsers for this section */
1425REGISTER_CONFIG_SECTION("ring", cfg_parse_ring, cfg_post_parse_ring);
1426REGISTER_POST_CHECK(post_sink_resolve);
1427
Willy Tarreau67b5a162019-08-11 16:38:56 +02001428/*
1429 * Local variables:
1430 * c-indent-level: 8
1431 * c-basic-offset: 8
1432 * End:
1433 */