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(FRR_USER) && defined(FRR_GROUP)
73 #if defined(VTY_GROUP)
74 .vty_group
= VTY_GROUP
,
77 .cap_num_p
= array_size(_caps_p
),
81 /* SIGINT / SIGTERM handler. */
88 static struct quagga_signal_t ldpe_signals
[] =
100 /* label distribution protocol engine */
102 ldpe(const char *user
, const char *group
, const char *ctl_path
)
104 struct thread thread
;
106 leconf
= config_new_empty();
108 #ifdef HAVE_SETPROCTITLE
109 setproctitle("ldp engine");
111 ldpd_process
= PROC_LDP_ENGINE
;
113 LIST_INIT(&global
.addr_list
);
114 RB_INIT(&global
.adj_tree
);
115 TAILQ_INIT(&global
.pending_conns
);
116 if (inet_pton(AF_INET
, AllRouters_v4
, &global
.mcast_addr_v4
) != 1)
118 if (inet_pton(AF_INET6
, AllRouters_v6
, &global
.mcast_addr_v6
) != 1)
121 global
.pfkeysock
= pfkey_init();
124 /* drop privileges */
126 ldpe_privs
.user
= user
;
128 ldpe_privs
.group
= group
;
129 zprivs_init(&ldpe_privs
);
131 strlcpy(ctl_sock_path
, ctl_path
, sizeof(ctl_sock_path
));
132 if (control_init() == -1)
133 fatalx("control socket setup failed");
136 if (pledge("stdio cpath inet mcast recvfd", NULL
) == -1)
140 master
= thread_master_create();
143 /* setup signal handler */
144 signal_init(master
, array_size(ldpe_signals
), ldpe_signals
);
146 /* setup pipes and event handlers to the parent process */
147 if ((iev_main
= calloc(1, sizeof(struct imsgev
))) == NULL
)
149 imsg_init(&iev_main
->ibuf
, LDPD_FD_ASYNC
);
150 iev_main
->handler_read
= ldpe_dispatch_main
;
151 iev_main
->ev_read
= thread_add_read(master
, iev_main
->handler_read
,
152 iev_main
, iev_main
->ibuf
.fd
);
153 iev_main
->handler_write
= ldp_write_handler
;
155 if ((iev_main_sync
= calloc(1, sizeof(struct imsgev
))) == NULL
)
157 imsg_init(&iev_main_sync
->ibuf
, LDPD_FD_SYNC
);
160 if (sysdep
.no_pfkey
== 0)
161 pfkey_ev
= thread_add_read(master
, ldpe_dispatch_pfkey
,
162 NULL
, global
.pfkeysock
);
165 /* mark sockets as closed */
166 global
.ipv4
.ldp_disc_socket
= -1;
167 global
.ipv4
.ldp_edisc_socket
= -1;
168 global
.ipv4
.ldp_session_socket
= -1;
169 global
.ipv6
.ldp_disc_socket
= -1;
170 global
.ipv6
.ldp_edisc_socket
= -1;
171 global
.ipv6
.ldp_session_socket
= -1;
173 /* listen on ldpd control socket */
174 TAILQ_INIT(&ctl_conns
);
177 if ((pkt_ptr
= calloc(1, IBUF_READ_SIZE
)) == NULL
)
180 /* Fetch next active thread. */
181 while (thread_fetch(master
, &thread
))
182 thread_call(&thread
);
188 struct if_addr
*if_addr
;
192 msgbuf_write(&iev_lde
->ibuf
.w
);
193 msgbuf_clear(&iev_lde
->ibuf
.w
);
194 close(iev_lde
->ibuf
.fd
);
195 msgbuf_write(&iev_main
->ibuf
.w
);
196 msgbuf_clear(&iev_main
->ibuf
.w
);
197 close(iev_main
->ibuf
.fd
);
198 msgbuf_clear(&iev_main_sync
->ibuf
.w
);
199 close(iev_main_sync
->ibuf
.fd
);
202 config_clear(leconf
);
205 if (sysdep
.no_pfkey
== 0) {
206 THREAD_READ_OFF(pfkey_ev
);
207 close(global
.pfkeysock
);
210 ldpe_close_sockets(AF_INET
);
211 ldpe_close_sockets(AF_INET6
);
213 /* remove addresses from global list */
214 while ((if_addr
= LIST_FIRST(&global
.addr_list
)) != NULL
) {
215 LIST_REMOVE(if_addr
, entry
);
218 while ((adj
= RB_ROOT(&global
.adj_tree
)) != NULL
)
219 adj_del(adj
, S_SHUTDOWN
);
227 log_info("ldp engine exiting");
233 ldpe_imsg_compose_parent(int type
, pid_t pid
, void *data
, uint16_t datalen
)
235 return (imsg_compose_event(iev_main
, type
, 0, pid
, -1, data
, datalen
));
239 ldpe_imsg_compose_lde(int type
, uint32_t peerid
, pid_t pid
, void *data
,
242 return (imsg_compose_event(iev_lde
, type
, peerid
, pid
, -1,
248 ldpe_dispatch_main(struct thread
*thread
)
250 static struct ldpd_conf
*nconf
;
251 struct iface
*niface
;
253 struct nbr_params
*nnbrp
;
254 static struct l2vpn
*nl2vpn
;
255 struct l2vpn_if
*nlif
;
256 struct l2vpn_pw
*npw
;
258 int fd
= THREAD_FD(thread
);
259 struct imsgev
*iev
= THREAD_ARG(thread
);
260 struct imsgbuf
*ibuf
= &iev
->ibuf
;
261 struct iface
*iface
= NULL
;
264 enum socket_type
*socket_type
;
265 static int disc_socket
= -1;
266 static int edisc_socket
= -1;
267 static int session_socket
= -1;
270 struct nbr_params
*nbrp
;
276 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
277 fatal("imsg_read error");
278 if (n
== 0) /* connection closed */
282 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
283 fatal("ldpe_dispatch_main: imsg_get error");
287 switch (imsg
.hdr
.type
) {
289 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
291 fatalx("IFSTATUS imsg with wrong len");
294 iface
= if_lookup_name(leconf
, kif
->ifname
);
298 if_update_info(iface
, kif
);
299 if_update(iface
, AF_UNSPEC
);
302 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
303 sizeof(struct kaddr
))
304 fatalx("NEWADDR imsg with wrong len");
306 if_addr_add(imsg
.data
);
309 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
310 sizeof(struct kaddr
))
311 fatalx("DELADDR imsg with wrong len");
313 if_addr_del(imsg
.data
);
315 case IMSG_SOCKET_IPC
:
317 log_warnx("%s: received unexpected imsg fd "
321 if ((fd
= imsg
.fd
) == -1) {
322 log_warnx("%s: expected to receive imsg fd to "
323 "lde but didn't receive any", __func__
);
327 if ((iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
329 imsg_init(&iev_lde
->ibuf
, fd
);
330 iev_lde
->handler_read
= ldpe_dispatch_lde
;
331 iev_lde
->ev_read
= thread_add_read(master
,
332 iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
);
333 iev_lde
->handler_write
= ldp_write_handler
;
334 iev_lde
->ev_write
= NULL
;
336 case IMSG_CLOSE_SOCKETS
:
337 af
= imsg
.hdr
.peerid
;
339 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
342 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
347 ldpe_close_sockets(af
);
354 if ((ldp_af_conf_get(leconf
, af
))->flags
&
356 ldpe_imsg_compose_parent(IMSG_REQUEST_SOCKETS
,
359 case IMSG_SOCKET_NET
:
360 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
361 sizeof(enum socket_type
))
362 fatalx("SOCKET_NET imsg with wrong len");
363 socket_type
= imsg
.data
;
365 switch (*socket_type
) {
366 case LDP_SOCKET_DISC
:
367 disc_socket
= imsg
.fd
;
369 case LDP_SOCKET_EDISC
:
370 edisc_socket
= imsg
.fd
;
372 case LDP_SOCKET_SESSION
:
373 session_socket
= imsg
.fd
;
377 case IMSG_SETUP_SOCKETS
:
378 af
= imsg
.hdr
.peerid
;
379 if (disc_socket
== -1 || edisc_socket
== -1 ||
380 session_socket
== -1) {
381 if (disc_socket
!= -1)
383 if (edisc_socket
!= -1)
385 if (session_socket
!= -1)
386 close(session_socket
);
390 ldpe_setup_sockets(af
, disc_socket
, edisc_socket
,
394 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
397 nbr
->laddr
= (ldp_af_conf_get(leconf
,
400 nbrp
= nbr_params_find(leconf
, nbr
->id
);
401 if (nbrp
&& pfkey_establish(nbr
, nbrp
) == -1)
402 fatalx("pfkey setup failed");
404 if (nbr_session_active_role(nbr
))
405 nbr_establish_connection(nbr
);
408 case IMSG_RTRID_UPDATE
:
409 memcpy(&global
.rtr_id
, imsg
.data
,
410 sizeof(global
.rtr_id
));
411 if (leconf
->rtr_id
.s_addr
== INADDR_ANY
) {
412 ldpe_reset_nbrs(AF_UNSPEC
);
414 if_update_all(AF_UNSPEC
);
415 tnbr_update_all(AF_UNSPEC
);
417 case IMSG_RECONF_CONF
:
418 if ((nconf
= malloc(sizeof(struct ldpd_conf
))) ==
421 memcpy(nconf
, imsg
.data
, sizeof(struct ldpd_conf
));
423 RB_INIT(&nconf
->iface_tree
);
424 RB_INIT(&nconf
->tnbr_tree
);
425 RB_INIT(&nconf
->nbrp_tree
);
426 RB_INIT(&nconf
->l2vpn_tree
);
428 case IMSG_RECONF_IFACE
:
429 if ((niface
= malloc(sizeof(struct iface
))) == NULL
)
431 memcpy(niface
, imsg
.data
, sizeof(struct iface
));
433 LIST_INIT(&niface
->addr_list
);
434 RB_INIT(&niface
->ipv4
.adj_tree
);
435 RB_INIT(&niface
->ipv6
.adj_tree
);
436 niface
->ipv4
.iface
= niface
;
437 niface
->ipv6
.iface
= niface
;
439 RB_INSERT(iface_head
, &nconf
->iface_tree
, niface
);
441 case IMSG_RECONF_TNBR
:
442 if ((ntnbr
= malloc(sizeof(struct tnbr
))) == NULL
)
444 memcpy(ntnbr
, imsg
.data
, sizeof(struct tnbr
));
446 RB_INSERT(tnbr_head
, &nconf
->tnbr_tree
, ntnbr
);
448 case IMSG_RECONF_NBRP
:
449 if ((nnbrp
= malloc(sizeof(struct nbr_params
))) == NULL
)
451 memcpy(nnbrp
, imsg
.data
, sizeof(struct nbr_params
));
453 RB_INSERT(nbrp_head
, &nconf
->nbrp_tree
, nnbrp
);
455 case IMSG_RECONF_L2VPN
:
456 if ((nl2vpn
= malloc(sizeof(struct l2vpn
))) == NULL
)
458 memcpy(nl2vpn
, imsg
.data
, sizeof(struct l2vpn
));
460 RB_INIT(&nl2vpn
->if_tree
);
461 RB_INIT(&nl2vpn
->pw_tree
);
462 RB_INIT(&nl2vpn
->pw_inactive_tree
);
464 RB_INSERT(l2vpn_head
, &nconf
->l2vpn_tree
, nl2vpn
);
466 case IMSG_RECONF_L2VPN_IF
:
467 if ((nlif
= malloc(sizeof(struct l2vpn_if
))) == NULL
)
469 memcpy(nlif
, imsg
.data
, sizeof(struct l2vpn_if
));
471 nlif
->l2vpn
= nl2vpn
;
472 RB_INSERT(l2vpn_if_head
, &nl2vpn
->if_tree
, nlif
);
474 case IMSG_RECONF_L2VPN_PW
:
475 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
477 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
480 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_tree
, npw
);
482 case IMSG_RECONF_L2VPN_IPW
:
483 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
485 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
488 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_inactive_tree
, npw
);
490 case IMSG_RECONF_END
:
491 merge_config(leconf
, nconf
);
493 global
.conf_seqnum
++;
496 control_imsg_relay(&imsg
);
498 case IMSG_DEBUG_UPDATE
:
499 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
501 log_warnx("%s: wrong imsg len", __func__
);
504 memcpy(&ldp_debug
, imsg
.data
, sizeof(ldp_debug
));
507 log_debug("ldpe_dispatch_main: error handling imsg %d",
516 /* this pipe is dead, so remove the event handlers and exit */
517 THREAD_READ_OFF(iev
->ev_read
);
518 THREAD_WRITE_OFF(iev
->ev_write
);
527 ldpe_dispatch_lde(struct thread
*thread
)
529 struct imsgev
*iev
= THREAD_ARG(thread
);
530 struct imsgbuf
*ibuf
= &iev
->ibuf
;
533 struct notify_msg nm
;
535 struct nbr
*nbr
= NULL
;
539 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
540 fatal("imsg_read error");
541 if (n
== 0) /* connection closed */
545 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
546 fatal("ldpe_dispatch_lde: imsg_get error");
550 switch (imsg
.hdr
.type
) {
551 case IMSG_MAPPING_ADD
:
552 case IMSG_RELEASE_ADD
:
553 case IMSG_REQUEST_ADD
:
554 case IMSG_WITHDRAW_ADD
:
555 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!= sizeof(map
))
556 fatalx("invalid size of map request");
557 memcpy(&map
, imsg
.data
, sizeof(map
));
559 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
561 log_debug("ldpe_dispatch_lde: cannot find "
565 if (nbr
->state
!= NBR_STA_OPER
)
568 switch (imsg
.hdr
.type
) {
569 case IMSG_MAPPING_ADD
:
570 mapping_list_add(&nbr
->mapping_list
, &map
);
572 case IMSG_RELEASE_ADD
:
573 mapping_list_add(&nbr
->release_list
, &map
);
575 case IMSG_REQUEST_ADD
:
576 mapping_list_add(&nbr
->request_list
, &map
);
578 case IMSG_WITHDRAW_ADD
:
579 mapping_list_add(&nbr
->withdraw_list
, &map
);
583 case IMSG_MAPPING_ADD_END
:
584 case IMSG_RELEASE_ADD_END
:
585 case IMSG_REQUEST_ADD_END
:
586 case IMSG_WITHDRAW_ADD_END
:
587 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
589 log_debug("ldpe_dispatch_lde: cannot find "
593 if (nbr
->state
!= NBR_STA_OPER
)
596 switch (imsg
.hdr
.type
) {
597 case IMSG_MAPPING_ADD_END
:
598 send_labelmessage(nbr
, MSG_TYPE_LABELMAPPING
,
601 case IMSG_RELEASE_ADD_END
:
602 send_labelmessage(nbr
, MSG_TYPE_LABELRELEASE
,
605 case IMSG_REQUEST_ADD_END
:
606 send_labelmessage(nbr
, MSG_TYPE_LABELREQUEST
,
609 case IMSG_WITHDRAW_ADD_END
:
610 send_labelmessage(nbr
, MSG_TYPE_LABELWITHDRAW
,
611 &nbr
->withdraw_list
);
615 case IMSG_NOTIFICATION_SEND
:
616 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!= sizeof(nm
))
617 fatalx("invalid size of OE request");
618 memcpy(&nm
, imsg
.data
, sizeof(nm
));
620 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
622 log_debug("ldpe_dispatch_lde: cannot find "
626 if (nbr
->state
!= NBR_STA_OPER
)
629 send_notification_full(nbr
->tcp
, &nm
);
632 case IMSG_CTL_SHOW_LIB
:
633 case IMSG_CTL_SHOW_L2VPN_PW
:
634 case IMSG_CTL_SHOW_L2VPN_BINDING
:
635 control_imsg_relay(&imsg
);
638 log_debug("ldpe_dispatch_lde: error handling imsg %d",
647 /* this pipe is dead, so remove the event handlers and exit */
648 THREAD_READ_OFF(iev
->ev_read
);
649 THREAD_WRITE_OFF(iev
->ev_write
);
659 ldpe_dispatch_pfkey(struct thread
*thread
)
661 int fd
= THREAD_FD(thread
);
663 pfkey_ev
= thread_add_read(master
, ldpe_dispatch_pfkey
,
664 NULL
, global
.pfkeysock
);
666 if (pfkey_read(fd
, NULL
) == -1)
667 fatal("pfkey_read failed, exiting...");
671 #endif /* __OpenBSD__ */
674 ldpe_setup_sockets(int af
, int disc_socket
, int edisc_socket
,
677 struct ldpd_af_global
*af_global
;
679 af_global
= ldp_af_global_get(&global
, af
);
681 /* discovery socket */
682 af_global
->ldp_disc_socket
= disc_socket
;
683 af_global
->disc_ev
= thread_add_read(master
, disc_recv_packet
,
684 &af_global
->disc_ev
, af_global
->ldp_disc_socket
);
686 /* extended discovery socket */
687 af_global
->ldp_edisc_socket
= edisc_socket
;
688 af_global
->edisc_ev
= thread_add_read(master
, disc_recv_packet
,
689 &af_global
->edisc_ev
, af_global
->ldp_edisc_socket
);
692 af_global
->ldp_session_socket
= session_socket
;
693 accept_add(af_global
->ldp_session_socket
, session_accept
, NULL
);
697 ldpe_close_sockets(int af
)
699 struct ldpd_af_global
*af_global
;
701 af_global
= ldp_af_global_get(&global
, af
);
703 /* discovery socket */
704 THREAD_READ_OFF(af_global
->disc_ev
);
705 if (af_global
->ldp_disc_socket
!= -1) {
706 close(af_global
->ldp_disc_socket
);
707 af_global
->ldp_disc_socket
= -1;
710 /* extended discovery socket */
711 THREAD_READ_OFF(af_global
->edisc_ev
);
712 if (af_global
->ldp_edisc_socket
!= -1) {
713 close(af_global
->ldp_edisc_socket
);
714 af_global
->ldp_edisc_socket
= -1;
718 if (af_global
->ldp_session_socket
!= -1) {
719 accept_del(af_global
->ldp_session_socket
);
720 close(af_global
->ldp_session_socket
);
721 af_global
->ldp_session_socket
= -1;
726 ldpe_acl_check(char *acl_name
, int af
, union ldpd_addr
*addr
, uint8_t prefixlen
)
728 return ldp_acl_request(iev_main_sync
, acl_name
, af
, addr
, prefixlen
);
732 ldpe_reset_nbrs(int af
)
736 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
737 if (af
== AF_UNSPEC
|| nbr
->af
== af
)
738 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
743 ldpe_reset_ds_nbrs(void)
747 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
749 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
754 ldpe_remove_dynamic_tnbrs(int af
)
756 struct tnbr
*tnbr
, *safe
;
758 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &leconf
->tnbr_tree
, safe
) {
762 tnbr
->flags
&= ~F_TNBR_DYNAMIC
;
763 tnbr_check(leconf
, tnbr
);
768 ldpe_stop_init_backoff(int af
)
772 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
773 if (nbr
->af
== af
&& nbr_pending_idtimer(nbr
)) {
774 nbr_stop_idtimer(nbr
);
775 nbr_establish_connection(nbr
);
781 ldpe_iface_af_ctl(struct ctl_conn
*c
, int af
, unsigned int idx
)
785 struct ctl_iface
*ictl
;
787 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
788 if (idx
== 0 || idx
== iface
->ifindex
) {
789 ia
= iface_af_get(iface
, af
);
793 ictl
= if_to_ctl(ia
);
794 imsg_compose_event(&c
->iev
,
795 IMSG_CTL_SHOW_INTERFACE
,
796 0, 0, -1, ictl
, sizeof(struct ctl_iface
));
802 ldpe_iface_ctl(struct ctl_conn
*c
, unsigned int idx
)
804 ldpe_iface_af_ctl(c
, AF_INET
, idx
);
805 ldpe_iface_af_ctl(c
, AF_INET6
, idx
);
809 ldpe_adj_ctl(struct ctl_conn
*c
)
814 struct ctl_adj
*actl
;
815 struct ctl_disc_if ictl
;
816 struct ctl_disc_tnbr tctl
;
818 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
820 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
821 memset(&ictl
, 0, sizeof(ictl
));
822 ictl
.active_v4
= (iface
->ipv4
.state
== IF_STA_ACTIVE
);
823 ictl
.active_v6
= (iface
->ipv6
.state
== IF_STA_ACTIVE
);
825 if (!ictl
.active_v4
&& !ictl
.active_v6
)
828 strlcpy(ictl
.name
, iface
->name
, sizeof(ictl
.name
));
829 if (RB_EMPTY(&iface
->ipv4
.adj_tree
) &&
830 RB_EMPTY(&iface
->ipv6
.adj_tree
))
832 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_IFACE
, 0, 0,
833 -1, &ictl
, sizeof(ictl
));
835 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv4
.adj_tree
) {
836 actl
= adj_to_ctl(adj
);
837 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
838 0, 0, -1, actl
, sizeof(struct ctl_adj
));
840 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv6
.adj_tree
) {
841 actl
= adj_to_ctl(adj
);
842 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
843 0, 0, -1, actl
, sizeof(struct ctl_adj
));
847 RB_FOREACH(tnbr
, tnbr_head
, &leconf
->tnbr_tree
) {
848 memset(&tctl
, 0, sizeof(tctl
));
850 tctl
.addr
= tnbr
->addr
;
851 if (tnbr
->adj
== NULL
)
854 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_TNBR
, 0, 0,
855 -1, &tctl
, sizeof(tctl
));
857 if (tnbr
->adj
== NULL
)
860 actl
= adj_to_ctl(tnbr
->adj
);
861 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
, 0, 0,
862 -1, actl
, sizeof(struct ctl_adj
));
865 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
869 ldpe_nbr_ctl(struct ctl_conn
*c
)
872 struct ctl_adj
*actl
;
874 struct ctl_nbr
*nctl
;
876 RB_FOREACH(nbr
, nbr_addr_head
, &nbrs_by_addr
) {
877 if (nbr
->state
== NBR_STA_PRESENT
)
880 nctl
= nbr_to_ctl(nbr
);
881 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, nctl
,
882 sizeof(struct ctl_nbr
));
884 RB_FOREACH(adj
, nbr_adj_head
, &nbr
->adj_tree
) {
885 actl
= adj_to_ctl(adj
);
886 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_DISC
,
887 0, 0, -1, actl
, sizeof(struct ctl_adj
));
890 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_END
, 0, 0, -1,
893 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
897 mapping_list_add(struct mapping_head
*mh
, struct map
*map
)
899 struct mapping_entry
*me
;
901 me
= calloc(1, sizeof(*me
));
906 TAILQ_INSERT_TAIL(mh
, me
, entry
);
910 mapping_list_clr(struct mapping_head
*mh
)
912 struct mapping_entry
*me
;
914 while ((me
= TAILQ_FIRST(mh
)) != NULL
) {
915 TAILQ_REMOVE(mh
, me
, entry
);