AS-path Based Filter of Customer BGP Routes
Any serious (or at least security-aware) ISP should not blindly accept BGP routes from its customers but at the very minimum do some sanity checks on them. For example, if a multi-homed customer is clumsy enough to advertise BGP routes between service providers, it’s nice if you still stop him from turning into a transit AS. The required filter is conceptually quite simple: all the BGP routes from the customer should contain only his AS number in the AS-path.
The initial non-scalable approach is obvious: accept only the AS paths that have exactly the customer’s AS number in the AS path. For example, if your customer’s AS number is 65001, you could use this filter: ip as-path access-list 100 permit ^65001$.
A more generic approach might recognize that the AS path received from the customer shall contain a single AS number, so the filter can be rewritten as ip as-path access-list 100 permit ^[0-9]+$, where the expression [0-9]+ matches one or more digits (also known as a number).
Both filters described above have a common problem: they fail if the customer is using AS-path prepending. In those cases, you should accept all AS-paths that contain a single number (potentially repeating multiple times). The explicit filter is simple: ip as-path access-list 100 permit ^65001(_65001)*$. This filter matches all AS paths that start with 65001 and contain zero or more occurrences of a delimiter (whitespace) followed by 65001.
Writing an implicit AS-path filter that recognizes AS-path prepending is trickier and requires the use of pattern recall – part of regular expression could match a pattern recognized earlier in the regular expression. In our case, the first AS number recognized could be repeated many times over as expressed with this cryptic filter: ip as-path access-list 100 permit ^([0-9]+)(_\1)*$. The \1 part of the filter is pattern recall and matches whatever was matched within the first parenthesis (the first AS number in the AS path).
neigh filter-list 1 out
ip as-path acces-list 1 permit ^$
Would this be fine ?
To make sure someone is not misusing you for transit and sending you traffic regardless of what you announce, you'd have to deploy packet filters on the ISP-facing interfaces. Probably not worth the effort from the traffic flow perspective these days (but might be worth it from security perspective).
How we can learn 2000-5000 customer routes from ISP using BGP regular expression?
Oh, it's simple (conceptually):
Alternatively, you could use RIB-to-FIB IP prefix filters if your router supports something along those lines.
You mean, first i need to figure out around 2000 prefixes which i want to learn from ISP ...right?
Note:- As of now we are allowing default route (0.0.0.0/0) from ISP and lets assume using 100 AS on ISP side.
HI, Could you please confirm my below doubt which i have replied above in your comment? You mean, first i need to figure out around 2000 prefixes which i want to learn from ISP ...right?
Note:- As of now we are allowing default route (0.0.0.0/0) from ISP and lets assume using 100 AS on ISP side.