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();
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_init(&ldpe_privs
);
147 /* listen on ldpd control socket */
148 strlcpy(ctl_sock_path
, init
->ctl_sock_path
, sizeof(ctl_sock_path
));
149 if (control_init(ctl_sock_path
) == -1)
150 fatalx("control socket setup failed");
151 TAILQ_INIT(&ctl_conns
);
155 if (pledge("stdio cpath inet mcast recvfd", NULL
) == -1)
159 LIST_INIT(&global
.addr_list
);
160 RB_INIT(&global
.adj_tree
);
161 TAILQ_INIT(&global
.pending_conns
);
162 if (inet_pton(AF_INET
, AllRouters_v4
, &global
.mcast_addr_v4
) != 1)
164 if (inet_pton(AF_INET6
, AllRouters_v6
, &global
.mcast_addr_v6
) != 1)
167 global
.pfkeysock
= pfkey_init();
168 if (sysdep
.no_pfkey
== 0) {
170 thread_add_read(master
, ldpe_dispatch_pfkey
, NULL
, global
.pfkeysock
,
175 /* mark sockets as closed */
176 global
.ipv4
.ldp_disc_socket
= -1;
177 global
.ipv4
.ldp_edisc_socket
= -1;
178 global
.ipv4
.ldp_session_socket
= -1;
179 global
.ipv6
.ldp_disc_socket
= -1;
180 global
.ipv6
.ldp_edisc_socket
= -1;
181 global
.ipv6
.ldp_session_socket
= -1;
183 if ((pkt_ptr
= calloc(1, IBUF_READ_SIZE
)) == NULL
)
192 struct if_addr
*if_addr
;
197 msgbuf_write(&iev_lde
->ibuf
.w
);
198 msgbuf_clear(&iev_lde
->ibuf
.w
);
199 close(iev_lde
->ibuf
.fd
);
201 msgbuf_write(&iev_main
->ibuf
.w
);
202 msgbuf_clear(&iev_main
->ibuf
.w
);
203 close(iev_main
->ibuf
.fd
);
204 msgbuf_clear(&iev_main_sync
->ibuf
.w
);
205 close(iev_main_sync
->ibuf
.fd
);
207 control_cleanup(ctl_sock_path
);
208 config_clear(leconf
);
211 if (sysdep
.no_pfkey
== 0) {
212 THREAD_READ_OFF(pfkey_ev
);
213 close(global
.pfkeysock
);
216 ldpe_close_sockets(AF_INET
);
217 ldpe_close_sockets(AF_INET6
);
219 /* remove addresses from global list */
220 while ((if_addr
= LIST_FIRST(&global
.addr_list
)) != NULL
) {
221 LIST_REMOVE(if_addr
, entry
);
224 while ((adj
= RB_ROOT(&global
.adj_tree
)) != NULL
)
225 adj_del(adj
, S_SHUTDOWN
);
234 log_info("ldp engine exiting");
240 ldpe_imsg_compose_parent(int type
, pid_t pid
, void *data
, uint16_t datalen
)
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 imsg_compose_event(iev_main_sync
, type
, 0, pid
, -1, data
, datalen
);
249 imsg_flush(&iev_main_sync
->ibuf
);
253 ldpe_imsg_compose_lde(int type
, uint32_t peerid
, pid_t pid
, void *data
,
256 return (imsg_compose_event(iev_lde
, type
, peerid
, pid
, -1,
262 ldpe_dispatch_main(struct thread
*thread
)
264 static struct ldpd_conf
*nconf
;
265 struct iface
*niface
;
267 struct nbr_params
*nnbrp
;
268 static struct l2vpn
*l2vpn
, *nl2vpn
;
269 struct l2vpn_if
*lif
, *nlif
;
270 struct l2vpn_pw
*pw
, *npw
;
272 int fd
= THREAD_FD(thread
);
273 struct imsgev
*iev
= THREAD_ARG(thread
);
274 struct imsgbuf
*ibuf
= &iev
->ibuf
;
275 struct iface
*iface
= NULL
;
278 enum socket_type
*socket_type
;
279 static int disc_socket
= -1;
280 static int edisc_socket
= -1;
281 static int session_socket
= -1;
284 struct nbr_params
*nbrp
;
290 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
291 fatal("imsg_read error");
292 if (n
== 0) /* connection closed */
296 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
297 fatal("ldpe_dispatch_main: imsg_get error");
301 switch (imsg
.hdr
.type
) {
303 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
305 fatalx("IFSTATUS imsg with wrong len");
308 iface
= if_lookup_name(leconf
, kif
->ifname
);
310 if_update_info(iface
, kif
);
311 ldp_if_update(iface
, AF_UNSPEC
);
315 RB_FOREACH(l2vpn
, l2vpn_head
, &leconf
->l2vpn_tree
) {
316 lif
= l2vpn_if_find(l2vpn
, kif
->ifname
);
318 l2vpn_if_update_info(lif
, kif
);
319 l2vpn_if_update(lif
);
322 pw
= l2vpn_pw_find(l2vpn
, kif
->ifname
);
324 l2vpn_pw_update_info(pw
, kif
);
330 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
331 sizeof(struct kaddr
))
332 fatalx("NEWADDR imsg with wrong len");
334 if_addr_add(imsg
.data
);
337 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
338 sizeof(struct kaddr
))
339 fatalx("DELADDR imsg with wrong len");
341 if_addr_del(imsg
.data
);
343 case IMSG_SOCKET_IPC
:
345 log_warnx("%s: received unexpected imsg fd "
349 if ((fd
= imsg
.fd
) == -1) {
350 log_warnx("%s: expected to receive imsg fd to "
351 "lde but didn't receive any", __func__
);
355 if ((iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
357 imsg_init(&iev_lde
->ibuf
, fd
);
358 iev_lde
->handler_read
= ldpe_dispatch_lde
;
359 iev_lde
->ev_read
= NULL
;
360 thread_add_read(master
, iev_lde
->handler_read
, iev_lde
, iev_lde
->ibuf
.fd
,
362 iev_lde
->handler_write
= ldp_write_handler
;
363 iev_lde
->ev_write
= NULL
;
366 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
367 sizeof(struct ldpd_init
))
368 fatalx("INIT imsg with wrong len");
370 memcpy(&init
, imsg
.data
, sizeof(init
));
373 case IMSG_CLOSE_SOCKETS
:
374 af
= imsg
.hdr
.peerid
;
376 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
379 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
383 nbr
->auth
.method
= AUTH_NONE
;
385 ldpe_close_sockets(af
);
392 if ((ldp_af_conf_get(leconf
, af
))->flags
&
394 ldpe_imsg_compose_parent(IMSG_REQUEST_SOCKETS
,
397 case IMSG_SOCKET_NET
:
398 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
399 sizeof(enum socket_type
))
400 fatalx("SOCKET_NET imsg with wrong len");
401 socket_type
= imsg
.data
;
403 switch (*socket_type
) {
404 case LDP_SOCKET_DISC
:
405 disc_socket
= imsg
.fd
;
407 case LDP_SOCKET_EDISC
:
408 edisc_socket
= imsg
.fd
;
410 case LDP_SOCKET_SESSION
:
411 session_socket
= imsg
.fd
;
415 case IMSG_SETUP_SOCKETS
:
416 af
= imsg
.hdr
.peerid
;
417 if (disc_socket
== -1 || edisc_socket
== -1 ||
418 session_socket
== -1) {
419 if (disc_socket
!= -1)
421 if (edisc_socket
!= -1)
423 if (session_socket
!= -1)
424 close(session_socket
);
428 ldpe_setup_sockets(af
, disc_socket
, edisc_socket
,
432 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
435 nbr
->laddr
= (ldp_af_conf_get(leconf
,
438 nbrp
= nbr_params_find(leconf
, nbr
->id
);
440 nbr
->auth
.method
= nbrp
->auth
.method
;
441 if (pfkey_establish(nbr
, nbrp
) == -1)
442 fatalx("pfkey setup failed");
445 if (nbr_session_active_role(nbr
))
446 nbr_establish_connection(nbr
);
449 case IMSG_RTRID_UPDATE
:
450 memcpy(&global
.rtr_id
, imsg
.data
,
451 sizeof(global
.rtr_id
));
452 if (leconf
->rtr_id
.s_addr
== INADDR_ANY
) {
453 ldpe_reset_nbrs(AF_UNSPEC
);
455 if_update_all(AF_UNSPEC
);
456 tnbr_update_all(AF_UNSPEC
);
458 case IMSG_RECONF_CONF
:
459 if ((nconf
= malloc(sizeof(struct ldpd_conf
))) ==
462 memcpy(nconf
, imsg
.data
, sizeof(struct ldpd_conf
));
464 RB_INIT(&nconf
->iface_tree
);
465 RB_INIT(&nconf
->tnbr_tree
);
466 RB_INIT(&nconf
->nbrp_tree
);
467 RB_INIT(&nconf
->l2vpn_tree
);
469 case IMSG_RECONF_IFACE
:
470 if ((niface
= malloc(sizeof(struct iface
))) == NULL
)
472 memcpy(niface
, imsg
.data
, sizeof(struct iface
));
474 RB_INSERT(iface_head
, &nconf
->iface_tree
, niface
);
476 case IMSG_RECONF_TNBR
:
477 if ((ntnbr
= malloc(sizeof(struct tnbr
))) == NULL
)
479 memcpy(ntnbr
, imsg
.data
, sizeof(struct tnbr
));
481 RB_INSERT(tnbr_head
, &nconf
->tnbr_tree
, ntnbr
);
483 case IMSG_RECONF_NBRP
:
484 if ((nnbrp
= malloc(sizeof(struct nbr_params
))) == NULL
)
486 memcpy(nnbrp
, imsg
.data
, sizeof(struct nbr_params
));
488 RB_INSERT(nbrp_head
, &nconf
->nbrp_tree
, nnbrp
);
490 case IMSG_RECONF_L2VPN
:
491 if ((nl2vpn
= malloc(sizeof(struct l2vpn
))) == NULL
)
493 memcpy(nl2vpn
, imsg
.data
, sizeof(struct l2vpn
));
495 RB_INIT(&nl2vpn
->if_tree
);
496 RB_INIT(&nl2vpn
->pw_tree
);
497 RB_INIT(&nl2vpn
->pw_inactive_tree
);
499 RB_INSERT(l2vpn_head
, &nconf
->l2vpn_tree
, nl2vpn
);
501 case IMSG_RECONF_L2VPN_IF
:
502 if ((nlif
= malloc(sizeof(struct l2vpn_if
))) == NULL
)
504 memcpy(nlif
, imsg
.data
, sizeof(struct l2vpn_if
));
506 RB_INSERT(l2vpn_if_head
, &nl2vpn
->if_tree
, nlif
);
508 case IMSG_RECONF_L2VPN_PW
:
509 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
511 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
513 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_tree
, npw
);
515 case IMSG_RECONF_L2VPN_IPW
:
516 if ((npw
= malloc(sizeof(struct l2vpn_pw
))) == NULL
)
518 memcpy(npw
, imsg
.data
, sizeof(struct l2vpn_pw
));
520 RB_INSERT(l2vpn_pw_head
, &nl2vpn
->pw_inactive_tree
, npw
);
522 case IMSG_RECONF_END
:
523 merge_config(leconf
, nconf
);
524 ldp_clear_config(nconf
);
526 global
.conf_seqnum
++;
529 control_imsg_relay(&imsg
);
531 case IMSG_DEBUG_UPDATE
:
532 if (imsg
.hdr
.len
!= IMSG_HEADER_SIZE
+
534 log_warnx("%s: wrong imsg len", __func__
);
537 memcpy(&ldp_debug
, imsg
.data
, sizeof(ldp_debug
));
540 log_debug("ldpe_dispatch_main: error handling imsg %d",
549 /* this pipe is dead, so remove the event handlers and exit */
550 THREAD_READ_OFF(iev
->ev_read
);
551 THREAD_WRITE_OFF(iev
->ev_write
);
560 ldpe_dispatch_lde(struct thread
*thread
)
562 struct imsgev
*iev
= THREAD_ARG(thread
);
563 struct imsgbuf
*ibuf
= &iev
->ibuf
;
566 struct notify_msg
*nm
;
572 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
573 fatal("imsg_read error");
574 if (n
== 0) /* connection closed */
578 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
579 fatal("ldpe_dispatch_lde: imsg_get error");
583 switch (imsg
.hdr
.type
) {
584 case IMSG_MAPPING_ADD
:
585 case IMSG_RELEASE_ADD
:
586 case IMSG_REQUEST_ADD
:
587 case IMSG_WITHDRAW_ADD
:
588 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
590 fatalx("invalid size of map request");
593 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
595 log_debug("ldpe_dispatch_lde: cannot find "
599 if (nbr
->state
!= NBR_STA_OPER
)
602 switch (imsg
.hdr
.type
) {
603 case IMSG_MAPPING_ADD
:
604 mapping_list_add(&nbr
->mapping_list
, map
);
606 case IMSG_RELEASE_ADD
:
607 mapping_list_add(&nbr
->release_list
, map
);
609 case IMSG_REQUEST_ADD
:
610 mapping_list_add(&nbr
->request_list
, map
);
612 case IMSG_WITHDRAW_ADD
:
613 mapping_list_add(&nbr
->withdraw_list
, map
);
617 case IMSG_MAPPING_ADD_END
:
618 case IMSG_RELEASE_ADD_END
:
619 case IMSG_REQUEST_ADD_END
:
620 case IMSG_WITHDRAW_ADD_END
:
621 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
623 log_debug("ldpe_dispatch_lde: cannot find "
627 if (nbr
->state
!= NBR_STA_OPER
)
630 switch (imsg
.hdr
.type
) {
631 case IMSG_MAPPING_ADD_END
:
632 send_labelmessage(nbr
, MSG_TYPE_LABELMAPPING
,
635 case IMSG_RELEASE_ADD_END
:
636 send_labelmessage(nbr
, MSG_TYPE_LABELRELEASE
,
639 case IMSG_REQUEST_ADD_END
:
640 send_labelmessage(nbr
, MSG_TYPE_LABELREQUEST
,
643 case IMSG_WITHDRAW_ADD_END
:
644 send_labelmessage(nbr
, MSG_TYPE_LABELWITHDRAW
,
645 &nbr
->withdraw_list
);
649 case IMSG_NOTIFICATION_SEND
:
650 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
651 sizeof(struct notify_msg
))
652 fatalx("invalid size of OE request");
655 nbr
= nbr_find_peerid(imsg
.hdr
.peerid
);
657 log_debug("ldpe_dispatch_lde: cannot find "
661 if (nbr
->state
!= NBR_STA_OPER
)
664 send_notification_full(nbr
->tcp
, nm
);
667 case IMSG_CTL_SHOW_LIB_BEGIN
:
668 case IMSG_CTL_SHOW_LIB_RCVD
:
669 case IMSG_CTL_SHOW_LIB_SENT
:
670 case IMSG_CTL_SHOW_LIB_END
:
671 case IMSG_CTL_SHOW_L2VPN_PW
:
672 case IMSG_CTL_SHOW_L2VPN_BINDING
:
673 control_imsg_relay(&imsg
);
676 log_debug("ldpe_dispatch_lde: error handling imsg %d",
685 /* this pipe is dead, so remove the event handlers and exit */
686 THREAD_READ_OFF(iev
->ev_read
);
687 THREAD_WRITE_OFF(iev
->ev_write
);
697 ldpe_dispatch_pfkey(struct thread
*thread
)
699 int fd
= THREAD_FD(thread
);
702 thread_add_read(master
, ldpe_dispatch_pfkey
, NULL
, global
.pfkeysock
,
705 if (pfkey_read(fd
, NULL
) == -1)
706 fatal("pfkey_read failed, exiting...");
710 #endif /* __OpenBSD__ */
713 ldpe_setup_sockets(int af
, int disc_socket
, int edisc_socket
,
716 struct ldpd_af_global
*af_global
;
718 af_global
= ldp_af_global_get(&global
, af
);
720 /* discovery socket */
721 af_global
->ldp_disc_socket
= disc_socket
;
722 af_global
->disc_ev
= NULL
;
723 thread_add_read(master
, disc_recv_packet
, &af_global
->disc_ev
, af_global
->ldp_disc_socket
,
724 &af_global
->disc_ev
);
726 /* extended discovery socket */
727 af_global
->ldp_edisc_socket
= edisc_socket
;
728 af_global
->edisc_ev
= NULL
;
729 thread_add_read(master
, disc_recv_packet
, &af_global
->edisc_ev
, af_global
->ldp_edisc_socket
,
730 &af_global
->edisc_ev
);
733 af_global
->ldp_session_socket
= session_socket
;
734 accept_add(af_global
->ldp_session_socket
, session_accept
, NULL
);
738 ldpe_close_sockets(int af
)
740 struct ldpd_af_global
*af_global
;
742 af_global
= ldp_af_global_get(&global
, af
);
744 /* discovery socket */
745 THREAD_READ_OFF(af_global
->disc_ev
);
746 if (af_global
->ldp_disc_socket
!= -1) {
747 close(af_global
->ldp_disc_socket
);
748 af_global
->ldp_disc_socket
= -1;
751 /* extended discovery socket */
752 THREAD_READ_OFF(af_global
->edisc_ev
);
753 if (af_global
->ldp_edisc_socket
!= -1) {
754 close(af_global
->ldp_edisc_socket
);
755 af_global
->ldp_edisc_socket
= -1;
759 if (af_global
->ldp_session_socket
!= -1) {
760 accept_del(af_global
->ldp_session_socket
);
761 close(af_global
->ldp_session_socket
);
762 af_global
->ldp_session_socket
= -1;
767 ldpe_acl_check(char *acl_name
, int af
, union ldpd_addr
*addr
, uint8_t prefixlen
)
769 return ldp_acl_request(iev_main_sync
, acl_name
, af
, addr
, prefixlen
);
773 ldpe_reset_nbrs(int af
)
777 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
778 if (af
== AF_UNSPEC
|| nbr
->af
== af
)
779 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
784 ldpe_reset_ds_nbrs(void)
788 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
790 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
795 ldpe_remove_dynamic_tnbrs(int af
)
797 struct tnbr
*tnbr
, *safe
;
799 RB_FOREACH_SAFE(tnbr
, tnbr_head
, &leconf
->tnbr_tree
, safe
) {
803 tnbr
->flags
&= ~F_TNBR_DYNAMIC
;
804 tnbr_check(leconf
, tnbr
);
809 ldpe_stop_init_backoff(int af
)
813 RB_FOREACH(nbr
, nbr_id_head
, &nbrs_by_id
) {
814 if (nbr
->af
== af
&& nbr_pending_idtimer(nbr
)) {
815 nbr_stop_idtimer(nbr
);
816 nbr_establish_connection(nbr
);
822 ldpe_iface_af_ctl(struct ctl_conn
*c
, int af
, unsigned int idx
)
826 struct ctl_iface
*ictl
;
828 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
829 if (idx
== 0 || idx
== iface
->ifindex
) {
830 ia
= iface_af_get(iface
, af
);
834 ictl
= if_to_ctl(ia
);
835 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_INTERFACE
,
836 0, 0, -1, ictl
, sizeof(struct ctl_iface
));
842 ldpe_iface_ctl(struct ctl_conn
*c
, unsigned int idx
)
844 ldpe_iface_af_ctl(c
, AF_INET
, idx
);
845 ldpe_iface_af_ctl(c
, AF_INET6
, idx
);
849 ldpe_adj_ctl(struct ctl_conn
*c
)
852 struct ctl_adj
*actl
;
854 RB_FOREACH(adj
, global_adj_head
, &global
.adj_tree
) {
855 actl
= adj_to_ctl(adj
);
856 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0,
857 -1, actl
, sizeof(struct ctl_adj
));
860 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
864 ldpe_adj_detail_ctl(struct ctl_conn
*c
)
869 struct ctl_adj
*actl
;
870 struct ctl_disc_if ictl
;
871 struct ctl_disc_tnbr tctl
;
873 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
875 RB_FOREACH(iface
, iface_head
, &leconf
->iface_tree
) {
876 memset(&ictl
, 0, sizeof(ictl
));
877 ictl
.active_v4
= (iface
->ipv4
.state
== IF_STA_ACTIVE
);
878 ictl
.active_v6
= (iface
->ipv6
.state
== IF_STA_ACTIVE
);
880 if (!ictl
.active_v4
&& !ictl
.active_v6
)
883 strlcpy(ictl
.name
, iface
->name
, sizeof(ictl
.name
));
884 if (RB_EMPTY(&iface
->ipv4
.adj_tree
) &&
885 RB_EMPTY(&iface
->ipv6
.adj_tree
))
887 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_IFACE
, 0, 0,
888 -1, &ictl
, sizeof(ictl
));
890 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv4
.adj_tree
) {
891 actl
= adj_to_ctl(adj
);
892 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
893 0, 0, -1, actl
, sizeof(struct ctl_adj
));
895 RB_FOREACH(adj
, ia_adj_head
, &iface
->ipv6
.adj_tree
) {
896 actl
= adj_to_ctl(adj
);
897 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
,
898 0, 0, -1, actl
, sizeof(struct ctl_adj
));
902 RB_FOREACH(tnbr
, tnbr_head
, &leconf
->tnbr_tree
) {
903 memset(&tctl
, 0, sizeof(tctl
));
905 tctl
.addr
= tnbr
->addr
;
906 if (tnbr
->adj
== NULL
)
909 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_TNBR
, 0, 0,
910 -1, &tctl
, sizeof(tctl
));
912 if (tnbr
->adj
== NULL
)
915 actl
= adj_to_ctl(tnbr
->adj
);
916 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_DISC_ADJ
, 0, 0,
917 -1, actl
, sizeof(struct ctl_adj
));
920 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
924 ldpe_nbr_ctl(struct ctl_conn
*c
)
927 struct ctl_adj
*actl
;
929 struct ctl_nbr
*nctl
;
931 RB_FOREACH(nbr
, nbr_addr_head
, &nbrs_by_addr
) {
932 if (nbr
->state
== NBR_STA_PRESENT
)
935 nctl
= nbr_to_ctl(nbr
);
936 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, nctl
,
937 sizeof(struct ctl_nbr
));
939 RB_FOREACH(adj
, nbr_adj_head
, &nbr
->adj_tree
) {
940 actl
= adj_to_ctl(adj
);
941 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_DISC
,
942 0, 0, -1, actl
, sizeof(struct ctl_adj
));
945 imsg_compose_event(&c
->iev
, IMSG_CTL_SHOW_NBR_END
, 0, 0, -1,
948 imsg_compose_event(&c
->iev
, IMSG_CTL_END
, 0, 0, -1, NULL
, 0);
952 mapping_list_add(struct mapping_head
*mh
, struct map
*map
)
954 struct mapping_entry
*me
;
956 me
= calloc(1, sizeof(*me
));
961 TAILQ_INSERT_TAIL(mh
, me
, entry
);
965 mapping_list_clr(struct mapping_head
*mh
)
967 struct mapping_entry
*me
;
969 while ((me
= TAILQ_FIRST(mh
)) != NULL
) {
970 TAILQ_REMOVE(mh
, me
, entry
);