-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: ISC | ||
/* | ||
* Copyright (c) 2024 David Lamparter, for NetDEF, Inc. | ||
*/ | ||
|
||
#ifndef _FRR_ZLOG_RECIRCULATE_H | ||
#define _FRR_ZLOG_RECIRCULATE_H | ||
|
||
/* fd should be one end of a socketpair() */ | ||
extern void zlog_recirculate_subscribe(struct event_loop *tm, int fd); | ||
|
||
#endif |