4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
6 * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include "ldp_debug.h"
32 #include <lib/version.h>
46 static void ldpd_shutdown(void);
47 static pid_t
start_child(enum ldpd_process
, char *, int, int);
48 static int main_dispatch_ldpe(struct thread
*);
49 static int main_dispatch_lde(struct thread
*);
50 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
52 static void main_imsg_send_net_sockets(int);
53 static void main_imsg_send_net_socket(int, enum socket_type
);
54 static int main_imsg_send_config(struct ldpd_conf
*);
55 static void ldp_config_normalize(struct ldpd_conf
*);
56 static void ldp_config_reset_main(struct ldpd_conf
*);
57 static void ldp_config_reset_af(struct ldpd_conf
*, int);
58 static void ldp_config_reset_l2vpns(struct ldpd_conf
*);
59 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
60 static void merge_af(int, struct ldpd_af_conf
*,
61 struct ldpd_af_conf
*);
62 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
63 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
64 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
65 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
66 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
67 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
70 DEFINE_QOBJ_TYPE(iface
)
71 DEFINE_QOBJ_TYPE(tnbr
)
72 DEFINE_QOBJ_TYPE(nbr_params
)
73 DEFINE_QOBJ_TYPE(l2vpn_if
)
74 DEFINE_QOBJ_TYPE(l2vpn_pw
)
75 DEFINE_QOBJ_TYPE(l2vpn
)
76 DEFINE_QOBJ_TYPE(ldpd_conf
)
78 struct ldpd_global global
;
79 struct ldpd_init init
;
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];
205 ldpd_process
= PROC_MAIN
;
206 log_procname
= log_procnames
[ldpd_process
];
208 saved_argv0
= argv
[0];
209 if (saved_argv0
== NULL
)
210 saved_argv0
= (char *)"ldpd";
212 frr_preinit(&ldpd_di
, argc
, argv
);
213 frr_opt_add("LEn:", longopts
,
214 " --ctl_socket Override ctl socket path\n"
215 "-n, --instance Instance id\n");
220 opt
= frr_getopt(argc
, argv
, NULL
);
229 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
235 * LDPD_SOCKET configured as relative path
236 * during config? Should really never happen for
239 ctl_sock_name
= (char *)LDPD_SOCKET
;
240 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
241 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
242 strlcat(ctl_sock_path
, ctl_sock_name
,
243 sizeof(ctl_sock_path
));
246 init
.instance
= atoi(optarg
);
247 if (init
.instance
< 1)
262 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
263 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
264 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
265 strlcpy(init
.zclient_serv_path
, zclient_serv_path_get(),
266 sizeof(init
.zclient_serv_path
));
270 if (argc
> 0 || (lflag
&& eflag
))
273 /* check for root privileges */
274 if (geteuid() != 0) {
276 perror(ldpd_di
.progname
);
280 openzlog(ldpd_di
.progname
, "LDP", 0,
281 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
288 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
290 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
291 pipe_parent2ldpe_sync
) == -1)
293 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
295 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
296 pipe_parent2lde_sync
) == -1)
298 sock_set_nonblock(pipe_parent2ldpe
[0]);
299 sock_set_cloexec(pipe_parent2ldpe
[0]);
300 sock_set_nonblock(pipe_parent2ldpe
[1]);
301 sock_set_cloexec(pipe_parent2ldpe
[1]);
302 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
303 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
304 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
305 sock_set_nonblock(pipe_parent2lde
[0]);
306 sock_set_cloexec(pipe_parent2lde
[0]);
307 sock_set_nonblock(pipe_parent2lde
[1]);
308 sock_set_cloexec(pipe_parent2lde
[1]);
309 sock_set_nonblock(pipe_parent2lde_sync
[0]);
310 sock_set_cloexec(pipe_parent2lde_sync
[0]);
311 sock_set_cloexec(pipe_parent2lde_sync
[1]);
314 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
315 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
316 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
317 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
319 /* drop privileges */
320 zprivs_init(&ldpd_privs
);
322 /* setup signal handler */
323 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
326 master
= thread_master_create();
330 vty_config_lockless();
335 ldp_zebra_init(master
);
337 /* create base configuration with sane defaults */
338 ldpd_conf
= config_new_empty();
339 ldp_config_reset_main(ldpd_conf
);
342 * Create vty_conf as a duplicate of the main configuration. All
343 * configuration requests (e.g. CLI) act on vty_conf and then call
344 * ldp_reload() to merge the changes into ldpd_conf.
346 vty_conf
= config_new_empty();
347 ldp_config_reset_main(vty_conf
);
348 QOBJ_REG(vty_conf
, ldpd_conf
);
350 /* read configuration file and daemonize */
353 /* setup pipes to children */
354 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
355 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
356 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
357 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
359 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
360 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
361 iev_ldpe
->ev_read
= NULL
;
362 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
364 iev_ldpe
->handler_write
= ldp_write_handler
;
366 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
367 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
368 iev_ldpe_sync
->ev_read
= NULL
;
369 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
370 &iev_ldpe_sync
->ev_read
);
371 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
373 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
374 iev_lde
->handler_read
= main_dispatch_lde
;
375 iev_lde
->ev_read
= NULL
;
376 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
378 iev_lde
->handler_write
= ldp_write_handler
;
380 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
381 iev_lde_sync
->handler_read
= main_dispatch_lde
;
382 iev_lde_sync
->ev_read
= NULL
;
383 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
384 &iev_lde_sync
->ev_read
);
385 iev_lde_sync
->handler_write
= ldp_write_handler
;
387 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
388 fatal("could not establish imsg links");
389 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
390 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
392 main_imsg_send_config(ldpd_conf
);
394 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
395 main_imsg_send_net_sockets(AF_INET
);
396 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
397 main_imsg_send_net_sockets(AF_INET6
);
412 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
413 close(iev_ldpe
->ibuf
.fd
);
414 msgbuf_clear(&iev_lde
->ibuf
.w
);
415 close(iev_lde
->ibuf
.fd
);
417 config_clear(ldpd_conf
);
419 ldp_config_reset_main(vty_conf
);
420 ldp_config_reset_l2vpns(vty_conf
);
421 QOBJ_UNREG(vty_conf
);
424 log_debug("waiting for children to terminate");
428 if (errno
!= EINTR
&& errno
!= ECHILD
)
430 } else if (WIFSIGNALED(status
))
431 log_warnx("%s terminated; signal %d",
432 (pid
== lde_pid
) ? "label decision engine" :
433 "ldp engine", WTERMSIG(status
));
434 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
439 log_info("terminating");
446 zprivs_terminate(&ldpd_privs
);
447 thread_master_free(master
);
454 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
460 switch (pid
= fork()) {
462 fatal("cannot fork");
471 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
472 fatal("cannot setup imsg async fd");
473 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
474 fatal("cannot setup imsg sync fd");
476 argv
[argc
++] = argv0
;
479 fatalx("Can not start main process");
480 case PROC_LDE_ENGINE
:
481 argv
[argc
++] = (char *)"-L";
483 case PROC_LDP_ENGINE
:
484 argv
[argc
++] = (char *)"-E";
496 main_dispatch_ldpe(struct thread
*thread
)
498 struct imsgev
*iev
= THREAD_ARG(thread
);
499 struct imsgbuf
*ibuf
= &iev
->ibuf
;
507 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
508 fatal("imsg_read error");
509 if (n
== 0) /* connection closed */
513 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
519 switch (imsg
.hdr
.type
) {
521 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
523 case IMSG_REQUEST_SOCKETS
:
525 main_imsg_send_net_sockets(af
);
528 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
529 sizeof(struct acl_check
))
530 fatalx("IMSG_ACL_CHECK imsg with wrong len");
531 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
534 log_debug("%s: error handling imsg %d", __func__
,
543 /* this pipe is dead, so remove the event handlers and exit */
544 THREAD_READ_OFF(iev
->ev_read
);
545 THREAD_WRITE_OFF(iev
->ev_write
);
550 kill(lde_pid
, SIGTERM
);
558 main_dispatch_lde(struct thread
*thread
)
560 struct imsgev
*iev
= THREAD_ARG(thread
);
561 struct imsgbuf
*ibuf
= &iev
->ibuf
;
568 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
569 fatal("imsg_read error");
570 if (n
== 0) /* connection closed */
574 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
580 switch (imsg
.hdr
.type
) {
582 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
584 case IMSG_KLABEL_CHANGE
:
585 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
586 sizeof(struct kroute
))
587 fatalx("invalid size of IMSG_KLABEL_CHANGE");
588 if (kr_change(imsg
.data
))
589 log_warnx("%s: error changing route", __func__
);
591 case IMSG_KLABEL_DELETE
:
592 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
593 sizeof(struct kroute
))
594 fatalx("invalid size of IMSG_KLABEL_DELETE");
595 if (kr_delete(imsg
.data
))
596 log_warnx("%s: error deleting route", __func__
);
598 case IMSG_KPWLABEL_CHANGE
:
599 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
601 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
602 if (kmpw_set(imsg
.data
))
603 log_warnx("%s: error changing pseudowire",
606 case IMSG_KPWLABEL_DELETE
:
607 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
609 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
610 if (kmpw_unset(imsg
.data
))
611 log_warnx("%s: error unsetting pseudowire",
615 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
616 sizeof(struct acl_check
))
617 fatalx("IMSG_ACL_CHECK imsg with wrong len");
618 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
621 log_debug("%s: error handling imsg %d", __func__
,
630 /* this pipe is dead, so remove the event handlers and exit */
631 THREAD_READ_OFF(iev
->ev_read
);
632 THREAD_WRITE_OFF(iev
->ev_write
);
637 kill(ldpe_pid
, SIGTERM
);
645 ldp_write_handler(struct thread
*thread
)
647 struct imsgev
*iev
= THREAD_ARG(thread
);
648 struct imsgbuf
*ibuf
= &iev
->ibuf
;
651 iev
->ev_write
= NULL
;
653 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
654 fatal("msgbuf_write");
656 /* this pipe is dead, so remove the event handlers */
657 THREAD_READ_OFF(iev
->ev_read
);
658 THREAD_WRITE_OFF(iev
->ev_write
);
668 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
670 if (iev_ldpe
== NULL
)
672 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
676 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
678 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
682 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
684 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
686 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
688 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
694 imsg_event_add(struct imsgev
*iev
)
696 if (iev
->handler_read
)
697 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
700 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
701 thread_add_write(master
, iev
->handler_write
, iev
,
702 iev
->ibuf
.fd
, &iev
->ev_write
);
706 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
707 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
711 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
712 pid
, fd
, data
, datalen
)) != -1)
718 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
720 ibuf_close(&eb
->wbuf
, buf
);
725 evbuf_event_add(struct evbuf
*eb
)
728 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
733 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
736 msgbuf_init(&eb
->wbuf
);
738 eb
->handler
= handler
;
743 evbuf_clear(struct evbuf
*eb
)
745 THREAD_WRITE_OFF(eb
->ev
);
746 msgbuf_clear(&eb
->wbuf
);
751 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
753 int pipe_ldpe2lde
[2];
755 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
757 sock_set_nonblock(pipe_ldpe2lde
[0]);
758 sock_set_nonblock(pipe_ldpe2lde
[1]);
760 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
763 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
771 main_imsg_send_net_sockets(int af
)
773 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
776 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
777 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
778 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
779 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
783 main_imsg_send_net_socket(int af
, enum socket_type type
)
787 fd
= ldp_create_socket(af
, type
);
789 log_warnx("%s: failed to create %s socket for address-family "
790 "%s", __func__
, socket_name(type
), af_name(af
));
794 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
799 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
800 union ldpd_addr
*addr
, uint8_t prefixlen
)
804 struct acl_check acl_check
;
806 if (acl_name
[0] == '\0')
807 return FILTER_PERMIT
;
810 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
812 acl_check
.addr
= *addr
;
813 acl_check
.prefixlen
= prefixlen
;
815 /* send (blocking) */
816 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
818 imsg_flush(&iev
->ibuf
);
820 /* receive (blocking) and parse result */
821 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
822 fatal("imsg_read error");
823 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
825 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
826 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
827 fatalx("ldp_acl_request: invalid response");
829 return (*((int *)imsg
.data
));
833 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
835 struct access_list
*alist
;
836 struct prefix prefix
;
839 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
841 result
= FILTER_DENY
;
843 prefix
.family
= acl_check
->af
;
844 switch (prefix
.family
) {
846 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
849 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
852 fatalx("ldp_acl_reply: unknown af");
854 prefix
.prefixlen
= acl_check
->prefixlen
;
855 result
= access_list_apply(alist
, &prefix
);
858 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
862 struct ldpd_af_conf
*
863 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
867 return (&xconf
->ipv4
);
869 return (&xconf
->ipv6
);
871 fatalx("ldp_af_conf_get: unknown af");
875 struct ldpd_af_global
*
876 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
880 return (&xglobal
->ipv4
);
882 return (&xglobal
->ipv6
);
884 fatalx("ldp_af_global_get: unknown af");
889 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
891 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
892 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
896 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
898 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
899 return (xconf
->rtr_id
.s_addr
);
901 return (global
.rtr_id
.s_addr
);
905 main_imsg_send_config(struct ldpd_conf
*xconf
)
909 struct nbr_params
*nbrp
;
911 struct l2vpn_if
*lif
;
914 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
915 sizeof(*xconf
)) == -1)
918 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
919 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
920 sizeof(*iface
)) == -1)
924 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
925 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
926 sizeof(*tnbr
)) == -1)
930 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
931 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
932 sizeof(*nbrp
)) == -1)
936 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
937 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
938 sizeof(*l2vpn
)) == -1)
941 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
942 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
946 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
947 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
951 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
952 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
958 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
965 ldp_reload(struct ldpd_conf
*xconf
)
970 ldp_config_normalize(xconf
);
972 if (main_imsg_send_config(xconf
) == -1)
975 merge_config(ldpd_conf
, xconf
);
981 ldp_config_normalize(struct ldpd_conf
*xconf
)
983 struct iface
*iface
, *itmp
;
984 struct nbr_params
*nbrp
, *ntmp
;
986 struct l2vpn_pw
*pw
, *ptmp
;
988 if (!(xconf
->flags
& F_LDPD_ENABLED
))
989 ldp_config_reset_main(xconf
);
991 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
992 ldp_config_reset_af(xconf
, AF_INET
);
993 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
994 ldp_config_reset_af(xconf
, AF_INET6
);
996 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
997 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1001 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1005 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1006 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1008 if (nbrp
->auth
.method
!= AUTH_NONE
)
1012 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1017 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1018 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1019 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1021 pw
->addr
.v4
= pw
->lsr_id
;
1024 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1026 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1027 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1029 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1031 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1033 pw
->addr
.v4
= pw
->lsr_id
;
1036 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1038 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1039 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1045 ldp_config_reset_main(struct ldpd_conf
*conf
)
1047 struct iface
*iface
;
1048 struct nbr_params
*nbrp
;
1050 while ((iface
= RB_ROOT(&conf
->iface_tree
)) != NULL
) {
1052 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1056 while ((nbrp
= RB_ROOT(&conf
->nbrp_tree
)) != NULL
) {
1058 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1062 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1063 ldp_config_reset_af(conf
, AF_INET
);
1064 ldp_config_reset_af(conf
, AF_INET6
);
1065 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1066 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1067 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1068 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1069 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1074 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1076 struct ldpd_af_conf
*af_conf
;
1077 struct iface
*iface
;
1078 struct iface_af
*ia
;
1079 struct tnbr
*tnbr
, *ttmp
;
1081 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1082 ia
= iface_af_get(iface
, af
);
1086 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1091 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1095 af_conf
= ldp_af_conf_get(conf
, af
);
1096 af_conf
->keepalive
= 180;
1097 af_conf
->lhello_holdtime
= 0;
1098 af_conf
->lhello_interval
= 0;
1099 af_conf
->thello_holdtime
= 0;
1100 af_conf
->thello_interval
= 0;
1101 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1106 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1108 struct l2vpn
*l2vpn
;
1109 struct l2vpn_if
*lif
;
1110 struct l2vpn_pw
*pw
;
1112 while ((l2vpn
= RB_ROOT(&conf
->l2vpn_tree
)) != NULL
) {
1113 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1115 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1118 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1120 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1123 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1125 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1129 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1135 ldp_clear_config(struct ldpd_conf
*xconf
)
1137 struct iface
*iface
;
1139 struct nbr_params
*nbrp
;
1140 struct l2vpn
*l2vpn
;
1142 while ((iface
= RB_ROOT(&xconf
->iface_tree
)) != NULL
) {
1143 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1146 while ((tnbr
= RB_ROOT(&xconf
->tnbr_tree
)) != NULL
) {
1147 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1150 while ((nbrp
= RB_ROOT(&xconf
->nbrp_tree
)) != NULL
) {
1151 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1154 while ((l2vpn
= RB_ROOT(&xconf
->l2vpn_tree
)) != NULL
) {
1155 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1162 #define COPY(a, b) do { \
1163 a = malloc(sizeof(*a)); \
1170 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1172 merge_global(conf
, xconf
);
1173 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1174 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1175 merge_ifaces(conf
, xconf
);
1176 merge_tnbrs(conf
, xconf
);
1177 merge_nbrps(conf
, xconf
);
1178 merge_l2vpns(conf
, xconf
);
1182 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1184 /* change of router-id requires resetting all neighborships */
1185 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1186 if (ldpd_process
== PROC_LDP_ENGINE
) {
1187 ldpe_reset_nbrs(AF_UNSPEC
);
1188 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1189 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1190 if_update_all(AF_UNSPEC
);
1191 tnbr_update_all(AF_UNSPEC
);
1194 conf
->rtr_id
= xconf
->rtr_id
;
1197 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1198 conf
->lhello_interval
= xconf
->lhello_interval
;
1199 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1200 conf
->thello_interval
= xconf
->thello_interval
;
1202 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1203 if (ldpd_process
== PROC_LDP_ENGINE
)
1204 ldpe_reset_ds_nbrs();
1205 conf
->trans_pref
= xconf
->trans_pref
;
1208 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1209 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1210 if (ldpd_process
== PROC_LDP_ENGINE
)
1211 ldpe_reset_ds_nbrs();
1214 conf
->flags
= xconf
->flags
;
1218 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1220 int stop_init_backoff
= 0;
1221 int remove_dynamic_tnbrs
= 0;
1222 int change_egress_label
= 0;
1223 int reset_nbrs_ipv4
= 0;
1225 int update_sockets
= 0;
1228 if (af_conf
->keepalive
!= xa
->keepalive
) {
1229 af_conf
->keepalive
= xa
->keepalive
;
1230 stop_init_backoff
= 1;
1232 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1233 af_conf
->lhello_interval
= xa
->lhello_interval
;
1234 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1235 af_conf
->thello_interval
= xa
->thello_interval
;
1238 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1239 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1240 remove_dynamic_tnbrs
= 1;
1241 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1242 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1244 /* need to set/unset IPV6_MINHOPCOUNT */
1247 /* for LDPv4 just resetting the neighbors is enough */
1248 reset_nbrs_ipv4
= 1;
1250 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1251 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1252 change_egress_label
= 1;
1253 af_conf
->flags
= xa
->flags
;
1255 /* update the transport address */
1256 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1257 af_conf
->trans_addr
= xa
->trans_addr
;
1262 if (strcmp(af_conf
->acl_label_advertise_to
,
1263 xa
->acl_label_advertise_to
) ||
1264 strcmp(af_conf
->acl_label_advertise_for
,
1265 xa
->acl_label_advertise_for
) ||
1266 strcmp(af_conf
->acl_label_accept_from
,
1267 xa
->acl_label_accept_from
) ||
1268 strcmp(af_conf
->acl_label_accept_for
,
1269 xa
->acl_label_accept_for
))
1271 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1272 remove_dynamic_tnbrs
= 1;
1273 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1274 change_egress_label
= 1;
1275 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1276 sizeof(af_conf
->acl_thello_accept_from
));
1277 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1278 sizeof(af_conf
->acl_label_allocate_for
));
1279 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1280 sizeof(af_conf
->acl_label_advertise_to
));
1281 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1282 sizeof(af_conf
->acl_label_advertise_for
));
1283 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1284 sizeof(af_conf
->acl_label_accept_from
));
1285 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1286 sizeof(af_conf
->acl_label_accept_for
));
1287 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1288 sizeof(af_conf
->acl_label_expnull_for
));
1290 /* apply the new configuration */
1291 switch (ldpd_process
) {
1292 case PROC_LDE_ENGINE
:
1293 if (change_egress_label
)
1294 lde_change_egress_label(af
);
1296 case PROC_LDP_ENGINE
:
1297 if (stop_init_backoff
)
1298 ldpe_stop_init_backoff(af
);
1299 if (remove_dynamic_tnbrs
)
1300 ldpe_remove_dynamic_tnbrs(af
);
1302 ldpe_reset_nbrs(AF_UNSPEC
);
1303 else if (reset_nbrs_ipv4
)
1304 ldpe_reset_nbrs(AF_INET
);
1307 if (update_sockets
&& iev_ldpe
)
1308 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1315 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1317 struct iface
*iface
, *itmp
, *xi
;
1319 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1320 /* find deleted interfaces */
1321 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1322 switch (ldpd_process
) {
1323 case PROC_LDP_ENGINE
:
1324 ldpe_if_exit(iface
);
1326 case PROC_LDE_ENGINE
:
1330 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1334 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1335 /* find new interfaces */
1336 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1338 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1340 switch (ldpd_process
) {
1341 case PROC_LDP_ENGINE
:
1342 ldpe_if_init(iface
);
1344 case PROC_LDE_ENGINE
:
1347 /* resend addresses to activate new interfaces */
1348 kif_redistribute(iface
->name
);
1354 /* update existing interfaces */
1355 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1356 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1361 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1363 if (ia
->enabled
!= xi
->enabled
) {
1364 ia
->enabled
= xi
->enabled
;
1365 if (ldpd_process
== PROC_LDP_ENGINE
)
1366 ldp_if_update(ia
->iface
, ia
->af
);
1368 ia
->hello_holdtime
= xi
->hello_holdtime
;
1369 ia
->hello_interval
= xi
->hello_interval
;
1373 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1375 struct tnbr
*tnbr
, *ttmp
, *xt
;
1377 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1378 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1381 /* find deleted tnbrs */
1382 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1383 switch (ldpd_process
) {
1384 case PROC_LDP_ENGINE
:
1385 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1386 tnbr_check(conf
, tnbr
);
1388 case PROC_LDE_ENGINE
:
1390 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1396 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1397 /* find new tnbrs */
1398 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1400 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1402 switch (ldpd_process
) {
1403 case PROC_LDP_ENGINE
:
1406 case PROC_LDE_ENGINE
:
1413 /* update existing tnbrs */
1414 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1415 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1420 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1422 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1426 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1427 /* find deleted nbrps */
1428 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1429 switch (ldpd_process
) {
1430 case PROC_LDP_ENGINE
:
1431 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1433 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1438 (ldp_af_global_get(&global
,
1439 nbr
->af
))->ldp_session_socket
,
1440 nbr
->af
, &nbr
->raddr
, NULL
);
1442 nbr
->auth
.method
= AUTH_NONE
;
1443 if (nbr_session_active_role(nbr
))
1444 nbr_establish_connection(nbr
);
1447 case PROC_LDE_ENGINE
:
1451 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1455 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1456 /* find new nbrps */
1457 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1459 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1461 switch (ldpd_process
) {
1462 case PROC_LDP_ENGINE
:
1463 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1465 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1466 nbr
->auth
.method
= nbrp
->auth
.method
;
1468 if (pfkey_establish(nbr
, nbrp
) == -1)
1469 fatalx("pfkey setup failed");
1472 (ldp_af_global_get(&global
,
1473 nbr
->af
))->ldp_session_socket
,
1474 nbr
->af
, &nbr
->raddr
,
1477 if (nbr_session_active_role(nbr
))
1478 nbr_establish_connection(nbr
);
1481 case PROC_LDE_ENGINE
:
1488 /* update existing nbrps */
1489 if (nbrp
->flags
!= xn
->flags
||
1490 nbrp
->keepalive
!= xn
->keepalive
||
1491 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1492 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1493 nbrp
->auth
.method
!= xn
->auth
.method
||
1494 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1499 nbrp
->keepalive
= xn
->keepalive
;
1500 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1501 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1502 nbrp
->auth
.method
= xn
->auth
.method
;
1503 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1504 sizeof(nbrp
->auth
.md5key
));
1505 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1506 nbrp
->flags
= xn
->flags
;
1508 if (ldpd_process
== PROC_LDP_ENGINE
) {
1509 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1510 if (nbr
&& nbrp_changed
) {
1511 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1514 nbr
->auth
.method
= nbrp
->auth
.method
;
1515 if (pfkey_establish(nbr
, nbrp
) == -1)
1516 fatalx("pfkey setup failed");
1518 nbr
->auth
.method
= nbrp
->auth
.method
;
1519 sock_set_md5sig((ldp_af_global_get(&global
,
1520 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1521 &nbr
->raddr
, nbrp
->auth
.md5key
);
1523 if (nbr_session_active_role(nbr
))
1524 nbr_establish_connection(nbr
);
1531 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1533 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1535 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1536 /* find deleted l2vpns */
1537 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1538 switch (ldpd_process
) {
1539 case PROC_LDE_ENGINE
:
1542 case PROC_LDP_ENGINE
:
1543 ldpe_l2vpn_exit(l2vpn
);
1548 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1552 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1553 /* find new l2vpns */
1554 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1556 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1557 RB_INIT(&l2vpn
->if_tree
);
1558 RB_INIT(&l2vpn
->pw_tree
);
1559 RB_INIT(&l2vpn
->pw_inactive_tree
);
1561 switch (ldpd_process
) {
1562 case PROC_LDE_ENGINE
:
1565 case PROC_LDP_ENGINE
:
1566 ldpe_l2vpn_init(l2vpn
);
1573 /* update existing l2vpns */
1574 merge_l2vpn(conf
, l2vpn
, xl
);
1579 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1581 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1582 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1584 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1585 int previous_pw_type
, previous_mtu
;
1587 previous_pw_type
= l2vpn
->pw_type
;
1588 previous_mtu
= l2vpn
->mtu
;
1590 /* merge intefaces */
1591 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1592 /* find deleted interfaces */
1593 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1594 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1598 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1599 /* find new interfaces */
1600 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1602 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1605 switch (ldpd_process
) {
1606 case PROC_LDP_ENGINE
:
1607 case PROC_LDE_ENGINE
:
1610 kif_redistribute(lif
->ifname
);
1616 /* merge active pseudowires */
1617 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1618 /* find deleted active pseudowires */
1619 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1620 switch (ldpd_process
) {
1621 case PROC_LDE_ENGINE
:
1624 case PROC_LDP_ENGINE
:
1625 ldpe_l2vpn_pw_exit(pw
);
1631 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1635 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1636 /* find new active pseudowires */
1637 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1639 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1642 switch (ldpd_process
) {
1643 case PROC_LDE_ENGINE
:
1646 case PROC_LDP_ENGINE
:
1647 ldpe_l2vpn_pw_init(pw
);
1650 kif_redistribute(pw
->ifname
);
1656 /* update existing active pseudowire */
1657 if (pw
->af
!= xp
->af
||
1658 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1663 /* changes that require a session restart */
1664 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1665 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1670 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1671 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1672 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1673 reinstall_pwfec
= 1;
1675 reinstall_pwfec
= 0;
1677 if (ldpd_process
== PROC_LDP_ENGINE
) {
1679 ldpe_l2vpn_pw_exit(pw
);
1681 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1682 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1683 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1686 if (ldpd_process
== PROC_LDE_ENGINE
&&
1687 !reset_nbr
&& reinstall_pwfec
)
1689 pw
->lsr_id
= xp
->lsr_id
;
1691 pw
->addr
= xp
->addr
;
1692 pw
->pwid
= xp
->pwid
;
1693 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1694 pw
->ifindex
= xp
->ifindex
;
1695 if (xp
->flags
& F_PW_CWORD_CONF
)
1696 pw
->flags
|= F_PW_CWORD_CONF
;
1698 pw
->flags
&= ~F_PW_CWORD_CONF
;
1699 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1700 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1702 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1703 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1704 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1706 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1707 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1708 ldpe_l2vpn_pw_init(pw
);
1709 if (ldpd_process
== PROC_LDE_ENGINE
&&
1710 !reset_nbr
&& reinstall_pwfec
) {
1711 l2vpn
->pw_type
= xl
->pw_type
;
1712 l2vpn
->mtu
= xl
->mtu
;
1714 l2vpn
->pw_type
= previous_pw_type
;
1715 l2vpn
->mtu
= previous_mtu
;
1719 /* merge inactive pseudowires */
1720 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1721 /* find deleted inactive pseudowires */
1722 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1723 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1727 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1728 /* find new inactive pseudowires */
1729 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1731 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1734 switch (ldpd_process
) {
1735 case PROC_LDE_ENGINE
:
1736 case PROC_LDP_ENGINE
:
1739 kif_redistribute(pw
->ifname
);
1745 /* update existing inactive pseudowire */
1746 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1748 pw
->addr
= xp
->addr
;
1749 pw
->pwid
= xp
->pwid
;
1750 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1751 pw
->ifindex
= xp
->ifindex
;
1752 pw
->flags
= xp
->flags
;
1755 l2vpn
->pw_type
= xl
->pw_type
;
1756 l2vpn
->mtu
= xl
->mtu
;
1757 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1758 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1762 config_new_empty(void)
1764 struct ldpd_conf
*xconf
;
1766 xconf
= calloc(1, sizeof(*xconf
));
1770 RB_INIT(&xconf
->iface_tree
);
1771 RB_INIT(&xconf
->tnbr_tree
);
1772 RB_INIT(&xconf
->nbrp_tree
);
1773 RB_INIT(&xconf
->l2vpn_tree
);
1779 config_clear(struct ldpd_conf
*conf
)
1781 struct ldpd_conf
*xconf
;
1784 * Merge current config with an empty config, this will deactivate
1785 * and deallocate all the interfaces, pseudowires and so on. Before
1786 * merging, copy the router-id and other variables to avoid some
1787 * unnecessary operations, like trying to reset the neighborships.
1789 xconf
= config_new_empty();
1790 xconf
->ipv4
= conf
->ipv4
;
1791 xconf
->ipv6
= conf
->ipv6
;
1792 xconf
->rtr_id
= conf
->rtr_id
;
1793 xconf
->trans_pref
= conf
->trans_pref
;
1794 xconf
->flags
= conf
->flags
;
1795 merge_config(conf
, xconf
);