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
,
190 static int ldp_config_fork_apply(struct thread
*t
)
193 * So the frr_config_fork() function schedules
194 * the read of the vty config( if there is a
195 * non-integrated config ) to be after the
196 * end of startup and we are starting the
197 * main process loop. We need to schedule
198 * the application of this if necessary
199 * after the read in of the config.
201 ldp_config_apply(NULL
, vty_conf
);
207 main(int argc
, char *argv
[])
210 int lflag
= 0, eflag
= 0;
211 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
212 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
214 struct thread
*thread
= NULL
;
216 ldpd_process
= PROC_MAIN
;
217 log_procname
= log_procnames
[ldpd_process
];
219 saved_argv0
= argv
[0];
220 if (saved_argv0
== NULL
)
221 saved_argv0
= (char *)"ldpd";
223 frr_preinit(&ldpd_di
, argc
, argv
);
224 frr_opt_add("LEn:", longopts
,
225 " --ctl_socket Override ctl socket path\n"
226 " -n, --instance Instance id\n");
231 opt
= frr_getopt(argc
, argv
, NULL
);
240 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
246 * LDPD_SOCKET configured as relative path
247 * during config? Should really never happen for
250 ctl_sock_name
= (char *)LDPD_SOCKET
;
251 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
252 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
253 strlcat(ctl_sock_path
, ctl_sock_name
,
254 sizeof(ctl_sock_path
));
257 init
.instance
= atoi(optarg
);
258 if (init
.instance
< 1)
273 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
274 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
275 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
276 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
277 sizeof(init
.zclient_serv_path
));
280 if (argc
> 0 || (lflag
&& eflag
))
283 /* check for root privileges */
284 if (geteuid() != 0) {
286 perror(ldpd_di
.progname
);
291 openzlog(ldpd_di
.progname
, "LDP", 0,
292 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
298 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
300 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
301 pipe_parent2ldpe_sync
) == -1)
303 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
305 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
306 pipe_parent2lde_sync
) == -1)
308 sock_set_nonblock(pipe_parent2ldpe
[0]);
309 sock_set_cloexec(pipe_parent2ldpe
[0]);
310 sock_set_nonblock(pipe_parent2ldpe
[1]);
311 sock_set_cloexec(pipe_parent2ldpe
[1]);
312 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
313 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
314 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
315 sock_set_nonblock(pipe_parent2lde
[0]);
316 sock_set_cloexec(pipe_parent2lde
[0]);
317 sock_set_nonblock(pipe_parent2lde
[1]);
318 sock_set_cloexec(pipe_parent2lde
[1]);
319 sock_set_nonblock(pipe_parent2lde_sync
[0]);
320 sock_set_cloexec(pipe_parent2lde_sync
[0]);
321 sock_set_cloexec(pipe_parent2lde_sync
[1]);
324 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
325 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
326 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
327 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
331 vty_config_lockless();
332 vrf_init(NULL
, NULL
, NULL
, NULL
);
335 ldp_zebra_init(master
);
338 * Create base configuration with sane defaults. All configuration
339 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
340 * to merge the changes into ldpd_conf, which contains the actual
341 * running configuration.
343 ldpd_conf
= config_new_empty();
344 vty_conf
= config_new_empty();
345 QOBJ_REG(vty_conf
, ldpd_conf
);
347 /* read configuration file and daemonize */
350 /* apply configuration */
351 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
353 /* setup pipes to children */
354 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
355 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
356 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
357 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
359 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
360 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
361 iev_ldpe
->ev_read
= NULL
;
362 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
364 iev_ldpe
->handler_write
= ldp_write_handler
;
366 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
367 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
368 iev_ldpe_sync
->ev_read
= NULL
;
369 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
370 &iev_ldpe_sync
->ev_read
);
371 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
373 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
374 iev_lde
->handler_read
= main_dispatch_lde
;
375 iev_lde
->ev_read
= NULL
;
376 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
378 iev_lde
->handler_write
= ldp_write_handler
;
380 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
381 iev_lde_sync
->handler_read
= main_dispatch_lde
;
382 iev_lde_sync
->ev_read
= NULL
;
383 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
384 &iev_lde_sync
->ev_read
);
385 iev_lde_sync
->handler_write
= ldp_write_handler
;
387 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
388 fatal("could not establish imsg links");
389 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
391 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
392 main_imsg_send_config(ldpd_conf
);
394 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
395 main_imsg_send_net_sockets(AF_INET
);
396 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
397 main_imsg_send_net_sockets(AF_INET6
);
414 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
415 close(iev_ldpe
->ibuf
.fd
);
416 msgbuf_clear(&iev_lde
->ibuf
.w
);
417 close(iev_lde
->ibuf
.fd
);
419 config_clear(ldpd_conf
);
421 ldp_config_reset(vty_conf
);
422 QOBJ_UNREG(vty_conf
);
425 log_debug("waiting for children to terminate");
428 /* Wait for child process. */
431 /* We got interrupted, try again. */
434 /* No more processes were found. */
438 /* Unhandled errno condition. */
443 /* We found something, lets announce it. */
444 if (WIFSIGNALED(status
))
445 log_warnx("%s terminated; signal %d",
446 (pid
== lde_pid
? "label decision engine"
450 /* Repeat until there are no more child processes. */
456 log_info("terminating");
467 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
470 int argc
= 0, nullfd
;
473 switch (pid
= fork()) {
475 fatal("cannot fork");
484 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
486 zlog_err("%s: failed to open /dev/null: %s", __func__
,
487 safe_strerror(errno
));
495 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
496 fatal("cannot setup imsg async fd");
497 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
498 fatal("cannot setup imsg sync fd");
500 argv
[argc
++] = argv0
;
503 fatalx("Can not start main process");
504 case PROC_LDE_ENGINE
:
505 argv
[argc
++] = (char *)"-L";
507 case PROC_LDP_ENGINE
:
508 argv
[argc
++] = (char *)"-E";
520 main_dispatch_ldpe(struct thread
*thread
)
522 struct imsgev
*iev
= THREAD_ARG(thread
);
523 struct imsgbuf
*ibuf
= &iev
->ibuf
;
531 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
532 fatal("imsg_read error");
533 if (n
== 0) /* connection closed */
537 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
543 switch (imsg
.hdr
.type
) {
545 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
547 case IMSG_REQUEST_SOCKETS
:
549 main_imsg_send_net_sockets(af
);
552 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
553 sizeof(struct acl_check
))
554 fatalx("IMSG_ACL_CHECK imsg with wrong len");
555 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
558 log_debug("%s: error handling imsg %d", __func__
,
567 /* this pipe is dead, so remove the event handlers and exit */
568 THREAD_READ_OFF(iev
->ev_read
);
569 THREAD_WRITE_OFF(iev
->ev_write
);
574 kill(lde_pid
, SIGTERM
);
582 main_dispatch_lde(struct thread
*thread
)
584 struct imsgev
*iev
= THREAD_ARG(thread
);
585 struct imsgbuf
*ibuf
= &iev
->ibuf
;
592 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
593 fatal("imsg_read error");
594 if (n
== 0) /* connection closed */
598 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
604 switch (imsg
.hdr
.type
) {
606 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
608 case IMSG_KLABEL_CHANGE
:
609 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
610 sizeof(struct kroute
))
611 fatalx("invalid size of IMSG_KLABEL_CHANGE");
612 if (kr_change(imsg
.data
))
613 log_warnx("%s: error changing route", __func__
);
615 case IMSG_KLABEL_DELETE
:
616 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
617 sizeof(struct kroute
))
618 fatalx("invalid size of IMSG_KLABEL_DELETE");
619 if (kr_delete(imsg
.data
))
620 log_warnx("%s: error deleting route", __func__
);
623 case IMSG_KPW_DELETE
:
626 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
627 sizeof(struct zapi_pw
))
628 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
630 switch (imsg
.hdr
.type
) {
632 if (kmpw_add(imsg
.data
))
633 log_warnx("%s: error adding "
634 "pseudowire", __func__
);
636 case IMSG_KPW_DELETE
:
637 if (kmpw_del(imsg
.data
))
638 log_warnx("%s: error deleting "
639 "pseudowire", __func__
);
642 if (kmpw_set(imsg
.data
))
643 log_warnx("%s: error setting "
644 "pseudowire", __func__
);
647 if (kmpw_unset(imsg
.data
))
648 log_warnx("%s: error unsetting "
649 "pseudowire", __func__
);
654 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
655 sizeof(struct acl_check
))
656 fatalx("IMSG_ACL_CHECK imsg with wrong len");
657 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
660 log_debug("%s: error handling imsg %d", __func__
,
669 /* this pipe is dead, so remove the event handlers and exit */
670 THREAD_READ_OFF(iev
->ev_read
);
671 THREAD_WRITE_OFF(iev
->ev_write
);
676 kill(ldpe_pid
, SIGTERM
);
684 ldp_write_handler(struct thread
*thread
)
686 struct imsgev
*iev
= THREAD_ARG(thread
);
687 struct imsgbuf
*ibuf
= &iev
->ibuf
;
690 iev
->ev_write
= NULL
;
692 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
693 fatal("msgbuf_write");
695 /* this pipe is dead, so remove the event handlers */
696 THREAD_READ_OFF(iev
->ev_read
);
697 THREAD_WRITE_OFF(iev
->ev_write
);
707 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
709 if (iev_ldpe
== NULL
)
711 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
715 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
717 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
721 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
723 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
725 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
727 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
733 imsg_event_add(struct imsgev
*iev
)
735 if (iev
->handler_read
)
736 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
739 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
740 thread_add_write(master
, iev
->handler_write
, iev
,
741 iev
->ibuf
.fd
, &iev
->ev_write
);
745 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
746 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
750 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
751 pid
, fd
, data
, datalen
)) != -1)
757 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
759 ibuf_close(&eb
->wbuf
, buf
);
764 evbuf_event_add(struct evbuf
*eb
)
767 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
772 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
775 msgbuf_init(&eb
->wbuf
);
777 eb
->handler
= handler
;
782 evbuf_clear(struct evbuf
*eb
)
784 THREAD_WRITE_OFF(eb
->ev
);
785 msgbuf_clear(&eb
->wbuf
);
790 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
792 int pipe_ldpe2lde
[2];
794 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
796 sock_set_nonblock(pipe_ldpe2lde
[0]);
797 sock_set_nonblock(pipe_ldpe2lde
[1]);
799 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
802 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
810 main_imsg_send_net_sockets(int af
)
812 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
815 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
816 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
817 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
818 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
822 main_imsg_send_net_socket(int af
, enum socket_type type
)
826 fd
= ldp_create_socket(af
, type
);
828 log_warnx("%s: failed to create %s socket for address-family "
829 "%s", __func__
, socket_name(type
), af_name(af
));
833 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
838 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
839 union ldpd_addr
*addr
, uint8_t prefixlen
)
843 struct acl_check acl_check
;
845 if (acl_name
[0] == '\0')
846 return FILTER_PERMIT
;
849 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
851 acl_check
.addr
= *addr
;
852 acl_check
.prefixlen
= prefixlen
;
854 /* send (blocking) */
855 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
857 imsg_flush(&iev
->ibuf
);
859 /* receive (blocking) and parse result */
860 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
861 fatal("imsg_read error");
862 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
864 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
865 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
866 fatalx("ldp_acl_request: invalid response");
868 return (*((int *)imsg
.data
));
872 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
874 struct access_list
*alist
;
875 struct prefix prefix
;
878 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
880 result
= FILTER_DENY
;
882 prefix
.family
= acl_check
->af
;
883 switch (prefix
.family
) {
885 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
888 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
891 fatalx("ldp_acl_reply: unknown af");
893 prefix
.prefixlen
= acl_check
->prefixlen
;
894 result
= access_list_apply(alist
, &prefix
);
897 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
901 struct ldpd_af_conf
*
902 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
906 return (&xconf
->ipv4
);
908 return (&xconf
->ipv6
);
910 fatalx("ldp_af_conf_get: unknown af");
914 struct ldpd_af_global
*
915 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
919 return (&xglobal
->ipv4
);
921 return (&xglobal
->ipv6
);
923 fatalx("ldp_af_global_get: unknown af");
928 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
930 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
931 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
935 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
937 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
938 return (xconf
->rtr_id
.s_addr
);
940 return (global
.rtr_id
.s_addr
);
944 main_imsg_send_config(struct ldpd_conf
*xconf
)
948 struct nbr_params
*nbrp
;
950 struct l2vpn_if
*lif
;
953 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
954 sizeof(*xconf
)) == -1)
957 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
958 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
959 sizeof(*iface
)) == -1)
963 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
964 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
965 sizeof(*tnbr
)) == -1)
969 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
970 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
971 sizeof(*nbrp
)) == -1)
975 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
976 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
977 sizeof(*l2vpn
)) == -1)
980 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
981 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
985 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
986 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
990 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
991 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
997 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
1004 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
1007 * When reading from a configuration file (startup and sighup), we
1008 * call merge_config() only once after the whole config has been read.
1009 * This is the optimal and least disruptive way to update the running
1012 if (vty
&& vty
->type
== VTY_FILE
)
1015 ldp_config_normalize(xconf
);
1017 if (main_imsg_send_config(xconf
) == -1)
1020 merge_config(ldpd_conf
, xconf
);
1026 ldp_config_normalize(struct ldpd_conf
*xconf
)
1028 struct iface
*iface
, *itmp
;
1029 struct nbr_params
*nbrp
, *ntmp
;
1030 struct l2vpn
*l2vpn
;
1031 struct l2vpn_pw
*pw
, *ptmp
;
1033 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1034 ldp_config_reset_main(xconf
);
1036 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1037 ldp_config_reset_af(xconf
, AF_INET
);
1038 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1039 ldp_config_reset_af(xconf
, AF_INET6
);
1041 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1042 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1046 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1050 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1051 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1053 if (nbrp
->auth
.method
!= AUTH_NONE
)
1057 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1062 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1063 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1064 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1066 pw
->addr
.v4
= pw
->lsr_id
;
1069 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1071 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1072 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1074 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1076 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1078 pw
->addr
.v4
= pw
->lsr_id
;
1081 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1083 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1084 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1090 ldp_config_reset(struct ldpd_conf
*conf
)
1092 ldp_config_reset_main(conf
);
1093 ldp_config_reset_l2vpns(conf
);
1097 ldp_config_reset_main(struct ldpd_conf
*conf
)
1099 struct iface
*iface
;
1100 struct nbr_params
*nbrp
;
1102 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1103 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1106 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1110 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1111 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1114 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1118 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1119 ldp_config_reset_af(conf
, AF_INET
);
1120 ldp_config_reset_af(conf
, AF_INET6
);
1121 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1122 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1123 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1124 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1125 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1130 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1132 struct ldpd_af_conf
*af_conf
;
1133 struct iface
*iface
;
1134 struct iface_af
*ia
;
1135 struct tnbr
*tnbr
, *ttmp
;
1137 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1138 ia
= iface_af_get(iface
, af
);
1142 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1147 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1151 af_conf
= ldp_af_conf_get(conf
, af
);
1152 af_conf
->keepalive
= 180;
1153 af_conf
->lhello_holdtime
= 0;
1154 af_conf
->lhello_interval
= 0;
1155 af_conf
->thello_holdtime
= 0;
1156 af_conf
->thello_interval
= 0;
1157 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1162 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1164 struct l2vpn
*l2vpn
;
1165 struct l2vpn_if
*lif
;
1166 struct l2vpn_pw
*pw
;
1168 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1169 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1170 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1171 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1174 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1177 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1178 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1181 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1184 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1185 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1188 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1192 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1198 ldp_clear_config(struct ldpd_conf
*xconf
)
1200 struct iface
*iface
;
1202 struct nbr_params
*nbrp
;
1203 struct l2vpn
*l2vpn
;
1205 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1206 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1208 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1211 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1212 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1214 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1217 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1218 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1220 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1223 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1224 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1226 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1233 #define COPY(a, b) do { \
1234 a = malloc(sizeof(*a)); \
1241 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1243 merge_global(conf
, xconf
);
1244 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1245 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1246 merge_ifaces(conf
, xconf
);
1247 merge_tnbrs(conf
, xconf
);
1248 merge_nbrps(conf
, xconf
);
1249 merge_l2vpns(conf
, xconf
);
1253 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1255 /* change of router-id requires resetting all neighborships */
1256 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1257 if (ldpd_process
== PROC_LDP_ENGINE
) {
1258 ldpe_reset_nbrs(AF_UNSPEC
);
1259 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1260 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1261 if_update_all(AF_UNSPEC
);
1262 tnbr_update_all(AF_UNSPEC
);
1265 conf
->rtr_id
= xconf
->rtr_id
;
1268 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1269 conf
->lhello_interval
= xconf
->lhello_interval
;
1270 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1271 conf
->thello_interval
= xconf
->thello_interval
;
1273 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1274 if (ldpd_process
== PROC_LDP_ENGINE
)
1275 ldpe_reset_ds_nbrs();
1276 conf
->trans_pref
= xconf
->trans_pref
;
1279 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1280 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1281 if (ldpd_process
== PROC_LDP_ENGINE
)
1282 ldpe_reset_ds_nbrs();
1285 conf
->flags
= xconf
->flags
;
1289 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1291 int stop_init_backoff
= 0;
1292 int remove_dynamic_tnbrs
= 0;
1293 int change_egress_label
= 0;
1294 int reset_nbrs_ipv4
= 0;
1296 int update_sockets
= 0;
1299 if (af_conf
->keepalive
!= xa
->keepalive
) {
1300 af_conf
->keepalive
= xa
->keepalive
;
1301 stop_init_backoff
= 1;
1303 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1304 af_conf
->lhello_interval
= xa
->lhello_interval
;
1305 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1306 af_conf
->thello_interval
= xa
->thello_interval
;
1309 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1310 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1311 remove_dynamic_tnbrs
= 1;
1312 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1313 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1315 /* need to set/unset IPV6_MINHOPCOUNT */
1318 /* for LDPv4 just resetting the neighbors is enough */
1319 reset_nbrs_ipv4
= 1;
1321 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1322 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1323 change_egress_label
= 1;
1324 af_conf
->flags
= xa
->flags
;
1326 /* update the transport address */
1327 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1328 af_conf
->trans_addr
= xa
->trans_addr
;
1333 if (strcmp(af_conf
->acl_label_advertise_to
,
1334 xa
->acl_label_advertise_to
) ||
1335 strcmp(af_conf
->acl_label_advertise_for
,
1336 xa
->acl_label_advertise_for
) ||
1337 strcmp(af_conf
->acl_label_accept_from
,
1338 xa
->acl_label_accept_from
) ||
1339 strcmp(af_conf
->acl_label_accept_for
,
1340 xa
->acl_label_accept_for
))
1342 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1343 remove_dynamic_tnbrs
= 1;
1344 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1345 change_egress_label
= 1;
1346 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1347 sizeof(af_conf
->acl_thello_accept_from
));
1348 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1349 sizeof(af_conf
->acl_label_allocate_for
));
1350 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1351 sizeof(af_conf
->acl_label_advertise_to
));
1352 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1353 sizeof(af_conf
->acl_label_advertise_for
));
1354 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1355 sizeof(af_conf
->acl_label_accept_from
));
1356 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1357 sizeof(af_conf
->acl_label_accept_for
));
1358 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1359 sizeof(af_conf
->acl_label_expnull_for
));
1361 /* apply the new configuration */
1362 switch (ldpd_process
) {
1363 case PROC_LDE_ENGINE
:
1364 if (change_egress_label
)
1365 lde_change_egress_label(af
);
1367 case PROC_LDP_ENGINE
:
1368 if (stop_init_backoff
)
1369 ldpe_stop_init_backoff(af
);
1370 if (remove_dynamic_tnbrs
)
1371 ldpe_remove_dynamic_tnbrs(af
);
1373 ldpe_reset_nbrs(AF_UNSPEC
);
1374 else if (reset_nbrs_ipv4
)
1375 ldpe_reset_nbrs(AF_INET
);
1378 if (update_sockets
&& iev_ldpe
)
1379 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1386 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1388 struct iface
*iface
, *itmp
, *xi
;
1390 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1391 /* find deleted interfaces */
1392 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1393 switch (ldpd_process
) {
1394 case PROC_LDP_ENGINE
:
1395 ldpe_if_exit(iface
);
1397 case PROC_LDE_ENGINE
:
1401 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1405 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1406 /* find new interfaces */
1407 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1409 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1411 switch (ldpd_process
) {
1412 case PROC_LDP_ENGINE
:
1413 ldpe_if_init(iface
);
1415 case PROC_LDE_ENGINE
:
1418 /* resend addresses to activate new interfaces */
1419 kif_redistribute(iface
->name
);
1425 /* update existing interfaces */
1426 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1427 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1432 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1434 if (ia
->enabled
!= xi
->enabled
) {
1435 ia
->enabled
= xi
->enabled
;
1436 if (ldpd_process
== PROC_LDP_ENGINE
)
1437 ldp_if_update(ia
->iface
, ia
->af
);
1439 ia
->hello_holdtime
= xi
->hello_holdtime
;
1440 ia
->hello_interval
= xi
->hello_interval
;
1444 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1446 struct tnbr
*tnbr
, *ttmp
, *xt
;
1448 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1449 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1452 /* find deleted tnbrs */
1453 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1454 switch (ldpd_process
) {
1455 case PROC_LDP_ENGINE
:
1456 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1457 tnbr_check(conf
, tnbr
);
1459 case PROC_LDE_ENGINE
:
1461 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1467 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1468 /* find new tnbrs */
1469 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1471 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1473 switch (ldpd_process
) {
1474 case PROC_LDP_ENGINE
:
1477 case PROC_LDE_ENGINE
:
1484 /* update existing tnbrs */
1485 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1486 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1491 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1493 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1497 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1498 /* find deleted nbrps */
1499 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1500 switch (ldpd_process
) {
1501 case PROC_LDP_ENGINE
:
1502 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1504 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1509 (ldp_af_global_get(&global
,
1510 nbr
->af
))->ldp_session_socket
,
1511 nbr
->af
, &nbr
->raddr
, NULL
);
1513 nbr
->auth
.method
= AUTH_NONE
;
1514 if (nbr_session_active_role(nbr
))
1515 nbr_establish_connection(nbr
);
1518 case PROC_LDE_ENGINE
:
1522 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1526 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1527 /* find new nbrps */
1528 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1530 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1532 switch (ldpd_process
) {
1533 case PROC_LDP_ENGINE
:
1534 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1536 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1537 nbr
->auth
.method
= nbrp
->auth
.method
;
1539 if (pfkey_establish(nbr
, nbrp
) == -1)
1540 fatalx("pfkey setup failed");
1543 (ldp_af_global_get(&global
,
1544 nbr
->af
))->ldp_session_socket
,
1545 nbr
->af
, &nbr
->raddr
,
1548 if (nbr_session_active_role(nbr
))
1549 nbr_establish_connection(nbr
);
1552 case PROC_LDE_ENGINE
:
1559 /* update existing nbrps */
1560 if (nbrp
->flags
!= xn
->flags
||
1561 nbrp
->keepalive
!= xn
->keepalive
||
1562 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1563 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1564 nbrp
->auth
.method
!= xn
->auth
.method
||
1565 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1570 nbrp
->keepalive
= xn
->keepalive
;
1571 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1572 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1573 nbrp
->auth
.method
= xn
->auth
.method
;
1574 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1575 sizeof(nbrp
->auth
.md5key
));
1576 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1577 nbrp
->flags
= xn
->flags
;
1579 if (ldpd_process
== PROC_LDP_ENGINE
) {
1580 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1581 if (nbr
&& nbrp_changed
) {
1582 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1585 nbr
->auth
.method
= nbrp
->auth
.method
;
1586 if (pfkey_establish(nbr
, nbrp
) == -1)
1587 fatalx("pfkey setup failed");
1589 nbr
->auth
.method
= nbrp
->auth
.method
;
1590 sock_set_md5sig((ldp_af_global_get(&global
,
1591 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1592 &nbr
->raddr
, nbrp
->auth
.md5key
);
1594 if (nbr_session_active_role(nbr
))
1595 nbr_establish_connection(nbr
);
1602 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1604 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1606 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1607 /* find deleted l2vpns */
1608 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1609 switch (ldpd_process
) {
1610 case PROC_LDE_ENGINE
:
1613 case PROC_LDP_ENGINE
:
1614 ldpe_l2vpn_exit(l2vpn
);
1619 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1623 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1624 /* find new l2vpns */
1625 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1627 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1628 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1629 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1630 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1632 switch (ldpd_process
) {
1633 case PROC_LDE_ENGINE
:
1636 case PROC_LDP_ENGINE
:
1637 ldpe_l2vpn_init(l2vpn
);
1644 /* update existing l2vpns */
1645 merge_l2vpn(conf
, l2vpn
, xl
);
1650 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1652 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1653 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1655 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1656 int previous_pw_type
, previous_mtu
;
1658 previous_pw_type
= l2vpn
->pw_type
;
1659 previous_mtu
= l2vpn
->mtu
;
1661 /* merge intefaces */
1662 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1663 /* find deleted interfaces */
1664 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1665 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1669 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1670 /* find new interfaces */
1671 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1673 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1676 switch (ldpd_process
) {
1677 case PROC_LDP_ENGINE
:
1678 case PROC_LDE_ENGINE
:
1681 kif_redistribute(lif
->ifname
);
1687 /* merge active pseudowires */
1688 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1689 /* find deleted active pseudowires */
1690 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1691 switch (ldpd_process
) {
1692 case PROC_LDE_ENGINE
:
1695 case PROC_LDP_ENGINE
:
1696 ldpe_l2vpn_pw_exit(pw
);
1702 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1706 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1707 /* find new active pseudowires */
1708 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1710 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1713 switch (ldpd_process
) {
1714 case PROC_LDE_ENGINE
:
1717 case PROC_LDP_ENGINE
:
1718 ldpe_l2vpn_pw_init(pw
);
1721 kif_redistribute(pw
->ifname
);
1727 /* update existing active pseudowire */
1728 if (pw
->af
!= xp
->af
||
1729 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1734 /* changes that require a session restart */
1735 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1736 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1741 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1742 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1743 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1744 reinstall_pwfec
= 1;
1746 reinstall_pwfec
= 0;
1748 if (ldpd_process
== PROC_LDP_ENGINE
) {
1750 ldpe_l2vpn_pw_exit(pw
);
1752 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1753 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1754 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1757 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1759 pw
->lsr_id
= xp
->lsr_id
;
1761 pw
->addr
= xp
->addr
;
1762 pw
->pwid
= xp
->pwid
;
1763 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1764 pw
->ifindex
= xp
->ifindex
;
1765 if (xp
->flags
& F_PW_CWORD_CONF
)
1766 pw
->flags
|= F_PW_CWORD_CONF
;
1768 pw
->flags
&= ~F_PW_CWORD_CONF
;
1769 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1770 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1772 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1773 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1774 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1776 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1777 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1778 ldpe_l2vpn_pw_init(pw
);
1779 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1780 l2vpn
->pw_type
= xl
->pw_type
;
1781 l2vpn
->mtu
= xl
->mtu
;
1783 l2vpn
->pw_type
= previous_pw_type
;
1784 l2vpn
->mtu
= previous_mtu
;
1788 /* merge inactive pseudowires */
1789 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1790 /* find deleted inactive pseudowires */
1791 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1792 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1796 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1797 /* find new inactive pseudowires */
1798 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1800 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1803 switch (ldpd_process
) {
1804 case PROC_LDE_ENGINE
:
1805 case PROC_LDP_ENGINE
:
1808 kif_redistribute(pw
->ifname
);
1814 /* update existing inactive pseudowire */
1815 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1817 pw
->addr
= xp
->addr
;
1818 pw
->pwid
= xp
->pwid
;
1819 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1820 pw
->ifindex
= xp
->ifindex
;
1821 pw
->flags
= xp
->flags
;
1824 l2vpn
->pw_type
= xl
->pw_type
;
1825 l2vpn
->mtu
= xl
->mtu
;
1826 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1827 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1831 config_new_empty(void)
1833 struct ldpd_conf
*xconf
;
1835 xconf
= calloc(1, sizeof(*xconf
));
1839 RB_INIT(iface_head
, &xconf
->iface_tree
);
1840 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1841 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1842 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1844 /* set default values */
1845 ldp_config_reset(xconf
);
1851 config_clear(struct ldpd_conf
*conf
)
1853 struct ldpd_conf
*xconf
;
1856 * Merge current config with an empty config, this will deactivate
1857 * and deallocate all the interfaces, pseudowires and so on. Before
1858 * merging, copy the router-id and other variables to avoid some
1859 * unnecessary operations, like trying to reset the neighborships.
1861 xconf
= config_new_empty();
1862 xconf
->ipv4
= conf
->ipv4
;
1863 xconf
->ipv6
= conf
->ipv6
;
1864 xconf
->rtr_id
= conf
->rtr_id
;
1865 xconf
->trans_pref
= conf
->trans_pref
;
1866 xconf
->flags
= conf
->flags
;
1867 merge_config(conf
, xconf
);