diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2024-01-25 22:11:44 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2024-03-10 12:42:02 +0100 |
commit | 5f16c640c248bba898addb3ff36b84d212f6e8e6 (patch) | |
tree | 97ba2b439fdf292edefd36e1e6eec0bca21bea25 /lib/zlog_recirculate.c | |
parent | Merge pull request #15510 from idryzhov/fix-rip-ripng-rpc (diff) | |
download | frr-5f16c640c248bba898addb3ff36b84d212f6e8e6.tar.xz frr-5f16c640c248bba898addb3ff36b84d212f6e8e6.zip |
lib: allow recirculating/relaying log messages
This is primarily intended for ldpd with its split-process architecture.
The LDE/LDPE subprocesses currently lose the extended zlog
functionality.
The zlog_live target already encapsulates all necessary bits for vtysh.
Reuse it for a relay function to be used in the main ldpd process.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/zlog_recirculate.c')
-rw-r--r-- | lib/zlog_recirculate.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/zlog_recirculate.c b/lib/zlog_recirculate.c new file mode 100644 index 000000000..abc73eeed --- /dev/null +++ b/lib/zlog_recirculate.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: ISC +/* + * Copyright (c) 2024 David Lamparter, for NetDEF, Inc. + */ + +#include "zebra.h" + +#include "log.h" +#include "frrevent.h" + +#include "zlog_recirculate.h" + +/* This is only the event loop part; it's split off from + * zlog_recirculate_live_msg since there's an integration boundary; this + * half deals with events, the other half with zlog interna. + * + * As of writing, this runs in ldpd in the *parent* process and receives log + * messages from the lde/ldpe subprocesses. It is not used anywhere else + * (yet?) + */ +static void zlog_recirculate_recv(struct event *ev) +{ + uint8_t rxbuf[4096]; + ssize_t n_rd; + int fd = EVENT_FD(ev); + + /* see below for -2, "\n\0" are added */ + n_rd = read(fd, rxbuf, sizeof(rxbuf) - 2); + if (n_rd == 0) { + /* EOF */ + close(fd); + /* event_add_read not called yet, nothing to cancel */ + return; + } + if (n_rd < 0 && (errno != EAGAIN) && (errno != EWOULDBLOCK)) { + /* error */ + zlog_warn("error on log relay socket %d: %m", fd); + close(fd); + /* event_add_read not called yet, nothing to cancel */ + return; + } + + event_add_read(ev->master, zlog_recirculate_recv, NULL, fd, NULL); + if (n_rd < 0) + return; + + /* log infrastructure has an implicit \n\0 at the end */ + rxbuf[n_rd] = '\n'; + rxbuf[n_rd + 1] = '\0'; + zlog_recirculate_live_msg(rxbuf, n_rd); +} + +void zlog_recirculate_subscribe(struct event_loop *el, int fd) +{ + event_add_read(el, zlog_recirculate_recv, NULL, fd, NULL); +} |