summaryrefslogtreecommitdiff
path: root/ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_bfd.c4
-rw-r--r--ospfd/ospf_bfd.h4
-rw-r--r--ospfd/ospf_vty.c233
-rw-r--r--ospfd/ospfd.c13
4 files changed, 185 insertions, 69 deletions
diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c
index df41897660..594735a08f 100644
--- a/ospfd/ospf_bfd.c
+++ b/ospfd/ospf_bfd.c
@@ -312,7 +312,7 @@ void ospf_bfd_write_config(struct vty *vty, struct ospf_if_params *params)
* ospf_bfd_show_info - Show BFD info structure
*/
void ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj,
- uint8_t use_json, int param_only)
+ bool use_json, int param_only)
{
if (param_only)
bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json,
@@ -326,7 +326,7 @@ void ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj,
* ospf_bfd_interface_show - Show the interface BFD configuration.
*/
void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp,
- json_object *json_interface_sub, uint8_t use_json)
+ json_object *json_interface_sub, bool use_json)
{
struct ospf_if_params *params;
diff --git a/ospfd/ospf_bfd.h b/ospfd/ospf_bfd.h
index 6d7caf4217..74385d3268 100644
--- a/ospfd/ospf_bfd.h
+++ b/ospfd/ospf_bfd.h
@@ -35,13 +35,13 @@ extern void ospf_bfd_trigger_event(struct ospf_neighbor *nbr, int old_state,
extern void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp,
json_object *json_interface_sub,
- uint8_t use_json);
+ bool use_json);
extern void ospf_bfd_info_nbr_create(struct ospf_interface *oi,
struct ospf_neighbor *nbr);
extern void ospf_bfd_show_info(struct vty *vty, void *bfd_info,
- json_object *json_obj, uint8_t use_json,
+ json_object *json_obj, bool use_json,
int param_only);
extern void ospf_bfd_info_free(void **bfd_info);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index fb9770d09a..aa877903fc 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -145,6 +145,8 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
if (argv_find(argv, argc, "vrf", &idx_vrf)) {
vrf_name = argv[idx_vrf + 1]->arg;
+ if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME))
+ vrf_name = NULL;
if (enable) {
/* Allocate VRF aware instance */
ospf = ospf_get(*instance, vrf_name);
@@ -2621,7 +2623,7 @@ const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)",
const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"};
static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
- json_object *json_areas, uint8_t use_json)
+ json_object *json_areas, bool use_json)
{
json_object *json_area = NULL;
@@ -3241,7 +3243,7 @@ DEFUN (show_ip_ospf,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL;
bool all_vrf = FALSE;
@@ -3261,11 +3263,15 @@ DEFUN (show_ip_ospf,
/* vrf input is provided could be all or specific vrf*/
if (vrf_name) {
+ bool ospf_output = FALSE;
+
use_vrf = 1;
+
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_common(vty, ospf, json,
use_vrf);
}
@@ -3274,21 +3280,34 @@ DEFUN (show_ip_ospf,
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
- }
+ } else if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if ((ospf == NULL) || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
} else {
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Display default ospf (instance 0) info */
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
}
@@ -3319,7 +3338,7 @@ DEFUN (show_ip_ospf_instance,
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
int ret = CMD_SUCCESS;
json_object *json = NULL;
@@ -3348,7 +3367,7 @@ DEFUN (show_ip_ospf_instance,
static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
struct interface *ifp,
json_object *json_interface_sub,
- uint8_t use_json)
+ bool use_json)
{
int is_up;
struct ospf_neighbor *nbr;
@@ -3665,7 +3684,7 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
char *intf_name, uint8_t use_vrf,
- json_object *json, uint8_t use_json)
+ json_object *json, bool use_json)
{
struct interface *ifp;
struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
@@ -3758,7 +3777,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
struct ospf_interface *oi,
json_object *json_interface_sub,
- uint8_t use_json)
+ bool use_json)
{
if (use_json) {
json_object_int_add(json_interface_sub, "ifIndex",
@@ -3796,7 +3815,7 @@ static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
/* OSPFv2 Packet Counters */
static int show_ip_ospf_interface_traffic_common(
struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
- int display_once, uint8_t use_vrf, uint8_t use_json)
+ int display_once, uint8_t use_vrf, bool use_json)
{
struct vrf *vrf = NULL;
struct interface *ifp = NULL;
@@ -3914,7 +3933,7 @@ DEFUN (show_ip_ospf_interface,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL, *intf_name = NULL;
bool all_vrf = FALSE;
@@ -3949,14 +3968,21 @@ DEFUN (show_ip_ospf_interface,
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
- }
+ } else if (!ospf)
+ vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
@@ -3966,8 +3992,14 @@ DEFUN (show_ip_ospf_interface,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
@@ -3998,7 +4030,7 @@ DEFUN (show_ip_ospf_instance_interface,
int idx_intf = 0;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
char *intf_name = NULL;
int ret = CMD_SUCCESS;
json_object *json = NULL;
@@ -4047,7 +4079,7 @@ DEFUN (show_ip_ospf_interface_traffic,
bool all_vrf = FALSE;
int inst = 0;
int idx_vrf = 0, idx_intf = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
int ret = CMD_SUCCESS;
int display_once = 0;
@@ -4123,7 +4155,7 @@ static void show_ip_ospf_neighbour_header(struct vty *vty)
static void show_ip_ospf_neighbor_sub(struct vty *vty,
struct ospf_interface *oi,
- json_object *json, uint8_t use_json)
+ json_object *json, bool use_json)
{
struct route_node *rn;
struct ospf_neighbor *nbr, *prev_nbr = NULL;
@@ -4234,7 +4266,7 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
}
static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
- json_object *json, uint8_t use_json,
+ json_object *json, bool use_json,
uint8_t use_vrf)
{
struct ospf_interface *oi;
@@ -4296,7 +4328,7 @@ DEFUN (show_ip_ospf_neighbor,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL;
bool all_vrf = FALSE;
@@ -4327,23 +4359,36 @@ DEFUN (show_ip_ospf_neighbor,
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
- }
+ } else if (!ospf)
+ vty_out(vty, "OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
}
@@ -4379,7 +4424,7 @@ DEFUN (show_ip_ospf_instance_neighbor,
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
int ret = CMD_SUCCESS;
@@ -4406,7 +4451,7 @@ DEFUN (show_ip_ospf_instance_neighbor,
}
static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
- json_object *json, uint8_t use_json,
+ json_object *json, bool use_json,
uint8_t use_vrf)
{
struct listnode *node;
@@ -4509,7 +4554,7 @@ DEFUN (show_ip_ospf_neighbor_all,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL;
bool all_vrf = FALSE;
@@ -4591,7 +4636,7 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
int ret = CMD_SUCCESS;
@@ -4619,7 +4664,7 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
int arg_base,
struct cmd_token **argv,
- uint8_t use_json, uint8_t use_vrf)
+ bool use_json, uint8_t use_vrf)
{
struct interface *ifp;
struct route_node *rn;
@@ -4678,7 +4723,7 @@ DEFUN (show_ip_ospf_neighbor_int,
{
struct ospf *ospf;
int idx_ifname = 4;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
int ret = CMD_SUCCESS;
struct interface *ifp = NULL;
@@ -4714,7 +4759,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int,
int idx_ifname = 5;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
if (!uj)
show_ip_ospf_neighbour_header(vty);
@@ -4737,8 +4782,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int,
static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
struct ospf_interface *oi,
struct ospf_nbr_nbma *nbr_nbma,
- uint8_t use_json,
- json_object *json)
+ bool use_json, json_object *json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_sub = NULL;
@@ -4818,8 +4862,7 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
struct ospf_interface *oi,
struct ospf_neighbor *nbr,
- json_object *json,
- uint8_t use_json)
+ json_object *json, bool use_json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_sub = NULL;
@@ -5035,7 +5078,7 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
int arg_base,
struct cmd_token **argv,
- uint8_t use_json, uint8_t use_vrf)
+ bool use_json, uint8_t use_vrf)
{
struct listnode *node;
struct ospf_neighbor *nbr;
@@ -5096,7 +5139,7 @@ DEFUN (show_ip_ospf_neighbor_id,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
int ret = CMD_SUCCESS;
@@ -5125,7 +5168,7 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
int idx_router_id = 5;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
@@ -5141,8 +5184,7 @@ DEFUN (show_ip_ospf_instance_neighbor_id,
static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
struct ospf *ospf,
- json_object *json,
- uint8_t use_json,
+ json_object *json, bool use_json,
uint8_t use_vrf)
{
struct ospf_interface *oi;
@@ -5210,7 +5252,7 @@ DEFUN (show_ip_ospf_neighbor_detail,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL;
bool all_vrf = FALSE;
@@ -5290,7 +5332,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
int ret = CMD_SUCCESS;
@@ -5319,7 +5361,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
struct ospf *ospf,
json_object *json,
- uint8_t use_json,
+ bool use_json,
uint8_t use_vrf)
{
struct listnode *node;
@@ -5399,7 +5441,7 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
char *vrf_name = NULL;
bool all_vrf = FALSE;
@@ -5481,7 +5523,7 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all,
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
int ret = CMD_SUCCESS;
@@ -5511,7 +5553,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
struct ospf *ospf,
int arg_base,
struct cmd_token **argv,
- uint8_t use_json)
+ bool use_json)
{
struct ospf_interface *oi;
struct interface *ifp;
@@ -5579,17 +5621,22 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
JSON_STR)
{
struct ospf *ospf;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
struct listnode *node = NULL;
int ret = CMD_SUCCESS;
+ bool ospf_output = FALSE;
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
argv, uj);
}
+ if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
+
return ret;
}
@@ -5609,7 +5656,7 @@ DEFUN (show_ip_ospf_instance_neighbor_int_detail,
int idx_ifname = 5;
struct ospf *ospf;
unsigned short instance = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
@@ -6294,19 +6341,28 @@ DEFUN (show_ip_ospf_database_max,
OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (vrf_name) {
+ bool ospf_output = FALSE;
+
use_vrf = 1;
+
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_database_common(
vty, ospf, idx_vrf ? 2 : 0, argc, argv,
use_vrf);
}
+
+ if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
ret = (show_ip_ospf_database_common(
vty, ospf, idx_vrf ? 2 : 0, argc, argv,
use_vrf));
@@ -6314,8 +6370,11 @@ DEFUN (show_ip_ospf_database_max,
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
use_vrf);
}
@@ -6375,16 +6434,22 @@ DEFUN (show_ip_ospf_instance_database,
}
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if ((ospf == NULL) || !ospf->oi_running)
+ if ((ospf == NULL) || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = (show_ip_ospf_database_common(
vty, ospf, idx ? 2 : 0, argc, argv, use_vrf));
}
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
use_vrf));
}
@@ -6413,8 +6478,10 @@ DEFUN (show_ip_ospf_instance_database_max,
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
- if (!ospf->oi_running)
+ if (!ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0);
}
@@ -6503,8 +6570,11 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
- if (!ospf->oi_running)
+ if (!ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
return (show_ip_ospf_database_type_adv_router_common(
vty, ospf, idx ? 1 : 0, argc, argv, use_vrf));
}
@@ -6512,27 +6582,39 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (vrf_name) {
+ bool ospf_output = FALSE;
+
use_vrf = 1;
+
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_database_type_adv_router_common(
vty, ospf, idx ? 1 : 0, argc, argv,
use_vrf);
}
+ if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if ((ospf == NULL) || !ospf->oi_running)
+ if ((ospf == NULL) || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = show_ip_ospf_database_type_adv_router_common(
vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
}
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = show_ip_ospf_database_type_adv_router_common(
vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
}
@@ -9269,19 +9351,28 @@ DEFUN (show_ip_ospf_border_routers,
OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (vrf_name) {
+ bool ospf_output = FALSE;
+
use_vrf = 1;
+
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_border_routers_common(
vty, ospf, use_vrf);
}
+
+ if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
ret = show_ip_ospf_border_routers_common(vty, ospf,
use_vrf);
@@ -9289,8 +9380,11 @@ DEFUN (show_ip_ospf_border_routers,
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (ospf == NULL || !ospf->oi_running)
+ if (ospf == NULL || !ospf->oi_running) {
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
+ }
+
ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
}
@@ -9391,7 +9485,7 @@ DEFUN (show_ip_ospf_route,
int inst = 0;
int idx_vrf = 0;
uint8_t use_vrf = 0;
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
if (uj)
@@ -9401,11 +9495,15 @@ DEFUN (show_ip_ospf_route,
/* vrf input is provided could be all or specific vrf*/
if (vrf_name) {
+ bool ospf_output = FALSE;
+
use_vrf = 1;
+
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
+ ospf_output = TRUE;
ret = show_ip_ospf_route_common(vty, ospf, json,
use_vrf);
}
@@ -9415,22 +9513,35 @@ DEFUN (show_ip_ospf_route,
vty_out(vty, "%s\n",
json_object_to_json_string(json));
json_object_free(json);
- }
+ } else if (!ospf_output)
+ vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj)
+ if (uj) {
+ vty_out(vty, "%s\n",
+ json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
+ } else
+ vty_out(vty, "%% OSPF instance not found\n");
+
return CMD_SUCCESS;
}
}
@@ -9482,7 +9593,7 @@ DEFUN (show_ip_ospf_vrfs,
"Show OSPF VRFs \n"
JSON_STR)
{
- uint8_t uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL;
json_object *json_vrfs = NULL;
struct ospf *ospf = NULL;
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index bfaedf2fe7..d311b4da6b 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -234,12 +234,10 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
new->instance = instance;
new->router_id.s_addr = htonl(0);
new->router_id_static.s_addr = htonl(0);
-
- if (name) {
+ if (name && !strmatch(name, VRF_DEFAULT_NAME)) {
new->vrf_id = VRF_UNKNOWN;
/* Freed in ospf_finish_final */
new->name = XSTRDUP(MTYPE_OSPF_TOP, name);
- vrf = vrf_lookup_by_name(new->name);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"%s: Create new ospf instance with vrf_name %s vrf_id %u",
@@ -381,6 +379,9 @@ struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
struct ospf *ospf = NULL;
struct listnode *node, *nnode;
+ if (name == NULL || strmatch(name, VRF_DEFAULT_NAME))
+ return ospf_lookup_by_vrf_id(VRF_DEFAULT);
+
for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) {
if ((ospf->instance == instance)
&& ((ospf->name == NULL && name == NULL)
@@ -2078,6 +2079,10 @@ static int ospf_vrf_enable(struct vrf *vrf)
ospf = ospf_lookup_by_name(vrf->name);
if (ospf) {
+ if (ospf->name && strmatch(vrf->name, VRF_DEFAULT_NAME)) {
+ XFREE(MTYPE_OSPF_TOP, ospf->name);
+ ospf->name = NULL;
+ }
old_vrf_id = ospf->vrf_id;
/* We have instance configured, link to VRF and make it "up". */
ospf_vrf_link(ospf, vrf);
@@ -2149,7 +2154,7 @@ static int ospf_vrf_disable(struct vrf *vrf)
void ospf_vrf_init(void)
{
vrf_init(ospf_vrf_new, ospf_vrf_enable, ospf_vrf_disable,
- ospf_vrf_delete);
+ ospf_vrf_delete, NULL);
}
void ospf_vrf_terminate(void)