Search routing table by subnet mask

So I recently ran into an issue where one of my BGP peers was sending me very specific routes smaller than /24 causing some routing loops within our internal network.

Is there a way to search the routing table for routes based on subnet mask or prefix length?

I have three BGP peers and over 1.5million routes so running a “ip route print where ‘string’ in dst-address” would take forever to complete even on a CCR and I don’t think it would accomplish the goal…

I’ve adjusted my filters to remove routes smaller than /24, the routing count went down for the peer but I wanted to confirm visually.

OK well.. it wasn’t as straight forward as:

sh ip bgp | i /25

in ROS its gotta be a regex..

ip route pr where dst-address~"^[0-9 \\.]*/25"

rinse and repeat for other prefixes… and wait for the CCR to go through all 1.6Million routes.

This seems too resource intensive – can we get grep already?!

IMHO you should have filters which will not allow to accept longer prefixes (than /24) from BGP peers (among with other things which is not safe to receive from a peer)…