From 52d0c099a06dc8a03497b9b2acff9c2515b9489f Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Fri, 6 Oct 2017 15:32:25 -0700 Subject: [PATCH] ospfd: OSPFv2 VRF abstact api Create an api to display vrf name in vty or json format. Use VRF Name for vtysh and vrfName for json output. Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 66 ++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 7d6f40bfe7..7b7a53baa9 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -171,6 +171,18 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, return ospf; } +static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, + json_object *json) +{ + if (ospf->name) { + if (json) + json_object_string_add(json, "vrfName", ospf->name); + else + vty_out(vty, "VRF Name: %s\n", ospf->name); + } + +} + #ifndef VTYSH_EXTRACT_PL #include "ospf_vty_clippy.c" #endif @@ -2890,12 +2902,7 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); /* Show Router ID. */ if (use_json) { @@ -3864,12 +3871,7 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) show_ip_ospf_neighbor_sub(vty, oi, json, use_json); @@ -4160,12 +4162,7 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); @@ -4579,12 +4576,7 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); ret = inet_aton(argv[arg_base]->arg, &router_id); if (!ret) { @@ -4685,12 +4677,7 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; @@ -4816,12 +4803,7 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); - } + ospf_show_vrf_name(ospf, vty, json); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; @@ -5633,8 +5615,7 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); - if (ospf->name) - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); + ospf_show_vrf_name(ospf, vty, NULL); vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -5857,8 +5838,7 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); - if (ospf->name) - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); + ospf_show_vrf_name(ospf, vty, NULL); vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -8416,8 +8396,7 @@ static int show_ip_ospf_border_routers_common(struct vty *vty, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); - if (ospf->name) - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); + ospf_show_vrf_name(ospf, vty, NULL); if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); @@ -8511,8 +8490,7 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); - if (ospf->name) - vty_out(vty, "OSPF vrfName: %s\n", ospf->name); + ospf_show_vrf_name(ospf, vty, NULL); if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); -- 2.39.5