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_main(struct ldpd_conf
*);
57 static void ldp_config_reset_af(struct ldpd_conf
*, int);
58 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
59 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
60 static void merge_af(int, struct ldpd_af_conf
*,
61 struct ldpd_af_conf
*);
62 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
63 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
64 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
65 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
66 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
67 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
70 DEFINE_QOBJ_TYPE(iface
)
71 DEFINE_QOBJ_TYPE(tnbr
)
72 DEFINE_QOBJ_TYPE(nbr_params
)
73 DEFINE_QOBJ_TYPE(l2vpn_if
)
74 DEFINE_QOBJ_TYPE(l2vpn_pw
)
75 DEFINE_QOBJ_TYPE(l2vpn
)
76 DEFINE_QOBJ_TYPE(ldpd_conf
)
78 struct ldpd_global global
;
79 struct ldpd_init init
;
80 struct ldpd_conf
*ldpd_conf
, *vty_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
;
93 static struct frr_daemon_info ldpd_di
;
96 static zebra_capabilities_t _caps_p
[] =
102 struct zebra_privs_t ldpd_privs
=
104 #if defined(FRR_USER) && defined(FRR_GROUP)
108 #if defined(VTY_GROUP)
109 .vty_group
= VTY_GROUP
,
112 .cap_num_p
= array_size(_caps_p
),
116 /* CTL Socket path */
117 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
120 #define OPTION_CTLSOCK 1001
121 static struct option longopts
[] =
123 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
124 { "instance", required_argument
, NULL
, 'n'},
128 /* SIGHUP handler. */
132 log_info("SIGHUP received");
135 ldp_config_reset_main(vty_conf
);
136 ldp_config_reset_l2vpns(vty_conf
);
138 /* read configuration file without applying any changes */
140 vty_read_config(ldpd_di
.config_file
, config_default
);
144 * Apply the new configuration all at once, this way merge_config()
145 * will be the least disruptive as possible.
147 ldp_reload(vty_conf
);
150 /* SIGINT / SIGTERM handler. */
154 log_info("SIGINT received");
158 /* SIGUSR1 handler. */
165 static struct quagga_signal_t ldp_signals
[] =
185 FRR_DAEMON_INFO(ldpd
, LDP
,
186 .vty_port
= LDP_VTY_PORT
,
188 .proghelp
= "Implementation of the LDP protocol.",
190 .signals
= ldp_signals
,
191 .n_signals
= array_size(ldp_signals
),
193 .privs
= &ldpd_privs
,
197 main(int argc
, char *argv
[])
200 int lflag
= 0, eflag
= 0;
201 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
202 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
205 ldpd_process
= PROC_MAIN
;
206 log_procname
= log_procnames
[ldpd_process
];
208 saved_argv0
= argv
[0];
209 if (saved_argv0
== NULL
)
210 saved_argv0
= (char *)"ldpd";
212 frr_preinit(&ldpd_di
, argc
, argv
);
213 frr_opt_add("LEn:", longopts
,
214 " --ctl_socket Override ctl socket path\n"
215 "-n, --instance Instance id\n");
220 opt
= frr_getopt(argc
, argv
, NULL
);
229 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
235 * LDPD_SOCKET configured as relative path
236 * during config? Should really never happen for
239 ctl_sock_name
= (char *)LDPD_SOCKET
;
240 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
241 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
242 strlcat(ctl_sock_path
, ctl_sock_name
,
243 sizeof(ctl_sock_path
));
246 init
.instance
= atoi(optarg
);
247 if (init
.instance
< 1)
262 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
263 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
264 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
265 strlcpy(init
.zclient_serv_path
, zclient_serv_path_get(),
266 sizeof(init
.zclient_serv_path
));
270 if (argc
> 0 || (lflag
&& eflag
))
273 /* check for root privileges */
274 if (geteuid() != 0) {
276 perror(ldpd_di
.progname
);
281 openzlog(ldpd_di
.progname
, "LDP", 0,
282 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
288 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
290 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
291 pipe_parent2ldpe_sync
) == -1)
293 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
295 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
296 pipe_parent2lde_sync
) == -1)
298 sock_set_nonblock(pipe_parent2ldpe
[0]);
299 sock_set_cloexec(pipe_parent2ldpe
[0]);
300 sock_set_nonblock(pipe_parent2ldpe
[1]);
301 sock_set_cloexec(pipe_parent2ldpe
[1]);
302 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
303 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
304 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
305 sock_set_nonblock(pipe_parent2lde
[0]);
306 sock_set_cloexec(pipe_parent2lde
[0]);
307 sock_set_nonblock(pipe_parent2lde
[1]);
308 sock_set_cloexec(pipe_parent2lde
[1]);
309 sock_set_nonblock(pipe_parent2lde_sync
[0]);
310 sock_set_cloexec(pipe_parent2lde_sync
[0]);
311 sock_set_cloexec(pipe_parent2lde_sync
[1]);
314 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
315 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
316 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
317 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
321 vty_config_lockless();
322 vrf_init(NULL
, NULL
, NULL
, NULL
);
325 ldp_zebra_init(master
);
327 /* create base configuration with sane defaults */
328 ldpd_conf
= config_new_empty();
329 ldp_config_reset_main(ldpd_conf
);
332 * Create vty_conf as a duplicate of the main configuration. All
333 * configuration requests (e.g. CLI) act on vty_conf and then call
334 * ldp_reload() to merge the changes into ldpd_conf.
336 vty_conf
= config_new_empty();
337 ldp_config_reset_main(vty_conf
);
338 QOBJ_REG(vty_conf
, ldpd_conf
);
340 /* read configuration file and daemonize */
343 /* setup pipes to children */
344 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
345 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
346 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
347 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
349 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
350 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
351 iev_ldpe
->ev_read
= NULL
;
352 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
354 iev_ldpe
->handler_write
= ldp_write_handler
;
356 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
357 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
358 iev_ldpe_sync
->ev_read
= NULL
;
359 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
360 &iev_ldpe_sync
->ev_read
);
361 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
363 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
364 iev_lde
->handler_read
= main_dispatch_lde
;
365 iev_lde
->ev_read
= NULL
;
366 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
368 iev_lde
->handler_write
= ldp_write_handler
;
370 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
371 iev_lde_sync
->handler_read
= main_dispatch_lde
;
372 iev_lde_sync
->ev_read
= NULL
;
373 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
374 &iev_lde_sync
->ev_read
);
375 iev_lde_sync
->handler_write
= ldp_write_handler
;
377 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
378 fatal("could not establish imsg links");
379 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
380 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
382 main_imsg_send_config(ldpd_conf
);
384 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
385 main_imsg_send_net_sockets(AF_INET
);
386 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
387 main_imsg_send_net_sockets(AF_INET6
);
402 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
403 close(iev_ldpe
->ibuf
.fd
);
404 msgbuf_clear(&iev_lde
->ibuf
.w
);
405 close(iev_lde
->ibuf
.fd
);
407 config_clear(ldpd_conf
);
409 ldp_config_reset_main(vty_conf
);
410 ldp_config_reset_l2vpns(vty_conf
);
411 QOBJ_UNREG(vty_conf
);
414 log_debug("waiting for children to terminate");
418 if (errno
!= EINTR
&& errno
!= ECHILD
)
420 } else if (WIFSIGNALED(status
))
421 log_warnx("%s terminated; signal %d",
422 (pid
== lde_pid
) ? "label decision engine" :
423 "ldp engine", WTERMSIG(status
));
424 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
429 log_info("terminating");
436 zprivs_terminate(&ldpd_privs
);
437 thread_master_free(master
);
444 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
450 switch (pid
= fork()) {
452 fatal("cannot fork");
461 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
462 fatal("cannot setup imsg async fd");
463 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
464 fatal("cannot setup imsg sync fd");
466 argv
[argc
++] = argv0
;
469 fatalx("Can not start main process");
470 case PROC_LDE_ENGINE
:
471 argv
[argc
++] = (char *)"-L";
473 case PROC_LDP_ENGINE
:
474 argv
[argc
++] = (char *)"-E";
486 main_dispatch_ldpe(struct thread
*thread
)
488 struct imsgev
*iev
= THREAD_ARG(thread
);
489 struct imsgbuf
*ibuf
= &iev
->ibuf
;
497 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
498 fatal("imsg_read error");
499 if (n
== 0) /* connection closed */
503 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
509 switch (imsg
.hdr
.type
) {
511 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
513 case IMSG_REQUEST_SOCKETS
:
515 main_imsg_send_net_sockets(af
);
518 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
519 sizeof(struct acl_check
))
520 fatalx("IMSG_ACL_CHECK imsg with wrong len");
521 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
524 log_debug("%s: error handling imsg %d", __func__
,
533 /* this pipe is dead, so remove the event handlers and exit */
534 THREAD_READ_OFF(iev
->ev_read
);
535 THREAD_WRITE_OFF(iev
->ev_write
);
540 kill(lde_pid
, SIGTERM
);
548 main_dispatch_lde(struct thread
*thread
)
550 struct imsgev
*iev
= THREAD_ARG(thread
);
551 struct imsgbuf
*ibuf
= &iev
->ibuf
;
558 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
559 fatal("imsg_read error");
560 if (n
== 0) /* connection closed */
564 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
570 switch (imsg
.hdr
.type
) {
572 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
574 case IMSG_KLABEL_CHANGE
:
575 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
576 sizeof(struct kroute
))
577 fatalx("invalid size of IMSG_KLABEL_CHANGE");
578 if (kr_change(imsg
.data
))
579 log_warnx("%s: error changing route", __func__
);
581 case IMSG_KLABEL_DELETE
:
582 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
583 sizeof(struct kroute
))
584 fatalx("invalid size of IMSG_KLABEL_DELETE");
585 if (kr_delete(imsg
.data
))
586 log_warnx("%s: error deleting route", __func__
);
588 case IMSG_KPWLABEL_CHANGE
:
589 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
591 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
592 if (kmpw_set(imsg
.data
))
593 log_warnx("%s: error changing pseudowire",
596 case IMSG_KPWLABEL_DELETE
:
597 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
599 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
600 if (kmpw_unset(imsg
.data
))
601 log_warnx("%s: error unsetting pseudowire",
605 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
606 sizeof(struct acl_check
))
607 fatalx("IMSG_ACL_CHECK imsg with wrong len");
608 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
611 log_debug("%s: error handling imsg %d", __func__
,
620 /* this pipe is dead, so remove the event handlers and exit */
621 THREAD_READ_OFF(iev
->ev_read
);
622 THREAD_WRITE_OFF(iev
->ev_write
);
627 kill(ldpe_pid
, SIGTERM
);
635 ldp_write_handler(struct thread
*thread
)
637 struct imsgev
*iev
= THREAD_ARG(thread
);
638 struct imsgbuf
*ibuf
= &iev
->ibuf
;
641 iev
->ev_write
= NULL
;
643 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
644 fatal("msgbuf_write");
646 /* this pipe is dead, so remove the event handlers */
647 THREAD_READ_OFF(iev
->ev_read
);
648 THREAD_WRITE_OFF(iev
->ev_write
);
658 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
660 if (iev_ldpe
== NULL
)
662 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
666 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
668 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
672 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
674 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
676 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
678 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
684 imsg_event_add(struct imsgev
*iev
)
686 if (iev
->handler_read
)
687 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
690 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
691 thread_add_write(master
, iev
->handler_write
, iev
,
692 iev
->ibuf
.fd
, &iev
->ev_write
);
696 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
697 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
701 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
702 pid
, fd
, data
, datalen
)) != -1)
708 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
710 ibuf_close(&eb
->wbuf
, buf
);
715 evbuf_event_add(struct evbuf
*eb
)
718 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
723 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
726 msgbuf_init(&eb
->wbuf
);
728 eb
->handler
= handler
;
733 evbuf_clear(struct evbuf
*eb
)
735 THREAD_WRITE_OFF(eb
->ev
);
736 msgbuf_clear(&eb
->wbuf
);
741 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
743 int pipe_ldpe2lde
[2];
745 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
747 sock_set_nonblock(pipe_ldpe2lde
[0]);
748 sock_set_nonblock(pipe_ldpe2lde
[1]);
750 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
753 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
761 main_imsg_send_net_sockets(int af
)
763 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
766 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
767 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
768 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
769 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
773 main_imsg_send_net_socket(int af
, enum socket_type type
)
777 fd
= ldp_create_socket(af
, type
);
779 log_warnx("%s: failed to create %s socket for address-family "
780 "%s", __func__
, socket_name(type
), af_name(af
));
784 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
789 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
790 union ldpd_addr
*addr
, uint8_t prefixlen
)
794 struct acl_check acl_check
;
796 if (acl_name
[0] == '\0')
797 return FILTER_PERMIT
;
800 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
802 acl_check
.addr
= *addr
;
803 acl_check
.prefixlen
= prefixlen
;
805 /* send (blocking) */
806 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
808 imsg_flush(&iev
->ibuf
);
810 /* receive (blocking) and parse result */
811 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
812 fatal("imsg_read error");
813 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
815 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
816 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
817 fatalx("ldp_acl_request: invalid response");
819 return (*((int *)imsg
.data
));
823 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
825 struct access_list
*alist
;
826 struct prefix prefix
;
829 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
831 result
= FILTER_DENY
;
833 prefix
.family
= acl_check
->af
;
834 switch (prefix
.family
) {
836 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
839 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
842 fatalx("ldp_acl_reply: unknown af");
844 prefix
.prefixlen
= acl_check
->prefixlen
;
845 result
= access_list_apply(alist
, &prefix
);
848 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
852 struct ldpd_af_conf
*
853 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
857 return (&xconf
->ipv4
);
859 return (&xconf
->ipv6
);
861 fatalx("ldp_af_conf_get: unknown af");
865 struct ldpd_af_global
*
866 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
870 return (&xglobal
->ipv4
);
872 return (&xglobal
->ipv6
);
874 fatalx("ldp_af_global_get: unknown af");
879 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
881 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
882 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
886 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
888 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
889 return (xconf
->rtr_id
.s_addr
);
891 return (global
.rtr_id
.s_addr
);
895 main_imsg_send_config(struct ldpd_conf
*xconf
)
899 struct nbr_params
*nbrp
;
901 struct l2vpn_if
*lif
;
904 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
905 sizeof(*xconf
)) == -1)
908 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
909 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
910 sizeof(*iface
)) == -1)
914 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
915 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
916 sizeof(*tnbr
)) == -1)
920 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
921 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
922 sizeof(*nbrp
)) == -1)
926 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
927 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
928 sizeof(*l2vpn
)) == -1)
931 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
932 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
936 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
937 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
941 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
942 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
948 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
955 ldp_reload(struct ldpd_conf
*xconf
)
960 ldp_config_normalize(xconf
);
962 if (main_imsg_send_config(xconf
) == -1)
965 merge_config(ldpd_conf
, xconf
);
971 ldp_config_normalize(struct ldpd_conf
*xconf
)
973 struct iface
*iface
, *itmp
;
974 struct nbr_params
*nbrp
, *ntmp
;
976 struct l2vpn_pw
*pw
, *ptmp
;
978 if (!(xconf
->flags
& F_LDPD_ENABLED
))
979 ldp_config_reset_main(xconf
);
981 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
982 ldp_config_reset_af(xconf
, AF_INET
);
983 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
984 ldp_config_reset_af(xconf
, AF_INET6
);
986 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
987 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
991 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
995 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
996 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
998 if (nbrp
->auth
.method
!= AUTH_NONE
)
1002 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1007 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1008 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1009 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1011 pw
->addr
.v4
= pw
->lsr_id
;
1014 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1016 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1017 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1019 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1021 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1023 pw
->addr
.v4
= pw
->lsr_id
;
1026 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1028 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1029 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1035 ldp_config_reset_main(struct ldpd_conf
*conf
)
1037 struct iface
*iface
;
1038 struct nbr_params
*nbrp
;
1040 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1042 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1046 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1048 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1052 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1053 ldp_config_reset_af(conf
, AF_INET
);
1054 ldp_config_reset_af(conf
, AF_INET6
);
1055 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1056 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1057 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1058 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1059 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1064 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1066 struct ldpd_af_conf
*af_conf
;
1067 struct iface
*iface
;
1068 struct iface_af
*ia
;
1069 struct tnbr
*tnbr
, *ttmp
;
1071 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1072 ia
= iface_af_get(iface
, af
);
1076 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1081 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1085 af_conf
= ldp_af_conf_get(conf
, af
);
1086 af_conf
->keepalive
= 180;
1087 af_conf
->lhello_holdtime
= 0;
1088 af_conf
->lhello_interval
= 0;
1089 af_conf
->thello_holdtime
= 0;
1090 af_conf
->thello_interval
= 0;
1091 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1096 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1098 struct l2vpn
*l2vpn
;
1099 struct l2vpn_if
*lif
;
1100 struct l2vpn_pw
*pw
;
1102 while ((l2vpn
= RB_ROOT(&conf
->l2vpn_tree
)) != NULL
) {
1103 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1105 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1108 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1110 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1113 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1115 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1119 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1125 ldp_clear_config(struct ldpd_conf
*xconf
)
1127 struct iface
*iface
;
1129 struct nbr_params
*nbrp
;
1130 struct l2vpn
*l2vpn
;
1132 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1133 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1136 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1137 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1140 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1141 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1144 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1145 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1152 #define COPY(a, b) do { \
1153 a = malloc(sizeof(*a)); \
1160 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1162 merge_global(conf
, xconf
);
1163 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1164 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1165 merge_ifaces(conf
, xconf
);
1166 merge_tnbrs(conf
, xconf
);
1167 merge_nbrps(conf
, xconf
);
1168 merge_l2vpns(conf
, xconf
);
1172 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1174 /* change of router-id requires resetting all neighborships */
1175 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1176 if (ldpd_process
== PROC_LDP_ENGINE
) {
1177 ldpe_reset_nbrs(AF_UNSPEC
);
1178 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1179 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1180 if_update_all(AF_UNSPEC
);
1181 tnbr_update_all(AF_UNSPEC
);
1184 conf
->rtr_id
= xconf
->rtr_id
;
1187 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1188 conf
->lhello_interval
= xconf
->lhello_interval
;
1189 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1190 conf
->thello_interval
= xconf
->thello_interval
;
1192 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1193 if (ldpd_process
== PROC_LDP_ENGINE
)
1194 ldpe_reset_ds_nbrs();
1195 conf
->trans_pref
= xconf
->trans_pref
;
1198 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1199 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1200 if (ldpd_process
== PROC_LDP_ENGINE
)
1201 ldpe_reset_ds_nbrs();
1204 conf
->flags
= xconf
->flags
;
1208 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1210 int stop_init_backoff
= 0;
1211 int remove_dynamic_tnbrs
= 0;
1212 int change_egress_label
= 0;
1213 int reset_nbrs_ipv4
= 0;
1215 int update_sockets
= 0;
1218 if (af_conf
->keepalive
!= xa
->keepalive
) {
1219 af_conf
->keepalive
= xa
->keepalive
;
1220 stop_init_backoff
= 1;
1222 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1223 af_conf
->lhello_interval
= xa
->lhello_interval
;
1224 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1225 af_conf
->thello_interval
= xa
->thello_interval
;
1228 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1229 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1230 remove_dynamic_tnbrs
= 1;
1231 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1232 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1234 /* need to set/unset IPV6_MINHOPCOUNT */
1237 /* for LDPv4 just resetting the neighbors is enough */
1238 reset_nbrs_ipv4
= 1;
1240 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1241 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1242 change_egress_label
= 1;
1243 af_conf
->flags
= xa
->flags
;
1245 /* update the transport address */
1246 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1247 af_conf
->trans_addr
= xa
->trans_addr
;
1252 if (strcmp(af_conf
->acl_label_advertise_to
,
1253 xa
->acl_label_advertise_to
) ||
1254 strcmp(af_conf
->acl_label_advertise_for
,
1255 xa
->acl_label_advertise_for
) ||
1256 strcmp(af_conf
->acl_label_accept_from
,
1257 xa
->acl_label_accept_from
) ||
1258 strcmp(af_conf
->acl_label_accept_for
,
1259 xa
->acl_label_accept_for
))
1261 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1262 remove_dynamic_tnbrs
= 1;
1263 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1264 change_egress_label
= 1;
1265 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1266 sizeof(af_conf
->acl_thello_accept_from
));
1267 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1268 sizeof(af_conf
->acl_label_allocate_for
));
1269 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1270 sizeof(af_conf
->acl_label_advertise_to
));
1271 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1272 sizeof(af_conf
->acl_label_advertise_for
));
1273 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1274 sizeof(af_conf
->acl_label_accept_from
));
1275 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1276 sizeof(af_conf
->acl_label_accept_for
));
1277 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1278 sizeof(af_conf
->acl_label_expnull_for
));
1280 /* apply the new configuration */
1281 switch (ldpd_process
) {
1282 case PROC_LDE_ENGINE
:
1283 if (change_egress_label
)
1284 lde_change_egress_label(af
);
1286 case PROC_LDP_ENGINE
:
1287 if (stop_init_backoff
)
1288 ldpe_stop_init_backoff(af
);
1289 if (remove_dynamic_tnbrs
)
1290 ldpe_remove_dynamic_tnbrs(af
);
1292 ldpe_reset_nbrs(AF_UNSPEC
);
1293 else if (reset_nbrs_ipv4
)
1294 ldpe_reset_nbrs(AF_INET
);
1297 if (update_sockets
&& iev_ldpe
)
1298 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1305 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1307 struct iface
*iface
, *itmp
, *xi
;
1309 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1310 /* find deleted interfaces */
1311 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1312 switch (ldpd_process
) {
1313 case PROC_LDP_ENGINE
:
1314 ldpe_if_exit(iface
);
1316 case PROC_LDE_ENGINE
:
1320 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1324 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1325 /* find new interfaces */
1326 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1328 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1330 switch (ldpd_process
) {
1331 case PROC_LDP_ENGINE
:
1332 ldpe_if_init(iface
);
1334 case PROC_LDE_ENGINE
:
1337 /* resend addresses to activate new interfaces */
1338 kif_redistribute(iface
->name
);
1344 /* update existing interfaces */
1345 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1346 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1351 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1353 if (ia
->enabled
!= xi
->enabled
) {
1354 ia
->enabled
= xi
->enabled
;
1355 if (ldpd_process
== PROC_LDP_ENGINE
)
1356 ldp_if_update(ia
->iface
, ia
->af
);
1358 ia
->hello_holdtime
= xi
->hello_holdtime
;
1359 ia
->hello_interval
= xi
->hello_interval
;
1363 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1365 struct tnbr
*tnbr
, *ttmp
, *xt
;
1367 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1368 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1371 /* find deleted tnbrs */
1372 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1373 switch (ldpd_process
) {
1374 case PROC_LDP_ENGINE
:
1375 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1376 tnbr_check(conf
, tnbr
);
1378 case PROC_LDE_ENGINE
:
1380 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1386 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1387 /* find new tnbrs */
1388 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1390 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1392 switch (ldpd_process
) {
1393 case PROC_LDP_ENGINE
:
1396 case PROC_LDE_ENGINE
:
1403 /* update existing tnbrs */
1404 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1405 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1410 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1412 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1416 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1417 /* find deleted nbrps */
1418 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1419 switch (ldpd_process
) {
1420 case PROC_LDP_ENGINE
:
1421 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1423 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1428 (ldp_af_global_get(&global
,
1429 nbr
->af
))->ldp_session_socket
,
1430 nbr
->af
, &nbr
->raddr
, NULL
);
1432 nbr
->auth
.method
= AUTH_NONE
;
1433 if (nbr_session_active_role(nbr
))
1434 nbr_establish_connection(nbr
);
1437 case PROC_LDE_ENGINE
:
1441 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1445 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1446 /* find new nbrps */
1447 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1449 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1451 switch (ldpd_process
) {
1452 case PROC_LDP_ENGINE
:
1453 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1455 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1456 nbr
->auth
.method
= nbrp
->auth
.method
;
1458 if (pfkey_establish(nbr
, nbrp
) == -1)
1459 fatalx("pfkey setup failed");
1462 (ldp_af_global_get(&global
,
1463 nbr
->af
))->ldp_session_socket
,
1464 nbr
->af
, &nbr
->raddr
,
1467 if (nbr_session_active_role(nbr
))
1468 nbr_establish_connection(nbr
);
1471 case PROC_LDE_ENGINE
:
1478 /* update existing nbrps */
1479 if (nbrp
->flags
!= xn
->flags
||
1480 nbrp
->keepalive
!= xn
->keepalive
||
1481 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1482 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1483 nbrp
->auth
.method
!= xn
->auth
.method
||
1484 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1489 nbrp
->keepalive
= xn
->keepalive
;
1490 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1491 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1492 nbrp
->auth
.method
= xn
->auth
.method
;
1493 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1494 sizeof(nbrp
->auth
.md5key
));
1495 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1496 nbrp
->flags
= xn
->flags
;
1498 if (ldpd_process
== PROC_LDP_ENGINE
) {
1499 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1500 if (nbr
&& nbrp_changed
) {
1501 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1504 nbr
->auth
.method
= nbrp
->auth
.method
;
1505 if (pfkey_establish(nbr
, nbrp
) == -1)
1506 fatalx("pfkey setup failed");
1508 nbr
->auth
.method
= nbrp
->auth
.method
;
1509 sock_set_md5sig((ldp_af_global_get(&global
,
1510 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1511 &nbr
->raddr
, nbrp
->auth
.md5key
);
1513 if (nbr_session_active_role(nbr
))
1514 nbr_establish_connection(nbr
);
1521 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1523 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1525 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1526 /* find deleted l2vpns */
1527 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1528 switch (ldpd_process
) {
1529 case PROC_LDE_ENGINE
:
1532 case PROC_LDP_ENGINE
:
1533 ldpe_l2vpn_exit(l2vpn
);
1538 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1542 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1543 /* find new l2vpns */
1544 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1546 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1547 RB_INIT(&l2vpn
->if_tree
);
1548 RB_INIT(&l2vpn
->pw_tree
);
1549 RB_INIT(&l2vpn
->pw_inactive_tree
);
1551 switch (ldpd_process
) {
1552 case PROC_LDE_ENGINE
:
1555 case PROC_LDP_ENGINE
:
1556 ldpe_l2vpn_init(l2vpn
);
1563 /* update existing l2vpns */
1564 merge_l2vpn(conf
, l2vpn
, xl
);
1569 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1571 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1572 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1574 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1575 int previous_pw_type
, previous_mtu
;
1577 previous_pw_type
= l2vpn
->pw_type
;
1578 previous_mtu
= l2vpn
->mtu
;
1580 /* merge intefaces */
1581 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1582 /* find deleted interfaces */
1583 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1584 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1588 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1589 /* find new interfaces */
1590 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1592 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1595 switch (ldpd_process
) {
1596 case PROC_LDP_ENGINE
:
1597 case PROC_LDE_ENGINE
:
1600 kif_redistribute(lif
->ifname
);
1606 /* merge active pseudowires */
1607 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1608 /* find deleted active pseudowires */
1609 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1610 switch (ldpd_process
) {
1611 case PROC_LDE_ENGINE
:
1614 case PROC_LDP_ENGINE
:
1615 ldpe_l2vpn_pw_exit(pw
);
1621 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1625 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1626 /* find new active pseudowires */
1627 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1629 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1632 switch (ldpd_process
) {
1633 case PROC_LDE_ENGINE
:
1636 case PROC_LDP_ENGINE
:
1637 ldpe_l2vpn_pw_init(pw
);
1640 kif_redistribute(pw
->ifname
);
1646 /* update existing active pseudowire */
1647 if (pw
->af
!= xp
->af
||
1648 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1653 /* changes that require a session restart */
1654 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1655 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1660 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1661 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1662 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1663 reinstall_pwfec
= 1;
1665 reinstall_pwfec
= 0;
1667 if (ldpd_process
== PROC_LDP_ENGINE
) {
1669 ldpe_l2vpn_pw_exit(pw
);
1671 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1672 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1673 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1676 if (ldpd_process
== PROC_LDE_ENGINE
&&
1677 !reset_nbr
&& reinstall_pwfec
)
1679 pw
->lsr_id
= xp
->lsr_id
;
1681 pw
->addr
= xp
->addr
;
1682 pw
->pwid
= xp
->pwid
;
1683 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1684 pw
->ifindex
= xp
->ifindex
;
1685 if (xp
->flags
& F_PW_CWORD_CONF
)
1686 pw
->flags
|= F_PW_CWORD_CONF
;
1688 pw
->flags
&= ~F_PW_CWORD_CONF
;
1689 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1690 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1692 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1693 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1694 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1696 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1697 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1698 ldpe_l2vpn_pw_init(pw
);
1699 if (ldpd_process
== PROC_LDE_ENGINE
&&
1700 !reset_nbr
&& reinstall_pwfec
) {
1701 l2vpn
->pw_type
= xl
->pw_type
;
1702 l2vpn
->mtu
= xl
->mtu
;
1704 l2vpn
->pw_type
= previous_pw_type
;
1705 l2vpn
->mtu
= previous_mtu
;
1709 /* merge inactive pseudowires */
1710 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1711 /* find deleted inactive pseudowires */
1712 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1713 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1717 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1718 /* find new inactive pseudowires */
1719 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1721 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1724 switch (ldpd_process
) {
1725 case PROC_LDE_ENGINE
:
1726 case PROC_LDP_ENGINE
:
1729 kif_redistribute(pw
->ifname
);
1735 /* update existing inactive pseudowire */
1736 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1738 pw
->addr
= xp
->addr
;
1739 pw
->pwid
= xp
->pwid
;
1740 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1741 pw
->ifindex
= xp
->ifindex
;
1742 pw
->flags
= xp
->flags
;
1745 l2vpn
->pw_type
= xl
->pw_type
;
1746 l2vpn
->mtu
= xl
->mtu
;
1747 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1748 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1752 config_new_empty(void)
1754 struct ldpd_conf
*xconf
;
1756 xconf
= calloc(1, sizeof(*xconf
));
1760 RB_INIT(&xconf
->iface_tree
);
1761 RB_INIT(&xconf
->tnbr_tree
);
1762 RB_INIT(&xconf
->nbrp_tree
);
1763 RB_INIT(&xconf
->l2vpn_tree
);
1769 config_clear(struct ldpd_conf
*conf
)
1771 struct ldpd_conf
*xconf
;
1774 * Merge current config with an empty config, this will deactivate
1775 * and deallocate all the interfaces, pseudowires and so on. Before
1776 * merging, copy the router-id and other variables to avoid some
1777 * unnecessary operations, like trying to reset the neighborships.
1779 xconf
= config_new_empty();
1780 xconf
->ipv4
= conf
->ipv4
;
1781 xconf
->ipv6
= conf
->ipv6
;
1782 xconf
->rtr_id
= conf
->rtr_id
;
1783 xconf
->trans_pref
= conf
->trans_pref
;
1784 xconf
->flags
= conf
->flags
;
1785 merge_config(conf
, xconf
);