2 * Copyright (C) 2016 by Open Source Routing.
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
54 #define LDPBUFSIZ 65535
56 static int show_interface_msg(struct vty
*, struct imsg
*,
57 struct show_params
*);
58 static int show_interface_msg_json(struct imsg
*,
59 struct show_params
*, json_object
*);
60 static int show_discovery_msg(struct vty
*, struct imsg
*,
61 struct show_params
*);
62 static void show_discovery_detail_adj(struct vty
*, char *,
64 static int show_discovery_detail_msg(struct vty
*, struct imsg
*,
65 struct show_params
*);
66 static int show_discovery_msg_json(struct imsg
*,
67 struct show_params
*, json_object
*);
68 static void show_discovery_detail_adj_json(json_object
*,
70 static int show_discovery_detail_msg_json(struct imsg
*,
71 struct show_params
*, json_object
*);
73 static int show_nbr_msg(struct vty
*, struct imsg
*,
74 struct show_params
*);
75 static int show_nbr_msg_json(struct imsg
*, struct show_params
*,
77 static void show_nbr_detail_adj(struct vty
*, char *,
79 static int show_nbr_detail_msg(struct vty
*, struct imsg
*,
80 struct show_params
*);
81 static void show_nbr_detail_adj_json(struct ctl_adj
*,
83 static int show_nbr_detail_msg_json(struct imsg
*,
84 struct show_params
*, json_object
*);
85 static void show_nbr_capabilities(struct vty
*, struct ctl_nbr
*);
86 static int show_nbr_capabilities_msg(struct vty
*, struct imsg
*,
87 struct show_params
*);
88 static void show_nbr_capabilities_json(struct ctl_nbr
*,
90 static int show_nbr_capabilities_msg_json(struct imsg
*,
91 struct show_params
*, json_object
*);
92 static int show_lib_msg(struct vty
*, struct imsg
*,
93 struct show_params
*);
94 static int show_lib_detail_msg(struct vty
*, struct imsg
*,
95 struct show_params
*);
96 static int show_lib_msg_json(struct imsg
*, struct show_params
*,
98 static int show_lib_detail_msg_json(struct imsg
*,
99 struct show_params
*, json_object
*);
100 static int show_l2vpn_binding_msg(struct vty
*, struct imsg
*,
101 struct show_params
*);
102 static int show_l2vpn_binding_msg_json(struct imsg
*,
103 struct show_params
*, json_object
*);
104 static int show_l2vpn_pw_msg(struct vty
*, struct imsg
*,
105 struct show_params
*);
106 static int show_l2vpn_pw_msg_json(struct imsg
*,
107 struct show_params
*, json_object
*);
108 static int ldp_vty_connect(struct imsgbuf
*);
109 static int ldp_vty_dispatch_msg(struct vty
*, struct imsg
*,
110 enum show_command
, struct show_params
*,
112 static int ldp_vty_dispatch(struct vty
*, struct imsgbuf
*,
113 enum show_command
, struct show_params
*);
114 static int ldp_vty_get_af(const char *, int *);
117 show_interface_msg(struct vty
*vty
, struct imsg
*imsg
,
118 struct show_params
*params
)
120 struct ctl_iface
*iface
;
123 switch (imsg
->hdr
.type
) {
124 case IMSG_CTL_SHOW_INTERFACE
:
127 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
130 snprintf(timers
, sizeof(timers
), "%u/%u",
131 iface
->hello_interval
, iface
->hello_holdtime
);
133 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3u%s",
134 af_name(iface
->af
), iface
->name
,
135 if_state_name(iface
->state
), iface
->uptime
== 0 ?
136 "00:00:00" : log_time(iface
->uptime
), timers
,
137 iface
->adj_cnt
, VTY_NEWLINE
);
140 vty_out(vty
, "%s", VTY_NEWLINE
);
150 show_interface_msg_json(struct imsg
*imsg
, struct show_params
*params
,
153 struct ctl_iface
*iface
;
154 json_object
*json_iface
;
157 switch (imsg
->hdr
.type
) {
158 case IMSG_CTL_SHOW_INTERFACE
:
161 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
164 json_iface
= json_object_new_object();
165 json_object_string_add(json_iface
, "name", iface
->name
);
166 json_object_string_add(json_iface
, "addressFamily",
168 json_object_string_add(json_iface
, "state",
169 if_state_name(iface
->state
));
170 json_object_string_add(json_iface
, "upTime",
171 log_time(iface
->uptime
));
172 json_object_int_add(json_iface
, "helloInterval",
173 iface
->hello_interval
);
174 json_object_int_add(json_iface
, "helloHoldtime",
175 iface
->hello_holdtime
);
176 json_object_int_add(json_iface
, "adjacencyCount",
179 sprintf(key_name
, "%s: %s", iface
->name
, af_name(iface
->af
));
180 json_object_object_add(json
, key_name
, json_iface
);
192 show_discovery_msg(struct vty
*vty
, struct imsg
*imsg
,
193 struct show_params
*params
)
198 switch (imsg
->hdr
.type
) {
199 case IMSG_CTL_SHOW_DISCOVERY
:
202 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
205 vty_out(vty
, "%-4s %-15s ", af_name(adj
->af
),
209 vty_out(vty
, "%-8s %-15s ", "Link", adj
->ifname
);
212 addr
= log_addr(adj
->af
, &adj
->src_addr
);
214 vty_out(vty
, "%-8s %-15s ", "Targeted", addr
);
215 if (strlen(addr
) > 15)
216 vty_out(vty
, "%s%46s", VTY_NEWLINE
, " ");
219 vty_out(vty
, "%9u%s", adj
->holdtime
, VTY_NEWLINE
);
222 vty_out(vty
, "%s", VTY_NEWLINE
);
232 show_discovery_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
234 size_t buflen
= strlen(buffer
);
236 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
237 " LSR Id: %s:0%s", inet_ntoa(adj
->id
), VTY_NEWLINE
);
238 buflen
= strlen(buffer
);
239 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
240 " Source address: %s%s",
241 log_addr(adj
->af
, &adj
->src_addr
), VTY_NEWLINE
);
242 buflen
= strlen(buffer
);
243 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
244 " Transport address: %s%s",
245 log_addr(adj
->af
, &adj
->trans_addr
), VTY_NEWLINE
);
246 buflen
= strlen(buffer
);
247 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
248 " Hello hold time: %u secs (due in %u secs)%s",
249 adj
->holdtime
, adj
->holdtime_remaining
, VTY_NEWLINE
);
250 buflen
= strlen(buffer
);
251 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
252 " Dual-stack capability TLV: %s%s",
253 (adj
->ds_tlv
) ? "yes" : "no", VTY_NEWLINE
);
257 show_discovery_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
258 struct show_params
*params
)
261 struct ctl_disc_if
*iface
;
262 struct ctl_disc_tnbr
*tnbr
;
263 struct in_addr rtr_id
;
264 union ldpd_addr
*trans_addr
;
266 static char ifaces_buffer
[LDPBUFSIZ
];
267 static char tnbrs_buffer
[LDPBUFSIZ
];
269 switch (imsg
->hdr
.type
) {
270 case IMSG_CTL_SHOW_DISCOVERY
:
271 ifaces_buffer
[0] = '\0';
272 tnbrs_buffer
[0] = '\0';
274 case IMSG_CTL_SHOW_DISC_IFACE
:
277 if (params
->family
!= AF_UNSPEC
&&
278 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
279 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
282 buflen
= strlen(ifaces_buffer
);
283 snprintf(ifaces_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
284 " %s: %s%s", iface
->name
, (iface
->no_adj
) ?
285 "(no adjacencies)" : "", VTY_NEWLINE
);
287 case IMSG_CTL_SHOW_DISC_TNBR
:
290 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
293 trans_addr
= &(ldp_af_conf_get(ldpd_conf
,
294 tnbr
->af
))->trans_addr
;
295 buflen
= strlen(tnbrs_buffer
);
296 snprintf(tnbrs_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
297 " %s -> %s: %s%s", log_addr(tnbr
->af
, trans_addr
),
298 log_addr(tnbr
->af
, &tnbr
->addr
), (tnbr
->no_adj
) ?
299 "(no adjacencies)" : "", VTY_NEWLINE
);
301 case IMSG_CTL_SHOW_DISC_ADJ
:
304 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
309 show_discovery_detail_adj(vty
, ifaces_buffer
, adj
);
312 show_discovery_detail_adj(vty
, tnbrs_buffer
, adj
);
317 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
318 vty_out(vty
, "Local:%s", VTY_NEWLINE
);
319 vty_out(vty
, " LSR Id: %s:0%s", inet_ntoa(rtr_id
),
321 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
322 vty_out(vty
, " Transport Address (IPv4): %s%s",
323 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
),
325 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
326 vty_out(vty
, " Transport Address (IPv6): %s%s",
327 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
),
329 vty_out(vty
, "Discovery Sources:%s", VTY_NEWLINE
);
330 vty_out(vty
, " Interfaces:%s", VTY_NEWLINE
);
331 vty_out(vty
, "%s", ifaces_buffer
);
332 vty_out(vty
, " Targeted Hellos:%s", VTY_NEWLINE
);
333 vty_out(vty
, "%s", tnbrs_buffer
);
334 vty_out(vty
, "%s", VTY_NEWLINE
);
344 show_discovery_msg_json(struct imsg
*imsg
, struct show_params
*params
,
348 json_object
*json_array
;
349 json_object
*json_adj
;
351 switch (imsg
->hdr
.type
) {
352 case IMSG_CTL_SHOW_DISCOVERY
:
355 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
358 json_object_object_get_ex(json
, "adjacencies", &json_array
);
360 json_array
= json_object_new_array();
361 json_object_object_add(json
, "adjacencies", json_array
);
364 json_adj
= json_object_new_object();
365 json_object_string_add(json_adj
, "addressFamily",
367 json_object_string_add(json_adj
, "neighborId",
371 json_object_string_add(json_adj
, "type", "link");
372 json_object_string_add(json_adj
, "interface",
376 json_object_string_add(json_adj
, "type", "targeted");
377 json_object_string_add(json_adj
, "peer",
378 log_addr(adj
->af
, &adj
->src_addr
));
381 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
383 json_object_array_add(json_array
, json_adj
);
395 show_discovery_detail_adj_json(json_object
*json
, struct ctl_adj
*adj
)
397 json_object
*json_adj
;
398 json_object
*json_array
;
400 json_object_object_get_ex(json
, "adjacencies", &json_array
);
402 json_array
= json_object_new_array();
403 json_object_object_add(json
, "adjacencies", json_array
);
406 json_adj
= json_object_new_object();
407 json_object_string_add(json_adj
, "lsrId", inet_ntoa(adj
->id
));
408 json_object_string_add(json_adj
, "sourceAddress", log_addr(adj
->af
,
410 json_object_string_add(json_adj
, "transportAddress", log_addr(adj
->af
,
412 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
413 json_object_int_add(json_adj
, "helloHoldtimeRemaining",
414 adj
->holdtime_remaining
);
415 json_object_int_add(json_adj
, "dualStackCapabilityTlv",
417 json_object_array_add(json_array
, json_adj
);
421 show_discovery_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
425 struct ctl_disc_if
*iface
;
426 struct ctl_disc_tnbr
*tnbr
;
427 struct in_addr rtr_id
;
428 union ldpd_addr
*trans_addr
;
429 json_object
*json_interface
;
430 json_object
*json_target
;
431 static json_object
*json_interfaces
;
432 static json_object
*json_targets
;
433 static json_object
*json_container
;
435 switch (imsg
->hdr
.type
) {
436 case IMSG_CTL_SHOW_DISCOVERY
:
437 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
438 json_object_string_add(json
, "lsrId", inet_ntoa(rtr_id
));
439 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
440 json_object_string_add(json
, "transportAddressIPv4",
441 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
442 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
443 json_object_string_add(json
, "transportAddressIPv6",
444 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
445 json_interfaces
= json_object_new_object();
446 json_object_object_add(json
, "interfaces", json_interfaces
);
447 json_targets
= json_object_new_object();
448 json_object_object_add(json
, "targetedHellos", json_targets
);
449 json_container
= NULL
;
451 case IMSG_CTL_SHOW_DISC_IFACE
:
454 if (params
->family
!= AF_UNSPEC
&&
455 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
456 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
459 json_interface
= json_object_new_object();
460 json_object_object_add(json_interfaces
, iface
->name
,
462 json_container
= json_interface
;
464 case IMSG_CTL_SHOW_DISC_TNBR
:
467 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
470 trans_addr
= &(ldp_af_conf_get(ldpd_conf
, tnbr
->af
))->trans_addr
;
472 json_target
= json_object_new_object();
473 json_object_string_add(json_target
, "sourceAddress",
474 log_addr(tnbr
->af
, trans_addr
));
475 json_object_object_add(json_targets
, log_addr(tnbr
->af
,
476 &tnbr
->addr
), json_target
);
477 json_container
= json_target
;
479 case IMSG_CTL_SHOW_DISC_ADJ
:
482 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
487 show_discovery_detail_adj_json(json_container
, adj
);
490 show_discovery_detail_adj_json(json_container
, adj
);
504 show_nbr_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
509 switch (imsg
->hdr
.type
) {
510 case IMSG_CTL_SHOW_NBR
:
513 addr
= log_addr(nbr
->af
, &nbr
->raddr
);
515 vty_out(vty
, "%-4s %-15s %-11s %-15s",
516 af_name(nbr
->af
), inet_ntoa(nbr
->id
),
517 nbr_state_name(nbr
->nbr_state
), addr
);
518 if (strlen(addr
) > 15)
519 vty_out(vty
, "%s%48s", VTY_NEWLINE
, " ");
520 vty_out(vty
, " %8s%s", nbr
->uptime
== 0 ? "-" :
521 log_time(nbr
->uptime
), VTY_NEWLINE
);
533 show_nbr_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
535 size_t buflen
= strlen(buffer
);
539 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
540 " Interface: %s%s", adj
->ifname
, VTY_NEWLINE
);
543 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
544 " Targeted Hello: %s%s", log_addr(adj
->af
,
545 &adj
->src_addr
), VTY_NEWLINE
);
551 show_nbr_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
552 struct show_params
*params
)
555 struct ldp_stats
*stats
;
557 static char v4adjs_buffer
[LDPBUFSIZ
];
558 static char v6adjs_buffer
[LDPBUFSIZ
];
560 switch (imsg
->hdr
.type
) {
561 case IMSG_CTL_SHOW_NBR
:
564 v4adjs_buffer
[0] = '\0';
565 v6adjs_buffer
[0] = '\0';
566 vty_out(vty
, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr
->id
),
568 vty_out(vty
, " TCP connection: %s:%u - %s:%u%s",
569 log_addr(nbr
->af
, &nbr
->laddr
), ntohs(nbr
->lport
),
570 log_addr(nbr
->af
, &nbr
->raddr
), ntohs(nbr
->rport
),
572 vty_out(vty
, " Authentication: %s%s",
573 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
574 "none", VTY_NEWLINE
);
575 vty_out(vty
, " Session Holdtime: %u secs; "
576 "KeepAlive interval: %u secs%s", nbr
->holdtime
,
577 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
, VTY_NEWLINE
);
578 vty_out(vty
, " State: %s; Downstream-Unsolicited%s",
579 nbr_state_name(nbr
->nbr_state
), VTY_NEWLINE
);
580 vty_out(vty
, " Up time: %s%s", log_time(nbr
->uptime
),
584 vty_out(vty
, " Messages sent/rcvd:%s", VTY_NEWLINE
);
585 vty_out(vty
, " - Keepalive Messages: %u/%u%s",
586 stats
->kalive_sent
, stats
->kalive_rcvd
, VTY_NEWLINE
);
587 vty_out(vty
, " - Address Messages: %u/%u%s",
588 stats
->addr_sent
, stats
->addr_rcvd
, VTY_NEWLINE
);
589 vty_out(vty
, " - Address Withdraw Messages: %u/%u%s",
590 stats
->addrwdraw_sent
, stats
->addrwdraw_rcvd
, VTY_NEWLINE
);
591 vty_out(vty
, " - Notification Messages: %u/%u%s",
592 stats
->notif_sent
, stats
->notif_rcvd
, VTY_NEWLINE
);
593 vty_out(vty
, " - Capability Messages: %u/%u%s",
594 stats
->capability_sent
, stats
->capability_rcvd
, VTY_NEWLINE
);
595 vty_out(vty
, " - Label Mapping Messages: %u/%u%s",
596 stats
->labelmap_sent
, stats
->labelmap_rcvd
, VTY_NEWLINE
);
597 vty_out(vty
, " - Label Request Messages: %u/%u%s",
598 stats
->labelreq_sent
, stats
->labelreq_rcvd
, VTY_NEWLINE
);
599 vty_out(vty
, " - Label Withdraw Messages: %u/%u%s",
600 stats
->labelwdraw_sent
, stats
->labelwdraw_rcvd
, VTY_NEWLINE
);
601 vty_out(vty
, " - Label Release Messages: %u/%u%s",
602 stats
->labelrel_sent
, stats
->labelrel_rcvd
, VTY_NEWLINE
);
603 vty_out(vty
, " - Label Abort Request Messages: %u/%u%s",
604 stats
->labelabreq_sent
, stats
->labelabreq_rcvd
, VTY_NEWLINE
);
606 show_nbr_capabilities(vty
, nbr
);
608 case IMSG_CTL_SHOW_NBR_DISC
:
613 show_nbr_detail_adj(vty
, v4adjs_buffer
, adj
);
616 show_nbr_detail_adj(vty
, v6adjs_buffer
, adj
);
619 fatalx("show_nbr_detail_msg: unknown af");
622 case IMSG_CTL_SHOW_NBR_END
:
623 vty_out(vty
, " LDP Discovery Sources:%s", VTY_NEWLINE
);
624 if (v4adjs_buffer
[0] != '\0') {
625 vty_out(vty
, " IPv4:%s", VTY_NEWLINE
);
626 vty_out(vty
, "%s", v4adjs_buffer
);
628 if (v6adjs_buffer
[0] != '\0') {
629 vty_out(vty
, " IPv6:%s", VTY_NEWLINE
);
630 vty_out(vty
, "%s", v6adjs_buffer
);
632 vty_out(vty
, "%s", VTY_NEWLINE
);
644 show_nbr_msg_json(struct imsg
*imsg
, struct show_params
*params
,
648 json_object
*json_array
;
649 json_object
*json_nbr
;
651 switch (imsg
->hdr
.type
) {
652 case IMSG_CTL_SHOW_NBR
:
655 json_object_object_get_ex(json
, "neighbors", &json_array
);
657 json_array
= json_object_new_array();
658 json_object_object_add(json
, "neighbors", json_array
);
661 json_nbr
= json_object_new_object();
662 json_object_string_add(json_nbr
, "addressFamily",
664 json_object_string_add(json_nbr
, "neighborId",
666 json_object_string_add(json_nbr
, "state",
667 nbr_state_name(nbr
->nbr_state
));
668 json_object_string_add(json_nbr
, "transportAddress",
669 log_addr(nbr
->af
, &nbr
->raddr
));
670 json_object_string_add(json_nbr
, "upTime",
671 log_time(nbr
->uptime
));
673 json_object_array_add(json_array
, json_nbr
);
685 show_nbr_detail_adj_json(struct ctl_adj
*adj
, json_object
*adj_list
)
687 char adj_string
[128];
691 strlcpy(adj_string
, "interface: ", sizeof(adj_string
));
692 strlcat(adj_string
, adj
->ifname
, sizeof(adj_string
));
695 strlcpy(adj_string
, "targetedHello: ", sizeof(adj_string
));
696 strlcat(adj_string
, log_addr(adj
->af
, &adj
->src_addr
),
701 json_object_array_add(adj_list
, json_object_new_string(adj_string
));
705 show_nbr_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
709 struct ldp_stats
*stats
;
711 json_object
*json_nbr
;
712 json_object
*json_array
;
713 json_object
*json_counter
;
714 static json_object
*json_nbr_sources
;
715 static json_object
*json_v4adjs
;
716 static json_object
*json_v6adjs
;
718 switch (imsg
->hdr
.type
) {
719 case IMSG_CTL_SHOW_NBR
:
722 json_nbr
= json_object_new_object();
723 json_object_object_add(json
, inet_ntoa(nbr
->id
), json_nbr
);
725 json_object_string_add(json_nbr
, "peerId", inet_ntoa(nbr
->id
));
726 json_object_string_add(json_nbr
, "tcpLocalAddress",
727 log_addr(nbr
->af
, &nbr
->laddr
));
728 json_object_int_add(json_nbr
, "tcpLocalPort",
730 json_object_string_add(json_nbr
, "tcpRemoteAddress",
731 log_addr(nbr
->af
, &nbr
->raddr
));
732 json_object_int_add(json_nbr
, "tcpRemotePort",
734 json_object_string_add(json_nbr
, "authentication",
735 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
737 json_object_int_add(json_nbr
, "sessionHoldtime", nbr
->holdtime
);
738 json_object_int_add(json_nbr
, "keepAliveInterval",
739 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
740 json_object_string_add(json_nbr
, "state",
741 nbr_state_name(nbr
->nbr_state
));
742 json_object_string_add(json_nbr
, "upTime",
743 log_time(nbr
->uptime
));
745 /* message_counters */
747 json_array
= json_object_new_array();
748 json_object_object_add(json_nbr
, "sentMessages", json_array
);
749 json_counter
= json_object_new_object();
750 json_object_int_add(json_counter
, "keepalive",
752 json_object_array_add(json_array
, json_counter
);
753 json_counter
= json_object_new_object();
754 json_object_int_add(json_counter
, "address",
756 json_object_array_add(json_array
, json_counter
);
757 json_counter
= json_object_new_object();
758 json_object_int_add(json_counter
, "addressWithdraw",
759 stats
->addrwdraw_sent
);
760 json_object_array_add(json_array
, json_counter
);
761 json_counter
= json_object_new_object();
762 json_object_int_add(json_counter
, "notification",
764 json_object_array_add(json_array
, json_counter
);
765 json_counter
= json_object_new_object();
766 json_object_int_add(json_counter
, "capability",
767 stats
->capability_sent
);
768 json_object_array_add(json_array
, json_counter
);
769 json_counter
= json_object_new_object();
770 json_object_int_add(json_counter
, "labelMapping",
771 stats
->labelmap_sent
);
772 json_object_array_add(json_array
, json_counter
);
773 json_counter
= json_object_new_object();
774 json_object_int_add(json_counter
, "labelRequest",
775 stats
->labelreq_sent
);
776 json_object_array_add(json_array
, json_counter
);
777 json_counter
= json_object_new_object();
778 json_object_int_add(json_counter
, "labelWithdraw",
779 stats
->labelwdraw_sent
);
780 json_object_array_add(json_array
, json_counter
);
781 json_counter
= json_object_new_object();
782 json_object_int_add(json_counter
, "labelRelease",
783 stats
->labelrel_sent
);
784 json_object_array_add(json_array
, json_counter
);
785 json_counter
= json_object_new_object();
786 json_object_int_add(json_counter
, "labelAbortRequest",
787 stats
->labelabreq_sent
);
788 json_object_array_add(json_array
, json_counter
);
790 json_array
= json_object_new_array();
791 json_object_object_add(json_nbr
, "receivedMessages", json_array
);
792 json_counter
= json_object_new_object();
793 json_object_int_add(json_counter
, "keepalive",
795 json_object_array_add(json_array
, json_counter
);
796 json_counter
= json_object_new_object();
797 json_object_int_add(json_counter
, "address",
799 json_object_array_add(json_array
, json_counter
);
800 json_counter
= json_object_new_object();
801 json_object_int_add(json_counter
, "addressWithdraw",
802 stats
->addrwdraw_rcvd
);
803 json_object_array_add(json_array
, json_counter
);
804 json_counter
= json_object_new_object();
805 json_object_int_add(json_counter
, "notification",
807 json_object_array_add(json_array
, json_counter
);
808 json_counter
= json_object_new_object();
809 json_object_int_add(json_counter
, "capability",
810 stats
->capability_rcvd
);
811 json_object_array_add(json_array
, json_counter
);
812 json_counter
= json_object_new_object();
813 json_object_int_add(json_counter
, "labelMapping",
814 stats
->labelmap_rcvd
);
815 json_object_array_add(json_array
, json_counter
);
816 json_counter
= json_object_new_object();
817 json_object_int_add(json_counter
, "labelRequest",
818 stats
->labelreq_rcvd
);
819 json_object_array_add(json_array
, json_counter
);
820 json_counter
= json_object_new_object();
821 json_object_int_add(json_counter
, "labelWithdraw",
822 stats
->labelwdraw_rcvd
);
823 json_object_array_add(json_array
, json_counter
);
824 json_counter
= json_object_new_object();
825 json_object_int_add(json_counter
, "labelRelease",
826 stats
->labelrel_rcvd
);
827 json_object_array_add(json_array
, json_counter
);
828 json_counter
= json_object_new_object();
829 json_object_int_add(json_counter
, "labelAbortRequest",
830 stats
->labelabreq_rcvd
);
831 json_object_array_add(json_array
, json_counter
);
834 show_nbr_capabilities_json(nbr
, json_nbr
);
836 /* discovery sources */
837 json_nbr_sources
= json_object_new_object();
838 json_object_object_add(json_nbr
, "discoverySources",
843 case IMSG_CTL_SHOW_NBR_DISC
:
849 json_v4adjs
= json_object_new_array();
850 json_object_object_add(json_nbr_sources
, "ipv4",
853 show_nbr_detail_adj_json(adj
, json_v4adjs
);
857 json_v6adjs
= json_object_new_array();
858 json_object_object_add(json_nbr_sources
, "ipv6",
861 show_nbr_detail_adj_json(adj
, json_v6adjs
);
864 fatalx("show_nbr_detail_msg_json: unknown af");
867 case IMSG_CTL_SHOW_NBR_END
:
879 show_nbr_capabilities(struct vty
*vty
, struct ctl_nbr
*nbr
)
881 vty_out(vty
, " Capabilities Sent:%s"
882 " - Dynamic Announcement (0x0506)%s"
883 " - Typed Wildcard (0x050B)%s"
884 " - Unrecognized Notification (0x0603)%s",
885 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
886 vty_out(vty
, " Capabilities Received:%s", VTY_NEWLINE
);
887 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
)
888 vty_out(vty
, " - Dynamic Announcement (0x0506)%s",
890 if (nbr
->flags
& F_NBR_CAP_TWCARD
)
891 vty_out(vty
, " - Typed Wildcard (0x050B)%s", VTY_NEWLINE
);
892 if (nbr
->flags
& F_NBR_CAP_UNOTIF
)
893 vty_out(vty
, " - Unrecognized Notification (0x0603)%s",
898 show_nbr_capabilities_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
902 switch (imsg
->hdr
.type
) {
903 case IMSG_CTL_SHOW_NBR
:
906 if (nbr
->nbr_state
!= NBR_STA_OPER
)
909 vty_out(vty
, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr
->id
),
911 show_nbr_capabilities(vty
, nbr
);
914 vty_out(vty
, "%s", VTY_NEWLINE
);
924 show_nbr_capabilities_json(struct ctl_nbr
*nbr
, json_object
*json_nbr
)
926 json_object
*json_array
;
927 json_object
*json_cap
;
929 /* sent capabilities */
930 json_array
= json_object_new_array();
931 json_object_object_add(json_nbr
, "sentCapabilities", json_array
);
933 /* Dynamic Announcement (0x0506) */
934 json_cap
= json_object_new_object();
935 json_object_string_add(json_cap
, "description", "Dynamic Announcement");
936 json_object_string_add(json_cap
, "tlvType", "0x0506");
937 json_object_array_add(json_array
, json_cap
);
939 /* Typed Wildcard (0x050B) */
940 json_cap
= json_object_new_object();
941 json_object_string_add(json_cap
, "description", "Typed Wildcard");
942 json_object_string_add(json_cap
, "tlvType", "0x050B");
943 json_object_array_add(json_array
, json_cap
);
945 /* Unrecognized Notification (0x0603) */
946 json_cap
= json_object_new_object();
947 json_object_string_add(json_cap
, "description",
948 "Unrecognized Notification");
949 json_object_string_add(json_cap
, "tlvType", "0x0603");
950 json_object_array_add(json_array
, json_cap
);
952 /* received capabilities */
953 json_array
= json_object_new_array();
954 json_object_object_add(json_nbr
, "receivedCapabilities", json_array
);
956 /* Dynamic Announcement (0x0506) */
957 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
) {
958 json_cap
= json_object_new_object();
959 json_object_string_add(json_cap
, "description",
960 "Dynamic Announcement");
961 json_object_string_add(json_cap
, "tlvType", "0x0506");
962 json_object_array_add(json_array
, json_cap
);
965 /* Typed Wildcard (0x050B) */
966 if (nbr
->flags
& F_NBR_CAP_TWCARD
) {
967 json_cap
= json_object_new_object();
968 json_object_string_add(json_cap
, "description",
970 json_object_string_add(json_cap
, "tlvType", "0x050B");
971 json_object_array_add(json_array
, json_cap
);
974 /* Unrecognized Notification (0x0603) */
975 if (nbr
->flags
& F_NBR_CAP_UNOTIF
) {
976 json_cap
= json_object_new_object();
977 json_object_string_add(json_cap
, "description",
978 "Unrecognized Notification");
979 json_object_string_add(json_cap
, "tlvType", "0x0603");
980 json_object_array_add(json_array
, json_cap
);
985 show_nbr_capabilities_msg_json(struct imsg
*imsg
, struct show_params
*params
,
989 json_object
*json_nbr
;
991 switch (imsg
->hdr
.type
) {
992 case IMSG_CTL_SHOW_NBR
:
995 if (nbr
->nbr_state
!= NBR_STA_OPER
)
998 json_nbr
= json_object_new_object();
999 json_object_object_add(json
, inet_ntoa(nbr
->id
), json_nbr
);
1000 show_nbr_capabilities_json(nbr
, json_nbr
);
1012 show_lib_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1015 char dstnet
[BUFSIZ
];
1017 switch (imsg
->hdr
.type
) {
1018 case IMSG_CTL_SHOW_LIB_BEGIN
:
1019 case IMSG_CTL_SHOW_LIB_RCVD
:
1022 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1026 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1029 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1030 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1032 vty_out(vty
, "%-4s %-20s", af_name(rt
->af
), dstnet
);
1033 if (strlen(dstnet
) > 20)
1034 vty_out(vty
, "%s%25s", VTY_NEWLINE
, " ");
1035 vty_out(vty
, " %-15s %-11s %-13s %6s%s", inet_ntoa(rt
->nexthop
),
1036 log_label(rt
->local_label
), log_label(rt
->remote_label
),
1037 rt
->in_use
? "yes" : "no", VTY_NEWLINE
);
1040 vty_out(vty
, "%s", VTY_NEWLINE
);
1050 show_lib_detail_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1053 char dstnet
[BUFSIZ
];
1054 static int upstream
, downstream
;
1056 static char sent_buffer
[LDPBUFSIZ
];
1057 static char rcvd_buffer
[LDPBUFSIZ
];
1059 switch (imsg
->hdr
.type
) {
1060 case IMSG_CTL_SHOW_LIB_BEGIN
:
1061 case IMSG_CTL_SHOW_LIB_SENT
:
1062 case IMSG_CTL_SHOW_LIB_RCVD
:
1063 case IMSG_CTL_SHOW_LIB_END
:
1065 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1072 switch (imsg
->hdr
.type
) {
1073 case IMSG_CTL_SHOW_LIB_BEGIN
:
1076 sent_buffer
[0] = '\0';
1077 rcvd_buffer
[0] = '\0';
1079 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1080 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1082 vty_out(vty
, "%s%s", dstnet
, VTY_NEWLINE
);
1083 vty_out(vty
, "%-8sLocal binding: label: %s%s", "",
1084 log_label(rt
->local_label
), VTY_NEWLINE
);
1086 case IMSG_CTL_SHOW_LIB_SENT
:
1088 buflen
= strlen(sent_buffer
);
1089 snprintf(sent_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1090 "%12s%s:0%s", "", inet_ntoa(rt
->nexthop
), VTY_NEWLINE
);
1092 case IMSG_CTL_SHOW_LIB_RCVD
:
1094 buflen
= strlen(rcvd_buffer
);
1095 snprintf(rcvd_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1096 "%12s%s:0, label %s%s%s", "", inet_ntoa(rt
->nexthop
),
1097 log_label(rt
->remote_label
),
1098 rt
->in_use
? " (in use)" : "", VTY_NEWLINE
);
1100 case IMSG_CTL_SHOW_LIB_END
:
1102 vty_out(vty
, "%-8sAdvertised to:%s", "", VTY_NEWLINE
);
1103 vty_out(vty
, "%s", sent_buffer
);
1106 vty_out(vty
, "%-8sRemote bindings:%s", "", VTY_NEWLINE
);
1107 vty_out(vty
, "%s", rcvd_buffer
);
1109 vty_out(vty
, "%-8sNo remote bindings%s", "",
1113 vty_out(vty
, "%s", VTY_NEWLINE
);
1123 show_lib_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1127 json_object
*json_array
;
1128 json_object
*json_lib_entry
;
1129 char dstnet
[BUFSIZ
];
1131 switch (imsg
->hdr
.type
) {
1132 case IMSG_CTL_SHOW_LIB_BEGIN
:
1133 case IMSG_CTL_SHOW_LIB_RCVD
:
1136 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1140 json_object_object_get_ex(json
, "bindings", &json_array
);
1142 json_array
= json_object_new_array();
1143 json_object_object_add(json
, "bindings", json_array
);
1146 json_lib_entry
= json_object_new_object();
1147 json_object_string_add(json_lib_entry
, "addressFamily",
1149 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1150 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1151 json_object_string_add(json_lib_entry
, "prefix", dstnet
);
1152 json_object_string_add(json_lib_entry
, "neighborId",
1153 inet_ntoa(rt
->nexthop
));
1154 json_object_string_add(json_lib_entry
, "localLabel",
1155 log_label(rt
->local_label
));
1156 json_object_string_add(json_lib_entry
, "remoteLabel",
1157 log_label(rt
->remote_label
));
1158 json_object_int_add(json_lib_entry
, "inUse", rt
->in_use
);
1160 json_object_array_add(json_array
, json_lib_entry
);
1172 show_lib_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1176 char dstnet
[BUFSIZ
];
1177 static json_object
*json_lib_entry
;
1178 static json_object
*json_adv_labels
;
1179 json_object
*json_adv_label
;
1180 static json_object
*json_remote_labels
;
1181 json_object
*json_remote_label
;
1183 switch (imsg
->hdr
.type
) {
1184 case IMSG_CTL_SHOW_LIB_BEGIN
:
1185 case IMSG_CTL_SHOW_LIB_SENT
:
1186 case IMSG_CTL_SHOW_LIB_RCVD
:
1187 case IMSG_CTL_SHOW_LIB_END
:
1189 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1196 switch (imsg
->hdr
.type
) {
1197 case IMSG_CTL_SHOW_LIB_BEGIN
:
1198 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1199 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1201 json_lib_entry
= json_object_new_object();
1202 json_object_string_add(json_lib_entry
, "localLabel",
1203 log_label(rt
->local_label
));
1205 json_adv_labels
= json_object_new_array();
1206 json_object_object_add(json_lib_entry
, "advertisedTo",
1209 json_remote_labels
= json_object_new_array();
1210 json_object_object_add(json_lib_entry
, "remoteLabels",
1211 json_remote_labels
);
1213 json_object_object_add(json
, dstnet
, json_lib_entry
);
1215 case IMSG_CTL_SHOW_LIB_SENT
:
1216 json_adv_label
= json_object_new_object();
1217 json_object_string_add(json_adv_label
, "neighborId",
1218 inet_ntoa(rt
->nexthop
));
1219 json_object_array_add(json_adv_labels
, json_adv_label
);
1221 case IMSG_CTL_SHOW_LIB_RCVD
:
1222 json_remote_label
= json_object_new_object();
1223 json_object_string_add(json_remote_label
, "neighborId",
1224 inet_ntoa(rt
->nexthop
));
1225 json_object_string_add(json_remote_label
, "label",
1226 log_label(rt
->remote_label
));
1227 json_object_int_add(json_remote_label
, "inUse", rt
->in_use
);
1228 json_object_array_add(json_remote_labels
, json_remote_label
);
1240 show_l2vpn_binding_msg(struct vty
*vty
, struct imsg
*imsg
,
1241 struct show_params
*params
)
1245 switch (imsg
->hdr
.type
) {
1246 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1249 vty_out(vty
, " Destination Address: %s, VC ID: %u%s",
1250 inet_ntoa(pw
->lsr_id
), pw
->pwid
, VTY_NEWLINE
);
1253 if (pw
->local_label
!= NO_LABEL
) {
1254 vty_out(vty
, " Local Label: %u%s", pw
->local_label
,
1256 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
1257 "GroupID: %u%s", "", pw
->local_cword
,
1258 pw_type_name(pw
->type
), pw
->local_gid
,
1260 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->local_ifmtu
,
1263 vty_out(vty
, " Local Label: unassigned%s",
1266 /* remote binding */
1267 if (pw
->remote_label
!= NO_LABEL
) {
1268 vty_out(vty
, " Remote Label: %u%s",
1269 pw
->remote_label
, VTY_NEWLINE
);
1270 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
1271 "GroupID: %u%s", "", pw
->remote_cword
,
1272 pw_type_name(pw
->type
), pw
->remote_gid
,
1274 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->remote_ifmtu
,
1277 vty_out(vty
, " Remote Label: unassigned%s",
1281 vty_out(vty
, "%s", VTY_NEWLINE
);
1291 show_l2vpn_binding_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1295 json_object
*json_pw
;
1298 switch (imsg
->hdr
.type
) {
1299 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1302 json_pw
= json_object_new_object();
1303 json_object_string_add(json_pw
, "destination",
1304 inet_ntoa(pw
->lsr_id
));
1305 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1308 if (pw
->local_label
!= NO_LABEL
) {
1309 json_object_int_add(json_pw
, "localLabel",
1311 json_object_int_add(json_pw
, "localControlWord",
1313 json_object_string_add(json_pw
, "localVcType",
1314 pw_type_name(pw
->type
));
1315 json_object_int_add(json_pw
, "localGroupID",
1317 json_object_int_add(json_pw
, "localIfMtu",
1320 json_object_string_add(json_pw
, "localLabel",
1323 /* remote binding */
1324 if (pw
->remote_label
!= NO_LABEL
) {
1325 json_object_int_add(json_pw
, "remoteLabel",
1327 json_object_int_add(json_pw
, "remoteControlWord",
1329 json_object_string_add(json_pw
, "remoteVcType",
1330 pw_type_name(pw
->type
));
1331 json_object_int_add(json_pw
, "remoteGroupID",
1333 json_object_int_add(json_pw
, "remoteIfMtu",
1336 json_object_string_add(json_pw
, "remoteLabel",
1339 sprintf(key_name
, "%s: %u", inet_ntoa(pw
->lsr_id
), pw
->pwid
);
1340 json_object_object_add(json
, key_name
, json_pw
);
1352 show_l2vpn_pw_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1356 switch (imsg
->hdr
.type
) {
1357 case IMSG_CTL_SHOW_L2VPN_PW
:
1360 vty_out(vty
, "%-9s %-15s %-10u %-16s %-10s%s", pw
->ifname
,
1361 inet_ntoa(pw
->lsr_id
), pw
->pwid
, pw
->l2vpn_name
,
1362 (pw
->status
? "UP" : "DOWN"), VTY_NEWLINE
);
1365 vty_out(vty
, "%s", VTY_NEWLINE
);
1375 show_l2vpn_pw_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1379 json_object
*json_pw
;
1381 switch (imsg
->hdr
.type
) {
1382 case IMSG_CTL_SHOW_L2VPN_PW
:
1385 json_pw
= json_object_new_object();
1386 json_object_string_add(json_pw
, "peerId", inet_ntoa(pw
->lsr_id
));
1387 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1388 json_object_string_add(json_pw
, "VpnName", pw
->l2vpn_name
);
1390 json_object_string_add(json_pw
, "status", "up");
1392 json_object_string_add(json_pw
, "status", "down");
1393 json_object_object_add(json
, pw
->ifname
, json_pw
);
1405 ldp_vty_connect(struct imsgbuf
*ibuf
)
1407 struct sockaddr_un s_un
;
1410 /* connect to ldpd control socket */
1411 if ((ctl_sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
1412 log_warn("%s: socket", __func__
);
1416 memset(&s_un
, 0, sizeof(s_un
));
1417 s_un
.sun_family
= AF_UNIX
;
1418 strlcpy(s_un
.sun_path
, ctl_sock_path
, sizeof(s_un
.sun_path
));
1419 if (connect(ctl_sock
, (struct sockaddr
*)&s_un
, sizeof(s_un
)) == -1) {
1420 log_warn("%s: connect: %s", __func__
, ctl_sock_path
);
1425 imsg_init(ibuf
, ctl_sock
);
1431 ldp_vty_dispatch_msg(struct vty
*vty
, struct imsg
*imsg
, enum show_command cmd
,
1432 struct show_params
*params
, json_object
*json
)
1439 ret
= show_interface_msg_json(imsg
, params
, json
);
1441 ret
= show_interface_msg(vty
, imsg
, params
);
1444 if (params
->detail
) {
1446 ret
= show_discovery_detail_msg_json(imsg
,
1449 ret
= show_discovery_detail_msg(vty
, imsg
,
1453 ret
= show_discovery_msg_json(imsg
, params
,
1456 ret
= show_discovery_msg(vty
, imsg
, params
);
1460 if (params
->capabilities
) {
1462 ret
= show_nbr_capabilities_msg_json(imsg
,
1465 ret
= show_nbr_capabilities_msg(vty
, imsg
,
1467 } else if (params
->detail
) {
1469 ret
= show_nbr_detail_msg_json(imsg
, params
,
1472 ret
= show_nbr_detail_msg(vty
, imsg
, params
);
1475 ret
= show_nbr_msg_json(imsg
, params
, json
);
1477 ret
= show_nbr_msg(vty
, imsg
, params
);
1481 if (params
->detail
) {
1483 ret
= show_lib_detail_msg_json(imsg
, params
,
1486 ret
= show_lib_detail_msg(vty
, imsg
, params
);
1489 ret
= show_lib_msg_json(imsg
, params
, json
);
1491 ret
= show_lib_msg(vty
, imsg
, params
);
1496 ret
= show_l2vpn_pw_msg_json(imsg
, params
, json
);
1498 ret
= show_l2vpn_pw_msg(vty
, imsg
, params
);
1500 case SHOW_L2VPN_BINDING
:
1502 ret
= show_l2vpn_binding_msg_json(imsg
, params
, json
);
1504 ret
= show_l2vpn_binding_msg(vty
, imsg
, params
);
1514 ldp_vty_dispatch(struct vty
*vty
, struct imsgbuf
*ibuf
, enum show_command cmd
,
1515 struct show_params
*params
)
1518 int n
, done
= 0, ret
= CMD_SUCCESS
;
1519 json_object
*json
= NULL
;
1521 while (ibuf
->w
.queued
)
1522 if (msgbuf_write(&ibuf
->w
) <= 0 && errno
!= EAGAIN
) {
1523 log_warn("write error");
1525 return (CMD_WARNING
);
1529 json
= json_object_new_object();
1532 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
) {
1533 log_warnx("imsg_read error");
1538 log_warnx("pipe closed");
1544 if ((n
= imsg_get(ibuf
, &imsg
)) == -1) {
1545 log_warnx("imsg_get error");
1551 done
= ldp_vty_dispatch_msg(vty
, &imsg
, cmd
, params
,
1560 vty_out(vty
, "%s%s", json_object_to_json_string_ext(json
,
1561 JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1562 json_object_free(json
);
1569 ldp_vty_get_af(const char *str
, int *af
)
1574 } else if (strcmp(str
, "ipv4") == 0) {
1577 } else if (strcmp(str
, "ipv6") == 0) {
1586 ldp_vty_show_binding(struct vty
*vty
, struct vty_arg
*args
[])
1588 struct imsgbuf ibuf
;
1589 struct show_params params
;
1593 if (ldp_vty_connect(&ibuf
) < 0)
1594 return (CMD_WARNING
);
1596 af_str
= vty_get_arg_value(args
, "address-family");
1597 if (ldp_vty_get_af(af_str
, &af
) < 0)
1598 return (CMD_ERR_NO_MATCH
);
1600 memset(¶ms
, 0, sizeof(params
));
1602 params
.detail
= vty_get_arg_value(args
, "detail") ? 1 : 0;
1603 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1605 if (!params
.detail
&& !params
.json
)
1606 vty_out(vty
, "%-4s %-20s %-15s %-11s %-13s %6s%s", "AF",
1607 "Destination", "Nexthop", "Local Label", "Remote Label",
1608 "In Use", VTY_NEWLINE
);
1610 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LIB
, 0, 0, -1, NULL
, 0);
1611 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LIB
, ¶ms
));
1615 ldp_vty_show_discovery(struct vty
*vty
, struct vty_arg
*args
[])
1617 struct imsgbuf ibuf
;
1618 struct show_params params
;
1622 if (ldp_vty_connect(&ibuf
) < 0)
1623 return (CMD_WARNING
);
1625 af_str
= vty_get_arg_value(args
, "address-family");
1626 if (ldp_vty_get_af(af_str
, &af
) < 0)
1627 return (CMD_ERR_NO_MATCH
);
1629 memset(¶ms
, 0, sizeof(params
));
1631 params
.detail
= vty_get_arg_value(args
, "detail") ? 1 : 0;
1632 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1634 if (!params
.detail
&& !params
.json
)
1635 vty_out(vty
, "%-4s %-15s %-8s %-15s %9s%s",
1636 "AF", "ID", "Type", "Source", "Holdtime", VTY_NEWLINE
);
1639 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY_DTL
, 0, 0, -1,
1642 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
1643 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_DISC
, ¶ms
));
1647 ldp_vty_show_interface(struct vty
*vty
, struct vty_arg
*args
[])
1649 struct imsgbuf ibuf
;
1650 struct show_params params
;
1651 unsigned int ifidx
= 0;
1655 if (ldp_vty_connect(&ibuf
) < 0)
1656 return (CMD_WARNING
);
1658 af_str
= vty_get_arg_value(args
, "address-family");
1659 if (ldp_vty_get_af(af_str
, &af
) < 0)
1660 return (CMD_ERR_NO_MATCH
);
1662 memset(¶ms
, 0, sizeof(params
));
1664 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1668 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3s%s", "AF",
1669 "Interface", "State", "Uptime", "Hello Timers", "ac",
1673 imsg_compose(&ibuf
, IMSG_CTL_SHOW_INTERFACE
, 0, 0, -1, &ifidx
,
1675 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_IFACE
, ¶ms
));
1679 ldp_vty_show_capabilities(struct vty
*vty
, struct vty_arg
*args
[])
1681 if (vty_get_arg_value(args
, "json")) {
1683 json_object
*json_array
;
1684 json_object
*json_cap
;
1686 json
= json_object_new_object();
1687 json_array
= json_object_new_array();
1688 json_object_object_add(json
, "capabilities", json_array
);
1690 /* Dynamic Announcement (0x0506) */
1691 json_cap
= json_object_new_object();
1692 json_object_string_add(json_cap
, "description",
1693 "Dynamic Announcement");
1694 json_object_string_add(json_cap
, "tlvType",
1696 json_object_array_add(json_array
, json_cap
);
1698 /* Typed Wildcard (0x050B) */
1699 json_cap
= json_object_new_object();
1700 json_object_string_add(json_cap
, "description",
1702 json_object_string_add(json_cap
, "tlvType",
1704 json_object_array_add(json_array
, json_cap
);
1706 /* Unrecognized Notification (0x0603) */
1707 json_cap
= json_object_new_object();
1708 json_object_string_add(json_cap
, "description",
1709 "Unrecognized Notification");
1710 json_object_string_add(json_cap
, "tlvType",
1712 json_object_array_add(json_array
, json_cap
);
1714 vty_out(vty
, "%s%s", json_object_to_json_string_ext(json
,
1715 JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1716 json_object_free(json
);
1721 "Supported LDP Capabilities%s"
1722 " * Dynamic Announcement (0x0506)%s"
1723 " * Typed Wildcard (0x050B)%s"
1724 " * Unrecognized Notification (0x0603)%s%s", VTY_NEWLINE
,
1725 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1731 ldp_vty_show_neighbor(struct vty
*vty
, struct vty_arg
*args
[])
1733 struct imsgbuf ibuf
;
1734 struct show_params params
;
1736 if (ldp_vty_connect(&ibuf
) < 0)
1737 return (CMD_WARNING
);
1739 memset(¶ms
, 0, sizeof(params
));
1740 params
.capabilities
= vty_get_arg_value(args
, "capabilities") ? 1 : 0;
1741 params
.detail
= vty_get_arg_value(args
, "detail") ? 1 : 0;
1742 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1744 if (params
.capabilities
)
1747 if (!params
.detail
&& !params
.json
)
1748 vty_out(vty
, "%-4s %-15s %-11s %-15s %8s%s",
1749 "AF", "ID", "State", "Remote Address", "Uptime",
1752 imsg_compose(&ibuf
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, NULL
, 0);
1753 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_NBR
, ¶ms
));
1757 ldp_vty_show_atom_binding(struct vty
*vty
, struct vty_arg
*args
[])
1759 struct imsgbuf ibuf
;
1760 struct show_params params
;
1762 if (ldp_vty_connect(&ibuf
) < 0)
1763 return (CMD_WARNING
);
1765 memset(¶ms
, 0, sizeof(params
));
1766 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1768 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_BINDING
, 0, 0, -1, NULL
, 0);
1769 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_BINDING
, ¶ms
));
1773 ldp_vty_show_atom_vc(struct vty
*vty
, struct vty_arg
*args
[])
1775 struct imsgbuf ibuf
;
1776 struct show_params params
;
1778 if (ldp_vty_connect(&ibuf
) < 0)
1779 return (CMD_WARNING
);
1781 memset(¶ms
, 0, sizeof(params
));
1782 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1786 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1787 "Interface", "Peer ID", "VC ID", "Name", "Status",
1789 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1790 "---------", "---------------", "----------",
1791 "----------------", "----------", VTY_NEWLINE
);
1794 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_PW
, 0, 0, -1, NULL
, 0);
1795 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_PW
, ¶ms
));
1799 ldp_vty_clear_nbr(struct vty
*vty
, struct vty_arg
*args
[])
1801 struct imsgbuf ibuf
;
1802 const char *addr_str
;
1805 addr_str
= vty_get_arg_value(args
, "addr");
1807 memset(&nbr
, 0, sizeof(nbr
));
1809 (ldp_get_address(addr_str
, &nbr
.af
, &nbr
.raddr
) == -1 ||
1810 bad_addr(nbr
.af
, &nbr
.raddr
))) {
1811 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1812 return (CMD_WARNING
);
1815 if (ldp_vty_connect(&ibuf
) < 0)
1816 return (CMD_WARNING
);
1818 imsg_compose(&ibuf
, IMSG_CTL_CLEAR_NBR
, 0, 0, -1, &nbr
, sizeof(nbr
));
1820 while (ibuf
.w
.queued
)
1821 if (msgbuf_write(&ibuf
.w
) <= 0 && errno
!= EAGAIN
) {
1822 log_warn("write error");
1824 return (CMD_WARNING
);
1829 return (CMD_SUCCESS
);