Friday, February 21, 2020

BGP Regular Expressions Examples

Regular Expressions are used often for BGP route manipulation or filtering. In this lesson we’ll take a look at some useful regular expressions. First let’s take a look at the different characters that we can use:

Characters

?repeats the previous character one or zero times.
*repeats the previous character zero or many times.
+repeats the previous character one or more times.
^matches the beginning of a string.
$matches the end of a string.
[]is a range.
_matches the space between AS numbers or the end of the AS PATH list.
\\is an escape character. You’ll need this for BGP confederations.

Examples

^$matches an empty AS PATH so it will match all prefixes from the local AS.
^51_matches prefixes from AS 51 that is directly connected to our AS.
 _51_matches prefixes that transit AS 51.
 _51$matches prefixes that originated in AS 51, the $ ensures that it’s the beginning of the AS PATH.
 ^([0-9]+)_51matches prefixes from AS 51 where AS 51 is behind one of our directly connected AS’es.
 ^51_([0-9]+)matches prefixes from the clients of directly connected AS 51.
 ^(51_)+([0-9]+)matches prefixes from the clients of directly connected AS 51, where AS 51 might be doing AS PATH prepending.
 ^51_([0-9]+_)+matches prefixes from the clients of directly connected AS 51, where the clients might be doing AS PATH prepending.
^\65200\)matches prefixed from confederation peer 65200.
If you need some practice for these, I would suggest to use a BGP looking glass server.
Got some more useful BGP regular expressions? Please let me know!

No comments:

Post a Comment