1 // SPDX-License-Identifier: ISC
5 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
6 * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
7 * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
8 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
19 #include "ldp_debug.h"
21 #include <lib/version.h>
34 #include "lib_errors.h"
36 static void ldpd_shutdown(void);
37 static pid_t
start_child(enum ldpd_process
, char *, int, int);
38 static void main_dispatch_ldpe(struct thread
*thread
);
39 static void main_dispatch_lde(struct thread
*thread
);
40 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
42 static void main_imsg_send_net_sockets(int);
43 static void main_imsg_send_net_socket(int, enum socket_type
);
44 static int main_imsg_send_config(struct ldpd_conf
*);
45 static void ldp_config_normalize(struct ldpd_conf
*);
46 static void ldp_config_reset(struct ldpd_conf
*);
47 static void ldp_config_reset_main(struct ldpd_conf
*);
48 static void ldp_config_reset_af(struct ldpd_conf
*, int);
49 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
50 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
51 static void merge_af(int, struct ldpd_af_conf
*,
52 struct ldpd_af_conf
*);
53 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
54 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
55 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
56 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
57 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
58 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
61 DEFINE_QOBJ_TYPE(iface
);
62 DEFINE_QOBJ_TYPE(tnbr
);
63 DEFINE_QOBJ_TYPE(nbr_params
);
64 DEFINE_QOBJ_TYPE(l2vpn_if
);
65 DEFINE_QOBJ_TYPE(l2vpn_pw
);
66 DEFINE_QOBJ_TYPE(l2vpn
);
67 DEFINE_QOBJ_TYPE(ldpd_conf
);
69 struct ldpd_global global
;
70 struct ldpd_init init
;
71 struct ldpd_conf
*ldpd_conf
, *vty_conf
;
73 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
74 static struct imsgev
*iev_lde
, *iev_lde_sync
;
75 static pid_t ldpe_pid
;
78 static struct frr_daemon_info ldpd_di
;
80 DEFINE_HOOK(ldp_register_mib
, (struct thread_master
* tm
), (tm
));
82 static void ldp_load_module(const char *name
)
85 dir
= ldpd_di
.module_path
? ldpd_di
.module_path
: frr_moduledir
;
86 struct frrmod_runtime
*module
;
88 module
= frrmod_load(name
, dir
, NULL
,NULL
);
90 fprintf(stderr
, "%s: failed to load %s", __func__
, name
);
91 log_warnx("%s: failed to load %s", __func__
, name
);
95 void ldp_agentx_enabled(void)
97 ldp_load_module("snmp");
98 hook_call(ldp_register_mib
, master
);
101 enum ldpd_process ldpd_process
;
103 #define LDP_DEFAULT_CONFIG "ldpd.conf"
104 #define LDP_VTY_PORT 2612
106 /* Master of threads. */
107 struct thread_master
*master
;
109 /* ldpd privileges */
110 static zebra_capabilities_t _caps_p
[] =
116 struct zebra_privs_t ldpd_privs
=
118 #if defined(FRR_USER) && defined(FRR_GROUP)
122 #if defined(VTY_GROUP)
123 .vty_group
= VTY_GROUP
,
126 .cap_num_p
= array_size(_caps_p
),
130 /* CTL Socket path */
131 char ctl_sock_path
[MAXPATHLEN
];
134 #define OPTION_CTLSOCK 1001
135 static const struct option longopts
[] =
137 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
138 { "instance", required_argument
, NULL
, 'n'},
142 /* SIGHUP handler. */
146 log_info("SIGHUP received");
149 * Do a full configuration reload. In other words, reset vty_conf
150 * and build a new configuartion from scratch.
152 ldp_config_reset(vty_conf
);
153 vty_read_config(NULL
, ldpd_di
.config_file
, config_default
);
154 ldp_config_apply(NULL
, vty_conf
);
157 /* SIGINT / SIGTERM handler. */
161 log_info("SIGINT received");
165 /* SIGUSR1 handler. */
172 static struct frr_signal_t ldp_signals
[] =
192 static const struct frr_yang_module_info
*const ldpd_yang_modules
[] = {
197 FRR_DAEMON_INFO(ldpd
, LDP
,
198 .vty_port
= LDP_VTY_PORT
,
200 .proghelp
= "Implementation of the LDP protocol.",
202 .signals
= ldp_signals
,
203 .n_signals
= array_size(ldp_signals
),
205 .privs
= &ldpd_privs
,
207 .yang_modules
= ldpd_yang_modules
,
208 .n_yang_modules
= array_size(ldpd_yang_modules
),
211 static void ldp_config_fork_apply(struct thread
*t
)
214 * So the frr_config_fork() function schedules
215 * the read of the vty config( if there is a
216 * non-integrated config ) to be after the
217 * end of startup and we are starting the
218 * main process loop. We need to schedule
219 * the application of this if necessary
220 * after the read in of the config.
222 ldp_config_apply(NULL
, vty_conf
);
226 main(int argc
, char *argv
[])
229 int lflag
= 0, eflag
= 0;
230 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
231 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
233 bool ctl_sock_used
= false;
235 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
238 ldpd_process
= PROC_MAIN
;
239 log_procname
= log_procnames
[ldpd_process
];
241 saved_argv0
= argv
[0];
242 if (saved_argv0
== NULL
)
243 saved_argv0
= (char *)"ldpd";
245 frr_preinit(&ldpd_di
, argc
, argv
);
246 frr_opt_add("LEn:", longopts
,
247 " --ctl_socket Override ctl socket path\n"
248 " -n, --instance Instance id\n");
253 opt
= frr_getopt(argc
, argv
, NULL
);
262 ctl_sock_used
= true;
263 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
269 * LDPD_SOCKET configured as relative path
270 * during config? Should really never happen for
273 ctl_sock_name
= (char *)LDPD_SOCKET
;
274 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
275 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
276 strlcat(ctl_sock_path
, ctl_sock_name
,
277 sizeof(ctl_sock_path
));
280 init
.instance
= atoi(optarg
);
281 if (init
.instance
< 1)
295 if (ldpd_di
.pathspace
&& !ctl_sock_used
)
296 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
297 "/", ldpd_di
.pathspace
);
299 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
300 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
301 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
302 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
303 sizeof(init
.zclient_serv_path
));
306 if (argc
> 0 || (lflag
&& eflag
))
309 /* check for root privileges */
310 if (geteuid() != 0) {
312 perror(ldpd_di
.progname
);
316 if (lflag
|| eflag
) {
317 struct zprivs_ids_t ids
;
319 zprivs_preinit(&ldpd_privs
);
320 zprivs_get_ids(&ids
);
322 zlog_init(ldpd_di
.progname
, "LDP", 0,
323 ids
.uid_normal
, ids
.gid_normal
);
330 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
332 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
333 pipe_parent2ldpe_sync
) == -1)
335 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
337 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
338 pipe_parent2lde_sync
) == -1)
340 sock_set_nonblock(pipe_parent2ldpe
[0]);
341 sock_set_cloexec(pipe_parent2ldpe
[0]);
342 sock_set_nonblock(pipe_parent2ldpe
[1]);
343 sock_set_cloexec(pipe_parent2ldpe
[1]);
344 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
345 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
346 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
347 sock_set_nonblock(pipe_parent2lde
[0]);
348 sock_set_cloexec(pipe_parent2lde
[0]);
349 sock_set_nonblock(pipe_parent2lde
[1]);
350 sock_set_cloexec(pipe_parent2lde
[1]);
351 sock_set_nonblock(pipe_parent2lde_sync
[0]);
352 sock_set_cloexec(pipe_parent2lde_sync
[0]);
353 sock_set_cloexec(pipe_parent2lde_sync
[1]);
356 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
357 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
358 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
359 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
363 vrf_init(NULL
, NULL
, NULL
, NULL
);
366 ldp_zebra_init(master
);
369 * Create base configuration with sane defaults. All configuration
370 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
371 * to merge the changes into ldpd_conf, which contains the actual
372 * running configuration.
374 ldpd_conf
= config_new_empty();
375 vty_conf
= config_new_empty();
376 QOBJ_REG(vty_conf
, ldpd_conf
);
378 /* read configuration file and daemonize */
381 /* apply configuration */
382 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, NULL
);
384 /* setup pipes to children */
385 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
386 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
387 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
388 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
390 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
391 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
392 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
394 iev_ldpe
->handler_write
= ldp_write_handler
;
396 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
397 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
398 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
399 &iev_ldpe_sync
->ev_read
);
400 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
402 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
403 iev_lde
->handler_read
= main_dispatch_lde
;
404 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
406 iev_lde
->handler_write
= ldp_write_handler
;
408 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
409 iev_lde_sync
->handler_read
= main_dispatch_lde
;
410 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
411 &iev_lde_sync
->ev_read
);
412 iev_lde_sync
->handler_write
= ldp_write_handler
;
414 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
415 fatal("could not establish imsg links");
416 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
418 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
419 main_imsg_send_config(ldpd_conf
);
421 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
422 main_imsg_send_net_sockets(AF_INET
);
423 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
424 main_imsg_send_net_sockets(AF_INET6
);
441 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
442 close(iev_ldpe
->ibuf
.fd
);
443 msgbuf_clear(&iev_lde
->ibuf
.w
);
444 close(iev_lde
->ibuf
.fd
);
446 config_clear(ldpd_conf
);
448 ldp_config_reset(vty_conf
);
449 QOBJ_UNREG(vty_conf
);
452 log_debug("waiting for children to terminate");
455 /* Wait for child process. */
458 /* We got interrupted, try again. */
461 /* No more processes were found. */
465 /* Unhandled errno condition. */
470 /* We found something, lets announce it. */
471 if (WIFSIGNALED(status
))
472 log_warnx("%s terminated; signal %d",
473 (pid
== lde_pid
? "label decision engine"
477 /* Repeat until there are no more child processes. */
483 log_info("terminating");
494 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
497 int argc
= 0, nullfd
;
503 fatal("cannot fork");
512 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
514 flog_err_sys(EC_LIB_SYSTEM_CALL
,
515 "%s: failed to open /dev/null: %s", __func__
,
516 safe_strerror(errno
));
524 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
525 fatal("cannot setup imsg async fd");
526 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
527 fatal("cannot setup imsg sync fd");
529 argv
[argc
++] = argv0
;
532 fatalx("Can not start main process");
533 case PROC_LDE_ENGINE
:
534 argv
[argc
++] = (char *)"-L";
536 case PROC_LDP_ENGINE
:
537 argv
[argc
++] = (char *)"-E";
541 argv
[argc
++] = (char *)"-u";
542 argv
[argc
++] = (char *)ldpd_privs
.user
;
543 argv
[argc
++] = (char *)"-g";
544 argv
[argc
++] = (char *)ldpd_privs
.group
;
553 static void main_dispatch_ldpe(struct thread
*thread
)
555 struct imsgev
*iev
= THREAD_ARG(thread
);
556 struct imsgbuf
*ibuf
= &iev
->ibuf
;
564 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
565 fatal("imsg_read error");
566 if (n
== 0) /* connection closed */
570 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
576 switch (imsg
.hdr
.type
) {
578 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
580 case IMSG_REQUEST_SOCKETS
:
582 main_imsg_send_net_sockets(af
);
585 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
586 sizeof(struct acl_check
))
587 fatalx("IMSG_ACL_CHECK imsg with wrong len");
588 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
590 case IMSG_LDP_SYNC_IF_STATE_UPDATE
:
591 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
592 sizeof(struct ldp_igp_sync_if_state
))
593 fatalx("IMSG_LDP_SYNC_IF_STATE_UPDATE imsg with wrong len");
595 ldp_sync_zebra_send_state_update((struct ldp_igp_sync_if_state
*)imsg
.data
);
598 log_debug("%s: error handling imsg %d", __func__
,
607 /* this pipe is dead, so remove the event handlers and exit */
608 THREAD_OFF(iev
->ev_read
);
609 THREAD_OFF(iev
->ev_write
);
614 kill(lde_pid
, SIGTERM
);
619 static void main_dispatch_lde(struct thread
*thread
)
621 struct imsgev
*iev
= THREAD_ARG(thread
);
622 struct imsgbuf
*ibuf
= &iev
->ibuf
;
626 struct zapi_rlfa_response
*rlfa_labels
;
630 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
631 fatal("imsg_read error");
632 if (n
== 0) /* connection closed */
636 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
642 switch (imsg
.hdr
.type
) {
644 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
646 case IMSG_KLABEL_CHANGE
:
647 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
648 sizeof(struct kroute
))
649 fatalx("invalid size of IMSG_KLABEL_CHANGE");
650 if (kr_change(imsg
.data
))
651 log_warnx("%s: error changing route", __func__
);
653 case IMSG_KLABEL_DELETE
:
654 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
655 sizeof(struct kroute
))
656 fatalx("invalid size of IMSG_KLABEL_DELETE");
657 if (kr_delete(imsg
.data
))
658 log_warnx("%s: error deleting route", __func__
);
661 case IMSG_KPW_DELETE
:
664 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
665 sizeof(struct zapi_pw
))
666 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
668 switch (imsg
.hdr
.type
) {
670 if (kmpw_add(imsg
.data
))
671 log_warnx("%s: error adding pseudowire", __func__
);
673 case IMSG_KPW_DELETE
:
674 if (kmpw_del(imsg
.data
))
675 log_warnx("%s: error deleting pseudowire", __func__
);
678 if (kmpw_set(imsg
.data
))
679 log_warnx("%s: error setting pseudowire", __func__
);
682 if (kmpw_unset(imsg
.data
))
683 log_warnx("%s: error unsetting pseudowire", __func__
);
688 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
689 sizeof(struct acl_check
))
690 fatalx("IMSG_ACL_CHECK imsg with wrong len");
691 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
693 case IMSG_RLFA_LABELS
:
694 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
695 sizeof(struct zapi_rlfa_response
)) {
696 log_warnx("%s: wrong imsg len", __func__
);
699 rlfa_labels
= imsg
.data
;
700 ldp_zebra_send_rlfa_labels(rlfa_labels
);
703 log_debug("%s: error handling imsg %d", __func__
,
712 /* this pipe is dead, so remove the event handlers and exit */
713 THREAD_OFF(iev
->ev_read
);
714 THREAD_OFF(iev
->ev_write
);
719 kill(ldpe_pid
, SIGTERM
);
724 void ldp_write_handler(struct thread
*thread
)
726 struct imsgev
*iev
= THREAD_ARG(thread
);
727 struct imsgbuf
*ibuf
= &iev
->ibuf
;
730 iev
->ev_write
= NULL
;
732 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
733 fatal("msgbuf_write");
735 /* this pipe is dead, so remove the event handlers */
736 THREAD_OFF(iev
->ev_read
);
737 THREAD_OFF(iev
->ev_write
);
745 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
747 if (iev_ldpe
== NULL
)
749 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
753 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
755 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
759 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
761 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
763 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
765 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
771 imsg_event_add(struct imsgev
*iev
)
773 if (iev
->handler_read
)
774 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
777 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
778 thread_add_write(master
, iev
->handler_write
, iev
,
779 iev
->ibuf
.fd
, &iev
->ev_write
);
783 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
784 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
788 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
789 pid
, fd
, data
, datalen
)) != -1)
795 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
797 ibuf_close(&eb
->wbuf
, buf
);
802 evbuf_event_add(struct evbuf
*eb
)
805 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
809 void evbuf_init(struct evbuf
*eb
, int fd
, void (*handler
)(struct thread
*),
812 msgbuf_init(&eb
->wbuf
);
814 eb
->handler
= handler
;
819 evbuf_clear(struct evbuf
*eb
)
822 msgbuf_clear(&eb
->wbuf
);
827 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
829 int pipe_ldpe2lde
[2];
831 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
833 sock_set_nonblock(pipe_ldpe2lde
[0]);
834 sock_set_nonblock(pipe_ldpe2lde
[1]);
836 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
839 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
847 main_imsg_send_net_sockets(int af
)
849 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
852 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
853 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
854 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
855 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
859 main_imsg_send_net_socket(int af
, enum socket_type type
)
863 fd
= ldp_create_socket(af
, type
);
865 log_warnx("%s: failed to create %s socket for address-family %s", __func__
, socket_name(type
), af_name(af
));
869 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
874 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
875 union ldpd_addr
*addr
, uint8_t prefixlen
)
878 struct acl_check acl_check
;
880 if (acl_name
[0] == '\0')
881 return FILTER_PERMIT
;
884 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
886 acl_check
.addr
= *addr
;
887 acl_check
.prefixlen
= prefixlen
;
889 /* send (blocking) */
890 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
892 imsg_flush(&iev
->ibuf
);
894 /* receive (blocking) and parse result */
895 if (imsg_read(&iev
->ibuf
) == -1)
896 fatal("imsg_read error");
897 if (imsg_get(&iev
->ibuf
, &imsg
) == -1)
899 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
900 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
901 fatalx("ldp_acl_request: invalid response");
903 return (*((int *)imsg
.data
));
907 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
909 struct access_list
*alist
;
910 struct prefix prefix
;
913 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
915 result
= FILTER_DENY
;
917 prefix
.family
= acl_check
->af
;
918 switch (prefix
.family
) {
920 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
923 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
926 fatalx("ldp_acl_reply: unknown af");
928 prefix
.prefixlen
= acl_check
->prefixlen
;
929 result
= access_list_apply(alist
, &prefix
);
932 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
936 struct ldpd_af_conf
*
937 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
941 return (&xconf
->ipv4
);
943 return (&xconf
->ipv6
);
945 fatalx("ldp_af_conf_get: unknown af");
949 struct ldpd_af_global
*
950 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
954 return (&xglobal
->ipv4
);
956 return (&xglobal
->ipv6
);
958 fatalx("ldp_af_global_get: unknown af");
963 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
965 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
966 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
970 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
972 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
973 return (xconf
->rtr_id
.s_addr
);
975 return (global
.rtr_id
.s_addr
);
979 main_imsg_send_config(struct ldpd_conf
*xconf
)
983 struct nbr_params
*nbrp
;
985 struct l2vpn_if
*lif
;
988 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
989 sizeof(*xconf
)) == -1)
992 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
993 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
994 sizeof(*iface
)) == -1)
998 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
999 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
1000 sizeof(*tnbr
)) == -1)
1004 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
1005 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
1006 sizeof(*nbrp
)) == -1)
1010 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1011 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
1012 sizeof(*l2vpn
)) == -1)
1015 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1016 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
1017 sizeof(*lif
)) == -1)
1020 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1021 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
1025 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1026 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1032 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1039 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1042 * When reading from a configuration file (startup and sighup), we
1043 * call merge_config() only once after the whole config has been read.
1044 * This is the optimal and least disruptive way to update the running
1047 if (vty
&& vty
->type
== VTY_FILE
)
1050 ldp_config_normalize(xconf
);
1052 if (main_imsg_send_config(xconf
) == -1)
1055 merge_config(ldpd_conf
, xconf
);
1061 ldp_config_normalize(struct ldpd_conf
*xconf
)
1063 struct iface
*iface
, *itmp
;
1064 struct nbr_params
*nbrp
, *ntmp
;
1065 struct l2vpn
*l2vpn
;
1066 struct l2vpn_pw
*pw
, *ptmp
;
1068 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1069 ldp_config_reset_main(xconf
);
1071 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1072 ldp_config_reset_af(xconf
, AF_INET
);
1073 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1074 ldp_config_reset_af(xconf
, AF_INET6
);
1076 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1077 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1081 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1085 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1086 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1088 if (nbrp
->auth
.method
!= AUTH_NONE
)
1092 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1097 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1098 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1099 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1101 pw
->addr
.v4
= pw
->lsr_id
;
1104 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1106 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1107 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1109 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1111 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1113 pw
->addr
.v4
= pw
->lsr_id
;
1116 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1118 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1119 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1125 ldp_config_reset(struct ldpd_conf
*conf
)
1127 ldp_config_reset_main(conf
);
1128 ldp_config_reset_l2vpns(conf
);
1132 ldp_config_reset_main(struct ldpd_conf
*conf
)
1134 struct iface
*iface
;
1135 struct nbr_params
*nbrp
;
1137 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1138 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1141 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1145 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1146 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1149 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1153 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1154 ldp_config_reset_af(conf
, AF_INET
);
1155 ldp_config_reset_af(conf
, AF_INET6
);
1156 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1157 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1158 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1159 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1160 conf
->wait_for_sync_interval
= DFLT_WAIT_FOR_SYNC
;
1161 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1166 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1168 struct ldpd_af_conf
*af_conf
;
1169 struct iface
*iface
;
1170 struct iface_af
*ia
;
1171 struct tnbr
*tnbr
, *ttmp
;
1173 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1174 ia
= iface_af_get(iface
, af
);
1178 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1183 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1187 af_conf
= ldp_af_conf_get(conf
, af
);
1188 af_conf
->keepalive
= 180;
1189 af_conf
->lhello_holdtime
= 0;
1190 af_conf
->lhello_interval
= 0;
1191 af_conf
->thello_holdtime
= 0;
1192 af_conf
->thello_interval
= 0;
1193 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1198 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1200 struct l2vpn
*l2vpn
;
1201 struct l2vpn_if
*lif
;
1202 struct l2vpn_pw
*pw
;
1204 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1205 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1206 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1207 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1210 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1213 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1214 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1217 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1220 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1221 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1224 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1228 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1234 ldp_clear_config(struct ldpd_conf
*xconf
)
1236 struct iface
*iface
;
1238 struct nbr_params
*nbrp
;
1239 struct l2vpn
*l2vpn
;
1241 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1242 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1244 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1247 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1248 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1250 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1253 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1254 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1256 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1259 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1260 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1262 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1269 #define COPY(a, b) do { \
1270 a = malloc(sizeof(*a)); \
1277 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1279 merge_global(conf
, xconf
);
1280 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1281 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1282 merge_ifaces(conf
, xconf
);
1283 merge_tnbrs(conf
, xconf
);
1284 merge_nbrps(conf
, xconf
);
1285 merge_l2vpns(conf
, xconf
);
1289 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1291 /* Removing global LDP config requires resetting LDP IGP Sync FSM */
1292 if ((conf
->flags
& F_LDPD_ENABLED
) &&
1293 (!(xconf
->flags
& F_LDPD_ENABLED
)))
1295 if (ldpd_process
== PROC_LDP_ENGINE
)
1296 ldp_sync_fsm_reset_all();
1299 /* change of router-id requires resetting all neighborships */
1300 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1301 if (ldpd_process
== PROC_LDP_ENGINE
) {
1302 ldpe_reset_nbrs(AF_UNSPEC
);
1303 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1304 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1305 if_update_all(AF_UNSPEC
);
1306 tnbr_update_all(AF_UNSPEC
);
1309 conf
->rtr_id
= xconf
->rtr_id
;
1313 * Configuration of ordered-control or independent-control
1314 * requires resetting all neighborships.
1316 if ((conf
->flags
& F_LDPD_ORDERED_CONTROL
) !=
1317 (xconf
->flags
& F_LDPD_ORDERED_CONTROL
))
1318 ldpe_reset_nbrs(AF_UNSPEC
);
1320 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1321 conf
->lhello_interval
= xconf
->lhello_interval
;
1322 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1323 conf
->thello_interval
= xconf
->thello_interval
;
1324 conf
->wait_for_sync_interval
= xconf
->wait_for_sync_interval
;
1326 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1327 if (ldpd_process
== PROC_LDP_ENGINE
)
1328 ldpe_reset_ds_nbrs();
1329 conf
->trans_pref
= xconf
->trans_pref
;
1332 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1333 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1334 if (ldpd_process
== PROC_LDP_ENGINE
)
1335 ldpe_reset_ds_nbrs();
1339 * Configuration of allow-broken-lsp requires reprograming all
1342 if ((conf
->flags
& F_LDPD_ALLOW_BROKEN_LSP
) !=
1343 (xconf
->flags
& F_LDPD_ALLOW_BROKEN_LSP
)) {
1344 if (ldpd_process
== PROC_LDE_ENGINE
)
1345 lde_allow_broken_lsp_update(xconf
->flags
);
1348 if (ldpd_process
== PROC_LDP_ENGINE
)
1349 ldpe_set_config_change_time();
1351 conf
->flags
= xconf
->flags
;
1355 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1357 int stop_init_backoff
= 0;
1358 int remove_dynamic_tnbrs
= 0;
1359 int change_egress_label
= 0;
1360 int change_host_label
= 0;
1361 int reset_nbrs_ipv4
= 0;
1363 int update_sockets
= 0;
1364 int change_ldp_disabled
= 0;
1367 if (af_conf
->keepalive
!= xa
->keepalive
) {
1368 af_conf
->keepalive
= xa
->keepalive
;
1369 stop_init_backoff
= 1;
1371 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1372 af_conf
->lhello_interval
= xa
->lhello_interval
;
1373 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1374 af_conf
->thello_interval
= xa
->thello_interval
;
1377 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1378 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1379 remove_dynamic_tnbrs
= 1;
1380 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1381 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1383 /* need to set/unset IPV6_MINHOPCOUNT */
1386 /* for LDPv4 just resetting the neighbors is enough */
1387 reset_nbrs_ipv4
= 1;
1389 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1390 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1391 change_egress_label
= 1;
1393 /* changing config of host only fec filtering */
1394 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
1395 != (xa
->flags
& F_LDPD_AF_ALLOCHOSTONLY
))
1396 change_host_label
= 1;
1398 /* disabling LDP for address family */
1399 if ((af_conf
->flags
& F_LDPD_AF_ENABLED
) &&
1400 !(xa
->flags
& F_LDPD_AF_ENABLED
))
1401 change_ldp_disabled
= 1;
1403 af_conf
->flags
= xa
->flags
;
1405 /* update the transport address */
1406 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1407 af_conf
->trans_addr
= xa
->trans_addr
;
1412 if (strcmp(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
))
1413 change_host_label
= 1;
1415 if (strcmp(af_conf
->acl_label_advertise_to
,
1416 xa
->acl_label_advertise_to
) ||
1417 strcmp(af_conf
->acl_label_advertise_for
,
1418 xa
->acl_label_advertise_for
) ||
1419 strcmp(af_conf
->acl_label_accept_from
,
1420 xa
->acl_label_accept_from
) ||
1421 strcmp(af_conf
->acl_label_accept_for
,
1422 xa
->acl_label_accept_for
))
1424 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1425 remove_dynamic_tnbrs
= 1;
1426 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1427 change_egress_label
= 1;
1428 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1429 sizeof(af_conf
->acl_thello_accept_from
));
1430 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1431 sizeof(af_conf
->acl_label_allocate_for
));
1432 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1433 sizeof(af_conf
->acl_label_advertise_to
));
1434 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1435 sizeof(af_conf
->acl_label_advertise_for
));
1436 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1437 sizeof(af_conf
->acl_label_accept_from
));
1438 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1439 sizeof(af_conf
->acl_label_accept_for
));
1440 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1441 sizeof(af_conf
->acl_label_expnull_for
));
1443 /* apply the new configuration */
1444 switch (ldpd_process
) {
1445 case PROC_LDE_ENGINE
:
1446 if (change_egress_label
)
1447 lde_change_egress_label(af
);
1448 if (change_host_label
)
1449 lde_change_allocate_filter(af
);
1450 if (change_ldp_disabled
)
1451 lde_route_update_release_all(af
);
1454 case PROC_LDP_ENGINE
:
1455 if (stop_init_backoff
)
1456 ldpe_stop_init_backoff(af
);
1457 if (remove_dynamic_tnbrs
)
1458 ldpe_remove_dynamic_tnbrs(af
);
1460 ldpe_reset_nbrs(AF_UNSPEC
);
1461 else if (reset_nbrs_ipv4
)
1462 ldpe_reset_nbrs(AF_INET
);
1465 if (update_sockets
&& iev_ldpe
)
1466 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1473 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1475 struct iface
*iface
, *itmp
, *xi
;
1477 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1478 /* find deleted interfaces, which occurs when LDP is removed
1479 * for all address families
1481 if (if_lookup_name(xconf
, iface
->name
) == NULL
) {
1482 switch (ldpd_process
) {
1483 case PROC_LDP_ENGINE
:
1484 ldpe_if_exit(iface
);
1486 case PROC_LDE_ENGINE
:
1487 if (iface
->ipv4
.enabled
)
1488 lde_route_update_release(iface
,
1490 if (iface
->ipv6
.enabled
)
1491 lde_route_update_release(iface
,
1497 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1501 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1502 /* find new interfaces */
1503 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1505 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1507 switch (ldpd_process
) {
1508 case PROC_LDP_ENGINE
:
1509 ldpe_if_init(iface
);
1511 case PROC_LDE_ENGINE
:
1514 /* resend addresses to activate new interfaces */
1515 kif_redistribute(iface
->name
);
1521 /* update labels when adding or removing ldp on an
1524 if (ldpd_process
== PROC_LDE_ENGINE
) {
1525 /* if we are removing lpd config for an address
1526 * family on an interface then advertise routes
1527 * learned over this interface as if they were
1530 if (iface
->ipv4
.enabled
&& !xi
->ipv4
.enabled
)
1531 lde_route_update_release(iface
, AF_INET
);
1532 if (iface
->ipv6
.enabled
&& !xi
->ipv6
.enabled
)
1533 lde_route_update_release(iface
, AF_INET6
);
1535 /* if we are adding lpd config for an address
1536 * family on an interface then add proper labels
1538 if (!iface
->ipv4
.enabled
&& xi
->ipv4
.enabled
)
1539 lde_route_update(iface
, AF_INET
);
1540 if (!iface
->ipv6
.enabled
&& xi
->ipv6
.enabled
)
1541 lde_route_update(iface
, AF_INET6
);
1544 /* update existing interfaces */
1545 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1546 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1551 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1553 if (ia
->enabled
!= xi
->enabled
) {
1554 ia
->enabled
= xi
->enabled
;
1555 if (ldpd_process
== PROC_LDP_ENGINE
)
1556 ldp_if_update(ia
->iface
, ia
->af
);
1558 ia
->hello_holdtime
= xi
->hello_holdtime
;
1559 ia
->hello_interval
= xi
->hello_interval
;
1563 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1565 struct tnbr
*tnbr
, *ttmp
, *xt
;
1567 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1568 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1571 /* find deleted tnbrs */
1572 if (tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
) == NULL
) {
1573 switch (ldpd_process
) {
1574 case PROC_LDP_ENGINE
:
1575 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1576 tnbr_check(conf
, tnbr
);
1578 case PROC_LDE_ENGINE
:
1580 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1586 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1587 /* find new tnbrs */
1588 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1590 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1592 switch (ldpd_process
) {
1593 case PROC_LDP_ENGINE
:
1596 case PROC_LDE_ENGINE
:
1603 /* update existing tnbrs */
1604 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1605 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1610 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1612 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1616 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1617 /* find deleted nbrps */
1618 if (nbr_params_find(xconf
, nbrp
->lsr_id
) != NULL
)
1621 switch (ldpd_process
) {
1622 case PROC_LDP_ENGINE
:
1623 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1625 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1630 (ldp_af_global_get(&global
, nbr
->af
))
1631 ->ldp_session_socket
,
1632 nbr
->af
, &nbr
->raddr
, NULL
);
1634 nbr
->auth
.method
= AUTH_NONE
;
1635 if (nbr_session_active_role(nbr
))
1636 nbr_establish_connection(nbr
);
1639 case PROC_LDE_ENGINE
:
1643 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1647 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1648 /* find new nbrps */
1649 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1651 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1653 switch (ldpd_process
) {
1654 case PROC_LDP_ENGINE
:
1655 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1657 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1658 nbr
->auth
.method
= nbrp
->auth
.method
;
1660 if (pfkey_establish(nbr
, nbrp
) == -1)
1661 fatalx("pfkey setup failed");
1664 (ldp_af_global_get(&global
,
1665 nbr
->af
))->ldp_session_socket
,
1666 nbr
->af
, &nbr
->raddr
,
1669 if (nbr_session_active_role(nbr
))
1670 nbr_establish_connection(nbr
);
1673 case PROC_LDE_ENGINE
:
1680 /* update existing nbrps */
1681 if (nbrp
->flags
!= xn
->flags
||
1682 nbrp
->keepalive
!= xn
->keepalive
||
1683 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1684 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1685 nbrp
->auth
.method
!= xn
->auth
.method
||
1686 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1691 nbrp
->keepalive
= xn
->keepalive
;
1692 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1693 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1694 nbrp
->auth
.method
= xn
->auth
.method
;
1695 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1696 sizeof(nbrp
->auth
.md5key
));
1697 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1698 nbrp
->flags
= xn
->flags
;
1700 if (ldpd_process
== PROC_LDP_ENGINE
) {
1701 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1702 if (nbr
&& nbrp_changed
) {
1703 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1706 nbr
->auth
.method
= nbrp
->auth
.method
;
1707 if (pfkey_establish(nbr
, nbrp
) == -1)
1708 fatalx("pfkey setup failed");
1710 nbr
->auth
.method
= nbrp
->auth
.method
;
1711 sock_set_md5sig((ldp_af_global_get(&global
,
1712 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1713 &nbr
->raddr
, nbrp
->auth
.md5key
);
1715 if (nbr_session_active_role(nbr
))
1716 nbr_establish_connection(nbr
);
1723 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1725 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1727 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1728 /* find deleted l2vpns */
1729 if (l2vpn_find(xconf
, l2vpn
->name
) == NULL
) {
1730 switch (ldpd_process
) {
1731 case PROC_LDE_ENGINE
:
1734 case PROC_LDP_ENGINE
:
1735 ldpe_l2vpn_exit(l2vpn
);
1740 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1744 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1745 /* find new l2vpns */
1746 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1748 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1749 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1750 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1751 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1753 switch (ldpd_process
) {
1754 case PROC_LDE_ENGINE
:
1757 case PROC_LDP_ENGINE
:
1758 ldpe_l2vpn_init(l2vpn
);
1765 /* update existing l2vpns */
1766 merge_l2vpn(conf
, l2vpn
, xl
);
1771 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1773 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1774 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1776 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1777 int previous_pw_type
, previous_mtu
;
1779 previous_pw_type
= l2vpn
->pw_type
;
1780 previous_mtu
= l2vpn
->mtu
;
1782 /* merge interfaces */
1783 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1784 /* find deleted interfaces */
1785 if (l2vpn_if_find(xl
, lif
->ifname
) == NULL
) {
1786 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1790 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1791 /* find new interfaces */
1792 if (l2vpn_if_find(l2vpn
, xf
->ifname
) == NULL
) {
1794 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1797 switch (ldpd_process
) {
1798 case PROC_LDP_ENGINE
:
1799 case PROC_LDE_ENGINE
:
1802 kif_redistribute(lif
->ifname
);
1808 /* merge active pseudowires */
1809 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1810 /* find deleted active pseudowires */
1811 if (l2vpn_pw_find_active(xl
, pw
->ifname
) == NULL
) {
1812 switch (ldpd_process
) {
1813 case PROC_LDE_ENGINE
:
1816 case PROC_LDP_ENGINE
:
1817 ldpe_l2vpn_pw_exit(pw
);
1823 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1827 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1828 /* find new active pseudowires */
1829 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1831 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1834 switch (ldpd_process
) {
1835 case PROC_LDE_ENGINE
:
1838 case PROC_LDP_ENGINE
:
1839 ldpe_l2vpn_pw_init(pw
);
1842 kif_redistribute(pw
->ifname
);
1848 /* update existing active pseudowire */
1849 if (pw
->af
!= xp
->af
||
1850 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1855 /* changes that require a session restart */
1856 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1857 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1862 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1863 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1864 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1865 reinstall_pwfec
= 1;
1867 reinstall_pwfec
= 0;
1869 if (ldpd_process
== PROC_LDP_ENGINE
) {
1871 ldpe_l2vpn_pw_exit(pw
);
1873 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1874 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1875 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1878 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1880 pw
->lsr_id
= xp
->lsr_id
;
1882 pw
->addr
= xp
->addr
;
1883 pw
->pwid
= xp
->pwid
;
1884 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1885 pw
->ifindex
= xp
->ifindex
;
1886 if (xp
->flags
& F_PW_CWORD_CONF
)
1887 pw
->flags
|= F_PW_CWORD_CONF
;
1889 pw
->flags
&= ~F_PW_CWORD_CONF
;
1890 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1891 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1893 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1894 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1895 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1897 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1898 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1899 ldpe_l2vpn_pw_init(pw
);
1900 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1901 l2vpn
->pw_type
= xl
->pw_type
;
1902 l2vpn
->mtu
= xl
->mtu
;
1904 l2vpn
->pw_type
= previous_pw_type
;
1905 l2vpn
->mtu
= previous_mtu
;
1909 /* merge inactive pseudowires */
1910 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1911 /* find deleted inactive pseudowires */
1912 if (l2vpn_pw_find_inactive(xl
, pw
->ifname
) == NULL
) {
1913 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1917 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1918 /* find new inactive pseudowires */
1919 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1921 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1924 switch (ldpd_process
) {
1925 case PROC_LDE_ENGINE
:
1926 case PROC_LDP_ENGINE
:
1929 kif_redistribute(pw
->ifname
);
1935 /* update existing inactive pseudowire */
1936 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1938 pw
->addr
= xp
->addr
;
1939 pw
->pwid
= xp
->pwid
;
1940 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1941 pw
->ifindex
= xp
->ifindex
;
1942 pw
->flags
= xp
->flags
;
1945 l2vpn
->pw_type
= xl
->pw_type
;
1946 l2vpn
->mtu
= xl
->mtu
;
1947 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1948 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1952 config_new_empty(void)
1954 struct ldpd_conf
*xconf
;
1956 xconf
= calloc(1, sizeof(*xconf
));
1960 RB_INIT(iface_head
, &xconf
->iface_tree
);
1961 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1962 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1963 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1965 /* set default values */
1966 ldp_config_reset(xconf
);
1972 config_clear(struct ldpd_conf
*conf
)
1974 struct ldpd_conf
*xconf
;
1977 * Merge current config with an empty config, this will deactivate
1978 * and deallocate all the interfaces, pseudowires and so on. Before
1979 * merging, copy the router-id and other variables to avoid some
1980 * unnecessary operations, like trying to reset the neighborships.
1982 xconf
= config_new_empty();
1983 xconf
->ipv4
= conf
->ipv4
;
1984 xconf
->ipv6
= conf
->ipv6
;
1985 xconf
->rtr_id
= conf
->rtr_id
;
1986 xconf
->trans_pref
= conf
->trans_pref
;
1987 xconf
->flags
= conf
->flags
;
1988 merge_config(conf
, xconf
);