mirror of
				https://git.proxmox.com/git/mirror_frr
				synced 2025-11-01 10:32:36 +00:00 
			
		
		
		
	Merge pull request #2248 from ppmathis/enhancement/bgp-adjacent-routes
bgpd: Improve show commands for adjacent routes (advertised/received-routes)
This commit is contained in:
		
						commit
						f7fba3423b
					
				
							
								
								
									
										133
									
								
								bgpd/bgp_route.c
									
									
									
									
									
								
							
							
						
						
									
										133
									
								
								bgpd/bgp_route.c
									
									
									
									
									
								
							| @ -10222,8 +10222,9 @@ DEFUN (show_ip_bgp_l2vpn_evpn_all_route_prefix, | ||||
| } | ||||
| 
 | ||||
| static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 			   safi_t safi, int in, const char *rmap_name, | ||||
| 			   uint8_t use_json, json_object *json) | ||||
| 			   safi_t safi, enum bgp_show_adj_route_type type, | ||||
| 			   const char *rmap_name, uint8_t use_json, | ||||
| 			   json_object *json) | ||||
| { | ||||
| 	struct bgp_table *table; | ||||
| 	struct bgp_adj_in *ain; | ||||
| @ -10280,7 +10281,7 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 	output_count = filtered_count = 0; | ||||
| 	subgrp = peer_subgroup(peer, afi, safi); | ||||
| 
 | ||||
| 	if (!in && subgrp | ||||
| 	if (type == bgp_show_adj_route_advertised && subgrp | ||||
| 	    && CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)) { | ||||
| 		if (use_json) { | ||||
| 			json_object_int_add(json, "bgpTableVersion", | ||||
| @ -10313,10 +10314,12 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 	} | ||||
| 
 | ||||
| 	for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { | ||||
| 		if (in) { | ||||
| 		if (type == bgp_show_adj_route_received | ||||
| 		    || type == bgp_show_adj_route_filtered) { | ||||
| 			for (ain = rn->adj_in; ain; ain = ain->next) { | ||||
| 				if (ain->peer != peer) | ||||
| 				if (ain->peer != peer || !ain->attr) | ||||
| 					continue; | ||||
| 
 | ||||
| 				if (header1) { | ||||
| 					if (use_json) { | ||||
| 						json_object_int_add( | ||||
| @ -10359,25 +10362,30 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 						vty_out(vty, BGP_SHOW_HEADER); | ||||
| 					header2 = 0; | ||||
| 				} | ||||
| 				if (ain->attr) { | ||||
| 					bgp_attr_dup(&attr, ain->attr); | ||||
| 					if (bgp_input_modifier(peer, &rn->p, | ||||
| 							       &attr, afi, safi, | ||||
| 							       rmap_name) | ||||
| 					    != RMAP_DENY) { | ||||
| 						route_vty_out_tmp(vty, &rn->p, | ||||
| 								  &attr, safi, | ||||
| 								  use_json, | ||||
| 								  json_ar); | ||||
| 						output_count++; | ||||
| 					} else | ||||
| 						filtered_count++; | ||||
| 
 | ||||
| 				bgp_attr_dup(&attr, ain->attr); | ||||
| 				ret = bgp_input_modifier(peer, &rn->p, &attr, | ||||
| 							 afi, safi, rmap_name); | ||||
| 
 | ||||
| 				if (type == bgp_show_adj_route_filtered | ||||
| 				    && ret != RMAP_DENY) { | ||||
| 					bgp_attr_undup(&attr, ain->attr); | ||||
| 					continue; | ||||
| 				} | ||||
| 
 | ||||
| 				if (type == bgp_show_adj_route_received | ||||
| 				    && ret == RMAP_DENY) | ||||
| 					filtered_count++; | ||||
| 
 | ||||
| 				route_vty_out_tmp(vty, &rn->p, &attr, safi, | ||||
| 						  use_json, json_ar); | ||||
| 				bgp_attr_undup(&attr, ain->attr); | ||||
| 				output_count++; | ||||
| 			} | ||||
| 		} else { | ||||
| 		} else if (type == bgp_show_adj_route_advertised) { | ||||
| 			for (adj = rn->adj_out; adj; adj = adj->next) | ||||
| 				SUBGRP_FOREACH_PEER (adj->subgroup, paf) { | ||||
| 					if (paf->peer != peer) | ||||
| 					if (paf->peer != peer || !adj->attr) | ||||
| 						continue; | ||||
| 
 | ||||
| 					if (header1) { | ||||
| @ -10425,7 +10433,6 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 						} | ||||
| 						header1 = 0; | ||||
| 					} | ||||
| 
 | ||||
| 					if (header2) { | ||||
| 						if (!use_json) | ||||
| 							vty_out(vty, | ||||
| @ -10433,48 +10440,49 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 						header2 = 0; | ||||
| 					} | ||||
| 
 | ||||
| 					if (adj->attr) { | ||||
| 						bgp_attr_dup(&attr, adj->attr); | ||||
| 						ret = bgp_output_modifier( | ||||
| 							peer, &rn->p, &attr, | ||||
| 							afi, safi, rmap_name); | ||||
| 						if (ret != RMAP_DENY) { | ||||
| 							route_vty_out_tmp( | ||||
| 								vty, &rn->p, | ||||
| 								&attr, safi, | ||||
| 								use_json, | ||||
| 								json_ar); | ||||
| 							output_count++; | ||||
| 						} else | ||||
| 							filtered_count++; | ||||
| 					bgp_attr_dup(&attr, adj->attr); | ||||
| 					ret = bgp_output_modifier( | ||||
| 						peer, &rn->p, &attr, afi, safi, | ||||
| 						rmap_name); | ||||
| 
 | ||||
| 						bgp_attr_undup(&attr, | ||||
| 							       adj->attr); | ||||
| 					if (ret != RMAP_DENY) { | ||||
| 						route_vty_out_tmp(vty, &rn->p, | ||||
| 								  &attr, safi, | ||||
| 								  use_json, | ||||
| 								  json_ar); | ||||
| 						output_count++; | ||||
| 					} else { | ||||
| 						filtered_count++; | ||||
| 					} | ||||
| 
 | ||||
| 					bgp_attr_undup(&attr, adj->attr); | ||||
| 				} | ||||
| 		} | ||||
| 	} | ||||
| 	if (use_json) | ||||
| 		json_object_object_add(json, "advertisedRoutes", json_ar); | ||||
| 
 | ||||
| 	if (output_count != 0) { | ||||
| 		if (use_json) | ||||
| 			json_object_int_add(json, "totalPrefixCounter", | ||||
| 					    output_count); | ||||
| 	if (use_json) { | ||||
| 		json_object_object_add(json, "advertisedRoutes", json_ar); | ||||
| 		json_object_int_add(json, "totalPrefixCounter", output_count); | ||||
| 		json_object_int_add(json, "filteredPrefixCounter", | ||||
| 				    filtered_count); | ||||
| 
 | ||||
| 		vty_out(vty, "%s\n", json_object_to_json_string_ext( | ||||
| 					     json, JSON_C_TO_STRING_PRETTY)); | ||||
| 		json_object_free(json); | ||||
| 	} else if (output_count > 0) { | ||||
| 		if (filtered_count > 0) | ||||
| 			vty_out(vty, | ||||
| 				"\nTotal number of prefixes %ld (%ld filtered)\n", | ||||
| 				output_count, filtered_count); | ||||
| 		else | ||||
| 			vty_out(vty, "\nTotal number of prefixes %ld\n", | ||||
| 				output_count); | ||||
| 	} | ||||
| 	if (use_json) { | ||||
| 		vty_out(vty, "%s\n", json_object_to_json_string_ext( | ||||
| 					     json, JSON_C_TO_STRING_PRETTY)); | ||||
| 		json_object_free(json); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 			   safi_t safi, int in, const char *rmap_name, | ||||
| 			   uint8_t use_json) | ||||
| 			   safi_t safi, enum bgp_show_adj_route_type type, | ||||
| 			   const char *rmap_name, uint8_t use_json) | ||||
| { | ||||
| 	json_object *json = NULL; | ||||
| 
 | ||||
| @ -10498,7 +10506,8 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 		return CMD_WARNING; | ||||
| 	} | ||||
| 
 | ||||
| 	if (in | ||||
| 	if ((type == bgp_show_adj_route_received | ||||
| 	     || type == bgp_show_adj_route_filtered) | ||||
| 	    && !CHECK_FLAG(peer->af_flags[afi][safi], | ||||
| 			   PEER_FLAG_SOFT_RECONFIG)) { | ||||
| 		if (use_json) { | ||||
| @ -10514,7 +10523,7 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| 		return CMD_WARNING; | ||||
| 	} | ||||
| 
 | ||||
| 	show_adj_route(vty, peer, afi, safi, in, rmap_name, use_json, json); | ||||
| 	show_adj_route(vty, peer, afi, safi, type, rmap_name, use_json, json); | ||||
| 
 | ||||
| 	return CMD_SUCCESS; | ||||
| } | ||||
| @ -10522,7 +10531,7 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, | ||||
| DEFUN (show_ip_bgp_instance_neighbor_advertised_route, | ||||
|        show_ip_bgp_instance_neighbor_advertised_route_cmd, | ||||
|        "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] " | ||||
|        "neighbors <A.B.C.D|X:X::X:X|WORD> <received-routes|advertised-routes> [route-map WORD] [json]", | ||||
|        "neighbors <A.B.C.D|X:X::X:X|WORD> <advertised-routes|received-routes|filtered-routes> [route-map WORD] [json]", | ||||
|        SHOW_STR | ||||
|        IP_STR | ||||
|        BGP_STR | ||||
| @ -10533,8 +10542,9 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route, | ||||
|        "Neighbor to display information about\n" | ||||
|        "Neighbor to display information about\n" | ||||
|        "Neighbor on BGP configured interface\n" | ||||
|        "Display the received routes from neighbor\n" | ||||
|        "Display the routes advertised to a BGP neighbor\n" | ||||
|        "Display the received routes from neighbor\n" | ||||
|        "Display the filtered routes received from neighbor\n" | ||||
|        "Route-map to modify the attributes\n" | ||||
|        "Name of the route map\n" | ||||
|        JSON_STR) | ||||
| @ -10543,18 +10553,18 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route, | ||||
| 	safi_t safi = SAFI_UNICAST; | ||||
| 	char *rmap_name = NULL; | ||||
| 	char *peerstr = NULL; | ||||
| 	int rcvd = 0; | ||||
| 	struct bgp *bgp = NULL; | ||||
| 	struct peer *peer; | ||||
| 	enum bgp_show_adj_route_type type = bgp_show_adj_route_advertised; | ||||
| 
 | ||||
| 	int idx = 0; | ||||
| 
 | ||||
| 	bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, | ||||
| 					    &bgp); | ||||
| 	if (!idx) | ||||
| 		return CMD_WARNING; | ||||
| 
 | ||||
| 	int uj = use_json(argc, argv); | ||||
| 
 | ||||
| 	if (uj) | ||||
| 		argc--; | ||||
| 
 | ||||
| @ -10566,14 +10576,17 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route, | ||||
| 	if (!peer) | ||||
| 		return CMD_WARNING; | ||||
| 
 | ||||
| 	if (argv_find(argv, argc, "received-routes", &idx)) | ||||
| 		rcvd = 1; | ||||
| 	if (argv_find(argv, argc, "advertised-routes", &idx)) | ||||
| 		rcvd = 0; | ||||
| 		type = bgp_show_adj_route_advertised; | ||||
| 	else if (argv_find(argv, argc, "received-routes", &idx)) | ||||
| 		type = bgp_show_adj_route_received; | ||||
| 	else if (argv_find(argv, argc, "filtered-routes", &idx)) | ||||
| 		type = bgp_show_adj_route_filtered; | ||||
| 
 | ||||
| 	if (argv_find(argv, argc, "route-map", &idx)) | ||||
| 		rmap_name = argv[++idx]->arg; | ||||
| 
 | ||||
| 	return peer_adj_routes(vty, peer, afi, safi, rcvd, rmap_name, uj); | ||||
| 	return peer_adj_routes(vty, peer, afi, safi, type, rmap_name, uj); | ||||
| } | ||||
| 
 | ||||
| DEFUN (show_ip_bgp_neighbor_received_prefix_filter, | ||||
|  | ||||
| @ -52,6 +52,12 @@ enum bgp_show_type { | ||||
| 	bgp_show_type_detail, | ||||
| }; | ||||
| 
 | ||||
| enum bgp_show_adj_route_type { | ||||
| 	bgp_show_adj_route_advertised, | ||||
| 	bgp_show_adj_route_received, | ||||
| 	bgp_show_adj_route_filtered, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| #define BGP_SHOW_SCODE_HEADER                                                  \ | ||||
| 	"Status codes:  s suppressed, d damped, "                              \ | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Jafar Al-Gharaibeh
						Jafar Al-Gharaibeh