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
,
191 main(int argc
, char *argv
[])
194 int lflag
= 0, eflag
= 0;
195 int pipe_parent2ldpe
[2], pipe_parent2ldpe_sync
[2];
196 int pipe_parent2lde
[2], pipe_parent2lde_sync
[2];
199 ldpd_process
= PROC_MAIN
;
200 log_procname
= log_procnames
[ldpd_process
];
202 saved_argv0
= argv
[0];
203 if (saved_argv0
== NULL
)
204 saved_argv0
= (char *)"ldpd";
206 frr_preinit(&ldpd_di
, argc
, argv
);
207 frr_opt_add("LEn:", longopts
,
208 " --ctl_socket Override ctl socket path\n"
209 " -n, --instance Instance id\n");
214 opt
= frr_getopt(argc
, argv
, NULL
);
223 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
229 * LDPD_SOCKET configured as relative path
230 * during config? Should really never happen for
233 ctl_sock_name
= (char *)LDPD_SOCKET
;
234 strlcpy(ctl_sock_path
, optarg
, sizeof(ctl_sock_path
));
235 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
236 strlcat(ctl_sock_path
, ctl_sock_name
,
237 sizeof(ctl_sock_path
));
240 init
.instance
= atoi(optarg
);
241 if (init
.instance
< 1)
256 strlcpy(init
.user
, ldpd_privs
.user
, sizeof(init
.user
));
257 strlcpy(init
.group
, ldpd_privs
.group
, sizeof(init
.group
));
258 strlcpy(init
.ctl_sock_path
, ctl_sock_path
, sizeof(init
.ctl_sock_path
));
259 strlcpy(init
.zclient_serv_path
, frr_zclientpath
,
260 sizeof(init
.zclient_serv_path
));
263 if (argc
> 0 || (lflag
&& eflag
))
266 /* check for root privileges */
267 if (geteuid() != 0) {
269 perror(ldpd_di
.progname
);
274 openzlog(ldpd_di
.progname
, "LDP", 0,
275 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
281 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
283 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
284 pipe_parent2ldpe_sync
) == -1)
286 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
288 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
,
289 pipe_parent2lde_sync
) == -1)
291 sock_set_nonblock(pipe_parent2ldpe
[0]);
292 sock_set_cloexec(pipe_parent2ldpe
[0]);
293 sock_set_nonblock(pipe_parent2ldpe
[1]);
294 sock_set_cloexec(pipe_parent2ldpe
[1]);
295 sock_set_nonblock(pipe_parent2ldpe_sync
[0]);
296 sock_set_cloexec(pipe_parent2ldpe_sync
[0]);
297 sock_set_cloexec(pipe_parent2ldpe_sync
[1]);
298 sock_set_nonblock(pipe_parent2lde
[0]);
299 sock_set_cloexec(pipe_parent2lde
[0]);
300 sock_set_nonblock(pipe_parent2lde
[1]);
301 sock_set_cloexec(pipe_parent2lde
[1]);
302 sock_set_nonblock(pipe_parent2lde_sync
[0]);
303 sock_set_cloexec(pipe_parent2lde_sync
[0]);
304 sock_set_cloexec(pipe_parent2lde_sync
[1]);
307 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
308 pipe_parent2lde
[1], pipe_parent2lde_sync
[1]);
309 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
310 pipe_parent2ldpe
[1], pipe_parent2ldpe_sync
[1]);
314 vty_config_lockless();
315 vrf_init(NULL
, NULL
, NULL
, NULL
);
318 ldp_zebra_init(master
);
321 * Create base configuration with sane defaults. All configuration
322 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
323 * to merge the changes into ldpd_conf, which contains the actual
324 * running configuration.
326 ldpd_conf
= config_new_empty();
327 vty_conf
= config_new_empty();
328 QOBJ_REG(vty_conf
, ldpd_conf
);
330 /* read configuration file and daemonize */
333 /* apply configuration */
334 ldp_config_apply(NULL
, vty_conf
);
336 /* setup pipes to children */
337 if ((iev_ldpe
= calloc(1, sizeof(struct imsgev
))) == NULL
||
338 (iev_ldpe_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
||
339 (iev_lde
= calloc(1, sizeof(struct imsgev
))) == NULL
||
340 (iev_lde_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
342 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
343 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
344 iev_ldpe
->ev_read
= NULL
;
345 thread_add_read(master
, iev_ldpe
->handler_read
, iev_ldpe
, iev_ldpe
->ibuf
.fd
,
347 iev_ldpe
->handler_write
= ldp_write_handler
;
349 imsg_init(&iev_ldpe_sync
->ibuf
, pipe_parent2ldpe_sync
[0]);
350 iev_ldpe_sync
->handler_read
= main_dispatch_ldpe
;
351 iev_ldpe_sync
->ev_read
= NULL
;
352 thread_add_read(master
, iev_ldpe_sync
->handler_read
, iev_ldpe_sync
, iev_ldpe_sync
->ibuf
.fd
,
353 &iev_ldpe_sync
->ev_read
);
354 iev_ldpe_sync
->handler_write
= ldp_write_handler
;
356 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
357 iev_lde
->handler_read
= main_dispatch_lde
;
358 iev_lde
->ev_read
= NULL
;
359 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
361 iev_lde
->handler_write
= ldp_write_handler
;
363 imsg_init(&iev_lde_sync
->ibuf
, pipe_parent2lde_sync
[0]);
364 iev_lde_sync
->handler_read
= main_dispatch_lde
;
365 iev_lde_sync
->ev_read
= NULL
;
366 thread_add_read(master
, iev_lde_sync
->handler_read
, iev_lde_sync
, iev_lde_sync
->ibuf
.fd
,
367 &iev_lde_sync
->ev_read
);
368 iev_lde_sync
->handler_write
= ldp_write_handler
;
370 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
371 fatal("could not establish imsg links");
372 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
374 main_imsg_compose_both(IMSG_INIT
, &init
, sizeof(init
));
375 main_imsg_send_config(ldpd_conf
);
377 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
378 main_imsg_send_net_sockets(AF_INET
);
379 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
380 main_imsg_send_net_sockets(AF_INET6
);
397 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
398 close(iev_ldpe
->ibuf
.fd
);
399 msgbuf_clear(&iev_lde
->ibuf
.w
);
400 close(iev_lde
->ibuf
.fd
);
402 config_clear(ldpd_conf
);
404 ldp_config_reset(vty_conf
);
405 QOBJ_UNREG(vty_conf
);
408 log_debug("waiting for children to terminate");
412 if (errno
!= EINTR
&& errno
!= ECHILD
)
414 } else if (WIFSIGNALED(status
))
415 log_warnx("%s terminated; signal %d",
416 (pid
== lde_pid
) ? "label decision engine" :
417 "ldp engine", WTERMSIG(status
));
418 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
423 log_info("terminating");
434 start_child(enum ldpd_process p
, char *argv0
, int fd_async
, int fd_sync
)
437 int argc
= 0, nullfd
;
440 switch (pid
= fork()) {
442 fatal("cannot fork");
451 nullfd
= open("/dev/null", O_RDONLY
| O_NOCTTY
);
453 zlog_err("%s: failed to open /dev/null: %s", __func__
,
454 safe_strerror(errno
));
462 if (dup2(fd_async
, LDPD_FD_ASYNC
) == -1)
463 fatal("cannot setup imsg async fd");
464 if (dup2(fd_sync
, LDPD_FD_SYNC
) == -1)
465 fatal("cannot setup imsg sync fd");
467 argv
[argc
++] = argv0
;
470 fatalx("Can not start main process");
471 case PROC_LDE_ENGINE
:
472 argv
[argc
++] = (char *)"-L";
474 case PROC_LDP_ENGINE
:
475 argv
[argc
++] = (char *)"-E";
487 main_dispatch_ldpe(struct thread
*thread
)
489 struct imsgev
*iev
= THREAD_ARG(thread
);
490 struct imsgbuf
*ibuf
= &iev
->ibuf
;
498 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
499 fatal("imsg_read error");
500 if (n
== 0) /* connection closed */
504 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
510 switch (imsg
.hdr
.type
) {
512 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
514 case IMSG_REQUEST_SOCKETS
:
516 main_imsg_send_net_sockets(af
);
519 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
520 sizeof(struct acl_check
))
521 fatalx("IMSG_ACL_CHECK imsg with wrong len");
522 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
525 log_debug("%s: error handling imsg %d", __func__
,
534 /* this pipe is dead, so remove the event handlers and exit */
535 THREAD_READ_OFF(iev
->ev_read
);
536 THREAD_WRITE_OFF(iev
->ev_write
);
541 kill(lde_pid
, SIGTERM
);
549 main_dispatch_lde(struct thread
*thread
)
551 struct imsgev
*iev
= THREAD_ARG(thread
);
552 struct imsgbuf
*ibuf
= &iev
->ibuf
;
559 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
560 fatal("imsg_read error");
561 if (n
== 0) /* connection closed */
565 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
571 switch (imsg
.hdr
.type
) {
573 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
575 case IMSG_KLABEL_CHANGE
:
576 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
577 sizeof(struct kroute
))
578 fatalx("invalid size of IMSG_KLABEL_CHANGE");
579 if (kr_change(imsg
.data
))
580 log_warnx("%s: error changing route", __func__
);
582 case IMSG_KLABEL_DELETE
:
583 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
584 sizeof(struct kroute
))
585 fatalx("invalid size of IMSG_KLABEL_DELETE");
586 if (kr_delete(imsg
.data
))
587 log_warnx("%s: error deleting route", __func__
);
590 case IMSG_KPW_DELETE
:
593 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
594 sizeof(struct zapi_pw
))
595 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
597 switch (imsg
.hdr
.type
) {
599 if (kmpw_add(imsg
.data
))
600 log_warnx("%s: error adding "
601 "pseudowire", __func__
);
603 case IMSG_KPW_DELETE
:
604 if (kmpw_del(imsg
.data
))
605 log_warnx("%s: error deleting "
606 "pseudowire", __func__
);
609 if (kmpw_set(imsg
.data
))
610 log_warnx("%s: error setting "
611 "pseudowire", __func__
);
614 if (kmpw_unset(imsg
.data
))
615 log_warnx("%s: error unsetting "
616 "pseudowire", __func__
);
621 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
622 sizeof(struct acl_check
))
623 fatalx("IMSG_ACL_CHECK imsg with wrong len");
624 ldp_acl_reply(iev
, (struct acl_check
*)imsg
.data
);
627 log_debug("%s: error handling imsg %d", __func__
,
636 /* this pipe is dead, so remove the event handlers and exit */
637 THREAD_READ_OFF(iev
->ev_read
);
638 THREAD_WRITE_OFF(iev
->ev_write
);
643 kill(ldpe_pid
, SIGTERM
);
651 ldp_write_handler(struct thread
*thread
)
653 struct imsgev
*iev
= THREAD_ARG(thread
);
654 struct imsgbuf
*ibuf
= &iev
->ibuf
;
657 iev
->ev_write
= NULL
;
659 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
660 fatal("msgbuf_write");
662 /* this pipe is dead, so remove the event handlers */
663 THREAD_READ_OFF(iev
->ev_read
);
664 THREAD_WRITE_OFF(iev
->ev_write
);
674 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
676 if (iev_ldpe
== NULL
)
678 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
682 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
684 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
688 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
690 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
692 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
694 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
700 imsg_event_add(struct imsgev
*iev
)
702 if (iev
->handler_read
)
703 thread_add_read(master
, iev
->handler_read
, iev
, iev
->ibuf
.fd
,
706 if (iev
->handler_write
&& iev
->ibuf
.w
.queued
)
707 thread_add_write(master
, iev
->handler_write
, iev
,
708 iev
->ibuf
.fd
, &iev
->ev_write
);
712 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
713 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
717 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
718 pid
, fd
, data
, datalen
)) != -1)
724 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
726 ibuf_close(&eb
->wbuf
, buf
);
731 evbuf_event_add(struct evbuf
*eb
)
734 thread_add_write(master
, eb
->handler
, eb
->arg
, eb
->wbuf
.fd
,
739 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
742 msgbuf_init(&eb
->wbuf
);
744 eb
->handler
= handler
;
749 evbuf_clear(struct evbuf
*eb
)
751 THREAD_WRITE_OFF(eb
->ev
);
752 msgbuf_clear(&eb
->wbuf
);
757 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
759 int pipe_ldpe2lde
[2];
761 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
763 sock_set_nonblock(pipe_ldpe2lde
[0]);
764 sock_set_nonblock(pipe_ldpe2lde
[1]);
766 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
769 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
777 main_imsg_send_net_sockets(int af
)
779 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
782 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
783 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
784 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
785 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
789 main_imsg_send_net_socket(int af
, enum socket_type type
)
793 fd
= ldp_create_socket(af
, type
);
795 log_warnx("%s: failed to create %s socket for address-family "
796 "%s", __func__
, socket_name(type
), af_name(af
));
800 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
805 ldp_acl_request(struct imsgev
*iev
, char *acl_name
, int af
,
806 union ldpd_addr
*addr
, uint8_t prefixlen
)
810 struct acl_check acl_check
;
812 if (acl_name
[0] == '\0')
813 return FILTER_PERMIT
;
816 strlcpy(acl_check
.acl
, acl_name
, sizeof(acl_check
.acl
));
818 acl_check
.addr
= *addr
;
819 acl_check
.prefixlen
= prefixlen
;
821 /* send (blocking) */
822 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &acl_check
,
824 imsg_flush(&iev
->ibuf
);
826 /* receive (blocking) and parse result */
827 if ((n
= imsg_read(&iev
->ibuf
)) == -1)
828 fatal("imsg_read error");
829 if ((n
= imsg_get(&iev
->ibuf
, &imsg
)) == -1)
831 if (imsg
.hdr
.type
!= IMSG_ACL_CHECK
||
832 imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+ sizeof(int))
833 fatalx("ldp_acl_request: invalid response");
835 return (*((int *)imsg
.data
));
839 ldp_acl_reply(struct imsgev
*iev
, struct acl_check
*acl_check
)
841 struct access_list
*alist
;
842 struct prefix prefix
;
845 alist
= access_list_lookup(family2afi(acl_check
->af
), acl_check
->acl
);
847 result
= FILTER_DENY
;
849 prefix
.family
= acl_check
->af
;
850 switch (prefix
.family
) {
852 prefix
.u
.prefix4
= acl_check
->addr
.v4
;
855 prefix
.u
.prefix6
= acl_check
->addr
.v6
;
858 fatalx("ldp_acl_reply: unknown af");
860 prefix
.prefixlen
= acl_check
->prefixlen
;
861 result
= access_list_apply(alist
, &prefix
);
864 imsg_compose_event(iev
, IMSG_ACL_CHECK
, 0, 0, -1, &result
,
868 struct ldpd_af_conf
*
869 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
873 return (&xconf
->ipv4
);
875 return (&xconf
->ipv6
);
877 fatalx("ldp_af_conf_get: unknown af");
881 struct ldpd_af_global
*
882 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
886 return (&xglobal
->ipv4
);
888 return (&xglobal
->ipv6
);
890 fatalx("ldp_af_global_get: unknown af");
895 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
897 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
898 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
902 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
904 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
905 return (xconf
->rtr_id
.s_addr
);
907 return (global
.rtr_id
.s_addr
);
911 main_imsg_send_config(struct ldpd_conf
*xconf
)
915 struct nbr_params
*nbrp
;
917 struct l2vpn_if
*lif
;
920 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
921 sizeof(*xconf
)) == -1)
924 RB_FOREACH(iface
, iface_head
, &xconf
->iface_tree
) {
925 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
926 sizeof(*iface
)) == -1)
930 RB_FOREACH(tnbr
, tnbr_head
, &xconf
->tnbr_tree
) {
931 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
932 sizeof(*tnbr
)) == -1)
936 RB_FOREACH(nbrp
, nbrp_head
, &xconf
->nbrp_tree
) {
937 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
938 sizeof(*nbrp
)) == -1)
942 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
943 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
944 sizeof(*l2vpn
)) == -1)
947 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
) {
948 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
952 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
) {
953 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
957 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
) {
958 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
964 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
971 ldp_config_apply(struct vty
*vty
, struct ldpd_conf
*xconf
)
974 * When reading from a configuration file (startup and sighup), we
975 * call merge_config() only once after the whole config has been read.
976 * This is the optimal and least disruptive way to update the running
979 if (vty
&& vty
->type
== VTY_FILE
)
982 ldp_config_normalize(xconf
);
984 if (main_imsg_send_config(xconf
) == -1)
987 merge_config(ldpd_conf
, xconf
);
993 ldp_config_normalize(struct ldpd_conf
*xconf
)
995 struct iface
*iface
, *itmp
;
996 struct nbr_params
*nbrp
, *ntmp
;
998 struct l2vpn_pw
*pw
, *ptmp
;
1000 if (!(xconf
->flags
& F_LDPD_ENABLED
))
1001 ldp_config_reset_main(xconf
);
1003 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
1004 ldp_config_reset_af(xconf
, AF_INET
);
1005 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
1006 ldp_config_reset_af(xconf
, AF_INET6
);
1008 RB_FOREACH_SAFE(iface
, iface_head
, &xconf
->iface_tree
, itmp
) {
1009 if (iface
->ipv4
.enabled
|| iface
->ipv6
.enabled
)
1013 RB_REMOVE(iface_head
, &vty_conf
->iface_tree
, iface
);
1017 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1018 if (nbrp
->flags
& (F_NBRP_KEEPALIVE
|F_NBRP_GTSM
))
1020 if (nbrp
->auth
.method
!= AUTH_NONE
)
1024 RB_REMOVE(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1029 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
1030 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
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_tree
, pw
);
1039 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1041 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
,
1043 if (!(pw
->flags
& F_PW_STATIC_NBR_ADDR
)) {
1045 pw
->addr
.v4
= pw
->lsr_id
;
1048 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1050 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1051 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1057 ldp_config_reset(struct ldpd_conf
*conf
)
1059 ldp_config_reset_main(conf
);
1060 ldp_config_reset_l2vpns(conf
);
1064 ldp_config_reset_main(struct ldpd_conf
*conf
)
1066 struct iface
*iface
;
1067 struct nbr_params
*nbrp
;
1069 while ((iface
= RB_ROOT(iface_head
, &conf
->iface_tree
)) != NULL
) {
1071 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1075 while ((nbrp
= RB_ROOT(nbrp_head
, &conf
->nbrp_tree
)) != NULL
) {
1077 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1081 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1082 ldp_config_reset_af(conf
, AF_INET
);
1083 ldp_config_reset_af(conf
, AF_INET6
);
1084 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1085 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1086 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1087 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1088 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1093 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
)
1095 struct ldpd_af_conf
*af_conf
;
1096 struct iface
*iface
;
1097 struct iface_af
*ia
;
1098 struct tnbr
*tnbr
, *ttmp
;
1100 RB_FOREACH(iface
, iface_head
, &conf
->iface_tree
) {
1101 ia
= iface_af_get(iface
, af
);
1105 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1110 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1114 af_conf
= ldp_af_conf_get(conf
, af
);
1115 af_conf
->keepalive
= 180;
1116 af_conf
->lhello_holdtime
= 0;
1117 af_conf
->lhello_interval
= 0;
1118 af_conf
->thello_holdtime
= 0;
1119 af_conf
->thello_interval
= 0;
1120 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1125 ldp_config_reset_l2vpns(struct ldpd_conf
*conf
)
1127 struct l2vpn
*l2vpn
;
1128 struct l2vpn_if
*lif
;
1129 struct l2vpn_pw
*pw
;
1131 while ((l2vpn
= RB_ROOT(l2vpn_head
, &conf
->l2vpn_tree
)) != NULL
) {
1132 while ((lif
= RB_ROOT(l2vpn_if_head
,
1133 &l2vpn
->if_tree
)) != NULL
) {
1135 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1138 while ((pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
)) != NULL
) {
1140 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1143 while ((pw
= RB_ROOT(l2vpn_pw_head
,
1144 &l2vpn
->pw_inactive_tree
)) != NULL
) {
1146 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1150 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1156 ldp_clear_config(struct ldpd_conf
*xconf
)
1158 struct iface
*iface
;
1160 struct nbr_params
*nbrp
;
1161 struct l2vpn
*l2vpn
;
1163 while ((iface
= RB_ROOT(iface_head
, &xconf
->iface_tree
)) != NULL
) {
1164 RB_REMOVE(iface_head
, &xconf
->iface_tree
, iface
);
1167 while ((tnbr
= RB_ROOT(tnbr_head
, &xconf
->tnbr_tree
)) != NULL
) {
1168 RB_REMOVE(tnbr_head
, &xconf
->tnbr_tree
, tnbr
);
1171 while ((nbrp
= RB_ROOT(nbrp_head
, &xconf
->nbrp_tree
)) != NULL
) {
1172 RB_REMOVE(nbrp_head
, &xconf
->nbrp_tree
, nbrp
);
1175 while ((l2vpn
= RB_ROOT(l2vpn_head
, &xconf
->l2vpn_tree
)) != NULL
) {
1176 RB_REMOVE(l2vpn_head
, &xconf
->l2vpn_tree
, l2vpn
);
1183 #define COPY(a, b) do { \
1184 a = malloc(sizeof(*a)); \
1191 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1193 merge_global(conf
, xconf
);
1194 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1195 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1196 merge_ifaces(conf
, xconf
);
1197 merge_tnbrs(conf
, xconf
);
1198 merge_nbrps(conf
, xconf
);
1199 merge_l2vpns(conf
, xconf
);
1203 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1205 /* change of router-id requires resetting all neighborships */
1206 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1207 if (ldpd_process
== PROC_LDP_ENGINE
) {
1208 ldpe_reset_nbrs(AF_UNSPEC
);
1209 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1210 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1211 if_update_all(AF_UNSPEC
);
1212 tnbr_update_all(AF_UNSPEC
);
1215 conf
->rtr_id
= xconf
->rtr_id
;
1218 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1219 conf
->lhello_interval
= xconf
->lhello_interval
;
1220 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1221 conf
->thello_interval
= xconf
->thello_interval
;
1223 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1224 if (ldpd_process
== PROC_LDP_ENGINE
)
1225 ldpe_reset_ds_nbrs();
1226 conf
->trans_pref
= xconf
->trans_pref
;
1229 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1230 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1231 if (ldpd_process
== PROC_LDP_ENGINE
)
1232 ldpe_reset_ds_nbrs();
1235 conf
->flags
= xconf
->flags
;
1239 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1241 int stop_init_backoff
= 0;
1242 int remove_dynamic_tnbrs
= 0;
1243 int change_egress_label
= 0;
1244 int reset_nbrs_ipv4
= 0;
1246 int update_sockets
= 0;
1249 if (af_conf
->keepalive
!= xa
->keepalive
) {
1250 af_conf
->keepalive
= xa
->keepalive
;
1251 stop_init_backoff
= 1;
1253 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1254 af_conf
->lhello_interval
= xa
->lhello_interval
;
1255 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1256 af_conf
->thello_interval
= xa
->thello_interval
;
1259 if ((af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1260 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1261 remove_dynamic_tnbrs
= 1;
1262 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1263 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1265 /* need to set/unset IPV6_MINHOPCOUNT */
1268 /* for LDPv4 just resetting the neighbors is enough */
1269 reset_nbrs_ipv4
= 1;
1271 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1272 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1273 change_egress_label
= 1;
1274 af_conf
->flags
= xa
->flags
;
1276 /* update the transport address */
1277 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1278 af_conf
->trans_addr
= xa
->trans_addr
;
1283 if (strcmp(af_conf
->acl_label_advertise_to
,
1284 xa
->acl_label_advertise_to
) ||
1285 strcmp(af_conf
->acl_label_advertise_for
,
1286 xa
->acl_label_advertise_for
) ||
1287 strcmp(af_conf
->acl_label_accept_from
,
1288 xa
->acl_label_accept_from
) ||
1289 strcmp(af_conf
->acl_label_accept_for
,
1290 xa
->acl_label_accept_for
))
1292 if (strcmp(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
))
1293 remove_dynamic_tnbrs
= 1;
1294 if (strcmp(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
))
1295 change_egress_label
= 1;
1296 strlcpy(af_conf
->acl_thello_accept_from
, xa
->acl_thello_accept_from
,
1297 sizeof(af_conf
->acl_thello_accept_from
));
1298 strlcpy(af_conf
->acl_label_allocate_for
, xa
->acl_label_allocate_for
,
1299 sizeof(af_conf
->acl_label_allocate_for
));
1300 strlcpy(af_conf
->acl_label_advertise_to
, xa
->acl_label_advertise_to
,
1301 sizeof(af_conf
->acl_label_advertise_to
));
1302 strlcpy(af_conf
->acl_label_advertise_for
, xa
->acl_label_advertise_for
,
1303 sizeof(af_conf
->acl_label_advertise_for
));
1304 strlcpy(af_conf
->acl_label_accept_from
, xa
->acl_label_accept_from
,
1305 sizeof(af_conf
->acl_label_accept_from
));
1306 strlcpy(af_conf
->acl_label_accept_for
, xa
->acl_label_accept_for
,
1307 sizeof(af_conf
->acl_label_accept_for
));
1308 strlcpy(af_conf
->acl_label_expnull_for
, xa
->acl_label_expnull_for
,
1309 sizeof(af_conf
->acl_label_expnull_for
));
1311 /* apply the new configuration */
1312 switch (ldpd_process
) {
1313 case PROC_LDE_ENGINE
:
1314 if (change_egress_label
)
1315 lde_change_egress_label(af
);
1317 case PROC_LDP_ENGINE
:
1318 if (stop_init_backoff
)
1319 ldpe_stop_init_backoff(af
);
1320 if (remove_dynamic_tnbrs
)
1321 ldpe_remove_dynamic_tnbrs(af
);
1323 ldpe_reset_nbrs(AF_UNSPEC
);
1324 else if (reset_nbrs_ipv4
)
1325 ldpe_reset_nbrs(AF_INET
);
1328 if (update_sockets
&& iev_ldpe
)
1329 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
,
1336 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1338 struct iface
*iface
, *itmp
, *xi
;
1340 RB_FOREACH_SAFE(iface
, iface_head
, &conf
->iface_tree
, itmp
) {
1341 /* find deleted interfaces */
1342 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1343 switch (ldpd_process
) {
1344 case PROC_LDP_ENGINE
:
1345 ldpe_if_exit(iface
);
1347 case PROC_LDE_ENGINE
:
1351 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1355 RB_FOREACH_SAFE(xi
, iface_head
, &xconf
->iface_tree
, itmp
) {
1356 /* find new interfaces */
1357 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1359 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1361 switch (ldpd_process
) {
1362 case PROC_LDP_ENGINE
:
1363 ldpe_if_init(iface
);
1365 case PROC_LDE_ENGINE
:
1368 /* resend addresses to activate new interfaces */
1369 kif_redistribute(iface
->name
);
1375 /* update existing interfaces */
1376 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1377 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1382 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1384 if (ia
->enabled
!= xi
->enabled
) {
1385 ia
->enabled
= xi
->enabled
;
1386 if (ldpd_process
== PROC_LDP_ENGINE
)
1387 ldp_if_update(ia
->iface
, ia
->af
);
1389 ia
->hello_holdtime
= xi
->hello_holdtime
;
1390 ia
->hello_interval
= xi
->hello_interval
;
1394 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1396 struct tnbr
*tnbr
, *ttmp
, *xt
;
1398 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &conf
->tnbr_tree
, ttmp
) {
1399 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1402 /* find deleted tnbrs */
1403 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1404 switch (ldpd_process
) {
1405 case PROC_LDP_ENGINE
:
1406 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1407 tnbr_check(conf
, tnbr
);
1409 case PROC_LDE_ENGINE
:
1411 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1417 RB_FOREACH_SAFE(xt
, tnbr_head
, &xconf
->tnbr_tree
, ttmp
) {
1418 /* find new tnbrs */
1419 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1421 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1423 switch (ldpd_process
) {
1424 case PROC_LDP_ENGINE
:
1427 case PROC_LDE_ENGINE
:
1434 /* update existing tnbrs */
1435 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1436 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1441 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1443 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1447 RB_FOREACH_SAFE(nbrp
, nbrp_head
, &conf
->nbrp_tree
, ntmp
) {
1448 /* find deleted nbrps */
1449 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1450 switch (ldpd_process
) {
1451 case PROC_LDP_ENGINE
:
1452 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1454 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1459 (ldp_af_global_get(&global
,
1460 nbr
->af
))->ldp_session_socket
,
1461 nbr
->af
, &nbr
->raddr
, NULL
);
1463 nbr
->auth
.method
= AUTH_NONE
;
1464 if (nbr_session_active_role(nbr
))
1465 nbr_establish_connection(nbr
);
1468 case PROC_LDE_ENGINE
:
1472 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1476 RB_FOREACH_SAFE(xn
, nbrp_head
, &xconf
->nbrp_tree
, ntmp
) {
1477 /* find new nbrps */
1478 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1480 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1482 switch (ldpd_process
) {
1483 case PROC_LDP_ENGINE
:
1484 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1486 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1487 nbr
->auth
.method
= nbrp
->auth
.method
;
1489 if (pfkey_establish(nbr
, nbrp
) == -1)
1490 fatalx("pfkey setup failed");
1493 (ldp_af_global_get(&global
,
1494 nbr
->af
))->ldp_session_socket
,
1495 nbr
->af
, &nbr
->raddr
,
1498 if (nbr_session_active_role(nbr
))
1499 nbr_establish_connection(nbr
);
1502 case PROC_LDE_ENGINE
:
1509 /* update existing nbrps */
1510 if (nbrp
->flags
!= xn
->flags
||
1511 nbrp
->keepalive
!= xn
->keepalive
||
1512 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1513 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1514 nbrp
->auth
.method
!= xn
->auth
.method
||
1515 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1520 nbrp
->keepalive
= xn
->keepalive
;
1521 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1522 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1523 nbrp
->auth
.method
= xn
->auth
.method
;
1524 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1525 sizeof(nbrp
->auth
.md5key
));
1526 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1527 nbrp
->flags
= xn
->flags
;
1529 if (ldpd_process
== PROC_LDP_ENGINE
) {
1530 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1531 if (nbr
&& nbrp_changed
) {
1532 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1535 nbr
->auth
.method
= nbrp
->auth
.method
;
1536 if (pfkey_establish(nbr
, nbrp
) == -1)
1537 fatalx("pfkey setup failed");
1539 nbr
->auth
.method
= nbrp
->auth
.method
;
1540 sock_set_md5sig((ldp_af_global_get(&global
,
1541 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1542 &nbr
->raddr
, nbrp
->auth
.md5key
);
1544 if (nbr_session_active_role(nbr
))
1545 nbr_establish_connection(nbr
);
1552 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1554 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1556 RB_FOREACH_SAFE(l2vpn
, l2vpn_head
, &conf
->l2vpn_tree
, ltmp
) {
1557 /* find deleted l2vpns */
1558 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1559 switch (ldpd_process
) {
1560 case PROC_LDE_ENGINE
:
1563 case PROC_LDP_ENGINE
:
1564 ldpe_l2vpn_exit(l2vpn
);
1569 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1573 RB_FOREACH_SAFE(xl
, l2vpn_head
, &xconf
->l2vpn_tree
, ltmp
) {
1574 /* find new l2vpns */
1575 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1577 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1578 RB_INIT(l2vpn_if_head
, &l2vpn
->if_tree
);
1579 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1580 RB_INIT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1582 switch (ldpd_process
) {
1583 case PROC_LDE_ENGINE
:
1586 case PROC_LDP_ENGINE
:
1587 ldpe_l2vpn_init(l2vpn
);
1594 /* update existing l2vpns */
1595 merge_l2vpn(conf
, l2vpn
, xl
);
1600 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1602 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1603 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1605 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1606 int previous_pw_type
, previous_mtu
;
1608 previous_pw_type
= l2vpn
->pw_type
;
1609 previous_mtu
= l2vpn
->mtu
;
1611 /* merge intefaces */
1612 RB_FOREACH_SAFE(lif
, l2vpn_if_head
, &l2vpn
->if_tree
, ftmp
) {
1613 /* find deleted interfaces */
1614 if ((xf
= l2vpn_if_find(xl
, lif
->ifname
)) == NULL
) {
1615 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1619 RB_FOREACH_SAFE(xf
, l2vpn_if_head
, &xl
->if_tree
, ftmp
) {
1620 /* find new interfaces */
1621 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifname
)) == NULL
) {
1623 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1626 switch (ldpd_process
) {
1627 case PROC_LDP_ENGINE
:
1628 case PROC_LDE_ENGINE
:
1631 kif_redistribute(lif
->ifname
);
1637 /* merge active pseudowires */
1638 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
, ptmp
) {
1639 /* find deleted active pseudowires */
1640 if ((xp
= l2vpn_pw_find_active(xl
, pw
->ifname
)) == NULL
) {
1641 switch (ldpd_process
) {
1642 case PROC_LDE_ENGINE
:
1645 case PROC_LDP_ENGINE
:
1646 ldpe_l2vpn_pw_exit(pw
);
1652 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1656 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_tree
, ptmp
) {
1657 /* find new active pseudowires */
1658 if ((pw
= l2vpn_pw_find_active(l2vpn
, xp
->ifname
)) == NULL
) {
1660 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1663 switch (ldpd_process
) {
1664 case PROC_LDE_ENGINE
:
1667 case PROC_LDP_ENGINE
:
1668 ldpe_l2vpn_pw_init(pw
);
1671 kif_redistribute(pw
->ifname
);
1677 /* update existing active pseudowire */
1678 if (pw
->af
!= xp
->af
||
1679 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1684 /* changes that require a session restart */
1685 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1686 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1691 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1692 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1693 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1694 reinstall_pwfec
= 1;
1696 reinstall_pwfec
= 0;
1698 if (ldpd_process
== PROC_LDP_ENGINE
) {
1700 ldpe_l2vpn_pw_exit(pw
);
1702 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1703 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1704 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1707 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
)
1709 pw
->lsr_id
= xp
->lsr_id
;
1711 pw
->addr
= xp
->addr
;
1712 pw
->pwid
= xp
->pwid
;
1713 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1714 pw
->ifindex
= xp
->ifindex
;
1715 if (xp
->flags
& F_PW_CWORD_CONF
)
1716 pw
->flags
|= F_PW_CWORD_CONF
;
1718 pw
->flags
&= ~F_PW_CWORD_CONF
;
1719 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1720 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1722 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1723 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1724 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1726 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1727 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1728 ldpe_l2vpn_pw_init(pw
);
1729 if (ldpd_process
== PROC_LDE_ENGINE
&& reinstall_pwfec
) {
1730 l2vpn
->pw_type
= xl
->pw_type
;
1731 l2vpn
->mtu
= xl
->mtu
;
1733 l2vpn
->pw_type
= previous_pw_type
;
1734 l2vpn
->mtu
= previous_mtu
;
1738 /* merge inactive pseudowires */
1739 RB_FOREACH_SAFE(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, ptmp
) {
1740 /* find deleted inactive pseudowires */
1741 if ((xp
= l2vpn_pw_find_inactive(xl
, pw
->ifname
)) == NULL
) {
1742 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1746 RB_FOREACH_SAFE(xp
, l2vpn_pw_head
, &xl
->pw_inactive_tree
, ptmp
) {
1747 /* find new inactive pseudowires */
1748 if ((pw
= l2vpn_pw_find_inactive(l2vpn
, xp
->ifname
)) == NULL
) {
1750 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1753 switch (ldpd_process
) {
1754 case PROC_LDE_ENGINE
:
1755 case PROC_LDP_ENGINE
:
1758 kif_redistribute(pw
->ifname
);
1764 /* update existing inactive pseudowire */
1765 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
1767 pw
->addr
= xp
->addr
;
1768 pw
->pwid
= xp
->pwid
;
1769 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1770 pw
->ifindex
= xp
->ifindex
;
1771 pw
->flags
= xp
->flags
;
1774 l2vpn
->pw_type
= xl
->pw_type
;
1775 l2vpn
->mtu
= xl
->mtu
;
1776 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1777 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1781 config_new_empty(void)
1783 struct ldpd_conf
*xconf
;
1785 xconf
= calloc(1, sizeof(*xconf
));
1789 RB_INIT(iface_head
, &xconf
->iface_tree
);
1790 RB_INIT(tnbr_head
, &xconf
->tnbr_tree
);
1791 RB_INIT(nbrp_head
, &xconf
->nbrp_tree
);
1792 RB_INIT(l2vpn_head
, &xconf
->l2vpn_tree
);
1794 /* set default values */
1795 ldp_config_reset(xconf
);
1801 config_clear(struct ldpd_conf
*conf
)
1803 struct ldpd_conf
*xconf
;
1806 * Merge current config with an empty config, this will deactivate
1807 * and deallocate all the interfaces, pseudowires and so on. Before
1808 * merging, copy the router-id and other variables to avoid some
1809 * unnecessary operations, like trying to reset the neighborships.
1811 xconf
= config_new_empty();
1812 xconf
->ipv4
= conf
->ipv4
;
1813 xconf
->ipv6
= conf
->ipv6
;
1814 xconf
->rtr_id
= conf
->rtr_id
;
1815 xconf
->trans_pref
= conf
->trans_pref
;
1816 xconf
->flags
= conf
->flags
;
1817 merge_config(conf
, xconf
);