]>
git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldpd.c
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.
22 #include <sys/types.h>
38 static void main_sig_handler(int, short, void *);
39 static __dead
void usage(void);
40 static __dead
void ldpd_shutdown(void);
41 static pid_t
start_child(enum ldpd_process
, char *, int, int, int);
42 static void main_dispatch_ldpe(int, short, void *);
43 static void main_dispatch_lde(int, short, void *);
44 static int main_imsg_compose_both(enum imsg_type
, void *,
46 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
48 static void main_imsg_send_net_sockets(int);
49 static void main_imsg_send_net_socket(int, enum socket_type
);
50 static int main_imsg_send_config(struct ldpd_conf
*);
51 static int ldp_reload(void);
52 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
53 static void merge_af(int, struct ldpd_af_conf
*,
54 struct ldpd_af_conf
*);
55 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*);
56 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
57 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*);
58 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*);
59 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*);
60 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
63 struct ldpd_global global
;
64 struct ldpd_conf
*ldpd_conf
;
66 static char *conffile
;
67 static struct imsgev
*iev_ldpe
;
68 static struct imsgev
*iev_lde
;
69 static pid_t ldpe_pid
;
74 main_sig_handler(int sig
, short event
, void *arg
)
76 /* signal handler rules don't apply, libevent decouples for us */
83 if (ldp_reload() == -1)
84 log_warnx("configuration reload failed");
86 log_debug("configuration reloaded");
89 fatalx("unexpected signal");
97 extern char *__progname
;
99 fprintf(stderr
, "usage: %s [-dnv] [-D macro=value] [-f file]\n",
105 main(int argc
, char *argv
[])
107 struct event ev_sigint
, ev_sigterm
, ev_sighup
;
110 int debug
= 0, lflag
= 0, eflag
= 0;
111 int pipe_parent2ldpe
[2];
112 int pipe_parent2lde
[2];
114 conffile
= CONF_FILE
;
115 ldpd_process
= PROC_MAIN
;
117 log_init(1); /* log to stderr until daemonized */
120 saved_argv0
= argv
[0];
121 if (saved_argv0
== NULL
)
122 saved_argv0
= "ldpd";
124 while ((ch
= getopt(argc
, argv
, "dD:f:nvLE")) != -1) {
130 if (cmdline_symset(optarg
) < 0)
131 log_warnx("could not parse macro definition %s",
138 global
.cmd_opts
|= LDPD_OPT_NOACTION
;
141 if (global
.cmd_opts
& LDPD_OPT_VERBOSE
)
142 global
.cmd_opts
|= LDPD_OPT_VERBOSE2
;
143 global
.cmd_opts
|= LDPD_OPT_VERBOSE
;
159 if (argc
> 0 || (lflag
&& eflag
))
163 lde(debug
, global
.cmd_opts
& LDPD_OPT_VERBOSE
);
165 ldpe(debug
, global
.cmd_opts
& LDPD_OPT_VERBOSE
);
167 /* fetch interfaces early */
170 /* parse config file */
171 if ((ldpd_conf
= parse_config(conffile
)) == NULL
) {
176 if (global
.cmd_opts
& LDPD_OPT_NOACTION
) {
177 if (global
.cmd_opts
& LDPD_OPT_VERBOSE
)
178 print_config(ldpd_conf
);
180 fprintf(stderr
, "configuration OK\n");
185 /* check for root privileges */
187 errx(1, "need root privileges");
189 /* check for ldpd user */
190 if (getpwnam(LDPD_USER
) == NULL
)
191 errx(1, "unknown user %s", LDPD_USER
);
194 log_verbose(global
.cmd_opts
& (LDPD_OPT_VERBOSE
| LDPD_OPT_VERBOSE2
));
201 if (socketpair(AF_UNIX
, SOCK_STREAM
| SOCK_NONBLOCK
| SOCK_CLOEXEC
,
202 PF_UNSPEC
, pipe_parent2ldpe
) == -1)
204 if (socketpair(AF_UNIX
, SOCK_STREAM
| SOCK_NONBLOCK
| SOCK_CLOEXEC
,
205 PF_UNSPEC
, pipe_parent2lde
) == -1)
209 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
210 pipe_parent2lde
[1], debug
, global
.cmd_opts
& LDPD_OPT_VERBOSE
);
211 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
212 pipe_parent2ldpe
[1], debug
, global
.cmd_opts
& LDPD_OPT_VERBOSE
);
216 /* setup signal handler */
217 signal_set(&ev_sigint
, SIGINT
, main_sig_handler
, NULL
);
218 signal_set(&ev_sigterm
, SIGTERM
, main_sig_handler
, NULL
);
219 signal_set(&ev_sighup
, SIGHUP
, main_sig_handler
, NULL
);
220 signal_add(&ev_sigint
, NULL
);
221 signal_add(&ev_sigterm
, NULL
);
222 signal_add(&ev_sighup
, NULL
);
223 signal(SIGPIPE
, SIG_IGN
);
225 /* setup pipes to children */
226 if ((iev_ldpe
= malloc(sizeof(struct imsgev
))) == NULL
||
227 (iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
229 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
230 iev_ldpe
->handler
= main_dispatch_ldpe
;
231 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
232 iev_lde
->handler
= main_dispatch_lde
;
234 /* setup event handler */
235 iev_ldpe
->events
= EV_READ
;
236 event_set(&iev_ldpe
->ev
, iev_ldpe
->ibuf
.fd
, iev_ldpe
->events
,
237 iev_ldpe
->handler
, iev_ldpe
);
238 event_add(&iev_ldpe
->ev
, NULL
);
240 iev_lde
->events
= EV_READ
;
241 event_set(&iev_lde
->ev
, iev_lde
->ibuf
.fd
, iev_lde
->events
,
242 iev_lde
->handler
, iev_lde
);
243 event_add(&iev_lde
->ev
, NULL
);
245 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
246 fatal("could not establish imsg links");
247 main_imsg_send_config(ldpd_conf
);
249 /* notify ldpe about existing interfaces and addresses */
250 kif_redistribute(NULL
);
252 if (kr_init(!(ldpd_conf
->flags
& F_LDPD_NO_FIB_UPDATE
)) == -1)
253 fatalx("kr_init failed");
255 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
256 main_imsg_send_net_sockets(AF_INET
);
257 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
258 main_imsg_send_net_sockets(AF_INET6
);
260 /* remove unneded stuff from config */
277 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
278 close(iev_ldpe
->ibuf
.fd
);
279 msgbuf_clear(&iev_lde
->ibuf
.w
);
280 close(iev_lde
->ibuf
.fd
);
283 config_clear(ldpd_conf
);
285 log_debug("waiting for children to terminate");
289 if (errno
!= EINTR
&& errno
!= ECHILD
)
291 } else if (WIFSIGNALED(status
))
292 log_warnx("%s terminated; signal %d",
293 (pid
== lde_pid
) ? "label decision engine" :
294 "ldp engine", WTERMSIG(status
));
295 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
300 log_info("terminating");
305 start_child(enum ldpd_process p
, char *argv0
, int fd
, int debug
, int verbose
)
311 switch (pid
= fork()) {
313 fatal("cannot fork");
321 if (dup2(fd
, 3) == -1)
322 fatal("cannot setup imsg fd");
324 argv
[argc
++] = argv0
;
327 fatalx("Can not start main process");
328 case PROC_LDE_ENGINE
:
331 case PROC_LDP_ENGINE
:
348 main_dispatch_ldpe(int fd
, short event
, void *bula
)
350 struct imsgev
*iev
= bula
;
351 struct imsgbuf
*ibuf
= &iev
->ibuf
;
355 int shut
= 0, verbose
;
357 if (event
& EV_READ
) {
358 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
359 fatal("imsg_read error");
360 if (n
== 0) /* connection closed */
363 if (event
& EV_WRITE
) {
364 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
365 fatal("msgbuf_write");
371 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
377 switch (imsg
.hdr
.type
) {
378 case IMSG_REQUEST_SOCKETS
:
380 main_imsg_send_net_sockets(af
);
382 case IMSG_CTL_RELOAD
:
383 if (ldp_reload() == -1)
384 log_warnx("configuration reload failed");
386 log_debug("configuration reloaded");
388 case IMSG_CTL_FIB_COUPLE
:
391 case IMSG_CTL_FIB_DECOUPLE
:
394 case IMSG_CTL_KROUTE
:
395 case IMSG_CTL_KROUTE_ADDR
:
396 kr_show_route(&imsg
);
398 case IMSG_CTL_IFINFO
:
399 if (imsg
.hdr
.len
== IMSG_HEADER_SIZE
)
400 kr_ifinfo(NULL
, imsg
.hdr
.pid
);
401 else if (imsg
.hdr
.len
== IMSG_HEADER_SIZE
+ IFNAMSIZ
)
402 kr_ifinfo(imsg
.data
, imsg
.hdr
.pid
);
404 log_warnx("IFINFO request with wrong len");
406 case IMSG_CTL_LOG_VERBOSE
:
407 /* already checked by ldpe */
408 memcpy(&verbose
, imsg
.data
, sizeof(verbose
));
409 log_verbose(verbose
);
412 log_debug("%s: error handling imsg %d", __func__
,
421 /* this pipe is dead, so remove the event handler */
423 event_loopexit(NULL
);
429 main_dispatch_lde(int fd
, short event
, void *bula
)
431 struct imsgev
*iev
= bula
;
432 struct imsgbuf
*ibuf
= &iev
->ibuf
;
437 if (event
& EV_READ
) {
438 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
439 fatal("imsg_read error");
440 if (n
== 0) /* connection closed */
443 if (event
& EV_WRITE
) {
444 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
445 fatal("msgbuf_write");
451 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
457 switch (imsg
.hdr
.type
) {
458 case IMSG_KLABEL_CHANGE
:
459 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
460 sizeof(struct kroute
))
461 fatalx("invalid size of IMSG_KLABEL_CHANGE");
462 if (kr_change(imsg
.data
))
463 log_warnx("%s: error changing route", __func__
);
465 case IMSG_KLABEL_DELETE
:
466 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
467 sizeof(struct kroute
))
468 fatalx("invalid size of IMSG_KLABEL_DELETE");
469 if (kr_delete(imsg
.data
))
470 log_warnx("%s: error deleting route", __func__
);
472 case IMSG_KPWLABEL_CHANGE
:
473 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
475 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
476 if (kmpw_set(imsg
.data
))
477 log_warnx("%s: error changing pseudowire",
480 case IMSG_KPWLABEL_DELETE
:
481 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
483 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
484 if (kmpw_unset(imsg
.data
))
485 log_warnx("%s: error unsetting pseudowire",
489 log_debug("%s: error handling imsg %d", __func__
,
498 /* this pipe is dead, so remove the event handler */
500 event_loopexit(NULL
);
505 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
507 if (iev_ldpe
== NULL
)
509 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
513 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
515 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
519 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
521 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
523 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
529 imsg_event_add(struct imsgev
*iev
)
531 iev
->events
= EV_READ
;
532 if (iev
->ibuf
.w
.queued
)
533 iev
->events
|= EV_WRITE
;
536 event_set(&iev
->ev
, iev
->ibuf
.fd
, iev
->events
, iev
->handler
, iev
);
537 event_add(&iev
->ev
, NULL
);
541 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
542 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
546 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
547 pid
, fd
, data
, datalen
)) != -1)
553 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
555 ibuf_close(&eb
->wbuf
, buf
);
560 evbuf_event_add(struct evbuf
*eb
)
563 event_add(&eb
->ev
, NULL
);
567 evbuf_init(struct evbuf
*eb
, int fd
, void (*handler
)(int, short, void *),
570 msgbuf_init(&eb
->wbuf
);
572 event_set(&eb
->ev
, eb
->wbuf
.fd
, EV_WRITE
, handler
, arg
);
576 evbuf_clear(struct evbuf
*eb
)
579 msgbuf_clear(&eb
->wbuf
);
584 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
586 int pipe_ldpe2lde
[2];
588 if (socketpair(AF_UNIX
, SOCK_STREAM
| SOCK_CLOEXEC
| SOCK_NONBLOCK
,
589 PF_UNSPEC
, pipe_ldpe2lde
) == -1)
592 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
595 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
603 main_imsg_send_net_sockets(int af
)
605 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
606 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
607 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
608 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
612 main_imsg_send_net_socket(int af
, enum socket_type type
)
616 fd
= ldp_create_socket(af
, type
);
618 log_warnx("%s: failed to create %s socket for address-family "
619 "%s", __func__
, socket_name(type
), af_name(af
));
623 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
627 struct ldpd_af_conf
*
628 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
632 return (&xconf
->ipv4
);
634 return (&xconf
->ipv6
);
636 fatalx("ldp_af_conf_get: unknown af");
640 struct ldpd_af_global
*
641 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
645 return (&xglobal
->ipv4
);
647 return (&xglobal
->ipv6
);
649 fatalx("ldp_af_global_get: unknown af");
654 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
656 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
657 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
661 main_imsg_send_config(struct ldpd_conf
*xconf
)
665 struct nbr_params
*nbrp
;
667 struct l2vpn_if
*lif
;
670 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
671 sizeof(*xconf
)) == -1)
674 LIST_FOREACH(iface
, &xconf
->iface_list
, entry
) {
675 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
676 sizeof(*iface
)) == -1)
680 LIST_FOREACH(tnbr
, &xconf
->tnbr_list
, entry
) {
681 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
682 sizeof(*tnbr
)) == -1)
686 LIST_FOREACH(nbrp
, &xconf
->nbrp_list
, entry
) {
687 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
688 sizeof(*nbrp
)) == -1)
692 LIST_FOREACH(l2vpn
, &xconf
->l2vpn_list
, entry
) {
693 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
694 sizeof(*l2vpn
)) == -1)
697 LIST_FOREACH(lif
, &l2vpn
->if_list
, entry
) {
698 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
702 LIST_FOREACH(pw
, &l2vpn
->pw_list
, entry
) {
703 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
709 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
718 struct ldpd_conf
*xconf
;
720 if ((xconf
= parse_config(conffile
)) == NULL
)
723 if (main_imsg_send_config(xconf
) == -1)
726 merge_config(ldpd_conf
, xconf
);
732 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
734 merge_global(conf
, xconf
);
735 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
736 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
737 merge_ifaces(conf
, xconf
);
738 merge_tnbrs(conf
, xconf
);
739 merge_nbrps(conf
, xconf
);
740 merge_l2vpns(conf
, xconf
);
745 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
747 /* change of router-id requires resetting all neighborships */
748 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
749 if (ldpd_process
== PROC_LDP_ENGINE
) {
750 ldpe_reset_nbrs(AF_INET
);
751 ldpe_reset_nbrs(AF_INET6
);
752 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
753 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
754 if_update_all(AF_UNSPEC
);
755 tnbr_update_all(AF_UNSPEC
);
758 conf
->rtr_id
= xconf
->rtr_id
;
761 if (conf
->trans_pref
!= xconf
->trans_pref
) {
762 if (ldpd_process
== PROC_LDP_ENGINE
)
763 ldpe_reset_ds_nbrs();
764 conf
->trans_pref
= xconf
->trans_pref
;
767 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
768 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
769 if (ldpd_process
== PROC_LDP_ENGINE
)
770 ldpe_reset_ds_nbrs();
773 conf
->flags
= xconf
->flags
;
777 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
779 int egress_label_changed
= 0;
780 int update_sockets
= 0;
782 if (af_conf
->keepalive
!= xa
->keepalive
) {
783 af_conf
->keepalive
= xa
->keepalive
;
784 if (ldpd_process
== PROC_LDP_ENGINE
)
785 ldpe_stop_init_backoff(af
);
787 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
788 af_conf
->thello_interval
= xa
->thello_interval
;
791 if (ldpd_process
== PROC_LDP_ENGINE
&&
792 (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
793 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
794 ldpe_remove_dynamic_tnbrs(af
);
796 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
797 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
799 /* need to set/unset IPV6_MINHOPCOUNT */
801 else if (ldpd_process
== PROC_LDP_ENGINE
)
802 /* for LDPv4 just resetting the neighbors is enough */
806 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
807 (xa
->flags
& F_LDPD_AF_EXPNULL
))
808 egress_label_changed
= 1;
810 af_conf
->flags
= xa
->flags
;
812 if (egress_label_changed
) {
813 switch (ldpd_process
) {
814 case PROC_LDE_ENGINE
:
815 lde_change_egress_label(af
, af_conf
->flags
&
819 kr_change_egress_label(af
, af_conf
->flags
&
827 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
828 af_conf
->trans_addr
= xa
->trans_addr
;
832 if (ldpd_process
== PROC_MAIN
&& update_sockets
)
833 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
, 0, -1,
838 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
840 struct iface
*iface
, *itmp
, *xi
;
842 LIST_FOREACH_SAFE(iface
, &conf
->iface_list
, entry
, itmp
) {
843 /* find deleted interfaces */
844 if ((xi
= if_lookup(xconf
, iface
->ifindex
)) == NULL
) {
845 LIST_REMOVE(iface
, entry
);
846 if (ldpd_process
== PROC_LDP_ENGINE
)
851 LIST_FOREACH_SAFE(xi
, &xconf
->iface_list
, entry
, itmp
) {
852 /* find new interfaces */
853 if ((iface
= if_lookup(conf
, xi
->ifindex
)) == NULL
) {
854 LIST_REMOVE(xi
, entry
);
855 LIST_INSERT_HEAD(&conf
->iface_list
, xi
, entry
);
857 /* resend addresses to activate new interfaces */
858 if (ldpd_process
== PROC_MAIN
)
859 kif_redistribute(xi
->name
);
863 /* update existing interfaces */
864 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
865 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
866 LIST_REMOVE(xi
, entry
);
872 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
874 if (ia
->enabled
!= xi
->enabled
) {
875 ia
->enabled
= xi
->enabled
;
876 if (ldpd_process
== PROC_LDP_ENGINE
)
877 if_update(ia
->iface
, ia
->af
);
879 ia
->hello_holdtime
= xi
->hello_holdtime
;
880 ia
->hello_interval
= xi
->hello_interval
;
884 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
886 struct tnbr
*tnbr
, *ttmp
, *xt
;
888 LIST_FOREACH_SAFE(tnbr
, &conf
->tnbr_list
, entry
, ttmp
) {
889 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
892 /* find deleted tnbrs */
893 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
894 if (ldpd_process
== PROC_LDP_ENGINE
) {
895 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
898 LIST_REMOVE(tnbr
, entry
);
903 LIST_FOREACH_SAFE(xt
, &xconf
->tnbr_list
, entry
, ttmp
) {
905 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
906 LIST_REMOVE(xt
, entry
);
907 LIST_INSERT_HEAD(&conf
->tnbr_list
, xt
, entry
);
909 if (ldpd_process
== PROC_LDP_ENGINE
)
914 /* update existing tnbrs */
915 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
916 tnbr
->flags
|= F_TNBR_CONFIGURED
;
917 tnbr
->hello_holdtime
= xt
->hello_holdtime
;
918 tnbr
->hello_interval
= xt
->hello_interval
;
919 LIST_REMOVE(xt
, entry
);
925 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
927 struct nbr_params
*nbrp
, *ntmp
, *xn
;
931 LIST_FOREACH_SAFE(nbrp
, &conf
->nbrp_list
, entry
, ntmp
) {
932 /* find deleted nbrps */
933 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
934 if (ldpd_process
== PROC_LDP_ENGINE
) {
935 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
937 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
939 if (nbr_session_active_role(nbr
))
940 nbr_establish_connection(nbr
);
943 LIST_REMOVE(nbrp
, entry
);
947 LIST_FOREACH_SAFE(xn
, &xconf
->nbrp_list
, entry
, ntmp
) {
949 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
950 LIST_REMOVE(xn
, entry
);
951 LIST_INSERT_HEAD(&conf
->nbrp_list
, xn
, entry
);
953 if (ldpd_process
== PROC_LDP_ENGINE
) {
954 nbr
= nbr_find_ldpid(xn
->lsr_id
.s_addr
);
956 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
957 if (pfkey_establish(nbr
, xn
) == -1)
958 fatalx("pfkey setup failed");
959 if (nbr_session_active_role(nbr
))
960 nbr_establish_connection(nbr
);
966 /* update existing nbrps */
967 if (nbrp
->flags
!= xn
->flags
||
968 nbrp
->keepalive
!= xn
->keepalive
||
969 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
970 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
971 nbrp
->auth
.method
!= xn
->auth
.method
||
972 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
977 nbrp
->keepalive
= xn
->keepalive
;
978 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
979 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
980 nbrp
->auth
.method
= xn
->auth
.method
;
981 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
982 sizeof(nbrp
->auth
.md5key
));
983 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
984 nbrp
->flags
= xn
->flags
;
986 if (ldpd_process
== PROC_LDP_ENGINE
) {
987 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
988 if (nbr
&& nbrp_changed
) {
989 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
991 if (pfkey_establish(nbr
, nbrp
) == -1)
992 fatalx("pfkey setup failed");
993 if (nbr_session_active_role(nbr
))
994 nbr_establish_connection(nbr
);
997 LIST_REMOVE(xn
, entry
);
1003 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1005 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1007 LIST_FOREACH_SAFE(l2vpn
, &conf
->l2vpn_list
, entry
, ltmp
) {
1008 /* find deleted l2vpns */
1009 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1010 LIST_REMOVE(l2vpn
, entry
);
1012 switch (ldpd_process
) {
1013 case PROC_LDE_ENGINE
:
1016 case PROC_LDP_ENGINE
:
1017 ldpe_l2vpn_exit(l2vpn
);
1025 LIST_FOREACH_SAFE(xl
, &xconf
->l2vpn_list
, entry
, ltmp
) {
1026 /* find new l2vpns */
1027 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1028 LIST_REMOVE(xl
, entry
);
1029 LIST_INSERT_HEAD(&conf
->l2vpn_list
, xl
, entry
);
1031 switch (ldpd_process
) {
1032 case PROC_LDE_ENGINE
:
1035 case PROC_LDP_ENGINE
:
1036 ldpe_l2vpn_init(xl
);
1044 /* update existing l2vpns */
1045 merge_l2vpn(conf
, l2vpn
, xl
);
1046 LIST_REMOVE(xl
, entry
);
1052 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
)
1054 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1055 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1057 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1058 int previous_pw_type
, previous_mtu
;
1060 previous_pw_type
= l2vpn
->pw_type
;
1061 previous_mtu
= l2vpn
->mtu
;
1063 /* merge intefaces */
1064 LIST_FOREACH_SAFE(lif
, &l2vpn
->if_list
, entry
, ftmp
) {
1065 /* find deleted interfaces */
1066 if ((xf
= l2vpn_if_find(xl
, lif
->ifindex
)) == NULL
) {
1067 LIST_REMOVE(lif
, entry
);
1071 LIST_FOREACH_SAFE(xf
, &xl
->if_list
, entry
, ftmp
) {
1072 /* find new interfaces */
1073 if ((lif
= l2vpn_if_find(l2vpn
, xf
->ifindex
)) == NULL
) {
1074 LIST_REMOVE(xf
, entry
);
1075 LIST_INSERT_HEAD(&l2vpn
->if_list
, xf
, entry
);
1080 LIST_REMOVE(xf
, entry
);
1084 /* merge pseudowires */
1085 LIST_FOREACH_SAFE(pw
, &l2vpn
->pw_list
, entry
, ptmp
) {
1086 /* find deleted pseudowires */
1087 if ((xp
= l2vpn_pw_find(xl
, pw
->ifindex
)) == NULL
) {
1088 switch (ldpd_process
) {
1089 case PROC_LDE_ENGINE
:
1092 case PROC_LDP_ENGINE
:
1093 ldpe_l2vpn_pw_exit(pw
);
1099 LIST_REMOVE(pw
, entry
);
1103 LIST_FOREACH_SAFE(xp
, &xl
->pw_list
, entry
, ptmp
) {
1104 /* find new pseudowires */
1105 if ((pw
= l2vpn_pw_find(l2vpn
, xp
->ifindex
)) == NULL
) {
1106 LIST_REMOVE(xp
, entry
);
1107 LIST_INSERT_HEAD(&l2vpn
->pw_list
, xp
, entry
);
1110 switch (ldpd_process
) {
1111 case PROC_LDE_ENGINE
:
1114 case PROC_LDP_ENGINE
:
1115 ldpe_l2vpn_pw_init(xp
);
1123 /* update existing pseudowire */
1124 if (pw
->af
!= xp
->af
||
1125 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1130 /* changes that require a session restart */
1131 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1132 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1137 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1138 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1139 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1140 reinstall_pwfec
= 1;
1142 reinstall_pwfec
= 0;
1144 if (ldpd_process
== PROC_LDP_ENGINE
) {
1146 ldpe_l2vpn_pw_exit(pw
);
1148 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1149 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1150 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1153 if (ldpd_process
== PROC_LDE_ENGINE
&&
1154 !reset_nbr
&& reinstall_pwfec
)
1156 pw
->lsr_id
= xp
->lsr_id
;
1158 pw
->addr
= xp
->addr
;
1159 pw
->pwid
= xp
->pwid
;
1160 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1161 pw
->ifindex
= xp
->ifindex
;
1162 if (xp
->flags
& F_PW_CWORD_CONF
)
1163 pw
->flags
|= F_PW_CWORD_CONF
;
1165 pw
->flags
&= ~F_PW_CWORD_CONF
;
1166 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1167 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1169 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1170 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1171 ldpe_l2vpn_pw_init(pw
);
1172 if (ldpd_process
== PROC_LDE_ENGINE
&&
1173 !reset_nbr
&& reinstall_pwfec
) {
1174 l2vpn
->pw_type
= xl
->pw_type
;
1175 l2vpn
->mtu
= xl
->mtu
;
1177 l2vpn
->pw_type
= previous_pw_type
;
1178 l2vpn
->mtu
= previous_mtu
;
1181 LIST_REMOVE(xp
, entry
);
1185 l2vpn
->pw_type
= xl
->pw_type
;
1186 l2vpn
->mtu
= xl
->mtu
;
1187 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1188 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1192 config_new_empty(void)
1194 struct ldpd_conf
*xconf
;
1196 xconf
= calloc(1, sizeof(*xconf
));
1200 LIST_INIT(&xconf
->iface_list
);
1201 LIST_INIT(&xconf
->tnbr_list
);
1202 LIST_INIT(&xconf
->nbrp_list
);
1203 LIST_INIT(&xconf
->l2vpn_list
);
1209 config_clear(struct ldpd_conf
*conf
)
1211 struct ldpd_conf
*xconf
;
1214 * Merge current config with an empty config, this will deactivate
1215 * and deallocate all the interfaces, pseudowires and so on. Before
1216 * merging, copy the router-id and other variables to avoid some
1217 * unnecessary operations, like trying to reset the neighborships.
1219 xconf
= config_new_empty();
1220 xconf
->ipv4
= conf
->ipv4
;
1221 xconf
->ipv6
= conf
->ipv6
;
1222 xconf
->rtr_id
= conf
->rtr_id
;
1223 xconf
->trans_pref
= conf
->trans_pref
;
1224 xconf
->flags
= conf
->flags
;
1225 merge_config(conf
, xconf
);