2 * Copyright (C) 2016 by Open Source Routing.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
52 #define LDPBUFSIZ 65535
54 static int show_interface_msg(struct vty
*, struct imsg
*,
55 struct show_params
*);
56 static int show_interface_msg_json(struct imsg
*,
57 struct show_params
*, json_object
*);
58 static int show_discovery_msg(struct vty
*, struct imsg
*,
59 struct show_params
*);
60 static void show_discovery_detail_adj(struct vty
*, char *,
62 static int show_discovery_detail_msg(struct vty
*, struct imsg
*,
63 struct show_params
*);
64 static int show_discovery_msg_json(struct imsg
*,
65 struct show_params
*, json_object
*);
66 static void show_discovery_detail_adj_json(json_object
*,
68 static int show_discovery_detail_msg_json(struct imsg
*,
69 struct show_params
*, json_object
*);
71 static int show_nbr_msg(struct vty
*, struct imsg
*,
72 struct show_params
*);
73 static int show_nbr_msg_json(struct imsg
*, struct show_params
*,
75 static void show_nbr_detail_adj(struct vty
*, char *,
77 static int show_nbr_detail_msg(struct vty
*, struct imsg
*,
78 struct show_params
*);
79 static void show_nbr_detail_adj_json(struct ctl_adj
*,
81 static int show_nbr_detail_msg_json(struct imsg
*,
82 struct show_params
*, json_object
*);
83 static void show_nbr_capabilities(struct vty
*, struct ctl_nbr
*);
84 static int show_nbr_capabilities_msg(struct vty
*, struct imsg
*,
85 struct show_params
*);
86 static void show_nbr_capabilities_json(struct ctl_nbr
*,
88 static int show_nbr_capabilities_msg_json(struct imsg
*,
89 struct show_params
*, json_object
*);
90 static int show_lib_msg(struct vty
*, struct imsg
*,
91 struct show_params
*);
92 static int show_lib_detail_msg(struct vty
*, struct imsg
*,
93 struct show_params
*);
94 static int show_lib_msg_json(struct imsg
*, struct show_params
*,
96 static int show_lib_detail_msg_json(struct imsg
*,
97 struct show_params
*, json_object
*);
98 static int show_l2vpn_binding_msg(struct vty
*, struct imsg
*,
99 struct show_params
*);
100 static int show_l2vpn_binding_msg_json(struct imsg
*,
101 struct show_params
*, json_object
*);
102 static int show_l2vpn_pw_msg(struct vty
*, struct imsg
*,
103 struct show_params
*);
104 static int show_l2vpn_pw_msg_json(struct imsg
*,
105 struct show_params
*, json_object
*);
106 static int ldp_vty_connect(struct imsgbuf
*);
107 static int ldp_vty_dispatch_msg(struct vty
*, struct imsg
*,
108 enum show_command
, struct show_params
*,
110 static int ldp_vty_dispatch(struct vty
*, struct imsgbuf
*,
111 enum show_command
, struct show_params
*);
112 static int ldp_vty_get_af(const char *, int *);
115 show_interface_msg(struct vty
*vty
, struct imsg
*imsg
,
116 struct show_params
*params
)
118 struct ctl_iface
*iface
;
121 switch (imsg
->hdr
.type
) {
122 case IMSG_CTL_SHOW_INTERFACE
:
125 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
128 snprintf(timers
, sizeof(timers
), "%u/%u",
129 iface
->hello_interval
, iface
->hello_holdtime
);
131 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3u%s",
132 af_name(iface
->af
), iface
->name
,
133 if_state_name(iface
->state
), iface
->uptime
== 0 ?
134 "00:00:00" : log_time(iface
->uptime
), timers
,
135 iface
->adj_cnt
, VTY_NEWLINE
);
138 vty_out(vty
, "%s", VTY_NEWLINE
);
148 show_interface_msg_json(struct imsg
*imsg
, struct show_params
*params
,
151 struct ctl_iface
*iface
;
152 json_object
*json_iface
;
155 switch (imsg
->hdr
.type
) {
156 case IMSG_CTL_SHOW_INTERFACE
:
159 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
162 json_iface
= json_object_new_object();
163 json_object_string_add(json_iface
, "name", iface
->name
);
164 json_object_string_add(json_iface
, "addressFamily",
166 json_object_string_add(json_iface
, "state",
167 if_state_name(iface
->state
));
168 json_object_string_add(json_iface
, "upTime",
169 log_time(iface
->uptime
));
170 json_object_int_add(json_iface
, "helloInterval",
171 iface
->hello_interval
);
172 json_object_int_add(json_iface
, "helloHoldtime",
173 iface
->hello_holdtime
);
174 json_object_int_add(json_iface
, "adjacencyCount",
177 sprintf(key_name
, "%s: %s", iface
->name
, af_name(iface
->af
));
178 json_object_object_add(json
, key_name
, json_iface
);
190 show_discovery_msg(struct vty
*vty
, struct imsg
*imsg
,
191 struct show_params
*params
)
196 switch (imsg
->hdr
.type
) {
197 case IMSG_CTL_SHOW_DISCOVERY
:
200 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
203 vty_out(vty
, "%-4s %-15s ", af_name(adj
->af
),
207 vty_out(vty
, "%-8s %-15s ", "Link", adj
->ifname
);
210 addr
= log_addr(adj
->af
, &adj
->src_addr
);
212 vty_out(vty
, "%-8s %-15s ", "Targeted", addr
);
213 if (strlen(addr
) > 15)
214 vty_out(vty
, "%s%46s", VTY_NEWLINE
, " ");
217 vty_out(vty
, "%9u%s", adj
->holdtime
, VTY_NEWLINE
);
220 vty_out(vty
, "%s", VTY_NEWLINE
);
230 show_discovery_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
232 size_t buflen
= strlen(buffer
);
234 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
235 " LSR Id: %s:0%s", inet_ntoa(adj
->id
), VTY_NEWLINE
);
236 buflen
= strlen(buffer
);
237 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
238 " Source address: %s%s",
239 log_addr(adj
->af
, &adj
->src_addr
), VTY_NEWLINE
);
240 buflen
= strlen(buffer
);
241 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
242 " Transport address: %s%s",
243 log_addr(adj
->af
, &adj
->trans_addr
), VTY_NEWLINE
);
244 buflen
= strlen(buffer
);
245 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
246 " Hello hold time: %u secs (due in %u secs)%s",
247 adj
->holdtime
, adj
->holdtime_remaining
, VTY_NEWLINE
);
248 buflen
= strlen(buffer
);
249 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
250 " Dual-stack capability TLV: %s%s",
251 (adj
->ds_tlv
) ? "yes" : "no", VTY_NEWLINE
);
255 show_discovery_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
256 struct show_params
*params
)
259 struct ctl_disc_if
*iface
;
260 struct ctl_disc_tnbr
*tnbr
;
261 struct in_addr rtr_id
;
262 union ldpd_addr
*trans_addr
;
264 static char ifaces_buffer
[LDPBUFSIZ
];
265 static char tnbrs_buffer
[LDPBUFSIZ
];
267 switch (imsg
->hdr
.type
) {
268 case IMSG_CTL_SHOW_DISCOVERY
:
269 ifaces_buffer
[0] = '\0';
270 tnbrs_buffer
[0] = '\0';
272 case IMSG_CTL_SHOW_DISC_IFACE
:
275 if (params
->family
!= AF_UNSPEC
&&
276 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
277 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
280 buflen
= strlen(ifaces_buffer
);
281 snprintf(ifaces_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
282 " %s: %s%s", iface
->name
, (iface
->no_adj
) ?
283 "(no adjacencies)" : "", VTY_NEWLINE
);
285 case IMSG_CTL_SHOW_DISC_TNBR
:
288 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
291 trans_addr
= &(ldp_af_conf_get(ldpd_conf
,
292 tnbr
->af
))->trans_addr
;
293 buflen
= strlen(tnbrs_buffer
);
294 snprintf(tnbrs_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
295 " %s -> %s: %s%s", log_addr(tnbr
->af
, trans_addr
),
296 log_addr(tnbr
->af
, &tnbr
->addr
), (tnbr
->no_adj
) ?
297 "(no adjacencies)" : "", VTY_NEWLINE
);
299 case IMSG_CTL_SHOW_DISC_ADJ
:
302 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
307 show_discovery_detail_adj(vty
, ifaces_buffer
, adj
);
310 show_discovery_detail_adj(vty
, tnbrs_buffer
, adj
);
315 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
316 vty_out(vty
, "Local:%s", VTY_NEWLINE
);
317 vty_out(vty
, " LSR Id: %s:0%s", inet_ntoa(rtr_id
),
319 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
320 vty_out(vty
, " Transport Address (IPv4): %s%s",
321 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
),
323 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
324 vty_out(vty
, " Transport Address (IPv6): %s%s",
325 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
),
327 vty_out(vty
, "Discovery Sources:%s", VTY_NEWLINE
);
328 vty_out(vty
, " Interfaces:%s", VTY_NEWLINE
);
329 vty_out(vty
, "%s", ifaces_buffer
);
330 vty_out(vty
, " Targeted Hellos:%s", VTY_NEWLINE
);
331 vty_out(vty
, "%s", tnbrs_buffer
);
332 vty_out(vty
, "%s", VTY_NEWLINE
);
342 show_discovery_msg_json(struct imsg
*imsg
, struct show_params
*params
,
346 json_object
*json_array
;
347 json_object
*json_adj
;
349 switch (imsg
->hdr
.type
) {
350 case IMSG_CTL_SHOW_DISCOVERY
:
353 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
356 json_object_object_get_ex(json
, "adjacencies", &json_array
);
358 json_array
= json_object_new_array();
359 json_object_object_add(json
, "adjacencies", json_array
);
362 json_adj
= json_object_new_object();
363 json_object_string_add(json_adj
, "addressFamily",
365 json_object_string_add(json_adj
, "neighborId",
369 json_object_string_add(json_adj
, "type", "link");
370 json_object_string_add(json_adj
, "interface",
374 json_object_string_add(json_adj
, "type", "targeted");
375 json_object_string_add(json_adj
, "peer",
376 log_addr(adj
->af
, &adj
->src_addr
));
379 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
381 json_object_array_add(json_array
, json_adj
);
393 show_discovery_detail_adj_json(json_object
*json
, struct ctl_adj
*adj
)
395 json_object
*json_adj
;
396 json_object
*json_array
;
398 json_object_object_get_ex(json
, "adjacencies", &json_array
);
400 json_array
= json_object_new_array();
401 json_object_object_add(json
, "adjacencies", json_array
);
404 json_adj
= json_object_new_object();
405 json_object_string_add(json_adj
, "lsrId", inet_ntoa(adj
->id
));
406 json_object_string_add(json_adj
, "sourceAddress", log_addr(adj
->af
,
408 json_object_string_add(json_adj
, "transportAddress", log_addr(adj
->af
,
410 json_object_int_add(json_adj
, "helloHoldtime", adj
->holdtime
);
411 json_object_int_add(json_adj
, "helloHoldtimeRemaining",
412 adj
->holdtime_remaining
);
413 json_object_int_add(json_adj
, "dualStackCapabilityTlv",
415 json_object_array_add(json_array
, json_adj
);
419 show_discovery_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
423 struct ctl_disc_if
*iface
;
424 struct ctl_disc_tnbr
*tnbr
;
425 struct in_addr rtr_id
;
426 union ldpd_addr
*trans_addr
;
427 json_object
*json_interface
;
428 json_object
*json_target
;
429 static json_object
*json_interfaces
;
430 static json_object
*json_targets
;
431 static json_object
*json_container
;
433 switch (imsg
->hdr
.type
) {
434 case IMSG_CTL_SHOW_DISCOVERY
:
435 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
436 json_object_string_add(json
, "lsrId", inet_ntoa(rtr_id
));
437 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
438 json_object_string_add(json
, "transportAddressIPv4",
439 log_addr(AF_INET
, &ldpd_conf
->ipv4
.trans_addr
));
440 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
441 json_object_string_add(json
, "transportAddressIPv6",
442 log_addr(AF_INET6
, &ldpd_conf
->ipv6
.trans_addr
));
443 json_interfaces
= json_object_new_object();
444 json_object_object_add(json
, "interfaces", json_interfaces
);
445 json_targets
= json_object_new_object();
446 json_object_object_add(json
, "targetedHellos", json_targets
);
447 json_container
= NULL
;
449 case IMSG_CTL_SHOW_DISC_IFACE
:
452 if (params
->family
!= AF_UNSPEC
&&
453 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
454 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
457 json_interface
= json_object_new_object();
458 json_object_object_add(json_interfaces
, iface
->name
,
460 json_container
= json_interface
;
462 case IMSG_CTL_SHOW_DISC_TNBR
:
465 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
468 trans_addr
= &(ldp_af_conf_get(ldpd_conf
, tnbr
->af
))->trans_addr
;
470 json_target
= json_object_new_object();
471 json_object_string_add(json_target
, "sourceAddress",
472 log_addr(tnbr
->af
, trans_addr
));
473 json_object_object_add(json_targets
, log_addr(tnbr
->af
,
474 &tnbr
->addr
), json_target
);
475 json_container
= json_target
;
477 case IMSG_CTL_SHOW_DISC_ADJ
:
480 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
485 show_discovery_detail_adj_json(json_container
, adj
);
488 show_discovery_detail_adj_json(json_container
, adj
);
502 show_nbr_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
507 switch (imsg
->hdr
.type
) {
508 case IMSG_CTL_SHOW_NBR
:
511 addr
= log_addr(nbr
->af
, &nbr
->raddr
);
513 vty_out(vty
, "%-4s %-15s %-11s %-15s",
514 af_name(nbr
->af
), inet_ntoa(nbr
->id
),
515 nbr_state_name(nbr
->nbr_state
), addr
);
516 if (strlen(addr
) > 15)
517 vty_out(vty
, "%s%48s", VTY_NEWLINE
, " ");
518 vty_out(vty
, " %8s%s", log_time(nbr
->uptime
), VTY_NEWLINE
);
530 show_nbr_detail_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
532 size_t buflen
= strlen(buffer
);
536 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
537 " Interface: %s%s", adj
->ifname
, VTY_NEWLINE
);
540 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
541 " Targeted Hello: %s%s", log_addr(adj
->af
,
542 &adj
->src_addr
), VTY_NEWLINE
);
548 show_nbr_detail_msg(struct vty
*vty
, struct imsg
*imsg
,
549 struct show_params
*params
)
552 struct ldp_stats
*stats
;
554 static char v4adjs_buffer
[LDPBUFSIZ
];
555 static char v6adjs_buffer
[LDPBUFSIZ
];
557 switch (imsg
->hdr
.type
) {
558 case IMSG_CTL_SHOW_NBR
:
561 v4adjs_buffer
[0] = '\0';
562 v6adjs_buffer
[0] = '\0';
563 vty_out(vty
, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr
->id
),
565 vty_out(vty
, " TCP connection: %s:%u - %s:%u%s",
566 log_addr(nbr
->af
, &nbr
->laddr
), ntohs(nbr
->lport
),
567 log_addr(nbr
->af
, &nbr
->raddr
), ntohs(nbr
->rport
),
569 vty_out(vty
, " Authentication: %s%s",
570 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
571 "none", VTY_NEWLINE
);
572 vty_out(vty
, " Session Holdtime: %u secs; "
573 "KeepAlive interval: %u secs%s", nbr
->holdtime
,
574 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
, VTY_NEWLINE
);
575 vty_out(vty
, " State: %s; Downstream-Unsolicited%s",
576 nbr_state_name(nbr
->nbr_state
), VTY_NEWLINE
);
577 vty_out(vty
, " Up time: %s%s", log_time(nbr
->uptime
),
581 vty_out(vty
, " Messages sent/rcvd:%s", VTY_NEWLINE
);
582 vty_out(vty
, " - Keepalive Messages: %u/%u%s",
583 stats
->kalive_sent
, stats
->kalive_rcvd
, VTY_NEWLINE
);
584 vty_out(vty
, " - Address Messages: %u/%u%s",
585 stats
->addr_sent
, stats
->addr_rcvd
, VTY_NEWLINE
);
586 vty_out(vty
, " - Address Withdraw Messages: %u/%u%s",
587 stats
->addrwdraw_sent
, stats
->addrwdraw_rcvd
, VTY_NEWLINE
);
588 vty_out(vty
, " - Notification Messages: %u/%u%s",
589 stats
->notif_sent
, stats
->notif_rcvd
, VTY_NEWLINE
);
590 vty_out(vty
, " - Capability Messages: %u/%u%s",
591 stats
->capability_sent
, stats
->capability_rcvd
, VTY_NEWLINE
);
592 vty_out(vty
, " - Label Mapping Messages: %u/%u%s",
593 stats
->labelmap_sent
, stats
->labelmap_rcvd
, VTY_NEWLINE
);
594 vty_out(vty
, " - Label Request Messages: %u/%u%s",
595 stats
->labelreq_sent
, stats
->labelreq_rcvd
, VTY_NEWLINE
);
596 vty_out(vty
, " - Label Withdraw Messages: %u/%u%s",
597 stats
->labelwdraw_sent
, stats
->labelwdraw_rcvd
, VTY_NEWLINE
);
598 vty_out(vty
, " - Label Release Messages: %u/%u%s",
599 stats
->labelrel_sent
, stats
->labelrel_rcvd
, VTY_NEWLINE
);
600 vty_out(vty
, " - Label Abort Request Messages: %u/%u%s",
601 stats
->labelabreq_sent
, stats
->labelabreq_rcvd
, VTY_NEWLINE
);
603 show_nbr_capabilities(vty
, nbr
);
605 case IMSG_CTL_SHOW_NBR_DISC
:
610 show_nbr_detail_adj(vty
, v4adjs_buffer
, adj
);
613 show_nbr_detail_adj(vty
, v6adjs_buffer
, adj
);
616 fatalx("show_nbr_detail_msg: unknown af");
619 case IMSG_CTL_SHOW_NBR_END
:
620 vty_out(vty
, " LDP Discovery Sources:%s", VTY_NEWLINE
);
621 if (v4adjs_buffer
[0] != '\0') {
622 vty_out(vty
, " IPv4:%s", VTY_NEWLINE
);
623 vty_out(vty
, "%s", v4adjs_buffer
);
625 if (v6adjs_buffer
[0] != '\0') {
626 vty_out(vty
, " IPv6:%s", VTY_NEWLINE
);
627 vty_out(vty
, "%s", v6adjs_buffer
);
629 vty_out(vty
, "%s", VTY_NEWLINE
);
641 show_nbr_msg_json(struct imsg
*imsg
, struct show_params
*params
,
645 json_object
*json_array
;
646 json_object
*json_nbr
;
648 switch (imsg
->hdr
.type
) {
649 case IMSG_CTL_SHOW_NBR
:
652 json_object_object_get_ex(json
, "neighbors", &json_array
);
654 json_array
= json_object_new_array();
655 json_object_object_add(json
, "neighbors", json_array
);
658 json_nbr
= json_object_new_object();
659 json_object_string_add(json_nbr
, "addressFamily",
661 json_object_string_add(json_nbr
, "neighborId",
663 json_object_string_add(json_nbr
, "state",
664 nbr_state_name(nbr
->nbr_state
));
665 json_object_string_add(json_nbr
, "transportAddress",
666 log_addr(nbr
->af
, &nbr
->raddr
));
667 json_object_string_add(json_nbr
, "upTime",
668 log_time(nbr
->uptime
));
670 json_object_array_add(json_array
, json_nbr
);
682 show_nbr_detail_adj_json(struct ctl_adj
*adj
, json_object
*adj_list
)
684 char adj_string
[128];
688 strlcpy(adj_string
, "interface: ", sizeof(adj_string
));
689 strlcat(adj_string
, adj
->ifname
, sizeof(adj_string
));
692 strlcpy(adj_string
, "targetedHello: ", sizeof(adj_string
));
693 strlcat(adj_string
, log_addr(adj
->af
, &adj
->src_addr
),
698 json_object_array_add(adj_list
, json_object_new_string(adj_string
));
702 show_nbr_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
706 struct ldp_stats
*stats
;
708 json_object
*json_nbr
;
709 json_object
*json_array
;
710 json_object
*json_counter
;
711 static json_object
*json_nbr_sources
;
712 static json_object
*json_v4adjs
;
713 static json_object
*json_v6adjs
;
715 switch (imsg
->hdr
.type
) {
716 case IMSG_CTL_SHOW_NBR
:
719 json_nbr
= json_object_new_object();
720 json_object_object_add(json
, inet_ntoa(nbr
->id
), json_nbr
);
722 json_object_string_add(json_nbr
, "peerId", inet_ntoa(nbr
->id
));
723 json_object_string_add(json_nbr
, "tcpLocalAddress",
724 log_addr(nbr
->af
, &nbr
->laddr
));
725 json_object_int_add(json_nbr
, "tcpLocalPort",
727 json_object_string_add(json_nbr
, "tcpRemoteAddress",
728 log_addr(nbr
->af
, &nbr
->raddr
));
729 json_object_int_add(json_nbr
, "tcpRemotePort",
731 json_object_string_add(json_nbr
, "authentication",
732 (nbr
->auth_method
== AUTH_MD5SIG
) ? "TCP MD5 Signature" :
734 json_object_int_add(json_nbr
, "sessionHoldtime", nbr
->holdtime
);
735 json_object_int_add(json_nbr
, "keepAliveInterval",
736 nbr
->holdtime
/ KEEPALIVE_PER_PERIOD
);
737 json_object_string_add(json_nbr
, "state",
738 nbr_state_name(nbr
->nbr_state
));
739 json_object_string_add(json_nbr
, "upTime",
740 log_time(nbr
->uptime
));
742 /* message_counters */
744 json_array
= json_object_new_array();
745 json_object_object_add(json_nbr
, "sentMessages", json_array
);
746 json_counter
= json_object_new_object();
747 json_object_int_add(json_counter
, "keepalive",
749 json_object_array_add(json_array
, json_counter
);
750 json_counter
= json_object_new_object();
751 json_object_int_add(json_counter
, "address",
753 json_object_array_add(json_array
, json_counter
);
754 json_counter
= json_object_new_object();
755 json_object_int_add(json_counter
, "addressWithdraw",
756 stats
->addrwdraw_sent
);
757 json_object_array_add(json_array
, json_counter
);
758 json_counter
= json_object_new_object();
759 json_object_int_add(json_counter
, "notification",
761 json_object_array_add(json_array
, json_counter
);
762 json_counter
= json_object_new_object();
763 json_object_int_add(json_counter
, "capability",
764 stats
->capability_sent
);
765 json_object_array_add(json_array
, json_counter
);
766 json_counter
= json_object_new_object();
767 json_object_int_add(json_counter
, "labelMapping",
768 stats
->labelmap_sent
);
769 json_object_array_add(json_array
, json_counter
);
770 json_counter
= json_object_new_object();
771 json_object_int_add(json_counter
, "labelRequest",
772 stats
->labelreq_sent
);
773 json_object_array_add(json_array
, json_counter
);
774 json_counter
= json_object_new_object();
775 json_object_int_add(json_counter
, "labelWithdraw",
776 stats
->labelwdraw_sent
);
777 json_object_array_add(json_array
, json_counter
);
778 json_counter
= json_object_new_object();
779 json_object_int_add(json_counter
, "labelRelease",
780 stats
->labelrel_sent
);
781 json_object_array_add(json_array
, json_counter
);
782 json_counter
= json_object_new_object();
783 json_object_int_add(json_counter
, "labelAbortRequest",
784 stats
->labelabreq_sent
);
785 json_object_array_add(json_array
, json_counter
);
787 json_array
= json_object_new_array();
788 json_object_object_add(json_nbr
, "receivedMessages", json_array
);
789 json_counter
= json_object_new_object();
790 json_object_int_add(json_counter
, "keepalive",
792 json_object_array_add(json_array
, json_counter
);
793 json_counter
= json_object_new_object();
794 json_object_int_add(json_counter
, "address",
796 json_object_array_add(json_array
, json_counter
);
797 json_counter
= json_object_new_object();
798 json_object_int_add(json_counter
, "addressWithdraw",
799 stats
->addrwdraw_rcvd
);
800 json_object_array_add(json_array
, json_counter
);
801 json_counter
= json_object_new_object();
802 json_object_int_add(json_counter
, "notification",
804 json_object_array_add(json_array
, json_counter
);
805 json_counter
= json_object_new_object();
806 json_object_int_add(json_counter
, "capability",
807 stats
->capability_rcvd
);
808 json_object_array_add(json_array
, json_counter
);
809 json_counter
= json_object_new_object();
810 json_object_int_add(json_counter
, "labelMapping",
811 stats
->labelmap_rcvd
);
812 json_object_array_add(json_array
, json_counter
);
813 json_counter
= json_object_new_object();
814 json_object_int_add(json_counter
, "labelRequest",
815 stats
->labelreq_rcvd
);
816 json_object_array_add(json_array
, json_counter
);
817 json_counter
= json_object_new_object();
818 json_object_int_add(json_counter
, "labelWithdraw",
819 stats
->labelwdraw_rcvd
);
820 json_object_array_add(json_array
, json_counter
);
821 json_counter
= json_object_new_object();
822 json_object_int_add(json_counter
, "labelRelease",
823 stats
->labelrel_rcvd
);
824 json_object_array_add(json_array
, json_counter
);
825 json_counter
= json_object_new_object();
826 json_object_int_add(json_counter
, "labelAbortRequest",
827 stats
->labelabreq_rcvd
);
828 json_object_array_add(json_array
, json_counter
);
831 show_nbr_capabilities_json(nbr
, json_nbr
);
833 /* discovery sources */
834 json_nbr_sources
= json_object_new_object();
835 json_object_object_add(json_nbr
, "discoverySources",
840 case IMSG_CTL_SHOW_NBR_DISC
:
846 json_v4adjs
= json_object_new_array();
847 json_object_object_add(json_nbr_sources
, "ipv4",
850 show_nbr_detail_adj_json(adj
, json_v4adjs
);
854 json_v6adjs
= json_object_new_array();
855 json_object_object_add(json_nbr_sources
, "ipv6",
858 show_nbr_detail_adj_json(adj
, json_v6adjs
);
861 fatalx("show_nbr_detail_msg_json: unknown af");
864 case IMSG_CTL_SHOW_NBR_END
:
876 show_nbr_capabilities(struct vty
*vty
, struct ctl_nbr
*nbr
)
878 vty_out(vty
, " Capabilities Sent:%s"
879 " - Dynamic Announcement (0x0506)%s"
880 " - Typed Wildcard (0x050B)%s"
881 " - Unrecognized Notification (0x0603)%s",
882 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
883 vty_out(vty
, " Capabilities Received:%s", VTY_NEWLINE
);
884 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
)
885 vty_out(vty
, " - Dynamic Announcement (0x0506)%s",
887 if (nbr
->flags
& F_NBR_CAP_TWCARD
)
888 vty_out(vty
, " - Typed Wildcard (0x050B)%s", VTY_NEWLINE
);
889 if (nbr
->flags
& F_NBR_CAP_UNOTIF
)
890 vty_out(vty
, " - Unrecognized Notification (0x0603)%s",
895 show_nbr_capabilities_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
899 switch (imsg
->hdr
.type
) {
900 case IMSG_CTL_SHOW_NBR
:
903 if (nbr
->nbr_state
!= NBR_STA_OPER
)
906 vty_out(vty
, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr
->id
),
908 show_nbr_capabilities(vty
, nbr
);
909 vty_out(vty
, "%s", VTY_NEWLINE
);
912 vty_out(vty
, "%s", VTY_NEWLINE
);
922 show_nbr_capabilities_json(struct ctl_nbr
*nbr
, json_object
*json_nbr
)
924 json_object
*json_array
;
925 json_object
*json_cap
;
927 /* sent capabilities */
928 json_array
= json_object_new_array();
929 json_object_object_add(json_nbr
, "sentCapabilities", json_array
);
931 /* Dynamic Announcement (0x0506) */
932 json_cap
= json_object_new_object();
933 json_object_string_add(json_cap
, "description", "Dynamic Announcement");
934 json_object_string_add(json_cap
, "tlvType", "0x0506");
935 json_object_array_add(json_array
, json_cap
);
937 /* Typed Wildcard (0x050B) */
938 json_cap
= json_object_new_object();
939 json_object_string_add(json_cap
, "description", "Typed Wildcard");
940 json_object_string_add(json_cap
, "tlvType", "0x050B");
941 json_object_array_add(json_array
, json_cap
);
943 /* Unrecognized Notification (0x0603) */
944 json_cap
= json_object_new_object();
945 json_object_string_add(json_cap
, "description",
946 "Unrecognized Notification");
947 json_object_string_add(json_cap
, "tlvType", "0x0603");
948 json_object_array_add(json_array
, json_cap
);
950 /* received capabilities */
951 json_array
= json_object_new_array();
952 json_object_object_add(json_nbr
, "receivedCapabilities", json_array
);
954 /* Dynamic Announcement (0x0506) */
955 if (nbr
->flags
& F_NBR_CAP_DYNAMIC
) {
956 json_cap
= json_object_new_object();
957 json_object_string_add(json_cap
, "description",
958 "Dynamic Announcement");
959 json_object_string_add(json_cap
, "tlvType", "0x0506");
960 json_object_array_add(json_array
, json_cap
);
963 /* Typed Wildcard (0x050B) */
964 if (nbr
->flags
& F_NBR_CAP_TWCARD
) {
965 json_cap
= json_object_new_object();
966 json_object_string_add(json_cap
, "description",
968 json_object_string_add(json_cap
, "tlvType", "0x050B");
969 json_object_array_add(json_array
, json_cap
);
972 /* Unrecognized Notification (0x0603) */
973 if (nbr
->flags
& F_NBR_CAP_UNOTIF
) {
974 json_cap
= json_object_new_object();
975 json_object_string_add(json_cap
, "description",
976 "Unrecognized Notification");
977 json_object_string_add(json_cap
, "tlvType", "0x0603");
978 json_object_array_add(json_array
, json_cap
);
983 show_nbr_capabilities_msg_json(struct imsg
*imsg
, struct show_params
*params
,
987 json_object
*json_nbr
;
989 switch (imsg
->hdr
.type
) {
990 case IMSG_CTL_SHOW_NBR
:
993 if (nbr
->nbr_state
!= NBR_STA_OPER
)
996 json_nbr
= json_object_new_object();
997 json_object_object_add(json
, inet_ntoa(nbr
->id
), json_nbr
);
998 show_nbr_capabilities_json(nbr
, json_nbr
);
1010 show_lib_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1013 char dstnet
[BUFSIZ
];
1015 switch (imsg
->hdr
.type
) {
1016 case IMSG_CTL_SHOW_LIB_BEGIN
:
1017 case IMSG_CTL_SHOW_LIB_RCVD
:
1020 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1024 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1027 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1028 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1030 vty_out(vty
, "%-4s %-20s", af_name(rt
->af
), dstnet
);
1031 if (strlen(dstnet
) > 20)
1032 vty_out(vty
, "%s%25s", VTY_NEWLINE
, " ");
1033 vty_out(vty
, " %-15s %-11s %-13s %6s%s", inet_ntoa(rt
->nexthop
),
1034 log_label(rt
->local_label
), log_label(rt
->remote_label
),
1035 rt
->in_use
? "yes" : "no", VTY_NEWLINE
);
1038 vty_out(vty
, "%s", VTY_NEWLINE
);
1048 show_lib_detail_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1050 struct ctl_rt
*rt
= NULL
;
1051 char dstnet
[BUFSIZ
];
1052 static int upstream
, downstream
;
1054 static char sent_buffer
[LDPBUFSIZ
];
1055 static char rcvd_buffer
[LDPBUFSIZ
];
1057 switch (imsg
->hdr
.type
) {
1058 case IMSG_CTL_SHOW_LIB_BEGIN
:
1059 case IMSG_CTL_SHOW_LIB_SENT
:
1060 case IMSG_CTL_SHOW_LIB_RCVD
:
1061 case IMSG_CTL_SHOW_LIB_END
:
1063 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1070 switch (imsg
->hdr
.type
) {
1071 case IMSG_CTL_SHOW_LIB_BEGIN
:
1074 sent_buffer
[0] = '\0';
1075 rcvd_buffer
[0] = '\0';
1077 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1078 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1080 vty_out(vty
, "%s%s", dstnet
, VTY_NEWLINE
);
1081 vty_out(vty
, "%-8sLocal binding: label: %s%s", "",
1082 log_label(rt
->local_label
), VTY_NEWLINE
);
1084 case IMSG_CTL_SHOW_LIB_SENT
:
1086 buflen
= strlen(sent_buffer
);
1087 snprintf(sent_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1088 "%12s%s:0%s", "", inet_ntoa(rt
->nexthop
), VTY_NEWLINE
);
1090 case IMSG_CTL_SHOW_LIB_RCVD
:
1092 buflen
= strlen(rcvd_buffer
);
1093 snprintf(rcvd_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
1094 "%12s%s:0, label %s%s%s", "", inet_ntoa(rt
->nexthop
),
1095 log_label(rt
->remote_label
),
1096 rt
->in_use
? " (in use)" : "", VTY_NEWLINE
);
1098 case IMSG_CTL_SHOW_LIB_END
:
1100 vty_out(vty
, "%-8sAdvertised to:%s", "", VTY_NEWLINE
);
1101 vty_out(vty
, "%s", sent_buffer
);
1104 vty_out(vty
, "%-8sRemote bindings:%s", "", VTY_NEWLINE
);
1105 vty_out(vty
, "%s", rcvd_buffer
);
1107 vty_out(vty
, "%-8sNo remote bindings%s", "",
1111 vty_out(vty
, "%s", VTY_NEWLINE
);
1121 show_lib_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1125 json_object
*json_array
;
1126 json_object
*json_lib_entry
;
1127 char dstnet
[BUFSIZ
];
1129 switch (imsg
->hdr
.type
) {
1130 case IMSG_CTL_SHOW_LIB_BEGIN
:
1131 case IMSG_CTL_SHOW_LIB_RCVD
:
1134 if (imsg
->hdr
.type
== IMSG_CTL_SHOW_LIB_BEGIN
&&
1138 json_object_object_get_ex(json
, "bindings", &json_array
);
1140 json_array
= json_object_new_array();
1141 json_object_object_add(json
, "bindings", json_array
);
1144 json_lib_entry
= json_object_new_object();
1145 json_object_string_add(json_lib_entry
, "addressFamily",
1147 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1148 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1149 json_object_string_add(json_lib_entry
, "prefix", dstnet
);
1150 json_object_string_add(json_lib_entry
, "neighborId",
1151 inet_ntoa(rt
->nexthop
));
1152 json_object_string_add(json_lib_entry
, "localLabel",
1153 log_label(rt
->local_label
));
1154 json_object_string_add(json_lib_entry
, "remoteLabel",
1155 log_label(rt
->remote_label
));
1156 json_object_int_add(json_lib_entry
, "inUse", rt
->in_use
);
1158 json_object_array_add(json_array
, json_lib_entry
);
1170 show_lib_detail_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1173 struct ctl_rt
*rt
= NULL
;
1174 char dstnet
[BUFSIZ
];
1175 static json_object
*json_lib_entry
;
1176 static json_object
*json_adv_labels
;
1177 json_object
*json_adv_label
;
1178 static json_object
*json_remote_labels
;
1179 json_object
*json_remote_label
;
1181 switch (imsg
->hdr
.type
) {
1182 case IMSG_CTL_SHOW_LIB_BEGIN
:
1183 case IMSG_CTL_SHOW_LIB_SENT
:
1184 case IMSG_CTL_SHOW_LIB_RCVD
:
1185 case IMSG_CTL_SHOW_LIB_END
:
1187 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
1194 switch (imsg
->hdr
.type
) {
1195 case IMSG_CTL_SHOW_LIB_BEGIN
:
1196 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
1197 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
1199 json_lib_entry
= json_object_new_object();
1200 json_object_string_add(json_lib_entry
, "localLabel",
1201 log_label(rt
->local_label
));
1203 json_adv_labels
= json_object_new_array();
1204 json_object_object_add(json_lib_entry
, "advertisedTo",
1207 json_remote_labels
= json_object_new_array();
1208 json_object_object_add(json_lib_entry
, "remoteLabels",
1209 json_remote_labels
);
1211 json_object_object_add(json
, dstnet
, json_lib_entry
);
1213 case IMSG_CTL_SHOW_LIB_SENT
:
1214 json_adv_label
= json_object_new_object();
1215 json_object_string_add(json_adv_label
, "neighborId",
1216 inet_ntoa(rt
->nexthop
));
1217 json_object_array_add(json_adv_labels
, json_adv_label
);
1219 case IMSG_CTL_SHOW_LIB_RCVD
:
1220 json_remote_label
= json_object_new_object();
1221 json_object_string_add(json_remote_label
, "neighborId",
1222 inet_ntoa(rt
->nexthop
));
1223 json_object_string_add(json_remote_label
, "label",
1224 log_label(rt
->remote_label
));
1225 json_object_int_add(json_remote_label
, "inUse", rt
->in_use
);
1226 json_object_array_add(json_remote_labels
, json_remote_label
);
1238 show_l2vpn_binding_msg(struct vty
*vty
, struct imsg
*imsg
,
1239 struct show_params
*params
)
1243 switch (imsg
->hdr
.type
) {
1244 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1247 vty_out(vty
, " Destination Address: %s, VC ID: %u%s",
1248 inet_ntoa(pw
->lsr_id
), pw
->pwid
, VTY_NEWLINE
);
1251 if (pw
->local_label
!= NO_LABEL
) {
1252 vty_out(vty
, " Local Label: %u%s", pw
->local_label
,
1254 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
1255 "GroupID: %u%s", "", pw
->local_cword
,
1256 pw_type_name(pw
->type
), pw
->local_gid
,
1258 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->local_ifmtu
,
1261 vty_out(vty
, " Local Label: unassigned%s",
1264 /* remote binding */
1265 if (pw
->remote_label
!= NO_LABEL
) {
1266 vty_out(vty
, " Remote Label: %u%s",
1267 pw
->remote_label
, VTY_NEWLINE
);
1268 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
1269 "GroupID: %u%s", "", pw
->remote_cword
,
1270 pw_type_name(pw
->type
), pw
->remote_gid
,
1272 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->remote_ifmtu
,
1275 vty_out(vty
, " Remote Label: unassigned%s",
1279 vty_out(vty
, "%s", VTY_NEWLINE
);
1289 show_l2vpn_binding_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1293 json_object
*json_pw
;
1296 switch (imsg
->hdr
.type
) {
1297 case IMSG_CTL_SHOW_L2VPN_BINDING
:
1300 json_pw
= json_object_new_object();
1301 json_object_string_add(json_pw
, "destination",
1302 inet_ntoa(pw
->lsr_id
));
1303 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1306 if (pw
->local_label
!= NO_LABEL
) {
1307 json_object_int_add(json_pw
, "localLabel",
1309 json_object_int_add(json_pw
, "localControlWord",
1311 json_object_string_add(json_pw
, "localVcType",
1312 pw_type_name(pw
->type
));
1313 json_object_int_add(json_pw
, "localGroupID",
1315 json_object_int_add(json_pw
, "localIfMtu",
1318 json_object_string_add(json_pw
, "localLabel",
1321 /* remote binding */
1322 if (pw
->remote_label
!= NO_LABEL
) {
1323 json_object_int_add(json_pw
, "remoteLabel",
1325 json_object_int_add(json_pw
, "remoteControlWord",
1327 json_object_string_add(json_pw
, "remoteVcType",
1328 pw_type_name(pw
->type
));
1329 json_object_int_add(json_pw
, "remoteGroupID",
1331 json_object_int_add(json_pw
, "remoteIfMtu",
1334 json_object_string_add(json_pw
, "remoteLabel",
1337 sprintf(key_name
, "%s: %u", inet_ntoa(pw
->lsr_id
), pw
->pwid
);
1338 json_object_object_add(json
, key_name
, json_pw
);
1350 show_l2vpn_pw_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
1354 switch (imsg
->hdr
.type
) {
1355 case IMSG_CTL_SHOW_L2VPN_PW
:
1358 vty_out(vty
, "%-9s %-15s %-10u %-16s %-10s%s", pw
->ifname
,
1359 inet_ntoa(pw
->lsr_id
), pw
->pwid
, pw
->l2vpn_name
,
1360 (pw
->status
? "UP" : "DOWN"), VTY_NEWLINE
);
1363 vty_out(vty
, "%s", VTY_NEWLINE
);
1373 show_l2vpn_pw_msg_json(struct imsg
*imsg
, struct show_params
*params
,
1377 json_object
*json_pw
;
1379 switch (imsg
->hdr
.type
) {
1380 case IMSG_CTL_SHOW_L2VPN_PW
:
1383 json_pw
= json_object_new_object();
1384 json_object_string_add(json_pw
, "peerId", inet_ntoa(pw
->lsr_id
));
1385 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
1386 json_object_string_add(json_pw
, "VpnName", pw
->l2vpn_name
);
1388 json_object_string_add(json_pw
, "status", "up");
1390 json_object_string_add(json_pw
, "status", "down");
1391 json_object_object_add(json
, pw
->ifname
, json_pw
);
1403 ldp_vty_connect(struct imsgbuf
*ibuf
)
1405 struct sockaddr_un s_un
;
1408 /* connect to ldpd control socket */
1409 if ((ctl_sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
1410 log_warn("%s: socket", __func__
);
1414 memset(&s_un
, 0, sizeof(s_un
));
1415 s_un
.sun_family
= AF_UNIX
;
1416 strlcpy(s_un
.sun_path
, ctl_sock_path
, sizeof(s_un
.sun_path
));
1417 if (connect(ctl_sock
, (struct sockaddr
*)&s_un
, sizeof(s_un
)) == -1) {
1418 log_warn("%s: connect: %s", __func__
, ctl_sock_path
);
1423 imsg_init(ibuf
, ctl_sock
);
1429 ldp_vty_dispatch_msg(struct vty
*vty
, struct imsg
*imsg
, enum show_command cmd
,
1430 struct show_params
*params
, json_object
*json
)
1437 ret
= show_interface_msg_json(imsg
, params
, json
);
1439 ret
= show_interface_msg(vty
, imsg
, params
);
1442 if (params
->detail
) {
1444 ret
= show_discovery_detail_msg_json(imsg
,
1447 ret
= show_discovery_detail_msg(vty
, imsg
,
1451 ret
= show_discovery_msg_json(imsg
, params
,
1454 ret
= show_discovery_msg(vty
, imsg
, params
);
1458 if (params
->capabilities
) {
1460 ret
= show_nbr_capabilities_msg_json(imsg
,
1463 ret
= show_nbr_capabilities_msg(vty
, imsg
,
1465 } else if (params
->detail
) {
1467 ret
= show_nbr_detail_msg_json(imsg
, params
,
1470 ret
= show_nbr_detail_msg(vty
, imsg
, params
);
1473 ret
= show_nbr_msg_json(imsg
, params
, json
);
1475 ret
= show_nbr_msg(vty
, imsg
, params
);
1479 if (params
->detail
) {
1481 ret
= show_lib_detail_msg_json(imsg
, params
,
1484 ret
= show_lib_detail_msg(vty
, imsg
, params
);
1487 ret
= show_lib_msg_json(imsg
, params
, json
);
1489 ret
= show_lib_msg(vty
, imsg
, params
);
1494 ret
= show_l2vpn_pw_msg_json(imsg
, params
, json
);
1496 ret
= show_l2vpn_pw_msg(vty
, imsg
, params
);
1498 case SHOW_L2VPN_BINDING
:
1500 ret
= show_l2vpn_binding_msg_json(imsg
, params
, json
);
1502 ret
= show_l2vpn_binding_msg(vty
, imsg
, params
);
1512 ldp_vty_dispatch(struct vty
*vty
, struct imsgbuf
*ibuf
, enum show_command cmd
,
1513 struct show_params
*params
)
1516 int n
, done
= 0, ret
= CMD_SUCCESS
;
1517 json_object
*json
= NULL
;
1519 while (ibuf
->w
.queued
)
1520 if (msgbuf_write(&ibuf
->w
) <= 0 && errno
!= EAGAIN
) {
1521 log_warn("write error");
1523 return (CMD_WARNING
);
1527 json
= json_object_new_object();
1530 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
) {
1531 log_warnx("imsg_read error");
1536 log_warnx("pipe closed");
1542 if ((n
= imsg_get(ibuf
, &imsg
)) == -1) {
1543 log_warnx("imsg_get error");
1549 done
= ldp_vty_dispatch_msg(vty
, &imsg
, cmd
, params
,
1558 vty_out(vty
, "%s%s", json_object_to_json_string_ext(json
,
1559 JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1560 json_object_free(json
);
1567 ldp_vty_get_af(const char *str
, int *af
)
1572 } else if (strcmp(str
, "ipv4") == 0) {
1575 } else if (strcmp(str
, "ipv6") == 0) {
1584 ldp_vty_show_binding(struct vty
*vty
, const char *af_str
, int detail
, int json
)
1586 struct imsgbuf ibuf
;
1587 struct show_params params
;
1590 if (ldp_vty_connect(&ibuf
) < 0)
1591 return (CMD_WARNING
);
1593 if (ldp_vty_get_af(af_str
, &af
) < 0)
1594 return (CMD_ERR_NO_MATCH
);
1596 memset(¶ms
, 0, sizeof(params
));
1598 params
.detail
= detail
;
1601 if (!params
.detail
&& !params
.json
)
1602 vty_out(vty
, "%-4s %-20s %-15s %-11s %-13s %6s%s", "AF",
1603 "Destination", "Nexthop", "Local Label", "Remote Label",
1604 "In Use", VTY_NEWLINE
);
1606 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LIB
, 0, 0, -1, NULL
, 0);
1607 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LIB
, ¶ms
));
1611 ldp_vty_show_discovery(struct vty
*vty
, const char *af_str
, int detail
,
1614 struct imsgbuf ibuf
;
1615 struct show_params params
;
1618 if (ldp_vty_connect(&ibuf
) < 0)
1619 return (CMD_WARNING
);
1621 if (ldp_vty_get_af(af_str
, &af
) < 0)
1622 return (CMD_ERR_NO_MATCH
);
1624 memset(¶ms
, 0, sizeof(params
));
1626 params
.detail
= detail
;
1629 if (!params
.detail
&& !params
.json
)
1630 vty_out(vty
, "%-4s %-15s %-8s %-15s %9s%s",
1631 "AF", "ID", "Type", "Source", "Holdtime", VTY_NEWLINE
);
1634 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY_DTL
, 0, 0, -1,
1637 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
1638 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_DISC
, ¶ms
));
1642 ldp_vty_show_interface(struct vty
*vty
, const char *af_str
, int json
)
1644 struct imsgbuf ibuf
;
1645 struct show_params params
;
1646 unsigned int ifidx
= 0;
1649 if (ldp_vty_connect(&ibuf
) < 0)
1650 return (CMD_WARNING
);
1652 if (ldp_vty_get_af(af_str
, &af
) < 0)
1653 return (CMD_ERR_NO_MATCH
);
1655 memset(¶ms
, 0, sizeof(params
));
1661 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3s%s", "AF",
1662 "Interface", "State", "Uptime", "Hello Timers", "ac",
1666 imsg_compose(&ibuf
, IMSG_CTL_SHOW_INTERFACE
, 0, 0, -1, &ifidx
,
1668 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_IFACE
, ¶ms
));
1672 ldp_vty_show_capabilities(struct vty
*vty
, int json
)
1676 json_object
*json_array
;
1677 json_object
*json_cap
;
1679 json
= json_object_new_object();
1680 json_array
= json_object_new_array();
1681 json_object_object_add(json
, "capabilities", json_array
);
1683 /* Dynamic Announcement (0x0506) */
1684 json_cap
= json_object_new_object();
1685 json_object_string_add(json_cap
, "description",
1686 "Dynamic Announcement");
1687 json_object_string_add(json_cap
, "tlvType",
1689 json_object_array_add(json_array
, json_cap
);
1691 /* Typed Wildcard (0x050B) */
1692 json_cap
= json_object_new_object();
1693 json_object_string_add(json_cap
, "description",
1695 json_object_string_add(json_cap
, "tlvType",
1697 json_object_array_add(json_array
, json_cap
);
1699 /* Unrecognized Notification (0x0603) */
1700 json_cap
= json_object_new_object();
1701 json_object_string_add(json_cap
, "description",
1702 "Unrecognized Notification");
1703 json_object_string_add(json_cap
, "tlvType",
1705 json_object_array_add(json_array
, json_cap
);
1707 vty_out(vty
, "%s%s", json_object_to_json_string_ext(json
,
1708 JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1709 json_object_free(json
);
1714 "Supported LDP Capabilities%s"
1715 " * Dynamic Announcement (0x0506)%s"
1716 " * Typed Wildcard (0x050B)%s"
1717 " * Unrecognized Notification (0x0603)%s%s", VTY_NEWLINE
,
1718 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1724 ldp_vty_show_neighbor(struct vty
*vty
, int capabilities
, int detail
, int json
)
1726 struct imsgbuf ibuf
;
1727 struct show_params params
;
1729 if (ldp_vty_connect(&ibuf
) < 0)
1730 return (CMD_WARNING
);
1732 memset(¶ms
, 0, sizeof(params
));
1733 params
.capabilities
= capabilities
;
1734 params
.detail
= detail
;
1737 if (params
.capabilities
)
1740 if (!params
.detail
&& !params
.json
)
1741 vty_out(vty
, "%-4s %-15s %-11s %-15s %8s%s",
1742 "AF", "ID", "State", "Remote Address", "Uptime",
1745 imsg_compose(&ibuf
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, NULL
, 0);
1746 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_NBR
, ¶ms
));
1750 ldp_vty_show_atom_binding(struct vty
*vty
, int json
)
1752 struct imsgbuf ibuf
;
1753 struct show_params params
;
1755 if (ldp_vty_connect(&ibuf
) < 0)
1756 return (CMD_WARNING
);
1758 memset(¶ms
, 0, sizeof(params
));
1761 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_BINDING
, 0, 0, -1, NULL
, 0);
1762 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_BINDING
, ¶ms
));
1766 ldp_vty_show_atom_vc(struct vty
*vty
, int json
)
1768 struct imsgbuf ibuf
;
1769 struct show_params params
;
1771 if (ldp_vty_connect(&ibuf
) < 0)
1772 return (CMD_WARNING
);
1774 memset(¶ms
, 0, sizeof(params
));
1779 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1780 "Interface", "Peer ID", "VC ID", "Name", "Status",
1782 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1783 "---------", "---------------", "----------",
1784 "----------------", "----------", VTY_NEWLINE
);
1787 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_PW
, 0, 0, -1, NULL
, 0);
1788 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_PW
, ¶ms
));
1792 ldp_vty_clear_nbr(struct vty
*vty
, const char *addr_str
)
1794 struct imsgbuf ibuf
;
1797 memset(&nbr
, 0, sizeof(nbr
));
1799 (ldp_get_address(addr_str
, &nbr
.af
, &nbr
.raddr
) == -1 ||
1800 bad_addr(nbr
.af
, &nbr
.raddr
))) {
1801 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1802 return (CMD_WARNING
);
1805 if (ldp_vty_connect(&ibuf
) < 0)
1806 return (CMD_WARNING
);
1808 imsg_compose(&ibuf
, IMSG_CTL_CLEAR_NBR
, 0, 0, -1, &nbr
, sizeof(nbr
));
1810 while (ibuf
.w
.queued
)
1811 if (msgbuf_write(&ibuf
.w
) <= 0 && errno
!= EAGAIN
) {
1812 log_warn("write error");
1814 return (CMD_WARNING
);
1819 return (CMD_SUCCESS
);