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)
333 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
334 pipe_parent2ldpe_sync
) == -1)
337 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
340 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
341 pipe_parent2lde_sync
) == -1)
344 sock_set_nonblock(pipe_parent2ldpe
[0]);
345 sock_set_cloexec(pipe_parent2ldpe
[0]);
346 sock_set_nonblock(pipe_parent2ldpe
[1]);
347 sock_set_cloexec(pipe_parent2ldpe
[1]);
348 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
349 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
350 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
351 sock_set_nonblock(pipe_parent2lde
[0]);
352 sock_set_cloexec(pipe_parent2lde
[0]);
353 sock_set_nonblock(pipe_parent2lde
[1]);
354 sock_set_cloexec(pipe_parent2lde
[1]);
355 sock_set_nonblock(pipe_parent2lde_sync
[0]);
356 sock_set_cloexec(pipe_parent2lde_sync
[0]);
357 sock_set_cloexec(pipe_parent2lde_sync
[1]);
360 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
361 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
362 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
363 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
367 vrf_init(NULL
, NULL
, NULL
, NULL
);
370 ldp_zebra_init(master
);
373 * Create base configuration with sane defaults. All configuration
374 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
375 * to merge the changes into ldpd_conf, which contains the actual
376 * running configuration.
378 ldpd_conf
= config_new_empty();
379 vty_conf
= config_new_empty();
380 QOBJ_REG(vty_conf
, ldpd_conf
);
382 /* read configuration file and daemonize */
385 /* apply configuration */
386 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, NULL
);
388 /* setup pipes to children */
389 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
390 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
391 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
392 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
395 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
396 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
397 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
399 iev_ldpe
->handler_write
= ldp_write_handler
;
401 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
402 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
403 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
404 &iev_ldpe_sync
->ev_read
);
405 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
407 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
408 iev_lde
->handler_read
= main_dispatch_lde
;
409 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
411 iev_lde
->handler_write
= ldp_write_handler
;
413 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
414 iev_lde_sync
->handler_read
= main_dispatch_lde
;
415 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
416 &iev_lde_sync
->ev_read
);
417 iev_lde_sync
->handler_write
= ldp_write_handler
;
419 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
420 fatal("could not establish imsg links");
422 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
, sizeof(ldp_debug
));
423 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
424 main_imsg_send_config(ldpd_conf
);
426 if (CHECK_FLAG(ldpd_conf
->ipv4
.flags
, F_LDPD_AF_ENABLED
))
427 main_imsg_send_net_sockets(AF_INET
);
429 if (CHECK_FLAG(ldpd_conf
->ipv6
.flags
, F_LDPD_AF_ENABLED
))
430 main_imsg_send_net_sockets(AF_INET6
);
447 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
448 close(iev_ldpe
->ibuf
.fd
);
449 msgbuf_clear(&iev_lde
->ibuf
.w
);
450 close(iev_lde
->ibuf
.fd
);
452 config_clear(ldpd_conf
);
454 ldp_config_reset(vty_conf
);
455 QOBJ_UNREG(vty_conf
);
458 log_debug("waiting for children to terminate");
461 /* Wait for child process. */
464 /* We got interrupted, try again. */
467 /* No more processes were found. */
471 /* Unhandled errno condition. */
476 /* We found something, lets announce it. */
477 if (WIFSIGNALED(status
))
478 log_warnx("%s terminated; signal %d",
479 (pid
== lde_pid
? "label decision engine"
483 /* Repeat until there are no more child processes. */
489 log_info("terminating");
500 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
503 int argc
= 0, nullfd
;
509 fatal("cannot fork");
518 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
520 flog_err_sys(EC_LIB_SYSTEM_CALL
,
521 "%s: failed to open /dev/null: %s", __func__
,
522 safe_strerror(errno
));
530 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
531 fatal("cannot setup imsg async fd");
533 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
534 fatal("cannot setup imsg sync fd");
536 argv
[argc
++] = argv0
;
539 fatalx("Can not start main process");
540 case PROC_LDE_ENGINE
:
541 argv
[argc
++] = (char *)"-L";
543 case PROC_LDP_ENGINE
:
544 argv
[argc
++] = (char *)"-E";
548 argv
[argc
++] = (char *)"-u";
549 argv
[argc
++] = (char *)ldpd_privs
.user
;
550 argv
[argc
++] = (char *)"-g";
551 argv
[argc
++] = (char *)ldpd_privs
.group
;
560 static void main_dispatch_ldpe(struct thread
*thread
)
562 struct imsgev
*iev
= THREAD_ARG(thread
);
563 struct imsgbuf
*ibuf
= &iev
->ibuf
;
571 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
572 fatal("imsg_read error");
574 if (n
== 0) /* connection closed */
578 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
584 switch (imsg
.hdr
.type
) {
586 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
588 case IMSG_REQUEST_SOCKETS
:
590 main_imsg_send_net_sockets(af
);
593 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
594 sizeof(struct acl_check
))
595 fatalx("IMSG_ACL_CHECK imsg with wrong len");
596 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
598 case IMSG_LDP_SYNC_IF_STATE_UPDATE
:
599 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
600 sizeof(struct ldp_igp_sync_if_state
))
601 fatalx("IMSG_LDP_SYNC_IF_STATE_UPDATE imsg with wrong len");
603 ldp_sync_zebra_send_state_update((struct ldp_igp_sync_if_state
*)imsg
.data
);
606 log_debug("%s: error handling imsg %d", __func__
,
615 /* this pipe is dead, so remove the event handlers and exit */
616 THREAD_OFF(iev
->ev_read
);
617 THREAD_OFF(iev
->ev_write
);
623 kill(lde_pid
, SIGTERM
);
628 static void main_dispatch_lde(struct thread
*thread
)
630 struct imsgev
*iev
= THREAD_ARG(thread
);
631 struct imsgbuf
*ibuf
= &iev
->ibuf
;
635 struct zapi_rlfa_response
*rlfa_labels
;
639 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
640 fatal("imsg_read error");
642 if (n
== 0) /* connection closed */
646 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
652 switch (imsg
.hdr
.type
) {
654 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
656 case IMSG_KLABEL_CHANGE
:
657 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
658 sizeof(struct kroute
))
659 fatalx("invalid size of IMSG_KLABEL_CHANGE");
660 if (kr_change(imsg
.data
))
661 log_warnx("%s: error changing route", __func__
);
663 case IMSG_KLABEL_DELETE
:
664 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
665 sizeof(struct kroute
))
666 fatalx("invalid size of IMSG_KLABEL_DELETE");
667 if (kr_delete(imsg
.data
))
668 log_warnx("%s: error deleting route", __func__
);
671 case IMSG_KPW_DELETE
:
674 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
675 sizeof(struct zapi_pw
))
676 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
678 switch (imsg
.hdr
.type
) {
680 if (kmpw_add(imsg
.data
))
681 log_warnx("%s: error adding pseudowire", __func__
);
683 case IMSG_KPW_DELETE
:
684 if (kmpw_del(imsg
.data
))
685 log_warnx("%s: error deleting pseudowire", __func__
);
688 if (kmpw_set(imsg
.data
))
689 log_warnx("%s: error setting pseudowire", __func__
);
692 if (kmpw_unset(imsg
.data
))
693 log_warnx("%s: error unsetting pseudowire", __func__
);
698 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
699 sizeof(struct acl_check
))
700 fatalx("IMSG_ACL_CHECK imsg with wrong len");
701 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
703 case IMSG_RLFA_LABELS
:
704 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
705 sizeof(struct zapi_rlfa_response
)) {
706 log_warnx("%s: wrong imsg len", __func__
);
709 rlfa_labels
= imsg
.data
;
710 ldp_zebra_send_rlfa_labels(rlfa_labels
);
713 log_debug("%s: error handling imsg %d", __func__
,
724 /* this pipe is dead, so remove the event handlers and exit */
725 THREAD_OFF(iev
->ev_read
);
726 THREAD_OFF(iev
->ev_write
);
731 kill(ldpe_pid
, SIGTERM
);
736 void ldp_write_handler(struct thread
*thread
)
738 struct imsgev
*iev
= THREAD_ARG(thread
);
739 struct imsgbuf
*ibuf
= &iev
->ibuf
;
742 iev
->ev_write
= NULL
;
744 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
745 fatal("msgbuf_write");
747 /* this pipe is dead, so remove the event handlers */
748 THREAD_OFF(iev
->ev_read
);
749 THREAD_OFF(iev
->ev_write
);
757 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
759 if (iev_ldpe
== NULL
)
762 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
766 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
768 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
772 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
774 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
777 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
780 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
787 imsg_event_add(struct imsgev
*iev
)
789 if (iev
->handler_read
)
790 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
793 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
794 thread_add_write(master
, iev
->handler_write
, iev
,
795 iev
->ibuf
.fd
, &iev
->ev_write
);
799 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
800 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
804 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
805 pid
, fd
, data
, datalen
)) != -1)
812 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
814 ibuf_close(&eb
->wbuf
, buf
);
819 evbuf_event_add(struct evbuf
*eb
)
822 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
826 void evbuf_init(struct evbuf
*eb
, int fd
, void (*handler
)(struct thread
*),
829 msgbuf_init(&eb
->wbuf
);
831 eb
->handler
= handler
;
836 evbuf_clear(struct evbuf
*eb
)
839 msgbuf_clear(&eb
->wbuf
);
844 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
846 int pipe_ldpe2lde
[2];
848 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
850 sock_set_nonblock(pipe_ldpe2lde
[0]);
851 sock_set_nonblock(pipe_ldpe2lde
[1]);
853 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
857 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
865 main_imsg_send_net_sockets(int af
)
867 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
870 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
871 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
872 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
873 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
877 main_imsg_send_net_socket(int af
, enum socket_type type
)
881 fd
= ldp_create_socket(af
, type
);
883 log_warnx("%s: failed to create %s socket for address-family %s", __func__
, socket_name(type
), af_name(af
));
887 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
892 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
893 union ldpd_addr
*addr
, uint8_t prefixlen
)
896 struct acl_check acl_check
;
898 if (acl_name
[0] == '\0')
899 return FILTER_PERMIT
;
902 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
904 acl_check
.addr
= *addr
;
905 acl_check
.prefixlen
= prefixlen
;
907 /* send (blocking) */
908 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
910 imsg_flush(&iev
->ibuf
);
912 /* receive (blocking) and parse result */
913 if (imsg_read(&iev
->ibuf
) == -1)
914 fatal("imsg_read error");
916 if (imsg_get(&iev
->ibuf
, &imsg
) == -1)
919 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
920 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
921 fatalx("ldp_acl_request: invalid response");
923 return (*((int *)imsg
.data
));
927 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
929 struct access_list
*alist
;
930 struct prefix prefix
;
933 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
935 result
= FILTER_DENY
;
937 prefix
.family
= acl_check
->af
;
938 switch (prefix
.family
) {
940 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
943 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
946 fatalx("ldp_acl_reply: unknown af");
948 prefix
.prefixlen
= acl_check
->prefixlen
;
949 result
= access_list_apply(alist
, &prefix
);
952 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
956 struct ldpd_af_conf
*
957 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
961 return (&xconf
->ipv4
);
963 return (&xconf
->ipv6
);
965 fatalx("ldp_af_conf_get: unknown af");
969 struct ldpd_af_global
*
970 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
974 return (&xglobal
->ipv4
);
976 return (&xglobal
->ipv6
);
978 fatalx("ldp_af_global_get: unknown af");
983 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
985 return (CHECK_FLAG(xconf
->ipv4
.flags
, F_LDPD_AF_ENABLED
)
986 && CHECK_FLAG(xconf
->ipv6
.flags
, F_LDPD_AF_ENABLED
));
990 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
992 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
993 return (xconf
->rtr_id
.s_addr
);
995 return (global
.rtr_id
.s_addr
);
999 main_imsg_send_config(struct ldpd_conf
*xconf
)
1001 struct iface
*iface
;
1003 struct nbr_params
*nbrp
;
1004 struct l2vpn
*l2vpn
;
1005 struct l2vpn_if
*lif
;
1006 struct l2vpn_pw
*pw
;
1008 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
1009 sizeof(*xconf
)) == -1)
1012 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
1013 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
1014 sizeof(*iface
)) == -1)
1018 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
1019 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
1020 sizeof(*tnbr
)) == -1)
1024 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
1025 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
1026 sizeof(*nbrp
)) == -1)
1030 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1031 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
1032 sizeof(*l2vpn
)) == -1)
1035 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1036 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
1037 sizeof(*lif
)) == -1)
1041 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1042 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
1047 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1048 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1054 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1061 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1064 * When reading from a configuration file (startup and sighup), we
1065 * call merge_config() only once after the whole config has been read.
1066 * This is the optimal and least disruptive way to update the running
1069 if (vty
&& vty
->type
== VTY_FILE
)
1072 ldp_config_normalize(xconf
);
1074 if (main_imsg_send_config(xconf
) == -1)
1077 merge_config(ldpd_conf
, xconf
);
1083 ldp_config_normalize(struct ldpd_conf
*xconf
)
1085 struct iface
*iface
, *itmp
;
1086 struct nbr_params
*nbrp
, *ntmp
;
1087 struct l2vpn
*l2vpn
;
1088 struct l2vpn_pw
*pw
, *ptmp
;
1090 if (!CHECK_FLAG(xconf
->flags
, F_LDPD_ENABLED
))
1091 ldp_config_reset_main(xconf
);
1093 if (!CHECK_FLAG(xconf
->ipv4
.flags
, F_LDPD_AF_ENABLED
))
1094 ldp_config_reset_af(xconf
, AF_INET
);
1095 if (!CHECK_FLAG(xconf
->ipv6
.flags
, F_LDPD_AF_ENABLED
))
1096 ldp_config_reset_af(xconf
, AF_INET6
);
1098 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1099 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1103 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1107 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1108 if (CHECK_FLAG(nbrp
->flags
, (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
)))
1110 if (nbrp
->auth
.method
!= AUTH_NONE
)
1114 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1119 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1120 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1121 if (!CHECK_FLAG(pw
->flags
, F_PW_STATIC_NBR_ADDR
)) {
1123 pw
->addr
.v4
= pw
->lsr_id
;
1126 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1128 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1129 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1132 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1134 if (!CHECK_FLAG(pw
->flags
, F_PW_STATIC_NBR_ADDR
)) {
1136 pw
->addr
.v4
= pw
->lsr_id
;
1139 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1141 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1142 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1148 ldp_config_reset(struct ldpd_conf
*conf
)
1150 ldp_config_reset_main(conf
);
1151 ldp_config_reset_l2vpns(conf
);
1155 ldp_config_reset_main(struct ldpd_conf
*conf
)
1157 struct iface
*iface
;
1158 struct nbr_params
*nbrp
;
1160 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1161 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1164 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1168 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1169 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1172 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1176 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1177 ldp_config_reset_af(conf
, AF_INET
);
1178 ldp_config_reset_af(conf
, AF_INET6
);
1179 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1180 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1181 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1182 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1183 conf
->wait_for_sync_interval
= DFLT_WAIT_FOR_SYNC
;
1184 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1189 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1191 struct ldpd_af_conf
*af_conf
;
1192 struct iface
*iface
;
1193 struct iface_af
*ia
;
1194 struct tnbr
*tnbr
, *ttmp
;
1196 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1197 ia
= iface_af_get(iface
, af
);
1201 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1206 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1210 af_conf
= ldp_af_conf_get(conf
, af
);
1211 af_conf
->keepalive
= 180;
1212 af_conf
->lhello_holdtime
= 0;
1213 af_conf
->lhello_interval
= 0;
1214 af_conf
->thello_holdtime
= 0;
1215 af_conf
->thello_interval
= 0;
1216 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1221 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1223 struct l2vpn
*l2vpn
;
1224 struct l2vpn_if
*lif
;
1225 struct l2vpn_pw
*pw
;
1227 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1228 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1229 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1230 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1233 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1237 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1238 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1241 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1245 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1246 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1249 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1254 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1260 ldp_clear_config(struct ldpd_conf
*xconf
)
1262 struct iface
*iface
;
1264 struct nbr_params
*nbrp
;
1265 struct l2vpn
*l2vpn
;
1267 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1268 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1270 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1274 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1275 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1277 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1281 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1282 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1284 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1288 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1289 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1291 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1298 #define COPY(a, b) do { \
1299 a = malloc(sizeof(*a)); \
1306 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1308 merge_global(conf
, xconf
);
1309 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1310 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1311 merge_ifaces(conf
, xconf
);
1312 merge_tnbrs(conf
, xconf
);
1313 merge_nbrps(conf
, xconf
);
1314 merge_l2vpns(conf
, xconf
);
1318 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1320 /* Removing global LDP config requires resetting LDP IGP Sync FSM */
1321 if (CHECK_FLAG(conf
->flags
, F_LDPD_ENABLED
)
1322 && (!CHECK_FLAG(xconf
->flags
, F_LDPD_ENABLED
)))
1324 if (ldpd_process
== PROC_LDP_ENGINE
)
1325 ldp_sync_fsm_reset_all();
1328 /* change of router-id requires resetting all neighborships */
1329 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1330 if (ldpd_process
== PROC_LDP_ENGINE
) {
1331 ldpe_reset_nbrs(AF_UNSPEC
);
1332 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1333 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1334 if_update_all(AF_UNSPEC
);
1335 tnbr_update_all(AF_UNSPEC
);
1338 conf
->rtr_id
= xconf
->rtr_id
;
1342 * Configuration of ordered-control or independent-control
1343 * requires resetting all neighborships.
1345 if (CHECK_FLAG(conf
->flags
, F_LDPD_ORDERED_CONTROL
) !=
1346 CHECK_FLAG(xconf
->flags
, F_LDPD_ORDERED_CONTROL
))
1347 ldpe_reset_nbrs(AF_UNSPEC
);
1349 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1350 conf
->lhello_interval
= xconf
->lhello_interval
;
1351 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1352 conf
->thello_interval
= xconf
->thello_interval
;
1353 conf
->wait_for_sync_interval
= xconf
->wait_for_sync_interval
;
1355 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1356 if (ldpd_process
== PROC_LDP_ENGINE
)
1357 ldpe_reset_ds_nbrs();
1358 conf
->trans_pref
= xconf
->trans_pref
;
1361 if (CHECK_FLAG(conf
->flags
, F_LDPD_DS_CISCO_INTEROP
) !=
1362 CHECK_FLAG(xconf
->flags
, F_LDPD_DS_CISCO_INTEROP
)) {
1363 if (ldpd_process
== PROC_LDP_ENGINE
)
1364 ldpe_reset_ds_nbrs();
1368 * Configuration of allow-broken-lsp requires reprograming all
1371 if (CHECK_FLAG(conf
->flags
, F_LDPD_ALLOW_BROKEN_LSP
) !=
1372 CHECK_FLAG(xconf
->flags
, F_LDPD_ALLOW_BROKEN_LSP
)) {
1373 if (ldpd_process
== PROC_LDE_ENGINE
)
1374 lde_allow_broken_lsp_update(xconf
->flags
);
1377 if (ldpd_process
== PROC_LDP_ENGINE
)
1378 ldpe_set_config_change_time();
1380 conf
->flags
= xconf
->flags
;
1384 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1386 int stop_init_backoff
= 0;
1387 int remove_dynamic_tnbrs
= 0;
1388 int change_egress_label
= 0;
1389 int change_host_label
= 0;
1390 int reset_nbrs_ipv4
= 0;
1392 int update_sockets
= 0;
1393 int change_ldp_disabled
= 0;
1396 if (af_conf
->keepalive
!= xa
->keepalive
) {
1397 af_conf
->keepalive
= xa
->keepalive
;
1398 stop_init_backoff
= 1;
1401 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1402 af_conf
->lhello_interval
= xa
->lhello_interval
;
1403 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1404 af_conf
->thello_interval
= xa
->thello_interval
;
1407 if (CHECK_FLAG(af_conf
->flags
, F_LDPD_AF_THELLO_ACCEPT
) &&
1408 !CHECK_FLAG(xa
->flags
, F_LDPD_AF_THELLO_ACCEPT
))
1409 remove_dynamic_tnbrs
= 1;
1411 if (CHECK_FLAG(af_conf
->flags
, F_LDPD_AF_NO_GTSM
) !=
1412 CHECK_FLAG(xa
->flags
, F_LDPD_AF_NO_GTSM
)) {
1414 /* need to set/unset IPV6_MINHOPCOUNT */
1417 /* for LDPv4 just resetting the neighbors is enough */
1418 reset_nbrs_ipv4
= 1;
1420 if (CHECK_FLAG(af_conf
->flags
, F_LDPD_AF_EXPNULL
) !=
1421 CHECK_FLAG(xa
->flags
, F_LDPD_AF_EXPNULL
))
1422 change_egress_label
= 1;
1424 /* changing config of host only fec filtering */
1425 if (CHECK_FLAG(af_conf
->flags
, F_LDPD_AF_ALLOCHOSTONLY
)
1426 != CHECK_FLAG(xa
->flags
, F_LDPD_AF_ALLOCHOSTONLY
))
1427 change_host_label
= 1;
1429 /* disabling LDP for address family */
1430 if (CHECK_FLAG(af_conf
->flags
, F_LDPD_AF_ENABLED
) &&
1431 !CHECK_FLAG(xa
->flags
, F_LDPD_AF_ENABLED
))
1432 change_ldp_disabled
= 1;
1434 af_conf
->flags
= xa
->flags
;
1436 /* update the transport address */
1437 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1438 af_conf
->trans_addr
= xa
->trans_addr
;
1443 if (strcmp(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
))
1444 change_host_label
= 1;
1446 if (strcmp(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
) ||
1447 strcmp(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
) ||
1448 strcmp(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
) ||
1449 strcmp(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
))
1452 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1453 remove_dynamic_tnbrs
= 1;
1455 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1456 change_egress_label
= 1;
1458 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1459 sizeof(af_conf
->acl_thello_accept_from
));
1461 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1462 sizeof(af_conf
->acl_label_allocate_for
));
1464 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1465 sizeof(af_conf
->acl_label_advertise_to
));
1467 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1468 sizeof(af_conf
->acl_label_advertise_for
));
1470 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1471 sizeof(af_conf
->acl_label_accept_from
));
1473 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1474 sizeof(af_conf
->acl_label_accept_for
));
1476 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1477 sizeof(af_conf
->acl_label_expnull_for
));
1479 /* apply the new configuration */
1480 switch (ldpd_process
) {
1481 case PROC_LDE_ENGINE
:
1482 if (change_egress_label
)
1483 lde_change_egress_label(af
);
1485 if (change_host_label
)
1486 lde_change_allocate_filter(af
);
1488 if (change_ldp_disabled
)
1489 lde_route_update_release_all(af
);
1492 case PROC_LDP_ENGINE
:
1493 if (stop_init_backoff
)
1494 ldpe_stop_init_backoff(af
);
1495 if (remove_dynamic_tnbrs
)
1496 ldpe_remove_dynamic_tnbrs(af
);
1498 ldpe_reset_nbrs(AF_UNSPEC
);
1499 else if (reset_nbrs_ipv4
)
1500 ldpe_reset_nbrs(AF_INET
);
1503 if (update_sockets
&& iev_ldpe
)
1504 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1511 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1513 struct iface
*iface
, *itmp
, *xi
;
1515 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1516 /* find deleted interfaces, which occurs when LDP is removed
1517 * for all address families
1519 if (if_lookup_name(xconf
, iface
->name
) == NULL
) {
1520 switch (ldpd_process
) {
1521 case PROC_LDP_ENGINE
:
1522 ldpe_if_exit(iface
);
1524 case PROC_LDE_ENGINE
:
1525 if (iface
->ipv4
.enabled
)
1526 lde_route_update_release(iface
,
1528 if (iface
->ipv6
.enabled
)
1529 lde_route_update_release(iface
,
1535 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1539 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1540 /* find new interfaces */
1541 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1543 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1545 switch (ldpd_process
) {
1546 case PROC_LDP_ENGINE
:
1547 ldpe_if_init(iface
);
1549 case PROC_LDE_ENGINE
:
1552 /* resend addresses to activate new interfaces */
1553 kif_redistribute(iface
->name
);
1559 /* update labels when adding or removing ldp on an
1562 if (ldpd_process
== PROC_LDE_ENGINE
) {
1563 /* if we are removing lpd config for an address
1564 * family on an interface then advertise routes
1565 * learned over this interface as if they were
1568 if (iface
->ipv4
.enabled
&& !xi
->ipv4
.enabled
)
1569 lde_route_update_release(iface
, AF_INET
);
1571 if (iface
->ipv6
.enabled
&& !xi
->ipv6
.enabled
)
1572 lde_route_update_release(iface
, AF_INET6
);
1574 /* if we are adding lpd config for an address
1575 * family on an interface then add proper labels
1577 if (!iface
->ipv4
.enabled
&& xi
->ipv4
.enabled
)
1578 lde_route_update(iface
, AF_INET
);
1580 if (!iface
->ipv6
.enabled
&& xi
->ipv6
.enabled
)
1581 lde_route_update(iface
, AF_INET6
);
1584 /* update existing interfaces */
1585 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1586 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1591 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1593 if (ia
->enabled
!= xi
->enabled
) {
1594 ia
->enabled
= xi
->enabled
;
1595 if (ldpd_process
== PROC_LDP_ENGINE
)
1596 ldp_if_update(ia
->iface
, ia
->af
);
1598 ia
->hello_holdtime
= xi
->hello_holdtime
;
1599 ia
->hello_interval
= xi
->hello_interval
;
1603 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1605 struct tnbr
*tnbr
, *ttmp
, *xt
;
1607 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1608 if (!CHECK_FLAG(tnbr
->flags
, F_TNBR_CONFIGURED
))
1611 /* find deleted tnbrs */
1612 if (tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
) == NULL
) {
1613 switch (ldpd_process
) {
1614 case PROC_LDP_ENGINE
:
1615 UNSET_FLAG(tnbr
->flags
, F_TNBR_CONFIGURED
);
1616 tnbr_check(conf
, tnbr
);
1618 case PROC_LDE_ENGINE
:
1620 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1626 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1627 /* find new tnbrs */
1628 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1630 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1632 switch (ldpd_process
) {
1633 case PROC_LDP_ENGINE
:
1636 case PROC_LDE_ENGINE
:
1643 /* update existing tnbrs */
1644 if (!CHECK_FLAG(tnbr
->flags
, F_TNBR_CONFIGURED
))
1645 SET_FLAG(tnbr
->flags
, F_TNBR_CONFIGURED
);
1650 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1652 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1656 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1657 /* find deleted nbrps */
1658 if (nbr_params_find(xconf
, nbrp
->lsr_id
) != NULL
)
1661 switch (ldpd_process
) {
1662 case PROC_LDP_ENGINE
:
1663 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1665 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1670 (ldp_af_global_get(&global
, nbr
->af
))
1671 ->ldp_session_socket
,
1672 nbr
->af
, &nbr
->raddr
, NULL
);
1674 nbr
->auth
.method
= AUTH_NONE
;
1675 if (nbr_session_active_role(nbr
))
1676 nbr_establish_connection(nbr
);
1679 case PROC_LDE_ENGINE
:
1683 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1687 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1688 /* find new nbrps */
1689 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1691 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1693 switch (ldpd_process
) {
1694 case PROC_LDP_ENGINE
:
1695 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1697 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1698 nbr
->auth
.method
= nbrp
->auth
.method
;
1700 if (pfkey_establish(nbr
, nbrp
) == -1)
1701 fatalx("pfkey setup failed");
1704 (ldp_af_global_get(&global
,
1705 nbr
->af
))->ldp_session_socket
,
1706 nbr
->af
, &nbr
->raddr
,
1709 if (nbr_session_active_role(nbr
))
1710 nbr_establish_connection(nbr
);
1713 case PROC_LDE_ENGINE
:
1720 /* update existing nbrps */
1721 if (nbrp
->flags
!= xn
->flags
||
1722 nbrp
->keepalive
!= xn
->keepalive
||
1723 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1724 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1725 nbrp
->auth
.method
!= xn
->auth
.method
||
1726 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1731 nbrp
->keepalive
= xn
->keepalive
;
1732 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1733 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1734 nbrp
->auth
.method
= xn
->auth
.method
;
1735 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1736 sizeof(nbrp
->auth
.md5key
));
1737 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1738 nbrp
->flags
= xn
->flags
;
1740 if (ldpd_process
== PROC_LDP_ENGINE
) {
1741 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1742 if (nbr
&& nbrp_changed
) {
1743 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1746 nbr
->auth
.method
= nbrp
->auth
.method
;
1747 if (pfkey_establish(nbr
, nbrp
) == -1)
1748 fatalx("pfkey setup failed");
1750 nbr
->auth
.method
= nbrp
->auth
.method
;
1751 sock_set_md5sig((ldp_af_global_get(&global
,
1752 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1753 &nbr
->raddr
, nbrp
->auth
.md5key
);
1755 if (nbr_session_active_role(nbr
))
1756 nbr_establish_connection(nbr
);
1763 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1765 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1767 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1768 /* find deleted l2vpns */
1769 if (l2vpn_find(xconf
, l2vpn
->name
) == NULL
) {
1770 switch (ldpd_process
) {
1771 case PROC_LDE_ENGINE
:
1774 case PROC_LDP_ENGINE
:
1775 ldpe_l2vpn_exit(l2vpn
);
1780 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1784 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1785 /* find new l2vpns */
1786 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1788 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1789 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1790 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1791 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1793 switch (ldpd_process
) {
1794 case PROC_LDE_ENGINE
:
1797 case PROC_LDP_ENGINE
:
1798 ldpe_l2vpn_init(l2vpn
);
1805 /* update existing l2vpns */
1806 merge_l2vpn(conf
, l2vpn
, xl
);
1811 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1813 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1814 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1816 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1817 int previous_pw_type
, previous_mtu
;
1819 previous_pw_type
= l2vpn
->pw_type
;
1820 previous_mtu
= l2vpn
->mtu
;
1822 /* merge interfaces */
1823 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1824 /* find deleted interfaces */
1825 if (l2vpn_if_find(xl
, lif
->ifname
) == NULL
) {
1826 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1830 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1831 /* find new interfaces */
1832 if (l2vpn_if_find(l2vpn
, xf
->ifname
) == NULL
) {
1834 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1837 switch (ldpd_process
) {
1838 case PROC_LDP_ENGINE
:
1839 case PROC_LDE_ENGINE
:
1842 kif_redistribute(lif
->ifname
);
1848 /* merge active pseudowires */
1849 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1850 /* find deleted active pseudowires */
1851 if (l2vpn_pw_find_active(xl
, pw
->ifname
) == NULL
) {
1852 switch (ldpd_process
) {
1853 case PROC_LDE_ENGINE
:
1856 case PROC_LDP_ENGINE
:
1857 ldpe_l2vpn_pw_exit(pw
);
1863 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1867 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1868 /* find new active pseudowires */
1869 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1871 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1874 switch (ldpd_process
) {
1875 case PROC_LDE_ENGINE
:
1878 case PROC_LDP_ENGINE
:
1879 ldpe_l2vpn_pw_init(pw
);
1882 kif_redistribute(pw
->ifname
);
1888 /* update existing active pseudowire */
1889 if (pw
->af
!= xp
->af
||
1890 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1895 /* changes that require a session restart */
1896 if (CHECK_FLAG(pw
->flags
, (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1897 CHECK_FLAG(xp
->flags
, (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1902 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1903 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1904 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1905 reinstall_pwfec
= 1;
1907 reinstall_pwfec
= 0;
1909 if (ldpd_process
== PROC_LDP_ENGINE
) {
1911 ldpe_l2vpn_pw_exit(pw
);
1913 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1914 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1915 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1918 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1920 pw
->lsr_id
= xp
->lsr_id
;
1922 pw
->addr
= xp
->addr
;
1923 pw
->pwid
= xp
->pwid
;
1924 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1925 pw
->ifindex
= xp
->ifindex
;
1926 if (CHECK_FLAG(xp
->flags
, F_PW_CWORD_CONF
))
1927 SET_FLAG(pw
->flags
, F_PW_CWORD_CONF
);
1929 UNSET_FLAG(pw
->flags
, F_PW_CWORD_CONF
);
1931 if (CHECK_FLAG(xp
->flags
, F_PW_STATUSTLV_CONF
))
1932 SET_FLAG(pw
->flags
, F_PW_STATUSTLV_CONF
);
1934 UNSET_FLAG(pw
->flags
, F_PW_STATUSTLV_CONF
);
1936 if (CHECK_FLAG(xp
->flags
, F_PW_STATIC_NBR_ADDR
))
1937 SET_FLAG(pw
->flags
, F_PW_STATIC_NBR_ADDR
);
1939 UNSET_FLAG(pw
->flags
, F_PW_STATIC_NBR_ADDR
);
1941 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1942 ldpe_l2vpn_pw_init(pw
);
1944 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1945 l2vpn
->pw_type
= xl
->pw_type
;
1946 l2vpn
->mtu
= xl
->mtu
;
1948 l2vpn
->pw_type
= previous_pw_type
;
1949 l2vpn
->mtu
= previous_mtu
;
1953 /* merge inactive pseudowires */
1954 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1955 /* find deleted inactive pseudowires */
1956 if (l2vpn_pw_find_inactive(xl
, pw
->ifname
) == NULL
) {
1957 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1961 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1962 /* find new inactive pseudowires */
1963 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1965 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1968 switch (ldpd_process
) {
1969 case PROC_LDE_ENGINE
:
1970 case PROC_LDP_ENGINE
:
1973 kif_redistribute(pw
->ifname
);
1979 /* update existing inactive pseudowire */
1980 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1982 pw
->addr
= xp
->addr
;
1983 pw
->pwid
= xp
->pwid
;
1984 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1985 pw
->ifindex
= xp
->ifindex
;
1986 pw
->flags
= xp
->flags
;
1989 l2vpn
->pw_type
= xl
->pw_type
;
1990 l2vpn
->mtu
= xl
->mtu
;
1991 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1992 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1996 config_new_empty(void)
1998 struct ldpd_conf
*xconf
;
2000 xconf
= calloc(1, sizeof(*xconf
));
2004 RB_INIT(iface_head
, &xconf
->iface_tree
);
2005 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
2006 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
2007 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
2009 /* set default values */
2010 ldp_config_reset(xconf
);
2016 config_clear(struct ldpd_conf
*conf
)
2018 struct ldpd_conf
*xconf
;
2021 * Merge current config with an empty config, this will deactivate
2022 * and deallocate all the interfaces, pseudowires and so on. Before
2023 * merging, copy the router-id and other variables to avoid some
2024 * unnecessary operations, like trying to reset the neighborships.
2026 xconf
= config_new_empty();
2027 xconf
->ipv4
= conf
->ipv4
;
2028 xconf
->ipv6
= conf
->ipv6
;
2029 xconf
->rtr_id
= conf
->rtr_id
;
2030 xconf
->trans_pref
= conf
->trans_pref
;
2031 xconf
->flags
= conf
->flags
;
2032 merge_config(conf
, xconf
);