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 void main_dispatch_ldpe(struct thread
*thread
);
50 static void main_dispatch_lde(struct thread
*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
;
97 struct frrmod_runtime
*module
;
99 module
= frrmod_load(name
, dir
, NULL
,NULL
);
101 fprintf(stderr
, "%s: failed to load %s", __func__
, name
);
102 log_warnx("%s: failed to load %s", __func__
, name
);
106 void ldp_agentx_enabled(void)
108 ldp_load_module("snmp");
109 hook_call(ldp_register_mib
, master
);
112 enum ldpd_process ldpd_process
;
114 #define LDP_DEFAULT_CONFIG "ldpd.conf"
115 #define LDP_VTY_PORT 2612
117 /* Master of threads. */
118 struct thread_master
*master
;
120 /* ldpd privileges */
121 static zebra_capabilities_t _caps_p
[] =
127 struct zebra_privs_t ldpd_privs
=
129 #if defined(FRR_USER) && defined(FRR_GROUP)
133 #if defined(VTY_GROUP)
134 .vty_group
= VTY_GROUP
,
137 .cap_num_p
= array_size(_caps_p
),
141 /* CTL Socket path */
142 char ctl_sock_path
[MAXPATHLEN
];
145 #define OPTION_CTLSOCK 1001
146 static const struct option longopts
[] =
148 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
149 { "instance", required_argument
, NULL
, 'n'},
153 /* SIGHUP handler. */
157 log_info("SIGHUP received");
160 * Do a full configuration reload. In other words, reset vty_conf
161 * and build a new configuartion from scratch.
163 ldp_config_reset(vty_conf
);
164 vty_read_config(NULL
, ldpd_di
.config_file
, config_default
);
165 ldp_config_apply(NULL
, vty_conf
);
168 /* SIGINT / SIGTERM handler. */
172 log_info("SIGINT received");
176 /* SIGUSR1 handler. */
183 static struct frr_signal_t ldp_signals
[] =
203 static const struct frr_yang_module_info
*const ldpd_yang_modules
[] = {
208 FRR_DAEMON_INFO(ldpd
, LDP
,
209 .vty_port
= LDP_VTY_PORT
,
211 .proghelp
= "Implementation of the LDP protocol.",
213 .signals
= ldp_signals
,
214 .n_signals
= array_size(ldp_signals
),
216 .privs
= &ldpd_privs
,
218 .yang_modules
= ldpd_yang_modules
,
219 .n_yang_modules
= array_size(ldpd_yang_modules
),
222 static void ldp_config_fork_apply(struct thread
*t
)
225 * So the frr_config_fork() function schedules
226 * the read of the vty config( if there is a
227 * non-integrated config ) to be after the
228 * end of startup and we are starting the
229 * main process loop. We need to schedule
230 * the application of this if necessary
231 * after the read in of the config.
233 ldp_config_apply(NULL
, vty_conf
);
237 main(int argc
, char *argv
[])
240 int lflag
= 0, eflag
= 0;
241 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
242 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
244 bool ctl_sock_used
= false;
246 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
249 ldpd_process
= PROC_MAIN
;
250 log_procname
= log_procnames
[ldpd_process
];
252 saved_argv0
= argv
[0];
253 if (saved_argv0
== NULL
)
254 saved_argv0
= (char *)"ldpd";
256 frr_preinit(&ldpd_di
, argc
, argv
);
257 frr_opt_add("LEn:", longopts
,
258 " --ctl_socket Override ctl socket path\n"
259 " -n, --instance Instance id\n");
264 opt
= frr_getopt(argc
, argv
, NULL
);
273 ctl_sock_used
= true;
274 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
280 * LDPD_SOCKET configured as relative path
281 * during config? Should really never happen for
284 ctl_sock_name
= (char *)LDPD_SOCKET
;
285 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
286 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
287 strlcat(ctl_sock_path
, ctl_sock_name
,
288 sizeof(ctl_sock_path
));
291 init
.instance
= atoi(optarg
);
292 if (init
.instance
< 1)
306 if (ldpd_di
.pathspace
&& !ctl_sock_used
)
307 snprintf(ctl_sock_path
, sizeof(ctl_sock_path
), LDPD_SOCKET
,
308 "/", ldpd_di
.pathspace
);
310 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
311 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
312 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
313 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
314 sizeof(init
.zclient_serv_path
));
317 if (argc
> 0 || (lflag
&& eflag
))
320 /* check for root privileges */
321 if (geteuid() != 0) {
323 perror(ldpd_di
.progname
);
327 if (lflag
|| eflag
) {
328 struct zprivs_ids_t ids
;
330 zprivs_preinit(&ldpd_privs
);
331 zprivs_get_ids(&ids
);
333 zlog_init(ldpd_di
.progname
, "LDP", 0,
334 ids
.uid_normal
, ids
.gid_normal
);
341 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
343 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
344 pipe_parent2ldpe_sync
) == -1)
346 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
348 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
349 pipe_parent2lde_sync
) == -1)
351 sock_set_nonblock(pipe_parent2ldpe
[0]);
352 sock_set_cloexec(pipe_parent2ldpe
[0]);
353 sock_set_nonblock(pipe_parent2ldpe
[1]);
354 sock_set_cloexec(pipe_parent2ldpe
[1]);
355 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
356 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
357 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
358 sock_set_nonblock(pipe_parent2lde
[0]);
359 sock_set_cloexec(pipe_parent2lde
[0]);
360 sock_set_nonblock(pipe_parent2lde
[1]);
361 sock_set_cloexec(pipe_parent2lde
[1]);
362 sock_set_nonblock(pipe_parent2lde_sync
[0]);
363 sock_set_cloexec(pipe_parent2lde_sync
[0]);
364 sock_set_cloexec(pipe_parent2lde_sync
[1]);
367 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
368 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
369 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
370 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
374 vrf_init(NULL
, NULL
, NULL
, NULL
);
377 ldp_zebra_init(master
);
380 * Create base configuration with sane defaults. All configuration
381 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
382 * to merge the changes into ldpd_conf, which contains the actual
383 * running configuration.
385 ldpd_conf
= config_new_empty();
386 vty_conf
= config_new_empty();
387 QOBJ_REG(vty_conf
, ldpd_conf
);
389 /* read configuration file and daemonize */
392 /* apply configuration */
393 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, NULL
);
395 /* setup pipes to children */
396 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
397 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
398 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
399 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
401 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
402 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
403 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
405 iev_ldpe
->handler_write
= ldp_write_handler
;
407 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
408 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
409 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
410 &iev_ldpe_sync
->ev_read
);
411 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
413 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
414 iev_lde
->handler_read
= main_dispatch_lde
;
415 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
417 iev_lde
->handler_write
= ldp_write_handler
;
419 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
420 iev_lde_sync
->handler_read
= main_dispatch_lde
;
421 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
422 &iev_lde_sync
->ev_read
);
423 iev_lde_sync
->handler_write
= ldp_write_handler
;
425 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
426 fatal("could not establish imsg links");
427 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
429 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
430 main_imsg_send_config(ldpd_conf
);
432 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
433 main_imsg_send_net_sockets(AF_INET
);
434 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
435 main_imsg_send_net_sockets(AF_INET6
);
452 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
453 close(iev_ldpe
->ibuf
.fd
);
454 msgbuf_clear(&iev_lde
->ibuf
.w
);
455 close(iev_lde
->ibuf
.fd
);
457 config_clear(ldpd_conf
);
459 ldp_config_reset(vty_conf
);
460 QOBJ_UNREG(vty_conf
);
463 log_debug("waiting for children to terminate");
466 /* Wait for child process. */
469 /* We got interrupted, try again. */
472 /* No more processes were found. */
476 /* Unhandled errno condition. */
481 /* We found something, lets announce it. */
482 if (WIFSIGNALED(status
))
483 log_warnx("%s terminated; signal %d",
484 (pid
== lde_pid
? "label decision engine"
488 /* Repeat until there are no more child processes. */
494 log_info("terminating");
505 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
508 int argc
= 0, nullfd
;
514 fatal("cannot fork");
523 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
525 flog_err_sys(EC_LIB_SYSTEM_CALL
,
526 "%s: failed to open /dev/null: %s", __func__
,
527 safe_strerror(errno
));
535 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
536 fatal("cannot setup imsg async fd");
537 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
538 fatal("cannot setup imsg sync fd");
540 argv
[argc
++] = argv0
;
543 fatalx("Can not start main process");
544 case PROC_LDE_ENGINE
:
545 argv
[argc
++] = (char *)"-L";
547 case PROC_LDP_ENGINE
:
548 argv
[argc
++] = (char *)"-E";
552 argv
[argc
++] = (char *)"-u";
553 argv
[argc
++] = (char *)ldpd_privs
.user
;
554 argv
[argc
++] = (char *)"-g";
555 argv
[argc
++] = (char *)ldpd_privs
.group
;
564 static void main_dispatch_ldpe(struct thread
*thread
)
566 struct imsgev
*iev
= THREAD_ARG(thread
);
567 struct imsgbuf
*ibuf
= &iev
->ibuf
;
575 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
576 fatal("imsg_read error");
577 if (n
== 0) /* connection closed */
581 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
587 switch (imsg
.hdr
.type
) {
589 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
591 case IMSG_REQUEST_SOCKETS
:
593 main_imsg_send_net_sockets(af
);
596 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
597 sizeof(struct acl_check
))
598 fatalx("IMSG_ACL_CHECK imsg with wrong len");
599 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
601 case IMSG_LDP_SYNC_IF_STATE_UPDATE
:
602 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
603 sizeof(struct ldp_igp_sync_if_state
))
604 fatalx("IMSG_LDP_SYNC_IF_STATE_UPDATE imsg with wrong len");
606 ldp_sync_zebra_send_state_update((struct ldp_igp_sync_if_state
*)imsg
.data
);
609 log_debug("%s: error handling imsg %d", __func__
,
618 /* this pipe is dead, so remove the event handlers and exit */
619 THREAD_OFF(iev
->ev_read
);
620 THREAD_OFF(iev
->ev_write
);
625 kill(lde_pid
, SIGTERM
);
630 static void main_dispatch_lde(struct thread
*thread
)
632 struct imsgev
*iev
= THREAD_ARG(thread
);
633 struct imsgbuf
*ibuf
= &iev
->ibuf
;
637 struct zapi_rlfa_response
*rlfa_labels
;
641 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
642 fatal("imsg_read error");
643 if (n
== 0) /* connection closed */
647 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
653 switch (imsg
.hdr
.type
) {
655 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
657 case IMSG_KLABEL_CHANGE
:
658 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
659 sizeof(struct kroute
))
660 fatalx("invalid size of IMSG_KLABEL_CHANGE");
661 if (kr_change(imsg
.data
))
662 log_warnx("%s: error changing route", __func__
);
664 case IMSG_KLABEL_DELETE
:
665 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
666 sizeof(struct kroute
))
667 fatalx("invalid size of IMSG_KLABEL_DELETE");
668 if (kr_delete(imsg
.data
))
669 log_warnx("%s: error deleting route", __func__
);
672 case IMSG_KPW_DELETE
:
675 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
676 sizeof(struct zapi_pw
))
677 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
679 switch (imsg
.hdr
.type
) {
681 if (kmpw_add(imsg
.data
))
682 log_warnx("%s: error adding pseudowire", __func__
);
684 case IMSG_KPW_DELETE
:
685 if (kmpw_del(imsg
.data
))
686 log_warnx("%s: error deleting pseudowire", __func__
);
689 if (kmpw_set(imsg
.data
))
690 log_warnx("%s: error setting pseudowire", __func__
);
693 if (kmpw_unset(imsg
.data
))
694 log_warnx("%s: error unsetting pseudowire", __func__
);
699 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
700 sizeof(struct acl_check
))
701 fatalx("IMSG_ACL_CHECK imsg with wrong len");
702 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
704 case IMSG_RLFA_LABELS
:
705 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
706 sizeof(struct zapi_rlfa_response
)) {
707 log_warnx("%s: wrong imsg len", __func__
);
710 rlfa_labels
= imsg
.data
;
711 ldp_zebra_send_rlfa_labels(rlfa_labels
);
714 log_debug("%s: error handling imsg %d", __func__
,
723 /* this pipe is dead, so remove the event handlers and exit */
724 THREAD_OFF(iev
->ev_read
);
725 THREAD_OFF(iev
->ev_write
);
730 kill(ldpe_pid
, SIGTERM
);
735 void ldp_write_handler(struct thread
*thread
)
737 struct imsgev
*iev
= THREAD_ARG(thread
);
738 struct imsgbuf
*ibuf
= &iev
->ibuf
;
741 iev
->ev_write
= NULL
;
743 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
744 fatal("msgbuf_write");
746 /* this pipe is dead, so remove the event handlers */
747 THREAD_OFF(iev
->ev_read
);
748 THREAD_OFF(iev
->ev_write
);
756 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
758 if (iev_ldpe
== NULL
)
760 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
764 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
766 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
770 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
772 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
774 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
776 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
782 imsg_event_add(struct imsgev
*iev
)
784 if (iev
->handler_read
)
785 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
788 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
789 thread_add_write(master
, iev
->handler_write
, iev
,
790 iev
->ibuf
.fd
, &iev
->ev_write
);
794 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
795 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
799 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
800 pid
, fd
, data
, datalen
)) != -1)
806 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
808 ibuf_close(&eb
->wbuf
, buf
);
813 evbuf_event_add(struct evbuf
*eb
)
816 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
820 void evbuf_init(struct evbuf
*eb
, int fd
, void (*handler
)(struct thread
*),
823 msgbuf_init(&eb
->wbuf
);
825 eb
->handler
= handler
;
830 evbuf_clear(struct evbuf
*eb
)
833 msgbuf_clear(&eb
->wbuf
);
838 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
840 int pipe_ldpe2lde
[2];
842 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
844 sock_set_nonblock(pipe_ldpe2lde
[0]);
845 sock_set_nonblock(pipe_ldpe2lde
[1]);
847 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
850 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
858 main_imsg_send_net_sockets(int af
)
860 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
863 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
864 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
865 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
866 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
870 main_imsg_send_net_socket(int af
, enum socket_type type
)
874 fd
= ldp_create_socket(af
, type
);
876 log_warnx("%s: failed to create %s socket for address-family %s", __func__
, socket_name(type
), af_name(af
));
880 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
885 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
886 union ldpd_addr
*addr
, uint8_t prefixlen
)
889 struct acl_check acl_check
;
891 if (acl_name
[0] == '\0')
892 return FILTER_PERMIT
;
895 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
897 acl_check
.addr
= *addr
;
898 acl_check
.prefixlen
= prefixlen
;
900 /* send (blocking) */
901 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
903 imsg_flush(&iev
->ibuf
);
905 /* receive (blocking) and parse result */
906 if (imsg_read(&iev
->ibuf
) == -1)
907 fatal("imsg_read error");
908 if (imsg_get(&iev
->ibuf
, &imsg
) == -1)
910 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
911 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
912 fatalx("ldp_acl_request: invalid response");
914 return (*((int *)imsg
.data
));
918 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
920 struct access_list
*alist
;
921 struct prefix prefix
;
924 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
926 result
= FILTER_DENY
;
928 prefix
.family
= acl_check
->af
;
929 switch (prefix
.family
) {
931 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
934 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
937 fatalx("ldp_acl_reply: unknown af");
939 prefix
.prefixlen
= acl_check
->prefixlen
;
940 result
= access_list_apply(alist
, &prefix
);
943 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
947 struct ldpd_af_conf
*
948 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
952 return (&xconf
->ipv4
);
954 return (&xconf
->ipv6
);
956 fatalx("ldp_af_conf_get: unknown af");
960 struct ldpd_af_global
*
961 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
965 return (&xglobal
->ipv4
);
967 return (&xglobal
->ipv6
);
969 fatalx("ldp_af_global_get: unknown af");
974 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
976 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
977 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
981 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
983 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
984 return (xconf
->rtr_id
.s_addr
);
986 return (global
.rtr_id
.s_addr
);
990 main_imsg_send_config(struct ldpd_conf
*xconf
)
994 struct nbr_params
*nbrp
;
996 struct l2vpn_if
*lif
;
999 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
1000 sizeof(*xconf
)) == -1)
1003 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
1004 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
1005 sizeof(*iface
)) == -1)
1009 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
1010 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
1011 sizeof(*tnbr
)) == -1)
1015 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
1016 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
1017 sizeof(*nbrp
)) == -1)
1021 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1022 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
1023 sizeof(*l2vpn
)) == -1)
1026 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1027 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
1028 sizeof(*lif
)) == -1)
1031 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1032 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
1036 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1037 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1043 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1050 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1053 * When reading from a configuration file (startup and sighup), we
1054 * call merge_config() only once after the whole config has been read.
1055 * This is the optimal and least disruptive way to update the running
1058 if (vty
&& vty
->type
== VTY_FILE
)
1061 ldp_config_normalize(xconf
);
1063 if (main_imsg_send_config(xconf
) == -1)
1066 merge_config(ldpd_conf
, xconf
);
1072 ldp_config_normalize(struct ldpd_conf
*xconf
)
1074 struct iface
*iface
, *itmp
;
1075 struct nbr_params
*nbrp
, *ntmp
;
1076 struct l2vpn
*l2vpn
;
1077 struct l2vpn_pw
*pw
, *ptmp
;
1079 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1080 ldp_config_reset_main(xconf
);
1082 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1083 ldp_config_reset_af(xconf
, AF_INET
);
1084 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1085 ldp_config_reset_af(xconf
, AF_INET6
);
1087 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1088 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1092 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1096 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1097 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1099 if (nbrp
->auth
.method
!= AUTH_NONE
)
1103 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1108 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1109 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1110 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1112 pw
->addr
.v4
= pw
->lsr_id
;
1115 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1117 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1118 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1120 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1122 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1124 pw
->addr
.v4
= pw
->lsr_id
;
1127 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1129 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1130 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1136 ldp_config_reset(struct ldpd_conf
*conf
)
1138 ldp_config_reset_main(conf
);
1139 ldp_config_reset_l2vpns(conf
);
1143 ldp_config_reset_main(struct ldpd_conf
*conf
)
1145 struct iface
*iface
;
1146 struct nbr_params
*nbrp
;
1148 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1149 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1152 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1156 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1157 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1160 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1164 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1165 ldp_config_reset_af(conf
, AF_INET
);
1166 ldp_config_reset_af(conf
, AF_INET6
);
1167 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1168 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1169 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1170 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1171 conf
->wait_for_sync_interval
= DFLT_WAIT_FOR_SYNC
;
1172 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1177 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1179 struct ldpd_af_conf
*af_conf
;
1180 struct iface
*iface
;
1181 struct iface_af
*ia
;
1182 struct tnbr
*tnbr
, *ttmp
;
1184 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1185 ia
= iface_af_get(iface
, af
);
1189 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1194 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1198 af_conf
= ldp_af_conf_get(conf
, af
);
1199 af_conf
->keepalive
= 180;
1200 af_conf
->lhello_holdtime
= 0;
1201 af_conf
->lhello_interval
= 0;
1202 af_conf
->thello_holdtime
= 0;
1203 af_conf
->thello_interval
= 0;
1204 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1209 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1211 struct l2vpn
*l2vpn
;
1212 struct l2vpn_if
*lif
;
1213 struct l2vpn_pw
*pw
;
1215 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1216 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1217 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1218 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1221 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1224 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1225 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1228 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1231 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1232 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1235 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1239 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1245 ldp_clear_config(struct ldpd_conf
*xconf
)
1247 struct iface
*iface
;
1249 struct nbr_params
*nbrp
;
1250 struct l2vpn
*l2vpn
;
1252 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1253 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1255 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1258 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1259 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1261 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1264 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1265 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1267 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1270 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1271 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1273 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1280 #define COPY(a, b) do { \
1281 a = malloc(sizeof(*a)); \
1288 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1290 merge_global(conf
, xconf
);
1291 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1292 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1293 merge_ifaces(conf
, xconf
);
1294 merge_tnbrs(conf
, xconf
);
1295 merge_nbrps(conf
, xconf
);
1296 merge_l2vpns(conf
, xconf
);
1300 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1302 /* Removing global LDP config requires resetting LDP IGP Sync FSM */
1303 if ((conf
->flags
& F_LDPD_ENABLED
) &&
1304 (!(xconf
->flags
& F_LDPD_ENABLED
)))
1306 if (ldpd_process
== PROC_LDP_ENGINE
)
1307 ldp_sync_fsm_reset_all();
1310 /* change of router-id requires resetting all neighborships */
1311 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1312 if (ldpd_process
== PROC_LDP_ENGINE
) {
1313 ldpe_reset_nbrs(AF_UNSPEC
);
1314 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1315 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1316 if_update_all(AF_UNSPEC
);
1317 tnbr_update_all(AF_UNSPEC
);
1320 conf
->rtr_id
= xconf
->rtr_id
;
1324 * Configuration of ordered-control or independent-control
1325 * requires resetting all neighborships.
1327 if ((conf
->flags
& F_LDPD_ORDERED_CONTROL
) !=
1328 (xconf
->flags
& F_LDPD_ORDERED_CONTROL
))
1329 ldpe_reset_nbrs(AF_UNSPEC
);
1331 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1332 conf
->lhello_interval
= xconf
->lhello_interval
;
1333 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1334 conf
->thello_interval
= xconf
->thello_interval
;
1335 conf
->wait_for_sync_interval
= xconf
->wait_for_sync_interval
;
1337 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1338 if (ldpd_process
== PROC_LDP_ENGINE
)
1339 ldpe_reset_ds_nbrs();
1340 conf
->trans_pref
= xconf
->trans_pref
;
1343 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1344 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1345 if (ldpd_process
== PROC_LDP_ENGINE
)
1346 ldpe_reset_ds_nbrs();
1350 * Configuration of allow-broken-lsp requires reprograming all
1353 if ((conf
->flags
& F_LDPD_ALLOW_BROKEN_LSP
) !=
1354 (xconf
->flags
& F_LDPD_ALLOW_BROKEN_LSP
)) {
1355 if (ldpd_process
== PROC_LDE_ENGINE
)
1356 lde_allow_broken_lsp_update(xconf
->flags
);
1359 if (ldpd_process
== PROC_LDP_ENGINE
)
1360 ldpe_set_config_change_time();
1362 conf
->flags
= xconf
->flags
;
1366 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1368 int stop_init_backoff
= 0;
1369 int remove_dynamic_tnbrs
= 0;
1370 int change_egress_label
= 0;
1371 int change_host_label
= 0;
1372 int reset_nbrs_ipv4
= 0;
1374 int update_sockets
= 0;
1375 int change_ldp_disabled
= 0;
1378 if (af_conf
->keepalive
!= xa
->keepalive
) {
1379 af_conf
->keepalive
= xa
->keepalive
;
1380 stop_init_backoff
= 1;
1382 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1383 af_conf
->lhello_interval
= xa
->lhello_interval
;
1384 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1385 af_conf
->thello_interval
= xa
->thello_interval
;
1388 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1389 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1390 remove_dynamic_tnbrs
= 1;
1391 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1392 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1394 /* need to set/unset IPV6_MINHOPCOUNT */
1397 /* for LDPv4 just resetting the neighbors is enough */
1398 reset_nbrs_ipv4
= 1;
1400 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1401 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1402 change_egress_label
= 1;
1404 /* changing config of host only fec filtering */
1405 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
1406 != (xa
->flags
& F_LDPD_AF_ALLOCHOSTONLY
))
1407 change_host_label
= 1;
1409 /* disabling LDP for address family */
1410 if ((af_conf
->flags
& F_LDPD_AF_ENABLED
) &&
1411 !(xa
->flags
& F_LDPD_AF_ENABLED
))
1412 change_ldp_disabled
= 1;
1414 af_conf
->flags
= xa
->flags
;
1416 /* update the transport address */
1417 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1418 af_conf
->trans_addr
= xa
->trans_addr
;
1423 if (strcmp(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
))
1424 change_host_label
= 1;
1426 if (strcmp(af_conf
->acl_label_advertise_to
,
1427 xa
->acl_label_advertise_to
) ||
1428 strcmp(af_conf
->acl_label_advertise_for
,
1429 xa
->acl_label_advertise_for
) ||
1430 strcmp(af_conf
->acl_label_accept_from
,
1431 xa
->acl_label_accept_from
) ||
1432 strcmp(af_conf
->acl_label_accept_for
,
1433 xa
->acl_label_accept_for
))
1435 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1436 remove_dynamic_tnbrs
= 1;
1437 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1438 change_egress_label
= 1;
1439 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1440 sizeof(af_conf
->acl_thello_accept_from
));
1441 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1442 sizeof(af_conf
->acl_label_allocate_for
));
1443 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1444 sizeof(af_conf
->acl_label_advertise_to
));
1445 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1446 sizeof(af_conf
->acl_label_advertise_for
));
1447 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1448 sizeof(af_conf
->acl_label_accept_from
));
1449 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1450 sizeof(af_conf
->acl_label_accept_for
));
1451 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1452 sizeof(af_conf
->acl_label_expnull_for
));
1454 /* apply the new configuration */
1455 switch (ldpd_process
) {
1456 case PROC_LDE_ENGINE
:
1457 if (change_egress_label
)
1458 lde_change_egress_label(af
);
1459 if (change_host_label
)
1460 lde_change_allocate_filter(af
);
1461 if (change_ldp_disabled
)
1462 lde_route_update_release_all(af
);
1465 case PROC_LDP_ENGINE
:
1466 if (stop_init_backoff
)
1467 ldpe_stop_init_backoff(af
);
1468 if (remove_dynamic_tnbrs
)
1469 ldpe_remove_dynamic_tnbrs(af
);
1471 ldpe_reset_nbrs(AF_UNSPEC
);
1472 else if (reset_nbrs_ipv4
)
1473 ldpe_reset_nbrs(AF_INET
);
1476 if (update_sockets
&& iev_ldpe
)
1477 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1484 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1486 struct iface
*iface
, *itmp
, *xi
;
1488 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1489 /* find deleted interfaces, which occurs when LDP is removed
1490 * for all address families
1492 if (if_lookup_name(xconf
, iface
->name
) == NULL
) {
1493 switch (ldpd_process
) {
1494 case PROC_LDP_ENGINE
:
1495 ldpe_if_exit(iface
);
1497 case PROC_LDE_ENGINE
:
1498 if (iface
->ipv4
.enabled
)
1499 lde_route_update_release(iface
,
1501 if (iface
->ipv6
.enabled
)
1502 lde_route_update_release(iface
,
1508 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1512 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1513 /* find new interfaces */
1514 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1516 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1518 switch (ldpd_process
) {
1519 case PROC_LDP_ENGINE
:
1520 ldpe_if_init(iface
);
1522 case PROC_LDE_ENGINE
:
1525 /* resend addresses to activate new interfaces */
1526 kif_redistribute(iface
->name
);
1532 /* update labels when adding or removing ldp on an
1535 if (ldpd_process
== PROC_LDE_ENGINE
) {
1536 /* if we are removing lpd config for an address
1537 * family on an interface then advertise routes
1538 * learned over this interface as if they were
1541 if (iface
->ipv4
.enabled
&& !xi
->ipv4
.enabled
)
1542 lde_route_update_release(iface
, AF_INET
);
1543 if (iface
->ipv6
.enabled
&& !xi
->ipv6
.enabled
)
1544 lde_route_update_release(iface
, AF_INET6
);
1546 /* if we are adding lpd config for an address
1547 * family on an interface then add proper labels
1549 if (!iface
->ipv4
.enabled
&& xi
->ipv4
.enabled
)
1550 lde_route_update(iface
, AF_INET
);
1551 if (!iface
->ipv6
.enabled
&& xi
->ipv6
.enabled
)
1552 lde_route_update(iface
, AF_INET6
);
1555 /* update existing interfaces */
1556 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1557 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1562 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1564 if (ia
->enabled
!= xi
->enabled
) {
1565 ia
->enabled
= xi
->enabled
;
1566 if (ldpd_process
== PROC_LDP_ENGINE
)
1567 ldp_if_update(ia
->iface
, ia
->af
);
1569 ia
->hello_holdtime
= xi
->hello_holdtime
;
1570 ia
->hello_interval
= xi
->hello_interval
;
1574 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1576 struct tnbr
*tnbr
, *ttmp
, *xt
;
1578 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1579 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1582 /* find deleted tnbrs */
1583 if (tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
) == NULL
) {
1584 switch (ldpd_process
) {
1585 case PROC_LDP_ENGINE
:
1586 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1587 tnbr_check(conf
, tnbr
);
1589 case PROC_LDE_ENGINE
:
1591 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1597 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1598 /* find new tnbrs */
1599 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1601 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1603 switch (ldpd_process
) {
1604 case PROC_LDP_ENGINE
:
1607 case PROC_LDE_ENGINE
:
1614 /* update existing tnbrs */
1615 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1616 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1621 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1623 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1627 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1628 /* find deleted nbrps */
1629 if (nbr_params_find(xconf
, nbrp
->lsr_id
) != NULL
)
1632 switch (ldpd_process
) {
1633 case PROC_LDP_ENGINE
:
1634 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1636 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1641 (ldp_af_global_get(&global
, nbr
->af
))
1642 ->ldp_session_socket
,
1643 nbr
->af
, &nbr
->raddr
, NULL
);
1645 nbr
->auth
.method
= AUTH_NONE
;
1646 if (nbr_session_active_role(nbr
))
1647 nbr_establish_connection(nbr
);
1650 case PROC_LDE_ENGINE
:
1654 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1658 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1659 /* find new nbrps */
1660 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1662 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1664 switch (ldpd_process
) {
1665 case PROC_LDP_ENGINE
:
1666 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1668 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1669 nbr
->auth
.method
= nbrp
->auth
.method
;
1671 if (pfkey_establish(nbr
, nbrp
) == -1)
1672 fatalx("pfkey setup failed");
1675 (ldp_af_global_get(&global
,
1676 nbr
->af
))->ldp_session_socket
,
1677 nbr
->af
, &nbr
->raddr
,
1680 if (nbr_session_active_role(nbr
))
1681 nbr_establish_connection(nbr
);
1684 case PROC_LDE_ENGINE
:
1691 /* update existing nbrps */
1692 if (nbrp
->flags
!= xn
->flags
||
1693 nbrp
->keepalive
!= xn
->keepalive
||
1694 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1695 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1696 nbrp
->auth
.method
!= xn
->auth
.method
||
1697 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
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 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1707 sizeof(nbrp
->auth
.md5key
));
1708 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1709 nbrp
->flags
= xn
->flags
;
1711 if (ldpd_process
== PROC_LDP_ENGINE
) {
1712 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1713 if (nbr
&& nbrp_changed
) {
1714 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1717 nbr
->auth
.method
= nbrp
->auth
.method
;
1718 if (pfkey_establish(nbr
, nbrp
) == -1)
1719 fatalx("pfkey setup failed");
1721 nbr
->auth
.method
= nbrp
->auth
.method
;
1722 sock_set_md5sig((ldp_af_global_get(&global
,
1723 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1724 &nbr
->raddr
, nbrp
->auth
.md5key
);
1726 if (nbr_session_active_role(nbr
))
1727 nbr_establish_connection(nbr
);
1734 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1736 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1738 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1739 /* find deleted l2vpns */
1740 if (l2vpn_find(xconf
, l2vpn
->name
) == NULL
) {
1741 switch (ldpd_process
) {
1742 case PROC_LDE_ENGINE
:
1745 case PROC_LDP_ENGINE
:
1746 ldpe_l2vpn_exit(l2vpn
);
1751 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1755 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1756 /* find new l2vpns */
1757 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1759 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1760 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1761 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1762 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1764 switch (ldpd_process
) {
1765 case PROC_LDE_ENGINE
:
1768 case PROC_LDP_ENGINE
:
1769 ldpe_l2vpn_init(l2vpn
);
1776 /* update existing l2vpns */
1777 merge_l2vpn(conf
, l2vpn
, xl
);
1782 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1784 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1785 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1787 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1788 int previous_pw_type
, previous_mtu
;
1790 previous_pw_type
= l2vpn
->pw_type
;
1791 previous_mtu
= l2vpn
->mtu
;
1793 /* merge interfaces */
1794 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1795 /* find deleted interfaces */
1796 if (l2vpn_if_find(xl
, lif
->ifname
) == NULL
) {
1797 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1801 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1802 /* find new interfaces */
1803 if (l2vpn_if_find(l2vpn
, xf
->ifname
) == NULL
) {
1805 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1808 switch (ldpd_process
) {
1809 case PROC_LDP_ENGINE
:
1810 case PROC_LDE_ENGINE
:
1813 kif_redistribute(lif
->ifname
);
1819 /* merge active pseudowires */
1820 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1821 /* find deleted active pseudowires */
1822 if (l2vpn_pw_find_active(xl
, pw
->ifname
) == NULL
) {
1823 switch (ldpd_process
) {
1824 case PROC_LDE_ENGINE
:
1827 case PROC_LDP_ENGINE
:
1828 ldpe_l2vpn_pw_exit(pw
);
1834 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1838 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1839 /* find new active pseudowires */
1840 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1842 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1845 switch (ldpd_process
) {
1846 case PROC_LDE_ENGINE
:
1849 case PROC_LDP_ENGINE
:
1850 ldpe_l2vpn_pw_init(pw
);
1853 kif_redistribute(pw
->ifname
);
1859 /* update existing active pseudowire */
1860 if (pw
->af
!= xp
->af
||
1861 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1866 /* changes that require a session restart */
1867 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1868 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1873 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1874 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1875 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1876 reinstall_pwfec
= 1;
1878 reinstall_pwfec
= 0;
1880 if (ldpd_process
== PROC_LDP_ENGINE
) {
1882 ldpe_l2vpn_pw_exit(pw
);
1884 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1885 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1886 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1889 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1891 pw
->lsr_id
= xp
->lsr_id
;
1893 pw
->addr
= xp
->addr
;
1894 pw
->pwid
= xp
->pwid
;
1895 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1896 pw
->ifindex
= xp
->ifindex
;
1897 if (xp
->flags
& F_PW_CWORD_CONF
)
1898 pw
->flags
|= F_PW_CWORD_CONF
;
1900 pw
->flags
&= ~F_PW_CWORD_CONF
;
1901 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1902 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1904 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1905 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1906 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1908 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1909 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1910 ldpe_l2vpn_pw_init(pw
);
1911 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1912 l2vpn
->pw_type
= xl
->pw_type
;
1913 l2vpn
->mtu
= xl
->mtu
;
1915 l2vpn
->pw_type
= previous_pw_type
;
1916 l2vpn
->mtu
= previous_mtu
;
1920 /* merge inactive pseudowires */
1921 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1922 /* find deleted inactive pseudowires */
1923 if (l2vpn_pw_find_inactive(xl
, pw
->ifname
) == NULL
) {
1924 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1928 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1929 /* find new inactive pseudowires */
1930 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1932 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1935 switch (ldpd_process
) {
1936 case PROC_LDE_ENGINE
:
1937 case PROC_LDP_ENGINE
:
1940 kif_redistribute(pw
->ifname
);
1946 /* update existing inactive pseudowire */
1947 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1949 pw
->addr
= xp
->addr
;
1950 pw
->pwid
= xp
->pwid
;
1951 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1952 pw
->ifindex
= xp
->ifindex
;
1953 pw
->flags
= xp
->flags
;
1956 l2vpn
->pw_type
= xl
->pw_type
;
1957 l2vpn
->mtu
= xl
->mtu
;
1958 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1959 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1963 config_new_empty(void)
1965 struct ldpd_conf
*xconf
;
1967 xconf
= calloc(1, sizeof(*xconf
));
1971 RB_INIT(iface_head
, &xconf
->iface_tree
);
1972 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1973 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1974 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1976 /* set default values */
1977 ldp_config_reset(xconf
);
1983 config_clear(struct ldpd_conf
*conf
)
1985 struct ldpd_conf
*xconf
;
1988 * Merge current config with an empty config, this will deactivate
1989 * and deallocate all the interfaces, pseudowires and so on. Before
1990 * merging, copy the router-id and other variables to avoid some
1991 * unnecessary operations, like trying to reset the neighborships.
1993 xconf
= config_new_empty();
1994 xconf
->ipv4
= conf
->ipv4
;
1995 xconf
->ipv6
= conf
->ipv6
;
1996 xconf
->rtr_id
= conf
->rtr_id
;
1997 xconf
->trans_pref
= conf
->trans_pref
;
1998 xconf
->flags
= conf
->flags
;
1999 merge_config(conf
, xconf
);