Introduction
This article describes how to filter Border Gateway Protocol (BGP) prefixes with 4-byte Autonomous System (AS) numbers in Cisco IOS®.
Background Information
4-byte AS numbers were introduced in BGP when the pool of free 2-byte AS numbers became low. This means that an AS number can now be a 2-byte or a 4-byte number. RFC 6793 specifies 4-byte AS numbers. A 2-byte AS number is a number between 1 and 65,535. A 4-byte AS number is a number between 1 and 4,294,967,295.
The 4-byte AS number can be represented in a dotted fashion or as a plain number. An example of a dotted 4-byte AS number is 7.52359. This is the AS notaton dot. An example of a plain 4-byte number is 511111. This is the AS notation asplain. 7.52359 is the same as 511111.
A Cisco IOS router can use either AS notation. The default in the most recent Cisco IOS versions is asplain. In order to use the dotted AS notation, the bgp asnotation dot command can be used.
If for any reason the network administrator does not want to send out BGP prefixes with one or more 4-byte AS numbers in the AS PATH towards an External BGP (eBGP) peer, then these prefixes can be filtered. This document provides one possible filter to achieve this. There could be a few reasons why you might not want a BGP speaker to send out BGP prefixes with 4-byte AS numbers in the AS PATH. One example could be that there is a defect on the receiving BGP speaker that results in adverse behavior, which only occurs for BGP prefixes with 4-byte AS numbers in the AS PATH.
4-byte AS Number Filter
Note: The filter in this section can only be used when BGP on the router runs in asnotation dot mode.
This filter can filter out prefixes with AS PATHS that hold one or more 4-byte AS numbers.
router bgp 1
bgp asnotation dot
neighbor 10.1.1.2 remote-as 2
address-family ipv4
neighbor 10.1.1.2 activate
neighbor 10.1.1.2 filter-list 1 out
ip as-path access-list 1 deny .*[0-9]+\.[0-9]+.*
ip as-path access-list 1 permit .*
Here is an examination of this filter.
- [0-9] means any digit.
- The + means one or more occurrences. So [0-9]+ means any number, because there can be multiple digits present.
- \. means the . (dot). The backslash is needed in order to make sure the router does not treat the dot as a special character but treats it as a dot. The . is a special character and means match any character (the wildcard).
- The * means match zero or more of the preceeding. So, .* means match anything.
- The complete filter .*[0-9]+\.[0-9]+.* means anything with a dot in it.
Here is an example:
Router 1 (R1) receives eight prefixes in BGP. The BGP prefix 10.100.1.1/32 is the only prefix with an AS PATH that consists of only 2-byte AS numbers. All of the other BGP prefixes have one or more 4-byte AS number in the AS PATH.
R1#show bgp ipv4 unicast
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
*> 10.100.1.2/32 10.1.3.4 0 0 4 1.34464 3.3392 4.37856 i
*> 10.100.1.3/32 10.1.3.4 0 0 4 1.34464 200 4.37856 i
*> 10.100.1.4/32 10.1.3.4 0 0 4 500 4.37856 600 ?
*> 10.100.1.5/32 10.1.3.4 0 0 4 7.41248 3200 400 65000 ?
*> 10.100.1.6/32 10.1.3.4 0 0 4 50 3200 400 9.60176 ?
*> 10.100.1.7/32 10.1.3.4 0 0 4 66 1.57464 77 5.17320 99 ?
*> 10.100.1.8/32 10.1.3.4 0 0 4 7.52359 99 66 99 5.18307
3.37515 99 66 3.37515 99 ?
R1 advertises only the prefixes without any 4-byte AS number in the AS PATH towards the BGP peer 10.1.1.2.
R1#show bgp ipv4 unicast neighbors 10.1.1.2 advertised-routes
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
Total number of prefixes 1
You can verify what the filter .*[0-9]+\.[0-9]+.* filters from the BGP table with the show ip bgp regexp command:
R1#show ip bgp regexp .*[0-9]+\.[0-9]+.*
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.2/32 10.1.3.4 0 0 4 1.34464 3.3392 4.37856 i
*> 10.100.1.3/32 10.1.3.4 0 0 4 1.34464 200 4.37856 i
*> 10.100.1.4/32 10.1.3.4 0 0 4 500 4.37856 600 ?
*> 10.100.1.5/32 10.1.3.4 0 0 4 7.41248 3200 400 65000 ?
*> 10.100.1.6/32 10.1.3.4 0 0 4 50 3200 400 9.60176 ?
*> 10.100.1.7/32 10.1.3.4 0 0 4 66 1.57464 77 5.17320 99 ?
*> 10.100.1.8/32 10.1.3.4 0 0 4 7.52359 99 66 99 5.18307
3.37515 99 66 3.37515 99 ?
The filter .*[0-9]+\.[0-9]+.* filters out all the prefixes with one or more 4-byte AS number in the AS PATH attribute.
Here is another way to check what the filter actually filters from the BGP table:
R1#show bgp ipv4 unicast filter-list 1
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
R2 received only the prefix 10.100.1.1/32 from R1 due to the filter.
R2#show bgp ipv4 unicast
BGP table version is 6, local router ID is 10.1.1.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
*> 10.100.1.1/32 10.1.1.1 0 1 4 100 200 300 i
Alternate Configuration
An alternate configuration is to use a route-map instead of a filter-list:
router bgp 1
bgp asnotation dot
neighbor 10.1.1.2 remote-as 2
address-family ipv4
neighbor 10.1.1.2 route-map no-4byte out
ip as-path access-list 1 deny .*[0-9]+\.[0-9]+.*
ip as-path access-list 1 permit .*
route-map no-4byte permit 10
match as-path 1
Asplain Mode
When the bgp asnotiation dot command is removed, which means the asnotation is asplain, the output no longer shows the dots in the 4-byte AS numbers. This output is the same as previously shown, except that the dotted AS numbers are now asplain.
R1#show bgp ipv4 unicast
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
*> 10.100.1.2/32 10.1.3.4 0 0 4 100000 200000 300000 i
*> 10.100.1.3/32 10.1.3.4 0 0 4 100000 200 300000 i
*> 10.100.1.4/32 10.1.3.4 0 0 4 500 300000 600 ?
*> 10.100.1.5/32 10.1.3.4 0 0 4 500000 3200 400 65000 ?
*> 10.100.1.6/32 10.1.3.4 0 0 4 50 3200 400 650000 ?
*> 10.100.1.7/32 10.1.3.4 0 0 4 66 123000 77 345000 99 ?
*> 10.100.1.8/32 10.1.3.4 0 0 4 511111 99 66 99 345987
234123 99 66 234123 99 ?
The BGP show command with the regular expression used in the filter on the router does not filter out the prefixes with a dot in the BGP table, because there are no longer prefixes with the dotted 4-byte AS number format in the BGP table. The 4-byte AS numbers are now in asplain format.
R1#show ip bgp regexp .*[0-9]+\.[0-9]+.*
R1#
The BGP show command with the filter-list also shows that the filter does not work while the router is in asplain mode:
R1#show bgp ipv4 unicast filter-list 1
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
*> 10.100.1.2/32 10.1.3.4 0 0 4 100000 200000 300000 i
*> 10.100.1.3/32 10.1.3.4 0 0 4 100000 200 300000 i
*> 10.100.1.4/32 10.1.3.4 0 0 4 500 300000 600 ?
*> 10.100.1.5/32 10.1.3.4 0 0 4 500000 3200 400 65000 ?
*> 10.100.1.6/32 10.1.3.4 0 0 4 50 3200 400 650000 ?
*> 10.100.1.7/32 10.1.3.4 0 0 4 66 123000 77 345000 99 ?
*> 10.100.1.8/32 10.1.3.4 0 0 4 511111 99 66 99 65509 56
100000 ?
The as-path filter will not work:
R1#show bgp ipv4 unicast neighbors 10.1.1.2 advertised-routes
BGP table version is 9, local router ID is 10.100.1.100
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
*> 10.100.1.1/32 10.1.3.4 0 0 4 100 200 300 i
*> 10.100.1.2/32 10.1.3.4 0 0 4 100000 200000 300000 i
*> 10.100.1.3/32 10.1.3.4 0 0 4 100000 200 300000 i
*> 10.100.1.4/32 10.1.3.4 0 0 4 500 300000 600 ?
*> 10.100.1.5/32 10.1.3.4 0 0 4 500000 3200 400 65000 ?
*> 10.100.1.6/32 10.1.3.4 0 0 4 50 3200 400 650000 ?
*> 10.100.1.7/32 10.1.3.4 0 0 4 66 123000 77 345000 99 ?
*> 10.100.1.8/32 10.1.3.4 0 0 4 511111 99 66 99 65509 56
100000 ?
Network Next Hop Metric LocPrf Weight Path
Total number of prefixes 8
Filter for Asplain Mode
This filter can be used when BGP on the router runs in asplain mode:
ip as-path access-list 4 deny _6553[6-9]_
ip as-path access-list 4 deny _655[4-9][0-9]_
ip as-path access-list 4 deny _65[6-9][0-9][0-9]_
ip as-path access-list 4 deny _[6][6-9][0-9][0-9][0-9]_
ip as-path access-list 4 deny _[7-9][0-9][0-9][0-9][0-9]_
ip as-path access-list 4 deny _[1-9][0-9][0-9][0-9][0-9][0-9]+_
ip as-path access-list 4 permit .*
Or, here is the same, but more compact:
ip as-path access-list 4 deny _(6553[6-9]|655[4-9][0-9]|65[6-9][0-9][0-9]|6[6-9]
[0-9][0-9][0-9]|[7-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]+)_
ip as-path access-list 4 permit .*
Because of this filter, any AS number higher than 65,535 is filtered. Again, this can be applied to the BGP neighbor if you use a filter-list or a route-map.
Note: The filtering in this article does not work on an Internal BGP (iBGP) session, which includes on a Route Reflector.