4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
6 * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include "ldp_debug.h"
32 #include <lib/version.h>
45 #include "lib_errors.h"
47 static void ldpd_shutdown(void);
48 static pid_t
start_child(enum ldpd_process
, char *, int, int);
49 static int main_dispatch_ldpe(struct thread
*);
50 static int main_dispatch_lde(struct thread
*);
51 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
53 static void main_imsg_send_net_sockets(int);
54 static void main_imsg_send_net_socket(int, enum socket_type
);
55 static int main_imsg_send_config(struct ldpd_conf
*);
56 static void ldp_config_normalize(struct ldpd_conf
*);
57 static void ldp_config_reset(struct ldpd_conf
*);
58 static void ldp_config_reset_main(struct ldpd_conf
*);
59 static void ldp_config_reset_af(struct ldpd_conf
*, int);
60 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
61 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
62 static void merge_af(int, struct ldpd_af_conf
*,
63 struct ldpd_af_conf
*);
64 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
65 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
66 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
67 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
68 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
69 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
72 DEFINE_QOBJ_TYPE(iface
)
73 DEFINE_QOBJ_TYPE(tnbr
)
74 DEFINE_QOBJ_TYPE(nbr_params
)
75 DEFINE_QOBJ_TYPE(l2vpn_if
)
76 DEFINE_QOBJ_TYPE(l2vpn_pw
)
77 DEFINE_QOBJ_TYPE(l2vpn
)
78 DEFINE_QOBJ_TYPE(ldpd_conf
)
80 struct ldpd_global global
;
81 struct ldpd_init init
;
82 struct ldpd_conf
*ldpd_conf
, *vty_conf
;
84 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
85 static struct imsgev
*iev_lde
, *iev_lde_sync
;
86 static pid_t ldpe_pid
;
89 #define LDP_DEFAULT_CONFIG "ldpd.conf"
90 #define LDP_VTY_PORT 2612
92 /* Master of threads. */
93 struct thread_master
*master
;
95 static struct frr_daemon_info ldpd_di
;
98 static zebra_capabilities_t _caps_p
[] =
104 struct zebra_privs_t ldpd_privs
=
106 #if defined(FRR_USER) && defined(FRR_GROUP)
110 #if defined(VTY_GROUP)
111 .vty_group
= VTY_GROUP
,
114 .cap_num_p
= array_size(_caps_p
),
118 /* CTL Socket path */
119 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
122 #define OPTION_CTLSOCK 1001
123 static struct option longopts
[] =
125 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
126 { "instance", required_argument
, NULL
, 'n'},
130 /* SIGHUP handler. */
134 log_info("SIGHUP received");
137 * Do a full configuration reload. In other words, reset vty_conf
138 * and build a new configuartion from scratch.
140 ldp_config_reset(vty_conf
);
141 vty_read_config(ldpd_di
.config_file
, config_default
);
142 ldp_config_apply(NULL
, vty_conf
);
145 /* SIGINT / SIGTERM handler. */
149 log_info("SIGINT received");
153 /* SIGUSR1 handler. */
160 static struct quagga_signal_t ldp_signals
[] =
180 FRR_DAEMON_INFO(ldpd
, LDP
,
181 .vty_port
= LDP_VTY_PORT
,
183 .proghelp
= "Implementation of the LDP protocol.",
185 .signals
= ldp_signals
,
186 .n_signals
= array_size(ldp_signals
),
188 .privs
= &ldpd_privs
,
191 static int ldp_config_fork_apply(struct thread
*t
)
194 * So the frr_config_fork() function schedules
195 * the read of the vty config( if there is a
196 * non-integrated config ) to be after the
197 * end of startup and we are starting the
198 * main process loop. We need to schedule
199 * the application of this if necessary
200 * after the read in of the config.
202 ldp_config_apply(NULL
, vty_conf
);
208 main(int argc
, char *argv
[])
211 int lflag
= 0, eflag
= 0;
212 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
213 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
215 struct thread
*thread
= NULL
;
217 ldpd_process
= PROC_MAIN
;
218 log_procname
= log_procnames
[ldpd_process
];
220 saved_argv0
= argv
[0];
221 if (saved_argv0
== NULL
)
222 saved_argv0
= (char *)"ldpd";
224 frr_preinit(&ldpd_di
, argc
, argv
);
225 frr_opt_add("LEn:", longopts
,
226 " --ctl_socket Override ctl socket path\n"
227 " -n, --instance Instance id\n");
232 opt
= frr_getopt(argc
, argv
, NULL
);
241 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
247 * LDPD_SOCKET configured as relative path
248 * during config? Should really never happen for
251 ctl_sock_name
= (char *)LDPD_SOCKET
;
252 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
253 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
254 strlcat(ctl_sock_path
, ctl_sock_name
,
255 sizeof(ctl_sock_path
));
258 init
.instance
= atoi(optarg
);
259 if (init
.instance
< 1)
274 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
275 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
276 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
277 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
278 sizeof(init
.zclient_serv_path
));
281 if (argc
> 0 || (lflag
&& eflag
))
284 /* check for root privileges */
285 if (geteuid() != 0) {
287 perror(ldpd_di
.progname
);
292 openzlog(ldpd_di
.progname
, "LDP", 0,
293 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
299 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
301 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
302 pipe_parent2ldpe_sync
) == -1)
304 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
306 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
307 pipe_parent2lde_sync
) == -1)
309 sock_set_nonblock(pipe_parent2ldpe
[0]);
310 sock_set_cloexec(pipe_parent2ldpe
[0]);
311 sock_set_nonblock(pipe_parent2ldpe
[1]);
312 sock_set_cloexec(pipe_parent2ldpe
[1]);
313 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
314 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
315 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
316 sock_set_nonblock(pipe_parent2lde
[0]);
317 sock_set_cloexec(pipe_parent2lde
[0]);
318 sock_set_nonblock(pipe_parent2lde
[1]);
319 sock_set_cloexec(pipe_parent2lde
[1]);
320 sock_set_nonblock(pipe_parent2lde_sync
[0]);
321 sock_set_cloexec(pipe_parent2lde_sync
[0]);
322 sock_set_cloexec(pipe_parent2lde_sync
[1]);
325 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
326 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
327 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
328 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
332 vty_config_lockless();
333 vrf_init(NULL
, NULL
, NULL
, NULL
, NULL
);
336 ldp_zebra_init(master
);
339 * Create base configuration with sane defaults. All configuration
340 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
341 * to merge the changes into ldpd_conf, which contains the actual
342 * running configuration.
344 ldpd_conf
= config_new_empty();
345 vty_conf
= config_new_empty();
346 QOBJ_REG(vty_conf
, ldpd_conf
);
348 /* read configuration file and daemonize */
351 /* apply configuration */
352 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
354 /* setup pipes to children */
355 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
356 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
357 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
358 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
360 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
361 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
362 iev_ldpe
->ev_read
= NULL
;
363 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
365 iev_ldpe
->handler_write
= ldp_write_handler
;
367 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
368 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
369 iev_ldpe_sync
->ev_read
= NULL
;
370 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
371 &iev_ldpe_sync
->ev_read
);
372 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
374 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
375 iev_lde
->handler_read
= main_dispatch_lde
;
376 iev_lde
->ev_read
= NULL
;
377 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
379 iev_lde
->handler_write
= ldp_write_handler
;
381 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
382 iev_lde_sync
->handler_read
= main_dispatch_lde
;
383 iev_lde_sync
->ev_read
= NULL
;
384 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
385 &iev_lde_sync
->ev_read
);
386 iev_lde_sync
->handler_write
= ldp_write_handler
;
388 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
389 fatal("could not establish imsg links");
390 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
392 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
393 main_imsg_send_config(ldpd_conf
);
395 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
396 main_imsg_send_net_sockets(AF_INET
);
397 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
398 main_imsg_send_net_sockets(AF_INET6
);
415 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
416 close(iev_ldpe
->ibuf
.fd
);
417 msgbuf_clear(&iev_lde
->ibuf
.w
);
418 close(iev_lde
->ibuf
.fd
);
420 config_clear(ldpd_conf
);
422 ldp_config_reset(vty_conf
);
423 QOBJ_UNREG(vty_conf
);
426 log_debug("waiting for children to terminate");
429 /* Wait for child process. */
432 /* We got interrupted, try again. */
435 /* No more processes were found. */
439 /* Unhandled errno condition. */
444 /* We found something, lets announce it. */
445 if (WIFSIGNALED(status
))
446 log_warnx("%s terminated; signal %d",
447 (pid
== lde_pid
? "label decision engine"
451 /* Repeat until there are no more child processes. */
457 log_info("terminating");
468 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
471 int argc
= 0, nullfd
;
474 switch (pid
= fork()) {
476 fatal("cannot fork");
485 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
487 flog_err_sys(EC_LIB_SYSTEM_CALL
,
488 "%s: failed to open /dev/null: %s", __func__
,
489 safe_strerror(errno
));
497 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
498 fatal("cannot setup imsg async fd");
499 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
500 fatal("cannot setup imsg sync fd");
502 argv
[argc
++] = argv0
;
505 fatalx("Can not start main process");
506 case PROC_LDE_ENGINE
:
507 argv
[argc
++] = (char *)"-L";
509 case PROC_LDP_ENGINE
:
510 argv
[argc
++] = (char *)"-E";
522 main_dispatch_ldpe(struct thread
*thread
)
524 struct imsgev
*iev
= THREAD_ARG(thread
);
525 struct imsgbuf
*ibuf
= &iev
->ibuf
;
533 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
534 fatal("imsg_read error");
535 if (n
== 0) /* connection closed */
539 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
545 switch (imsg
.hdr
.type
) {
547 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
549 case IMSG_REQUEST_SOCKETS
:
551 main_imsg_send_net_sockets(af
);
554 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
555 sizeof(struct acl_check
))
556 fatalx("IMSG_ACL_CHECK imsg with wrong len");
557 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
560 log_debug("%s: error handling imsg %d", __func__
,
569 /* this pipe is dead, so remove the event handlers and exit */
570 THREAD_READ_OFF(iev
->ev_read
);
571 THREAD_WRITE_OFF(iev
->ev_write
);
576 kill(lde_pid
, SIGTERM
);
584 main_dispatch_lde(struct thread
*thread
)
586 struct imsgev
*iev
= THREAD_ARG(thread
);
587 struct imsgbuf
*ibuf
= &iev
->ibuf
;
594 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
595 fatal("imsg_read error");
596 if (n
== 0) /* connection closed */
600 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
606 switch (imsg
.hdr
.type
) {
608 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
610 case IMSG_KLABEL_CHANGE
:
611 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
612 sizeof(struct kroute
))
613 fatalx("invalid size of IMSG_KLABEL_CHANGE");
614 if (kr_change(imsg
.data
))
615 log_warnx("%s: error changing route", __func__
);
617 case IMSG_KLABEL_DELETE
:
618 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
619 sizeof(struct kroute
))
620 fatalx("invalid size of IMSG_KLABEL_DELETE");
621 if (kr_delete(imsg
.data
))
622 log_warnx("%s: error deleting route", __func__
);
625 case IMSG_KPW_DELETE
:
628 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
629 sizeof(struct zapi_pw
))
630 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
632 switch (imsg
.hdr
.type
) {
634 if (kmpw_add(imsg
.data
))
635 log_warnx("%s: error adding "
636 "pseudowire", __func__
);
638 case IMSG_KPW_DELETE
:
639 if (kmpw_del(imsg
.data
))
640 log_warnx("%s: error deleting "
641 "pseudowire", __func__
);
644 if (kmpw_set(imsg
.data
))
645 log_warnx("%s: error setting "
646 "pseudowire", __func__
);
649 if (kmpw_unset(imsg
.data
))
650 log_warnx("%s: error unsetting "
651 "pseudowire", __func__
);
656 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
657 sizeof(struct acl_check
))
658 fatalx("IMSG_ACL_CHECK imsg with wrong len");
659 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
662 log_debug("%s: error handling imsg %d", __func__
,
671 /* this pipe is dead, so remove the event handlers and exit */
672 THREAD_READ_OFF(iev
->ev_read
);
673 THREAD_WRITE_OFF(iev
->ev_write
);
678 kill(ldpe_pid
, SIGTERM
);
686 ldp_write_handler(struct thread
*thread
)
688 struct imsgev
*iev
= THREAD_ARG(thread
);
689 struct imsgbuf
*ibuf
= &iev
->ibuf
;
692 iev
->ev_write
= NULL
;
694 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
695 fatal("msgbuf_write");
697 /* this pipe is dead, so remove the event handlers */
698 THREAD_READ_OFF(iev
->ev_read
);
699 THREAD_WRITE_OFF(iev
->ev_write
);
709 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
711 if (iev_ldpe
== NULL
)
713 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
717 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
719 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
723 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
725 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
727 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
729 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
735 imsg_event_add(struct imsgev
*iev
)
737 if (iev
->handler_read
)
738 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
741 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
742 thread_add_write(master
, iev
->handler_write
, iev
,
743 iev
->ibuf
.fd
, &iev
->ev_write
);
747 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
748 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
752 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
753 pid
, fd
, data
, datalen
)) != -1)
759 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
761 ibuf_close(&eb
->wbuf
, buf
);
766 evbuf_event_add(struct evbuf
*eb
)
769 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
774 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
777 msgbuf_init(&eb
->wbuf
);
779 eb
->handler
= handler
;
784 evbuf_clear(struct evbuf
*eb
)
786 THREAD_WRITE_OFF(eb
->ev
);
787 msgbuf_clear(&eb
->wbuf
);
792 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
794 int pipe_ldpe2lde
[2];
796 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
798 sock_set_nonblock(pipe_ldpe2lde
[0]);
799 sock_set_nonblock(pipe_ldpe2lde
[1]);
801 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
804 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
812 main_imsg_send_net_sockets(int af
)
814 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
817 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
818 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
819 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
820 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
824 main_imsg_send_net_socket(int af
, enum socket_type type
)
828 fd
= ldp_create_socket(af
, type
);
830 log_warnx("%s: failed to create %s socket for address-family "
831 "%s", __func__
, socket_name(type
), af_name(af
));
835 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
840 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
841 union ldpd_addr
*addr
, uint8_t prefixlen
)
845 struct acl_check acl_check
;
847 if (acl_name
[0] == '\0')
848 return FILTER_PERMIT
;
851 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
853 acl_check
.addr
= *addr
;
854 acl_check
.prefixlen
= prefixlen
;
856 /* send (blocking) */
857 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
859 imsg_flush(&iev
->ibuf
);
861 /* receive (blocking) and parse result */
862 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
863 fatal("imsg_read error");
864 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
866 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
867 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
868 fatalx("ldp_acl_request: invalid response");
870 return (*((int *)imsg
.data
));
874 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
876 struct access_list
*alist
;
877 struct prefix prefix
;
880 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
882 result
= FILTER_DENY
;
884 prefix
.family
= acl_check
->af
;
885 switch (prefix
.family
) {
887 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
890 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
893 fatalx("ldp_acl_reply: unknown af");
895 prefix
.prefixlen
= acl_check
->prefixlen
;
896 result
= access_list_apply(alist
, &prefix
);
899 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
903 struct ldpd_af_conf
*
904 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
908 return (&xconf
->ipv4
);
910 return (&xconf
->ipv6
);
912 fatalx("ldp_af_conf_get: unknown af");
916 struct ldpd_af_global
*
917 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
921 return (&xglobal
->ipv4
);
923 return (&xglobal
->ipv6
);
925 fatalx("ldp_af_global_get: unknown af");
930 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
932 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
933 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
937 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
939 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
940 return (xconf
->rtr_id
.s_addr
);
942 return (global
.rtr_id
.s_addr
);
946 main_imsg_send_config(struct ldpd_conf
*xconf
)
950 struct nbr_params
*nbrp
;
952 struct l2vpn_if
*lif
;
955 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
956 sizeof(*xconf
)) == -1)
959 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
960 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
961 sizeof(*iface
)) == -1)
965 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
966 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
967 sizeof(*tnbr
)) == -1)
971 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
972 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
973 sizeof(*nbrp
)) == -1)
977 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
978 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
979 sizeof(*l2vpn
)) == -1)
982 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
983 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
987 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
988 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
992 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
993 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
999 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1006 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1009 * When reading from a configuration file (startup and sighup), we
1010 * call merge_config() only once after the whole config has been read.
1011 * This is the optimal and least disruptive way to update the running
1014 if (vty
&& vty
->type
== VTY_FILE
)
1017 ldp_config_normalize(xconf
);
1019 if (main_imsg_send_config(xconf
) == -1)
1022 merge_config(ldpd_conf
, xconf
);
1028 ldp_config_normalize(struct ldpd_conf
*xconf
)
1030 struct iface
*iface
, *itmp
;
1031 struct nbr_params
*nbrp
, *ntmp
;
1032 struct l2vpn
*l2vpn
;
1033 struct l2vpn_pw
*pw
, *ptmp
;
1035 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1036 ldp_config_reset_main(xconf
);
1038 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1039 ldp_config_reset_af(xconf
, AF_INET
);
1040 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1041 ldp_config_reset_af(xconf
, AF_INET6
);
1043 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1044 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1048 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1052 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1053 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1055 if (nbrp
->auth
.method
!= AUTH_NONE
)
1059 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1064 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1065 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1066 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1068 pw
->addr
.v4
= pw
->lsr_id
;
1071 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1073 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1074 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1076 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1078 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1080 pw
->addr
.v4
= pw
->lsr_id
;
1083 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1085 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1086 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1092 ldp_config_reset(struct ldpd_conf
*conf
)
1094 ldp_config_reset_main(conf
);
1095 ldp_config_reset_l2vpns(conf
);
1099 ldp_config_reset_main(struct ldpd_conf
*conf
)
1101 struct iface
*iface
;
1102 struct nbr_params
*nbrp
;
1104 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1105 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1108 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1112 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1113 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1116 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1120 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1121 ldp_config_reset_af(conf
, AF_INET
);
1122 ldp_config_reset_af(conf
, AF_INET6
);
1123 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1124 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1125 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1126 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1127 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1132 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1134 struct ldpd_af_conf
*af_conf
;
1135 struct iface
*iface
;
1136 struct iface_af
*ia
;
1137 struct tnbr
*tnbr
, *ttmp
;
1139 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1140 ia
= iface_af_get(iface
, af
);
1144 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1149 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1153 af_conf
= ldp_af_conf_get(conf
, af
);
1154 af_conf
->keepalive
= 180;
1155 af_conf
->lhello_holdtime
= 0;
1156 af_conf
->lhello_interval
= 0;
1157 af_conf
->thello_holdtime
= 0;
1158 af_conf
->thello_interval
= 0;
1159 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1164 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1166 struct l2vpn
*l2vpn
;
1167 struct l2vpn_if
*lif
;
1168 struct l2vpn_pw
*pw
;
1170 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1171 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1172 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1173 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1176 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1179 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1180 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1183 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1186 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1187 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1190 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1194 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1200 ldp_clear_config(struct ldpd_conf
*xconf
)
1202 struct iface
*iface
;
1204 struct nbr_params
*nbrp
;
1205 struct l2vpn
*l2vpn
;
1207 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1208 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1210 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1213 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1214 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1216 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1219 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1220 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1222 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1225 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1226 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1228 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1235 #define COPY(a, b) do { \
1236 a = malloc(sizeof(*a)); \
1243 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1245 merge_global(conf
, xconf
);
1246 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1247 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1248 merge_ifaces(conf
, xconf
);
1249 merge_tnbrs(conf
, xconf
);
1250 merge_nbrps(conf
, xconf
);
1251 merge_l2vpns(conf
, xconf
);
1255 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1257 /* change of router-id requires resetting all neighborships */
1258 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1259 if (ldpd_process
== PROC_LDP_ENGINE
) {
1260 ldpe_reset_nbrs(AF_UNSPEC
);
1261 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1262 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1263 if_update_all(AF_UNSPEC
);
1264 tnbr_update_all(AF_UNSPEC
);
1267 conf
->rtr_id
= xconf
->rtr_id
;
1270 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1271 conf
->lhello_interval
= xconf
->lhello_interval
;
1272 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1273 conf
->thello_interval
= xconf
->thello_interval
;
1275 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1276 if (ldpd_process
== PROC_LDP_ENGINE
)
1277 ldpe_reset_ds_nbrs();
1278 conf
->trans_pref
= xconf
->trans_pref
;
1281 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1282 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1283 if (ldpd_process
== PROC_LDP_ENGINE
)
1284 ldpe_reset_ds_nbrs();
1287 conf
->flags
= xconf
->flags
;
1291 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1293 int stop_init_backoff
= 0;
1294 int remove_dynamic_tnbrs
= 0;
1295 int change_egress_label
= 0;
1296 int reset_nbrs_ipv4
= 0;
1298 int update_sockets
= 0;
1301 if (af_conf
->keepalive
!= xa
->keepalive
) {
1302 af_conf
->keepalive
= xa
->keepalive
;
1303 stop_init_backoff
= 1;
1305 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1306 af_conf
->lhello_interval
= xa
->lhello_interval
;
1307 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1308 af_conf
->thello_interval
= xa
->thello_interval
;
1311 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1312 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1313 remove_dynamic_tnbrs
= 1;
1314 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1315 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1317 /* need to set/unset IPV6_MINHOPCOUNT */
1320 /* for LDPv4 just resetting the neighbors is enough */
1321 reset_nbrs_ipv4
= 1;
1323 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1324 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1325 change_egress_label
= 1;
1326 af_conf
->flags
= xa
->flags
;
1328 /* update the transport address */
1329 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1330 af_conf
->trans_addr
= xa
->trans_addr
;
1335 if (strcmp(af_conf
->acl_label_advertise_to
,
1336 xa
->acl_label_advertise_to
) ||
1337 strcmp(af_conf
->acl_label_advertise_for
,
1338 xa
->acl_label_advertise_for
) ||
1339 strcmp(af_conf
->acl_label_accept_from
,
1340 xa
->acl_label_accept_from
) ||
1341 strcmp(af_conf
->acl_label_accept_for
,
1342 xa
->acl_label_accept_for
))
1344 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1345 remove_dynamic_tnbrs
= 1;
1346 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1347 change_egress_label
= 1;
1348 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1349 sizeof(af_conf
->acl_thello_accept_from
));
1350 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1351 sizeof(af_conf
->acl_label_allocate_for
));
1352 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1353 sizeof(af_conf
->acl_label_advertise_to
));
1354 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1355 sizeof(af_conf
->acl_label_advertise_for
));
1356 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1357 sizeof(af_conf
->acl_label_accept_from
));
1358 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1359 sizeof(af_conf
->acl_label_accept_for
));
1360 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1361 sizeof(af_conf
->acl_label_expnull_for
));
1363 /* apply the new configuration */
1364 switch (ldpd_process
) {
1365 case PROC_LDE_ENGINE
:
1366 if (change_egress_label
)
1367 lde_change_egress_label(af
);
1369 case PROC_LDP_ENGINE
:
1370 if (stop_init_backoff
)
1371 ldpe_stop_init_backoff(af
);
1372 if (remove_dynamic_tnbrs
)
1373 ldpe_remove_dynamic_tnbrs(af
);
1375 ldpe_reset_nbrs(AF_UNSPEC
);
1376 else if (reset_nbrs_ipv4
)
1377 ldpe_reset_nbrs(AF_INET
);
1380 if (update_sockets
&& iev_ldpe
)
1381 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1388 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1390 struct iface
*iface
, *itmp
, *xi
;
1392 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1393 /* find deleted interfaces */
1394 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1395 switch (ldpd_process
) {
1396 case PROC_LDP_ENGINE
:
1397 ldpe_if_exit(iface
);
1399 case PROC_LDE_ENGINE
:
1403 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1407 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1408 /* find new interfaces */
1409 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1411 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1413 switch (ldpd_process
) {
1414 case PROC_LDP_ENGINE
:
1415 ldpe_if_init(iface
);
1417 case PROC_LDE_ENGINE
:
1420 /* resend addresses to activate new interfaces */
1421 kif_redistribute(iface
->name
);
1427 /* update existing interfaces */
1428 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1429 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1434 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1436 if (ia
->enabled
!= xi
->enabled
) {
1437 ia
->enabled
= xi
->enabled
;
1438 if (ldpd_process
== PROC_LDP_ENGINE
)
1439 ldp_if_update(ia
->iface
, ia
->af
);
1441 ia
->hello_holdtime
= xi
->hello_holdtime
;
1442 ia
->hello_interval
= xi
->hello_interval
;
1446 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1448 struct tnbr
*tnbr
, *ttmp
, *xt
;
1450 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1451 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1454 /* find deleted tnbrs */
1455 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1456 switch (ldpd_process
) {
1457 case PROC_LDP_ENGINE
:
1458 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1459 tnbr_check(conf
, tnbr
);
1461 case PROC_LDE_ENGINE
:
1463 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1469 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1470 /* find new tnbrs */
1471 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1473 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1475 switch (ldpd_process
) {
1476 case PROC_LDP_ENGINE
:
1479 case PROC_LDE_ENGINE
:
1486 /* update existing tnbrs */
1487 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1488 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1493 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1495 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1499 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1500 /* find deleted nbrps */
1501 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1502 switch (ldpd_process
) {
1503 case PROC_LDP_ENGINE
:
1504 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1506 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1511 (ldp_af_global_get(&global
,
1512 nbr
->af
))->ldp_session_socket
,
1513 nbr
->af
, &nbr
->raddr
, NULL
);
1515 nbr
->auth
.method
= AUTH_NONE
;
1516 if (nbr_session_active_role(nbr
))
1517 nbr_establish_connection(nbr
);
1520 case PROC_LDE_ENGINE
:
1524 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1528 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1529 /* find new nbrps */
1530 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1532 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1534 switch (ldpd_process
) {
1535 case PROC_LDP_ENGINE
:
1536 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1538 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1539 nbr
->auth
.method
= nbrp
->auth
.method
;
1541 if (pfkey_establish(nbr
, nbrp
) == -1)
1542 fatalx("pfkey setup failed");
1545 (ldp_af_global_get(&global
,
1546 nbr
->af
))->ldp_session_socket
,
1547 nbr
->af
, &nbr
->raddr
,
1550 if (nbr_session_active_role(nbr
))
1551 nbr_establish_connection(nbr
);
1554 case PROC_LDE_ENGINE
:
1561 /* update existing nbrps */
1562 if (nbrp
->flags
!= xn
->flags
||
1563 nbrp
->keepalive
!= xn
->keepalive
||
1564 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1565 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1566 nbrp
->auth
.method
!= xn
->auth
.method
||
1567 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1572 nbrp
->keepalive
= xn
->keepalive
;
1573 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1574 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1575 nbrp
->auth
.method
= xn
->auth
.method
;
1576 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1577 sizeof(nbrp
->auth
.md5key
));
1578 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1579 nbrp
->flags
= xn
->flags
;
1581 if (ldpd_process
== PROC_LDP_ENGINE
) {
1582 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1583 if (nbr
&& nbrp_changed
) {
1584 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1587 nbr
->auth
.method
= nbrp
->auth
.method
;
1588 if (pfkey_establish(nbr
, nbrp
) == -1)
1589 fatalx("pfkey setup failed");
1591 nbr
->auth
.method
= nbrp
->auth
.method
;
1592 sock_set_md5sig((ldp_af_global_get(&global
,
1593 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1594 &nbr
->raddr
, nbrp
->auth
.md5key
);
1596 if (nbr_session_active_role(nbr
))
1597 nbr_establish_connection(nbr
);
1604 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1606 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1608 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1609 /* find deleted l2vpns */
1610 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1611 switch (ldpd_process
) {
1612 case PROC_LDE_ENGINE
:
1615 case PROC_LDP_ENGINE
:
1616 ldpe_l2vpn_exit(l2vpn
);
1621 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1625 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1626 /* find new l2vpns */
1627 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1629 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1630 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1631 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1632 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1634 switch (ldpd_process
) {
1635 case PROC_LDE_ENGINE
:
1638 case PROC_LDP_ENGINE
:
1639 ldpe_l2vpn_init(l2vpn
);
1646 /* update existing l2vpns */
1647 merge_l2vpn(conf
, l2vpn
, xl
);
1652 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1654 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1655 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1657 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1658 int previous_pw_type
, previous_mtu
;
1660 previous_pw_type
= l2vpn
->pw_type
;
1661 previous_mtu
= l2vpn
->mtu
;
1663 /* merge intefaces */
1664 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1665 /* find deleted interfaces */
1666 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1667 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1671 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1672 /* find new interfaces */
1673 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1675 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1678 switch (ldpd_process
) {
1679 case PROC_LDP_ENGINE
:
1680 case PROC_LDE_ENGINE
:
1683 kif_redistribute(lif
->ifname
);
1689 /* merge active pseudowires */
1690 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1691 /* find deleted active pseudowires */
1692 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1693 switch (ldpd_process
) {
1694 case PROC_LDE_ENGINE
:
1697 case PROC_LDP_ENGINE
:
1698 ldpe_l2vpn_pw_exit(pw
);
1704 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1708 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1709 /* find new active pseudowires */
1710 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1712 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1715 switch (ldpd_process
) {
1716 case PROC_LDE_ENGINE
:
1719 case PROC_LDP_ENGINE
:
1720 ldpe_l2vpn_pw_init(pw
);
1723 kif_redistribute(pw
->ifname
);
1729 /* update existing active pseudowire */
1730 if (pw
->af
!= xp
->af
||
1731 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1736 /* changes that require a session restart */
1737 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1738 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1743 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1744 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1745 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1746 reinstall_pwfec
= 1;
1748 reinstall_pwfec
= 0;
1750 if (ldpd_process
== PROC_LDP_ENGINE
) {
1752 ldpe_l2vpn_pw_exit(pw
);
1754 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1755 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1756 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1759 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1761 pw
->lsr_id
= xp
->lsr_id
;
1763 pw
->addr
= xp
->addr
;
1764 pw
->pwid
= xp
->pwid
;
1765 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1766 pw
->ifindex
= xp
->ifindex
;
1767 if (xp
->flags
& F_PW_CWORD_CONF
)
1768 pw
->flags
|= F_PW_CWORD_CONF
;
1770 pw
->flags
&= ~F_PW_CWORD_CONF
;
1771 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1772 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1774 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1775 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1776 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1778 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1779 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1780 ldpe_l2vpn_pw_init(pw
);
1781 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1782 l2vpn
->pw_type
= xl
->pw_type
;
1783 l2vpn
->mtu
= xl
->mtu
;
1785 l2vpn
->pw_type
= previous_pw_type
;
1786 l2vpn
->mtu
= previous_mtu
;
1790 /* merge inactive pseudowires */
1791 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1792 /* find deleted inactive pseudowires */
1793 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1794 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1798 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1799 /* find new inactive pseudowires */
1800 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1802 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1805 switch (ldpd_process
) {
1806 case PROC_LDE_ENGINE
:
1807 case PROC_LDP_ENGINE
:
1810 kif_redistribute(pw
->ifname
);
1816 /* update existing inactive pseudowire */
1817 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1819 pw
->addr
= xp
->addr
;
1820 pw
->pwid
= xp
->pwid
;
1821 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1822 pw
->ifindex
= xp
->ifindex
;
1823 pw
->flags
= xp
->flags
;
1826 l2vpn
->pw_type
= xl
->pw_type
;
1827 l2vpn
->mtu
= xl
->mtu
;
1828 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1829 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1833 config_new_empty(void)
1835 struct ldpd_conf
*xconf
;
1837 xconf
= calloc(1, sizeof(*xconf
));
1841 RB_INIT(iface_head
, &xconf
->iface_tree
);
1842 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1843 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1844 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1846 /* set default values */
1847 ldp_config_reset(xconf
);
1853 config_clear(struct ldpd_conf
*conf
)
1855 struct ldpd_conf
*xconf
;
1858 * Merge current config with an empty config, this will deactivate
1859 * and deallocate all the interfaces, pseudowires and so on. Before
1860 * merging, copy the router-id and other variables to avoid some
1861 * unnecessary operations, like trying to reset the neighborships.
1863 xconf
= config_new_empty();
1864 xconf
->ipv4
= conf
->ipv4
;
1865 xconf
->ipv6
= conf
->ipv6
;
1866 xconf
->rtr_id
= conf
->rtr_id
;
1867 xconf
->trans_pref
= conf
->trans_pref
;
1868 xconf
->flags
= conf
->flags
;
1869 merge_config(conf
, xconf
);