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 argv
[argc
++] = (char *)"-z";
504 argv
[argc
++] = (char *)zclient_serv_path_get();
507 argv
[argc
++] = (char *)"-n";
508 argv
[argc
++] = (char *)instance
;
519 main_dispatch_ldpe(struct thread
*thread
)
521 struct imsgev
*iev
= THREAD_ARG(thread
);
522 struct imsgbuf
*ibuf
= &iev
->ibuf
;
530 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
531 fatal("imsg_read error");
532 if (n
== 0) /* connection closed */
536 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
542 switch (imsg
.hdr
.type
) {
544 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
546 case IMSG_REQUEST_SOCKETS
:
548 main_imsg_send_net_sockets(af
);
551 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
552 sizeof(struct acl_check
))
553 fatalx("IMSG_ACL_CHECK imsg with wrong len");
554 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
557 log_debug("%s: error handling imsg %d", __func__
,
566 /* this pipe is dead, so remove the event handlers and exit */
567 THREAD_READ_OFF(iev
->ev_read
);
568 THREAD_WRITE_OFF(iev
->ev_write
);
573 kill(lde_pid
, SIGTERM
);
581 main_dispatch_lde(struct thread
*thread
)
583 struct imsgev
*iev
= THREAD_ARG(thread
);
584 struct imsgbuf
*ibuf
= &iev
->ibuf
;
591 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
592 fatal("imsg_read error");
593 if (n
== 0) /* connection closed */
597 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
603 switch (imsg
.hdr
.type
) {
605 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
607 case IMSG_KLABEL_CHANGE
:
608 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
609 sizeof(struct kroute
))
610 fatalx("invalid size of IMSG_KLABEL_CHANGE");
611 if (kr_change(imsg
.data
))
612 log_warnx("%s: error changing route", __func__
);
614 case IMSG_KLABEL_DELETE
:
615 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
616 sizeof(struct kroute
))
617 fatalx("invalid size of IMSG_KLABEL_DELETE");
618 if (kr_delete(imsg
.data
))
619 log_warnx("%s: error deleting route", __func__
);
621 case IMSG_KPWLABEL_CHANGE
:
622 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
624 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
625 if (kmpw_set(imsg
.data
))
626 log_warnx("%s: error changing pseudowire",
629 case IMSG_KPWLABEL_DELETE
:
630 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
632 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
633 if (kmpw_unset(imsg
.data
))
634 log_warnx("%s: error unsetting pseudowire",
638 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
639 sizeof(struct acl_check
))
640 fatalx("IMSG_ACL_CHECK imsg with wrong len");
641 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
644 log_debug("%s: error handling imsg %d", __func__
,
653 /* this pipe is dead, so remove the event handlers and exit */
654 THREAD_READ_OFF(iev
->ev_read
);
655 THREAD_WRITE_OFF(iev
->ev_write
);
660 kill(ldpe_pid
, SIGTERM
);
668 ldp_write_handler(struct thread
*thread
)
670 struct imsgev
*iev
= THREAD_ARG(thread
);
671 struct imsgbuf
*ibuf
= &iev
->ibuf
;
674 iev
->ev_write
= NULL
;
676 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
677 fatal("msgbuf_write");
679 /* this pipe is dead, so remove the event handlers */
680 THREAD_READ_OFF(iev
->ev_read
);
681 THREAD_WRITE_OFF(iev
->ev_write
);
691 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
693 if (iev_ldpe
== NULL
)
695 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
699 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
701 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
705 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
707 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
709 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
711 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
717 imsg_event_add(struct imsgev
*iev
)
719 if (iev
->handler_read
)
720 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
723 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
724 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
729 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
730 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
734 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
735 pid
, fd
, data
, datalen
)) != -1)
741 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
743 ibuf_close(&eb
->wbuf
, buf
);
748 evbuf_event_add(struct evbuf
*eb
)
751 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
756 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
759 msgbuf_init(&eb
->wbuf
);
761 eb
->handler
= handler
;
766 evbuf_clear(struct evbuf
*eb
)
768 THREAD_WRITE_OFF(eb
->ev
);
769 msgbuf_clear(&eb
->wbuf
);
774 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
776 int pipe_ldpe2lde
[2];
778 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
780 sock_set_nonblock(pipe_ldpe2lde
[0]);
781 sock_set_nonblock(pipe_ldpe2lde
[1]);
783 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
786 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
794 main_imsg_send_net_sockets(int af
)
796 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
799 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
800 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
801 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
802 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
806 main_imsg_send_net_socket(int af
, enum socket_type type
)
810 fd
= ldp_create_socket(af
, type
);
812 log_warnx("%s: failed to create %s socket for address-family "
813 "%s", __func__
, socket_name(type
), af_name(af
));
817 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
822 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
823 union ldpd_addr
*addr
, uint8_t prefixlen
)
827 struct acl_check acl_check
;
829 if (acl_name
[0] == '\0')
830 return FILTER_PERMIT
;
833 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
835 acl_check
.addr
= *addr
;
836 acl_check
.prefixlen
= prefixlen
;
838 /* send (blocking) */
839 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
841 imsg_flush(&iev
->ibuf
);
843 /* receive (blocking) and parse result */
844 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
845 fatal("imsg_read error");
846 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
848 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
849 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
850 fatalx("ldp_acl_request: invalid response");
852 return (*((int *)imsg
.data
));
856 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
858 struct access_list
*alist
;
859 struct prefix prefix
;
862 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
864 result
= FILTER_DENY
;
866 prefix
.family
= acl_check
->af
;
867 switch (prefix
.family
) {
869 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
872 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
875 fatalx("ldp_acl_reply: unknown af");
877 prefix
.prefixlen
= acl_check
->prefixlen
;
878 result
= access_list_apply(alist
, &prefix
);
881 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
885 struct ldpd_af_conf
*
886 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
890 return (&xconf
->ipv4
);
892 return (&xconf
->ipv6
);
894 fatalx("ldp_af_conf_get: unknown af");
898 struct ldpd_af_global
*
899 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
903 return (&xglobal
->ipv4
);
905 return (&xglobal
->ipv6
);
907 fatalx("ldp_af_global_get: unknown af");
912 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
914 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
915 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
919 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
921 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
922 return (xconf
->rtr_id
.s_addr
);
924 return (global
.rtr_id
.s_addr
);
928 main_imsg_send_config(struct ldpd_conf
*xconf
)
932 struct nbr_params
*nbrp
;
934 struct l2vpn_if
*lif
;
937 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
938 sizeof(*xconf
)) == -1)
941 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
942 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
943 sizeof(*iface
)) == -1)
947 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
948 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
949 sizeof(*tnbr
)) == -1)
953 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
954 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
955 sizeof(*nbrp
)) == -1)
959 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
960 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
961 sizeof(*l2vpn
)) == -1)
964 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
965 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
969 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
970 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
974 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
975 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
981 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
988 ldp_reload(struct ldpd_conf
*xconf
)
993 ldp_config_normalize(xconf
);
995 if (main_imsg_send_config(xconf
) == -1)
998 merge_config(ldpd_conf
, xconf
);
1004 ldp_config_normalize(struct ldpd_conf
*xconf
)
1006 struct iface
*iface
, *itmp
;
1007 struct nbr_params
*nbrp
, *ntmp
;
1008 struct l2vpn
*l2vpn
;
1009 struct l2vpn_pw
*pw
, *ptmp
;
1011 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1012 ldp_config_reset_main(xconf
);
1014 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1015 ldp_config_reset_af(xconf
, AF_INET
);
1016 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1017 ldp_config_reset_af(xconf
, AF_INET6
);
1019 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1020 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1024 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1028 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1029 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1031 if (nbrp
->auth
.method
!= AUTH_NONE
)
1035 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1040 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1041 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1042 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1044 pw
->addr
.v4
= pw
->lsr_id
;
1047 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1049 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1050 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1052 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1054 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1056 pw
->addr
.v4
= pw
->lsr_id
;
1059 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1061 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1062 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1068 ldp_config_reset_main(struct ldpd_conf
*conf
)
1070 struct iface
*iface
;
1071 struct nbr_params
*nbrp
;
1073 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1075 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1079 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1081 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1085 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1086 ldp_config_reset_af(conf
, AF_INET
);
1087 ldp_config_reset_af(conf
, AF_INET6
);
1088 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1089 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1090 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1091 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1092 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1097 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1099 struct ldpd_af_conf
*af_conf
;
1100 struct iface
*iface
;
1101 struct iface_af
*ia
;
1102 struct tnbr
*tnbr
, *ttmp
;
1104 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1105 ia
= iface_af_get(iface
, af
);
1109 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1114 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1118 af_conf
= ldp_af_conf_get(conf
, af
);
1119 af_conf
->keepalive
= 180;
1120 af_conf
->lhello_holdtime
= 0;
1121 af_conf
->lhello_interval
= 0;
1122 af_conf
->thello_holdtime
= 0;
1123 af_conf
->thello_interval
= 0;
1124 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1129 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1131 struct l2vpn
*l2vpn
;
1132 struct l2vpn_if
*lif
;
1133 struct l2vpn_pw
*pw
;
1135 while ((l2vpn
= RB_ROOT(&conf
->l2vpn_tree
)) != NULL
) {
1136 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1138 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1141 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1143 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1146 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1148 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1152 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1158 ldp_clear_config(struct ldpd_conf
*xconf
)
1160 struct iface
*iface
;
1162 struct nbr_params
*nbrp
;
1163 struct l2vpn
*l2vpn
;
1165 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1166 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1169 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1170 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1173 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1174 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1177 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1178 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1185 #define COPY(a, b) do { \
1186 a = malloc(sizeof(*a)); \
1193 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1195 merge_global(conf
, xconf
);
1196 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1197 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1198 merge_ifaces(conf
, xconf
);
1199 merge_tnbrs(conf
, xconf
);
1200 merge_nbrps(conf
, xconf
);
1201 merge_l2vpns(conf
, xconf
);
1205 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1207 /* change of router-id requires resetting all neighborships */
1208 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1209 if (ldpd_process
== PROC_LDP_ENGINE
) {
1210 ldpe_reset_nbrs(AF_UNSPEC
);
1211 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1212 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1213 if_update_all(AF_UNSPEC
);
1214 tnbr_update_all(AF_UNSPEC
);
1217 conf
->rtr_id
= xconf
->rtr_id
;
1220 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1221 conf
->lhello_interval
= xconf
->lhello_interval
;
1222 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1223 conf
->thello_interval
= xconf
->thello_interval
;
1225 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1226 if (ldpd_process
== PROC_LDP_ENGINE
)
1227 ldpe_reset_ds_nbrs();
1228 conf
->trans_pref
= xconf
->trans_pref
;
1231 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1232 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1233 if (ldpd_process
== PROC_LDP_ENGINE
)
1234 ldpe_reset_ds_nbrs();
1237 conf
->flags
= xconf
->flags
;
1241 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1243 int stop_init_backoff
= 0;
1244 int remove_dynamic_tnbrs
= 0;
1245 int change_egress_label
= 0;
1246 int reset_nbrs_ipv4
= 0;
1248 int update_sockets
= 0;
1251 if (af_conf
->keepalive
!= xa
->keepalive
) {
1252 af_conf
->keepalive
= xa
->keepalive
;
1253 stop_init_backoff
= 1;
1255 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1256 af_conf
->lhello_interval
= xa
->lhello_interval
;
1257 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1258 af_conf
->thello_interval
= xa
->thello_interval
;
1261 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1262 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1263 remove_dynamic_tnbrs
= 1;
1264 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1265 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1267 /* need to set/unset IPV6_MINHOPCOUNT */
1270 /* for LDPv4 just resetting the neighbors is enough */
1271 reset_nbrs_ipv4
= 1;
1273 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1274 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1275 change_egress_label
= 1;
1276 af_conf
->flags
= xa
->flags
;
1278 /* update the transport address */
1279 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1280 af_conf
->trans_addr
= xa
->trans_addr
;
1285 if (strcmp(af_conf
->acl_label_advertise_to
,
1286 xa
->acl_label_advertise_to
) ||
1287 strcmp(af_conf
->acl_label_advertise_for
,
1288 xa
->acl_label_advertise_for
) ||
1289 strcmp(af_conf
->acl_label_accept_from
,
1290 xa
->acl_label_accept_from
) ||
1291 strcmp(af_conf
->acl_label_accept_for
,
1292 xa
->acl_label_accept_for
))
1294 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1295 remove_dynamic_tnbrs
= 1;
1296 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1297 change_egress_label
= 1;
1298 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1299 sizeof(af_conf
->acl_thello_accept_from
));
1300 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1301 sizeof(af_conf
->acl_label_allocate_for
));
1302 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1303 sizeof(af_conf
->acl_label_advertise_to
));
1304 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1305 sizeof(af_conf
->acl_label_advertise_for
));
1306 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1307 sizeof(af_conf
->acl_label_accept_from
));
1308 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1309 sizeof(af_conf
->acl_label_accept_for
));
1310 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1311 sizeof(af_conf
->acl_label_expnull_for
));
1313 /* apply the new configuration */
1314 switch (ldpd_process
) {
1315 case PROC_LDE_ENGINE
:
1316 if (change_egress_label
)
1317 lde_change_egress_label(af
);
1319 case PROC_LDP_ENGINE
:
1320 if (stop_init_backoff
)
1321 ldpe_stop_init_backoff(af
);
1322 if (remove_dynamic_tnbrs
)
1323 ldpe_remove_dynamic_tnbrs(af
);
1325 ldpe_reset_nbrs(AF_UNSPEC
);
1326 else if (reset_nbrs_ipv4
)
1327 ldpe_reset_nbrs(AF_INET
);
1330 if (update_sockets
&& iev_ldpe
)
1331 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1338 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1340 struct iface
*iface
, *itmp
, *xi
;
1342 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1343 /* find deleted interfaces */
1344 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1345 switch (ldpd_process
) {
1346 case PROC_LDP_ENGINE
:
1347 ldpe_if_exit(iface
);
1349 case PROC_LDE_ENGINE
:
1353 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1357 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1358 /* find new interfaces */
1359 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1361 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1363 switch (ldpd_process
) {
1364 case PROC_LDP_ENGINE
:
1365 ldpe_if_init(iface
);
1367 case PROC_LDE_ENGINE
:
1370 /* resend addresses to activate new interfaces */
1371 kif_redistribute(iface
->name
);
1377 /* update existing interfaces */
1378 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1379 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1384 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1386 if (ia
->enabled
!= xi
->enabled
) {
1387 ia
->enabled
= xi
->enabled
;
1388 if (ldpd_process
== PROC_LDP_ENGINE
)
1389 ldp_if_update(ia
->iface
, ia
->af
);
1391 ia
->hello_holdtime
= xi
->hello_holdtime
;
1392 ia
->hello_interval
= xi
->hello_interval
;
1396 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1398 struct tnbr
*tnbr
, *ttmp
, *xt
;
1400 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1401 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1404 /* find deleted tnbrs */
1405 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1406 switch (ldpd_process
) {
1407 case PROC_LDP_ENGINE
:
1408 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1409 tnbr_check(conf
, tnbr
);
1411 case PROC_LDE_ENGINE
:
1413 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1419 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1420 /* find new tnbrs */
1421 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1423 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1425 switch (ldpd_process
) {
1426 case PROC_LDP_ENGINE
:
1429 case PROC_LDE_ENGINE
:
1436 /* update existing tnbrs */
1437 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1438 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1443 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1445 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1449 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1450 /* find deleted nbrps */
1451 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1452 switch (ldpd_process
) {
1453 case PROC_LDP_ENGINE
:
1454 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1456 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1461 (ldp_af_global_get(&global
,
1462 nbr
->af
))->ldp_session_socket
,
1463 nbr
->af
, &nbr
->raddr
, NULL
);
1465 nbr
->auth
.method
= AUTH_NONE
;
1466 if (nbr_session_active_role(nbr
))
1467 nbr_establish_connection(nbr
);
1470 case PROC_LDE_ENGINE
:
1474 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1478 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1479 /* find new nbrps */
1480 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1482 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1484 switch (ldpd_process
) {
1485 case PROC_LDP_ENGINE
:
1486 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1488 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1489 nbr
->auth
.method
= nbrp
->auth
.method
;
1491 if (pfkey_establish(nbr
, nbrp
) == -1)
1492 fatalx("pfkey setup failed");
1495 (ldp_af_global_get(&global
,
1496 nbr
->af
))->ldp_session_socket
,
1497 nbr
->af
, &nbr
->raddr
,
1500 if (nbr_session_active_role(nbr
))
1501 nbr_establish_connection(nbr
);
1504 case PROC_LDE_ENGINE
:
1511 /* update existing nbrps */
1512 if (nbrp
->flags
!= xn
->flags
||
1513 nbrp
->keepalive
!= xn
->keepalive
||
1514 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1515 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1516 nbrp
->auth
.method
!= xn
->auth
.method
||
1517 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1522 nbrp
->keepalive
= xn
->keepalive
;
1523 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1524 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1525 nbrp
->auth
.method
= xn
->auth
.method
;
1526 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1527 sizeof(nbrp
->auth
.md5key
));
1528 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1529 nbrp
->flags
= xn
->flags
;
1531 if (ldpd_process
== PROC_LDP_ENGINE
) {
1532 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1533 if (nbr
&& nbrp_changed
) {
1534 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1537 nbr
->auth
.method
= nbrp
->auth
.method
;
1538 if (pfkey_establish(nbr
, nbrp
) == -1)
1539 fatalx("pfkey setup failed");
1541 nbr
->auth
.method
= nbrp
->auth
.method
;
1542 sock_set_md5sig((ldp_af_global_get(&global
,
1543 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1544 &nbr
->raddr
, nbrp
->auth
.md5key
);
1546 if (nbr_session_active_role(nbr
))
1547 nbr_establish_connection(nbr
);
1554 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1556 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1558 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1559 /* find deleted l2vpns */
1560 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1561 switch (ldpd_process
) {
1562 case PROC_LDE_ENGINE
:
1565 case PROC_LDP_ENGINE
:
1566 ldpe_l2vpn_exit(l2vpn
);
1571 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1575 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1576 /* find new l2vpns */
1577 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1579 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1580 RB_INIT(&l2vpn
->if_tree
);
1581 RB_INIT(&l2vpn
->pw_tree
);
1582 RB_INIT(&l2vpn
->pw_inactive_tree
);
1584 switch (ldpd_process
) {
1585 case PROC_LDE_ENGINE
:
1588 case PROC_LDP_ENGINE
:
1589 ldpe_l2vpn_init(l2vpn
);
1596 /* update existing l2vpns */
1597 merge_l2vpn(conf
, l2vpn
, xl
);
1602 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1604 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1605 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1607 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1608 int previous_pw_type
, previous_mtu
;
1610 previous_pw_type
= l2vpn
->pw_type
;
1611 previous_mtu
= l2vpn
->mtu
;
1613 /* merge intefaces */
1614 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1615 /* find deleted interfaces */
1616 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1617 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1621 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1622 /* find new interfaces */
1623 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1625 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1628 switch (ldpd_process
) {
1629 case PROC_LDP_ENGINE
:
1630 case PROC_LDE_ENGINE
:
1633 kif_redistribute(lif
->ifname
);
1639 /* merge active pseudowires */
1640 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1641 /* find deleted active pseudowires */
1642 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1643 switch (ldpd_process
) {
1644 case PROC_LDE_ENGINE
:
1647 case PROC_LDP_ENGINE
:
1648 ldpe_l2vpn_pw_exit(pw
);
1654 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1658 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1659 /* find new active pseudowires */
1660 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1662 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1665 switch (ldpd_process
) {
1666 case PROC_LDE_ENGINE
:
1669 case PROC_LDP_ENGINE
:
1670 ldpe_l2vpn_pw_init(pw
);
1673 kif_redistribute(pw
->ifname
);
1679 /* update existing active pseudowire */
1680 if (pw
->af
!= xp
->af
||
1681 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1686 /* changes that require a session restart */
1687 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1688 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1693 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1694 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1695 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1696 reinstall_pwfec
= 1;
1698 reinstall_pwfec
= 0;
1700 if (ldpd_process
== PROC_LDP_ENGINE
) {
1702 ldpe_l2vpn_pw_exit(pw
);
1704 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1705 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1706 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1709 if (ldpd_process
== PROC_LDE_ENGINE
&&
1710 !reset_nbr
&& reinstall_pwfec
)
1712 pw
->lsr_id
= xp
->lsr_id
;
1714 pw
->addr
= xp
->addr
;
1715 pw
->pwid
= xp
->pwid
;
1716 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1717 pw
->ifindex
= xp
->ifindex
;
1718 if (xp
->flags
& F_PW_CWORD_CONF
)
1719 pw
->flags
|= F_PW_CWORD_CONF
;
1721 pw
->flags
&= ~F_PW_CWORD_CONF
;
1722 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1723 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1725 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1726 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1727 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1729 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1730 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1731 ldpe_l2vpn_pw_init(pw
);
1732 if (ldpd_process
== PROC_LDE_ENGINE
&&
1733 !reset_nbr
&& reinstall_pwfec
) {
1734 l2vpn
->pw_type
= xl
->pw_type
;
1735 l2vpn
->mtu
= xl
->mtu
;
1737 l2vpn
->pw_type
= previous_pw_type
;
1738 l2vpn
->mtu
= previous_mtu
;
1742 /* merge inactive pseudowires */
1743 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1744 /* find deleted inactive pseudowires */
1745 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1746 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1750 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1751 /* find new inactive pseudowires */
1752 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1754 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1757 switch (ldpd_process
) {
1758 case PROC_LDE_ENGINE
:
1759 case PROC_LDP_ENGINE
:
1762 kif_redistribute(pw
->ifname
);
1768 /* update existing inactive pseudowire */
1769 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1771 pw
->addr
= xp
->addr
;
1772 pw
->pwid
= xp
->pwid
;
1773 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1774 pw
->ifindex
= xp
->ifindex
;
1775 pw
->flags
= xp
->flags
;
1778 l2vpn
->pw_type
= xl
->pw_type
;
1779 l2vpn
->mtu
= xl
->mtu
;
1780 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1781 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1785 config_new_empty(void)
1787 struct ldpd_conf
*xconf
;
1789 xconf
= calloc(1, sizeof(*xconf
));
1793 RB_INIT(&xconf
->iface_tree
);
1794 RB_INIT(&xconf
->tnbr_tree
);
1795 RB_INIT(&xconf
->nbrp_tree
);
1796 RB_INIT(&xconf
->l2vpn_tree
);
1802 config_clear(struct ldpd_conf
*conf
)
1804 struct ldpd_conf
*xconf
;
1807 * Merge current config with an empty config, this will deactivate
1808 * and deallocate all the interfaces, pseudowires and so on. Before
1809 * merging, copy the router-id and other variables to avoid some
1810 * unnecessary operations, like trying to reset the neighborships.
1812 xconf
= config_new_empty();
1813 xconf
->ipv4
= conf
->ipv4
;
1814 xconf
->ipv6
= conf
->ipv6
;
1815 xconf
->rtr_id
= conf
->rtr_id
;
1816 xconf
->trans_pref
= conf
->trans_pref
;
1817 xconf
->flags
= conf
->flags
;
1818 merge_config(conf
, xconf
);