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(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_init init
;
81 struct ldpd_conf
*ldpd_conf
, *vty_conf
;
83 static struct imsgev
*iev_ldpe
, *iev_ldpe_sync
;
84 static struct imsgev
*iev_lde
, *iev_lde_sync
;
85 static pid_t ldpe_pid
;
88 #define LDP_DEFAULT_CONFIG "ldpd.conf"
89 #define LDP_VTY_PORT 2612
91 /* Master of threads. */
92 struct thread_master
*master
;
94 static struct frr_daemon_info ldpd_di
;
97 static zebra_capabilities_t _caps_p
[] =
103 struct zebra_privs_t ldpd_privs
=
105 #if defined(FRR_USER) && defined(FRR_GROUP)
109 #if defined(VTY_GROUP)
110 .vty_group
= VTY_GROUP
,
113 .cap_num_p
= array_size(_caps_p
),
117 /* CTL Socket path */
118 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
121 #define OPTION_CTLSOCK 1001
122 static struct option longopts
[] =
124 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
125 { "instance", required_argument
, NULL
, 'n'},
129 /* SIGHUP handler. */
133 log_info("SIGHUP received");
136 * Do a full configuration reload. In other words, reset vty_conf
137 * and build a new configuartion from scratch.
139 ldp_config_reset(vty_conf
);
140 vty_read_config(ldpd_di
.config_file
, config_default
);
141 ldp_config_apply(NULL
, vty_conf
);
144 /* SIGINT / SIGTERM handler. */
148 log_info("SIGINT received");
152 /* SIGUSR1 handler. */
159 static struct quagga_signal_t ldp_signals
[] =
179 FRR_DAEMON_INFO(ldpd
, LDP
,
180 .vty_port
= LDP_VTY_PORT
,
182 .proghelp
= "Implementation of the LDP protocol.",
184 .signals
= ldp_signals
,
185 .n_signals
= array_size(ldp_signals
),
187 .privs
= &ldpd_privs
,
190 static int ldp_config_fork_apply(struct thread
*t
)
193 * So the frr_config_fork() function schedules
194 * the read of the vty config( if there is a
195 * non-integrated config ) to be after the
196 * end of startup and we are starting the
197 * main process loop. We need to schedule
198 * the application of this if necessary
199 * after the read in of the config.
201 ldp_config_apply(NULL
, vty_conf
);
207 main(int argc
, char *argv
[])
210 int lflag
= 0, eflag
= 0;
211 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
212 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
214 struct thread
*thread
= NULL
;
216 ldpd_process
= PROC_MAIN
;
217 log_procname
= log_procnames
[ldpd_process
];
219 saved_argv0
= argv
[0];
220 if (saved_argv0
== NULL
)
221 saved_argv0
= (char *)"ldpd";
223 frr_preinit(&ldpd_di
, argc
, argv
);
224 frr_opt_add("LEn:", longopts
,
225 " --ctl_socket Override ctl socket path\n"
226 " -n, --instance Instance id\n");
231 opt
= frr_getopt(argc
, argv
, NULL
);
240 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
246 * LDPD_SOCKET configured as relative path
247 * during config? Should really never happen for
250 ctl_sock_name
= (char *)LDPD_SOCKET
;
251 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
252 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
253 strlcat(ctl_sock_path
, ctl_sock_name
,
254 sizeof(ctl_sock_path
));
257 init
.instance
= atoi(optarg
);
258 if (init
.instance
< 1)
273 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
274 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
275 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
276 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
277 sizeof(init
.zclient_serv_path
));
280 if (argc
> 0 || (lflag
&& eflag
))
283 /* check for root privileges */
284 if (geteuid() != 0) {
286 perror(ldpd_di
.progname
);
291 openzlog(ldpd_di
.progname
, "LDP", 0,
292 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
298 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
300 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
301 pipe_parent2ldpe_sync
) == -1)
303 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
305 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
306 pipe_parent2lde_sync
) == -1)
308 sock_set_nonblock(pipe_parent2ldpe
[0]);
309 sock_set_cloexec(pipe_parent2ldpe
[0]);
310 sock_set_nonblock(pipe_parent2ldpe
[1]);
311 sock_set_cloexec(pipe_parent2ldpe
[1]);
312 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
313 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
314 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
315 sock_set_nonblock(pipe_parent2lde
[0]);
316 sock_set_cloexec(pipe_parent2lde
[0]);
317 sock_set_nonblock(pipe_parent2lde
[1]);
318 sock_set_cloexec(pipe_parent2lde
[1]);
319 sock_set_nonblock(pipe_parent2lde_sync
[0]);
320 sock_set_cloexec(pipe_parent2lde_sync
[0]);
321 sock_set_cloexec(pipe_parent2lde_sync
[1]);
324 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
325 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
326 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
327 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
331 vty_config_lockless();
332 vrf_init(NULL
, NULL
, NULL
, NULL
);
335 ldp_zebra_init(master
);
338 * Create base configuration with sane defaults. All configuration
339 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
340 * to merge the changes into ldpd_conf, which contains the actual
341 * running configuration.
343 ldpd_conf
= config_new_empty();
344 vty_conf
= config_new_empty();
345 QOBJ_REG(vty_conf
, ldpd_conf
);
347 /* read configuration file and daemonize */
350 /* apply configuration */
351 thread_add_event(master
, ldp_config_fork_apply
, NULL
, 0, &thread
);
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_DEBUG_UPDATE
, &ldp_debug
,
391 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
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
);
414 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
415 close(iev_ldpe
->ibuf
.fd
);
416 msgbuf_clear(&iev_lde
->ibuf
.w
);
417 close(iev_lde
->ibuf
.fd
);
419 config_clear(ldpd_conf
);
421 ldp_config_reset(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");
451 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
454 int argc
= 0, nullfd
;
457 switch (pid
= fork()) {
459 fatal("cannot fork");
468 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
470 zlog_err("%s: failed to open /dev/null: %s", __func__
,
471 safe_strerror(errno
));
479 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
480 fatal("cannot setup imsg async fd");
481 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
482 fatal("cannot setup imsg sync fd");
484 argv
[argc
++] = argv0
;
487 fatalx("Can not start main process");
488 case PROC_LDE_ENGINE
:
489 argv
[argc
++] = (char *)"-L";
491 case PROC_LDP_ENGINE
:
492 argv
[argc
++] = (char *)"-E";
504 main_dispatch_ldpe(struct thread
*thread
)
506 struct imsgev
*iev
= THREAD_ARG(thread
);
507 struct imsgbuf
*ibuf
= &iev
->ibuf
;
515 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
516 fatal("imsg_read error");
517 if (n
== 0) /* connection closed */
521 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
527 switch (imsg
.hdr
.type
) {
529 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
531 case IMSG_REQUEST_SOCKETS
:
533 main_imsg_send_net_sockets(af
);
536 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
537 sizeof(struct acl_check
))
538 fatalx("IMSG_ACL_CHECK imsg with wrong len");
539 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
542 log_debug("%s: error handling imsg %d", __func__
,
551 /* this pipe is dead, so remove the event handlers and exit */
552 THREAD_READ_OFF(iev
->ev_read
);
553 THREAD_WRITE_OFF(iev
->ev_write
);
558 kill(lde_pid
, SIGTERM
);
566 main_dispatch_lde(struct thread
*thread
)
568 struct imsgev
*iev
= THREAD_ARG(thread
);
569 struct imsgbuf
*ibuf
= &iev
->ibuf
;
576 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
577 fatal("imsg_read error");
578 if (n
== 0) /* connection closed */
582 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
588 switch (imsg
.hdr
.type
) {
590 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
592 case IMSG_KLABEL_CHANGE
:
593 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
594 sizeof(struct kroute
))
595 fatalx("invalid size of IMSG_KLABEL_CHANGE");
596 if (kr_change(imsg
.data
))
597 log_warnx("%s: error changing route", __func__
);
599 case IMSG_KLABEL_DELETE
:
600 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
601 sizeof(struct kroute
))
602 fatalx("invalid size of IMSG_KLABEL_DELETE");
603 if (kr_delete(imsg
.data
))
604 log_warnx("%s: error deleting route", __func__
);
607 case IMSG_KPW_DELETE
:
610 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
611 sizeof(struct zapi_pw
))
612 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
614 switch (imsg
.hdr
.type
) {
616 if (kmpw_add(imsg
.data
))
617 log_warnx("%s: error adding "
618 "pseudowire", __func__
);
620 case IMSG_KPW_DELETE
:
621 if (kmpw_del(imsg
.data
))
622 log_warnx("%s: error deleting "
623 "pseudowire", __func__
);
626 if (kmpw_set(imsg
.data
))
627 log_warnx("%s: error setting "
628 "pseudowire", __func__
);
631 if (kmpw_unset(imsg
.data
))
632 log_warnx("%s: error unsetting "
633 "pseudowire", __func__
);
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_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
723 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
724 thread_add_write(master
, iev
->handler_write
, iev
,
725 iev
->ibuf
.fd
, &iev
->ev_write
);
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_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
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_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
991 * When reading from a configuration file (startup and sighup), we
992 * call merge_config() only once after the whole config has been read.
993 * This is the optimal and least disruptive way to update the running
996 if (vty
&& vty
->type
== VTY_FILE
)
999 ldp_config_normalize(xconf
);
1001 if (main_imsg_send_config(xconf
) == -1)
1004 merge_config(ldpd_conf
, xconf
);
1010 ldp_config_normalize(struct ldpd_conf
*xconf
)
1012 struct iface
*iface
, *itmp
;
1013 struct nbr_params
*nbrp
, *ntmp
;
1014 struct l2vpn
*l2vpn
;
1015 struct l2vpn_pw
*pw
, *ptmp
;
1017 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1018 ldp_config_reset_main(xconf
);
1020 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1021 ldp_config_reset_af(xconf
, AF_INET
);
1022 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1023 ldp_config_reset_af(xconf
, AF_INET6
);
1025 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1026 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1030 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1034 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1035 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1037 if (nbrp
->auth
.method
!= AUTH_NONE
)
1041 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1046 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1047 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1048 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1050 pw
->addr
.v4
= pw
->lsr_id
;
1053 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0)
1055 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1056 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1058 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1060 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1062 pw
->addr
.v4
= pw
->lsr_id
;
1065 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1067 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1068 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1074 ldp_config_reset(struct ldpd_conf
*conf
)
1076 ldp_config_reset_main(conf
);
1077 ldp_config_reset_l2vpns(conf
);
1081 ldp_config_reset_main(struct ldpd_conf
*conf
)
1083 struct iface
*iface
;
1084 struct nbr_params
*nbrp
;
1086 while (!RB_EMPTY(iface_head
, &conf
->iface_tree
)) {
1087 iface
= RB_ROOT(iface_head
, &conf
->iface_tree
);
1090 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1094 while (!RB_EMPTY(nbrp_head
, &conf
->nbrp_tree
)) {
1095 nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
);
1098 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1102 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1103 ldp_config_reset_af(conf
, AF_INET
);
1104 ldp_config_reset_af(conf
, AF_INET6
);
1105 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1106 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1107 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1108 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1109 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1114 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1116 struct ldpd_af_conf
*af_conf
;
1117 struct iface
*iface
;
1118 struct iface_af
*ia
;
1119 struct tnbr
*tnbr
, *ttmp
;
1121 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1122 ia
= iface_af_get(iface
, af
);
1126 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1131 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1135 af_conf
= ldp_af_conf_get(conf
, af
);
1136 af_conf
->keepalive
= 180;
1137 af_conf
->lhello_holdtime
= 0;
1138 af_conf
->lhello_interval
= 0;
1139 af_conf
->thello_holdtime
= 0;
1140 af_conf
->thello_interval
= 0;
1141 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1146 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1148 struct l2vpn
*l2vpn
;
1149 struct l2vpn_if
*lif
;
1150 struct l2vpn_pw
*pw
;
1152 while (!RB_EMPTY(l2vpn_head
, &conf
->l2vpn_tree
)) {
1153 l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
);
1154 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1155 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1158 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1161 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1162 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1165 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1168 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1169 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1172 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1176 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1182 ldp_clear_config(struct ldpd_conf
*xconf
)
1184 struct iface
*iface
;
1186 struct nbr_params
*nbrp
;
1187 struct l2vpn
*l2vpn
;
1189 while (!RB_EMPTY(iface_head
, &xconf
->iface_tree
)) {
1190 iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
);
1192 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1195 while (!RB_EMPTY(tnbr_head
, &xconf
->tnbr_tree
)) {
1196 tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
);
1198 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1201 while (!RB_EMPTY(nbrp_head
, &xconf
->nbrp_tree
)) {
1202 nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
);
1204 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1207 while (!RB_EMPTY(l2vpn_head
, &xconf
->l2vpn_tree
)) {
1208 l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
);
1210 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1217 #define COPY(a, b) do { \
1218 a = malloc(sizeof(*a)); \
1225 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1227 merge_global(conf
, xconf
);
1228 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1229 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1230 merge_ifaces(conf
, xconf
);
1231 merge_tnbrs(conf
, xconf
);
1232 merge_nbrps(conf
, xconf
);
1233 merge_l2vpns(conf
, xconf
);
1237 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1239 /* change of router-id requires resetting all neighborships */
1240 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1241 if (ldpd_process
== PROC_LDP_ENGINE
) {
1242 ldpe_reset_nbrs(AF_UNSPEC
);
1243 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1244 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1245 if_update_all(AF_UNSPEC
);
1246 tnbr_update_all(AF_UNSPEC
);
1249 conf
->rtr_id
= xconf
->rtr_id
;
1252 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1253 conf
->lhello_interval
= xconf
->lhello_interval
;
1254 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1255 conf
->thello_interval
= xconf
->thello_interval
;
1257 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1258 if (ldpd_process
== PROC_LDP_ENGINE
)
1259 ldpe_reset_ds_nbrs();
1260 conf
->trans_pref
= xconf
->trans_pref
;
1263 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1264 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1265 if (ldpd_process
== PROC_LDP_ENGINE
)
1266 ldpe_reset_ds_nbrs();
1269 conf
->flags
= xconf
->flags
;
1273 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1275 int stop_init_backoff
= 0;
1276 int remove_dynamic_tnbrs
= 0;
1277 int change_egress_label
= 0;
1278 int reset_nbrs_ipv4
= 0;
1280 int update_sockets
= 0;
1283 if (af_conf
->keepalive
!= xa
->keepalive
) {
1284 af_conf
->keepalive
= xa
->keepalive
;
1285 stop_init_backoff
= 1;
1287 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1288 af_conf
->lhello_interval
= xa
->lhello_interval
;
1289 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1290 af_conf
->thello_interval
= xa
->thello_interval
;
1293 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1294 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1295 remove_dynamic_tnbrs
= 1;
1296 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1297 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1299 /* need to set/unset IPV6_MINHOPCOUNT */
1302 /* for LDPv4 just resetting the neighbors is enough */
1303 reset_nbrs_ipv4
= 1;
1305 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1306 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1307 change_egress_label
= 1;
1308 af_conf
->flags
= xa
->flags
;
1310 /* update the transport address */
1311 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1312 af_conf
->trans_addr
= xa
->trans_addr
;
1317 if (strcmp(af_conf
->acl_label_advertise_to
,
1318 xa
->acl_label_advertise_to
) ||
1319 strcmp(af_conf
->acl_label_advertise_for
,
1320 xa
->acl_label_advertise_for
) ||
1321 strcmp(af_conf
->acl_label_accept_from
,
1322 xa
->acl_label_accept_from
) ||
1323 strcmp(af_conf
->acl_label_accept_for
,
1324 xa
->acl_label_accept_for
))
1326 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1327 remove_dynamic_tnbrs
= 1;
1328 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1329 change_egress_label
= 1;
1330 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1331 sizeof(af_conf
->acl_thello_accept_from
));
1332 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1333 sizeof(af_conf
->acl_label_allocate_for
));
1334 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1335 sizeof(af_conf
->acl_label_advertise_to
));
1336 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1337 sizeof(af_conf
->acl_label_advertise_for
));
1338 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1339 sizeof(af_conf
->acl_label_accept_from
));
1340 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1341 sizeof(af_conf
->acl_label_accept_for
));
1342 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1343 sizeof(af_conf
->acl_label_expnull_for
));
1345 /* apply the new configuration */
1346 switch (ldpd_process
) {
1347 case PROC_LDE_ENGINE
:
1348 if (change_egress_label
)
1349 lde_change_egress_label(af
);
1351 case PROC_LDP_ENGINE
:
1352 if (stop_init_backoff
)
1353 ldpe_stop_init_backoff(af
);
1354 if (remove_dynamic_tnbrs
)
1355 ldpe_remove_dynamic_tnbrs(af
);
1357 ldpe_reset_nbrs(AF_UNSPEC
);
1358 else if (reset_nbrs_ipv4
)
1359 ldpe_reset_nbrs(AF_INET
);
1362 if (update_sockets
&& iev_ldpe
)
1363 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1370 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1372 struct iface
*iface
, *itmp
, *xi
;
1374 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1375 /* find deleted interfaces */
1376 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1377 switch (ldpd_process
) {
1378 case PROC_LDP_ENGINE
:
1379 ldpe_if_exit(iface
);
1381 case PROC_LDE_ENGINE
:
1385 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1389 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1390 /* find new interfaces */
1391 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1393 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1395 switch (ldpd_process
) {
1396 case PROC_LDP_ENGINE
:
1397 ldpe_if_init(iface
);
1399 case PROC_LDE_ENGINE
:
1402 /* resend addresses to activate new interfaces */
1403 kif_redistribute(iface
->name
);
1409 /* update existing interfaces */
1410 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1411 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1416 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1418 if (ia
->enabled
!= xi
->enabled
) {
1419 ia
->enabled
= xi
->enabled
;
1420 if (ldpd_process
== PROC_LDP_ENGINE
)
1421 ldp_if_update(ia
->iface
, ia
->af
);
1423 ia
->hello_holdtime
= xi
->hello_holdtime
;
1424 ia
->hello_interval
= xi
->hello_interval
;
1428 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1430 struct tnbr
*tnbr
, *ttmp
, *xt
;
1432 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1433 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1436 /* find deleted tnbrs */
1437 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1438 switch (ldpd_process
) {
1439 case PROC_LDP_ENGINE
:
1440 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1441 tnbr_check(conf
, tnbr
);
1443 case PROC_LDE_ENGINE
:
1445 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1451 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1452 /* find new tnbrs */
1453 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1455 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1457 switch (ldpd_process
) {
1458 case PROC_LDP_ENGINE
:
1461 case PROC_LDE_ENGINE
:
1468 /* update existing tnbrs */
1469 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1470 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1475 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1477 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1481 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1482 /* find deleted nbrps */
1483 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
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);
1493 (ldp_af_global_get(&global
,
1494 nbr
->af
))->ldp_session_socket
,
1495 nbr
->af
, &nbr
->raddr
, NULL
);
1497 nbr
->auth
.method
= AUTH_NONE
;
1498 if (nbr_session_active_role(nbr
))
1499 nbr_establish_connection(nbr
);
1502 case PROC_LDE_ENGINE
:
1506 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1510 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1511 /* find new nbrps */
1512 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1514 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1516 switch (ldpd_process
) {
1517 case PROC_LDP_ENGINE
:
1518 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1520 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1521 nbr
->auth
.method
= nbrp
->auth
.method
;
1523 if (pfkey_establish(nbr
, nbrp
) == -1)
1524 fatalx("pfkey setup failed");
1527 (ldp_af_global_get(&global
,
1528 nbr
->af
))->ldp_session_socket
,
1529 nbr
->af
, &nbr
->raddr
,
1532 if (nbr_session_active_role(nbr
))
1533 nbr_establish_connection(nbr
);
1536 case PROC_LDE_ENGINE
:
1543 /* update existing nbrps */
1544 if (nbrp
->flags
!= xn
->flags
||
1545 nbrp
->keepalive
!= xn
->keepalive
||
1546 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1547 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1548 nbrp
->auth
.method
!= xn
->auth
.method
||
1549 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1554 nbrp
->keepalive
= xn
->keepalive
;
1555 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1556 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1557 nbrp
->auth
.method
= xn
->auth
.method
;
1558 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1559 sizeof(nbrp
->auth
.md5key
));
1560 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1561 nbrp
->flags
= xn
->flags
;
1563 if (ldpd_process
== PROC_LDP_ENGINE
) {
1564 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1565 if (nbr
&& nbrp_changed
) {
1566 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1569 nbr
->auth
.method
= nbrp
->auth
.method
;
1570 if (pfkey_establish(nbr
, nbrp
) == -1)
1571 fatalx("pfkey setup failed");
1573 nbr
->auth
.method
= nbrp
->auth
.method
;
1574 sock_set_md5sig((ldp_af_global_get(&global
,
1575 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1576 &nbr
->raddr
, nbrp
->auth
.md5key
);
1578 if (nbr_session_active_role(nbr
))
1579 nbr_establish_connection(nbr
);
1586 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1588 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1590 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1591 /* find deleted l2vpns */
1592 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1593 switch (ldpd_process
) {
1594 case PROC_LDE_ENGINE
:
1597 case PROC_LDP_ENGINE
:
1598 ldpe_l2vpn_exit(l2vpn
);
1603 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1607 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1608 /* find new l2vpns */
1609 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1611 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1612 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1613 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1614 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1616 switch (ldpd_process
) {
1617 case PROC_LDE_ENGINE
:
1620 case PROC_LDP_ENGINE
:
1621 ldpe_l2vpn_init(l2vpn
);
1628 /* update existing l2vpns */
1629 merge_l2vpn(conf
, l2vpn
, xl
);
1634 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1636 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1637 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1639 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1640 int previous_pw_type
, previous_mtu
;
1642 previous_pw_type
= l2vpn
->pw_type
;
1643 previous_mtu
= l2vpn
->mtu
;
1645 /* merge intefaces */
1646 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1647 /* find deleted interfaces */
1648 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1649 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1653 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1654 /* find new interfaces */
1655 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1657 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1660 switch (ldpd_process
) {
1661 case PROC_LDP_ENGINE
:
1662 case PROC_LDE_ENGINE
:
1665 kif_redistribute(lif
->ifname
);
1671 /* merge active pseudowires */
1672 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1673 /* find deleted active pseudowires */
1674 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1675 switch (ldpd_process
) {
1676 case PROC_LDE_ENGINE
:
1679 case PROC_LDP_ENGINE
:
1680 ldpe_l2vpn_pw_exit(pw
);
1686 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1690 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1691 /* find new active pseudowires */
1692 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1694 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1697 switch (ldpd_process
) {
1698 case PROC_LDE_ENGINE
:
1701 case PROC_LDP_ENGINE
:
1702 ldpe_l2vpn_pw_init(pw
);
1705 kif_redistribute(pw
->ifname
);
1711 /* update existing active pseudowire */
1712 if (pw
->af
!= xp
->af
||
1713 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1718 /* changes that require a session restart */
1719 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1720 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1725 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1726 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1727 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1728 reinstall_pwfec
= 1;
1730 reinstall_pwfec
= 0;
1732 if (ldpd_process
== PROC_LDP_ENGINE
) {
1734 ldpe_l2vpn_pw_exit(pw
);
1736 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1737 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1738 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1741 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1743 pw
->lsr_id
= xp
->lsr_id
;
1745 pw
->addr
= xp
->addr
;
1746 pw
->pwid
= xp
->pwid
;
1747 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1748 pw
->ifindex
= xp
->ifindex
;
1749 if (xp
->flags
& F_PW_CWORD_CONF
)
1750 pw
->flags
|= F_PW_CWORD_CONF
;
1752 pw
->flags
&= ~F_PW_CWORD_CONF
;
1753 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1754 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1756 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1757 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1758 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1760 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1761 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1762 ldpe_l2vpn_pw_init(pw
);
1763 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1764 l2vpn
->pw_type
= xl
->pw_type
;
1765 l2vpn
->mtu
= xl
->mtu
;
1767 l2vpn
->pw_type
= previous_pw_type
;
1768 l2vpn
->mtu
= previous_mtu
;
1772 /* merge inactive pseudowires */
1773 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1774 /* find deleted inactive pseudowires */
1775 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1776 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1780 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1781 /* find new inactive pseudowires */
1782 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1784 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1787 switch (ldpd_process
) {
1788 case PROC_LDE_ENGINE
:
1789 case PROC_LDP_ENGINE
:
1792 kif_redistribute(pw
->ifname
);
1798 /* update existing inactive pseudowire */
1799 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1801 pw
->addr
= xp
->addr
;
1802 pw
->pwid
= xp
->pwid
;
1803 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1804 pw
->ifindex
= xp
->ifindex
;
1805 pw
->flags
= xp
->flags
;
1808 l2vpn
->pw_type
= xl
->pw_type
;
1809 l2vpn
->mtu
= xl
->mtu
;
1810 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1811 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1815 config_new_empty(void)
1817 struct ldpd_conf
*xconf
;
1819 xconf
= calloc(1, sizeof(*xconf
));
1823 RB_INIT(iface_head
, &xconf
->iface_tree
);
1824 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1825 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1826 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1828 /* set default values */
1829 ldp_config_reset(xconf
);
1835 config_clear(struct ldpd_conf
*conf
)
1837 struct ldpd_conf
*xconf
;
1840 * Merge current config with an empty config, this will deactivate
1841 * and deallocate all the interfaces, pseudowires and so on. Before
1842 * merging, copy the router-id and other variables to avoid some
1843 * unnecessary operations, like trying to reset the neighborships.
1845 xconf
= config_new_empty();
1846 xconf
->ipv4
= conf
->ipv4
;
1847 xconf
->ipv6
= conf
->ipv6
;
1848 xconf
->rtr_id
= conf
->rtr_id
;
1849 xconf
->trans_pref
= conf
->trans_pref
;
1850 xconf
->flags
= conf
->flags
;
1851 merge_config(conf
, xconf
);