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(NULL
, 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 static const struct frr_yang_module_info
*ldpd_yang_modules
[] = {
183 FRR_DAEMON_INFO(ldpd
, LDP
,
184 .vty_port
= LDP_VTY_PORT
,
186 .proghelp
= "Implementation of the LDP protocol.",
188 .signals
= ldp_signals
,
189 .n_signals
= array_size(ldp_signals
),
191 .privs
= &ldpd_privs
,
193 .yang_modules
= ldpd_yang_modules
,
194 .n_yang_modules
= array_size(ldpd_yang_modules
),
197 static int ldp_config_fork_apply(struct thread
*t
)
200 * So the frr_config_fork() function schedules
201 * the read of the vty config( if there is a
202 * non-integrated config ) to be after the
203 * end of startup and we are starting the
204 * main process loop. We need to schedule
205 * the application of this if necessary
206 * after the read in of the config.
208 ldp_config_apply(NULL
, vty_conf
);
214 main(int argc
, char *argv
[])
217 int lflag
= 0, eflag
= 0;
218 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
219 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
221 struct thread
*thread
= NULL
;
223 ldpd_process
= PROC_MAIN
;
224 log_procname
= log_procnames
[ldpd_process
];
226 saved_argv0
= argv
[0];
227 if (saved_argv0
== NULL
)
228 saved_argv0
= (char *)"ldpd";
230 frr_preinit(&ldpd_di
, argc
, argv
);
231 frr_opt_add("LEn:", longopts
,
232 " --ctl_socket Override ctl socket path\n"
233 " -n, --instance Instance id\n");
238 opt
= frr_getopt(argc
, argv
, NULL
);
247 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
253 * LDPD_SOCKET configured as relative path
254 * during config? Should really never happen for
257 ctl_sock_name
= (char *)LDPD_SOCKET
;
258 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
259 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
260 strlcat(ctl_sock_path
, ctl_sock_name
,
261 sizeof(ctl_sock_path
));
264 init
.instance
= atoi(optarg
);
265 if (init
.instance
< 1)
280 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
281 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
282 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
283 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
284 sizeof(init
.zclient_serv_path
));
287 if (argc
> 0 || (lflag
&& eflag
))
290 /* check for root privileges */
291 if (geteuid() != 0) {
293 perror(ldpd_di
.progname
);
298 openzlog(ldpd_di
.progname
, "LDP", 0,
299 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
305 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
307 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
308 pipe_parent2ldpe_sync
) == -1)
310 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
312 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
313 pipe_parent2lde_sync
) == -1)
315 sock_set_nonblock(pipe_parent2ldpe
[0]);
316 sock_set_cloexec(pipe_parent2ldpe
[0]);
317 sock_set_nonblock(pipe_parent2ldpe
[1]);
318 sock_set_cloexec(pipe_parent2ldpe
[1]);
319 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
320 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
321 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
322 sock_set_nonblock(pipe_parent2lde
[0]);
323 sock_set_cloexec(pipe_parent2lde
[0]);
324 sock_set_nonblock(pipe_parent2lde
[1]);
325 sock_set_cloexec(pipe_parent2lde
[1]);
326 sock_set_nonblock(pipe_parent2lde_sync
[0]);
327 sock_set_cloexec(pipe_parent2lde_sync
[0]);
328 sock_set_cloexec(pipe_parent2lde_sync
[1]);
331 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
332 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
333 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
334 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
338 vrf_init(NULL
, NULL
, NULL
, NULL
, NULL
);
341 ldp_zebra_init(master
);
344 * Create base configuration with sane defaults. All configuration
345 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
346 * to merge the changes into ldpd_conf, which contains the actual
347 * running configuration.
349 ldpd_conf
= config_new_empty();
350 vty_conf
= config_new_empty();
351 QOBJ_REG(vty_conf
, ldpd_conf
);
353 /* read configuration file and daemonize */
356 /* apply configuration */
357 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
359 /* setup pipes to children */
360 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
361 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
362 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
363 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
365 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
366 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
367 iev_ldpe
->ev_read
= NULL
;
368 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
370 iev_ldpe
->handler_write
= ldp_write_handler
;
372 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
373 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
374 iev_ldpe_sync
->ev_read
= NULL
;
375 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
376 &iev_ldpe_sync
->ev_read
);
377 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
379 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
380 iev_lde
->handler_read
= main_dispatch_lde
;
381 iev_lde
->ev_read
= NULL
;
382 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
384 iev_lde
->handler_write
= ldp_write_handler
;
386 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
387 iev_lde_sync
->handler_read
= main_dispatch_lde
;
388 iev_lde_sync
->ev_read
= NULL
;
389 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
390 &iev_lde_sync
->ev_read
);
391 iev_lde_sync
->handler_write
= ldp_write_handler
;
393 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
394 fatal("could not establish imsg links");
395 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
397 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
398 main_imsg_send_config(ldpd_conf
);
400 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
401 main_imsg_send_net_sockets(AF_INET
);
402 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
403 main_imsg_send_net_sockets(AF_INET6
);
420 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
421 close(iev_ldpe
->ibuf
.fd
);
422 msgbuf_clear(&iev_lde
->ibuf
.w
);
423 close(iev_lde
->ibuf
.fd
);
425 config_clear(ldpd_conf
);
427 ldp_config_reset(vty_conf
);
428 QOBJ_UNREG(vty_conf
);
431 log_debug("waiting for children to terminate");
434 /* Wait for child process. */
437 /* We got interrupted, try again. */
440 /* No more processes were found. */
444 /* Unhandled errno condition. */
449 /* We found something, lets announce it. */
450 if (WIFSIGNALED(status
))
451 log_warnx("%s terminated; signal %d",
452 (pid
== lde_pid
? "label decision engine"
456 /* Repeat until there are no more child processes. */
462 log_info("terminating");
473 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
476 int argc
= 0, nullfd
;
479 switch (pid
= fork()) {
481 fatal("cannot fork");
490 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
492 flog_err_sys(EC_LIB_SYSTEM_CALL
,
493 "%s: failed to open /dev/null: %s", __func__
,
494 safe_strerror(errno
));
502 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
503 fatal("cannot setup imsg async fd");
504 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
505 fatal("cannot setup imsg sync fd");
507 argv
[argc
++] = argv0
;
510 fatalx("Can not start main process");
511 case PROC_LDE_ENGINE
:
512 argv
[argc
++] = (char *)"-L";
514 case PROC_LDP_ENGINE
:
515 argv
[argc
++] = (char *)"-E";
527 main_dispatch_ldpe(struct thread
*thread
)
529 struct imsgev
*iev
= THREAD_ARG(thread
);
530 struct imsgbuf
*ibuf
= &iev
->ibuf
;
538 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
539 fatal("imsg_read error");
540 if (n
== 0) /* connection closed */
544 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
550 switch (imsg
.hdr
.type
) {
552 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
554 case IMSG_REQUEST_SOCKETS
:
556 main_imsg_send_net_sockets(af
);
559 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
560 sizeof(struct acl_check
))
561 fatalx("IMSG_ACL_CHECK imsg with wrong len");
562 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
565 log_debug("%s: error handling imsg %d", __func__
,
574 /* this pipe is dead, so remove the event handlers and exit */
575 THREAD_READ_OFF(iev
->ev_read
);
576 THREAD_WRITE_OFF(iev
->ev_write
);
581 kill(lde_pid
, SIGTERM
);
589 main_dispatch_lde(struct thread
*thread
)
591 struct imsgev
*iev
= THREAD_ARG(thread
);
592 struct imsgbuf
*ibuf
= &iev
->ibuf
;
599 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
600 fatal("imsg_read error");
601 if (n
== 0) /* connection closed */
605 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
611 switch (imsg
.hdr
.type
) {
613 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
615 case IMSG_KLABEL_CHANGE
:
616 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
617 sizeof(struct kroute
))
618 fatalx("invalid size of IMSG_KLABEL_CHANGE");
619 if (kr_change(imsg
.data
))
620 log_warnx("%s: error changing route", __func__
);
622 case IMSG_KLABEL_DELETE
:
623 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
624 sizeof(struct kroute
))
625 fatalx("invalid size of IMSG_KLABEL_DELETE");
626 if (kr_delete(imsg
.data
))
627 log_warnx("%s: error deleting route", __func__
);
630 case IMSG_KPW_DELETE
:
633 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
634 sizeof(struct zapi_pw
))
635 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
637 switch (imsg
.hdr
.type
) {
639 if (kmpw_add(imsg
.data
))
640 log_warnx("%s: error adding "
641 "pseudowire", __func__
);
643 case IMSG_KPW_DELETE
:
644 if (kmpw_del(imsg
.data
))
645 log_warnx("%s: error deleting "
646 "pseudowire", __func__
);
649 if (kmpw_set(imsg
.data
))
650 log_warnx("%s: error setting "
651 "pseudowire", __func__
);
654 if (kmpw_unset(imsg
.data
))
655 log_warnx("%s: error unsetting "
656 "pseudowire", __func__
);
661 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
662 sizeof(struct acl_check
))
663 fatalx("IMSG_ACL_CHECK imsg with wrong len");
664 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
667 log_debug("%s: error handling imsg %d", __func__
,
676 /* this pipe is dead, so remove the event handlers and exit */
677 THREAD_READ_OFF(iev
->ev_read
);
678 THREAD_WRITE_OFF(iev
->ev_write
);
683 kill(ldpe_pid
, SIGTERM
);
691 ldp_write_handler(struct thread
*thread
)
693 struct imsgev
*iev
= THREAD_ARG(thread
);
694 struct imsgbuf
*ibuf
= &iev
->ibuf
;
697 iev
->ev_write
= NULL
;
699 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
700 fatal("msgbuf_write");
702 /* this pipe is dead, so remove the event handlers */
703 THREAD_READ_OFF(iev
->ev_read
);
704 THREAD_WRITE_OFF(iev
->ev_write
);
714 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
716 if (iev_ldpe
== NULL
)
718 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
722 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
724 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
728 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
730 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
732 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
734 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
740 imsg_event_add(struct imsgev
*iev
)
742 if (iev
->handler_read
)
743 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
746 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
747 thread_add_write(master
, iev
->handler_write
, iev
,
748 iev
->ibuf
.fd
, &iev
->ev_write
);
752 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
753 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
757 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
758 pid
, fd
, data
, datalen
)) != -1)
764 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
766 ibuf_close(&eb
->wbuf
, buf
);
771 evbuf_event_add(struct evbuf
*eb
)
774 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
779 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
782 msgbuf_init(&eb
->wbuf
);
784 eb
->handler
= handler
;
789 evbuf_clear(struct evbuf
*eb
)
791 THREAD_WRITE_OFF(eb
->ev
);
792 msgbuf_clear(&eb
->wbuf
);
797 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
799 int pipe_ldpe2lde
[2];
801 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
803 sock_set_nonblock(pipe_ldpe2lde
[0]);
804 sock_set_nonblock(pipe_ldpe2lde
[1]);
806 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
809 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
817 main_imsg_send_net_sockets(int af
)
819 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
822 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
823 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
824 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
825 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
829 main_imsg_send_net_socket(int af
, enum socket_type type
)
833 fd
= ldp_create_socket(af
, type
);
835 log_warnx("%s: failed to create %s socket for address-family "
836 "%s", __func__
, socket_name(type
), af_name(af
));
840 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
845 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
846 union ldpd_addr
*addr
, uint8_t prefixlen
)
850 struct acl_check acl_check
;
852 if (acl_name
[0] == '\0')
853 return FILTER_PERMIT
;
856 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
858 acl_check
.addr
= *addr
;
859 acl_check
.prefixlen
= prefixlen
;
861 /* send (blocking) */
862 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
864 imsg_flush(&iev
->ibuf
);
866 /* receive (blocking) and parse result */
867 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
868 fatal("imsg_read error");
869 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
871 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
872 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
873 fatalx("ldp_acl_request: invalid response");
875 return (*((int *)imsg
.data
));
879 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
881 struct access_list
*alist
;
882 struct prefix prefix
;
885 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
887 result
= FILTER_DENY
;
889 prefix
.family
= acl_check
->af
;
890 switch (prefix
.family
) {
892 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
895 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
898 fatalx("ldp_acl_reply: unknown af");
900 prefix
.prefixlen
= acl_check
->prefixlen
;
901 result
= access_list_apply(alist
, &prefix
);
904 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
908 struct ldpd_af_conf
*
909 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
913 return (&xconf
->ipv4
);
915 return (&xconf
->ipv6
);
917 fatalx("ldp_af_conf_get: unknown af");
921 struct ldpd_af_global
*
922 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
926 return (&xglobal
->ipv4
);
928 return (&xglobal
->ipv6
);
930 fatalx("ldp_af_global_get: unknown af");
935 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
937 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
938 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
942 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
944 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
945 return (xconf
->rtr_id
.s_addr
);
947 return (global
.rtr_id
.s_addr
);
951 main_imsg_send_config(struct ldpd_conf
*xconf
)
955 struct nbr_params
*nbrp
;
957 struct l2vpn_if
*lif
;
960 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
961 sizeof(*xconf
)) == -1)
964 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
965 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
966 sizeof(*iface
)) == -1)
970 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
971 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
972 sizeof(*tnbr
)) == -1)
976 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
977 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
978 sizeof(*nbrp
)) == -1)
982 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
983 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
984 sizeof(*l2vpn
)) == -1)
987 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
988 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
992 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
993 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
997 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
998 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1004 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1011 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1014 * When reading from a configuration file (startup and sighup), we
1015 * call merge_config() only once after the whole config has been read.
1016 * This is the optimal and least disruptive way to update the running
1019 if (vty
&& vty
->type
== VTY_FILE
)
1022 ldp_config_normalize(xconf
);
1024 if (main_imsg_send_config(xconf
) == -1)
1027 merge_config(ldpd_conf
, xconf
);
1033 ldp_config_normalize(struct ldpd_conf
*xconf
)
1035 struct iface
*iface
, *itmp
;
1036 struct nbr_params
*nbrp
, *ntmp
;
1037 struct l2vpn
*l2vpn
;
1038 struct l2vpn_pw
*pw
, *ptmp
;
1040 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1041 ldp_config_reset_main(xconf
);
1043 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1044 ldp_config_reset_af(xconf
, AF_INET
);
1045 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1046 ldp_config_reset_af(xconf
, AF_INET6
);
1048 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1049 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1053 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1057 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1058 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1060 if (nbrp
->auth
.method
!= AUTH_NONE
)
1064 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1069 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1070 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1071 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1073 pw
->addr
.v4
= pw
->lsr_id
;
1076 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1078 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1079 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1081 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1083 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1085 pw
->addr
.v4
= pw
->lsr_id
;
1088 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1090 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1091 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1097 ldp_config_reset(struct ldpd_conf
*conf
)
1099 ldp_config_reset_main(conf
);
1100 ldp_config_reset_l2vpns(conf
);
1104 ldp_config_reset_main(struct ldpd_conf
*conf
)
1106 struct iface
*iface
;
1107 struct nbr_params
*nbrp
;
1109 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1110 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1113 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1117 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1118 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1121 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1125 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1126 ldp_config_reset_af(conf
, AF_INET
);
1127 ldp_config_reset_af(conf
, AF_INET6
);
1128 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1129 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1130 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1131 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1132 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1137 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1139 struct ldpd_af_conf
*af_conf
;
1140 struct iface
*iface
;
1141 struct iface_af
*ia
;
1142 struct tnbr
*tnbr
, *ttmp
;
1144 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1145 ia
= iface_af_get(iface
, af
);
1149 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1154 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1158 af_conf
= ldp_af_conf_get(conf
, af
);
1159 af_conf
->keepalive
= 180;
1160 af_conf
->lhello_holdtime
= 0;
1161 af_conf
->lhello_interval
= 0;
1162 af_conf
->thello_holdtime
= 0;
1163 af_conf
->thello_interval
= 0;
1164 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1169 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1171 struct l2vpn
*l2vpn
;
1172 struct l2vpn_if
*lif
;
1173 struct l2vpn_pw
*pw
;
1175 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1176 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1177 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1178 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1181 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1184 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1185 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1188 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1191 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1192 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1195 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1199 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1205 ldp_clear_config(struct ldpd_conf
*xconf
)
1207 struct iface
*iface
;
1209 struct nbr_params
*nbrp
;
1210 struct l2vpn
*l2vpn
;
1212 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1213 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1215 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1218 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1219 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1221 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1224 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1225 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1227 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1230 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1231 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1233 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1240 #define COPY(a, b) do { \
1241 a = malloc(sizeof(*a)); \
1248 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1250 merge_global(conf
, xconf
);
1251 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1252 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1253 merge_ifaces(conf
, xconf
);
1254 merge_tnbrs(conf
, xconf
);
1255 merge_nbrps(conf
, xconf
);
1256 merge_l2vpns(conf
, xconf
);
1260 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1262 /* change of router-id requires resetting all neighborships */
1263 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1264 if (ldpd_process
== PROC_LDP_ENGINE
) {
1265 ldpe_reset_nbrs(AF_UNSPEC
);
1266 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1267 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1268 if_update_all(AF_UNSPEC
);
1269 tnbr_update_all(AF_UNSPEC
);
1272 conf
->rtr_id
= xconf
->rtr_id
;
1275 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1276 conf
->lhello_interval
= xconf
->lhello_interval
;
1277 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1278 conf
->thello_interval
= xconf
->thello_interval
;
1280 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1281 if (ldpd_process
== PROC_LDP_ENGINE
)
1282 ldpe_reset_ds_nbrs();
1283 conf
->trans_pref
= xconf
->trans_pref
;
1286 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1287 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1288 if (ldpd_process
== PROC_LDP_ENGINE
)
1289 ldpe_reset_ds_nbrs();
1292 conf
->flags
= xconf
->flags
;
1296 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1298 int stop_init_backoff
= 0;
1299 int remove_dynamic_tnbrs
= 0;
1300 int change_egress_label
= 0;
1301 int reset_nbrs_ipv4
= 0;
1303 int update_sockets
= 0;
1306 if (af_conf
->keepalive
!= xa
->keepalive
) {
1307 af_conf
->keepalive
= xa
->keepalive
;
1308 stop_init_backoff
= 1;
1310 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1311 af_conf
->lhello_interval
= xa
->lhello_interval
;
1312 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1313 af_conf
->thello_interval
= xa
->thello_interval
;
1316 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1317 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1318 remove_dynamic_tnbrs
= 1;
1319 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1320 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1322 /* need to set/unset IPV6_MINHOPCOUNT */
1325 /* for LDPv4 just resetting the neighbors is enough */
1326 reset_nbrs_ipv4
= 1;
1328 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1329 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1330 change_egress_label
= 1;
1331 af_conf
->flags
= xa
->flags
;
1333 /* update the transport address */
1334 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1335 af_conf
->trans_addr
= xa
->trans_addr
;
1340 if (strcmp(af_conf
->acl_label_advertise_to
,
1341 xa
->acl_label_advertise_to
) ||
1342 strcmp(af_conf
->acl_label_advertise_for
,
1343 xa
->acl_label_advertise_for
) ||
1344 strcmp(af_conf
->acl_label_accept_from
,
1345 xa
->acl_label_accept_from
) ||
1346 strcmp(af_conf
->acl_label_accept_for
,
1347 xa
->acl_label_accept_for
))
1349 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1350 remove_dynamic_tnbrs
= 1;
1351 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1352 change_egress_label
= 1;
1353 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1354 sizeof(af_conf
->acl_thello_accept_from
));
1355 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1356 sizeof(af_conf
->acl_label_allocate_for
));
1357 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1358 sizeof(af_conf
->acl_label_advertise_to
));
1359 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1360 sizeof(af_conf
->acl_label_advertise_for
));
1361 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1362 sizeof(af_conf
->acl_label_accept_from
));
1363 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1364 sizeof(af_conf
->acl_label_accept_for
));
1365 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1366 sizeof(af_conf
->acl_label_expnull_for
));
1368 /* apply the new configuration */
1369 switch (ldpd_process
) {
1370 case PROC_LDE_ENGINE
:
1371 if (change_egress_label
)
1372 lde_change_egress_label(af
);
1374 case PROC_LDP_ENGINE
:
1375 if (stop_init_backoff
)
1376 ldpe_stop_init_backoff(af
);
1377 if (remove_dynamic_tnbrs
)
1378 ldpe_remove_dynamic_tnbrs(af
);
1380 ldpe_reset_nbrs(AF_UNSPEC
);
1381 else if (reset_nbrs_ipv4
)
1382 ldpe_reset_nbrs(AF_INET
);
1385 if (update_sockets
&& iev_ldpe
)
1386 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1393 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1395 struct iface
*iface
, *itmp
, *xi
;
1397 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1398 /* find deleted interfaces */
1399 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1400 switch (ldpd_process
) {
1401 case PROC_LDP_ENGINE
:
1402 ldpe_if_exit(iface
);
1404 case PROC_LDE_ENGINE
:
1408 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1412 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1413 /* find new interfaces */
1414 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1416 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1418 switch (ldpd_process
) {
1419 case PROC_LDP_ENGINE
:
1420 ldpe_if_init(iface
);
1422 case PROC_LDE_ENGINE
:
1425 /* resend addresses to activate new interfaces */
1426 kif_redistribute(iface
->name
);
1432 /* update existing interfaces */
1433 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1434 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1439 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1441 if (ia
->enabled
!= xi
->enabled
) {
1442 ia
->enabled
= xi
->enabled
;
1443 if (ldpd_process
== PROC_LDP_ENGINE
)
1444 ldp_if_update(ia
->iface
, ia
->af
);
1446 ia
->hello_holdtime
= xi
->hello_holdtime
;
1447 ia
->hello_interval
= xi
->hello_interval
;
1451 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1453 struct tnbr
*tnbr
, *ttmp
, *xt
;
1455 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1456 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1459 /* find deleted tnbrs */
1460 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1461 switch (ldpd_process
) {
1462 case PROC_LDP_ENGINE
:
1463 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1464 tnbr_check(conf
, tnbr
);
1466 case PROC_LDE_ENGINE
:
1468 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1474 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1475 /* find new tnbrs */
1476 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1478 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1480 switch (ldpd_process
) {
1481 case PROC_LDP_ENGINE
:
1484 case PROC_LDE_ENGINE
:
1491 /* update existing tnbrs */
1492 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1493 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1498 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1500 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1504 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1505 /* find deleted nbrps */
1506 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1507 switch (ldpd_process
) {
1508 case PROC_LDP_ENGINE
:
1509 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1511 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1516 (ldp_af_global_get(&global
,
1517 nbr
->af
))->ldp_session_socket
,
1518 nbr
->af
, &nbr
->raddr
, NULL
);
1520 nbr
->auth
.method
= AUTH_NONE
;
1521 if (nbr_session_active_role(nbr
))
1522 nbr_establish_connection(nbr
);
1525 case PROC_LDE_ENGINE
:
1529 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1533 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1534 /* find new nbrps */
1535 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1537 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1539 switch (ldpd_process
) {
1540 case PROC_LDP_ENGINE
:
1541 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1543 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1544 nbr
->auth
.method
= nbrp
->auth
.method
;
1546 if (pfkey_establish(nbr
, nbrp
) == -1)
1547 fatalx("pfkey setup failed");
1550 (ldp_af_global_get(&global
,
1551 nbr
->af
))->ldp_session_socket
,
1552 nbr
->af
, &nbr
->raddr
,
1555 if (nbr_session_active_role(nbr
))
1556 nbr_establish_connection(nbr
);
1559 case PROC_LDE_ENGINE
:
1566 /* update existing nbrps */
1567 if (nbrp
->flags
!= xn
->flags
||
1568 nbrp
->keepalive
!= xn
->keepalive
||
1569 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1570 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1571 nbrp
->auth
.method
!= xn
->auth
.method
||
1572 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1577 nbrp
->keepalive
= xn
->keepalive
;
1578 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1579 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1580 nbrp
->auth
.method
= xn
->auth
.method
;
1581 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1582 sizeof(nbrp
->auth
.md5key
));
1583 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1584 nbrp
->flags
= xn
->flags
;
1586 if (ldpd_process
== PROC_LDP_ENGINE
) {
1587 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1588 if (nbr
&& nbrp_changed
) {
1589 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1592 nbr
->auth
.method
= nbrp
->auth
.method
;
1593 if (pfkey_establish(nbr
, nbrp
) == -1)
1594 fatalx("pfkey setup failed");
1596 nbr
->auth
.method
= nbrp
->auth
.method
;
1597 sock_set_md5sig((ldp_af_global_get(&global
,
1598 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1599 &nbr
->raddr
, nbrp
->auth
.md5key
);
1601 if (nbr_session_active_role(nbr
))
1602 nbr_establish_connection(nbr
);
1609 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1611 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1613 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1614 /* find deleted l2vpns */
1615 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1616 switch (ldpd_process
) {
1617 case PROC_LDE_ENGINE
:
1620 case PROC_LDP_ENGINE
:
1621 ldpe_l2vpn_exit(l2vpn
);
1626 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1630 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1631 /* find new l2vpns */
1632 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1634 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1635 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1636 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1637 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1639 switch (ldpd_process
) {
1640 case PROC_LDE_ENGINE
:
1643 case PROC_LDP_ENGINE
:
1644 ldpe_l2vpn_init(l2vpn
);
1651 /* update existing l2vpns */
1652 merge_l2vpn(conf
, l2vpn
, xl
);
1657 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1659 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1660 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1662 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1663 int previous_pw_type
, previous_mtu
;
1665 previous_pw_type
= l2vpn
->pw_type
;
1666 previous_mtu
= l2vpn
->mtu
;
1668 /* merge intefaces */
1669 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1670 /* find deleted interfaces */
1671 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1672 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1676 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1677 /* find new interfaces */
1678 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1680 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1683 switch (ldpd_process
) {
1684 case PROC_LDP_ENGINE
:
1685 case PROC_LDE_ENGINE
:
1688 kif_redistribute(lif
->ifname
);
1694 /* merge active pseudowires */
1695 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1696 /* find deleted active pseudowires */
1697 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1698 switch (ldpd_process
) {
1699 case PROC_LDE_ENGINE
:
1702 case PROC_LDP_ENGINE
:
1703 ldpe_l2vpn_pw_exit(pw
);
1709 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1713 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1714 /* find new active pseudowires */
1715 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1717 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1720 switch (ldpd_process
) {
1721 case PROC_LDE_ENGINE
:
1724 case PROC_LDP_ENGINE
:
1725 ldpe_l2vpn_pw_init(pw
);
1728 kif_redistribute(pw
->ifname
);
1734 /* update existing active pseudowire */
1735 if (pw
->af
!= xp
->af
||
1736 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1741 /* changes that require a session restart */
1742 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1743 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1748 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1749 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1750 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1751 reinstall_pwfec
= 1;
1753 reinstall_pwfec
= 0;
1755 if (ldpd_process
== PROC_LDP_ENGINE
) {
1757 ldpe_l2vpn_pw_exit(pw
);
1759 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1760 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1761 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1764 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1766 pw
->lsr_id
= xp
->lsr_id
;
1768 pw
->addr
= xp
->addr
;
1769 pw
->pwid
= xp
->pwid
;
1770 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1771 pw
->ifindex
= xp
->ifindex
;
1772 if (xp
->flags
& F_PW_CWORD_CONF
)
1773 pw
->flags
|= F_PW_CWORD_CONF
;
1775 pw
->flags
&= ~F_PW_CWORD_CONF
;
1776 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1777 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1779 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1780 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1781 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1783 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1784 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1785 ldpe_l2vpn_pw_init(pw
);
1786 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1787 l2vpn
->pw_type
= xl
->pw_type
;
1788 l2vpn
->mtu
= xl
->mtu
;
1790 l2vpn
->pw_type
= previous_pw_type
;
1791 l2vpn
->mtu
= previous_mtu
;
1795 /* merge inactive pseudowires */
1796 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1797 /* find deleted inactive pseudowires */
1798 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1799 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1803 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1804 /* find new inactive pseudowires */
1805 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1807 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1810 switch (ldpd_process
) {
1811 case PROC_LDE_ENGINE
:
1812 case PROC_LDP_ENGINE
:
1815 kif_redistribute(pw
->ifname
);
1821 /* update existing inactive pseudowire */
1822 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1824 pw
->addr
= xp
->addr
;
1825 pw
->pwid
= xp
->pwid
;
1826 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1827 pw
->ifindex
= xp
->ifindex
;
1828 pw
->flags
= xp
->flags
;
1831 l2vpn
->pw_type
= xl
->pw_type
;
1832 l2vpn
->mtu
= xl
->mtu
;
1833 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1834 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1838 config_new_empty(void)
1840 struct ldpd_conf
*xconf
;
1842 xconf
= calloc(1, sizeof(*xconf
));
1846 RB_INIT(iface_head
, &xconf
->iface_tree
);
1847 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1848 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1849 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1851 /* set default values */
1852 ldp_config_reset(xconf
);
1858 config_clear(struct ldpd_conf
*conf
)
1860 struct ldpd_conf
*xconf
;
1863 * Merge current config with an empty config, this will deactivate
1864 * and deallocate all the interfaces, pseudowires and so on. Before
1865 * merging, copy the router-id and other variables to avoid some
1866 * unnecessary operations, like trying to reset the neighborships.
1868 xconf
= config_new_empty();
1869 xconf
->ipv4
= conf
->ipv4
;
1870 xconf
->ipv6
= conf
->ipv6
;
1871 xconf
->rtr_id
= conf
->rtr_id
;
1872 xconf
->trans_pref
= conf
->trans_pref
;
1873 xconf
->flags
= conf
->flags
;
1874 merge_config(conf
, xconf
);