diff options
Diffstat (limited to 'zebra/zebra_vty.c')
| -rw-r--r-- | zebra/zebra_vty.c | 278 |
1 files changed, 112 insertions, 166 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 86ec2ffef3..ccc6e9e46b 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -62,7 +62,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id); + unsigned short ospf_instance_id, uint32_t tableid); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast, bool use_fib, bool show_ng); static void vty_show_ip_route_summary(struct vty *vty, @@ -131,7 +131,7 @@ DEFUN (show_ip_rpf, { bool uj = use_json(argc, argv); return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST, - false, uj, 0, NULL, false, 0, 0); + false, uj, 0, NULL, false, 0, 0, 0); } DEFUN (show_ip_rpf_addr, @@ -241,30 +241,18 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, vty_out(vty, "\n"); time_t uptime; - struct tm *tm; uptime = monotime(NULL); uptime -= re->uptime; - tm = gmtime(&uptime); - vty_out(vty, " Last update "); + frrtime_to_interval(uptime, buf, sizeof(buf)); - if (uptime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); - vty_out(vty, " ago\n"); + vty_out(vty, " Last update %s ago\n", buf); if (show_ng) vty_out(vty, " Nexthop Group ID: %u\n", re->nhe_id); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { char addrstr[32]; vty_out(vty, " %c%s", @@ -286,7 +274,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out(vty, " %s", inet_ntop(AF_INET6, &nexthop->gate.ipv6, - buf, sizeof buf)); + buf, sizeof(buf))); if (nexthop->ifindex) vty_out(vty, ", via %s", ifindex2ifname( @@ -348,7 +336,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, - addrstr, sizeof addrstr)) + addrstr, sizeof(addrstr))) vty_out(vty, ", src %s", addrstr); } @@ -359,7 +347,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, - addrstr, sizeof addrstr)) + addrstr, sizeof(addrstr))) vty_out(vty, ", src %s", addrstr); } @@ -378,7 +366,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, mpls_label2str( nexthop->nh_label->num_labels, nexthop->nh_label->label, buf, - sizeof buf, 1)); + sizeof(buf), 1)); } if (nexthop->weight) @@ -402,14 +390,15 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object *json_route = NULL; json_object *json_labels = NULL; time_t uptime; - struct tm *tm; struct vrf *vrf = NULL; rib_dest_t *dest = rib_dest_from_rnode(rn); struct nexthop_group *nhg; + char up_str[MONOTIME_STRLEN]; uptime = monotime(NULL); uptime -= re->uptime; - tm = gmtime(&uptime); + + frrtime_to_interval(uptime, up_str, sizeof(up_str)); /* If showing fib information, use the fib view of the * nexthops. @@ -417,14 +406,14 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (is_fib) nhg = rib_active_nhg(re); else - nhg = re->nhe->nhg; + nhg = &(re->nhe->nhg); if (json) { json_route = json_object_new_object(); json_nexthops = json_object_new_array(); json_object_string_add(json_route, "prefix", - srcdest_rnode2str(rn, buf, sizeof buf)); + srcdest_rnode2str(rn, buf, sizeof(buf))); json_object_string_add(json_route, "protocol", zebra_route_string(re->type)); @@ -470,22 +459,12 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_int_add(json_route, "internalFlags", re->flags); json_object_int_add(json_route, "internalNextHopNum", - nexthop_group_nexthop_num(re->nhe->nhg)); + nexthop_group_nexthop_num(&(re->nhe->nhg))); json_object_int_add(json_route, "internalNextHopActiveNum", nexthop_group_active_nexthop_num( - re->nhe->nhg)); - if (uptime < ONE_DAY_SECOND) - sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); + &(re->nhe->nhg))); - json_object_string_add(json_route, "uptime", buf); + json_object_string_add(json_route, "uptime", up_str); for (ALL_NEXTHOPS_PTR(nhg, nexthop)) { json_nexthop = json_object_new_object(); @@ -526,7 +505,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_string_add( json_nexthop, "ip", inet_ntop(AF_INET6, &nexthop->gate.ipv6, - buf, sizeof buf)); + buf, sizeof(buf))); json_object_string_add(json_nexthop, "afi", "ipv6"); @@ -606,7 +585,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, - sizeof buf)) + sizeof(buf))) json_object_string_add( json_nexthop, "source", buf); @@ -618,7 +597,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, - sizeof buf)) + sizeof(buf))) json_object_string_add( json_nexthop, "source", buf); @@ -667,7 +646,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, ? '>' : ' ', re_status_output_char(re, nexthop), - srcdest_rnode2str(rn, buf, sizeof buf)); + srcdest_rnode2str(rn, buf, sizeof(buf))); /* Distance and metric display. */ if (((re->type == ZEBRA_ROUTE_CONNECT) && @@ -694,7 +673,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out(vty, " via %s", inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, - sizeof buf)); + sizeof(buf))); if (nexthop->ifindex) vty_out(vty, ", %s", ifindex2ifname(nexthop->ifindex, @@ -750,7 +729,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV4_IFINDEX: if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, - sizeof buf)) + sizeof(buf))) vty_out(vty, ", src %s", buf); } break; @@ -758,7 +737,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, - sizeof buf)) + sizeof(buf))) vty_out(vty, ", src %s", buf); } break; @@ -771,20 +750,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, vty_out(vty, ", label %s", mpls_label2str(nexthop->nh_label->num_labels, nexthop->nh_label->label, buf, - sizeof buf, 1)); + sizeof(buf), 1)); } - if (uptime < ONE_DAY_SECOND) - vty_out(vty, ", %02d:%02d:%02d", tm->tm_hour, - tm->tm_min, tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, ", %dd%02dh%02dm", tm->tm_yday, - tm->tm_hour, tm->tm_min); - else - vty_out(vty, ", %02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); - vty_out(vty, "\n"); + vty_out(vty, ", %s\n", up_str); } } @@ -915,12 +884,40 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } } +static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, + afi_t afi, bool use_fib, bool use_json, + route_tag_t tag, + const struct prefix *longer_prefix_p, + bool supernets_only, int type, + unsigned short ospf_instance_id) +{ + struct zebra_router_table *zrt; + rib_table_info_t *info; + + RB_FOREACH (zrt, zebra_router_table_head, + &zrouter.tables) { + info = route_table_get_info(zrt->table); + + if (zvrf != info->zvrf) + continue; + if (zrt->afi != afi || + zrt->safi != SAFI_UNICAST) + continue; + + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, use_fib, use_json, + tag, longer_prefix_p, + supernets_only, type, + ospf_instance_id, zrt->tableid); + } +} + static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, safi_t safi, bool use_fib, bool use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id) + unsigned short ospf_instance_id, uint32_t tableid) { struct route_table *table; struct zebra_vrf *zvrf = NULL; @@ -941,7 +938,10 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, return CMD_SUCCESS; } - table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); + if (tableid) + table = zebra_router_find_table(zvrf, tableid, afi, SAFI_UNICAST); + else + table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); if (!table) { if (use_json) vty_out(vty, "{}\n"); @@ -950,98 +950,11 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, - ospf_instance_id, use_json, 0); - - return CMD_SUCCESS; -} - -DEFPY (show_route_table, - show_route_table_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - struct route_table *t; - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); - - return CMD_SUCCESS; -} - -DEFPY (show_route_table_vrf, - show_route_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table vrf NAME$vrf_name [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - VRF_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf; - struct route_table *t; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (vrf_name) - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); + ospf_instance_id, use_json, tableid); return CMD_SUCCESS; } -DEFPY (show_route_all_table_vrf, - show_route_all_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route [vrf <NAME$vrf_name|all$vrf_all>] tables [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Display all tables\n" - VRF_FULL_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = NULL; - vrf_id_t vrf_id = VRF_UNKNOWN; - struct zebra_router_table *zrt; - - if (vrf_name) { - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - } - - RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) { - rib_table_info_t *info = route_table_get_info(zrt->table); - - if (zvrf && zvrf != info->zvrf) - continue; - if (zrt->afi != afi || zrt->safi != SAFI_UNICAST) - continue; - - do_show_route_helper(vty, info->zvrf, zrt->table, afi, false, 0, - false, false, 0, 0, !!json, zrt->tableid); - } - return CMD_SUCCESS; -} - DEFPY (show_ip_nht, show_ip_nht_cmd, "show <ip$ipv4|ipv6$ipv6> <nht|import-check>$type [<A.B.C.D|X:X::X:X>$addr|vrf NAME$vrf_name [<A.B.C.D|X:X::X:X>$addr]|vrf all$vrf_all]", @@ -1149,7 +1062,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe) vty_out(vty, "\n"); } - for (ALL_NEXTHOPS_PTR(nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(nhe->nhg, nexthop)) { if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) vty_out(vty, " "); else @@ -1512,7 +1425,8 @@ DEFPY (show_route, show_route_cmd, "show\ <\ - ip$ipv4 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + ip$ipv4 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |A.B.C.D/M$prefix longer-prefixes\ @@ -1522,7 +1436,8 @@ DEFPY (show_route, " FRR_IP_REDIST_STR_ZEBRA "$type_str\ |ospf$type_str (1-65535)$ospf_instance_id\ >]\ - |ipv6$ipv6 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + |ipv6$ipv6 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |X:X::X:X/M$prefix longer-prefixes\ @@ -1534,6 +1449,9 @@ DEFPY (show_route, IP_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1546,6 +1464,9 @@ DEFPY (show_route, IPV6_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1557,7 +1478,19 @@ DEFPY (show_route, afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct vrf *vrf; int type = 0; + struct zebra_vrf *zvrf; + if (!vrf_is_backend_netns()) { + if ((vrf_all || vrf_name) && (table || table_all)) { + if (!!json) + vty_out(vty, "{}\n"); + else { + vty_out(vty, "Linux vrf backend already points to table id\n"); + vty_out(vty, "Either remove table parameter or vrf parameter\n"); + } + return CMD_SUCCESS; + } + } if (type_str) { type = proto_redistnum(afi, type_str); if (type < 0) { @@ -1568,17 +1501,22 @@ DEFPY (show_route, if (vrf_all) { RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - struct zebra_vrf *zvrf; - struct route_table *table; - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) + || (zvrf->table[afi][SAFI_UNICAST] == NULL)) continue; - do_show_ip_route( - vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, !!fib, !!json, tag, + prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id, table); } } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -1586,9 +1524,21 @@ DEFPY (show_route, if (vrf_name) VRF_GET_ID(vrf_id, vrf_name, !!json); vrf = vrf_lookup_by_id(vrf_id); - do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (vrf) + zvrf = vrf->info; + if (!vrf || !zvrf) + return CMD_SUCCESS; + + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, + !!json, tag, prefix_str ? prefix : NULL, + !!supernets_only, type, ospf_instance_id, table); } return CMD_SUCCESS; @@ -1970,7 +1920,7 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, fib_cnt[ZEBRA_ROUTE_TOTAL]++; fib_cnt[re->type]++; } - for (nexthop = re->nhe->nhg->nexthop; (!cnt && nexthop); + for (nexthop = re->nhe->nhg.nexthop; (!cnt && nexthop); nexthop = nexthop->next) { cnt++; rib_cnt[ZEBRA_ROUTE_TOTAL]++; @@ -3539,10 +3489,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_vrf_cmd); install_element(VIEW_NODE, &show_vrf_vni_cmd); install_element(VIEW_NODE, &show_route_cmd); - install_element(VIEW_NODE, &show_route_table_cmd); - if (vrf_is_backend_netns()) - install_element(VIEW_NODE, &show_route_table_vrf_cmd); - install_element(VIEW_NODE, &show_route_all_table_vrf_cmd); install_element(VIEW_NODE, &show_route_detail_cmd); install_element(VIEW_NODE, &show_route_summary_cmd); install_element(VIEW_NODE, &show_ip_nht_cmd); |
