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.
29 #include "ldp_debug.h"
36 static void ldpe_shutdown(void);
37 static int ldpe_dispatch_main(struct thread
*);
38 static int ldpe_dispatch_lde(struct thread
*);
40 static int ldpe_dispatch_pfkey(struct thread
*);
42 static void ldpe_setup_sockets(int, int, int, int);
43 static void ldpe_close_sockets(int);
44 static void ldpe_iface_af_ctl(struct ctl_conn
*, int, unsigned int);
46 struct ldpd_conf
*leconf
;
48 struct ldpd_sysdep sysdep
;
51 static struct imsgev
*iev_main
, *iev_main_sync
;
52 static struct imsgev
*iev_lde
;
54 static struct thread
*pfkey_ev
;
57 /* Master of threads. */
58 struct thread_master
*master
;
61 static zebra_capabilities_t _caps_p
[] =
67 struct zebra_privs_t ldpe_privs
=
69 #if defined(VTY_GROUP)
70 .vty_group
= VTY_GROUP
,
73 .cap_num_p
= array_size(_caps_p
),
77 /* SIGINT / SIGTERM handler. */
84 static struct quagga_signal_t ldpe_signals
[] =
100 /* label distribution protocol engine */
104 struct thread thread
;
106 #ifdef HAVE_SETPROCTITLE
107 setproctitle("ldp engine");
109 ldpd_process
= PROC_LDP_ENGINE
;
110 log_procname
= log_procnames
[ldpd_process
];
112 master
= thread_master_create(NULL
);
114 /* setup signal handler */
115 signal_init(master
, array_size(ldpe_signals
), ldpe_signals
);
117 /* setup pipes and event handlers to the parent process */
118 if ((iev_main
= calloc(1, sizeof(struct imsgev
))) == NULL
)
120 imsg_init(&iev_main
->ibuf
, LDPD_FD_ASYNC
);
121 iev_main
->handler_read
= ldpe_dispatch_main
;
122 iev_main
->ev_read
= NULL
;
123 thread_add_read(master
, iev_main
->handler_read
, iev_main
, iev_main
->ibuf
.fd
,
125 iev_main
->handler_write
= ldp_write_handler
;
127 if ((iev_main_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
129 imsg_init(&iev_main_sync
->ibuf
, LDPD_FD_SYNC
);
131 /* create base configuration */
132 leconf
= config_new_empty();
134 /* Fetch next active thread. */
135 while (thread_fetch(master
, &thread
))
136 thread_call(&thread
);
140 ldpe_init(struct ldpd_init
*init
)
142 /* drop privileges */
143 ldpe_privs
.user
= init
->user
;
144 ldpe_privs
.group
= init
->group
;
145 zprivs_preinit(&ldpe_privs
);
146 zprivs_init(&ldpe_privs
);
148 /* listen on ldpd control socket */
149 strlcpy(ctl_sock_path
, init
->ctl_sock_path
, sizeof(ctl_sock_path
));
150 if (control_init(ctl_sock_path
) == -1)
151 fatalx("control socket setup failed");
152 TAILQ_INIT(&ctl_conns
);
155 LIST_INIT(&global
.addr_list
);
156 RB_INIT(global_adj_head
, &global
.adj_tree
);
157 TAILQ_INIT(&global
.pending_conns
);
158 if (inet_pton(AF_INET
, AllRouters_v4
, &global
.mcast_addr_v4
) != 1)
160 if (inet_pton(AF_INET6
, AllRouters_v6
, &global
.mcast_addr_v6
) != 1)
163 global
.pfkeysock
= pfkey_init();
164 if (sysdep
.no_pfkey
== 0) {
166 thread_add_read(master
, ldpe_dispatch_pfkey
, NULL
, global
.pfkeysock
,
171 /* mark sockets as closed */
172 global
.ipv4
.ldp_disc_socket
= -1;
173 global
.ipv4
.ldp_edisc_socket
= -1;
174 global
.ipv4
.ldp_session_socket
= -1;
175 global
.ipv6
.ldp_disc_socket
= -1;
176 global
.ipv6
.ldp_edisc_socket
= -1;
177 global
.ipv6
.ldp_session_socket
= -1;
179 if ((pkt_ptr
= calloc(1, IBUF_READ_SIZE
)) == NULL
)
188 struct if_addr
*if_addr
;
193 msgbuf_clear(&iev_lde
->ibuf
.w
);
194 close(iev_lde
->ibuf
.fd
);
195 iev_lde
->ibuf
.fd
= -1;
197 msgbuf_clear(&iev_main
->ibuf
.w
);
198 close(iev_main
->ibuf
.fd
);
199 iev_main
->ibuf
.fd
= -1;
200 msgbuf_clear(&iev_main_sync
->ibuf
.w
);
201 close(iev_main_sync
->ibuf
.fd
);
202 iev_main_sync
->ibuf
.fd
= -1;
204 control_cleanup(ctl_sock_path
);
205 config_clear(leconf
);
208 if (sysdep
.no_pfkey
== 0) {
209 THREAD_READ_OFF(pfkey_ev
);
210 close(global
.pfkeysock
);
213 ldpe_close_sockets(AF_INET
);
214 ldpe_close_sockets(AF_INET6
);
216 /* remove addresses from global list */
217 while ((if_addr
= LIST_FIRST(&global
.addr_list
)) != NULL
) {
218 LIST_REMOVE(if_addr
, entry
);
219 assert(if_addr
!= LIST_FIRST(&global
.addr_list
));
222 while ((adj
= RB_ROOT(global_adj_head
, &global
.adj_tree
)) != NULL
)
223 adj_del(adj
, S_SHUTDOWN
);
232 log_info("ldp engine exiting");
238 ldpe_imsg_compose_parent(int type
, pid_t pid
, void *data
, uint16_t datalen
)
240 if (iev_main
->ibuf
.fd
== -1)
242 return (imsg_compose_event(iev_main
, type
, 0, pid
, -1, data
, datalen
));
246 ldpe_imsg_compose_parent_sync(int type
, pid_t pid
, void *data
, uint16_t datalen
)
248 if (iev_main_sync
->ibuf
.fd
== -1)
250 imsg_compose_event(iev_main_sync
, type
, 0, pid
, -1, data
, datalen
);
251 imsg_flush(&iev_main_sync
->ibuf
);
255 ldpe_imsg_compose_lde(int type
, uint32_t peerid
, pid_t pid
, void *data
,
258 if (iev_lde
->ibuf
.fd
== -1)
260 return (imsg_compose_event(iev_lde
, type
, peerid
, pid
, -1,
266 ldpe_dispatch_main(struct thread
*thread
)
268 static struct ldpd_conf
*nconf
;
269 struct iface
*niface
;
271 struct nbr_params
*nnbrp
;
272 static struct l2vpn
*l2vpn
, *nl2vpn
;
273 struct l2vpn_if
*lif
, *nlif
;
274 struct l2vpn_pw
*pw
, *npw
;
277 struct imsgev
*iev
= THREAD_ARG(thread
);
278 struct imsgbuf
*ibuf
= &iev
->ibuf
;
279 struct iface
*iface
= NULL
;
282 enum socket_type
*socket_type
;
283 static int disc_socket
= -1;
284 static int edisc_socket
= -1;
285 static int session_socket
= -1;
288 struct nbr_params
*nbrp
;
294 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
295 fatal("imsg_read error");
296 if (n
== 0) /* connection closed */
300 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
301 fatal("ldpe_dispatch_main: imsg_get error");
305 switch (imsg
.hdr
.type
) {
307 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
309 fatalx("IFSTATUS imsg with wrong len");
312 iface
= if_lookup_name(leconf
, kif
->ifname
);
314 if_update_info(iface
, kif
);
315 ldp_if_update(iface
, AF_UNSPEC
);
319 RB_FOREACH(l2vpn
, l2vpn_head
, &leconf
->l2vpn_tree
) {
320 lif
= l2vpn_if_find(l2vpn
, kif
->ifname
);
322 l2vpn_if_update_info(lif
, kif
);
323 l2vpn_if_update(lif
);
326 pw
= l2vpn_pw_find(l2vpn
, kif
->ifname
);
328 l2vpn_pw_update_info(pw
, kif
);
334 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
335 sizeof(struct kaddr
))
336 fatalx("NEWADDR imsg with wrong len");
338 if_addr_add(imsg
.data
);
341 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
342 sizeof(struct kaddr
))
343 fatalx("DELADDR imsg with wrong len");
345 if_addr_del(imsg
.data
);
347 case IMSG_SOCKET_IPC
:
349 log_warnx("%s: received unexpected imsg fd "
353 if ((fd
= imsg
.fd
) == -1) {
354 log_warnx("%s: expected to receive imsg fd to "
355 "lde but didn't receive any", __func__
);
359 if ((iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
361 imsg_init(&iev_lde
->ibuf
, fd
);
362 iev_lde
->handler_read
= ldpe_dispatch_lde
;
363 iev_lde
->ev_read
= NULL
;
364 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
366 iev_lde
->handler_write
= ldp_write_handler
;
367 iev_lde
->ev_write
= NULL
;
370 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
371 sizeof(struct ldpd_init
))
372 fatalx("INIT imsg with wrong len");
374 memcpy(&init
, imsg
.data
, sizeof(init
));
377 case IMSG_CLOSE_SOCKETS
:
378 af
= imsg
.hdr
.peerid
;
380 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
383 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
387 nbr
->auth
.method
= AUTH_NONE
;
389 ldpe_close_sockets(af
);
396 if ((ldp_af_conf_get(leconf
, af
))->flags
&
398 ldpe_imsg_compose_parent(IMSG_REQUEST_SOCKETS
,
401 case IMSG_SOCKET_NET
:
402 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
403 sizeof(enum socket_type
))
404 fatalx("SOCKET_NET imsg with wrong len");
405 socket_type
= imsg
.data
;
407 switch (*socket_type
) {
408 case LDP_SOCKET_DISC
:
409 disc_socket
= imsg
.fd
;
411 case LDP_SOCKET_EDISC
:
412 edisc_socket
= imsg
.fd
;
414 case LDP_SOCKET_SESSION
:
415 session_socket
= imsg
.fd
;
419 case IMSG_SETUP_SOCKETS
:
420 af
= imsg
.hdr
.peerid
;
421 if (disc_socket
== -1 || edisc_socket
== -1 ||
422 session_socket
== -1) {
423 if (disc_socket
!= -1)
425 if (edisc_socket
!= -1)
427 if (session_socket
!= -1)
428 close(session_socket
);
432 ldpe_setup_sockets(af
, disc_socket
, edisc_socket
,
436 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
439 nbr
->laddr
= (ldp_af_conf_get(leconf
,
442 nbrp
= nbr_params_find(leconf
, nbr
->id
);
444 nbr
->auth
.method
= nbrp
->auth
.method
;
445 if (pfkey_establish(nbr
, nbrp
) == -1)
446 fatalx("pfkey setup failed");
449 if (nbr_session_active_role(nbr
))
450 nbr_establish_connection(nbr
);
453 case IMSG_RTRID_UPDATE
:
454 memcpy(&global
.rtr_id
, imsg
.data
,
455 sizeof(global
.rtr_id
));
456 if (leconf
->rtr_id
.s_addr
== INADDR_ANY
) {
457 ldpe_reset_nbrs(AF_UNSPEC
);
459 if_update_all(AF_UNSPEC
);
460 tnbr_update_all(AF_UNSPEC
);
462 case IMSG_RECONF_CONF
:
463 if ((nconf
= malloc(sizeof(struct ldpd_conf
))) ==
466 memcpy(nconf
, imsg
.data
, sizeof(struct ldpd_conf
));
468 RB_INIT(iface_head
, &nconf
->iface_tree
);
469 RB_INIT(tnbr_head
, &nconf
->tnbr_tree
);
470 RB_INIT(nbrp_head
, &nconf
->nbrp_tree
);
471 RB_INIT(l2vpn_head
, &nconf
->l2vpn_tree
);
473 case IMSG_RECONF_IFACE
:
474 if ((niface
= malloc(sizeof(struct iface
))) == NULL
)
476 memcpy(niface
, imsg
.data
, sizeof(struct iface
));
478 RB_INSERT(iface_head
, &nconf
->iface_tree
, niface
);
480 case IMSG_RECONF_TNBR
:
481 if ((ntnbr
= malloc(sizeof(struct tnbr
))) == NULL
)
483 memcpy(ntnbr
, imsg
.data
, sizeof(struct tnbr
));
485 RB_INSERT(tnbr_head
, &nconf
->tnbr_tree
, ntnbr
);
487 case IMSG_RECONF_NBRP
:
488 if ((nnbrp
= malloc(sizeof(struct nbr_params
))) == NULL
)
490 memcpy(nnbrp
, imsg
.data
, sizeof(struct nbr_params
));
492 RB_INSERT(nbrp_head
, &nconf
->nbrp_tree
, nnbrp
);
494 case IMSG_RECONF_L2VPN
:
495 if ((nl2vpn
= malloc(sizeof(struct l2vpn
))) == NULL
)
497 memcpy(nl2vpn
, imsg
.data
, sizeof(struct l2vpn
));
499 RB_INIT(l2vpn_if_head
, &nl2vpn
->if_tree
);
500 RB_INIT(l2vpn_pw_head
, &nl2vpn
->pw_tree
);
501 RB_INIT(l2vpn_pw_head
, &nl2vpn
->pw_inactive_tree
);
503 RB_INSERT(l2vpn_head
, &nconf
->l2vpn_tree
, nl2vpn
);
505 case IMSG_RECONF_L2VPN_IF
:
506 if ((nlif
= malloc(sizeof(struct l2vpn_if
))) == NULL
)
508 memcpy(nlif
, imsg
.data
, sizeof(struct l2vpn_if
));
510 RB_INSERT(l2vpn_if_head
, &nl2vpn
->if_tree
, nlif
);
512 case IMSG_RECONF_L2VPN_PW
:
513 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
515 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
517 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_tree
, npw
);
519 case IMSG_RECONF_L2VPN_IPW
:
520 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
522 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
524 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_inactive_tree
, npw
);
526 case IMSG_RECONF_END
:
527 merge_config(leconf
, nconf
);
528 ldp_clear_config(nconf
);
530 global
.conf_seqnum
++;
533 control_imsg_relay(&imsg
);
535 case IMSG_DEBUG_UPDATE
:
536 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
538 log_warnx("%s: wrong imsg len", __func__
);
541 memcpy(&ldp_debug
, imsg
.data
, sizeof(ldp_debug
));
544 log_debug("ldpe_dispatch_main: error handling imsg %d",
553 /* this pipe is dead, so remove the event handlers and exit */
554 THREAD_READ_OFF(iev
->ev_read
);
555 THREAD_WRITE_OFF(iev
->ev_write
);
564 ldpe_dispatch_lde(struct thread
*thread
)
566 struct imsgev
*iev
= THREAD_ARG(thread
);
567 struct imsgbuf
*ibuf
= &iev
->ibuf
;
570 struct notify_msg
*nm
;
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)
583 fatal("ldpe_dispatch_lde: imsg_get error");
587 switch (imsg
.hdr
.type
) {
588 case IMSG_MAPPING_ADD
:
589 case IMSG_RELEASE_ADD
:
590 case IMSG_REQUEST_ADD
:
591 case IMSG_WITHDRAW_ADD
:
592 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
594 fatalx("invalid size of map request");
597 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
599 log_debug("ldpe_dispatch_lde: cannot find "
603 if (nbr
->state
!= NBR_STA_OPER
)
606 switch (imsg
.hdr
.type
) {
607 case IMSG_MAPPING_ADD
:
608 mapping_list_add(&nbr
->mapping_list
, map
);
610 case IMSG_RELEASE_ADD
:
611 mapping_list_add(&nbr
->release_list
, map
);
613 case IMSG_REQUEST_ADD
:
614 mapping_list_add(&nbr
->request_list
, map
);
616 case IMSG_WITHDRAW_ADD
:
617 mapping_list_add(&nbr
->withdraw_list
, map
);
621 case IMSG_MAPPING_ADD_END
:
622 case IMSG_RELEASE_ADD_END
:
623 case IMSG_REQUEST_ADD_END
:
624 case IMSG_WITHDRAW_ADD_END
:
625 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
627 log_debug("ldpe_dispatch_lde: cannot find "
631 if (nbr
->state
!= NBR_STA_OPER
)
634 switch (imsg
.hdr
.type
) {
635 case IMSG_MAPPING_ADD_END
:
636 send_labelmessage(nbr
, MSG_TYPE_LABELMAPPING
,
639 case IMSG_RELEASE_ADD_END
:
640 send_labelmessage(nbr
, MSG_TYPE_LABELRELEASE
,
643 case IMSG_REQUEST_ADD_END
:
644 send_labelmessage(nbr
, MSG_TYPE_LABELREQUEST
,
647 case IMSG_WITHDRAW_ADD_END
:
648 send_labelmessage(nbr
, MSG_TYPE_LABELWITHDRAW
,
649 &nbr
->withdraw_list
);
653 case IMSG_NOTIFICATION_SEND
:
654 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
655 sizeof(struct notify_msg
))
656 fatalx("invalid size of OE request");
659 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
661 log_debug("ldpe_dispatch_lde: cannot find "
665 if (nbr
->state
!= NBR_STA_OPER
)
668 send_notification_full(nbr
->tcp
, nm
);
671 case IMSG_CTL_SHOW_LIB_BEGIN
:
672 case IMSG_CTL_SHOW_LIB_RCVD
:
673 case IMSG_CTL_SHOW_LIB_SENT
:
674 case IMSG_CTL_SHOW_LIB_END
:
675 case IMSG_CTL_SHOW_L2VPN_PW
:
676 case IMSG_CTL_SHOW_L2VPN_BINDING
:
677 control_imsg_relay(&imsg
);
680 log_debug("ldpe_dispatch_lde: error handling imsg %d",
689 /* this pipe is dead, so remove the event handlers and exit */
690 THREAD_READ_OFF(iev
->ev_read
);
691 THREAD_WRITE_OFF(iev
->ev_write
);
701 ldpe_dispatch_pfkey(struct thread
*thread
)
703 int fd
= THREAD_FD(thread
);
706 thread_add_read(master
, ldpe_dispatch_pfkey
, NULL
, global
.pfkeysock
,
709 if (pfkey_read(fd
, NULL
) == -1)
710 fatal("pfkey_read failed, exiting...");
714 #endif /* __OpenBSD__ */
717 ldpe_setup_sockets(int af
, int disc_socket
, int edisc_socket
,
720 struct ldpd_af_global
*af_global
;
722 af_global
= ldp_af_global_get(&global
, af
);
724 /* discovery socket */
725 af_global
->ldp_disc_socket
= disc_socket
;
726 af_global
->disc_ev
= NULL
;
727 thread_add_read(master
, disc_recv_packet
, &af_global
->disc_ev
, af_global
->ldp_disc_socket
,
728 &af_global
->disc_ev
);
730 /* extended discovery socket */
731 af_global
->ldp_edisc_socket
= edisc_socket
;
732 af_global
->edisc_ev
= NULL
;
733 thread_add_read(master
, disc_recv_packet
, &af_global
->edisc_ev
, af_global
->ldp_edisc_socket
,
734 &af_global
->edisc_ev
);
737 af_global
->ldp_session_socket
= session_socket
;
738 accept_add(af_global
->ldp_session_socket
, session_accept
, NULL
);
742 ldpe_close_sockets(int af
)
744 struct ldpd_af_global
*af_global
;
746 af_global
= ldp_af_global_get(&global
, af
);
748 /* discovery socket */
749 THREAD_READ_OFF(af_global
->disc_ev
);
750 if (af_global
->ldp_disc_socket
!= -1) {
751 close(af_global
->ldp_disc_socket
);
752 af_global
->ldp_disc_socket
= -1;
755 /* extended discovery socket */
756 THREAD_READ_OFF(af_global
->edisc_ev
);
757 if (af_global
->ldp_edisc_socket
!= -1) {
758 close(af_global
->ldp_edisc_socket
);
759 af_global
->ldp_edisc_socket
= -1;
763 if (af_global
->ldp_session_socket
!= -1) {
764 accept_del(af_global
->ldp_session_socket
);
765 close(af_global
->ldp_session_socket
);
766 af_global
->ldp_session_socket
= -1;
771 ldpe_acl_check(char *acl_name
, int af
, union ldpd_addr
*addr
, uint8_t prefixlen
)
773 return ldp_acl_request(iev_main_sync
, acl_name
, af
, addr
, prefixlen
);
777 ldpe_reset_nbrs(int af
)
781 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
782 if (af
== AF_UNSPEC
|| nbr
->af
== af
)
783 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
788 ldpe_reset_ds_nbrs(void)
792 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
794 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
799 ldpe_remove_dynamic_tnbrs(int af
)
801 struct tnbr
*tnbr
, *safe
;
803 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &leconf
->tnbr_tree
, safe
) {
807 tnbr
->flags
&= ~F_TNBR_DYNAMIC
;
808 tnbr_check(leconf
, tnbr
);
813 ldpe_stop_init_backoff(int af
)
817 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
818 if (nbr
->af
== af
&& nbr_pending_idtimer(nbr
)) {
819 nbr_stop_idtimer(nbr
);
820 nbr_establish_connection(nbr
);
826 ldpe_iface_af_ctl(struct ctl_conn
*c
, int af
, unsigned int idx
)
830 struct ctl_iface
*ictl
;
832 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
833 if (idx
== 0 || idx
== iface
->ifindex
) {
834 ia
= iface_af_get(iface
, af
);
838 ictl
= if_to_ctl(ia
);
839 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_INTERFACE
,
840 0, 0, -1, ictl
, sizeof(struct ctl_iface
));
846 ldpe_iface_ctl(struct ctl_conn
*c
, unsigned int idx
)
848 ldpe_iface_af_ctl(c
, AF_INET
, idx
);
849 ldpe_iface_af_ctl(c
, AF_INET6
, idx
);
853 ldpe_adj_ctl(struct ctl_conn
*c
)
856 struct ctl_adj
*actl
;
858 RB_FOREACH(adj
, global_adj_head
, &global
.adj_tree
) {
859 actl
= adj_to_ctl(adj
);
860 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0,
861 -1, actl
, sizeof(struct ctl_adj
));
864 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
868 ldpe_adj_detail_ctl(struct ctl_conn
*c
)
873 struct ctl_adj
*actl
;
874 struct ctl_disc_if ictl
;
875 struct ctl_disc_tnbr tctl
;
877 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
879 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
880 memset(&ictl
, 0, sizeof(ictl
));
881 ictl
.active_v4
= (iface
->ipv4
.state
== IF_STA_ACTIVE
);
882 ictl
.active_v6
= (iface
->ipv6
.state
== IF_STA_ACTIVE
);
884 if (!ictl
.active_v4
&& !ictl
.active_v6
)
887 strlcpy(ictl
.name
, iface
->name
, sizeof(ictl
.name
));
888 if (RB_EMPTY(ia_adj_head
, &iface
->ipv4
.adj_tree
) &&
889 RB_EMPTY(ia_adj_head
, &iface
->ipv6
.adj_tree
))
891 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_IFACE
, 0, 0,
892 -1, &ictl
, sizeof(ictl
));
894 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv4
.adj_tree
) {
895 actl
= adj_to_ctl(adj
);
896 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
897 0, 0, -1, actl
, sizeof(struct ctl_adj
));
899 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv6
.adj_tree
) {
900 actl
= adj_to_ctl(adj
);
901 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
902 0, 0, -1, actl
, sizeof(struct ctl_adj
));
906 RB_FOREACH(tnbr
, tnbr_head
, &leconf
->tnbr_tree
) {
907 memset(&tctl
, 0, sizeof(tctl
));
909 tctl
.addr
= tnbr
->addr
;
910 if (tnbr
->adj
== NULL
)
913 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_TNBR
, 0, 0,
914 -1, &tctl
, sizeof(tctl
));
916 if (tnbr
->adj
== NULL
)
919 actl
= adj_to_ctl(tnbr
->adj
);
920 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
, 0, 0,
921 -1, actl
, sizeof(struct ctl_adj
));
924 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
928 ldpe_nbr_ctl(struct ctl_conn
*c
)
931 struct ctl_adj
*actl
;
933 struct ctl_nbr
*nctl
;
935 RB_FOREACH(nbr
, nbr_addr_head
, &nbrs_by_addr
) {
936 if (nbr
->state
== NBR_STA_PRESENT
)
939 nctl
= nbr_to_ctl(nbr
);
940 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, nctl
,
941 sizeof(struct ctl_nbr
));
943 RB_FOREACH(adj
, nbr_adj_head
, &nbr
->adj_tree
) {
944 actl
= adj_to_ctl(adj
);
945 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_DISC
,
946 0, 0, -1, actl
, sizeof(struct ctl_adj
));
949 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_END
, 0, 0, -1,
952 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
956 mapping_list_add(struct mapping_head
*mh
, struct map
*map
)
958 struct mapping_entry
*me
;
960 me
= calloc(1, sizeof(*me
));
965 TAILQ_INSERT_TAIL(mh
, me
, entry
);
969 mapping_list_clr(struct mapping_head
*mh
)
971 struct mapping_entry
*me
;
973 while ((me
= TAILQ_FIRST(mh
)) != NULL
) {
974 TAILQ_REMOVE(mh
, me
, entry
);
975 assert(me
!= TAILQ_FIRST(mh
));