summaryrefslogtreecommitdiffstats
path: root/ospf6d
diff options
context:
space:
mode:
authoranlan_cs <anlan_cs@tom.com>2022-01-11 10:21:05 +0100
committeranlan_cs <anlan_cs@tom.com>2022-01-11 10:21:05 +0100
commitd6b901ac78f164a5239c7694076968456bd163d4 (patch)
tree0fbaa60bae41c0c4bc9529784bf5ee12b1dfd7fd /ospf6d
parentMerge pull request #10299 from donaldsharp/various_stuff (diff)
downloadfrr-d6b901ac78f164a5239c7694076968456bd163d4.tar.xz
frr-d6b901ac78f164a5239c7694076968456bd163d4.zip
ospf6d: give error information for commands with non-exist vrfs
Currently the ospf6d's commands with non-exist vrfs can't give the error informations to users. This commit adds a macro "OSPF6_CMD_CHECK_VRF" to give error information if with non-exist vrfs. As usual, skip the checking process in the case of json. So one command can call this macro to do the checking process in its end. At that time it need know json style or not, so add "json" parameter for several related functions. BTW, suppress the build warning of the macro `OSPF6_FIND_VRF_ARGS`: "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects." Signed-off-by: anlan_cs <anlan_cs@tom.com>
Diffstat (limited to 'ospf6d')
-rw-r--r--ospf6d/ospf6_area.c6
-rw-r--r--ospf6d/ospf6_asbr.c2
-rw-r--r--ospf6d/ospf6_interface.c20
-rw-r--r--ospf6d/ospf6_neighbor.c11
-rw-r--r--ospf6d/ospf6_top.c12
-rw-r--r--ospf6d/ospf6d.c36
-rw-r--r--ospf6d/ospf6d.h22
7 files changed, 94 insertions, 15 deletions
diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c
index 7e8e34a22..417fc6969 100644
--- a/ospf6d/ospf6_area.c
+++ b/ospf6d/ospf6_area.c
@@ -1075,6 +1075,8 @@ DEFUN(show_ipv6_ospf6_spf_tree, show_ipv6_ospf6_spf_tree_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1142,6 +1144,8 @@ DEFUN(show_ipv6_ospf6_area_spf_tree, show_ipv6_ospf6_area_spf_tree_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1230,6 +1234,8 @@ DEFUN(show_ipv6_ospf6_simulate_spf_tree_root,
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 99f30a4a0..863441ae1 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -2553,6 +2553,8 @@ DEFUN(show_ipv6_ospf6_redistribute, show_ipv6_ospf6_redistribute_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c
index a0c921f41..6fc0670f8 100644
--- a/ospf6d/ospf6_interface.c
+++ b/ospf6d/ospf6_interface.c
@@ -1260,14 +1260,13 @@ struct in6_addr *ospf6_interface_get_global_address(struct interface *ifp)
static int show_ospf6_interface_common(struct vty *vty, vrf_id_t vrf_id,
int argc, struct cmd_token **argv,
int idx_ifname, int intf_idx,
- int json_idx)
+ int json_idx, bool uj)
{
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
struct interface *ifp;
json_object *json;
json_object *json_int;
- bool uj = use_json(argc, argv);
if (uj) {
json = json_object_new_object();
@@ -1323,6 +1322,7 @@ DEFUN(show_ipv6_ospf6_interface, show_ipv6_ospf6_interface_ifname_cmd,
const char *vrf_name = NULL;
bool all_vrf = false;
int idx_vrf = 0;
+ bool uj = use_json(argc, argv);
OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (idx_vrf > 0) {
@@ -1335,13 +1335,15 @@ DEFUN(show_ipv6_ospf6_interface, show_ipv6_ospf6_interface_ifname_cmd,
if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
show_ospf6_interface_common(vty, ospf6->vrf_id, argc,
argv, idx_ifname, intf_idx,
- json_idx);
+ json_idx, uj);
if (!all_vrf)
break;
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1457,14 +1459,13 @@ static int ospf6_interface_show_traffic(struct vty *vty,
static int ospf6_interface_show_traffic_common(struct vty *vty, int argc,
struct cmd_token **argv,
- vrf_id_t vrf_id)
+ vrf_id_t vrf_id, bool uj)
{
int idx_ifname = 0;
int display_once = 0;
char *intf_name = NULL;
struct interface *ifp = NULL;
json_object *json = NULL;
- bool uj = use_json(argc, argv);
if (uj)
json = json_object_new_object();
@@ -1525,19 +1526,22 @@ DEFUN(show_ipv6_ospf6_interface_traffic, show_ipv6_ospf6_interface_traffic_cmd,
const char *vrf_name = NULL;
bool all_vrf = false;
int idx_vrf = 0;
+ bool uj = use_json(argc, argv);
OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
ospf6_interface_show_traffic_common(vty, argc, argv,
- ospf6->vrf_id);
+ ospf6->vrf_id, uj);
if (!all_vrf)
break;
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1601,6 +1605,8 @@ DEFUN(show_ipv6_ospf6_interface_ifname_prefix,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1651,6 +1657,8 @@ DEFUN(show_ipv6_ospf6_interface_prefix, show_ipv6_ospf6_interface_prefix_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c
index 1a8fedea0..afa504d13 100644
--- a/ospf6d/ospf6_neighbor.c
+++ b/ospf6d/ospf6_neighbor.c
@@ -1111,12 +1111,15 @@ DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
static int ospf6_neighbor_show_common(struct vty *vty, int argc,
struct cmd_token **argv,
- struct ospf6 *ospf6, int idx_ipv4)
+ struct ospf6 *ospf6, int idx_ipv4,
+ bool uj)
{
struct ospf6_neighbor *on;
struct ospf6_interface *oi;
@@ -1126,7 +1129,6 @@ static int ospf6_neighbor_show_common(struct vty *vty, int argc,
json_object *json, bool use_json);
uint32_t router_id;
json_object *json = NULL;
- bool uj = use_json(argc, argv);
showfunc = ospf6_neighbor_show_detail;
if (uj)
@@ -1164,6 +1166,7 @@ DEFUN(show_ipv6_ospf6_neighbor_one, show_ipv6_ospf6_neighbor_one_cmd,
const char *vrf_name = NULL;
bool all_vrf = false;
int idx_vrf = 0;
+ bool uj = use_json(argc, argv);
OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (idx_vrf > 0)
@@ -1172,13 +1175,15 @@ DEFUN(show_ipv6_ospf6_neighbor_one, show_ipv6_ospf6_neighbor_one_cmd,
for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
ospf6_neighbor_show_common(vty, argc, argv, ospf6,
- idx_ipv4);
+ idx_ipv4, uj);
if (!all_vrf)
break;
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c
index 6bff52fc5..5fcfc7e70 100644
--- a/ospf6d/ospf6_top.c
+++ b/ospf6d/ospf6_top.c
@@ -1536,6 +1536,8 @@ DEFUN(show_ipv6_ospf6, show_ipv6_ospf6_cmd,
if (uj)
json_object_free(json);
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1574,6 +1576,8 @@ DEFUN(show_ipv6_ospf6_route, show_ipv6_ospf6_route_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1607,6 +1611,8 @@ DEFUN(show_ipv6_ospf6_route_match, show_ipv6_ospf6_route_match_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1641,6 +1647,8 @@ DEFUN(show_ipv6_ospf6_route_match_detail,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1676,6 +1684,8 @@ DEFUN(show_ipv6_ospf6_route_type_detail, show_ipv6_ospf6_route_type_detail_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -2091,6 +2101,8 @@ DEFPY (show_ipv6_ospf6_external_aggregator,
vty_json(vty, json);
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c
index d9f730586..cc5a0f787 100644
--- a/ospf6d/ospf6d.c
+++ b/ospf6d/ospf6d.c
@@ -421,6 +421,8 @@ DEFUN(show_ipv6_ospf6_database, show_ipv6_ospf6_database_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -471,6 +473,8 @@ DEFUN(show_ipv6_ospf6_database_type, show_ipv6_ospf6_database_type_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -512,6 +516,8 @@ DEFUN(show_ipv6_ospf6_database_id, show_ipv6_ospf6_database_id_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -557,6 +563,8 @@ DEFUN(show_ipv6_ospf6_database_router, show_ipv6_ospf6_database_router_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -625,6 +633,8 @@ DEFUN_HIDDEN(
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -681,6 +691,8 @@ DEFUN(show_ipv6_ospf6_database_type_id, show_ipv6_ospf6_database_type_id_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -740,6 +752,8 @@ DEFUN(show_ipv6_ospf6_database_type_router,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -789,6 +803,8 @@ DEFUN(show_ipv6_ospf6_database_id_router,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -838,6 +854,8 @@ DEFUN(show_ipv6_ospf6_database_adv_router_linkstate_id,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -899,6 +917,8 @@ DEFUN(show_ipv6_ospf6_database_type_id_router,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -967,6 +987,8 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1008,6 +1030,8 @@ DEFUN(show_ipv6_ospf6_database_self_originated,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1065,6 +1089,8 @@ DEFUN(show_ipv6_ospf6_database_type_self_originated,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1127,6 +1153,8 @@ DEFUN(show_ipv6_ospf6_database_type_self_originated_linkstate_id,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1187,6 +1215,8 @@ DEFUN(show_ipv6_ospf6_database_type_id_self_originated,
}
}
+ OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1263,6 +1293,8 @@ DEFUN(show_ipv6_ospf6_border_routers, show_ipv6_ospf6_border_routers_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1306,6 +1338,8 @@ DEFUN(show_ipv6_ospf6_linkstate, show_ipv6_ospf6_linkstate_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
@@ -1346,6 +1380,8 @@ DEFUN(show_ipv6_ospf6_linkstate_detail, show_ipv6_ospf6_linkstate_detail_cmd,
}
}
+ OSPF6_CMD_CHECK_VRF(false, all_vrf, ospf6);
+
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h
index 041a9b1df..43549de74 100644
--- a/ospf6d/ospf6d.h
+++ b/ospf6d/ospf6d.h
@@ -93,14 +93,24 @@ extern struct thread_master *master;
#define OSPF6_ROUTER_ID_STR "Specify Router-ID\n"
#define OSPF6_LS_ID_STR "Specify Link State ID\n"
+#define OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6) \
+ do { \
+ if (uj == false && all_vrf == false && ospf6 == NULL) { \
+ vty_out(vty, "%% OSPFv3 instance not found\n"); \
+ return CMD_SUCCESS; \
+ } \
+ } while (0)
+
#define IS_OSPF6_ASBR(O) ((O)->flag & OSPF6_FLAG_ASBR)
#define OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
- if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
- vrf_name = argv[idx_vrf + 1]->arg; \
- all_vrf = strmatch(vrf_name, "all"); \
- } else { \
- vrf_name = VRF_DEFAULT_NAME; \
- }
+ do { \
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
+ vrf_name = argv[idx_vrf + 1]->arg; \
+ all_vrf = strmatch(vrf_name, "all"); \
+ } else { \
+ vrf_name = VRF_DEFAULT_NAME; \
+ } \
+ } while (0)
#define OSPF6_FALSE false
#define OSPF6_TRUE true