bgpd: collision-detect should retain Established peers + tidy logic + logs
* bgp_network.c: (bgp_accept) We should also reject connections where
the main peer is in >Established state.
Could potentially also reject connections for main peer == Established
here too.
Log the port number too, so it's easier to reconcile logs with
network dumps.
* bgp_packet.c: (bgp_collision_detect) Try factor out some of the
conditionals controlling the action of the loop to the top, for
readability.
Handle existing Established session, by closing the new one, favouring
stability and as per RFC, except for GR.
(bgp_open_receive) Tidy up the logic a bit for readability, making each
case distinct in the main body of the loop.
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 885082f..aaa3870 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -215,11 +215,15 @@
bgp_update_sock_send_buffer_size(bgp_sock);
if (BGP_DEBUG (events, EVENTS))
- zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
+ zlog_debug ("[Event] BGP connection from host %s:%d",
+ inet_sutop (&su, buf), sockunion_get_port (&su));
/* Check remote IP address */
peer1 = peer_lookup (NULL, &su);
- if (! peer1 || peer1->status == Idle)
+ /* We could perhaps just drop new connections from already Established
+ * peers here.
+ */
+ if (! peer1 || peer1->status == Idle || peer1->status > Established)
{
if (BGP_DEBUG (events, EVENTS))
{
@@ -227,8 +231,9 @@
zlog_debug ("[Event] BGP connection IP address %s is not configured",
inet_sutop (&su, buf));
else
- zlog_debug ("[Event] BGP connection IP address %s is Idle state",
- inet_sutop (&su, buf));
+ zlog_debug ("[Event] BGP connection IP address %s is %s state",
+ inet_sutop (&su, buf),
+ LOOKUP (bgp_status_msg, peer1->status));
}
close (bgp_sock);
return -1;