#include "libfrr.h"
static void ldpd_shutdown(void);
-static pid_t start_child(enum ldpd_process, char *, int, int,
- const char *, const char *, const char *, const char *);
+static pid_t start_child(enum ldpd_process, char *, int, int);
static int main_dispatch_ldpe(struct thread *);
static int main_dispatch_lde(struct thread *);
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
static void main_imsg_send_net_socket(int, enum socket_type);
static int main_imsg_send_config(struct ldpd_conf *);
static void ldp_config_normalize(struct ldpd_conf *);
+static void ldp_config_reset(struct ldpd_conf *);
static void ldp_config_reset_main(struct ldpd_conf *);
static void ldp_config_reset_af(struct ldpd_conf *, int);
static void ldp_config_reset_l2vpns(struct ldpd_conf *);
DEFINE_QOBJ_TYPE(ldpd_conf)
struct ldpd_global global;
+struct ldpd_init init;
struct ldpd_conf *ldpd_conf, *vty_conf;
static struct imsgev *iev_ldpe, *iev_ldpe_sync;
{
log_info("SIGHUP received");
- /* reset vty_conf */
- ldp_config_reset_main(vty_conf);
- ldp_config_reset_l2vpns(vty_conf);
-
- /* read configuration file without applying any changes */
- global.sighup = 1;
- vty_read_config(ldpd_di.config_file, config_default);
- global.sighup = 0;
-
/*
- * Apply the new configuration all at once, this way merge_config()
- * will be the least disruptive as possible.
+ * Do a full configuration reload. In other words, reset vty_conf
+ * and build a new configuartion from scratch.
*/
- ldp_reload(vty_conf);
+ ldp_config_reset(vty_conf);
+ vty_read_config(ldpd_di.config_file, config_default);
+ ldp_config_apply(NULL, vty_conf);
}
/* SIGINT / SIGTERM handler. */
int lflag = 0, eflag = 0;
int pipe_parent2ldpe[2], pipe_parent2ldpe_sync[2];
int pipe_parent2lde[2], pipe_parent2lde_sync[2];
- char *ctl_sock_custom_path = NULL;
char *ctl_sock_name;
- const char *user = NULL;
- const char *group = NULL;
- u_short instance = 0;
- const char *instance_char = NULL;
ldpd_process = PROC_MAIN;
+ log_procname = log_procnames[ldpd_process];
saved_argv0 = argv[0];
if (saved_argv0 == NULL)
* sensible config
*/
ctl_sock_name = (char *)LDPD_SOCKET;
- ctl_sock_custom_path = optarg;
- strlcpy(ctl_sock_path, ctl_sock_custom_path,
- sizeof(ctl_sock_path));
+ strlcpy(ctl_sock_path, optarg, sizeof(ctl_sock_path));
strlcat(ctl_sock_path, "/", sizeof(ctl_sock_path));
strlcat(ctl_sock_path, ctl_sock_name,
sizeof(ctl_sock_path));
break;
case 'n':
- instance = atoi(optarg);
- instance_char = optarg;
- if (instance < 1)
+ init.instance = atoi(optarg);
+ if (init.instance < 1)
exit(0);
break;
case 'L':
}
}
- user = ldpd_privs.user;
- group = ldpd_privs.group;
+ strlcpy(init.user, ldpd_privs.user, sizeof(init.user));
+ strlcpy(init.group, ldpd_privs.group, sizeof(init.group));
+ strlcpy(init.ctl_sock_path, ctl_sock_path, sizeof(init.ctl_sock_path));
+ strlcpy(init.zclient_serv_path, frr_zclientpath,
+ sizeof(init.zclient_serv_path));
argc -= optind;
argv += optind;
exit(1);
}
+ if (lflag || eflag)
+ openzlog(ldpd_di.progname, "LDP", 0,
+ LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
if (lflag)
- lde(user, group, instance);
+ lde();
else if (eflag)
- ldpe(user, group, ctl_sock_path);
-
- openzlog(ldpd_di.progname, "LDP", 0,
- LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
+ ldpe();
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2ldpe) == -1)
fatal("socketpair");
/* start children */
lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
- pipe_parent2lde[1], pipe_parent2lde_sync[1],
- user, group, ctl_sock_custom_path, instance_char);
+ pipe_parent2lde[1], pipe_parent2lde_sync[1]);
ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
- pipe_parent2ldpe[1], pipe_parent2ldpe_sync[1],
- user, group, ctl_sock_custom_path, instance_char);
-
- /* drop privileges */
- zprivs_init(&ldpd_privs);
+ pipe_parent2ldpe[1], pipe_parent2ldpe_sync[1]);
- /* setup signal handler */
- signal_init(master, array_size(ldp_signals), ldp_signals);
+ master = frr_init();
- /* thread master */
- master = thread_master_create();
-
- /* library inits */
- cmd_init(1);
vty_config_lockless();
- vty_init(master);
- vrf_init();
+ vrf_init(NULL, NULL, NULL, NULL);
access_list_init();
ldp_vty_init();
ldp_zebra_init(master);
- /* create base configuration with sane defaults */
- ldpd_conf = config_new_empty();
- ldp_config_reset_main(ldpd_conf);
-
/*
- * Create vty_conf as a duplicate of the main configuration. All
- * configuration requests (e.g. CLI) act on vty_conf and then call
- * ldp_reload() to merge the changes into ldpd_conf.
+ * Create base configuration with sane defaults. All configuration
+ * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
+ * to merge the changes into ldpd_conf, which contains the actual
+ * running configuration.
*/
+ ldpd_conf = config_new_empty();
vty_conf = config_new_empty();
- ldp_config_reset_main(vty_conf);
QOBJ_REG(vty_conf, ldpd_conf);
/* read configuration file and daemonize */
frr_config_fork();
+ /* apply configuration */
+ ldp_config_apply(NULL, vty_conf);
+
/* setup pipes to children */
if ((iev_ldpe = calloc(1, sizeof(struct imsgev))) == NULL ||
(iev_ldpe_sync = calloc(1, sizeof(struct imsgev))) == NULL ||
fatal(NULL);
imsg_init(&iev_ldpe->ibuf, pipe_parent2ldpe[0]);
iev_ldpe->handler_read = main_dispatch_ldpe;
- iev_ldpe->ev_read = thread_add_read(master, iev_ldpe->handler_read,
- iev_ldpe, iev_ldpe->ibuf.fd);
+ iev_ldpe->ev_read = NULL;
+ thread_add_read(master, iev_ldpe->handler_read, iev_ldpe, iev_ldpe->ibuf.fd,
+ &iev_ldpe->ev_read);
iev_ldpe->handler_write = ldp_write_handler;
imsg_init(&iev_ldpe_sync->ibuf, pipe_parent2ldpe_sync[0]);
iev_ldpe_sync->handler_read = main_dispatch_ldpe;
- iev_ldpe_sync->ev_read = thread_add_read(master,
- iev_ldpe_sync->handler_read, iev_ldpe_sync, iev_ldpe_sync->ibuf.fd);
+ iev_ldpe_sync->ev_read = NULL;
+ thread_add_read(master, iev_ldpe_sync->handler_read, iev_ldpe_sync, iev_ldpe_sync->ibuf.fd,
+ &iev_ldpe_sync->ev_read);
iev_ldpe_sync->handler_write = ldp_write_handler;
imsg_init(&iev_lde->ibuf, pipe_parent2lde[0]);
iev_lde->handler_read = main_dispatch_lde;
- iev_lde->ev_read = thread_add_read(master, iev_lde->handler_read,
- iev_lde, iev_lde->ibuf.fd);
+ iev_lde->ev_read = NULL;
+ thread_add_read(master, iev_lde->handler_read, iev_lde, iev_lde->ibuf.fd,
+ &iev_lde->ev_read);
iev_lde->handler_write = ldp_write_handler;
imsg_init(&iev_lde_sync->ibuf, pipe_parent2lde_sync[0]);
iev_lde_sync->handler_read = main_dispatch_lde;
- iev_lde_sync->ev_read = thread_add_read(master,
- iev_lde_sync->handler_read, iev_lde_sync, iev_lde_sync->ibuf.fd);
+ iev_lde_sync->ev_read = NULL;
+ thread_add_read(master, iev_lde_sync->handler_read, iev_lde_sync, iev_lde_sync->ibuf.fd,
+ &iev_lde_sync->ev_read);
iev_lde_sync->handler_write = ldp_write_handler;
if (main_imsg_send_ipc_sockets(&iev_ldpe->ibuf, &iev_lde->ibuf))
fatal("could not establish imsg links");
+ main_imsg_compose_both(IMSG_INIT, &init, sizeof(init));
main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
sizeof(ldp_debug));
main_imsg_send_config(ldpd_conf);
config_clear(ldpd_conf);
- ldp_config_reset_main(vty_conf);
- ldp_config_reset_l2vpns(vty_conf);
+ ldp_config_reset(vty_conf);
QOBJ_UNREG(vty_conf);
free(vty_conf);
}
static pid_t
-start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync,
- const char *user, const char *group, const char *ctl_sock_custom_path,
- const char *instance)
+start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
{
- char *argv[13];
+ char *argv[3];
int argc = 0;
pid_t pid;
argv[argc++] = (char *)"-E";
break;
}
- if (user) {
- argv[argc++] = (char *)"-u";
- argv[argc++] = (char *)user;
- }
- if (group) {
- argv[argc++] = (char *)"-g";
- argv[argc++] = (char *)group;
- }
- if (ctl_sock_custom_path) {
- argv[argc++] = (char *)"--ctl_socket";
- argv[argc++] = (char *)ctl_sock_custom_path;
- }
- /* zclient serv path */
-#ifdef HAVE_TCP_ZEBRA
-#else
- argv[argc++] = (char *)"-z";
- argv[argc++] = (char *)zclient_serv_path_get();
-#endif
- /* instance */
- if (instance) {
- argv[argc++] = (char *)"-n";
- argv[argc++] = (char *)instance;
- }
argv[argc++] = NULL;
execvp(argv0, argv);
if (kr_delete(imsg.data))
log_warnx("%s: error deleting route", __func__);
break;
- case IMSG_KPWLABEL_CHANGE:
+ case IMSG_KPW_ADD:
+ case IMSG_KPW_DELETE:
+ case IMSG_KPW_SET:
+ case IMSG_KPW_UNSET:
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
- sizeof(struct kpw))
+ sizeof(struct zapi_pw))
fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
- if (kmpw_set(imsg.data))
- log_warnx("%s: error changing pseudowire",
- __func__);
- break;
- case IMSG_KPWLABEL_DELETE:
- if (imsg.hdr.len - IMSG_HEADER_SIZE !=
- sizeof(struct kpw))
- fatalx("invalid size of IMSG_KPWLABEL_DELETE");
- if (kmpw_unset(imsg.data))
- log_warnx("%s: error unsetting pseudowire",
- __func__);
+
+ switch (imsg.hdr.type) {
+ case IMSG_KPW_ADD:
+ if (kmpw_add(imsg.data))
+ log_warnx("%s: error adding "
+ "pseudowire", __func__);
+ break;
+ case IMSG_KPW_DELETE:
+ if (kmpw_del(imsg.data))
+ log_warnx("%s: error deleting "
+ "pseudowire", __func__);
+ break;
+ case IMSG_KPW_SET:
+ if (kmpw_set(imsg.data))
+ log_warnx("%s: error setting "
+ "pseudowire", __func__);
+ break;
+ case IMSG_KPW_UNSET:
+ if (kmpw_unset(imsg.data))
+ log_warnx("%s: error unsetting "
+ "pseudowire", __func__);
+ break;
+ }
break;
case IMSG_ACL_CHECK:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
imsg_event_add(struct imsgev *iev)
{
if (iev->handler_read)
- THREAD_READ_ON(master, iev->ev_read, iev->handler_read, iev,
- iev->ibuf.fd);
+ thread_add_read(master, iev->handler_read, iev, iev->ibuf.fd,
+ &iev->ev_read);
if (iev->handler_write && iev->ibuf.w.queued)
- THREAD_WRITE_ON(master, iev->ev_write, iev->handler_write, iev,
- iev->ibuf.fd);
+ thread_add_write(master, iev->handler_write, iev,
+ iev->ibuf.fd, &iev->ev_write);
}
int
evbuf_event_add(struct evbuf *eb)
{
if (eb->wbuf.queued)
- THREAD_WRITE_ON(master, eb->ev, eb->handler, eb->arg,
- eb->wbuf.fd);
+ thread_add_write(master, eb->handler, eb->arg, eb->wbuf.fd,
+ &eb->ev);
}
void
}
int
-ldp_reload(struct ldpd_conf *xconf)
+ldp_config_apply(struct vty *vty, struct ldpd_conf *xconf)
{
- if (global.sighup)
+ /*
+ * When reading from a configuration file (startup and sighup), we
+ * call merge_config() only once after the whole config has been read.
+ * This is the optimal and least disruptive way to update the running
+ * configuration.
+ */
+ if (vty && vty->type == VTY_FILE)
return (0);
ldp_config_normalize(xconf);
}
}
+static void
+ldp_config_reset(struct ldpd_conf *conf)
+{
+ ldp_config_reset_main(conf);
+ ldp_config_reset_l2vpns(conf);
+}
+
static void
ldp_config_reset_main(struct ldpd_conf *conf)
{
struct iface *iface;
struct nbr_params *nbrp;
- while ((iface = RB_ROOT(&conf->iface_tree)) != NULL) {
+ while ((iface = RB_ROOT(iface_head, &conf->iface_tree)) != NULL) {
QOBJ_UNREG(iface);
RB_REMOVE(iface_head, &conf->iface_tree, iface);
free(iface);
}
- while ((nbrp = RB_ROOT(&conf->nbrp_tree)) != NULL) {
+ while ((nbrp = RB_ROOT(nbrp_head, &conf->nbrp_tree)) != NULL) {
QOBJ_UNREG(nbrp);
RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp);
free(nbrp);
struct l2vpn_if *lif;
struct l2vpn_pw *pw;
- while ((l2vpn = RB_ROOT(&conf->l2vpn_tree)) != NULL) {
- while ((lif = RB_ROOT(&l2vpn->if_tree)) != NULL) {
+ while ((l2vpn = RB_ROOT(l2vpn_head, &conf->l2vpn_tree)) != NULL) {
+ while ((lif = RB_ROOT(l2vpn_if_head,
+ &l2vpn->if_tree)) != NULL) {
QOBJ_UNREG(lif);
RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
free(lif);
}
- while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) {
+ while ((pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree)) != NULL) {
QOBJ_UNREG(pw);
RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
free(pw);
}
- while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) {
+ while ((pw = RB_ROOT(l2vpn_pw_head,
+ &l2vpn->pw_inactive_tree)) != NULL) {
QOBJ_UNREG(pw);
RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
free(pw);
struct nbr_params *nbrp;
struct l2vpn *l2vpn;
- while ((iface = RB_ROOT(&xconf->iface_tree)) != NULL) {
+ while ((iface = RB_ROOT(iface_head, &xconf->iface_tree)) != NULL) {
RB_REMOVE(iface_head, &xconf->iface_tree, iface);
free(iface);
}
- while ((tnbr = RB_ROOT(&xconf->tnbr_tree)) != NULL) {
+ while ((tnbr = RB_ROOT(tnbr_head, &xconf->tnbr_tree)) != NULL) {
RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr);
free(tnbr);
}
- while ((nbrp = RB_ROOT(&xconf->nbrp_tree)) != NULL) {
+ while ((nbrp = RB_ROOT(nbrp_head, &xconf->nbrp_tree)) != NULL) {
RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp);
free(nbrp);
}
- while ((l2vpn = RB_ROOT(&xconf->l2vpn_tree)) != NULL) {
+ while ((l2vpn = RB_ROOT(l2vpn_head, &xconf->l2vpn_tree)) != NULL) {
RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, l2vpn);
l2vpn_del(l2vpn);
}
if ((l2vpn = l2vpn_find(conf, xl->name)) == NULL) {
COPY(l2vpn, xl);
RB_INSERT(l2vpn_head, &conf->l2vpn_tree, l2vpn);
- RB_INIT(&l2vpn->if_tree);
- RB_INIT(&l2vpn->pw_tree);
- RB_INIT(&l2vpn->pw_inactive_tree);
+ RB_INIT(l2vpn_if_head, &l2vpn->if_tree);
+ RB_INIT(l2vpn_pw_head, &l2vpn->pw_tree);
+ RB_INIT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
switch (ldpd_process) {
case PROC_LDE_ENGINE:
session_shutdown(nbr, S_SHUTDOWN, 0, 0);
}
}
- if (ldpd_process == PROC_LDE_ENGINE &&
- !reset_nbr && reinstall_pwfec)
+ if (ldpd_process == PROC_LDE_ENGINE && reinstall_pwfec)
l2vpn_pw_exit(pw);
pw->lsr_id = xp->lsr_id;
pw->af = xp->af;
pw->flags &= ~F_PW_STATIC_NBR_ADDR;
if (ldpd_process == PROC_LDP_ENGINE && reinstall_tnbr)
ldpe_l2vpn_pw_init(pw);
- if (ldpd_process == PROC_LDE_ENGINE &&
- !reset_nbr && reinstall_pwfec) {
+ if (ldpd_process == PROC_LDE_ENGINE && reinstall_pwfec) {
l2vpn->pw_type = xl->pw_type;
l2vpn->mtu = xl->mtu;
l2vpn_pw_init(pw);
if (xconf == NULL)
fatal(NULL);
- RB_INIT(&xconf->iface_tree);
- RB_INIT(&xconf->tnbr_tree);
- RB_INIT(&xconf->nbrp_tree);
- RB_INIT(&xconf->l2vpn_tree);
+ RB_INIT(iface_head, &xconf->iface_tree);
+ RB_INIT(tnbr_head, &xconf->tnbr_tree);
+ RB_INIT(nbrp_head, &xconf->nbrp_tree);
+ RB_INIT(l2vpn_head, &xconf->l2vpn_tree);
+
+ /* set default values */
+ ldp_config_reset(xconf);
return (xconf);
}