mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 19:10:35 +00:00
zebra: Add code to display interesting tables
With the ability of zebra to handle random tables, add code to display those tables via the show <ip|ipv6> route table (1-...) [json] command. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
36064c0d9b
commit
ae825b8bf0
@ -74,6 +74,23 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
|
||||||
|
uint32_t tableid, afi_t afi)
|
||||||
|
{
|
||||||
|
struct zebra_ns_tables finder;
|
||||||
|
struct zebra_ns_tables *znst;
|
||||||
|
|
||||||
|
memset(&finder, 0, sizeof(finder));
|
||||||
|
finder.afi = afi;
|
||||||
|
finder.tableid = tableid;
|
||||||
|
znst = RB_FIND(zebra_ns_tables_head, &zns->ns_tables, &finder);
|
||||||
|
|
||||||
|
if (znst)
|
||||||
|
return znst->table;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
||||||
struct zebra_vrf *zvrf, uint32_t tableid,
|
struct zebra_vrf *zvrf, uint32_t tableid,
|
||||||
afi_t afi)
|
afi_t afi)
|
||||||
|
@ -77,6 +77,8 @@ int zebra_ns_init(void);
|
|||||||
int zebra_ns_enable(ns_id_t ns_id, void **info);
|
int zebra_ns_enable(ns_id_t ns_id, void **info);
|
||||||
int zebra_ns_disable(ns_id_t ns_id, void **info);
|
int zebra_ns_disable(ns_id_t ns_id, void **info);
|
||||||
|
|
||||||
|
extern struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
|
||||||
|
uint32_t tableid, afi_t afi);
|
||||||
extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
||||||
struct zebra_vrf *zvrf,
|
struct zebra_vrf *zvrf,
|
||||||
uint32_t tableid, afi_t afi);
|
uint32_t tableid, afi_t afi);
|
||||||
|
@ -1235,46 +1235,21 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
|
static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
|
||||||
safi_t safi, bool use_fib, u_char use_json,
|
struct route_table *table, afi_t afi,
|
||||||
route_tag_t tag,
|
bool use_fib, route_tag_t tag,
|
||||||
const struct prefix *longer_prefix_p,
|
const struct prefix *longer_prefix_p,
|
||||||
bool supernets_only, int type,
|
bool supernets_only, int type,
|
||||||
u_short ospf_instance_id)
|
u_short ospf_instance_id, u_char use_json)
|
||||||
{
|
{
|
||||||
struct route_table *table;
|
|
||||||
rib_dest_t *dest;
|
|
||||||
struct route_node *rn;
|
struct route_node *rn;
|
||||||
struct route_entry *re;
|
struct route_entry *re;
|
||||||
int first = 1;
|
int first = 1;
|
||||||
struct zebra_vrf *zvrf = NULL;
|
rib_dest_t *dest;
|
||||||
char buf[BUFSIZ];
|
|
||||||
json_object *json = NULL;
|
json_object *json = NULL;
|
||||||
json_object *json_prefix = NULL;
|
json_object *json_prefix = NULL;
|
||||||
u_int32_t addr;
|
uint32_t addr;
|
||||||
|
char buf[BUFSIZ];
|
||||||
if (!(zvrf = zebra_vrf_lookup_by_name(vrf_name))) {
|
|
||||||
if (use_json)
|
|
||||||
vty_out(vty, "{}\n");
|
|
||||||
else
|
|
||||||
vty_out(vty, "vrf %s not defined\n", vrf_name);
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zvrf_id(zvrf) == VRF_UNKNOWN) {
|
|
||||||
if (use_json)
|
|
||||||
vty_out(vty, "{}\n");
|
|
||||||
else
|
|
||||||
vty_out(vty, "vrf %s inactive\n", vrf_name);
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
table = zebra_vrf_table(afi, safi, zvrf_id(zvrf));
|
|
||||||
if (!table) {
|
|
||||||
if (use_json)
|
|
||||||
vty_out(vty, "{}\n");
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use_json)
|
if (use_json)
|
||||||
json = json_object_new_object();
|
json = json_object_new_object();
|
||||||
@ -1352,6 +1327,67 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
|
|||||||
json, JSON_C_TO_STRING_PRETTY));
|
json, JSON_C_TO_STRING_PRETTY));
|
||||||
json_object_free(json);
|
json_object_free(json);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
|
||||||
|
safi_t safi, bool use_fib, u_char use_json,
|
||||||
|
route_tag_t tag,
|
||||||
|
const struct prefix *longer_prefix_p,
|
||||||
|
bool supernets_only, int type,
|
||||||
|
u_short ospf_instance_id)
|
||||||
|
{
|
||||||
|
struct route_table *table;
|
||||||
|
struct zebra_vrf *zvrf = NULL;
|
||||||
|
|
||||||
|
if (!(zvrf = zebra_vrf_lookup_by_name(vrf_name))) {
|
||||||
|
if (use_json)
|
||||||
|
vty_out(vty, "{}\n");
|
||||||
|
else
|
||||||
|
vty_out(vty, "vrf %s not defined\n", vrf_name);
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zvrf_id(zvrf) == VRF_UNKNOWN) {
|
||||||
|
if (use_json)
|
||||||
|
vty_out(vty, "{}\n");
|
||||||
|
else
|
||||||
|
vty_out(vty, "vrf %s inactive\n", vrf_name);
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
table = zebra_vrf_table(afi, safi, zvrf_id(zvrf));
|
||||||
|
if (!table) {
|
||||||
|
if (use_json)
|
||||||
|
vty_out(vty, "{}\n");
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_show_route_helper(vty, zvrf, table, afi, use_fib, tag,
|
||||||
|
longer_prefix_p, supernets_only, type,
|
||||||
|
ospf_instance_id, use_json);
|
||||||
|
|
||||||
|
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_ns_find_table(zvrf->zns, table, afi);
|
||||||
|
if (t)
|
||||||
|
do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
|
||||||
|
0, 0, !!json);
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -3341,6 +3377,7 @@ void zebra_vty_init(void)
|
|||||||
install_element(VIEW_NODE, &show_vrf_cmd);
|
install_element(VIEW_NODE, &show_vrf_cmd);
|
||||||
install_element(VIEW_NODE, &show_vrf_vni_cmd);
|
install_element(VIEW_NODE, &show_vrf_vni_cmd);
|
||||||
install_element(VIEW_NODE, &show_route_cmd);
|
install_element(VIEW_NODE, &show_route_cmd);
|
||||||
|
install_element(VIEW_NODE, &show_route_table_cmd);
|
||||||
install_element(VIEW_NODE, &show_route_detail_cmd);
|
install_element(VIEW_NODE, &show_route_detail_cmd);
|
||||||
install_element(VIEW_NODE, &show_route_summary_cmd);
|
install_element(VIEW_NODE, &show_route_summary_cmd);
|
||||||
install_element(VIEW_NODE, &show_ip_nht_cmd);
|
install_element(VIEW_NODE, &show_ip_nht_cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user