A BGP Session Is Just a TCP Connection With Opinions
Unlike OSPF or IS-IS, BGP does not run its own transport. A BGP session rides on an ordinary TCP connection to port 179 (RFC 4271). That single design choice explains most of what you see when a peering misbehaves: BGP inherits TCP's reliability, and it also inherits TCP's failure modes. A session that is stuck is very often a TCP problem first and a BGP problem second.
This post follows one peering from "nothing configured" to "routes flowing", walks through the finite state machine (FSM) defined in RFC 4271, and then covers the failures you will actually meet. It deliberately stops at the moment the session reaches Established. How routes are carried and chosen after that is covered in BGP UPDATE messages and best-path selection, and the loop-prevention logic is in BGP path vector and AS_PATH.
The Six States
RFC 4271 defines six states. Think of them as a checklist the router works through with each neighbor.
Idle: the router refuses all incoming connections and initiates none. It is waiting for a start event, such as the neighbor being configured or enabled.
Connect: the router is waiting for its own TCP connection attempt to complete. A ConnectRetry timer runs. If TCP succeeds, the router sends an OPEN message and moves on. If the timer expires, it tries again.
Active: the router is listening for, or retrying, a TCP connection. The name is misleading. Active does not mean healthy; it means "the last connect attempt did not complete and I am still trying".
OpenSent: TCP is up and our OPEN has been sent. We are waiting for the peer's OPEN.
OpenConfirm: both OPENs have been exchanged and accepted. We are waiting for a KEEPALIVE (confirming the peer accepted ours) or a NOTIFICATION.
Established: UPDATE, KEEPALIVE and NOTIFICATION messages can now be exchanged. This is the only state in which routes are advertised.
Any error in any state sends the session back to Idle, usually after sending a NOTIFICATION message and closing the TCP connection.
What Each Message Does
Four message types drive the FSM. Every message starts with a 19-byte header: a 16-byte marker, a 2-byte length and a 1-byte type.
OPEN carries the BGP version (4), the sender's AS number, the proposed Hold Time, the BGP Identifier (a 32-bit value, normally the router ID) and optional parameters. Capabilities such as multiprotocol support (RFC 4760), route refresh, and 4-byte AS numbers (RFC 6793) are negotiated here using the capabilities mechanism of RFC 5492.
KEEPALIVE is just the 19-byte header with no body. It confirms the OPEN in OpenConfirm and then keeps the session alive.
UPDATE advertises and withdraws routes. Only valid once Established.
NOTIFICATION reports an error and closes the session.
Walking Through the Handshake
Here is the happy path between two routers, R1 and R2, with R1 initiating:
R1 (Idle) -- start event R1 (Idle) -- start event --> R1 (Connect)
R1 -> R2 TCP SYN to port 179
R2 -> R1 TCP SYN/ACK
R1 -> R2 TCP ACK (TCP established)
R1 (OpenSent) -- OPEN R2 TCP ACK (TCP established)
R1 (OpenSent) -- OPEN --> R2
R2 (OpenSent) The TCP part is the ordinary three-way handshake. If you want to see exactly what the SYN, SYN/ACK and ACK carry, see the TCP three-way handshake explained. The BGP-specific work only starts after that completes.
Note that the source port of the connecting side is ephemeral, while the listening side uses 179. In a capture you will therefore see a packet flow like 49152 -> 179 in one direction and 179 -> 49152 in the other. Both routers try to connect at the same time in many networks, which leads to the next topic.
Connection Collisions
If both routers initiate a TCP connection simultaneously, you end up with two TCP connections between the same pair of peers. RFC 4271 section 6.8 handles this with collision detection: when an OPEN arrives on one connection while another exists, the router compares BGP Identifiers. The connection initiated by the router with the higher BGP Identifier is kept, and the other is closed with a NOTIFICATION (Cease). This is why a duplicate router ID can cause baffling flapping: the identifiers are what the tie-break depends on.
Timers That Matter
ConnectRetryTimer: how long to wait before trying TCP again. RFC 4271 suggests 120 seconds, though many implementations use shorter or adaptive values.
HoldTime: if no KEEPALIVE or UPDATE arrives within this period, the session is declared dead. RFC 4271 suggests 90 seconds. Each side proposes a value in its OPEN, and the lower of the two is used. A negotiated value must be zero (no keepalives) or at least 3 seconds.
KeepaliveTimer: suggested as one third of the Hold Time, so 30 seconds with a 90-second hold time.
These are BGP application-layer timers, separate from TCP keepalives. If you want the lower-layer picture of how TCP itself probes an idle connection, see TCP keepalive explained with Wireshark. BGP does not rely on it; it runs its own liveness check.
Reading the State From the CLI
The following is illustrative output in the style of an FRRouting router. Exact formatting differs between vendors and versions, so treat it as a shape to recognize, not a literal transcript.
R1# show bgp summary
Neighbor V AS MsgRcvd MsgSent Up/Down State/PfxRcd
192.0.2.2 4 65002 0 0 never Active
198.51.100.2 4 65003 42 40 00:12:31 5The useful trick: in the State/PfxRcd column, a number means Established and shows prefixes received. A word means the session is not up, and the word tells you where it stalled.
Troubleshooting by State
Stuck in Idle
Idle usually means the router does not want to start. Common causes: the neighbor is administratively shut down, there is no route to the peer's address, the local source address is not usable, or a previous failure triggered a backoff. Check the neighbor configuration and routing to the peer first. Some implementations also show Idle with a reason such as a missing remote-AS or a policy requirement for eBGP.
Flapping Between Connect and Active
This is the classic symptom of TCP not completing. Work down the stack:
Can the peer address be reached with ping, and from the correct source address?
Is something blocking TCP 179 in either direction, such as an ACL or firewall? Remember that either side may initiate, so both directions matter.
Is the neighbor address the one the peer expects? A peer configured for a loopback address will reject a session coming from an interface address.
For eBGP between loopbacks, are multihop settings in place? Directly connected eBGP peers conventionally send packets with an IP TTL of 1, so a loopback peering across a hop fails unless TTL is raised. The Generalized TTL Security Mechanism (RFC 5082) works the other way round, requiring a high TTL to prove the sender is close.
Is TCP authentication configured on only one side? A mismatched TCP MD5 signature (RFC 2385) or TCP-AO (RFC 5925) makes the segments silently dropped, which looks identical to a blocked port.
A packet capture settles this quickly. If you see SYNs with no SYN/ACK, it is a reachability or filtering problem. If you see a SYN/ACK followed by an RST, something on the far side accepted and then rejected the connection.
Bouncing Between OpenSent and Idle
TCP works, but the OPEN is rejected. The NOTIFICATION that follows tells you why. Typical OPEN error subcodes include a bad peer AS (the AS in the OPEN does not match the configured remote AS), a bad BGP Identifier, an unsupported version, and an unacceptable Hold Time. A wrong remote-AS configuration is the most common culprit in labs and migrations.
Established, Then Dropped
Once Established, a drop is usually one of these:
Hold Timer Expired (NOTIFICATION code 4): keepalives did not arrive in time. Look for packet loss, a congested control path, CPU starvation on a router, or an MTU problem that stops larger packets while small keepalives still pass.
UPDATE Message Error (code 3): the peer sent a malformed UPDATE.
Cease (code 6): an administrative action, a collision, or a configured maximum-prefix limit was reached. Subcodes distinguish these.
Finite State Machine Error (code 5): a message arrived in a state where it is not allowed.
The full list of NOTIFICATION codes is: Message Header Error (1), OPEN Message Error (2), UPDATE Message Error (3), Hold Timer Expired (4), Finite State Machine Error (5) and Cease (6).
A Minimal Illustrative Configuration
This is a simple eBGP peering in FRR-style syntax, shown for illustration. Addresses come from documentation ranges.
router bgp 65001
bgp router-id 192.0.2.1
neighbor 192.0.2.2 remote-as 65002
neighbor 192.0.2.2 timers 30 90
neighbor 192.0.2.2 password EXAMPLE-ONLY
address-family ipv4 unicast
neighbor 192.0.2.2 activate
exit-address-familyHere the timers line sets the keepalive to 30 seconds and the hold time to 90 seconds, which matches the RFC's suggested values. The password line enables TCP MD5 authentication; it must match on both sides. Command names and defaults vary by vendor, so check your platform documentation.
A Practical Debug Routine
Note the state in
show bgp summary. The state is your first clue about which layer is failing.If it is Idle, Connect or Active, treat it as a TCP problem: ping from the right source, check ACLs, check TTL and authentication.
If it cycles through OpenSent, read the NOTIFICATION. It names the exact problem.
If it drops after being Established, check the last reset reason and look at timers, loss and MTU.
When in doubt, capture on port 179 on one side and read the TCP and BGP messages directly.
Once you can read a peering this way, a session that will not come up stops being mysterious. It becomes a short list of questions: did TCP complete, was the OPEN accepted, and did keepalives keep arriving?
Comments (0)
Please sign in to comment.