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
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 void show_discovery_adj(struct vty
*, char *,
60 static int show_discovery_msg(struct vty
*, struct imsg
*,
61 struct show_params
*);
62 static void show_discovery_adj_json(json_object
*,
64 static int show_discovery_msg_json(struct imsg
*,
65 struct show_params
*, json_object
*);
66 static void show_nbr_adj(struct vty
*, char *, struct ctl_adj
*);
67 static int show_nbr_msg(struct vty
*, struct imsg
*,
68 struct show_params
*);
69 static void show_nbr_adj_json(struct ctl_adj
*, json_object
*);
70 static int show_nbr_msg_json(struct imsg
*, struct show_params
*,
72 static int show_lib_msg(struct vty
*, struct imsg
*,
73 struct show_params
*);
74 static int show_lib_msg_json(struct imsg
*, struct show_params
*,
76 static int show_l2vpn_binding_msg(struct vty
*, struct imsg
*,
77 struct show_params
*);
78 static int show_l2vpn_binding_msg_json(struct imsg
*,
79 struct show_params
*, json_object
*);
80 static int show_l2vpn_pw_msg(struct vty
*, struct imsg
*,
81 struct show_params
*);
82 static int show_l2vpn_pw_msg_json(struct imsg
*,
83 struct show_params
*, json_object
*);
84 static int ldp_vty_connect(struct imsgbuf
*);
85 static int ldp_vty_dispatch_msg(struct vty
*, struct imsg
*,
86 enum show_command
, struct show_params
*,
88 static int ldp_vty_dispatch(struct vty
*, struct imsgbuf
*,
89 enum show_command
, struct show_params
*);
90 static int ldp_vty_get_af(const char *, int *);
93 show_interface_msg(struct vty
*vty
, struct imsg
*imsg
,
94 struct show_params
*params
)
96 struct ctl_iface
*iface
;
99 switch (imsg
->hdr
.type
) {
100 case IMSG_CTL_SHOW_INTERFACE
:
103 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
106 snprintf(timers
, sizeof(timers
), "%u/%u",
107 iface
->hello_interval
, iface
->hello_holdtime
);
109 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3u%s",
110 af_name(iface
->af
), iface
->name
,
111 if_state_name(iface
->state
), iface
->uptime
== 0 ?
112 "00:00:00" : log_time(iface
->uptime
), timers
,
113 iface
->adj_cnt
, VTY_NEWLINE
);
116 vty_out(vty
, "%s", VTY_NEWLINE
);
126 show_interface_msg_json(struct imsg
*imsg
, struct show_params
*params
,
129 struct ctl_iface
*iface
;
130 json_object
*json_iface
;
133 switch (imsg
->hdr
.type
) {
134 case IMSG_CTL_SHOW_INTERFACE
:
137 if (params
->family
!= AF_UNSPEC
&& params
->family
!= iface
->af
)
140 json_iface
= json_object_new_object();
141 json_object_string_add(json_iface
, "name", iface
->name
);
142 json_object_string_add(json_iface
, "addressFamily",
144 json_object_string_add(json_iface
, "state",
145 if_state_name(iface
->state
));
146 json_object_string_add(json_iface
, "upTime",
147 log_time(iface
->uptime
));
148 json_object_int_add(json_iface
, "helloInterval",
149 iface
->hello_interval
);
150 json_object_int_add(json_iface
, "helloHoldtime",
151 iface
->hello_holdtime
);
152 json_object_int_add(json_iface
, "adjacencyCount",
155 sprintf(key_name
, "%s: %s", iface
->name
, af_name(iface
->af
));
156 json_object_object_add(json
, key_name
, json_iface
);
168 show_discovery_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
170 size_t buflen
= strlen(buffer
);
172 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
173 " LDP Id: %s:0, Transport address: %s%s",
174 inet_ntoa(adj
->id
), log_addr(adj
->af
,
175 &adj
->trans_addr
), VTY_NEWLINE
);
176 buflen
= strlen(buffer
);
177 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
178 " Hold time: %u sec%s", adj
->holdtime
, VTY_NEWLINE
);
182 show_discovery_msg(struct vty
*vty
, struct imsg
*imsg
,
183 struct show_params
*params
)
186 struct ctl_disc_if
*iface
;
187 struct ctl_disc_tnbr
*tnbr
;
188 struct in_addr rtr_id
;
189 union ldpd_addr
*trans_addr
;
191 static char ifaces_buffer
[LDPBUFSIZ
];
192 static char tnbrs_buffer
[LDPBUFSIZ
];
194 switch (imsg
->hdr
.type
) {
195 case IMSG_CTL_SHOW_DISCOVERY
:
196 ifaces_buffer
[0] = '\0';
197 tnbrs_buffer
[0] = '\0';
199 case IMSG_CTL_SHOW_DISC_IFACE
:
202 if (params
->family
!= AF_UNSPEC
&&
203 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
204 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
207 buflen
= strlen(ifaces_buffer
);
208 snprintf(ifaces_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
209 " %s: %s%s", iface
->name
, (iface
->no_adj
) ?
210 "xmit" : "xmit/recv", VTY_NEWLINE
);
212 case IMSG_CTL_SHOW_DISC_TNBR
:
215 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
218 trans_addr
= &(ldp_af_conf_get(ldpd_conf
,
219 tnbr
->af
))->trans_addr
;
220 buflen
= strlen(tnbrs_buffer
);
221 snprintf(tnbrs_buffer
+ buflen
, LDPBUFSIZ
- buflen
,
222 " %s -> %s: %s%s", log_addr(tnbr
->af
, trans_addr
),
223 log_addr(tnbr
->af
, &tnbr
->addr
), (tnbr
->no_adj
) ? "xmit" :
224 "xmit/recv", VTY_NEWLINE
);
226 case IMSG_CTL_SHOW_DISC_ADJ
:
229 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
234 show_discovery_adj(vty
, ifaces_buffer
, adj
);
237 show_discovery_adj(vty
, tnbrs_buffer
, adj
);
242 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
243 vty_out(vty
, "Local LDP Identifier: %s:0%s", inet_ntoa(rtr_id
),
245 vty_out(vty
, "Discovery Sources:%s", VTY_NEWLINE
);
246 vty_out(vty
, " Interfaces:%s", VTY_NEWLINE
);
247 vty_out(vty
, "%s", ifaces_buffer
);
248 vty_out(vty
, " Targeted Hellos:%s", VTY_NEWLINE
);
249 vty_out(vty
, "%s", tnbrs_buffer
);
250 vty_out(vty
, "%s", VTY_NEWLINE
);
260 show_discovery_adj_json(json_object
*json
, struct ctl_adj
*adj
)
262 json_object
*json_adj
;
263 json_object
*json_array
;
265 json_object_object_get_ex(json
, "adjacencies", &json_array
);
267 json_array
= json_object_new_array();
268 json_object_object_add(json
, "adjacencies", json_array
);
271 json_adj
= json_object_new_object();
272 json_object_string_add(json_adj
, "id", inet_ntoa(adj
->id
));
273 json_object_string_add(json_adj
, "transportAddress", log_addr(adj
->af
,
275 json_object_int_add(json_adj
, "holdtime", adj
->holdtime
);
276 json_object_array_add(json_array
, json_adj
);
280 show_discovery_msg_json(struct imsg
*imsg
, struct show_params
*params
,
284 struct ctl_disc_if
*iface
;
285 struct ctl_disc_tnbr
*tnbr
;
286 struct in_addr rtr_id
;
287 union ldpd_addr
*trans_addr
;
288 json_object
*json_interface
;
289 json_object
*json_target
;
290 static json_object
*json_interfaces
;
291 static json_object
*json_targets
;
292 static json_object
*json_container
;
294 switch (imsg
->hdr
.type
) {
295 case IMSG_CTL_SHOW_DISCOVERY
:
296 rtr_id
.s_addr
= ldp_rtr_id_get(ldpd_conf
);
297 json_object_string_add(json
, "id", inet_ntoa(rtr_id
));
298 json_interfaces
= json_object_new_object();
299 json_object_object_add(json
, "interfaces", json_interfaces
);
300 json_targets
= json_object_new_object();
301 json_object_object_add(json
, "targetedHellos", json_targets
);
302 json_container
= NULL
;
304 case IMSG_CTL_SHOW_DISC_IFACE
:
307 if (params
->family
!= AF_UNSPEC
&&
308 ((params
->family
== AF_INET
&& !iface
->active_v4
) ||
309 (params
->family
== AF_INET6
&& !iface
->active_v6
)))
312 json_interface
= json_object_new_object();
313 json_object_boolean_true_add(json_interface
, "transmit");
315 json_object_boolean_true_add(json_interface
, "receive");
317 json_object_object_add(json_interfaces
, iface
->name
,
319 json_container
= json_interface
;
321 case IMSG_CTL_SHOW_DISC_TNBR
:
324 if (params
->family
!= AF_UNSPEC
&& params
->family
!= tnbr
->af
)
327 trans_addr
= &(ldp_af_conf_get(ldpd_conf
, tnbr
->af
))->trans_addr
;
329 json_target
= json_object_new_object();
330 json_object_string_add(json_target
, "sourceAddress",
331 log_addr(tnbr
->af
, trans_addr
));
332 json_object_boolean_true_add(json_target
, "transmit");
334 json_object_boolean_true_add(json_target
, "receive");
336 json_object_object_add(json_targets
, log_addr(tnbr
->af
,
337 &tnbr
->addr
), json_target
);
338 json_container
= json_target
;
340 case IMSG_CTL_SHOW_DISC_ADJ
:
343 if (params
->family
!= AF_UNSPEC
&& params
->family
!= adj
->af
)
348 show_discovery_adj_json(json_container
, adj
);
351 show_discovery_adj_json(json_container
, adj
);
365 show_nbr_adj(struct vty
*vty
, char *buffer
, struct ctl_adj
*adj
)
367 size_t buflen
= strlen(buffer
);
371 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
372 " Interface: %s%s", adj
->ifname
, VTY_NEWLINE
);
375 snprintf(buffer
+ buflen
, LDPBUFSIZ
- buflen
,
376 " Targeted Hello: %s%s", log_addr(adj
->af
,
377 &adj
->src_addr
), VTY_NEWLINE
);
383 show_nbr_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
387 static char v4adjs_buffer
[LDPBUFSIZ
];
388 static char v6adjs_buffer
[LDPBUFSIZ
];
390 switch (imsg
->hdr
.type
) {
391 case IMSG_CTL_SHOW_NBR
:
394 v4adjs_buffer
[0] = '\0';
395 v6adjs_buffer
[0] = '\0';
396 vty_out(vty
, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr
->id
),
398 vty_out(vty
, " TCP connection: %s:%u - %s:%u%s",
399 log_addr(nbr
->af
, &nbr
->laddr
), ntohs(nbr
->lport
),
400 log_addr(nbr
->af
, &nbr
->raddr
), ntohs(nbr
->rport
),
402 vty_out(vty
, " Session Holdtime: %u sec%s", nbr
->holdtime
,
404 vty_out(vty
, " State: %s; Downstream-Unsolicited%s",
405 nbr_state_name(nbr
->nbr_state
), VTY_NEWLINE
);
406 vty_out(vty
, " Up time: %s%s", log_time(nbr
->uptime
),
409 case IMSG_CTL_SHOW_NBR_DISC
:
414 show_nbr_adj(vty
, v4adjs_buffer
, adj
);
417 show_nbr_adj(vty
, v6adjs_buffer
, adj
);
420 fatalx("show_nbr_msg: unknown af");
423 case IMSG_CTL_SHOW_NBR_END
:
424 vty_out(vty
, " LDP Discovery Sources:%s", VTY_NEWLINE
);
425 if (v4adjs_buffer
[0] != '\0') {
426 vty_out(vty
, " IPv4:%s", VTY_NEWLINE
);
427 vty_out(vty
, "%s", v4adjs_buffer
);
429 if (v6adjs_buffer
[0] != '\0') {
430 vty_out(vty
, " IPv6:%s", VTY_NEWLINE
);
431 vty_out(vty
, "%s", v6adjs_buffer
);
433 vty_out(vty
, "%s", VTY_NEWLINE
);
445 show_nbr_adj_json(struct ctl_adj
*adj
, json_object
*adj_list
)
447 char adj_string
[128];
451 strlcpy(adj_string
, "interface: ", sizeof(adj_string
));
452 strlcat(adj_string
, adj
->ifname
, sizeof(adj_string
));
455 strlcpy(adj_string
, "targetedHello: ", sizeof(adj_string
));
456 strlcat(adj_string
, log_addr(adj
->af
, &adj
->src_addr
),
461 json_object_array_add(adj_list
, json_object_new_string(adj_string
));
465 show_nbr_msg_json(struct imsg
*imsg
, struct show_params
*params
,
470 json_object
*json_nbr
;
471 static json_object
*json_nbr_sources
;
472 static json_object
*json_v4adjs
;
473 static json_object
*json_v6adjs
;
475 switch (imsg
->hdr
.type
) {
476 case IMSG_CTL_SHOW_NBR
:
479 json_nbr
= json_object_new_object();
480 json_object_string_add(json_nbr
, "peerId", inet_ntoa(nbr
->id
));
481 json_object_string_add(json_nbr
, "tcpLocalAddress",
482 log_addr(nbr
->af
, &nbr
->laddr
));
483 json_object_int_add(json_nbr
, "tcpLocalPort",
485 json_object_string_add(json_nbr
, "tcpRemoteAddress",
486 log_addr(nbr
->af
, &nbr
->raddr
));
487 json_object_int_add(json_nbr
, "tcpRemotePort",
489 json_object_int_add(json_nbr
, "holdtime", nbr
->holdtime
);
490 json_object_string_add(json_nbr
, "state",
491 nbr_state_name(nbr
->nbr_state
));
492 json_object_string_add(json_nbr
, "upTime",
493 log_time(nbr
->uptime
));
494 json_object_object_add(json
, inet_ntoa(nbr
->id
), json_nbr
);
496 json_nbr_sources
= json_object_new_object();
497 json_object_object_add(json_nbr
, "discoverySources",
502 case IMSG_CTL_SHOW_NBR_DISC
:
508 json_v4adjs
= json_object_new_array();
509 json_object_object_add(json_nbr_sources
, "ipv4",
512 show_nbr_adj_json(adj
, json_v4adjs
);
516 json_v6adjs
= json_object_new_array();
517 json_object_object_add(json_nbr_sources
, "ipv6",
520 show_nbr_adj_json(adj
, json_v6adjs
);
523 fatalx("show_nbr_msg_json: unknown af");
526 case IMSG_CTL_SHOW_NBR_END
:
538 show_lib_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
543 switch (imsg
->hdr
.type
) {
544 case IMSG_CTL_SHOW_LIB
:
547 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
550 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
551 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
554 vty_out(vty
, "%s%s", dstnet
, VTY_NEWLINE
);
555 vty_out(vty
, "%-8sLocal binding: label: %s%s", "",
556 log_label(rt
->local_label
), VTY_NEWLINE
);
558 if (rt
->remote_label
!= NO_LABEL
) {
559 vty_out(vty
, "%-8sRemote bindings:%s", "",
561 vty_out(vty
, "%-12sPeer Label%s",
563 vty_out(vty
, "%-12s----------------- "
564 "---------%s", "", VTY_NEWLINE
);
566 vty_out(vty
, "%-8sNo remote bindings%s", "",
569 if (rt
->remote_label
!= NO_LABEL
)
570 vty_out(vty
, "%12s%-20s%s%s", "", inet_ntoa(rt
->nexthop
),
571 log_label(rt
->remote_label
), VTY_NEWLINE
);
574 vty_out(vty
, "%s", VTY_NEWLINE
);
584 show_lib_msg_json(struct imsg
*imsg
, struct show_params
*params
,
589 static json_object
*json_binding
;
590 static json_object
*json_remote_labels
;
591 json_object
*json_remote_label
;
593 switch (imsg
->hdr
.type
) {
594 case IMSG_CTL_SHOW_LIB
:
597 if (params
->family
!= AF_UNSPEC
&& params
->family
!= rt
->af
)
600 snprintf(dstnet
, sizeof(dstnet
), "%s/%d",
601 log_addr(rt
->af
, &rt
->prefix
), rt
->prefixlen
);
604 json_binding
= json_object_new_object();
605 json_object_string_add(json_binding
, "localLabel",
606 log_label(rt
->local_label
));
608 json_remote_labels
= json_object_new_array();
609 json_object_object_add(json_binding
, "remoteLabels",
611 json_object_object_add(json
, dstnet
, json_binding
);
614 if (rt
->remote_label
!= NO_LABEL
) {
615 json_remote_label
= json_object_new_object();
616 json_object_string_add(json_remote_label
, "nexthop",
617 inet_ntoa(rt
->nexthop
));
618 json_object_string_add(json_remote_label
, "label",
619 log_label(rt
->remote_label
));
620 json_object_array_add(json_remote_labels
,
634 show_l2vpn_binding_msg(struct vty
*vty
, struct imsg
*imsg
,
635 struct show_params
*params
)
639 switch (imsg
->hdr
.type
) {
640 case IMSG_CTL_SHOW_L2VPN_BINDING
:
643 vty_out(vty
, " Destination Address: %s, VC ID: %u%s",
644 inet_ntoa(pw
->lsr_id
), pw
->pwid
, VTY_NEWLINE
);
647 if (pw
->local_label
!= NO_LABEL
) {
648 vty_out(vty
, " Local Label: %u%s", pw
->local_label
,
650 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
651 "GroupID: %u%s", "", pw
->local_cword
,
652 pw_type_name(pw
->type
), pw
->local_gid
,
654 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->local_ifmtu
,
657 vty_out(vty
, " Local Label: unassigned%s",
661 if (pw
->remote_label
!= NO_LABEL
) {
662 vty_out(vty
, " Remote Label: %u%s",
663 pw
->remote_label
, VTY_NEWLINE
);
664 vty_out(vty
, "%-8sCbit: %u, VC Type: %s, "
665 "GroupID: %u%s", "", pw
->remote_cword
,
666 pw_type_name(pw
->type
), pw
->remote_gid
,
668 vty_out(vty
, "%-8sMTU: %u%s", "", pw
->remote_ifmtu
,
671 vty_out(vty
, " Remote Label: unassigned%s",
675 vty_out(vty
, "%s", VTY_NEWLINE
);
685 show_l2vpn_binding_msg_json(struct imsg
*imsg
, struct show_params
*params
,
689 json_object
*json_pw
;
692 switch (imsg
->hdr
.type
) {
693 case IMSG_CTL_SHOW_L2VPN_BINDING
:
696 json_pw
= json_object_new_object();
697 json_object_string_add(json_pw
, "destination",
698 inet_ntoa(pw
->lsr_id
));
699 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
702 if (pw
->local_label
!= NO_LABEL
) {
703 json_object_int_add(json_pw
, "localLabel",
705 json_object_int_add(json_pw
, "localControlWord",
707 json_object_string_add(json_pw
, "localVcType",
708 pw_type_name(pw
->type
));
709 json_object_int_add(json_pw
, "localGroupID",
711 json_object_int_add(json_pw
, "localIfMtu",
714 json_object_string_add(json_pw
, "localLabel",
718 if (pw
->remote_label
!= NO_LABEL
) {
719 json_object_int_add(json_pw
, "remoteLabel",
721 json_object_int_add(json_pw
, "remoteControlWord",
723 json_object_string_add(json_pw
, "remoteVcType",
724 pw_type_name(pw
->type
));
725 json_object_int_add(json_pw
, "remoteGroupID",
727 json_object_int_add(json_pw
, "remoteIfMtu",
730 json_object_string_add(json_pw
, "remoteLabel",
733 sprintf(key_name
, "%s: %u", inet_ntoa(pw
->lsr_id
), pw
->pwid
);
734 json_object_object_add(json
, key_name
, json_pw
);
746 show_l2vpn_pw_msg(struct vty
*vty
, struct imsg
*imsg
, struct show_params
*params
)
750 switch (imsg
->hdr
.type
) {
751 case IMSG_CTL_SHOW_L2VPN_PW
:
754 vty_out(vty
, "%-9s %-15s %-10u %-16s %-10s%s", pw
->ifname
,
755 inet_ntoa(pw
->lsr_id
), pw
->pwid
, pw
->l2vpn_name
,
756 (pw
->status
? "UP" : "DOWN"), VTY_NEWLINE
);
759 vty_out(vty
, "%s", VTY_NEWLINE
);
769 show_l2vpn_pw_msg_json(struct imsg
*imsg
, struct show_params
*params
,
773 json_object
*json_pw
;
775 switch (imsg
->hdr
.type
) {
776 case IMSG_CTL_SHOW_L2VPN_PW
:
779 json_pw
= json_object_new_object();
780 json_object_string_add(json_pw
, "peerId", inet_ntoa(pw
->lsr_id
));
781 json_object_int_add(json_pw
, "vcId", pw
->pwid
);
782 json_object_string_add(json_pw
, "VpnName", pw
->l2vpn_name
);
784 json_object_string_add(json_pw
, "status", "up");
786 json_object_string_add(json_pw
, "status", "down");
787 json_object_object_add(json
, pw
->ifname
, json_pw
);
799 ldp_vty_connect(struct imsgbuf
*ibuf
)
801 struct sockaddr_un s_un
;
804 /* connect to ldpd control socket */
805 if ((ctl_sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
806 log_warn("%s: socket", __func__
);
810 memset(&s_un
, 0, sizeof(s_un
));
811 s_un
.sun_family
= AF_UNIX
;
812 strlcpy(s_un
.sun_path
, ctl_sock_path
, sizeof(s_un
.sun_path
));
813 if (connect(ctl_sock
, (struct sockaddr
*)&s_un
, sizeof(s_un
)) == -1) {
814 log_warn("%s: connect: %s", __func__
, ctl_sock_path
);
819 imsg_init(ibuf
, ctl_sock
);
825 ldp_vty_dispatch_msg(struct vty
*vty
, struct imsg
*imsg
, enum show_command cmd
,
826 struct show_params
*params
, json_object
*json
)
831 return (show_interface_msg_json(imsg
, params
, json
));
832 return (show_interface_msg(vty
, imsg
, params
));
835 return (show_discovery_msg_json(imsg
, params
, json
));
836 return (show_discovery_msg(vty
, imsg
, params
));
839 return (show_nbr_msg_json(imsg
, params
, json
));
840 return (show_nbr_msg(vty
, imsg
, params
));
843 return (show_lib_msg_json(imsg
, params
, json
));
844 return (show_lib_msg(vty
, imsg
, params
));
847 return (show_l2vpn_pw_msg_json(imsg
, params
, json
));
848 return (show_l2vpn_pw_msg(vty
, imsg
, params
));
849 case SHOW_L2VPN_BINDING
:
851 return (show_l2vpn_binding_msg_json(imsg
, params
, json
));
852 return (show_l2vpn_binding_msg(vty
, imsg
, params
));
859 ldp_vty_dispatch(struct vty
*vty
, struct imsgbuf
*ibuf
, enum show_command cmd
,
860 struct show_params
*params
)
863 int n
, done
= 0, ret
= CMD_SUCCESS
;
864 json_object
*json
= NULL
;
866 while (ibuf
->w
.queued
)
867 if (msgbuf_write(&ibuf
->w
) <= 0 && errno
!= EAGAIN
) {
868 log_warn("write error");
870 return (CMD_WARNING
);
874 json
= json_object_new_object();
877 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
) {
878 log_warnx("imsg_read error");
883 log_warnx("pipe closed");
889 if ((n
= imsg_get(ibuf
, &imsg
)) == -1) {
890 log_warnx("imsg_get error");
896 done
= ldp_vty_dispatch_msg(vty
, &imsg
, cmd
, params
,
905 vty_out(vty
, "%s%s", json_object_to_json_string_ext(json
,
906 JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
907 json_object_free(json
);
914 ldp_vty_get_af(const char *str
, int *af
)
919 } else if (strcmp(str
, "ipv4") == 0) {
922 } else if (strcmp(str
, "ipv6") == 0) {
931 ldp_vty_show_binding(struct vty
*vty
, struct vty_arg
*args
[])
934 struct show_params params
;
938 if (ldp_vty_connect(&ibuf
) < 0)
939 return (CMD_WARNING
);
941 af_str
= vty_get_arg_value(args
, "address-family");
942 if (ldp_vty_get_af(af_str
, &af
) < 0)
943 return (CMD_ERR_NO_MATCH
);
945 memset(¶ms
, 0, sizeof(params
));
947 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
949 imsg_compose(&ibuf
, IMSG_CTL_SHOW_LIB
, 0, 0, -1, NULL
, 0);
950 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_LIB
, ¶ms
));
954 ldp_vty_show_discovery(struct vty
*vty
, struct vty_arg
*args
[])
957 struct show_params params
;
961 if (ldp_vty_connect(&ibuf
) < 0)
962 return (CMD_WARNING
);
964 af_str
= vty_get_arg_value(args
, "address-family");
965 if (ldp_vty_get_af(af_str
, &af
) < 0)
966 return (CMD_ERR_NO_MATCH
);
968 memset(¶ms
, 0, sizeof(params
));
970 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
972 imsg_compose(&ibuf
, IMSG_CTL_SHOW_DISCOVERY
, 0, 0, -1, NULL
, 0);
973 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_DISC
, ¶ms
));
977 ldp_vty_show_interface(struct vty
*vty
, struct vty_arg
*args
[])
980 struct show_params params
;
981 unsigned int ifidx
= 0;
985 if (ldp_vty_connect(&ibuf
) < 0)
986 return (CMD_WARNING
);
988 af_str
= vty_get_arg_value(args
, "address-family");
989 if (ldp_vty_get_af(af_str
, &af
) < 0)
990 return (CMD_ERR_NO_MATCH
);
992 memset(¶ms
, 0, sizeof(params
));
994 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
998 vty_out(vty
, "%-4s %-11s %-6s %-8s %-12s %3s%s", "AF",
999 "Interface", "State", "Uptime", "Hello Timers", "ac",
1003 imsg_compose(&ibuf
, IMSG_CTL_SHOW_INTERFACE
, 0, 0, -1, &ifidx
,
1005 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_IFACE
, ¶ms
));
1009 ldp_vty_show_neighbor(struct vty
*vty
, struct vty_arg
*args
[])
1011 struct imsgbuf ibuf
;
1012 struct show_params params
;
1014 if (ldp_vty_connect(&ibuf
) < 0)
1015 return (CMD_WARNING
);
1017 memset(¶ms
, 0, sizeof(params
));
1018 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1020 imsg_compose(&ibuf
, IMSG_CTL_SHOW_NBR
, 0, 0, -1, NULL
, 0);
1021 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_NBR
, ¶ms
));
1025 ldp_vty_show_atom_binding(struct vty
*vty
, struct vty_arg
*args
[])
1027 struct imsgbuf ibuf
;
1028 struct show_params params
;
1030 if (ldp_vty_connect(&ibuf
) < 0)
1031 return (CMD_WARNING
);
1033 memset(¶ms
, 0, sizeof(params
));
1034 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1036 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_BINDING
, 0, 0, -1, NULL
, 0);
1037 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_BINDING
, ¶ms
));
1041 ldp_vty_show_atom_vc(struct vty
*vty
, struct vty_arg
*args
[])
1043 struct imsgbuf ibuf
;
1044 struct show_params params
;
1046 if (ldp_vty_connect(&ibuf
) < 0)
1047 return (CMD_WARNING
);
1049 memset(¶ms
, 0, sizeof(params
));
1050 params
.json
= vty_get_arg_value(args
, "json") ? 1 : 0;
1054 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1055 "Interface", "Peer ID", "VC ID", "Name", "Status",
1057 vty_out(vty
, "%-9s %-15s %-10s %-16s %-10s%s",
1058 "---------", "---------------", "----------",
1059 "----------------", "----------", VTY_NEWLINE
);
1062 imsg_compose(&ibuf
, IMSG_CTL_SHOW_L2VPN_PW
, 0, 0, -1, NULL
, 0);
1063 return (ldp_vty_dispatch(vty
, &ibuf
, SHOW_L2VPN_PW
, ¶ms
));
1067 ldp_vty_clear_nbr(struct vty
*vty
, struct vty_arg
*args
[])
1069 struct imsgbuf ibuf
;
1070 const char *addr_str
;
1073 addr_str
= vty_get_arg_value(args
, "addr");
1075 memset(&nbr
, 0, sizeof(nbr
));
1077 (ldp_get_address(addr_str
, &nbr
.af
, &nbr
.raddr
) == -1 ||
1078 bad_addr(nbr
.af
, &nbr
.raddr
))) {
1079 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1080 return (CMD_WARNING
);
1083 if (ldp_vty_connect(&ibuf
) < 0)
1084 return (CMD_WARNING
);
1086 imsg_compose(&ibuf
, IMSG_CTL_CLEAR_NBR
, 0, 0, -1, &nbr
, sizeof(nbr
));
1088 while (ibuf
.w
.queued
)
1089 if (msgbuf_write(&ibuf
.w
) <= 0 && errno
!= EAGAIN
) {
1090 log_warn("write error");
1092 return (CMD_WARNING
);
1097 return (CMD_SUCCESS
);