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 static int main_dispatch_ldpe(struct thread
*);
49 static int main_dispatch_lde(struct thread
*);
50 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
52 static void main_imsg_send_net_sockets(int);
53 static void main_imsg_send_net_socket(int, enum socket_type
);
54 static int main_imsg_send_config(struct ldpd_conf
*);
55 static void ldp_config_normalize(struct ldpd_conf
*);
56 static void ldp_config_reset(struct ldpd_conf
*);
57 static void ldp_config_reset_main(struct ldpd_conf
*);
58 static void ldp_config_reset_af(struct ldpd_conf
*, int);
59 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
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
*);
64 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
65 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
66 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
67 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
68 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
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_init init
;
81 struct ldpd_conf
*ldpd_conf
, *vty_conf
;
83 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
84 static struct imsgev
*iev_lde
, *iev_lde_sync
;
85 static pid_t ldpe_pid
;
88 #define LDP_DEFAULT_CONFIG "ldpd.conf"
89 #define LDP_VTY_PORT 2612
91 /* Master of threads. */
92 struct thread_master
*master
;
94 static struct frr_daemon_info ldpd_di
;
97 static zebra_capabilities_t _caps_p
[] =
103 struct zebra_privs_t ldpd_privs
=
105 #if defined(FRR_USER) && defined(FRR_GROUP)
109 #if defined(VTY_GROUP)
110 .vty_group
= VTY_GROUP
,
113 .cap_num_p
= array_size(_caps_p
),
117 /* CTL Socket path */
118 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
121 #define OPTION_CTLSOCK 1001
122 static struct option longopts
[] =
124 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
125 { "instance", required_argument
, NULL
, 'n'},
129 /* SIGHUP handler. */
133 log_info("SIGHUP received");
136 * Do a full configuration reload. In other words, reset vty_conf
137 * and build a new configuartion from scratch.
139 ldp_config_reset(vty_conf
);
140 vty_read_config(ldpd_di
.config_file
, config_default
);
141 ldp_config_apply(NULL
, vty_conf
);
144 /* SIGINT / SIGTERM handler. */
148 log_info("SIGINT received");
152 /* SIGUSR1 handler. */
159 static struct quagga_signal_t ldp_signals
[] =
179 FRR_DAEMON_INFO(ldpd
, LDP
,
180 .vty_port
= LDP_VTY_PORT
,
182 .proghelp
= "Implementation of the LDP protocol.",
184 .signals
= ldp_signals
,
185 .n_signals
= array_size(ldp_signals
),
187 .privs
= &ldpd_privs
,
191 main(int argc
, char *argv
[])
194 int lflag
= 0, eflag
= 0;
195 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
196 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
199 ldpd_process
= PROC_MAIN
;
200 log_procname
= log_procnames
[ldpd_process
];
202 saved_argv0
= argv
[0];
203 if (saved_argv0
== NULL
)
204 saved_argv0
= (char *)"ldpd";
206 frr_preinit(&ldpd_di
, argc
, argv
);
207 frr_opt_add("LEn:", longopts
,
208 " --ctl_socket Override ctl socket path\n"
209 "-n, --instance Instance id\n");
214 opt
= frr_getopt(argc
, argv
, NULL
);
223 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
229 * LDPD_SOCKET configured as relative path
230 * during config? Should really never happen for
233 ctl_sock_name
= (char *)LDPD_SOCKET
;
234 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
235 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
236 strlcat(ctl_sock_path
, ctl_sock_name
,
237 sizeof(ctl_sock_path
));
240 init
.instance
= atoi(optarg
);
241 if (init
.instance
< 1)
256 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
257 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
258 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
259 strlcpy(init
.zclient_serv_path
, zclient_serv_path_get(),
260 sizeof(init
.zclient_serv_path
));
264 if (argc
> 0 || (lflag
&& eflag
))
267 /* check for root privileges */
268 if (geteuid() != 0) {
270 perror(ldpd_di
.progname
);
275 openzlog(ldpd_di
.progname
, "LDP", 0,
276 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
282 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
284 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
285 pipe_parent2ldpe_sync
) == -1)
287 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
289 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
290 pipe_parent2lde_sync
) == -1)
292 sock_set_nonblock(pipe_parent2ldpe
[0]);
293 sock_set_cloexec(pipe_parent2ldpe
[0]);
294 sock_set_nonblock(pipe_parent2ldpe
[1]);
295 sock_set_cloexec(pipe_parent2ldpe
[1]);
296 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
297 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
298 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
299 sock_set_nonblock(pipe_parent2lde
[0]);
300 sock_set_cloexec(pipe_parent2lde
[0]);
301 sock_set_nonblock(pipe_parent2lde
[1]);
302 sock_set_cloexec(pipe_parent2lde
[1]);
303 sock_set_nonblock(pipe_parent2lde_sync
[0]);
304 sock_set_cloexec(pipe_parent2lde_sync
[0]);
305 sock_set_cloexec(pipe_parent2lde_sync
[1]);
308 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
309 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
310 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
311 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
315 vty_config_lockless();
316 vrf_init(NULL
, NULL
, NULL
, NULL
);
319 ldp_zebra_init(master
);
322 * Create base configuration with sane defaults. All configuration
323 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
324 * to merge the changes into ldpd_conf, which contains the actual
325 * running configuration.
327 ldpd_conf
= config_new_empty();
328 vty_conf
= config_new_empty();
329 QOBJ_REG(vty_conf
, ldpd_conf
);
331 /* read configuration file and daemonize */
334 /* apply configuration */
335 ldp_config_apply(NULL
, vty_conf
);
337 /* setup pipes to children */
338 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
339 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
340 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
341 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
343 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
344 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
345 iev_ldpe
->ev_read
= NULL
;
346 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
348 iev_ldpe
->handler_write
= ldp_write_handler
;
350 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
351 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
352 iev_ldpe_sync
->ev_read
= NULL
;
353 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
354 &iev_ldpe_sync
->ev_read
);
355 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
357 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
358 iev_lde
->handler_read
= main_dispatch_lde
;
359 iev_lde
->ev_read
= NULL
;
360 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
362 iev_lde
->handler_write
= ldp_write_handler
;
364 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
365 iev_lde_sync
->handler_read
= main_dispatch_lde
;
366 iev_lde_sync
->ev_read
= NULL
;
367 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
368 &iev_lde_sync
->ev_read
);
369 iev_lde_sync
->handler_write
= ldp_write_handler
;
371 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
372 fatal("could not establish imsg links");
373 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
374 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
376 main_imsg_send_config(ldpd_conf
);
378 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
379 main_imsg_send_net_sockets(AF_INET
);
380 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
381 main_imsg_send_net_sockets(AF_INET6
);
396 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
397 close(iev_ldpe
->ibuf
.fd
);
398 msgbuf_clear(&iev_lde
->ibuf
.w
);
399 close(iev_lde
->ibuf
.fd
);
401 config_clear(ldpd_conf
);
403 ldp_config_reset(vty_conf
);
404 QOBJ_UNREG(vty_conf
);
407 log_debug("waiting for children to terminate");
411 if (errno
!= EINTR
&& errno
!= ECHILD
)
413 } else if (WIFSIGNALED(status
))
414 log_warnx("%s terminated; signal %d",
415 (pid
== lde_pid
) ? "label decision engine" :
416 "ldp engine", WTERMSIG(status
));
417 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
422 log_info("terminating");
429 zprivs_terminate(&ldpd_privs
);
430 thread_master_free(master
);
437 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
443 switch (pid
= fork()) {
445 fatal("cannot fork");
454 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
455 fatal("cannot setup imsg async fd");
456 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
457 fatal("cannot setup imsg sync fd");
459 argv
[argc
++] = argv0
;
462 fatalx("Can not start main process");
463 case PROC_LDE_ENGINE
:
464 argv
[argc
++] = (char *)"-L";
466 case PROC_LDP_ENGINE
:
467 argv
[argc
++] = (char *)"-E";
479 main_dispatch_ldpe(struct thread
*thread
)
481 struct imsgev
*iev
= THREAD_ARG(thread
);
482 struct imsgbuf
*ibuf
= &iev
->ibuf
;
490 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
491 fatal("imsg_read error");
492 if (n
== 0) /* connection closed */
496 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
502 switch (imsg
.hdr
.type
) {
504 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
506 case IMSG_REQUEST_SOCKETS
:
508 main_imsg_send_net_sockets(af
);
511 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
512 sizeof(struct acl_check
))
513 fatalx("IMSG_ACL_CHECK imsg with wrong len");
514 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
517 log_debug("%s: error handling imsg %d", __func__
,
526 /* this pipe is dead, so remove the event handlers and exit */
527 THREAD_READ_OFF(iev
->ev_read
);
528 THREAD_WRITE_OFF(iev
->ev_write
);
533 kill(lde_pid
, SIGTERM
);
541 main_dispatch_lde(struct thread
*thread
)
543 struct imsgev
*iev
= THREAD_ARG(thread
);
544 struct imsgbuf
*ibuf
= &iev
->ibuf
;
551 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
552 fatal("imsg_read error");
553 if (n
== 0) /* connection closed */
557 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
563 switch (imsg
.hdr
.type
) {
565 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
567 case IMSG_KLABEL_CHANGE
:
568 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
569 sizeof(struct kroute
))
570 fatalx("invalid size of IMSG_KLABEL_CHANGE");
571 if (kr_change(imsg
.data
))
572 log_warnx("%s: error changing route", __func__
);
574 case IMSG_KLABEL_DELETE
:
575 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
576 sizeof(struct kroute
))
577 fatalx("invalid size of IMSG_KLABEL_DELETE");
578 if (kr_delete(imsg
.data
))
579 log_warnx("%s: error deleting route", __func__
);
581 case IMSG_KPWLABEL_CHANGE
:
582 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
584 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
585 if (kmpw_set(imsg
.data
))
586 log_warnx("%s: error changing pseudowire",
589 case IMSG_KPWLABEL_DELETE
:
590 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
592 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
593 if (kmpw_unset(imsg
.data
))
594 log_warnx("%s: error unsetting pseudowire",
598 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
599 sizeof(struct acl_check
))
600 fatalx("IMSG_ACL_CHECK imsg with wrong len");
601 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
604 log_debug("%s: error handling imsg %d", __func__
,
613 /* this pipe is dead, so remove the event handlers and exit */
614 THREAD_READ_OFF(iev
->ev_read
);
615 THREAD_WRITE_OFF(iev
->ev_write
);
620 kill(ldpe_pid
, SIGTERM
);
628 ldp_write_handler(struct thread
*thread
)
630 struct imsgev
*iev
= THREAD_ARG(thread
);
631 struct imsgbuf
*ibuf
= &iev
->ibuf
;
634 iev
->ev_write
= NULL
;
636 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
637 fatal("msgbuf_write");
639 /* this pipe is dead, so remove the event handlers */
640 THREAD_READ_OFF(iev
->ev_read
);
641 THREAD_WRITE_OFF(iev
->ev_write
);
651 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
653 if (iev_ldpe
== NULL
)
655 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
659 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
661 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
665 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
667 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
669 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
671 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
677 imsg_event_add(struct imsgev
*iev
)
679 if (iev
->handler_read
)
680 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
683 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
684 thread_add_write(master
, iev
->handler_write
, iev
,
685 iev
->ibuf
.fd
, &iev
->ev_write
);
689 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
690 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
694 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
695 pid
, fd
, data
, datalen
)) != -1)
701 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
703 ibuf_close(&eb
->wbuf
, buf
);
708 evbuf_event_add(struct evbuf
*eb
)
711 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
716 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
719 msgbuf_init(&eb
->wbuf
);
721 eb
->handler
= handler
;
726 evbuf_clear(struct evbuf
*eb
)
728 THREAD_WRITE_OFF(eb
->ev
);
729 msgbuf_clear(&eb
->wbuf
);
734 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
736 int pipe_ldpe2lde
[2];
738 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
740 sock_set_nonblock(pipe_ldpe2lde
[0]);
741 sock_set_nonblock(pipe_ldpe2lde
[1]);
743 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
746 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
754 main_imsg_send_net_sockets(int af
)
756 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
759 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
760 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
761 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
762 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
766 main_imsg_send_net_socket(int af
, enum socket_type type
)
770 fd
= ldp_create_socket(af
, type
);
772 log_warnx("%s: failed to create %s socket for address-family "
773 "%s", __func__
, socket_name(type
), af_name(af
));
777 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
782 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
783 union ldpd_addr
*addr
, uint8_t prefixlen
)
787 struct acl_check acl_check
;
789 if (acl_name
[0] == '\0')
790 return FILTER_PERMIT
;
793 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
795 acl_check
.addr
= *addr
;
796 acl_check
.prefixlen
= prefixlen
;
798 /* send (blocking) */
799 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
801 imsg_flush(&iev
->ibuf
);
803 /* receive (blocking) and parse result */
804 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
805 fatal("imsg_read error");
806 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
808 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
809 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
810 fatalx("ldp_acl_request: invalid response");
812 return (*((int *)imsg
.data
));
816 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
818 struct access_list
*alist
;
819 struct prefix prefix
;
822 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
824 result
= FILTER_DENY
;
826 prefix
.family
= acl_check
->af
;
827 switch (prefix
.family
) {
829 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
832 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
835 fatalx("ldp_acl_reply: unknown af");
837 prefix
.prefixlen
= acl_check
->prefixlen
;
838 result
= access_list_apply(alist
, &prefix
);
841 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
845 struct ldpd_af_conf
*
846 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
850 return (&xconf
->ipv4
);
852 return (&xconf
->ipv6
);
854 fatalx("ldp_af_conf_get: unknown af");
858 struct ldpd_af_global
*
859 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
863 return (&xglobal
->ipv4
);
865 return (&xglobal
->ipv6
);
867 fatalx("ldp_af_global_get: unknown af");
872 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
874 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
875 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
879 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
881 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
882 return (xconf
->rtr_id
.s_addr
);
884 return (global
.rtr_id
.s_addr
);
888 main_imsg_send_config(struct ldpd_conf
*xconf
)
892 struct nbr_params
*nbrp
;
894 struct l2vpn_if
*lif
;
897 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
898 sizeof(*xconf
)) == -1)
901 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
902 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
903 sizeof(*iface
)) == -1)
907 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
908 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
909 sizeof(*tnbr
)) == -1)
913 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
914 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
915 sizeof(*nbrp
)) == -1)
919 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
920 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
921 sizeof(*l2vpn
)) == -1)
924 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
925 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
929 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
930 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
934 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
935 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
941 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
948 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
951 * When reading from a configuration file (startup and sighup), we
952 * call merge_config() only once after the whole config has been read.
953 * This is the optimal and least disruptive way to update the running
956 if (vty
&& vty
->type
== VTY_FILE
)
959 ldp_config_normalize(xconf
);
961 if (main_imsg_send_config(xconf
) == -1)
964 merge_config(ldpd_conf
, xconf
);
970 ldp_config_normalize(struct ldpd_conf
*xconf
)
972 struct iface
*iface
, *itmp
;
973 struct nbr_params
*nbrp
, *ntmp
;
975 struct l2vpn_pw
*pw
, *ptmp
;
977 if (!(xconf
->flags
& F_LDPD_ENABLED
))
978 ldp_config_reset_main(xconf
);
980 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
981 ldp_config_reset_af(xconf
, AF_INET
);
982 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
983 ldp_config_reset_af(xconf
, AF_INET6
);
985 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
986 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
990 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
994 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
995 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
997 if (nbrp
->auth
.method
!= AUTH_NONE
)
1001 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1006 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1007 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1008 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1010 pw
->addr
.v4
= pw
->lsr_id
;
1013 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1015 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1016 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1018 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1020 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1022 pw
->addr
.v4
= pw
->lsr_id
;
1025 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1027 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1028 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1034 ldp_config_reset(struct ldpd_conf
*conf
)
1036 ldp_config_reset_main(conf
);
1037 ldp_config_reset_l2vpns(conf
);
1041 ldp_config_reset_main(struct ldpd_conf
*conf
)
1043 struct iface
*iface
;
1044 struct nbr_params
*nbrp
;
1046 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1048 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1052 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1054 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1058 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1059 ldp_config_reset_af(conf
, AF_INET
);
1060 ldp_config_reset_af(conf
, AF_INET6
);
1061 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1062 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1063 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1064 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1065 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1070 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1072 struct ldpd_af_conf
*af_conf
;
1073 struct iface
*iface
;
1074 struct iface_af
*ia
;
1075 struct tnbr
*tnbr
, *ttmp
;
1077 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1078 ia
= iface_af_get(iface
, af
);
1082 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1087 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1091 af_conf
= ldp_af_conf_get(conf
, af
);
1092 af_conf
->keepalive
= 180;
1093 af_conf
->lhello_holdtime
= 0;
1094 af_conf
->lhello_interval
= 0;
1095 af_conf
->thello_holdtime
= 0;
1096 af_conf
->thello_interval
= 0;
1097 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1102 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1104 struct l2vpn
*l2vpn
;
1105 struct l2vpn_if
*lif
;
1106 struct l2vpn_pw
*pw
;
1108 while ((l2vpn
= RB_ROOT(&conf
->l2vpn_tree
)) != NULL
) {
1109 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1111 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1114 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1116 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1119 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1121 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1125 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1131 ldp_clear_config(struct ldpd_conf
*xconf
)
1133 struct iface
*iface
;
1135 struct nbr_params
*nbrp
;
1136 struct l2vpn
*l2vpn
;
1138 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1139 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1142 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1143 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1146 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1147 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1150 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1151 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1158 #define COPY(a, b) do { \
1159 a = malloc(sizeof(*a)); \
1166 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1168 merge_global(conf
, xconf
);
1169 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1170 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1171 merge_ifaces(conf
, xconf
);
1172 merge_tnbrs(conf
, xconf
);
1173 merge_nbrps(conf
, xconf
);
1174 merge_l2vpns(conf
, xconf
);
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
)
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 switch (ldpd_process
) {
1319 case PROC_LDP_ENGINE
:
1320 ldpe_if_exit(iface
);
1322 case PROC_LDE_ENGINE
:
1326 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1330 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1331 /* find new interfaces */
1332 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1334 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1336 switch (ldpd_process
) {
1337 case PROC_LDP_ENGINE
:
1338 ldpe_if_init(iface
);
1340 case PROC_LDE_ENGINE
:
1343 /* resend addresses to activate new interfaces */
1344 kif_redistribute(iface
->name
);
1350 /* update existing interfaces */
1351 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1352 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1357 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1359 if (ia
->enabled
!= xi
->enabled
) {
1360 ia
->enabled
= xi
->enabled
;
1361 if (ldpd_process
== PROC_LDP_ENGINE
)
1362 ldp_if_update(ia
->iface
, ia
->af
);
1364 ia
->hello_holdtime
= xi
->hello_holdtime
;
1365 ia
->hello_interval
= xi
->hello_interval
;
1369 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1371 struct tnbr
*tnbr
, *ttmp
, *xt
;
1373 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1374 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1377 /* find deleted tnbrs */
1378 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1379 switch (ldpd_process
) {
1380 case PROC_LDP_ENGINE
:
1381 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1382 tnbr_check(conf
, tnbr
);
1384 case PROC_LDE_ENGINE
:
1386 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1392 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1393 /* find new tnbrs */
1394 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1396 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1398 switch (ldpd_process
) {
1399 case PROC_LDP_ENGINE
:
1402 case PROC_LDE_ENGINE
:
1409 /* update existing tnbrs */
1410 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1411 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1416 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1418 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1422 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1423 /* find deleted nbrps */
1424 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1425 switch (ldpd_process
) {
1426 case PROC_LDP_ENGINE
:
1427 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1429 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1434 (ldp_af_global_get(&global
,
1435 nbr
->af
))->ldp_session_socket
,
1436 nbr
->af
, &nbr
->raddr
, NULL
);
1438 nbr
->auth
.method
= AUTH_NONE
;
1439 if (nbr_session_active_role(nbr
))
1440 nbr_establish_connection(nbr
);
1443 case PROC_LDE_ENGINE
:
1447 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1451 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1452 /* find new nbrps */
1453 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1455 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1457 switch (ldpd_process
) {
1458 case PROC_LDP_ENGINE
:
1459 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1461 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1462 nbr
->auth
.method
= nbrp
->auth
.method
;
1464 if (pfkey_establish(nbr
, nbrp
) == -1)
1465 fatalx("pfkey setup failed");
1468 (ldp_af_global_get(&global
,
1469 nbr
->af
))->ldp_session_socket
,
1470 nbr
->af
, &nbr
->raddr
,
1473 if (nbr_session_active_role(nbr
))
1474 nbr_establish_connection(nbr
);
1477 case PROC_LDE_ENGINE
:
1484 /* update existing nbrps */
1485 if (nbrp
->flags
!= xn
->flags
||
1486 nbrp
->keepalive
!= xn
->keepalive
||
1487 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1488 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1489 nbrp
->auth
.method
!= xn
->auth
.method
||
1490 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1495 nbrp
->keepalive
= xn
->keepalive
;
1496 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1497 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1498 nbrp
->auth
.method
= xn
->auth
.method
;
1499 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1500 sizeof(nbrp
->auth
.md5key
));
1501 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1502 nbrp
->flags
= xn
->flags
;
1504 if (ldpd_process
== PROC_LDP_ENGINE
) {
1505 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1506 if (nbr
&& nbrp_changed
) {
1507 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1510 nbr
->auth
.method
= nbrp
->auth
.method
;
1511 if (pfkey_establish(nbr
, nbrp
) == -1)
1512 fatalx("pfkey setup failed");
1514 nbr
->auth
.method
= nbrp
->auth
.method
;
1515 sock_set_md5sig((ldp_af_global_get(&global
,
1516 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1517 &nbr
->raddr
, nbrp
->auth
.md5key
);
1519 if (nbr_session_active_role(nbr
))
1520 nbr_establish_connection(nbr
);
1527 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1529 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1531 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1532 /* find deleted l2vpns */
1533 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1534 switch (ldpd_process
) {
1535 case PROC_LDE_ENGINE
:
1538 case PROC_LDP_ENGINE
:
1539 ldpe_l2vpn_exit(l2vpn
);
1544 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1548 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1549 /* find new l2vpns */
1550 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1552 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1553 RB_INIT(&l2vpn
->if_tree
);
1554 RB_INIT(&l2vpn
->pw_tree
);
1555 RB_INIT(&l2vpn
->pw_inactive_tree
);
1557 switch (ldpd_process
) {
1558 case PROC_LDE_ENGINE
:
1561 case PROC_LDP_ENGINE
:
1562 ldpe_l2vpn_init(l2vpn
);
1569 /* update existing l2vpns */
1570 merge_l2vpn(conf
, l2vpn
, xl
);
1575 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1577 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1578 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1580 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1581 int previous_pw_type
, previous_mtu
;
1583 previous_pw_type
= l2vpn
->pw_type
;
1584 previous_mtu
= l2vpn
->mtu
;
1586 /* merge intefaces */
1587 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1588 /* find deleted interfaces */
1589 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1590 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1594 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1595 /* find new interfaces */
1596 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1598 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1601 switch (ldpd_process
) {
1602 case PROC_LDP_ENGINE
:
1603 case PROC_LDE_ENGINE
:
1606 kif_redistribute(lif
->ifname
);
1612 /* merge active pseudowires */
1613 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1614 /* find deleted active pseudowires */
1615 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1616 switch (ldpd_process
) {
1617 case PROC_LDE_ENGINE
:
1620 case PROC_LDP_ENGINE
:
1621 ldpe_l2vpn_pw_exit(pw
);
1627 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1631 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1632 /* find new active pseudowires */
1633 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1635 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1638 switch (ldpd_process
) {
1639 case PROC_LDE_ENGINE
:
1642 case PROC_LDP_ENGINE
:
1643 ldpe_l2vpn_pw_init(pw
);
1646 kif_redistribute(pw
->ifname
);
1652 /* update existing active pseudowire */
1653 if (pw
->af
!= xp
->af
||
1654 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1659 /* changes that require a session restart */
1660 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1661 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1666 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1667 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1668 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1669 reinstall_pwfec
= 1;
1671 reinstall_pwfec
= 0;
1673 if (ldpd_process
== PROC_LDP_ENGINE
) {
1675 ldpe_l2vpn_pw_exit(pw
);
1677 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1678 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1679 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1682 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1684 pw
->lsr_id
= xp
->lsr_id
;
1686 pw
->addr
= xp
->addr
;
1687 pw
->pwid
= xp
->pwid
;
1688 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1689 pw
->ifindex
= xp
->ifindex
;
1690 if (xp
->flags
& F_PW_CWORD_CONF
)
1691 pw
->flags
|= F_PW_CWORD_CONF
;
1693 pw
->flags
&= ~F_PW_CWORD_CONF
;
1694 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1695 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1697 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1698 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1699 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1701 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1702 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1703 ldpe_l2vpn_pw_init(pw
);
1704 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1705 l2vpn
->pw_type
= xl
->pw_type
;
1706 l2vpn
->mtu
= xl
->mtu
;
1708 l2vpn
->pw_type
= previous_pw_type
;
1709 l2vpn
->mtu
= previous_mtu
;
1713 /* merge inactive pseudowires */
1714 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1715 /* find deleted inactive pseudowires */
1716 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1717 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1721 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1722 /* find new inactive pseudowires */
1723 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1725 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1728 switch (ldpd_process
) {
1729 case PROC_LDE_ENGINE
:
1730 case PROC_LDP_ENGINE
:
1733 kif_redistribute(pw
->ifname
);
1739 /* update existing inactive pseudowire */
1740 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1742 pw
->addr
= xp
->addr
;
1743 pw
->pwid
= xp
->pwid
;
1744 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1745 pw
->ifindex
= xp
->ifindex
;
1746 pw
->flags
= xp
->flags
;
1749 l2vpn
->pw_type
= xl
->pw_type
;
1750 l2vpn
->mtu
= xl
->mtu
;
1751 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1752 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1756 config_new_empty(void)
1758 struct ldpd_conf
*xconf
;
1760 xconf
= calloc(1, sizeof(*xconf
));
1764 RB_INIT(&xconf
->iface_tree
);
1765 RB_INIT(&xconf
->tnbr_tree
);
1766 RB_INIT(&xconf
->nbrp_tree
);
1767 RB_INIT(&xconf
->l2vpn_tree
);
1769 /* set default values */
1770 ldp_config_reset(xconf
);
1776 config_clear(struct ldpd_conf
*conf
)
1778 struct ldpd_conf
*xconf
;
1781 * Merge current config with an empty config, this will deactivate
1782 * and deallocate all the interfaces, pseudowires and so on. Before
1783 * merging, copy the router-id and other variables to avoid some
1784 * unnecessary operations, like trying to reset the neighborships.
1786 xconf
= config_new_empty();
1787 xconf
->ipv4
= conf
->ipv4
;
1788 xconf
->ipv6
= conf
->ipv6
;
1789 xconf
->rtr_id
= conf
->rtr_id
;
1790 xconf
->trans_pref
= conf
->trans_pref
;
1791 xconf
->flags
= conf
->flags
;
1792 merge_config(conf
, xconf
);