2 * Copyright (C) 2016 by Open Source Routing.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 #include "lib/printfrr.h"
53 struct in_addr lsr_id
;
59 struct in_addr neighbor
;
61 uint32_t remote_label
;
66 uint32_t remote_label
;
67 char ifname
[IFNAMSIZ
];
73 #define LDPBUFSIZ 65535
75 static int show_interface_msg(struct vty
*, struct imsg
*,
76 struct show_params
*);
77 static int show_interface_msg_json(struct imsg
*,
78 struct show_params
*, json_object
*);
79 static int show_discovery_msg(struct vty
*, struct imsg
*,
80 struct show_params
*);
81 static void show_discovery_detail_adj(struct vty
*, char *,
83 static int show_discovery_detail_msg(struct vty
*, struct imsg
*,
84 struct show_params
*);
85 static int show_discovery_msg_json(struct imsg
*,
86 struct show_params
*, json_object
*);
87 static void show_discovery_detail_adj_json(json_object
*,
89 static int show_discovery_detail_msg_json(struct imsg
*,
90 struct show_params
*, json_object
*);
91 static int show_ldp_sync_msg(struct vty
*, struct imsg
*,
92 struct show_params
*);
93 static int show_ldp_sync_msg_json(struct imsg
*,
94 struct show_params
*, json_object
*);
96 static int show_nbr_msg(struct vty
*, struct imsg
*,
97 struct show_params
*);
98 static int show_nbr_msg_json(struct imsg
*, struct show_params
*,
100 static void show_nbr_detail_adj(struct vty
*, char *,
102 static int show_nbr_detail_msg(struct vty
*, struct imsg
*,
103 struct show_params
*);
104 static void show_nbr_detail_adj_json(struct ctl_adj
*,
106 static int show_nbr_detail_msg_json(struct imsg
*,
107 struct show_params
*, json_object
*);
108 static void show_nbr_capabilities(struct vty
*, struct ctl_nbr
*);
109 static int show_nbr_capabilities_msg(struct vty
*, struct imsg
*,
110 struct show_params
*);
111 static void show_nbr_capabilities_json(struct ctl_nbr
*,
113 static int show_nbr_capabilities_msg_json(struct imsg
*,
114 struct show_params
*, json_object
*);
115 static int show_lib_msg(struct vty
*, struct imsg
*,
116 struct show_params
*);
117 static int show_lib_detail_msg(struct vty
*, struct imsg
*,
118 struct show_params
*);
119 static int show_lib_msg_json(struct imsg
*, struct show_params
*,
121 static int show_lib_detail_msg_json(struct imsg
*,
122 struct show_params
*, json_object
*);
123 static int show_l2vpn_binding_msg(struct vty
*, struct imsg
*,
124 struct show_params
*);
125 static int show_l2vpn_binding_msg_json(struct imsg
*,
126 struct show_params
*, json_object
*);
127 static int show_l2vpn_pw_msg(struct vty
*, struct imsg
*,
128 struct show_params
*);
129 static int show_l2vpn_pw_msg_json(struct imsg
*,
130 struct show_params
*, json_object
*);
131 static int ldp_vty_dispatch_msg(struct vty
*, struct imsg
*,
132 enum show_command
, struct show_params
*,
134 static int ldp_vty_dispatch(struct vty
*, struct imsgbuf
*,
135 enum show_command
, struct show_params
*);
136 static int ldp_vty_get_af(const char *, int *);
139 show_interface_msg(struct vty
*vty
, struct imsg
*imsg
,
140 struct show_params
*params
)
142 struct ctl_iface
*iface
;
145 switch (imsg
->hdr
.type
) {
146 case IMSG_CTL_SHOW_INTERFACE
:
149 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
152 snprintf(timers
, sizeof(timers
), "%u/%u",
153 iface
->hello_interval
, iface
->hello_holdtime
);
155 vty_out (vty
, "%-4s %-11s %-6s %-8s %-12s %3u\n",
156 af_name(iface
->af
), iface
->name
,
157 if_state_name(iface
->state
), iface
->uptime
== 0 ?
158 "00:00:00" : log_time(iface
->uptime
), timers
,
172 show_interface_msg_json(struct imsg
*imsg
, struct show_params
*params
,
175 struct ctl_iface
*iface
;
176 json_object
*json_iface
;
179 switch (imsg
->hdr
.type
) {
180 case IMSG_CTL_SHOW_INTERFACE
:
183 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
186 json_iface
= json_object_new_object();
187 json_object_string_add(json_iface
, "name", iface
->name
);
188 json_object_string_add(json_iface
, "addressFamily",
190 json_object_string_add(json_iface
, "state",
191 if_state_name(iface
->state
));
192 json_object_string_add(json_iface
, "upTime",
193 log_time(iface
->uptime
));
194 json_object_int_add(json_iface
, "helloInterval",
195 iface
->hello_interval
);
196 json_object_int_add(json_iface
, "helloHoldtime",
197 iface
->hello_holdtime
);
198 json_object_int_add(json_iface
, "adjacencyCount",
201 snprintf(key_name
, sizeof(key_name
), "%s: %s", iface
->name
,
203 json_object_object_add(json
, key_name
, json_iface
);
215 show_ldp_sync_msg(struct vty
*vty
, struct imsg
*imsg
,
216 struct show_params
*params
)
218 struct ctl_ldp_sync
*iface
;
220 switch (imsg
->hdr
.type
) {
221 case IMSG_CTL_SHOW_LDP_SYNC
:
224 vty_out (vty
, "%s:\n", iface
->name
);
226 vty_out (vty
, " Status: initial label exchange complete\n");
228 vty_out (vty
, " Status: label exchange not complete\n");
230 if (iface
->timer_running
) {
231 vty_out (vty
, " Wait time: %d seconds (%d seconds left)\n",
232 iface
->wait_time
, iface
->wait_time_remaining
);
233 vty_out (vty
, " Timer is running\n");
235 vty_out (vty
, " Wait time: %d seconds\n",
237 vty_out (vty
, " Timer is not running\n");
240 if (iface
->peer_ldp_id
.s_addr
)
241 vty_out (vty
, " Peer LDP Identifier: %pI4:0\n",
242 &iface
->peer_ldp_id
);
255 show_ldp_sync_msg_json(struct imsg
*imsg
, struct show_params
*params
,
258 struct ctl_ldp_sync
*iface
;
259 json_object
*json_iface
;
260 char buf
[PREFIX_STRLEN
];
262 switch (imsg
->hdr
.type
) {
263 case IMSG_CTL_SHOW_LDP_SYNC
:
266 json_iface
= json_object_new_object();
267 json_object_string_add(json_iface
, "state",
269 ? "labelExchangeComplete"
270 : "labelExchangeNotComplete");
271 json_object_int_add(json_iface
, "waitTime",
273 json_object_int_add(json_iface
, "waitTimeRemaining",
274 iface
->wait_time_remaining
);
276 if (iface
->timer_running
)
277 json_object_boolean_true_add(json_iface
, "timerRunning");
279 json_object_boolean_false_add(json_iface
, "timerRunning");
281 json_object_string_add(json_iface
, "peerLdpId",
282 iface
->peer_ldp_id
.s_addr
?
283 inet_ntop(AF_INET
, &iface
->peer_ldp_id
, buf
, sizeof(buf
)) :
286 json_object_object_add(json
, iface
->name
, json_iface
);
298 show_discovery_msg(struct vty
*vty
, struct imsg
*imsg
,
299 struct show_params
*params
)
304 switch (imsg
->hdr
.type
) {
305 case IMSG_CTL_SHOW_DISCOVERY
:
308 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
311 vty_out(vty
, "%-4s %-15pI4 ", af_name(adj
->af
), &adj
->id
);
314 vty_out(vty
, "%-8s %-15s ", "Link", adj
->ifname
);
317 addr
= log_addr(adj
->af
, &adj
->src_addr
);
319 vty_out(vty
, "%-8s %-15s ", "Targeted", addr
);
320 if (strlen(addr
) > 15)
321 vty_out(vty
, "\n%46s", " ");
324 vty_out (vty
, "%9u\n", adj
->holdtime
);
337 show_discovery_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
339 size_t buflen
= strlen(buffer
);
341 snprintfrr(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
342 " LSR Id: %pI4:0\n", &adj
->id
);
343 buflen
= strlen(buffer
);
344 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
345 " Source address: %s\n",
346 log_addr(adj
->af
, &adj
->src_addr
));
347 buflen
= strlen(buffer
);
348 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
349 " Transport address: %s\n",
350 log_addr(adj
->af
, &adj
->trans_addr
));
351 buflen
= strlen(buffer
);
352 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
353 " Hello hold time: %u secs (due in %u secs)\n",
354 adj
->holdtime
, adj
->holdtime_remaining
);
355 buflen
= strlen(buffer
);
356 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
357 " Dual-stack capability TLV: %s\n",
358 (adj
->ds_tlv
) ? "yes" : "no");
362 show_discovery_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
363 struct show_params
*params
)
366 struct ctl_disc_if
*iface
;
367 struct ctl_disc_tnbr
*tnbr
;
368 struct in_addr rtr_id
;
369 union ldpd_addr
*trans_addr
;
371 static char ifaces_buffer
[LDPBUFSIZ
];
372 static char tnbrs_buffer
[LDPBUFSIZ
];
374 switch (imsg
->hdr
.type
) {
375 case IMSG_CTL_SHOW_DISCOVERY
:
376 ifaces_buffer
[0] = '\0';
377 tnbrs_buffer
[0] = '\0';
379 case IMSG_CTL_SHOW_DISC_IFACE
:
382 if (params
->family
!= AF_UNSPEC
&&
383 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
384 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
387 buflen
= strlen(ifaces_buffer
);
388 snprintf(ifaces_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
389 " %s: %s\n", iface
->name
, (iface
->no_adj
) ?
390 "(no adjacencies)" : "");
392 case IMSG_CTL_SHOW_DISC_TNBR
:
395 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
398 trans_addr
= &(ldp_af_conf_get(ldpd_conf
,
399 tnbr
->af
))->trans_addr
;
400 buflen
= strlen(tnbrs_buffer
);
401 snprintf(tnbrs_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
402 " %s -> %s: %s\n", log_addr(tnbr
->af
, trans_addr
),
403 log_addr(tnbr
->af
, &tnbr
->addr
), (tnbr
->no_adj
) ?
404 "(no adjacencies)" : "");
406 case IMSG_CTL_SHOW_DISC_ADJ
:
409 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
414 show_discovery_detail_adj(vty
, ifaces_buffer
, adj
);
417 show_discovery_detail_adj(vty
, tnbrs_buffer
, adj
);
422 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
423 vty_out (vty
, "Local:\n");
424 vty_out (vty
, " LSR Id: %pI4:0\n",&rtr_id
);
425 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
426 vty_out (vty
, " Transport Address (IPv4): %s\n",
427 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
428 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
429 vty_out (vty
, " Transport Address (IPv6): %s\n",
430 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
431 vty_out (vty
, "Discovery Sources:\n");
432 vty_out (vty
, " Interfaces:\n");
433 vty_out(vty
, "%s", ifaces_buffer
);
434 vty_out (vty
, " Targeted Hellos:\n");
435 vty_out(vty
, "%s", tnbrs_buffer
);
446 show_discovery_msg_json(struct imsg
*imsg
, struct show_params
*params
,
450 json_object
*json_array
;
451 json_object
*json_adj
;
453 switch (imsg
->hdr
.type
) {
454 case IMSG_CTL_SHOW_DISCOVERY
:
457 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
460 json_object_object_get_ex(json
, "adjacencies", &json_array
);
462 json_array
= json_object_new_array();
463 json_object_object_add(json
, "adjacencies", json_array
);
466 json_adj
= json_object_new_object();
467 json_object_string_add(json_adj
, "addressFamily",
469 json_object_string_addf(json_adj
, "neighborId", "%pI4",
473 json_object_string_add(json_adj
, "type", "link");
474 json_object_string_add(json_adj
, "interface",
478 json_object_string_add(json_adj
, "type", "targeted");
479 json_object_string_add(json_adj
, "peer",
480 log_addr(adj
->af
, &adj
->src_addr
));
483 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
485 json_object_array_add(json_array
, json_adj
);
497 show_discovery_detail_adj_json(json_object
*json
, struct ctl_adj
*adj
)
499 json_object
*json_adj
;
500 json_object
*json_array
;
502 json_object_object_get_ex(json
, "adjacencies", &json_array
);
504 json_array
= json_object_new_array();
505 json_object_object_add(json
, "adjacencies", json_array
);
508 json_adj
= json_object_new_object();
509 json_object_string_addf(json_adj
, "lsrId", "%pI4", &adj
->id
);
510 json_object_string_add(json_adj
, "sourceAddress", log_addr(adj
->af
,
512 json_object_string_add(json_adj
, "transportAddress", log_addr(adj
->af
,
514 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
515 json_object_int_add(json_adj
, "helloHoldtimeRemaining",
516 adj
->holdtime_remaining
);
517 json_object_int_add(json_adj
, "dualStackCapabilityTlv",
519 json_object_array_add(json_array
, json_adj
);
523 show_discovery_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
527 struct ctl_disc_if
*iface
;
528 struct ctl_disc_tnbr
*tnbr
;
529 struct in_addr rtr_id
;
530 union ldpd_addr
*trans_addr
;
531 json_object
*json_interface
;
532 json_object
*json_target
;
533 static json_object
*json_interfaces
;
534 static json_object
*json_targets
;
535 static json_object
*json_container
;
537 switch (imsg
->hdr
.type
) {
538 case IMSG_CTL_SHOW_DISCOVERY
:
539 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
540 json_object_string_addf(json
, "lsrId", "%pI4", &rtr_id
);
541 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
542 json_object_string_add(json
, "transportAddressIPv4",
543 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
544 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
545 json_object_string_add(json
, "transportAddressIPv6",
546 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
547 json_interfaces
= json_object_new_object();
548 json_object_object_add(json
, "interfaces", json_interfaces
);
549 json_targets
= json_object_new_object();
550 json_object_object_add(json
, "targetedHellos", json_targets
);
551 json_container
= NULL
;
553 case IMSG_CTL_SHOW_DISC_IFACE
:
556 if (params
->family
!= AF_UNSPEC
&&
557 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
558 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
561 json_interface
= json_object_new_object();
562 json_object_object_add(json_interfaces
, iface
->name
,
564 json_container
= json_interface
;
566 case IMSG_CTL_SHOW_DISC_TNBR
:
569 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
572 trans_addr
= &(ldp_af_conf_get(ldpd_conf
, tnbr
->af
))->trans_addr
;
574 json_target
= json_object_new_object();
575 json_object_string_add(json_target
, "sourceAddress",
576 log_addr(tnbr
->af
, trans_addr
));
577 json_object_object_add(json_targets
, log_addr(tnbr
->af
,
578 &tnbr
->addr
), json_target
);
579 json_container
= json_target
;
581 case IMSG_CTL_SHOW_DISC_ADJ
:
584 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
589 show_discovery_detail_adj_json(json_container
, adj
);
592 show_discovery_detail_adj_json(json_container
, adj
);
606 show_nbr_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
611 switch (imsg
->hdr
.type
) {
612 case IMSG_CTL_SHOW_NBR
:
615 addr
= log_addr(nbr
->af
, &nbr
->raddr
);
617 vty_out(vty
, "%-4s %-15pI4 %-11s %-15s",
618 af_name(nbr
->af
), &nbr
->id
,
619 nbr_state_name(nbr
->nbr_state
), addr
);
620 if (strlen(addr
) > 15)
621 vty_out(vty
, "\n%48s", " ");
622 vty_out (vty
, " %8s\n", log_time(nbr
->uptime
));
634 show_nbr_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
636 size_t buflen
= strlen(buffer
);
640 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
641 " Interface: %s\n", adj
->ifname
);
644 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
645 " Targeted Hello: %s\n", log_addr(adj
->af
,
652 show_nbr_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
653 struct show_params
*params
)
656 struct ldp_stats
*stats
;
658 static char v4adjs_buffer
[LDPBUFSIZ
];
659 static char v6adjs_buffer
[LDPBUFSIZ
];
661 switch (imsg
->hdr
.type
) {
662 case IMSG_CTL_SHOW_NBR
:
665 v4adjs_buffer
[0] = '\0';
666 v6adjs_buffer
[0] = '\0';
667 vty_out (vty
, "Peer LDP Identifier: %pI4:0\n",
669 vty_out (vty
, " TCP connection: %s:%u - %s:%u\n",
670 log_addr(nbr
->af
, &nbr
->laddr
), ntohs(nbr
->lport
),
671 log_addr(nbr
->af
, &nbr
->raddr
),ntohs(nbr
->rport
));
672 vty_out (vty
, " Authentication: %s\n",
673 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" : "none");
674 vty_out(vty
, " Session Holdtime: %u secs; KeepAlive interval: %u secs\n", nbr
->holdtime
,
675 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
676 vty_out(vty
, " State: %s; Downstream-Unsolicited\n",
677 nbr_state_name(nbr
->nbr_state
));
678 vty_out (vty
, " Up time: %s\n",log_time(nbr
->uptime
));
681 vty_out (vty
, " Messages sent/rcvd:\n");
682 vty_out (vty
, " - Keepalive Messages: %u/%u\n",
683 stats
->kalive_sent
, stats
->kalive_rcvd
);
684 vty_out (vty
, " - Address Messages: %u/%u\n",
685 stats
->addr_sent
, stats
->addr_rcvd
);
686 vty_out (vty
, " - Address Withdraw Messages: %u/%u\n",
687 stats
->addrwdraw_sent
, stats
->addrwdraw_rcvd
);
688 vty_out (vty
, " - Notification Messages: %u/%u\n",
689 stats
->notif_sent
, stats
->notif_rcvd
);
690 vty_out (vty
, " - Capability Messages: %u/%u\n",
691 stats
->capability_sent
, stats
->capability_rcvd
);
692 vty_out (vty
, " - Label Mapping Messages: %u/%u\n",
693 stats
->labelmap_sent
, stats
->labelmap_rcvd
);
694 vty_out (vty
, " - Label Request Messages: %u/%u\n",
695 stats
->labelreq_sent
, stats
->labelreq_rcvd
);
696 vty_out (vty
, " - Label Withdraw Messages: %u/%u\n",
697 stats
->labelwdraw_sent
, stats
->labelwdraw_rcvd
);
698 vty_out (vty
, " - Label Release Messages: %u/%u\n",
699 stats
->labelrel_sent
, stats
->labelrel_rcvd
);
700 vty_out (vty
, " - Label Abort Request Messages: %u/%u\n",
701 stats
->labelabreq_sent
, stats
->labelabreq_rcvd
);
703 show_nbr_capabilities(vty
, nbr
);
705 case IMSG_CTL_SHOW_NBR_DISC
:
710 show_nbr_detail_adj(vty
, v4adjs_buffer
, adj
);
713 show_nbr_detail_adj(vty
, v6adjs_buffer
, adj
);
716 fatalx("show_nbr_detail_msg: unknown af");
719 case IMSG_CTL_SHOW_NBR_END
:
720 vty_out (vty
, " LDP Discovery Sources:\n");
721 if (v4adjs_buffer
[0] != '\0') {
722 vty_out (vty
, " IPv4:\n");
723 vty_out(vty
, "%s", v4adjs_buffer
);
725 if (v6adjs_buffer
[0] != '\0') {
726 vty_out (vty
, " IPv6:\n");
727 vty_out(vty
, "%s", v6adjs_buffer
);
741 show_nbr_msg_json(struct imsg
*imsg
, struct show_params
*params
,
745 json_object
*json_array
;
746 json_object
*json_nbr
;
748 switch (imsg
->hdr
.type
) {
749 case IMSG_CTL_SHOW_NBR
:
752 json_object_object_get_ex(json
, "neighbors", &json_array
);
754 json_array
= json_object_new_array();
755 json_object_object_add(json
, "neighbors", json_array
);
758 json_nbr
= json_object_new_object();
759 json_object_string_add(json_nbr
, "addressFamily",
761 json_object_string_addf(json_nbr
, "neighborId", "%pI4",
763 json_object_string_add(json_nbr
, "state",
764 nbr_state_name(nbr
->nbr_state
));
765 json_object_string_add(json_nbr
, "transportAddress",
766 log_addr(nbr
->af
, &nbr
->raddr
));
767 json_object_string_add(json_nbr
, "upTime",
768 log_time(nbr
->uptime
));
770 json_object_array_add(json_array
, json_nbr
);
782 show_nbr_detail_adj_json(struct ctl_adj
*adj
, json_object
*adj_list
)
784 char adj_string
[128];
788 strlcpy(adj_string
, "interface: ", sizeof(adj_string
));
789 strlcat(adj_string
, adj
->ifname
, sizeof(adj_string
));
792 strlcpy(adj_string
, "targetedHello: ", sizeof(adj_string
));
793 strlcat(adj_string
, log_addr(adj
->af
, &adj
->src_addr
),
798 json_object_array_add(adj_list
, json_object_new_string(adj_string
));
802 show_nbr_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
806 struct ldp_stats
*stats
;
808 char buf
[PREFIX_STRLEN
];
809 json_object
*json_nbr
;
810 json_object
*json_array
;
811 json_object
*json_counter
;
812 static json_object
*json_nbr_sources
;
813 static json_object
*json_v4adjs
;
814 static json_object
*json_v6adjs
;
816 switch (imsg
->hdr
.type
) {
817 case IMSG_CTL_SHOW_NBR
:
820 json_nbr
= json_object_new_object();
821 json_object_object_add(json
,
822 inet_ntop(AF_INET
, &nbr
->id
, buf
,
823 sizeof(buf
)), json_nbr
);
824 json_object_string_addf(json_nbr
, "peerId", "%pI4", &nbr
->id
);
825 json_object_string_add(json_nbr
, "tcpLocalAddress",
826 log_addr(nbr
->af
, &nbr
->laddr
));
827 json_object_int_add(json_nbr
, "tcpLocalPort",
829 json_object_string_add(json_nbr
, "tcpRemoteAddress",
830 log_addr(nbr
->af
, &nbr
->raddr
));
831 json_object_int_add(json_nbr
, "tcpRemotePort",
833 json_object_string_add(json_nbr
, "authentication",
834 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
836 json_object_int_add(json_nbr
, "sessionHoldtime", nbr
->holdtime
);
837 json_object_int_add(json_nbr
, "keepAliveInterval",
838 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
839 json_object_string_add(json_nbr
, "state",
840 nbr_state_name(nbr
->nbr_state
));
841 json_object_string_add(json_nbr
, "upTime",
842 log_time(nbr
->uptime
));
844 /* message_counters */
846 json_array
= json_object_new_array();
847 json_object_object_add(json_nbr
, "sentMessages", json_array
);
848 json_counter
= json_object_new_object();
849 json_object_int_add(json_counter
, "keepalive",
851 json_object_array_add(json_array
, json_counter
);
852 json_counter
= json_object_new_object();
853 json_object_int_add(json_counter
, "address",
855 json_object_array_add(json_array
, json_counter
);
856 json_counter
= json_object_new_object();
857 json_object_int_add(json_counter
, "addressWithdraw",
858 stats
->addrwdraw_sent
);
859 json_object_array_add(json_array
, json_counter
);
860 json_counter
= json_object_new_object();
861 json_object_int_add(json_counter
, "notification",
863 json_object_array_add(json_array
, json_counter
);
864 json_counter
= json_object_new_object();
865 json_object_int_add(json_counter
, "capability",
866 stats
->capability_sent
);
867 json_object_array_add(json_array
, json_counter
);
868 json_counter
= json_object_new_object();
869 json_object_int_add(json_counter
, "labelMapping",
870 stats
->labelmap_sent
);
871 json_object_array_add(json_array
, json_counter
);
872 json_counter
= json_object_new_object();
873 json_object_int_add(json_counter
, "labelRequest",
874 stats
->labelreq_sent
);
875 json_object_array_add(json_array
, json_counter
);
876 json_counter
= json_object_new_object();
877 json_object_int_add(json_counter
, "labelWithdraw",
878 stats
->labelwdraw_sent
);
879 json_object_array_add(json_array
, json_counter
);
880 json_counter
= json_object_new_object();
881 json_object_int_add(json_counter
, "labelRelease",
882 stats
->labelrel_sent
);
883 json_object_array_add(json_array
, json_counter
);
884 json_counter
= json_object_new_object();
885 json_object_int_add(json_counter
, "labelAbortRequest",
886 stats
->labelabreq_sent
);
887 json_object_array_add(json_array
, json_counter
);
889 json_array
= json_object_new_array();
890 json_object_object_add(json_nbr
, "receivedMessages", json_array
);
891 json_counter
= json_object_new_object();
892 json_object_int_add(json_counter
, "keepalive",
894 json_object_array_add(json_array
, json_counter
);
895 json_counter
= json_object_new_object();
896 json_object_int_add(json_counter
, "address",
898 json_object_array_add(json_array
, json_counter
);
899 json_counter
= json_object_new_object();
900 json_object_int_add(json_counter
, "addressWithdraw",
901 stats
->addrwdraw_rcvd
);
902 json_object_array_add(json_array
, json_counter
);
903 json_counter
= json_object_new_object();
904 json_object_int_add(json_counter
, "notification",
906 json_object_array_add(json_array
, json_counter
);
907 json_counter
= json_object_new_object();
908 json_object_int_add(json_counter
, "capability",
909 stats
->capability_rcvd
);
910 json_object_array_add(json_array
, json_counter
);
911 json_counter
= json_object_new_object();
912 json_object_int_add(json_counter
, "labelMapping",
913 stats
->labelmap_rcvd
);
914 json_object_array_add(json_array
, json_counter
);
915 json_counter
= json_object_new_object();
916 json_object_int_add(json_counter
, "labelRequest",
917 stats
->labelreq_rcvd
);
918 json_object_array_add(json_array
, json_counter
);
919 json_counter
= json_object_new_object();
920 json_object_int_add(json_counter
, "labelWithdraw",
921 stats
->labelwdraw_rcvd
);
922 json_object_array_add(json_array
, json_counter
);
923 json_counter
= json_object_new_object();
924 json_object_int_add(json_counter
, "labelRelease",
925 stats
->labelrel_rcvd
);
926 json_object_array_add(json_array
, json_counter
);
927 json_counter
= json_object_new_object();
928 json_object_int_add(json_counter
, "labelAbortRequest",
929 stats
->labelabreq_rcvd
);
930 json_object_array_add(json_array
, json_counter
);
933 show_nbr_capabilities_json(nbr
, json_nbr
);
935 /* discovery sources */
936 json_nbr_sources
= json_object_new_object();
937 json_object_object_add(json_nbr
, "discoverySources",
942 case IMSG_CTL_SHOW_NBR_DISC
:
948 json_v4adjs
= json_object_new_array();
949 json_object_object_add(json_nbr_sources
, "ipv4",
952 show_nbr_detail_adj_json(adj
, json_v4adjs
);
956 json_v6adjs
= json_object_new_array();
957 json_object_object_add(json_nbr_sources
, "ipv6",
960 show_nbr_detail_adj_json(adj
, json_v6adjs
);
963 fatalx("show_nbr_detail_msg_json: unknown af");
966 case IMSG_CTL_SHOW_NBR_END
:
978 show_nbr_capabilities(struct vty
*vty
, struct ctl_nbr
*nbr
)
980 vty_out (vty
, " Capabilities Sent:\n"
981 " - Dynamic Announcement (0x0506)\n"
982 " - Typed Wildcard (0x050B)\n"
983 " - Unrecognized Notification (0x0603)\n");
984 vty_out (vty
, " Capabilities Received:\n");
985 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
)
986 vty_out (vty
," - Dynamic Announcement (0x0506)\n");
987 if (nbr
->flags
& F_NBR_CAP_TWCARD
)
988 vty_out (vty
, " - Typed Wildcard (0x050B)\n");
989 if (nbr
->flags
& F_NBR_CAP_UNOTIF
)
990 vty_out (vty
," - Unrecognized Notification (0x0603)\n");
994 show_nbr_capabilities_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
998 switch (imsg
->hdr
.type
) {
999 case IMSG_CTL_SHOW_NBR
:
1002 if (nbr
->nbr_state
!= NBR_STA_OPER
)
1005 vty_out (vty
, "Peer LDP Identifier: %pI4:0\n",
1007 show_nbr_capabilities(vty
, nbr
);
1008 vty_out (vty
, "\n");
1011 vty_out (vty
, "\n");
1021 show_nbr_capabilities_json(struct ctl_nbr
*nbr
, json_object
*json_nbr
)
1023 json_object
*json_array
;
1024 json_object
*json_cap
;
1026 /* sent capabilities */
1027 json_array
= json_object_new_array();
1028 json_object_object_add(json_nbr
, "sentCapabilities", json_array
);
1030 /* Dynamic Announcement (0x0506) */
1031 json_cap
= json_object_new_object();
1032 json_object_string_add(json_cap
, "description", "Dynamic Announcement");
1033 json_object_string_add(json_cap
, "tlvType", "0x0506");
1034 json_object_array_add(json_array
, json_cap
);
1036 /* Typed Wildcard (0x050B) */
1037 json_cap
= json_object_new_object();
1038 json_object_string_add(json_cap
, "description", "Typed Wildcard");
1039 json_object_string_add(json_cap
, "tlvType", "0x050B");
1040 json_object_array_add(json_array
, json_cap
);
1042 /* Unrecognized Notification (0x0603) */
1043 json_cap
= json_object_new_object();
1044 json_object_string_add(json_cap
, "description",
1045 "Unrecognized Notification");
1046 json_object_string_add(json_cap
, "tlvType", "0x0603");
1047 json_object_array_add(json_array
, json_cap
);
1049 /* received capabilities */
1050 json_array
= json_object_new_array();
1051 json_object_object_add(json_nbr
, "receivedCapabilities", json_array
);
1053 /* Dynamic Announcement (0x0506) */
1054 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
) {
1055 json_cap
= json_object_new_object();
1056 json_object_string_add(json_cap
, "description",
1057 "Dynamic Announcement");
1058 json_object_string_add(json_cap
, "tlvType", "0x0506");
1059 json_object_array_add(json_array
, json_cap
);
1062 /* Typed Wildcard (0x050B) */
1063 if (nbr
->flags
& F_NBR_CAP_TWCARD
) {
1064 json_cap
= json_object_new_object();
1065 json_object_string_add(json_cap
, "description",
1067 json_object_string_add(json_cap
, "tlvType", "0x050B");
1068 json_object_array_add(json_array
, json_cap
);
1071 /* Unrecognized Notification (0x0603) */
1072 if (nbr
->flags
& F_NBR_CAP_UNOTIF
) {
1073 json_cap
= json_object_new_object();
1074 json_object_string_add(json_cap
, "description",
1075 "Unrecognized Notification");
1076 json_object_string_add(json_cap
, "tlvType", "0x0603");
1077 json_object_array_add(json_array
, json_cap
);
1082 show_nbr_capabilities_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1085 struct ctl_nbr
*nbr
;
1086 char buf
[PREFIX_STRLEN
];
1087 json_object
*json_nbr
;
1089 switch (imsg
->hdr
.type
) {
1090 case IMSG_CTL_SHOW_NBR
:
1093 if (nbr
->nbr_state
!= NBR_STA_OPER
)
1096 json_nbr
= json_object_new_object();
1097 json_object_object_add(json
, inet_ntop(AF_INET
, &nbr
->id
, buf
,
1098 sizeof(buf
)), json_nbr
);
1099 show_nbr_capabilities_json(nbr
, json_nbr
);
1111 show_lib_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1114 char dstnet
[BUFSIZ
];
1116 switch (imsg
->hdr
.type
) {
1117 case IMSG_CTL_SHOW_LIB_BEGIN
:
1120 if (params
->lib
.remote_label
!= NO_LABEL
&&
1121 params
->lib
.remote_label
!= rt
->remote_label
)
1124 case IMSG_CTL_SHOW_LIB_RCVD
:
1127 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1131 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1132 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1134 vty_out(vty
, "%-4s %-20s", af_name(rt
->af
), dstnet
);
1135 if (strlen(dstnet
) > 20)
1136 vty_out(vty
, "\n%25s", " ");
1137 vty_out (vty
, " %-15pI4 %-11s %-13s %6s\n",
1138 &rt
->nexthop
, log_label(rt
->local_label
),
1139 log_label(rt
->remote_label
),
1140 rt
->in_use
? "yes" : "no");
1143 vty_out (vty
, "\n");
1153 show_lib_detail_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1155 struct ctl_rt
*rt
= NULL
;
1156 static char dstnet
[BUFSIZ
];
1157 static int upstream
, downstream
;
1159 static char sent_buffer
[LDPBUFSIZ
];
1160 static char rcvd_buffer
[LDPBUFSIZ
];
1162 switch (imsg
->hdr
.type
) {
1163 case IMSG_CTL_SHOW_LIB_BEGIN
:
1168 sent_buffer
[0] = '\0';
1169 rcvd_buffer
[0] = '\0';
1170 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1171 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1173 case IMSG_CTL_SHOW_LIB_SENT
:
1177 buflen
= strlen(sent_buffer
);
1178 snprintfrr(sent_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1179 "%12s%pI4:0\n", "", &rt
->nexthop
);
1181 case IMSG_CTL_SHOW_LIB_RCVD
:
1184 buflen
= strlen(rcvd_buffer
);
1185 snprintfrr(rcvd_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1186 "%12s%pI4:0, label %s%s\n", "", &rt
->nexthop
,
1187 log_label(rt
->remote_label
),
1188 rt
->in_use
? " (in use)" : "");
1190 case IMSG_CTL_SHOW_LIB_END
:
1193 if (params
->lib
.remote_label
!= NO_LABEL
&&
1196 vty_out(vty
, "%s\n", dstnet
);
1197 vty_out(vty
, "%-8sLocal binding: label: %s\n", "",
1198 log_label(rt
->local_label
));
1200 vty_out (vty
, "%-8sAdvertised to:\n", "");
1201 vty_out(vty
, "%s", sent_buffer
);
1204 vty_out (vty
, "%-8sRemote bindings:\n", "");
1205 vty_out(vty
, "%s", rcvd_buffer
);
1207 vty_out (vty
, "%-8sNo remote bindings\n","");
1210 vty_out (vty
, "\n");
1220 show_lib_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1224 json_object
*json_array
;
1225 json_object
*json_lib_entry
;
1226 char dstnet
[BUFSIZ
];
1228 switch (imsg
->hdr
.type
) {
1229 case IMSG_CTL_SHOW_LIB_BEGIN
:
1230 case IMSG_CTL_SHOW_LIB_RCVD
:
1233 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1237 json_object_object_get_ex(json
, "bindings", &json_array
);
1239 json_array
= json_object_new_array();
1240 json_object_object_add(json
, "bindings", json_array
);
1243 json_lib_entry
= json_object_new_object();
1244 json_object_string_add(json_lib_entry
, "addressFamily",
1246 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1247 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1248 json_object_string_add(json_lib_entry
, "prefix", dstnet
);
1249 json_object_string_addf(json_lib_entry
, "neighborId", "%pI4",
1251 json_object_string_add(json_lib_entry
, "localLabel",
1252 log_label(rt
->local_label
));
1253 json_object_string_add(json_lib_entry
, "remoteLabel",
1254 log_label(rt
->remote_label
));
1255 json_object_int_add(json_lib_entry
, "inUse", rt
->in_use
);
1257 json_object_array_add(json_array
, json_lib_entry
);
1269 show_lib_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1272 struct ctl_rt
*rt
= NULL
;
1273 char dstnet
[BUFSIZ
];
1274 static json_object
*json_lib_entry
;
1275 static json_object
*json_adv_labels
;
1276 json_object
*json_adv_label
;
1277 static json_object
*json_remote_labels
;
1278 json_object
*json_remote_label
;
1280 switch (imsg
->hdr
.type
) {
1281 case IMSG_CTL_SHOW_LIB_BEGIN
:
1284 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1285 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1287 json_lib_entry
= json_object_new_object();
1288 json_object_string_add(json_lib_entry
, "localLabel",
1289 log_label(rt
->local_label
));
1291 json_adv_labels
= json_object_new_array();
1292 json_object_object_add(json_lib_entry
, "advertisedTo",
1295 json_remote_labels
= json_object_new_array();
1296 json_object_object_add(json_lib_entry
, "remoteLabels",
1297 json_remote_labels
);
1299 json_object_object_add(json
, dstnet
, json_lib_entry
);
1301 case IMSG_CTL_SHOW_LIB_SENT
:
1304 json_adv_label
= json_object_new_object();
1305 json_object_string_addf(json_adv_label
, "neighborId", "%pI4",
1307 json_object_array_add(json_adv_labels
, json_adv_label
);
1309 case IMSG_CTL_SHOW_LIB_RCVD
:
1312 json_remote_label
= json_object_new_object();
1313 json_object_string_addf(json_remote_label
, "neighborId", "%pI4",
1315 json_object_string_add(json_remote_label
, "label",
1316 log_label(rt
->remote_label
));
1317 json_object_int_add(json_remote_label
, "inUse", rt
->in_use
);
1318 json_object_array_add(json_remote_labels
, json_remote_label
);
1330 show_l2vpn_binding_msg(struct vty
*vty
, struct imsg
*imsg
,
1331 struct show_params
*params
)
1335 switch (imsg
->hdr
.type
) {
1336 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1339 vty_out (vty
, " Destination Address: %pI4, VC ID: %u\n",
1340 &pw
->lsr_id
, pw
->pwid
);
1343 if (pw
->local_label
!= NO_LABEL
) {
1344 vty_out (vty
, " Local Label: %u\n",
1346 vty_out (vty
, "%-8sCbit: %u, VC Type: %s, GroupID: %u\n", "", pw
->local_cword
,
1347 pw_type_name(pw
->type
),pw
->local_gid
);
1348 vty_out (vty
, "%-8sMTU: %u\n", "",pw
->local_ifmtu
);
1349 vty_out (vty
, "%-8sLast failure: %s\n", "",
1350 pw_error_code(pw
->reason
));
1352 vty_out (vty
," Local Label: unassigned\n");
1354 /* remote binding */
1355 if (pw
->remote_label
!= NO_LABEL
) {
1356 vty_out (vty
, " Remote Label: %u\n",
1358 vty_out (vty
, "%-8sCbit: %u, VC Type: %s, GroupID: %u\n", "", pw
->remote_cword
,
1359 pw_type_name(pw
->type
),pw
->remote_gid
);
1360 vty_out (vty
, "%-8sMTU: %u\n", "",pw
->remote_ifmtu
);
1362 vty_out (vty
," Remote Label: unassigned\n");
1365 vty_out (vty
, "\n");
1375 show_l2vpn_binding_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1379 json_object
*json_pw
;
1382 switch (imsg
->hdr
.type
) {
1383 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1386 json_pw
= json_object_new_object();
1387 json_object_string_addf(json_pw
, "destination", "%pI4",
1389 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1392 if (pw
->local_label
!= NO_LABEL
) {
1393 json_object_int_add(json_pw
, "localLabel",
1395 json_object_int_add(json_pw
, "localControlWord",
1397 json_object_string_add(json_pw
, "localVcType",
1398 pw_type_name(pw
->type
));
1399 json_object_int_add(json_pw
, "localGroupID",
1401 json_object_int_add(json_pw
, "localIfMtu",
1403 json_object_string_add(json_pw
, "lastFailureReason",
1404 pw_error_code(pw
->reason
));
1406 json_object_string_add(json_pw
, "localLabel",
1409 /* remote binding */
1410 if (pw
->remote_label
!= NO_LABEL
) {
1411 json_object_int_add(json_pw
, "remoteLabel",
1413 json_object_int_add(json_pw
, "remoteControlWord",
1415 json_object_string_add(json_pw
, "remoteVcType",
1416 pw_type_name(pw
->type
));
1417 json_object_int_add(json_pw
, "remoteGroupID",
1419 json_object_int_add(json_pw
, "remoteIfMtu",
1422 json_object_string_add(json_pw
, "remoteLabel",
1425 snprintfrr(key_name
, sizeof(key_name
), "%pI4: %u",
1426 &pw
->lsr_id
, pw
->pwid
);
1427 json_object_object_add(json
, key_name
, json_pw
);
1439 show_l2vpn_pw_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1443 switch (imsg
->hdr
.type
) {
1444 case IMSG_CTL_SHOW_L2VPN_PW
:
1447 vty_out (vty
, "%-9s %-15pI4 %-10u %-16s %-10s\n", pw
->ifname
,
1448 &pw
->lsr_id
, pw
->pwid
, pw
->l2vpn_name
,
1449 (pw
->status
== PW_FORWARDING
? "UP" : "DOWN"));
1452 vty_out (vty
, "\n");
1462 show_l2vpn_pw_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1466 json_object
*json_pw
;
1468 switch (imsg
->hdr
.type
) {
1469 case IMSG_CTL_SHOW_L2VPN_PW
:
1472 json_pw
= json_object_new_object();
1473 json_object_string_addf(json_pw
, "peerId", "%pI4", &pw
->lsr_id
);
1474 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1475 json_object_string_add(json_pw
, "VpnName", pw
->l2vpn_name
);
1476 if (pw
->status
== PW_FORWARDING
)
1477 json_object_string_add(json_pw
, "status", "up");
1479 json_object_string_add(json_pw
, "status", "down");
1480 json_object_object_add(json
, pw
->ifname
, json_pw
);
1492 ldp_vty_connect(struct imsgbuf
*ibuf
)
1494 struct sockaddr_un s_un
;
1497 /* connect to ldpd control socket */
1498 if ((ctl_sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
1499 log_warn("%s: socket", __func__
);
1503 memset(&s_un
, 0, sizeof(s_un
));
1504 s_un
.sun_family
= AF_UNIX
;
1505 strlcpy(s_un
.sun_path
, ctl_sock_path
, sizeof(s_un
.sun_path
));
1506 if (connect(ctl_sock
, (struct sockaddr
*)&s_un
, sizeof(s_un
)) == -1) {
1507 log_warn("%s: connect: %s", __func__
, ctl_sock_path
);
1512 imsg_init(ibuf
, ctl_sock
);
1518 ldp_vty_dispatch_iface(struct vty
*vty
, struct imsg
*imsg
,
1519 struct show_params
*params
, json_object
*json
)
1524 ret
= show_interface_msg_json(imsg
, params
, json
);
1526 ret
= show_interface_msg(vty
, imsg
, params
);
1532 ldp_vty_dispatch_ldp_sync(struct vty
*vty
, struct imsg
*imsg
,
1533 struct show_params
*params
, json_object
*json
)
1538 ret
= show_ldp_sync_msg_json(imsg
, params
, json
);
1540 ret
= show_ldp_sync_msg(vty
, imsg
, params
);
1546 ldp_vty_dispatch_disc(struct vty
*vty
, struct imsg
*imsg
,
1547 struct show_params
*params
, json_object
*json
)
1551 if (params
->detail
) {
1553 ret
= show_discovery_detail_msg_json(imsg
, params
,
1556 ret
= show_discovery_detail_msg(vty
, imsg
, params
);
1559 ret
= show_discovery_msg_json(imsg
, params
, json
);
1561 ret
= show_discovery_msg(vty
, imsg
, params
);
1568 ldp_vty_dispatch_nbr(struct vty
*vty
, struct imsg
*imsg
,
1569 struct show_params
*params
, json_object
*json
)
1571 static bool filtered
= false;
1572 struct ctl_nbr
*nbr
;
1575 switch (imsg
->hdr
.type
) {
1576 case IMSG_CTL_SHOW_NBR
:
1580 if (params
->neighbor
.lsr_id
.s_addr
!= INADDR_ANY
&&
1581 params
->neighbor
.lsr_id
.s_addr
!= nbr
->id
.s_addr
) {
1586 case IMSG_CTL_SHOW_NBR_DISC
:
1587 case IMSG_CTL_SHOW_NBR_END
:
1595 if (params
->neighbor
.capabilities
) {
1597 ret
= show_nbr_capabilities_msg_json(imsg
, params
,
1600 ret
= show_nbr_capabilities_msg(vty
, imsg
, params
);
1601 } else if (params
->detail
) {
1603 ret
= show_nbr_detail_msg_json(imsg
, params
, json
);
1605 ret
= show_nbr_detail_msg(vty
, imsg
, params
);
1608 ret
= show_nbr_msg_json(imsg
, params
, json
);
1610 ret
= show_nbr_msg(vty
, imsg
, params
);
1617 ldp_vty_dispatch_lib(struct vty
*vty
, struct imsg
*imsg
,
1618 struct show_params
*params
, json_object
*json
)
1620 static bool filtered
= false;
1621 struct ctl_rt
*rt
= NULL
;
1622 struct prefix prefix
;
1625 switch (imsg
->hdr
.type
) {
1626 case IMSG_CTL_SHOW_LIB_BEGIN
:
1629 case IMSG_CTL_SHOW_LIB_SENT
:
1630 case IMSG_CTL_SHOW_LIB_RCVD
:
1631 case IMSG_CTL_SHOW_LIB_END
:
1639 switch (imsg
->hdr
.type
) {
1640 case IMSG_CTL_SHOW_LIB_BEGIN
:
1641 case IMSG_CTL_SHOW_LIB_SENT
:
1642 case IMSG_CTL_SHOW_LIB_RCVD
:
1643 case IMSG_CTL_SHOW_LIB_END
:
1646 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
) {
1651 prefix
.family
= rt
->af
;
1652 prefix
.prefixlen
= rt
->prefixlen
;
1653 memcpy(&prefix
.u
.val
, &rt
->prefix
, sizeof(prefix
.u
.val
));
1654 if (params
->lib
.prefix
.family
!= AF_UNSPEC
) {
1655 if (!params
->lib
.longer_prefixes
&&
1656 !prefix_same(¶ms
->lib
.prefix
, &prefix
)) {
1659 } else if (params
->lib
.longer_prefixes
&&
1660 !prefix_match(¶ms
->lib
.prefix
, &prefix
)) {
1666 if (params
->lib
.local_label
!= NO_LABEL
&&
1667 params
->lib
.local_label
!= rt
->local_label
) {
1676 switch (imsg
->hdr
.type
) {
1677 case IMSG_CTL_SHOW_LIB_SENT
:
1678 case IMSG_CTL_SHOW_LIB_RCVD
:
1679 if (params
->lib
.neighbor
.s_addr
!= INADDR_ANY
&&
1680 params
->lib
.neighbor
.s_addr
!= rt
->nexthop
.s_addr
)
1687 switch (imsg
->hdr
.type
) {
1688 case IMSG_CTL_SHOW_LIB_RCVD
:
1689 if (params
->lib
.remote_label
!= NO_LABEL
&&
1690 params
->lib
.remote_label
!= rt
->remote_label
)
1697 if (params
->detail
) {
1699 ret
= show_lib_detail_msg_json(imsg
, params
, json
);
1701 ret
= show_lib_detail_msg(vty
, imsg
, params
);
1704 ret
= show_lib_msg_json(imsg
, params
, json
);
1706 ret
= show_lib_msg(vty
, imsg
, params
);
1713 ldp_vty_dispatch_l2vpn_pw(struct vty
*vty
, struct imsg
*imsg
,
1714 struct show_params
*params
, json_object
*json
)
1719 switch (imsg
->hdr
.type
) {
1720 case IMSG_CTL_SHOW_L2VPN_PW
:
1722 if (params
->l2vpn
.peer
.s_addr
!= INADDR_ANY
&&
1723 params
->l2vpn
.peer
.s_addr
!= pw
->lsr_id
.s_addr
)
1725 if (params
->l2vpn
.ifname
[0] != '\0' &&
1726 strcmp(params
->l2vpn
.ifname
, pw
->ifname
))
1728 if (params
->l2vpn
.vcid
&& params
->l2vpn
.vcid
!= pw
->pwid
)
1736 ret
= show_l2vpn_pw_msg_json(imsg
, params
, json
);
1738 ret
= show_l2vpn_pw_msg(vty
, imsg
, params
);
1744 ldp_vty_dispatch_l2vpn_binding(struct vty
*vty
, struct imsg
*imsg
,
1745 struct show_params
*params
, json_object
*json
)
1750 switch (imsg
->hdr
.type
) {
1751 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1753 if (params
->l2vpn
.peer
.s_addr
!= INADDR_ANY
&&
1754 params
->l2vpn
.peer
.s_addr
!= pw
->lsr_id
.s_addr
)
1756 if (params
->l2vpn
.local_label
!= NO_LABEL
&&
1757 params
->l2vpn
.local_label
!= pw
->local_label
)
1759 if (params
->l2vpn
.remote_label
!= NO_LABEL
&&
1760 params
->l2vpn
.remote_label
!= pw
->remote_label
)
1768 ret
= show_l2vpn_binding_msg_json(imsg
, params
, json
);
1770 ret
= show_l2vpn_binding_msg(vty
, imsg
, params
);
1776 ldp_vty_dispatch_msg(struct vty
*vty
, struct imsg
*imsg
, enum show_command cmd
,
1777 struct show_params
*params
, json_object
*json
)
1781 return (ldp_vty_dispatch_iface(vty
, imsg
, params
, json
));
1783 return (ldp_vty_dispatch_disc(vty
, imsg
, params
, json
));
1785 return (ldp_vty_dispatch_nbr(vty
, imsg
, params
, json
));
1787 return (ldp_vty_dispatch_lib(vty
, imsg
, params
, json
));
1789 return (ldp_vty_dispatch_l2vpn_pw(vty
, imsg
, params
, json
));
1790 case SHOW_L2VPN_BINDING
:
1791 return (ldp_vty_dispatch_l2vpn_binding(vty
, imsg
, params
,
1794 return (ldp_vty_dispatch_ldp_sync(vty
, imsg
, params
, json
));
1801 ldp_vty_dispatch(struct vty
*vty
, struct imsgbuf
*ibuf
, enum show_command cmd
,
1802 struct show_params
*params
)
1805 int n
, done
= 0, ret
= CMD_SUCCESS
;
1806 json_object
*json
= NULL
;
1808 while (ibuf
->w
.queued
)
1809 if (msgbuf_write(&ibuf
->w
) <= 0 && errno
!= EAGAIN
) {
1810 log_warn("write error");
1812 return (CMD_WARNING
);
1816 json
= json_object_new_object();
1819 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
) {
1820 log_warnx("imsg_read error");
1825 log_warnx("pipe closed");
1831 if ((n
= imsg_get(ibuf
, &imsg
)) == -1) {
1832 log_warnx("imsg_get error");
1838 done
= ldp_vty_dispatch_msg(vty
, &imsg
, cmd
, params
,
1847 vty_json(vty
, json
);
1854 ldp_vty_get_af(const char *str
, int *af
)
1859 } else if (strcmp(str
, "ipv4") == 0) {
1862 } else if (strcmp(str
, "ipv6") == 0) {
1871 ldp_vty_show_binding(struct vty
*vty
, const char *af_str
, const char *prefix
,
1872 int longer_prefixes
, const char *neighbor
, unsigned long local_label
,
1873 unsigned long remote_label
, const char *detail
, const char *json
)
1875 struct imsgbuf ibuf
;
1876 struct show_params params
;
1879 if (ldp_vty_connect(&ibuf
) < 0)
1880 return (CMD_WARNING
);
1882 if (ldp_vty_get_af(af_str
, &af
) < 0)
1883 return (CMD_ERR_NO_MATCH
);
1885 memset(¶ms
, 0, sizeof(params
));
1887 params
.detail
= (detail
) ? 1 : 0;
1888 params
.json
= (json
) ? 1 : 0;
1890 (void)str2prefix(prefix
, ¶ms
.lib
.prefix
);
1891 params
.lib
.longer_prefixes
= longer_prefixes
;
1894 (inet_pton(AF_INET
, neighbor
, ¶ms
.lib
.neighbor
) != 1 ||
1895 bad_addr_v4(params
.lib
.neighbor
))) {
1896 vty_out (vty
, "%% Malformed address\n");
1897 return (CMD_SUCCESS
);
1899 params
.lib
.local_label
= local_label
;
1900 params
.lib
.remote_label
= remote_label
;
1902 if (!params
.detail
&& !params
.json
)
1903 vty_out (vty
, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF",
1904 "Destination", "Nexthop", "Local Label", "Remote Label",
1907 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LIB
, 0, 0, -1, NULL
, 0);
1908 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LIB
, ¶ms
));
1912 ldp_vty_show_discovery(struct vty
*vty
, const char *af_str
, const char *detail
,
1915 struct imsgbuf ibuf
;
1916 struct show_params params
;
1919 if (ldp_vty_connect(&ibuf
) < 0)
1920 return (CMD_WARNING
);
1922 if (ldp_vty_get_af(af_str
, &af
) < 0)
1923 return (CMD_ERR_NO_MATCH
);
1925 memset(¶ms
, 0, sizeof(params
));
1927 params
.detail
= (detail
) ? 1 : 0;
1928 params
.json
= (json
) ? 1 : 0;
1930 if (!params
.detail
&& !params
.json
)
1931 vty_out (vty
, "%-4s %-15s %-8s %-15s %9s\n",
1932 "AF", "ID", "Type", "Source", "Holdtime");
1935 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY_DTL
, 0, 0, -1,
1938 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
1939 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_DISC
, ¶ms
));
1943 ldp_vty_show_interface(struct vty
*vty
, const char *af_str
, const char *json
)
1945 struct imsgbuf ibuf
;
1946 struct show_params params
;
1947 unsigned int ifidx
= 0;
1950 if (ldp_vty_connect(&ibuf
) < 0)
1951 return (CMD_WARNING
);
1953 if (ldp_vty_get_af(af_str
, &af
) < 0)
1954 return (CMD_ERR_NO_MATCH
);
1956 memset(¶ms
, 0, sizeof(params
));
1958 params
.json
= (json
) ? 1 : 0;
1962 vty_out (vty
, "%-4s %-11s %-6s %-8s %-12s %3s\n", "AF",
1963 "Interface", "State", "Uptime", "Hello Timers","ac");
1966 imsg_compose(&ibuf
, IMSG_CTL_SHOW_INTERFACE
, 0, 0, -1, &ifidx
,
1968 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_IFACE
, ¶ms
));
1972 ldp_vty_show_capabilities(struct vty
*vty
, const char *json
)
1976 json_object
*json_array
;
1977 json_object
*json_cap
;
1979 json
= json_object_new_object();
1980 json_array
= json_object_new_array();
1981 json_object_object_add(json
, "capabilities", json_array
);
1983 /* Dynamic Announcement (0x0506) */
1984 json_cap
= json_object_new_object();
1985 json_object_string_add(json_cap
, "description",
1986 "Dynamic Announcement");
1987 json_object_string_add(json_cap
, "tlvType",
1989 json_object_array_add(json_array
, json_cap
);
1991 /* Typed Wildcard (0x050B) */
1992 json_cap
= json_object_new_object();
1993 json_object_string_add(json_cap
, "description",
1995 json_object_string_add(json_cap
, "tlvType",
1997 json_object_array_add(json_array
, json_cap
);
1999 /* Unrecognized Notification (0x0603) */
2000 json_cap
= json_object_new_object();
2001 json_object_string_add(json_cap
, "description",
2002 "Unrecognized Notification");
2003 json_object_string_add(json_cap
, "tlvType",
2005 json_object_array_add(json_array
, json_cap
);
2007 vty_json(vty
, json
);
2012 "Supported LDP Capabilities\n"
2013 " * Dynamic Announcement (0x0506)\n"
2014 " * Typed Wildcard (0x050B)\n"
2015 " * Unrecognized Notification (0x0603)\n\n");
2021 ldp_vty_show_neighbor(struct vty
*vty
, const char *lsr_id
, int capabilities
,
2022 const char *detail
, const char *json
)
2024 struct imsgbuf ibuf
;
2025 struct show_params params
;
2027 if (ldp_vty_connect(&ibuf
) < 0)
2028 return (CMD_WARNING
);
2030 memset(¶ms
, 0, sizeof(params
));
2031 params
.detail
= (detail
) ? 1 : 0;
2032 params
.json
= (json
) ? 1 : 0;
2033 params
.neighbor
.capabilities
= capabilities
;
2035 (inet_pton(AF_INET
, lsr_id
, ¶ms
.neighbor
.lsr_id
) != 1 ||
2036 bad_addr_v4(params
.neighbor
.lsr_id
))) {
2037 vty_out (vty
, "%% Malformed address\n");
2038 return (CMD_SUCCESS
);
2041 if (params
.neighbor
.capabilities
)
2044 if (!params
.detail
&& !params
.json
)
2045 vty_out (vty
, "%-4s %-15s %-11s %-15s %8s\n",
2046 "AF", "ID", "State", "Remote Address","Uptime");
2048 imsg_compose(&ibuf
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, NULL
, 0);
2049 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_NBR
, ¶ms
));
2053 ldp_vty_show_ldp_sync(struct vty
*vty
, const char *json
)
2055 struct imsgbuf ibuf
;
2056 struct show_params params
;
2058 if (ldp_vty_connect(&ibuf
) < 0)
2059 return (CMD_WARNING
);
2061 memset(¶ms
, 0, sizeof(params
));
2062 params
.json
= (json
) ? 1 : 0;
2064 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LDP_SYNC
, 0, 0, -1, NULL
, 0);
2065 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LDP_SYNC
, ¶ms
));
2069 ldp_vty_show_atom_binding(struct vty
*vty
, const char *peer
,
2070 unsigned long local_label
, unsigned long remote_label
, const char *json
)
2072 struct imsgbuf ibuf
;
2073 struct show_params params
;
2075 if (ldp_vty_connect(&ibuf
) < 0)
2076 return (CMD_WARNING
);
2078 memset(¶ms
, 0, sizeof(params
));
2079 params
.json
= (json
) ? 1 : 0;
2081 (inet_pton(AF_INET
, peer
, ¶ms
.l2vpn
.peer
) != 1 ||
2082 bad_addr_v4(params
.l2vpn
.peer
))) {
2083 vty_out (vty
, "%% Malformed address\n");
2084 return (CMD_SUCCESS
);
2086 params
.l2vpn
.local_label
= local_label
;
2087 params
.l2vpn
.remote_label
= remote_label
;
2089 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_BINDING
, 0, 0, -1, NULL
, 0);
2090 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_BINDING
, ¶ms
));
2094 ldp_vty_show_atom_vc(struct vty
*vty
, const char *peer
, const char *ifname
,
2095 const char *vcid
, const char *json
)
2097 struct imsgbuf ibuf
;
2098 struct show_params params
;
2100 if (ldp_vty_connect(&ibuf
) < 0)
2101 return (CMD_WARNING
);
2103 memset(¶ms
, 0, sizeof(params
));
2104 params
.json
= (json
) ? 1 : 0;
2106 (inet_pton(AF_INET
, peer
, ¶ms
.l2vpn
.peer
) != 1 ||
2107 bad_addr_v4(params
.l2vpn
.peer
))) {
2108 vty_out (vty
, "%% Malformed address\n");
2109 return (CMD_SUCCESS
);
2112 strlcpy(params
.l2vpn
.ifname
, ifname
,
2113 sizeof(params
.l2vpn
.ifname
));
2115 params
.l2vpn
.vcid
= atoi(vcid
);
2119 vty_out (vty
, "%-9s %-15s %-10s %-16s %-10s\n",
2120 "Interface", "Peer ID", "VC ID", "Name","Status");
2121 vty_out (vty
, "%-9s %-15s %-10s %-16s %-10s\n",
2122 "---------", "---------------", "----------",
2123 "----------------", "----------");
2126 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_PW
, 0, 0, -1, NULL
, 0);
2127 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_PW
, ¶ms
));
2131 ldp_vty_clear_nbr(struct vty
*vty
, const char *addr_str
)
2133 struct imsgbuf ibuf
;
2136 memset(&nbr
, 0, sizeof(nbr
));
2138 (ldp_get_address(addr_str
, &nbr
.af
, &nbr
.raddr
) == -1 ||
2139 bad_addr(nbr
.af
, &nbr
.raddr
))) {
2140 vty_out (vty
, "%% Malformed address\n");
2141 return (CMD_WARNING
);
2144 if (ldp_vty_connect(&ibuf
) < 0)
2145 return (CMD_WARNING
);
2147 imsg_compose(&ibuf
, IMSG_CTL_CLEAR_NBR
, 0, 0, -1, &nbr
, sizeof(nbr
));
2149 while (ibuf
.w
.queued
)
2150 if (msgbuf_write(&ibuf
.w
) <= 0 && errno
!= EAGAIN
) {
2151 log_warn("write error");
2153 return (CMD_WARNING
);
2158 return (CMD_SUCCESS
);