RFC 1163
Border Gateway Protocol (BGP)
A Border Gateway Protocol (BGP) ๐ฆ
RFC 1163: A Border Gateway Protocol (BGP) โจ (Part 1 of 6)
okay bestie, this one is the BGP spec from June 1990 ๐ It was written by K. Lougheed (cisco Systems) and Y. Rekhter (T.J. Watson Research Center, IBM Corp). It's a Proposed Standard, meant to go with its companion RFC-1164, "Application of the Border Gateway Protocol in the Internet". It obsoletes RFC 1105 ๐
Status of This Memo ๐
So this RFC and its companion RFC-1164 together define a Proposed Standard for an inter-autonomous system routing protocol for the Internet ๐
BGP is at an early stage, so it may still change before it becomes a full Internet Standard, based on what people learn from deploying it. Implementers are encouraged to keep an eye on this protocol (or any protocol) as it moves through standardization, and to share their own experience with it ๐ซถ
The protocol is being looked at by the Interconnectivity Working Group (IWG) of the Internet Engineering Task Force (IETF). You can follow BGP's progress or report on it through the IWG mailing list, which is IWG@nri.reston.va.us ๐
For the current status of standard Internet protocols, check the latest edition of the "IAB Official Protocol Standards" RFC ๐
Distribution of this memo is unlimited ๐ฆ
Table of Contents ๐๏ธ
1. Acknowledgements...................................... 2
2. Introduction.......................................... 2
3. Summary of Operation.................................. 4
4. Message Formats....................................... 5
4.1 Message Header Format................................. 5
4.2 OPEN Message Format................................... 6
4.3 UPDATE Message Format................................. 8
4.4 KEEPALIVE Message Format.............................. 10
4.5 NOTIFICATION Message Format........................... 10
5. Path Attributes....................................... 12
6. BGP Error Handling.................................... 14
6.1 Message Header error handling......................... 14
6.2 OPEN message error handling........................... 15
6.3 UPDATE message error handling......................... 16
6.4 NOTIFICATION message error handling................... 17
6.5 Hold Timer Expired error handling..................... 17
6.6 Finite State Machine error handling................... 18
6.7 Cease................................................. 18
7. BGP Version Negotiation............................... 18
8. BGP Finite State machine.............................. 18
9. UPDATE Message Handling............................... 22
10. Detection of Inter-AS Policy Contradictions........... 23
Appendix 1. BGP FSM State Transitions and Actions........ 25
Appendix 2. Comparison with RFC 1105..................... 28
Appendix 3. TCP options that may be used with BGP........ 28
References................................................ 29
Security Considerations................................... 29
Authors' Addresses........................................ 29
1. Acknowledgements โจ
Big thank-yous to Guy Almes (Rice University), Len Bosack (cisco Systems), and Jeffrey C. Honig (Cornell Theory Center) ๐ซถ Thanks also to everyone in the Interconnectivity Working Group of the Internet Engineering Task Force, which Guy Almes chaired, for their contributions to this document ๐
We'd also like to thank Bob Hinden, Director for Routing of the Internet Engineering Steering Group, along with the team of reviewers he pulled together to look at earlier versions of this document ๐ 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 iconic ๐
2. Introduction ๐ธ
So BGP is an inter-Autonomous System routing protocol ๐ It's built on what people learned from EGP, as defined in RFC 904 [1], and from EGP usage in the NSFNET Backbone, described in RFC 1092 [2] and RFC 1093 [3].
The main job of a BGP speaking system is to swap network reachability information with other BGP systems ๐ฆ That information includes the full path of Autonomous Systems (ASs) that traffic has to go through to reach those networks. It's enough to build a graph of AS connectivity, which lets you prune routing loops and enforce some AS-level policy decisions. Main character energy, ngl โจ
Now, to figure out which policies BGP can enforce, you have to look at one big rule: an AS only advertises to its neighbor ASs the routes it actually uses itself ๐ง This rule matches the "hop-by-hop" routing paradigm that the current Internet mostly runs on. Some policies can't work with hop-by-hop routing, so they need techniques like source routing to enforce. For example, BGP doesn't let one AS send traffic to a neighbor AS and have that traffic take a different route than traffic that started in the neighbor AS ๐ BUT, and this is the good part, BGP can support any policy that fits the hop-by-hop paradigm. Since the Internet only uses hop-by-hop routing, and BGP handles everything that fits it, BGP is a super fitting choice as an inter-AS routing protocol for today's Internet ๐ฅ
A fuller discussion of which policies can and can't be enforced with BGP is outside the scope of this document. If you want the deeper dive, check out the companion document about BGP usage [5] ๐
Here's the transport situation: BGP runs over a reliable transport protocol ๐ That means nobody has to write explicit update fragmentation, retransmission, acknowledgement, or sequencing, which is a relief. Any authentication scheme the transport protocol uses can be used on top of BGP's own authentication mechanisms too. The error notification mechanism in BGP assumes that the transport protocol supports a "graceful" close, meaning that all outstanding data gets delivered before the connection is closed ๐
BGP uses TCP [4] as its transport protocol ๐ TCP meets BGP's transport requirements and shows up in basically every commercial router and host. In these descriptions, "transport protocol connection" just means a TCP connection. BGP uses TCP port 179 to set up its connections ๐ฆ
This memo uses the term "Autonomous System" (AS) all the way through ๐ซถ The classic definition is a set of routers under one technical administration, using an interior gateway protocol and common metrics to route packets inside the AS, and an exterior gateway protocol to route packets to other ASs ๐ Since that definition was written, it's become common for one AS to run several interior gateway protocols, and sometimes several sets of metrics inside it. The way this memo uses the term stresses that, even with multiple IGPs and metrics, the administration of an AS still looks to other ASs like it has one coherent interior routing plan and gives a consistent picture of which networks are reachable through it โจ From the standpoint of exterior routing, an AS can be treated as monolithic: reachability to networks directly connected to the AS has to be the same from every border gateway of the AS ๐
The planned use of BGP in the Internet environment, covering things like topology, how BGP and IGPs interact, and how routing policy rules get enforced, is in a companion document [5] ๐ง This document is the first of a series planned to explore different aspects of BGP application ๐
3. Summary of Operation ๐ง
Two systems form a transport protocol connection between each other ๐ฆ They exchange messages to open the connection and confirm its parameters. The initial data flow is the entire BGP routing table. After that, incremental updates get sent whenever the routing tables change. BGP doesn't need a periodic refresh of the entire BGP routing table, so a BGP speaker has to keep the current version of the entire BGP routing tables of all its peers for as long as the connection lasts ๐ KeepAlive messages go out periodically to make sure the connection is still alive ๐ Notification messages are sent in response to errors or special conditions. If a connection runs into an error condition, a notification message is sent and the connection gets closed ๐
The hosts running the Border Gateway Protocol don't have to be routers ๐ธ A non-routing host could swap routing information with routers using EGP, or even an interior routing protocol. That non-routing host could then use BGP to swap routing information with a border router in another Autonomous System. The implications and applications of this setup are left for further study ๐
Now, if a particular AS has several BGP speakers and provides transit service for other ASs, you have to be careful to keep a consistent view of routing inside the AS โ ๏ธ The interior routing protocol gives a consistent view of the AS's interior routes. A consistent view of the routes exterior to the AS can come from having all the BGP speakers inside the AS keep direct BGP connections with each other ๐ซถ Using a common set of policies, the BGP speakers agree on which border routers will serve as exit/entry points for particular networks outside the AS. That info gets passed to the AS's internal routers, possibly through the interior routing protocol. You also have to make sure the interior routers have all been updated with transit information before the BGP speakers tell other ASs that transit service is being provided ๐
Connections between BGP speakers in different ASs are called "external" links ๐ BGP connections between BGP speakers in the same AS are called "internal" links ๐ฆ
4. Message Formats ๐
This section describes the message formats BGP uses ๐
Messages get sent over a reliable transport protocol connection ๐ A message only gets processed after it has been entirely received. The maximum message size is 4096 octets, and all implementations are required to support this maximum message size ๐ The smallest message that may be sent is just a BGP header with no data portion, which is 19 octets ๐ง
4.1 Message Header Format ๐
okay bestie, every message starts with a fixed-size header ๐ Depending on the message type, there may or may not be a data portion after it โจ Here's the layout:
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 is a 16-octet field ๐ฆ It holds a value that the receiver of the message can predict. If the Type of the message is OPEN, or if the Authentication Code used in the OPEN message of the connection is zero, then the Marker must be all ones ๐ Otherwise, the value of the Marker can be predicted by some computation specified as part of the authentication mechanism being used. The Marker can be used to detect loss of synchronization between a pair of BGP peers, and to authenticate incoming BGP messages ๐
Length:
This is a 2-octet unsigned integer that tells you the total length of the message, including the header, in octets ๐ Thus, e.g., it lets you locate the (Marker field of the) next message in the transport-level stream. The value of the Length field must always be at least 19 and no greater than 4096, and it may be further constrained depending on the message type. No "padding" of extra data after the message is allowed, so the Length field must have the smallest value required given the rest of the message ๐
Type:
This is a 1-octet unsigned integer that indicates the type code of the message. The following type codes are defined:
1 - OPEN
2 - UPDATE
3 - NOTIFICATION
4 - KEEPALIVE
4.2 OPEN Message Format ๐ธ
After a transport protocol connection is established, the first message sent by each side is an OPEN message ๐ฆ If the OPEN message is acceptable, a KEEPALIVE message confirming the OPEN is sent back. Once the OPEN is confirmed, UPDATE, KEEPALIVE, and NOTIFICATION messages may be exchanged โจ
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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Auth. Code |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Authentication Data |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Version:
This is a 1-octet unsigned integer that indicates the protocol version number of the message. The current BGP version number is 2 ๐
My Autonomous System:
This is a 2-octet unsigned integer that indicates the Autonomous System number of the sender ๐ง
Hold Time:
This is a 2-octet unsigned integer that indicates the maximum number of seconds that may elapse between the receipt of successive KEEPALIVE and/or UPDATE and/or NOTIFICATION messages โณ
Authentication Code:
This is a 1-octet unsigned integer that indicates the authentication mechanism being used. Whenever an authentication mechanism is specified for use within BGP, three things must be included in the specification:
- the value of the Authentication Code which indicates use of the mechanism,
- the form and meaning of the Authentication Data, and
- the algorithm for computing values of Marker fields.
Only one authentication mechanism is specified as part of this memo:
- its Authentication Code is zero,
- its Authentication Data must be empty (of zero length), and
- the Marker fields of all messages must be all ones.
The semantics of non-zero Authentication Codes lies outside the scope of this memo. Note that a separate authentication mechanism may be used in establishing the transport level connection ๐
Authentication Data:
The form and meaning of this field is a variable-length field depend on the Authentication Code. If the value of the Authentication Code field is zero, the Authentication Data field must have zero length. The semantics of the non-zero length Authentication Data field is outside the scope of this memo.
Note that the length of the Authentication Data field can be determined from the message Length field by the formula:
Message Length = 25 + Authentication Data Length
The minimum length of the OPEN message is 25 octets (including message header) ๐
4.3 UPDATE Message Format ๐ฆ
UPDATE messages are used to transfer routing information between BGP peers ๐ The information in the UPDATE packet can be used to construct a graph describing 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. Iconic behaviour ๐
In addition to the fixed-size BGP header, the UPDATE message contains the following fields (note that all fields may have arbitrary alignment):
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Total Path Attributes Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Path Attributes /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Network n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Total Path Attribute Length:
This is a 2-octet unsigned integer that indicates the total length of the Path Attributes field in octets. Its value must allow the (non-negative integer) number of Network fields to be determined as specified below ๐งฎ
Path Attributes:
A variable-length sequence of path attributes is present in every UPDATE โจ Each path attribute is a triple <attribute type, attribute length, attribute value> of variable length.
Attribute Type is a two-octet field that consists 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|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The high-order bit (bit 0) of the Attribute Flags octet is the Optional bit ๐ฏ It defines whether the attribute is optional (if set to 1) or well-known (if set to 0).
The second high-order bit (bit 1) of the Attribute Flags octet is the Transitive bit ๐ It defines whether an optional attribute is transitive (if set to 1) or non-transitive (if set to 0). For well-known attributes, the Transitive bit must be set to 1. (See Section 5 for a discussion of transitive attributes.)
The third high-order bit (bit 2) of the Attribute Flags octet is the Partial bit ๐งฉ It defines whether the information contained in the optional transitive attribute is partial (if set to 1) or complete (if 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) of the Attribute Flags octet is the Extended Length bit ๐ It defines whether the Attribute Length is one octet (if set to 0) or two octets (if set to 1). Extended Length may be used only if the length of the attribute value is greater than 255 octets.
The lower-order four bits of the Attribute Flags octet are unused. They must be zero (and should be ignored when received).
The Attribute Type Code octet contains the Attribute Type Code. Currently defined Attribute Type Codes are discussed in Section 5 ๐
If the Extended Length bit of the Attribute Flags octet is set to 0, the third octet of the Path Attribute contains the length of the attribute data in octets.
If the Extended Length bit of the Attribute Flags octet is set to 1, then the third and the fourth octets of the Path Attribute contain the length of the attribute data in octets.
The remaining octets of the Path Attribute represent the attribute value and are interpreted according to the Attribute Flags and the Attribute Type Code.
The meaning and handling of Path Attributes is discussed in Section 5 ๐
Network:
Each 4-octet Internet network number indicates one network whose Inter-Autonomous System routing is described by the Path Attributes. Subnets and host addresses are specifically not allowed ๐ซ The total number of Network fields in the UPDATE message can be determined by the formula:
Message Length = 19 + Total Path Attribute Length + 4 * #Nets
The message Length field of the message header and the Path Attributes Length field of the UPDATE message must be such that the formula results in a non-negative integer number of Network fields.
The minimum length of the UPDATE message is 37 octets (including message header) ๐ท
4.4 KEEPALIVE Message Format ๐ซถ
BGP does not use any transport protocol-based keep-alive mechanism to determine if peers are reachable ๐ Instead, KEEPALIVE messages are exchanged between peers often enough not to cause the hold time (as advertised in the OPEN message) to expire. A reasonable maximum time between KEEPALIVE messages would be one third of the Hold Time interval โฐ
A KEEPALIVE message consists of only the message header and has a length of 19 octets ๐ญ
4.5 NOTIFICATION Message Format โจ
Okay bestie, the NOTIFICATION message is the "something went WRONG ๐จ" message ๐. It gets sent whenever an error condition is detected, and the BGP connection gets closed immediately after. No dramatic goodbye, just bye ๐
In addition to 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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Error Code
This 1-octet unsigned integer tells you the type of NOTIFICATION. These are the Error Codes that have been 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 you more specific info about the nature of the error โจ. Each Error Code may have one or more Error Subcodes attached to it. If no appropriate Error Subcode is defined, then a zero (Unspecific) value is used for the Error Subcode field ๐ซถ.
Message Header Error subcodes:
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 - Unsupported Authentication Code.
4 - Authentication Failure.
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 - AS Routing Loop.
8 - Invalid NEXT_HOP Attribute.
9 - Optional Attribute Error.
10 - Invalid Network Field.
Data
This variable-length field is used to diagnose the reason for the NOTIFICATION. Its contents depend on the Error Code and Error Subcode, so check out Section 6 below for the full tea ๐ต.
Also, the length of the Data field can be worked out from the message Length field with this formula:
Message Length = 21 + Data Length
The minimum length of the NOTIFICATION message is 21 octets (including message header). Iconic ๐ธ.
5. Path Attributes ๐
This section is all about the path attributes of the UPDATE message, so let's gooo ๐.
Path attributes fall into four separate categories:
- Well-known mandatory.
- Well-known discretionary.
- Optional transitive.
- Optional non-transitive.
Well-known attributes must be recognized by all BGP implementations. Some of them are mandatory and must be included in every UPDATE message. Others are discretionary, which means they may or may not show up in a particular UPDATE message. The table below shows which well-known attributes are mandatory and which are discretionary ๐ฆ.
All well-known attributes must be passed along (after proper updating, if necessary) to other BGP peers.
In addition to well-known attributes, each path may contain one or more optional attributes. It is not required or expected that all BGP implementations support all optional attributes. How an unrecognized optional attribute gets handled depends on the setting of the Transitive bit in the attribute flags octet. Unrecognized transitive optional attributes should be accepted and passed along to other BGP peers. If a path with an unrecognized transitive optional attribute is accepted and passed along to other BGP peers, the Partial bit in the Attribute Flags octet is 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, then the current AS does not set it back to 0. Unrecognized non-transitive optional attributes should 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 AS in the path. If they are not 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 nature of the specific attribute, and the documentation of each new non-transitive optional attribute is expected to include those rules. (The description of the INTER-AS METRIC attribute gives an example.) All optional attributes, both transitive and non-transitive, may be updated (if appropriate) by ASs in the path.
The order of attributes within the Path Attributes field of a particular UPDATE message is irrelevant, so no stressing about order ๐.
The same attribute cannot appear more than once within the Path Attributes field of a particular UPDATE message.
Here's the table that gives the attribute type code, attribute length, and attribute category for the path attributes defined in this document ๐:
Attribute Name Type Code Length Attribute category
ORIGIN 1 1 well-known, mandatory
AS_PATH 2 variable well-known, mandatory
NEXT_HOP 3 4 well-known, mandatory
UNREACHABLE 4 0 well-known, discretionary
INTER-AS METRIC 5 2 optional, non-transitive
ORIGIN
The ORIGIN path attribute defines the origin of the path information. Its data octet can take on these values:
Value Meaning
0 IGP - network(s) are interior to the originating AS
1 EGP - network(s) learned via EGP
2 INCOMPLETE - network(s) learned by some other means
AS_PATH
The AS_PATH attribute lists the ASs that have to be traversed to reach the networks in the UPDATE message ๐ง. Since an AS identifier is 2 octets, the length of an AS_PATH attribute is twice the number of ASs in the path. Rules for constructing an AS_PATH attribute are discussed in Section 9.
NEXT_HOP
The NEXT_HOP path attribute defines the IP address of the border router that should be used as the next hop to the networks listed in the UPDATE message. This border router must belong to the same AS as the BGP peer that advertises it. Main character energy ๐.
UNREACHABLE
The UNREACHABLE attribute is used to tell a BGP peer that some of the routes it was previously sent have become unreachable ๐.
INTER-AS METRIC
The INTER-AS METRIC attribute may be used on external (inter-AS) links to tell apart multiple exit or entry points to the same neighboring AS โญ. Its value is a 2-octet unsigned number, which is called a metric. All other factors being equal, the exit or entry point with the lower metric should be preferred. If it's received over external links, the INTER-AS METRIC attribute may be propagated over internal links to other BGP speakers within the same AS. It is never propagated to BGP speakers in neighboring AS's, so it stays home ๐ .
6. BGP Error Handling โจ
This section describes the actions to be taken when errors are detected while processing BGP messages. It's the emergency protocol ๐จ.
When any of the conditions described here are detected, a NOTIFICATION message with the indicated Error Code, Error Subcode, and Data fields is sent, and the BGP connection is closed. If no Error Subcode is specified, then a zero should be used.
The phrase "the BGP connection is closed" means that the transport protocol connection has been closed and that all resources for that BGP connection have been deallocated. Routing table entries associated with the remote peer are marked as invalid. The fact that the routes have become invalid is passed to other BGP peers before the routes are deleted from the system ๐.
Unless it's specified explicitly, the Data field of the NOTIFICATION message that is sent to indicate an error is empty.
6.1 Message Header error handling. ๐ซถ
All errors detected while processing the Message Header are indicated by sending a NOTIFICATION message with Error Code Message Header Error. The Error Subcode gets into the specifics of what went wrong.
The expected value of the Marker field of the message header is all ones if the message type is OPEN. The expected value of the Marker field for all other types of BGP messages is determined based on the Authentication Code in the BGP OPEN message and the actual authentication mechanism (if the Authentication Code in the BGP OPEN message is non-zero). If the Marker field of the message header is not the expected one, then a synchronization error has occurred and the Error Subcode is set to Connection Not Synchronized ๐ฅ.
If the Length field of the message header is less than 19 or greater than 4096, or if the Length field of an OPEN message is less than the minimum length of the OPEN message, or if the Length field of an UPDATE message is less than the minimum length of the UPDATE message, or if the Length field of a KEEPALIVE message is not equal to 19, or if the Length field of a NOTIFICATION message is less than the minimum length of the NOTIFICATION message, then the Error Subcode is set to Bad Message Length. The Data field contains the erroneous Length field ๐.
If the Type field of the message header is not recognized, then the Error Subcode is set to Bad Message Type. The Data field contains the erroneous Type field ๐.
6.2. OPEN message error handling โจ
okay so, every error we catch while processing an OPEN message gets reported by sending a NOTIFICATION message with Error Code OPEN Message Error ๐. The Error Subcode is what spills the tea on exactly what went wrong ๐ต๏ธโโ๏ธ.
If the version number in the Version field of the received OPEN message isn't supported, the Error Subcode gets set to Unsupported Version Number. The Data field is a 2-octet unsigned integer, and it tells the peer 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 Autonomous System field of the OPEN message is unacceptable, the Error Subcode is set to Bad Peer AS. Deciding which Autonomous System numbers are acceptable is outside the scope of this protocol, so that one isn't on this doc ๐
โโ๏ธ.
If the Authentication Code of the OPEN message isn't recognized, the Error Subcode is set to Unsupported Authentication Code ๐.
If the Authentication Code is zero, then the Authentication Data must be of zero length. Otherwise, the Error Subcode is set to Authentication Failure.
If the Authentication Code is non-zero, then the matching authentication procedure gets invoked. If that procedure (based on Authentication Code and Authentication Data) fails, the Error Subcode is set to Authentication Failure ๐ญ.
6.3. UPDATE message error handling โจ
All errors found while processing the UPDATE message get reported by sending a NOTIFICATION message with Error Code UPDATE Message Error. The error subcode is the part that tells you the specific problem ๐.
Error checking for an UPDATE message starts with the path attributes ๐ง. If the Total Attribute Length is too large (i.e., if Total Attribute Length + 21 exceeds the message Length), or if the (non-negative integer) Number of Network fields cannot be computed as in Section 4.3, then the Error Subcode is set to Malformed Attribute List ๐.
If any recognized attribute has Attribute Flags that conflict with the Attribute Type Code, the Error Subcode is set to Attribute Flags Error. The Data field contains the erroneous attribute (type, length and value).
If any recognized attribute has Attribute Length that conflicts with the expected length (based on the attribute type code), the Error Subcode is set to Attribute Length Error. The Data field contains the erroneous attribute (type, length and value).
If any of the mandatory well-known attributes are not present, the Error Subcode is set to Missing Well-known Attribute. The Data field contains the Attribute Type Code of the missing well-known attribute.
If any of the mandatory well-known attributes are not recognized, the Error Subcode is set to Unrecognized Well-known Attribute. The Data field contains the unrecognized attribute (type, length and value).
If the ORIGIN attribute has an undefined value, the Error Subcode is set to Invalid Origin Attribute. The Data field contains the unrecognized attribute (type, length and value).
If the NEXT_HOP attribute field is syntactically incorrect, the Error Subcode is set to Invalid NEXT_HOP Attribute. The Data field contains the incorrect attribute (type, length and value). Syntactic correctness means that the NEXT_HOP attribute represents a valid IP host address ๐.
The AS route specified by the AS_PATH attribute gets checked for AS loops ๐. AS loop detection is done by scanning the full AS route (as specified in the AS_PATH attribute) and checking that each AS occurs at most once. If a loop is detected, the Error Subcode is set to AS Routing Loop. The Data field contains the incorrect attribute (type, length and value).
If an optional attribute is recognized, then its value gets checked. If an error is detected, the attribute is discarded, and the Error Subcode is set to Optional Attribute Error. The Data field contains the attribute (type, length and value).
If any attribute appears more than once in the UPDATE message, the Error Subcode is set to Malformed Attribute List ๐.
Each Network field in the UPDATE message gets checked for syntactic validity. If the Network field is syntactically incorrect, or contains a subnet or a host address, the Error Subcode is set to Invalid Network Field ๐ซ.
6.4. NOTIFICATION message error handling โจ
If a peer sends a NOTIFICATION message and there's an error in that message, sadly there's no way to report that error with a follow-up NOTIFICATION message ๐ญ. Any such error, like an unrecognized Error Code or Error Subcode, should be noticed, logged locally, and brought to the attention of the administration of the peer. How to do that part, though, lies outside the scope of this document ๐ง.
6.5. Hold Timer Expired error handling โจ
If a system doesn't receive successive KEEPALIVE and/or UPDATE and/or NOTIFICATION messages within the period specified in the Hold Time field of the OPEN message, then the NOTIFICATION message with Hold Timer Expired Error Code should be sent and the BGP connection 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 Error Code Finite State Machine Error ๐ข.
6.7. Cease โจ
If there are no fatal errors (the ones indicated in this section), a BGP peer may choose at any given time to close its BGP connection by sending the NOTIFICATION message with Error Code Cease. However, the Cease NOTIFICATION message should not be used when a fatal error indicated by this section does exist. ๐
7. BGP Version Negotiation โจ
BGP speakers may negotiate the version of the protocol by making multiple attempts to open a BGP connection, starting with the highest version number each supports. If an open attempt fails with an Error Code OPEN Message Error, and an Error Subcode Unsupported Version Number, then the BGP speaker has available the version number it tried, the version number its peer tried, the version number passed by its peer in the NOTIFICATION message, and the version numbers that it supports. If the two peers do support one or more common versions, then this will allow them to rapidly determine the highest common version. ๐ฆ
In order to support BGP version negotiation, future versions of BGP must retain the format of the OPEN and NOTIFICATION messages ๐.
8. BGP Finite State machine โจ
okay so this section is where BGP's state machine lives, and it is giving organized ๐ It gives a quick summary of how BGP behaves in each state. A condensed version is in Appendix 1 ๐
BGP starts out in the Idle state ๐ธ
Idle state:
In this state BGP refuses all incoming BGP connections. No resources get allocated to the BGP neighbor ๐ When a Start event shows up (from either system or the operator), the local system initializes all BGP resources, starts the ConnectRetry timer, starts a transport connection to the other BGP peer while it listens for a connection the remote BGP peer might start, and changes its state to Connect ๐ง
The exact value of the ConnectRetry timer is a local matter, but it should be big enough to give TCP time to initialize ๐ฆ
Any other event that shows up in Idle gets ignored ๐ค
Connect state:
In this state BGP is waiting for the transport protocol connection to finish โณ
If the transport protocol connection succeeds, the local system clears the ConnectRetry timer, finishes initialization, sends an OPEN message to its peer, and changes its state to OpenSent โจ
If the transport protocol connect fails (e.g., retransmission timeout), the local system restarts the ConnectRetry timer, keeps listening for a connection the remote BGP peer might start, and changes its state to Active ๐ฅบ
When the ConnectRetry timer expires, the local system restarts the ConnectRetry timer, starts a transport connection to the other BGP peer, keeps listening for a connection the remote BGP peer might start, and stays in Connect ๐
Start event is ignored in the Active state.
For any other event (from either system or the operator), the local system releases all BGP resources tied to this connection and changes its state to Idle ๐งน
Active state:
In this state BGP is trying to find a BGP neighbor by starting a transport protocol connection ๐
If the transport protocol connection succeeds, the local system clears the ConnectRetry timer, finishes initialization, sends an OPEN message to its peer, sets its hold timer to a large value, and changes its state to OpenSent ๐
When the ConnectRetry timer expires, the local system restarts the ConnectRetry timer, starts a transport connection to the other BGP peer, keeps listening for a connection the remote BGP peer might start, and changes its state to Connect โจ
If the local system notices that a remote peer is trying to set up a BGP connection with it, and the IP address of that remote peer isn't one it expects, the local system restarts the ConnectRetry timer, rejects the attempted connection, keeps listening for a connection the remote BGP peer might start, and stays in Active ๐ซ
Start event is ignored in the Active state.
For any other event (from either system or the operator), the local system releases all BGP resources tied to this connection and changes its state to Idle ๐งน
OpenSent state:
In this state BGP waits for an OPEN message from its peer. When one arrives, all of its fields get checked for correctness ๐ If the BGP message header checking or the OPEN message checking finds an error (see Section 6), the local system sends a NOTIFICATION message and changes its state to Idle ๐
If there are no errors in the OPEN message, BGP sends a KEEPALIVE message and sets a KeepAlive timer. The hold timer, which was first set to an arbitrary large value (see above), gets replaced with the value from the OPEN message โฐ If the value of the Autonomous System field is the same as our own, then the connection is "internal" connection. Otherwise, it's "external". (This will affect UPDATE processing as described below ๐) Finally, the state changes to OpenConfirm ๐
If a disconnect notification comes in from the underlying transport protocol, the local system closes the BGP connection, restarts the ConnectRetry timer, keeps listening for a connection the remote BGP peer might start, and goes into the Active state ๐
If the hold time expires, the local system sends a NOTIFICATION message with error code Hold Timer Expired and changes its state to Idle โ
For the Stop event (from either system or the operator), the local system sends a NOTIFICATION message with Error Code Cease and changes its state to Idle ๐
Start event is ignored in the OpenSent state.
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and changes its state to Idle ๐ฌ
Whenever BGP changes its state from OpenSent to Idle, it closes the BGP (and transport-level) connection and releases all resources tied to that connection ๐งน
OpenConfirm state:
In this state BGP waits for a KEEPALIVE or NOTIFICATION message ๐
If the local system gets a KEEPALIVE message, it changes its state to Established ๐ฅณ
If the hold timer expires before a KEEPALIVE message arrives, the local system sends a NOTIFICATION message with error code Hold Timer expired and changes its state to Idle โฐ
If the local system gets a NOTIFICATION message, it changes its state to Idle ๐
If the KeepAlive timer expires, the local system sends a KEEPALIVE message and restarts its KeepAlive timer ๐
If a disconnect notification comes in from the underlying transport protocol, the local system changes its state to Idle ๐
For the Stop event (from either system or the operator), the local system sends a NOTIFICATION message with Error Code Cease and changes its state to Idle ๐
Start event is ignored in the OpenConfirm state.
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and changes its state to Idle ๐ฌ
Whenever BGP changes its state from OpenConfirm to Idle, it closes the BGP (and transport-level) connection and releases all resources tied to that connection ๐งน
Established state:
In the Established state BGP can swap UPDATE, NOTIFICATION, and KEEPALIVE messages with its peer ๐ค
If the local system gets an UPDATE or KEEPALIVE message, it restarts its Holdtime timer ๐
If the local system gets a NOTIFICATION message, it changes its state to Idle ๐
If the local system gets an UPDATE message and the UPDATE message error handling procedure (see Section 6.3) finds an error, the local system sends a NOTIFICATION message and changes its state to Idle ๐จ
If a disconnect notification comes in from the underlying transport protocol, the local system changes its state to Idle ๐
If the Holdtime timer expires, the local system sends a NOTIFICATION message with Error Code Hold Timer Expired and changes its state to Idle โ
If the KeepAlive timer expires, the local system sends a KEEPALIVE message and restarts its KeepAlive timer ๐
Each time the local system sends a KEEPALIVE or UPDATE message, it restarts its KeepAlive timer ๐
For the Stop event (from either system or the operator), the local system sends a NOTIFICATION message with Error Code Cease and changes its state to Idle ๐
Start event is ignored in the Established state.
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and changes its state to Idle ๐ฌ
Whenever BGP changes its state from Established to Idle, it closes the BGP (and transport-level) connection, releases all resources tied to that connection, and deletes all routes derived from that connection ๐๏ธ
9. UPDATE Message Handling ๐ฌ
An UPDATE message may be received only in the Established state. When an UPDATE message arrives, each field gets checked for validity as described in Section 6.3 โ
If an optional non-transitive attribute is unrecognized, it's 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 so it can be passed on to other BGP speakers ๐
If an optional attribute is recognized and has a valid value, then depending on the type of that optional attribute, it gets processed locally, kept, and updated if necessary for possible propagation to other BGP speakers ๐งฉ
If the network and the path attributes associated with a route to that network are correct, then the route is compared with other routes to the same network. If the new route is better than the current one, then it's propagated via an UPDATE message to adjacent BGP speakers, as follows:
- If a route in the UPDATE was received over an internal link, it isn't propagated over any other internal link. This restriction is because all BGP speakers within a single AS form a completely connected graph (see above) ๐ธ๏ธ
- If the UPDATE message is propagated over an external link, the local AS number gets prepended to the
AS_PATHattribute, and theNEXT_HOPattribute gets updated with an IP address of the router that should be used as a next hop to the network. If the UPDATE message is propagated over an internal link, theAS_PATHattribute is passed along unmodified and theNEXT_HOPattribute is replaced with the sender's own IP address ๐ฃ๏ธ
Generally speaking, the rules for comparing routes among several alternatives are outside the scope of this document. There are two exceptions ๐
- If the local AS appears in the AS path of the new route being considered, then that new route can't be viewed as better than any other route. If such a route were ever used, a routing loop would result ๐๐
- In order to achieve successful distributed operation, only routes with a likelihood of stability can be chosen. So an AS must avoid using unstable routes, and it must not make rapid spontaneous changes to its choice of route. Quantifying the terms "unstable" and "rapid" in the previous sentence will take experience, but the principle is clear โจ
10. Detection of Inter-AS Policy Contradictions ๐ฅ
okay so bestie, BGP doesn't have a central boss deciding routing policy for every AS ๐ and policies aren't even shared through the protocol itself, which means a bunch of ASs can end up with policies that just can't all be true at once ๐ญ. when that happens the routes can keep flip-flopping forever. it's giving chaos ngl ๐
so to catch this, every BGP speaker has to follow this rule โจ: if the route you're currently using to reach a destination turns out to be unreachable (like when an UPDATE for it shows up with the UNREACHABLE attribute), then before you switch to a different route, you have to advertise that route as unreachable to every BGP neighbor you previously advertised it to ๐ซถ.
why is this so iconic? because it lets other ASs tell two situations apart ๐:
- your system switched routes because the old one actually died ๐
- your system switched routes because it simply liked the new one more, and the old one is still totally alive ๐ธ
in the first case, the neighbors get an UPDATE message with the UNREACHABLE attribute for the old route. in the second case they don't ๐
sometimes this lets a BGP speaker figure out that its own policies plus some other AS's policies just can't both be satisfied ๐ญ๐. for example, picture AS A and its neighbor AS B ๐ฆ. B advertises a route with a path like <B,...>, and A isn't in it. A decides to use that path and sends <A,B,...> out to all its neighbors โจ. later B sends <B,...,A,...> right back to A, and B never declared its earlier <B,...> path unreachable. so A clearly prefers routes through B, and B clearly prefers routes through A ๐ . their combined policies can't be satisfied, and that should be noticed, logged locally, and brought to AS A's administration's attention ๐. how to actually do that is outside the scope of this document ๐ง, and so is a more complete procedure for detecting these contradictions ๐.
โ ๏ธ the protocol itself does NOT give any way to stop the route oscillation that these unsatisfiable policies can cause ๐ญ. the reason is that routing policies are seen as external to the protocol and set by each local AS administrator, so it's not the protocol's job ๐.
Appendix 1. BGP FSM State Transitions and Actions ๐ง
okay this part is the state machine tea โโจ. it talks about how the BGP FSM moves between states when BGP events happen, and here are the lists of states and events ๐.
BGP States:
1 - Idle
2 - Connect
3 - Active
4 - OpenSent
5 - OpenConfirm
6 - Established
BGP Events:
1 - BGP Start
2 - BGP Stop
3 - BGP Transport connection open
4 - BGP Transport connection closed
5 - BGP Transport connection open failed
6 - BGP Transport fatal error
7 - ConnectRetry timer expired
8 - Holdtime timer expired
9 - KeepAlive timer expired
10 - Receive OPEN message
11 - Receive KEEPALIVE message
12 - Receive UPDATE messages
13 - Receive NOTIFICATION message
this next table shows the state transitions and the actions that each transition kicks off ๐. it's a whole vibe ๐ญ:
Event Actions Message Sent Next State
--------------------------------------------------------------------
Idle (1)
1 Initialize resources none 2
Start ConnectRetry timer
Initiate a transport connection
others none none 1
Connect(2)
1 none none 2
3 Complete initialization OPEN 4
Clear ConnectRetry timer
5 Restart ConnectRetry timer none 3
7 Restart ConnectRetry timer none 2
Initiate a transport connection
others Release resources none 1
Active (3)
1 none none 3
3 Complete initialization OPEN 4
Clear ConnectRetry timer
5 Close connection 3
Restart ConnectRetry timer
7 Restart ConnectRetry timer none 2
Initiate a transport connection
others Release resources none 1
OpenSent(4)
1 none none 4
4 Close transport connection none 3
Restart ConnectRetry timer
6 Release resources none 1
10 Process OPEN is OK KEEPALIVE 5
Process OPEN failed NOTIFICATION 1
others Close transport connection NOTIFICATION 1
Release resources
OpenConfirm (5)
1 none none 5
4 Release resources none 1
6 Release resources none 1
9 Restart KeepAlive timer KEEPALIVE 5
11 Complete initialization none 6
Restart Holdtime timer
13 Close transport connection 1
Release resources
others Close transport connection NOTIFICATION 1
Release resources
Established (6)
1 none none 6
4 Release resources none 1
6 Release resources none 1
9 Restart KeepAlive timer KEEPALIVE 6
11 Restart Holdtime timer KEEPALIVE 6
12 Process UPDATE is OK UPDATE 6
Process UPDATE failed NOTIFICATION 1
13 Close transport connection 1
Release resources
others Close transport connection NOTIFICATION 1
Release resources
---------------------------------------------------------------------
and here's the condensed version of that same table, for when you just want the quick sparkle โจ:
Events| Idle | Active | Connect | OpenSent | OpenConfirm | Estab
| (1) | (2) | (3) | (4) | (5) | (6)
|--------------------------------------------------------------
1 | 2 | 2 | 3 | 4 | 5 | 6
| | | | | |
2 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
3 | 1 | 4 | 4 | 1 | 1 | 1
| | | | | |
4 | 1 | 1 | 1 | 3 | 1 | 1
| | | | | |
5 | 1 | 3 | 3 | 1 | 1 | 1
| | | | | |
6 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
7 | 1 | 2 | 2 | 1 | 1 | 1
| | | | | |
8 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
9 | 1 | 1 | 1 | 1 | 5 | 6
| | | | | |
10 | 1 | 1 | 1 | 1 or 5 | 1 | 1
| | | | | |
11 | 1 | 1 | 1 | 1 | 6 | 6
| | | | | |
12 | 1 | 1 | 1 | 1 | 1 | 1 or 6
| | | | | |
13 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
---------------------------------------------------------------
Appendix 2. Comparison with RFC 1105 ๐
okay so the RFC 1105 state machine needed some minor tweaks to fit the TCP user interface that 4.3 BSD provided ๐. also, the Up/Down/Horizontal relations from RFC 1105 are gone from the protocol entirely ๐.
the message format changed from RFC 1105 in these ways ๐:
- the Hold Time field got moved out of the BGP header and into the OPEN message ๐ .
- the version field got moved out of the BGP header and into the OPEN message ๐ฆ.
- the Link Type field was removed from the OPEN message ๐ญ.
- the OPEN CONFIRM message was eliminated, and the KEEPALIVE message now provides the implicit confirmation instead โจ.
- the UPDATE message format changed a lot ๐ฅ. new fields were added so it can carry multiple path attributes ๐ซถ.
- the Marker field got expanded and its job got broadened so it can support authentication ๐ก๏ธ๐.
Appendix 3. TCP options that may be used with BGP ๐ง
if the local system's TCP user interface supports the TCP PUSH function, then every BGP message should go out with the PUSH flag set ๐ธ. setting the PUSH flag forces BGP messages to be sent promptly to the receiver ๐จ.
if the local system's TCP user interface can set precedence on a TCP connection, then the BGP transport connection should be opened with precedence set to the Internetwork Control (110) value (see also [6]) ๐โจ.
References ๐
[1] Mills, D., "Exterior Gateway Protocol Formal Specification", RFC 904, BBN, April 1984.
[2] Rekhter, Y., "EGP and Policy Based Routing in the New NSFNET Backbone", RFC 1092, T.J. Watson Research Center, February 1989.
[3] Braun, H-W., "The NSFNET Routing Architecture", RFC 1093, MERIT/NSFNET Project, February 1989.
[4] Postel, J., "Transmission Control Protocol - DARPA Internet Program Protocol Specification", RFC 793, DARPA, September 1981.
[5] Honig, J., Katz, D., Mathis, M., Rekhter, Y., and J. Yu, "Application of the Border Gateway Protocol in the Internet", RFC 1164, Cornell University Theory Center, Merit/NSFNET, Pittsburgh Supercomputing Center, IBM, Merit/NSFNET, June 1990.
[6] Postel, J., "Internet Protocol - DARPA Internet Program Protocol Specification", RFC 791, DARPA, September 1981.
Security Considerations ๐๐
Security issues are not discussed in this memo. ๐ญ so yeah, this doc just doesn't go there ๐โจ.
Authors' Addresses ๐ฆ
Kirk Lougheed cisco Systems, Inc. 1525 O'Brien Drive Menlo Park, CA 94025
Phone: (415) 326-1941
Email: LOUGHEED@CISCO.COM
Yakov Rekhter T.J. Watson Research Center IBM Corporation P.O. Box 218 Yorktown Heights, NY 10598
Phone: (914) 945-3896
Email: YAKOV@IBM.COM
๐ฆ where this page comes from
- ietf: rfc1163 1990-06
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms