Securing the BGP Transport: MD5, TCP-AO and Protecting Port 179
Why the Transport Needs Protecting
A BGP session is a long-lived TCP connection between two routers, often across a link shared with another organisation. Anyone who can inject a valid-looking TCP segment into that connection can reset it, and a reset BGP session on an Internet edge means a full reconvergence. Anyone who can open a connection to port 179 can also make the router spend CPU on handshakes it will never complete. Securing BGP therefore starts below BGP itself, at the TCP layer, and Cisco gives you three groups of tools for it: authenticating the segments, limiting who can reach port 179, and checking the TTL of what arrives.
TTL security has its own post in this series, so this one concentrates on the first two. Authentication answers the question "did this segment really come from my neighbour?" Port 179 protection answers "should this packet even reach the control plane?" A well built edge uses both.
MD5 and TCP-AO Authentication
The classic tool is TCP MD5 authentication. Both routers share a password, and each TCP segment carries an MD5 digest calculated over the segment and the password. A segment with a missing or wrong digest is discarded before TCP processes it, so a forged reset cannot tear down the session. On Cisco it is one command per neighbour.
R1(config)#router bgp 65001
R1(config-router)#neighbor 10.1.12.2 password 7hisIsN0tAG00dKey
R1#show ip bgp neighbors 10.1.12.2 | include BGP state|Option Flags
BGP state = Established, up for 00:03:12
Option Flags: nagle, path mtu capable, md5
The md5 flag confirms the option is in use. When the two sides disagree, the router logs exactly what went wrong, and the wording distinguishes the two common mistakes.
R1#
%TCP-6-BADAUTH: Invalid MD5 digest from 10.1.12.2(52713) to 10.1.12.1(179) tableid - 0
R1#
%TCP-6-BADAUTH: No MD5 digest from 10.1.12.2(52713) to 10.1.12.1(179) tableid - 0
"Invalid MD5 digest" means both sides use MD5 but the passwords differ. "No MD5 digest" means the neighbour sends no digest at all, so it has no password configured. These two lines solve most authentication tickets in seconds, which is why they are worth memorising.
Changing a password on a live session needs care, and the behaviour is precise. When you change "#neighbor password" on R1, the session stays up. R1 starts signing with the new password immediately, so R2 starts rejecting R1's segments. Nothing resets yet, but no BGP messages get through. If R2 is updated before its hold timer expires, 180 seconds by default, the session survives without a reset. If not, R2's hold timer expires and the session drops. In practice, change both ends within the same short window, and lower nothing else at the same time.
MD5 has real weaknesses. The algorithm itself is considered broken for most security purposes, the key cannot be changed without that tight timing window, and there is no way to run two keys at once. TCP Authentication Option, TCP-AO, replaces it. It supports stronger algorithms, and it uses key chains with separate send and receive identifiers, so keys can be rolled over in a planned way.
R1(config)#key chain BGP-AO tcp
R1(config-keychain)#key 1
R1(config-keychain-key)#send-id 10
R1(config-keychain-key)#recv-id 10
R1(config-keychain-key)#key-string Str0ngA0KeyForR2
R1(config-keychain-key)#cryptographic-algorithm hmac-sha-256
R1(config-keychain-key)#router bgp 65001
R1(config-router)#neighbor 10.1.12.2 ao BGP-AO
The key chain must be created with the "#tcp" keyword. Each key has a send-id and recv-id between 0 and 255, a key string and an algorithm, chosen from aes-128-cmac, hmac-sha-1 and hmac-sha-256. The neighbour then references the chain with "#neighbor ao". The send-id on one side must match the recv-id on the other, which is how both routers agree on which key protects which segment. Moving a session from MD5 to TCP-AO is a change of authentication method, so plan it as a maintenance window in case the session resets. Cisco's documentation does not describe this transition in detail, so test the exact behaviour on your release before doing it in production.
Protecting Port 179 and IOS XR LPTS
Authentication protects an established session, but the router still has to receive and inspect every packet aimed at port 179, including floods of SYN packets from addresses that are not neighbours at all. The second layer of protection keeps those packets away from the control plane.
On IOS XE the standard tools are an infrastructure ACL on edge interfaces and Control Plane Policing. The ACL permits BGP only from configured neighbours and drops everything else aimed at port 179. The policy is simple to write and easy to forget when a new neighbour is added, which is its main operational risk.
R1(config)#ip access-list extended EDGE-IN
R1(config-ext-nacl)#permit tcp host 10.1.12.2 host 10.1.12.1 eq bgp
R1(config-ext-nacl)#permit tcp host 10.1.12.2 eq bgp host 10.1.12.1
R1(config-ext-nacl)#deny tcp any any eq bgp
R1(config-ext-nacl)#permit ip any any
R1(config-ext-nacl)#interface GigabitEthernet0/0
R1(config-if)#ip access-group EDGE-IN in
R1#show ip access-lists EDGE-IN
Extended IP access list EDGE-IN
10 permit tcp host 10.1.12.2 host 10.1.12.1 eq bgp (412 matches)
20 permit tcp host 10.1.12.2 eq bgp host 10.1.12.1 (388 matches)
30 deny tcp any any eq bgp (1792 matches)
40 permit ip any any (2093315 matches)
The two permit lines cover both directions of session setup, because either side may be the one that connects. The deny line counts every other attempt to reach port 179, and on an Internet edge that counter is rarely zero.
IOS XR adds a built-in layer called Local Packet Transport Services, LPTS. LPTS classifies traffic for the router itself and polices it by category before it reaches the route processor. For BGP, it treats packets from unknown sources harshly, packets from configured neighbours that are still connecting moderately, and packets belonging to established sessions lightly. A SYN flood from random addresses therefore cannot starve an existing session. LPTS does not replace interface ACLs, and you can see the BGP entries it has built with "#show lpts bindings brief".
RP/0/RP0/CPU0:XR1#show lpts bindings brief | include BGP
Wed Nov 11 20:14:51.330 UTC
0/RP0/CPU0 TCP LR IPV4 TCP default any any,179 10.1.12.2
0/RP0/CPU0 TCP LR IPV4 TCP default any 10.1.12.1,179 10.1.12.2,52713
Put together, the layers give a clear design for every external BGP session. Filter port 179 at the edge so that only real neighbours reach the control plane. Use TTL security so that a forged packet from far away fails before TCP even sees it. Authenticate the session, with TCP-AO where both sides support it and MD5 where they do not. And when a session will not come up after a security change, read the log first: a %TCP-6-BADAUTH line or a rising ACL deny counter will tell you which layer is doing its job a little too well.