BGP AS Path Filter Example

Hi Jon,

This regex seems to be valid, I tested it on a looking glass server (routeserver.sunrise.ch):

RS_AS6730>show ip bgp regexp ^([0-9]+)(_\1)+$
BGP table version is 1413944297, local router ID is 193.192.254.90
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, x best-external
Origin codes: i - IGP, e - EGP, ? - incomplete

Network Next Hop Metric LocPrf Weight Path
*>i1.9.0.0/16 193.192.254.1 20 80 0 4788 4788 4788 i
* i 193.192.254.35 20 80 0 4788 4788 4788 i
* i 212.161.178.91 20 80 0 4788 4788 4788 i
* i 212.161.178.91 20 80 0 4788 4788 4788 i
*>i1.9.21.0/24 193.192.254.1 20 80 0 4788 4788 i
* i 212.161.178.91 20 80 0 4788 4788 i
* i 212.161.178.91 20 80 0 4788 4788 i
*>i1.9.52.0/24 193.192.254.1 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
*>i1.9.53.0/24 193.192.254.1 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
*>i1.9.54.0/24 193.192.254.1 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
*>i1.9.55.0/24 193.192.254.1 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?
* i 212.161.178.91 20 80 0 4788 4788 4788 ?

And in my lab it’s working too:

hostname R1
!
router bgp 1
bgp log-neighbor-changes
network 1.1.1.0 mask 255.255.255.0
network 11.11.11.0 mask 255.255.255.0
neighbor 192.168.12.2 remote-as 2
neighbor 192.168.12.2 route-map PREPEND out

route-map PREPEND permit 10
match ip address 1
set as-path prepend 1 1 1 1 1
!
route-map PREPEND permit 20
!
access-list 1 permit 1.1.1.0 0.0.0.255

Here’s what R1 is advertising:

R1#show ip bgp neighbors 192.168.12.2 advertised-routes
BGP table version is 3, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
*> 11.11.11.0/24 0.0.0.0 0 32768 i

Total number of prefixes 2

And here’s what R2 has:

router bgp 2
bgp log-neighbor-changes
neighbor 192.168.12.1 remote-as 1
neighbor 192.168.12.1 filter-list 1 in
!
ip forward-protocol nd
!
ip as-path access-list 1 permit ^([0-9]+)(_\1)+$

And the result:

R2#show ip bgp
BGP table version is 2, local router ID is 192.168.12.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.12.1 0 0 1 1 1 1 1 1 i

This is the only prefix it’s now accepting.

Rene