Octet

How do AS path access lists and regular expressions work? Give me the common patterns.

Show the answer

Say this first

An AS path access list (ip as-path access-list) matches the AS_PATH as a string using a regular expression, and is applied with neighbor x filter-list N in|out or match as-path in a route map. The patterns everyone uses: ^$ is my own routes (empty path), ^64496_ came in from neighbor 64496, _64496$ was originated by 64496, ^64496$ was originated by 64496 and learned directly from it, _64496_ passed through 64496 anywhere, and .* matches everything.

Go deeper

Characters

SymbolMeaning
^ $Start and end of the path
_Any delimiter: space, comma, brace, start or end of string
.Any single character
* + ?Zero or more, one or more, zero or one of the previous item
[0-9]One character from a range
( ) ``

Patterns

RegexMatches
^$Locally originated routes
.*Any path
^64496$Originated by directly connected AS 64496
^64496_Learned from 64496
_64496$Originated by 64496, from anywhere
_64496_64496 anywhere in the path
^64496_[0-9]+$One AS behind 64496: its direct customers
^64500(_64500)*$Originated by 64500, with any number of prepends
^[0-9]+$Originated by whichever neighbor sent it

Test before you apply

Output
R1# show ip bgp regexp ^64496_[0-9]+$

Then apply:

Cisco IOS
ip as-path access-list 10 permit ^64496_[0-9]+$
ip as-path access-list 10 permit ^64496$
!
router bgp 64500
 neighbor 192.0.2.1 filter-list 10 in

Like prefix lists, AS path access lists end with an implicit deny.

Junos

Junos AS path regex works on whole AS numbers, not characters: . is any one AS, so 64496 .* means learned from 64496.

Traps

  • Writing 64496 with no anchors, which matches 164496 or 644961 as well.
How did you do?Book 4.1 Global Internet