summaryrefslogtreecommitdiff
path: root/zebra/zebra_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'zebra/zebra_vty.c')
-rw-r--r--zebra/zebra_vty.c151
1 files changed, 108 insertions, 43 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index f5ad9c1c8a..4824c09f3d 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -458,6 +458,12 @@ DEFPY(ip_route_blackhole_vrf,
VTY_DECLVAR_CONTEXT(vrf, vrf);
struct zebra_vrf *zvrf = vrf->info;
+ /*
+ * Coverity is complaining that prefix could
+ * be dereferenced, but we know that prefix will
+ * valid. Add an assert to make it happy
+ */
+ assert(prefix);
return zebra_static_route_leak(vty, zvrf, zvrf,
AFI_IP, SAFI_UNICAST, no, prefix,
mask_str, NULL, NULL, NULL, flag,
@@ -1229,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,
- 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)
+static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
+ struct route_table *table, afi_t afi,
+ bool use_fib, route_tag_t tag,
+ const struct prefix *longer_prefix_p,
+ bool supernets_only, int type,
+ u_short ospf_instance_id, u_char use_json)
{
- struct route_table *table;
- rib_dest_t *dest;
struct route_node *rn;
struct route_entry *re;
int first = 1;
- struct zebra_vrf *zvrf = NULL;
- char buf[BUFSIZ];
+ rib_dest_t *dest;
json_object *json = NULL;
json_object *json_prefix = NULL;
- u_int32_t addr;
-
- 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;
- }
+ uint32_t addr;
+ char buf[BUFSIZ];
if (use_json)
json = json_object_new_object();
@@ -1346,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_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;
}
@@ -2014,6 +2056,12 @@ DEFPY(ipv6_route_blackhole_vrf,
VTY_DECLVAR_CONTEXT(vrf, vrf);
struct zebra_vrf *zvrf = vrf->info;
+ /*
+ * Coverity is complaining that prefix could
+ * be dereferenced, but we know that prefix will
+ * valid. Add an assert to make it happy
+ */
+ assert(prefix);
return zebra_static_route_leak(vty, zvrf, zvrf,
AFI_IP6, SAFI_UNICAST, no, prefix_str,
NULL, from_str, NULL, NULL, flag,
@@ -2326,8 +2374,12 @@ DEFUN (show_vrf,
continue;
vty_out(vty, "vrf %s ", zvrf_name(zvrf));
- if (zvrf_id(zvrf) == VRF_UNKNOWN)
+ if (zvrf_id(zvrf) == VRF_UNKNOWN
+ || !zvrf_is_active(zvrf))
vty_out(vty, "inactive");
+ else if (zvrf_ns_name(zvrf))
+ vty_out(vty, "id %u netns %s",
+ zvrf_id(zvrf), zvrf_ns_name(zvrf));
else
vty_out(vty, "id %u table %u", zvrf_id(zvrf),
zvrf->table_id);
@@ -2341,20 +2393,26 @@ DEFUN (show_vrf,
DEFUN (default_vrf_vni_mapping,
default_vrf_vni_mapping_cmd,
- "vni " CMD_VNI_RANGE,
+ "vni " CMD_VNI_RANGE "[prefix-routes-only]",
"VNI corresponding to the DEFAULT VRF\n"
- "VNI-ID\n")
+ "VNI-ID\n"
+ "Prefix routes only \n")
{
int ret = 0;
char err[ERR_STR_SZ];
struct zebra_vrf *zvrf = NULL;
vni_t vni = strtoul(argv[1]->arg, NULL, 10);
+ int filter = 0;
zvrf = vrf_info_lookup(VRF_DEFAULT);
if (!zvrf)
return CMD_WARNING;
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 1);
+ if (argc == 3)
+ filter = 1;
+
+ ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
+ filter, 1);
if (ret != 0) {
vty_out(vty, "%s\n", err);
return CMD_WARNING;
@@ -2379,7 +2437,7 @@ DEFUN (no_default_vrf_vni_mapping,
if (!zvrf)
return CMD_WARNING;
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0);
+ ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0, 0);
if (ret != 0) {
vty_out(vty, "%s\n", err);
return CMD_WARNING;
@@ -2390,11 +2448,13 @@ DEFUN (no_default_vrf_vni_mapping,
DEFUN (vrf_vni_mapping,
vrf_vni_mapping_cmd,
- "vni " CMD_VNI_RANGE,
+ "vni " CMD_VNI_RANGE "[prefix-routes-only]",
"VNI corresponding to tenant VRF\n"
- "VNI-ID\n")
+ "VNI-ID\n"
+ "prefix-routes-only\n")
{
int ret = 0;
+ int filter = 0;
ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
vni_t vni = strtoul(argv[1]->arg, NULL, 10);
@@ -2403,9 +2463,13 @@ DEFUN (vrf_vni_mapping,
assert(vrf);
assert(zvrf);
+ if (argc == 3)
+ filter = 1;
+
/* Mark as having FRR configuration */
vrf_set_user_cfged(vrf);
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 1);
+ ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
+ filter, 1);
if (ret != 0) {
vty_out(vty, "%s\n", err);
return CMD_WARNING;
@@ -2430,7 +2494,7 @@ DEFUN (no_vrf_vni_mapping,
assert(vrf);
assert(zvrf);
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0);
+ ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0, 0);
if (ret != 0) {
vty_out(vty, "%s\n", err);
return CMD_WARNING;
@@ -3329,6 +3393,7 @@ 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);
install_element(VIEW_NODE, &show_route_detail_cmd);
install_element(VIEW_NODE, &show_route_summary_cmd);
install_element(VIEW_NODE, &show_ip_nht_cmd);