DEFPY commands are easier to maintain and less susceptible to
bugs. In the long term we should try to merge the plethora of
"show ip ospf neighbor" commands (total of 14) into a single DEFPY.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
}
static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
}
static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
- int arg_base,
- struct cmd_token **argv,
+ struct in_addr *router_id,
bool use_json, uint8_t use_vrf)
{
struct listnode *node;
struct ospf_neighbor *nbr;
struct ospf_interface *oi;
bool use_json, uint8_t use_vrf)
{
struct listnode *node;
struct ospf_neighbor *nbr;
struct ospf_interface *oi;
- struct in_addr router_id;
- int ret;
json_object *json = NULL;
if (use_json)
json_object *json = NULL;
if (use_json)
ospf_show_vrf_name(ospf, vty, json, use_vrf);
ospf_show_vrf_name(ospf, vty, json, use_vrf);
- ret = inet_aton(argv[arg_base]->arg, &router_id);
- if (!ret) {
- if (!use_json)
- vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
- else {
- vty_out(vty, "{}\n");
- json_object_free(json);
- }
- return CMD_WARNING;
- }
-
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
- if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) {
+ if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) {
show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
use_json);
}
show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
use_json);
}
-DEFUN (show_ip_ospf_neighbor_id,
+DEFPY (show_ip_ospf_neighbor_id,
show_ip_ospf_neighbor_id_cmd,
show_ip_ospf_neighbor_id_cmd,
- "show ip ospf neighbor A.B.C.D [json]",
+ "show ip ospf neighbor A.B.C.D$router_id [json$json]",
SHOW_STR
IP_STR
"OSPF information\n"
SHOW_STR
IP_STR
"OSPF information\n"
JSON_STR)
{
struct ospf *ospf;
JSON_STR)
{
struct ospf *ospf;
- bool uj = use_json(argc, argv);
- struct listnode *node = NULL;
- int idx_router_id = 0;
-
- argv_find(argv, argc, "A.B.C.D", &idx_router_id);
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
- ret = show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id,
- argv, uj, 0);
+ ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
+ !!json, 0);
-DEFUN (show_ip_ospf_instance_neighbor_id,
+DEFPY (show_ip_ospf_instance_neighbor_id,
show_ip_ospf_instance_neighbor_id_cmd,
show_ip_ospf_instance_neighbor_id_cmd,
- "show ip ospf (1-65535) neighbor A.B.C.D [json]",
+ "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
SHOW_STR
IP_STR
"OSPF information\n"
SHOW_STR
IP_STR
"OSPF information\n"
"Neighbor ID\n"
JSON_STR)
{
"Neighbor ID\n"
JSON_STR)
{
- int idx_number = 3;
- int idx_router_id = 5;
- unsigned short instance = 0;
- bool uj = use_json(argc, argv);
- instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
return CMD_SUCCESS;
if (!ospf->oi_running)
return CMD_SUCCESS;
- return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv,
- uj, 0);
+ return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
+ 0);
}
static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
}
static int show_ip_ospf_neighbor_detail_common(struct vty *vty,