1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2016 by Open Source Routing.
8 #include "lib/printfrr.h"
39 struct in_addr lsr_id
;
45 struct in_addr neighbor
;
47 uint32_t remote_label
;
52 uint32_t remote_label
;
53 char ifname
[IFNAMSIZ
];
59 #define LDPBUFSIZ 65535
61 static int show_interface_msg(struct vty
*, struct imsg
*,
62 struct show_params
*);
63 static int show_interface_msg_json(struct imsg
*,
64 struct show_params
*, json_object
*);
65 static int show_discovery_msg(struct vty
*, struct imsg
*,
66 struct show_params
*);
67 static void show_discovery_detail_adj(struct vty
*, char *,
69 static int show_discovery_detail_msg(struct vty
*, struct imsg
*,
70 struct show_params
*);
71 static int show_discovery_msg_json(struct imsg
*,
72 struct show_params
*, json_object
*);
73 static void show_discovery_detail_adj_json(json_object
*,
75 static int show_discovery_detail_msg_json(struct imsg
*,
76 struct show_params
*, json_object
*);
77 static int show_ldp_sync_msg(struct vty
*, struct imsg
*,
78 struct show_params
*);
79 static int show_ldp_sync_msg_json(struct imsg
*,
80 struct show_params
*, json_object
*);
82 static int show_nbr_msg(struct vty
*, struct imsg
*,
83 struct show_params
*);
84 static int show_nbr_msg_json(struct imsg
*, struct show_params
*,
86 static void show_nbr_detail_adj(struct vty
*, char *,
88 static int show_nbr_detail_msg(struct vty
*, struct imsg
*,
89 struct show_params
*);
90 static void show_nbr_detail_adj_json(struct ctl_adj
*,
92 static int show_nbr_detail_msg_json(struct imsg
*,
93 struct show_params
*, json_object
*);
94 static void show_nbr_capabilities(struct vty
*, struct ctl_nbr
*);
95 static int show_nbr_capabilities_msg(struct vty
*, struct imsg
*,
96 struct show_params
*);
97 static void show_nbr_capabilities_json(struct ctl_nbr
*,
99 static int show_nbr_capabilities_msg_json(struct imsg
*,
100 struct show_params
*, json_object
*);
101 static int show_lib_msg(struct vty
*, struct imsg
*,
102 struct show_params
*);
103 static int show_lib_detail_msg(struct vty
*, struct imsg
*,
104 struct show_params
*);
105 static int show_lib_msg_json(struct imsg
*, struct show_params
*,
107 static int show_lib_detail_msg_json(struct imsg
*,
108 struct show_params
*, json_object
*);
109 static int show_l2vpn_binding_msg(struct vty
*, struct imsg
*,
110 struct show_params
*);
111 static int show_l2vpn_binding_msg_json(struct imsg
*,
112 struct show_params
*, json_object
*);
113 static int show_l2vpn_pw_msg(struct vty
*, struct imsg
*,
114 struct show_params
*);
115 static int show_l2vpn_pw_msg_json(struct imsg
*,
116 struct show_params
*, json_object
*);
117 static int ldp_vty_dispatch_msg(struct vty
*, struct imsg
*,
118 enum show_command
, struct show_params
*,
120 static int ldp_vty_dispatch(struct vty
*, struct imsgbuf
*,
121 enum show_command
, struct show_params
*);
122 static int ldp_vty_get_af(const char *, int *);
125 show_interface_msg(struct vty
*vty
, struct imsg
*imsg
,
126 struct show_params
*params
)
128 struct ctl_iface
*iface
;
131 switch (imsg
->hdr
.type
) {
132 case IMSG_CTL_SHOW_INTERFACE
:
135 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
138 snprintf(timers
, sizeof(timers
), "%u/%u",
139 iface
->hello_interval
, iface
->hello_holdtime
);
141 vty_out (vty
, "%-4s %-11s %-6s %-8s %-12s %3u\n",
142 af_name(iface
->af
), iface
->name
,
143 if_state_name(iface
->state
), iface
->uptime
== 0 ?
144 "00:00:00" : log_time(iface
->uptime
), timers
,
158 show_interface_msg_json(struct imsg
*imsg
, struct show_params
*params
,
161 struct ctl_iface
*iface
;
162 json_object
*json_iface
;
165 switch (imsg
->hdr
.type
) {
166 case IMSG_CTL_SHOW_INTERFACE
:
169 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
172 json_iface
= json_object_new_object();
173 json_object_string_add(json_iface
, "name", iface
->name
);
174 json_object_string_add(json_iface
, "addressFamily",
176 json_object_string_add(json_iface
, "state",
177 if_state_name(iface
->state
));
178 json_object_string_add(json_iface
, "upTime",
179 log_time(iface
->uptime
));
180 json_object_int_add(json_iface
, "helloInterval",
181 iface
->hello_interval
);
182 json_object_int_add(json_iface
, "helloHoldtime",
183 iface
->hello_holdtime
);
184 json_object_int_add(json_iface
, "adjacencyCount",
187 snprintf(key_name
, sizeof(key_name
), "%s: %s", iface
->name
,
189 json_object_object_add(json
, key_name
, json_iface
);
201 show_ldp_sync_msg(struct vty
*vty
, struct imsg
*imsg
,
202 struct show_params
*params
)
204 struct ctl_ldp_sync
*iface
;
206 switch (imsg
->hdr
.type
) {
207 case IMSG_CTL_SHOW_LDP_SYNC
:
210 vty_out (vty
, "%s:\n", iface
->name
);
212 vty_out (vty
, " Status: initial label exchange complete\n");
214 vty_out (vty
, " Status: label exchange not complete\n");
216 if (iface
->timer_running
) {
217 vty_out (vty
, " Wait time: %d seconds (%d seconds left)\n",
218 iface
->wait_time
, iface
->wait_time_remaining
);
219 vty_out (vty
, " Timer is running\n");
221 vty_out (vty
, " Wait time: %d seconds\n",
223 vty_out (vty
, " Timer is not running\n");
226 if (iface
->peer_ldp_id
.s_addr
)
227 vty_out (vty
, " Peer LDP Identifier: %pI4:0\n",
228 &iface
->peer_ldp_id
);
241 show_ldp_sync_msg_json(struct imsg
*imsg
, struct show_params
*params
,
244 struct ctl_ldp_sync
*iface
;
245 json_object
*json_iface
;
246 char buf
[PREFIX_STRLEN
];
248 switch (imsg
->hdr
.type
) {
249 case IMSG_CTL_SHOW_LDP_SYNC
:
252 json_iface
= json_object_new_object();
253 json_object_string_add(json_iface
, "state",
255 ? "labelExchangeComplete"
256 : "labelExchangeNotComplete");
257 json_object_int_add(json_iface
, "waitTime",
259 json_object_int_add(json_iface
, "waitTimeRemaining",
260 iface
->wait_time_remaining
);
262 if (iface
->timer_running
)
263 json_object_boolean_true_add(json_iface
, "timerRunning");
265 json_object_boolean_false_add(json_iface
, "timerRunning");
267 json_object_string_add(json_iface
, "peerLdpId",
268 iface
->peer_ldp_id
.s_addr
?
269 inet_ntop(AF_INET
, &iface
->peer_ldp_id
, buf
, sizeof(buf
)) :
272 json_object_object_add(json
, iface
->name
, json_iface
);
284 show_discovery_msg(struct vty
*vty
, struct imsg
*imsg
,
285 struct show_params
*params
)
290 switch (imsg
->hdr
.type
) {
291 case IMSG_CTL_SHOW_DISCOVERY
:
294 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
297 vty_out(vty
, "%-4s %-15pI4 ", af_name(adj
->af
), &adj
->id
);
300 vty_out(vty
, "%-8s %-15s ", "Link", adj
->ifname
);
303 addr
= log_addr(adj
->af
, &adj
->src_addr
);
305 vty_out(vty
, "%-8s %-15s ", "Targeted", addr
);
306 if (strlen(addr
) > 15)
307 vty_out(vty
, "\n%46s", " ");
310 vty_out (vty
, "%9u\n", adj
->holdtime
);
323 show_discovery_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
325 size_t buflen
= strlen(buffer
);
327 snprintfrr(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
328 " LSR Id: %pI4:0\n", &adj
->id
);
329 buflen
= strlen(buffer
);
330 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
331 " Source address: %s\n",
332 log_addr(adj
->af
, &adj
->src_addr
));
333 buflen
= strlen(buffer
);
334 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
335 " Transport address: %s\n",
336 log_addr(adj
->af
, &adj
->trans_addr
));
337 buflen
= strlen(buffer
);
338 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
339 " Hello hold time: %u secs (due in %u secs)\n",
340 adj
->holdtime
, adj
->holdtime_remaining
);
341 buflen
= strlen(buffer
);
342 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
343 " Dual-stack capability TLV: %s\n",
344 (adj
->ds_tlv
) ? "yes" : "no");
348 show_discovery_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
349 struct show_params
*params
)
352 struct ctl_disc_if
*iface
;
353 struct ctl_disc_tnbr
*tnbr
;
354 struct in_addr rtr_id
;
355 union ldpd_addr
*trans_addr
;
357 static char ifaces_buffer
[LDPBUFSIZ
];
358 static char tnbrs_buffer
[LDPBUFSIZ
];
360 switch (imsg
->hdr
.type
) {
361 case IMSG_CTL_SHOW_DISCOVERY
:
362 ifaces_buffer
[0] = '\0';
363 tnbrs_buffer
[0] = '\0';
365 case IMSG_CTL_SHOW_DISC_IFACE
:
368 if (params
->family
!= AF_UNSPEC
&&
369 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
370 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
373 buflen
= strlen(ifaces_buffer
);
374 snprintf(ifaces_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
375 " %s: %s\n", iface
->name
, (iface
->no_adj
) ?
376 "(no adjacencies)" : "");
378 case IMSG_CTL_SHOW_DISC_TNBR
:
381 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
384 trans_addr
= &(ldp_af_conf_get(ldpd_conf
,
385 tnbr
->af
))->trans_addr
;
386 buflen
= strlen(tnbrs_buffer
);
387 snprintf(tnbrs_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
388 " %s -> %s: %s\n", log_addr(tnbr
->af
, trans_addr
),
389 log_addr(tnbr
->af
, &tnbr
->addr
), (tnbr
->no_adj
) ?
390 "(no adjacencies)" : "");
392 case IMSG_CTL_SHOW_DISC_ADJ
:
395 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
400 show_discovery_detail_adj(vty
, ifaces_buffer
, adj
);
403 show_discovery_detail_adj(vty
, tnbrs_buffer
, adj
);
408 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
409 vty_out (vty
, "Local:\n");
410 vty_out (vty
, " LSR Id: %pI4:0\n",&rtr_id
);
411 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
412 vty_out (vty
, " Transport Address (IPv4): %s\n",
413 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
414 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
415 vty_out (vty
, " Transport Address (IPv6): %s\n",
416 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
417 vty_out (vty
, "Discovery Sources:\n");
418 vty_out (vty
, " Interfaces:\n");
419 vty_out(vty
, "%s", ifaces_buffer
);
420 vty_out (vty
, " Targeted Hellos:\n");
421 vty_out(vty
, "%s", tnbrs_buffer
);
432 show_discovery_msg_json(struct imsg
*imsg
, struct show_params
*params
,
436 json_object
*json_array
;
437 json_object
*json_adj
;
439 switch (imsg
->hdr
.type
) {
440 case IMSG_CTL_SHOW_DISCOVERY
:
443 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
446 json_object_object_get_ex(json
, "adjacencies", &json_array
);
448 json_array
= json_object_new_array();
449 json_object_object_add(json
, "adjacencies", json_array
);
452 json_adj
= json_object_new_object();
453 json_object_string_add(json_adj
, "addressFamily",
455 json_object_string_addf(json_adj
, "neighborId", "%pI4",
459 json_object_string_add(json_adj
, "type", "link");
460 json_object_string_add(json_adj
, "interface",
464 json_object_string_add(json_adj
, "type", "targeted");
465 json_object_string_add(json_adj
, "peer",
466 log_addr(adj
->af
, &adj
->src_addr
));
469 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
471 json_object_array_add(json_array
, json_adj
);
483 show_discovery_detail_adj_json(json_object
*json
, struct ctl_adj
*adj
)
485 json_object
*json_adj
;
486 json_object
*json_array
;
488 json_object_object_get_ex(json
, "adjacencies", &json_array
);
490 json_array
= json_object_new_array();
491 json_object_object_add(json
, "adjacencies", json_array
);
494 json_adj
= json_object_new_object();
495 json_object_string_addf(json_adj
, "lsrId", "%pI4", &adj
->id
);
496 json_object_string_add(json_adj
, "sourceAddress", log_addr(adj
->af
,
498 json_object_string_add(json_adj
, "transportAddress", log_addr(adj
->af
,
500 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
501 json_object_int_add(json_adj
, "helloHoldtimeRemaining",
502 adj
->holdtime_remaining
);
503 json_object_int_add(json_adj
, "dualStackCapabilityTlv",
505 json_object_array_add(json_array
, json_adj
);
509 show_discovery_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
513 struct ctl_disc_if
*iface
;
514 struct ctl_disc_tnbr
*tnbr
;
515 struct in_addr rtr_id
;
516 union ldpd_addr
*trans_addr
;
517 json_object
*json_interface
;
518 json_object
*json_target
;
519 static json_object
*json_interfaces
;
520 static json_object
*json_targets
;
521 static json_object
*json_container
;
523 switch (imsg
->hdr
.type
) {
524 case IMSG_CTL_SHOW_DISCOVERY
:
525 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
526 json_object_string_addf(json
, "lsrId", "%pI4", &rtr_id
);
527 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
528 json_object_string_add(json
, "transportAddressIPv4",
529 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
530 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
531 json_object_string_add(json
, "transportAddressIPv6",
532 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
533 json_interfaces
= json_object_new_object();
534 json_object_object_add(json
, "interfaces", json_interfaces
);
535 json_targets
= json_object_new_object();
536 json_object_object_add(json
, "targetedHellos", json_targets
);
537 json_container
= NULL
;
539 case IMSG_CTL_SHOW_DISC_IFACE
:
542 if (params
->family
!= AF_UNSPEC
&&
543 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
544 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
547 json_interface
= json_object_new_object();
548 json_object_object_add(json_interfaces
, iface
->name
,
550 json_container
= json_interface
;
552 case IMSG_CTL_SHOW_DISC_TNBR
:
555 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
558 trans_addr
= &(ldp_af_conf_get(ldpd_conf
, tnbr
->af
))->trans_addr
;
560 json_target
= json_object_new_object();
561 json_object_string_add(json_target
, "sourceAddress",
562 log_addr(tnbr
->af
, trans_addr
));
563 json_object_object_add(json_targets
, log_addr(tnbr
->af
,
564 &tnbr
->addr
), json_target
);
565 json_container
= json_target
;
567 case IMSG_CTL_SHOW_DISC_ADJ
:
570 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
575 show_discovery_detail_adj_json(json_container
, adj
);
578 show_discovery_detail_adj_json(json_container
, adj
);
592 show_nbr_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
597 switch (imsg
->hdr
.type
) {
598 case IMSG_CTL_SHOW_NBR
:
601 addr
= log_addr(nbr
->af
, &nbr
->raddr
);
603 vty_out(vty
, "%-4s %-15pI4 %-11s %-15s",
604 af_name(nbr
->af
), &nbr
->id
,
605 nbr_state_name(nbr
->nbr_state
), addr
);
606 if (strlen(addr
) > 15)
607 vty_out(vty
, "\n%48s", " ");
608 vty_out (vty
, " %8s\n", log_time(nbr
->uptime
));
620 show_nbr_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
622 size_t buflen
= strlen(buffer
);
626 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
627 " Interface: %s\n", adj
->ifname
);
630 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
631 " Targeted Hello: %s\n", log_addr(adj
->af
,
638 show_nbr_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
639 struct show_params
*params
)
642 struct ldp_stats
*stats
;
644 static char v4adjs_buffer
[LDPBUFSIZ
];
645 static char v6adjs_buffer
[LDPBUFSIZ
];
647 switch (imsg
->hdr
.type
) {
648 case IMSG_CTL_SHOW_NBR
:
651 v4adjs_buffer
[0] = '\0';
652 v6adjs_buffer
[0] = '\0';
653 vty_out (vty
, "Peer LDP Identifier: %pI4:0\n",
655 vty_out (vty
, " TCP connection: %s:%u - %s:%u\n",
656 log_addr(nbr
->af
, &nbr
->laddr
), ntohs(nbr
->lport
),
657 log_addr(nbr
->af
, &nbr
->raddr
),ntohs(nbr
->rport
));
658 vty_out (vty
, " Authentication: %s\n",
659 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" : "none");
660 vty_out(vty
, " Session Holdtime: %u secs; KeepAlive interval: %u secs\n", nbr
->holdtime
,
661 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
662 vty_out(vty
, " State: %s; Downstream-Unsolicited\n",
663 nbr_state_name(nbr
->nbr_state
));
664 vty_out (vty
, " Up time: %s\n",log_time(nbr
->uptime
));
667 vty_out (vty
, " Messages sent/rcvd:\n");
668 vty_out (vty
, " - Keepalive Messages: %u/%u\n",
669 stats
->kalive_sent
, stats
->kalive_rcvd
);
670 vty_out (vty
, " - Address Messages: %u/%u\n",
671 stats
->addr_sent
, stats
->addr_rcvd
);
672 vty_out (vty
, " - Address Withdraw Messages: %u/%u\n",
673 stats
->addrwdraw_sent
, stats
->addrwdraw_rcvd
);
674 vty_out (vty
, " - Notification Messages: %u/%u\n",
675 stats
->notif_sent
, stats
->notif_rcvd
);
676 vty_out (vty
, " - Capability Messages: %u/%u\n",
677 stats
->capability_sent
, stats
->capability_rcvd
);
678 vty_out (vty
, " - Label Mapping Messages: %u/%u\n",
679 stats
->labelmap_sent
, stats
->labelmap_rcvd
);
680 vty_out (vty
, " - Label Request Messages: %u/%u\n",
681 stats
->labelreq_sent
, stats
->labelreq_rcvd
);
682 vty_out (vty
, " - Label Withdraw Messages: %u/%u\n",
683 stats
->labelwdraw_sent
, stats
->labelwdraw_rcvd
);
684 vty_out (vty
, " - Label Release Messages: %u/%u\n",
685 stats
->labelrel_sent
, stats
->labelrel_rcvd
);
686 vty_out (vty
, " - Label Abort Request Messages: %u/%u\n",
687 stats
->labelabreq_sent
, stats
->labelabreq_rcvd
);
689 show_nbr_capabilities(vty
, nbr
);
691 case IMSG_CTL_SHOW_NBR_DISC
:
696 show_nbr_detail_adj(vty
, v4adjs_buffer
, adj
);
699 show_nbr_detail_adj(vty
, v6adjs_buffer
, adj
);
702 fatalx("show_nbr_detail_msg: unknown af");
705 case IMSG_CTL_SHOW_NBR_END
:
706 vty_out (vty
, " LDP Discovery Sources:\n");
707 if (v4adjs_buffer
[0] != '\0') {
708 vty_out (vty
, " IPv4:\n");
709 vty_out(vty
, "%s", v4adjs_buffer
);
711 if (v6adjs_buffer
[0] != '\0') {
712 vty_out (vty
, " IPv6:\n");
713 vty_out(vty
, "%s", v6adjs_buffer
);
727 show_nbr_msg_json(struct imsg
*imsg
, struct show_params
*params
,
731 json_object
*json_array
;
732 json_object
*json_nbr
;
734 switch (imsg
->hdr
.type
) {
735 case IMSG_CTL_SHOW_NBR
:
738 json_object_object_get_ex(json
, "neighbors", &json_array
);
740 json_array
= json_object_new_array();
741 json_object_object_add(json
, "neighbors", json_array
);
744 json_nbr
= json_object_new_object();
745 json_object_string_add(json_nbr
, "addressFamily",
747 json_object_string_addf(json_nbr
, "neighborId", "%pI4",
749 json_object_string_add(json_nbr
, "state",
750 nbr_state_name(nbr
->nbr_state
));
751 json_object_string_add(json_nbr
, "transportAddress",
752 log_addr(nbr
->af
, &nbr
->raddr
));
753 json_object_string_add(json_nbr
, "upTime",
754 log_time(nbr
->uptime
));
756 json_object_array_add(json_array
, json_nbr
);
768 show_nbr_detail_adj_json(struct ctl_adj
*adj
, json_object
*adj_list
)
770 char adj_string
[128];
774 strlcpy(adj_string
, "interface: ", sizeof(adj_string
));
775 strlcat(adj_string
, adj
->ifname
, sizeof(adj_string
));
778 strlcpy(adj_string
, "targetedHello: ", sizeof(adj_string
));
779 strlcat(adj_string
, log_addr(adj
->af
, &adj
->src_addr
),
784 json_object_array_add(adj_list
, json_object_new_string(adj_string
));
788 show_nbr_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
792 struct ldp_stats
*stats
;
794 char buf
[PREFIX_STRLEN
];
795 json_object
*json_nbr
;
796 json_object
*json_array
;
797 json_object
*json_counter
;
798 static json_object
*json_nbr_sources
;
799 static json_object
*json_v4adjs
;
800 static json_object
*json_v6adjs
;
802 switch (imsg
->hdr
.type
) {
803 case IMSG_CTL_SHOW_NBR
:
806 json_nbr
= json_object_new_object();
807 json_object_object_add(json
,
808 inet_ntop(AF_INET
, &nbr
->id
, buf
,
809 sizeof(buf
)), json_nbr
);
810 json_object_string_addf(json_nbr
, "peerId", "%pI4", &nbr
->id
);
811 json_object_string_add(json_nbr
, "tcpLocalAddress",
812 log_addr(nbr
->af
, &nbr
->laddr
));
813 json_object_int_add(json_nbr
, "tcpLocalPort",
815 json_object_string_add(json_nbr
, "tcpRemoteAddress",
816 log_addr(nbr
->af
, &nbr
->raddr
));
817 json_object_int_add(json_nbr
, "tcpRemotePort",
819 json_object_string_add(json_nbr
, "authentication",
820 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
822 json_object_int_add(json_nbr
, "sessionHoldtime", nbr
->holdtime
);
823 json_object_int_add(json_nbr
, "keepAliveInterval",
824 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
825 json_object_string_add(json_nbr
, "state",
826 nbr_state_name(nbr
->nbr_state
));
827 json_object_string_add(json_nbr
, "upTime",
828 log_time(nbr
->uptime
));
830 /* message_counters */
832 json_array
= json_object_new_array();
833 json_object_object_add(json_nbr
, "sentMessages", json_array
);
834 json_counter
= json_object_new_object();
835 json_object_int_add(json_counter
, "keepalive",
837 json_object_array_add(json_array
, json_counter
);
838 json_counter
= json_object_new_object();
839 json_object_int_add(json_counter
, "address",
841 json_object_array_add(json_array
, json_counter
);
842 json_counter
= json_object_new_object();
843 json_object_int_add(json_counter
, "addressWithdraw",
844 stats
->addrwdraw_sent
);
845 json_object_array_add(json_array
, json_counter
);
846 json_counter
= json_object_new_object();
847 json_object_int_add(json_counter
, "notification",
849 json_object_array_add(json_array
, json_counter
);
850 json_counter
= json_object_new_object();
851 json_object_int_add(json_counter
, "capability",
852 stats
->capability_sent
);
853 json_object_array_add(json_array
, json_counter
);
854 json_counter
= json_object_new_object();
855 json_object_int_add(json_counter
, "labelMapping",
856 stats
->labelmap_sent
);
857 json_object_array_add(json_array
, json_counter
);
858 json_counter
= json_object_new_object();
859 json_object_int_add(json_counter
, "labelRequest",
860 stats
->labelreq_sent
);
861 json_object_array_add(json_array
, json_counter
);
862 json_counter
= json_object_new_object();
863 json_object_int_add(json_counter
, "labelWithdraw",
864 stats
->labelwdraw_sent
);
865 json_object_array_add(json_array
, json_counter
);
866 json_counter
= json_object_new_object();
867 json_object_int_add(json_counter
, "labelRelease",
868 stats
->labelrel_sent
);
869 json_object_array_add(json_array
, json_counter
);
870 json_counter
= json_object_new_object();
871 json_object_int_add(json_counter
, "labelAbortRequest",
872 stats
->labelabreq_sent
);
873 json_object_array_add(json_array
, json_counter
);
875 json_array
= json_object_new_array();
876 json_object_object_add(json_nbr
, "receivedMessages", json_array
);
877 json_counter
= json_object_new_object();
878 json_object_int_add(json_counter
, "keepalive",
880 json_object_array_add(json_array
, json_counter
);
881 json_counter
= json_object_new_object();
882 json_object_int_add(json_counter
, "address",
884 json_object_array_add(json_array
, json_counter
);
885 json_counter
= json_object_new_object();
886 json_object_int_add(json_counter
, "addressWithdraw",
887 stats
->addrwdraw_rcvd
);
888 json_object_array_add(json_array
, json_counter
);
889 json_counter
= json_object_new_object();
890 json_object_int_add(json_counter
, "notification",
892 json_object_array_add(json_array
, json_counter
);
893 json_counter
= json_object_new_object();
894 json_object_int_add(json_counter
, "capability",
895 stats
->capability_rcvd
);
896 json_object_array_add(json_array
, json_counter
);
897 json_counter
= json_object_new_object();
898 json_object_int_add(json_counter
, "labelMapping",
899 stats
->labelmap_rcvd
);
900 json_object_array_add(json_array
, json_counter
);
901 json_counter
= json_object_new_object();
902 json_object_int_add(json_counter
, "labelRequest",
903 stats
->labelreq_rcvd
);
904 json_object_array_add(json_array
, json_counter
);
905 json_counter
= json_object_new_object();
906 json_object_int_add(json_counter
, "labelWithdraw",
907 stats
->labelwdraw_rcvd
);
908 json_object_array_add(json_array
, json_counter
);
909 json_counter
= json_object_new_object();
910 json_object_int_add(json_counter
, "labelRelease",
911 stats
->labelrel_rcvd
);
912 json_object_array_add(json_array
, json_counter
);
913 json_counter
= json_object_new_object();
914 json_object_int_add(json_counter
, "labelAbortRequest",
915 stats
->labelabreq_rcvd
);
916 json_object_array_add(json_array
, json_counter
);
919 show_nbr_capabilities_json(nbr
, json_nbr
);
921 /* discovery sources */
922 json_nbr_sources
= json_object_new_object();
923 json_object_object_add(json_nbr
, "discoverySources",
928 case IMSG_CTL_SHOW_NBR_DISC
:
934 json_v4adjs
= json_object_new_array();
935 json_object_object_add(json_nbr_sources
, "ipv4",
938 show_nbr_detail_adj_json(adj
, json_v4adjs
);
942 json_v6adjs
= json_object_new_array();
943 json_object_object_add(json_nbr_sources
, "ipv6",
946 show_nbr_detail_adj_json(adj
, json_v6adjs
);
949 fatalx("show_nbr_detail_msg_json: unknown af");
952 case IMSG_CTL_SHOW_NBR_END
:
964 show_nbr_capabilities(struct vty
*vty
, struct ctl_nbr
*nbr
)
966 vty_out (vty
, " Capabilities Sent:\n"
967 " - Dynamic Announcement (0x0506)\n"
968 " - Typed Wildcard (0x050B)\n"
969 " - Unrecognized Notification (0x0603)\n");
970 vty_out (vty
, " Capabilities Received:\n");
971 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
)
972 vty_out (vty
," - Dynamic Announcement (0x0506)\n");
973 if (nbr
->flags
& F_NBR_CAP_TWCARD
)
974 vty_out (vty
, " - Typed Wildcard (0x050B)\n");
975 if (nbr
->flags
& F_NBR_CAP_UNOTIF
)
976 vty_out (vty
," - Unrecognized Notification (0x0603)\n");
980 show_nbr_capabilities_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
984 switch (imsg
->hdr
.type
) {
985 case IMSG_CTL_SHOW_NBR
:
988 if (nbr
->nbr_state
!= NBR_STA_OPER
)
991 vty_out (vty
, "Peer LDP Identifier: %pI4:0\n",
993 show_nbr_capabilities(vty
, nbr
);
1007 show_nbr_capabilities_json(struct ctl_nbr
*nbr
, json_object
*json_nbr
)
1009 json_object
*json_array
;
1010 json_object
*json_cap
;
1012 /* sent capabilities */
1013 json_array
= json_object_new_array();
1014 json_object_object_add(json_nbr
, "sentCapabilities", json_array
);
1016 /* Dynamic Announcement (0x0506) */
1017 json_cap
= json_object_new_object();
1018 json_object_string_add(json_cap
, "description", "Dynamic Announcement");
1019 json_object_string_add(json_cap
, "tlvType", "0x0506");
1020 json_object_array_add(json_array
, json_cap
);
1022 /* Typed Wildcard (0x050B) */
1023 json_cap
= json_object_new_object();
1024 json_object_string_add(json_cap
, "description", "Typed Wildcard");
1025 json_object_string_add(json_cap
, "tlvType", "0x050B");
1026 json_object_array_add(json_array
, json_cap
);
1028 /* Unrecognized Notification (0x0603) */
1029 json_cap
= json_object_new_object();
1030 json_object_string_add(json_cap
, "description",
1031 "Unrecognized Notification");
1032 json_object_string_add(json_cap
, "tlvType", "0x0603");
1033 json_object_array_add(json_array
, json_cap
);
1035 /* received capabilities */
1036 json_array
= json_object_new_array();
1037 json_object_object_add(json_nbr
, "receivedCapabilities", json_array
);
1039 /* Dynamic Announcement (0x0506) */
1040 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
) {
1041 json_cap
= json_object_new_object();
1042 json_object_string_add(json_cap
, "description",
1043 "Dynamic Announcement");
1044 json_object_string_add(json_cap
, "tlvType", "0x0506");
1045 json_object_array_add(json_array
, json_cap
);
1048 /* Typed Wildcard (0x050B) */
1049 if (nbr
->flags
& F_NBR_CAP_TWCARD
) {
1050 json_cap
= json_object_new_object();
1051 json_object_string_add(json_cap
, "description",
1053 json_object_string_add(json_cap
, "tlvType", "0x050B");
1054 json_object_array_add(json_array
, json_cap
);
1057 /* Unrecognized Notification (0x0603) */
1058 if (nbr
->flags
& F_NBR_CAP_UNOTIF
) {
1059 json_cap
= json_object_new_object();
1060 json_object_string_add(json_cap
, "description",
1061 "Unrecognized Notification");
1062 json_object_string_add(json_cap
, "tlvType", "0x0603");
1063 json_object_array_add(json_array
, json_cap
);
1068 show_nbr_capabilities_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1071 struct ctl_nbr
*nbr
;
1072 char buf
[PREFIX_STRLEN
];
1073 json_object
*json_nbr
;
1075 switch (imsg
->hdr
.type
) {
1076 case IMSG_CTL_SHOW_NBR
:
1079 if (nbr
->nbr_state
!= NBR_STA_OPER
)
1082 json_nbr
= json_object_new_object();
1083 json_object_object_add(json
, inet_ntop(AF_INET
, &nbr
->id
, buf
,
1084 sizeof(buf
)), json_nbr
);
1085 show_nbr_capabilities_json(nbr
, json_nbr
);
1097 show_lib_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1100 char dstnet
[BUFSIZ
];
1102 switch (imsg
->hdr
.type
) {
1103 case IMSG_CTL_SHOW_LIB_BEGIN
:
1106 if (params
->lib
.remote_label
!= NO_LABEL
&&
1107 params
->lib
.remote_label
!= rt
->remote_label
)
1110 case IMSG_CTL_SHOW_LIB_RCVD
:
1113 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1117 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1118 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1120 vty_out(vty
, "%-4s %-20s", af_name(rt
->af
), dstnet
);
1121 if (strlen(dstnet
) > 20)
1122 vty_out(vty
, "\n%25s", " ");
1123 vty_out (vty
, " %-15pI4 %-11s %-13s %6s\n",
1124 &rt
->nexthop
, log_label(rt
->local_label
),
1125 log_label(rt
->remote_label
),
1126 rt
->in_use
? "yes" : "no");
1129 vty_out (vty
, "\n");
1139 show_lib_detail_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1141 struct ctl_rt
*rt
= NULL
;
1142 static char dstnet
[BUFSIZ
];
1143 static int upstream
, downstream
;
1145 static char sent_buffer
[LDPBUFSIZ
];
1146 static char rcvd_buffer
[LDPBUFSIZ
];
1148 switch (imsg
->hdr
.type
) {
1149 case IMSG_CTL_SHOW_LIB_BEGIN
:
1154 sent_buffer
[0] = '\0';
1155 rcvd_buffer
[0] = '\0';
1156 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1157 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1159 case IMSG_CTL_SHOW_LIB_SENT
:
1163 buflen
= strlen(sent_buffer
);
1164 snprintfrr(sent_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1165 "%12s%pI4:0\n", "", &rt
->nexthop
);
1167 case IMSG_CTL_SHOW_LIB_RCVD
:
1170 buflen
= strlen(rcvd_buffer
);
1171 snprintfrr(rcvd_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1172 "%12s%pI4:0, label %s%s\n", "", &rt
->nexthop
,
1173 log_label(rt
->remote_label
),
1174 rt
->in_use
? " (in use)" : "");
1176 case IMSG_CTL_SHOW_LIB_END
:
1179 if (params
->lib
.remote_label
!= NO_LABEL
&&
1182 vty_out(vty
, "%s\n", dstnet
);
1183 vty_out(vty
, "%-8sLocal binding: label: %s\n", "",
1184 log_label(rt
->local_label
));
1186 vty_out (vty
, "%-8sAdvertised to:\n", "");
1187 vty_out(vty
, "%s", sent_buffer
);
1190 vty_out (vty
, "%-8sRemote bindings:\n", "");
1191 vty_out(vty
, "%s", rcvd_buffer
);
1193 vty_out (vty
, "%-8sNo remote bindings\n","");
1196 vty_out (vty
, "\n");
1206 show_lib_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1210 json_object
*json_array
;
1211 json_object
*json_lib_entry
;
1212 char dstnet
[BUFSIZ
];
1214 switch (imsg
->hdr
.type
) {
1215 case IMSG_CTL_SHOW_LIB_BEGIN
:
1216 case IMSG_CTL_SHOW_LIB_RCVD
:
1219 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1223 json_object_object_get_ex(json
, "bindings", &json_array
);
1225 json_array
= json_object_new_array();
1226 json_object_object_add(json
, "bindings", json_array
);
1229 json_lib_entry
= json_object_new_object();
1230 json_object_string_add(json_lib_entry
, "addressFamily",
1232 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1233 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1234 json_object_string_add(json_lib_entry
, "prefix", dstnet
);
1235 json_object_string_addf(json_lib_entry
, "neighborId", "%pI4",
1237 json_object_string_add(json_lib_entry
, "localLabel",
1238 log_label(rt
->local_label
));
1239 json_object_string_add(json_lib_entry
, "remoteLabel",
1240 log_label(rt
->remote_label
));
1241 json_object_int_add(json_lib_entry
, "inUse", rt
->in_use
);
1243 json_object_array_add(json_array
, json_lib_entry
);
1255 show_lib_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1258 struct ctl_rt
*rt
= NULL
;
1259 char dstnet
[BUFSIZ
];
1260 static json_object
*json_lib_entry
;
1261 static json_object
*json_adv_labels
;
1262 json_object
*json_adv_label
;
1263 static json_object
*json_remote_labels
;
1264 json_object
*json_remote_label
;
1266 switch (imsg
->hdr
.type
) {
1267 case IMSG_CTL_SHOW_LIB_BEGIN
:
1270 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1271 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1273 json_lib_entry
= json_object_new_object();
1274 json_object_string_add(json_lib_entry
, "localLabel",
1275 log_label(rt
->local_label
));
1277 json_adv_labels
= json_object_new_array();
1278 json_object_object_add(json_lib_entry
, "advertisedTo",
1281 json_remote_labels
= json_object_new_array();
1282 json_object_object_add(json_lib_entry
, "remoteLabels",
1283 json_remote_labels
);
1285 json_object_object_add(json
, dstnet
, json_lib_entry
);
1287 case IMSG_CTL_SHOW_LIB_SENT
:
1290 json_adv_label
= json_object_new_object();
1291 json_object_string_addf(json_adv_label
, "neighborId", "%pI4",
1293 json_object_array_add(json_adv_labels
, json_adv_label
);
1295 case IMSG_CTL_SHOW_LIB_RCVD
:
1298 json_remote_label
= json_object_new_object();
1299 json_object_string_addf(json_remote_label
, "neighborId", "%pI4",
1301 json_object_string_add(json_remote_label
, "label",
1302 log_label(rt
->remote_label
));
1303 json_object_int_add(json_remote_label
, "inUse", rt
->in_use
);
1304 json_object_array_add(json_remote_labels
, json_remote_label
);
1316 show_l2vpn_binding_msg(struct vty
*vty
, struct imsg
*imsg
,
1317 struct show_params
*params
)
1321 switch (imsg
->hdr
.type
) {
1322 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1325 vty_out (vty
, " Destination Address: %pI4, VC ID: %u\n",
1326 &pw
->lsr_id
, pw
->pwid
);
1329 if (pw
->local_label
!= NO_LABEL
) {
1330 vty_out (vty
, " Local Label: %u\n",
1332 vty_out (vty
, "%-8sCbit: %u, VC Type: %s, GroupID: %u\n", "", pw
->local_cword
,
1333 pw_type_name(pw
->type
),pw
->local_gid
);
1334 vty_out (vty
, "%-8sMTU: %u\n", "",pw
->local_ifmtu
);
1335 vty_out (vty
, "%-8sLast failure: %s\n", "",
1336 pw_error_code(pw
->reason
));
1338 vty_out (vty
," Local Label: unassigned\n");
1340 /* remote binding */
1341 if (pw
->remote_label
!= NO_LABEL
) {
1342 vty_out (vty
, " Remote Label: %u\n",
1344 vty_out (vty
, "%-8sCbit: %u, VC Type: %s, GroupID: %u\n", "", pw
->remote_cword
,
1345 pw_type_name(pw
->type
),pw
->remote_gid
);
1346 vty_out (vty
, "%-8sMTU: %u\n", "",pw
->remote_ifmtu
);
1348 vty_out (vty
," Remote Label: unassigned\n");
1351 vty_out (vty
, "\n");
1361 show_l2vpn_binding_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1365 json_object
*json_pw
;
1368 switch (imsg
->hdr
.type
) {
1369 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1372 json_pw
= json_object_new_object();
1373 json_object_string_addf(json_pw
, "destination", "%pI4",
1375 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1378 if (pw
->local_label
!= NO_LABEL
) {
1379 json_object_int_add(json_pw
, "localLabel",
1381 json_object_int_add(json_pw
, "localControlWord",
1383 json_object_string_add(json_pw
, "localVcType",
1384 pw_type_name(pw
->type
));
1385 json_object_int_add(json_pw
, "localGroupID",
1387 json_object_int_add(json_pw
, "localIfMtu",
1389 json_object_string_add(json_pw
, "lastFailureReason",
1390 pw_error_code(pw
->reason
));
1392 json_object_string_add(json_pw
, "localLabel",
1395 /* remote binding */
1396 if (pw
->remote_label
!= NO_LABEL
) {
1397 json_object_int_add(json_pw
, "remoteLabel",
1399 json_object_int_add(json_pw
, "remoteControlWord",
1401 json_object_string_add(json_pw
, "remoteVcType",
1402 pw_type_name(pw
->type
));
1403 json_object_int_add(json_pw
, "remoteGroupID",
1405 json_object_int_add(json_pw
, "remoteIfMtu",
1408 json_object_string_add(json_pw
, "remoteLabel",
1411 snprintfrr(key_name
, sizeof(key_name
), "%pI4: %u",
1412 &pw
->lsr_id
, pw
->pwid
);
1413 json_object_object_add(json
, key_name
, json_pw
);
1425 show_l2vpn_pw_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1429 switch (imsg
->hdr
.type
) {
1430 case IMSG_CTL_SHOW_L2VPN_PW
:
1433 vty_out (vty
, "%-9s %-15pI4 %-10u %-16s %-10s\n", pw
->ifname
,
1434 &pw
->lsr_id
, pw
->pwid
, pw
->l2vpn_name
,
1435 (pw
->status
== PW_FORWARDING
? "UP" : "DOWN"));
1438 vty_out (vty
, "\n");
1448 show_l2vpn_pw_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1452 json_object
*json_pw
;
1454 switch (imsg
->hdr
.type
) {
1455 case IMSG_CTL_SHOW_L2VPN_PW
:
1458 json_pw
= json_object_new_object();
1459 json_object_string_addf(json_pw
, "peerId", "%pI4", &pw
->lsr_id
);
1460 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1461 json_object_string_add(json_pw
, "vpnName", pw
->l2vpn_name
);
1462 if (pw
->status
== PW_FORWARDING
)
1463 json_object_string_add(json_pw
, "status", "up");
1465 json_object_string_add(json_pw
, "status", "down");
1466 json_object_object_add(json
, pw
->ifname
, json_pw
);
1478 ldp_vty_connect(struct imsgbuf
*ibuf
)
1480 struct sockaddr_un s_un
;
1483 /* connect to ldpd control socket */
1484 if ((ctl_sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
1485 log_warn("%s: socket", __func__
);
1489 memset(&s_un
, 0, sizeof(s_un
));
1490 s_un
.sun_family
= AF_UNIX
;
1491 strlcpy(s_un
.sun_path
, ctl_sock_path
, sizeof(s_un
.sun_path
));
1492 if (connect(ctl_sock
, (struct sockaddr
*)&s_un
, sizeof(s_un
)) == -1) {
1493 log_warn("%s: connect: %s", __func__
, ctl_sock_path
);
1498 imsg_init(ibuf
, ctl_sock
);
1504 ldp_vty_dispatch_iface(struct vty
*vty
, struct imsg
*imsg
,
1505 struct show_params
*params
, json_object
*json
)
1510 ret
= show_interface_msg_json(imsg
, params
, json
);
1512 ret
= show_interface_msg(vty
, imsg
, params
);
1518 ldp_vty_dispatch_ldp_sync(struct vty
*vty
, struct imsg
*imsg
,
1519 struct show_params
*params
, json_object
*json
)
1524 ret
= show_ldp_sync_msg_json(imsg
, params
, json
);
1526 ret
= show_ldp_sync_msg(vty
, imsg
, params
);
1532 ldp_vty_dispatch_disc(struct vty
*vty
, struct imsg
*imsg
,
1533 struct show_params
*params
, json_object
*json
)
1537 if (params
->detail
) {
1539 ret
= show_discovery_detail_msg_json(imsg
, params
,
1542 ret
= show_discovery_detail_msg(vty
, imsg
, params
);
1545 ret
= show_discovery_msg_json(imsg
, params
, json
);
1547 ret
= show_discovery_msg(vty
, imsg
, params
);
1554 ldp_vty_dispatch_nbr(struct vty
*vty
, struct imsg
*imsg
,
1555 struct show_params
*params
, json_object
*json
)
1557 static bool filtered
= false;
1558 struct ctl_nbr
*nbr
;
1561 switch (imsg
->hdr
.type
) {
1562 case IMSG_CTL_SHOW_NBR
:
1566 if (params
->neighbor
.lsr_id
.s_addr
!= INADDR_ANY
&&
1567 params
->neighbor
.lsr_id
.s_addr
!= nbr
->id
.s_addr
) {
1572 case IMSG_CTL_SHOW_NBR_DISC
:
1573 case IMSG_CTL_SHOW_NBR_END
:
1581 if (params
->neighbor
.capabilities
) {
1583 ret
= show_nbr_capabilities_msg_json(imsg
, params
,
1586 ret
= show_nbr_capabilities_msg(vty
, imsg
, params
);
1587 } else if (params
->detail
) {
1589 ret
= show_nbr_detail_msg_json(imsg
, params
, json
);
1591 ret
= show_nbr_detail_msg(vty
, imsg
, params
);
1594 ret
= show_nbr_msg_json(imsg
, params
, json
);
1596 ret
= show_nbr_msg(vty
, imsg
, params
);
1603 ldp_vty_dispatch_lib(struct vty
*vty
, struct imsg
*imsg
,
1604 struct show_params
*params
, json_object
*json
)
1606 static bool filtered
= false;
1607 struct ctl_rt
*rt
= NULL
;
1608 struct prefix prefix
;
1611 switch (imsg
->hdr
.type
) {
1612 case IMSG_CTL_SHOW_LIB_BEGIN
:
1615 case IMSG_CTL_SHOW_LIB_SENT
:
1616 case IMSG_CTL_SHOW_LIB_RCVD
:
1617 case IMSG_CTL_SHOW_LIB_END
:
1625 switch (imsg
->hdr
.type
) {
1626 case IMSG_CTL_SHOW_LIB_BEGIN
:
1627 case IMSG_CTL_SHOW_LIB_SENT
:
1628 case IMSG_CTL_SHOW_LIB_RCVD
:
1629 case IMSG_CTL_SHOW_LIB_END
:
1632 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
) {
1637 prefix
.family
= rt
->af
;
1638 prefix
.prefixlen
= rt
->prefixlen
;
1639 memcpy(&prefix
.u
.val
, &rt
->prefix
, sizeof(prefix
.u
.val
));
1640 if (params
->lib
.prefix
.family
!= AF_UNSPEC
) {
1641 if (!params
->lib
.longer_prefixes
&&
1642 !prefix_same(¶ms
->lib
.prefix
, &prefix
)) {
1645 } else if (params
->lib
.longer_prefixes
&&
1646 !prefix_match(¶ms
->lib
.prefix
, &prefix
)) {
1652 if (params
->lib
.local_label
!= NO_LABEL
&&
1653 params
->lib
.local_label
!= rt
->local_label
) {
1662 switch (imsg
->hdr
.type
) {
1663 case IMSG_CTL_SHOW_LIB_SENT
:
1664 case IMSG_CTL_SHOW_LIB_RCVD
:
1665 if (params
->lib
.neighbor
.s_addr
!= INADDR_ANY
&&
1666 params
->lib
.neighbor
.s_addr
!= rt
->nexthop
.s_addr
)
1673 switch (imsg
->hdr
.type
) {
1674 case IMSG_CTL_SHOW_LIB_RCVD
:
1675 if (params
->lib
.remote_label
!= NO_LABEL
&&
1676 params
->lib
.remote_label
!= rt
->remote_label
)
1683 if (params
->detail
) {
1685 ret
= show_lib_detail_msg_json(imsg
, params
, json
);
1687 ret
= show_lib_detail_msg(vty
, imsg
, params
);
1690 ret
= show_lib_msg_json(imsg
, params
, json
);
1692 ret
= show_lib_msg(vty
, imsg
, params
);
1699 ldp_vty_dispatch_l2vpn_pw(struct vty
*vty
, struct imsg
*imsg
,
1700 struct show_params
*params
, json_object
*json
)
1705 switch (imsg
->hdr
.type
) {
1706 case IMSG_CTL_SHOW_L2VPN_PW
:
1708 if (params
->l2vpn
.peer
.s_addr
!= INADDR_ANY
&&
1709 params
->l2vpn
.peer
.s_addr
!= pw
->lsr_id
.s_addr
)
1711 if (params
->l2vpn
.ifname
[0] != '\0' &&
1712 strcmp(params
->l2vpn
.ifname
, pw
->ifname
))
1714 if (params
->l2vpn
.vcid
&& params
->l2vpn
.vcid
!= pw
->pwid
)
1722 ret
= show_l2vpn_pw_msg_json(imsg
, params
, json
);
1724 ret
= show_l2vpn_pw_msg(vty
, imsg
, params
);
1730 ldp_vty_dispatch_l2vpn_binding(struct vty
*vty
, struct imsg
*imsg
,
1731 struct show_params
*params
, json_object
*json
)
1736 switch (imsg
->hdr
.type
) {
1737 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1739 if (params
->l2vpn
.peer
.s_addr
!= INADDR_ANY
&&
1740 params
->l2vpn
.peer
.s_addr
!= pw
->lsr_id
.s_addr
)
1742 if (params
->l2vpn
.local_label
!= NO_LABEL
&&
1743 params
->l2vpn
.local_label
!= pw
->local_label
)
1745 if (params
->l2vpn
.remote_label
!= NO_LABEL
&&
1746 params
->l2vpn
.remote_label
!= pw
->remote_label
)
1754 ret
= show_l2vpn_binding_msg_json(imsg
, params
, json
);
1756 ret
= show_l2vpn_binding_msg(vty
, imsg
, params
);
1762 ldp_vty_dispatch_msg(struct vty
*vty
, struct imsg
*imsg
, enum show_command cmd
,
1763 struct show_params
*params
, json_object
*json
)
1767 return (ldp_vty_dispatch_iface(vty
, imsg
, params
, json
));
1769 return (ldp_vty_dispatch_disc(vty
, imsg
, params
, json
));
1771 return (ldp_vty_dispatch_nbr(vty
, imsg
, params
, json
));
1773 return (ldp_vty_dispatch_lib(vty
, imsg
, params
, json
));
1775 return (ldp_vty_dispatch_l2vpn_pw(vty
, imsg
, params
, json
));
1776 case SHOW_L2VPN_BINDING
:
1777 return (ldp_vty_dispatch_l2vpn_binding(vty
, imsg
, params
,
1780 return (ldp_vty_dispatch_ldp_sync(vty
, imsg
, params
, json
));
1787 ldp_vty_dispatch(struct vty
*vty
, struct imsgbuf
*ibuf
, enum show_command cmd
,
1788 struct show_params
*params
)
1791 int n
, done
= 0, ret
= CMD_SUCCESS
;
1792 json_object
*json
= NULL
;
1794 while (ibuf
->w
.queued
)
1795 if (msgbuf_write(&ibuf
->w
) <= 0 && errno
!= EAGAIN
) {
1796 log_warn("write error");
1798 return (CMD_WARNING
);
1802 json
= json_object_new_object();
1805 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
) {
1806 log_warnx("imsg_read error");
1811 log_warnx("pipe closed");
1817 if ((n
= imsg_get(ibuf
, &imsg
)) == -1) {
1818 log_warnx("imsg_get error");
1824 done
= ldp_vty_dispatch_msg(vty
, &imsg
, cmd
, params
,
1833 vty_json(vty
, json
);
1840 ldp_vty_get_af(const char *str
, int *af
)
1845 } else if (strcmp(str
, "ipv4") == 0) {
1848 } else if (strcmp(str
, "ipv6") == 0) {
1857 ldp_vty_show_binding(struct vty
*vty
, const char *af_str
, const char *prefix
,
1858 int longer_prefixes
, const char *neighbor
, unsigned long local_label
,
1859 unsigned long remote_label
, const char *detail
, const char *json
)
1861 struct imsgbuf ibuf
;
1862 struct show_params params
;
1865 if (ldp_vty_connect(&ibuf
) < 0)
1866 return (CMD_WARNING
);
1868 if (ldp_vty_get_af(af_str
, &af
) < 0)
1869 return (CMD_ERR_NO_MATCH
);
1871 memset(¶ms
, 0, sizeof(params
));
1873 params
.detail
= (detail
) ? 1 : 0;
1874 params
.json
= (json
) ? 1 : 0;
1876 (void)str2prefix(prefix
, ¶ms
.lib
.prefix
);
1877 params
.lib
.longer_prefixes
= longer_prefixes
;
1880 (inet_pton(AF_INET
, neighbor
, ¶ms
.lib
.neighbor
) != 1 ||
1881 bad_addr_v4(params
.lib
.neighbor
))) {
1882 vty_out (vty
, "%% Malformed address\n");
1883 return (CMD_SUCCESS
);
1885 params
.lib
.local_label
= local_label
;
1886 params
.lib
.remote_label
= remote_label
;
1888 if (!params
.detail
&& !params
.json
)
1889 vty_out (vty
, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF",
1890 "Destination", "Nexthop", "Local Label", "Remote Label",
1893 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LIB
, 0, 0, -1, NULL
, 0);
1894 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LIB
, ¶ms
));
1898 ldp_vty_show_discovery(struct vty
*vty
, const char *af_str
, const char *detail
,
1901 struct imsgbuf ibuf
;
1902 struct show_params params
;
1905 if (ldp_vty_connect(&ibuf
) < 0)
1906 return (CMD_WARNING
);
1908 if (ldp_vty_get_af(af_str
, &af
) < 0)
1909 return (CMD_ERR_NO_MATCH
);
1911 memset(¶ms
, 0, sizeof(params
));
1913 params
.detail
= (detail
) ? 1 : 0;
1914 params
.json
= (json
) ? 1 : 0;
1916 if (!params
.detail
&& !params
.json
)
1917 vty_out (vty
, "%-4s %-15s %-8s %-15s %9s\n",
1918 "AF", "ID", "Type", "Source", "Holdtime");
1921 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY_DTL
, 0, 0, -1,
1924 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
1925 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_DISC
, ¶ms
));
1929 ldp_vty_show_interface(struct vty
*vty
, const char *af_str
, const char *json
)
1931 struct imsgbuf ibuf
;
1932 struct show_params params
;
1933 unsigned int ifidx
= 0;
1936 if (ldp_vty_connect(&ibuf
) < 0)
1937 return (CMD_WARNING
);
1939 if (ldp_vty_get_af(af_str
, &af
) < 0)
1940 return (CMD_ERR_NO_MATCH
);
1942 memset(¶ms
, 0, sizeof(params
));
1944 params
.json
= (json
) ? 1 : 0;
1948 vty_out (vty
, "%-4s %-11s %-6s %-8s %-12s %3s\n", "AF",
1949 "Interface", "State", "Uptime", "Hello Timers","ac");
1952 imsg_compose(&ibuf
, IMSG_CTL_SHOW_INTERFACE
, 0, 0, -1, &ifidx
,
1954 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_IFACE
, ¶ms
));
1958 ldp_vty_show_capabilities(struct vty
*vty
, const char *json
)
1962 json_object
*json_array
;
1963 json_object
*json_cap
;
1965 json
= json_object_new_object();
1966 json_array
= json_object_new_array();
1967 json_object_object_add(json
, "capabilities", json_array
);
1969 /* Dynamic Announcement (0x0506) */
1970 json_cap
= json_object_new_object();
1971 json_object_string_add(json_cap
, "description",
1972 "Dynamic Announcement");
1973 json_object_string_add(json_cap
, "tlvType",
1975 json_object_array_add(json_array
, json_cap
);
1977 /* Typed Wildcard (0x050B) */
1978 json_cap
= json_object_new_object();
1979 json_object_string_add(json_cap
, "description",
1981 json_object_string_add(json_cap
, "tlvType",
1983 json_object_array_add(json_array
, json_cap
);
1985 /* Unrecognized Notification (0x0603) */
1986 json_cap
= json_object_new_object();
1987 json_object_string_add(json_cap
, "description",
1988 "Unrecognized Notification");
1989 json_object_string_add(json_cap
, "tlvType",
1991 json_object_array_add(json_array
, json_cap
);
1993 vty_json(vty
, json
);
1998 "Supported LDP Capabilities\n"
1999 " * Dynamic Announcement (0x0506)\n"
2000 " * Typed Wildcard (0x050B)\n"
2001 " * Unrecognized Notification (0x0603)\n\n");
2007 ldp_vty_show_neighbor(struct vty
*vty
, const char *lsr_id
, int capabilities
,
2008 const char *detail
, const char *json
)
2010 struct imsgbuf ibuf
;
2011 struct show_params params
;
2013 if (ldp_vty_connect(&ibuf
) < 0)
2014 return (CMD_WARNING
);
2016 memset(¶ms
, 0, sizeof(params
));
2017 params
.detail
= (detail
) ? 1 : 0;
2018 params
.json
= (json
) ? 1 : 0;
2019 params
.neighbor
.capabilities
= capabilities
;
2021 (inet_pton(AF_INET
, lsr_id
, ¶ms
.neighbor
.lsr_id
) != 1 ||
2022 bad_addr_v4(params
.neighbor
.lsr_id
))) {
2023 vty_out (vty
, "%% Malformed address\n");
2024 return (CMD_SUCCESS
);
2027 if (params
.neighbor
.capabilities
)
2030 if (!params
.detail
&& !params
.json
)
2031 vty_out (vty
, "%-4s %-15s %-11s %-15s %8s\n",
2032 "AF", "ID", "State", "Remote Address","Uptime");
2034 imsg_compose(&ibuf
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, NULL
, 0);
2035 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_NBR
, ¶ms
));
2039 ldp_vty_show_ldp_sync(struct vty
*vty
, const char *json
)
2041 struct imsgbuf ibuf
;
2042 struct show_params params
;
2044 if (ldp_vty_connect(&ibuf
) < 0)
2045 return (CMD_WARNING
);
2047 memset(¶ms
, 0, sizeof(params
));
2048 params
.json
= (json
) ? 1 : 0;
2050 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LDP_SYNC
, 0, 0, -1, NULL
, 0);
2051 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LDP_SYNC
, ¶ms
));
2055 ldp_vty_show_atom_binding(struct vty
*vty
, const char *peer
,
2056 unsigned long local_label
, unsigned long remote_label
, const char *json
)
2058 struct imsgbuf ibuf
;
2059 struct show_params params
;
2061 if (ldp_vty_connect(&ibuf
) < 0)
2062 return (CMD_WARNING
);
2064 memset(¶ms
, 0, sizeof(params
));
2065 params
.json
= (json
) ? 1 : 0;
2067 (inet_pton(AF_INET
, peer
, ¶ms
.l2vpn
.peer
) != 1 ||
2068 bad_addr_v4(params
.l2vpn
.peer
))) {
2069 vty_out (vty
, "%% Malformed address\n");
2070 return (CMD_SUCCESS
);
2072 params
.l2vpn
.local_label
= local_label
;
2073 params
.l2vpn
.remote_label
= remote_label
;
2075 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_BINDING
, 0, 0, -1, NULL
, 0);
2076 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_BINDING
, ¶ms
));
2080 ldp_vty_show_atom_vc(struct vty
*vty
, const char *peer
, const char *ifname
,
2081 const char *vcid
, const char *json
)
2083 struct imsgbuf ibuf
;
2084 struct show_params params
;
2086 if (ldp_vty_connect(&ibuf
) < 0)
2087 return (CMD_WARNING
);
2089 memset(¶ms
, 0, sizeof(params
));
2090 params
.json
= (json
) ? 1 : 0;
2092 (inet_pton(AF_INET
, peer
, ¶ms
.l2vpn
.peer
) != 1 ||
2093 bad_addr_v4(params
.l2vpn
.peer
))) {
2094 vty_out (vty
, "%% Malformed address\n");
2095 return (CMD_SUCCESS
);
2098 strlcpy(params
.l2vpn
.ifname
, ifname
,
2099 sizeof(params
.l2vpn
.ifname
));
2101 params
.l2vpn
.vcid
= atoi(vcid
);
2105 vty_out (vty
, "%-9s %-15s %-10s %-16s %-10s\n",
2106 "Interface", "Peer ID", "VC ID", "Name","Status");
2107 vty_out (vty
, "%-9s %-15s %-10s %-16s %-10s\n",
2108 "---------", "---------------", "----------",
2109 "----------------", "----------");
2112 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_PW
, 0, 0, -1, NULL
, 0);
2113 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_PW
, ¶ms
));
2117 ldp_vty_clear_nbr(struct vty
*vty
, const char *addr_str
)
2119 struct imsgbuf ibuf
;
2122 memset(&nbr
, 0, sizeof(nbr
));
2124 (ldp_get_address(addr_str
, &nbr
.af
, &nbr
.raddr
) == -1 ||
2125 bad_addr(nbr
.af
, &nbr
.raddr
))) {
2126 vty_out (vty
, "%% Malformed address\n");
2127 return (CMD_WARNING
);
2130 if (ldp_vty_connect(&ibuf
) < 0)
2131 return (CMD_WARNING
);
2133 imsg_compose(&ibuf
, IMSG_CTL_CLEAR_NBR
, 0, 0, -1, &nbr
, sizeof(nbr
));
2135 while (ibuf
.w
.queued
)
2136 if (msgbuf_write(&ibuf
.w
) <= 0 && errno
!= EAGAIN
) {
2137 log_warn("write error");
2139 return (CMD_WARNING
);
2144 return (CMD_SUCCESS
);