BGP AS_PATH Attribute on the Wire: AS_SET and AS4_PATH
At 04:08 UTC this morning the RouteViews collector in Oregon held four copies of 94.176.176.0/22. Each one had an AS path of 258 or 259 autonomous systems, 255 of them the same number, AS205624. The router marked all four maxas-limit and printed no best path: the prefix was in the table and yet unreachable from there. A few lines of the BGP AS_PATH attribute decided that. AS_PATH is the list of networks a route has crossed. It stops loops, it is the first real tie-breaker after LOCAL_PREF, and it is the attribute most people touch with prepending. This part of the series goes below the show ip bgp line: how the list is encoded byte by byte, why 4-byte AS numbers needed a second attribute (AS4_PATH) and a fake AS number (23456), what changed for AS_SET in 2025, and what a GoBGP lab and 5.6 million real Internet paths show.
- What it is: AS_PATH is type code 2, well-known mandatory. Its value is one or more segments; each segment is a type byte, a count byte and the ASNs. An eBGP speaker puts its own AS on the left; an iBGP speaker does not touch the path.[1]
- Segment types: 1 AS_SET, 2 AS_SEQUENCE, 3 AS_CONFED_SEQUENCE, 4 AS_CONFED_SET. RFC 9774 (May 2025) deprecated both set types: do not send them, treat a received one as withdraw.[1][4][5]
- 4-byte ASNs: between two 4-octet speakers every ASN is 4 bytes. Towards an old speaker the path is 2-byte, ASNs above 65535 become AS_TRANS 23456, and the real path rides in AS4_PATH (type 17). Our lab captured both encodings and the rebuild rules.[2][21]
- Loops and overrides: a router drops routes that carry its own AS. allowas-in/loops, as-override, remove-private-as and local-as change that, each with a catch. We tested them in GoBGP 4.11 and found three spots where it is more lenient than the RFCs.[1][13][15][16][17][21]
- Real Internet: in RIPE RIS rrc14 at 00:00 UTC today 66.7% of 5,587,145 IPv4 paths had 3 or 4 ASNs, 18.3% contained prepending, 873 still carried an AS_SET, and the longest had 258 ASNs.[22]
What the BGP AS_PATH attribute is
RFC 4271 calls AS_PATH a well-known mandatory attribute that "identifies the autonomous systems through which routing information carried in this UPDATE message has passed".[1] Well-known means every BGP implementation must understand it. Mandatory means it must be present in every UPDATE that announces reachable prefixes; an UPDATE that only withdraws prefixes does not need it. The attribute does three jobs, and the rest of this article follows them:
- Loop prevention. A speaker that finds its own AS number in a received path must not use the route.[1]
- Path selection. Among routes with equal LOCAL_PREF, the one with fewer ASNs wins (tie-break step (a) of RFC 4271 s.9.1.2.2, before ORIGIN and MED).[1]
- Policy. Filters match on it (AS-path regular expressions), and operators lengthen it on purpose (prepending) to steer inbound traffic.
The rules for changing it are short. When a speaker sends a route to an internal peer it "SHALL NOT modify the AS_PATH". When it sends to an external peer it prepends its own AS number on the left. A route the speaker originates goes to eBGP peers with a path that holds only its own AS, and to iBGP peers with an empty AS_PATH (attribute length 0). RFC 4271 also allows a speaker to prepend "more than one instance of its own AS number", controlled by local configuration: that one sentence is the whole legal basis of prepending.[1]
AS_PATH on the wire, byte by byte
The attribute starts with the usual header: flags 0x40 (well-known, transitive) or 0x50 when the Extended Length bit is set because the value is longer than 255 bytes, type code 0x02, and the length. The value is a list of segments. RFC 4271 defines each segment as a triple: segment type (1 byte), segment length (1 byte, "the number of ASes (not the number of octets)"), and the ASNs.[1] RFC 4271 itself still says each AS number is "encoded as a 2-octet" field; RFC 6793 widened that to 4 octets between speakers that both advertise the four-octet AS capability (code 65).[1][2]
We captured both encodings in the lab described below. Router r1 (AS 65001) learned 203.0.113.0/24 from r2 in AS 4200000002 and sent it to two raw Python speakers. Observer O had advertised capability 65; the speaker called OLD had not. These are the bytes after the 19-byte BGP header (GoBGP 4.11 lab output):[21]
to O (4-octet peer): 00 00 00 18 40 01 01 00 40 02 0a 02 02 00 00 fd e9 fa 56 ea 02 40 03 04 7f 00 02 47 18 cb 00 71
withdrawn len 0 | path attr len 0x18
40 01 01 00 ORIGIN IGP
40 02 0a 02 02 0000fde9 fa56ea02 AS_PATH: SEQUENCE of 2, 65001 4200000002
40 03 04 7f000247 NEXT_HOP 127.0.2.71
18 cb0071 NLRI 203.0.113.0/24
to OLD (2-byte peer): 00 00 00 21 40 01 01 00 40 02 06 02 02 fd e9 5b a0 40 03 04 7f 00 02 47 c0 11 0a 02 02 00 00 fd e9 fa 56 ea 02 18 cb 00 71
40 02 06 02 02 fde9 5ba0 AS_PATH: SEQUENCE of 2, 65001 23456 (AS_TRANS)
c0 11 0a 02 02 0000fde9 fa56ea02 AS4_PATH (type 17, optional transitive): 65001 4200000002
Three details are worth a second look. First, the 2-byte path still has two ASNs: AS_TRANS keeps the path length the same, so best-path selection on the old router is not distorted.[2] Second, the AS4_PATH flags are 0xC0, optional transitive, so an old router that does not know type 17 passes it on untouched. Third, the first copy of the same prefix that OLD received, before r2's route arrived, came from r3 with a prepended path, and it had no AS4_PATH at all:
00 00 00 1a 40 01 01 00 40 02 0c 02 05 fd e9 fd eb fd eb fd eb fd eb 40 03 04 7f 00 02 47 18 cb 00 71 40 02 0c 02 05 fde9 fdeb fdeb fdeb fdeb AS_PATH: 65001 65003 65003 65003 65003
That is RFC 6793 to the letter: when every ASN in the path fits in 2 bytes, the NEW speaker "MUST NOT send the AS4_PATH attribute".[2] The four copies of 65003 are r3's own AS plus three prepends from its export policy (set-as-path-prepend as "65003" repeat-n 3).
The OPEN message side of 4-byte ASNs
A speaker with a 4-byte ASN has the same problem in its OPEN message, whose My Autonomous System field is only 2 bytes. Our test speaker N (AS 4200000005) sent this OPEN body:
04 5b a0 00 5a 0a 00 00 4b 0e 02 0c 01 04 00 01 00 01 41 04 fa 56 ea 05 04 | 5ba0 = My AS 23456 (AS_TRANS) | 005a hold 90 | 0a00004b BGP ID 10.0.0.75 ... 41 04 fa56ea05 = capability 65, length 4, AS 4200000005
r1 brought the session up and listed the neighbour as AS 4200000005, because RFC 6793 tells a NEW speaker to use the AS in the capability "in lieu of" the My AS field.[2][21] An old router would have seen AS 23456 and, if configured for that number, would have peered with it; that is how a 4-byte AS peers with a 2-byte-only box at all.[2]
AS_SEQUENCE, AS_SET and the confederation segments
AS_SEQUENCE (type 2) is the normal case: an ordered list, newest AS first. Each ASN counts 1 toward the path length that best-path selection compares.[1]
AS_SET (type 1) comes from aggregation. When a speaker merges several routes into one shorter prefix, RFC 4271 lets it put the ASNs that appear in the contributing paths but not in their common leading sequence into an unordered set, so loop detection still sees them. For path length "an AS_SET counts as 1, no matter how many ASes are in the set".[1] Cisco prints a set in braces, as in the real RouteViews entry for 37.52.0.0/14 this morning: 3356 9002 6849 {6877}, (aggregated by 6849 195.5.8.126).[23]
The trouble with sets is that nobody can tell which AS in the set originated the prefix, which breaks origin validation with RPKI ROAs. BCP 172 (RFC 6472, 2011) recommended not sending them. In May 2025 RFC 9774 turned that into a requirement for both AS_SET and AS_CONFED_SET. Unless an operator configures otherwise, BGP speakers "MUST NOT advertise BGP UPDATE messages containing AS_SETs or AS_CONFED_SETs" and "MUST use the 'treat-as-withdraw' error handling behavior" when they receive one, in AS_PATH or in AS4_PATH.[5][6] For aggregation it asks for "consistent brief" aggregation instead: truncate the path after the desired origin AS and attach ATOMIC_AGGREGATE.[5]
AS_CONFED_SEQUENCE (3) and AS_CONFED_SET (4) exist only inside a confederation (RFC 5065): member-AS hops are recorded in these segments, and at the confederation edge they are removed and replaced by the confederation identifier. RFC 5065 says they "SHOULD NOT be counted" in path length.[4] Cisco prints confed sequences in parentheses. Confederations get their own part later in the series.
4-byte ASNs: AS_TRANS, AS4_PATH and how the path is rebuilt
The 2-byte AS space ran short in the mid-2000s. RFC 4893 (May 2007) added 4-octet ASNs, and RFC 6793 (December 2012) replaced it.[3][2] The design keeps old routers working without touching them:
- Between two NEW speakers, AS_PATH carries 4-byte ASNs, and AS4_PATH "MUST NOT be carried". If a NEW speaker receives AS4_PATH from another NEW speaker anyway, it "MUST discard the path attribute and continue processing the UPDATE".[2]
- Towards an OLD speaker, AS_PATH is 2-byte with AS_TRANS (23456) in place of every non-mappable ASN, plus AS4_PATH with the real 4-byte path (confederation segments excluded).[2]
- A NEW speaker that receives both from an OLD neighbour counts the ASNs in each. If AS_PATH has fewer than AS4_PATH, AS4_PATH "SHALL be ignored". Otherwise it takes as many leading ASNs from AS_PATH as needed and prepends them to AS4_PATH, so the result has the AS_PATH's length.[2]
We sent both cases from OLD (AS 65004, no capability 65). The first UPDATE carried the 2-byte path 65004 23456 65010 and AS4_PATH 4200000099 65010; the second carried 65004 23456 with a three-ASN AS4_PATH. GoBGP 4.11 rebuilt the first and ignored the second, exactly as RFC 6793 s.4.2.3 says (GoBGP 4.11 lab output):[21]
$ gobgp global rib -a ipv4 192.0.2.0/24
Network Next Hop AS_PATH Age Attrs
*> 192.0.2.0/24 127.0.2.74 65004 4200000099 65010 00:00:04 [{Origin: i}]
$ gobgp global rib -a ipv4 198.19.0.0/24
Network Next Hop AS_PATH Age Attrs
*> 198.19.0.0/24 127.0.2.74 65004 23456 00:00:02 [{Origin: i}]
The second result is what you would see in a real table if an old router somewhere aggregated or mangled the path: AS 23456 stays visible. RFC 6793 itself warns that the full path cannot always be rebuilt, for example after an OLD speaker aggregates routes that carry 4-byte ASNs.[2] We also sent AS4_PATH from N, a NEW speaker. GoBGP discarded the attribute, kept the route with its AS_PATH 4200000005 65070, and when it passed the route to OLD it built a fresh AS4_PATH of its own.[21]
How common is this today? In the RIS snapshot, 2,240,695 of 5,587,145 IPv4 entries (40.1%) contained at least one ASN above 65535, and not a single entry contained AS 23456.[22] Every RIS peer session is 4-octet, so the collector never sees the 2-byte form. The AS_TRANS machinery still runs, but only on the last old boxes at the edge.
Loop prevention and the knobs that bend it
RFC 4271 s.9.1.2 is plain: if the AS_PATH "contains an AS loop", the route "should be excluded from the Phase 2 decision function", and detection is done by "checking that the autonomous system number of the local system does not appear in the AS path". Accepting your own AS is "outside the scope of this document".[1] RFC 5065 adds that a confederation member must treat its confederation identifier the same way.[4] That rule breaks in one common design: a customer with many sites that all use the same AS number behind an MPLS VPN or a single transit. Site A's routes arrive at site B with B's own AS in the path and are dropped. Vendors offer four knobs:
- allowas-in [n] (Junos:
loops n, GoBGP:allow-own-as) on the receiving router accepts routes that contain its own AS up to n times. FRR accepts 1-10 occurrences ororigin(only routes originated by the own AS).[13][16][17] - as-override (GoBGP:
replace-peer-as) on the sending PE replaces the customer's AS in the path with the provider's AS, so the receiving CE sees no loop. Juniper warns that it can create real loops, and Cisco tells you to use it together with Site of Origin (SoO).[13][14][15][16] - remove-private-as strips private ASNs (64512-65534 and 4200000000-4294967294) towards an eBGP peer.[9][12] Classic Cisco IOS removes them only if the path has nothing but private ASNs, and not if the path contains the neighbour's AS; the
allandreplace-askeywords on IOS XE go further.[12] - local-as makes the router appear to one neighbour as a different AS, usually during an AS migration. FRR by default prepends the local-as in addition to the real AS;
no-prependandreplace-aschange that. Junos addsprivateandaliasoptions.[15][16]
We ran all four in GoBGP 4.11, in three phases with fresh daemons. Phase A had no options:
$ gobgp global rib -a ipv4 198.18.1.0/24 # N sent 4200000005 65001 65020 Network not in table
The route with r1's own AS 65001 in the middle was dropped silently. The Discarded counter did not move and the session stayed up.[21] In phase B we set allow-own-as = 1 on N's session and remove-private-as = "all" plus replace-peer-as = true towards O:
$ gobgp global rib -a ipv4 198.18.1.0/24 # one copy of 65001: now accepted
Network Next Hop AS_PATH Age Attrs
*> 198.18.1.0/24 127.0.2.75 4200000005 65001 65020 00:00:02 [{Origin: i}]
$ gobgp global rib -a ipv4 198.18.12.0/24 # 4200000005 65001 65001 65021: two copies, still dropped
Network not in table
$ gobgp neighbor 127.0.2.76 adj-out -a ipv4 # towards O with remove-private-as all
ID Network Next Hop AS_PATH AttrsFiltered
1 198.18.0.0/24 127.0.2.71 65001 [{Origin: i}]not filtered
1 198.18.1.0/24 127.0.2.71 65001 [{Origin: i}]not filtered
1 198.18.10.0/24 127.0.2.71 65001 [{Origin: i}]not filtered
1 198.18.13.0/24 127.0.2.71 65001 3356 [{Origin: i}]not filtered
2 203.0.113.0/24 127.0.2.71 65001 [{Origin: i}]not filtered
$ gobgp neighbor 127.0.2.74 adj-out -a ipv4 # same routes towards OLD, no options
ID Network Next Hop AS_PATH AttrsFiltered
1 198.18.0.0/24 127.0.2.71 65001 4200000005 65010 64512 [{Origin: i}]not filtered
1 198.18.1.0/24 127.0.2.71 65001 4200000005 65001 65020 [{Origin: i}]not filtered
1 198.18.10.0/24 127.0.2.71 65001 4200000005 65006 65090 [{Origin: i}]not filtered
1 198.18.13.0/24 127.0.2.71 65001 4200000005 3356 64600 [{Origin: i}]not filtered
2 203.0.113.0/24 127.0.2.71 65001 4200000002 [{Origin: i}]not filtered
Two results stand out. GoBGP's all removed private ASNs even when a public ASN sat between them (4200000005 3356 64600 became 65001 3356); classic IOS without all would have left that path alone.[12][21] And the routes from N lost every ASN but r1's: 4200000005, 65010, 64512 and also 65006 are all private, so the replace-peer-as effect on 198.18.10.0/24 is hidden by the private-AS removal. Test as-override on its own before you rely on it. In phase A, without replace-peer-as, r1 did not send 198.18.10.0/24 to O at all, because the path already contained O's AS 65006; it sent it to OLD. That sender-side check saves an UPDATE that the receiver would drop anyway.[21]
Phase C set local-as = 64999 towards O. r1's OPEN to O carried My AS fde7 (64999) and capability 65 with 64999, and the paths came out like this:
ID Network Next Hop AS_PATH AttrsFiltered
1 198.18.0.0/24 127.0.2.71 64999 4200000005 65010 64512 [{Origin: i}]not filtered
1 198.18.13.0/24 127.0.2.71 64999 4200000005 3356 64600 [{Origin: i}]not filtered
2 203.0.113.0/24 127.0.2.71 64999 4200000002 [{Origin: i}]not filtered
GoBGP replaced 65001 with 64999 instead of adding both. FRR documents a different default: without modifiers the local-as is prepended to received paths and added to outgoing paths in addition to the process AS, and only no-prepend replace-as sends the local-as alone. The same word means different paths on different stacks.[16][21] Check what your peer actually receives (show ip bgp neighbors x advertised-routes or its looking glass) after every local-as change.
AS_PATH length in best-path selection
RFC 4271 compares AS_PATH length first among routes that are equally preferable after LOCAL_PREF: "Remove from consideration all routes that are not tied for having the smallest number of AS numbers present in their AS_PATH attributes", with an AS_SET counting 1.[1] Cisco puts it after weight, LOCAL_PREF, locally originated routes and AIGP, and before ORIGIN and MED.[10] Our r1 showed the simplest case. r2 sent 203.0.113.0/24 with path 4200000002, r3 with 65003 65003 65003 65003; r3's route arrived first and still lost:
$ gobgp global rib -a ipv4 203.0.113.0/24
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.72 4200000002 00:00:02 [{Origin: i}]
* 203.0.113.0/24 127.0.2.73 65003 65003 65003 65003 00:00:03 [{Origin: i}]
Some knobs take length out of the decision or loosen it. IOS XR has bgp bestpath as-path ignore: "all steps are performed as usual except comparison of the autonomous path length".[13] FRR has bgp bestpath as-path multipath-relax, which lets routes with equal length but different ASNs share load (by default the whole path must match), and bgp bestpath as-path confed, which counts confed segments after all.[16] Two things the length does not tell you: how many routers the traffic crosses (one AS can be a single router or a continent) and whether the path is real. Prepends, AS_SETs and AS 23456 all bend the count.
Prepending in real tables
Prepending is the most used inbound traffic-engineering tool that needs no help from the provider: you send a longer path on the link you want to be backup. Our earlier article on controlling inbound BGP traffic covers the design side. Here is what it looks like in bulk. We parsed the full RIS rrc14 RIB dump of 00:00 UTC today with our own MRT parser:[22]
- 5,587,145 IPv4 and 1,396,903 IPv6 entries from 20 peers. Average IPv4 path length 4.14 ASNs, 3.68 once repeated ASNs are collapsed. 66.7% of entries had 3 or 4 ASNs.
- 1,024,822 IPv4 entries (18.3%) and 259,229 IPv6 entries (18.6%) contained at least one repeated ASN. In 658,948 IPv4 entries the repetition was at the origin end, the typical "prepend to everyone" pattern.
- 17,307 IPv4 entries repeated one ASN 10 or more times; 51,880 had more than 10 ASNs and 15 more than 50.
- Only 11 IPv4 entries carried a private ASN after the first hop, for example
6762 42845 65300 65340 65302 64906 47977seen via Sparkle. Somebody's remove-private-as did not fire.
Doug Madory showed at RIPE 79 that excessive prepending is "a self-inflicted vulnerability": a long path loses to any shorter announcement of the same prefix, including a hijack or a leak, and he found prefixes prepended to everyone that leaked further than they should have.[20] The data above matches that picture: prepending is everywhere, and much of it is applied to all neighbours, where it only makes the route weaker.
The extreme case from the intro is real data from two independent collectors. In RIS rrc14 the AS_PATH for 94.176.176.0/22 was 258 ASNs long, encoded as two AS_SEQUENCE segments of 3 and 255 ASNs, attribute flags 0x50 (extended length) and 1,036 bytes of value. Only two of the five IPv4 full-table peers at rrc14 had the route at all, both via AS174 Cogent, which hints that the others filter long paths.[22] RouteViews had four copies and refused all four:[23]
route-views> show ip bgp 94.176.176.0/22
BGP routing table entry for 94.176.176.0/22, version 0
Paths: (4 available, no best path)
Not advertised to any peer
49788 174 35699 205624 205624 205624 ... (255 x 205624)
Origin IGP, metric 0, localpref 100, valid, external, maxas-limit
... 3 more paths of length 258-259, all flagged maxas-limit
Prefix 102.206.158.0/24 shows a less extreme version: the best path was 3356 5511 37447, while copies with 125, 99 and 48 repeats of AS37447 were valid but lost on length. The long prepend strings also contain a typo, a stray 3744 between copies of 37447 (37447 3744 37447), visible both at RouteViews and in RIS.[23][22] Madory showed the same kind of transposed-digit prepends in 2020.[20]
Long paths have broken more than reachability. In February 2009, AS47868 announced a prefix with 252 prepends. NANOG traced it to a router configuration that expected a prepend count, received an AS number, and kept only the low 8 bits: 47868 mod 256 = 252.[19] Ivan Pepelnjak and Cisco reproduced the Cisco IOS bug that turned this into session resets (CSCsx73770): with inbound or outbound prepending on a path close to 255 ASNs, IOS sent a malformed UPDATE and the downstream peer reset the session. The workaround was bgp maxas-limit.[18] The 255 matters because it is the limit of one segment's count byte. Our lab shows how a correct implementation handles the overflow: when N sent 256 ASNs as two segments (255 + 1), r1 added a new one-ASN segment in front instead of overflowing the first one, as RFC 4271 s.5.1.2 says:[1][21]
to O: 40 01 01 00 50 02 040a 02 01 0000fde9 02 ff fa56ea05 0000fe38 0000fe38 ...
extended length 0x040a = 1034 bytes: SEQ(1) 65001, SEQ(255) 4200000005 65080 x254, then SEQ(1) 65081
to OLD: 40 01 01 00 50 02 0208 02 01 fde9 02 ff 5ba0 fe38 fe38 ... + AS4_PATH
Malformed and unusual AS_PATHs: RFC vs GoBGP 4.11
Before 2015 a broken AS_PATH reset the session with error subcode 11, Malformed AS_PATH.[1] RFC 7606 changed that to treat-as-withdraw: the routes in the bad UPDATE are removed, the session stays up. An AS_PATH is malformed if a segment type is unknown, a segment length overruns the attribute, one byte is left over, or a segment has length zero. RFC 7606 also asks that a route whose leftmost AS is not the peer's AS be treated as withdraw.[7] RFC 7607 adds AS 0: an AS_PATH with AS 0 is malformed.[8] We sent ten unusual paths from N and checked r1 after each:
Seven results follow the standards. Three do not, and they are worth knowing if you run GoBGP as a route server or a monitoring collector:
$ gobgp global rib -a ipv4 198.18.2.0/24 # AS_SET: RFC 9774 says treat-as-withdraw
Network Next Hop AS_PATH Age Attrs
*> 198.18.2.0/24 127.0.2.75 4200000005 65030 {65031,65032} 00:00:02 [{Origin: i}]
$ gobgp global rib -a ipv4 198.18.7.0/24 # leftmost AS 65099 is not N's AS 4200000005
Network Next Hop AS_PATH Age Attrs
*> 198.18.7.0/24 127.0.2.75 65099 65060 00:00:02 [{Origin: i}]
$ gobgp global rib -a ipv4 198.18.11.0/24 # empty AS_PATH from an eBGP peer
Network Next Hop AS_PATH Age Attrs
*> 198.18.11.0/24 127.0.2.75 00:00:02 [{Origin: i}]
GoBGP 4.11 accepted the AS_SET and also sent it on to O, with r1's sequence in front: 02 03 0000fde9 fa56ea05 0000fe06 01 02 0000fe07 0000fe08. It accepted a path whose first AS was not the peer's, and an empty AS_PATH from an eBGP peer, and passed both on with only 65001 added.[21] RFC 4271 makes the first-AS check a MAY, so this is legal, but Cisco IOS XR reports the opposite behaviour as "Enforce first AS enabled" in show bgp process, controlled by bgp enforce-first-as disable.[13] The confed sequence, AS 0 and the two malformed segment cases were dropped; only the two length errors raised the Discarded counter. Grep the log, not only the counters, when a prefix goes missing.
Configuration examples
These are configuration examples in the syntax of the official documentation, not lab output. A CE that reuses the customer AS at every site, and the PE alternative:[13][14][16]
! Cisco IOS XE - CE accepts its own AS once (site-to-site over the same AS)
router bgp 65000
address-family ipv4
neighbor 10.1.1.1 allowas-in 1
!
! Cisco IOS XE - or on the PE: replace the customer AS towards the CE
router bgp 10
address-family ipv4 vrf CUST
neighbor 10.1.1.2 as-override
!
! Cisco IOS XR - prepend twice on export, cap received path length
route-policy PREPEND-BACKUP
prepend as-path 65001 2
end-policy
route-policy DROP-LONG
if as-path length ge 50 then
drop
else
pass
endif
end-policy
# Junos - accept own AS once, strip private ASNs to an upstream set routing-options autonomous-system 65001 loops 2 set protocols bgp group UPSTREAM remove-private set policy-options policy-statement PREPEND then as-path-prepend "65001 65001" # FRR router bgp 65001 neighbor 192.0.2.1 remote-as 64496 address-family ipv4 unicast neighbor 192.0.2.1 allowas-in 1 neighbor 192.0.2.1 remove-private-AS all replace-AS neighbor 192.0.2.1 route-map PREPEND out route-map PREPEND permit 10 set as-path prepend 65001 65001
Test the Junos loops value in a lab before production: it sets how many occurrences of the own AS are tolerated, and the same option also exists on local-as.[15] The IOS XR as-path length condition is a route-policy match; treat the threshold as your choice, not a standard value. For the matching side, AS-path regular expressions and filter lists are covered in Filtering BGP Routes: Prefix Lists and AS-Path Filters.
Common mistakes and troubleshooting
| Symptom | Cause | Check / fix |
|---|---|---|
| Routes between two sites of the same AS never arrive | AS loop check drops them; the own AS is in the path[1] | allowas-in 1 on the CE or as-override on the PE, plus SoO |
| AS 23456 shows up in a path | An old speaker in the path, and AS4_PATH was lost or inconsistent[2] | Find the 2-byte-only box; compare paths from several collectors |
| Prepending changes nothing | The upstream sets LOCAL_PREF on customer routes, compared before length[1] | Use the provider's TE communities instead |
| A prefix is visible on some looking glasses, missing on others | Length filters (maxas-limit) or AS_SET filtering under RFC 9774[5][23] | Shorten the prepend string, stop sending AS_SET |
| remove-private-as seems to do nothing | Classic IOS keeps private ASNs when a public ASN is in the path[12] | Use remove-private-as all, or fix the design |
| After a local-as change the peer sees the wrong path | Different defaults: prepend both vs replace[16][21] | Read the advertised routes, set no-prepend replace-as explicitly |
| A typo in a prepend string | A foreign or wrong ASN in the path, like 37447 3744 37447[23] | Use a prepend count (prepend as-path 65001 3, last-as) instead of typed strings |
For a public prefix, our free BGP Route Lookup shows the origin AS and AS paths seen by RIPE RIS; to read a full Cisco route-server entry line by line, see How to Read a Real BGP Table Entry.
FAQ
What is the BGP AS_PATH attribute?
AS_PATH (type code 2) is a well-known mandatory attribute that lists the autonomous systems a route has crossed, newest on the left. Every eBGP speaker adds its own AS when it sends the route on; iBGP speakers leave it alone. Routers use it for loop prevention, for best-path selection (shorter wins) and for policy.
What is the difference between AS_SEQUENCE and AS_SET?
An AS_SEQUENCE is an ordered list of ASNs and each ASN counts 1 toward path length. An AS_SET is an unordered set created by route aggregation and counts 1 in total. RFC 9774 (May 2025) deprecated AS_SET: speakers MUST NOT send it and MUST treat a received one as withdraw, unless an operator configures otherwise.
What is AS 23456 in a BGP path?
AS 23456 is AS_TRANS, a reserved 2-byte placeholder from RFC 6793. A router that supports 4-byte ASNs sends it to an old 2-byte-only neighbour in place of every ASN above 65535, and carries the real numbers in the optional transitive AS4_PATH attribute. If you see 23456 in a modern table, some router on the way failed to rebuild the path.
How does BGP prevent routing loops with AS_PATH?
A router drops any route whose AS_PATH already contains its own AS number (RFC 4271 s.9.1.2). Knobs such as allowas-in (Junos: loops), as-override and local-as change this check or the numbers in the path, mostly for MPLS VPN sites that reuse one AS number and for AS migrations.
Does AS_PATH prepending always work?
Only where AS_PATH length decides. LOCAL_PREF is compared earlier, so a provider that prefers customer routes ignores your prepends. Very long prepends also hurt: in our RouteViews capture a path with 255 copies of the same ASN was flagged maxas-limit and never used.
What is the maximum length of an AS_PATH?
One segment holds at most 255 ASNs, because its count field is one byte. Longer paths use more segments, and the attribute switches to the 2-byte extended length. Many operators cap the length by policy (Cisco bgp maxas-limit). On 30 November 2026 RIPE RIS rrc14 held IPv4 paths of up to 258 ASNs.
What does remove-private-as do?
It removes private ASNs (64512-65534 and 4200000000-4294967294) from the AS_PATH sent to an eBGP neighbour. Classic Cisco IOS removes them only if the path contains nothing but private ASNs; the all keyword removes them everywhere. GoBGP's remove-private-as all removed them even between public ASNs in our lab.
Our shorter posts on the same attribute are BGP AS_PATH: Loop Prevention and Path Selection (2026) and BGP Attribute - AS_PATH (2012). Large communities, the policy tags built for 4-byte ASNs, are in BGP Large Communities: Policy Tags for 4-Byte ASNs. Next in the series is NEXT_HOP, the third well-known mandatory attribute.
Series hub: BGP in 26 Parts: From EGP to EVPN
Previous: BGP ORIGIN Attribute: Lab Tests and Who Rewrites It
Next: How BGP NEXT_HOP Changes Between eBGP and iBGP (coming soon)
References (all read on 30 November 2026)
[1] Y. Rekhter, T. Li, S. Hares (eds.), RFC 4271: A Border Gateway Protocol 4 (BGP-4), January 2006: s.4.3 b), s.5.1.2, s.6.3, s.9.1.2, s.9.1.2.2 (a).
[2] Q. Vohra, E. Chen, RFC 6793: BGP Support for Four-Octet Autonomous System (AS) Number Space, December 2012: s.3 AS_TRANS, s.4.1-4.2.3.
[3] Q. Vohra, E. Chen, RFC 4893: BGP Support for Four-octet AS Number Space, May 2007 (obsoleted by RFC 6793).
[4] P. Traina, D. McPherson, J. Scudder, RFC 5065: Autonomous System Confederations for BGP, August 2007: s.3 segment types, s.4, s.5.
[5] W. Kumari, K. Sriram, L. Hannachi, J. Haas, RFC 9774: Deprecation of AS_SET and AS_CONFED_SET in BGP, May 2025: s.3, s.5.2.
[6] W. Kumari, K. Sriram, RFC 6472 (BCP 172): Recommendation for Not Using AS_SET and AS_CONFED_SET in BGP, December 2011 (obsoleted by RFC 9774).
[7] E. Chen, J. Scudder, P. Mohapatra, K. Patel, RFC 7606: Revised Error Handling for BGP UPDATE Messages, August 2015: s.7.2.
[8] W. Kumari, R. Bush, H. Schiller, K. Patel, RFC 7607: Codification of AS 0 Processing, August 2015.
[9] J. Mitchell, RFC 6996: Autonomous System (AS) Reservation for Private Use, July 2013; RFC 7300: Reservation of Last Autonomous System (AS) Numbers, July 2014; IANA Autonomous System (AS) Numbers registry.
[10] Cisco, Select BGP Best-path Algorithm, document 13753.
[11] G. Huston, M. Rossi, G. Armitage, RFC 5398: Autonomous System (AS) Number Reservation for Documentation Use, December 2008.
[12] Cisco, Removing Private Autonomous System Numbers in BGP, document 13756; IOS XE 17.x: Removing Private AS Numbers from the AS Path in BGP.
[13] Cisco, BGP Command Reference for Cisco 8000 Series Routers (allowas-in, as-override, bgp bestpath as-path ignore); BGP Commands on Cisco IOS XR Software, Release 4.0 (show bgp process: Enforce first AS).
[14] Cisco Community, MPLS VPN with eBGP on PE-CE Links: AS Override and allowas-in.
[15] Juniper Networks, Junos CLI reference: as-override, remove-private, local-as.
[16] FRRouting, BGP documentation (allowas-in, as-override, local-as, set as-path prepend, bgp bestpath as-path confed / multipath-relax) and source bgpd/bgp_vty.c (remove-private-AS all replace-AS), master branch.
[17] GoBGP, configuration.md (local-as, remove-private-as, allow-own-as, replace-peer-as) and policy.md (set-as-path-prepend, as-path-length).
[18] I. Pepelnjak, Oversized AS Paths: Cisco IOS Bug Details and Root Cause Analysis: Oversized AS Paths, ipSpace.net, 20 February 2009.
[19] NANOG mailing list, Lots of prepends - AS20912 case, 20 February 2009.
[20] D. Madory, M. Prosser, Excessive BGP AS Path Prepending is a Self-Inflicted Vulnerability, RIPE 79, 2019; updated talk at LACNOG, October 2020.
[21] Network freak lab: GoBGP 4.11.0 routers r1-r3 (127.0.2.71-73) and raw Python BGP speakers OLD, N and O (127.0.2.74-76), three phases, 30 November 2026, 05:33-05:40 CET. Configs, logs and bytes kept with the article sources.
[22] RIPE NCC, RIS raw data, rrc14: bview.20261130.0000.gz (30 November 2026 00:00 UTC), parsed with our own MRT TABLE_DUMP_V2 parser.
[23] University of Oregon RouteViews, route-views.routeviews.org (telnet, user rviews): show ip bgp for 94.176.176.0/22, 37.52.0.0/14, 102.206.158.0/24 and 103.169.198.0/24, 30 November 2026, 04:08 UTC.
Figures 1-8: Network freak, drawn from the sources above, our lab, RIPE RIS and RouteViews.
Try it: BGP Route Lookup: origin AS, AS paths and RPKI check - free, runs in your browser.
Comments
Post a Comment