ospf6d: fix "show ipv6 ospf6 neighbor" command

Simplify the logic and fix processing of "detail" and "drchoice"
arguments.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2021-06-18 22:42:49 +03:00
parent d7193080af
commit ee3e6d7ff3

View File

@ -969,10 +969,9 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
} }
} }
static void ospf6_neighbor_show_detail_common(struct vty *vty, int argc, static void ospf6_neighbor_show_detail_common(struct vty *vty,
struct cmd_token **argv, struct ospf6 *ospf6, bool uj,
struct ospf6 *ospf6, int idx_type, bool detail, bool drchoice)
int detail_idx, int json_idx)
{ {
struct ospf6_neighbor *on; struct ospf6_neighbor *on;
struct ospf6_interface *oi; struct ospf6_interface *oi;
@ -980,18 +979,15 @@ static void ospf6_neighbor_show_detail_common(struct vty *vty, int argc,
struct listnode *i, *j, *k; struct listnode *i, *j, *k;
json_object *json = NULL; json_object *json = NULL;
json_object *json_array = NULL; json_object *json_array = NULL;
bool uj = use_json(argc, argv);
void (*showfunc)(struct vty *, struct ospf6_neighbor *, void (*showfunc)(struct vty *, struct ospf6_neighbor *,
json_object *json, bool use_json); json_object *json, bool use_json);
showfunc = ospf6_neighbor_show; if (detail)
showfunc = ospf6_neighbor_show_detail;
if ((uj && argc == detail_idx) || (!uj && argc == json_idx)) { else if (drchoice)
if (!strncmp(argv[idx_type]->arg, "de", 2)) showfunc = ospf6_neighbor_show_drchoice;
showfunc = ospf6_neighbor_show_detail; else
else if (!strncmp(argv[idx_type]->arg, "dr", 2)) showfunc = ospf6_neighbor_show;
showfunc = ospf6_neighbor_show_drchoice;
}
if (uj) { if (uj) {
json = json_object_new_object(); json = json_object_new_object();
@ -1036,28 +1032,28 @@ DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd,
"Display details\n" "Display details\n"
"Display DR choices\n" JSON_STR) "Display DR choices\n" JSON_STR)
{ {
int idx_type = 4;
int detail_idx = 5;
int json_idx = 6;
struct ospf6 *ospf6; struct ospf6 *ospf6;
struct listnode *node; struct listnode *node;
const char *vrf_name = NULL; const char *vrf_name = NULL;
bool all_vrf = false; bool all_vrf = false;
int idx_vrf = 0; int idx_vrf = 0;
int idx_type = 4;
bool uj = use_json(argc, argv);
bool detail = false;
bool drchoice = false;
OSPF6_CMD_CHECK_RUNNING(); OSPF6_CMD_CHECK_RUNNING();
OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
if (idx_vrf > 0) {
idx_type += 2; if (argv_find(argv, argc, "detail", &idx_type))
detail_idx += 2; detail = true;
json_idx += 2; else if (argv_find(argv, argc, "drchoice", &idx_type))
} drchoice = true;
for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
ospf6_neighbor_show_detail_common(vty, argc, argv, ospf6_neighbor_show_detail_common(vty, ospf6, uj,
ospf6, idx_type, detail, drchoice);
detail_idx, json_idx);
if (!all_vrf) if (!all_vrf)
break; break;
} }