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_outln (vty, "%-4s %-11s %-6s %-8s %-12s %3u",
+ 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);
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_outln (vty, "%9u", adj->holdtime);
+ vty_out (vty, "%9u\n", adj->holdtime);
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_outln (vty, "Local:");
- vty_outln (vty, " LSR Id: %s:0",inet_ntoa(rtr_id));
+ 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_outln (vty, " Transport Address (IPv4): %s",
+ 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_outln (vty, " Transport Address (IPv6): %s",
+ vty_out (vty, " Transport Address (IPv6): %s\n",
log_addr(AF_INET6, &ldpd_conf->ipv6.trans_addr));
- vty_outln (vty, "Discovery Sources:");
- vty_outln (vty, " Interfaces:");
+ vty_out (vty, "Discovery Sources:\n");
+ vty_out (vty, " Interfaces:\n");
vty_out(vty, "%s", ifaces_buffer);
- vty_outln (vty, " Targeted Hellos:");
+ vty_out (vty, " Targeted Hellos:\n");
vty_out(vty, "%s", tnbrs_buffer);
- vty_outln (vty, "");
+ 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_outln (vty, " %8s", log_time(nbr->uptime));
+ 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_outln (vty, "Peer LDP Identifier: %s:0",
+ vty_out (vty, "Peer LDP Identifier: %s:0\n",
inet_ntoa(nbr->id));
- vty_outln (vty, " TCP connection: %s:%u - %s:%u",
+ 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_outln (vty, " Authentication: %s",
+ vty_out (vty, " Authentication: %s\n",
(nbr->auth_method == AUTH_MD5SIG) ? "TCP MD5 Signature" : "none");
- vty_outln(vty, " Session Holdtime: %u secs; "
- "KeepAlive interval: %u secs", nbr->holdtime,
+ vty_out(vty, " Session Holdtime: %u secs; "
+ "KeepAlive interval: %u secs\n", nbr->holdtime,
nbr->holdtime / KEEPALIVE_PER_PERIOD);
- vty_outln(vty, " State: %s; Downstream-Unsolicited",
+ vty_out(vty, " State: %s; Downstream-Unsolicited\n",
nbr_state_name(nbr->nbr_state));
- vty_outln (vty, " Up time: %s",log_time(nbr->uptime));
+ vty_out (vty, " Up time: %s\n",log_time(nbr->uptime));
stats = &nbr->stats;
- vty_outln (vty, " Messages sent/rcvd:");
- vty_outln (vty, " - Keepalive Messages: %u/%u",
+ vty_out (vty, " Messages sent/rcvd:\n");
+ vty_out (vty, " - Keepalive Messages: %u/%u\n",
stats->kalive_sent, stats->kalive_rcvd);
- vty_outln (vty, " - Address Messages: %u/%u",
+ vty_out (vty, " - Address Messages: %u/%u\n",
stats->addr_sent, stats->addr_rcvd);
- vty_outln (vty, " - Address Withdraw Messages: %u/%u",
+ vty_out (vty, " - Address Withdraw Messages: %u/%u\n",
stats->addrwdraw_sent, stats->addrwdraw_rcvd);
- vty_outln (vty, " - Notification Messages: %u/%u",
+ vty_out (vty, " - Notification Messages: %u/%u\n",
stats->notif_sent, stats->notif_rcvd);
- vty_outln (vty, " - Capability Messages: %u/%u",
+ vty_out (vty, " - Capability Messages: %u/%u\n",
stats->capability_sent, stats->capability_rcvd);
- vty_outln (vty, " - Label Mapping Messages: %u/%u",
+ vty_out (vty, " - Label Mapping Messages: %u/%u\n",
stats->labelmap_sent, stats->labelmap_rcvd);
- vty_outln (vty, " - Label Request Messages: %u/%u",
+ vty_out (vty, " - Label Request Messages: %u/%u\n",
stats->labelreq_sent, stats->labelreq_rcvd);
- vty_outln (vty, " - Label Withdraw Messages: %u/%u",
+ vty_out (vty, " - Label Withdraw Messages: %u/%u\n",
stats->labelwdraw_sent, stats->labelwdraw_rcvd);
- vty_outln (vty, " - Label Release Messages: %u/%u",
+ vty_out (vty, " - Label Release Messages: %u/%u\n",
stats->labelrel_sent, stats->labelrel_rcvd);
- vty_outln (vty, " - Label Abort Request Messages: %u/%u",
+ vty_out (vty, " - Label Abort Request Messages: %u/%u\n",
stats->labelabreq_sent, stats->labelabreq_rcvd);
show_nbr_capabilities(vty, nbr);
}
break;
case IMSG_CTL_SHOW_NBR_END:
- vty_outln (vty, " LDP Discovery Sources:");
+ vty_out (vty, " LDP Discovery Sources:\n");
if (v4adjs_buffer[0] != '\0') {
- vty_outln (vty, " IPv4:");
+ vty_out (vty, " IPv4:\n");
vty_out(vty, "%s", v4adjs_buffer);
}
if (v6adjs_buffer[0] != '\0') {
- vty_outln (vty, " IPv6:");
+ vty_out (vty, " IPv6:\n");
vty_out(vty, "%s", v6adjs_buffer);
}
- vty_outln (vty, "");
+ vty_out (vty, "\n");
break;
case IMSG_CTL_END:
return (1);
void
show_nbr_capabilities(struct vty *vty, struct ctl_nbr *nbr)
{
- vty_outln (vty, " Capabilities Sent:%s"
- " - Dynamic Announcement (0x0506)%s"
- " - Typed Wildcard (0x050B)%s"
- " - Unrecognized Notification (0x0603)",
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
- vty_outln (vty, " Capabilities Received:");
+ 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_outln (vty," - Dynamic Announcement (0x0506)");
+ vty_out (vty," - Dynamic Announcement (0x0506)\n");
if (nbr->flags & F_NBR_CAP_TWCARD)
- vty_outln (vty, " - Typed Wildcard (0x050B)");
+ vty_out (vty, " - Typed Wildcard (0x050B)\n");
if (nbr->flags & F_NBR_CAP_UNOTIF)
- vty_outln (vty," - Unrecognized Notification (0x0603)");
+ vty_out (vty," - Unrecognized Notification (0x0603)\n");
}
static int
if (nbr->nbr_state != NBR_STA_OPER)
break;
- vty_outln (vty, "Peer LDP Identifier: %s:0",
+ vty_out (vty, "Peer LDP Identifier: %s:0\n",
inet_ntoa(nbr->id));
show_nbr_capabilities(vty, nbr);
- vty_outln (vty, "");
+ vty_out (vty, "\n");
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_outln (vty, " %-15s %-11s %-13s %6s", 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");
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_outln (vty, "%s", dstnet);
- vty_outln (vty, "%-8sLocal binding: label: %s", "",
- log_label(rt->local_label));
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_outln (vty, "%-8sAdvertised to:", "");
+ vty_out (vty, "%-8sAdvertised to:\n", "");
vty_out(vty, "%s", sent_buffer);
}
if (downstream) {
- vty_outln (vty, "%-8sRemote bindings:", "");
+ vty_out (vty, "%-8sRemote bindings:\n", "");
vty_out(vty, "%s", rcvd_buffer);
} else
- vty_outln (vty, "%-8sNo remote bindings","");
+ vty_out (vty, "%-8sNo remote bindings\n","");
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_outln (vty, " Destination Address: %s, VC ID: %u",
+ 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_outln (vty, " Local Label: %u",
+ vty_out (vty, " Local Label: %u\n",
pw->local_label);
- vty_outln (vty, "%-8sCbit: %u, VC Type: %s, "
- "GroupID: %u", "", pw->local_cword,
+ vty_out (vty, "%-8sCbit: %u, VC Type: %s, "
+ "GroupID: %u\n", "", pw->local_cword,
pw_type_name(pw->type),pw->local_gid);
- vty_outln (vty, "%-8sMTU: %u", "",pw->local_ifmtu);
+ vty_out (vty, "%-8sMTU: %u\n", "",pw->local_ifmtu);
} else
- vty_outln (vty," Local Label: unassigned");
+ vty_out (vty," Local Label: unassigned\n");
/* remote binding */
if (pw->remote_label != NO_LABEL) {
- vty_outln (vty, " Remote Label: %u",
+ vty_out (vty, " Remote Label: %u\n",
pw->remote_label);
- vty_outln (vty, "%-8sCbit: %u, VC Type: %s, "
- "GroupID: %u", "", pw->remote_cword,
+ vty_out (vty, "%-8sCbit: %u, VC Type: %s, "
+ "GroupID: %u\n", "", pw->remote_cword,
pw_type_name(pw->type),pw->remote_gid);
- vty_outln (vty, "%-8sMTU: %u", "",pw->remote_ifmtu);
+ vty_out (vty, "%-8sMTU: %u\n", "",pw->remote_ifmtu);
} else
- vty_outln (vty," Remote Label: unassigned");
+ vty_out (vty," Remote Label: unassigned\n");
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ vty_out (vty, "\n");
return (1);
default:
break;
case IMSG_CTL_SHOW_L2VPN_PW:
pw = imsg->data;
- vty_outln (vty, "%-9s %-15s %-10u %-16s %-10s", 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"));
break;
case IMSG_CTL_END:
- vty_outln (vty, "");
+ 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_l2vpn_pw_msg(vty, imsg, params);
+ 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);
+ }
+
+ 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_l2vpn_binding_msg_json(imsg, params, json);
+ ret = show_lib_detail_msg_json(imsg, params, json);
else
- ret = show_l2vpn_binding_msg(vty, imsg, params);
+ 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);
+ }
+
+ 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_outln (vty, "%s",
+ 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, const char *af_str, int detail, int json)
+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;
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.detail = detail;
- params.json = json;
+ 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_outln (vty, "%-4s %-20s %-15s %-11s %-13s %6s", "AF",
+ vty_out (vty, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF",
"Destination", "Nexthop", "Local Label", "Remote Label",
"In Use");
}
int
-ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail,
- int json)
+ldp_vty_show_discovery(struct vty *vty, const char *af_str, const char *detail,
+ const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.detail = detail;
- params.json = json;
+ params.detail = (detail) ? 1 : 0;
+ params.json = (json) ? 1 : 0;
if (!params.detail && !params.json)
- vty_outln (vty, "%-4s %-15s %-8s %-15s %9s",
+ vty_out (vty, "%-4s %-15s %-8s %-15s %9s\n",
"AF", "ID", "Type", "Source", "Holdtime");
if (params.detail)
}
int
-ldp_vty_show_interface(struct vty *vty, const char *af_str, int json)
+ldp_vty_show_interface(struct vty *vty, const char *af_str, const char *json)
{
struct imsgbuf ibuf;
struct show_params params;
memset(¶ms, 0, sizeof(params));
params.family = af;
- params.json = json;
+ params.json = (json) ? 1 : 0;
/* header */
if (!params.json) {
- vty_outln (vty, "%-4s %-11s %-6s %-8s %-12s %3s", "AF",
+ vty_out (vty, "%-4s %-11s %-6s %-8s %-12s %3s\n", "AF",
"Interface", "State", "Uptime", "Hello Timers","ac");
}
}
int
-ldp_vty_show_capabilities(struct vty *vty, int json)
+ldp_vty_show_capabilities(struct vty *vty, const char *json)
{
if (json) {
json_object *json;
"0x0603");
json_object_array_add(json_array, json_cap);
- vty_outln (vty, "%s",
+ vty_out (vty, "%s\n",
json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
return (0);
}
- vty_outln (vty,
- "Supported LDP Capabilities%s"
- " * Dynamic Announcement (0x0506)%s"
- " * Typed Wildcard (0x050B)%s"
- " * Unrecognized Notification (0x0603)%s", 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, int capabilities, int detail, int json)
+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 = capabilities;
- params.detail = detail;
- params.json = json;
+ 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_outln (vty, "%-4s %-15s %-11s %-15s %8s",
+ 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);
}
int
-ldp_vty_show_atom_binding(struct vty *vty, int json)
+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 = json;
+ 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, int json)
+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 = json;
+ 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_outln (vty, "%-9s %-15s %-10s %-16s %-10s",
+ vty_out (vty, "%-9s %-15s %-10s %-16s %-10s\n",
"Interface", "Peer ID", "VC ID", "Name","Status");
- vty_outln (vty, "%-9s %-15s %-10s %-16s %-10s",
+ vty_out (vty, "%-9s %-15s %-10s %-16s %-10s\n",
"---------", "---------------", "----------",
"----------------", "----------");
}
if (addr_str &&
(ldp_get_address(addr_str, &nbr.af, &nbr.raddr) == -1 ||
bad_addr(nbr.af, &nbr.raddr))) {
- vty_outln (vty, "%% Malformed address");
+ vty_out (vty, "%% Malformed address\n");
return (CMD_WARNING);
}