diff options
| author | Zhiyuan Wan <h@iloli.bid> | 2023-03-29 23:05:20 +0800 | 
|---|---|---|
| committer | Zhiyuan Wan <h@iloli.bid> | 2023-07-18 14:20:05 +0800 | 
| commit | 0ce2d1aaa18ae429fae10ac9bbcae171b5fa1a5f (patch) | |
| tree | 8a993fbda57bfbab6fc3362e857e507cb360c0ba /ospfd | |
| parent | 788cf6e892ebe3c8db7ad90093ff1979e5f37be4 (diff) | |
ospfd: Support show advertise router in 'show ip ospf route' command
Users can now use 'show ip ospf route [detail]' command to show the
originator of each OSPF route item.
Signed-off-by: Zhiyuan Wan <h@iloli.bid>
Diffstat (limited to 'ospfd')
| -rw-r--r-- | ospfd/ospf_vty.c | 56 | 
1 files changed, 44 insertions, 12 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 54fd60af23..0438bbcdf8 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -10732,7 +10732,7 @@ static void config_write_stub_router(struct vty *vty, struct ospf *ospf)  static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,  				       struct route_table *rt, -				       json_object *json) +				       json_object *json, bool detail)  {  	struct route_node *rn;  	struct ospf_route * or ; @@ -10857,6 +10857,10 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,  								ifindex2ifname(  									path->ifindex,  									ospf->vrf_id)); +							json_object_string_addf( +								json_nexthop, +								"adv", "%pI4", +								&path->adv_router);  						} else {  							vty_out(vty,  								"%24s   via %pI4, %s\n", @@ -10866,6 +10870,11 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,  									path->ifindex,  									ospf->vrf_id));  						} +						if (detail && !json) +							vty_out(vty, +								"%24s   adv %pI4\n", +								"", +								&path->adv_router);  					}  				}  			} @@ -11020,7 +11029,7 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,  static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,  					struct route_table *rt, -					json_object *json) +					json_object *json, bool detail)  {  	struct route_node *rn;  	struct ospf_route *er; @@ -11124,6 +11133,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,  							ifindex2ifname(  								path->ifindex,  								ospf->vrf_id)); +						json_object_string_addf( +							json_nexthop, "adv", +							"%pI4", +							&path->adv_router);  					} else {  						vty_out(vty,  							"%24s   via %pI4, %s\n", @@ -11133,6 +11146,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,  								path->ifindex,  								ospf->vrf_id));  					} +					if (detail && !json) +						vty_out(vty, +							"%24s   adv %pI4\n", "", +							&path->adv_router);  				}  			}  		} @@ -11419,7 +11436,8 @@ DEFUN (show_ip_ospf_instance_border_routers,  }  static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, -				     json_object *json, uint8_t use_vrf) +				     json_object *json, uint8_t use_vrf, +				     bool detail)  {  	json_object *json_vrf = NULL; @@ -11447,7 +11465,8 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,  	}  	/* Show Network routes. */ -	show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); +	show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf, +				   detail);  	/* Show Router routes. */  	show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); @@ -11458,7 +11477,7 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,  	/* Show AS External routes. */  	show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, -				    json_vrf); +				    json_vrf, detail);  	if (json) {  		if (use_vrf) { @@ -11476,13 +11495,14 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,  DEFUN (show_ip_ospf_route,         show_ip_ospf_route_cmd, -	"show ip ospf [vrf <NAME|all>] route [json]", +	"show ip ospf [vrf <NAME|all>] route [detail] [json]",  	SHOW_STR  	IP_STR  	"OSPF information\n"  	VRF_CMD_HELP_STR  	"All VRFs\n"  	"OSPF routing table\n" +	"Detailed information\n"  	JSON_STR)  {  	struct ospf *ospf = NULL; @@ -11491,14 +11511,19 @@ DEFUN (show_ip_ospf_route,  	bool all_vrf = false;  	int ret = CMD_SUCCESS;  	int inst = 0; +	int idx = 0;  	int idx_vrf = 0;  	uint8_t use_vrf = 0;  	bool uj = use_json(argc, argv); +	bool detail = false;  	json_object *json = NULL;  	if (uj)  		json = json_object_new_object(); +	if (argv_find(argv, argc, "detail", &idx)) +		detail = true; +  	OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);  	/* vrf input is provided could be all or specific vrf*/ @@ -11512,8 +11537,8 @@ DEFUN (show_ip_ospf_route,  				if (!ospf->oi_running)  					continue;  				ospf_output = true; -				ret = show_ip_ospf_route_common(vty, ospf, json, -								use_vrf); +				ret = show_ip_ospf_route_common( +					vty, ospf, json, use_vrf, detail);  			}  			if (uj) { @@ -11550,7 +11575,8 @@ DEFUN (show_ip_ospf_route,  	}  	if (ospf) { -		ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); +		ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf, +						detail);  		/* Keep Non-pretty format */  		if (uj)  			vty_out(vty, "%s\n", @@ -11566,16 +11592,22 @@ DEFUN (show_ip_ospf_route,  DEFUN (show_ip_ospf_instance_route,         show_ip_ospf_instance_route_cmd, -       "show ip ospf (1-65535) route", +       "show ip ospf (1-65535) route [detail]",         SHOW_STR         IP_STR         "OSPF information\n"         "Instance ID\n" -       "OSPF routing table\n") +       "OSPF routing table\n" +       "Detailed information\n")  {  	int idx_number = 3; +	int idx = 0;  	struct ospf *ospf;  	unsigned short instance = 0; +	bool detail = false; + +	if (argv_find(argv, argc, "detail", &idx)) +		detail = true;  	instance = strtoul(argv[idx_number]->arg, NULL, 10);  	if (instance != ospf_instance) @@ -11585,7 +11617,7 @@ DEFUN (show_ip_ospf_instance_route,  	if (!ospf || !ospf->oi_running)  		return CMD_SUCCESS; -	return show_ip_ospf_route_common(vty, ospf, NULL, 0); +	return show_ip_ospf_route_common(vty, ospf, NULL, 0, detail);  }  | 
