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
, frr_zclientpath
,
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_DEBUG_UPDATE
, &ldp_debug
,
375 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
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
);
398 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
399 close(iev_ldpe
->ibuf
.fd
);
400 msgbuf_clear(&iev_lde
->ibuf
.w
);
401 close(iev_lde
->ibuf
.fd
);
403 config_clear(ldpd_conf
);
405 ldp_config_reset(vty_conf
);
406 QOBJ_UNREG(vty_conf
);
409 log_debug("waiting for children to terminate");
413 if (errno
!= EINTR
&& errno
!= ECHILD
)
415 } else if (WIFSIGNALED(status
))
416 log_warnx("%s terminated; signal %d",
417 (pid
== lde_pid
) ? "label decision engine" :
418 "ldp engine", WTERMSIG(status
));
419 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
424 log_info("terminating");
435 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
441 switch (pid
= fork()) {
443 fatal("cannot fork");
452 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
453 fatal("cannot setup imsg async fd");
454 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
455 fatal("cannot setup imsg sync fd");
457 argv
[argc
++] = argv0
;
460 fatalx("Can not start main process");
461 case PROC_LDE_ENGINE
:
462 argv
[argc
++] = (char *)"-L";
464 case PROC_LDP_ENGINE
:
465 argv
[argc
++] = (char *)"-E";
477 main_dispatch_ldpe(struct thread
*thread
)
479 struct imsgev
*iev
= THREAD_ARG(thread
);
480 struct imsgbuf
*ibuf
= &iev
->ibuf
;
488 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
489 fatal("imsg_read error");
490 if (n
== 0) /* connection closed */
494 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
500 switch (imsg
.hdr
.type
) {
502 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
504 case IMSG_REQUEST_SOCKETS
:
506 main_imsg_send_net_sockets(af
);
509 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
510 sizeof(struct acl_check
))
511 fatalx("IMSG_ACL_CHECK imsg with wrong len");
512 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
515 log_debug("%s: error handling imsg %d", __func__
,
524 /* this pipe is dead, so remove the event handlers and exit */
525 THREAD_READ_OFF(iev
->ev_read
);
526 THREAD_WRITE_OFF(iev
->ev_write
);
531 kill(lde_pid
, SIGTERM
);
539 main_dispatch_lde(struct thread
*thread
)
541 struct imsgev
*iev
= THREAD_ARG(thread
);
542 struct imsgbuf
*ibuf
= &iev
->ibuf
;
549 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
550 fatal("imsg_read error");
551 if (n
== 0) /* connection closed */
555 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
561 switch (imsg
.hdr
.type
) {
563 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
565 case IMSG_KLABEL_CHANGE
:
566 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
567 sizeof(struct kroute
))
568 fatalx("invalid size of IMSG_KLABEL_CHANGE");
569 if (kr_change(imsg
.data
))
570 log_warnx("%s: error changing route", __func__
);
572 case IMSG_KLABEL_DELETE
:
573 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
574 sizeof(struct kroute
))
575 fatalx("invalid size of IMSG_KLABEL_DELETE");
576 if (kr_delete(imsg
.data
))
577 log_warnx("%s: error deleting route", __func__
);
580 case IMSG_KPW_DELETE
:
583 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
584 sizeof(struct zapi_pw
))
585 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
587 switch (imsg
.hdr
.type
) {
589 if (kmpw_add(imsg
.data
))
590 log_warnx("%s: error adding "
591 "pseudowire", __func__
);
593 case IMSG_KPW_DELETE
:
594 if (kmpw_del(imsg
.data
))
595 log_warnx("%s: error deleting "
596 "pseudowire", __func__
);
599 if (kmpw_set(imsg
.data
))
600 log_warnx("%s: error setting "
601 "pseudowire", __func__
);
604 if (kmpw_unset(imsg
.data
))
605 log_warnx("%s: error unsetting "
606 "pseudowire", __func__
);
611 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
612 sizeof(struct acl_check
))
613 fatalx("IMSG_ACL_CHECK imsg with wrong len");
614 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
617 log_debug("%s: error handling imsg %d", __func__
,
626 /* this pipe is dead, so remove the event handlers and exit */
627 THREAD_READ_OFF(iev
->ev_read
);
628 THREAD_WRITE_OFF(iev
->ev_write
);
633 kill(ldpe_pid
, SIGTERM
);
641 ldp_write_handler(struct thread
*thread
)
643 struct imsgev
*iev
= THREAD_ARG(thread
);
644 struct imsgbuf
*ibuf
= &iev
->ibuf
;
647 iev
->ev_write
= NULL
;
649 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
650 fatal("msgbuf_write");
652 /* this pipe is dead, so remove the event handlers */
653 THREAD_READ_OFF(iev
->ev_read
);
654 THREAD_WRITE_OFF(iev
->ev_write
);
664 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
666 if (iev_ldpe
== NULL
)
668 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
672 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
674 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
678 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
680 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
682 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
684 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
690 imsg_event_add(struct imsgev
*iev
)
692 if (iev
->handler_read
)
693 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
696 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
697 thread_add_write(master
, iev
->handler_write
, iev
,
698 iev
->ibuf
.fd
, &iev
->ev_write
);
702 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
703 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
707 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
708 pid
, fd
, data
, datalen
)) != -1)
714 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
716 ibuf_close(&eb
->wbuf
, buf
);
721 evbuf_event_add(struct evbuf
*eb
)
724 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
729 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
732 msgbuf_init(&eb
->wbuf
);
734 eb
->handler
= handler
;
739 evbuf_clear(struct evbuf
*eb
)
741 THREAD_WRITE_OFF(eb
->ev
);
742 msgbuf_clear(&eb
->wbuf
);
747 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
749 int pipe_ldpe2lde
[2];
751 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
753 sock_set_nonblock(pipe_ldpe2lde
[0]);
754 sock_set_nonblock(pipe_ldpe2lde
[1]);
756 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
759 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
767 main_imsg_send_net_sockets(int af
)
769 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
772 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
773 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
774 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
775 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
779 main_imsg_send_net_socket(int af
, enum socket_type type
)
783 fd
= ldp_create_socket(af
, type
);
785 log_warnx("%s: failed to create %s socket for address-family "
786 "%s", __func__
, socket_name(type
), af_name(af
));
790 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
795 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
796 union ldpd_addr
*addr
, uint8_t prefixlen
)
800 struct acl_check acl_check
;
802 if (acl_name
[0] == '\0')
803 return FILTER_PERMIT
;
806 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
808 acl_check
.addr
= *addr
;
809 acl_check
.prefixlen
= prefixlen
;
811 /* send (blocking) */
812 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
814 imsg_flush(&iev
->ibuf
);
816 /* receive (blocking) and parse result */
817 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
818 fatal("imsg_read error");
819 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
821 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
822 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
823 fatalx("ldp_acl_request: invalid response");
825 return (*((int *)imsg
.data
));
829 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
831 struct access_list
*alist
;
832 struct prefix prefix
;
835 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
837 result
= FILTER_DENY
;
839 prefix
.family
= acl_check
->af
;
840 switch (prefix
.family
) {
842 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
845 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
848 fatalx("ldp_acl_reply: unknown af");
850 prefix
.prefixlen
= acl_check
->prefixlen
;
851 result
= access_list_apply(alist
, &prefix
);
854 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
858 struct ldpd_af_conf
*
859 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
863 return (&xconf
->ipv4
);
865 return (&xconf
->ipv6
);
867 fatalx("ldp_af_conf_get: unknown af");
871 struct ldpd_af_global
*
872 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
876 return (&xglobal
->ipv4
);
878 return (&xglobal
->ipv6
);
880 fatalx("ldp_af_global_get: unknown af");
885 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
887 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
888 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
892 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
894 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
895 return (xconf
->rtr_id
.s_addr
);
897 return (global
.rtr_id
.s_addr
);
901 main_imsg_send_config(struct ldpd_conf
*xconf
)
905 struct nbr_params
*nbrp
;
907 struct l2vpn_if
*lif
;
910 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
911 sizeof(*xconf
)) == -1)
914 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
915 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
916 sizeof(*iface
)) == -1)
920 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
921 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
922 sizeof(*tnbr
)) == -1)
926 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
927 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
928 sizeof(*nbrp
)) == -1)
932 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
933 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
934 sizeof(*l2vpn
)) == -1)
937 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
938 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
942 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
943 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
947 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
948 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
954 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
961 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
964 * When reading from a configuration file (startup and sighup), we
965 * call merge_config() only once after the whole config has been read.
966 * This is the optimal and least disruptive way to update the running
969 if (vty
&& vty
->type
== VTY_FILE
)
972 ldp_config_normalize(xconf
);
974 if (main_imsg_send_config(xconf
) == -1)
977 merge_config(ldpd_conf
, xconf
);
983 ldp_config_normalize(struct ldpd_conf
*xconf
)
985 struct iface
*iface
, *itmp
;
986 struct nbr_params
*nbrp
, *ntmp
;
988 struct l2vpn_pw
*pw
, *ptmp
;
990 if (!(xconf
->flags
& F_LDPD_ENABLED
))
991 ldp_config_reset_main(xconf
);
993 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
994 ldp_config_reset_af(xconf
, AF_INET
);
995 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
996 ldp_config_reset_af(xconf
, AF_INET6
);
998 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
999 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1003 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1007 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1008 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1010 if (nbrp
->auth
.method
!= AUTH_NONE
)
1014 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1019 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1020 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
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_tree
, pw
);
1029 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1031 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1033 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1035 pw
->addr
.v4
= pw
->lsr_id
;
1038 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1040 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1041 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1047 ldp_config_reset(struct ldpd_conf
*conf
)
1049 ldp_config_reset_main(conf
);
1050 ldp_config_reset_l2vpns(conf
);
1054 ldp_config_reset_main(struct ldpd_conf
*conf
)
1056 struct iface
*iface
;
1057 struct nbr_params
*nbrp
;
1059 while ((iface
= RB_ROOT(iface_head
, &conf
->iface_tree
)) != NULL
) {
1061 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1065 while ((nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
)) != NULL
) {
1067 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1071 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1072 ldp_config_reset_af(conf
, AF_INET
);
1073 ldp_config_reset_af(conf
, AF_INET6
);
1074 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1075 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1076 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1077 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1078 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1083 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1085 struct ldpd_af_conf
*af_conf
;
1086 struct iface
*iface
;
1087 struct iface_af
*ia
;
1088 struct tnbr
*tnbr
, *ttmp
;
1090 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1091 ia
= iface_af_get(iface
, af
);
1095 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1100 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1104 af_conf
= ldp_af_conf_get(conf
, af
);
1105 af_conf
->keepalive
= 180;
1106 af_conf
->lhello_holdtime
= 0;
1107 af_conf
->lhello_interval
= 0;
1108 af_conf
->thello_holdtime
= 0;
1109 af_conf
->thello_interval
= 0;
1110 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1115 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1117 struct l2vpn
*l2vpn
;
1118 struct l2vpn_if
*lif
;
1119 struct l2vpn_pw
*pw
;
1121 while ((l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
)) != NULL
) {
1122 while ((lif
= RB_ROOT(l2vpn_if_head
,
1123 &l2vpn
->if_tree
)) != NULL
) {
1125 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1128 while ((pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
)) != NULL
) {
1130 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1133 while ((pw
= RB_ROOT(l2vpn_pw_head
,
1134 &l2vpn
->pw_inactive_tree
)) != NULL
) {
1136 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1140 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1146 ldp_clear_config(struct ldpd_conf
*xconf
)
1148 struct iface
*iface
;
1150 struct nbr_params
*nbrp
;
1151 struct l2vpn
*l2vpn
;
1153 while ((iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
)) != NULL
) {
1154 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1157 while ((tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
)) != NULL
) {
1158 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1161 while ((nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
)) != NULL
) {
1162 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1165 while ((l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
)) != NULL
) {
1166 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1173 #define COPY(a, b) do { \
1174 a = malloc(sizeof(*a)); \
1181 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1183 merge_global(conf
, xconf
);
1184 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1185 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1186 merge_ifaces(conf
, xconf
);
1187 merge_tnbrs(conf
, xconf
);
1188 merge_nbrps(conf
, xconf
);
1189 merge_l2vpns(conf
, xconf
);
1193 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1195 /* change of router-id requires resetting all neighborships */
1196 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1197 if (ldpd_process
== PROC_LDP_ENGINE
) {
1198 ldpe_reset_nbrs(AF_UNSPEC
);
1199 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1200 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1201 if_update_all(AF_UNSPEC
);
1202 tnbr_update_all(AF_UNSPEC
);
1205 conf
->rtr_id
= xconf
->rtr_id
;
1208 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1209 conf
->lhello_interval
= xconf
->lhello_interval
;
1210 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1211 conf
->thello_interval
= xconf
->thello_interval
;
1213 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1214 if (ldpd_process
== PROC_LDP_ENGINE
)
1215 ldpe_reset_ds_nbrs();
1216 conf
->trans_pref
= xconf
->trans_pref
;
1219 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1220 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1221 if (ldpd_process
== PROC_LDP_ENGINE
)
1222 ldpe_reset_ds_nbrs();
1225 conf
->flags
= xconf
->flags
;
1229 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1231 int stop_init_backoff
= 0;
1232 int remove_dynamic_tnbrs
= 0;
1233 int change_egress_label
= 0;
1234 int reset_nbrs_ipv4
= 0;
1236 int update_sockets
= 0;
1239 if (af_conf
->keepalive
!= xa
->keepalive
) {
1240 af_conf
->keepalive
= xa
->keepalive
;
1241 stop_init_backoff
= 1;
1243 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1244 af_conf
->lhello_interval
= xa
->lhello_interval
;
1245 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1246 af_conf
->thello_interval
= xa
->thello_interval
;
1249 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1250 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1251 remove_dynamic_tnbrs
= 1;
1252 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1253 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1255 /* need to set/unset IPV6_MINHOPCOUNT */
1258 /* for LDPv4 just resetting the neighbors is enough */
1259 reset_nbrs_ipv4
= 1;
1261 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1262 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1263 change_egress_label
= 1;
1264 af_conf
->flags
= xa
->flags
;
1266 /* update the transport address */
1267 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1268 af_conf
->trans_addr
= xa
->trans_addr
;
1273 if (strcmp(af_conf
->acl_label_advertise_to
,
1274 xa
->acl_label_advertise_to
) ||
1275 strcmp(af_conf
->acl_label_advertise_for
,
1276 xa
->acl_label_advertise_for
) ||
1277 strcmp(af_conf
->acl_label_accept_from
,
1278 xa
->acl_label_accept_from
) ||
1279 strcmp(af_conf
->acl_label_accept_for
,
1280 xa
->acl_label_accept_for
))
1282 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1283 remove_dynamic_tnbrs
= 1;
1284 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1285 change_egress_label
= 1;
1286 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1287 sizeof(af_conf
->acl_thello_accept_from
));
1288 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1289 sizeof(af_conf
->acl_label_allocate_for
));
1290 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1291 sizeof(af_conf
->acl_label_advertise_to
));
1292 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1293 sizeof(af_conf
->acl_label_advertise_for
));
1294 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1295 sizeof(af_conf
->acl_label_accept_from
));
1296 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1297 sizeof(af_conf
->acl_label_accept_for
));
1298 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1299 sizeof(af_conf
->acl_label_expnull_for
));
1301 /* apply the new configuration */
1302 switch (ldpd_process
) {
1303 case PROC_LDE_ENGINE
:
1304 if (change_egress_label
)
1305 lde_change_egress_label(af
);
1307 case PROC_LDP_ENGINE
:
1308 if (stop_init_backoff
)
1309 ldpe_stop_init_backoff(af
);
1310 if (remove_dynamic_tnbrs
)
1311 ldpe_remove_dynamic_tnbrs(af
);
1313 ldpe_reset_nbrs(AF_UNSPEC
);
1314 else if (reset_nbrs_ipv4
)
1315 ldpe_reset_nbrs(AF_INET
);
1318 if (update_sockets
&& iev_ldpe
)
1319 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1326 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1328 struct iface
*iface
, *itmp
, *xi
;
1330 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1331 /* find deleted interfaces */
1332 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1333 switch (ldpd_process
) {
1334 case PROC_LDP_ENGINE
:
1335 ldpe_if_exit(iface
);
1337 case PROC_LDE_ENGINE
:
1341 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1345 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1346 /* find new interfaces */
1347 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1349 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1351 switch (ldpd_process
) {
1352 case PROC_LDP_ENGINE
:
1353 ldpe_if_init(iface
);
1355 case PROC_LDE_ENGINE
:
1358 /* resend addresses to activate new interfaces */
1359 kif_redistribute(iface
->name
);
1365 /* update existing interfaces */
1366 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1367 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1372 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1374 if (ia
->enabled
!= xi
->enabled
) {
1375 ia
->enabled
= xi
->enabled
;
1376 if (ldpd_process
== PROC_LDP_ENGINE
)
1377 ldp_if_update(ia
->iface
, ia
->af
);
1379 ia
->hello_holdtime
= xi
->hello_holdtime
;
1380 ia
->hello_interval
= xi
->hello_interval
;
1384 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1386 struct tnbr
*tnbr
, *ttmp
, *xt
;
1388 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1389 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1392 /* find deleted tnbrs */
1393 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1394 switch (ldpd_process
) {
1395 case PROC_LDP_ENGINE
:
1396 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1397 tnbr_check(conf
, tnbr
);
1399 case PROC_LDE_ENGINE
:
1401 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1407 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1408 /* find new tnbrs */
1409 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1411 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1413 switch (ldpd_process
) {
1414 case PROC_LDP_ENGINE
:
1417 case PROC_LDE_ENGINE
:
1424 /* update existing tnbrs */
1425 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1426 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1431 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1433 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1437 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1438 /* find deleted nbrps */
1439 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1440 switch (ldpd_process
) {
1441 case PROC_LDP_ENGINE
:
1442 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1444 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1449 (ldp_af_global_get(&global
,
1450 nbr
->af
))->ldp_session_socket
,
1451 nbr
->af
, &nbr
->raddr
, NULL
);
1453 nbr
->auth
.method
= AUTH_NONE
;
1454 if (nbr_session_active_role(nbr
))
1455 nbr_establish_connection(nbr
);
1458 case PROC_LDE_ENGINE
:
1462 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1466 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1467 /* find new nbrps */
1468 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1470 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1472 switch (ldpd_process
) {
1473 case PROC_LDP_ENGINE
:
1474 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1476 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1477 nbr
->auth
.method
= nbrp
->auth
.method
;
1479 if (pfkey_establish(nbr
, nbrp
) == -1)
1480 fatalx("pfkey setup failed");
1483 (ldp_af_global_get(&global
,
1484 nbr
->af
))->ldp_session_socket
,
1485 nbr
->af
, &nbr
->raddr
,
1488 if (nbr_session_active_role(nbr
))
1489 nbr_establish_connection(nbr
);
1492 case PROC_LDE_ENGINE
:
1499 /* update existing nbrps */
1500 if (nbrp
->flags
!= xn
->flags
||
1501 nbrp
->keepalive
!= xn
->keepalive
||
1502 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1503 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1504 nbrp
->auth
.method
!= xn
->auth
.method
||
1505 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1510 nbrp
->keepalive
= xn
->keepalive
;
1511 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1512 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1513 nbrp
->auth
.method
= xn
->auth
.method
;
1514 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1515 sizeof(nbrp
->auth
.md5key
));
1516 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1517 nbrp
->flags
= xn
->flags
;
1519 if (ldpd_process
== PROC_LDP_ENGINE
) {
1520 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1521 if (nbr
&& nbrp_changed
) {
1522 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1525 nbr
->auth
.method
= nbrp
->auth
.method
;
1526 if (pfkey_establish(nbr
, nbrp
) == -1)
1527 fatalx("pfkey setup failed");
1529 nbr
->auth
.method
= nbrp
->auth
.method
;
1530 sock_set_md5sig((ldp_af_global_get(&global
,
1531 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1532 &nbr
->raddr
, nbrp
->auth
.md5key
);
1534 if (nbr_session_active_role(nbr
))
1535 nbr_establish_connection(nbr
);
1542 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1544 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1546 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1547 /* find deleted l2vpns */
1548 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1549 switch (ldpd_process
) {
1550 case PROC_LDE_ENGINE
:
1553 case PROC_LDP_ENGINE
:
1554 ldpe_l2vpn_exit(l2vpn
);
1559 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1563 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1564 /* find new l2vpns */
1565 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1567 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1568 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1569 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1570 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1572 switch (ldpd_process
) {
1573 case PROC_LDE_ENGINE
:
1576 case PROC_LDP_ENGINE
:
1577 ldpe_l2vpn_init(l2vpn
);
1584 /* update existing l2vpns */
1585 merge_l2vpn(conf
, l2vpn
, xl
);
1590 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1592 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1593 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1595 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1596 int previous_pw_type
, previous_mtu
;
1598 previous_pw_type
= l2vpn
->pw_type
;
1599 previous_mtu
= l2vpn
->mtu
;
1601 /* merge intefaces */
1602 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1603 /* find deleted interfaces */
1604 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1605 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1609 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1610 /* find new interfaces */
1611 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1613 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1616 switch (ldpd_process
) {
1617 case PROC_LDP_ENGINE
:
1618 case PROC_LDE_ENGINE
:
1621 kif_redistribute(lif
->ifname
);
1627 /* merge active pseudowires */
1628 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1629 /* find deleted active pseudowires */
1630 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1631 switch (ldpd_process
) {
1632 case PROC_LDE_ENGINE
:
1635 case PROC_LDP_ENGINE
:
1636 ldpe_l2vpn_pw_exit(pw
);
1642 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1646 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1647 /* find new active pseudowires */
1648 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1650 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1653 switch (ldpd_process
) {
1654 case PROC_LDE_ENGINE
:
1657 case PROC_LDP_ENGINE
:
1658 ldpe_l2vpn_pw_init(pw
);
1661 kif_redistribute(pw
->ifname
);
1667 /* update existing active pseudowire */
1668 if (pw
->af
!= xp
->af
||
1669 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1674 /* changes that require a session restart */
1675 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1676 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1681 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1682 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1683 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1684 reinstall_pwfec
= 1;
1686 reinstall_pwfec
= 0;
1688 if (ldpd_process
== PROC_LDP_ENGINE
) {
1690 ldpe_l2vpn_pw_exit(pw
);
1692 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1693 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1694 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1697 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1699 pw
->lsr_id
= xp
->lsr_id
;
1701 pw
->addr
= xp
->addr
;
1702 pw
->pwid
= xp
->pwid
;
1703 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1704 pw
->ifindex
= xp
->ifindex
;
1705 if (xp
->flags
& F_PW_CWORD_CONF
)
1706 pw
->flags
|= F_PW_CWORD_CONF
;
1708 pw
->flags
&= ~F_PW_CWORD_CONF
;
1709 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1710 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1712 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1713 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1714 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1716 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1717 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1718 ldpe_l2vpn_pw_init(pw
);
1719 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1720 l2vpn
->pw_type
= xl
->pw_type
;
1721 l2vpn
->mtu
= xl
->mtu
;
1723 l2vpn
->pw_type
= previous_pw_type
;
1724 l2vpn
->mtu
= previous_mtu
;
1728 /* merge inactive pseudowires */
1729 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1730 /* find deleted inactive pseudowires */
1731 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1732 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1736 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1737 /* find new inactive pseudowires */
1738 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1740 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1743 switch (ldpd_process
) {
1744 case PROC_LDE_ENGINE
:
1745 case PROC_LDP_ENGINE
:
1748 kif_redistribute(pw
->ifname
);
1754 /* update existing inactive pseudowire */
1755 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1757 pw
->addr
= xp
->addr
;
1758 pw
->pwid
= xp
->pwid
;
1759 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1760 pw
->ifindex
= xp
->ifindex
;
1761 pw
->flags
= xp
->flags
;
1764 l2vpn
->pw_type
= xl
->pw_type
;
1765 l2vpn
->mtu
= xl
->mtu
;
1766 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1767 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1771 config_new_empty(void)
1773 struct ldpd_conf
*xconf
;
1775 xconf
= calloc(1, sizeof(*xconf
));
1779 RB_INIT(iface_head
, &xconf
->iface_tree
);
1780 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1781 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1782 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1784 /* set default values */
1785 ldp_config_reset(xconf
);
1791 config_clear(struct ldpd_conf
*conf
)
1793 struct ldpd_conf
*xconf
;
1796 * Merge current config with an empty config, this will deactivate
1797 * and deallocate all the interfaces, pseudowires and so on. Before
1798 * merging, copy the router-id and other variables to avoid some
1799 * unnecessary operations, like trying to reset the neighborships.
1801 xconf
= config_new_empty();
1802 xconf
->ipv4
= conf
->ipv4
;
1803 xconf
->ipv6
= conf
->ipv6
;
1804 xconf
->rtr_id
= conf
->rtr_id
;
1805 xconf
->trans_pref
= conf
->trans_pref
;
1806 xconf
->flags
= conf
->flags
;
1807 merge_config(conf
, xconf
);