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
*);
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_conf
*ldpd_conf
, *vty_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
;
93 static struct frr_daemon_info ldpd_di
;
96 static zebra_capabilities_t _caps_p
[] =
102 struct zebra_privs_t ldpd_privs
=
104 #if defined(FRR_USER) && defined(FRR_GROUP)
108 #if defined(VTY_GROUP)
109 .vty_group
= VTY_GROUP
,
112 .cap_num_p
= array_size(_caps_p
),
116 /* CTL Socket path */
117 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
120 #define OPTION_CTLSOCK 1001
121 static struct option longopts
[] =
123 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
124 { "instance", required_argument
, NULL
, 'n'},
128 /* SIGHUP handler. */
132 log_info("SIGHUP received");
135 ldp_config_reset_main(vty_conf
);
136 ldp_config_reset_l2vpns(vty_conf
);
138 /* read configuration file without applying any changes */
140 vty_read_config(ldpd_di
.config_file
, config_default
);
144 * Apply the new configuration all at once, this way merge_config()
145 * will be the least disruptive as possible.
147 ldp_reload(vty_conf
);
150 /* SIGINT / SIGTERM handler. */
154 log_info("SIGINT received");
158 /* SIGUSR1 handler. */
165 static struct quagga_signal_t ldp_signals
[] =
185 FRR_DAEMON_INFO(ldpd
, LDP
,
186 .vty_port
= LDP_VTY_PORT
,
188 .proghelp
= "Implementation of the LDP protocol.",
190 .signals
= ldp_signals
,
191 .n_signals
= array_size(ldp_signals
),
193 .privs
= &ldpd_privs
,
197 main(int argc
, char *argv
[])
200 int lflag
= 0, eflag
= 0;
201 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
202 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
203 char *ctl_sock_custom_path
= NULL
;
205 const char *user
= NULL
;
206 const char *group
= NULL
;
207 u_short instance
= 0;
208 const char *instance_char
= NULL
;
210 ldpd_process
= PROC_MAIN
;
212 saved_argv0
= argv
[0];
213 if (saved_argv0
== NULL
)
214 saved_argv0
= (char *)"ldpd";
216 frr_preinit(&ldpd_di
, argc
, argv
);
217 frr_opt_add("LEn:", longopts
,
218 " --ctl_socket Override ctl socket path\n"
219 "-n, --instance Instance id\n");
224 opt
= frr_getopt(argc
, argv
, NULL
);
233 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
239 * LDPD_SOCKET configured as relative path
240 * during config? Should really never happen for
243 ctl_sock_name
= (char *)LDPD_SOCKET
;
244 ctl_sock_custom_path
= optarg
;
245 strlcpy(ctl_sock_path
, ctl_sock_custom_path
,
246 sizeof(ctl_sock_path
));
247 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
248 strlcat(ctl_sock_path
, ctl_sock_name
,
249 sizeof(ctl_sock_path
));
252 instance
= atoi(optarg
);
253 instance_char
= optarg
;
269 user
= ldpd_privs
.user
;
270 group
= ldpd_privs
.group
;
274 if (argc
> 0 || (lflag
&& eflag
))
277 /* check for root privileges */
278 if (geteuid() != 0) {
280 perror(ldpd_di
.progname
);
285 lde(user
, group
, instance
);
287 ldpe(user
, group
, ctl_sock_path
);
289 openzlog(ldpd_di
.progname
, "LDP", 0,
290 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
292 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
294 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
295 pipe_parent2ldpe_sync
) == -1)
297 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
299 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
300 pipe_parent2lde_sync
) == -1)
302 sock_set_nonblock(pipe_parent2ldpe
[0]);
303 sock_set_cloexec(pipe_parent2ldpe
[0]);
304 sock_set_nonblock(pipe_parent2ldpe
[1]);
305 sock_set_cloexec(pipe_parent2ldpe
[1]);
306 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
307 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
308 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
309 sock_set_nonblock(pipe_parent2lde
[0]);
310 sock_set_cloexec(pipe_parent2lde
[0]);
311 sock_set_nonblock(pipe_parent2lde
[1]);
312 sock_set_cloexec(pipe_parent2lde
[1]);
313 sock_set_nonblock(pipe_parent2lde_sync
[0]);
314 sock_set_cloexec(pipe_parent2lde_sync
[0]);
315 sock_set_cloexec(pipe_parent2lde_sync
[1]);
318 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
319 pipe_parent2lde
[1], pipe_parent2lde_sync
[1],
320 user
, group
, ctl_sock_custom_path
, instance_char
);
321 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
322 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1],
323 user
, group
, ctl_sock_custom_path
, instance_char
);
325 /* drop privileges */
326 zprivs_init(&ldpd_privs
);
328 /* setup signal handler */
329 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
332 master
= thread_master_create();
336 vty_config_lockless();
341 ldp_zebra_init(master
);
343 /* create base configuration with sane defaults */
344 ldpd_conf
= config_new_empty();
345 ldp_config_reset_main(ldpd_conf
);
348 * Create vty_conf as a duplicate of the main configuration. All
349 * configuration requests (e.g. CLI) act on vty_conf and then call
350 * ldp_reload() to merge the changes into ldpd_conf.
352 vty_conf
= config_new_empty();
353 ldp_config_reset_main(vty_conf
);
354 QOBJ_REG(vty_conf
, ldpd_conf
);
356 /* read configuration file and daemonize */
359 /* setup pipes to children */
360 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
361 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
362 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
363 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
365 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
366 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
367 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
368 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
369 iev_ldpe
->handler_write
= ldp_write_handler
;
371 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
372 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
373 iev_ldpe_sync
->ev_read
= thread_add_read(master
,
374 iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
);
375 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
377 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
378 iev_lde
->handler_read
= main_dispatch_lde
;
379 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
380 iev_lde
, iev_lde
->ibuf
.fd
);
381 iev_lde
->handler_write
= ldp_write_handler
;
383 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
384 iev_lde_sync
->handler_read
= main_dispatch_lde
;
385 iev_lde_sync
->ev_read
= thread_add_read(master
,
386 iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
);
387 iev_lde_sync
->handler_write
= ldp_write_handler
;
389 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
390 fatal("could not establish imsg links");
391 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
393 main_imsg_send_config(ldpd_conf
);
395 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
396 main_imsg_send_net_sockets(AF_INET
);
397 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
398 main_imsg_send_net_sockets(AF_INET6
);
413 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
414 close(iev_ldpe
->ibuf
.fd
);
415 msgbuf_clear(&iev_lde
->ibuf
.w
);
416 close(iev_lde
->ibuf
.fd
);
418 config_clear(ldpd_conf
);
420 ldp_config_reset_main(vty_conf
);
421 ldp_config_reset_l2vpns(vty_conf
);
422 QOBJ_UNREG(vty_conf
);
425 log_debug("waiting for children to terminate");
429 if (errno
!= EINTR
&& errno
!= ECHILD
)
431 } else if (WIFSIGNALED(status
))
432 log_warnx("%s terminated; signal %d",
433 (pid
== lde_pid
) ? "label decision engine" :
434 "ldp engine", WTERMSIG(status
));
435 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
440 log_info("terminating");
447 zprivs_terminate(&ldpd_privs
);
448 thread_master_free(master
);
455 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
,
456 const char *user
, const char *group
, const char *ctl_sock_custom_path
,
457 const char *instance
)
463 switch (pid
= fork()) {
465 fatal("cannot fork");
474 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
475 fatal("cannot setup imsg async fd");
476 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
477 fatal("cannot setup imsg sync fd");
479 argv
[argc
++] = argv0
;
482 fatalx("Can not start main process");
483 case PROC_LDE_ENGINE
:
484 argv
[argc
++] = (char *)"-L";
486 case PROC_LDP_ENGINE
:
487 argv
[argc
++] = (char *)"-E";
491 argv
[argc
++] = (char *)"-u";
492 argv
[argc
++] = (char *)user
;
495 argv
[argc
++] = (char *)"-g";
496 argv
[argc
++] = (char *)group
;
498 if (ctl_sock_custom_path
) {
499 argv
[argc
++] = (char *)"--ctl_socket";
500 argv
[argc
++] = (char *)ctl_sock_custom_path
;
502 /* zclient serv path */
503 #ifdef HAVE_TCP_ZEBRA
505 argv
[argc
++] = (char *)"-z";
506 argv
[argc
++] = (char *)zclient_serv_path_get();
510 argv
[argc
++] = (char *)"-n";
511 argv
[argc
++] = (char *)instance
;
522 main_dispatch_ldpe(struct thread
*thread
)
524 struct imsgev
*iev
= THREAD_ARG(thread
);
525 struct imsgbuf
*ibuf
= &iev
->ibuf
;
533 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
534 fatal("imsg_read error");
535 if (n
== 0) /* connection closed */
539 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
545 switch (imsg
.hdr
.type
) {
547 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
549 case IMSG_REQUEST_SOCKETS
:
551 main_imsg_send_net_sockets(af
);
554 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
555 sizeof(struct acl_check
))
556 fatalx("IMSG_ACL_CHECK imsg with wrong len");
557 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
560 log_debug("%s: error handling imsg %d", __func__
,
569 /* this pipe is dead, so remove the event handlers and exit */
570 THREAD_READ_OFF(iev
->ev_read
);
571 THREAD_WRITE_OFF(iev
->ev_write
);
576 kill(lde_pid
, SIGTERM
);
584 main_dispatch_lde(struct thread
*thread
)
586 struct imsgev
*iev
= THREAD_ARG(thread
);
587 struct imsgbuf
*ibuf
= &iev
->ibuf
;
594 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
595 fatal("imsg_read error");
596 if (n
== 0) /* connection closed */
600 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
606 switch (imsg
.hdr
.type
) {
608 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
610 case IMSG_KLABEL_CHANGE
:
611 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
612 sizeof(struct kroute
))
613 fatalx("invalid size of IMSG_KLABEL_CHANGE");
614 if (kr_change(imsg
.data
))
615 log_warnx("%s: error changing route", __func__
);
617 case IMSG_KLABEL_DELETE
:
618 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
619 sizeof(struct kroute
))
620 fatalx("invalid size of IMSG_KLABEL_DELETE");
621 if (kr_delete(imsg
.data
))
622 log_warnx("%s: error deleting route", __func__
);
624 case IMSG_KPWLABEL_CHANGE
:
625 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
627 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
628 if (kmpw_set(imsg
.data
))
629 log_warnx("%s: error changing pseudowire",
632 case IMSG_KPWLABEL_DELETE
:
633 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
635 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
636 if (kmpw_unset(imsg
.data
))
637 log_warnx("%s: error unsetting pseudowire",
641 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
642 sizeof(struct acl_check
))
643 fatalx("IMSG_ACL_CHECK imsg with wrong len");
644 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
647 log_debug("%s: error handling imsg %d", __func__
,
656 /* this pipe is dead, so remove the event handlers and exit */
657 THREAD_READ_OFF(iev
->ev_read
);
658 THREAD_WRITE_OFF(iev
->ev_write
);
663 kill(ldpe_pid
, SIGTERM
);
671 ldp_write_handler(struct thread
*thread
)
673 struct imsgev
*iev
= THREAD_ARG(thread
);
674 struct imsgbuf
*ibuf
= &iev
->ibuf
;
677 iev
->ev_write
= NULL
;
679 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
680 fatal("msgbuf_write");
682 /* this pipe is dead, so remove the event handlers */
683 THREAD_READ_OFF(iev
->ev_read
);
684 THREAD_WRITE_OFF(iev
->ev_write
);
694 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
696 if (iev_ldpe
== NULL
)
698 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
702 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
704 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
708 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
710 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
712 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
714 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
720 imsg_event_add(struct imsgev
*iev
)
722 if (iev
->handler_read
)
723 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
726 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
727 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
732 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
733 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
737 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
738 pid
, fd
, data
, datalen
)) != -1)
744 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
746 ibuf_close(&eb
->wbuf
, buf
);
751 evbuf_event_add(struct evbuf
*eb
)
754 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
759 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
762 msgbuf_init(&eb
->wbuf
);
764 eb
->handler
= handler
;
769 evbuf_clear(struct evbuf
*eb
)
771 THREAD_WRITE_OFF(eb
->ev
);
772 msgbuf_clear(&eb
->wbuf
);
777 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
779 int pipe_ldpe2lde
[2];
781 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
783 sock_set_nonblock(pipe_ldpe2lde
[0]);
784 sock_set_nonblock(pipe_ldpe2lde
[1]);
786 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
789 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
797 main_imsg_send_net_sockets(int af
)
799 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
802 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
803 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
804 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
805 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
809 main_imsg_send_net_socket(int af
, enum socket_type type
)
813 fd
= ldp_create_socket(af
, type
);
815 log_warnx("%s: failed to create %s socket for address-family "
816 "%s", __func__
, socket_name(type
), af_name(af
));
820 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
825 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
826 union ldpd_addr
*addr
, uint8_t prefixlen
)
830 struct acl_check acl_check
;
832 if (acl_name
[0] == '\0')
833 return FILTER_PERMIT
;
836 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
838 acl_check
.addr
= *addr
;
839 acl_check
.prefixlen
= prefixlen
;
841 /* send (blocking) */
842 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
844 imsg_flush(&iev
->ibuf
);
846 /* receive (blocking) and parse result */
847 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
848 fatal("imsg_read error");
849 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
851 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
852 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
853 fatalx("ldp_acl_request: invalid response");
855 return (*((int *)imsg
.data
));
859 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
861 struct access_list
*alist
;
862 struct prefix prefix
;
865 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
867 result
= FILTER_DENY
;
869 prefix
.family
= acl_check
->af
;
870 switch (prefix
.family
) {
872 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
875 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
878 fatalx("ldp_acl_reply: unknown af");
880 prefix
.prefixlen
= acl_check
->prefixlen
;
881 result
= access_list_apply(alist
, &prefix
);
884 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
888 struct ldpd_af_conf
*
889 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
893 return (&xconf
->ipv4
);
895 return (&xconf
->ipv6
);
897 fatalx("ldp_af_conf_get: unknown af");
901 struct ldpd_af_global
*
902 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
906 return (&xglobal
->ipv4
);
908 return (&xglobal
->ipv6
);
910 fatalx("ldp_af_global_get: unknown af");
915 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
917 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
918 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
922 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
924 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
925 return (xconf
->rtr_id
.s_addr
);
927 return (global
.rtr_id
.s_addr
);
931 main_imsg_send_config(struct ldpd_conf
*xconf
)
935 struct nbr_params
*nbrp
;
937 struct l2vpn_if
*lif
;
940 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
941 sizeof(*xconf
)) == -1)
944 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
945 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
946 sizeof(*iface
)) == -1)
950 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
951 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
952 sizeof(*tnbr
)) == -1)
956 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
957 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
958 sizeof(*nbrp
)) == -1)
962 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
963 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
964 sizeof(*l2vpn
)) == -1)
967 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
968 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
972 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
973 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
977 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
978 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
984 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
991 ldp_reload(struct ldpd_conf
*xconf
)
996 ldp_config_normalize(xconf
);
998 if (main_imsg_send_config(xconf
) == -1)
1001 merge_config(ldpd_conf
, xconf
);
1007 ldp_config_normalize(struct ldpd_conf
*xconf
)
1009 struct iface
*iface
, *itmp
;
1010 struct nbr_params
*nbrp
, *ntmp
;
1011 struct l2vpn
*l2vpn
;
1012 struct l2vpn_pw
*pw
, *ptmp
;
1014 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1015 ldp_config_reset_main(xconf
);
1017 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1018 ldp_config_reset_af(xconf
, AF_INET
);
1019 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1020 ldp_config_reset_af(xconf
, AF_INET6
);
1022 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1023 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1027 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1031 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1032 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1034 if (nbrp
->auth
.method
!= AUTH_NONE
)
1038 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1043 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1044 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1045 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1047 pw
->addr
.v4
= pw
->lsr_id
;
1050 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1052 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1053 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1055 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1057 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1059 pw
->addr
.v4
= pw
->lsr_id
;
1062 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1064 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1065 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1071 ldp_config_reset_main(struct ldpd_conf
*conf
)
1073 struct iface
*iface
;
1074 struct nbr_params
*nbrp
;
1076 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1078 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1082 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1084 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1088 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1089 ldp_config_reset_af(conf
, AF_INET
);
1090 ldp_config_reset_af(conf
, AF_INET6
);
1091 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1092 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1093 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1094 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1095 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1100 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1102 struct ldpd_af_conf
*af_conf
;
1103 struct iface
*iface
;
1104 struct iface_af
*ia
;
1105 struct tnbr
*tnbr
, *ttmp
;
1107 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1108 ia
= iface_af_get(iface
, af
);
1112 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1117 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1121 af_conf
= ldp_af_conf_get(conf
, af
);
1122 af_conf
->keepalive
= 180;
1123 af_conf
->lhello_holdtime
= 0;
1124 af_conf
->lhello_interval
= 0;
1125 af_conf
->thello_holdtime
= 0;
1126 af_conf
->thello_interval
= 0;
1127 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1132 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1134 struct l2vpn
*l2vpn
;
1135 struct l2vpn_if
*lif
;
1136 struct l2vpn_pw
*pw
;
1138 while ((l2vpn
= RB_ROOT(&conf
->l2vpn_tree
)) != NULL
) {
1139 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1141 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1144 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1146 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1149 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1151 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1155 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1161 ldp_clear_config(struct ldpd_conf
*xconf
)
1163 struct iface
*iface
;
1165 struct nbr_params
*nbrp
;
1166 struct l2vpn
*l2vpn
;
1168 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1169 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1172 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1173 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1176 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1177 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1180 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1181 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1188 #define COPY(a, b) do { \
1189 a = malloc(sizeof(*a)); \
1196 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1198 merge_global(conf
, xconf
);
1199 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1200 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1201 merge_ifaces(conf
, xconf
);
1202 merge_tnbrs(conf
, xconf
);
1203 merge_nbrps(conf
, xconf
);
1204 merge_l2vpns(conf
, xconf
);
1208 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1210 /* change of router-id requires resetting all neighborships */
1211 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1212 if (ldpd_process
== PROC_LDP_ENGINE
) {
1213 ldpe_reset_nbrs(AF_UNSPEC
);
1214 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1215 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1216 if_update_all(AF_UNSPEC
);
1217 tnbr_update_all(AF_UNSPEC
);
1220 conf
->rtr_id
= xconf
->rtr_id
;
1223 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1224 conf
->lhello_interval
= xconf
->lhello_interval
;
1225 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1226 conf
->thello_interval
= xconf
->thello_interval
;
1228 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1229 if (ldpd_process
== PROC_LDP_ENGINE
)
1230 ldpe_reset_ds_nbrs();
1231 conf
->trans_pref
= xconf
->trans_pref
;
1234 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1235 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1236 if (ldpd_process
== PROC_LDP_ENGINE
)
1237 ldpe_reset_ds_nbrs();
1240 conf
->flags
= xconf
->flags
;
1244 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1246 int stop_init_backoff
= 0;
1247 int remove_dynamic_tnbrs
= 0;
1248 int change_egress_label
= 0;
1249 int reset_nbrs_ipv4
= 0;
1251 int update_sockets
= 0;
1254 if (af_conf
->keepalive
!= xa
->keepalive
) {
1255 af_conf
->keepalive
= xa
->keepalive
;
1256 stop_init_backoff
= 1;
1258 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1259 af_conf
->lhello_interval
= xa
->lhello_interval
;
1260 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1261 af_conf
->thello_interval
= xa
->thello_interval
;
1264 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1265 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1266 remove_dynamic_tnbrs
= 1;
1267 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1268 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1270 /* need to set/unset IPV6_MINHOPCOUNT */
1273 /* for LDPv4 just resetting the neighbors is enough */
1274 reset_nbrs_ipv4
= 1;
1276 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1277 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1278 change_egress_label
= 1;
1279 af_conf
->flags
= xa
->flags
;
1281 /* update the transport address */
1282 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1283 af_conf
->trans_addr
= xa
->trans_addr
;
1288 if (strcmp(af_conf
->acl_label_advertise_to
,
1289 xa
->acl_label_advertise_to
) ||
1290 strcmp(af_conf
->acl_label_advertise_for
,
1291 xa
->acl_label_advertise_for
) ||
1292 strcmp(af_conf
->acl_label_accept_from
,
1293 xa
->acl_label_accept_from
) ||
1294 strcmp(af_conf
->acl_label_accept_for
,
1295 xa
->acl_label_accept_for
))
1297 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1298 remove_dynamic_tnbrs
= 1;
1299 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1300 change_egress_label
= 1;
1301 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1302 sizeof(af_conf
->acl_thello_accept_from
));
1303 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1304 sizeof(af_conf
->acl_label_allocate_for
));
1305 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1306 sizeof(af_conf
->acl_label_advertise_to
));
1307 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1308 sizeof(af_conf
->acl_label_advertise_for
));
1309 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1310 sizeof(af_conf
->acl_label_accept_from
));
1311 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1312 sizeof(af_conf
->acl_label_accept_for
));
1313 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1314 sizeof(af_conf
->acl_label_expnull_for
));
1316 /* apply the new configuration */
1317 switch (ldpd_process
) {
1318 case PROC_LDE_ENGINE
:
1319 if (change_egress_label
)
1320 lde_change_egress_label(af
);
1322 case PROC_LDP_ENGINE
:
1323 if (stop_init_backoff
)
1324 ldpe_stop_init_backoff(af
);
1325 if (remove_dynamic_tnbrs
)
1326 ldpe_remove_dynamic_tnbrs(af
);
1328 ldpe_reset_nbrs(AF_UNSPEC
);
1329 else if (reset_nbrs_ipv4
)
1330 ldpe_reset_nbrs(AF_INET
);
1333 if (update_sockets
&& iev_ldpe
)
1334 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1341 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1343 struct iface
*iface
, *itmp
, *xi
;
1345 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1346 /* find deleted interfaces */
1347 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1348 switch (ldpd_process
) {
1349 case PROC_LDP_ENGINE
:
1350 ldpe_if_exit(iface
);
1352 case PROC_LDE_ENGINE
:
1356 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1360 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1361 /* find new interfaces */
1362 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1364 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1366 switch (ldpd_process
) {
1367 case PROC_LDP_ENGINE
:
1368 ldpe_if_init(iface
);
1370 case PROC_LDE_ENGINE
:
1373 /* resend addresses to activate new interfaces */
1374 kif_redistribute(iface
->name
);
1380 /* update existing interfaces */
1381 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1382 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1387 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1389 if (ia
->enabled
!= xi
->enabled
) {
1390 ia
->enabled
= xi
->enabled
;
1391 if (ldpd_process
== PROC_LDP_ENGINE
)
1392 ldp_if_update(ia
->iface
, ia
->af
);
1394 ia
->hello_holdtime
= xi
->hello_holdtime
;
1395 ia
->hello_interval
= xi
->hello_interval
;
1399 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1401 struct tnbr
*tnbr
, *ttmp
, *xt
;
1403 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1404 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1407 /* find deleted tnbrs */
1408 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1409 switch (ldpd_process
) {
1410 case PROC_LDP_ENGINE
:
1411 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1412 tnbr_check(conf
, tnbr
);
1414 case PROC_LDE_ENGINE
:
1416 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1422 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1423 /* find new tnbrs */
1424 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1426 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1428 switch (ldpd_process
) {
1429 case PROC_LDP_ENGINE
:
1432 case PROC_LDE_ENGINE
:
1439 /* update existing tnbrs */
1440 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1441 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1446 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
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_LDP_ENGINE
:
1457 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1459 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1464 (ldp_af_global_get(&global
,
1465 nbr
->af
))->ldp_session_socket
,
1466 nbr
->af
, &nbr
->raddr
, NULL
);
1468 nbr
->auth
.method
= AUTH_NONE
;
1469 if (nbr_session_active_role(nbr
))
1470 nbr_establish_connection(nbr
);
1473 case PROC_LDE_ENGINE
:
1477 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1481 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1482 /* find new nbrps */
1483 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1485 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1487 switch (ldpd_process
) {
1488 case PROC_LDP_ENGINE
:
1489 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1491 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1492 nbr
->auth
.method
= nbrp
->auth
.method
;
1494 if (pfkey_establish(nbr
, nbrp
) == -1)
1495 fatalx("pfkey setup failed");
1498 (ldp_af_global_get(&global
,
1499 nbr
->af
))->ldp_session_socket
,
1500 nbr
->af
, &nbr
->raddr
,
1503 if (nbr_session_active_role(nbr
))
1504 nbr_establish_connection(nbr
);
1507 case PROC_LDE_ENGINE
:
1514 /* update existing nbrps */
1515 if (nbrp
->flags
!= xn
->flags
||
1516 nbrp
->keepalive
!= xn
->keepalive
||
1517 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1518 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1519 nbrp
->auth
.method
!= xn
->auth
.method
||
1520 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1525 nbrp
->keepalive
= xn
->keepalive
;
1526 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1527 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1528 nbrp
->auth
.method
= xn
->auth
.method
;
1529 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1530 sizeof(nbrp
->auth
.md5key
));
1531 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1532 nbrp
->flags
= xn
->flags
;
1534 if (ldpd_process
== PROC_LDP_ENGINE
) {
1535 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1536 if (nbr
&& nbrp_changed
) {
1537 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1540 nbr
->auth
.method
= nbrp
->auth
.method
;
1541 if (pfkey_establish(nbr
, nbrp
) == -1)
1542 fatalx("pfkey setup failed");
1544 nbr
->auth
.method
= nbrp
->auth
.method
;
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
);
1557 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1559 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1561 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1562 /* find deleted l2vpns */
1563 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1564 switch (ldpd_process
) {
1565 case PROC_LDE_ENGINE
:
1568 case PROC_LDP_ENGINE
:
1569 ldpe_l2vpn_exit(l2vpn
);
1574 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1578 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1579 /* find new l2vpns */
1580 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1582 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1583 RB_INIT(&l2vpn
->if_tree
);
1584 RB_INIT(&l2vpn
->pw_tree
);
1585 RB_INIT(&l2vpn
->pw_inactive_tree
);
1587 switch (ldpd_process
) {
1588 case PROC_LDE_ENGINE
:
1591 case PROC_LDP_ENGINE
:
1592 ldpe_l2vpn_init(l2vpn
);
1599 /* update existing l2vpns */
1600 merge_l2vpn(conf
, l2vpn
, xl
);
1605 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1607 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1608 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1610 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1611 int previous_pw_type
, previous_mtu
;
1613 previous_pw_type
= l2vpn
->pw_type
;
1614 previous_mtu
= l2vpn
->mtu
;
1616 /* merge intefaces */
1617 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1618 /* find deleted interfaces */
1619 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1620 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1624 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1625 /* find new interfaces */
1626 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1628 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1631 switch (ldpd_process
) {
1632 case PROC_LDP_ENGINE
:
1633 case PROC_LDE_ENGINE
:
1636 kif_redistribute(lif
->ifname
);
1642 /* merge active pseudowires */
1643 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1644 /* find deleted active pseudowires */
1645 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1646 switch (ldpd_process
) {
1647 case PROC_LDE_ENGINE
:
1650 case PROC_LDP_ENGINE
:
1651 ldpe_l2vpn_pw_exit(pw
);
1657 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1661 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1662 /* find new active pseudowires */
1663 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1665 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1668 switch (ldpd_process
) {
1669 case PROC_LDE_ENGINE
:
1672 case PROC_LDP_ENGINE
:
1673 ldpe_l2vpn_pw_init(pw
);
1676 kif_redistribute(pw
->ifname
);
1682 /* update existing active pseudowire */
1683 if (pw
->af
!= xp
->af
||
1684 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1689 /* changes that require a session restart */
1690 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1691 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1696 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1697 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1698 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1699 reinstall_pwfec
= 1;
1701 reinstall_pwfec
= 0;
1703 if (ldpd_process
== PROC_LDP_ENGINE
) {
1705 ldpe_l2vpn_pw_exit(pw
);
1707 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1708 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1709 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1712 if (ldpd_process
== PROC_LDE_ENGINE
&&
1713 !reset_nbr
&& reinstall_pwfec
)
1715 pw
->lsr_id
= xp
->lsr_id
;
1717 pw
->addr
= xp
->addr
;
1718 pw
->pwid
= xp
->pwid
;
1719 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1720 pw
->ifindex
= xp
->ifindex
;
1721 if (xp
->flags
& F_PW_CWORD_CONF
)
1722 pw
->flags
|= F_PW_CWORD_CONF
;
1724 pw
->flags
&= ~F_PW_CWORD_CONF
;
1725 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1726 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1728 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1729 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1730 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1732 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1733 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1734 ldpe_l2vpn_pw_init(pw
);
1735 if (ldpd_process
== PROC_LDE_ENGINE
&&
1736 !reset_nbr
&& reinstall_pwfec
) {
1737 l2vpn
->pw_type
= xl
->pw_type
;
1738 l2vpn
->mtu
= xl
->mtu
;
1740 l2vpn
->pw_type
= previous_pw_type
;
1741 l2vpn
->mtu
= previous_mtu
;
1745 /* merge inactive pseudowires */
1746 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1747 /* find deleted inactive pseudowires */
1748 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1749 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1753 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1754 /* find new inactive pseudowires */
1755 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1757 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1760 switch (ldpd_process
) {
1761 case PROC_LDE_ENGINE
:
1762 case PROC_LDP_ENGINE
:
1765 kif_redistribute(pw
->ifname
);
1771 /* update existing inactive pseudowire */
1772 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1774 pw
->addr
= xp
->addr
;
1775 pw
->pwid
= xp
->pwid
;
1776 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1777 pw
->ifindex
= xp
->ifindex
;
1778 pw
->flags
= xp
->flags
;
1781 l2vpn
->pw_type
= xl
->pw_type
;
1782 l2vpn
->mtu
= xl
->mtu
;
1783 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1784 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1788 config_new_empty(void)
1790 struct ldpd_conf
*xconf
;
1792 xconf
= calloc(1, sizeof(*xconf
));
1796 RB_INIT(&xconf
->iface_tree
);
1797 RB_INIT(&xconf
->tnbr_tree
);
1798 RB_INIT(&xconf
->nbrp_tree
);
1799 RB_INIT(&xconf
->l2vpn_tree
);
1805 config_clear(struct ldpd_conf
*conf
)
1807 struct ldpd_conf
*xconf
;
1810 * Merge current config with an empty config, this will deactivate
1811 * and deallocate all the interfaces, pseudowires and so on. Before
1812 * merging, copy the router-id and other variables to avoid some
1813 * unnecessary operations, like trying to reset the neighborships.
1815 xconf
= config_new_empty();
1816 xconf
->ipv4
= conf
->ipv4
;
1817 xconf
->ipv6
= conf
->ipv6
;
1818 xconf
->rtr_id
= conf
->rtr_id
;
1819 xconf
->trans_pref
= conf
->trans_pref
;
1820 xconf
->flags
= conf
->flags
;
1821 merge_config(conf
, xconf
);