RFC 4271
A Border Gateway Protocol 4 (BGP-4)
A Border Gateway Protocol 4 (BGP-4) ๐
okay bestie, this is RFC 4271 ๐ the spec that defines BGP-4, so every word counts. It came out of the Network Working Group in January 2006 and is a Standards Track document. The editors are Y. Rekhter, T. Li, and S. Hares, each marked as Ed. โจ It obsoletes RFC 1771, so that older version is officially replaced by this one ๐
Status of This Memo
This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. For the standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1) ๐ง Distribution of this memo is unlimited.
Copyright Notice
Copyright (C) The Internet Society (2006). ๐ธ
Abstract
okay so this doc is all about the Border Gateway Protocol (BGP), which is an inter-Autonomous System routing protocol ๐ฆ
The main job of a BGP speaking system is to swap network reachability information with other BGP systems. That info includes the list of Autonomous Systems (ASes) that the reachability info travels through. It's enough to build a graph of AS connectivity for that reachability, which lets you prune routing loops and, at the AS level, enforce some policy decisions ๐
BGP-4 comes with a set of mechanisms for Classless Inter-Domain Routing (CIDR). It lets you advertise a bunch of destinations as one IP prefix, and it gets rid of the whole idea of network "class" inside BGP ๐ BGP-4 also brings in ways to aggregate routes, including aggregating AS paths, which is so iconic โจ
This document obsoletes RFC 1771.
Table of Contents ๐
1. Introduction ....................................................4
1.1. Definition of Commonly Used Terms ..........................4
1.2. Specification of Requirements ..............................6
2. Acknowledgements ................................................6
3. Summary of Operation ............................................7
3.1. Routes: Advertisement and Storage ..........................9
3.2. Routing Information Base ..................................10
4. Message Formats ................................................11
4.1. Message Header Format .....................................12
4.2. OPEN Message Format .......................................13
4.3. UPDATE Message Format .....................................14
4.4. KEEPALIVE Message Format ..................................21
4.5. NOTIFICATION Message Format ...............................21
5. Path Attributes ................................................23
5.1. Path Attribute Usage ......................................25
5.1.1. ORIGIN .............................................25
5.1.2. AS_PATH ............................................25
5.1.3. NEXT_HOP ...........................................26
5.1.4. MULTI_EXIT_DISC ....................................28
5.1.5. LOCAL_PREF .........................................29
5.1.6. ATOMIC_AGGREGATE ...................................29
5.1.7. AGGREGATOR .........................................30
6. BGP Error Handling. ............................................30
6.1. Message Header Error Handling .............................31
6.2. OPEN Message Error Handling ...............................31
6.3. UPDATE Message Error Handling .............................32
6.4. NOTIFICATION Message Error Handling .......................34
6.5. Hold Timer Expired Error Handling .........................34
6.6. Finite State Machine Error Handling .......................35
6.7. Cease .....................................................35
6.8. BGP Connection Collision Detection ........................35
7. BGP Version Negotiation ........................................36
8. BGP Finite State Machine (FSM) .................................37
8.1. Events for the BGP FSM ....................................38
8.1.1. Optional Events Linked to Optional Session
Attributes .........................................38
8.1.2. Administrative Events ..............................42
8.1.3. Timer Events .......................................46
8.1.4. TCP Connection-Based Events ........................47
8.1.5. BGP Message-Based Events ...........................49
8.2. Description of FSM ........................................51
8.2.1. FSM Definition .....................................51
8.2.1.1. Terms "active" and "passive" ..............52
8.2.1.2. FSM and Collision Detection ...............52
8.2.1.3. FSM and Optional Session Attributes .......52
8.2.1.4. FSM Event Numbers .........................53
8.2.1.5. FSM Actions that are Implementation
Dependent .................................53
8.2.2. Finite State Machine ...............................53
9. UPDATE Message Handling ........................................75
9.1. Decision Process ..........................................76
9.1.1. Phase 1: Calculation of Degree of Preference .......77
9.1.2. Phase 2: Route Selection ...........................77
9.1.2.1. Route Resolvability Condition .............79
9.1.2.2. Breaking Ties (Phase 2) ...................80
9.1.3. Phase 3: Route Dissemination .......................82
9.1.4. Overlapping Routes .................................83
9.2. Update-Send Process .......................................84
9.2.1. Controlling Routing Traffic Overhead ...............85
9.2.1.1. Frequency of Route Advertisement ..........85
9.2.1.2. Frequency of Route Origination ............85
9.2.2. Efficient Organization of Routing Information ......86
9.2.2.1. Information Reduction .....................86
9.2.2.2. Aggregating Routing Information ...........87
9.3. Route Selection Criteria ..................................89
9.4. Originating BGP routes ....................................89
10. BGP Timers ....................................................90
Appendix A. Comparison with RFC 1771 .............................92
Appendix B. Comparison with RFC 1267 .............................93
Appendix C. Comparison with RFC 1163 .............................93
Appendix D. Comparison with RFC 1105 .............................94
Appendix E. TCP Options that May Be Used with BGP ................94
Appendix F. Implementation Recommendations .......................95
Appendix F.1. Multiple Networks Per Message .........95
Appendix F.2. Reducing Route Flapping ...............96
Appendix F.3. Path Attribute Ordering ...............96
Appendix F.4. AS_SET Sorting ........................96
Appendix F.5. Control Over Version Negotiation ......96
Appendix F.6. Complex AS_PATH Aggregation ...........96
Security Considerations ...........................................97
IANA Considerations ...............................................99
Normative References .............................................101
Informative References ...........................................101
1. Introduction โจ
okay so BGP (the Border Gateway Protocol) is an inter-Autonomous System routing protocol ๐
Its main job is swapping network reachability information with other BGP systems. That info includes the list of Autonomous Systems (ASes) the reachability info travels through. It's enough to build a graph of AS connectivity for that reachability, which means routing loops can get pruned and, at the AS level, some policy decisions can be enforced ๐ซถ
BGP-4 supports Classless Inter-Domain Routing (CIDR) [RFC1518, RFC1519] ๐ It lets you advertise a set of destinations as an IP prefix, and it ditches the concept of network "class" within BGP. BGP-4 also brings in mechanisms for aggregating routes, including aggregating AS paths. literally so iconic ๐
Here's the part that's lowkey important ๐ routing info exchanged over BGP only supports the destination-based forwarding paradigm. That means a router forwards a packet based solely on the destination address in the packet's IP header. This reflects the set of policy decisions that BGP can and cannot enforce. BGP can only support policies that conform to the destination-based forwarding paradigm ๐ฆ
1.1. Definition of Commonly Used Terms โจ
okay bestie, before we dive in we need the vocab ๐๐ this section defines the terms BGP uses like it's their whole personality, and they show up everywhere after this, so let's lock them in.
Adj-RIB-In ๐ซง The Adj-RIBs-In holds the raw, unprocessed routing info that the local BGP speaker's peers have advertised to it. Think of it as the inbox, still unsorted ๐
Adj-RIB-Out ๐ค The Adj-RIBs-Out holds the routes the local speaker is getting ready to advertise to specific peers, sent along in its UPDATE messages.
Autonomous System (AS) ๐ฐ The classic definition is a set of routers under a single technical administration. They use an interior gateway protocol (IGP) and common metrics to figure out how to route packets inside the AS, and an inter-AS routing protocol to route packets to other ASes. Here's the tea โ: over time, a single AS started running several IGPs and sometimes several sets of metrics internally. The term "Autonomous System" is all about the vibe that, even with all that mixing, the AS's administration still looks like one coherent interior routing plan to everyone else, and gives a consistent picture of the destinations reachable through it. Main character energy, fr ๐
BGP Identifier ๐ชช A 4-octet unsigned integer that identifies the sender of BGP messages. Each BGP speaker sets its BGP Identifier to an IP address assigned to that speaker. It gets decided at startup, and it's the same for every local interface and every BGP peer. Consistent girl, consistent ID ๐
BGP speaker ๐ฃ๏ธ A router that implements BGP. That's it, that's the whole vibe โจ
EBGP ๐ External BGP, which is the BGP connection between external peers.
External peer ๐ช A peer in a different Autonomous System than the local system.
Feasible route โ An advertised route that the recipient is allowed to use.
IBGP ๐ก Internal BGP, which is the BGP connection between internal peers.
Internal peer ๐ซถ A peer in the same Autonomous System as the local system.
IGP ๐งญ Interior Gateway Protocol, a routing protocol used to swap routing info among routers inside a single Autonomous System.
Loc-RIB ๐ฏ The Loc-RIB holds the routes the local BGP speaker's Decision Process has selected. These are the chosen ones ๐
NLRI ๐ฆ Network Layer Reachability Information.
Route ๐ฃ๏ธ A unit of info that pairs a set of destinations with the attributes of a path to those destinations. The destinations are systems whose IP addresses sit inside one IP address prefix carried in the Network Layer Reachability Information (NLRI) field of an UPDATE message. The path is whatever's reported in the path attributes field of that same UPDATE message. Destinations plus path, bestie, that's a route ๐ฆ
RIB ๐๏ธ Routing Information Base.
Unfeasible route ๐ฅ A route that was previously advertised as feasible but isn't available for use anymore. Ngl, it's the ex of routes ๐
1.2. Specification of Requirements ๐
So here's how we talk about requirements in this doc ๐ซถ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" are to be read the way RFC 2119 [RFC2119] describes. Those capital words are the serious ones, so pay attention when you see them ๐ค
2. Acknowledgements ๐
This doc was first published as [RFC1267] back in October 1991, and it was written by Kirk Lougheed and Yakov Rekhter together. Iconic duo ๐ฏโโ๏ธ
Huge thanks to Guy Almes, Len Bosack, and Jeffrey C. Honig for their work on the earlier version (BGP-1) ๐ธ
Special shoutout to Dennis Ferguson for numerous contributions to that earlier version. He really carried ๐
We want to explicitly thank Bob Braden for reviewing the earlier version (BGP-2) and for his constructive, valuable comments ๐ซถ
We also want to thank Bob Hinden, who was the Director for Routing of the Internet Engineering Steering Group, and the reviewer team he put together to look at BGP-2. That team was Deborah Estrin, Milo Medin, John Moy, Radia Perlman, Martha Steenstrup, Mike St. Johns, and Paul Tsuchiya. They were tough, professional, and courteous all at once, which is honestly the dream ๐
Some sections borrowed heavily from IDRP [IS10747], the OSI counterpart of BGP. Credit goes to the ANSI X3S3.3 group, chaired by Lyman Chapin, and to Charles Kunzinger, who was the IDRP editor in that group ๐
We'd also love to thank Benjamin Abarbanel, Enke Chen, Edward Crabbe, Mike Craren, Vincent Gillet, Eric Gray, Jeffrey Haas, Dimitry Haskin, Stephen Kent, John Krawczyk, David LeRoy, Dan Massey, Jonathan Natale, Dan Pei, Mathew Richardson, John Scudder, John Stewart III, Dave Thaler, Paul Traina, Russ White, Curtis Villamizar, and Alex Zinin for their comments. Such a big list, you all ate ๐
Special thanks to Andrew Lange for helping prepare the final version of this document โจ
Finally, a big hug to everyone in the IDR Working Group for their ideas and support ๐ซ๐
3. Summary of Operation ๐ฆ
BGP, the Border Gateway Protocol, is an inter-Autonomous System routing protocol. It's built on experience from EGP (as defined in [RFC904]) and EGP usage in the NSFNET Backbone (as described in [RFC1092] and [RFC1093]). For more BGP info, check out [RFC1772], [RFC1930], [RFC1997], and [RFC2858] ๐
The main job of a BGP speaking system is to swap network reachability info with other BGP systems. That info includes the list of Autonomous Systems (ASes) the reachability info travels through. This is enough to build a graph of AS connectivity, which lets you prune routing loops, and at the AS level it lets you enforce some policy decisions too. Loop-free and policy-friendly, iykyk ๐
In this doc we assume that a BGP speaker only advertises to its peers the routes it actually uses itself. Here, a BGP speaker "uses" a BGP route when it's the most preferred BGP route and it's used for forwarding. Every other case is outside the scope of this doc ๐ โโ๏ธ
In this doc, "IP address" means an IP Version 4 address [RFC791] ๐ข
Routing info exchanged via BGP only supports the destination-based forwarding paradigm. That means a router forwards a packet based solely on the destination address in the packet's IP header. This reflects which policy decisions BGP can and can't enforce. Some policies can't be supported by destination-based forwarding, so they need things like source routing (aka explicit routing) to be enforced. BGP can't enforce those policies either ๐ For example, BGP doesn't let one AS send traffic to a neighboring AS for forwarding to some destination (reachable through but) beyond that neighbor, while wanting that traffic to take a different route than the traffic originating in the neighboring AS would take for that same destination. On the flip side, BGP can support any policy that fits the destination-based forwarding paradigm ๐
BGP-4 brings a new set of mechanisms for Classless Inter-Domain Routing (CIDR) [RFC1518, RFC1519] ๐ธ These mechanisms let you advertise a set of destinations as an IP prefix, and they get rid of the concept of a network "class" inside BGP. BGP-4 also adds mechanisms for route aggregation, including aggregation of AS paths. Very clean, very tidy ๐งน
This doc uses the term 'Autonomous System' (AS) all the way through. The classic definition is a set of routers under a single technical administration, using an interior gateway protocol (IGP) and common metrics to route packets inside the AS, and an inter-AS routing protocol to route packets to other ASes. Since that definition came out, it's become common for one AS to run several IGPs and sometimes several sets of metrics internally. The term stresses that even with all that going on, the administration of an AS still looks like one coherent interior routing plan to other ASes, with a consistent picture of the destinations reachable through it ๐
BGP uses TCP [RFC793] as its transport protocol, which means BGP doesn't need to implement its own update fragmentation, retransmission, acknowledgement, or sequencing. Lowkey a relief ๐ BGP listens on TCP port 179. The error notification mechanism in BGP assumes TCP supports a "graceful" close, meaning all outstanding data gets delivered before the connection closes ๐ค
A TCP connection gets formed between two systems, and they exchange messages to open the connection and confirm its parameters ๐ค
The initial data flow is the part of the BGP routing table that the export policy allows, called the Adj-Ribs-Out (see 3.2). After that, incremental updates get sent whenever the routing tables change. BGP doesn't require a periodic refresh of the routing table ๐ To let local policy changes take effect correctly without resetting any BGP connections, a BGP speaker SHOULD either (a) retain the current version of the routes advertised to it by all of its peers for the duration of the connection, or (b) make use of the Route Refresh extension [RFC2918] ๐ช
KEEPALIVE messages may be sent periodically to make sure the connection is still live ๐ NOTIFICATION messages get sent in response to errors or special conditions. If a connection hits an error condition, a NOTIFICATION message is sent and the connection closes ๐จ
A peer in a different AS is called an external peer, and a peer in the same AS is called an internal peer. Internal BGP and external BGP are commonly shortened to IBGP and EBGP ๐ท๏ธ
If a particular AS has multiple BGP speakers and provides transit service for other ASes, then you have to be careful to keep a consistent view of routing within the AS. The IGP used inside the AS gives a consistent view of the AS's interior routes. For this doc, it's assumed that a consistent view of the exterior routes comes from having all BGP speakers within the AS maintain IBGP with each other ๐ซถ
This document specifies the base behavior of BGP. That behavior can be, and is, modified by extension specifications. When the protocol gets extended, the new behavior is fully documented in those extension specifications โจ
3.1. Routes: Advertisement and Storage ๐ฆ
okay so bestie, a route in BGP is a unit of info that pairs a bunch of destinations with the attributes of a path to get there ๐ฃ๏ธ The destinations are systems whose IP addresses all sit inside one IP address prefix, carried in the Network Layer Reachability Information (NLRI) field of an UPDATE message. The path is whatever's reported in the path attributes field of that same UPDATE message. so iconic, right? ๐
Routes get advertised between BGP speakers inside UPDATE messages. If several routes have the same path attributes, you can cram them all into one UPDATE by listing multiple prefixes in the NLRI field. it's giving efficiency ๐ธ
Routes live in the Routing Information Bases (RIBs): the Adj-RIBs-In, the Loc-RIB, and the Adj-RIBs-Out. we'll get into those in Section 3.2 ๐ง
If a BGP speaker decides to pass along a route it got earlier, it MAY add to, or modify, the path attributes of that route before sending it to a peer. main character glow-up energy โจ
Now, BGP also needs a way to say "hey, that route isn't usable anymore" ๐ There are three methods a speaker can use to mark a route as withdrawn from service:
- a) the IP prefix that describes the destination of a previously advertised route can be advertised in the WITHDRAWN ROUTES field in the UPDATE message, which marks the associated route as no longer available for use,
- b) a replacement route with the same NLRI can be advertised, or
- c) the BGP speaker connection can be closed, which implicitly removes all routes the pair of speakers had advertised to each other from service.
And if you want to change a route's attributes, you don't edit it in place ๐ You send a replacement route instead. That replacement carries the new, changed attributes and has the same address prefix as the original. honestly so clean.
3.2. Routing Information Base ๐
the Routing Information Base (RIB) inside a BGP speaker has three distinct parts:
- a) Adj-RIBs-In: The Adj-RIBs-In stores routing information learned from inbound UPDATE messages that were received from other BGP speakers. Their contents represent routes that are available as input to the Decision Process.
- b) Loc-RIB: The Loc-RIB contains the local routing information the BGP speaker selected by applying its local policies to the routing information contained in its Adj-RIBs-In. These are the routes that will be used by the local BGP speaker. The next hop for each of these routes MUST be resolvable via the local BGP speaker's Routing Table.
- c) Adj-RIBs-Out: The Adj-RIBs-Out stores information the local BGP speaker selected for advertisement to its peers. The routing information stored in the Adj-RIBs-Out will be carried in the local BGP speaker's UPDATE messages and advertised to its peers.
so in summary ๐ the Adj-RIBs-In holds the raw, unprocessed stuff your peers told you. The Loc-RIB holds the routes the Decision Process picked as winners. And the Adj-RIBs-Out organizes routes for specific peers, by way of your UPDATE messages. it's a whole system, bestie ๐
Here's the tea: the conceptual model splits things into Adj-RIBs-In, Loc-RIB, and Adj-RIBs-Out, but that does NOT mean you need three separate copies of the data. it neither implies nor requires that. You could keep three copies, or one copy with pointers, and the protocol doesn't care which you pick ๐ซถ
Routing info the speaker uses to actually forward packets (or to build the forwarding table used for forwarding) lives in the Routing Table. That table collects routes to directly connected networks, static routes, routes learned from IGP protocols, and routes learned from BGP. Whether a BGP route should get installed in the Routing Table, and whether a BGP route should override a route to the same destination from another source, is a local policy decision. This document doesn't specify it ๐ On top of forwarding, the Routing Table is also used to resolve the next-hop addresses in BGP updates (see Section 5.1.3).
4. Message Formats โจ
This section describes the message formats BGP uses. ๐
BGP messages get sent over TCP connections. A message is only processed after it's been entirely received. The maximum message size is 4096 octets. All implementations are required to support this maximum message size. The smallest message that may be sent is a BGP header with no data portion (19 octets).
All multi-octet fields are in network byte order. ๐ฅ
4.1. Message Header Format ๐
Every message has a fixed-size header. Depending on the message type, there may or may not be a data portion after it. The layout of these fields looks like this:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ +
| Marker |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Marker:
This 16-octet field is included for compatibility; it MUST be set to all ones.
Length:
This 2-octet unsigned integer indicates the total length of the message, including the header in octets. Thus, it allows one to locate the (Marker field of the) next message in the TCP stream. The value of the Length field MUST always be at least 19 and no greater than 4096, and MAY be further constrained, depending on the message type. "padding" of extra data after the message is not allowed. Therefore, the Length field MUST have the smallest value required, given the rest of the message.
Type:
This 1-octet unsigned integer indicates the type code of the message. This document defines the following type codes:
1 - OPEN
2 - UPDATE
3 - NOTIFICATION
4 - KEEPALIVE
[RFC2918] defines one more type code.
4.2. OPEN Message Format ๐ฆ
After a TCP connection is established, the first message each side sends is an OPEN message. If the OPEN message is acceptable, a KEEPALIVE message confirming the OPEN gets sent back. ๐ซถ
In addition to the fixed-size BGP header, the OPEN message contains the following fields:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| My Autonomous System |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Hold Time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BGP Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opt Parm Len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Optional Parameters (variable) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Version:
This 1-octet unsigned integer indicates the protocol version number of the message. The current BGP version number is 4.
My Autonomous System:
This 2-octet unsigned integer indicates the Autonomous System number of the sender.
Hold Time:
This 2-octet unsigned integer indicates the number of seconds the sender proposes for the value of the Hold Timer. Upon receipt of an OPEN message, a BGP speaker MUST calculate the value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time received in the OPEN message. The Hold Time MUST be either zero or at least three seconds. An implementation MAY reject connections on the basis of the Hold Time. The calculated value indicates the maximum number of seconds that may elapse between the receipt of successive KEEPALIVE and/or UPDATE messages from the sender.
the timer stuff is a big deal, so pay attention ๐
BGP Identifier:
This 4-octet unsigned integer indicates the BGP Identifier of the sender. A given BGP speaker sets the value of its BGP Identifier to an IP address that is assigned to that BGP speaker. The value of the BGP Identifier is determined upon startup and is the same for every local interface and BGP peer.
Optional Parameters Length:
This 1-octet unsigned integer indicates the total length of the Optional Parameters field in octets. If the value of this field is zero, no Optional Parameters are present.
Optional Parameters:
This field contains a list of optional parameters, in which each parameter is encoded as a <Parameter Type, Parameter Length, Parameter Value> triplet.
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
| Parm. Type | Parm. Length | Parameter Value (variable)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
Parameter Type is a one octet field that unambiguously identifies individual parameters. Parameter Length is a one octet field that contains the length of the Parameter Value field in octets. Parameter Value is a variable length field that is interpreted according to the value of the Parameter Type field.
[RFC3392] defines the Capabilities Optional Parameter.
The minimum length of the OPEN message is 29 octets (including the message header).
4.3. UPDATE Message Format ๐ธ
UPDATE messages are used to transfer routing information between BGP peers. The information in an UPDATE message can be used to construct a graph that describes the relationships of the various Autonomous Systems. By applying rules to be discussed, routing information loops and some other anomalies may be detected and removed from inter-AS routing. ๐
An UPDATE message is bestie's way of saying "hey, these feasible routes share the same path attributes, so here they are," or "these unfeasible routes are out of service now" (see 3.1) ๐ฆ. It can even do both at once, since an UPDATE MAY simultaneously advertise a feasible route and withdraw multiple unfeasible routes from service ๐ . It always has the fixed-size BGP header, plus the other fields below. Some of those fields might not show up in every UPDATE, so don't freak out if one is missing ๐
+-----------------------------------------------------+
| Withdrawn Routes Length (2 octets) |
+-----------------------------------------------------+
| Withdrawn Routes (variable) |
+-----------------------------------------------------+
| Total Path Attribute Length (2 octets) |
+-----------------------------------------------------+
| Path Attributes (variable) |
+-----------------------------------------------------+
| Network Layer Reachability Information (variable) |
+-----------------------------------------------------+
Withdrawn Routes Length ๐งบ
This is a 2-octets unsigned integer giving the total length of the Withdrawn Routes field in octets. It's the key that unlocks how long the Network Layer Reachability Information field is, which we'll get to later ๐
A value of 0 means no routes are being withdrawn from service, and the WITHDRAWN ROUTES field is not present in this UPDATE message. Zero withdrawals, no drama โจ
Withdrawn Routes ๐ช
This is a variable-length field holding a list of IP address prefixes for the routes being withdrawn from service. Each prefix gets encoded as a 2-tuple shaped like <length, prefix>, so here's the layout ๐
+---------------------------+
| Length (1 octet) |
+---------------------------+
| Prefix (variable) |
+---------------------------+
Here's what each piece does:
- a) Length: This tells you the length in bits of the IP address prefix. A length of zero means a prefix that matches all IP addresses (with the prefix itself being zero octets). Big catch-all energy ๐
- b) Prefix: This holds an IP address prefix, followed by the minimum number of trailing bits needed to make the end of the field land on an octet boundary. The value of those trailing bits is irrelevant, so nobody needs to stress about them ๐ซถ
Total Path Attribute Length ๐
This is a 2-octet unsigned integer for the total length of the Path Attributes field in octets. It lets you figure out the length of the Network Layer Reachability field, as explained below ๐งฎ
A value of 0 means neither the Network Layer Reachability Information field nor the Path Attribute field is present in this UPDATE message. Totally empty vibes ๐ซง
Path Attributes ๐
Every UPDATE message carries a variable-length sequence of path attributes, except for an UPDATE that only carries withdrawn routes. Each path attribute is a triple <attribute type, attribute length, attribute value> of variable length ๐
The Attribute Type is a two-octet field made up of the Attribute Flags octet, followed by the Attribute Type Code octet:
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Attr. Flags |Attr. Type Code|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Now let's break down those flag bits, because they're a whole vibe ๐ฅ
- The high-order bit (bit 0) of the Attribute Flags octet is the Optional bit. It says whether the attribute is optional (set to 1) or well-known (set to 0).
- The second high-order bit (bit 1) is the Transitive bit. For an optional attribute, it says whether that attribute is transitive (set to 1) or non-transitive (set to 0).
- For well-known attributes, the Transitive bit MUST be set to 1. (Check out Section 5 for the full tea on transitive attributes โ)
- The third high-order bit (bit 2) is the Partial bit. For an optional transitive attribute, it says whether the information is partial (set to 1) or complete (set to 0). For well-known attributes and for optional non-transitive attributes, the Partial bit MUST be set to 0.
- The fourth high-order bit (bit 3) is the Extended Length bit. It says whether the Attribute Length is one octet (set to 0) or two octets (set to 1) ๐
- The lower-order four bits of the Attribute Flags octet are unused. They MUST be zero when sent and MUST be ignored when received. Leftover bits, handled with care ๐งผ
The Attribute Type Code octet holds the Attribute Type Code. The currently defined codes are discussed in Section 5 ๐
If the Extended Length bit is set to 0, the third octet of the Path Attribute holds the length of the attribute data in octets. If the Extended Length bit is set to 1, then the third and fourth octets hold that length instead ๐ช
The remaining octets are the attribute value, and they get interpreted according to the Attribute Flags and the Attribute Type Code. Here are the supported Attribute Type Codes, their attribute values, and what they're used for ๐
- a) ORIGIN (Type Code 1):
ORIGIN is a well-known mandatory attribute that defines where the path information came from. The data octet can be one of these values:
Value Meaning
0 IGP - Network Layer Reachability Information
is interior to the originating AS
1 EGP - Network Layer Reachability Information
learned via the EGP protocol [RFC904]
2 INCOMPLETE - Network Layer Reachability
Information learned by some other means
Usage of this attribute is defined in 5.1.1. ๐ธ
- b) AS_PATH (Type Code 2):
AS_PATH is a well-known mandatory attribute made up of a sequence of AS path segments. Each AS path segment is represented by a triple <path segment type, path segment length, path segment value>.
The path segment type is a 1-octet length field with these values defined:
Value Segment Type
1 AS_SET: unordered set of ASes a route in the
UPDATE message has traversed
2 AS_SEQUENCE: ordered set of ASes a route in
the UPDATE message has traversed
The path segment length is a 1-octet length field containing the number of ASes (not the number of octets) in the path segment value field.
The path segment value field contains one or more AS numbers, each encoded as a 2-octet length field.
Usage of this attribute is defined in 5.1.2. ๐ฃ๏ธ
- c) NEXT_HOP (Type Code 3):
This is a well-known mandatory attribute that defines the (unicast) IP address of the router that SHOULD be used as the next hop to the destinations listed in the Network Layer Reachability Information field of the UPDATE message.
Usage of this attribute is defined in 5.1.3. ๐
- d) MULTI_EXIT_DISC (Type Code 4):
This is an optional non-transitive attribute that is a four-octet unsigned integer. The value of this attribute MAY be used by a BGP speaker's Decision Process to discriminate among multiple entry points to a neighboring autonomous system.
Usage of this attribute is defined in 5.1.4. ๐ช
- e) LOCAL_PREF (Type Code 5):
LOCAL_PREF is a well-known attribute that is a four-octet unsigned integer. A BGP speaker uses it to tell its other internal peers the advertising speaker's degree of preference for an advertised route.
Usage of this attribute is defined in 5.1.5. ๐
- f) ATOMIC_AGGREGATE (Type Code 6)
ATOMIC_AGGREGATE is a well-known discretionary attribute of length 0.
Usage of this attribute is defined in 5.1.6. ๐ง
- g) AGGREGATOR (Type Code 7)
AGGREGATOR is an optional transitive attribute of length 6. The attribute contains the last AS number that formed the aggregate route (encoded as 2 octets), followed by the IP address of the BGP speaker that formed the aggregate route (encoded as 4 octets). This SHOULD be the same address as the one used for the BGP Identifier of the speaker.
Usage of this attribute is defined in 5.1.7. ๐ซง
Network Layer Reachability Information ๐
This variable-length field holds a list of IP address prefixes. The length of the Network Layer Reachability Information, in octets, isn't encoded explicitly. Instead you calculate it like this ๐ง
UPDATE message Length - 23 - Total Path Attributes Length
- Withdrawn Routes Length
Here, UPDATE message Length is the value encoded in the fixed-size BGP header, while Total Path Attribute Length and Withdrawn Routes Length are the values encoded in the variable part of the UPDATE message. The 23 is the combined length of the fixed-size BGP header, the Total Path Attribute Length field, and the Withdrawn Routes Length field. Math with a purpose โจ
Reachability information is encoded as one or more 2-tuples of the form <length, prefix>, and the fields work like this:
+---------------------------+
| Length (1 octet) |
+---------------------------+
| Prefix (variable) |
+---------------------------+
- a) Length: This is the length in bits of the IP address prefix. A length of zero means a prefix that matches all IP addresses (with the prefix itself being zero octets).
- b) Prefix: This contains an IP address prefix, followed by enough trailing bits to make the end of the field land on an octet boundary. The value of the trailing bits is irrelevant ๐ฆ
The minimum length of the UPDATE message is 23 octets ๐. That's 19 octets for the fixed header, plus 2 octets for the Withdrawn Routes Length, plus 2 octets for the Total Path Attribute Length. In that minimum case, the Withdrawn Routes Length is 0 and the Total Path Attribute Length is 0, so the smallest possible UPDATE is basically just the skeleton ๐ฆด
Okay, that's the whole UPDATE breakdown, and honestly it's giving very organized ๐
You're literally going to love the way UPDATE messages carry multiple destinations ๐ฆ okay so, one UPDATE can advertise at most one set of path attributes, but it can cover multiple destinations as long as they all share those attributes ๐ every path attribute in that message applies to every destination in the NLRI field, no exceptions ๐ซถ
Withdrawing routes is its own vibe ๐ธ an UPDATE can list a bunch of routes to pull from service. Each one is identified by its destination (an IP prefix), and that's what makes it unambiguous, but only inside the BGP speaker to BGP speaker connection where it was originally advertised โจ
An UPDATE might only withdraw routes, in which case it won't have path attributes or NLRI at all ๐ Or it might only advertise a feasible route, and then the WITHDRAWN ROUTES field doesn't need to show up. Totally flexible, bestie ๐ง
Don't put the same address prefix in both WITHDRAWN ROUTES and NLRI, because that's messy ๐ It's NOT a hard no, though: a receiver still has to handle it, and the receiver should just act like the WITHDRAWN ROUTES don't include that prefix.
Here's the thing: an UPDATE message SHOULD NOT include the same address prefix in the WITHDRAWN ROUTES and Network Layer Reachability Information fields. However, a BGP speaker MUST be able to process UPDATE messages in this form. A BGP speaker SHOULD treat an UPDATE message of this form as though the WITHDRAWN ROUTES do not contain the address prefix.
4.4. KEEPALIVE Message Format ๐
BGP doesn't use any TCP-based keep-alive mechanism to check whether peers are reachable ๐ Instead, peers swap KEEPALIVE messages often enough that the Hold Timer never expires. A reasonable maximum time between KEEPALIVE messages would be one third of the Hold Time interval.
KEEPALIVE messages MUST NOT be sent more frequently than one per second. An implementation MAY adjust the rate at which it sends KEEPALIVE messages as a function of the Hold Time interval ๐
If the negotiated Hold Time interval is zero, then periodic KEEPALIVE messages MUST NOT be sent ๐ โโ๏ธ
A KEEPALIVE message is just the message header, with a length of 19 octets. Simple, clean, iconic โจ
4.5. NOTIFICATION Message Format ๐ฅ
A NOTIFICATION message gets sent when an error condition is detected ๐จ and the BGP connection is closed immediately after it's sent. Dramatic, but it's a whole vibe ๐
Besides the fixed-size BGP header, the NOTIFICATION message has these fields:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Error code | Error subcode | Data (variable) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Error Code ๐ This 1-octet unsigned integer tells you what type of NOTIFICATION it is. These Error Codes are defined:
Error Code Symbolic Name Reference
1 Message Header Error Section 6.1
2 OPEN Message Error Section 6.2
3 UPDATE Message Error Section 6.3
4 Hold Timer Expired Section 6.5
5 Finite State Machine Error Section 6.6
6 Cease Section 6.7
Error subcode ๐ง This 1-octet unsigned integer gives more specific info about what went wrong. Each Error Code can have one or more Error Subcodes attached to it. If there isn't an appropriate Error Subcode defined, the zero (Unspecific) value goes in the Error Subcode field ๐
Message Header Error subcodes, which are giving very "header problems" energy:
1 - Connection Not Synchronized.
2 - Bad Message Length.
3 - Bad Message Type.
OPEN Message Error subcodes:
1 - Unsupported Version Number.
2 - Bad Peer AS.
3 - Bad BGP Identifier.
4 - Unsupported Optional Parameter.
5 - [Deprecated - see Appendix A].
6 - Unacceptable Hold Time.
UPDATE Message Error subcodes:
1 - Malformed Attribute List.
2 - Unrecognized Well-known Attribute.
3 - Missing Well-known Attribute.
4 - Attribute Flags Error.
5 - Attribute Length Error.
6 - Invalid ORIGIN Attribute.
7 - [Deprecated - see Appendix A].
8 - Invalid NEXT_HOP Attribute.
9 - Optional Attribute Error.
10 - Invalid Network Field.
11 - Malformed AS_PATH.
Data ๐ธ This variable-length field is used to diagnose why the NOTIFICATION happened. What's in the Data field depends on the Error Code and Error Subcode. See Section 6 for more details.
Also, the length of the Data field can be figured out from the message Length field with this formula:
Message Length = 21 + Data Length
The minimum length of a NOTIFICATION message is 21 octets, including the message header โจ
5. Path Attributes ๐ฆ
This section is all about the path attributes of the UPDATE message, and honestly they're the main character of the whole protocol ๐
Path attributes fall into four separate categories:
- Well-known mandatory.
- Well-known discretionary.
- Optional transitive.
- Optional non-transitive.
BGP implementations MUST recognize all well-known attributes. Some of these are mandatory and MUST be included in every UPDATE message that contains NLRI. Others are discretionary and MAY or MAY NOT be sent in a particular UPDATE message ๐
Once a BGP peer has updated any well-known attributes, it MUST pass these attributes to its peers in any updates it transmits. No dropping them, periodt ๐ซถ
Each path MAY contain one or more optional attributes on top of the well-known ones. It isn't required or expected that every BGP implementation supports every optional attribute ๐ How an unrecognized optional attribute gets handled depends on the Transitive bit in the attribute flags octet.
Paths with unrecognized transitive optional attributes SHOULD be accepted. If a path with an unrecognized transitive optional attribute is accepted and passed to other BGP peers, then that attribute MUST be passed along with the path, with the Partial bit in the Attribute Flags octet set to 1. If a path with a recognized, transitive optional attribute is accepted and passed along to other BGP peers, and the Partial bit in the Attribute Flags octet was set to 1 by some previous AS, it MUST NOT be set back to 0 by the current AS. (Once it's flagged, it stays flagged, iykyk ๐)
Unrecognized non-transitive optional attributes MUST be quietly ignored and not passed along to other BGP peers ๐คซ
New transitive optional attributes MAY be attached to the path by the originator or by any other BGP speaker in the path. If they aren't attached by the originator, the Partial bit in the Attribute Flags octet is set to 1. The rules for attaching new non-transitive optional attributes depend on the specific attribute. The documentation for each new non-transitive optional attribute is expected to include those rules, and the description of the MULTI_EXIT_DISC attribute gives an example ๐ All optional attributes, both transitive and non-transitive, MAY be updated (if appropriate) by BGP speakers in the path.
The sender of an UPDATE message SHOULD order path attributes within the UPDATE message in ascending order of attribute type. The receiver of an UPDATE message MUST be prepared to handle path attributes that are out of order ๐ง
The same attribute (attribute with the same type) cannot appear more than once within the Path Attributes field of a particular UPDATE message. One per customer, bestie ๐
The mandatory category refers to an attribute that MUST be present in both IBGP and EBGP exchanges if NLRI are contained in the UPDATE message. Attributes that are optional for the purpose of the protocol extension mechanism may be purely discretionary, discretionary, required, or disallowed in certain contexts ๐ธ
Here's the attribute table, in full glory:
attribute EBGP IBGP
ORIGIN mandatory mandatory
AS_PATH mandatory mandatory
NEXT_HOP mandatory mandatory
MULTI_EXIT_DISC discretionary discretionary
LOCAL_PREF see Section 5.1.5 required
ATOMIC_AGGREGATE see Section 5.1.6 and 9.1.4
AGGREGATOR discretionary discretionary
5.1. Path Attribute Usage โจ
The usage of each BGP path attribute is described in the clauses below ๐
5.1.1. ORIGIN ๐
ORIGIN is a well-known mandatory attribute. It's generated by the speaker that originates the associated routing information. Its value SHOULD NOT be changed by any other speaker ๐
5.1.2. AS_PATH ๐ค๏ธ
AS_PATH is a well-known mandatory attribute. It identifies the autonomous systems that the routing information carried in this UPDATE message has passed through. The components of this list can be AS_SETs or AS_SEQUENCEs ๐
When a BGP speaker propagates a route it learned from another BGP speaker's UPDATE message, it modifies the route's AS_PATH attribute based on where the BGP speaker that the route will be sent to is located:
a) When a given BGP speaker advertises the route to an internal peer, the advertising speaker SHALL NOT modify the AS_PATH attribute associated with the route.
b) When a given BGP speaker advertises the route to an external peer, the advertising speaker updates the AS_PATH attribute as follows:
- If the first path segment of the AS_PATH is of type AS_SEQUENCE, the local system prepends its own AS number as the last element of the sequence (put it in the leftmost position with respect to the position of octets in the protocol message). If the act of prepending will cause an overflow in the AS_PATH segment (i.e., more than 255 ASes), it SHOULD prepend a new segment of type AS_SEQUENCE and prepend its own AS number to this new segment.
- If the first path segment of the AS_PATH is of type AS_SET, the local system prepends a new path segment of type AS_SEQUENCE to the AS_PATH, including its own AS number in that segment.
- If the AS_PATH is empty, the local system creates a path segment of type AS_SEQUENCE, places its own AS into that segment, and places that segment into the AS_PATH.
When a BGP speaker originates a route, then:
a) The originating speaker includes its own AS number in a path segment, of type AS_SEQUENCE, in the AS_PATH attribute of all UPDATE messages sent to an external peer. In this case, the AS number of the originating speaker's autonomous system will be the only entry in the path segment, and this path segment will be the only segment in the AS_PATH attribute.
b) The originating speaker includes an empty AS_PATH attribute in all UPDATE messages sent to internal peers. (An empty AS_PATH attribute is one whose length field contains the value zero.)
Whenever the modification of the AS_PATH attribute calls for including or prepending the AS number of the local system, the local system MAY include or prepend more than one instance of its own AS number in the AS_PATH attribute. This is controlled via local configuration ๐ฅ
5.1.3. NEXT_HOP โจ
okay so NEXT_HOP is a well-known mandatory attribute ๐ and it tells you the IP address of the router that SHOULD be used as the next hop to the destinations listed in the UPDATE message. here's how it gets calculated ๐ซถ
- When sending a message to an internal peer, if the route is not locally originated, the BGP speaker SHOULD NOT modify the NEXT_HOP attribute unless it has been explicitly configured to announce its own IP address as the NEXT_HOP. When announcing a locally-originated route to an internal peer, the BGP speaker SHOULD use the interface address of the router through which the announced network is reachable for the speaker as the NEXT_HOP. If the route is directly connected to the speaker, or if the interface address of the router through which the announced network is reachable for the speaker is the internal peer's address, then the BGP speaker SHOULD use its own IP address for the NEXT_HOP attribute (the address of the interface that is used to reach the peer). ๐ธ
- When sending a message to an external peer, X, and the peer is one IP hop away from the speaker:
- If the route being announced was learned from an internal peer or is locally originated, the BGP speaker can use an interface address of the internal peer router (or the internal router) through which the announced network is reachable for the speaker for the NEXT_HOP attribute, provided that peer X shares a common subnet with this address. This is a form of "third party" NEXT_HOP attribute.
- Otherwise, if the route being announced was learned from an external peer, the speaker can use an IP address of any adjacent router (known from the received NEXT_HOP attribute) that the speaker itself uses for local route calculation in the NEXT_HOP attribute, provided that peer X shares a common subnet with this address. This is a second form of "third party" NEXT_HOP attribute.
- Otherwise, if the external peer to which the route is being advertised shares a common subnet with one of the interfaces of the announcing BGP speaker, the speaker MAY use the IP address associated with such an interface in the NEXT_HOP attribute. This is known as a "first party" NEXT_HOP attribute.
- By default (if none of the above conditions apply), the BGP speaker SHOULD use the IP address of the interface that the speaker uses to establish the BGP connection to peer X in the NEXT_HOP attribute. ๐ฆ
- When sending a message to an external peer X, and the peer is multiple IP hops away from the speaker (aka "multihop EBGP"):
- The speaker MAY be configured to propagate the NEXT_HOP attribute. In this case, when advertising a route that the speaker learned from one of its peers, the NEXT_HOP attribute of the advertised route is exactly the same as the NEXT_HOP attribute of the learned route (the speaker does not modify the NEXT_HOP attribute).
- By default, the BGP speaker SHOULD use the IP address of the interface that the speaker uses in the NEXT_HOP attribute to establish the BGP connection to peer X.
Normally, the NEXT_HOP attribute is chosen so that the shortest available path gets taken ๐ฃ๏ธ A BGP speaker MUST be able to support disabling the advertisement of third party NEXT_HOP attributes, so it can handle imperfectly bridged media. that one is a must-have, bestie ๐ญ
A route originated by a BGP speaker SHALL NOT be advertised to a peer using an address of that peer as NEXT_HOP. A BGP speaker SHALL NOT install a route with itself as the next hop. absolutely not, we don't do that here ๐ โโ๏ธ
The NEXT_HOP attribute is what the BGP speaker uses to figure out the actual outbound interface and the immediate next-hop address that SHOULD be used to forward transit packets to the associated destinations. it's giving main character routing โจ
The immediate next-hop address is determined by doing a recursive route lookup for the IP address in the NEXT_HOP attribute, using the contents of the Routing Table, and selecting one entry if multiple entries of equal cost exist. The Routing Table entry that resolves the IP address in the NEXT_HOP attribute will always specify the outbound interface. If the entry specifies an attached subnet but does not specify a next-hop address, then the address in the NEXT_HOP attribute SHOULD be used as the immediate next-hop address. If the entry also specifies the next-hop address, this address SHOULD be used as the immediate next-hop address for packet forwarding. ๐
5.1.4. MULTI_EXIT_DISC ๐
the MULTI_EXIT_DISC is an optional non-transitive attribute, and it's meant for external (inter-AS) links so you can tell apart multiple exit or entry points to the same neighbouring AS ๐ฆ Its value is a four-octet unsigned number called a metric. All other factors being equal, the exit point with the lower metric SHOULD be preferred. If it's received over EBGP, the MULTI_EXIT_DISC attribute MAY be propagated over IBGP to other BGP speakers within the same AS (see also 9.1.2.2). The MULTI_EXIT_DISC attribute received from a neighbouring AS MUST NOT be propagated to other neighbouring ASes. ngl that last rule is so important ๐ซ
A BGP speaker MUST implement a mechanism, based on local configuration, that allows the MULTI_EXIT_DISC attribute to be removed from a route. If a BGP speaker is configured to remove the MULTI_EXIT_DISC attribute from a route, then this removal MUST be done prior to determining the degree of preference of the route and prior to performing route selection (Decision Process phases 1 and 2). ๐งน
An implementation MAY also, based on local configuration, alter the value of the MULTI_EXIT_DISC attribute received over EBGP. If a BGP speaker is configured to alter that value, then the altering MUST be done prior to determining the degree of preference of the route and prior to performing route selection (Decision Process phases 1 and 2). See Section 9.1.2.2 for the necessary restrictions on this. ๐
5.1.5. LOCAL_PREF ๐
LOCAL_PREF is a well-known attribute that SHALL be included in all UPDATE messages that a given BGP speaker sends to other internal peers. A BGP speaker SHALL calculate the degree of preference for each external route based on the locally-configured policy, and include that degree of preference when advertising the route to its internal peers. The higher degree of preference MUST be preferred. A BGP speaker uses the degree of preference learned via LOCAL_PREF in its Decision Process (see Section 9.1.1). the highest one wins, periodt ๐
A BGP speaker MUST NOT include this attribute in UPDATE messages it sends to external peers, except in the case of BGP Confederations [RFC3065]. If it shows up in an UPDATE message received from an external peer, then the receiving speaker MUST ignore this attribute, except in the case of BGP Confederations [RFC3065]. ๐
5.1.6. ATOMIC_AGGREGATE ๐
ATOMIC_AGGREGATE is a well-known discretionary attribute ๐
When a BGP speaker aggregates several routes to advertise to a particular peer, the AS_PATH of the aggregated route normally includes an AS_SET formed from the set of ASes the aggregate came from. In lots of cases, the network administrator can figure out whether the aggregate can be safely advertised without that AS_SET, and without forming route loops ๐ง
If an aggregate leaves out at least some of the AS numbers present in the AS_PATH of the aggregated routes (because the AS_SET got dropped), then the aggregated route SHOULD include the ATOMIC_AGGREGATE attribute when it's advertised to the peer. โจ
A BGP speaker that receives a route with the ATOMIC_AGGREGATE attribute SHOULD NOT remove that attribute when propagating the route to other speakers. ๐ซถ
A BGP speaker that receives a route with the ATOMIC_AGGREGATE attribute MUST NOT make any NLRI of that route more specific (as defined in 9.1.4) when advertising the route to other BGP speakers. no splitting it up, sis ๐ซ
A BGP speaker that receives a route with the ATOMIC_AGGREGATE attribute needs to know that the actual path to the destinations in the route's NLRI, even though it's loop-free, might not be the path listed in the route's AS_PATH attribute. it's a little plot twist, but it's fine ๐
5.1.7. AGGREGATOR ๐
AGGREGATOR is an optional transitive attribute. It MAY be included in updates formed by aggregation (see Section 9.2.2.2). A BGP speaker that does route aggregation MAY add the AGGREGATOR attribute, which SHALL contain its own AS number and IP address. The IP address SHOULD be the same as the BGP Identifier of the speaker. main character of the aggregate, honestly ๐
6. BGP Error Handling ๐จ
this section is all about what to do when things go wrong while a BGP message is being processed. it's not the fun part, but it's kinda important ๐ฅฒ
When any of the conditions described here are detected, a NOTIFICATION message gets sent with the indicated Error Code, Error Subcode, and Data fields, and then the BGP connection is closed. The one exception is when it's explicitly stated that no NOTIFICATION message is to be sent and the BGP connection isn't to be closed. If no Error Subcode is specified, then a zero MUST be used. ๐ฅ
The phrase "the BGP connection is closed" means the TCP connection has been closed, the associated Adj-RIB-In has been cleared, and all resources for that BGP connection have been deallocated. Entries in the Loc-RIB associated with the remote peer are marked as invalid. The local system then recalculates its best routes for the destinations of the routes marked as invalid. Before the invalid routes are deleted from the system, it advertises to its peers either withdraws for the routes marked as invalid, or the new best routes. the order matters, so no skipping steps ๐
Unless it's specified explicitly, the Data field of the NOTIFICATION message that gets sent to indicate an error is empty. ๐งบ
6.1. Message Header Error Handling ๐ซง
All errors detected while processing the Message Header MUST be indicated by sending the NOTIFICATION message with the Error Code Message Header Error. The Error Subcode gives the specifics of what went wrong. ๐ฃ
The expected value of the Marker field of the message header is all ones. If the Marker field isn't what's expected, then a synchronization error has happened, and the Error Subcode MUST be set to Connection Not Synchronized. ๐
If at least one of the following is true:
- the
Lengthfield of the message header is less than 19 or greater than 4096, or - the
Lengthfield of an OPEN message is less than the minimum length of the OPEN message, or - the
Lengthfield of an UPDATE message is less than the minimum length of the UPDATE message, or - the
Lengthfield of a KEEPALIVE message is not equal to 19, or - the
Lengthfield of a NOTIFICATION message is less than the minimum length of the NOTIFICATION message,
then the Error Subcode MUST be set to Bad Message Length. The Data field MUST contain the erroneous Length field. ๐
If the Type field of the message header isn't recognized, then the Error Subcode MUST be set to Bad Message Type. The Data field MUST contain the erroneous Type field. ๐
โโ๏ธ
6.2. OPEN Message Error Handling ๐
okay bestie, so every error we catch while processing an OPEN message MUST get reported by sending a NOTIFICATION message with the Error Code OPEN Message Error ๐
. The Error Subcode is where we spell out exactly what went wrong ๐.
If the version number in the Version field of the received OPEN message isn't supported, the Error Subcode MUST be set to Unsupported Version Number ๐. The Data field is a 2-octet unsigned integer, and it holds the largest locally-supported version number that's still less than the version the remote BGP peer bid (as shown in the received OPEN message). If the smallest locally-supported version number is already greater than the version the remote BGP peer bid, the Data field holds that smallest locally-supported version number instead โจ.
If the Autonomous System field of the OPEN message is unacceptable, the Error Subcode MUST be set to Bad Peer AS ๐ซ. Figuring out which Autonomous System numbers count as acceptable is outside the scope of this protocol, so that's a different story ๐.
If the Hold Time field of the OPEN message is unacceptable, the Error Subcode MUST be set to Unacceptable Hold Time โฐ. An implementation MUST reject Hold Time values of one or two seconds. An implementation MAY reject any proposed Hold Time. An implementation that accepts a Hold Time MUST use the negotiated value for the Hold Time ๐ซถ.
If the BGP Identifier field of the OPEN message is syntactically incorrect, the Error Subcode MUST be set to Bad BGP Identifier ๐ชช. Syntactic correctness here means the BGP Identifier field represents a valid unicast IP host address ๐ธ.
If one of the Optional Parameters in the OPEN message is not recognized, the Error Subcode MUST be set to Unsupported Optional Parameters ๐งฉ.
If one of the Optional Parameters in the OPEN message is recognized but malformed, the Error Subcode MUST be set to 0 (Unspecific) ๐คทโโ๏ธ.
6.3. UPDATE Message Error Handling ๐
All errors detected while processing the UPDATE message MUST be indicated by sending the NOTIFICATION message with the Error Code UPDATE Message Error ๐ฅ. The Error Subcode tells you the specific vibe of the error ๐ซง.
Error checking of an UPDATE message starts with the path attributes ๐. If the Withdrawn Routes Length or Total Attribute Length is too large (i.e., if Withdrawn Routes Length + Total Attribute Length + 23 exceeds the message Length), the Error Subcode MUST be set to Malformed Attribute List ๐.
If any recognized attribute has Attribute Flags that conflict with the Attribute Type Code, the Error Subcode MUST be set to Attribute Flags Error. The Data field MUST contain the erroneous attribute (type, length, and value) ๐ฉ.
If any recognized attribute has an Attribute Length that conflicts with the expected length (based on the attribute type code), the Error Subcode MUST be set to Attribute Length Error. The Data field MUST contain the erroneous attribute (type, length, and value) ๐.
If any of the well-known mandatory attributes are not present, the Error Subcode MUST be set to Missing Well-known Attribute. The Data field MUST contain the Attribute Type Code of the missing, well-known attribute ๐ป.
If any of the well-known mandatory attributes are not recognized, the Error Subcode MUST be set to Unrecognized Well-known Attribute. The Data field MUST contain the unrecognized attribute (type, length, and value) ๐.
If the ORIGIN attribute has an undefined value, the Error Subcode MUST be set to Invalid Origin Attribute. The Data field MUST contain the unrecognized attribute (type, length, and value) ๐.
If the NEXT_HOP attribute field is syntactically incorrect, the Error Subcode MUST be set to Invalid NEXT_HOP Attribute. The Data field MUST contain the incorrect attribute (type, length, and value). Syntactic correctness means the NEXT_HOP attribute represents a valid IP host address ๐.
The IP address in the NEXT_HOP MUST meet the following criteria to be considered semantically correct ๐ง:
- a) It MUST NOT be the IP address of the receiving speaker.
- b) In the case of an EBGP, where the sender and receiver are one IP hop away from each other, either the IP address in the
NEXT_HOPMUST be the sender's IP address that is used to establish the BGP connection, or the interface associated with theNEXT_HOPIP address MUST share a common subnet with the receiving BGP speaker.
If the NEXT_HOP attribute is semantically incorrect, the error SHOULD be logged, and the route SHOULD be ignored. In this case, a NOTIFICATION message SHOULD NOT be sent, and the connection SHOULD NOT be closed. ๐ซฃ
The AS_PATH attribute gets checked for syntactic correctness ๐. If the path is syntactically incorrect, the Error Subcode MUST be set to Malformed AS_PATH ๐งต.
If the UPDATE message is received from an external peer, the local system MAY check whether the leftmost (with respect to the position of octets in the protocol message) AS in the AS_PATH attribute is equal to the autonomous system number of the peer that sent the message ๐. If the check determines this is not the case, the Error Subcode MUST be set to Malformed AS_PATH ๐
โโ๏ธ.
If an optional attribute is recognized, then the value of this attribute MUST be checked. If an error is detected, the attribute MUST be discarded, and the Error Subcode MUST be set to Optional Attribute Error. The Data field MUST contain the attribute (type, length, and value) ๐๏ธ.
If any attribute appears more than once in the UPDATE message, the Error Subcode MUST be set to Malformed Attribute List ๐ฏ.
The NLRI field in the UPDATE message gets checked for syntactic validity ๐บ๏ธ. If the field is syntactically incorrect, the Error Subcode MUST be set to Invalid Network Field ๐ซ๏ธ.
If a prefix in the NLRI field is semantically incorrect (e.g., an unexpected multicast IP address), an error SHOULD be logged locally, and the prefix SHOULD be ignored ๐.
An UPDATE message that contains correct path attributes but no NLRI SHALL be treated as a valid UPDATE message โ . Not the drama I expected, but honestly iconic ๐ .
6.4. NOTIFICATION Message Error Handling ๐ท
If a peer sends a NOTIFICATION message and the receiver detects an error in that message, the receiver cannot use a NOTIFICATION message to report this error back to the peer ๐. Any such error (e.g., an unrecognized Error Code or Error Subcode) SHOULD be noticed, logged locally, and brought to the attention of the administration of the peer ๐ฃ. The means to do this, however, lies outside the scope of this document ๐งญ.
6.5. Hold Timer Expired Error Handling โณ
If a system does not receive successive KEEPALIVE, UPDATE, and/or NOTIFICATION messages within the period specified in the Hold Time field of the OPEN message, then the NOTIFICATION message with the Hold Timer Expired Error Code is sent and the BGP connection is closed ๐ญ.
6.6. Finite State Machine Error Handling ๐ข
Any error detected by the BGP Finite State Machine (e.g., receipt of an unexpected event) is indicated by sending the NOTIFICATION message with the Error Code Finite State Machine Error ๐ช๏ธ.
6.7. Cease ๐๏ธ
In the absence of any fatal errors (that are indicated in this section), a BGP peer MAY choose, at any given time, to close its BGP connection by sending the NOTIFICATION message with the Error Code Cease. However, the Cease NOTIFICATION message MUST NOT be used when a fatal error indicated by this section does exist ๐.
A BGP speaker MAY support the ability to impose a locally-configured, upper bound on the number of address prefixes the speaker is willing to accept from a neighbor ๐งฎ. When the upper bound is reached, the speaker, under control of local configuration, either (a) discards new address prefixes from the neighbor (while maintaining the BGP connection with the neighbor), or (b) terminates the BGP connection with the neighbor. If the BGP speaker decides to terminate its BGP connection with a neighbor because the number of address prefixes received from the neighbor exceeds the locally-configured, upper bound, then the speaker MUST send the neighbor a NOTIFICATION message with the Error Code Cease. The speaker MAY also log this locally ๐.
6.8. BGP Connection Collision Detection ๐
If a pair of BGP speakers try to establish a BGP connection with each other simultaneously, then two parallel connections will be formed ๐ฏโโ๏ธ. If the source IP address used by one of these connections is the same as the destination IP address used by the other, and the destination IP address used by the first connection is the same as the source IP address used by the other, connection collision has occurred ๐ฅ. In the event of connection collision, one of the connections MUST be closed ๐ช.
Based on the value of the BGP Identifier, a convention is established for detecting which BGP connection is to be preserved when a collision occurs ๐. The convention is to compare the BGP Identifiers of the peers involved in the collision and to retain only the connection initiated by the BGP speaker with the higher-valued BGP Identifier ๐ฅ.
Upon receipt of an OPEN message, the local system MUST examine all of its connections that are in the OpenConfirm state ๐. A BGP speaker MAY also examine connections in an OpenSent state if it knows the BGP Identifier of the peer by means outside of the protocol ๐ต๏ธโโ๏ธ. If, among these connections, there is a connection to a remote BGP speaker whose BGP Identifier equals the one in the OPEN message, and this connection collides with the connection over which the OPEN message is received, then the local system performs the following collision resolution procedure ๐ซถ:
- The BGP Identifier of the local system is compared to the BGP Identifier of the remote system (as specified in the OPEN message). Comparing BGP Identifiers is done by converting them to host byte order and treating them as 4-octet unsigned integers ๐ข.
- If the value of the local BGP Identifier is less than the remote one, the local system closes the BGP connection that already exists (the one that is already in the OpenConfirm state), and accepts the BGP connection initiated by the remote system ๐ค.
- Otherwise, the local system closes the newly created BGP connection (the one associated with the newly received OPEN message), and continues to use the existing one (the one that is already in the OpenConfirm state) ๐.
Unless allowed via configuration, a connection collision with an existing BGP connection that is in the Established state causes closing of the newly created connection ๐ก๏ธ.
Note that a connection collision cannot be detected with connections that are in Idle, Connect, or Active states ๐.
Closing the BGP connection (that results from the collision resolution procedure) is accomplished by sending the NOTIFICATION message with the Error Code Cease ๐โจ.
7. BGP Version Negotiation ๐ฆ
okay so BGP speakers MAY negotiate the protocol version by trying to open a BGP connection more than once, starting with the highest version number each speaker supports ๐. if an open attempt fails with an Error Code of OPEN Message Error and an Error Subcode of Unsupported Version Number, the speaker now knows four things: the version it tried, the version its peer tried, the version its peer put in the NOTIFICATION message, and every version it supports ๐. if the two peers have one or more versions in common, this info lets them find the highest common version super fast โก. so, in order to make version negotiation work at all, future versions of BGP MUST keep the OPEN and NOTIFICATION message formats exactly the same ๐ bestie, that rule is non-negotiable.
8. BGP Finite State Machine (FSM) โจ
the data structures and FSM in this document are conceptual ๐ง . you do NOT have to build them exactly like this, as long as your implementation gives the same functionality and the same externally visible behavior ๐
this section explains BGP operation as a Finite State Machine (FSM) ๐. it's split into two parts:
- Description of Events for the State machine (Section 8.1)
- Description of the FSM (Section 8.2)
these are the session attributes that every connection MUST have ๐:
StateConnectRetryCounterConnectRetryTimerConnectRetryTimeHoldTimerHoldTimeKeepaliveTimerKeepaliveTime
the State attribute tracks the current state of the BGP FSM ๐ฆ. the ConnectRetryCounter counts how many times a BGP peer has tried to set up a peer session ๐ข
the timer-related attributes are mandatory too, and they're covered in Section 10 โฐ. every timer comes as a pair: a "timer" and a "time", where the "time" is its starting value ๐ธ
next up are the optional session attributes ๐. these might be supported per connection or per local system, and they're:
AcceptConnectionsUnconfiguredPeersAllowAutomaticStartAllowAutomaticStopCollisionDetectEstablishedStateDampPeerOscillationsDelayOpenDelayOpenTimeDelayOpenTimerIdleHoldTimeIdleHoldTimerPassiveTcpEstablishmentSendNOTIFICATIONwithoutOPENTrackTcpState
these optional attributes unlock different BGP features, and some of them change how FSM state transitions happen ๐ฆ the timer-related ones come in two groups:
- group 1:
DelayOpen,DelayOpenTime,DelayOpenTimer - group 2:
DampPeerOscillations,IdleHoldTime,IdleHoldTimer
in each group, the first parameter (DelayOpen or DampPeerOscillations) is the optional flag that says the timer function is active ๐. the "Time" value (DelayOpenTime or IdleHoldTime) is the starting value for the "Timer" (DelayOpenTimer or IdleHoldTimer), and the "Timer" is the actual running timer โณ
if you want the full scoop on how these optional attributes interact with the events the state machine gets, check out Section 8.1.1 ๐ and Section 8.2.1.3 gives a quick overview of the two kinds of optional attributes (flags and timers) ๐
8.1. Events for the BGP FSM ๐
8.1.1. Optional Events Linked to Optional Session Attributes โจ
okay so the BGP FSM takes events as its inputs ๐ซถ and those events can be either mandatory or optional. some of the optional ones are tied to optional session attributes, and those attributes unlock whole groups of FSM functionality. it's giving "customize your own experience" ๐
here's how the FSM functionality, the events, and the optional session attributes all link up, sorted into four groups ๐
Group 1: Automatic Administrative Events (Start/Stop) ๐ธ
Optional Session Attributes: AllowAutomaticStart, AllowAutomaticStop, DampPeerOscillations, IdleHoldTime, IdleHoldTimer
- Option 1:
AllowAutomaticStart๐ฆ- Description: a BGP peer connection can be started and stopped by administrative control. that control can be manual (an operator doing the thing) or built into the implementation's own logic. "automatic" just means a start gets handed to the peer connection FSM when that logic decides the connection should restart.
- The
AllowAutomaticStartattribute says this BGP connection supports automatic starting of the BGP connection. if the implementation supports it, the peer may be restarted over and over. three other options control how fast that automatic restart happens:DampPeerOscillations,IdleHoldTime, and theIdleHoldTimer. DampPeerOscillationssays the implementation brings in extra logic to damp the oscillations of BGP peers when there's a run of automatic starts and automatic stops.IdleHoldTimeis how long the peer gets held in the Idle state before the next automatic restart is allowed. theIdleHoldTimeris the timer doing the holding ๐ง- example vibe: if a peer keeps connecting and disconnecting, damping logic can kick in when it does that 10 times within 5 minutes. then
IdleHoldTimegoes from 0 to 120 seconds. the peer is literally put in timeout ๐ญ - Values:
TRUEorFALSE
- Option 2:
AllowAutomaticStop๐- Description: this BGP peer session optional attribute says the BGP connection allows "automatic" stopping of the BGP connection. an "automatic" stop is one that happens under the control of implementation-specific logic. that logic is outside the scope of this specification, so not our problem today ๐
- Values:
TRUEorFALSE
- Option 3:
DampPeerOscillations๐- Description: the
DampPeerOscillationsoptional session attribute says the BGP connection is using logic that damps BGP peer oscillations in the Idle State. main character energy for stability ๐ - Value:
TRUEorFALSE
- Description: the
- Option 4:
IdleHoldTimeโญ- Description: the
IdleHoldTimeis the value that gets set in theIdleHoldTimer. - Values: Time in seconds
- Description: the
- Option 5:
IdleHoldTimerโฐ- Description: the
IdleHoldTimerhelps control BGP peer oscillation. it's used to keep the BGP peer in Idle for a particular duration. theIdleHoldTimer_Expiresevent is described in Section 8.1.3. - Values: Time in seconds
- Description: the
Group 2: Unconfigured Peers ๐
Optional Session Attributes: AcceptConnectionsUnconfiguredPeers
- Option 1:
AcceptConnectionsUnconfiguredPeers๐ซง- Description: the BGP FSM can optionally allow BGP peer connections from neighbors that aren't pre-configured. the
"AcceptConnectionsUnconfiguredPeers"optional session attribute lets the FSM support the state transitions that let the implementation accept or reject these unconfigured peers. - Value: True or False
- Description: the BGP FSM can optionally allow BGP peer connections from neighbors that aren't pre-configured. the
โ ๏ธ this one is serious, bestie. AcceptConnectionsUnconfiguredPeers has security implications. please refer to the BGP Vulnerabilities document [RFC4272] for details. don't skip this one ๐
Group 3: TCP processing ๐ฆ
Optional Session Attributes: PassiveTcpEstablishment, TrackTcpState
- Option 1:
PassiveTcpEstablishment๐ท- Description: this option says the BGP FSM will passively wait for the remote BGP peer to establish the BGP TCP connection. patience is a whole aesthetic ๐ง
- value:
TRUEorFALSE
- Option 2:
TrackTcpState๐- Description: normally, the BGP FSM tracks the end result of a TCP connection attempt rather than individual TCP messages. optionally, the BGP FSM can support additional interaction with the TCP connection negotiation. the catch is that interacting with the TCP events may increase the amount of logging the BGP peer connection requires and the number of BGP FSM changes ๐
- Value:
TRUEorFALSE
Group 4: BGP Message Processing ๐
Optional Session Attributes: DelayOpen, DelayOpenTime, DelayOpenTimer, SendNOTIFICATIONwithoutOPEN, CollisionDetectEstablishedState
- Option 1:
DelayOpenโณ- Description: the
DelayOpenoptional session attribute lets implementations be configured to delay sending an OPEN message for a specific time period (DelayOpenTime). the delay gives the remote BGP Peer time to send the first OPEN message. let them cook ๐ณ - Value:
TRUEorFALSE
- Description: the
- Option 2:
DelayOpenTime๐ฐ๏ธ- Description: the
DelayOpenTimeis the initial value set in theDelayOpenTimer. - Value: Time in seconds
- Description: the
- Option 3:
DelayOpenTimerโ- Description: the
DelayOpenTimeroptional session attribute is used to delay the sending of an OPEN message on a connection. theDelayOpenTimer_Expiresevent (Event 12) is described in Section 8.1.3. - Value: Time in seconds
- Description: the
- Option 4:
SendNOTIFICATIONwithoutOPEN๐ฃ- Description: the
SendNOTIFICATIONwithoutOPENlets a peer send a NOTIFICATION without first sending an OPEN message. without this optional session attribute, the BGP connection assumes that an OPEN message must be sent by a peer before the peer sends a NOTIFICATION message. the rules, bestie ๐ - Value: True or False
- Description: the
- Option 5:
CollisionDetectEstablishedState๐ฅ- Description: normally, a Detect Collision (see Section 6.8) will be ignored in the Established state. this optional session attribute says this BGP connection processes collisions in the Established state. the exception that hits different ๐ญ
- Value: True or False
Note: the optional session attributes clarify the BGP FSM description for existing features of BGP implementations. they may be pre-defined for an implementation and not readable via management interfaces for existing correct implementations. as newer BGP MIBs (version 2 and beyond) are supported, these fields will be accessible via a management interface ๐ธ
8.1.2. Administrative Events โจ
okay bestie, so an administrative event is when the operator interface and the BGP Policy engine tell the BGP FSM to start or stop the BGP state machine ๐. The plain start and stop signals come with optional connection attributes stapled on, and those tell the FSM what kind of start or stop mechanism to use ๐
. Take Event 5, AutomaticStart_with_PassiveTcpEstablishment: the implementation is basically saying "hey, I'm doing an Automatic Start, and I want Passive TCP Establishment," which means this FSM just sits there and waits for the other side to start the TCP connection ๐ฆ. Iconic waiting energy ๐ญ.
ngl, only Event 1 (ManualStart) and Event 2 (ManualStop) are mandatory admin events ๐ซถ. Events 3-8 are optional ๐ธ. Each event below has a name, a definition, a status (mandatory or optional), and the optional session attributes that SHOULD be set at each stage. When an implementation generates Event 1 through Event 8, it checks the conditions in the "Optional Attribute Status" section, and if any of them aren't met, the local system should log an FSM error ๐.
The optional session attributes can be implicit in some implementations, so an operator might never set them by hand ๐ง. Section 8.2.1.5 explains those implicit settings. The admin states can be implicit too, and an operator might not be able to configure them directly ๐.
Event 1: ManualStart ๐
- Definition: the local system's admin is the one who manually starts the peer connection, no autopilot needed.
- Status: Mandatory
- Optional Attribute Status: The
PassiveTcpEstablishmentattribute SHOULD be set toFALSE.
Event 2: ManualStop ๐
- Definition: the local system's admin is the one who manually stops the peer connection.
- Status: Mandatory
- Optional Attribute Status: No interaction with any optional attributes.
Event 3: AutomaticStart ๐ค
- Definition: the local system automatically starts the BGP connection.
- Status: Optional, depending on local system
- Optional Attribute Status:
- The
AllowAutomaticStartattribute SHOULD be set toTRUEif this event occurs. - If the
PassiveTcpEstablishmentoptional session attribute is supported, it SHOULD be set toFALSE. - If the
DampPeerOscillationsis supported, it SHOULD be set toFALSEwhen this event occurs.
- The
Event 4: ManualStart_with_PassiveTcpEstablishment ๐
- Definition: the local system's admin manually starts the peer connection, but
PassiveTcpEstablishmentis turned on. ThePassiveTcpEstablishmentoptional attribute means the peer will listen before the connection gets established. - Status: Optional, depending on local system
- Optional Attribute Status:
- The
PassiveTcpEstablishmentattribute SHOULD be set toTRUEif this event occurs. - The
DampPeerOscillationsattribute SHOULD be set toFALSEwhen this event occurs.
- The
Event 5: AutomaticStart_with_PassiveTcpEstablishment ๐ง
- Definition: the local system automatically starts the BGP connection with
PassiveTcpEstablishmentturned on. ThePassiveTcpEstablishmentoptional attribute means the peer will listen before establishing a connection. - Status: Optional, depending on local system
- Optional Attribute Status:
- The
AllowAutomaticStartattribute SHOULD be set toTRUE. - The
PassiveTcpEstablishmentattribute SHOULD be set toTRUE. - If the
DampPeerOscillationsattribute is supported, theDampPeerOscillationsSHOULD be set toFALSE.
- The
Event 6: AutomaticStart_with_DampPeerOscillations ๐
- Definition: the local system automatically starts the BGP peer connection with peer oscillation damping turned on. The exact method of damping persistent peer oscillations is up to the implementation and is outside the scope of this document.
- Status: Optional, depending on local system.
- Optional Attribute Status:
- The
AllowAutomaticStartattribute SHOULD be set toTRUE. - The
DampPeerOscillationsattribute SHOULD be set toTRUE. - The
PassiveTcpEstablishmentattribute SHOULD be set toFALSE.
- The
Event 7: AutomaticStart_with_DampPeerOscillations_and_PassiveTcpEstablishment ๐
- Definition: the local system automatically starts the BGP peer connection with peer oscillation damping and
PassiveTcpEstablishmentboth turned on. The exact method of damping persistent peer oscillations is up to the implementation and is outside the scope of this document. - Status: Optional, depending on local system
- Optional Attributes Status:
- The
AllowAutomaticStartattribute SHOULD be set toTRUE. - The
DampPeerOscillationsattribute SHOULD be set toTRUE. - The
PassiveTcpEstablishmentattribute SHOULD be set toTRUE.
- The
Event 8: AutomaticStop ๐
- Definition: the local system automatically stops the BGP connection. An example of an automatic stop is going over the number of prefixes for a given peer, so the local system automatically disconnects that peer.
- Status: Optional, depending on local system
- Optional Attribute Status:
- The
AllowAutomaticStopattribute SHOULD beTRUE.
- The
8.1.3. Timer Events โฐ
Event 9: ConnectRetryTimer_Expires ๐
- Definition: an event that gets generated when the ConnectRetryTimer expires.
- Status: Mandatory
Event 10: HoldTimer_Expires ๐
- Definition: an event that gets generated when the HoldTimer expires.
- Status: Mandatory
Event 11: KeepaliveTimer_Expires ๐
- Definition: an event that gets generated when the KeepaliveTimer expires.
- Status: Mandatory
Event 12: DelayOpenTimer_Expires ๐ฐ๏ธ
- Definition: an event that gets generated when the DelayOpenTimer expires.
- Status: Optional
- Optional Attribute Status: If this event occurs,
- The DelayOpen attribute SHOULD be set to
TRUE, - The DelayOpenTime attribute SHOULD be supported,
- The DelayOpenTimer SHOULD be supported.
- The DelayOpen attribute SHOULD be set to
Event 13: IdleHoldTimer_Expires ๐ง
- Definition: an event that gets generated when the IdleHoldTimer expires, which tells us the BGP connection has finished waiting out the back-off period that prevents BGP peer oscillation. The IdleHoldTimer only gets used when persistent peer oscillation damping is turned on by setting the
DampPeerOscillationsoptional attribute toTRUE. Implementations that don't do persistent peer oscillation damping may not have the IdleHoldTimer at all. - Status: Optional
- Optional Attribute Status: If this event occurs:
- The
DampPeerOscillationsattribute SHOULD be set toTRUE. - The IdleHoldTimer SHOULD have just expired.
- The
8.1.4. TCP Connection-Based Events ๐
Event 14: TcpConnection_Valid ๐
- Definition: an event that tells us the local system got a TCP connection request with a valid source IP address, TCP port, destination IP address, and TCP port. What counts as an invalid source or invalid destination IP address is up to the implementation. BGP's destination port SHOULD be port 179, as IANA defined. A TCP connection request is when the local system receives a TCP SYN.
- Status: Optional
- Optional Attribute Status:
- The
TrackTcpStateattribute SHOULD be set toTRUEif this event occurs.
- The
Event 15: Tcp_CR_Invalid ๐ซ
- Definition: an event that tells us the local system got a TCP connection request with either an invalid source address or port number, or an invalid destination address or port number. The BGP destination port number SHOULD be 179, as IANA defined. A TCP connection request happens when the local system receives a TCP SYN.
- Status: Optional
- Optional Attribute Status:
- The
TrackTcpStateattribute should be set toTRUEif this event occurs.
- The
Event 16: Tcp_CR_Acked ๐ค
- Definition: an event that tells us the local system asked to set up a TCP connection to the remote peer. The local system's TCP connection sent a TCP SYN, got a TCP SYN/ACK back, and then sent a TCP ACK.
- Status: Mandatory
Event 17: TcpConnectionConfirmed โ
- Definition: an event that tells us the local system got confirmation that the remote site has set up the TCP connection. The remote peer's TCP engine sent a TCP SYN. The local peer's TCP engine sent a SYN, ACK message and has now received a final ACK.
- Status: Mandatory
Event 18: TcpConnectionFails ๐
- Definition: an event that tells us the local system got a TCP connection failure notice. The remote BGP peer's TCP machine could have sent a FIN, and the local peer would respond with a FIN-ACK. Another possibility is that the local peer hit a timeout on the TCP connection and took the connection down.
- Status: Mandatory
8.1.5. BGP Message-Based Events โจ
Event 19: BGPOpen ๐
- Definition: an event gets generated when a valid OPEN message has been received ๐จ
- Status: Mandatory
- Optional Attribute Status:
- The
DelayOpenoptional attribute SHOULD be set to FALSE. - The
DelayOpenTimerSHOULD not be running.
- The
Event 20: BGPOpen with DelayOpenTimer running ๐ฆ
- Definition: an event gets generated when a valid OPEN message has been received for a peer that has a successfully established transport connection and is currently delaying the sending of a BGP open message. It's giving patience ๐ง
- Status: Optional
- Optional Attribute Status:
- The
DelayOpenattribute SHOULD be set to TRUE. - The
DelayOpenTimerSHOULD be running.
- The
Event 21: BGPHeaderErr ๐
- Definition: an event gets generated when a received BGP message header is not valid. Header, not valid, bestie ๐
- Status: Mandatory
Event 22: BGPOpenMsgErr ๐ญ
- Definition: an event gets generated when an OPEN message has been received with errors.
- Status: Mandatory
Event 23: OpenCollisionDump ๐ฅ
- Definition: an event generated administratively when a connection collision has been detected while processing an incoming OPEN message and this connection has been selected to be disconnected. Collision drama, iykyk. Check Section 6.8 for the full tea on collision detection ๐
- Status: Optional
Event 23 is an administrative action generated by implementation logic that determines whether this connection needs to be dropped per the rules in Section 6.8. This event may occur if the FSM is implemented as two linked state machines. Very main character energy for the implementation logic ๐
- Optional Attribute Status: if the state machine is to process this event in the Established state, the
CollisionDetectEstablishedStateoptional attribute SHOULD be set to TRUE.
Please note: the OpenCollisionDump event can occur in Idle, Connect, Active, OpenSent, and OpenConfirm without any optional attributes being set. No attributes needed, it just happens ๐
Event 24: NotifMsgVerErr ๐ธ
- Definition: an event gets generated when a NOTIFICATION message with "version error" is received.
- Status: Mandatory
Event 25: NotifMsg ๐
- Definition: an event gets generated when a NOTIFICATION message is received and the error code is anything but "version error".
- Status: Mandatory
Event 26: KeepAliveMsg ๐
- Definition: an event gets generated when a KEEPALIVE message is received. Little heartbeat check ๐ซถ
- Status: Mandatory
Event 27: UpdateMsg โจ
- Definition: an event gets generated when a valid UPDATE message is received.
- Status: Mandatory
Event 28: UpdateMsgErr ๐
- Definition: an event gets generated when an invalid UPDATE message is received.
- Status: Mandatory
8.2. Description of FSM ๐ง
8.2.1. FSM Definition ๐ซ
BGP MUST maintain a separate FSM for each configured peer. Each BGP peer paired in a potential connection will attempt to connect to the other, unless configured to remain in the idle state, or configured to remain passive. Okay so for this chat, the active or connecting side of the TCP connection (the side that sends the first TCP SYN packet) is called outgoing. The passive or listening side (the sender of the first SYN/ACK) is called an incoming connection. Lowkey the active and passive terms are explained more in Section 8.2.1.1, so go check that when you get a sec ๐ฆ
A BGP implementation MUST connect to and listen on TCP port 179 for incoming connections in addition to trying to connect to peers. For each incoming connection, a state machine MUST be instantiated. There's a stretch where you know who the peer is on the other end of an incoming connection, but you don't know the BGP identifier yet. During that time, both an incoming and outgoing connection may exist for the same configured peering. This is referred to as a connection collision (see Section 6.8). Collision moment, bestie ๐
A BGP implementation will have, at most, one FSM for each configured peering, plus one FSM for each incoming TCP connection for which the peer has not yet been identified. Each FSM corresponds to exactly one TCP connection. One FSM, one connection, no cap ๐
There may be more than one connection between a pair of peers if the connections are configured to use a different pair of IP addresses. This is referred to as multiple "configured peerings" to the same peer. Two peerings, same friend, it's giving double the bond ๐
8.2.1.1. Terms "active" and "passive" ๐ท
The terms active and passive have been in the Internet operator's vocabulary for almost a decade and have proven useful. The words active and passive have slightly different meanings when applied to a TCP connection or a peer. There is only one active side and one passive side to any one TCP connection, per the definition above and the state machine below. When a BGP speaker is configured as active, it may end up on either the active or passive side of the connection that eventually gets established. Once the TCP connection is completed, it doesn't matter which end was active and which was passive. The only difference is in which side of the TCP connection has port number 179. Port 179 is literally the only thing that tells them apart ๐
8.2.1.2. FSM and Collision Detection ๐ซง
There is one FSM per BGP connection. When the connection collision occurs prior to determining what peer a connection is associated with, there may be two connections for one peer. After the connection collision is resolved (see Section 6.8), the FSM for the connection that is closed SHOULD be disposed. Clean up after the drama, periodt ๐งน
8.2.1.3. FSM and Optional Session Attributes ๐
Optional Session Attributes specify either attributes that act as flags (TRUE or FALSE) or optional timers. For optional attributes that act as flags, if the optional session attribute can be set to TRUE on the system, the corresponding BGP FSM actions must be supported. For example, if the following options can be set in a BGP implementation: AutoStart and PassiveTcpEstablishment, then Events 3, 4 and 5 must be supported. If an Optional Session attribute cannot be set to TRUE, the events supporting that set of options do not have to be supported. Basically, if the switch can flip on, the matching moves have to work ๐ง
Each of the optional timers (DelayOpenTimer and IdleHoldTimer) has a group of attributes that are:
- flag indicating support,
- Time set in Timer
- Timer.
The two optional timers show this format:
DelayOpenTimer: DelayOpen, DelayOpenTime, DelayOpenTimer
IdleHoldTimer: DampPeerOscillations, IdleHoldTime,
IdleHoldTimer
If the flag indicating support for an optional timer (DelayOpen or DampPeerOscillations) cannot be set to TRUE, the timers and events supporting that option do not have to be supported. Skip the extras if they're not on the menu ๐
8.2.1.4. FSM Event Numbers ๐ข
The Event numbers (1-28) utilized in this state machine description aid in specifying the behavior of the BGP state machine. Implementations MAY use these numbers to provide network management information. The exact form of an FSM or the FSM events are specific to each implementation. The numbers are a helpful label system, and you can use them for network management if you want to ๐
8.2.1.5. FSM Actions that are Implementation Dependent ๐ ๏ธ
At certain points, the BGP FSM specifies that BGP initialization will occur or that BGP resources will be deleted. The initialization of the BGP FSM and the associated resources depend on the policy portion of the BGP implementation. The details of these actions are outside the scope of the FSM document. That's the implementation's problem to vibe with, not the FSM doc's ๐ซถ
8.2.2. Finite State Machine ๐
Idle state:
Initially, the BGP peer FSM is in the Idle state. Hereafter, the BGP peer FSM will be shortened to BGP FSM. Idle is the starting point, no drama yet ๐
In this state, BGP FSM refuses all incoming BGP connections for this peer. No resources are allocated to the peer. In response to a ManualStart event (Event 1) or an AutomaticStart event (Event 3), the local system:
- initializes all BGP resources for the peer connection,
- sets ConnectRetryCounter to zero,
- starts the ConnectRetryTimer with the initial value,
- initiates a TCP connection to the other BGP peer,
- listens for a connection that may be initiated by the remote BGP peer, and
- changes its state to Connect.
The ManualStop event (Event 2) and AutomaticStop (Event 8) event are ignored in the Idle state. Nothing to see here, just vibes ๐
In response to a ManualStart_with_PassiveTcpEstablishment event (Event 4) or AutomaticStart_with_PassiveTcpEstablishment event (Event 5), the local system:
- initializes all BGP resources,
- sets the ConnectRetryCounter to zero,
- starts the ConnectRetryTimer with the initial value,
- listens for a connection that may be initiated by the remote peer, and
- changes its state to Active.
The exact value of the ConnectRetryTimer is a local matter, but it SHOULD be sufficiently large to allow TCP initialization. Give TCP enough time to get ready, bestie โฐ
If the DampPeerOscillations attribute is set to TRUE, the following three additional events may occur within the Idle state:
AutomaticStart_with_DampPeerOscillations(Event 6),AutomaticStart_with_DampPeerOscillations_and_PassiveTcpEstablishment(Event 7),- IdleHoldTimer_Expires (Event 13).
Upon receiving these 3 events, the local system will use these events to prevent peer oscillations. The method of preventing persistent peer oscillation is outside the scope of this document. Anti-flip-flop energy ๐ฆ
Any other event (Events 9-12, 15-28) received in the Idle state does not cause change in the state of the local system. Ignored, moving on ๐
Connect State:
In this state, BGP FSM is waiting for the TCP connection to be completed. Waiting room vibes โณ
The start events (Events 1, 3-7) are ignored in the Connect state. Already started, we're good ๐ธ
In response to a ManualStop event (Event 2), the local system:
- drops the TCP connection,
- releases all BGP resources,
- sets ConnectRetryCounter to zero,
- stops the ConnectRetryTimer and sets ConnectRetryTimer to zero, and
- changes its state to Idle.
In response to the ConnectRetryTimer_Expires event (Event 9), the local system:
- drops the TCP connection,
- restarts the ConnectRetryTimer,
- stops the DelayOpenTimer and resets the timer to zero,
- initiates a TCP connection to the other BGP peer,
- continues to listen for a connection that may be initiated by the remote BGP peer, and
- stays in the Connect state.
If the DelayOpenTimer_Expires event (Event 12) occurs in the Connect state, the local system:
- sends an OPEN message to its peer,
- sets the HoldTimer to a large value, and
- changes its state to OpenSent.
If the BGP FSM receives a TcpConnection_Valid event (Event 14), the TCP connection is processed, and the connection remains in the Connect state. Valid connection, we're processing it ๐
If the BGP FSM receives a Tcp_CR_Invalid event (Event 15), the local system rejects the TCP connection, and the connection remains in the Connect state. Not today, invalid connection ๐ โโ๏ธ
Okay so the TCP connection succeeds (Event 16 or Event 17) and the local system has to check the DelayOpen attribute before it does anything else ๐ ๐. If DelayOpen is set to TRUE, the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero โฐ, - sets the
DelayOpenTimerto its initial value, and - stays in the Connect state ๐งธ.
If DelayOpen is set to FALSE, the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero, - completes BGP initialization,
- sends an OPEN message to its peer ๐จ,
- sets the
HoldTimerto a large value, and - changes its state to OpenSent ๐ซ.
A HoldTimer value of 4 minutes is suggested, bestie โฑ๏ธ.
If the TCP connection fails (Event 18), the local system checks the DelayOpenTimer. If the DelayOpenTimer is running, the local system:
- restarts the
ConnectRetryTimerwith the initial value, - stops the
DelayOpenTimerand resets its value to zero, - continues to listen for a connection that may be initiated by the remote BGP peer ๐, and
- changes its state to Active ๐ฆ.
If the DelayOpenTimer is not running, the local system:
- stops the
ConnectRetryTimerand sets it to zero, - drops the TCP connection,
- releases all BGP resources, and
- changes its state to Idle ๐ฅ.
If an OPEN message is received while the DelayOpenTimer is running (Event 20), the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero, - completes the BGP initialization,
- stops and clears the
DelayOpenTimer(sets the value to zero), - sends an OPEN message,
- sends a KEEPALIVE message,
- if the
HoldTimerinitial value is non-zero:- starts the
KeepaliveTimerwith the initial value, and - resets the
HoldTimerto the negotiated value,
- starts the
- else, if the
HoldTimerinitial value is zero:- resets the
KeepaliveTimer, and - resets the
HoldTimervalue to zero,
- resets the
- and changes its state to OpenConfirm ๐ซถ.
If the value of the autonomous system field is the same as the local Autonomous System number, set the connection status to an internal connection; otherwise it will be "external" ๐.
If BGP message header checking (Event 21) or OPEN message checking detects an error (Event 22) (see Section 6.2), the local system:
- (optionally) if the
SendNOTIFICATIONwithoutOPENattribute is set toTRUE, first sends a NOTIFICATION message with the appropriate error code, and then - stops the
ConnectRetryTimer(if running) and sets it to zero, - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle ๐.
If a NOTIFICATION message is received with a version error (Event 24), the local system checks the DelayOpenTimer. If the DelayOpenTimer is running, the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero, - stops and resets the
DelayOpenTimer(sets it to zero), - releases all BGP resources,
- drops the TCP connection, and
- changes its state to Idle.
If the DelayOpenTimer is not running, the local system:
- stops the
ConnectRetryTimerand sets it to zero, - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTrue, and - changes its state to Idle.
In response to any other events (Events 8, 10-11, 13, 19, 23, 25-28), the local system:
- if the
ConnectRetryTimeris running, stops and resets it (sets it to zero), - if the
DelayOpenTimeris running, stops and resets it (sets it to zero), - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTrue, and - changes its state to Idle ๐.
Active State ๐ธ
In this state, the BGP FSM is trying to acquire a peer by listening for, and accepting, a TCP connection ๐ง.
The start events (Events 1, 3-7) are ignored in the Active state ๐ โโ๏ธ.
In response to a ManualStop event (Event 2), the local system:
- if the
DelayOpenTimeris running and theSendNOTIFICATIONwithoutOPENsession attribute is set, sends a NOTIFICATION with a Cease, - releases all BGP resources, including stopping the
DelayOpenTimer, - drops the TCP connection,
- sets the
ConnectRetryCounterto zero, - stops the
ConnectRetryTimerand sets it to zero, and - changes its state to Idle.
In response to a ConnectRetryTimer_Expires event (Event 9), the local system:
- restarts the
ConnectRetryTimer(with the initial value), - initiates a TCP connection to the other BGP peer,
- continues to listen for a TCP connection that may be initiated by a remote BGP peer, and
- changes its state to Connect.
If the local system receives a DelayOpenTimer_Expires event (Event 12), the local system:
- sets the
ConnectRetryTimerto zero, - stops and clears the
DelayOpenTimer(sets it to zero), - completes the BGP initialization,
- sends the OPEN message to its remote peer,
- sets its hold timer to a large value, and
- changes its state to OpenSent ๐.
A HoldTimer value of 4 minutes is also suggested for this state transition โฑ๏ธ.
If the local system receives a TcpConnection_Valid event (Event 14), the local system processes the TCP connection flags and stays in the Active state.
If the local system receives a Tcp_CR_Invalid event (Event 15), the local system rejects the TCP connection and stays in the Active State ๐ซ.
In response to the success of a TCP connection (Event 16 or Event 17), the local system checks the DelayOpen optional attribute prior to processing.
If the DelayOpen attribute is set to TRUE, the local system:
- stops the
ConnectRetryTimerand sets it to zero, - sets the
DelayOpenTimerto the initial value (DelayOpenTime), and - stays in the Active state.
If the DelayOpen attribute is set to FALSE, the local system:
- sets the
ConnectRetryTimerto zero, - completes the BGP initialization,
- sends the OPEN message to its peer,
- sets its
HoldTimerto a large value, and - changes its state to OpenSent.
A HoldTimer value of 4 minutes is suggested as a "large value" for the HoldTimer ๐.
If the local system receives a TcpConnectionFails event (Event 18), the local system:
- restarts the
ConnectRetryTimer(with the initial value), - stops and clears the
DelayOpenTimer(sets the value to zero), - releases all BGP resource,
- increments the
ConnectRetryCounterby 1, - optionally performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
If an OPEN message is received and the DelayOpenTimer is running (Event 20), the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero, - stops and clears the
DelayOpenTimer(sets it to zero), - completes the BGP initialization,
- sends an OPEN message,
- sends a KEEPALIVE message,
- if the
HoldTimervalue is non-zero:- starts the
KeepaliveTimerto the initial value, and - resets the
HoldTimerto the negotiated value,
- starts the
- else if the
HoldTimeris zero:- resets the
KeepaliveTimer(set to zero), and - resets the
HoldTimerto zero, and
- resets the
- changes its state to OpenConfirm ๐.
If the value of the autonomous system field is the same as the local Autonomous System number, set the connection status to an internal connection; otherwise it will be external.
If BGP message header checking (Event 21) or OPEN message checking detects an error (Event 22) (see Section 6.2), the local system:
- (optionally) sends a NOTIFICATION message with the appropriate error code if the
SendNOTIFICATIONwithoutOPENattribute is set toTRUE, - sets the
ConnectRetryTimerto zero, - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
If a NOTIFICATION message is received with a version error (Event 24), the local system checks the DelayOpenTimer. If the DelayOpenTimer is running, the local system:
- stops the
ConnectRetryTimer(if running) and sets it to zero, - stops and resets the
DelayOpenTimer(sets it to zero), - releases all BGP resources,
- drops the TCP connection, and
- changes its state to Idle.
If the DelayOpenTimer is not running, the local system:
- sets the
ConnectRetryTimerto zero, - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
In response to any other event (Events 8, 10-11, 13, 19, 23, 25-28), the local system:
- sets the
ConnectRetryTimerto zero, - releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby one, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle ๐งธ.
OpenSent ๐ฌ
In this state, the BGP FSM waits for an OPEN message from its peer ๐.
The start events (Events 1, 3-7) are ignored in the OpenSent state.
If a ManualStop event (Event 2) is issued in the OpenSent state, the local system:
- sends the NOTIFICATION with a Cease,
- sets the
ConnectRetryTimerto zero, - releases all BGP resources,
- drops the TCP connection,
- sets the
ConnectRetryCounterto zero, and - changes its state to Idle.
If an AutomaticStop event (Event 8) is issued in the OpenSent state, the local system:
- sends the NOTIFICATION with a Cease,
- sets the
ConnectRetryTimerto zero, - releases all the BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
If the HoldTimer_Expires (Event 10), the local system:
- sends a NOTIFICATION message with the error code Hold Timer Expired,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
okay so if a TcpConnection_Valid (Event 14), Tcp_CR_Acked (Event 16), or a TcpConnectionConfirmed event (Event 17) shows up, a second TCP connection may be in progress ๐. This second TCP connection gets tracked under Connection Collision processing (Section 6.8) until an OPEN message is received ๐ซถ.
A TCP Connection Request for an Invalid port (Tcp_CR_Invalid (Event 15)) gets ignored ๐.
If a TcpConnectionFails event (Event 18) is received, the local system:
- closes the BGP connection,
- restarts the ConnectRetryTimer,
- continues to listen for a connection that may be initiated by the remote BGP peer, and
- changes its state to Active.
When an OPEN message is received, all fields get checked for correctness ๐. If there are no errors in the OPEN message (Event 19), the local system:
- resets the DelayOpenTimer to zero,
- sets the BGP ConnectRetryTimer to zero,
- sends a KEEPALIVE message, and
- sets a KeepaliveTimer (via the text below)
- sets the HoldTimer according to the negotiated value (see Section 4.2),
- changes its state to OpenConfirm.
If the negotiated hold time value is zero, then the HoldTimer and KeepaliveTimer are not started ๐. If the value of the Autonomous System field is the same as the local Autonomous System number, then the connection is an "internal" connection. Otherwise, it is an "external" connection. (This will impact UPDATE processing as described below ๐ง)
If the BGP message header checking (Event 21) or OPEN message checking detects an error (Event 22) (see Section 6.2), the local system:
- sends a NOTIFICATION message with the appropriate error code,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is TRUE, and - changes its state to Idle.
Collision detection mechanisms (Section 6.8) need to be applied when a valid BGP OPEN message is received (Event 19 or Event 20) ๐
. Check Section 6.8 for the details of the comparison. A CollisionDetectDump event occurs when the BGP implementation determines, by means outside the scope of this document, that a connection collision has occurred.
If a connection in the OpenSent state is determined to be the connection that must be closed, an OpenCollisionDump (Event 23) is signaled to the state machine. If such an event is received in the OpenSent state, the local system:
- sends a NOTIFICATION with a Cease,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If a NOTIFICATION message is received with a version error (Event 24), the local system:
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection, and
- changes its state to Idle.
In response to any other event (Events 9, 11-13, 20, 25-28), the local system:
- sends the NOTIFICATION with the Error Code Finite State Machine Error,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
OpenConfirm State ๐ธ
In this state, BGP waits for a KEEPALIVE or NOTIFICATION message ๐.
Any start event (Events 1, 3-7) gets ignored in the OpenConfirm state ๐ โโ๏ธ.
In response to a ManualStop event (Event 2) initiated by the operator, the local system:
- sends the NOTIFICATION message with a Cease,
- releases all BGP resources,
- drops the TCP connection,
- sets the ConnectRetryCounter to zero,
- sets the ConnectRetryTimer to zero, and
- changes its state to Idle.
In response to the AutomaticStop event initiated by the system (Event 8), the local system:
- sends the NOTIFICATION message with a Cease,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If the HoldTimer_Expires event (Event 10) occurs before a KEEPALIVE message is received, the local system:
- sends the NOTIFICATION message with the Error Code Hold Timer Expired,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If the local system receives a KeepaliveTimer_Expires event (Event 11), the local system:
- sends a KEEPALIVE message,
- restarts the KeepaliveTimer, and
- remains in the OpenConfirmed state.
In the event of a TcpConnection_Valid event (Event 14), or the success of a TCP connection (Event 16 or Event 17) while in OpenConfirm, the local system needs to track the second connection ๐ต๏ธโโ๏ธ.
If a TCP connection is attempted with an invalid port (Event 15), the local system will ignore the second connection attempt.
If the local system receives a TcpConnectionFails event (Event 18) from the underlying TCP or a NOTIFICATION message (Event 25), the local system:
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If the local system receives a NOTIFICATION message with a version error (NotifMsgVerErr (Event 24)), the local system:
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection, and
- changes its state to Idle.
If the local system receives a valid OPEN message (BGPOpen (Event 19)), the collision detect function is processed per Section 6.8. If this connection is to be dropped due to connection collision, the local system:
- sends a NOTIFICATION with a Cease,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection (send TCP FIN),
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If an OPEN message is received, all fields get checked for correctness. If the BGP message header checking (BGPHeaderErr (Event 21)) or OPEN message checking detects an error (see Section 6.2) (BGPOpenMsgErr (Event 22)), the local system:
- sends a NOTIFICATION message with the appropriate error code,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If, during the processing of another OPEN message, the BGP implementation determines, by a means outside the scope of this document, that a connection collision has occurred and this connection is to be closed, the local system will issue an OpenCollisionDump event (Event 23). When the local system receives an OpenCollisionDump event (Event 23), the local system:
- sends a NOTIFICATION with a Cease,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
If the local system receives a KEEPALIVE message (KeepAliveMsg (Event 26)), the local system:
- restarts the HoldTimer and
- changes its state to Established.
In response to any other event (Events 9, 12-13, 20, 27-28), the local system:
- sends a NOTIFICATION with a code of Finite State Machine Error,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
Established State ๐ฆ
In the Established state, the BGP FSM can exchange UPDATE, NOTIFICATION, and KEEPALIVE messages with its peer ๐.
Any Start event (Events 1, 3-7) gets ignored in the Established state.
In response to a ManualStop event (initiated by an operator) (Event 2), the local system:
- sends the NOTIFICATION message with a Cease,
- sets the ConnectRetryTimer to zero,
- deletes all routes associated with this connection,
- releases BGP resources,
- drops the TCP connection,
- sets the ConnectRetryCounter to zero, and
- changes its state to Idle.
In response to an AutomaticStop event (Event 8), the local system:
- sends a NOTIFICATION with a Cease,
- sets the ConnectRetryTimer to zero,
- deletes all routes associated with this connection,
- releases all BGP resources,
- drops the TCP connection,
- increments the ConnectRetryCounter by 1,
- (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set to TRUE, and - changes its state to Idle.
One reason for an AutomaticStop event is: A BGP receives an UPDATE messages with a number of prefixes for a given peer such that the total prefixes received exceeds the maximum number of prefixes configured. The local system automatically disconnects the peer ๐จ.
If the HoldTimer_Expires event occurs (Event 10), the local system:
- sends a NOTIFICATION message with the Error Code Hold Timer Expired,
- sets the ConnectRetryTimer to zero,
- releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
If the KeepaliveTimer_Expires event happens (Event 11), the local system:
- sends a KEEPALIVE message, and
- restarts its
KeepaliveTimer, unless the negotiatedHoldTimevalue is zero.
Every time the local system sends a KEEPALIVE or UPDATE message, it restarts its KeepaliveTimer, unless the negotiated HoldTime value is zero. ๐ฐ๏ธโจ
A TcpConnection_Valid (Event 14) that shows up for a valid port makes the second connection get tracked. ๐
An invalid TCP connection (Tcp_CR_Invalid event, Event 15) just gets ignored. Bye bye ๐ซถ
When the TCP connection comes back as successfully established (Event 16 or Event 17), the second connection SHALL be tracked until it sends an OPEN message. ๐ฆ
If a valid OPEN message (BGPOpen, Event 19) arrives and the CollisionDetectEstablishedState optional attribute is TRUE, the OPEN message gets checked to see if it collides (Section 6.8) with any other connection. If the BGP implementation decides this connection needs to be terminated, it processes an OpenCollisionDump event (Event 23). If this connection needs to be terminated, the local system:
- sends a NOTIFICATION with a Cease,
- sets the
ConnectRetryTimerto zero, - deletes all routes associated with this connection,
- releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsis set toTRUE, and - changes its state to Idle.
If the local system gets a NOTIFICATION message (Event 24 or Event 25) or a TcpConnectionFails (Event 18) from the underlying TCP, the local system:
- sets the
ConnectRetryTimerto zero, - deletes all routes associated with this connection,
- releases all the BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, and - changes its state to Idle.
If the local system gets a KEEPALIVE message (Event 26), the local system:
- restarts its
HoldTimer, if the negotiatedHoldTimevalue is non-zero, and - remains in the Established state. ๐
If the local system gets an UPDATE message (Event 27), the local system:
- processes the message,
- restarts its
HoldTimer, if the negotiatedHoldTimevalue is non-zero, and - remains in the Established state. ๐
If the local system gets an UPDATE message, and the UPDATE message error handling procedure (see Section 6.3) detects an error (Event 28), the local system:
- sends a NOTIFICATION message with an Update error,
- sets the
ConnectRetryTimerto zero, - deletes all routes associated with this connection,
- releases all BGP resources,
- drops the TCP connection,
- increments the
ConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if the
DampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
In response to any other event (Events 9, 12-13, 20-22), the local system does all of this, no exceptions, because it's a Finite State Machine Error situation ๐จ: - sends a NOTIFICATION message with the Error Code Finite State Machine Error, - deletes all routes associated with this connection, - sets theConnectRetryTimerto zero, - releases all BGP resources, - drops the TCP connection, - increments theConnectRetryCounterby 1, - (optionally) performs peer oscillation damping if theDampPeerOscillationsattribute is set toTRUE, and - changes its state to Idle.
9. UPDATE Message Handling โจ
An UPDATE message MAY be received only in the Established state. Getting an UPDATE message in any other state is an error. When an UPDATE message comes in, each field gets checked for validity, as specified in Section 6.3. ๐
If an optional non-transitive attribute is unrecognized, it gets quietly ignored ๐คซ. If an optional transitive attribute is unrecognized, the Partial bit (the third high-order bit) in the attribute flags octet is set to 1, and the attribute is kept around for propagation to other BGP speakers. Passing it along, bestie ๐
If an optional attribute is recognized and has a valid value, then, depending on the type of the optional attribute, it gets processed locally, retained, and updated if necessary for possible propagation to other BGP speakers. ๐
If the UPDATE message has a non-empty WITHDRAWN ROUTES field, the previously advertised routes whose destinations (expressed as IP prefixes) are in this field SHALL be removed from the Adj-RIB-In. This BGP speaker SHALL run its Decision Process, because the previously advertised route isn't available for use anymore ๐ฅ
If the UPDATE message has a feasible route, the Adj-RIB-In gets updated with this route like so: if the NLRI of the new route is identical to the one the route already has stored in the Adj-RIB-In, then the new route SHALL replace the older route in the Adj-RIB-In, thus implicitly withdrawing the older route from service. Otherwise, if the Adj-RIB-In has no route with NLRI identical to the new route, the new route SHALL be placed in the Adj-RIB-In. ๐
Once the BGP speaker updates the Adj-RIB-In, the speaker SHALL run its Decision Process. ๐ง
9.1. Decision Process
The Decision Process picks routes for later advertisement by applying the policies in the local Policy Information Base (PIB) to the routes stored in its Adj-RIBs-In. The output of the Decision Process is the set of routes that will be advertised to peers. The selected routes get stored in the local speaker's Adj-RIBs-Out, according to policy. ๐ฎ
The BGP Decision Process described here is conceptual. It does not have to be implemented precisely as described, as long as the implementations support the described functionality and they exhibit the same externally visible behavior. Vibes matter, but so do outcomes ๐ธ
The selection process is formalized by defining a function that takes the attributes of a given route as an argument and returns either (a) a non-negative integer denoting the degree of preference for the route, or (b) a value denoting that this route is ineligible to be installed in Loc-RIB and will be excluded from the next phase of route selection. ๐
The function that calculates the degree of preference for a given route SHALL NOT use any of the following as its inputs: the existence of other routes, the non-existence of other routes, or the path attributes of other routes. Route selection then consists of applying the degree of preference function to each feasible route one at a time, followed by choosing the one with the highest degree of preference. ๐
The Decision Process operates on routes contained in the Adj-RIBs-In, and is responsible for:
- selection of routes to be used locally by the speaker
- selection of routes to be advertised to other BGP peers
- route aggregation and route information reduction
The Decision Process happens in three distinct phases, each triggered by a different event:
a) Phase 1 is responsible for calculating the degree of preference for each route received from a peer.
b) Phase 2 is invoked on completion of phase 1. It is responsible for choosing the best route out of all those available for each distinct destination, and for installing each chosen route into the Loc-RIB.
c) Phase 3 is invoked after the Loc-RIB has been modified. It is responsible for disseminating routes in the Loc-RIB to each peer, according to the policies contained in the PIB. Route aggregation and information reduction can optionally be performed within this phase. ๐ฏ
9.1.1. Phase 1: Calculation of Degree of Preference
The Phase 1 decision function is invoked whenever the local BGP speaker receives, from a peer, an UPDATE message that advertises a new route, a replacement route, or withdrawn routes. ๐ฌ
The Phase 1 decision function is a separate process, which completes when it has no further work to do. โ
The Phase 1 decision function locks an Adj-RIB-In before operating on any route contained within it, and unlocks it after operating on all new or unfeasible routes contained within it. ๐
For each newly received or replacement feasible route, the local BGP speaker determines a degree of preference as follows:
If the route is learned from an internal peer, either the value of the LOCAL_PREF attribute is taken as the degree of preference, or the local system computes the degree of preference of the route based on preconfigured policy information. Note that the latter may result in formation of persistent routing loops. ๐
If the route is learned from an external peer, then the local BGP speaker computes the degree of preference based on preconfigured policy information. If the return value indicates the route is ineligible, the route MAY NOT serve as an input to the next phase of route selection. Otherwise, the return value MUST be used as the LOCAL_PREF value in any IBGP readvertisement. ๐ฃ
The exact nature of this policy information, and the computation involved, is a local matter. ๐ง
9.1.2. Phase 2: Route Selection โจ
okay bestie, Phase 2 is where the real drama happens ๐ The Phase 2 decision function gets invoked as soon as Phase 1 wraps up. It's its own separate process, and it finishes when it has no more work to do ๐ซถ It considers all the routes that are eligible in the Adj-RIBs-In.
Phase 2 is blocked from running while Phase 3 is in process ๐ซ It locks all the Adj-RIBs-In before it starts and unlocks them once it's done ๐
If the NEXT_HOP attribute of a BGP route shows an address that is not resolvable, or that would become unresolvable if the route got installed in the routing table, that BGP route MUST be excluded from the Phase 2 decision function ๐
If the AS_PATH attribute of a BGP route contains an AS loop, the BGP route should be excluded from the Phase 2 decision function ๐ AS loop detection means scanning the full AS path (as specified in the AS_PATH attribute) and checking that the autonomous system number of the local system doesn't show up in it. What a BGP speaker does when it's configured to accept routes with its own autonomous system number in the AS path is outside the scope of this document, so we're leaving that one alone ๐ง
It is critical that BGP speakers within an AS do not make conflicting route selection decisions that would cause forwarding loops ๐ญ that's a whole no-go zone ๐จ
For each set of destinations where a feasible route exists in the Adj-RIBs-In, the local BGP speaker picks the route that has:
- a) the highest degree of preference of any route to the same set of destinations, or
- b) is the only route to that destination, or
- c) is selected as a result of the Phase 2 tie breaking rules specified in Section 9.1.2.2.
The local speaker SHALL then install that route in the Loc-RIB, replacing any route to the same destination that's currently being held there ๐ When the new BGP route gets installed in the Routing Table, care must be taken to make sure existing routes to the same destination that are now invalid get removed from the Routing Table ๐งน Whether the new BGP route replaces an existing non-BGP route in the Routing Table depends on the policy configured on the BGP speaker ๐
The local speaker MUST determine the immediate next-hop address from the NEXT_HOP attribute of the selected route (see Section 5.1.3) ๐ If either the immediate next-hop or the IGP cost to the NEXT_HOP (where the NEXT_HOP is resolved through an IGP route) changes, Phase 2 Route Selection MUST be performed again ๐
Notice that even though BGP routes don't have to be installed in the Routing Table with the immediate next-hop(s), implementations MUST take care that, before any packets get forwarded along a BGP route, its associated NEXT_HOP address is resolved to the immediate (directly connected) next-hop address ๐ธ and that this address (or multiple addresses) is the one that's finally used for actual packet forwarding ๐ฆ
Unresolvable routes SHALL be removed from the Loc-RIB and the routing table ๐ฎ However, the corresponding unresolvable routes SHOULD be kept in the Adj-RIBs-In, just in case they become resolvable later ๐ฅน
9.1.2.1. Route Resolvability Condition
okay so, as Section 9.1.2 mentioned, BGP speakers SHOULD exclude unresolvable routes from the Phase 2 decision ๐ โโ๏ธ This makes sure only valid routes end up in the Loc-RIB and the Routing Table โจ
The route resolvability condition is defined like this:
- 1) A route Rte1, referencing only the intermediate network address, is considered resolvable if the Routing Table contains at least one resolvable route Rte2 that matches Rte1's intermediate network address and is not recursively resolved (directly or indirectly) through Rte1. If multiple matching routes are available, only the longest matching route SHOULD be considered.
- 2) Routes referencing interfaces (with or without intermediate addresses) are considered resolvable if the state of the referenced interface is up and if IP processing is enabled on this interface.
BGP routes don't refer to interfaces directly, but they can be resolved through routes in the Routing Table, and those can be of both types (ones that specify interfaces and ones that don't) ๐งฉ IGP routes and routes to directly connected networks are expected to specify the outbound interface ๐ฃ๏ธ Static routes can specify the outbound interface, the intermediate address, or both ๐ซ
Heads up, bestie ๐จ a BGP route is considered unresolvable when the BGP speaker's Routing Table has no route matching the BGP route's NEXT_HOP ๐ Mutually recursive routes (routes resolving each other, or themselves) also fail the resolvability check ๐
It's also important that implementations don't consider feasible routes that would become unresolvable if they got installed in the Routing Table, even if their NEXT_HOPs are resolvable using the current contents of the Routing Table (mutually recursive routes are an example of this) ๐ช This check makes sure a BGP speaker doesn't install routes in the Routing Table that will get removed and never used by the speaker ๐๏ธ So on top of local Routing Table stability, this check also improves how the protocol behaves across the network ๐๐
Whenever a BGP speaker identifies a route that fails the resolvability check because of mutual recursion, an error message SHOULD be logged ๐
9.1.2.2. Breaking Ties (Phase 2)
okay, so picture this ๐ฌ In its Adj-RIBs-In, a BGP speaker might have several routes to the same destination that all have the same degree of preference ๐ณ The local speaker can only pick one of them for the associated Loc-RIB. It considers all the routes with the same degree of preference, both the ones received from internal peers and the ones received from external peers ๐ซ
The following tie-breaking procedure assumes that, for each candidate route, all the BGP speakers within an autonomous system can work out the cost of a path (interior distance) to the address shown in the route's NEXT_HOP attribute, and that they all follow the same route selection algorithm ๐ง
The tie-breaking algorithm starts by looking at all the equally preferable routes to the same destination, and then picks routes to remove from consideration โ๏ธ It stops as soon as only one route is left in consideration ๐ The criteria MUST be applied in the order specified ๐
Several of the criteria are described using pseudo-code. The pseudo-code was written for clarity, not efficiency ๐ง It isn't meant to specify any particular implementation. BGP implementations MAY use any algorithm that produces the same results as the ones described here ๐ฆ
- a) Remove from consideration all routes that are not tied for having the smallest number of AS numbers present in their AS_PATH attributes. When counting this number, an AS_SET counts as 1, no matter how many ASes are in the set ๐ข
- b) Remove from consideration all routes that are not tied for having the lowest Origin number in their Origin attribute ๐ฅ
- c) Remove from consideration routes with less-preferred MULTI_EXIT_DISC attributes. MULTI_EXIT_DISC is only comparable between routes learned from the same neighboring AS (the neighboring AS is determined from the AS_PATH attribute). Routes that do not have the MULTI_EXIT_DISC attribute are considered to have the lowest possible MULTI_EXIT_DISC value ๐ช
This is also described in the following procedure:
for m = all routes still under consideration
for n = all routes still under consideration
if (neighborAS(m) == neighborAS(n)) and (MED(n) < MED(m))
remove route m from consideration
In the pseudo-code above, MED(n) is a function that returns the value of route n's MULTI_EXIT_DISC attribute. If route n has no MULTI_EXIT_DISC attribute, the function returns the lowest possible MULTI_EXIT_DISC value (i.e., 0) ๐งฎ
Similarly, neighborAS(n) is a function that returns the neighbor AS from which the route was received. If the route is learned via IBGP, and the other IBGP speaker didn't originate the route, it is the neighbor AS from which the other IBGP speaker learned the route. If the route is learned via IBGP, and the other IBGP speaker either (a) originated the route, or (b) created the route by aggregation and the AS_PATH attribute of the aggregate route is either empty or begins with an AS_SET, it is the local AS ๐
If a MULTI_EXIT_DISC attribute is removed before re-advertising a route into IBGP, then comparison based on the received EBGP MULTI_EXIT_DISC attribute MAY still be performed. If an implementation chooses to remove MULTI_EXIT_DISC, then the optional comparison on MULTI_EXIT_DISC, if performed, MUST be performed only among EBGP-learned routes. The best EBGP-learned route may then be compared with IBGP-learned routes after the removal of the MULTI_EXIT_DISC attribute. If MULTI_EXIT_DISC is removed from a subset of EBGP-learned routes, and the selected "best" EBGP-learned route will not have MULTI_EXIT_DISC removed, then the MULTI_EXIT_DISC must be used in the comparison with IBGP-learned routes. For IBGP-learned routes, the MULTI_EXIT_DISC MUST be used in route comparisons that reach this step in the Decision Process. Including the MULTI_EXIT_DISC of an EBGP-learned route in the comparison with an IBGP-learned route, then removing the MULTI_EXIT_DISC attribute, and advertising the route has been proven to cause route loops ๐๐
- d) If at least one of the candidate routes was received via EBGP, remove from consideration all routes that were received via IBGP ๐
- e) Remove from consideration any routes with less-preferred interior cost. The interior cost of a route is determined by calculating the metric to the NEXT_HOP for the route using the Routing Table. If the NEXT_HOP hop for a route is reachable, but no cost can be determined, then this step should be skipped (equivalently, consider all routes to have equal costs) ๐
This is also described in the following procedure.
for m = all routes still under consideration
for n = all routes in still under consideration
if (cost(n) is lower than cost(m))
remove m from consideration
In the pseudo-code above, cost(n) is a function that returns the cost of the path (interior distance) to the address given in the NEXT_HOP attribute of the route ๐บ๏ธ
- f) Remove from consideration all routes other than the route that was advertised by the BGP speaker with the lowest BGP Identifier value ๐
- g) Prefer the route received from the lowest peer address ๐
9.1.3. Phase 3: Route Dissemination โจ
okay so the Phase 3 decision function kicks in when Phase 2 finishes, or whenever any of these things happen ๐
- a) when routes in the Loc-RIB to local destinations have changed
- b) when locally generated routes learned by means outside of BGP have changed
- c) when a new BGP speaker connection has been established
The Phase 3 function is its own separate process that wraps up once it has no more work to do ๐ . The Phase 3 Routing Decision function is blocked from running while the Phase 2 decision function is in process, so no overlapping drama allowed ๐ .
All routes in the Loc-RIB get processed into Adj-RIBs-Out according to configured policy. This policy MAY exclude a route in the Loc-RIB from being installed in a particular Adj-RIB-Out. A route SHALL NOT be installed in the Adj-Rib-Out unless the destination, and NEXT_HOP described by this route, may be forwarded appropriately by the Routing Table ๐ง. If a route in Loc-RIB is excluded from a particular Adj-RIB-Out, the previously advertised route in that Adj-RIB-Out MUST be withdrawn from service by means of an UPDATE message (see 9.2) ๐ญ.
Route aggregation and information reduction techniques (see Section 9.2.2.1) may optionally be applied ๐ธ.
Any local policy that results in routes being added to an Adj-RIB-Out without also being added to the local BGP speaker's forwarding table is outside the scope of this document ๐.
When the updating of the Adj-RIBs-Out and the Routing Table is complete, the local BGP speaker runs the Update-Send process of 9.2 ๐.
9.1.4. Overlapping Routes ๐
A BGP speaker may transmit routes with overlapping Network Layer Reachability Information (NLRI) to another BGP speaker. NLRI overlap happens when a set of destinations is identified in non-matching multiple routes. Because BGP encodes NLRI using IP prefixes, overlap will always show subset relationships. A route describing a smaller set of destinations (a longer prefix) is said to be more specific than a route describing a larger set of destinations (a shorter prefix). Similarly, a route describing a larger set of destinations is said to be less specific than a route describing a smaller set of destinations ๐.
The precedence relationship effectively splits less specific routes into two parts:
- a set of destinations described only by the less specific route, and
- a set of destinations described by the overlap of the less specific and the more specific routes
The set of destinations described by the overlap represents a portion of the less specific route that is feasible but is not currently in use ๐. If a more specific route is later withdrawn, the set of destinations described by the overlap will still be reachable using the less specific route โจ.
If a BGP speaker receives overlapping routes, the Decision Process MUST consider both routes based on the configured acceptance policy. If both a less and a more specific route are accepted, then the Decision Process MUST install, in Loc-RIB, either both the less and the more specific routes or aggregate the two routes and install, in Loc-RIB, the aggregated route, provided that both routes have the same value of the NEXT_HOP attribute ๐ฅ.
If a BGP speaker chooses to aggregate, then it SHOULD either include all ASes used to form the aggregate in an AS_SET, or add the ATOMIC_AGGREGATE attribute to the route. This attribute is now primarily informational ๐
. With the elimination of IP routing protocols that do not support classless routing, and the elimination of router and host implementations that do not support classless routing, there is no longer a need to de-aggregate. Routes SHOULD NOT be de-aggregated. In particular, a route that carries the ATOMIC_AGGREGATE attribute MUST NOT be de-aggregated. That is, the NLRI of this route cannot be more specific. Forwarding along such a route does not guarantee that IP packets will actually traverse only ASes listed in the AS_PATH attribute of the route ๐.
9.2. Update-Send Process ๐
The Update-Send process is responsible for advertising UPDATE messages to all peers. For example, it distributes the routes chosen by the Decision Process to other BGP speakers, which may be located in either the same autonomous system or a neighboring autonomous system ๐ฎ.
When a BGP speaker receives an UPDATE message from an internal peer, the receiving BGP speaker SHALL NOT re-distribute the routing information contained in that UPDATE message to other internal peers (unless the speaker acts as a BGP Route Reflector [RFC2796]) ๐ซ.
As part of Phase 3 of the route selection process, the BGP speaker has updated its Adj-RIBs-Out. All newly installed routes and all newly unfeasible routes for which there is no replacement route SHALL be advertised to its peers by means of an UPDATE message ๐ฃ.
A BGP speaker SHOULD NOT advertise a given feasible BGP route from its Adj-RIB-Out if it would produce an UPDATE message containing the same BGP route as was previously advertised ๐ .
Any routes in the Loc-RIB marked as unfeasible SHALL be removed. Changes to the reachable destinations within its own autonomous system SHALL also be advertised in an UPDATE message ๐งน.
If, due to the limits on the maximum size of an UPDATE message (see Section 4), a single route doesn't fit into the message, the BGP speaker MUST not advertise the route to its peers and MAY choose to log an error locally ๐ฅบ.
9.2.1. Controlling Routing Traffic Overhead ๐ฆ
The BGP protocol constrains the amount of routing traffic (that is, UPDATE messages), in order to limit both the link bandwidth needed to advertise UPDATE messages and the processing power needed by the Decision Process to digest the information contained in the UPDATE messages ๐ง .
9.2.1.1. Frequency of Route Advertisement โฐ
The parameter MinRouteAdvertisementIntervalTimer determines the minimum amount of time that must elapse between an advertisement and/or withdrawal of routes to a particular destination by a BGP speaker to a peer. This rate limiting procedure applies on a per-destination basis, although the value of MinRouteAdvertisementIntervalTimer is set on a per BGP peer basis ๐ฏ.
Two UPDATE messages sent by a BGP speaker to a peer that advertise feasible routes and/or withdrawal of unfeasible routes to some common set of destinations MUST be separated by at least MinRouteAdvertisementIntervalTimer. This can only be achieved by keeping a separate timer for each common set of destinations. This would be unwarranted overhead. Any technique that ensures that the interval between two UPDATE messages sent from a BGP speaker to a peer that advertise feasible routes and/or withdrawal of unfeasible routes to some common set of destinations will be at least MinRouteAdvertisementIntervalTimer, and will also ensure that a constant upper bound on the interval is acceptable ๐ซถ.
Since fast convergence is needed within an autonomous system, either (a) the MinRouteAdvertisementIntervalTimer used for internal peers SHOULD be shorter than the MinRouteAdvertisementIntervalTimer used for external peers, or (b) the procedure describe in this section SHOULD NOT apply to routes sent to internal peers ๐๏ธ.
This procedure does not limit the rate of route selection, but only the rate of route advertisement. If new routes are selected multiple times while awaiting the expiration of MinRouteAdvertisementIntervalTimer, the last route selected SHALL be advertised at the end of MinRouteAdvertisementIntervalTimer ๐.
9.2.1.2. Frequency of Route Origination ๐ท
The parameter MinASOriginationIntervalTimer determines the minimum amount of time that must elapse between successive advertisements of UPDATE messages that report changes within the advertising BGP speaker's own autonomous systems ๐.
9.2.2. Efficient Organization of Routing Information ๐๏ธ
Having selected the routing information it will advertise, a BGP speaker may avail itself of several methods to organize this information in an efficient manner โจ.
9.2.2.1. Information Reduction ๐ช
Information reduction may imply a reduction in granularity of policy control. After information is collapsed, the same policies will apply to all destinations and paths in the equivalence class ๐ค.
The Decision Process may optionally reduce the amount of information that it will place in the Adj-RIBs-Out by any of the following methods:
- a) Network Layer Reachability Information (NLRI):
Destination IP addresses can be represented as IP address prefixes. In cases where there is a correspondence between the address structure and the systems under control of an autonomous system administrator, it will be possible to reduce the size of the NLRI carried in the UPDATE messages ๐งฉ.
- b) AS_PATHs:
AS path information can be represented as ordered AS_SEQUENCEs or unordered AS_SETs. AS_SETs are used in the route aggregation algorithm described in Section 9.2.2.2. They reduce the size of the AS_PATH information by listing each AS number only once, regardless of how many times it may have appeared in multiple AS_PATHs that were aggregated ๐ฆ.
An AS_SET implies that the destinations listed in the NLRI can be reached through paths that traverse at least some of the constituent autonomous systems. AS_SETs provide sufficient information to avoid routing information looping; however, their use may prune potentially feasible paths because such paths are no longer listed individually in the form of AS_SEQUENCEs. In practice, this is not likely to be a problem because once an IP packet arrives at the edge of a group of autonomous systems, the BGP speaker is likely to have more detailed path information and can distinguish individual paths from destinations ๐ฅน.
9.2.2.2. Aggregating Routing Information โจ
Okay so aggregation is basically when you squish a bunch of different routes together so you can advertise just ONE route instead ๐ซถ It can happen as part of the Decision Process, and it helps cut down how much routing info ends up in the Adj-RIBs-Out ๐ง
It also means a BGP speaker has less stuff to store and swap with other BGP speakers, which is so clean ๐ You can aggregate routes by running the following procedure separately on path attributes of the same type and on the Network Layer Reachability Information.
Routes with different MULTI_EXIT_DISC attributes SHALL NOT be aggregated. Not me trying to mix them ๐
If the aggregated route has an AS_SET as the first element in its AS_PATH attribute, then the router that originates the route SHOULD NOT advertise the MULTI_EXIT_DISC attribute with this route. ๐
Path attributes with different type codes cannot be aggregated together. Path attributes with the same type code may be aggregated, following these rules:
- NEXT_HOP: When you aggregate routes that have different NEXT_HOP attributes, the NEXT_HOP attribute of the aggregated route SHALL identify an interface on the BGP speaker that performs the aggregation. ๐ธ
- ORIGIN attribute: If at least one route being aggregated has ORIGIN set to
INCOMPLETE, then the aggregated route MUST have the ORIGIN attribute set toINCOMPLETE. Otherwise, if at least one route being aggregated has ORIGIN set toEGP, then the aggregated route MUST have the ORIGIN attribute set toEGP. In all other cases, the value of the ORIGIN attribute of the aggregated route isIGP. ๐ - AS_PATH attribute: If the routes being aggregated have identical AS_PATH attributes, then the aggregated route has the same AS_PATH attribute as each individual route. ๐ฆ
Okay, now the spicy part ๐ถ๏ธ For aggregating AS_PATH attributes, we model each AS within the AS_PATH attribute as a tuple <type, value>. The "type" tells you what kind of path segment the AS belongs to (like AS_SEQUENCE or AS_SET), and the "value" is the AS number. If the routes being aggregated have different AS_PATH attributes, then the aggregated AS_PATH attribute SHALL satisfy all of the following conditions:
- all tuples of type
AS_SEQUENCEin the aggregated AS_PATH SHALL appear in all of the AS_PATHs in the initial set of routes to be aggregated. - all tuples of type
AS_SETin the aggregated AS_PATH SHALL appear in at least one of the AS_PATHs in the initial set (they may appear as eitherAS_SETorAS_SEQUENCEtypes). - for any tuple X of type
AS_SEQUENCEin the aggregated AS_PATH, which precedes tuple Y in the aggregated AS_PATH, X precedes Y in each AS_PATH in the initial set which contains Y, regardless of the type of Y. - No tuple of type
AS_SETwith the same value SHALL appear more than once in the aggregated AS_PATH. - Multiple tuples of type
AS_SEQUENCEwith the same value may appear in the aggregated AS_PATH only when adjacent to another tuple of the same type and value.
An implementation may choose any algorithm that follows these rules. At a minimum, though, a conformant implementation SHALL be able to run the following algorithm, which meets all of the above conditions:
- determine the longest leading sequence of tuples (as defined above) common to all the AS_PATH attributes of the routes to be aggregated. Make this sequence the leading sequence of the aggregated AS_PATH attribute.
- set the type of the rest of the tuples from the AS_PATH attributes of the routes to be aggregated to
AS_SET, and append them to the aggregated AS_PATH attribute. - if the aggregated AS_PATH has more than one tuple with the same value (regardless of tuple's type), eliminate all but one such tuple by deleting tuples of the type
AS_SETfrom the aggregated AS_PATH attribute. - for each pair of adjacent tuples in the aggregated AS_PATH, if both tuples have the same type, merge them together, as long as doing so will not cause a segment with a length greater than 255 to be generated.
Appendix F, Section F.6 presents another algorithm that satisfies the conditions and allows for more complex policy configurations. Ooh, fancy ๐ง
- ATOMIC_AGGREGATE: If at least one of the routes being aggregated has the ATOMIC_AGGREGATE path attribute, then the aggregated route SHALL have this attribute as well. โจ
- AGGREGATOR: Any AGGREGATOR attributes from the routes being aggregated MUST NOT be included in the aggregated route. The BGP speaker performing the route aggregation MAY attach a new AGGREGATOR attribute (see Section 5.1.7). ๐
9.3. Route Selection Criteria ๐ฅ
Generally, extra rules for comparing routes among several alternatives are outside the scope of this document. There are two exceptions, though:
- If the local AS appears in the AS path of the new route being considered, then that new route cannot be viewed as better than any other route (provided that the speaker is configured to accept such routes). If such a route were ever used, a routing loop could result. ๐ญ
- In order to achieve a successful distributed operation, only routes with a likelihood of stability can be chosen. So an AS SHOULD avoid using unstable routes, and it SHOULD NOT make rapid, spontaneous changes to its choice of route. Quantifying the terms "unstable" and "rapid" (from the previous sentence) will require experience, but the principle is clear. Routes that are unstable can be "penalized" (e.g., by using the procedures described in [RFC2439]). ๐
9.4. Originating BGP routes ๐ง
A BGP speaker may originate BGP routes by injecting routing information acquired by some other means (e.g., via an IGP) into BGP. A BGP speaker that originates BGP routes assigns the degree of preference (e.g., according to local configuration) to these routes by passing them through the Decision Process (see Section 9.1). These routes MAY also be distributed to other BGP speakers within the local AS as part of the update process (see Section 9.2). Whether to distribute non-BGP acquired routes within an AS via BGP depends on the environment within the AS (e.g., type of IGP) and SHOULD be controlled via configuration. It's giving "it depends" energy ๐
10. BGP Timers โฐ
BGP employs five timers: ConnectRetryTimer (see Section 8), HoldTimer (see Section 4.2), KeepaliveTimer (see Section 8), MinASOriginationIntervalTimer (see Section 9.2.1.2), and MinRouteAdvertisementIntervalTimer (see Section 9.2.1.1). ๐ฐ๏ธ
Two optional timers MAY be supported: DelayOpenTimer, IdleHoldTimer by BGP (see Section 8). Section 8 describes their use. The full operation of these optional timers is outside the scope of this document. ๐ฆ
ConnectRetryTime is a mandatory FSM attribute that stores the initial value for the ConnectRetryTimer. The suggested default value for the ConnectRetryTime is 120 seconds. ๐
HoldTime is a mandatory FSM attribute that stores the initial value for the HoldTimer. The suggested default value for the HoldTime is 90 seconds. ๐ธ
During some portions of the state machine (see Section 8), the HoldTimer is set to a large value. The suggested default for this large value is 4 minutes. ๐
The KeepaliveTime is a mandatory FSM attribute that stores the initial value for the KeepaliveTimer. The suggested default value for the KeepaliveTime is 1/3 of the HoldTime. โจ
The suggested default value for the MinASOriginationIntervalTimer is 15 seconds. ๐
The suggested default value for the MinRouteAdvertisementIntervalTimer on EBGP connections is 30 seconds. ๐ซถ
The suggested default value for the MinRouteAdvertisementIntervalTimer on IBGP connections is 5 seconds. ๐ซถ
An implementation of BGP MUST allow the HoldTimer to be configurable on a per-peer basis, and MAY allow the other timers to be configurable. ๐
To minimize the likelihood that the distribution of BGP messages by a given BGP speaker will contain peaks, jitter SHOULD be applied to the timers associated with MinASOriginationIntervalTimer, KeepaliveTimer, MinRouteAdvertisementIntervalTimer, and ConnectRetryTimer. A given BGP speaker MAY apply the same jitter to each of these quantities, regardless of the destinations to which the updates are being sent. That is, jitter does not need to be configured on a per-peer basis. ๐
The suggested default amount of jitter SHALL be determined by multiplying the base value of the appropriate timer by a random factor, which is uniformly distributed in the range from 0.75 to 1.0. A new random value SHOULD be picked each time the timer is set. The range of the jitter's random value MAY be configurable. ๐ฒ
Appendix A. Comparison with RFC 1771 ๐
There are numerous editorial changes compared to [RFC1771] (way too many to list here). ๐
The following list the technical changes:
- Changes to reflect the usage of features such as TCP MD5 [RFC2385], BGP Route Reflectors [RFC2796], BGP Confederations [RFC3065], and BGP Route Refresh [RFC2918].
- Clarification of the use of the BGP Identifier in the AGGREGATOR attribute.
- Procedures for imposing an upper bound on the number of prefixes that a BGP speaker would accept from a peer.
- The ability of a BGP speaker to include more than one instance of its own AS in the AS_PATH attribute for the purpose of inter-AS traffic engineering.
- Clarification of the various types of NEXT_HOPs.
- Clarification of the use of the ATOMIC_AGGREGATE attribute.
- The relationship between the immediate next hop and the next hop as specified in the NEXT_HOP path attribute.
- Clarification of the tie-breaking procedures.
- Clarification of the frequency of route advertisements.
- Optional Parameter Type 1 (Authentication Information) has been deprecated.
- UPDATE Message Error subcode 7 (AS Routing Loop) has been deprecated.
- OPEN Message Error subcode 5 (Authentication Failure) has been deprecated.
- Use of the Marker field for authentication has been deprecated.
- Implementations MUST support TCP MD5 [RFC2385] for authentication.
- Clarification of BGP FSM.
Okay that's the whole glow-up for this chunk ๐๐
Appendix B. Comparison with RFC 1267 ๐
okay so Appendix B is basically "everything in Appendix A, PLUS these new glow-ups" ๐ โจ
BGP-4 can work in a world where a whole bunch of reachable destinations get squished into one IP prefix ๐ฆ. Classful networks and subnetting are literally not part of BGP-4's vibe ๐
โโ๏ธ. To make that work, BGP-4 changed both the meaning and the encoding of the AS_PATH attribute, and new text was added about what IP prefixes mean ๐ง . All of that is what lets BGP-4 support the proposed supernetting scheme [RFC1518, RFC1519] ๐ฆ.
To make configuration less of a headache ๐ซถ, this version adds a brand-new attribute called LOCAL_PREF, which helps with route selection ๐ฏ.
The INTER_AS_METRIC attribute got a new name: MULTI_EXIT_DISC ๐.
There's also a new ATOMIC_AGGREGATE attribute. Its job is to make sure certain aggregates don't get de-aggregated again ๐
โโ๏ธ๐. Another new one, AGGREGATOR, can be added to aggregated routes so you can see which AS, and which BGP speaker inside that AS, did the aggregating ๐โจ.
Last but not least, Hold Timers now need to be symmetric, so the Hold Timer gets negotiated on a per-connection basis ๐ค. And Hold Timers of zero are now supported too ๐ iconic.
Appendix C. Comparison with RFC 1163 ๐ธ
All of the changes from Appendices A and B are included here too, plus these ๐ซถ.
To detect and recover from a BGP connection collision, a new field (BGP Identifier) got added to the OPEN message ๐ฅ. Section 6.8 is the new text that explains how to detect and recover from collisions ๐ต๏ธโโ๏ธ.
The new document no longer requires that the router passed in the NEXT_HOP path attribute be part of the same Autonomous System as the BGP Speaker ๐. Lowkey a big deal.
It also streamlines and optimizes how information about previously reachable routes gets exchanged ๐.
Appendix D. Comparison with RFC 1105 ๐ฆ
Everything from Appendices A, B, and C is included, plus the stuff below ๐.
Some small tweaks to the [RFC1105] Finite State Machine were needed so it works with the TCP user interface that BSD version 4.3 provides ๐ง.
The Up/Down/Horizontal relationship idea from RFC 1105 has been removed from the protocol, so it's gone ๐๏ธ๐.
Here's how the message format changed from RFC 1105 ๐:
- The Hold Time field moved out of the BGP header and into the OPEN message โฐ.
- The version field moved out of the BGP header and into the OPEN message ๐ข.
- The Link Type field got removed from the OPEN message ๐.
- The OPEN CONFIRM message is gone. Confirmation now happens implicitly through the KEEPALIVE message โจ.
- The UPDATE message format changed a lot. New fields got added to support multiple path attributes ๐ .
- The Marker field got expanded, and its role got broadened so it can support authentication ๐.
Quick naming tea โ: BGP as specified in RFC 1105 is often called BGP-1. BGP as specified in [RFC1163] is BGP-2. BGP as specified in RFC 1267 is BGP-3. And BGP as specified in this document is BGP-4 ๐.
Appendix E. TCP Options that May Be Used with BGP ๐งโโ๏ธ
okay so if a local system's TCP user interface supports the TCP PUSH function, then each BGP message SHOULD be sent with the PUSH flag set ๐. Setting the PUSH flag makes sure BGP messages get delivered to the receiver promptly ๐โโ๏ธ๐จ.
If a local system's TCP user interface can set the DSCP field [RFC2474] on TCP connections, then the TCP connection BGP uses SHOULD be opened with bits 0-2 of the DSCP field set to 110 (binary) ๐.
An implementation MUST support the TCP MD5 option [RFC2385]. This one is non-negotiable bestie ๐๐
Appendix F. Implementation Recommendations ๐ ๏ธ
Here are some implementation recommendations, bestie ๐ โจ.
Appendix F.1. Multiple Networks Per Message ๐ฆ
BGP lets you put several address prefixes that have the same path attributes into one message, and honestly? Using this is highly recommended ๐. If you send one address prefix per message, the receiver's overhead goes way up ๐ฉ. It's not just the extra messages it has to receive: scanning the routing table for updates to BGP peers and other routing protocols (and sending the matching messages) also happens over and over again ๐.
Here's one way to build messages with lots of address prefixes per path attribute set, even when your routing table isn't organized by path attributes ๐งฉ. As you scan the routing table, process each address prefix. Allocate a message for its path attribute set if one doesn't exist yet, and add the prefix to it. If that message already exists, just append the new prefix to it. If the message doesn't have room for the new prefix, send it, allocate a new message, and put the prefix in there. Once the whole table has been scanned, send every allocated message and release its resources ๐. You get the most compression when all the destinations covered by the address prefixes share one set of path attributes, because then you can cram lots of prefixes into a single 4096-byte message ๐.
If you're peering with a BGP implementation that doesn't pack multiple address prefixes into one message, you might need to take steps to cut down the overhead from the flood of data that shows up when a peer comes up or when a big topology change happens ๐ญ. One option is to limit the rate of updates. That gets rid of the repeated table scanning that happens to send flash updates to BGP peers and other routing protocols ๐งน. The downside is that routing information takes longer to propagate โณ. If you pick a minimum flash update interval that's not much bigger than the time it takes to process those multiple messages, that extra latency should stay small โจ. Even better, read all the received messages before you send any updates ๐ง ๐.
Appendix F.2. Reducing Route Flapping ๐ฆ
To avoid excessive route flapping, a BGP speaker that needs to withdraw a destination and also send an update about a more specific or less specific route should bundle them into the same UPDATE message ๐ซถ.
Appendix F.3. Path Attribute Ordering ๐ข
Implementations that combine update messages (as described above in Section 6.1) may prefer seeing all path attributes in a known order ๐ง. That makes it way easier for them to quickly spot sets of attributes from different update messages that are semantically identical ๐. So it's a useful optimization to order the path attributes by type code ๐. This optimization is entirely optional, no pressure ๐.
Appendix F.4. AS_SET Sorting ๐
Another useful optimization that can simplify things is sorting the AS numbers found in an AS_SET ๐๏ธ. This optimization is entirely optional too ๐
.
Appendix F.5. Control Over Version Negotiation ๐๏ธ
Because BGP-4 can carry aggregated routes that can't be properly represented in BGP-3, an implementation that supports BGP-4 and another BGP version should provide the ability to speak only BGP-4 on a per-peer basis ๐ค๐.
Appendix F.6. Complex AS_PATH Aggregation ๐งฎ
If you're writing an implementation that offers a path aggregation algorithm which keeps a lot of path information, you may want to use the procedure below ๐ง ๐.
For aggregating the AS_PATH attributes of two routes, we model each AS as a tuple <type, value>. Here, "type" says what kind of path segment the AS belongs to (for example, AS_SEQUENCE or AS_SET), and "value" is the AS number. Two ASes count as the same if their <type, value> tuples are the same ๐ฏโโ๏ธ.
Here's how to aggregate two AS_PATH attributes ๐ช:
a) Find the same ASes (using the definition above) within each AS_PATH attribute that appear in the same relative order in both AS_PATH attributes. Two ASes, X and Y, are in the same order if either:
- X comes before Y in both
AS_PATHattributes, or - Y comes before X in both
AS_PATHattributes.
b) The aggregated AS_PATH attribute consists of the ASes identified in (a), in exactly the same order they show up in the AS_PATH attributes being aggregated. If two consecutive ASes identified in (a) don't immediately follow each other in both AS_PATH attributes, then the in-between ASes (the ones sitting between those two same ASes) from both attributes get combined into an AS_SET path segment made of those in-between ASes ๐งฉ. That segment gets placed between the two consecutive ASes identified in (a) in the aggregated attribute. If two consecutive ASes identified in (a) immediately follow each other in one attribute but not the other, then the in-between ASes from the other attribute get combined into an AS_SET path segment, which is placed between those same two ASes in the aggregated attribute ๐ธ.
c) For each pair of adjacent tuples in the aggregated AS_PATH, if both tuples have the same type, merge them together, as long as that doesn't create a segment longer than 255 ๐ซ.
If, after all that, a given AS number shows up more than once in the aggregated AS_PATH attribute, then every instance except the last one (the rightmost occurrence) should be removed from the aggregated AS_PATH attribute ๐งนโจ.
Security Considerations ๐
Okay bestie, this is the serious section, so let's get into it ๐ซถ. A BGP implementation MUST support the authentication mechanism from RFC 2385 [RFC2385], and that auth can be set up per-peer ๐.
BGP runs over TCP for reliable delivery between peer routers ๐ฃ๏ธ. To get connection-oriented integrity and data origin authentication on each point-to-point link, BGP uses the RFC 2385 mechanism. Its job is to catch and reject active wiretapping attacks on the router-to-router TCP connections ๐ซ. Without those protections, attackers can knock the TCP connections over or pretend to be a legit peer router ๐. The RFC 2385 mechanism doesn't do peer-entity authentication, though, so replay attacks can still slip past TCP, and that can result in "broken" or "spoofed" BGP messages being handed up from TCP ๐ญ.
RFC 2385 adds a 16-byte message authentication code (MAC) on top of the normal TCP checksum. The MAC is computed over the same data as the checksum ๐งฎ. It's built on the one-way hash function MD5 plus a secret key ๐. The key is shared between the peer routers, and an attacker who doesn't have it can't easily compute the MAC values ๐ โโ๏ธ. A compliant implementation must support this mechanism, and must let a network administrator turn it on per-peer ๐๏ธ.
RFC 2385 doesn't say how to manage the MAC keys (generating, distributing, and replacing them) ๐๏ธ. RFC 3562 [RFC3562] is an informational document that gives some guidance here and explains the reasoning behind it ๐. It says each protected peer should get its own distinct key ๐. If one key gets shared across several peers, the security services can get weaker, because one compromised router can then hurt the others ๐.
The MAC keys should also get changed regularly, so a key compromise or a successful cryptanalytic attack does less damage ๐. RFC 3562 suggests a crypto period (how long a key is in use) of 90 days at most ๐ . Changing keys more often makes replay attacks less likely to work ๐ฏ. But without a standard way to change keys in sync between peers, you can't assume BGP-4 implementations following this RFC will handle frequent key changes ๐คทโโ๏ธ.
Each key should also be hard for an attacker to guess ๐ง . RFC 1750 has techniques for random number generation that help when making key values ๐ฒ. RFC 2385 says implementations should support keys "composed of a string of printable ASCII of 80 bytes or less." ๐ RFC 3562 suggests 12 to 24 bytes of random (pseudo-random) bits instead ๐. That lines up with what analogous MAC algorithms usually use, which is keys in the 16 to 20 byte range โจ. To get enough random bits at the low end of that range, RFC 3562 also points out that a typical ACSII text string would have to be close to the upper bound for key length in RFC 2385 ๐ซ .
BGP vulnerability analysis is covered in [RFC4272] ๐ฆ.
IANA Considerations ๐
Every BGP message has an 8-bit message type ๐. IANA created and maintains a registry for these, called "BGP Message Types" ๐๏ธ. This document defines the following message types:
Name Value Definition
---- ----- ----------
OPEN 1 See Section 4.2
UPDATE 2 See Section 4.3
NOTIFICATION 3 See Section 4.5
KEEPALIVE 4 See Section 4.4
Future assignments go through either the Standards Action process in [RFC2434] or the Early IANA Allocation process in [RFC4020] ๐ฎ. Each assignment is a name and a value ๐ท๏ธ.
BGP UPDATE messages can carry one or more Path Attributes, and each Attribute has an 8-bit Attribute Type Code ๐งฉ. IANA already maintains a registry for these, called "BGP Path Attributes" ๐. This document defines these Path Attribute Type Codes:
Name Value Definition
---- ----- ----------
ORIGIN 1 See Section 5.1.1
AS_PATH 2 See Section 5.1.2
NEXT_HOP 3 See Section 5.1.3
MULTI_EXIT_DISC 4 See Section 5.1.4
LOCAL_PREF 5 See Section 5.1.5
ATOMIC_AGGREGATE 6 See Section 5.1.6
AGGREGATOR 7 See Section 5.1.7
Future assignments go through either the Standards Action process in [RFC2434] or the Early IANA Allocation process in [RFC4020] ๐ฎ. Each assignment is a name and a value ๐ท๏ธ.
The BGP NOTIFICATION message carries an 8-bit Error Code ๐จ. IANA created and maintains a registry for these, called "BGP Error Codes" ๐๏ธ. This document defines these Error Codes:
Name Value Definition
------------ ----- ----------
Message Header Error 1 Section 6.1
OPEN Message Error 2 Section 6.2
UPDATE Message Error 3 Section 6.3
Hold Timer Expired 4 Section 6.5
Finite State Machine Error 5 Section 6.6
Cease 6 Section 6.7
Future assignments go through either the Standards Action process in [RFC2434] or the Early IANA Allocation process in [RFC4020] ๐ฎ. Each assignment is a name and a value ๐ท๏ธ.
The BGP NOTIFICATION message also carries an 8-bit Error Subcode ๐. Each Subcode is defined within the context of one particular Error Code, so it only has to be unique inside that context ๐ซ.
IANA created and maintains a set of registries called "Error Subcodes", with a separate registry for each BGP Error Code ๐. Future assignments go through either the Standards Action process in [RFC2434] or the Early IANA Allocation process in [RFC4020] ๐ฎ. Each assignment is a name and a value ๐ท๏ธ.
This document defines these Message Header Error subcodes:
Name Value Definition
-------------------- ----- ----------
Connection Not Synchronized 1 See Section 6.1
Bad Message Length 2 See Section 6.1
Bad Message Type 3 See Section 6.1
This document defines these OPEN Message Error subcodes:
Name Value Definition
-------------------- ----- ----------
Unsupported Version Number 1 See Section 6.2
Bad Peer AS 2 See Section 6.2
Bad BGP Identifier 3 See Section 6.2
Unsupported Optional Parameter 4 See Section 6.2
[Deprecated] 5 See Appendix A
Unacceptable Hold Time 6 See Section 6.2
This document defines these UPDATE Message Error subcodes:
Name Value Definition
-------------------- --- ----------
Malformed Attribute List 1 See Section 6.3
Unrecognized Well-known Attribute 2 See Section 6.3
Missing Well-known Attribute 3 See Section 6.3
Attribute Flags Error 4 See Section 6.3
Attribute Length Error 5 See Section 6.3
Invalid ORIGIN Attribute 6 See Section 6.3
[Deprecated] 7 See Appendix A
Invalid NEXT_HOP Attribute 8 See Section 6.3
Optional Attribute Error 9 See Section 6.3
Invalid Network Field 10 See Section 6.3
Malformed AS_PATH 11 See Section 6.3
Normative References ๐
- [RFC791] Postel, J., "Internet Protocol", STD 5, RFC 791, September 1981. ๐
- [RFC793] Postel, J., "Transmission Control Protocol", STD 7, RFC 793, September 1981. ๐
- [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997. ๐
- [RFC2385] Heffernan, A., "Protection of BGP Sessions via the TCP MD5 Signature Option", RFC 2385, August 1998. ๐ก๏ธ
- [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 2434, October 1998. ๐งญ
Informative References ๐โจ
okay bestie, these are the receipts ๐งพ every source this spec leaned on, so if you ever want to go deeper, this is your reading list ๐
- [RFC904] Mills, D., "Exterior Gateway Protocol formal specification", RFC 904, April 1984.
- [RFC1092] Rekhter, J., "EGP and policy based routing in the new NSFNET backbone", RFC 1092, February 1989.
- [RFC1093] Braun, H., "NSFNET routing architecture", RFC 1093, February 1989.
- [RFC1105] Lougheed, K. and Y. Rekhter, "Border Gateway Protocol (BGP)", RFC 1105, June 1989.
- [RFC1163] Lougheed, K. and Y. Rekhter, "Border Gateway Protocol (BGP)", RFC 1163, June 1990.
- [RFC1267] Lougheed, K. and Y. Rekhter, "Border Gateway Protocol 3 (BGP-3)", RFC 1267, October 1991.
- [RFC1771] Rekhter, Y. and T. Li, "A Border Gateway Protocol 4 (BGP-4)", RFC 1771, March 1995.
- [RFC1772] Rekhter, Y. and P. Gross, "Application of the Border Gateway Protocol in the Internet", RFC 1772, March 1995.
- [RFC1518] Rekhter, Y. and T. Li, "An Architecture for IP Address Allocation with CIDR", RFC 1518, September 1993.
- [RFC1519] Fuller, V., Li, T., Yu, J., and K. Varadhan, "Classless Inter-Domain Routing (CIDR): an Address Assignment and Aggregation Strategy", RFC 1519, September 1993.
- [RFC1930] Hawkinson, J. and T. Bates, "Guidelines for creation, selection, and registration of an Autonomous System (AS)", BCP 6, RFC 1930, March 1996.
- [RFC1997] Chandra, R., Traina, P., and T. Li, "BGP Communities Attribute", RFC 1997, August 1996.
- [RFC2439] Villamizar, C., Chandra, R., and R. Govindan, "BGP Route Flap Damping", RFC 2439, November 1998.
- [RFC2474] Nichols, K., Blake, S., Baker, F., and D. Black, "Definition of the Differentiated Services Field (DS Field) in the IPv4 and IPv6 Headers", RFC 2474, December 1998.
- [RFC2796] Bates, T., Chandra, R., and E. Chen, "BGP Route Reflection - An Alternative to Full Mesh IBGP", RFC 2796, April 2000.
- [RFC2858] Bates, T., Rekhter, Y., Chandra, R., and D. Katz, "Multiprotocol Extensions for BGP-4", RFC 2858, June 2000.
- [RFC3392] Chandra, R. and J. Scudder, "Capabilities Advertisement with BGP-4", RFC 3392, November 2002.
- [RFC2918] Chen, E., "Route Refresh Capability for BGP-4", RFC 2918, September 2000.
- [RFC3065] Traina, P., McPherson, D., and J. Scudder, "Autonomous System Confederations for BGP", RFC 3065, February 2001.
- [RFC3562] Leech, M., "Key Management Considerations for the TCP MD5 Signature Option", RFC 3562, July 2003.
- [IS10747] "Information Processing Systems - Telecommunications and Information Exchange between Systems - Protocol for Exchange of Inter-domain Routeing Information among Intermediate Systems to Support Forwarding of ISO 8473 PDUs", ISO/IEC IS10747, 1993.
- [RFC4272] Murphy, S., "BGP Security Vulnerabilities Analysis", RFC 4272, January 2006
- [RFC4020] Kompella, K. and A. Zinin, "Early IANA Allocation of Standards Track Code Points", BCP 100, RFC 4020, February 2005.
Editors' Addresses ๐
these are the people who wrangled the whole thing into shape ๐ซถ here's how to reach them:
Yakov Rekhter
Juniper Networks
EMail: yakov@juniper.net
Tony Li
EMail: tony.li@tony.li
Susan Hares
NextHop Technologies, Inc.
825 Victors Way
Ann Arbor, MI 48108
Phone: (734)222-1610
EMail: skh@nexthop.com
Full Copyright Statement โ๏ธ
Copyright (C) The Internet Society (2006). ๐ธ
this doc is covered by the rights, licenses and restrictions in BCP 78, and apart from what that says, the authors keep all their rights ๐
Heads up, bestie: the doc and everything in it is provided "AS IS" ๐ THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ๐
Intellectual Property ๐ฆ
the IETF doesn't take a side on whether any IPR (patents, copyrights, that whole legal vibe) covering this tech is valid or how far it reaches, and it doesn't say whether licenses are available either ๐ it also hasn't gone hunting for every possible right, so don't assume it did ๐ the rules for rights in RFC docs live in BCP 78 and BCP 79 ๐
copies of IPR disclosures sent to the IETF Secretariat, plus any promised licenses, or the results of trying to get a general license for implementers or users, can be found in the IETF online IPR repository at http://www.ietf.org/ipr โจ
the IETF also invites anyone who knows about copyrights, patents, patent applications, or other proprietary rights that might cover tech needed to implement this standard to tell them about it at ietf-ipr@ietf.org ๐ซถ
Acknowledgement ๐
funding for the RFC Editor function comes from the IETF Administrative Support Activity (IASA) ๐ thank you, IASA, you're iconic ๐
and that's the whole spec, bestie! ๐งโจ๐
๐ฆ where this page comes from
- ietf: rfc4271 2006-01
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms