bgpd: consolidate start timer backoff via a 'BGP_Stop_with_error' FSM event
* Exponential increase/back-off on the peer start timer is replicated in
a few places. Consolidate by adding a "BGP_Stop_with_error" event
so places outside FSM can just raise that event.
* bgpd.h: Add BGP_Stop_with_error
* bgp_fsm.c: (bgp_event_str[]) Add text for BGP_Stop_with_error.
FSM table: Handle BGP_Stop_with_error, identical to bgp_stop
in nearly all cases.
* bgp_packet.c: (bgp_write,bgp_write_notify) can just raise new event now.
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 9f0b64c..abcefdd 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -971,6 +971,7 @@
{bgp_ignore, Idle}, /* Receive_UPDATE_message */
{bgp_ignore, Idle}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_ignore, Idle}, /* BGP_Stop_with_error */
},
{
/* Connect */
@@ -988,6 +989,7 @@
{bgp_ignore, Idle}, /* Receive_UPDATE_message */
{bgp_stop, Idle}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Idle},/* BGP_Stop_with_error */
},
{
/* Active, */
@@ -1005,6 +1007,7 @@
{bgp_ignore, Idle}, /* Receive_UPDATE_message */
{bgp_stop_with_error, Idle}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Idle},/* BGP_Stop_with_error */
},
{
/* OpenSent, */
@@ -1022,6 +1025,7 @@
{bgp_fsm_event_error, Idle}, /* Receive_UPDATE_message */
{bgp_stop_with_error, Idle}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Idle},/* BGP_Stop_with_error */
},
{
/* OpenConfirm, */
@@ -1039,6 +1043,7 @@
{bgp_ignore, Idle}, /* Receive_UPDATE_message */
{bgp_stop_with_error, Idle}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Idle},/* BGP_Stop_with_error */
},
{
/* Established, */
@@ -1056,6 +1061,7 @@
{bgp_fsm_update, Established}, /* Receive_UPDATE_message */
{bgp_stop_with_error, Clearing}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Clearing}, /* BGP_Stop_with_error */
},
{
/* Clearing, */
@@ -1073,6 +1079,7 @@
{bgp_stop, Clearing}, /* Receive_UPDATE_message */
{bgp_stop, Clearing}, /* Receive_NOTIFICATION_message */
{bgp_clearing_completed, Idle}, /* Clearing_Completed */
+ {bgp_stop_with_error, Clearing}, /* BGP_Stop_with_error */
},
{
/* Deleted, */
@@ -1090,6 +1097,7 @@
{bgp_ignore, Deleted}, /* Receive_UPDATE_message */
{bgp_ignore, Deleted}, /* Receive_NOTIFICATION_message */
{bgp_ignore, Deleted}, /* Clearing_Completed */
+ {bgp_ignore, Deleted}, /* BGP_Stop_with_error */
},
};
@@ -1110,6 +1118,7 @@
"Receive_UPDATE_message",
"Receive_NOTIFICATION_message",
"Clearing_Completed",
+ "BGP_Stop_with_error",
};
/* Execute event process. */
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index f42e544..51b006a 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -766,15 +766,9 @@
break;
case BGP_MSG_NOTIFY:
peer->notify_out++;
- /* Double start timer. */
- peer->v_start *= 2;
-
- /* Overflow check. */
- if (peer->v_start >= (60 * 2))
- peer->v_start = (60 * 2);
/* Flush any existing events */
- BGP_EVENT_ADD (peer, BGP_Stop);
+ BGP_EVENT_ADD (peer, BGP_Stop_with_error);
goto done;
case BGP_MSG_KEEPALIVE:
@@ -846,14 +840,7 @@
/* Type should be notify. */
peer->notify_out++;
- /* Double start timer. */
- peer->v_start *= 2;
-
- /* Overflow check. */
- if (peer->v_start >= (60 * 2))
- peer->v_start = (60 * 2);
-
- BGP_EVENT_ADD (peer, BGP_Stop);
+ BGP_EVENT_ADD (peer, BGP_Stop_with_error);
return 0;
}
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 2b279cd..a6cc34e 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -747,6 +747,7 @@
#define Receive_UPDATE_message 12
#define Receive_NOTIFICATION_message 13
#define Clearing_Completed 14
+#define BGP_Stop_with_error 15
#define BGP_EVENTS_MAX 16
/* BGP timers default value. */