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 const char *, const char *, const char *, const char *);
49 static int main_dispatch_ldpe(struct thread
*);
50 static int main_dispatch_lde(struct thread
*);
51 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
53 static void main_imsg_send_net_sockets(int);
54 static void main_imsg_send_net_socket(int, enum socket_type
);
55 static int main_imsg_send_config(struct ldpd_conf
*);
56 static void ldp_config_normalize(struct ldpd_conf
*, void **);
57 static void ldp_config_reset_main(struct ldpd_conf
*, void **);
58 static void ldp_config_reset_af(struct ldpd_conf
*, int, void **);
59 static void merge_config_ref(struct ldpd_conf
*, struct ldpd_conf
*, void **);
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
*, void **);
64 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
65 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*, void **);
66 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*, void **);
67 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*, void **);
68 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
69 struct l2vpn
*, void **);
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_conf
*ldpd_conf
;
82 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
83 static struct imsgev
*iev_lde
, *iev_lde_sync
;
84 static pid_t ldpe_pid
;
87 #define LDP_DEFAULT_CONFIG "ldpd.conf"
88 #define LDP_VTY_PORT 2612
90 /* Master of threads. */
91 struct thread_master
*master
;
94 static zebra_capabilities_t _caps_p
[] =
100 struct zebra_privs_t ldpd_privs
=
102 #if defined(FRR_USER) && defined(FRR_GROUP)
106 #if defined(VTY_GROUP)
107 .vty_group
= VTY_GROUP
,
110 .cap_num_p
= array_size(_caps_p
),
114 /* CTL Socket path */
115 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
118 #define OPTION_CTLSOCK 1001
119 static struct option longopts
[] =
121 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
122 { "instance", required_argument
, NULL
, 'n'},
126 /* SIGHUP handler. */
130 log_info("SIGHUP received");
133 /* SIGINT / SIGTERM handler. */
137 log_info("SIGINT received");
141 /* SIGUSR1 handler. */
148 static struct quagga_signal_t ldp_signals
[] =
168 FRR_DAEMON_INFO(ldpd
, LDP
,
169 .vty_port
= LDP_VTY_PORT
,
171 .proghelp
= "Implementation of the LDP protocol.",
173 .signals
= ldp_signals
,
174 .n_signals
= array_size(ldp_signals
),
176 .privs
= &ldpd_privs
,
180 main(int argc
, char *argv
[])
183 int lflag
= 0, eflag
= 0;
184 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
185 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
186 char *ctl_sock_custom_path
= NULL
;
188 const char *user
= NULL
;
189 const char *group
= NULL
;
190 u_short instance
= 0;
191 const char *instance_char
= NULL
;
193 ldpd_process
= PROC_MAIN
;
195 saved_argv0
= argv
[0];
196 if (saved_argv0
== NULL
)
197 saved_argv0
= (char *)"ldpd";
199 frr_preinit(&ldpd_di
, argc
, argv
);
200 frr_opt_add("LEn:", longopts
,
201 " --ctl_socket Override ctl socket path\n"
202 "-n, --instance Instance id\n");
207 opt
= frr_getopt(argc
, argv
, NULL
);
216 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
222 * LDPD_SOCKET configured as relative path
223 * during config? Should really never happen for
226 ctl_sock_name
= (char *)LDPD_SOCKET
;
227 ctl_sock_custom_path
= optarg
;
228 strlcpy(ctl_sock_path
, ctl_sock_custom_path
,
229 sizeof(ctl_sock_path
));
230 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
231 strlcat(ctl_sock_path
, ctl_sock_name
,
232 sizeof(ctl_sock_path
));
235 instance
= atoi(optarg
);
236 instance_char
= optarg
;
252 user
= ldpd_privs
.user
;
253 group
= ldpd_privs
.group
;
257 if (argc
> 0 || (lflag
&& eflag
))
260 /* check for root privileges */
261 if (geteuid() != 0) {
263 perror(ldpd_di
.progname
);
268 lde(user
, group
, instance
);
270 ldpe(user
, group
, ctl_sock_path
);
272 openzlog(ldpd_di
.progname
, "LDP", 0,
273 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
275 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
277 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
278 pipe_parent2ldpe_sync
) == -1)
280 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
282 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
283 pipe_parent2lde_sync
) == -1)
285 sock_set_nonblock(pipe_parent2ldpe
[0]);
286 sock_set_cloexec(pipe_parent2ldpe
[0]);
287 sock_set_nonblock(pipe_parent2ldpe
[1]);
288 sock_set_cloexec(pipe_parent2ldpe
[1]);
289 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
290 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
291 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
292 sock_set_nonblock(pipe_parent2lde
[0]);
293 sock_set_cloexec(pipe_parent2lde
[0]);
294 sock_set_nonblock(pipe_parent2lde
[1]);
295 sock_set_cloexec(pipe_parent2lde
[1]);
296 sock_set_nonblock(pipe_parent2lde_sync
[0]);
297 sock_set_cloexec(pipe_parent2lde_sync
[0]);
298 sock_set_cloexec(pipe_parent2lde_sync
[1]);
301 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
302 pipe_parent2lde
[1], pipe_parent2lde_sync
[1],
303 user
, group
, ctl_sock_custom_path
, instance_char
);
304 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
305 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1],
306 user
, group
, ctl_sock_custom_path
, instance_char
);
308 /* drop privileges */
309 zprivs_init(&ldpd_privs
);
311 /* setup signal handler */
312 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
315 master
= thread_master_create();
319 vty_config_lockless();
325 ldp_zebra_init(master
);
327 /* Get configuration file. */
328 ldpd_conf
= config_new_empty();
329 ldp_config_reset_main(ldpd_conf
, NULL
);
330 QOBJ_REG(ldpd_conf
, ldpd_conf
);
333 /* setup pipes to children */
334 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
335 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
336 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
337 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
339 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
340 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
341 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
342 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
343 iev_ldpe
->handler_write
= ldp_write_handler
;
345 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
346 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
347 iev_ldpe_sync
->ev_read
= thread_add_read(master
,
348 iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
);
349 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
351 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
352 iev_lde
->handler_read
= main_dispatch_lde
;
353 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
354 iev_lde
, iev_lde
->ibuf
.fd
);
355 iev_lde
->handler_write
= ldp_write_handler
;
357 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
358 iev_lde_sync
->handler_read
= main_dispatch_lde
;
359 iev_lde_sync
->ev_read
= thread_add_read(master
,
360 iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
);
361 iev_lde_sync
->handler_write
= ldp_write_handler
;
363 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
364 fatal("could not establish imsg links");
365 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
367 main_imsg_send_config(ldpd_conf
);
369 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
370 main_imsg_send_net_sockets(AF_INET
);
371 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
372 main_imsg_send_net_sockets(AF_INET6
);
387 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
388 close(iev_ldpe
->ibuf
.fd
);
389 msgbuf_clear(&iev_lde
->ibuf
.w
);
390 close(iev_lde
->ibuf
.fd
);
392 config_clear(ldpd_conf
);
393 QOBJ_UNREG(ldpd_conf
);
395 log_debug("waiting for children to terminate");
399 if (errno
!= EINTR
&& errno
!= ECHILD
)
401 } else if (WIFSIGNALED(status
))
402 log_warnx("%s terminated; signal %d",
403 (pid
== lde_pid
) ? "label decision engine" :
404 "ldp engine", WTERMSIG(status
));
405 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
410 log_info("terminating");
417 zprivs_terminate(&ldpd_privs
);
418 thread_master_free(master
);
425 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
,
426 const char *user
, const char *group
, const char *ctl_sock_custom_path
,
427 const char *instance
)
433 switch (pid
= fork()) {
435 fatal("cannot fork");
444 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
445 fatal("cannot setup imsg async fd");
446 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
447 fatal("cannot setup imsg sync fd");
449 argv
[argc
++] = argv0
;
452 fatalx("Can not start main process");
453 case PROC_LDE_ENGINE
:
454 argv
[argc
++] = (char *)"-L";
456 case PROC_LDP_ENGINE
:
457 argv
[argc
++] = (char *)"-E";
461 argv
[argc
++] = (char *)"-u";
462 argv
[argc
++] = (char *)user
;
465 argv
[argc
++] = (char *)"-g";
466 argv
[argc
++] = (char *)group
;
468 if (ctl_sock_custom_path
) {
469 argv
[argc
++] = (char *)"--ctl_socket";
470 argv
[argc
++] = (char *)ctl_sock_custom_path
;
472 /* zclient serv path */
473 argv
[argc
++] = (char *)"-z";
474 argv
[argc
++] = (char *)zclient_serv_path_get();
477 argv
[argc
++] = (char *)"-n";
478 argv
[argc
++] = (char *)instance
;
489 main_dispatch_ldpe(struct thread
*thread
)
491 struct imsgev
*iev
= THREAD_ARG(thread
);
492 struct imsgbuf
*ibuf
= &iev
->ibuf
;
500 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
501 fatal("imsg_read error");
502 if (n
== 0) /* connection closed */
506 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
512 switch (imsg
.hdr
.type
) {
514 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
516 case IMSG_REQUEST_SOCKETS
:
518 main_imsg_send_net_sockets(af
);
521 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
522 sizeof(struct acl_check
))
523 fatalx("IMSG_ACL_CHECK imsg with wrong len");
524 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
527 log_debug("%s: error handling imsg %d", __func__
,
536 /* this pipe is dead, so remove the event handlers and exit */
537 THREAD_READ_OFF(iev
->ev_read
);
538 THREAD_WRITE_OFF(iev
->ev_write
);
543 kill(lde_pid
, SIGTERM
);
551 main_dispatch_lde(struct thread
*thread
)
553 struct imsgev
*iev
= THREAD_ARG(thread
);
554 struct imsgbuf
*ibuf
= &iev
->ibuf
;
561 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
562 fatal("imsg_read error");
563 if (n
== 0) /* connection closed */
567 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
573 switch (imsg
.hdr
.type
) {
575 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
577 case IMSG_KLABEL_CHANGE
:
578 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
579 sizeof(struct kroute
))
580 fatalx("invalid size of IMSG_KLABEL_CHANGE");
581 if (kr_change(imsg
.data
))
582 log_warnx("%s: error changing route", __func__
);
584 case IMSG_KLABEL_DELETE
:
585 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
586 sizeof(struct kroute
))
587 fatalx("invalid size of IMSG_KLABEL_DELETE");
588 if (kr_delete(imsg
.data
))
589 log_warnx("%s: error deleting route", __func__
);
591 case IMSG_KPWLABEL_CHANGE
:
592 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
594 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
595 if (kmpw_set(imsg
.data
))
596 log_warnx("%s: error changing pseudowire",
599 case IMSG_KPWLABEL_DELETE
:
600 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
602 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
603 if (kmpw_unset(imsg
.data
))
604 log_warnx("%s: error unsetting pseudowire",
608 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
609 sizeof(struct acl_check
))
610 fatalx("IMSG_ACL_CHECK imsg with wrong len");
611 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
614 log_debug("%s: error handling imsg %d", __func__
,
623 /* this pipe is dead, so remove the event handlers and exit */
624 THREAD_READ_OFF(iev
->ev_read
);
625 THREAD_WRITE_OFF(iev
->ev_write
);
630 kill(ldpe_pid
, SIGTERM
);
638 ldp_write_handler(struct thread
*thread
)
640 struct imsgev
*iev
= THREAD_ARG(thread
);
641 struct imsgbuf
*ibuf
= &iev
->ibuf
;
644 iev
->ev_write
= NULL
;
646 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
647 fatal("msgbuf_write");
649 /* this pipe is dead, so remove the event handlers */
650 THREAD_READ_OFF(iev
->ev_read
);
651 THREAD_WRITE_OFF(iev
->ev_write
);
661 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
663 if (iev_ldpe
== NULL
)
665 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
669 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
671 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
675 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
677 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
679 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
681 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
687 imsg_event_add(struct imsgev
*iev
)
689 if (iev
->handler_read
)
690 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
693 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
694 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
699 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
700 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
704 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
705 pid
, fd
, data
, datalen
)) != -1)
711 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
713 ibuf_close(&eb
->wbuf
, buf
);
718 evbuf_event_add(struct evbuf
*eb
)
721 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
726 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
729 msgbuf_init(&eb
->wbuf
);
731 eb
->handler
= handler
;
736 evbuf_clear(struct evbuf
*eb
)
738 THREAD_WRITE_OFF(eb
->ev
);
739 msgbuf_clear(&eb
->wbuf
);
744 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
746 int pipe_ldpe2lde
[2];
748 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
750 sock_set_nonblock(pipe_ldpe2lde
[0]);
751 sock_set_nonblock(pipe_ldpe2lde
[1]);
753 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
756 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
764 main_imsg_send_net_sockets(int af
)
766 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
769 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
770 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
771 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
772 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
776 main_imsg_send_net_socket(int af
, enum socket_type type
)
780 fd
= ldp_create_socket(af
, type
);
782 log_warnx("%s: failed to create %s socket for address-family "
783 "%s", __func__
, socket_name(type
), af_name(af
));
787 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
792 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
793 union ldpd_addr
*addr
, uint8_t prefixlen
)
797 struct acl_check acl_check
;
799 if (acl_name
[0] == '\0')
800 return FILTER_PERMIT
;
803 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
805 acl_check
.addr
= *addr
;
806 acl_check
.prefixlen
= prefixlen
;
808 /* send (blocking) */
809 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
811 imsg_flush(&iev
->ibuf
);
813 /* receive (blocking) and parse result */
814 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
815 fatal("imsg_read error");
816 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
818 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
819 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
820 fatalx("ldp_acl_request: invalid response");
822 return (*((int *)imsg
.data
));
826 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
828 struct access_list
*alist
;
829 struct prefix prefix
;
832 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
834 result
= FILTER_DENY
;
836 prefix
.family
= acl_check
->af
;
837 switch (prefix
.family
) {
839 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
842 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
845 fatalx("ldp_acl_reply: unknown af");
847 prefix
.prefixlen
= acl_check
->prefixlen
;
848 result
= access_list_apply(alist
, &prefix
);
851 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
855 struct ldpd_af_conf
*
856 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
860 return (&xconf
->ipv4
);
862 return (&xconf
->ipv6
);
864 fatalx("ldp_af_conf_get: unknown af");
868 struct ldpd_af_global
*
869 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
873 return (&xglobal
->ipv4
);
875 return (&xglobal
->ipv6
);
877 fatalx("ldp_af_global_get: unknown af");
882 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
884 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
885 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
889 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
891 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
892 return (xconf
->rtr_id
.s_addr
);
894 return (global
.rtr_id
.s_addr
);
898 main_imsg_send_config(struct ldpd_conf
*xconf
)
902 struct nbr_params
*nbrp
;
904 struct l2vpn_if
*lif
;
907 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
908 sizeof(*xconf
)) == -1)
911 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
912 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
913 sizeof(*iface
)) == -1)
917 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
918 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
919 sizeof(*tnbr
)) == -1)
923 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
924 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
925 sizeof(*nbrp
)) == -1)
929 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
930 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
931 sizeof(*l2vpn
)) == -1)
934 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
935 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
939 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
940 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
944 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
945 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
951 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
958 ldp_reload_ref(struct ldpd_conf
*xconf
, void **ref
)
960 ldp_config_normalize(xconf
, ref
);
962 if (main_imsg_send_config(xconf
) == -1)
965 merge_config_ref(ldpd_conf
, xconf
, ref
);
971 ldp_reload(struct ldpd_conf
*xconf
)
973 return ldp_reload_ref(xconf
, NULL
);
977 ldp_config_normalize(struct ldpd_conf
*xconf
, void **ref
)
982 if (!(xconf
->flags
& F_LDPD_ENABLED
))
983 ldp_config_reset_main(xconf
, ref
);
985 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
986 ldp_config_reset_af(xconf
, AF_INET
, ref
);
987 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
988 ldp_config_reset_af(xconf
, AF_INET6
, ref
);
991 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
992 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
993 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
997 pw
->addr
.v4
= pw
->lsr_id
;
999 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1000 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
1004 pw
->addr
.v4
= pw
->lsr_id
;
1010 ldp_config_reset_main(struct ldpd_conf
*conf
, void **ref
)
1012 struct iface
*iface
;
1013 struct nbr_params
*nbrp
;
1015 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1016 if (ref
&& *ref
== iface
)
1018 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1022 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1023 if (ref
&& *ref
== nbrp
)
1025 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1029 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1030 ldp_config_reset_af(conf
, AF_INET
, ref
);
1031 ldp_config_reset_af(conf
, AF_INET6
, ref
);
1032 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1033 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1034 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1035 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1036 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1041 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
, void **ref
)
1043 struct ldpd_af_conf
*af_conf
;
1044 struct iface
*iface
;
1045 struct iface_af
*ia
;
1046 struct tnbr
*tnbr
, *ttmp
;
1048 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1049 ia
= iface_af_get(iface
, af
);
1053 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1057 if (ref
&& *ref
== tnbr
)
1059 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1063 af_conf
= ldp_af_conf_get(conf
, af
);
1064 af_conf
->keepalive
= 180;
1065 af_conf
->lhello_holdtime
= 0;
1066 af_conf
->lhello_interval
= 0;
1067 af_conf
->thello_holdtime
= 0;
1068 af_conf
->thello_interval
= 0;
1069 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1074 ldp_dup_config_ref(struct ldpd_conf
*conf
, void **ref
)
1076 struct ldpd_conf
*xconf
;
1077 struct iface
*iface
, *xi
;
1078 struct tnbr
*tnbr
, *xt
;
1079 struct nbr_params
*nbrp
, *xn
;
1080 struct l2vpn
*l2vpn
, *xl
;
1081 struct l2vpn_if
*lif
, *xf
;
1082 struct l2vpn_pw
*pw
, *xp
;
1084 #define COPY(a, b) do { \
1085 a = calloc(1, sizeof(*a)); \
1089 if (ref && *ref == b) *ref = a; \
1093 RB_INIT(&xconf
->iface_tree
);
1094 RB_INIT(&xconf
->tnbr_tree
);
1095 RB_INIT(&xconf
->nbrp_tree
);
1096 RB_INIT(&xconf
->l2vpn_tree
);
1098 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1100 xi
->ipv4
.iface
= xi
;
1101 xi
->ipv6
.iface
= xi
;
1102 RB_INSERT(iface_head
, &xconf
->iface_tree
, xi
);
1104 RB_FOREACH(tnbr
, tnbr_head
, &conf
->tnbr_tree
) {
1106 RB_INSERT(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1108 RB_FOREACH(nbrp
, nbrp_head
, &conf
->nbrp_tree
) {
1110 RB_INSERT(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1112 RB_FOREACH(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
) {
1114 RB_INIT(&xl
->if_tree
);
1115 RB_INIT(&xl
->pw_tree
);
1116 RB_INIT(&xl
->pw_inactive_tree
);
1117 RB_INSERT(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1119 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1122 RB_INSERT(l2vpn_if_head
, &xl
->if_tree
, xf
);
1124 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1127 RB_INSERT(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1129 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1132 RB_INSERT(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1141 ldp_dup_config(struct ldpd_conf
*conf
)
1143 return ldp_dup_config_ref(conf
, NULL
);
1147 ldp_clear_config(struct ldpd_conf
*xconf
)
1149 struct iface
*iface
;
1151 struct nbr_params
*nbrp
;
1152 struct l2vpn
*l2vpn
;
1154 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1155 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1158 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1159 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1162 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1163 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1166 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1167 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1175 merge_config_ref(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1177 merge_global(conf
, xconf
);
1178 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1179 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1180 merge_ifaces(conf
, xconf
, ref
);
1181 merge_tnbrs(conf
, xconf
, ref
);
1182 merge_nbrps(conf
, xconf
, ref
);
1183 merge_l2vpns(conf
, xconf
, ref
);
1184 if (ref
&& *ref
== xconf
)
1190 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1192 merge_config_ref(conf
, xconf
, NULL
);
1196 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1198 /* change of router-id requires resetting all neighborships */
1199 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1200 if (ldpd_process
== PROC_LDP_ENGINE
) {
1201 ldpe_reset_nbrs(AF_UNSPEC
);
1202 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1203 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1204 if_update_all(AF_UNSPEC
);
1205 tnbr_update_all(AF_UNSPEC
);
1208 conf
->rtr_id
= xconf
->rtr_id
;
1211 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1212 conf
->lhello_interval
= xconf
->lhello_interval
;
1213 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1214 conf
->thello_interval
= xconf
->thello_interval
;
1216 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1217 if (ldpd_process
== PROC_LDP_ENGINE
)
1218 ldpe_reset_ds_nbrs();
1219 conf
->trans_pref
= xconf
->trans_pref
;
1222 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1223 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1224 if (ldpd_process
== PROC_LDP_ENGINE
)
1225 ldpe_reset_ds_nbrs();
1228 conf
->flags
= xconf
->flags
;
1232 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1234 int stop_init_backoff
= 0;
1235 int remove_dynamic_tnbrs
= 0;
1236 int change_egress_label
= 0;
1237 int reset_nbrs_ipv4
= 0;
1239 int update_sockets
= 0;
1242 if (af_conf
->keepalive
!= xa
->keepalive
) {
1243 af_conf
->keepalive
= xa
->keepalive
;
1244 stop_init_backoff
= 1;
1246 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1247 af_conf
->lhello_interval
= xa
->lhello_interval
;
1248 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1249 af_conf
->thello_interval
= xa
->thello_interval
;
1252 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1253 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1254 remove_dynamic_tnbrs
= 1;
1255 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1256 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1258 /* need to set/unset IPV6_MINHOPCOUNT */
1261 /* for LDPv4 just resetting the neighbors is enough */
1262 reset_nbrs_ipv4
= 1;
1264 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1265 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1266 change_egress_label
= 1;
1267 af_conf
->flags
= xa
->flags
;
1269 /* update the transport address */
1270 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1271 af_conf
->trans_addr
= xa
->trans_addr
;
1276 if (strcmp(af_conf
->acl_label_advertise_to
,
1277 xa
->acl_label_advertise_to
) ||
1278 strcmp(af_conf
->acl_label_advertise_for
,
1279 xa
->acl_label_advertise_for
) ||
1280 strcmp(af_conf
->acl_label_accept_from
,
1281 xa
->acl_label_accept_from
) ||
1282 strcmp(af_conf
->acl_label_accept_for
,
1283 xa
->acl_label_accept_for
))
1285 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1286 remove_dynamic_tnbrs
= 1;
1287 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1288 change_egress_label
= 1;
1289 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1290 sizeof(af_conf
->acl_thello_accept_from
));
1291 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1292 sizeof(af_conf
->acl_label_allocate_for
));
1293 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1294 sizeof(af_conf
->acl_label_advertise_to
));
1295 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1296 sizeof(af_conf
->acl_label_advertise_for
));
1297 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1298 sizeof(af_conf
->acl_label_accept_from
));
1299 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1300 sizeof(af_conf
->acl_label_accept_for
));
1301 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1302 sizeof(af_conf
->acl_label_expnull_for
));
1304 /* apply the new configuration */
1305 switch (ldpd_process
) {
1306 case PROC_LDE_ENGINE
:
1307 if (change_egress_label
)
1308 lde_change_egress_label(af
);
1310 case PROC_LDP_ENGINE
:
1311 if (stop_init_backoff
)
1312 ldpe_stop_init_backoff(af
);
1313 if (remove_dynamic_tnbrs
)
1314 ldpe_remove_dynamic_tnbrs(af
);
1316 ldpe_reset_nbrs(AF_UNSPEC
);
1317 else if (reset_nbrs_ipv4
)
1318 ldpe_reset_nbrs(AF_INET
);
1321 if (update_sockets
&& iev_ldpe
)
1322 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1329 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1331 struct iface
*iface
, *itmp
, *xi
;
1333 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1334 /* find deleted interfaces */
1335 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1336 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1338 switch (ldpd_process
) {
1339 case PROC_LDE_ENGINE
:
1341 case PROC_LDP_ENGINE
:
1351 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1352 /* find new interfaces */
1353 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1354 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1355 RB_INSERT(iface_head
, &conf
->iface_tree
, xi
);
1357 if (ldpd_process
== PROC_MAIN
) {
1358 QOBJ_REG (xi
, iface
);
1359 /* resend addresses to activate new interfaces */
1360 kif_redistribute(xi
->name
);
1365 /* update existing interfaces */
1366 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1367 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1368 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1369 if (ref
&& *ref
== xi
)
1376 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1378 if (ia
->enabled
!= xi
->enabled
) {
1379 ia
->enabled
= xi
->enabled
;
1380 if (ldpd_process
== PROC_LDP_ENGINE
)
1381 ldp_if_update(ia
->iface
, ia
->af
);
1383 ia
->hello_holdtime
= xi
->hello_holdtime
;
1384 ia
->hello_interval
= xi
->hello_interval
;
1388 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1390 struct tnbr
*tnbr
, *ttmp
, *xt
;
1392 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1393 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1396 /* find deleted tnbrs */
1397 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1398 switch (ldpd_process
) {
1399 case PROC_LDE_ENGINE
:
1400 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1403 case PROC_LDP_ENGINE
:
1404 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1405 tnbr_check(conf
, tnbr
);
1408 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1415 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1416 /* find new tnbrs */
1417 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1418 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1419 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, xt
);
1421 switch (ldpd_process
) {
1422 case PROC_LDE_ENGINE
:
1424 case PROC_LDP_ENGINE
:
1428 QOBJ_REG (xt
, tnbr
);
1434 /* update existing tnbrs */
1435 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1436 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1437 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1438 if (ref
&& *ref
== xt
)
1445 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1447 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1451 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1452 /* find deleted nbrps */
1453 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1454 switch (ldpd_process
) {
1455 case PROC_LDE_ENGINE
:
1457 case PROC_LDP_ENGINE
:
1458 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1460 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1465 (ldp_af_global_get(&global
,
1466 nbr
->af
))->ldp_session_socket
,
1467 nbr
->af
, &nbr
->raddr
, NULL
);
1469 nbr
->auth
.method
= AUTH_NONE
;
1470 if (nbr_session_active_role(nbr
))
1471 nbr_establish_connection(nbr
);
1478 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1482 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1483 /* find new nbrps */
1484 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1485 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1486 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, xn
);
1488 switch (ldpd_process
) {
1489 case PROC_LDE_ENGINE
:
1491 case PROC_LDP_ENGINE
:
1492 nbr
= nbr_find_ldpid(xn
->lsr_id
.s_addr
);
1494 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1495 nbr
->auth
.method
= xn
->auth
.method
;
1497 if (pfkey_establish(nbr
, xn
) == -1)
1498 fatalx("pfkey setup failed");
1501 (ldp_af_global_get(&global
,
1502 nbr
->af
))->ldp_session_socket
,
1503 nbr
->af
, &nbr
->raddr
,
1506 if (nbr_session_active_role(nbr
))
1507 nbr_establish_connection(nbr
);
1511 QOBJ_REG (xn
, nbr_params
);
1517 /* update existing nbrps */
1518 if (nbrp
->flags
!= xn
->flags
||
1519 nbrp
->keepalive
!= xn
->keepalive
||
1520 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1521 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1522 nbrp
->auth
.method
!= xn
->auth
.method
||
1523 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
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 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1533 sizeof(nbrp
->auth
.md5key
));
1534 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1535 nbrp
->flags
= xn
->flags
;
1537 if (ldpd_process
== PROC_LDP_ENGINE
) {
1538 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1539 if (nbr
&& nbrp_changed
) {
1540 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1543 nbr
->auth
.method
= nbrp
->auth
.method
;
1544 if (pfkey_establish(nbr
, nbrp
) == -1)
1545 fatalx("pfkey setup failed");
1547 nbr
->auth
.method
= nbrp
->auth
.method
;
1548 sock_set_md5sig((ldp_af_global_get(&global
,
1549 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1550 &nbr
->raddr
, nbrp
->auth
.md5key
);
1552 if (nbr_session_active_role(nbr
))
1553 nbr_establish_connection(nbr
);
1556 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1557 if (ref
&& *ref
== xn
)
1564 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1566 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1567 struct l2vpn_if
*lif
;
1568 struct l2vpn_pw
*pw
;
1570 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1571 /* find deleted l2vpns */
1572 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1573 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1575 switch (ldpd_process
) {
1576 case PROC_LDE_ENGINE
:
1579 case PROC_LDP_ENGINE
:
1580 ldpe_l2vpn_exit(l2vpn
);
1583 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1585 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1587 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1595 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1596 /* find new l2vpns */
1597 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1598 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1599 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, xl
);
1601 switch (ldpd_process
) {
1602 case PROC_LDE_ENGINE
:
1605 case PROC_LDP_ENGINE
:
1606 ldpe_l2vpn_init(xl
);
1609 QOBJ_REG (xl
, l2vpn
);
1615 /* update existing l2vpns */
1616 merge_l2vpn(conf
, l2vpn
, xl
, ref
);
1617 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1618 if (ref
&& *ref
== xl
)
1625 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
, void **ref
)
1627 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1628 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1630 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1631 struct l2vpn_pw_head pw_aux_list
;
1632 int previous_pw_type
, previous_mtu
;
1634 previous_pw_type
= l2vpn
->pw_type
;
1635 previous_mtu
= l2vpn
->mtu
;
1637 /* merge intefaces */
1638 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1639 /* find deleted interfaces */
1640 if ((xf
= l2vpn_if_find_name(xl
, lif
->ifname
)) == NULL
) {
1641 if (ldpd_process
== PROC_MAIN
)
1643 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1647 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1648 /* find new interfaces */
1649 if ((lif
= l2vpn_if_find_name(l2vpn
, xf
->ifname
)) == NULL
) {
1650 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1651 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, xf
);
1653 if (ldpd_process
== PROC_MAIN
)
1654 QOBJ_REG (xf
, l2vpn_if
);
1658 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1659 if (ref
&& *ref
== xf
)
1664 /* merge active pseudowires */
1665 RB_INIT(&pw_aux_list
);
1666 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1667 /* find deleted active pseudowires */
1668 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1669 switch (ldpd_process
) {
1670 case PROC_LDE_ENGINE
:
1673 case PROC_LDP_ENGINE
:
1674 ldpe_l2vpn_pw_exit(pw
);
1681 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1685 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1686 /* find new active pseudowires */
1687 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1688 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1689 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, xp
);
1692 switch (ldpd_process
) {
1693 case PROC_LDE_ENGINE
:
1696 case PROC_LDP_ENGINE
:
1697 ldpe_l2vpn_pw_init(xp
);
1700 QOBJ_REG (xp
, l2vpn_pw
);
1706 /* update existing active pseudowire */
1707 if (pw
->af
!= xp
->af
||
1708 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1713 /* changes that require a session restart */
1714 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1715 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1720 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1721 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1722 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1723 reinstall_pwfec
= 1;
1725 reinstall_pwfec
= 0;
1727 /* check if the pseudowire should be disabled */
1728 if (xp
->lsr_id
.s_addr
== INADDR_ANY
|| xp
->pwid
== 0) {
1731 reinstall_pwfec
= 0;
1733 switch (ldpd_process
) {
1734 case PROC_LDE_ENGINE
:
1737 case PROC_LDP_ENGINE
:
1738 ldpe_l2vpn_pw_exit(pw
);
1744 /* remove from active list */
1745 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1746 RB_INSERT(l2vpn_pw_head
, &pw_aux_list
, pw
);
1749 if (ldpd_process
== PROC_LDP_ENGINE
) {
1751 ldpe_l2vpn_pw_exit(pw
);
1753 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1754 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1755 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1758 if (ldpd_process
== PROC_LDE_ENGINE
&&
1759 !reset_nbr
&& reinstall_pwfec
)
1761 pw
->lsr_id
= xp
->lsr_id
;
1763 pw
->addr
= xp
->addr
;
1764 pw
->pwid
= xp
->pwid
;
1765 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1766 pw
->ifindex
= xp
->ifindex
;
1767 if (xp
->flags
& F_PW_CWORD_CONF
)
1768 pw
->flags
|= F_PW_CWORD_CONF
;
1770 pw
->flags
&= ~F_PW_CWORD_CONF
;
1771 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1772 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1774 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1775 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1776 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1778 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1779 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1780 ldpe_l2vpn_pw_init(pw
);
1781 if (ldpd_process
== PROC_LDE_ENGINE
&&
1782 !reset_nbr
&& reinstall_pwfec
) {
1783 l2vpn
->pw_type
= xl
->pw_type
;
1784 l2vpn
->mtu
= xl
->mtu
;
1786 l2vpn
->pw_type
= previous_pw_type
;
1787 l2vpn
->mtu
= previous_mtu
;
1790 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1791 if (ref
&& *ref
== xp
)
1796 /* merge inactive pseudowires */
1797 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1798 /* find deleted inactive pseudowires */
1799 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1800 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1801 if (ldpd_process
== PROC_MAIN
)
1806 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1807 /* find new inactive pseudowires */
1808 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1809 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1810 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, xp
);
1812 if (ldpd_process
== PROC_MAIN
)
1813 QOBJ_REG (xp
, l2vpn_pw
);
1817 /* update existing inactive pseudowire */
1818 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1820 pw
->addr
= xp
->addr
;
1821 pw
->pwid
= xp
->pwid
;
1822 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1823 pw
->ifindex
= xp
->ifindex
;
1824 pw
->flags
= xp
->flags
;
1826 /* check if the pseudowire should be activated */
1827 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0) {
1828 /* remove from inactive list */
1829 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1830 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1832 switch (ldpd_process
) {
1833 case PROC_LDE_ENGINE
:
1836 case PROC_LDP_ENGINE
:
1837 ldpe_l2vpn_pw_init(pw
);
1844 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1845 if (ref
&& *ref
== xp
)
1850 /* insert pseudowires that were disabled in the inactive list */
1851 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &pw_aux_list
, ptmp
) {
1852 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1853 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1856 l2vpn
->pw_type
= xl
->pw_type
;
1857 l2vpn
->mtu
= xl
->mtu
;
1858 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1859 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1863 config_new_empty(void)
1865 struct ldpd_conf
*xconf
;
1867 xconf
= calloc(1, sizeof(*xconf
));
1871 RB_INIT(&xconf
->iface_tree
);
1872 RB_INIT(&xconf
->tnbr_tree
);
1873 RB_INIT(&xconf
->nbrp_tree
);
1874 RB_INIT(&xconf
->l2vpn_tree
);
1880 config_clear(struct ldpd_conf
*conf
)
1882 struct ldpd_conf
*xconf
;
1885 * Merge current config with an empty config, this will deactivate
1886 * and deallocate all the interfaces, pseudowires and so on. Before
1887 * merging, copy the router-id and other variables to avoid some
1888 * unnecessary operations, like trying to reset the neighborships.
1890 xconf
= config_new_empty();
1891 xconf
->ipv4
= conf
->ipv4
;
1892 xconf
->ipv6
= conf
->ipv6
;
1893 xconf
->rtr_id
= conf
->rtr_id
;
1894 xconf
->trans_pref
= conf
->trans_pref
;
1895 xconf
->flags
= conf
->flags
;
1896 merge_config(conf
, xconf
);