4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
6 * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include "ldp_debug.h"
32 #include <lib/version.h>
45 #include "lib_errors.h"
47 static void ldpd_shutdown(void);
48 static pid_t
start_child(enum ldpd_process
, char *, int, int);
49 static int main_dispatch_ldpe(struct thread
*);
50 static int main_dispatch_lde(struct thread
*);
51 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
53 static void main_imsg_send_net_sockets(int);
54 static void main_imsg_send_net_socket(int, enum socket_type
);
55 static int main_imsg_send_config(struct ldpd_conf
*);
56 static void ldp_config_normalize(struct ldpd_conf
*);
57 static void ldp_config_reset(struct ldpd_conf
*);
58 static void ldp_config_reset_main(struct ldpd_conf
*);
59 static void ldp_config_reset_af(struct ldpd_conf
*, int);
60 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
61 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
62 static void merge_af(int, struct ldpd_af_conf
*,
63 struct ldpd_af_conf
*);
64 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
65 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
66 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
67 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
68 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
69 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
72 DEFINE_QOBJ_TYPE(iface
)
73 DEFINE_QOBJ_TYPE(tnbr
)
74 DEFINE_QOBJ_TYPE(nbr_params
)
75 DEFINE_QOBJ_TYPE(l2vpn_if
)
76 DEFINE_QOBJ_TYPE(l2vpn_pw
)
77 DEFINE_QOBJ_TYPE(l2vpn
)
78 DEFINE_QOBJ_TYPE(ldpd_conf
)
80 struct ldpd_global global
;
81 struct ldpd_init init
;
82 struct ldpd_conf
*ldpd_conf
, *vty_conf
;
84 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
85 static struct imsgev
*iev_lde
, *iev_lde_sync
;
86 static pid_t ldpe_pid
;
89 static struct frr_daemon_info ldpd_di
;
91 DEFINE_HOOK(ldp_register_mib
, (struct thread_master
* tm
), (tm
))
93 static void ldp_load_module(const char *name
)
96 dir
= ldpd_di
.module_path
? ldpd_di
.module_path
: frr_moduledir
;
98 struct frrmod_runtime
*module
;
100 module
= frrmod_load(name
, dir
, moderr
, sizeof(moderr
));
102 fprintf(stderr
, "%s: failed to load %s", __func__
, name
);
103 log_warnx("%s: failed to load %s", __func__
, name
);
107 void ldp_agentx_enabled(void)
109 ldp_load_module("snmp");
110 hook_call(ldp_register_mib
, master
);
113 enum ldpd_process ldpd_process
;
115 #define LDP_DEFAULT_CONFIG "ldpd.conf"
116 #define LDP_VTY_PORT 2612
118 /* Master of threads. */
119 struct thread_master
*master
;
121 /* ldpd privileges */
122 static zebra_capabilities_t _caps_p
[] =
128 struct zebra_privs_t ldpd_privs
=
130 #if defined(FRR_USER) && defined(FRR_GROUP)
134 #if defined(VTY_GROUP)
135 .vty_group
= VTY_GROUP
,
138 .cap_num_p
= array_size(_caps_p
),
142 /* CTL Socket path */
143 char ctl_sock_path
[MAXPATHLEN
];
146 #define OPTION_CTLSOCK 1001
147 static const struct option longopts
[] =
149 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
150 { "instance", required_argument
, NULL
, 'n'},
154 /* SIGHUP handler. */
158 log_info("SIGHUP received");
161 * Do a full configuration reload. In other words, reset vty_conf
162 * and build a new configuartion from scratch.
164 ldp_config_reset(vty_conf
);
165 vty_read_config(NULL
, ldpd_di
.config_file
, config_default
);
166 ldp_config_apply(NULL
, vty_conf
);
169 /* SIGINT / SIGTERM handler. */
173 log_info("SIGINT received");
177 /* SIGUSR1 handler. */
184 static struct quagga_signal_t ldp_signals
[] =
204 static const struct frr_yang_module_info
*const ldpd_yang_modules
[] = {
209 FRR_DAEMON_INFO(ldpd
, LDP
,
210 .vty_port
= LDP_VTY_PORT
,
212 .proghelp
= "Implementation of the LDP protocol.",
214 .signals
= ldp_signals
,
215 .n_signals
= array_size(ldp_signals
),
217 .privs
= &ldpd_privs
,
219 .yang_modules
= ldpd_yang_modules
,
220 .n_yang_modules
= array_size(ldpd_yang_modules
),
223 static int ldp_config_fork_apply(struct thread
*t
)
226 * So the frr_config_fork() function schedules
227 * the read of the vty config( if there is a
228 * non-integrated config ) to be after the
229 * end of startup and we are starting the
230 * main process loop. We need to schedule
231 * the application of this if necessary
232 * after the read in of the config.
234 ldp_config_apply(NULL
, vty_conf
);
240 main(int argc
, char *argv
[])
243 int lflag
= 0, eflag
= 0;
244 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
245 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
247 struct thread
*thread
= NULL
;
248 bool ctl_sock_used
= false;
250 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
253 ldpd_process
= PROC_MAIN
;
254 log_procname
= log_procnames
[ldpd_process
];
256 saved_argv0
= argv
[0];
257 if (saved_argv0
== NULL
)
258 saved_argv0
= (char *)"ldpd";
260 frr_preinit(&ldpd_di
, argc
, argv
);
261 frr_opt_add("LEn:", longopts
,
262 " --ctl_socket Override ctl socket path\n"
263 " -n, --instance Instance id\n");
268 opt
= frr_getopt(argc
, argv
, NULL
);
277 ctl_sock_used
= true;
278 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
284 * LDPD_SOCKET configured as relative path
285 * during config? Should really never happen for
288 ctl_sock_name
= (char *)LDPD_SOCKET
;
289 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
290 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
291 strlcat(ctl_sock_path
, ctl_sock_name
,
292 sizeof(ctl_sock_path
));
295 init
.instance
= atoi(optarg
);
296 if (init
.instance
< 1)
311 if (ldpd_di
.pathspace
&& !ctl_sock_used
)
312 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
313 "/", ldpd_di
.pathspace
);
315 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
316 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
317 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
318 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
319 sizeof(init
.zclient_serv_path
));
322 if (argc
> 0 || (lflag
&& eflag
))
325 /* check for root privileges */
326 if (geteuid() != 0) {
328 perror(ldpd_di
.progname
);
332 if (lflag
|| eflag
) {
333 struct zprivs_ids_t ids
;
335 zprivs_preinit(&ldpd_privs
);
336 zprivs_get_ids(&ids
);
338 zlog_init(ldpd_di
.progname
, "LDP", 0,
339 ids
.uid_normal
, ids
.gid_normal
);
346 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
348 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
349 pipe_parent2ldpe_sync
) == -1)
351 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
353 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
354 pipe_parent2lde_sync
) == -1)
356 sock_set_nonblock(pipe_parent2ldpe
[0]);
357 sock_set_cloexec(pipe_parent2ldpe
[0]);
358 sock_set_nonblock(pipe_parent2ldpe
[1]);
359 sock_set_cloexec(pipe_parent2ldpe
[1]);
360 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
361 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
362 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
363 sock_set_nonblock(pipe_parent2lde
[0]);
364 sock_set_cloexec(pipe_parent2lde
[0]);
365 sock_set_nonblock(pipe_parent2lde
[1]);
366 sock_set_cloexec(pipe_parent2lde
[1]);
367 sock_set_nonblock(pipe_parent2lde_sync
[0]);
368 sock_set_cloexec(pipe_parent2lde_sync
[0]);
369 sock_set_cloexec(pipe_parent2lde_sync
[1]);
372 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
373 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
374 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
375 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
379 vrf_init(NULL
, NULL
, NULL
, NULL
, NULL
);
382 ldp_zebra_init(master
);
385 * Create base configuration with sane defaults. All configuration
386 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
387 * to merge the changes into ldpd_conf, which contains the actual
388 * running configuration.
390 ldpd_conf
= config_new_empty();
391 vty_conf
= config_new_empty();
392 QOBJ_REG(vty_conf
, ldpd_conf
);
394 /* read configuration file and daemonize */
397 /* apply configuration */
398 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
400 /* setup pipes to children */
401 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
402 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
403 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
404 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
406 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
407 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
408 iev_ldpe
->ev_read
= NULL
;
409 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
411 iev_ldpe
->handler_write
= ldp_write_handler
;
413 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
414 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
415 iev_ldpe_sync
->ev_read
= NULL
;
416 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
417 &iev_ldpe_sync
->ev_read
);
418 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
420 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
421 iev_lde
->handler_read
= main_dispatch_lde
;
422 iev_lde
->ev_read
= NULL
;
423 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
425 iev_lde
->handler_write
= ldp_write_handler
;
427 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
428 iev_lde_sync
->handler_read
= main_dispatch_lde
;
429 iev_lde_sync
->ev_read
= NULL
;
430 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
431 &iev_lde_sync
->ev_read
);
432 iev_lde_sync
->handler_write
= ldp_write_handler
;
434 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
435 fatal("could not establish imsg links");
436 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
438 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
439 main_imsg_send_config(ldpd_conf
);
441 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
442 main_imsg_send_net_sockets(AF_INET
);
443 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
444 main_imsg_send_net_sockets(AF_INET6
);
461 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
462 close(iev_ldpe
->ibuf
.fd
);
463 msgbuf_clear(&iev_lde
->ibuf
.w
);
464 close(iev_lde
->ibuf
.fd
);
466 config_clear(ldpd_conf
);
468 ldp_config_reset(vty_conf
);
469 QOBJ_UNREG(vty_conf
);
472 log_debug("waiting for children to terminate");
475 /* Wait for child process. */
478 /* We got interrupted, try again. */
481 /* No more processes were found. */
485 /* Unhandled errno condition. */
490 /* We found something, lets announce it. */
491 if (WIFSIGNALED(status
))
492 log_warnx("%s terminated; signal %d",
493 (pid
== lde_pid
? "label decision engine"
497 /* Repeat until there are no more child processes. */
503 log_info("terminating");
514 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
517 int argc
= 0, nullfd
;
523 fatal("cannot fork");
532 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
534 flog_err_sys(EC_LIB_SYSTEM_CALL
,
535 "%s: failed to open /dev/null: %s", __func__
,
536 safe_strerror(errno
));
544 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
545 fatal("cannot setup imsg async fd");
546 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
547 fatal("cannot setup imsg sync fd");
549 argv
[argc
++] = argv0
;
552 fatalx("Can not start main process");
553 case PROC_LDE_ENGINE
:
554 argv
[argc
++] = (char *)"-L";
556 case PROC_LDP_ENGINE
:
557 argv
[argc
++] = (char *)"-E";
561 argv
[argc
++] = (char *)"-u";
562 argv
[argc
++] = (char *)ldpd_privs
.user
;
563 argv
[argc
++] = (char *)"-g";
564 argv
[argc
++] = (char *)ldpd_privs
.group
;
574 main_dispatch_ldpe(struct thread
*thread
)
576 struct imsgev
*iev
= THREAD_ARG(thread
);
577 struct imsgbuf
*ibuf
= &iev
->ibuf
;
585 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
586 fatal("imsg_read error");
587 if (n
== 0) /* connection closed */
591 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
597 switch (imsg
.hdr
.type
) {
599 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
601 case IMSG_REQUEST_SOCKETS
:
603 main_imsg_send_net_sockets(af
);
606 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
607 sizeof(struct acl_check
))
608 fatalx("IMSG_ACL_CHECK imsg with wrong len");
609 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
611 case IMSG_LDP_SYNC_IF_STATE_UPDATE
:
612 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
613 sizeof(struct ldp_igp_sync_if_state
))
614 fatalx("IMSG_LDP_SYNC_IF_STATE_UPDATE imsg with wrong len");
616 ldp_sync_zebra_send_state_update((struct ldp_igp_sync_if_state
*)imsg
.data
);
619 log_debug("%s: error handling imsg %d", __func__
,
628 /* this pipe is dead, so remove the event handlers and exit */
629 thread_cancel(&iev
->ev_read
);
630 thread_cancel(&iev
->ev_write
);
635 kill(lde_pid
, SIGTERM
);
643 main_dispatch_lde(struct thread
*thread
)
645 struct imsgev
*iev
= THREAD_ARG(thread
);
646 struct imsgbuf
*ibuf
= &iev
->ibuf
;
650 struct zapi_rlfa_response
*rlfa_labels
;
654 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
655 fatal("imsg_read error");
656 if (n
== 0) /* connection closed */
660 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
666 switch (imsg
.hdr
.type
) {
668 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
670 case IMSG_KLABEL_CHANGE
:
671 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
672 sizeof(struct kroute
))
673 fatalx("invalid size of IMSG_KLABEL_CHANGE");
674 if (kr_change(imsg
.data
))
675 log_warnx("%s: error changing route", __func__
);
677 case IMSG_KLABEL_DELETE
:
678 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
679 sizeof(struct kroute
))
680 fatalx("invalid size of IMSG_KLABEL_DELETE");
681 if (kr_delete(imsg
.data
))
682 log_warnx("%s: error deleting route", __func__
);
685 case IMSG_KPW_DELETE
:
688 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
689 sizeof(struct zapi_pw
))
690 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
692 switch (imsg
.hdr
.type
) {
694 if (kmpw_add(imsg
.data
))
695 log_warnx("%s: error adding pseudowire", __func__
);
697 case IMSG_KPW_DELETE
:
698 if (kmpw_del(imsg
.data
))
699 log_warnx("%s: error deleting pseudowire", __func__
);
702 if (kmpw_set(imsg
.data
))
703 log_warnx("%s: error setting pseudowire", __func__
);
706 if (kmpw_unset(imsg
.data
))
707 log_warnx("%s: error unsetting pseudowire", __func__
);
712 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
713 sizeof(struct acl_check
))
714 fatalx("IMSG_ACL_CHECK imsg with wrong len");
715 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
717 case IMSG_RLFA_LABELS
:
718 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
719 sizeof(struct zapi_rlfa_response
)) {
720 log_warnx("%s: wrong imsg len", __func__
);
723 rlfa_labels
= imsg
.data
;
724 ldp_zebra_send_rlfa_labels(rlfa_labels
);
727 log_debug("%s: error handling imsg %d", __func__
,
736 /* this pipe is dead, so remove the event handlers and exit */
737 thread_cancel(&iev
->ev_read
);
738 thread_cancel(&iev
->ev_write
);
743 kill(ldpe_pid
, SIGTERM
);
751 ldp_write_handler(struct thread
*thread
)
753 struct imsgev
*iev
= THREAD_ARG(thread
);
754 struct imsgbuf
*ibuf
= &iev
->ibuf
;
757 iev
->ev_write
= NULL
;
759 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
760 fatal("msgbuf_write");
762 /* this pipe is dead, so remove the event handlers */
763 thread_cancel(&iev
->ev_read
);
764 thread_cancel(&iev
->ev_write
);
774 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
776 if (iev_ldpe
== NULL
)
778 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
782 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
784 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
788 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
790 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
792 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
794 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
800 imsg_event_add(struct imsgev
*iev
)
802 if (iev
->handler_read
)
803 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
806 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
807 thread_add_write(master
, iev
->handler_write
, iev
,
808 iev
->ibuf
.fd
, &iev
->ev_write
);
812 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
813 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
817 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
818 pid
, fd
, data
, datalen
)) != -1)
824 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
826 ibuf_close(&eb
->wbuf
, buf
);
831 evbuf_event_add(struct evbuf
*eb
)
834 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
839 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
842 msgbuf_init(&eb
->wbuf
);
844 eb
->handler
= handler
;
849 evbuf_clear(struct evbuf
*eb
)
851 thread_cancel(&eb
->ev
);
852 msgbuf_clear(&eb
->wbuf
);
857 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
859 int pipe_ldpe2lde
[2];
861 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
863 sock_set_nonblock(pipe_ldpe2lde
[0]);
864 sock_set_nonblock(pipe_ldpe2lde
[1]);
866 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
869 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
877 main_imsg_send_net_sockets(int af
)
879 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
882 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
883 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
884 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
885 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
889 main_imsg_send_net_socket(int af
, enum socket_type type
)
893 fd
= ldp_create_socket(af
, type
);
895 log_warnx("%s: failed to create %s socket for address-family %s", __func__
, socket_name(type
), af_name(af
));
899 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
904 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
905 union ldpd_addr
*addr
, uint8_t prefixlen
)
908 struct acl_check acl_check
;
910 if (acl_name
[0] == '\0')
911 return FILTER_PERMIT
;
914 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
916 acl_check
.addr
= *addr
;
917 acl_check
.prefixlen
= prefixlen
;
919 /* send (blocking) */
920 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
922 imsg_flush(&iev
->ibuf
);
924 /* receive (blocking) and parse result */
925 if (imsg_read(&iev
->ibuf
) == -1)
926 fatal("imsg_read error");
927 if (imsg_get(&iev
->ibuf
, &imsg
) == -1)
929 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
930 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
931 fatalx("ldp_acl_request: invalid response");
933 return (*((int *)imsg
.data
));
937 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
939 struct access_list
*alist
;
940 struct prefix prefix
;
943 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
945 result
= FILTER_DENY
;
947 prefix
.family
= acl_check
->af
;
948 switch (prefix
.family
) {
950 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
953 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
956 fatalx("ldp_acl_reply: unknown af");
958 prefix
.prefixlen
= acl_check
->prefixlen
;
959 result
= access_list_apply(alist
, &prefix
);
962 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
966 struct ldpd_af_conf
*
967 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
971 return (&xconf
->ipv4
);
973 return (&xconf
->ipv6
);
975 fatalx("ldp_af_conf_get: unknown af");
979 struct ldpd_af_global
*
980 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
984 return (&xglobal
->ipv4
);
986 return (&xglobal
->ipv6
);
988 fatalx("ldp_af_global_get: unknown af");
993 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
995 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
996 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
1000 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
1002 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
1003 return (xconf
->rtr_id
.s_addr
);
1005 return (global
.rtr_id
.s_addr
);
1009 main_imsg_send_config(struct ldpd_conf
*xconf
)
1011 struct iface
*iface
;
1013 struct nbr_params
*nbrp
;
1014 struct l2vpn
*l2vpn
;
1015 struct l2vpn_if
*lif
;
1016 struct l2vpn_pw
*pw
;
1018 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
1019 sizeof(*xconf
)) == -1)
1022 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
1023 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
1024 sizeof(*iface
)) == -1)
1028 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
1029 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
1030 sizeof(*tnbr
)) == -1)
1034 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
1035 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
1036 sizeof(*nbrp
)) == -1)
1040 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1041 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
1042 sizeof(*l2vpn
)) == -1)
1045 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1046 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
1047 sizeof(*lif
)) == -1)
1050 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1051 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
1055 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1056 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1062 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1069 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1072 * When reading from a configuration file (startup and sighup), we
1073 * call merge_config() only once after the whole config has been read.
1074 * This is the optimal and least disruptive way to update the running
1077 if (vty
&& vty
->type
== VTY_FILE
)
1080 ldp_config_normalize(xconf
);
1082 if (main_imsg_send_config(xconf
) == -1)
1085 merge_config(ldpd_conf
, xconf
);
1091 ldp_config_normalize(struct ldpd_conf
*xconf
)
1093 struct iface
*iface
, *itmp
;
1094 struct nbr_params
*nbrp
, *ntmp
;
1095 struct l2vpn
*l2vpn
;
1096 struct l2vpn_pw
*pw
, *ptmp
;
1098 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1099 ldp_config_reset_main(xconf
);
1101 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1102 ldp_config_reset_af(xconf
, AF_INET
);
1103 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1104 ldp_config_reset_af(xconf
, AF_INET6
);
1106 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1107 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1111 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1115 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1116 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1118 if (nbrp
->auth
.method
!= AUTH_NONE
)
1122 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1127 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1128 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1129 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1131 pw
->addr
.v4
= pw
->lsr_id
;
1134 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1136 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1137 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1139 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1141 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1143 pw
->addr
.v4
= pw
->lsr_id
;
1146 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1148 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1149 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1155 ldp_config_reset(struct ldpd_conf
*conf
)
1157 ldp_config_reset_main(conf
);
1158 ldp_config_reset_l2vpns(conf
);
1162 ldp_config_reset_main(struct ldpd_conf
*conf
)
1164 struct iface
*iface
;
1165 struct nbr_params
*nbrp
;
1167 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1168 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1171 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1175 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1176 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1179 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1183 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1184 ldp_config_reset_af(conf
, AF_INET
);
1185 ldp_config_reset_af(conf
, AF_INET6
);
1186 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1187 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1188 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1189 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1190 conf
->wait_for_sync_interval
= DFLT_WAIT_FOR_SYNC
;
1191 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1196 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1198 struct ldpd_af_conf
*af_conf
;
1199 struct iface
*iface
;
1200 struct iface_af
*ia
;
1201 struct tnbr
*tnbr
, *ttmp
;
1203 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1204 ia
= iface_af_get(iface
, af
);
1208 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1213 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1217 af_conf
= ldp_af_conf_get(conf
, af
);
1218 af_conf
->keepalive
= 180;
1219 af_conf
->lhello_holdtime
= 0;
1220 af_conf
->lhello_interval
= 0;
1221 af_conf
->thello_holdtime
= 0;
1222 af_conf
->thello_interval
= 0;
1223 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1228 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1230 struct l2vpn
*l2vpn
;
1231 struct l2vpn_if
*lif
;
1232 struct l2vpn_pw
*pw
;
1234 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1235 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1236 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1237 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1240 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1243 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1244 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1247 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1250 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1251 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1254 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1258 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1264 ldp_clear_config(struct ldpd_conf
*xconf
)
1266 struct iface
*iface
;
1268 struct nbr_params
*nbrp
;
1269 struct l2vpn
*l2vpn
;
1271 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1272 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1274 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1277 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1278 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1280 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1283 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1284 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1286 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1289 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1290 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1292 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1299 #define COPY(a, b) do { \
1300 a = malloc(sizeof(*a)); \
1307 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1309 merge_global(conf
, xconf
);
1310 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1311 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1312 merge_ifaces(conf
, xconf
);
1313 merge_tnbrs(conf
, xconf
);
1314 merge_nbrps(conf
, xconf
);
1315 merge_l2vpns(conf
, xconf
);
1319 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1321 /* Removing global LDP config requires resetting LDP IGP Sync FSM */
1322 if ((conf
->flags
& F_LDPD_ENABLED
) &&
1323 (!(xconf
->flags
& F_LDPD_ENABLED
)))
1325 if (ldpd_process
== PROC_LDP_ENGINE
)
1326 ldp_sync_fsm_reset_all();
1329 /* change of router-id requires resetting all neighborships */
1330 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1331 if (ldpd_process
== PROC_LDP_ENGINE
) {
1332 ldpe_reset_nbrs(AF_UNSPEC
);
1333 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1334 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1335 if_update_all(AF_UNSPEC
);
1336 tnbr_update_all(AF_UNSPEC
);
1339 conf
->rtr_id
= xconf
->rtr_id
;
1343 * Configuration of ordered-control or independent-control
1344 * requires resetting all neighborships.
1346 if ((conf
->flags
& F_LDPD_ORDERED_CONTROL
) !=
1347 (xconf
->flags
& F_LDPD_ORDERED_CONTROL
))
1348 ldpe_reset_nbrs(AF_UNSPEC
);
1350 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1351 conf
->lhello_interval
= xconf
->lhello_interval
;
1352 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1353 conf
->thello_interval
= xconf
->thello_interval
;
1354 conf
->wait_for_sync_interval
= xconf
->wait_for_sync_interval
;
1356 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1357 if (ldpd_process
== PROC_LDP_ENGINE
)
1358 ldpe_reset_ds_nbrs();
1359 conf
->trans_pref
= xconf
->trans_pref
;
1362 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1363 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1364 if (ldpd_process
== PROC_LDP_ENGINE
)
1365 ldpe_reset_ds_nbrs();
1368 if (ldpd_process
== PROC_LDP_ENGINE
)
1369 ldpe_set_config_change_time();
1371 conf
->flags
= xconf
->flags
;
1375 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1377 int stop_init_backoff
= 0;
1378 int remove_dynamic_tnbrs
= 0;
1379 int change_egress_label
= 0;
1380 int change_host_label
= 0;
1381 int reset_nbrs_ipv4
= 0;
1383 int update_sockets
= 0;
1384 int change_ldp_disabled
= 0;
1387 if (af_conf
->keepalive
!= xa
->keepalive
) {
1388 af_conf
->keepalive
= xa
->keepalive
;
1389 stop_init_backoff
= 1;
1391 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1392 af_conf
->lhello_interval
= xa
->lhello_interval
;
1393 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1394 af_conf
->thello_interval
= xa
->thello_interval
;
1397 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1398 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1399 remove_dynamic_tnbrs
= 1;
1400 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1401 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1403 /* need to set/unset IPV6_MINHOPCOUNT */
1406 /* for LDPv4 just resetting the neighbors is enough */
1407 reset_nbrs_ipv4
= 1;
1409 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1410 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1411 change_egress_label
= 1;
1413 /* changing config of host only fec filtering */
1414 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
1415 != (xa
->flags
& F_LDPD_AF_ALLOCHOSTONLY
))
1416 change_host_label
= 1;
1418 /* disabling LDP for address family */
1419 if ((af_conf
->flags
& F_LDPD_AF_ENABLED
) &&
1420 !(xa
->flags
& F_LDPD_AF_ENABLED
))
1421 change_ldp_disabled
= 1;
1423 af_conf
->flags
= xa
->flags
;
1425 /* update the transport address */
1426 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1427 af_conf
->trans_addr
= xa
->trans_addr
;
1432 if (strcmp(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
))
1433 change_host_label
= 1;
1435 if (strcmp(af_conf
->acl_label_advertise_to
,
1436 xa
->acl_label_advertise_to
) ||
1437 strcmp(af_conf
->acl_label_advertise_for
,
1438 xa
->acl_label_advertise_for
) ||
1439 strcmp(af_conf
->acl_label_accept_from
,
1440 xa
->acl_label_accept_from
) ||
1441 strcmp(af_conf
->acl_label_accept_for
,
1442 xa
->acl_label_accept_for
))
1444 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1445 remove_dynamic_tnbrs
= 1;
1446 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1447 change_egress_label
= 1;
1448 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1449 sizeof(af_conf
->acl_thello_accept_from
));
1450 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1451 sizeof(af_conf
->acl_label_allocate_for
));
1452 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1453 sizeof(af_conf
->acl_label_advertise_to
));
1454 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1455 sizeof(af_conf
->acl_label_advertise_for
));
1456 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1457 sizeof(af_conf
->acl_label_accept_from
));
1458 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1459 sizeof(af_conf
->acl_label_accept_for
));
1460 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1461 sizeof(af_conf
->acl_label_expnull_for
));
1463 /* apply the new configuration */
1464 switch (ldpd_process
) {
1465 case PROC_LDE_ENGINE
:
1466 if (change_egress_label
)
1467 lde_change_egress_label(af
);
1468 if (change_host_label
)
1469 lde_change_allocate_filter(af
);
1470 if (change_ldp_disabled
)
1471 lde_route_update_release_all(af
);
1474 case PROC_LDP_ENGINE
:
1475 if (stop_init_backoff
)
1476 ldpe_stop_init_backoff(af
);
1477 if (remove_dynamic_tnbrs
)
1478 ldpe_remove_dynamic_tnbrs(af
);
1480 ldpe_reset_nbrs(AF_UNSPEC
);
1481 else if (reset_nbrs_ipv4
)
1482 ldpe_reset_nbrs(AF_INET
);
1485 if (update_sockets
&& iev_ldpe
)
1486 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1493 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1495 struct iface
*iface
, *itmp
, *xi
;
1497 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1498 /* find deleted interfaces, which occurs when LDP is removed
1499 * for all address families
1501 if (if_lookup_name(xconf
, iface
->name
) == NULL
) {
1502 switch (ldpd_process
) {
1503 case PROC_LDP_ENGINE
:
1504 ldpe_if_exit(iface
);
1506 case PROC_LDE_ENGINE
:
1507 if (iface
->ipv4
.enabled
)
1508 lde_route_update_release(iface
,
1510 if (iface
->ipv6
.enabled
)
1511 lde_route_update_release(iface
,
1517 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1521 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1522 /* find new interfaces */
1523 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1525 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1527 switch (ldpd_process
) {
1528 case PROC_LDP_ENGINE
:
1529 ldpe_if_init(iface
);
1531 case PROC_LDE_ENGINE
:
1534 /* resend addresses to activate new interfaces */
1535 kif_redistribute(iface
->name
);
1541 /* update labels when adding or removing ldp on an
1544 if (ldpd_process
== PROC_LDE_ENGINE
) {
1545 /* if we are removing lpd config for an address
1546 * family on an interface then advertise routes
1547 * learned over this interface as if they were
1550 if (iface
->ipv4
.enabled
&& !xi
->ipv4
.enabled
)
1551 lde_route_update_release(iface
, AF_INET
);
1552 if (iface
->ipv6
.enabled
&& !xi
->ipv6
.enabled
)
1553 lde_route_update_release(iface
, AF_INET6
);
1555 /* if we are adding lpd config for an address
1556 * family on an interface then add proper labels
1558 if (!iface
->ipv4
.enabled
&& xi
->ipv4
.enabled
)
1559 lde_route_update(iface
, AF_INET
);
1560 if (!iface
->ipv6
.enabled
&& xi
->ipv6
.enabled
)
1561 lde_route_update(iface
, AF_INET6
);
1564 /* update existing interfaces */
1565 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1566 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1571 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1573 if (ia
->enabled
!= xi
->enabled
) {
1574 ia
->enabled
= xi
->enabled
;
1575 if (ldpd_process
== PROC_LDP_ENGINE
)
1576 ldp_if_update(ia
->iface
, ia
->af
);
1578 ia
->hello_holdtime
= xi
->hello_holdtime
;
1579 ia
->hello_interval
= xi
->hello_interval
;
1583 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1585 struct tnbr
*tnbr
, *ttmp
, *xt
;
1587 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1588 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1591 /* find deleted tnbrs */
1592 if (tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
) == NULL
) {
1593 switch (ldpd_process
) {
1594 case PROC_LDP_ENGINE
:
1595 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1596 tnbr_check(conf
, tnbr
);
1598 case PROC_LDE_ENGINE
:
1600 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1606 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1607 /* find new tnbrs */
1608 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1610 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1612 switch (ldpd_process
) {
1613 case PROC_LDP_ENGINE
:
1616 case PROC_LDE_ENGINE
:
1623 /* update existing tnbrs */
1624 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1625 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1630 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1632 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1636 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1637 /* find deleted nbrps */
1638 if (nbr_params_find(xconf
, nbrp
->lsr_id
) != NULL
)
1641 switch (ldpd_process
) {
1642 case PROC_LDP_ENGINE
:
1643 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1645 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1650 (ldp_af_global_get(&global
, nbr
->af
))
1651 ->ldp_session_socket
,
1652 nbr
->af
, &nbr
->raddr
, NULL
);
1654 nbr
->auth
.method
= AUTH_NONE
;
1655 if (nbr_session_active_role(nbr
))
1656 nbr_establish_connection(nbr
);
1659 case PROC_LDE_ENGINE
:
1663 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1667 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1668 /* find new nbrps */
1669 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1671 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1673 switch (ldpd_process
) {
1674 case PROC_LDP_ENGINE
:
1675 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1677 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1678 nbr
->auth
.method
= nbrp
->auth
.method
;
1680 if (pfkey_establish(nbr
, nbrp
) == -1)
1681 fatalx("pfkey setup failed");
1684 (ldp_af_global_get(&global
,
1685 nbr
->af
))->ldp_session_socket
,
1686 nbr
->af
, &nbr
->raddr
,
1689 if (nbr_session_active_role(nbr
))
1690 nbr_establish_connection(nbr
);
1693 case PROC_LDE_ENGINE
:
1700 /* update existing nbrps */
1701 if (nbrp
->flags
!= xn
->flags
||
1702 nbrp
->keepalive
!= xn
->keepalive
||
1703 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1704 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1705 nbrp
->auth
.method
!= xn
->auth
.method
||
1706 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1711 nbrp
->keepalive
= xn
->keepalive
;
1712 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1713 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1714 nbrp
->auth
.method
= xn
->auth
.method
;
1715 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1716 sizeof(nbrp
->auth
.md5key
));
1717 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1718 nbrp
->flags
= xn
->flags
;
1720 if (ldpd_process
== PROC_LDP_ENGINE
) {
1721 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1722 if (nbr
&& nbrp_changed
) {
1723 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1726 nbr
->auth
.method
= nbrp
->auth
.method
;
1727 if (pfkey_establish(nbr
, nbrp
) == -1)
1728 fatalx("pfkey setup failed");
1730 nbr
->auth
.method
= nbrp
->auth
.method
;
1731 sock_set_md5sig((ldp_af_global_get(&global
,
1732 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1733 &nbr
->raddr
, nbrp
->auth
.md5key
);
1735 if (nbr_session_active_role(nbr
))
1736 nbr_establish_connection(nbr
);
1743 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1745 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1747 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1748 /* find deleted l2vpns */
1749 if (l2vpn_find(xconf
, l2vpn
->name
) == NULL
) {
1750 switch (ldpd_process
) {
1751 case PROC_LDE_ENGINE
:
1754 case PROC_LDP_ENGINE
:
1755 ldpe_l2vpn_exit(l2vpn
);
1760 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1764 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1765 /* find new l2vpns */
1766 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1768 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1769 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1770 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1771 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1773 switch (ldpd_process
) {
1774 case PROC_LDE_ENGINE
:
1777 case PROC_LDP_ENGINE
:
1778 ldpe_l2vpn_init(l2vpn
);
1785 /* update existing l2vpns */
1786 merge_l2vpn(conf
, l2vpn
, xl
);
1791 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1793 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1794 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1796 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1797 int previous_pw_type
, previous_mtu
;
1799 previous_pw_type
= l2vpn
->pw_type
;
1800 previous_mtu
= l2vpn
->mtu
;
1802 /* merge intefaces */
1803 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1804 /* find deleted interfaces */
1805 if (l2vpn_if_find(xl
, lif
->ifname
) == NULL
) {
1806 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1810 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1811 /* find new interfaces */
1812 if (l2vpn_if_find(l2vpn
, xf
->ifname
) == NULL
) {
1814 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1817 switch (ldpd_process
) {
1818 case PROC_LDP_ENGINE
:
1819 case PROC_LDE_ENGINE
:
1822 kif_redistribute(lif
->ifname
);
1828 /* merge active pseudowires */
1829 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1830 /* find deleted active pseudowires */
1831 if (l2vpn_pw_find_active(xl
, pw
->ifname
) == NULL
) {
1832 switch (ldpd_process
) {
1833 case PROC_LDE_ENGINE
:
1836 case PROC_LDP_ENGINE
:
1837 ldpe_l2vpn_pw_exit(pw
);
1843 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1847 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1848 /* find new active pseudowires */
1849 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1851 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1854 switch (ldpd_process
) {
1855 case PROC_LDE_ENGINE
:
1858 case PROC_LDP_ENGINE
:
1859 ldpe_l2vpn_pw_init(pw
);
1862 kif_redistribute(pw
->ifname
);
1868 /* update existing active pseudowire */
1869 if (pw
->af
!= xp
->af
||
1870 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1875 /* changes that require a session restart */
1876 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1877 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1882 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1883 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1884 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1885 reinstall_pwfec
= 1;
1887 reinstall_pwfec
= 0;
1889 if (ldpd_process
== PROC_LDP_ENGINE
) {
1891 ldpe_l2vpn_pw_exit(pw
);
1893 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1894 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1895 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1898 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1900 pw
->lsr_id
= xp
->lsr_id
;
1902 pw
->addr
= xp
->addr
;
1903 pw
->pwid
= xp
->pwid
;
1904 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1905 pw
->ifindex
= xp
->ifindex
;
1906 if (xp
->flags
& F_PW_CWORD_CONF
)
1907 pw
->flags
|= F_PW_CWORD_CONF
;
1909 pw
->flags
&= ~F_PW_CWORD_CONF
;
1910 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1911 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1913 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1914 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1915 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1917 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1918 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1919 ldpe_l2vpn_pw_init(pw
);
1920 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1921 l2vpn
->pw_type
= xl
->pw_type
;
1922 l2vpn
->mtu
= xl
->mtu
;
1924 l2vpn
->pw_type
= previous_pw_type
;
1925 l2vpn
->mtu
= previous_mtu
;
1929 /* merge inactive pseudowires */
1930 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1931 /* find deleted inactive pseudowires */
1932 if (l2vpn_pw_find_inactive(xl
, pw
->ifname
) == NULL
) {
1933 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1937 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1938 /* find new inactive pseudowires */
1939 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1941 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1944 switch (ldpd_process
) {
1945 case PROC_LDE_ENGINE
:
1946 case PROC_LDP_ENGINE
:
1949 kif_redistribute(pw
->ifname
);
1955 /* update existing inactive pseudowire */
1956 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1958 pw
->addr
= xp
->addr
;
1959 pw
->pwid
= xp
->pwid
;
1960 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1961 pw
->ifindex
= xp
->ifindex
;
1962 pw
->flags
= xp
->flags
;
1965 l2vpn
->pw_type
= xl
->pw_type
;
1966 l2vpn
->mtu
= xl
->mtu
;
1967 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1968 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1972 config_new_empty(void)
1974 struct ldpd_conf
*xconf
;
1976 xconf
= calloc(1, sizeof(*xconf
));
1980 RB_INIT(iface_head
, &xconf
->iface_tree
);
1981 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1982 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1983 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1985 /* set default values */
1986 ldp_config_reset(xconf
);
1992 config_clear(struct ldpd_conf
*conf
)
1994 struct ldpd_conf
*xconf
;
1997 * Merge current config with an empty config, this will deactivate
1998 * and deallocate all the interfaces, pseudowires and so on. Before
1999 * merging, copy the router-id and other variables to avoid some
2000 * unnecessary operations, like trying to reset the neighborships.
2002 xconf
= config_new_empty();
2003 xconf
->ipv4
= conf
->ipv4
;
2004 xconf
->ipv6
= conf
->ipv6
;
2005 xconf
->rtr_id
= conf
->rtr_id
;
2006 xconf
->trans_pref
= conf
->trans_pref
;
2007 xconf
->flags
= conf
->flags
;
2008 merge_config(conf
, xconf
);