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 vty_config_lockless();
339 vrf_init(NULL
, NULL
, NULL
, NULL
, NULL
);
342 ldp_zebra_init(master
);
345 * Create base configuration with sane defaults. All configuration
346 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
347 * to merge the changes into ldpd_conf, which contains the actual
348 * running configuration.
350 ldpd_conf
= config_new_empty();
351 vty_conf
= config_new_empty();
352 QOBJ_REG(vty_conf
, ldpd_conf
);
354 /* read configuration file and daemonize */
357 /* apply configuration */
358 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
360 /* setup pipes to children */
361 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
362 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
363 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
364 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
366 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
367 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
368 iev_ldpe
->ev_read
= NULL
;
369 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
371 iev_ldpe
->handler_write
= ldp_write_handler
;
373 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
374 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
375 iev_ldpe_sync
->ev_read
= NULL
;
376 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
377 &iev_ldpe_sync
->ev_read
);
378 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
380 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
381 iev_lde
->handler_read
= main_dispatch_lde
;
382 iev_lde
->ev_read
= NULL
;
383 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
385 iev_lde
->handler_write
= ldp_write_handler
;
387 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
388 iev_lde_sync
->handler_read
= main_dispatch_lde
;
389 iev_lde_sync
->ev_read
= NULL
;
390 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
391 &iev_lde_sync
->ev_read
);
392 iev_lde_sync
->handler_write
= ldp_write_handler
;
394 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
395 fatal("could not establish imsg links");
396 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
398 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
399 main_imsg_send_config(ldpd_conf
);
401 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
402 main_imsg_send_net_sockets(AF_INET
);
403 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
404 main_imsg_send_net_sockets(AF_INET6
);
421 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
422 close(iev_ldpe
->ibuf
.fd
);
423 msgbuf_clear(&iev_lde
->ibuf
.w
);
424 close(iev_lde
->ibuf
.fd
);
426 config_clear(ldpd_conf
);
428 ldp_config_reset(vty_conf
);
429 QOBJ_UNREG(vty_conf
);
432 log_debug("waiting for children to terminate");
435 /* Wait for child process. */
438 /* We got interrupted, try again. */
441 /* No more processes were found. */
445 /* Unhandled errno condition. */
450 /* We found something, lets announce it. */
451 if (WIFSIGNALED(status
))
452 log_warnx("%s terminated; signal %d",
453 (pid
== lde_pid
? "label decision engine"
457 /* Repeat until there are no more child processes. */
463 log_info("terminating");
474 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
477 int argc
= 0, nullfd
;
480 switch (pid
= fork()) {
482 fatal("cannot fork");
491 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
493 flog_err_sys(EC_LIB_SYSTEM_CALL
,
494 "%s: failed to open /dev/null: %s", __func__
,
495 safe_strerror(errno
));
503 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
504 fatal("cannot setup imsg async fd");
505 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
506 fatal("cannot setup imsg sync fd");
508 argv
[argc
++] = argv0
;
511 fatalx("Can not start main process");
512 case PROC_LDE_ENGINE
:
513 argv
[argc
++] = (char *)"-L";
515 case PROC_LDP_ENGINE
:
516 argv
[argc
++] = (char *)"-E";
528 main_dispatch_ldpe(struct thread
*thread
)
530 struct imsgev
*iev
= THREAD_ARG(thread
);
531 struct imsgbuf
*ibuf
= &iev
->ibuf
;
539 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
540 fatal("imsg_read error");
541 if (n
== 0) /* connection closed */
545 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
551 switch (imsg
.hdr
.type
) {
553 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
555 case IMSG_REQUEST_SOCKETS
:
557 main_imsg_send_net_sockets(af
);
560 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
561 sizeof(struct acl_check
))
562 fatalx("IMSG_ACL_CHECK imsg with wrong len");
563 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
566 log_debug("%s: error handling imsg %d", __func__
,
575 /* this pipe is dead, so remove the event handlers and exit */
576 THREAD_READ_OFF(iev
->ev_read
);
577 THREAD_WRITE_OFF(iev
->ev_write
);
582 kill(lde_pid
, SIGTERM
);
590 main_dispatch_lde(struct thread
*thread
)
592 struct imsgev
*iev
= THREAD_ARG(thread
);
593 struct imsgbuf
*ibuf
= &iev
->ibuf
;
600 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
601 fatal("imsg_read error");
602 if (n
== 0) /* connection closed */
606 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
612 switch (imsg
.hdr
.type
) {
614 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
616 case IMSG_KLABEL_CHANGE
:
617 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
618 sizeof(struct kroute
))
619 fatalx("invalid size of IMSG_KLABEL_CHANGE");
620 if (kr_change(imsg
.data
))
621 log_warnx("%s: error changing route", __func__
);
623 case IMSG_KLABEL_DELETE
:
624 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
625 sizeof(struct kroute
))
626 fatalx("invalid size of IMSG_KLABEL_DELETE");
627 if (kr_delete(imsg
.data
))
628 log_warnx("%s: error deleting route", __func__
);
631 case IMSG_KPW_DELETE
:
634 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
635 sizeof(struct zapi_pw
))
636 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
638 switch (imsg
.hdr
.type
) {
640 if (kmpw_add(imsg
.data
))
641 log_warnx("%s: error adding "
642 "pseudowire", __func__
);
644 case IMSG_KPW_DELETE
:
645 if (kmpw_del(imsg
.data
))
646 log_warnx("%s: error deleting "
647 "pseudowire", __func__
);
650 if (kmpw_set(imsg
.data
))
651 log_warnx("%s: error setting "
652 "pseudowire", __func__
);
655 if (kmpw_unset(imsg
.data
))
656 log_warnx("%s: error unsetting "
657 "pseudowire", __func__
);
662 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
663 sizeof(struct acl_check
))
664 fatalx("IMSG_ACL_CHECK imsg with wrong len");
665 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
668 log_debug("%s: error handling imsg %d", __func__
,
677 /* this pipe is dead, so remove the event handlers and exit */
678 THREAD_READ_OFF(iev
->ev_read
);
679 THREAD_WRITE_OFF(iev
->ev_write
);
684 kill(ldpe_pid
, SIGTERM
);
692 ldp_write_handler(struct thread
*thread
)
694 struct imsgev
*iev
= THREAD_ARG(thread
);
695 struct imsgbuf
*ibuf
= &iev
->ibuf
;
698 iev
->ev_write
= NULL
;
700 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
701 fatal("msgbuf_write");
703 /* this pipe is dead, so remove the event handlers */
704 THREAD_READ_OFF(iev
->ev_read
);
705 THREAD_WRITE_OFF(iev
->ev_write
);
715 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
717 if (iev_ldpe
== NULL
)
719 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
723 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
725 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
729 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
731 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
733 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
735 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
741 imsg_event_add(struct imsgev
*iev
)
743 if (iev
->handler_read
)
744 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
747 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
748 thread_add_write(master
, iev
->handler_write
, iev
,
749 iev
->ibuf
.fd
, &iev
->ev_write
);
753 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
754 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
758 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
759 pid
, fd
, data
, datalen
)) != -1)
765 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
767 ibuf_close(&eb
->wbuf
, buf
);
772 evbuf_event_add(struct evbuf
*eb
)
775 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
780 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
783 msgbuf_init(&eb
->wbuf
);
785 eb
->handler
= handler
;
790 evbuf_clear(struct evbuf
*eb
)
792 THREAD_WRITE_OFF(eb
->ev
);
793 msgbuf_clear(&eb
->wbuf
);
798 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
800 int pipe_ldpe2lde
[2];
802 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
804 sock_set_nonblock(pipe_ldpe2lde
[0]);
805 sock_set_nonblock(pipe_ldpe2lde
[1]);
807 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
810 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
818 main_imsg_send_net_sockets(int af
)
820 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
823 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
824 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
825 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
826 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
830 main_imsg_send_net_socket(int af
, enum socket_type type
)
834 fd
= ldp_create_socket(af
, type
);
836 log_warnx("%s: failed to create %s socket for address-family "
837 "%s", __func__
, socket_name(type
), af_name(af
));
841 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
846 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
847 union ldpd_addr
*addr
, uint8_t prefixlen
)
851 struct acl_check acl_check
;
853 if (acl_name
[0] == '\0')
854 return FILTER_PERMIT
;
857 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
859 acl_check
.addr
= *addr
;
860 acl_check
.prefixlen
= prefixlen
;
862 /* send (blocking) */
863 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
865 imsg_flush(&iev
->ibuf
);
867 /* receive (blocking) and parse result */
868 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
869 fatal("imsg_read error");
870 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
872 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
873 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
874 fatalx("ldp_acl_request: invalid response");
876 return (*((int *)imsg
.data
));
880 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
882 struct access_list
*alist
;
883 struct prefix prefix
;
886 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
888 result
= FILTER_DENY
;
890 prefix
.family
= acl_check
->af
;
891 switch (prefix
.family
) {
893 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
896 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
899 fatalx("ldp_acl_reply: unknown af");
901 prefix
.prefixlen
= acl_check
->prefixlen
;
902 result
= access_list_apply(alist
, &prefix
);
905 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
909 struct ldpd_af_conf
*
910 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
914 return (&xconf
->ipv4
);
916 return (&xconf
->ipv6
);
918 fatalx("ldp_af_conf_get: unknown af");
922 struct ldpd_af_global
*
923 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
927 return (&xglobal
->ipv4
);
929 return (&xglobal
->ipv6
);
931 fatalx("ldp_af_global_get: unknown af");
936 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
938 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
939 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
943 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
945 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
946 return (xconf
->rtr_id
.s_addr
);
948 return (global
.rtr_id
.s_addr
);
952 main_imsg_send_config(struct ldpd_conf
*xconf
)
956 struct nbr_params
*nbrp
;
958 struct l2vpn_if
*lif
;
961 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
962 sizeof(*xconf
)) == -1)
965 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
966 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
967 sizeof(*iface
)) == -1)
971 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
972 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
973 sizeof(*tnbr
)) == -1)
977 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
978 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
979 sizeof(*nbrp
)) == -1)
983 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
984 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
985 sizeof(*l2vpn
)) == -1)
988 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
989 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
993 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
994 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
998 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
999 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
1005 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1012 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1015 * When reading from a configuration file (startup and sighup), we
1016 * call merge_config() only once after the whole config has been read.
1017 * This is the optimal and least disruptive way to update the running
1020 if (vty
&& vty
->type
== VTY_FILE
)
1023 ldp_config_normalize(xconf
);
1025 if (main_imsg_send_config(xconf
) == -1)
1028 merge_config(ldpd_conf
, xconf
);
1034 ldp_config_normalize(struct ldpd_conf
*xconf
)
1036 struct iface
*iface
, *itmp
;
1037 struct nbr_params
*nbrp
, *ntmp
;
1038 struct l2vpn
*l2vpn
;
1039 struct l2vpn_pw
*pw
, *ptmp
;
1041 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1042 ldp_config_reset_main(xconf
);
1044 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1045 ldp_config_reset_af(xconf
, AF_INET
);
1046 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1047 ldp_config_reset_af(xconf
, AF_INET6
);
1049 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1050 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1054 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1058 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1059 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1061 if (nbrp
->auth
.method
!= AUTH_NONE
)
1065 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1070 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1071 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1072 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1074 pw
->addr
.v4
= pw
->lsr_id
;
1077 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1079 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1080 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1082 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1084 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1086 pw
->addr
.v4
= pw
->lsr_id
;
1089 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1091 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1092 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1098 ldp_config_reset(struct ldpd_conf
*conf
)
1100 ldp_config_reset_main(conf
);
1101 ldp_config_reset_l2vpns(conf
);
1105 ldp_config_reset_main(struct ldpd_conf
*conf
)
1107 struct iface
*iface
;
1108 struct nbr_params
*nbrp
;
1110 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1111 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1114 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1118 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1119 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1122 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1126 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1127 ldp_config_reset_af(conf
, AF_INET
);
1128 ldp_config_reset_af(conf
, AF_INET6
);
1129 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1130 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1131 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1132 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1133 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1138 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1140 struct ldpd_af_conf
*af_conf
;
1141 struct iface
*iface
;
1142 struct iface_af
*ia
;
1143 struct tnbr
*tnbr
, *ttmp
;
1145 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1146 ia
= iface_af_get(iface
, af
);
1150 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1155 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1159 af_conf
= ldp_af_conf_get(conf
, af
);
1160 af_conf
->keepalive
= 180;
1161 af_conf
->lhello_holdtime
= 0;
1162 af_conf
->lhello_interval
= 0;
1163 af_conf
->thello_holdtime
= 0;
1164 af_conf
->thello_interval
= 0;
1165 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1170 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1172 struct l2vpn
*l2vpn
;
1173 struct l2vpn_if
*lif
;
1174 struct l2vpn_pw
*pw
;
1176 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1177 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1178 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1179 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1182 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1185 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1186 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1189 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1192 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1193 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1196 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1200 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1206 ldp_clear_config(struct ldpd_conf
*xconf
)
1208 struct iface
*iface
;
1210 struct nbr_params
*nbrp
;
1211 struct l2vpn
*l2vpn
;
1213 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1214 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1216 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1219 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1220 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1222 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1225 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1226 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1228 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1231 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1232 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1234 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1241 #define COPY(a, b) do { \
1242 a = malloc(sizeof(*a)); \
1249 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1251 merge_global(conf
, xconf
);
1252 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1253 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1254 merge_ifaces(conf
, xconf
);
1255 merge_tnbrs(conf
, xconf
);
1256 merge_nbrps(conf
, xconf
);
1257 merge_l2vpns(conf
, xconf
);
1261 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1263 /* change of router-id requires resetting all neighborships */
1264 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1265 if (ldpd_process
== PROC_LDP_ENGINE
) {
1266 ldpe_reset_nbrs(AF_UNSPEC
);
1267 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1268 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1269 if_update_all(AF_UNSPEC
);
1270 tnbr_update_all(AF_UNSPEC
);
1273 conf
->rtr_id
= xconf
->rtr_id
;
1276 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1277 conf
->lhello_interval
= xconf
->lhello_interval
;
1278 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1279 conf
->thello_interval
= xconf
->thello_interval
;
1281 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1282 if (ldpd_process
== PROC_LDP_ENGINE
)
1283 ldpe_reset_ds_nbrs();
1284 conf
->trans_pref
= xconf
->trans_pref
;
1287 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1288 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1289 if (ldpd_process
== PROC_LDP_ENGINE
)
1290 ldpe_reset_ds_nbrs();
1293 conf
->flags
= xconf
->flags
;
1297 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1299 int stop_init_backoff
= 0;
1300 int remove_dynamic_tnbrs
= 0;
1301 int change_egress_label
= 0;
1302 int reset_nbrs_ipv4
= 0;
1304 int update_sockets
= 0;
1307 if (af_conf
->keepalive
!= xa
->keepalive
) {
1308 af_conf
->keepalive
= xa
->keepalive
;
1309 stop_init_backoff
= 1;
1311 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1312 af_conf
->lhello_interval
= xa
->lhello_interval
;
1313 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1314 af_conf
->thello_interval
= xa
->thello_interval
;
1317 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1318 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1319 remove_dynamic_tnbrs
= 1;
1320 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1321 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1323 /* need to set/unset IPV6_MINHOPCOUNT */
1326 /* for LDPv4 just resetting the neighbors is enough */
1327 reset_nbrs_ipv4
= 1;
1329 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1330 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1331 change_egress_label
= 1;
1332 af_conf
->flags
= xa
->flags
;
1334 /* update the transport address */
1335 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1336 af_conf
->trans_addr
= xa
->trans_addr
;
1341 if (strcmp(af_conf
->acl_label_advertise_to
,
1342 xa
->acl_label_advertise_to
) ||
1343 strcmp(af_conf
->acl_label_advertise_for
,
1344 xa
->acl_label_advertise_for
) ||
1345 strcmp(af_conf
->acl_label_accept_from
,
1346 xa
->acl_label_accept_from
) ||
1347 strcmp(af_conf
->acl_label_accept_for
,
1348 xa
->acl_label_accept_for
))
1350 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1351 remove_dynamic_tnbrs
= 1;
1352 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1353 change_egress_label
= 1;
1354 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1355 sizeof(af_conf
->acl_thello_accept_from
));
1356 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1357 sizeof(af_conf
->acl_label_allocate_for
));
1358 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1359 sizeof(af_conf
->acl_label_advertise_to
));
1360 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1361 sizeof(af_conf
->acl_label_advertise_for
));
1362 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1363 sizeof(af_conf
->acl_label_accept_from
));
1364 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1365 sizeof(af_conf
->acl_label_accept_for
));
1366 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1367 sizeof(af_conf
->acl_label_expnull_for
));
1369 /* apply the new configuration */
1370 switch (ldpd_process
) {
1371 case PROC_LDE_ENGINE
:
1372 if (change_egress_label
)
1373 lde_change_egress_label(af
);
1375 case PROC_LDP_ENGINE
:
1376 if (stop_init_backoff
)
1377 ldpe_stop_init_backoff(af
);
1378 if (remove_dynamic_tnbrs
)
1379 ldpe_remove_dynamic_tnbrs(af
);
1381 ldpe_reset_nbrs(AF_UNSPEC
);
1382 else if (reset_nbrs_ipv4
)
1383 ldpe_reset_nbrs(AF_INET
);
1386 if (update_sockets
&& iev_ldpe
)
1387 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1394 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1396 struct iface
*iface
, *itmp
, *xi
;
1398 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1399 /* find deleted interfaces */
1400 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1401 switch (ldpd_process
) {
1402 case PROC_LDP_ENGINE
:
1403 ldpe_if_exit(iface
);
1405 case PROC_LDE_ENGINE
:
1409 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1413 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1414 /* find new interfaces */
1415 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1417 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1419 switch (ldpd_process
) {
1420 case PROC_LDP_ENGINE
:
1421 ldpe_if_init(iface
);
1423 case PROC_LDE_ENGINE
:
1426 /* resend addresses to activate new interfaces */
1427 kif_redistribute(iface
->name
);
1433 /* update existing interfaces */
1434 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1435 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1440 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1442 if (ia
->enabled
!= xi
->enabled
) {
1443 ia
->enabled
= xi
->enabled
;
1444 if (ldpd_process
== PROC_LDP_ENGINE
)
1445 ldp_if_update(ia
->iface
, ia
->af
);
1447 ia
->hello_holdtime
= xi
->hello_holdtime
;
1448 ia
->hello_interval
= xi
->hello_interval
;
1452 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1454 struct tnbr
*tnbr
, *ttmp
, *xt
;
1456 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1457 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1460 /* find deleted tnbrs */
1461 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1462 switch (ldpd_process
) {
1463 case PROC_LDP_ENGINE
:
1464 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1465 tnbr_check(conf
, tnbr
);
1467 case PROC_LDE_ENGINE
:
1469 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1475 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1476 /* find new tnbrs */
1477 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1479 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1481 switch (ldpd_process
) {
1482 case PROC_LDP_ENGINE
:
1485 case PROC_LDE_ENGINE
:
1492 /* update existing tnbrs */
1493 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1494 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1499 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1501 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1505 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1506 /* find deleted nbrps */
1507 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1508 switch (ldpd_process
) {
1509 case PROC_LDP_ENGINE
:
1510 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1512 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1517 (ldp_af_global_get(&global
,
1518 nbr
->af
))->ldp_session_socket
,
1519 nbr
->af
, &nbr
->raddr
, NULL
);
1521 nbr
->auth
.method
= AUTH_NONE
;
1522 if (nbr_session_active_role(nbr
))
1523 nbr_establish_connection(nbr
);
1526 case PROC_LDE_ENGINE
:
1530 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1534 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1535 /* find new nbrps */
1536 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1538 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1540 switch (ldpd_process
) {
1541 case PROC_LDP_ENGINE
:
1542 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1544 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1545 nbr
->auth
.method
= nbrp
->auth
.method
;
1547 if (pfkey_establish(nbr
, nbrp
) == -1)
1548 fatalx("pfkey setup failed");
1551 (ldp_af_global_get(&global
,
1552 nbr
->af
))->ldp_session_socket
,
1553 nbr
->af
, &nbr
->raddr
,
1556 if (nbr_session_active_role(nbr
))
1557 nbr_establish_connection(nbr
);
1560 case PROC_LDE_ENGINE
:
1567 /* update existing nbrps */
1568 if (nbrp
->flags
!= xn
->flags
||
1569 nbrp
->keepalive
!= xn
->keepalive
||
1570 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1571 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1572 nbrp
->auth
.method
!= xn
->auth
.method
||
1573 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1578 nbrp
->keepalive
= xn
->keepalive
;
1579 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1580 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1581 nbrp
->auth
.method
= xn
->auth
.method
;
1582 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1583 sizeof(nbrp
->auth
.md5key
));
1584 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1585 nbrp
->flags
= xn
->flags
;
1587 if (ldpd_process
== PROC_LDP_ENGINE
) {
1588 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1589 if (nbr
&& nbrp_changed
) {
1590 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1593 nbr
->auth
.method
= nbrp
->auth
.method
;
1594 if (pfkey_establish(nbr
, nbrp
) == -1)
1595 fatalx("pfkey setup failed");
1597 nbr
->auth
.method
= nbrp
->auth
.method
;
1598 sock_set_md5sig((ldp_af_global_get(&global
,
1599 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1600 &nbr
->raddr
, nbrp
->auth
.md5key
);
1602 if (nbr_session_active_role(nbr
))
1603 nbr_establish_connection(nbr
);
1610 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1612 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1614 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1615 /* find deleted l2vpns */
1616 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1617 switch (ldpd_process
) {
1618 case PROC_LDE_ENGINE
:
1621 case PROC_LDP_ENGINE
:
1622 ldpe_l2vpn_exit(l2vpn
);
1627 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1631 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1632 /* find new l2vpns */
1633 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1635 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1636 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1637 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1638 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1640 switch (ldpd_process
) {
1641 case PROC_LDE_ENGINE
:
1644 case PROC_LDP_ENGINE
:
1645 ldpe_l2vpn_init(l2vpn
);
1652 /* update existing l2vpns */
1653 merge_l2vpn(conf
, l2vpn
, xl
);
1658 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1660 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1661 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1663 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1664 int previous_pw_type
, previous_mtu
;
1666 previous_pw_type
= l2vpn
->pw_type
;
1667 previous_mtu
= l2vpn
->mtu
;
1669 /* merge intefaces */
1670 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1671 /* find deleted interfaces */
1672 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1673 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1677 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1678 /* find new interfaces */
1679 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1681 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1684 switch (ldpd_process
) {
1685 case PROC_LDP_ENGINE
:
1686 case PROC_LDE_ENGINE
:
1689 kif_redistribute(lif
->ifname
);
1695 /* merge active pseudowires */
1696 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1697 /* find deleted active pseudowires */
1698 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1699 switch (ldpd_process
) {
1700 case PROC_LDE_ENGINE
:
1703 case PROC_LDP_ENGINE
:
1704 ldpe_l2vpn_pw_exit(pw
);
1710 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1714 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1715 /* find new active pseudowires */
1716 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1718 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1721 switch (ldpd_process
) {
1722 case PROC_LDE_ENGINE
:
1725 case PROC_LDP_ENGINE
:
1726 ldpe_l2vpn_pw_init(pw
);
1729 kif_redistribute(pw
->ifname
);
1735 /* update existing active pseudowire */
1736 if (pw
->af
!= xp
->af
||
1737 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1742 /* changes that require a session restart */
1743 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1744 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1749 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1750 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1751 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1752 reinstall_pwfec
= 1;
1754 reinstall_pwfec
= 0;
1756 if (ldpd_process
== PROC_LDP_ENGINE
) {
1758 ldpe_l2vpn_pw_exit(pw
);
1760 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1761 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1762 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1765 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1767 pw
->lsr_id
= xp
->lsr_id
;
1769 pw
->addr
= xp
->addr
;
1770 pw
->pwid
= xp
->pwid
;
1771 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1772 pw
->ifindex
= xp
->ifindex
;
1773 if (xp
->flags
& F_PW_CWORD_CONF
)
1774 pw
->flags
|= F_PW_CWORD_CONF
;
1776 pw
->flags
&= ~F_PW_CWORD_CONF
;
1777 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1778 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1780 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1781 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1782 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1784 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1785 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1786 ldpe_l2vpn_pw_init(pw
);
1787 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1788 l2vpn
->pw_type
= xl
->pw_type
;
1789 l2vpn
->mtu
= xl
->mtu
;
1791 l2vpn
->pw_type
= previous_pw_type
;
1792 l2vpn
->mtu
= previous_mtu
;
1796 /* merge inactive pseudowires */
1797 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1798 /* find deleted inactive pseudowires */
1799 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1800 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1804 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1805 /* find new inactive pseudowires */
1806 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1808 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1811 switch (ldpd_process
) {
1812 case PROC_LDE_ENGINE
:
1813 case PROC_LDP_ENGINE
:
1816 kif_redistribute(pw
->ifname
);
1822 /* update existing inactive pseudowire */
1823 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1825 pw
->addr
= xp
->addr
;
1826 pw
->pwid
= xp
->pwid
;
1827 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1828 pw
->ifindex
= xp
->ifindex
;
1829 pw
->flags
= xp
->flags
;
1832 l2vpn
->pw_type
= xl
->pw_type
;
1833 l2vpn
->mtu
= xl
->mtu
;
1834 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1835 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1839 config_new_empty(void)
1841 struct ldpd_conf
*xconf
;
1843 xconf
= calloc(1, sizeof(*xconf
));
1847 RB_INIT(iface_head
, &xconf
->iface_tree
);
1848 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1849 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1850 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1852 /* set default values */
1853 ldp_config_reset(xconf
);
1859 config_clear(struct ldpd_conf
*conf
)
1861 struct ldpd_conf
*xconf
;
1864 * Merge current config with an empty config, this will deactivate
1865 * and deallocate all the interfaces, pseudowires and so on. Before
1866 * merging, copy the router-id and other variables to avoid some
1867 * unnecessary operations, like trying to reset the neighborships.
1869 xconf
= config_new_empty();
1870 xconf
->ipv4
= conf
->ipv4
;
1871 xconf
->ipv6
= conf
->ipv6
;
1872 xconf
->rtr_id
= conf
->rtr_id
;
1873 xconf
->trans_pref
= conf
->trans_pref
;
1874 xconf
->flags
= conf
->flags
;
1875 merge_config(conf
, xconf
);