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
);
267 openzlog(ldpd_di
.progname
, "LDP", 0,
268 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
271 lde(user
, group
, instance
);
273 ldpe(user
, group
, ctl_sock_path
);
275 master
= thread_master_create();
278 vty_config_lockless ();
285 /* Get configuration file. */
286 ldpd_conf
= config_new_empty();
287 ldp_config_reset_main(ldpd_conf
, NULL
);
291 QOBJ_REG (ldpd_conf
, ldpd_conf
);
293 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
295 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
296 pipe_parent2ldpe_sync
) == -1)
298 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
300 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
301 pipe_parent2lde_sync
) == -1)
303 sock_set_nonblock(pipe_parent2ldpe
[0]);
304 sock_set_cloexec(pipe_parent2ldpe
[0]);
305 sock_set_nonblock(pipe_parent2ldpe
[1]);
306 sock_set_cloexec(pipe_parent2ldpe
[1]);
307 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
308 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
309 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
310 sock_set_nonblock(pipe_parent2lde
[0]);
311 sock_set_cloexec(pipe_parent2lde
[0]);
312 sock_set_nonblock(pipe_parent2lde
[1]);
313 sock_set_cloexec(pipe_parent2lde
[1]);
314 sock_set_nonblock(pipe_parent2lde_sync
[0]);
315 sock_set_cloexec(pipe_parent2lde_sync
[0]);
316 sock_set_cloexec(pipe_parent2lde_sync
[1]);
319 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
320 pipe_parent2lde
[1], pipe_parent2lde_sync
[1],
321 user
, group
, ctl_sock_custom_path
, instance_char
);
322 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
323 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1],
324 user
, group
, ctl_sock_custom_path
, instance_char
);
326 /* drop privileges */
327 zprivs_init(&ldpd_privs
);
329 /* setup signal handler */
330 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
333 ldp_zebra_init(master
);
335 /* setup pipes to children */
336 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
337 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
338 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
339 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
341 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
342 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
343 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
344 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
345 iev_ldpe
->handler_write
= ldp_write_handler
;
347 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
348 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
349 iev_ldpe_sync
->ev_read
= thread_add_read(master
,
350 iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
);
351 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
353 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
354 iev_lde
->handler_read
= main_dispatch_lde
;
355 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
356 iev_lde
, iev_lde
->ibuf
.fd
);
357 iev_lde
->handler_write
= ldp_write_handler
;
359 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
360 iev_lde_sync
->handler_read
= main_dispatch_lde
;
361 iev_lde_sync
->ev_read
= thread_add_read(master
,
362 iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
);
363 iev_lde_sync
->handler_write
= ldp_write_handler
;
365 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
366 fatal("could not establish imsg links");
367 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
369 main_imsg_send_config(ldpd_conf
);
371 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
372 main_imsg_send_net_sockets(AF_INET
);
373 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
374 main_imsg_send_net_sockets(AF_INET6
);
389 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
390 close(iev_ldpe
->ibuf
.fd
);
391 msgbuf_clear(&iev_lde
->ibuf
.w
);
392 close(iev_lde
->ibuf
.fd
);
394 config_clear(ldpd_conf
);
396 log_debug("waiting for children to terminate");
400 if (errno
!= EINTR
&& errno
!= ECHILD
)
402 } else if (WIFSIGNALED(status
))
403 log_warnx("%s terminated; signal %d",
404 (pid
== lde_pid
) ? "label decision engine" :
405 "ldp engine", WTERMSIG(status
));
406 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
411 log_info("terminating");
418 zprivs_terminate(&ldpd_privs
);
419 thread_master_free(master
);
426 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
,
427 const char *user
, const char *group
, const char *ctl_sock_custom_path
,
428 const char *instance
)
434 switch (pid
= fork()) {
436 fatal("cannot fork");
445 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
446 fatal("cannot setup imsg async fd");
447 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
448 fatal("cannot setup imsg sync fd");
450 argv
[argc
++] = argv0
;
453 fatalx("Can not start main process");
454 case PROC_LDE_ENGINE
:
455 argv
[argc
++] = (char *)"-L";
457 case PROC_LDP_ENGINE
:
458 argv
[argc
++] = (char *)"-E";
462 argv
[argc
++] = (char *)"-u";
463 argv
[argc
++] = (char *)user
;
466 argv
[argc
++] = (char *)"-g";
467 argv
[argc
++] = (char *)group
;
469 if (ctl_sock_custom_path
) {
470 argv
[argc
++] = (char *)"--ctl_socket";
471 argv
[argc
++] = (char *)ctl_sock_custom_path
;
473 /* zclient serv path */
474 argv
[argc
++] = (char *)"-z";
475 argv
[argc
++] = (char *)zclient_serv_path_get();
478 argv
[argc
++] = (char *)"-n";
479 argv
[argc
++] = (char *)instance
;
490 main_dispatch_ldpe(struct thread
*thread
)
492 struct imsgev
*iev
= THREAD_ARG(thread
);
493 struct imsgbuf
*ibuf
= &iev
->ibuf
;
501 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
502 fatal("imsg_read error");
503 if (n
== 0) /* connection closed */
507 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
513 switch (imsg
.hdr
.type
) {
515 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
517 case IMSG_REQUEST_SOCKETS
:
519 main_imsg_send_net_sockets(af
);
522 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
523 sizeof(struct acl_check
))
524 fatalx("IMSG_ACL_CHECK imsg with wrong len");
525 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
528 log_debug("%s: error handling imsg %d", __func__
,
537 /* this pipe is dead, so remove the event handlers and exit */
538 THREAD_READ_OFF(iev
->ev_read
);
539 THREAD_WRITE_OFF(iev
->ev_write
);
544 kill(lde_pid
, SIGTERM
);
552 main_dispatch_lde(struct thread
*thread
)
554 struct imsgev
*iev
= THREAD_ARG(thread
);
555 struct imsgbuf
*ibuf
= &iev
->ibuf
;
562 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
563 fatal("imsg_read error");
564 if (n
== 0) /* connection closed */
568 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
574 switch (imsg
.hdr
.type
) {
576 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
578 case IMSG_KLABEL_CHANGE
:
579 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
580 sizeof(struct kroute
))
581 fatalx("invalid size of IMSG_KLABEL_CHANGE");
582 if (kr_change(imsg
.data
))
583 log_warnx("%s: error changing route", __func__
);
585 case IMSG_KLABEL_DELETE
:
586 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
587 sizeof(struct kroute
))
588 fatalx("invalid size of IMSG_KLABEL_DELETE");
589 if (kr_delete(imsg
.data
))
590 log_warnx("%s: error deleting route", __func__
);
592 case IMSG_KPWLABEL_CHANGE
:
593 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
595 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
596 if (kmpw_set(imsg
.data
))
597 log_warnx("%s: error changing pseudowire",
600 case IMSG_KPWLABEL_DELETE
:
601 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
603 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
604 if (kmpw_unset(imsg
.data
))
605 log_warnx("%s: error unsetting pseudowire",
609 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
610 sizeof(struct acl_check
))
611 fatalx("IMSG_ACL_CHECK imsg with wrong len");
612 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
615 log_debug("%s: error handling imsg %d", __func__
,
624 /* this pipe is dead, so remove the event handlers and exit */
625 THREAD_READ_OFF(iev
->ev_read
);
626 THREAD_WRITE_OFF(iev
->ev_write
);
631 kill(ldpe_pid
, SIGTERM
);
639 ldp_write_handler(struct thread
*thread
)
641 struct imsgev
*iev
= THREAD_ARG(thread
);
642 struct imsgbuf
*ibuf
= &iev
->ibuf
;
645 iev
->ev_write
= NULL
;
647 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
648 fatal("msgbuf_write");
650 /* this pipe is dead, so remove the event handlers */
651 THREAD_READ_OFF(iev
->ev_read
);
652 THREAD_WRITE_OFF(iev
->ev_write
);
662 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
664 if (iev_ldpe
== NULL
)
666 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
670 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
672 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
676 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
678 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
680 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
682 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
688 imsg_event_add(struct imsgev
*iev
)
690 if (iev
->handler_read
)
691 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
694 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
695 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
700 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
701 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
705 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
706 pid
, fd
, data
, datalen
)) != -1)
712 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
714 ibuf_close(&eb
->wbuf
, buf
);
719 evbuf_event_add(struct evbuf
*eb
)
722 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
727 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
730 msgbuf_init(&eb
->wbuf
);
732 eb
->handler
= handler
;
737 evbuf_clear(struct evbuf
*eb
)
739 THREAD_WRITE_OFF(eb
->ev
);
740 msgbuf_clear(&eb
->wbuf
);
745 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
747 int pipe_ldpe2lde
[2];
749 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
751 sock_set_nonblock(pipe_ldpe2lde
[0]);
752 sock_set_nonblock(pipe_ldpe2lde
[1]);
754 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
757 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
765 main_imsg_send_net_sockets(int af
)
767 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
770 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
771 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
772 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
773 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
777 main_imsg_send_net_socket(int af
, enum socket_type type
)
781 fd
= ldp_create_socket(af
, type
);
783 log_warnx("%s: failed to create %s socket for address-family "
784 "%s", __func__
, socket_name(type
), af_name(af
));
788 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
793 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
794 union ldpd_addr
*addr
, uint8_t prefixlen
)
798 struct acl_check acl_check
;
800 if (acl_name
[0] == '\0')
801 return FILTER_PERMIT
;
804 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
806 acl_check
.addr
= *addr
;
807 acl_check
.prefixlen
= prefixlen
;
809 /* send (blocking) */
810 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
812 imsg_flush(&iev
->ibuf
);
814 /* receive (blocking) and parse result */
815 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
816 fatal("imsg_read error");
817 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
819 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
820 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
821 fatalx("ldp_acl_request: invalid response");
823 return (*((int *)imsg
.data
));
827 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
829 struct access_list
*alist
;
830 struct prefix prefix
;
833 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
835 result
= FILTER_DENY
;
837 prefix
.family
= acl_check
->af
;
838 switch (prefix
.family
) {
840 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
843 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
846 fatalx("ldp_acl_reply: unknown af");
848 prefix
.prefixlen
= acl_check
->prefixlen
;
849 result
= access_list_apply(alist
, &prefix
);
852 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
856 struct ldpd_af_conf
*
857 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
861 return (&xconf
->ipv4
);
863 return (&xconf
->ipv6
);
865 fatalx("ldp_af_conf_get: unknown af");
869 struct ldpd_af_global
*
870 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
874 return (&xglobal
->ipv4
);
876 return (&xglobal
->ipv6
);
878 fatalx("ldp_af_global_get: unknown af");
883 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
885 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
886 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
890 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
892 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
893 return (xconf
->rtr_id
.s_addr
);
895 return (global
.rtr_id
.s_addr
);
899 main_imsg_send_config(struct ldpd_conf
*xconf
)
903 struct nbr_params
*nbrp
;
905 struct l2vpn_if
*lif
;
908 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
909 sizeof(*xconf
)) == -1)
912 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
913 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
914 sizeof(*iface
)) == -1)
918 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
919 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
920 sizeof(*tnbr
)) == -1)
924 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
925 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
926 sizeof(*nbrp
)) == -1)
930 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
931 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
932 sizeof(*l2vpn
)) == -1)
935 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
936 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
940 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
941 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
945 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
946 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
952 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
959 ldp_reload_ref(struct ldpd_conf
*xconf
, void **ref
)
961 ldp_config_normalize(xconf
, ref
);
963 if (main_imsg_send_config(xconf
) == -1)
966 merge_config_ref(ldpd_conf
, xconf
, ref
);
972 ldp_reload(struct ldpd_conf
*xconf
)
974 return ldp_reload_ref(xconf
, NULL
);
978 ldp_config_normalize(struct ldpd_conf
*xconf
, void **ref
)
983 if (!(xconf
->flags
& F_LDPD_ENABLED
))
984 ldp_config_reset_main(xconf
, ref
);
986 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
987 ldp_config_reset_af(xconf
, AF_INET
, ref
);
988 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
989 ldp_config_reset_af(xconf
, AF_INET6
, ref
);
992 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
993 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
994 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
998 pw
->addr
.v4
= pw
->lsr_id
;
1000 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1001 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
1005 pw
->addr
.v4
= pw
->lsr_id
;
1011 ldp_config_reset_main(struct ldpd_conf
*conf
, void **ref
)
1013 struct iface
*iface
;
1014 struct nbr_params
*nbrp
;
1016 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1017 if (ref
&& *ref
== iface
)
1019 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1023 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1024 if (ref
&& *ref
== nbrp
)
1026 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1030 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1031 ldp_config_reset_af(conf
, AF_INET
, ref
);
1032 ldp_config_reset_af(conf
, AF_INET6
, ref
);
1033 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1034 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1035 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1036 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1037 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1042 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
, void **ref
)
1044 struct ldpd_af_conf
*af_conf
;
1045 struct iface
*iface
;
1046 struct iface_af
*ia
;
1047 struct tnbr
*tnbr
, *ttmp
;
1049 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1050 ia
= iface_af_get(iface
, af
);
1054 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1058 if (ref
&& *ref
== tnbr
)
1060 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1064 af_conf
= ldp_af_conf_get(conf
, af
);
1065 af_conf
->keepalive
= 180;
1066 af_conf
->lhello_holdtime
= 0;
1067 af_conf
->lhello_interval
= 0;
1068 af_conf
->thello_holdtime
= 0;
1069 af_conf
->thello_interval
= 0;
1070 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1075 ldp_dup_config_ref(struct ldpd_conf
*conf
, void **ref
)
1077 struct ldpd_conf
*xconf
;
1078 struct iface
*iface
, *xi
;
1079 struct tnbr
*tnbr
, *xt
;
1080 struct nbr_params
*nbrp
, *xn
;
1081 struct l2vpn
*l2vpn
, *xl
;
1082 struct l2vpn_if
*lif
, *xf
;
1083 struct l2vpn_pw
*pw
, *xp
;
1085 #define COPY(a, b) do { \
1086 a = calloc(1, sizeof(*a)); \
1090 if (ref && *ref == b) *ref = a; \
1094 RB_INIT(&xconf
->iface_tree
);
1095 RB_INIT(&xconf
->tnbr_tree
);
1096 RB_INIT(&xconf
->nbrp_tree
);
1097 RB_INIT(&xconf
->l2vpn_tree
);
1099 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1101 xi
->ipv4
.iface
= xi
;
1102 xi
->ipv6
.iface
= xi
;
1103 RB_INSERT(iface_head
, &xconf
->iface_tree
, xi
);
1105 RB_FOREACH(tnbr
, tnbr_head
, &conf
->tnbr_tree
) {
1107 RB_INSERT(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1109 RB_FOREACH(nbrp
, nbrp_head
, &conf
->nbrp_tree
) {
1111 RB_INSERT(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1113 RB_FOREACH(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
) {
1115 RB_INIT(&xl
->if_tree
);
1116 RB_INIT(&xl
->pw_tree
);
1117 RB_INIT(&xl
->pw_inactive_tree
);
1118 RB_INSERT(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1120 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
1123 RB_INSERT(l2vpn_if_head
, &xl
->if_tree
, xf
);
1125 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
1128 RB_INSERT(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1130 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
1133 RB_INSERT(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1142 ldp_dup_config(struct ldpd_conf
*conf
)
1144 return ldp_dup_config_ref(conf
, NULL
);
1148 ldp_clear_config(struct ldpd_conf
*xconf
)
1150 struct iface
*iface
;
1152 struct nbr_params
*nbrp
;
1153 struct l2vpn
*l2vpn
;
1155 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1156 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1159 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1160 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1163 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1164 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1167 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1168 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1176 merge_config_ref(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1178 merge_global(conf
, xconf
);
1179 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1180 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1181 merge_ifaces(conf
, xconf
, ref
);
1182 merge_tnbrs(conf
, xconf
, ref
);
1183 merge_nbrps(conf
, xconf
, ref
);
1184 merge_l2vpns(conf
, xconf
, ref
);
1185 if (ref
&& *ref
== xconf
)
1191 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1193 merge_config_ref(conf
, xconf
, NULL
);
1197 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1199 /* change of router-id requires resetting all neighborships */
1200 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1201 if (ldpd_process
== PROC_LDP_ENGINE
) {
1202 ldpe_reset_nbrs(AF_UNSPEC
);
1203 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1204 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1205 if_update_all(AF_UNSPEC
);
1206 tnbr_update_all(AF_UNSPEC
);
1209 conf
->rtr_id
= xconf
->rtr_id
;
1212 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1213 conf
->lhello_interval
= xconf
->lhello_interval
;
1214 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1215 conf
->thello_interval
= xconf
->thello_interval
;
1217 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1218 if (ldpd_process
== PROC_LDP_ENGINE
)
1219 ldpe_reset_ds_nbrs();
1220 conf
->trans_pref
= xconf
->trans_pref
;
1223 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1224 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1225 if (ldpd_process
== PROC_LDP_ENGINE
)
1226 ldpe_reset_ds_nbrs();
1229 conf
->flags
= xconf
->flags
;
1233 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1235 int stop_init_backoff
= 0;
1236 int remove_dynamic_tnbrs
= 0;
1237 int change_egress_label
= 0;
1238 int reset_nbrs_ipv4
= 0;
1240 int update_sockets
= 0;
1243 if (af_conf
->keepalive
!= xa
->keepalive
) {
1244 af_conf
->keepalive
= xa
->keepalive
;
1245 stop_init_backoff
= 1;
1247 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1248 af_conf
->lhello_interval
= xa
->lhello_interval
;
1249 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1250 af_conf
->thello_interval
= xa
->thello_interval
;
1253 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1254 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1255 remove_dynamic_tnbrs
= 1;
1256 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1257 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1259 /* need to set/unset IPV6_MINHOPCOUNT */
1262 /* for LDPv4 just resetting the neighbors is enough */
1263 reset_nbrs_ipv4
= 1;
1265 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1266 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1267 change_egress_label
= 1;
1268 af_conf
->flags
= xa
->flags
;
1270 /* update the transport address */
1271 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1272 af_conf
->trans_addr
= xa
->trans_addr
;
1277 if (strcmp(af_conf
->acl_label_advertise_to
,
1278 xa
->acl_label_advertise_to
) ||
1279 strcmp(af_conf
->acl_label_advertise_for
,
1280 xa
->acl_label_advertise_for
) ||
1281 strcmp(af_conf
->acl_label_accept_from
,
1282 xa
->acl_label_accept_from
) ||
1283 strcmp(af_conf
->acl_label_accept_for
,
1284 xa
->acl_label_accept_for
))
1286 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1287 remove_dynamic_tnbrs
= 1;
1288 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1289 change_egress_label
= 1;
1290 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1291 sizeof(af_conf
->acl_thello_accept_from
));
1292 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1293 sizeof(af_conf
->acl_label_allocate_for
));
1294 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1295 sizeof(af_conf
->acl_label_advertise_to
));
1296 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1297 sizeof(af_conf
->acl_label_advertise_for
));
1298 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1299 sizeof(af_conf
->acl_label_accept_from
));
1300 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1301 sizeof(af_conf
->acl_label_accept_for
));
1302 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1303 sizeof(af_conf
->acl_label_expnull_for
));
1305 /* apply the new configuration */
1306 switch (ldpd_process
) {
1307 case PROC_LDE_ENGINE
:
1308 if (change_egress_label
)
1309 lde_change_egress_label(af
);
1311 case PROC_LDP_ENGINE
:
1312 if (stop_init_backoff
)
1313 ldpe_stop_init_backoff(af
);
1314 if (remove_dynamic_tnbrs
)
1315 ldpe_remove_dynamic_tnbrs(af
);
1317 ldpe_reset_nbrs(AF_UNSPEC
);
1318 else if (reset_nbrs_ipv4
)
1319 ldpe_reset_nbrs(AF_INET
);
1322 if (update_sockets
&& iev_ldpe
)
1323 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1330 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1332 struct iface
*iface
, *itmp
, *xi
;
1334 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1335 /* find deleted interfaces */
1336 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1337 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1339 switch (ldpd_process
) {
1340 case PROC_LDE_ENGINE
:
1342 case PROC_LDP_ENGINE
:
1352 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1353 /* find new interfaces */
1354 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1355 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1356 RB_INSERT(iface_head
, &conf
->iface_tree
, xi
);
1358 if (ldpd_process
== PROC_MAIN
) {
1359 QOBJ_REG (xi
, iface
);
1360 /* resend addresses to activate new interfaces */
1361 kif_redistribute(xi
->name
);
1366 /* update existing interfaces */
1367 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1368 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1369 RB_REMOVE(iface_head
, &xconf
->iface_tree
, xi
);
1370 if (ref
&& *ref
== xi
)
1377 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1379 if (ia
->enabled
!= xi
->enabled
) {
1380 ia
->enabled
= xi
->enabled
;
1381 if (ldpd_process
== PROC_LDP_ENGINE
)
1382 ldp_if_update(ia
->iface
, ia
->af
);
1384 ia
->hello_holdtime
= xi
->hello_holdtime
;
1385 ia
->hello_interval
= xi
->hello_interval
;
1389 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1391 struct tnbr
*tnbr
, *ttmp
, *xt
;
1393 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1394 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1397 /* find deleted tnbrs */
1398 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1399 switch (ldpd_process
) {
1400 case PROC_LDE_ENGINE
:
1401 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1404 case PROC_LDP_ENGINE
:
1405 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1406 tnbr_check(conf
, tnbr
);
1409 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1416 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1417 /* find new tnbrs */
1418 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1419 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1420 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, xt
);
1422 switch (ldpd_process
) {
1423 case PROC_LDE_ENGINE
:
1425 case PROC_LDP_ENGINE
:
1429 QOBJ_REG (xt
, tnbr
);
1435 /* update existing tnbrs */
1436 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1437 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1438 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, xt
);
1439 if (ref
&& *ref
== xt
)
1446 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1448 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1452 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1453 /* find deleted nbrps */
1454 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1455 switch (ldpd_process
) {
1456 case PROC_LDE_ENGINE
:
1458 case PROC_LDP_ENGINE
:
1459 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1461 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1466 (ldp_af_global_get(&global
,
1467 nbr
->af
))->ldp_session_socket
,
1468 nbr
->af
, &nbr
->raddr
, NULL
);
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);
1496 if (pfkey_establish(nbr
, xn
) == -1)
1497 fatalx("pfkey setup failed");
1500 (ldp_af_global_get(&global
,
1501 nbr
->af
))->ldp_session_socket
,
1502 nbr
->af
, &nbr
->raddr
,
1505 if (nbr_session_active_role(nbr
))
1506 nbr_establish_connection(nbr
);
1510 QOBJ_REG (xn
, nbr_params
);
1516 /* update existing nbrps */
1517 if (nbrp
->flags
!= xn
->flags
||
1518 nbrp
->keepalive
!= xn
->keepalive
||
1519 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1520 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1521 nbrp
->auth
.method
!= xn
->auth
.method
||
1522 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1527 nbrp
->keepalive
= xn
->keepalive
;
1528 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1529 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1530 nbrp
->auth
.method
= xn
->auth
.method
;
1531 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1532 sizeof(nbrp
->auth
.md5key
));
1533 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1534 nbrp
->flags
= xn
->flags
;
1536 if (ldpd_process
== PROC_LDP_ENGINE
) {
1537 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1538 if (nbr
&& nbrp_changed
) {
1539 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1542 if (pfkey_establish(nbr
, nbrp
) == -1)
1543 fatalx("pfkey setup failed");
1545 sock_set_md5sig((ldp_af_global_get(&global
,
1546 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1547 &nbr
->raddr
, nbrp
->auth
.md5key
);
1549 if (nbr_session_active_role(nbr
))
1550 nbr_establish_connection(nbr
);
1553 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, xn
);
1554 if (ref
&& *ref
== xn
)
1561 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1563 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1564 struct l2vpn_if
*lif
;
1565 struct l2vpn_pw
*pw
;
1567 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1568 /* find deleted l2vpns */
1569 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1570 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1572 switch (ldpd_process
) {
1573 case PROC_LDE_ENGINE
:
1576 case PROC_LDP_ENGINE
:
1577 ldpe_l2vpn_exit(l2vpn
);
1580 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1582 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1584 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1592 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1593 /* find new l2vpns */
1594 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1595 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1596 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, xl
);
1598 switch (ldpd_process
) {
1599 case PROC_LDE_ENGINE
:
1602 case PROC_LDP_ENGINE
:
1603 ldpe_l2vpn_init(xl
);
1606 QOBJ_REG (xl
, l2vpn
);
1612 /* update existing l2vpns */
1613 merge_l2vpn(conf
, l2vpn
, xl
, ref
);
1614 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, xl
);
1615 if (ref
&& *ref
== xl
)
1622 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
, void **ref
)
1624 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1625 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1627 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1628 struct l2vpn_pw_head pw_aux_list
;
1629 int previous_pw_type
, previous_mtu
;
1631 previous_pw_type
= l2vpn
->pw_type
;
1632 previous_mtu
= l2vpn
->mtu
;
1634 /* merge intefaces */
1635 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1636 /* find deleted interfaces */
1637 if ((xf
= l2vpn_if_find_name(xl
, lif
->ifname
)) == NULL
) {
1638 if (ldpd_process
== PROC_MAIN
)
1640 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1644 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1645 /* find new interfaces */
1646 if ((lif
= l2vpn_if_find_name(l2vpn
, xf
->ifname
)) == NULL
) {
1647 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1648 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, xf
);
1650 if (ldpd_process
== PROC_MAIN
)
1651 QOBJ_REG (xf
, l2vpn_if
);
1655 RB_REMOVE(l2vpn_if_head
, &xl
->if_tree
, xf
);
1656 if (ref
&& *ref
== xf
)
1661 /* merge active pseudowires */
1662 RB_INIT(&pw_aux_list
);
1663 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1664 /* find deleted active pseudowires */
1665 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1666 switch (ldpd_process
) {
1667 case PROC_LDE_ENGINE
:
1670 case PROC_LDP_ENGINE
:
1671 ldpe_l2vpn_pw_exit(pw
);
1678 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1682 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1683 /* find new active pseudowires */
1684 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1685 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1686 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, xp
);
1689 switch (ldpd_process
) {
1690 case PROC_LDE_ENGINE
:
1693 case PROC_LDP_ENGINE
:
1694 ldpe_l2vpn_pw_init(xp
);
1697 QOBJ_REG (xp
, l2vpn_pw
);
1703 /* update existing active pseudowire */
1704 if (pw
->af
!= xp
->af
||
1705 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1710 /* changes that require a session restart */
1711 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1712 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1717 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1718 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1719 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1720 reinstall_pwfec
= 1;
1722 reinstall_pwfec
= 0;
1724 /* check if the pseudowire should be disabled */
1725 if (xp
->lsr_id
.s_addr
== INADDR_ANY
|| xp
->pwid
== 0) {
1728 reinstall_pwfec
= 0;
1730 switch (ldpd_process
) {
1731 case PROC_LDE_ENGINE
:
1734 case PROC_LDP_ENGINE
:
1735 ldpe_l2vpn_pw_exit(pw
);
1741 /* remove from active list */
1742 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1743 RB_INSERT(l2vpn_pw_head
, &pw_aux_list
, pw
);
1746 if (ldpd_process
== PROC_LDP_ENGINE
) {
1748 ldpe_l2vpn_pw_exit(pw
);
1750 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1751 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1752 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1755 if (ldpd_process
== PROC_LDE_ENGINE
&&
1756 !reset_nbr
&& reinstall_pwfec
)
1758 pw
->lsr_id
= xp
->lsr_id
;
1760 pw
->addr
= xp
->addr
;
1761 pw
->pwid
= xp
->pwid
;
1762 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1763 pw
->ifindex
= xp
->ifindex
;
1764 if (xp
->flags
& F_PW_CWORD_CONF
)
1765 pw
->flags
|= F_PW_CWORD_CONF
;
1767 pw
->flags
&= ~F_PW_CWORD_CONF
;
1768 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1769 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1771 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1772 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1773 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1775 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1776 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1777 ldpe_l2vpn_pw_init(pw
);
1778 if (ldpd_process
== PROC_LDE_ENGINE
&&
1779 !reset_nbr
&& reinstall_pwfec
) {
1780 l2vpn
->pw_type
= xl
->pw_type
;
1781 l2vpn
->mtu
= xl
->mtu
;
1783 l2vpn
->pw_type
= previous_pw_type
;
1784 l2vpn
->mtu
= previous_mtu
;
1787 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_tree
, xp
);
1788 if (ref
&& *ref
== xp
)
1793 /* merge inactive pseudowires */
1794 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1795 /* find deleted inactive pseudowires */
1796 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1797 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1798 if (ldpd_process
== PROC_MAIN
)
1803 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1804 /* find new inactive pseudowires */
1805 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1806 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1807 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, xp
);
1809 if (ldpd_process
== PROC_MAIN
)
1810 QOBJ_REG (xp
, l2vpn_pw
);
1814 /* update existing inactive pseudowire */
1815 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1817 pw
->addr
= xp
->addr
;
1818 pw
->pwid
= xp
->pwid
;
1819 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1820 pw
->ifindex
= xp
->ifindex
;
1821 pw
->flags
= xp
->flags
;
1823 /* check if the pseudowire should be activated */
1824 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0) {
1825 /* remove from inactive list */
1826 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1827 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1829 switch (ldpd_process
) {
1830 case PROC_LDE_ENGINE
:
1833 case PROC_LDP_ENGINE
:
1834 ldpe_l2vpn_pw_init(pw
);
1841 RB_REMOVE(l2vpn_pw_head
, &xl
->pw_inactive_tree
, xp
);
1842 if (ref
&& *ref
== xp
)
1847 /* insert pseudowires that were disabled in the inactive list */
1848 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &pw_aux_list
, ptmp
) {
1849 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1850 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1853 l2vpn
->pw_type
= xl
->pw_type
;
1854 l2vpn
->mtu
= xl
->mtu
;
1855 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1856 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1860 config_new_empty(void)
1862 struct ldpd_conf
*xconf
;
1864 xconf
= calloc(1, sizeof(*xconf
));
1868 RB_INIT(&xconf
->iface_tree
);
1869 RB_INIT(&xconf
->tnbr_tree
);
1870 RB_INIT(&xconf
->nbrp_tree
);
1871 RB_INIT(&xconf
->l2vpn_tree
);
1877 config_clear(struct ldpd_conf
*conf
)
1879 struct ldpd_conf
*xconf
;
1882 * Merge current config with an empty config, this will deactivate
1883 * and deallocate all the interfaces, pseudowires and so on. Before
1884 * merging, copy the router-id and other variables to avoid some
1885 * unnecessary operations, like trying to reset the neighborships.
1887 xconf
= config_new_empty();
1888 xconf
->ipv4
= conf
->ipv4
;
1889 xconf
->ipv6
= conf
->ipv6
;
1890 xconf
->rtr_id
= conf
->rtr_id
;
1891 xconf
->trans_pref
= conf
->trans_pref
;
1892 xconf
->flags
= conf
->flags
;
1893 merge_config(conf
, xconf
);
1894 if (ldpd_process
== PROC_MAIN
)