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>
46 static void ldpd_shutdown(void);
47 static pid_t
start_child(enum ldpd_process
, char *, int, int,
48 const char *, const char *, const char *);
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
*, void **);
57 static void ldp_config_reset_main(struct ldpd_conf
*, void **);
58 static void ldp_config_reset_af(struct ldpd_conf
*, int, void **);
59 static void merge_config_ref(struct ldpd_conf
*, struct ldpd_conf
*, void **);
60 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
61 static void merge_af(int, struct ldpd_af_conf
*,
62 struct ldpd_af_conf
*);
63 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*, void **);
64 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
65 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*, void **);
66 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*, void **);
67 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*, void **);
68 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
69 struct l2vpn
*, void **);
71 DEFINE_QOBJ_TYPE(iface
)
72 DEFINE_QOBJ_TYPE(tnbr
)
73 DEFINE_QOBJ_TYPE(nbr_params
)
74 DEFINE_QOBJ_TYPE(l2vpn_if
)
75 DEFINE_QOBJ_TYPE(l2vpn_pw
)
76 DEFINE_QOBJ_TYPE(l2vpn
)
77 DEFINE_QOBJ_TYPE(ldpd_conf
)
79 struct ldpd_global global
;
80 struct ldpd_conf
*ldpd_conf
;
82 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
83 static struct imsgev
*iev_lde
, *iev_lde_sync
;
84 static pid_t ldpe_pid
;
87 #define LDP_DEFAULT_CONFIG "ldpd.conf"
88 #define LDP_VTY_PORT 2612
90 /* Master of threads. */
91 struct thread_master
*master
;
94 static zebra_capabilities_t _caps_p
[] =
100 struct zebra_privs_t ldpd_privs
=
102 #if defined(FRR_USER) && defined(FRR_GROUP)
106 #if defined(VTY_GROUP)
107 .vty_group
= VTY_GROUP
,
110 .cap_num_p
= array_size(_caps_p
),
114 /* CTL Socket path */
115 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
118 #define OPTION_CTLSOCK 1001
119 static struct option longopts
[] =
121 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
125 /* SIGHUP handler. */
129 log_info("SIGHUP received");
132 /* SIGINT / SIGTERM handler. */
136 log_info("SIGINT received");
140 /* SIGUSR1 handler. */
147 static struct quagga_signal_t ldp_signals
[] =
167 FRR_DAEMON_INFO(ldpd
, LDP
,
168 .vty_port
= LDP_VTY_PORT
,
170 .proghelp
= "Implementation of the LDP protocol.",
172 .signals
= ldp_signals
,
173 .n_signals
= array_size(ldp_signals
),
175 .privs
= &ldpd_privs
,
179 main(int argc
, char *argv
[])
182 int lflag
= 0, eflag
= 0;
183 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
184 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
185 char *ctl_sock_custom_path
= NULL
;
187 const char *user
= NULL
;
188 const char *group
= NULL
;
190 ldpd_process
= PROC_MAIN
;
192 saved_argv0
= argv
[0];
193 if (saved_argv0
== NULL
)
194 saved_argv0
= (char *)"ldpd";
196 frr_preinit(&ldpd_di
, argc
, argv
);
197 frr_opt_add("LE", longopts
,
198 " --ctl_socket Override ctl socket path\n");
203 opt
= frr_getopt(argc
, argv
, NULL
);
212 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
218 * LDPD_SOCKET configured as relative path
219 * during config? Should really never happen for
222 ctl_sock_name
= (char *)LDPD_SOCKET
;
223 ctl_sock_custom_path
= optarg
;
224 strlcpy(ctl_sock_path
, ctl_sock_custom_path
,
225 sizeof(ctl_sock_path
));
226 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
227 strlcat(ctl_sock_path
, ctl_sock_name
,
228 sizeof(ctl_sock_path
));
242 user
= ldpd_privs
.user
;
243 group
= ldpd_privs
.group
;
247 if (argc
> 0 || (lflag
&& eflag
))
250 /* check for root privileges */
251 if (geteuid() != 0) {
253 perror(ldpd_di
.progname
);
257 zlog_default
= openzlog(ldpd_di
.progname
, ZLOG_LDP
, 0,
258 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
263 ldpe(user
, group
, ctl_sock_path
);
265 master
= thread_master_create();
268 vty_config_lockless ();
275 /* Get configuration file. */
276 ldpd_conf
= config_new_empty();
277 ldp_config_reset_main(ldpd_conf
, NULL
);
281 QOBJ_REG (ldpd_conf
, ldpd_conf
);
283 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
285 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
286 pipe_parent2ldpe_sync
) == -1)
288 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
290 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
291 pipe_parent2lde_sync
) == -1)
293 sock_set_nonblock(pipe_parent2ldpe
[0]);
294 sock_set_cloexec(pipe_parent2ldpe
[0]);
295 sock_set_nonblock(pipe_parent2ldpe
[1]);
296 sock_set_cloexec(pipe_parent2ldpe
[1]);
297 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
298 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
299 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
300 sock_set_nonblock(pipe_parent2lde
[0]);
301 sock_set_cloexec(pipe_parent2lde
[0]);
302 sock_set_nonblock(pipe_parent2lde
[1]);
303 sock_set_cloexec(pipe_parent2lde
[1]);
304 sock_set_nonblock(pipe_parent2lde_sync
[0]);
305 sock_set_cloexec(pipe_parent2lde_sync
[0]);
306 sock_set_cloexec(pipe_parent2lde_sync
[1]);
309 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
310 pipe_parent2lde
[1], pipe_parent2lde_sync
[1],
311 user
, group
, ctl_sock_custom_path
);
312 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
313 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1],
314 user
, group
, ctl_sock_custom_path
);
316 /* drop privileges */
317 zprivs_init(&ldpd_privs
);
319 /* setup signal handler */
320 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
323 ldp_zebra_init(master
);
325 /* setup pipes to children */
326 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
327 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
328 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
329 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
331 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
332 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
333 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
334 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
335 iev_ldpe
->handler_write
= ldp_write_handler
;
337 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
338 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
339 iev_ldpe_sync
->ev_read
= thread_add_read(master
,
340 iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
);
341 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
343 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
344 iev_lde
->handler_read
= main_dispatch_lde
;
345 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
346 iev_lde
, iev_lde
->ibuf
.fd
);
347 iev_lde
->handler_write
= ldp_write_handler
;
349 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
350 iev_lde_sync
->handler_read
= main_dispatch_lde
;
351 iev_lde_sync
->ev_read
= thread_add_read(master
,
352 iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
);
353 iev_lde_sync
->handler_write
= ldp_write_handler
;
355 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
356 fatal("could not establish imsg links");
357 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
359 main_imsg_send_config(ldpd_conf
);
361 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
362 main_imsg_send_net_sockets(AF_INET
);
363 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
364 main_imsg_send_net_sockets(AF_INET6
);
379 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
380 close(iev_ldpe
->ibuf
.fd
);
381 msgbuf_clear(&iev_lde
->ibuf
.w
);
382 close(iev_lde
->ibuf
.fd
);
384 config_clear(ldpd_conf
);
386 log_debug("waiting for children to terminate");
390 if (errno
!= EINTR
&& errno
!= ECHILD
)
392 } else if (WIFSIGNALED(status
))
393 log_warnx("%s terminated; signal %d",
394 (pid
== lde_pid
) ? "label decision engine" :
395 "ldp engine", WTERMSIG(status
));
396 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
401 log_info("terminating");
408 zprivs_terminate(&ldpd_privs
);
409 thread_master_free(master
);
410 closezlog(zlog_default
);
416 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
,
417 const char *user
, const char *group
, const char *ctl_sock_custom_path
)
423 switch (pid
= fork()) {
425 fatal("cannot fork");
434 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
435 fatal("cannot setup imsg async fd");
436 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
437 fatal("cannot setup imsg sync fd");
439 argv
[argc
++] = argv0
;
442 fatalx("Can not start main process");
443 case PROC_LDE_ENGINE
:
444 argv
[argc
++] = (char *)"-L";
446 case PROC_LDP_ENGINE
:
447 argv
[argc
++] = (char *)"-E";
451 argv
[argc
++] = (char *)"-u";
452 argv
[argc
++] = (char *)user
;
455 argv
[argc
++] = (char *)"-g";
456 argv
[argc
++] = (char *)group
;
458 if (ctl_sock_custom_path
) {
459 argv
[argc
++] = (char *)"--ctl_socket";
460 argv
[argc
++] = (char *)ctl_sock_custom_path
;
471 main_dispatch_ldpe(struct thread
*thread
)
473 struct imsgev
*iev
= THREAD_ARG(thread
);
474 struct imsgbuf
*ibuf
= &iev
->ibuf
;
482 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
483 fatal("imsg_read error");
484 if (n
== 0) /* connection closed */
488 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
494 switch (imsg
.hdr
.type
) {
496 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
498 case IMSG_REQUEST_SOCKETS
:
500 main_imsg_send_net_sockets(af
);
503 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
504 sizeof(struct acl_check
))
505 fatalx("IMSG_ACL_CHECK imsg with wrong len");
506 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
509 log_debug("%s: error handling imsg %d", __func__
,
518 /* this pipe is dead, so remove the event handlers and exit */
519 THREAD_READ_OFF(iev
->ev_read
);
520 THREAD_WRITE_OFF(iev
->ev_write
);
525 kill(lde_pid
, SIGTERM
);
533 main_dispatch_lde(struct thread
*thread
)
535 struct imsgev
*iev
= THREAD_ARG(thread
);
536 struct imsgbuf
*ibuf
= &iev
->ibuf
;
543 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
544 fatal("imsg_read error");
545 if (n
== 0) /* connection closed */
549 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
555 switch (imsg
.hdr
.type
) {
557 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
559 case IMSG_KLABEL_CHANGE
:
560 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
561 sizeof(struct kroute
))
562 fatalx("invalid size of IMSG_KLABEL_CHANGE");
563 if (kr_change(imsg
.data
))
564 log_warnx("%s: error changing route", __func__
);
566 case IMSG_KLABEL_DELETE
:
567 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
568 sizeof(struct kroute
))
569 fatalx("invalid size of IMSG_KLABEL_DELETE");
570 if (kr_delete(imsg
.data
))
571 log_warnx("%s: error deleting route", __func__
);
573 case IMSG_KPWLABEL_CHANGE
:
574 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
576 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
577 if (kmpw_set(imsg
.data
))
578 log_warnx("%s: error changing pseudowire",
581 case IMSG_KPWLABEL_DELETE
:
582 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
584 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
585 if (kmpw_unset(imsg
.data
))
586 log_warnx("%s: error unsetting pseudowire",
590 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
591 sizeof(struct acl_check
))
592 fatalx("IMSG_ACL_CHECK imsg with wrong len");
593 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
596 log_debug("%s: error handling imsg %d", __func__
,
605 /* this pipe is dead, so remove the event handlers and exit */
606 THREAD_READ_OFF(iev
->ev_read
);
607 THREAD_WRITE_OFF(iev
->ev_write
);
612 kill(ldpe_pid
, SIGTERM
);
620 ldp_write_handler(struct thread
*thread
)
622 struct imsgev
*iev
= THREAD_ARG(thread
);
623 struct imsgbuf
*ibuf
= &iev
->ibuf
;
626 iev
->ev_write
= NULL
;
628 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
629 fatal("msgbuf_write");
631 /* this pipe is dead, so remove the event handlers */
632 THREAD_READ_OFF(iev
->ev_read
);
633 THREAD_WRITE_OFF(iev
->ev_write
);
643 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
645 if (iev_ldpe
== NULL
)
647 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
651 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
653 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
657 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
659 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
661 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
663 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
669 imsg_event_add(struct imsgev
*iev
)
671 if (iev
->handler_read
)
672 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
675 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
676 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
681 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
682 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
686 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
687 pid
, fd
, data
, datalen
)) != -1)
693 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
695 ibuf_close(&eb
->wbuf
, buf
);
700 evbuf_event_add(struct evbuf
*eb
)
703 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
708 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
711 msgbuf_init(&eb
->wbuf
);
713 eb
->handler
= handler
;
718 evbuf_clear(struct evbuf
*eb
)
720 THREAD_WRITE_OFF(eb
->ev
);
721 msgbuf_clear(&eb
->wbuf
);
726 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
728 int pipe_ldpe2lde
[2];
730 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
732 sock_set_nonblock(pipe_ldpe2lde
[0]);
733 sock_set_nonblock(pipe_ldpe2lde
[1]);
735 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
738 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
746 main_imsg_send_net_sockets(int af
)
748 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
751 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
752 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
753 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
754 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
758 main_imsg_send_net_socket(int af
, enum socket_type type
)
762 fd
= ldp_create_socket(af
, type
);
764 log_warnx("%s: failed to create %s socket for address-family "
765 "%s", __func__
, socket_name(type
), af_name(af
));
769 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
774 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
775 union ldpd_addr
*addr
, uint8_t prefixlen
)
779 struct acl_check acl_check
;
781 if (acl_name
[0] == '\0')
782 return FILTER_PERMIT
;
785 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
787 acl_check
.addr
= *addr
;
788 acl_check
.prefixlen
= prefixlen
;
790 /* send (blocking) */
791 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
793 imsg_flush(&iev
->ibuf
);
795 /* receive (blocking) and parse result */
796 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
797 fatal("imsg_read error");
798 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
800 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
801 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
802 fatalx("ldp_acl_request: invalid response");
804 return (*((int *)imsg
.data
));
808 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
810 struct access_list
*alist
;
811 struct prefix prefix
;
814 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
816 result
= FILTER_DENY
;
818 prefix
.family
= acl_check
->af
;
819 switch (prefix
.family
) {
821 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
824 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
827 fatalx("ldp_acl_reply: unknown af");
829 prefix
.prefixlen
= acl_check
->prefixlen
;
830 result
= access_list_apply(alist
, &prefix
);
833 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
837 struct ldpd_af_conf
*
838 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
842 return (&xconf
->ipv4
);
844 return (&xconf
->ipv6
);
846 fatalx("ldp_af_conf_get: unknown af");
850 struct ldpd_af_global
*
851 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
855 return (&xglobal
->ipv4
);
857 return (&xglobal
->ipv6
);
859 fatalx("ldp_af_global_get: unknown af");
864 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
866 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
867 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
871 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
873 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
874 return (xconf
->rtr_id
.s_addr
);
876 return (global
.rtr_id
.s_addr
);
880 main_imsg_send_config(struct ldpd_conf
*xconf
)
884 struct nbr_params
*nbrp
;
886 struct l2vpn_if
*lif
;
889 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
890 sizeof(*xconf
)) == -1)
893 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
894 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
895 sizeof(*iface
)) == -1)
899 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
900 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
901 sizeof(*tnbr
)) == -1)
905 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
906 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
907 sizeof(*nbrp
)) == -1)
911 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
912 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
913 sizeof(*l2vpn
)) == -1)
916 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
917 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
921 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
922 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
926 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
927 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
933 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
940 ldp_reload_ref(struct ldpd_conf
*xconf
, void **ref
)
942 ldp_config_normalize(xconf
, ref
);
944 if (main_imsg_send_config(xconf
) == -1)
947 merge_config_ref(ldpd_conf
, xconf
, ref
);
953 ldp_reload(struct ldpd_conf
*xconf
)
955 return ldp_reload_ref(xconf
, NULL
);
959 ldp_config_normalize(struct ldpd_conf
*xconf
, void **ref
)
964 if (!(xconf
->flags
& F_LDPD_ENABLED
))
965 ldp_config_reset_main(xconf
, ref
);
967 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
968 ldp_config_reset_af(xconf
, AF_INET
, ref
);
969 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
970 ldp_config_reset_af(xconf
, AF_INET6
, ref
);
973 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
974 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
975 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
979 pw
->addr
.v4
= pw
->lsr_id
;
981 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
982 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
986 pw
->addr
.v4
= pw
->lsr_id
;
992 ldp_config_reset_main(struct ldpd_conf
*conf
, void **ref
)
995 struct nbr_params
*nbrp
;
997 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
998 if (ref
&& *ref
== iface
)
1000 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1004 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1005 if (ref
&& *ref
== nbrp
)
1007 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1011 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1012 ldp_config_reset_af(conf
, AF_INET
, ref
);
1013 ldp_config_reset_af(conf
, AF_INET6
, ref
);
1014 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1015 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1016 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1017 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1018 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1023 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
, void **ref
)
1025 struct ldpd_af_conf
*af_conf
;
1026 struct iface
*iface
;
1027 struct iface_af
*ia
;
1028 struct tnbr
*tnbr
, *ttmp
;
1030 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1031 ia
= iface_af_get(iface
, af
);
1035 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1039 if (ref
&& *ref
== tnbr
)
1041 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1045 af_conf
= ldp_af_conf_get(conf
, af
);
1046 af_conf
->keepalive
= 180;
1047 af_conf
->lhello_holdtime
= 0;
1048 af_conf
->lhello_interval
= 0;
1049 af_conf
->thello_holdtime
= 0;
1050 af_conf
->thello_interval
= 0;
1051 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1056 ldp_dup_config_ref(struct ldpd_conf
*conf
, void **ref
)
1058 struct ldpd_conf
*xconf
;
1059 struct iface
*iface
, *xi
;
1060 struct tnbr
*tnbr
, *xt
;
1061 struct nbr_params
*nbrp
, *xn
;
1062 struct l2vpn
*l2vpn
, *xl
;
1063 struct l2vpn_if
*lif
, *xf
;
1064 struct l2vpn_pw
*pw
, *xp
;
1066 #define COPY(a, b) do { \
1067 a = calloc(1, sizeof(*a)); \
1071 if (ref && *ref == b) *ref = a; \
1075 RB_INIT(&xconf
->iface_tree
);
1076 RB_INIT(&xconf
->tnbr_tree
);
1077 RB_INIT(&xconf
->nbrp_tree
);
1078 RB_INIT(&xconf
->l2vpn_tree
);
1080 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1082 xi
->ipv4
.iface
= xi
;
1083 xi
->ipv6
.iface
= xi
;
1084 RB_INSERT(iface_head
, &xconf
->iface_tree
, xi
);
1086 RB_FOREACH(tnbr
, tnbr_head
, &conf
->tnbr_tree
) {
1088 RB_INSERT(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1090 RB_FOREACH(nbrp
, nbrp_head
, &conf
->nbrp_tree
) {
1092 RB_INSERT(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1094 RB_FOREACH(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
) {
1096 RB_INIT(&xl
->if_tree
);
1097 RB_INIT(&xl
->pw_tree
);
1098 RB_INIT(&xl
->pw_inactive_tree
);
1099 RB_INSERT(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1101 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1104 RB_INSERT(l2vpn_if_head
, &xl
->if_tree
, xf
);
1106 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1109 RB_INSERT(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1111 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1114 RB_INSERT(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1123 ldp_dup_config(struct ldpd_conf
*conf
)
1125 return ldp_dup_config_ref(conf
, NULL
);
1129 ldp_clear_config(struct ldpd_conf
*xconf
)
1131 struct iface
*iface
;
1133 struct nbr_params
*nbrp
;
1134 struct l2vpn
*l2vpn
;
1136 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1137 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1140 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1141 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1144 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1145 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1148 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1149 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1157 merge_config_ref(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1159 merge_global(conf
, xconf
);
1160 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1161 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1162 merge_ifaces(conf
, xconf
, ref
);
1163 merge_tnbrs(conf
, xconf
, ref
);
1164 merge_nbrps(conf
, xconf
, ref
);
1165 merge_l2vpns(conf
, xconf
, ref
);
1166 if (ref
&& *ref
== xconf
)
1172 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1174 merge_config_ref(conf
, xconf
, NULL
);
1178 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1180 /* change of router-id requires resetting all neighborships */
1181 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1182 if (ldpd_process
== PROC_LDP_ENGINE
) {
1183 ldpe_reset_nbrs(AF_UNSPEC
);
1184 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1185 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1186 if_update_all(AF_UNSPEC
);
1187 tnbr_update_all(AF_UNSPEC
);
1190 conf
->rtr_id
= xconf
->rtr_id
;
1193 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1194 conf
->lhello_interval
= xconf
->lhello_interval
;
1195 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1196 conf
->thello_interval
= xconf
->thello_interval
;
1198 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1199 if (ldpd_process
== PROC_LDP_ENGINE
)
1200 ldpe_reset_ds_nbrs();
1201 conf
->trans_pref
= xconf
->trans_pref
;
1204 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1205 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1206 if (ldpd_process
== PROC_LDP_ENGINE
)
1207 ldpe_reset_ds_nbrs();
1210 conf
->flags
= xconf
->flags
;
1214 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1216 int stop_init_backoff
= 0;
1217 int remove_dynamic_tnbrs
= 0;
1218 int change_egress_label
= 0;
1219 int reset_nbrs_ipv4
= 0;
1221 int update_sockets
= 0;
1224 if (af_conf
->keepalive
!= xa
->keepalive
) {
1225 af_conf
->keepalive
= xa
->keepalive
;
1226 stop_init_backoff
= 1;
1228 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1229 af_conf
->lhello_interval
= xa
->lhello_interval
;
1230 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1231 af_conf
->thello_interval
= xa
->thello_interval
;
1234 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1235 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1236 remove_dynamic_tnbrs
= 1;
1237 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1238 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1240 /* need to set/unset IPV6_MINHOPCOUNT */
1243 /* for LDPv4 just resetting the neighbors is enough */
1244 reset_nbrs_ipv4
= 1;
1246 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1247 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1248 change_egress_label
= 1;
1249 af_conf
->flags
= xa
->flags
;
1251 /* update the transport address */
1252 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1253 af_conf
->trans_addr
= xa
->trans_addr
;
1258 if (strcmp(af_conf
->acl_label_advertise_to
,
1259 xa
->acl_label_advertise_to
) ||
1260 strcmp(af_conf
->acl_label_advertise_for
,
1261 xa
->acl_label_advertise_for
) ||
1262 strcmp(af_conf
->acl_label_accept_from
,
1263 xa
->acl_label_accept_from
) ||
1264 strcmp(af_conf
->acl_label_accept_for
,
1265 xa
->acl_label_accept_for
))
1267 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1268 remove_dynamic_tnbrs
= 1;
1269 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1270 change_egress_label
= 1;
1271 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1272 sizeof(af_conf
->acl_thello_accept_from
));
1273 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1274 sizeof(af_conf
->acl_label_allocate_for
));
1275 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1276 sizeof(af_conf
->acl_label_advertise_to
));
1277 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1278 sizeof(af_conf
->acl_label_advertise_for
));
1279 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1280 sizeof(af_conf
->acl_label_accept_from
));
1281 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1282 sizeof(af_conf
->acl_label_accept_for
));
1283 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1284 sizeof(af_conf
->acl_label_expnull_for
));
1286 /* apply the new configuration */
1287 switch (ldpd_process
) {
1288 case PROC_LDE_ENGINE
:
1289 if (change_egress_label
)
1290 lde_change_egress_label(af
);
1292 case PROC_LDP_ENGINE
:
1293 if (stop_init_backoff
)
1294 ldpe_stop_init_backoff(af
);
1295 if (remove_dynamic_tnbrs
)
1296 ldpe_remove_dynamic_tnbrs(af
);
1298 ldpe_reset_nbrs(AF_UNSPEC
);
1299 else if (reset_nbrs_ipv4
)
1300 ldpe_reset_nbrs(AF_INET
);
1303 if (update_sockets
&& iev_ldpe
)
1304 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1311 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1313 struct iface
*iface
, *itmp
, *xi
;
1315 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1316 /* find deleted interfaces */
1317 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1318 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1320 switch (ldpd_process
) {
1321 case PROC_LDE_ENGINE
:
1323 case PROC_LDP_ENGINE
:
1333 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1334 /* find new interfaces */
1335 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1336 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1337 RB_INSERT(iface_head
, &conf
->iface_tree
, xi
);
1339 if (ldpd_process
== PROC_MAIN
) {
1340 QOBJ_REG (xi
, iface
);
1341 /* resend addresses to activate new interfaces */
1342 kif_redistribute(xi
->name
);
1347 /* update existing interfaces */
1348 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1349 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1350 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1351 if (ref
&& *ref
== xi
)
1358 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1360 if (ia
->enabled
!= xi
->enabled
) {
1361 ia
->enabled
= xi
->enabled
;
1362 if (ldpd_process
== PROC_LDP_ENGINE
)
1363 if_update(ia
->iface
, ia
->af
);
1365 ia
->hello_holdtime
= xi
->hello_holdtime
;
1366 ia
->hello_interval
= xi
->hello_interval
;
1370 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1372 struct tnbr
*tnbr
, *ttmp
, *xt
;
1374 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1375 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1378 /* find deleted tnbrs */
1379 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1380 switch (ldpd_process
) {
1381 case PROC_LDE_ENGINE
:
1382 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1385 case PROC_LDP_ENGINE
:
1386 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1387 tnbr_check(conf
, tnbr
);
1390 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1397 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1398 /* find new tnbrs */
1399 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1400 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1401 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, xt
);
1403 switch (ldpd_process
) {
1404 case PROC_LDE_ENGINE
:
1406 case PROC_LDP_ENGINE
:
1410 QOBJ_REG (xt
, tnbr
);
1416 /* update existing tnbrs */
1417 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1418 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1419 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1420 if (ref
&& *ref
== xt
)
1427 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1429 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1433 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1434 /* find deleted nbrps */
1435 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1436 switch (ldpd_process
) {
1437 case PROC_LDE_ENGINE
:
1439 case PROC_LDP_ENGINE
:
1440 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1442 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1447 (ldp_af_global_get(&global
,
1448 nbr
->af
))->ldp_session_socket
,
1449 nbr
->af
, &nbr
->raddr
, NULL
);
1451 if (nbr_session_active_role(nbr
))
1452 nbr_establish_connection(nbr
);
1459 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1463 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1464 /* find new nbrps */
1465 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1466 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1467 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, xn
);
1469 switch (ldpd_process
) {
1470 case PROC_LDE_ENGINE
:
1472 case PROC_LDP_ENGINE
:
1473 nbr
= nbr_find_ldpid(xn
->lsr_id
.s_addr
);
1475 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1477 if (pfkey_establish(nbr
, xn
) == -1)
1478 fatalx("pfkey setup failed");
1481 (ldp_af_global_get(&global
,
1482 nbr
->af
))->ldp_session_socket
,
1483 nbr
->af
, &nbr
->raddr
,
1486 if (nbr_session_active_role(nbr
))
1487 nbr_establish_connection(nbr
);
1491 QOBJ_REG (xn
, nbr_params
);
1497 /* update existing nbrps */
1498 if (nbrp
->flags
!= xn
->flags
||
1499 nbrp
->keepalive
!= xn
->keepalive
||
1500 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1501 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1502 nbrp
->auth
.method
!= xn
->auth
.method
||
1503 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1508 nbrp
->keepalive
= xn
->keepalive
;
1509 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1510 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1511 nbrp
->auth
.method
= xn
->auth
.method
;
1512 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1513 sizeof(nbrp
->auth
.md5key
));
1514 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1515 nbrp
->flags
= xn
->flags
;
1517 if (ldpd_process
== PROC_LDP_ENGINE
) {
1518 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1519 if (nbr
&& nbrp_changed
) {
1520 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1523 if (pfkey_establish(nbr
, nbrp
) == -1)
1524 fatalx("pfkey setup failed");
1526 sock_set_md5sig((ldp_af_global_get(&global
,
1527 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1528 &nbr
->raddr
, nbrp
->auth
.md5key
);
1530 if (nbr_session_active_role(nbr
))
1531 nbr_establish_connection(nbr
);
1534 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1535 if (ref
&& *ref
== xn
)
1542 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1544 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1545 struct l2vpn_if
*lif
;
1546 struct l2vpn_pw
*pw
;
1548 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1549 /* find deleted l2vpns */
1550 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1551 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1553 switch (ldpd_process
) {
1554 case PROC_LDE_ENGINE
:
1557 case PROC_LDP_ENGINE
:
1558 ldpe_l2vpn_exit(l2vpn
);
1561 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1563 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1565 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1573 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1574 /* find new l2vpns */
1575 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1576 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1577 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, xl
);
1579 switch (ldpd_process
) {
1580 case PROC_LDE_ENGINE
:
1583 case PROC_LDP_ENGINE
:
1584 ldpe_l2vpn_init(xl
);
1587 QOBJ_REG (xl
, l2vpn
);
1593 /* update existing l2vpns */
1594 merge_l2vpn(conf
, l2vpn
, xl
, ref
);
1595 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1596 if (ref
&& *ref
== xl
)
1603 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
, void **ref
)
1605 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1606 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1608 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1609 struct l2vpn_pw_head pw_aux_list
;
1610 int previous_pw_type
, previous_mtu
;
1612 previous_pw_type
= l2vpn
->pw_type
;
1613 previous_mtu
= l2vpn
->mtu
;
1615 /* merge intefaces */
1616 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1617 /* find deleted interfaces */
1618 if ((xf
= l2vpn_if_find_name(xl
, lif
->ifname
)) == NULL
) {
1619 if (ldpd_process
== PROC_MAIN
)
1621 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1625 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1626 /* find new interfaces */
1627 if ((lif
= l2vpn_if_find_name(l2vpn
, xf
->ifname
)) == NULL
) {
1628 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1629 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, xf
);
1631 if (ldpd_process
== PROC_MAIN
)
1632 QOBJ_REG (xf
, l2vpn_if
);
1636 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1637 if (ref
&& *ref
== xf
)
1642 /* merge active pseudowires */
1643 RB_INIT(&pw_aux_list
);
1644 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1645 /* find deleted active pseudowires */
1646 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1647 switch (ldpd_process
) {
1648 case PROC_LDE_ENGINE
:
1651 case PROC_LDP_ENGINE
:
1652 ldpe_l2vpn_pw_exit(pw
);
1659 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1663 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1664 /* find new active pseudowires */
1665 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1666 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1667 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, xp
);
1670 switch (ldpd_process
) {
1671 case PROC_LDE_ENGINE
:
1674 case PROC_LDP_ENGINE
:
1675 ldpe_l2vpn_pw_init(xp
);
1678 QOBJ_REG (xp
, l2vpn_pw
);
1684 /* update existing active pseudowire */
1685 if (pw
->af
!= xp
->af
||
1686 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1691 /* changes that require a session restart */
1692 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1693 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1698 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1699 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1700 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1701 reinstall_pwfec
= 1;
1703 reinstall_pwfec
= 0;
1705 /* check if the pseudowire should be disabled */
1706 if (xp
->lsr_id
.s_addr
== INADDR_ANY
|| xp
->pwid
== 0) {
1709 reinstall_pwfec
= 0;
1711 switch (ldpd_process
) {
1712 case PROC_LDE_ENGINE
:
1715 case PROC_LDP_ENGINE
:
1716 ldpe_l2vpn_pw_exit(pw
);
1722 /* remove from active list */
1723 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1724 RB_INSERT(l2vpn_pw_head
, &pw_aux_list
, pw
);
1727 if (ldpd_process
== PROC_LDP_ENGINE
) {
1729 ldpe_l2vpn_pw_exit(pw
);
1731 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1732 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1733 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1736 if (ldpd_process
== PROC_LDE_ENGINE
&&
1737 !reset_nbr
&& reinstall_pwfec
)
1739 pw
->lsr_id
= xp
->lsr_id
;
1741 pw
->addr
= xp
->addr
;
1742 pw
->pwid
= xp
->pwid
;
1743 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1744 pw
->ifindex
= xp
->ifindex
;
1745 if (xp
->flags
& F_PW_CWORD_CONF
)
1746 pw
->flags
|= F_PW_CWORD_CONF
;
1748 pw
->flags
&= ~F_PW_CWORD_CONF
;
1749 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1750 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1752 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1753 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1754 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1756 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1757 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1758 ldpe_l2vpn_pw_init(pw
);
1759 if (ldpd_process
== PROC_LDE_ENGINE
&&
1760 !reset_nbr
&& reinstall_pwfec
) {
1761 l2vpn
->pw_type
= xl
->pw_type
;
1762 l2vpn
->mtu
= xl
->mtu
;
1764 l2vpn
->pw_type
= previous_pw_type
;
1765 l2vpn
->mtu
= previous_mtu
;
1768 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1769 if (ref
&& *ref
== xp
)
1774 /* merge inactive pseudowires */
1775 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1776 /* find deleted inactive pseudowires */
1777 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1778 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1779 if (ldpd_process
== PROC_MAIN
)
1784 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1785 /* find new inactive pseudowires */
1786 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1787 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1788 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, xp
);
1790 if (ldpd_process
== PROC_MAIN
)
1791 QOBJ_REG (xp
, l2vpn_pw
);
1795 /* update existing inactive pseudowire */
1796 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1798 pw
->addr
= xp
->addr
;
1799 pw
->pwid
= xp
->pwid
;
1800 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1801 pw
->ifindex
= xp
->ifindex
;
1802 pw
->flags
= xp
->flags
;
1804 /* check if the pseudowire should be activated */
1805 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0) {
1806 /* remove from inactive list */
1807 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1808 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1810 switch (ldpd_process
) {
1811 case PROC_LDE_ENGINE
:
1814 case PROC_LDP_ENGINE
:
1815 ldpe_l2vpn_pw_init(pw
);
1822 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1823 if (ref
&& *ref
== xp
)
1828 /* insert pseudowires that were disabled in the inactive list */
1829 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &pw_aux_list
, ptmp
) {
1830 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1831 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1834 l2vpn
->pw_type
= xl
->pw_type
;
1835 l2vpn
->mtu
= xl
->mtu
;
1836 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1837 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1841 config_new_empty(void)
1843 struct ldpd_conf
*xconf
;
1845 xconf
= calloc(1, sizeof(*xconf
));
1849 RB_INIT(&xconf
->iface_tree
);
1850 RB_INIT(&xconf
->tnbr_tree
);
1851 RB_INIT(&xconf
->nbrp_tree
);
1852 RB_INIT(&xconf
->l2vpn_tree
);
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
);
1875 if (ldpd_process
== PROC_MAIN
)