diff options
| author | anlan_cs <anlan_cs@tom.com> | 2022-01-11 04:21:05 -0500 |
|---|---|---|
| committer | anlan_cs <anlan_cs@tom.com> | 2022-01-11 04:21:05 -0500 |
| commit | d6b901ac78f164a5239c7694076968456bd163d4 (patch) | |
| tree | 0fbaa60bae41c0c4bc9529784bf5ee12b1dfd7fd /ospf6d/ospf6_interface.c | |
| parent | c274b697ee856a67cd225d5ae05195063a991047 (diff) | |
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/ospf6_interface.c')
| -rw-r--r-- | ospf6d/ospf6_interface.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index a0c921f419..6fc0670f83 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; } |
