/*
* Copyright (C) 2016 by Open Source Routing.
*
- * This file is part of GNU Zebra.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
+ * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING. If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * along with this program; see the file COPYING; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301 USA
*/
#include <zebra.h>
int family;
union ldpd_addr addr;
uint8_t prefixlen;
- int capabilities;
int detail;
int json;
+ union {
+ struct {
+ struct in_addr lsr_id;
+ int capabilities;
+ } neighbor;
+ struct {
+ struct prefix prefix;
+ int longer_prefixes;
+ struct in_addr neighbor;
+ uint32_t local_label;
+ uint32_t remote_label;
+ } lib;
+ struct {
+ struct in_addr peer;
+ uint32_t local_label;
+ uint32_t remote_label;
+ char ifname[IFNAMSIZ];
+ uint32_t vcid;
+ } l2vpn;
+ };
};
#define LDPBUFSIZ 65535
snprintf(timers, sizeof(timers), "%u/%u",
iface->hello_interval, iface->hello_holdtime);
- vty_out(vty, "%-4s %-11s %-6s %-8s %-12s %3u%s",
+ vty_out (vty, "%-4s %-11s %-6s %-8s %-12s %3u\n",
af_name(iface->af), iface->name,
if_state_name(iface->state), iface->uptime == 0 ?
"00:00:00" : log_time(iface->uptime), timers,
- iface->adj_cnt, VTY_NEWLINE);
+ iface->adj_cnt);
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
vty_out(vty, "%-8s %-15s ", "Targeted", addr);
if (strlen(addr) > 15)
- vty_out(vty, "%s%46s", VTY_NEWLINE, " ");
+ vty_out(vty, "\n%46s", " ");
break;
}
- vty_out(vty, "%9u%s", adj->holdtime, VTY_NEWLINE);
+ vty_out (vty, "%9u\n", adj->holdtime);
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
size_t buflen = strlen(buffer);
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " LSR Id: %s:0%s", inet_ntoa(adj->id), VTY_NEWLINE);
+ " LSR Id: %s:0\n", inet_ntoa(adj->id));
buflen = strlen(buffer);
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Source address: %s%s",
- log_addr(adj->af, &adj->src_addr), VTY_NEWLINE);
+ " Source address: %s\n",
+ log_addr(adj->af, &adj->src_addr));
buflen = strlen(buffer);
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Transport address: %s%s",
- log_addr(adj->af, &adj->trans_addr), VTY_NEWLINE);
+ " Transport address: %s\n",
+ log_addr(adj->af, &adj->trans_addr));
buflen = strlen(buffer);
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Hello hold time: %u secs (due in %u secs)%s",
- adj->holdtime, adj->holdtime_remaining, VTY_NEWLINE);
+ " Hello hold time: %u secs (due in %u secs)\n",
+ adj->holdtime, adj->holdtime_remaining);
buflen = strlen(buffer);
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Dual-stack capability TLV: %s%s",
- (adj->ds_tlv) ? "yes" : "no", VTY_NEWLINE);
+ " Dual-stack capability TLV: %s\n",
+ (adj->ds_tlv) ? "yes" : "no");
}
static int
buflen = strlen(ifaces_buffer);
snprintf(ifaces_buffer + buflen, LDPBUFSIZ - buflen,
- " %s: %s%s", iface->name, (iface->no_adj) ?
- "(no adjacencies)" : "", VTY_NEWLINE);
+ " %s: %s\n", iface->name, (iface->no_adj) ?
+ "(no adjacencies)" : "");
break;
case IMSG_CTL_SHOW_DISC_TNBR:
tnbr = imsg->data;
tnbr->af))->trans_addr;
buflen = strlen(tnbrs_buffer);
snprintf(tnbrs_buffer + buflen, LDPBUFSIZ - buflen,
- " %s -> %s: %s%s", log_addr(tnbr->af, trans_addr),
+ " %s -> %s: %s\n", log_addr(tnbr->af, trans_addr),
log_addr(tnbr->af, &tnbr->addr), (tnbr->no_adj) ?
- "(no adjacencies)" : "", VTY_NEWLINE);
+ "(no adjacencies)" : "");
break;
case IMSG_CTL_SHOW_DISC_ADJ:
adj = imsg->data;
break;
case IMSG_CTL_END:
rtr_id.s_addr = ldp_rtr_id_get(ldpd_conf);
- vty_out(vty, "Local:%s", VTY_NEWLINE);
- vty_out(vty, " LSR Id: %s:0%s", inet_ntoa(rtr_id),
- VTY_NEWLINE);
+ vty_out (vty, "Local:\n");
+ vty_out (vty, " LSR Id: %s:0\n",inet_ntoa(rtr_id));
if (ldpd_conf->ipv4.flags & F_LDPD_AF_ENABLED)
- vty_out(vty, " Transport Address (IPv4): %s%s",
- log_addr(AF_INET, &ldpd_conf->ipv4.trans_addr),
- VTY_NEWLINE);
+ vty_out (vty, " Transport Address (IPv4): %s\n",
+ log_addr(AF_INET, &ldpd_conf->ipv4.trans_addr));
if (ldpd_conf->ipv6.flags & F_LDPD_AF_ENABLED)
- vty_out(vty, " Transport Address (IPv6): %s%s",
- log_addr(AF_INET6, &ldpd_conf->ipv6.trans_addr),
- VTY_NEWLINE);
- vty_out(vty, "Discovery Sources:%s", VTY_NEWLINE);
- vty_out(vty, " Interfaces:%s", VTY_NEWLINE);
+ vty_out (vty, " Transport Address (IPv6): %s\n",
+ log_addr(AF_INET6, &ldpd_conf->ipv6.trans_addr));
+ vty_out (vty, "Discovery Sources:\n");
+ vty_out (vty, " Interfaces:\n");
vty_out(vty, "%s", ifaces_buffer);
- vty_out(vty, " Targeted Hellos:%s", VTY_NEWLINE);
+ vty_out (vty, " Targeted Hellos:\n");
vty_out(vty, "%s", tnbrs_buffer);
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
af_name(nbr->af), inet_ntoa(nbr->id),
nbr_state_name(nbr->nbr_state), addr);
if (strlen(addr) > 15)
- vty_out(vty, "%s%48s", VTY_NEWLINE, " ");
- vty_out(vty, " %8s%s", log_time(nbr->uptime), VTY_NEWLINE);
+ vty_out(vty, "\n%48s", " ");
+ vty_out (vty, " %8s\n", log_time(nbr->uptime));
break;
case IMSG_CTL_END:
return (1);
switch (adj->type) {
case HELLO_LINK:
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Interface: %s%s", adj->ifname, VTY_NEWLINE);
+ " Interface: %s\n", adj->ifname);
break;
case HELLO_TARGETED:
snprintf(buffer + buflen, LDPBUFSIZ - buflen,
- " Targeted Hello: %s%s", log_addr(adj->af,
- &adj->src_addr), VTY_NEWLINE);
+ " Targeted Hello: %s\n", log_addr(adj->af,
+ &adj->src_addr));
break;
}
}
v4adjs_buffer[0] = '\0';
v6adjs_buffer[0] = '\0';
- vty_out(vty, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr->id),
- VTY_NEWLINE);
- vty_out(vty, " TCP connection: %s:%u - %s:%u%s",
+ vty_out (vty, "Peer LDP Identifier: %s:0\n",
+ inet_ntoa(nbr->id));
+ vty_out (vty, " TCP connection: %s:%u - %s:%u\n",
log_addr(nbr->af, &nbr->laddr), ntohs(nbr->lport),
- log_addr(nbr->af, &nbr->raddr), ntohs(nbr->rport),
- VTY_NEWLINE);
- vty_out(vty, " Authentication: %s%s",
- (nbr->auth_method == AUTH_MD5SIG) ? "TCP MD5 Signature" :
- "none", VTY_NEWLINE);
+ log_addr(nbr->af, &nbr->raddr),ntohs(nbr->rport));
+ vty_out (vty, " Authentication: %s\n",
+ (nbr->auth_method == AUTH_MD5SIG) ? "TCP MD5 Signature" : "none");
vty_out(vty, " Session Holdtime: %u secs; "
- "KeepAlive interval: %u secs%s", nbr->holdtime,
- nbr->holdtime / KEEPALIVE_PER_PERIOD, VTY_NEWLINE);
- vty_out(vty, " State: %s; Downstream-Unsolicited%s",
- nbr_state_name(nbr->nbr_state), VTY_NEWLINE);
- vty_out(vty, " Up time: %s%s", log_time(nbr->uptime),
- VTY_NEWLINE);
+ "KeepAlive interval: %u secs\n", nbr->holdtime,
+ nbr->holdtime / KEEPALIVE_PER_PERIOD);
+ vty_out(vty, " State: %s; Downstream-Unsolicited\n",
+ nbr_state_name(nbr->nbr_state));
+ vty_out (vty, " Up time: %s\n",log_time(nbr->uptime));
stats = &nbr->stats;
- vty_out(vty, " Messages sent/rcvd:%s", VTY_NEWLINE);
- vty_out(vty, " - Keepalive Messages: %u/%u%s",
- stats->kalive_sent, stats->kalive_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Address Messages: %u/%u%s",
- stats->addr_sent, stats->addr_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Address Withdraw Messages: %u/%u%s",
- stats->addrwdraw_sent, stats->addrwdraw_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Notification Messages: %u/%u%s",
- stats->notif_sent, stats->notif_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Capability Messages: %u/%u%s",
- stats->capability_sent, stats->capability_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Label Mapping Messages: %u/%u%s",
- stats->labelmap_sent, stats->labelmap_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Label Request Messages: %u/%u%s",
- stats->labelreq_sent, stats->labelreq_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Label Withdraw Messages: %u/%u%s",
- stats->labelwdraw_sent, stats->labelwdraw_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Label Release Messages: %u/%u%s",
- stats->labelrel_sent, stats->labelrel_rcvd, VTY_NEWLINE);
- vty_out(vty, " - Label Abort Request Messages: %u/%u%s",
- stats->labelabreq_sent, stats->labelabreq_rcvd, VTY_NEWLINE);
+ vty_out (vty, " Messages sent/rcvd:\n");
+ vty_out (vty, " - Keepalive Messages: %u/%u\n",
+ stats->kalive_sent, stats->kalive_rcvd);
+ vty_out (vty, " - Address Messages: %u/%u\n",
+ stats->addr_sent, stats->addr_rcvd);
+ vty_out (vty, " - Address Withdraw Messages: %u/%u\n",
+ stats->addrwdraw_sent, stats->addrwdraw_rcvd);
+ vty_out (vty, " - Notification Messages: %u/%u\n",
+ stats->notif_sent, stats->notif_rcvd);
+ vty_out (vty, " - Capability Messages: %u/%u\n",
+ stats->capability_sent, stats->capability_rcvd);
+ vty_out (vty, " - Label Mapping Messages: %u/%u\n",
+ stats->labelmap_sent, stats->labelmap_rcvd);
+ vty_out (vty, " - Label Request Messages: %u/%u\n",
+ stats->labelreq_sent, stats->labelreq_rcvd);
+ vty_out (vty, " - Label Withdraw Messages: %u/%u\n",
+ stats->labelwdraw_sent, stats->labelwdraw_rcvd);
+ vty_out (vty, " - Label Release Messages: %u/%u\n",
+ stats->labelrel_sent, stats->labelrel_rcvd);
+ vty_out (vty, " - Label Abort Request Messages: %u/%u\n",
+ stats->labelabreq_sent, stats->labelabreq_rcvd);
show_nbr_capabilities(vty, nbr);
break;
}
break;
case IMSG_CTL_SHOW_NBR_END:
- vty_out(vty, " LDP Discovery Sources:%s", VTY_NEWLINE);
+ vty_out (vty, " LDP Discovery Sources:\n");
if (v4adjs_buffer[0] != '\0') {
- vty_out(vty, " IPv4:%s", VTY_NEWLINE);
+ vty_out (vty, " IPv4:\n");
vty_out(vty, "%s", v4adjs_buffer);
}
if (v6adjs_buffer[0] != '\0') {
- vty_out(vty, " IPv6:%s", VTY_NEWLINE);
+ vty_out (vty, " IPv6:\n");
vty_out(vty, "%s", v6adjs_buffer);
}
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
break;
case IMSG_CTL_END:
return (1);
void
show_nbr_capabilities(struct vty *vty, struct ctl_nbr *nbr)
{
- vty_out(vty, " Capabilities Sent:%s"
- " - Dynamic Announcement (0x0506)%s"
- " - Typed Wildcard (0x050B)%s"
- " - Unrecognized Notification (0x0603)%s",
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
- vty_out(vty, " Capabilities Received:%s", VTY_NEWLINE);
+ vty_out (vty, " Capabilities Sent:\n"
+ " - Dynamic Announcement (0x0506)\n"
+ " - Typed Wildcard (0x050B)\n"
+ " - Unrecognized Notification (0x0603)\n");
+ vty_out (vty, " Capabilities Received:\n");
if (nbr->flags & F_NBR_CAP_DYNAMIC)
- vty_out(vty, " - Dynamic Announcement (0x0506)%s",
- VTY_NEWLINE);
+ vty_out (vty," - Dynamic Announcement (0x0506)\n");
if (nbr->flags & F_NBR_CAP_TWCARD)
- vty_out(vty, " - Typed Wildcard (0x050B)%s", VTY_NEWLINE);
+ vty_out (vty, " - Typed Wildcard (0x050B)\n");
if (nbr->flags & F_NBR_CAP_UNOTIF)
- vty_out(vty, " - Unrecognized Notification (0x0603)%s",
- VTY_NEWLINE);
+ vty_out (vty," - Unrecognized Notification (0x0603)\n");
}
static int
if (nbr->nbr_state != NBR_STA_OPER)
break;
- vty_out(vty, "Peer LDP Identifier: %s:0%s", inet_ntoa(nbr->id),
- VTY_NEWLINE);
+ vty_out (vty, "Peer LDP Identifier: %s:0\n",
+ inet_ntoa(nbr->id));
show_nbr_capabilities(vty, nbr);
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_LIB_BEGIN:
+ rt = imsg->data;
+
+ if (params->lib.remote_label != NO_LABEL &&
+ params->lib.remote_label != rt->remote_label)
+ return (0);
+ /* FALLTHROUGH */
case IMSG_CTL_SHOW_LIB_RCVD:
rt = imsg->data;
!rt->no_downstream)
break;
- if (params->family != AF_UNSPEC && params->family != rt->af)
- break;
-
snprintf(dstnet, sizeof(dstnet), "%s/%d",
log_addr(rt->af, &rt->prefix), rt->prefixlen);
vty_out(vty, "%-4s %-20s", af_name(rt->af), dstnet);
if (strlen(dstnet) > 20)
- vty_out(vty, "%s%25s", VTY_NEWLINE, " ");
- vty_out(vty, " %-15s %-11s %-13s %6s%s", inet_ntoa(rt->nexthop),
+ vty_out(vty, "\n%25s", " ");
+ vty_out (vty, " %-15s %-11s %-13s %6s\n", inet_ntoa(rt->nexthop),
log_label(rt->local_label), log_label(rt->remote_label),
- rt->in_use ? "yes" : "no", VTY_NEWLINE);
+ rt->in_use ? "yes" : "no");
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
show_lib_detail_msg(struct vty *vty, struct imsg *imsg, struct show_params *params)
{
struct ctl_rt *rt = NULL;
- char dstnet[BUFSIZ];
+ static char dstnet[BUFSIZ];
static int upstream, downstream;
size_t buflen;
static char sent_buffer[LDPBUFSIZ];
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_LIB_BEGIN:
- case IMSG_CTL_SHOW_LIB_SENT:
- case IMSG_CTL_SHOW_LIB_RCVD:
- case IMSG_CTL_SHOW_LIB_END:
rt = imsg->data;
- if (params->family != AF_UNSPEC && params->family != rt->af)
- return (0);
- break;
- default:
- break;
- }
- switch (imsg->hdr.type) {
- case IMSG_CTL_SHOW_LIB_BEGIN:
upstream = 0;
downstream = 0;
sent_buffer[0] = '\0';
rcvd_buffer[0] = '\0';
-
snprintf(dstnet, sizeof(dstnet), "%s/%d",
log_addr(rt->af, &rt->prefix), rt->prefixlen);
-
- vty_out(vty, "%s%s", dstnet, VTY_NEWLINE);
- vty_out(vty, "%-8sLocal binding: label: %s%s", "",
- log_label(rt->local_label), VTY_NEWLINE);
break;
case IMSG_CTL_SHOW_LIB_SENT:
+ rt = imsg->data;
+
upstream = 1;
buflen = strlen(sent_buffer);
snprintf(sent_buffer + buflen, LDPBUFSIZ - buflen,
- "%12s%s:0%s", "", inet_ntoa(rt->nexthop), VTY_NEWLINE);
+ "%12s%s:0\n", "", inet_ntoa(rt->nexthop));
break;
case IMSG_CTL_SHOW_LIB_RCVD:
+ rt = imsg->data;
downstream = 1;
buflen = strlen(rcvd_buffer);
snprintf(rcvd_buffer + buflen, LDPBUFSIZ - buflen,
- "%12s%s:0, label %s%s%s", "", inet_ntoa(rt->nexthop),
+ "%12s%s:0, label %s%s\n", "", inet_ntoa(rt->nexthop),
log_label(rt->remote_label),
- rt->in_use ? " (in use)" : "", VTY_NEWLINE);
+ rt->in_use ? " (in use)" : "");
break;
case IMSG_CTL_SHOW_LIB_END:
+ rt = imsg->data;
+
+ if (params->lib.remote_label != NO_LABEL &&
+ !downstream)
+ break;
+ vty_out(vty, "%s\n", dstnet);
+ vty_out(vty, "%-8sLocal binding: label: %s\n", "",
+ log_label(rt->local_label));
if (upstream) {
- vty_out(vty, "%-8sAdvertised to:%s", "", VTY_NEWLINE);
+ vty_out (vty, "%-8sAdvertised to:\n", "");
vty_out(vty, "%s", sent_buffer);
}
if (downstream) {
- vty_out(vty, "%-8sRemote bindings:%s", "", VTY_NEWLINE);
+ vty_out (vty, "%-8sRemote bindings:\n", "");
vty_out(vty, "%s", rcvd_buffer);
} else
- vty_out(vty, "%-8sNo remote bindings%s", "",
- VTY_NEWLINE);
+ vty_out (vty, "%-8sNo remote bindings\n","");
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_LIB_BEGIN:
- case IMSG_CTL_SHOW_LIB_SENT:
- case IMSG_CTL_SHOW_LIB_RCVD:
- case IMSG_CTL_SHOW_LIB_END:
rt = imsg->data;
- if (params->family != AF_UNSPEC && params->family != rt->af)
- return (0);
- break;
- default:
- break;
- }
- switch (imsg->hdr.type) {
- case IMSG_CTL_SHOW_LIB_BEGIN:
snprintf(dstnet, sizeof(dstnet), "%s/%d",
log_addr(rt->af, &rt->prefix), rt->prefixlen);
json_object_object_add(json, dstnet, json_lib_entry);
break;
case IMSG_CTL_SHOW_LIB_SENT:
+ rt = imsg->data;
+
json_adv_label = json_object_new_object();
json_object_string_add(json_adv_label, "neighborId",
inet_ntoa(rt->nexthop));
json_object_array_add(json_adv_labels, json_adv_label);
break;
case IMSG_CTL_SHOW_LIB_RCVD:
+ rt = imsg->data;
+
json_remote_label = json_object_new_object();
json_object_string_add(json_remote_label, "neighborId",
inet_ntoa(rt->nexthop));
case IMSG_CTL_SHOW_L2VPN_BINDING:
pw = imsg->data;
- vty_out(vty, " Destination Address: %s, VC ID: %u%s",
- inet_ntoa(pw->lsr_id), pw->pwid, VTY_NEWLINE);
+ vty_out (vty, " Destination Address: %s, VC ID: %u\n",
+ inet_ntoa(pw->lsr_id), pw->pwid);
/* local binding */
if (pw->local_label != NO_LABEL) {
- vty_out(vty, " Local Label: %u%s", pw->local_label,
- VTY_NEWLINE);
- vty_out(vty, "%-8sCbit: %u, VC Type: %s, "
- "GroupID: %u%s", "", pw->local_cword,
- pw_type_name(pw->type), pw->local_gid,
- VTY_NEWLINE);
- vty_out(vty, "%-8sMTU: %u%s", "", pw->local_ifmtu,
- VTY_NEWLINE);
+ vty_out (vty, " Local Label: %u\n",
+ pw->local_label);
+ vty_out (vty, "%-8sCbit: %u, VC Type: %s, "
+ "GroupID: %u\n", "", pw->local_cword,
+ pw_type_name(pw->type),pw->local_gid);
+ vty_out (vty, "%-8sMTU: %u\n", "",pw->local_ifmtu);
} else
- vty_out(vty, " Local Label: unassigned%s",
- VTY_NEWLINE);
+ vty_out (vty," Local Label: unassigned\n");
/* remote binding */
if (pw->remote_label != NO_LABEL) {
- vty_out(vty, " Remote Label: %u%s",
- pw->remote_label, VTY_NEWLINE);
- vty_out(vty, "%-8sCbit: %u, VC Type: %s, "
- "GroupID: %u%s", "", pw->remote_cword,
- pw_type_name(pw->type), pw->remote_gid,
- VTY_NEWLINE);
- vty_out(vty, "%-8sMTU: %u%s", "", pw->remote_ifmtu,
- VTY_NEWLINE);
+ vty_out (vty, " Remote Label: %u\n",
+ pw->remote_label);
+ vty_out (vty, "%-8sCbit: %u, VC Type: %s, "
+ "GroupID: %u\n", "", pw->remote_cword,
+ pw_type_name(pw->type),pw->remote_gid);
+ vty_out (vty, "%-8sMTU: %u\n", "",pw->remote_ifmtu);
} else
- vty_out(vty, " Remote Label: unassigned%s",
- VTY_NEWLINE);
+ vty_out (vty," Remote Label: unassigned\n");
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
case IMSG_CTL_SHOW_L2VPN_PW:
pw = imsg->data;
- vty_out(vty, "%-9s %-15s %-10u %-16s %-10s%s", pw->ifname,
+ vty_out (vty, "%-9s %-15s %-10u %-16s %-10s\n", pw->ifname,
inet_ntoa(pw->lsr_id), pw->pwid, pw->l2vpn_name,
- (pw->status ? "UP" : "DOWN"), VTY_NEWLINE);
+ (pw->status ? "UP" : "DOWN"));
break;
case IMSG_CTL_END:
- vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out (vty, "\n");
return (1);
default:
break;
}
static int
-ldp_vty_dispatch_msg(struct vty *vty, struct imsg *imsg, enum show_command cmd,
+ldp_vty_dispatch_iface(struct vty *vty, struct imsg *imsg,
struct show_params *params, json_object *json)
{
int ret;
- switch (cmd) {
- case SHOW_IFACE:
+ if (params->json)
+ ret = show_interface_msg_json(imsg, params, json);
+ else
+ ret = show_interface_msg(vty, imsg, params);
+
+ return (ret);
+}
+
+static int
+ldp_vty_dispatch_disc(struct vty *vty, struct imsg *imsg,
+ struct show_params *params, json_object *json)
+{
+ int ret;
+
+ if (params->detail) {
if (params->json)
- ret = show_interface_msg_json(imsg, params, json);
+ ret = show_discovery_detail_msg_json(imsg, params,
+ json);
else
- ret = show_interface_msg(vty, imsg, params);
- break;
- case SHOW_DISC:
- if (params->detail) {
- if (params->json)
- ret = show_discovery_detail_msg_json(imsg,
- params, json);
- else
- ret = show_discovery_detail_msg(vty, imsg,
- params);
- } else {
- if (params->json)
- ret = show_discovery_msg_json(imsg, params,
- json);
- else
- ret = show_discovery_msg(vty, imsg, params);
+ ret = show_discovery_detail_msg(vty, imsg, params);
+ } else {
+ if (params->json)
+ ret = show_discovery_msg_json(imsg, params, json);
+ else
+ ret = show_discovery_msg(vty, imsg, params);
+ }
+
+ return (ret);
+}
+
+static int
+ldp_vty_dispatch_nbr(struct vty *vty, struct imsg *imsg,
+ struct show_params *params, json_object *json)
+{
+ static bool filtered = false;
+ struct ctl_nbr *nbr;
+ int ret;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_NBR:
+ filtered = false;
+ nbr = imsg->data;
+
+ if (params->neighbor.lsr_id.s_addr != INADDR_ANY &&
+ params->neighbor.lsr_id.s_addr != nbr->id.s_addr) {
+ filtered = true;
+ return (0);
}
break;
- case SHOW_NBR:
- if (params->capabilities) {
- if (params->json)
- ret = show_nbr_capabilities_msg_json(imsg,
- params, json);
- else
- ret = show_nbr_capabilities_msg(vty, imsg,
- params);
- } else if (params->detail) {
- if (params->json)
- ret = show_nbr_detail_msg_json(imsg, params,
- json);
- else
- ret = show_nbr_detail_msg(vty, imsg, params);
- } else {
- if (params->json)
- ret = show_nbr_msg_json(imsg, params, json);
- else
- ret = show_nbr_msg(vty, imsg, params);
- }
+ case IMSG_CTL_SHOW_NBR_DISC:
+ case IMSG_CTL_SHOW_NBR_END:
+ if (filtered)
+ return (0);
break;
- case SHOW_LIB:
- if (params->detail) {
- if (params->json)
- ret = show_lib_detail_msg_json(imsg, params,
- json);
- else
- ret = show_lib_detail_msg(vty, imsg, params);
- } else {
- if (params->json)
- ret = show_lib_msg_json(imsg, params, json);
- else
- ret = show_lib_msg(vty, imsg, params);
- }
+ default:
break;
- case SHOW_L2VPN_PW:
+ }
+
+ if (params->neighbor.capabilities) {
if (params->json)
- ret = show_l2vpn_pw_msg_json(imsg, params, json);
+ ret = show_nbr_capabilities_msg_json(imsg, params,
+ json);
+ else
+ ret = show_nbr_capabilities_msg(vty, imsg, params);
+ } else if (params->detail) {
+ if (params->json)
+ ret = show_nbr_detail_msg_json(imsg, params, json);
else
- ret = show_l2vpn_pw_msg(vty, imsg, params);
+ ret = show_nbr_detail_msg(vty, imsg, params);
+ } else {
+ if (params->json)
+ ret = show_nbr_msg_json(imsg, params, json);
+ else
+ ret = show_nbr_msg(vty, imsg, params);
+ }
+
+ return (ret);
+}
+
+static int
+ldp_vty_dispatch_lib(struct vty *vty, struct imsg *imsg,
+ struct show_params *params, json_object *json)
+{
+ static bool filtered = false;
+ struct ctl_rt *rt = NULL;
+ struct prefix prefix;
+ int ret;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_LIB_BEGIN:
+ filtered = false;
break;
- case SHOW_L2VPN_BINDING:
+ case IMSG_CTL_SHOW_LIB_SENT:
+ case IMSG_CTL_SHOW_LIB_RCVD:
+ case IMSG_CTL_SHOW_LIB_END:
+ if (filtered)
+ return (0);
+ break;
+ default:
+ break;
+ }
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_LIB_BEGIN:
+ case IMSG_CTL_SHOW_LIB_SENT:
+ case IMSG_CTL_SHOW_LIB_RCVD:
+ case IMSG_CTL_SHOW_LIB_END:
+ rt = imsg->data;
+
+ if (params->family != AF_UNSPEC && params->family != rt->af) {
+ filtered = true;
+ return (0);
+ }
+
+ prefix.family = rt->af;
+ prefix.prefixlen = rt->prefixlen;
+ memcpy(&prefix.u.val, &rt->prefix, sizeof(prefix.u.val));
+ if (params->lib.prefix.family != AF_UNSPEC) {
+ if (!params->lib.longer_prefixes &&
+ !prefix_same(¶ms->lib.prefix, &prefix)) {
+ filtered = true;
+ return (0);
+ } else if (params->lib.longer_prefixes &&
+ !prefix_match(¶ms->lib.prefix, &prefix)) {
+ filtered = true;
+ return (0);
+ }
+ }
+
+ if (params->lib.local_label != NO_LABEL &&
+ params->lib.local_label != rt->local_label) {
+ filtered = true;
+ return (0);
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_LIB_SENT:
+ case IMSG_CTL_SHOW_LIB_RCVD:
+ if (params->lib.neighbor.s_addr != INADDR_ANY &&
+ params->lib.neighbor.s_addr != rt->nexthop.s_addr)
+ return (0);
+ break;
+ default:
+ break;
+ }
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_LIB_RCVD:
+ if (params->lib.remote_label != NO_LABEL &&
+ params->lib.remote_label != rt->remote_label)
+ return (0);
+ break;
+ default:
+ break;
+ }
+
+ if (params->detail) {
+ if (params->json)
+ ret = show_lib_detail_msg_json(imsg, params, json);
+ else
+ ret = show_lib_detail_msg(vty, imsg, params);
+ } else {
if (params->json)
- ret = show_l2vpn_binding_msg_json(imsg, params, json);
+ ret = show_lib_msg_json(imsg, params, json);
else
- ret = show_l2vpn_binding_msg(vty, imsg, params);
+ ret = show_lib_msg(vty, imsg, params);
+ }
+
+ return (ret);
+}
+
+static int
+ldp_vty_dispatch_l2vpn_pw(struct vty *vty, struct imsg *imsg,
+ struct show_params *params, json_object *json)
+{
+ struct ctl_pw *pw;
+ int ret;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_L2VPN_PW:
+ pw = imsg->data;
+ if (params->l2vpn.peer.s_addr != INADDR_ANY &&
+ params->l2vpn.peer.s_addr != pw->lsr_id.s_addr)
+ return (0);
+ if (params->l2vpn.ifname[0] != '\0' &&
+ strcmp(params->l2vpn.ifname, pw->ifname))
+ return (0);
+ if (params->l2vpn.vcid && params->l2vpn.vcid != pw->pwid)
+ return (0);
break;
default:
- return (0);
+ break;
}
+ if (params->json)
+ ret = show_l2vpn_pw_msg_json(imsg, params, json);
+ else
+ ret = show_l2vpn_pw_msg(vty, imsg, params);
+
return (ret);
}
+static int
+ldp_vty_dispatch_l2vpn_binding(struct vty *vty, struct imsg *imsg,
+ struct show_params *params, json_object *json)
+{
+ struct ctl_pw *pw;
+ int ret;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_L2VPN_BINDING:
+ pw = imsg->data;
+ if (params->l2vpn.peer.s_addr != INADDR_ANY &&
+ params->l2vpn.peer.s_addr != pw->lsr_id.s_addr)
+ return (0);
+ if (params->l2vpn.local_label != NO_LABEL &&
+ params->l2vpn.local_label != pw->local_label)
+ return (0);
+ if (params->l2vpn.remote_label != NO_LABEL &&
+ params->l2vpn.remote_label != pw->remote_label)
+ return (0);
+ break;
+ default:
+ break;
+ }
+
+ if (params->json)
+ ret = show_l2vpn_binding_msg_json(imsg, params, json);
+ else
+ ret = show_l2vpn_binding_msg(vty, imsg, params);
+
+ return (ret);
+}
+
+static int
+ldp_vty_dispatch_msg(struct vty *vty, struct imsg *imsg, enum show_command cmd,
+ struct show_params *params, json_object *json)
+{
+ switch (cmd) {
+ case SHOW_IFACE:
+ return (ldp_vty_dispatch_iface(vty, imsg, params, json));
+ case SHOW_DISC:
+ return (ldp_vty_dispatch_disc(vty, imsg, params, json));
+ case SHOW_NBR:
+ return (ldp_vty_dispatch_nbr(vty, imsg, params, json));
+ case SHOW_LIB:
+ return (ldp_vty_dispatch_lib(vty, imsg, params, json));
+ case SHOW_L2VPN_PW:
+ return (ldp_vty_dispatch_l2vpn_pw(vty, imsg, params, json));
+ case SHOW_L2VPN_BINDING:
+ return (ldp_vty_dispatch_l2vpn_binding(vty, imsg, params,
+ json));
+ default:
+ return (0);
+ }
+}
+
static int
ldp_vty_dispatch(struct vty *vty, struct imsgbuf *ibuf, enum show_command cmd,
struct show_params *params)
done:
close(ibuf->fd);
if (json) {
- vty_out(vty, "%s%s", json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
+ vty_out (vty, "%s\n",
+ json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
int
-ldp_vty_show_binding(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_binding(struct vty *vty, const char *af_str, const char *prefix,
+ int longer_prefixes, const char *neighbor, unsigned long local_label,
+ unsigned long remote_label, const char *detail, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
- const char *af_str;
int af;
if (ldp_vty_connect(&ibuf) < 0)
return (CMD_WARNING);
- af_str = vty_get_arg_value(args, "address-family");
if (ldp_vty_get_af(af_str, &af) < 0)
return (CMD_ERR_NO_MATCH);
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.detail = vty_get_arg_value(args, "detail") ? 1 : 0;
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.detail = (detail) ? 1 : 0;
+ params.json = (json) ? 1 : 0;
+ if (prefix) {
+ (void)str2prefix(prefix, ¶ms.lib.prefix);
+ params.lib.longer_prefixes = longer_prefixes;
+ }
+ if (neighbor &&
+ (inet_pton(AF_INET, neighbor, ¶ms.lib.neighbor) != 1 ||
+ bad_addr_v4(params.lib.neighbor))) {
+ vty_out (vty, "%% Malformed address\n");
+ return (CMD_SUCCESS);
+ }
+ params.lib.local_label = local_label;
+ params.lib.remote_label = remote_label;
if (!params.detail && !params.json)
- vty_out(vty, "%-4s %-20s %-15s %-11s %-13s %6s%s", "AF",
+ vty_out (vty, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF",
"Destination", "Nexthop", "Local Label", "Remote Label",
- "In Use", VTY_NEWLINE);
+ "In Use");
imsg_compose(&ibuf, IMSG_CTL_SHOW_LIB, 0, 0, -1, NULL, 0);
return (ldp_vty_dispatch(vty, &ibuf, SHOW_LIB, ¶ms));
}
int
-ldp_vty_show_discovery(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_discovery(struct vty *vty, const char *af_str, const char *detail,
+ const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
- const char *af_str;
int af;
if (ldp_vty_connect(&ibuf) < 0)
return (CMD_WARNING);
- af_str = vty_get_arg_value(args, "address-family");
if (ldp_vty_get_af(af_str, &af) < 0)
return (CMD_ERR_NO_MATCH);
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.detail = vty_get_arg_value(args, "detail") ? 1 : 0;
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.detail = (detail) ? 1 : 0;
+ params.json = (json) ? 1 : 0;
if (!params.detail && !params.json)
- vty_out(vty, "%-4s %-15s %-8s %-15s %9s%s",
- "AF", "ID", "Type", "Source", "Holdtime", VTY_NEWLINE);
+ vty_out (vty, "%-4s %-15s %-8s %-15s %9s\n",
+ "AF", "ID", "Type", "Source", "Holdtime");
if (params.detail)
imsg_compose(&ibuf, IMSG_CTL_SHOW_DISCOVERY_DTL, 0, 0, -1,
}
int
-ldp_vty_show_interface(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_interface(struct vty *vty, const char *af_str, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
unsigned int ifidx = 0;
- const char *af_str;
int af;
if (ldp_vty_connect(&ibuf) < 0)
return (CMD_WARNING);
- af_str = vty_get_arg_value(args, "address-family");
if (ldp_vty_get_af(af_str, &af) < 0)
return (CMD_ERR_NO_MATCH);
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.json = (json) ? 1 : 0;
/* header */
if (!params.json) {
- vty_out(vty, "%-4s %-11s %-6s %-8s %-12s %3s%s", "AF",
- "Interface", "State", "Uptime", "Hello Timers", "ac",
- VTY_NEWLINE);
+ vty_out (vty, "%-4s %-11s %-6s %-8s %-12s %3s\n", "AF",
+ "Interface", "State", "Uptime", "Hello Timers","ac");
}
imsg_compose(&ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, &ifidx,
}
int
-ldp_vty_show_capabilities(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_capabilities(struct vty *vty, const char *json)
{
- if (vty_get_arg_value(args, "json")) {
+ if (json) {
json_object *json;
json_object *json_array;
json_object *json_cap;
"0x0603");
json_object_array_add(json_array, json_cap);
- vty_out(vty, "%s%s", json_object_to_json_string_ext(json,
- JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
+ vty_out (vty, "%s\n",
+ json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
return (0);
}
- vty_out(vty,
- "Supported LDP Capabilities%s"
- " * Dynamic Announcement (0x0506)%s"
- " * Typed Wildcard (0x050B)%s"
- " * Unrecognized Notification (0x0603)%s%s", VTY_NEWLINE,
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty,
+ "Supported LDP Capabilities\n"
+ " * Dynamic Announcement (0x0506)\n"
+ " * Typed Wildcard (0x050B)\n"
+ " * Unrecognized Notification (0x0603)\n\n");
return (0);
}
int
-ldp_vty_show_neighbor(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_neighbor(struct vty *vty, const char *lsr_id, int capabilities,
+ const char *detail, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
return (CMD_WARNING);
memset(¶ms, 0, sizeof(params));
- params.capabilities = vty_get_arg_value(args, "capabilities") ? 1 : 0;
- params.detail = vty_get_arg_value(args, "detail") ? 1 : 0;
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.detail = (detail) ? 1 : 0;
+ params.json = (json) ? 1 : 0;
+ params.neighbor.capabilities = capabilities;
+ if (lsr_id &&
+ (inet_pton(AF_INET, lsr_id, ¶ms.neighbor.lsr_id) != 1 ||
+ bad_addr_v4(params.neighbor.lsr_id))) {
+ vty_out (vty, "%% Malformed address\n");
+ return (CMD_SUCCESS);
+ }
- if (params.capabilities)
+ if (params.neighbor.capabilities)
params.detail = 1;
if (!params.detail && !params.json)
- vty_out(vty, "%-4s %-15s %-11s %-15s %8s%s",
- "AF", "ID", "State", "Remote Address", "Uptime",
- VTY_NEWLINE);
+ vty_out (vty, "%-4s %-15s %-11s %-15s %8s\n",
+ "AF", "ID", "State", "Remote Address","Uptime");
imsg_compose(&ibuf, IMSG_CTL_SHOW_NBR, 0, 0, -1, NULL, 0);
return (ldp_vty_dispatch(vty, &ibuf, SHOW_NBR, ¶ms));
}
int
-ldp_vty_show_atom_binding(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_atom_binding(struct vty *vty, const char *peer,
+ unsigned long local_label, unsigned long remote_label, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
return (CMD_WARNING);
memset(¶ms, 0, sizeof(params));
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.json = (json) ? 1 : 0;
+ if (peer &&
+ (inet_pton(AF_INET, peer, ¶ms.l2vpn.peer) != 1 ||
+ bad_addr_v4(params.l2vpn.peer))) {
+ vty_out (vty, "%% Malformed address\n");
+ return (CMD_SUCCESS);
+ }
+ params.l2vpn.local_label = local_label;
+ params.l2vpn.remote_label = remote_label;
imsg_compose(&ibuf, IMSG_CTL_SHOW_L2VPN_BINDING, 0, 0, -1, NULL, 0);
return (ldp_vty_dispatch(vty, &ibuf, SHOW_L2VPN_BINDING, ¶ms));
}
int
-ldp_vty_show_atom_vc(struct vty *vty, struct vty_arg *args[])
+ldp_vty_show_atom_vc(struct vty *vty, const char *peer, const char *ifname,
+ const char *vcid, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
return (CMD_WARNING);
memset(¶ms, 0, sizeof(params));
- params.json = vty_get_arg_value(args, "json") ? 1 : 0;
+ params.json = (json) ? 1 : 0;
+ if (peer &&
+ (inet_pton(AF_INET, peer, ¶ms.l2vpn.peer) != 1 ||
+ bad_addr_v4(params.l2vpn.peer))) {
+ vty_out (vty, "%% Malformed address\n");
+ return (CMD_SUCCESS);
+ }
+ if (ifname)
+ strlcpy(params.l2vpn.ifname, ifname,
+ sizeof(params.l2vpn.ifname));
+ if (vcid)
+ params.l2vpn.vcid = atoi(vcid);
if (!params.json) {
/* header */
- vty_out(vty, "%-9s %-15s %-10s %-16s %-10s%s",
- "Interface", "Peer ID", "VC ID", "Name", "Status",
- VTY_NEWLINE);
- vty_out(vty, "%-9s %-15s %-10s %-16s %-10s%s",
+ vty_out (vty, "%-9s %-15s %-10s %-16s %-10s\n",
+ "Interface", "Peer ID", "VC ID", "Name","Status");
+ vty_out (vty, "%-9s %-15s %-10s %-16s %-10s\n",
"---------", "---------------", "----------",
- "----------------", "----------", VTY_NEWLINE);
+ "----------------", "----------");
}
imsg_compose(&ibuf, IMSG_CTL_SHOW_L2VPN_PW, 0, 0, -1, NULL, 0);
}
int
-ldp_vty_clear_nbr(struct vty *vty, struct vty_arg *args[])
+ldp_vty_clear_nbr(struct vty *vty, const char *addr_str)
{
struct imsgbuf ibuf;
- const char *addr_str;
struct ctl_nbr nbr;
- addr_str = vty_get_arg_value(args, "addr");
-
memset(&nbr, 0, sizeof(nbr));
if (addr_str &&
(ldp_get_address(addr_str, &nbr.af, &nbr.raddr) == -1 ||
bad_addr(nbr.af, &nbr.raddr))) {
- vty_out(vty, "%% Malformed address%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed address\n");
return (CMD_WARNING);
}