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_INIT
, &init
, sizeof(init
));
374 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
376 main_imsg_send_config(ldpd_conf
);
378 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
379 main_imsg_send_net_sockets(AF_INET
);
380 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
381 main_imsg_send_net_sockets(AF_INET6
);
396 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
397 close(iev_ldpe
->ibuf
.fd
);
398 msgbuf_clear(&iev_lde
->ibuf
.w
);
399 close(iev_lde
->ibuf
.fd
);
401 config_clear(ldpd_conf
);
403 ldp_config_reset(vty_conf
);
404 QOBJ_UNREG(vty_conf
);
407 log_debug("waiting for children to terminate");
411 if (errno
!= EINTR
&& errno
!= ECHILD
)
413 } else if (WIFSIGNALED(status
))
414 log_warnx("%s terminated; signal %d",
415 (pid
== lde_pid
) ? "label decision engine" :
416 "ldp engine", WTERMSIG(status
));
417 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
422 log_info("terminating");
429 zprivs_terminate(&ldpd_privs
);
430 thread_master_free(master
);
437 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
443 switch (pid
= fork()) {
445 fatal("cannot fork");
454 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
455 fatal("cannot setup imsg async fd");
456 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
457 fatal("cannot setup imsg sync fd");
459 argv
[argc
++] = argv0
;
462 fatalx("Can not start main process");
463 case PROC_LDE_ENGINE
:
464 argv
[argc
++] = (char *)"-L";
466 case PROC_LDP_ENGINE
:
467 argv
[argc
++] = (char *)"-E";
479 main_dispatch_ldpe(struct thread
*thread
)
481 struct imsgev
*iev
= THREAD_ARG(thread
);
482 struct imsgbuf
*ibuf
= &iev
->ibuf
;
490 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
491 fatal("imsg_read error");
492 if (n
== 0) /* connection closed */
496 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
502 switch (imsg
.hdr
.type
) {
504 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
506 case IMSG_REQUEST_SOCKETS
:
508 main_imsg_send_net_sockets(af
);
511 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
512 sizeof(struct acl_check
))
513 fatalx("IMSG_ACL_CHECK imsg with wrong len");
514 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
517 log_debug("%s: error handling imsg %d", __func__
,
526 /* this pipe is dead, so remove the event handlers and exit */
527 THREAD_READ_OFF(iev
->ev_read
);
528 THREAD_WRITE_OFF(iev
->ev_write
);
533 kill(lde_pid
, SIGTERM
);
541 main_dispatch_lde(struct thread
*thread
)
543 struct imsgev
*iev
= THREAD_ARG(thread
);
544 struct imsgbuf
*ibuf
= &iev
->ibuf
;
551 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
552 fatal("imsg_read error");
553 if (n
== 0) /* connection closed */
557 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
563 switch (imsg
.hdr
.type
) {
565 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
567 case IMSG_KLABEL_CHANGE
:
568 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
569 sizeof(struct kroute
))
570 fatalx("invalid size of IMSG_KLABEL_CHANGE");
571 if (kr_change(imsg
.data
))
572 log_warnx("%s: error changing route", __func__
);
574 case IMSG_KLABEL_DELETE
:
575 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
576 sizeof(struct kroute
))
577 fatalx("invalid size of IMSG_KLABEL_DELETE");
578 if (kr_delete(imsg
.data
))
579 log_warnx("%s: error deleting route", __func__
);
582 case IMSG_KPW_DELETE
:
585 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
586 sizeof(struct zapi_pw
))
587 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
589 switch (imsg
.hdr
.type
) {
591 if (kmpw_add(imsg
.data
))
592 log_warnx("%s: error adding "
593 "pseudowire", __func__
);
595 case IMSG_KPW_DELETE
:
596 if (kmpw_del(imsg
.data
))
597 log_warnx("%s: error deleting "
598 "pseudowire", __func__
);
601 if (kmpw_set(imsg
.data
))
602 log_warnx("%s: error setting "
603 "pseudowire", __func__
);
606 if (kmpw_unset(imsg
.data
))
607 log_warnx("%s: error unsetting "
608 "pseudowire", __func__
);
613 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
614 sizeof(struct acl_check
))
615 fatalx("IMSG_ACL_CHECK imsg with wrong len");
616 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
619 log_debug("%s: error handling imsg %d", __func__
,
628 /* this pipe is dead, so remove the event handlers and exit */
629 THREAD_READ_OFF(iev
->ev_read
);
630 THREAD_WRITE_OFF(iev
->ev_write
);
635 kill(ldpe_pid
, SIGTERM
);
643 ldp_write_handler(struct thread
*thread
)
645 struct imsgev
*iev
= THREAD_ARG(thread
);
646 struct imsgbuf
*ibuf
= &iev
->ibuf
;
649 iev
->ev_write
= NULL
;
651 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
652 fatal("msgbuf_write");
654 /* this pipe is dead, so remove the event handlers */
655 THREAD_READ_OFF(iev
->ev_read
);
656 THREAD_WRITE_OFF(iev
->ev_write
);
666 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
668 if (iev_ldpe
== NULL
)
670 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
674 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
676 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
680 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
682 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
684 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
686 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
692 imsg_event_add(struct imsgev
*iev
)
694 if (iev
->handler_read
)
695 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
698 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
699 thread_add_write(master
, iev
->handler_write
, iev
,
700 iev
->ibuf
.fd
, &iev
->ev_write
);
704 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
705 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
709 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
710 pid
, fd
, data
, datalen
)) != -1)
716 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
718 ibuf_close(&eb
->wbuf
, buf
);
723 evbuf_event_add(struct evbuf
*eb
)
726 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
731 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
734 msgbuf_init(&eb
->wbuf
);
736 eb
->handler
= handler
;
741 evbuf_clear(struct evbuf
*eb
)
743 THREAD_WRITE_OFF(eb
->ev
);
744 msgbuf_clear(&eb
->wbuf
);
749 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
751 int pipe_ldpe2lde
[2];
753 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
755 sock_set_nonblock(pipe_ldpe2lde
[0]);
756 sock_set_nonblock(pipe_ldpe2lde
[1]);
758 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
761 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
769 main_imsg_send_net_sockets(int af
)
771 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
774 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
775 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
776 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
777 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
781 main_imsg_send_net_socket(int af
, enum socket_type type
)
785 fd
= ldp_create_socket(af
, type
);
787 log_warnx("%s: failed to create %s socket for address-family "
788 "%s", __func__
, socket_name(type
), af_name(af
));
792 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
797 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
798 union ldpd_addr
*addr
, uint8_t prefixlen
)
802 struct acl_check acl_check
;
804 if (acl_name
[0] == '\0')
805 return FILTER_PERMIT
;
808 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
810 acl_check
.addr
= *addr
;
811 acl_check
.prefixlen
= prefixlen
;
813 /* send (blocking) */
814 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
816 imsg_flush(&iev
->ibuf
);
818 /* receive (blocking) and parse result */
819 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
820 fatal("imsg_read error");
821 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
823 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
824 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
825 fatalx("ldp_acl_request: invalid response");
827 return (*((int *)imsg
.data
));
831 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
833 struct access_list
*alist
;
834 struct prefix prefix
;
837 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
839 result
= FILTER_DENY
;
841 prefix
.family
= acl_check
->af
;
842 switch (prefix
.family
) {
844 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
847 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
850 fatalx("ldp_acl_reply: unknown af");
852 prefix
.prefixlen
= acl_check
->prefixlen
;
853 result
= access_list_apply(alist
, &prefix
);
856 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
860 struct ldpd_af_conf
*
861 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
865 return (&xconf
->ipv4
);
867 return (&xconf
->ipv6
);
869 fatalx("ldp_af_conf_get: unknown af");
873 struct ldpd_af_global
*
874 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
878 return (&xglobal
->ipv4
);
880 return (&xglobal
->ipv6
);
882 fatalx("ldp_af_global_get: unknown af");
887 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
889 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
890 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
894 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
896 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
897 return (xconf
->rtr_id
.s_addr
);
899 return (global
.rtr_id
.s_addr
);
903 main_imsg_send_config(struct ldpd_conf
*xconf
)
907 struct nbr_params
*nbrp
;
909 struct l2vpn_if
*lif
;
912 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
913 sizeof(*xconf
)) == -1)
916 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
917 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
918 sizeof(*iface
)) == -1)
922 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
923 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
924 sizeof(*tnbr
)) == -1)
928 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
929 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
930 sizeof(*nbrp
)) == -1)
934 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
935 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
936 sizeof(*l2vpn
)) == -1)
939 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
940 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
944 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
945 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
949 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
950 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
956 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
963 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
966 * When reading from a configuration file (startup and sighup), we
967 * call merge_config() only once after the whole config has been read.
968 * This is the optimal and least disruptive way to update the running
971 if (vty
&& vty
->type
== VTY_FILE
)
974 ldp_config_normalize(xconf
);
976 if (main_imsg_send_config(xconf
) == -1)
979 merge_config(ldpd_conf
, xconf
);
985 ldp_config_normalize(struct ldpd_conf
*xconf
)
987 struct iface
*iface
, *itmp
;
988 struct nbr_params
*nbrp
, *ntmp
;
990 struct l2vpn_pw
*pw
, *ptmp
;
992 if (!(xconf
->flags
& F_LDPD_ENABLED
))
993 ldp_config_reset_main(xconf
);
995 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
996 ldp_config_reset_af(xconf
, AF_INET
);
997 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
998 ldp_config_reset_af(xconf
, AF_INET6
);
1000 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1001 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1005 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1009 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1010 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1012 if (nbrp
->auth
.method
!= AUTH_NONE
)
1016 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1021 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1022 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1023 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1025 pw
->addr
.v4
= pw
->lsr_id
;
1028 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1030 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1031 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1033 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1035 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1037 pw
->addr
.v4
= pw
->lsr_id
;
1040 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1042 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1043 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1049 ldp_config_reset(struct ldpd_conf
*conf
)
1051 ldp_config_reset_main(conf
);
1052 ldp_config_reset_l2vpns(conf
);
1056 ldp_config_reset_main(struct ldpd_conf
*conf
)
1058 struct iface
*iface
;
1059 struct nbr_params
*nbrp
;
1061 while ((iface
= RB_ROOT(iface_head
, &conf
->iface_tree
)) != NULL
) {
1063 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1067 while ((nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
)) != NULL
) {
1069 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1073 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1074 ldp_config_reset_af(conf
, AF_INET
);
1075 ldp_config_reset_af(conf
, AF_INET6
);
1076 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1077 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1078 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1079 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1080 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1085 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1087 struct ldpd_af_conf
*af_conf
;
1088 struct iface
*iface
;
1089 struct iface_af
*ia
;
1090 struct tnbr
*tnbr
, *ttmp
;
1092 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1093 ia
= iface_af_get(iface
, af
);
1097 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1102 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1106 af_conf
= ldp_af_conf_get(conf
, af
);
1107 af_conf
->keepalive
= 180;
1108 af_conf
->lhello_holdtime
= 0;
1109 af_conf
->lhello_interval
= 0;
1110 af_conf
->thello_holdtime
= 0;
1111 af_conf
->thello_interval
= 0;
1112 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1117 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1119 struct l2vpn
*l2vpn
;
1120 struct l2vpn_if
*lif
;
1121 struct l2vpn_pw
*pw
;
1123 while ((l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
)) != NULL
) {
1124 while ((lif
= RB_ROOT(l2vpn_if_head
,
1125 &l2vpn
->if_tree
)) != NULL
) {
1127 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1130 while ((pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
)) != NULL
) {
1132 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1135 while ((pw
= RB_ROOT(l2vpn_pw_head
,
1136 &l2vpn
->pw_inactive_tree
)) != NULL
) {
1138 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1142 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1148 ldp_clear_config(struct ldpd_conf
*xconf
)
1150 struct iface
*iface
;
1152 struct nbr_params
*nbrp
;
1153 struct l2vpn
*l2vpn
;
1155 while ((iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
)) != NULL
) {
1156 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1159 while ((tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
)) != NULL
) {
1160 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1163 while ((nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
)) != NULL
) {
1164 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1167 while ((l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
)) != NULL
) {
1168 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1175 #define COPY(a, b) do { \
1176 a = malloc(sizeof(*a)); \
1183 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1185 merge_global(conf
, xconf
);
1186 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1187 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1188 merge_ifaces(conf
, xconf
);
1189 merge_tnbrs(conf
, xconf
);
1190 merge_nbrps(conf
, xconf
);
1191 merge_l2vpns(conf
, xconf
);
1195 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1197 /* change of router-id requires resetting all neighborships */
1198 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1199 if (ldpd_process
== PROC_LDP_ENGINE
) {
1200 ldpe_reset_nbrs(AF_UNSPEC
);
1201 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1202 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1203 if_update_all(AF_UNSPEC
);
1204 tnbr_update_all(AF_UNSPEC
);
1207 conf
->rtr_id
= xconf
->rtr_id
;
1210 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1211 conf
->lhello_interval
= xconf
->lhello_interval
;
1212 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1213 conf
->thello_interval
= xconf
->thello_interval
;
1215 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1216 if (ldpd_process
== PROC_LDP_ENGINE
)
1217 ldpe_reset_ds_nbrs();
1218 conf
->trans_pref
= xconf
->trans_pref
;
1221 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1222 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1223 if (ldpd_process
== PROC_LDP_ENGINE
)
1224 ldpe_reset_ds_nbrs();
1227 conf
->flags
= xconf
->flags
;
1231 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1233 int stop_init_backoff
= 0;
1234 int remove_dynamic_tnbrs
= 0;
1235 int change_egress_label
= 0;
1236 int reset_nbrs_ipv4
= 0;
1238 int update_sockets
= 0;
1241 if (af_conf
->keepalive
!= xa
->keepalive
) {
1242 af_conf
->keepalive
= xa
->keepalive
;
1243 stop_init_backoff
= 1;
1245 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1246 af_conf
->lhello_interval
= xa
->lhello_interval
;
1247 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1248 af_conf
->thello_interval
= xa
->thello_interval
;
1251 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1252 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1253 remove_dynamic_tnbrs
= 1;
1254 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1255 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1257 /* need to set/unset IPV6_MINHOPCOUNT */
1260 /* for LDPv4 just resetting the neighbors is enough */
1261 reset_nbrs_ipv4
= 1;
1263 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1264 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1265 change_egress_label
= 1;
1266 af_conf
->flags
= xa
->flags
;
1268 /* update the transport address */
1269 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1270 af_conf
->trans_addr
= xa
->trans_addr
;
1275 if (strcmp(af_conf
->acl_label_advertise_to
,
1276 xa
->acl_label_advertise_to
) ||
1277 strcmp(af_conf
->acl_label_advertise_for
,
1278 xa
->acl_label_advertise_for
) ||
1279 strcmp(af_conf
->acl_label_accept_from
,
1280 xa
->acl_label_accept_from
) ||
1281 strcmp(af_conf
->acl_label_accept_for
,
1282 xa
->acl_label_accept_for
))
1284 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1285 remove_dynamic_tnbrs
= 1;
1286 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1287 change_egress_label
= 1;
1288 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1289 sizeof(af_conf
->acl_thello_accept_from
));
1290 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1291 sizeof(af_conf
->acl_label_allocate_for
));
1292 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1293 sizeof(af_conf
->acl_label_advertise_to
));
1294 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1295 sizeof(af_conf
->acl_label_advertise_for
));
1296 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1297 sizeof(af_conf
->acl_label_accept_from
));
1298 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1299 sizeof(af_conf
->acl_label_accept_for
));
1300 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1301 sizeof(af_conf
->acl_label_expnull_for
));
1303 /* apply the new configuration */
1304 switch (ldpd_process
) {
1305 case PROC_LDE_ENGINE
:
1306 if (change_egress_label
)
1307 lde_change_egress_label(af
);
1309 case PROC_LDP_ENGINE
:
1310 if (stop_init_backoff
)
1311 ldpe_stop_init_backoff(af
);
1312 if (remove_dynamic_tnbrs
)
1313 ldpe_remove_dynamic_tnbrs(af
);
1315 ldpe_reset_nbrs(AF_UNSPEC
);
1316 else if (reset_nbrs_ipv4
)
1317 ldpe_reset_nbrs(AF_INET
);
1320 if (update_sockets
&& iev_ldpe
)
1321 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1328 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1330 struct iface
*iface
, *itmp
, *xi
;
1332 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1333 /* find deleted interfaces */
1334 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1335 switch (ldpd_process
) {
1336 case PROC_LDP_ENGINE
:
1337 ldpe_if_exit(iface
);
1339 case PROC_LDE_ENGINE
:
1343 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1347 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1348 /* find new interfaces */
1349 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1351 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1353 switch (ldpd_process
) {
1354 case PROC_LDP_ENGINE
:
1355 ldpe_if_init(iface
);
1357 case PROC_LDE_ENGINE
:
1360 /* resend addresses to activate new interfaces */
1361 kif_redistribute(iface
->name
);
1367 /* update existing interfaces */
1368 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1369 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1374 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1376 if (ia
->enabled
!= xi
->enabled
) {
1377 ia
->enabled
= xi
->enabled
;
1378 if (ldpd_process
== PROC_LDP_ENGINE
)
1379 ldp_if_update(ia
->iface
, ia
->af
);
1381 ia
->hello_holdtime
= xi
->hello_holdtime
;
1382 ia
->hello_interval
= xi
->hello_interval
;
1386 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1388 struct tnbr
*tnbr
, *ttmp
, *xt
;
1390 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1391 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1394 /* find deleted tnbrs */
1395 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1396 switch (ldpd_process
) {
1397 case PROC_LDP_ENGINE
:
1398 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1399 tnbr_check(conf
, tnbr
);
1401 case PROC_LDE_ENGINE
:
1403 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1409 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1410 /* find new tnbrs */
1411 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1413 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1415 switch (ldpd_process
) {
1416 case PROC_LDP_ENGINE
:
1419 case PROC_LDE_ENGINE
:
1426 /* update existing tnbrs */
1427 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1428 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1433 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1435 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1439 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1440 /* find deleted nbrps */
1441 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1442 switch (ldpd_process
) {
1443 case PROC_LDP_ENGINE
:
1444 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1446 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1451 (ldp_af_global_get(&global
,
1452 nbr
->af
))->ldp_session_socket
,
1453 nbr
->af
, &nbr
->raddr
, NULL
);
1455 nbr
->auth
.method
= AUTH_NONE
;
1456 if (nbr_session_active_role(nbr
))
1457 nbr_establish_connection(nbr
);
1460 case PROC_LDE_ENGINE
:
1464 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1468 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1469 /* find new nbrps */
1470 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1472 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1474 switch (ldpd_process
) {
1475 case PROC_LDP_ENGINE
:
1476 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1478 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1479 nbr
->auth
.method
= nbrp
->auth
.method
;
1481 if (pfkey_establish(nbr
, nbrp
) == -1)
1482 fatalx("pfkey setup failed");
1485 (ldp_af_global_get(&global
,
1486 nbr
->af
))->ldp_session_socket
,
1487 nbr
->af
, &nbr
->raddr
,
1490 if (nbr_session_active_role(nbr
))
1491 nbr_establish_connection(nbr
);
1494 case PROC_LDE_ENGINE
:
1501 /* update existing nbrps */
1502 if (nbrp
->flags
!= xn
->flags
||
1503 nbrp
->keepalive
!= xn
->keepalive
||
1504 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1505 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1506 nbrp
->auth
.method
!= xn
->auth
.method
||
1507 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1512 nbrp
->keepalive
= xn
->keepalive
;
1513 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1514 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1515 nbrp
->auth
.method
= xn
->auth
.method
;
1516 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1517 sizeof(nbrp
->auth
.md5key
));
1518 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1519 nbrp
->flags
= xn
->flags
;
1521 if (ldpd_process
== PROC_LDP_ENGINE
) {
1522 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1523 if (nbr
&& nbrp_changed
) {
1524 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1527 nbr
->auth
.method
= nbrp
->auth
.method
;
1528 if (pfkey_establish(nbr
, nbrp
) == -1)
1529 fatalx("pfkey setup failed");
1531 nbr
->auth
.method
= nbrp
->auth
.method
;
1532 sock_set_md5sig((ldp_af_global_get(&global
,
1533 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1534 &nbr
->raddr
, nbrp
->auth
.md5key
);
1536 if (nbr_session_active_role(nbr
))
1537 nbr_establish_connection(nbr
);
1544 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1546 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1548 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1549 /* find deleted l2vpns */
1550 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1551 switch (ldpd_process
) {
1552 case PROC_LDE_ENGINE
:
1555 case PROC_LDP_ENGINE
:
1556 ldpe_l2vpn_exit(l2vpn
);
1561 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1565 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1566 /* find new l2vpns */
1567 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1569 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1570 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1571 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1572 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1574 switch (ldpd_process
) {
1575 case PROC_LDE_ENGINE
:
1578 case PROC_LDP_ENGINE
:
1579 ldpe_l2vpn_init(l2vpn
);
1586 /* update existing l2vpns */
1587 merge_l2vpn(conf
, l2vpn
, xl
);
1592 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1594 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1595 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1597 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1598 int previous_pw_type
, previous_mtu
;
1600 previous_pw_type
= l2vpn
->pw_type
;
1601 previous_mtu
= l2vpn
->mtu
;
1603 /* merge intefaces */
1604 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1605 /* find deleted interfaces */
1606 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1607 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1611 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1612 /* find new interfaces */
1613 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1615 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1618 switch (ldpd_process
) {
1619 case PROC_LDP_ENGINE
:
1620 case PROC_LDE_ENGINE
:
1623 kif_redistribute(lif
->ifname
);
1629 /* merge active pseudowires */
1630 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1631 /* find deleted active pseudowires */
1632 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1633 switch (ldpd_process
) {
1634 case PROC_LDE_ENGINE
:
1637 case PROC_LDP_ENGINE
:
1638 ldpe_l2vpn_pw_exit(pw
);
1644 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1648 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1649 /* find new active pseudowires */
1650 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1652 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1655 switch (ldpd_process
) {
1656 case PROC_LDE_ENGINE
:
1659 case PROC_LDP_ENGINE
:
1660 ldpe_l2vpn_pw_init(pw
);
1663 kif_redistribute(pw
->ifname
);
1669 /* update existing active pseudowire */
1670 if (pw
->af
!= xp
->af
||
1671 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1676 /* changes that require a session restart */
1677 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1678 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1683 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1684 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1685 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1686 reinstall_pwfec
= 1;
1688 reinstall_pwfec
= 0;
1690 if (ldpd_process
== PROC_LDP_ENGINE
) {
1692 ldpe_l2vpn_pw_exit(pw
);
1694 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1695 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1696 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1699 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1701 pw
->lsr_id
= xp
->lsr_id
;
1703 pw
->addr
= xp
->addr
;
1704 pw
->pwid
= xp
->pwid
;
1705 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1706 pw
->ifindex
= xp
->ifindex
;
1707 if (xp
->flags
& F_PW_CWORD_CONF
)
1708 pw
->flags
|= F_PW_CWORD_CONF
;
1710 pw
->flags
&= ~F_PW_CWORD_CONF
;
1711 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1712 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1714 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1715 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1716 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1718 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1719 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1720 ldpe_l2vpn_pw_init(pw
);
1721 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1722 l2vpn
->pw_type
= xl
->pw_type
;
1723 l2vpn
->mtu
= xl
->mtu
;
1725 l2vpn
->pw_type
= previous_pw_type
;
1726 l2vpn
->mtu
= previous_mtu
;
1730 /* merge inactive pseudowires */
1731 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1732 /* find deleted inactive pseudowires */
1733 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1734 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1738 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1739 /* find new inactive pseudowires */
1740 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1742 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1745 switch (ldpd_process
) {
1746 case PROC_LDE_ENGINE
:
1747 case PROC_LDP_ENGINE
:
1750 kif_redistribute(pw
->ifname
);
1756 /* update existing inactive pseudowire */
1757 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1759 pw
->addr
= xp
->addr
;
1760 pw
->pwid
= xp
->pwid
;
1761 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1762 pw
->ifindex
= xp
->ifindex
;
1763 pw
->flags
= xp
->flags
;
1766 l2vpn
->pw_type
= xl
->pw_type
;
1767 l2vpn
->mtu
= xl
->mtu
;
1768 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1769 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1773 config_new_empty(void)
1775 struct ldpd_conf
*xconf
;
1777 xconf
= calloc(1, sizeof(*xconf
));
1781 RB_INIT(iface_head
, &xconf
->iface_tree
);
1782 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1783 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1784 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1786 /* set default values */
1787 ldp_config_reset(xconf
);
1793 config_clear(struct ldpd_conf
*conf
)
1795 struct ldpd_conf
*xconf
;
1798 * Merge current config with an empty config, this will deactivate
1799 * and deallocate all the interfaces, pseudowires and so on. Before
1800 * merging, copy the router-id and other variables to avoid some
1801 * unnecessary operations, like trying to reset the neighborships.
1803 xconf
= config_new_empty();
1804 xconf
->ipv4
= conf
->ipv4
;
1805 xconf
->ipv6
= conf
->ipv6
;
1806 xconf
->rtr_id
= conf
->rtr_id
;
1807 xconf
->trans_pref
= conf
->trans_pref
;
1808 xconf
->flags
= conf
->flags
;
1809 merge_config(conf
, xconf
);