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>
44 static void ldpd_shutdown(void);
45 static pid_t
start_child(enum ldpd_process
, char *, int,
46 const char *, const char *);
47 static int main_dispatch_ldpe(struct thread
*);
48 static int main_dispatch_lde(struct thread
*);
49 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
51 static void main_imsg_send_net_sockets(int);
52 static void main_imsg_send_net_socket(int, enum socket_type
);
53 static int main_imsg_send_config(struct ldpd_conf
*);
54 static void ldp_config_normalize(struct ldpd_conf
*, void **);
55 static void ldp_config_reset_main(struct ldpd_conf
*, void **);
56 static void ldp_config_reset_af(struct ldpd_conf
*, int, void **);
57 static void merge_config_ref(struct ldpd_conf
*, struct ldpd_conf
*, void **);
58 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
59 static void merge_af(int, struct ldpd_af_conf
*,
60 struct ldpd_af_conf
*);
61 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*, void **);
62 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
63 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*, void **);
64 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*, void **);
65 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*, void **);
66 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
67 struct l2vpn
*, void **);
69 DEFINE_QOBJ_TYPE(iface
)
70 DEFINE_QOBJ_TYPE(tnbr
)
71 DEFINE_QOBJ_TYPE(nbr_params
)
72 DEFINE_QOBJ_TYPE(l2vpn_if
)
73 DEFINE_QOBJ_TYPE(l2vpn_pw
)
74 DEFINE_QOBJ_TYPE(l2vpn
)
75 DEFINE_QOBJ_TYPE(ldpd_conf
)
77 struct ldpd_global global
;
78 struct ldpd_conf
*ldpd_conf
;
80 static struct imsgev
*iev_ldpe
;
81 static struct imsgev
*iev_lde
;
82 static pid_t ldpe_pid
;
85 #define LDP_DEFAULT_CONFIG "ldpd.conf"
86 #define LDP_VTY_PORT 2612
88 /* Master of threads. */
89 struct thread_master
*master
;
91 /* Process ID saved for use by init system */
92 static const char *pid_file
= PATH_LDPD_PID
;
94 /* Configuration filename and directory. */
95 static char config_default
[] = SYSCONFDIR LDP_DEFAULT_CONFIG
;
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
),
119 static struct option longopts
[] =
121 { "daemon", no_argument
, NULL
, 'd'},
122 { "config_file", required_argument
, NULL
, 'f'},
123 { "pid_file", required_argument
, NULL
, 'i'},
124 { "socket", required_argument
, NULL
, 'z'},
125 { "dryrun", no_argument
, NULL
, 'C'},
126 { "help", no_argument
, NULL
, 'h'},
127 { "vty_addr", required_argument
, NULL
, 'A'},
128 { "vty_port", required_argument
, NULL
, 'P'},
129 { "user", required_argument
, NULL
, 'u'},
130 { "group", required_argument
, NULL
, 'g'},
131 { "version", no_argument
, NULL
, 'v'},
135 /* Help information display. */
136 static void __attribute__ ((noreturn
))
137 usage(char *progname
, int status
)
140 fprintf(stderr
, "Try `%s --help' for more information.\n",
143 printf("Usage : %s [OPTION...]\n\
144 Daemon which manages LDP.\n\n\
145 -d, --daemon Runs in daemon mode\n\
146 -f, --config_file Set configuration file name\n\
147 -i, --pid_file Set process identifier file name\n\
148 -z, --socket Set path of zebra socket\n\
149 -A, --vty_addr Set vty's bind address\n\
150 -P, --vty_port Set vty's port number\n\
151 -u, --user User to run as\n\
152 -g, --group Group to run as\n\
153 -v, --version Print program version\n\
154 -C, --dryrun Check configuration for validity and exit\n\
155 -h, --help Display this help and exit\n\
157 Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
163 /* SIGHUP handler. */
167 log_info("SIGHUP received");
170 /* SIGINT / SIGTERM handler. */
174 log_info("SIGINT received");
178 /* SIGUSR1 handler. */
185 static struct quagga_signal_t ldp_signals
[] =
206 main(int argc
, char *argv
[])
209 int lflag
= 0, eflag
= 0;
210 int pipe_parent2ldpe
[2];
211 int pipe_parent2lde
[2];
213 char *vty_addr
= NULL
;
214 int vty_port
= LDP_VTY_PORT
;
216 const char *user
= NULL
;
217 const char *group
= NULL
;
218 char *config_file
= NULL
;
220 struct thread thread
;
223 ldpd_process
= PROC_MAIN
;
225 /* Set umask before anything for security */
228 /* get program name */
229 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
231 saved_argv0
= argv
[0];
232 if (saved_argv0
== NULL
)
233 saved_argv0
= (char *)"ldpd";
238 opt
= getopt_long(argc
, argv
, "df:i:z:hA:P:u:g:vCLE",
251 config_file
= optarg
;
260 zclient_serv_path_set(optarg
);
264 * Deal with atoi() returning 0 on failure, and ldpd
265 * not listening on ldpd port.
267 if (strcmp(optarg
, "0") == 0) {
271 vty_port
= atoi(optarg
);
272 if (vty_port
<= 0 || vty_port
> 0xffff)
273 vty_port
= LDP_VTY_PORT
;
282 print_version(progname
);
305 if (argc
> 0 || (lflag
&& eflag
))
308 /* check for root privileges */
309 if (geteuid() != 0) {
315 zlog_default
= openzlog(progname
, ZLOG_LDP
, 0,
316 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
323 master
= thread_master_create();
326 vty_config_lockless ();
332 /* Get configuration file. */
333 ldpd_conf
= config_new_empty();
334 ldp_config_reset_main(ldpd_conf
, NULL
);
335 vty_read_config(config_file
, config_default
);
337 /* Start execution only if not in dry-run mode */
341 QOBJ_REG (ldpd_conf
, ldpd_conf
);
343 if (daemon_mode
&& daemon(0, 0) < 0) {
344 log_warn("LDPd daemon failed");
348 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
350 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
352 sock_set_nonblock(pipe_parent2ldpe
[0]);
353 sock_set_cloexec(pipe_parent2ldpe
[0]);
354 sock_set_nonblock(pipe_parent2ldpe
[1]);
355 sock_set_cloexec(pipe_parent2ldpe
[1]);
356 sock_set_nonblock(pipe_parent2lde
[0]);
357 sock_set_cloexec(pipe_parent2lde
[0]);
358 sock_set_nonblock(pipe_parent2lde
[1]);
359 sock_set_cloexec(pipe_parent2lde
[1]);
362 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
363 pipe_parent2lde
[1], user
, group
);
364 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
365 pipe_parent2ldpe
[1], user
, group
);
367 /* drop privileges */
369 ldpd_privs
.user
= user
;
371 ldpd_privs
.group
= group
;
372 zprivs_init(&ldpd_privs
);
374 /* setup signal handler */
375 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
378 ldp_zebra_init(master
);
380 /* setup pipes to children */
381 if ((iev_ldpe
= malloc(sizeof(struct imsgev
))) == NULL
||
382 (iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
384 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
385 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
386 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
387 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
388 iev_ldpe
->handler_write
= ldp_write_handler
;
389 iev_ldpe
->ev_write
= NULL
;
391 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
392 iev_lde
->handler_read
= main_dispatch_lde
;
393 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
394 iev_lde
, iev_lde
->ibuf
.fd
);
395 iev_lde
->handler_write
= ldp_write_handler
;
396 iev_lde
->ev_write
= NULL
;
398 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
399 fatal("could not establish imsg links");
400 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
402 main_imsg_send_config(ldpd_conf
);
404 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
405 main_imsg_send_net_sockets(AF_INET
);
406 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
407 main_imsg_send_net_sockets(AF_INET6
);
409 /* Process id file create. */
410 pid_output(pid_file
);
412 /* Create VTY socket */
413 vty_serv_sock(vty_addr
, vty_port
, LDP_VTYSH_PATH
);
416 log_notice("LDPd %s starting: vty@%d", FRR_VERSION
, vty_port
);
418 /* Fetch next active thread. */
419 while (thread_fetch(master
, &thread
))
420 thread_call(&thread
);
433 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
434 close(iev_ldpe
->ibuf
.fd
);
435 msgbuf_clear(&iev_lde
->ibuf
.w
);
436 close(iev_lde
->ibuf
.fd
);
438 config_clear(ldpd_conf
);
440 log_debug("waiting for children to terminate");
444 if (errno
!= EINTR
&& errno
!= ECHILD
)
446 } else if (WIFSIGNALED(status
))
447 log_warnx("%s terminated; signal %d",
448 (pid
== lde_pid
) ? "label decision engine" :
449 "ldp engine", WTERMSIG(status
));
450 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
455 log_info("terminating");
460 start_child(enum ldpd_process p
, char *argv0
, int fd
, const char *user
,
467 switch (pid
= fork()) {
469 fatal("cannot fork");
477 if (dup2(fd
, 3) == -1)
478 fatal("cannot setup imsg fd");
480 argv
[argc
++] = argv0
;
483 fatalx("Can not start main process");
484 case PROC_LDE_ENGINE
:
485 argv
[argc
++] = (char *)"-L";
487 case PROC_LDP_ENGINE
:
488 argv
[argc
++] = (char *)"-E";
492 argv
[argc
++] = (char *)"-u";
493 argv
[argc
++] = (char *)user
;
496 argv
[argc
++] = (char *)"-g";
497 argv
[argc
++] = (char *)group
;
508 main_dispatch_ldpe(struct thread
*thread
)
510 struct imsgev
*iev
= THREAD_ARG(thread
);
511 struct imsgbuf
*ibuf
= &iev
->ibuf
;
519 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
520 fatal("imsg_read error");
521 if (n
== 0) /* connection closed */
525 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
531 switch (imsg
.hdr
.type
) {
533 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
535 case IMSG_REQUEST_SOCKETS
:
537 main_imsg_send_net_sockets(af
);
540 log_debug("%s: error handling imsg %d", __func__
,
549 /* this pipe is dead, so remove the event handlers and exit */
550 THREAD_READ_OFF(iev
->ev_read
);
551 THREAD_WRITE_OFF(iev
->ev_write
);
556 kill(lde_pid
, SIGTERM
);
564 main_dispatch_lde(struct thread
*thread
)
566 struct imsgev
*iev
= THREAD_ARG(thread
);
567 struct imsgbuf
*ibuf
= &iev
->ibuf
;
574 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
575 fatal("imsg_read error");
576 if (n
== 0) /* connection closed */
580 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
586 switch (imsg
.hdr
.type
) {
588 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
590 case IMSG_KLABEL_CHANGE
:
591 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
592 sizeof(struct kroute
))
593 fatalx("invalid size of IMSG_KLABEL_CHANGE");
594 if (kr_change(imsg
.data
))
595 log_warnx("%s: error changing route", __func__
);
597 case IMSG_KLABEL_DELETE
:
598 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
599 sizeof(struct kroute
))
600 fatalx("invalid size of IMSG_KLABEL_DELETE");
601 if (kr_delete(imsg
.data
))
602 log_warnx("%s: error deleting route", __func__
);
604 case IMSG_KPWLABEL_CHANGE
:
605 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
607 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
608 if (kmpw_set(imsg
.data
))
609 log_warnx("%s: error changing pseudowire",
612 case IMSG_KPWLABEL_DELETE
:
613 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
615 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
616 if (kmpw_unset(imsg
.data
))
617 log_warnx("%s: error unsetting pseudowire",
621 log_debug("%s: error handling imsg %d", __func__
,
630 /* this pipe is dead, so remove the event handlers and exit */
631 THREAD_READ_OFF(iev
->ev_read
);
632 THREAD_WRITE_OFF(iev
->ev_write
);
637 kill(ldpe_pid
, SIGTERM
);
645 ldp_write_handler(struct thread
*thread
)
647 struct imsgev
*iev
= THREAD_ARG(thread
);
648 struct imsgbuf
*ibuf
= &iev
->ibuf
;
651 iev
->ev_write
= NULL
;
653 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
654 fatal("msgbuf_write");
656 /* this pipe is dead, so remove the event handlers */
657 THREAD_READ_OFF(iev
->ev_read
);
658 THREAD_WRITE_OFF(iev
->ev_write
);
668 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
670 if (iev_ldpe
== NULL
)
672 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
676 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
678 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
682 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
684 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
686 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
688 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
694 imsg_event_add(struct imsgev
*iev
)
696 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
699 if (iev
->ibuf
.w
.queued
)
700 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
705 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
706 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
710 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
711 pid
, fd
, data
, datalen
)) != -1)
717 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
719 ibuf_close(&eb
->wbuf
, buf
);
724 evbuf_event_add(struct evbuf
*eb
)
727 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
732 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
735 msgbuf_init(&eb
->wbuf
);
737 eb
->handler
= handler
;
742 evbuf_clear(struct evbuf
*eb
)
744 THREAD_WRITE_OFF(eb
->ev
);
745 msgbuf_clear(&eb
->wbuf
);
750 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
752 int pipe_ldpe2lde
[2];
754 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
756 sock_set_nonblock(pipe_ldpe2lde
[0]);
757 sock_set_nonblock(pipe_ldpe2lde
[1]);
759 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
762 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
770 main_imsg_send_net_sockets(int af
)
772 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
775 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
776 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
777 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
778 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
782 main_imsg_send_net_socket(int af
, enum socket_type type
)
786 fd
= ldp_create_socket(af
, type
);
788 log_warnx("%s: failed to create %s socket for address-family "
789 "%s", __func__
, socket_name(type
), af_name(af
));
793 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
797 struct ldpd_af_conf
*
798 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
802 return (&xconf
->ipv4
);
804 return (&xconf
->ipv6
);
806 fatalx("ldp_af_conf_get: unknown af");
810 struct ldpd_af_global
*
811 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
815 return (&xglobal
->ipv4
);
817 return (&xglobal
->ipv6
);
819 fatalx("ldp_af_global_get: unknown af");
824 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
826 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
827 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
831 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
833 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
834 return (xconf
->rtr_id
.s_addr
);
836 return (global
.rtr_id
.s_addr
);
840 main_imsg_send_config(struct ldpd_conf
*xconf
)
844 struct nbr_params
*nbrp
;
846 struct l2vpn_if
*lif
;
849 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
850 sizeof(*xconf
)) == -1)
853 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
854 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
855 sizeof(*iface
)) == -1)
859 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
860 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
861 sizeof(*tnbr
)) == -1)
865 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
866 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
867 sizeof(*nbrp
)) == -1)
871 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
872 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
873 sizeof(*l2vpn
)) == -1)
876 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
877 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
881 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
882 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
886 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
887 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
893 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
900 ldp_reload_ref(struct ldpd_conf
*xconf
, void **ref
)
902 ldp_config_normalize(xconf
, ref
);
904 if (main_imsg_send_config(xconf
) == -1)
907 merge_config_ref(ldpd_conf
, xconf
, ref
);
913 ldp_reload(struct ldpd_conf
*xconf
)
915 return ldp_reload_ref(xconf
, NULL
);
919 ldp_config_normalize(struct ldpd_conf
*xconf
, void **ref
)
924 if (!(xconf
->flags
& F_LDPD_ENABLED
))
925 ldp_config_reset_main(xconf
, ref
);
927 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
928 ldp_config_reset_af(xconf
, AF_INET
, ref
);
929 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
930 ldp_config_reset_af(xconf
, AF_INET6
, ref
);
933 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
934 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
935 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
939 pw
->addr
.v4
= pw
->lsr_id
;
941 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
942 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
946 pw
->addr
.v4
= pw
->lsr_id
;
952 ldp_config_reset_main(struct ldpd_conf
*conf
, void **ref
)
955 struct nbr_params
*nbrp
;
957 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
958 if (ref
&& *ref
== iface
)
960 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
964 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
965 if (ref
&& *ref
== nbrp
)
967 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
971 conf
->rtr_id
.s_addr
= INADDR_ANY
;
972 ldp_config_reset_af(conf
, AF_INET
, ref
);
973 ldp_config_reset_af(conf
, AF_INET6
, ref
);
974 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
975 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
976 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
977 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
978 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
983 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
, void **ref
)
985 struct ldpd_af_conf
*af_conf
;
988 struct tnbr
*tnbr
, *ttmp
;
990 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
991 ia
= iface_af_get(iface
, af
);
995 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
999 if (ref
&& *ref
== tnbr
)
1001 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1005 af_conf
= ldp_af_conf_get(conf
, af
);
1006 af_conf
->keepalive
= 180;
1007 af_conf
->lhello_holdtime
= 0;
1008 af_conf
->lhello_interval
= 0;
1009 af_conf
->thello_holdtime
= 0;
1010 af_conf
->thello_interval
= 0;
1011 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1016 ldp_dup_config_ref(struct ldpd_conf
*conf
, void **ref
)
1018 struct ldpd_conf
*xconf
;
1019 struct iface
*iface
, *xi
;
1020 struct tnbr
*tnbr
, *xt
;
1021 struct nbr_params
*nbrp
, *xn
;
1022 struct l2vpn
*l2vpn
, *xl
;
1023 struct l2vpn_if
*lif
, *xf
;
1024 struct l2vpn_pw
*pw
, *xp
;
1026 #define COPY(a, b) do { \
1027 a = calloc(1, sizeof(*a)); \
1031 if (ref && *ref == b) *ref = a; \
1035 RB_INIT(&xconf
->iface_tree
);
1036 RB_INIT(&xconf
->tnbr_tree
);
1037 RB_INIT(&xconf
->nbrp_tree
);
1038 RB_INIT(&xconf
->l2vpn_tree
);
1040 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1042 xi
->ipv4
.iface
= xi
;
1043 xi
->ipv6
.iface
= xi
;
1044 RB_INSERT(iface_head
, &xconf
->iface_tree
, xi
);
1046 RB_FOREACH(tnbr
, tnbr_head
, &conf
->tnbr_tree
) {
1048 RB_INSERT(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1050 RB_FOREACH(nbrp
, nbrp_head
, &conf
->nbrp_tree
) {
1052 RB_INSERT(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1054 RB_FOREACH(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
) {
1056 RB_INIT(&xl
->if_tree
);
1057 RB_INIT(&xl
->pw_tree
);
1058 RB_INIT(&xl
->pw_inactive_tree
);
1059 RB_INSERT(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1061 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1064 RB_INSERT(l2vpn_if_head
, &xl
->if_tree
, xf
);
1066 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1069 RB_INSERT(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1071 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1074 RB_INSERT(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1083 ldp_dup_config(struct ldpd_conf
*conf
)
1085 return ldp_dup_config_ref(conf
, NULL
);
1089 ldp_clear_config(struct ldpd_conf
*xconf
)
1091 struct iface
*iface
;
1093 struct nbr_params
*nbrp
;
1094 struct l2vpn
*l2vpn
;
1096 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1097 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1100 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1101 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1104 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1105 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1108 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1109 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1117 merge_config_ref(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1119 merge_global(conf
, xconf
);
1120 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1121 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1122 merge_ifaces(conf
, xconf
, ref
);
1123 merge_tnbrs(conf
, xconf
, ref
);
1124 merge_nbrps(conf
, xconf
, ref
);
1125 merge_l2vpns(conf
, xconf
, ref
);
1126 if (ref
&& *ref
== xconf
)
1132 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1134 merge_config_ref(conf
, xconf
, NULL
);
1138 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1140 /* change of router-id requires resetting all neighborships */
1141 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1142 if (ldpd_process
== PROC_LDP_ENGINE
) {
1143 ldpe_reset_nbrs(AF_INET
);
1144 ldpe_reset_nbrs(AF_INET6
);
1145 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1146 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1147 if_update_all(AF_UNSPEC
);
1148 tnbr_update_all(AF_UNSPEC
);
1151 conf
->rtr_id
= xconf
->rtr_id
;
1154 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1155 conf
->lhello_interval
= xconf
->lhello_interval
;
1156 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1157 conf
->thello_interval
= xconf
->thello_interval
;
1159 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1160 if (ldpd_process
== PROC_LDP_ENGINE
)
1161 ldpe_reset_ds_nbrs();
1162 conf
->trans_pref
= xconf
->trans_pref
;
1165 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1166 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1167 if (ldpd_process
== PROC_LDP_ENGINE
)
1168 ldpe_reset_ds_nbrs();
1171 conf
->flags
= xconf
->flags
;
1175 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1177 int egress_label_changed
= 0;
1178 int update_sockets
= 0;
1180 if (af_conf
->keepalive
!= xa
->keepalive
) {
1181 af_conf
->keepalive
= xa
->keepalive
;
1182 if (ldpd_process
== PROC_LDP_ENGINE
)
1183 ldpe_stop_init_backoff(af
);
1186 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1187 af_conf
->lhello_interval
= xa
->lhello_interval
;
1188 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1189 af_conf
->thello_interval
= xa
->thello_interval
;
1192 if (ldpd_process
== PROC_LDP_ENGINE
&&
1193 (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1194 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1195 ldpe_remove_dynamic_tnbrs(af
);
1197 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1198 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1200 /* need to set/unset IPV6_MINHOPCOUNT */
1202 else if (ldpd_process
== PROC_LDP_ENGINE
)
1203 /* for LDPv4 just resetting the neighbors is enough */
1204 ldpe_reset_nbrs(af
);
1207 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1208 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1209 egress_label_changed
= 1;
1211 af_conf
->flags
= xa
->flags
;
1213 if (egress_label_changed
) {
1214 switch (ldpd_process
) {
1215 case PROC_LDE_ENGINE
:
1216 lde_change_egress_label(af
, af_conf
->flags
&
1224 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1225 af_conf
->trans_addr
= xa
->trans_addr
;
1229 if (ldpd_process
== PROC_MAIN
&& iev_ldpe
&& update_sockets
)
1230 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
, 0, -1,
1235 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1237 struct iface
*iface
, *itmp
, *xi
;
1239 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1240 /* find deleted interfaces */
1241 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1242 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1244 switch (ldpd_process
) {
1245 case PROC_LDE_ENGINE
:
1247 case PROC_LDP_ENGINE
:
1257 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1258 /* find new interfaces */
1259 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1260 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1261 RB_INSERT(iface_head
, &conf
->iface_tree
, xi
);
1263 if (ldpd_process
== PROC_MAIN
) {
1264 QOBJ_REG (xi
, iface
);
1265 /* resend addresses to activate new interfaces */
1266 kif_redistribute(xi
->name
);
1271 /* update existing interfaces */
1272 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1273 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1274 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1275 if (ref
&& *ref
== xi
)
1282 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1284 if (ia
->enabled
!= xi
->enabled
) {
1285 ia
->enabled
= xi
->enabled
;
1286 if (ldpd_process
== PROC_LDP_ENGINE
)
1287 if_update(ia
->iface
, ia
->af
);
1289 ia
->hello_holdtime
= xi
->hello_holdtime
;
1290 ia
->hello_interval
= xi
->hello_interval
;
1294 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1296 struct tnbr
*tnbr
, *ttmp
, *xt
;
1298 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1299 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1302 /* find deleted tnbrs */
1303 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1304 switch (ldpd_process
) {
1305 case PROC_LDE_ENGINE
:
1306 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1309 case PROC_LDP_ENGINE
:
1310 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1311 tnbr_check(conf
, tnbr
);
1314 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1321 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1322 /* find new tnbrs */
1323 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1324 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1325 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, xt
);
1327 switch (ldpd_process
) {
1328 case PROC_LDE_ENGINE
:
1330 case PROC_LDP_ENGINE
:
1334 QOBJ_REG (xt
, tnbr
);
1340 /* update existing tnbrs */
1341 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1342 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1343 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1344 if (ref
&& *ref
== xt
)
1351 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1353 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1357 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1358 /* find deleted nbrps */
1359 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1360 switch (ldpd_process
) {
1361 case PROC_LDE_ENGINE
:
1363 case PROC_LDP_ENGINE
:
1364 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1366 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1371 (ldp_af_global_get(&global
,
1372 nbr
->af
))->ldp_session_socket
,
1373 nbr
->af
, &nbr
->raddr
, NULL
);
1375 if (nbr_session_active_role(nbr
))
1376 nbr_establish_connection(nbr
);
1383 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1387 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1388 /* find new nbrps */
1389 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1390 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1391 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, xn
);
1393 switch (ldpd_process
) {
1394 case PROC_LDE_ENGINE
:
1396 case PROC_LDP_ENGINE
:
1397 nbr
= nbr_find_ldpid(xn
->lsr_id
.s_addr
);
1399 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1401 if (pfkey_establish(nbr
, xn
) == -1)
1402 fatalx("pfkey setup failed");
1405 (ldp_af_global_get(&global
,
1406 nbr
->af
))->ldp_session_socket
,
1407 nbr
->af
, &nbr
->raddr
,
1410 if (nbr_session_active_role(nbr
))
1411 nbr_establish_connection(nbr
);
1415 QOBJ_REG (xn
, nbr_params
);
1421 /* update existing nbrps */
1422 if (nbrp
->flags
!= xn
->flags
||
1423 nbrp
->keepalive
!= xn
->keepalive
||
1424 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1425 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1426 nbrp
->auth
.method
!= xn
->auth
.method
||
1427 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1432 nbrp
->keepalive
= xn
->keepalive
;
1433 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1434 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1435 nbrp
->auth
.method
= xn
->auth
.method
;
1436 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1437 sizeof(nbrp
->auth
.md5key
));
1438 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1439 nbrp
->flags
= xn
->flags
;
1441 if (ldpd_process
== PROC_LDP_ENGINE
) {
1442 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1443 if (nbr
&& nbrp_changed
) {
1444 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1447 if (pfkey_establish(nbr
, nbrp
) == -1)
1448 fatalx("pfkey setup failed");
1450 sock_set_md5sig((ldp_af_global_get(&global
,
1451 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1452 &nbr
->raddr
, nbrp
->auth
.md5key
);
1454 if (nbr_session_active_role(nbr
))
1455 nbr_establish_connection(nbr
);
1458 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1459 if (ref
&& *ref
== xn
)
1466 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1468 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1469 struct l2vpn_if
*lif
;
1470 struct l2vpn_pw
*pw
;
1472 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1473 /* find deleted l2vpns */
1474 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1475 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1477 switch (ldpd_process
) {
1478 case PROC_LDE_ENGINE
:
1481 case PROC_LDP_ENGINE
:
1482 ldpe_l2vpn_exit(l2vpn
);
1485 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1487 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1489 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1497 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1498 /* find new l2vpns */
1499 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1500 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1501 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, xl
);
1503 switch (ldpd_process
) {
1504 case PROC_LDE_ENGINE
:
1507 case PROC_LDP_ENGINE
:
1508 ldpe_l2vpn_init(xl
);
1511 QOBJ_REG (xl
, l2vpn
);
1517 /* update existing l2vpns */
1518 merge_l2vpn(conf
, l2vpn
, xl
, ref
);
1519 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1520 if (ref
&& *ref
== xl
)
1527 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
, void **ref
)
1529 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1530 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1532 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1533 struct l2vpn_pw_head pw_aux_list
;
1534 int previous_pw_type
, previous_mtu
;
1536 previous_pw_type
= l2vpn
->pw_type
;
1537 previous_mtu
= l2vpn
->mtu
;
1539 /* merge intefaces */
1540 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1541 /* find deleted interfaces */
1542 if ((xf
= l2vpn_if_find_name(xl
, lif
->ifname
)) == NULL
) {
1543 if (ldpd_process
== PROC_MAIN
)
1545 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1549 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1550 /* find new interfaces */
1551 if ((lif
= l2vpn_if_find_name(l2vpn
, xf
->ifname
)) == NULL
) {
1552 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1553 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, xf
);
1555 if (ldpd_process
== PROC_MAIN
)
1556 QOBJ_REG (xf
, l2vpn_if
);
1560 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1561 if (ref
&& *ref
== xf
)
1566 /* merge active pseudowires */
1567 RB_INIT(&pw_aux_list
);
1568 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1569 /* find deleted active pseudowires */
1570 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1571 switch (ldpd_process
) {
1572 case PROC_LDE_ENGINE
:
1575 case PROC_LDP_ENGINE
:
1576 ldpe_l2vpn_pw_exit(pw
);
1583 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1587 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1588 /* find new active pseudowires */
1589 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1590 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1591 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, xp
);
1594 switch (ldpd_process
) {
1595 case PROC_LDE_ENGINE
:
1598 case PROC_LDP_ENGINE
:
1599 ldpe_l2vpn_pw_init(xp
);
1602 QOBJ_REG (xp
, l2vpn_pw
);
1608 /* update existing active pseudowire */
1609 if (pw
->af
!= xp
->af
||
1610 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1615 /* changes that require a session restart */
1616 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1617 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1622 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1623 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1624 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1625 reinstall_pwfec
= 1;
1627 reinstall_pwfec
= 0;
1629 /* check if the pseudowire should be disabled */
1630 if (xp
->lsr_id
.s_addr
== INADDR_ANY
|| xp
->pwid
== 0) {
1633 reinstall_pwfec
= 0;
1635 switch (ldpd_process
) {
1636 case PROC_LDE_ENGINE
:
1639 case PROC_LDP_ENGINE
:
1640 ldpe_l2vpn_pw_exit(pw
);
1646 /* remove from active list */
1647 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1648 RB_INSERT(l2vpn_pw_head
, &pw_aux_list
, pw
);
1651 if (ldpd_process
== PROC_LDP_ENGINE
) {
1653 ldpe_l2vpn_pw_exit(pw
);
1655 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1656 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1657 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1660 if (ldpd_process
== PROC_LDE_ENGINE
&&
1661 !reset_nbr
&& reinstall_pwfec
)
1663 pw
->lsr_id
= xp
->lsr_id
;
1665 pw
->addr
= xp
->addr
;
1666 pw
->pwid
= xp
->pwid
;
1667 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1668 pw
->ifindex
= xp
->ifindex
;
1669 if (xp
->flags
& F_PW_CWORD_CONF
)
1670 pw
->flags
|= F_PW_CWORD_CONF
;
1672 pw
->flags
&= ~F_PW_CWORD_CONF
;
1673 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1674 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1676 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1677 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1678 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1680 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1681 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1682 ldpe_l2vpn_pw_init(pw
);
1683 if (ldpd_process
== PROC_LDE_ENGINE
&&
1684 !reset_nbr
&& reinstall_pwfec
) {
1685 l2vpn
->pw_type
= xl
->pw_type
;
1686 l2vpn
->mtu
= xl
->mtu
;
1688 l2vpn
->pw_type
= previous_pw_type
;
1689 l2vpn
->mtu
= previous_mtu
;
1692 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1693 if (ref
&& *ref
== xp
)
1698 /* merge inactive pseudowires */
1699 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1700 /* find deleted inactive pseudowires */
1701 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1702 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1703 if (ldpd_process
== PROC_MAIN
)
1708 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1709 /* find new inactive pseudowires */
1710 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1711 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1712 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, xp
);
1714 if (ldpd_process
== PROC_MAIN
)
1715 QOBJ_REG (xp
, l2vpn_pw
);
1719 /* update existing inactive pseudowire */
1720 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1722 pw
->addr
= xp
->addr
;
1723 pw
->pwid
= xp
->pwid
;
1724 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1725 pw
->ifindex
= xp
->ifindex
;
1726 pw
->flags
= xp
->flags
;
1728 /* check if the pseudowire should be activated */
1729 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0) {
1730 /* remove from inactive list */
1731 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1732 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1734 switch (ldpd_process
) {
1735 case PROC_LDE_ENGINE
:
1738 case PROC_LDP_ENGINE
:
1739 ldpe_l2vpn_pw_init(pw
);
1746 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1747 if (ref
&& *ref
== xp
)
1752 /* insert pseudowires that were disabled in the inactive list */
1753 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &pw_aux_list
, ptmp
) {
1754 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1755 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1758 l2vpn
->pw_type
= xl
->pw_type
;
1759 l2vpn
->mtu
= xl
->mtu
;
1760 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1761 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1765 config_new_empty(void)
1767 struct ldpd_conf
*xconf
;
1769 xconf
= calloc(1, sizeof(*xconf
));
1773 RB_INIT(&xconf
->iface_tree
);
1774 RB_INIT(&xconf
->tnbr_tree
);
1775 RB_INIT(&xconf
->nbrp_tree
);
1776 RB_INIT(&xconf
->l2vpn_tree
);
1782 config_clear(struct ldpd_conf
*conf
)
1784 struct ldpd_conf
*xconf
;
1787 * Merge current config with an empty config, this will deactivate
1788 * and deallocate all the interfaces, pseudowires and so on. Before
1789 * merging, copy the router-id and other variables to avoid some
1790 * unnecessary operations, like trying to reset the neighborships.
1792 xconf
= config_new_empty();
1793 xconf
->ipv4
= conf
->ipv4
;
1794 xconf
->ipv6
= conf
->ipv6
;
1795 xconf
->rtr_id
= conf
->rtr_id
;
1796 xconf
->trans_pref
= conf
->trans_pref
;
1797 xconf
->flags
= conf
->flags
;
1798 merge_config(conf
, xconf
);
1799 if (ldpd_process
== PROC_MAIN
)