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");
412 if (errno
!= EINTR
&& errno
!= ECHILD
)
414 } else if (WIFSIGNALED(status
))
415 log_warnx("%s terminated; signal %d",
416 (pid
== lde_pid
) ? "label decision engine" :
417 "ldp engine", WTERMSIG(status
));
418 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
423 log_info("terminating");
434 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
437 int argc
= 0, nullfd
;
440 switch (pid
= fork()) {
442 fatal("cannot fork");
451 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
453 zlog_err("%s: failed to open /dev/null: %s", __func__
,
454 safe_strerror(errno
));
462 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
463 fatal("cannot setup imsg async fd");
464 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
465 fatal("cannot setup imsg sync fd");
467 argv
[argc
++] = argv0
;
470 fatalx("Can not start main process");
471 case PROC_LDE_ENGINE
:
472 argv
[argc
++] = (char *)"-L";
474 case PROC_LDP_ENGINE
:
475 argv
[argc
++] = (char *)"-E";
487 main_dispatch_ldpe(struct thread
*thread
)
489 struct imsgev
*iev
= THREAD_ARG(thread
);
490 struct imsgbuf
*ibuf
= &iev
->ibuf
;
498 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
499 fatal("imsg_read error");
500 if (n
== 0) /* connection closed */
504 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
510 switch (imsg
.hdr
.type
) {
512 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
514 case IMSG_REQUEST_SOCKETS
:
516 main_imsg_send_net_sockets(af
);
519 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
520 sizeof(struct acl_check
))
521 fatalx("IMSG_ACL_CHECK imsg with wrong len");
522 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
525 log_debug("%s: error handling imsg %d", __func__
,
534 /* this pipe is dead, so remove the event handlers and exit */
535 THREAD_READ_OFF(iev
->ev_read
);
536 THREAD_WRITE_OFF(iev
->ev_write
);
541 kill(lde_pid
, SIGTERM
);
549 main_dispatch_lde(struct thread
*thread
)
551 struct imsgev
*iev
= THREAD_ARG(thread
);
552 struct imsgbuf
*ibuf
= &iev
->ibuf
;
559 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
560 fatal("imsg_read error");
561 if (n
== 0) /* connection closed */
565 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
571 switch (imsg
.hdr
.type
) {
573 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
575 case IMSG_KLABEL_CHANGE
:
576 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
577 sizeof(struct kroute
))
578 fatalx("invalid size of IMSG_KLABEL_CHANGE");
579 if (kr_change(imsg
.data
))
580 log_warnx("%s: error changing route", __func__
);
582 case IMSG_KLABEL_DELETE
:
583 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
584 sizeof(struct kroute
))
585 fatalx("invalid size of IMSG_KLABEL_DELETE");
586 if (kr_delete(imsg
.data
))
587 log_warnx("%s: error deleting route", __func__
);
590 case IMSG_KPW_DELETE
:
593 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
594 sizeof(struct zapi_pw
))
595 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
597 switch (imsg
.hdr
.type
) {
599 if (kmpw_add(imsg
.data
))
600 log_warnx("%s: error adding "
601 "pseudowire", __func__
);
603 case IMSG_KPW_DELETE
:
604 if (kmpw_del(imsg
.data
))
605 log_warnx("%s: error deleting "
606 "pseudowire", __func__
);
609 if (kmpw_set(imsg
.data
))
610 log_warnx("%s: error setting "
611 "pseudowire", __func__
);
614 if (kmpw_unset(imsg
.data
))
615 log_warnx("%s: error unsetting "
616 "pseudowire", __func__
);
621 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
622 sizeof(struct acl_check
))
623 fatalx("IMSG_ACL_CHECK imsg with wrong len");
624 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
627 log_debug("%s: error handling imsg %d", __func__
,
636 /* this pipe is dead, so remove the event handlers and exit */
637 THREAD_READ_OFF(iev
->ev_read
);
638 THREAD_WRITE_OFF(iev
->ev_write
);
643 kill(ldpe_pid
, SIGTERM
);
651 ldp_write_handler(struct thread
*thread
)
653 struct imsgev
*iev
= THREAD_ARG(thread
);
654 struct imsgbuf
*ibuf
= &iev
->ibuf
;
657 iev
->ev_write
= NULL
;
659 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
660 fatal("msgbuf_write");
662 /* this pipe is dead, so remove the event handlers */
663 THREAD_READ_OFF(iev
->ev_read
);
664 THREAD_WRITE_OFF(iev
->ev_write
);
674 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
676 if (iev_ldpe
== NULL
)
678 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
682 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
684 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
688 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
690 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
692 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
694 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
700 imsg_event_add(struct imsgev
*iev
)
702 if (iev
->handler_read
)
703 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
706 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
707 thread_add_write(master
, iev
->handler_write
, iev
,
708 iev
->ibuf
.fd
, &iev
->ev_write
);
712 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
713 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
717 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
718 pid
, fd
, data
, datalen
)) != -1)
724 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
726 ibuf_close(&eb
->wbuf
, buf
);
731 evbuf_event_add(struct evbuf
*eb
)
734 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
739 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
742 msgbuf_init(&eb
->wbuf
);
744 eb
->handler
= handler
;
749 evbuf_clear(struct evbuf
*eb
)
751 THREAD_WRITE_OFF(eb
->ev
);
752 msgbuf_clear(&eb
->wbuf
);
757 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
759 int pipe_ldpe2lde
[2];
761 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
763 sock_set_nonblock(pipe_ldpe2lde
[0]);
764 sock_set_nonblock(pipe_ldpe2lde
[1]);
766 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
769 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
777 main_imsg_send_net_sockets(int af
)
779 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
782 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
783 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
784 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
785 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
789 main_imsg_send_net_socket(int af
, enum socket_type type
)
793 fd
= ldp_create_socket(af
, type
);
795 log_warnx("%s: failed to create %s socket for address-family "
796 "%s", __func__
, socket_name(type
), af_name(af
));
800 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
805 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
806 union ldpd_addr
*addr
, uint8_t prefixlen
)
810 struct acl_check acl_check
;
812 if (acl_name
[0] == '\0')
813 return FILTER_PERMIT
;
816 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
818 acl_check
.addr
= *addr
;
819 acl_check
.prefixlen
= prefixlen
;
821 /* send (blocking) */
822 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
824 imsg_flush(&iev
->ibuf
);
826 /* receive (blocking) and parse result */
827 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
828 fatal("imsg_read error");
829 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
831 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
832 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
833 fatalx("ldp_acl_request: invalid response");
835 return (*((int *)imsg
.data
));
839 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
841 struct access_list
*alist
;
842 struct prefix prefix
;
845 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
847 result
= FILTER_DENY
;
849 prefix
.family
= acl_check
->af
;
850 switch (prefix
.family
) {
852 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
855 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
858 fatalx("ldp_acl_reply: unknown af");
860 prefix
.prefixlen
= acl_check
->prefixlen
;
861 result
= access_list_apply(alist
, &prefix
);
864 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
868 struct ldpd_af_conf
*
869 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
873 return (&xconf
->ipv4
);
875 return (&xconf
->ipv6
);
877 fatalx("ldp_af_conf_get: unknown af");
881 struct ldpd_af_global
*
882 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
886 return (&xglobal
->ipv4
);
888 return (&xglobal
->ipv6
);
890 fatalx("ldp_af_global_get: unknown af");
895 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
897 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
898 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
902 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
904 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
905 return (xconf
->rtr_id
.s_addr
);
907 return (global
.rtr_id
.s_addr
);
911 main_imsg_send_config(struct ldpd_conf
*xconf
)
915 struct nbr_params
*nbrp
;
917 struct l2vpn_if
*lif
;
920 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
921 sizeof(*xconf
)) == -1)
924 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
925 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
926 sizeof(*iface
)) == -1)
930 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
931 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
932 sizeof(*tnbr
)) == -1)
936 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
937 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
938 sizeof(*nbrp
)) == -1)
942 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
943 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
944 sizeof(*l2vpn
)) == -1)
947 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
948 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
952 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
953 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
957 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
958 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
964 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
971 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
974 * When reading from a configuration file (startup and sighup), we
975 * call merge_config() only once after the whole config has been read.
976 * This is the optimal and least disruptive way to update the running
979 if (vty
&& vty
->type
== VTY_FILE
)
982 ldp_config_normalize(xconf
);
984 if (main_imsg_send_config(xconf
) == -1)
987 merge_config(ldpd_conf
, xconf
);
993 ldp_config_normalize(struct ldpd_conf
*xconf
)
995 struct iface
*iface
, *itmp
;
996 struct nbr_params
*nbrp
, *ntmp
;
998 struct l2vpn_pw
*pw
, *ptmp
;
1000 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1001 ldp_config_reset_main(xconf
);
1003 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1004 ldp_config_reset_af(xconf
, AF_INET
);
1005 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1006 ldp_config_reset_af(xconf
, AF_INET6
);
1008 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1009 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1013 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1017 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1018 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1020 if (nbrp
->auth
.method
!= AUTH_NONE
)
1024 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1029 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1030 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1031 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1033 pw
->addr
.v4
= pw
->lsr_id
;
1036 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1038 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1039 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1041 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1043 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1045 pw
->addr
.v4
= pw
->lsr_id
;
1048 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1050 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1051 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1057 ldp_config_reset(struct ldpd_conf
*conf
)
1059 ldp_config_reset_main(conf
);
1060 ldp_config_reset_l2vpns(conf
);
1064 ldp_config_reset_main(struct ldpd_conf
*conf
)
1066 struct iface
*iface
;
1067 struct nbr_params
*nbrp
;
1069 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1070 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1073 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1077 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1078 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1081 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1085 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1086 ldp_config_reset_af(conf
, AF_INET
);
1087 ldp_config_reset_af(conf
, AF_INET6
);
1088 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1089 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1090 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1091 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1092 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1097 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1099 struct ldpd_af_conf
*af_conf
;
1100 struct iface
*iface
;
1101 struct iface_af
*ia
;
1102 struct tnbr
*tnbr
, *ttmp
;
1104 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1105 ia
= iface_af_get(iface
, af
);
1109 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1114 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1118 af_conf
= ldp_af_conf_get(conf
, af
);
1119 af_conf
->keepalive
= 180;
1120 af_conf
->lhello_holdtime
= 0;
1121 af_conf
->lhello_interval
= 0;
1122 af_conf
->thello_holdtime
= 0;
1123 af_conf
->thello_interval
= 0;
1124 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1129 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1131 struct l2vpn
*l2vpn
;
1132 struct l2vpn_if
*lif
;
1133 struct l2vpn_pw
*pw
;
1135 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1136 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1137 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1138 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1141 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1144 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1145 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1148 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1151 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1152 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1155 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1159 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1165 ldp_clear_config(struct ldpd_conf
*xconf
)
1167 struct iface
*iface
;
1169 struct nbr_params
*nbrp
;
1170 struct l2vpn
*l2vpn
;
1172 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1173 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1175 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1178 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1179 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1181 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1184 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1185 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1187 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1190 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1191 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1193 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1200 #define COPY(a, b) do { \
1201 a = malloc(sizeof(*a)); \
1208 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1210 merge_global(conf
, xconf
);
1211 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1212 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1213 merge_ifaces(conf
, xconf
);
1214 merge_tnbrs(conf
, xconf
);
1215 merge_nbrps(conf
, xconf
);
1216 merge_l2vpns(conf
, xconf
);
1220 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1222 /* change of router-id requires resetting all neighborships */
1223 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1224 if (ldpd_process
== PROC_LDP_ENGINE
) {
1225 ldpe_reset_nbrs(AF_UNSPEC
);
1226 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1227 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1228 if_update_all(AF_UNSPEC
);
1229 tnbr_update_all(AF_UNSPEC
);
1232 conf
->rtr_id
= xconf
->rtr_id
;
1235 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1236 conf
->lhello_interval
= xconf
->lhello_interval
;
1237 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1238 conf
->thello_interval
= xconf
->thello_interval
;
1240 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1241 if (ldpd_process
== PROC_LDP_ENGINE
)
1242 ldpe_reset_ds_nbrs();
1243 conf
->trans_pref
= xconf
->trans_pref
;
1246 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1247 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1248 if (ldpd_process
== PROC_LDP_ENGINE
)
1249 ldpe_reset_ds_nbrs();
1252 conf
->flags
= xconf
->flags
;
1256 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1258 int stop_init_backoff
= 0;
1259 int remove_dynamic_tnbrs
= 0;
1260 int change_egress_label
= 0;
1261 int reset_nbrs_ipv4
= 0;
1263 int update_sockets
= 0;
1266 if (af_conf
->keepalive
!= xa
->keepalive
) {
1267 af_conf
->keepalive
= xa
->keepalive
;
1268 stop_init_backoff
= 1;
1270 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1271 af_conf
->lhello_interval
= xa
->lhello_interval
;
1272 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1273 af_conf
->thello_interval
= xa
->thello_interval
;
1276 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1277 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1278 remove_dynamic_tnbrs
= 1;
1279 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1280 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1282 /* need to set/unset IPV6_MINHOPCOUNT */
1285 /* for LDPv4 just resetting the neighbors is enough */
1286 reset_nbrs_ipv4
= 1;
1288 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1289 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1290 change_egress_label
= 1;
1291 af_conf
->flags
= xa
->flags
;
1293 /* update the transport address */
1294 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1295 af_conf
->trans_addr
= xa
->trans_addr
;
1300 if (strcmp(af_conf
->acl_label_advertise_to
,
1301 xa
->acl_label_advertise_to
) ||
1302 strcmp(af_conf
->acl_label_advertise_for
,
1303 xa
->acl_label_advertise_for
) ||
1304 strcmp(af_conf
->acl_label_accept_from
,
1305 xa
->acl_label_accept_from
) ||
1306 strcmp(af_conf
->acl_label_accept_for
,
1307 xa
->acl_label_accept_for
))
1309 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1310 remove_dynamic_tnbrs
= 1;
1311 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1312 change_egress_label
= 1;
1313 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1314 sizeof(af_conf
->acl_thello_accept_from
));
1315 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1316 sizeof(af_conf
->acl_label_allocate_for
));
1317 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1318 sizeof(af_conf
->acl_label_advertise_to
));
1319 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1320 sizeof(af_conf
->acl_label_advertise_for
));
1321 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1322 sizeof(af_conf
->acl_label_accept_from
));
1323 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1324 sizeof(af_conf
->acl_label_accept_for
));
1325 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1326 sizeof(af_conf
->acl_label_expnull_for
));
1328 /* apply the new configuration */
1329 switch (ldpd_process
) {
1330 case PROC_LDE_ENGINE
:
1331 if (change_egress_label
)
1332 lde_change_egress_label(af
);
1334 case PROC_LDP_ENGINE
:
1335 if (stop_init_backoff
)
1336 ldpe_stop_init_backoff(af
);
1337 if (remove_dynamic_tnbrs
)
1338 ldpe_remove_dynamic_tnbrs(af
);
1340 ldpe_reset_nbrs(AF_UNSPEC
);
1341 else if (reset_nbrs_ipv4
)
1342 ldpe_reset_nbrs(AF_INET
);
1345 if (update_sockets
&& iev_ldpe
)
1346 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1353 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1355 struct iface
*iface
, *itmp
, *xi
;
1357 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1358 /* find deleted interfaces */
1359 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1360 switch (ldpd_process
) {
1361 case PROC_LDP_ENGINE
:
1362 ldpe_if_exit(iface
);
1364 case PROC_LDE_ENGINE
:
1368 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1372 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1373 /* find new interfaces */
1374 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1376 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1378 switch (ldpd_process
) {
1379 case PROC_LDP_ENGINE
:
1380 ldpe_if_init(iface
);
1382 case PROC_LDE_ENGINE
:
1385 /* resend addresses to activate new interfaces */
1386 kif_redistribute(iface
->name
);
1392 /* update existing interfaces */
1393 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1394 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1399 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1401 if (ia
->enabled
!= xi
->enabled
) {
1402 ia
->enabled
= xi
->enabled
;
1403 if (ldpd_process
== PROC_LDP_ENGINE
)
1404 ldp_if_update(ia
->iface
, ia
->af
);
1406 ia
->hello_holdtime
= xi
->hello_holdtime
;
1407 ia
->hello_interval
= xi
->hello_interval
;
1411 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1413 struct tnbr
*tnbr
, *ttmp
, *xt
;
1415 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1416 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1419 /* find deleted tnbrs */
1420 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1421 switch (ldpd_process
) {
1422 case PROC_LDP_ENGINE
:
1423 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1424 tnbr_check(conf
, tnbr
);
1426 case PROC_LDE_ENGINE
:
1428 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1434 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1435 /* find new tnbrs */
1436 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1438 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1440 switch (ldpd_process
) {
1441 case PROC_LDP_ENGINE
:
1444 case PROC_LDE_ENGINE
:
1451 /* update existing tnbrs */
1452 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1453 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1458 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1460 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1464 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1465 /* find deleted nbrps */
1466 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1467 switch (ldpd_process
) {
1468 case PROC_LDP_ENGINE
:
1469 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1471 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1476 (ldp_af_global_get(&global
,
1477 nbr
->af
))->ldp_session_socket
,
1478 nbr
->af
, &nbr
->raddr
, NULL
);
1480 nbr
->auth
.method
= AUTH_NONE
;
1481 if (nbr_session_active_role(nbr
))
1482 nbr_establish_connection(nbr
);
1485 case PROC_LDE_ENGINE
:
1489 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1493 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1494 /* find new nbrps */
1495 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1497 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1499 switch (ldpd_process
) {
1500 case PROC_LDP_ENGINE
:
1501 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1503 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1504 nbr
->auth
.method
= nbrp
->auth
.method
;
1506 if (pfkey_establish(nbr
, nbrp
) == -1)
1507 fatalx("pfkey setup failed");
1510 (ldp_af_global_get(&global
,
1511 nbr
->af
))->ldp_session_socket
,
1512 nbr
->af
, &nbr
->raddr
,
1515 if (nbr_session_active_role(nbr
))
1516 nbr_establish_connection(nbr
);
1519 case PROC_LDE_ENGINE
:
1526 /* update existing nbrps */
1527 if (nbrp
->flags
!= xn
->flags
||
1528 nbrp
->keepalive
!= xn
->keepalive
||
1529 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1530 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1531 nbrp
->auth
.method
!= xn
->auth
.method
||
1532 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1537 nbrp
->keepalive
= xn
->keepalive
;
1538 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1539 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1540 nbrp
->auth
.method
= xn
->auth
.method
;
1541 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1542 sizeof(nbrp
->auth
.md5key
));
1543 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1544 nbrp
->flags
= xn
->flags
;
1546 if (ldpd_process
== PROC_LDP_ENGINE
) {
1547 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1548 if (nbr
&& nbrp_changed
) {
1549 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1552 nbr
->auth
.method
= nbrp
->auth
.method
;
1553 if (pfkey_establish(nbr
, nbrp
) == -1)
1554 fatalx("pfkey setup failed");
1556 nbr
->auth
.method
= nbrp
->auth
.method
;
1557 sock_set_md5sig((ldp_af_global_get(&global
,
1558 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1559 &nbr
->raddr
, nbrp
->auth
.md5key
);
1561 if (nbr_session_active_role(nbr
))
1562 nbr_establish_connection(nbr
);
1569 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1571 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1573 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1574 /* find deleted l2vpns */
1575 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1576 switch (ldpd_process
) {
1577 case PROC_LDE_ENGINE
:
1580 case PROC_LDP_ENGINE
:
1581 ldpe_l2vpn_exit(l2vpn
);
1586 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1590 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1591 /* find new l2vpns */
1592 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1594 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1595 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1596 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1597 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1599 switch (ldpd_process
) {
1600 case PROC_LDE_ENGINE
:
1603 case PROC_LDP_ENGINE
:
1604 ldpe_l2vpn_init(l2vpn
);
1611 /* update existing l2vpns */
1612 merge_l2vpn(conf
, l2vpn
, xl
);
1617 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1619 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1620 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1622 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1623 int previous_pw_type
, previous_mtu
;
1625 previous_pw_type
= l2vpn
->pw_type
;
1626 previous_mtu
= l2vpn
->mtu
;
1628 /* merge intefaces */
1629 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1630 /* find deleted interfaces */
1631 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1632 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1636 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1637 /* find new interfaces */
1638 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1640 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1643 switch (ldpd_process
) {
1644 case PROC_LDP_ENGINE
:
1645 case PROC_LDE_ENGINE
:
1648 kif_redistribute(lif
->ifname
);
1654 /* merge active pseudowires */
1655 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1656 /* find deleted active pseudowires */
1657 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1658 switch (ldpd_process
) {
1659 case PROC_LDE_ENGINE
:
1662 case PROC_LDP_ENGINE
:
1663 ldpe_l2vpn_pw_exit(pw
);
1669 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1673 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1674 /* find new active pseudowires */
1675 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1677 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1680 switch (ldpd_process
) {
1681 case PROC_LDE_ENGINE
:
1684 case PROC_LDP_ENGINE
:
1685 ldpe_l2vpn_pw_init(pw
);
1688 kif_redistribute(pw
->ifname
);
1694 /* update existing active pseudowire */
1695 if (pw
->af
!= xp
->af
||
1696 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1701 /* changes that require a session restart */
1702 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1703 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1708 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1709 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1710 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1711 reinstall_pwfec
= 1;
1713 reinstall_pwfec
= 0;
1715 if (ldpd_process
== PROC_LDP_ENGINE
) {
1717 ldpe_l2vpn_pw_exit(pw
);
1719 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1720 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1721 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1724 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1726 pw
->lsr_id
= xp
->lsr_id
;
1728 pw
->addr
= xp
->addr
;
1729 pw
->pwid
= xp
->pwid
;
1730 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1731 pw
->ifindex
= xp
->ifindex
;
1732 if (xp
->flags
& F_PW_CWORD_CONF
)
1733 pw
->flags
|= F_PW_CWORD_CONF
;
1735 pw
->flags
&= ~F_PW_CWORD_CONF
;
1736 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1737 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1739 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1740 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1741 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1743 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1744 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1745 ldpe_l2vpn_pw_init(pw
);
1746 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1747 l2vpn
->pw_type
= xl
->pw_type
;
1748 l2vpn
->mtu
= xl
->mtu
;
1750 l2vpn
->pw_type
= previous_pw_type
;
1751 l2vpn
->mtu
= previous_mtu
;
1755 /* merge inactive pseudowires */
1756 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1757 /* find deleted inactive pseudowires */
1758 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1759 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1763 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1764 /* find new inactive pseudowires */
1765 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1767 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1770 switch (ldpd_process
) {
1771 case PROC_LDE_ENGINE
:
1772 case PROC_LDP_ENGINE
:
1775 kif_redistribute(pw
->ifname
);
1781 /* update existing inactive pseudowire */
1782 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1784 pw
->addr
= xp
->addr
;
1785 pw
->pwid
= xp
->pwid
;
1786 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1787 pw
->ifindex
= xp
->ifindex
;
1788 pw
->flags
= xp
->flags
;
1791 l2vpn
->pw_type
= xl
->pw_type
;
1792 l2vpn
->mtu
= xl
->mtu
;
1793 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1794 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1798 config_new_empty(void)
1800 struct ldpd_conf
*xconf
;
1802 xconf
= calloc(1, sizeof(*xconf
));
1806 RB_INIT(iface_head
, &xconf
->iface_tree
);
1807 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1808 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1809 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1811 /* set default values */
1812 ldp_config_reset(xconf
);
1818 config_clear(struct ldpd_conf
*conf
)
1820 struct ldpd_conf
*xconf
;
1823 * Merge current config with an empty config, this will deactivate
1824 * and deallocate all the interfaces, pseudowires and so on. Before
1825 * merging, copy the router-id and other variables to avoid some
1826 * unnecessary operations, like trying to reset the neighborships.
1828 xconf
= config_new_empty();
1829 xconf
->ipv4
= conf
->ipv4
;
1830 xconf
->ipv6
= conf
->ipv6
;
1831 xconf
->rtr_id
= conf
->rtr_id
;
1832 xconf
->trans_pref
= conf
->trans_pref
;
1833 xconf
->flags
= conf
->flags
;
1834 merge_config(conf
, xconf
);