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
));
263 if (argc
> 0 || (lflag
&& eflag
))
266 /* check for root privileges */
267 if (geteuid() != 0) {
269 perror(ldpd_di
.progname
);
274 openzlog(ldpd_di
.progname
, "LDP", 0,
275 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
281 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
283 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
284 pipe_parent2ldpe_sync
) == -1)
286 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
288 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
289 pipe_parent2lde_sync
) == -1)
291 sock_set_nonblock(pipe_parent2ldpe
[0]);
292 sock_set_cloexec(pipe_parent2ldpe
[0]);
293 sock_set_nonblock(pipe_parent2ldpe
[1]);
294 sock_set_cloexec(pipe_parent2ldpe
[1]);
295 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
296 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
297 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
298 sock_set_nonblock(pipe_parent2lde
[0]);
299 sock_set_cloexec(pipe_parent2lde
[0]);
300 sock_set_nonblock(pipe_parent2lde
[1]);
301 sock_set_cloexec(pipe_parent2lde
[1]);
302 sock_set_nonblock(pipe_parent2lde_sync
[0]);
303 sock_set_cloexec(pipe_parent2lde_sync
[0]);
304 sock_set_cloexec(pipe_parent2lde_sync
[1]);
307 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
308 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
309 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
310 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
314 vty_config_lockless();
315 vrf_init(NULL
, NULL
, NULL
, NULL
);
318 ldp_zebra_init(master
);
321 * Create base configuration with sane defaults. All configuration
322 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
323 * to merge the changes into ldpd_conf, which contains the actual
324 * running configuration.
326 ldpd_conf
= config_new_empty();
327 vty_conf
= config_new_empty();
328 QOBJ_REG(vty_conf
, ldpd_conf
);
330 /* read configuration file and daemonize */
333 /* apply configuration */
334 ldp_config_apply(NULL
, vty_conf
);
336 /* setup pipes to children */
337 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
338 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
339 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
340 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
342 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
343 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
344 iev_ldpe
->ev_read
= NULL
;
345 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
347 iev_ldpe
->handler_write
= ldp_write_handler
;
349 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
350 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
351 iev_ldpe_sync
->ev_read
= NULL
;
352 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
353 &iev_ldpe_sync
->ev_read
);
354 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
356 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
357 iev_lde
->handler_read
= main_dispatch_lde
;
358 iev_lde
->ev_read
= NULL
;
359 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
361 iev_lde
->handler_write
= ldp_write_handler
;
363 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
364 iev_lde_sync
->handler_read
= main_dispatch_lde
;
365 iev_lde_sync
->ev_read
= NULL
;
366 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
367 &iev_lde_sync
->ev_read
);
368 iev_lde_sync
->handler_write
= ldp_write_handler
;
370 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
371 fatal("could not establish imsg links");
372 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
374 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
375 main_imsg_send_config(ldpd_conf
);
377 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
378 main_imsg_send_net_sockets(AF_INET
);
379 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
380 main_imsg_send_net_sockets(AF_INET6
);
397 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
398 close(iev_ldpe
->ibuf
.fd
);
399 msgbuf_clear(&iev_lde
->ibuf
.w
);
400 close(iev_lde
->ibuf
.fd
);
402 config_clear(ldpd_conf
);
404 ldp_config_reset(vty_conf
);
405 QOBJ_UNREG(vty_conf
);
408 log_debug("waiting for children to terminate");
411 /* Wait for child process. */
414 /* We got interrupted, try again. */
417 /* No more processes were found. */
421 /* Unhandled errno condition. */
426 /* We found something, lets announce it. */
427 if (WIFSIGNALED(status
))
428 log_warnx("%s terminated; signal %d",
429 (pid
== lde_pid
? "label decision engine"
433 /* Repeat until there are no more child processes. */
439 log_info("terminating");
450 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
453 int argc
= 0, nullfd
;
456 switch (pid
= fork()) {
458 fatal("cannot fork");
467 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
469 zlog_err("%s: failed to open /dev/null: %s", __func__
,
470 safe_strerror(errno
));
478 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
479 fatal("cannot setup imsg async fd");
480 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
481 fatal("cannot setup imsg sync fd");
483 argv
[argc
++] = argv0
;
486 fatalx("Can not start main process");
487 case PROC_LDE_ENGINE
:
488 argv
[argc
++] = (char *)"-L";
490 case PROC_LDP_ENGINE
:
491 argv
[argc
++] = (char *)"-E";
503 main_dispatch_ldpe(struct thread
*thread
)
505 struct imsgev
*iev
= THREAD_ARG(thread
);
506 struct imsgbuf
*ibuf
= &iev
->ibuf
;
514 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
515 fatal("imsg_read error");
516 if (n
== 0) /* connection closed */
520 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
526 switch (imsg
.hdr
.type
) {
528 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
530 case IMSG_REQUEST_SOCKETS
:
532 main_imsg_send_net_sockets(af
);
535 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
536 sizeof(struct acl_check
))
537 fatalx("IMSG_ACL_CHECK imsg with wrong len");
538 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
541 log_debug("%s: error handling imsg %d", __func__
,
550 /* this pipe is dead, so remove the event handlers and exit */
551 THREAD_READ_OFF(iev
->ev_read
);
552 THREAD_WRITE_OFF(iev
->ev_write
);
557 kill(lde_pid
, SIGTERM
);
565 main_dispatch_lde(struct thread
*thread
)
567 struct imsgev
*iev
= THREAD_ARG(thread
);
568 struct imsgbuf
*ibuf
= &iev
->ibuf
;
575 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
576 fatal("imsg_read error");
577 if (n
== 0) /* connection closed */
581 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
587 switch (imsg
.hdr
.type
) {
589 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
591 case IMSG_KLABEL_CHANGE
:
592 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
593 sizeof(struct kroute
))
594 fatalx("invalid size of IMSG_KLABEL_CHANGE");
595 if (kr_change(imsg
.data
))
596 log_warnx("%s: error changing route", __func__
);
598 case IMSG_KLABEL_DELETE
:
599 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
600 sizeof(struct kroute
))
601 fatalx("invalid size of IMSG_KLABEL_DELETE");
602 if (kr_delete(imsg
.data
))
603 log_warnx("%s: error deleting route", __func__
);
606 case IMSG_KPW_DELETE
:
609 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
610 sizeof(struct zapi_pw
))
611 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
613 switch (imsg
.hdr
.type
) {
615 if (kmpw_add(imsg
.data
))
616 log_warnx("%s: error adding "
617 "pseudowire", __func__
);
619 case IMSG_KPW_DELETE
:
620 if (kmpw_del(imsg
.data
))
621 log_warnx("%s: error deleting "
622 "pseudowire", __func__
);
625 if (kmpw_set(imsg
.data
))
626 log_warnx("%s: error setting "
627 "pseudowire", __func__
);
630 if (kmpw_unset(imsg
.data
))
631 log_warnx("%s: error unsetting "
632 "pseudowire", __func__
);
637 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
638 sizeof(struct acl_check
))
639 fatalx("IMSG_ACL_CHECK imsg with wrong len");
640 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
643 log_debug("%s: error handling imsg %d", __func__
,
652 /* this pipe is dead, so remove the event handlers and exit */
653 THREAD_READ_OFF(iev
->ev_read
);
654 THREAD_WRITE_OFF(iev
->ev_write
);
659 kill(ldpe_pid
, SIGTERM
);
667 ldp_write_handler(struct thread
*thread
)
669 struct imsgev
*iev
= THREAD_ARG(thread
);
670 struct imsgbuf
*ibuf
= &iev
->ibuf
;
673 iev
->ev_write
= NULL
;
675 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
676 fatal("msgbuf_write");
678 /* this pipe is dead, so remove the event handlers */
679 THREAD_READ_OFF(iev
->ev_read
);
680 THREAD_WRITE_OFF(iev
->ev_write
);
690 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
692 if (iev_ldpe
== NULL
)
694 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
698 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
700 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
704 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
706 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
708 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
710 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
716 imsg_event_add(struct imsgev
*iev
)
718 if (iev
->handler_read
)
719 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
722 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
723 thread_add_write(master
, iev
->handler_write
, iev
,
724 iev
->ibuf
.fd
, &iev
->ev_write
);
728 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
729 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
733 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
734 pid
, fd
, data
, datalen
)) != -1)
740 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
742 ibuf_close(&eb
->wbuf
, buf
);
747 evbuf_event_add(struct evbuf
*eb
)
750 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
755 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
758 msgbuf_init(&eb
->wbuf
);
760 eb
->handler
= handler
;
765 evbuf_clear(struct evbuf
*eb
)
767 THREAD_WRITE_OFF(eb
->ev
);
768 msgbuf_clear(&eb
->wbuf
);
773 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
775 int pipe_ldpe2lde
[2];
777 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
779 sock_set_nonblock(pipe_ldpe2lde
[0]);
780 sock_set_nonblock(pipe_ldpe2lde
[1]);
782 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
785 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
793 main_imsg_send_net_sockets(int af
)
795 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
798 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
799 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
800 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
801 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
805 main_imsg_send_net_socket(int af
, enum socket_type type
)
809 fd
= ldp_create_socket(af
, type
);
811 log_warnx("%s: failed to create %s socket for address-family "
812 "%s", __func__
, socket_name(type
), af_name(af
));
816 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
821 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
822 union ldpd_addr
*addr
, uint8_t prefixlen
)
826 struct acl_check acl_check
;
828 if (acl_name
[0] == '\0')
829 return FILTER_PERMIT
;
832 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
834 acl_check
.addr
= *addr
;
835 acl_check
.prefixlen
= prefixlen
;
837 /* send (blocking) */
838 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
840 imsg_flush(&iev
->ibuf
);
842 /* receive (blocking) and parse result */
843 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
844 fatal("imsg_read error");
845 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
847 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
848 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
849 fatalx("ldp_acl_request: invalid response");
851 return (*((int *)imsg
.data
));
855 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
857 struct access_list
*alist
;
858 struct prefix prefix
;
861 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
863 result
= FILTER_DENY
;
865 prefix
.family
= acl_check
->af
;
866 switch (prefix
.family
) {
868 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
871 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
874 fatalx("ldp_acl_reply: unknown af");
876 prefix
.prefixlen
= acl_check
->prefixlen
;
877 result
= access_list_apply(alist
, &prefix
);
880 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
884 struct ldpd_af_conf
*
885 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
889 return (&xconf
->ipv4
);
891 return (&xconf
->ipv6
);
893 fatalx("ldp_af_conf_get: unknown af");
897 struct ldpd_af_global
*
898 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
902 return (&xglobal
->ipv4
);
904 return (&xglobal
->ipv6
);
906 fatalx("ldp_af_global_get: unknown af");
911 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
913 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
914 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
918 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
920 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
921 return (xconf
->rtr_id
.s_addr
);
923 return (global
.rtr_id
.s_addr
);
927 main_imsg_send_config(struct ldpd_conf
*xconf
)
931 struct nbr_params
*nbrp
;
933 struct l2vpn_if
*lif
;
936 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
937 sizeof(*xconf
)) == -1)
940 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
941 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
942 sizeof(*iface
)) == -1)
946 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
947 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
948 sizeof(*tnbr
)) == -1)
952 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
953 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
954 sizeof(*nbrp
)) == -1)
958 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
959 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
960 sizeof(*l2vpn
)) == -1)
963 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
964 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
968 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
969 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
973 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
974 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
980 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
987 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
990 * When reading from a configuration file (startup and sighup), we
991 * call merge_config() only once after the whole config has been read.
992 * This is the optimal and least disruptive way to update the running
995 if (vty
&& vty
->type
== VTY_FILE
)
998 ldp_config_normalize(xconf
);
1000 if (main_imsg_send_config(xconf
) == -1)
1003 merge_config(ldpd_conf
, xconf
);
1009 ldp_config_normalize(struct ldpd_conf
*xconf
)
1011 struct iface
*iface
, *itmp
;
1012 struct nbr_params
*nbrp
, *ntmp
;
1013 struct l2vpn
*l2vpn
;
1014 struct l2vpn_pw
*pw
, *ptmp
;
1016 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1017 ldp_config_reset_main(xconf
);
1019 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1020 ldp_config_reset_af(xconf
, AF_INET
);
1021 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1022 ldp_config_reset_af(xconf
, AF_INET6
);
1024 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1025 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1029 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1033 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1034 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1036 if (nbrp
->auth
.method
!= AUTH_NONE
)
1040 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1045 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1046 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1047 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1049 pw
->addr
.v4
= pw
->lsr_id
;
1052 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1054 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1055 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1057 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1059 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1061 pw
->addr
.v4
= pw
->lsr_id
;
1064 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1066 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1067 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1073 ldp_config_reset(struct ldpd_conf
*conf
)
1075 ldp_config_reset_main(conf
);
1076 ldp_config_reset_l2vpns(conf
);
1080 ldp_config_reset_main(struct ldpd_conf
*conf
)
1082 struct iface
*iface
;
1083 struct nbr_params
*nbrp
;
1085 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1086 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1089 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1093 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1094 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1097 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1101 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1102 ldp_config_reset_af(conf
, AF_INET
);
1103 ldp_config_reset_af(conf
, AF_INET6
);
1104 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1105 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1106 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1107 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1108 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1113 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1115 struct ldpd_af_conf
*af_conf
;
1116 struct iface
*iface
;
1117 struct iface_af
*ia
;
1118 struct tnbr
*tnbr
, *ttmp
;
1120 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1121 ia
= iface_af_get(iface
, af
);
1125 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1130 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1134 af_conf
= ldp_af_conf_get(conf
, af
);
1135 af_conf
->keepalive
= 180;
1136 af_conf
->lhello_holdtime
= 0;
1137 af_conf
->lhello_interval
= 0;
1138 af_conf
->thello_holdtime
= 0;
1139 af_conf
->thello_interval
= 0;
1140 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1145 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1147 struct l2vpn
*l2vpn
;
1148 struct l2vpn_if
*lif
;
1149 struct l2vpn_pw
*pw
;
1151 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1152 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1153 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1154 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1157 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1160 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1161 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1164 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1167 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1168 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1171 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1175 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1181 ldp_clear_config(struct ldpd_conf
*xconf
)
1183 struct iface
*iface
;
1185 struct nbr_params
*nbrp
;
1186 struct l2vpn
*l2vpn
;
1188 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1189 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1191 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1194 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1195 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1197 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1200 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1201 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1203 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1206 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1207 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1209 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1216 #define COPY(a, b) do { \
1217 a = malloc(sizeof(*a)); \
1224 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1226 merge_global(conf
, xconf
);
1227 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1228 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1229 merge_ifaces(conf
, xconf
);
1230 merge_tnbrs(conf
, xconf
);
1231 merge_nbrps(conf
, xconf
);
1232 merge_l2vpns(conf
, xconf
);
1236 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1238 /* change of router-id requires resetting all neighborships */
1239 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1240 if (ldpd_process
== PROC_LDP_ENGINE
) {
1241 ldpe_reset_nbrs(AF_UNSPEC
);
1242 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1243 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1244 if_update_all(AF_UNSPEC
);
1245 tnbr_update_all(AF_UNSPEC
);
1248 conf
->rtr_id
= xconf
->rtr_id
;
1251 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1252 conf
->lhello_interval
= xconf
->lhello_interval
;
1253 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1254 conf
->thello_interval
= xconf
->thello_interval
;
1256 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1257 if (ldpd_process
== PROC_LDP_ENGINE
)
1258 ldpe_reset_ds_nbrs();
1259 conf
->trans_pref
= xconf
->trans_pref
;
1262 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1263 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1264 if (ldpd_process
== PROC_LDP_ENGINE
)
1265 ldpe_reset_ds_nbrs();
1268 conf
->flags
= xconf
->flags
;
1272 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1274 int stop_init_backoff
= 0;
1275 int remove_dynamic_tnbrs
= 0;
1276 int change_egress_label
= 0;
1277 int reset_nbrs_ipv4
= 0;
1279 int update_sockets
= 0;
1282 if (af_conf
->keepalive
!= xa
->keepalive
) {
1283 af_conf
->keepalive
= xa
->keepalive
;
1284 stop_init_backoff
= 1;
1286 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1287 af_conf
->lhello_interval
= xa
->lhello_interval
;
1288 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1289 af_conf
->thello_interval
= xa
->thello_interval
;
1292 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1293 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1294 remove_dynamic_tnbrs
= 1;
1295 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1296 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1298 /* need to set/unset IPV6_MINHOPCOUNT */
1301 /* for LDPv4 just resetting the neighbors is enough */
1302 reset_nbrs_ipv4
= 1;
1304 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1305 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1306 change_egress_label
= 1;
1307 af_conf
->flags
= xa
->flags
;
1309 /* update the transport address */
1310 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1311 af_conf
->trans_addr
= xa
->trans_addr
;
1316 if (strcmp(af_conf
->acl_label_advertise_to
,
1317 xa
->acl_label_advertise_to
) ||
1318 strcmp(af_conf
->acl_label_advertise_for
,
1319 xa
->acl_label_advertise_for
) ||
1320 strcmp(af_conf
->acl_label_accept_from
,
1321 xa
->acl_label_accept_from
) ||
1322 strcmp(af_conf
->acl_label_accept_for
,
1323 xa
->acl_label_accept_for
))
1325 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1326 remove_dynamic_tnbrs
= 1;
1327 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1328 change_egress_label
= 1;
1329 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1330 sizeof(af_conf
->acl_thello_accept_from
));
1331 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1332 sizeof(af_conf
->acl_label_allocate_for
));
1333 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1334 sizeof(af_conf
->acl_label_advertise_to
));
1335 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1336 sizeof(af_conf
->acl_label_advertise_for
));
1337 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1338 sizeof(af_conf
->acl_label_accept_from
));
1339 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1340 sizeof(af_conf
->acl_label_accept_for
));
1341 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1342 sizeof(af_conf
->acl_label_expnull_for
));
1344 /* apply the new configuration */
1345 switch (ldpd_process
) {
1346 case PROC_LDE_ENGINE
:
1347 if (change_egress_label
)
1348 lde_change_egress_label(af
);
1350 case PROC_LDP_ENGINE
:
1351 if (stop_init_backoff
)
1352 ldpe_stop_init_backoff(af
);
1353 if (remove_dynamic_tnbrs
)
1354 ldpe_remove_dynamic_tnbrs(af
);
1356 ldpe_reset_nbrs(AF_UNSPEC
);
1357 else if (reset_nbrs_ipv4
)
1358 ldpe_reset_nbrs(AF_INET
);
1361 if (update_sockets
&& iev_ldpe
)
1362 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1369 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1371 struct iface
*iface
, *itmp
, *xi
;
1373 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1374 /* find deleted interfaces */
1375 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1376 switch (ldpd_process
) {
1377 case PROC_LDP_ENGINE
:
1378 ldpe_if_exit(iface
);
1380 case PROC_LDE_ENGINE
:
1384 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1388 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1389 /* find new interfaces */
1390 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1392 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1394 switch (ldpd_process
) {
1395 case PROC_LDP_ENGINE
:
1396 ldpe_if_init(iface
);
1398 case PROC_LDE_ENGINE
:
1401 /* resend addresses to activate new interfaces */
1402 kif_redistribute(iface
->name
);
1408 /* update existing interfaces */
1409 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1410 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1415 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1417 if (ia
->enabled
!= xi
->enabled
) {
1418 ia
->enabled
= xi
->enabled
;
1419 if (ldpd_process
== PROC_LDP_ENGINE
)
1420 ldp_if_update(ia
->iface
, ia
->af
);
1422 ia
->hello_holdtime
= xi
->hello_holdtime
;
1423 ia
->hello_interval
= xi
->hello_interval
;
1427 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1429 struct tnbr
*tnbr
, *ttmp
, *xt
;
1431 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1432 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1435 /* find deleted tnbrs */
1436 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1437 switch (ldpd_process
) {
1438 case PROC_LDP_ENGINE
:
1439 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1440 tnbr_check(conf
, tnbr
);
1442 case PROC_LDE_ENGINE
:
1444 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1450 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1451 /* find new tnbrs */
1452 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1454 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1456 switch (ldpd_process
) {
1457 case PROC_LDP_ENGINE
:
1460 case PROC_LDE_ENGINE
:
1467 /* update existing tnbrs */
1468 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1469 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1474 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1476 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1480 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1481 /* find deleted nbrps */
1482 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1483 switch (ldpd_process
) {
1484 case PROC_LDP_ENGINE
:
1485 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1487 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1492 (ldp_af_global_get(&global
,
1493 nbr
->af
))->ldp_session_socket
,
1494 nbr
->af
, &nbr
->raddr
, NULL
);
1496 nbr
->auth
.method
= AUTH_NONE
;
1497 if (nbr_session_active_role(nbr
))
1498 nbr_establish_connection(nbr
);
1501 case PROC_LDE_ENGINE
:
1505 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1509 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1510 /* find new nbrps */
1511 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1513 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1515 switch (ldpd_process
) {
1516 case PROC_LDP_ENGINE
:
1517 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1519 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1520 nbr
->auth
.method
= nbrp
->auth
.method
;
1522 if (pfkey_establish(nbr
, nbrp
) == -1)
1523 fatalx("pfkey setup failed");
1526 (ldp_af_global_get(&global
,
1527 nbr
->af
))->ldp_session_socket
,
1528 nbr
->af
, &nbr
->raddr
,
1531 if (nbr_session_active_role(nbr
))
1532 nbr_establish_connection(nbr
);
1535 case PROC_LDE_ENGINE
:
1542 /* update existing nbrps */
1543 if (nbrp
->flags
!= xn
->flags
||
1544 nbrp
->keepalive
!= xn
->keepalive
||
1545 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1546 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1547 nbrp
->auth
.method
!= xn
->auth
.method
||
1548 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1553 nbrp
->keepalive
= xn
->keepalive
;
1554 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1555 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1556 nbrp
->auth
.method
= xn
->auth
.method
;
1557 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1558 sizeof(nbrp
->auth
.md5key
));
1559 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1560 nbrp
->flags
= xn
->flags
;
1562 if (ldpd_process
== PROC_LDP_ENGINE
) {
1563 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1564 if (nbr
&& nbrp_changed
) {
1565 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1568 nbr
->auth
.method
= nbrp
->auth
.method
;
1569 if (pfkey_establish(nbr
, nbrp
) == -1)
1570 fatalx("pfkey setup failed");
1572 nbr
->auth
.method
= nbrp
->auth
.method
;
1573 sock_set_md5sig((ldp_af_global_get(&global
,
1574 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1575 &nbr
->raddr
, nbrp
->auth
.md5key
);
1577 if (nbr_session_active_role(nbr
))
1578 nbr_establish_connection(nbr
);
1585 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1587 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1589 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1590 /* find deleted l2vpns */
1591 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1592 switch (ldpd_process
) {
1593 case PROC_LDE_ENGINE
:
1596 case PROC_LDP_ENGINE
:
1597 ldpe_l2vpn_exit(l2vpn
);
1602 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1606 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1607 /* find new l2vpns */
1608 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1610 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1611 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1612 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1613 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1615 switch (ldpd_process
) {
1616 case PROC_LDE_ENGINE
:
1619 case PROC_LDP_ENGINE
:
1620 ldpe_l2vpn_init(l2vpn
);
1627 /* update existing l2vpns */
1628 merge_l2vpn(conf
, l2vpn
, xl
);
1633 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1635 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1636 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1638 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1639 int previous_pw_type
, previous_mtu
;
1641 previous_pw_type
= l2vpn
->pw_type
;
1642 previous_mtu
= l2vpn
->mtu
;
1644 /* merge intefaces */
1645 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1646 /* find deleted interfaces */
1647 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1648 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1652 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1653 /* find new interfaces */
1654 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1656 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1659 switch (ldpd_process
) {
1660 case PROC_LDP_ENGINE
:
1661 case PROC_LDE_ENGINE
:
1664 kif_redistribute(lif
->ifname
);
1670 /* merge active pseudowires */
1671 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1672 /* find deleted active pseudowires */
1673 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1674 switch (ldpd_process
) {
1675 case PROC_LDE_ENGINE
:
1678 case PROC_LDP_ENGINE
:
1679 ldpe_l2vpn_pw_exit(pw
);
1685 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1689 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1690 /* find new active pseudowires */
1691 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1693 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1696 switch (ldpd_process
) {
1697 case PROC_LDE_ENGINE
:
1700 case PROC_LDP_ENGINE
:
1701 ldpe_l2vpn_pw_init(pw
);
1704 kif_redistribute(pw
->ifname
);
1710 /* update existing active pseudowire */
1711 if (pw
->af
!= xp
->af
||
1712 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1717 /* changes that require a session restart */
1718 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1719 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1724 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1725 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1726 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1727 reinstall_pwfec
= 1;
1729 reinstall_pwfec
= 0;
1731 if (ldpd_process
== PROC_LDP_ENGINE
) {
1733 ldpe_l2vpn_pw_exit(pw
);
1735 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1736 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1737 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1740 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1742 pw
->lsr_id
= xp
->lsr_id
;
1744 pw
->addr
= xp
->addr
;
1745 pw
->pwid
= xp
->pwid
;
1746 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1747 pw
->ifindex
= xp
->ifindex
;
1748 if (xp
->flags
& F_PW_CWORD_CONF
)
1749 pw
->flags
|= F_PW_CWORD_CONF
;
1751 pw
->flags
&= ~F_PW_CWORD_CONF
;
1752 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1753 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1755 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1756 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1757 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1759 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1760 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1761 ldpe_l2vpn_pw_init(pw
);
1762 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1763 l2vpn
->pw_type
= xl
->pw_type
;
1764 l2vpn
->mtu
= xl
->mtu
;
1766 l2vpn
->pw_type
= previous_pw_type
;
1767 l2vpn
->mtu
= previous_mtu
;
1771 /* merge inactive pseudowires */
1772 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1773 /* find deleted inactive pseudowires */
1774 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1775 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1779 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1780 /* find new inactive pseudowires */
1781 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1783 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1786 switch (ldpd_process
) {
1787 case PROC_LDE_ENGINE
:
1788 case PROC_LDP_ENGINE
:
1791 kif_redistribute(pw
->ifname
);
1797 /* update existing inactive pseudowire */
1798 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1800 pw
->addr
= xp
->addr
;
1801 pw
->pwid
= xp
->pwid
;
1802 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1803 pw
->ifindex
= xp
->ifindex
;
1804 pw
->flags
= xp
->flags
;
1807 l2vpn
->pw_type
= xl
->pw_type
;
1808 l2vpn
->mtu
= xl
->mtu
;
1809 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1810 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1814 config_new_empty(void)
1816 struct ldpd_conf
*xconf
;
1818 xconf
= calloc(1, sizeof(*xconf
));
1822 RB_INIT(iface_head
, &xconf
->iface_tree
);
1823 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1824 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1825 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1827 /* set default values */
1828 ldp_config_reset(xconf
);
1834 config_clear(struct ldpd_conf
*conf
)
1836 struct ldpd_conf
*xconf
;
1839 * Merge current config with an empty config, this will deactivate
1840 * and deallocate all the interfaces, pseudowires and so on. Before
1841 * merging, copy the router-id and other variables to avoid some
1842 * unnecessary operations, like trying to reset the neighborships.
1844 xconf
= config_new_empty();
1845 xconf
->ipv4
= conf
->ipv4
;
1846 xconf
->ipv6
= conf
->ipv6
;
1847 xconf
->rtr_id
= conf
->rtr_id
;
1848 xconf
->trans_pref
= conf
->trans_pref
;
1849 xconf
->flags
= conf
->flags
;
1850 merge_config(conf
, xconf
);