Crafting endless AS paths in BGP

Vincent Bernat

Com­bin­ing BGP con­fed­er­a­tions and AS over­ride can po­ten­tially cre­ate a BGP rout­ing loop, re­sult­ing in an in­def­i­nitely ex­pand­ing AS path.

BGP con­fed­er­a­tion is a tech­nique used to re­duce the num­ber of iBGP ses­sions and im­prove scal­a­bil­ity in large au­ton­o­mous sys­tems (AS). It di­vides an AS into sub-ASes. Most eBGP rules ap­ply be­tween sub-ASes, ex­cept that next-hop, MED, and lo­cal pref­er­ences re­main un­changed. The AS path length ig­nores con­tri­bu­tions from con­fed­er­a­tion sub-ASes. BGP con­fed­er­a­tion is rarely used and BGP route re­flec­tion is typ­i­cally pre­ferred for scaling.

AS over­ride is a fea­ture that al­lows a router to re­place the ASN of a neigh­bor in the AS path of out­go­ing BGP routes with its own. It’s use­ful when two dis­tinct au­ton­o­mous sys­tems share the same ASN. How­ever, it in­ter­feres with BGP’s loop pre­ven­tion mech­a­nism and should be used cau­tiously. A safer al­ter­na­tive is the allowas-in di­rective.1

In the ex­am­ple be­low, we have four routers in a sin­gle con­fed­er­a­tion, each in its own sub-AS. R0 orig­i­nates the 2001:​db8::​1/128 pre­fix. R1, R2, and R3 for­ward this pre­fix to the next router in the loop.

BGP routing loop involving 4 routers: R0 originates a prefix, R1, R2, R3 make
it loop using next-hop-self and as-override
BGP routing loop using a confederation

The router con­fig­u­ra­tions are avail­able in a Git repos­i­tory. They are run­ning Cisco IOS XR. R2 uses the fol­low­ing con­fig­u­ra­tion for BGP:

router bgp 64502
 bgp confederation peers
  64500
  64501
  64503
 !
 bgp confederation identifier 64496
 bgp router-id 1.0.0.2
 address-family ipv6 unicast
 !
 neighbor 2001:db8::2:0
  remote-as 64501
  description R1
  address-family ipv6 unicast
  !
 !
 neighbor 2001:db8::3:1
  remote-as 64503
  advertisement-interval 0
  description R3
  address-family ipv6 unicast
   next-hop-self
   as-override
  !
 !
!

The ses­sion with R3 uses both as-override and next-hop-self di­rec­tives. The lat­ter is only nec­es­sary to make the an­nounced pre­fix valid, as there is no IGP in this example.2

Here’s the se­quence of events lead­ing to an in­fi­nite AS path:

  1. R0 sends the pre­fix to R1 with AS path (64500).3

  2. R1 se­lects it as the best path, for­ward­ing it to R2 with AS path (64501 64500).

  3. R2 se­lects it as the best path, for­ward­ing it to R3 with AS path (64500 64501 64502).

  4. R3 se­lects it as the best path. It would for­ward it to R1 with AS path (64503 64502 64501 64500), but due to AS over­ride, it sub­sti­tutes R1’s ASN with its own, for­ward­ing it with AS path (64503 64502 64503 64500).

  5. R1 ac­cepts the pre­fix, as its own ASN is not in the AS path. It com­pares this new pre­fix with the one from R0. Both (64500) and (64503 64502 64503 64500) have the same length be­cause con­fed­er­a­tion sub-ASes don’t con­trib­ute to AS path length. The first tie-breaker is the router ID. R0’s router ID (1.0.0.4) is higher than R3’s (1.0.0.3). The new pre­fix be­comes the best path and is for­warded to R2 with AS path (64501 64503 64501 64503 64500).

  6. R2 re­ceives the new pre­fix, re­plac­ing the old one. It se­lects it as the best path and for­wards it to R3 with AS path (64502 64501 64502 64501 64502 64500).

  7. R3 re­ceives the new pre­fix, re­plac­ing the old one. It se­lects it as the best path and for­wards it to R0 with AS path (64503 64502 64503 64502 64503 64502 64500).

  8. R1 re­ceives the new pre­fix, re­plac­ing the old one. Again, it com­petes with the pre­fix from R0, and again the new pre­fix wins due to the lower router ID. The pre­fix is for­warded to R2 with AS path (64501 64503 64501 64503 64501 64503 64501 64500).

A few it­er­a­tions later, R1 views the loop­ing pre­fix as follows:4

RP/0/RP0/CPU0:R1#show bgp ipv6 u 2001:db8::1/128 bestpath-compare
BGP routing table entry for 2001:db8::1/128
Last Modified: Jul 28 10:23:05.560 for 00:00:00
Paths: (2 available, best #2)
  Path #1: Received by speaker 0
  Not advertised to any peer
  (64500)
    2001:db8::1:0 from 2001:db8::1:0 (1.0.0.4), if-handle 0x00000000
      Origin IGP, metric 0, localpref 100, valid, confed-external
      Received Path ID 0, Local Path ID 0, version 0
      Higher router ID than best path (path #2)
  Path #2: Received by speaker 0
  Advertised IPv6 Unicast paths to peers (in unique update groups):
    2001:db8::2:1
  (64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64503 64502 64500)
    2001:db8::4:0 from 2001:db8::4:0 (1.0.0.3), if-handle 0x00000000
      Origin IGP, metric 0, localpref 100, valid, confed-external, best, group-best
      Received Path ID 0, Local Path ID 1, version 37
      best of AS 64503, Overall best

There’s no up­per bound for an AS path, but BGP mes­sages have size lim­its (4096 bytes per RFC 4271 or 65535 bytes per RFC 8654). At some point, BGP up­dates can’t be gen­er­ated. On Cisco IOS XR, the BGP process crashes well be­fore reach­ing this limit.5


The main lessons from this tale are:

  • never use BGP con­fed­er­a­tions un­der any cir­cum­stances, and
  • be cau­tious of fea­tures that weaken BGP rout­ing loop de­tection. 🌀

Up­date (2026-10)

This post was briefly dis­cussed on Hacker News.