Skip to content

Commit

Permalink
Merge pull request #15515 from opensourcerouting/zlog-recirculate-ldpd
Browse files Browse the repository at this point in the history
ldpd, lib: integrate lde/ldpe into standard logging infrastructure
  • Loading branch information
donaldsharp authored Mar 10, 2024
2 parents aa6ceee + 95a737e commit 5c30b2e
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 182 deletions.
5 changes: 5 additions & 0 deletions ldpd/lde.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "stream.h"
#include "network.h"
#include "libfrr.h"
#include "zlog_live.h"

static void lde_shutdown(void);
static void lde_dispatch_imsg(struct event *thread);
Expand Down Expand Up @@ -116,13 +117,17 @@ static struct frr_signal_t lde_signals[] =
void
lde(void)
{
static struct zlog_live_cfg child_log;

#ifdef HAVE_SETPROCTITLE
setproctitle("label decision engine");
#endif
ldpd_process = PROC_LDE_ENGINE;
log_procname = log_procnames[PROC_LDE_ENGINE];

master = frr_init();
zlog_live_open_fd(&child_log, LOG_DEBUG, LDPD_FD_LOG);

/* no frr_config_fork() here, allow frr_pthread to create threads */
frr_is_after_fork = true;

Expand Down
60 changes: 39 additions & 21 deletions ldpd/ldpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
#include "qobj.h"
#include "libfrr.h"
#include "lib_errors.h"
#include "zlog_recirculate.h"

static void ldpd_shutdown(void);
static pid_t start_child(enum ldpd_process, char *, int, int);
static pid_t start_child(enum ldpd_process, char *, int, int, int);
static void main_dispatch_ldpe(struct event *thread);
static void main_dispatch_lde(struct event *thread);
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
Expand Down Expand Up @@ -69,6 +70,8 @@ DEFINE_QOBJ_TYPE(l2vpn_pw);
DEFINE_QOBJ_TYPE(l2vpn);
DEFINE_QOBJ_TYPE(ldpd_conf);

const char *log_procname;

struct ldpd_global global;
struct ldpd_init init;
struct ldpd_conf *ldpd_conf, *vty_conf;
Expand Down Expand Up @@ -231,8 +234,12 @@ main(int argc, char *argv[])
{
char *saved_argv0;
int lflag = 0, eflag = 0;
int pipe_parent2ldpe[2], pipe_parent2ldpe_sync[2];
int pipe_parent2lde[2], pipe_parent2lde_sync[2];
int pipe_parent2ldpe[2];
int pipe_parent2ldpe_sync[2];
int pipe_ldpe_log[2];
int pipe_parent2lde[2];
int pipe_parent2lde_sync[2];
int pipe_lde_log[2];
bool ctl_sock_used = false;

ldpd_process = PROC_MAIN;
Expand Down Expand Up @@ -300,15 +307,6 @@ main(int argc, char *argv[])
exit(1);
}

if (lflag || eflag) {
struct zprivs_ids_t ids;

zprivs_preinit(&ldpd_privs);
zprivs_get_ids(&ids);

zlog_init(ldpd_di.progname, "LDP", 0,
ids.uid_normal, ids.gid_normal);
}
if (lflag)
lde();
else if (eflag)
Expand All @@ -321,35 +319,56 @@ main(int argc, char *argv[])
pipe_parent2ldpe_sync) == -1)
fatal("socketpair");

if (socketpair(AF_UNIX, SOCK_DGRAM, PF_UNSPEC, pipe_ldpe_log) == -1)
fatal("socketpair");

if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2lde) == -1)
fatal("socketpair");

if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
pipe_parent2lde_sync) == -1)
fatal("socketpair");

if (socketpair(AF_UNIX, SOCK_DGRAM, PF_UNSPEC, pipe_lde_log) == -1)
fatal("socketpair");

sock_set_nonblock(pipe_parent2ldpe[0]);
sock_set_cloexec(pipe_parent2ldpe[0]);
sock_set_nonblock(pipe_parent2ldpe[1]);
sock_set_cloexec(pipe_parent2ldpe[1]);
sock_set_nonblock(pipe_parent2ldpe_sync[0]);
sock_set_cloexec(pipe_parent2ldpe_sync[0]);
sock_set_cloexec(pipe_parent2ldpe_sync[1]);
sock_set_nonblock(pipe_ldpe_log[0]);
sock_set_cloexec(pipe_ldpe_log[0]);
sock_set_nonblock(pipe_ldpe_log[1]);
sock_set_cloexec(pipe_ldpe_log[1]);

sock_set_nonblock(pipe_parent2lde[0]);
sock_set_cloexec(pipe_parent2lde[0]);
sock_set_nonblock(pipe_parent2lde[1]);
sock_set_cloexec(pipe_parent2lde[1]);
sock_set_nonblock(pipe_parent2lde_sync[0]);
sock_set_cloexec(pipe_parent2lde_sync[0]);
sock_set_cloexec(pipe_parent2lde_sync[1]);
sock_set_nonblock(pipe_lde_log[0]);
sock_set_cloexec(pipe_lde_log[0]);
sock_set_nonblock(pipe_lde_log[1]);
sock_set_cloexec(pipe_lde_log[1]);

/* start children */
lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
pipe_parent2lde[1], pipe_parent2lde_sync[1]);
pipe_parent2lde[1], pipe_parent2lde_sync[1], pipe_lde_log[1]);
ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
pipe_parent2ldpe[1], pipe_parent2ldpe_sync[1]);
pipe_parent2ldpe[1], pipe_parent2ldpe_sync[1], pipe_ldpe_log[1]);

master = frr_init();
/* The two child processes use the zlog_live backend to send their
* messages here, where the actual logging config is then applied.
* Look for zlog_live_open_fd() to find the other end of this.
*/
zlog_recirculate_subscribe(master, pipe_lde_log[0]);
zlog_recirculate_subscribe(master, pipe_ldpe_log[0]);

vrf_init(NULL, NULL, NULL, NULL);
access_list_init();
Expand Down Expand Up @@ -484,7 +503,8 @@ ldpd_shutdown(void)
}

static pid_t
start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync,
int fd_log)
{
char *argv[7];
int argc = 0, nullfd;
Expand All @@ -499,6 +519,7 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
default:
close(fd_async);
close(fd_sync);
close(fd_log);
return (pid);
}

Expand All @@ -520,6 +541,9 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
if (dup2(fd_sync, LDPD_FD_SYNC) == -1)
fatal("cannot setup imsg sync fd");

if (dup2(fd_log, LDPD_FD_LOG) == -1)
fatal("cannot setup zlog fd");

argv[argc++] = argv0;
switch (p) {
case PROC_MAIN:
Expand Down Expand Up @@ -569,9 +593,6 @@ static void main_dispatch_ldpe(struct event *thread)
break;

switch (imsg.hdr.type) {
case IMSG_LOG:
logit(imsg.hdr.pid, "%s", (const char *)imsg.data);
break;
case IMSG_REQUEST_SOCKETS:
af = imsg.hdr.pid;
main_imsg_send_net_sockets(af);
Expand Down Expand Up @@ -637,9 +658,6 @@ static void main_dispatch_lde(struct event *thread)
break;

switch (imsg.hdr.type) {
case IMSG_LOG:
logit(imsg.hdr.pid, "%s", (const char *)imsg.data);
break;
case IMSG_KLABEL_CHANGE:
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
sizeof(struct kroute))
Expand Down
2 changes: 1 addition & 1 deletion ldpd/ldpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#define LDPD_FD_ASYNC 3
#define LDPD_FD_SYNC 4
#define LDPD_FD_LOG 5

#define LDPD_OPT_VERBOSE 0x00000001
#define LDPD_OPT_VERBOSE2 0x00000002
Expand Down Expand Up @@ -139,7 +140,6 @@ enum imsg_type {
IMSG_RECONF_L2VPN_IPW,
IMSG_RECONF_END,
IMSG_DEBUG_UPDATE,
IMSG_LOG,
IMSG_ACL_CHECK,
IMSG_INIT,
IMSG_PW_UPDATE,
Expand Down
5 changes: 5 additions & 0 deletions ldpd/ldpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "privs.h"
#include "sigevent.h"
#include "libfrr.h"
#include "zlog_live.h"

static void ldpe_shutdown(void);
static void ldpe_dispatch_main(struct event *thread);
Expand Down Expand Up @@ -93,13 +94,17 @@ char *pkt_ptr; /* packet buffer */
void
ldpe(void)
{
static struct zlog_live_cfg child_log;

#ifdef HAVE_SETPROCTITLE
setproctitle("ldp engine");
#endif
ldpd_process = PROC_LDP_ENGINE;
log_procname = log_procnames[ldpd_process];

master = frr_init();
zlog_live_open_fd(&child_log, LOG_DEBUG, LDPD_FD_LOG);

/* no frr_config_fork() here, allow frr_pthread to create threads */
frr_is_after_fork = true;

Expand Down
138 changes: 0 additions & 138 deletions ldpd/log.c

This file was deleted.

Loading

0 comments on commit 5c30b2e

Please sign in to comment.