|
|
fad460 |
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
|
|
|
fad460 |
index 7e756e0..52ba677 100644
|
|
|
fad460 |
--- a/includes/dhcpd.h
|
|
|
fad460 |
+++ b/includes/dhcpd.h
|
|
|
fad460 |
@@ -3347,6 +3347,7 @@ isc_result_t dhcp_failover_state_signal (omapi_object_t *,
|
|
|
fad460 |
isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *,
|
|
|
fad460 |
const char *);
|
|
|
fad460 |
isc_result_t dhcp_failover_set_service_state (dhcp_failover_state_t *state);
|
|
|
fad460 |
+void dhcp_failover_rescind_updates (dhcp_failover_state_t *);
|
|
|
fad460 |
isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *,
|
|
|
fad460 |
enum failover_state);
|
|
|
fad460 |
isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *,
|
|
|
fad460 |
diff --git a/server/failover.c b/server/failover.c
|
|
|
fad460 |
index 8944102..6083672 100644
|
|
|
fad460 |
--- a/server/failover.c
|
|
|
fad460 |
+++ b/server/failover.c
|
|
|
fad460 |
@@ -1520,8 +1520,16 @@ isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *state,
|
|
|
fad460 |
/* In these situations, we remain in the current
|
|
|
fad460 |
* state, or if in startup enter those states.
|
|
|
fad460 |
*/
|
|
|
fad460 |
- case communications_interrupted:
|
|
|
fad460 |
case conflict_done:
|
|
|
fad460 |
+ /* As the peer may not have received or may have
|
|
|
fad460 |
+ * lost track of updates we sent previously we
|
|
|
fad460 |
+ * rescind them, causing us to retransmit them
|
|
|
fad460 |
+ * on an update request.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ dhcp_failover_rescind_updates(state);
|
|
|
fad460 |
+ /* fall through */
|
|
|
fad460 |
+
|
|
|
fad460 |
+ case communications_interrupted:
|
|
|
fad460 |
case partner_down:
|
|
|
fad460 |
case paused:
|
|
|
fad460 |
case recover:
|
|
|
fad460 |
@@ -1704,6 +1712,52 @@ isc_result_t dhcp_failover_set_service_state (dhcp_failover_state_t *state)
|
|
|
fad460 |
return ISC_R_SUCCESS;
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
+/*!
|
|
|
fad460 |
+ * \brief Return any leases on the ack queue back to the update queue
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * Re-schedule any pending updates by moving them from the ack queue
|
|
|
fad460 |
+ * (update sent awaiting response) back to the update queue (need to
|
|
|
fad460 |
+ * send an update for this lease). This will result in a retransmission
|
|
|
fad460 |
+ * of the update.
|
|
|
fad460 |
+ *
|
|
|
fad460 |
+ * \param state is the state block for the failover connection we are
|
|
|
fad460 |
+ * updating.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+
|
|
|
fad460 |
+void dhcp_failover_rescind_updates (dhcp_failover_state_t *state)
|
|
|
fad460 |
+{
|
|
|
fad460 |
+ struct lease *lp;
|
|
|
fad460 |
+
|
|
|
fad460 |
+ if (state->ack_queue_tail == NULL)
|
|
|
fad460 |
+ return;
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /* Zap the flags. */
|
|
|
fad460 |
+ for (lp = state->ack_queue_head; lp; lp = lp->next_pending)
|
|
|
fad460 |
+ lp->flags = ((lp->flags & ~ON_ACK_QUEUE) | ON_UPDATE_QUEUE);
|
|
|
fad460 |
+
|
|
|
fad460 |
+ /* Now hook the ack queue to the beginning of the update queue. */
|
|
|
fad460 |
+ if (state->update_queue_head) {
|
|
|
fad460 |
+ lease_reference(&state->ack_queue_tail->next_pending,
|
|
|
fad460 |
+ state->update_queue_head, MDL);
|
|
|
fad460 |
+ lease_dereference(&state->update_queue_head, MDL);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+ lease_reference(&state->update_queue_head, state->ack_queue_head, MDL);
|
|
|
fad460 |
+
|
|
|
fad460 |
+ if (!state->update_queue_tail) {
|
|
|
fad460 |
+#if defined (POINTER_DEBUG)
|
|
|
fad460 |
+ if (state->ack_queue_tail->next_pending) {
|
|
|
fad460 |
+ log_error("next pending on ack queue tail.");
|
|
|
fad460 |
+ abort();
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+ lease_reference(&state->update_queue_tail,
|
|
|
fad460 |
+ state->ack_queue_tail, MDL);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+ lease_dereference(&state->ack_queue_tail, MDL);
|
|
|
fad460 |
+ lease_dereference(&state->ack_queue_head, MDL);
|
|
|
fad460 |
+ state->cur_unacked_updates = 0;
|
|
|
fad460 |
+}
|
|
|
fad460 |
+
|
|
|
fad460 |
isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
|
|
|
fad460 |
enum failover_state new_state)
|
|
|
fad460 |
{
|
|
|
fad460 |
@@ -1724,37 +1778,9 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
|
|
|
fad460 |
case normal:
|
|
|
fad460 |
case potential_conflict:
|
|
|
fad460 |
case partner_down:
|
|
|
fad460 |
- if (state -> ack_queue_tail) {
|
|
|
fad460 |
- struct lease *lp;
|
|
|
fad460 |
-
|
|
|
fad460 |
- /* Zap the flags. */
|
|
|
fad460 |
- for (lp = state -> ack_queue_head; lp; lp = lp -> next_pending)
|
|
|
fad460 |
- lp -> flags = ((lp -> flags & ~ON_ACK_QUEUE) |
|
|
|
fad460 |
- ON_UPDATE_QUEUE);
|
|
|
fad460 |
-
|
|
|
fad460 |
- /* Now hook the ack queue to the beginning of the update
|
|
|
fad460 |
- queue. */
|
|
|
fad460 |
- if (state -> update_queue_head) {
|
|
|
fad460 |
- lease_reference (&state -> ack_queue_tail -> next_pending,
|
|
|
fad460 |
- state -> update_queue_head, MDL);
|
|
|
fad460 |
- lease_dereference (&state -> update_queue_head, MDL);
|
|
|
fad460 |
- }
|
|
|
fad460 |
- lease_reference (&state -> update_queue_head,
|
|
|
fad460 |
- state -> ack_queue_head, MDL);
|
|
|
fad460 |
- if (!state -> update_queue_tail) {
|
|
|
fad460 |
-#if defined (POINTER_DEBUG)
|
|
|
fad460 |
- if (state -> ack_queue_tail -> next_pending) {
|
|
|
fad460 |
- log_error ("next pending on ack queue tail.");
|
|
|
fad460 |
- abort ();
|
|
|
fad460 |
- }
|
|
|
fad460 |
-#endif
|
|
|
fad460 |
- lease_reference (&state -> update_queue_tail,
|
|
|
fad460 |
- state -> ack_queue_tail, MDL);
|
|
|
fad460 |
- }
|
|
|
fad460 |
- lease_dereference (&state -> ack_queue_tail, MDL);
|
|
|
fad460 |
- lease_dereference (&state -> ack_queue_head, MDL);
|
|
|
fad460 |
- state -> cur_unacked_updates = 0;
|
|
|
fad460 |
- }
|
|
|
fad460 |
+ /* Move the ack queue to the update queue */
|
|
|
fad460 |
+ dhcp_failover_rescind_updates(state);
|
|
|
fad460 |
+
|
|
|
fad460 |
/* We will re-queue a timeout later, if applicable. */
|
|
|
fad460 |
cancel_timeout (dhcp_failover_keepalive, state);
|
|
|
fad460 |
break;
|
|
|
fad460 |
@@ -1858,7 +1884,9 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
|
|
|
fad460 |
break;
|
|
|
fad460 |
|
|
|
fad460 |
case potential_conflict:
|
|
|
fad460 |
- if (state -> i_am == primary)
|
|
|
fad460 |
+ if ((state->i_am == primary) ||
|
|
|
fad460 |
+ ((state->i_am == secondary) &&
|
|
|
fad460 |
+ (state->partner.state == conflict_done)))
|
|
|
fad460 |
dhcp_failover_send_update_request (state);
|
|
|
fad460 |
break;
|
|
|
fad460 |
|
|
|
fad460 |
@@ -1961,7 +1989,18 @@ isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *state,
|
|
|
fad460 |
if (state -> partner.state == new_state && state -> me.state) {
|
|
|
fad460 |
switch (state -> me.state) {
|
|
|
fad460 |
case startup:
|
|
|
fad460 |
- dhcp_failover_set_state (state, state -> saved_state);
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * If we have a peer state we must be connected.
|
|
|
fad460 |
+ * If so we should move to potential_conflict
|
|
|
fad460 |
+ * instead of resolution_interrupted, otherwise
|
|
|
fad460 |
+ * back to whereever we were before we stopped.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ if (state->saved_state == resolution_interrupted)
|
|
|
fad460 |
+ dhcp_failover_set_state(state,
|
|
|
fad460 |
+ potential_conflict);
|
|
|
fad460 |
+ else
|
|
|
fad460 |
+ dhcp_failover_set_state(state,
|
|
|
fad460 |
+ state->saved_state);
|
|
|
fad460 |
return ISC_R_SUCCESS;
|
|
|
fad460 |
|
|
|
fad460 |
case unknown_state:
|
|
|
fad460 |
@@ -2179,6 +2218,17 @@ isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *state,
|
|
|
fad460 |
dhcp_failover_set_state(state, new_state);
|
|
|
fad460 |
break;
|
|
|
fad460 |
|
|
|
fad460 |
+ case potential_conflict:
|
|
|
fad460 |
+ case resolution_interrupted:
|
|
|
fad460 |
+ /*
|
|
|
fad460 |
+ * This can happen when the connection is lost and
|
|
|
fad460 |
+ * recovered after the primary has moved to
|
|
|
fad460 |
+ * conflict-done but the secondary is still in
|
|
|
fad460 |
+ * potential-conflict. In that case, we have to
|
|
|
fad460 |
+ * remain in conflict-done.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
+ break;
|
|
|
fad460 |
+
|
|
|
fad460 |
default:
|
|
|
fad460 |
log_fatal("Peer %s: Invalid attempt to move from %s "
|
|
|
fad460 |
"to %s while local state is conflict-done.",
|
|
|
fad460 |
@@ -4867,16 +4917,17 @@ isc_result_t dhcp_failover_send_update_request (dhcp_failover_state_t *state)
|
|
|
fad460 |
if (!link -> outer || link -> outer -> type != omapi_type_connection)
|
|
|
fad460 |
return DHCP_R_INVALIDARG;
|
|
|
fad460 |
|
|
|
fad460 |
- if (state -> curUPD)
|
|
|
fad460 |
- return ISC_R_ALREADYRUNNING;
|
|
|
fad460 |
+ /* We allow an update to be restarted in case we requested an update
|
|
|
fad460 |
+ * and were interrupted by something. If we had an ALL going we need
|
|
|
fad460 |
+ * to restart that. Otherwise we simply continue with the request */
|
|
|
fad460 |
+ if (state -> curUPD == FTM_UPDREQALL) {
|
|
|
fad460 |
+ return (dhcp_failover_send_update_request_all(state));
|
|
|
fad460 |
+ }
|
|
|
fad460 |
|
|
|
fad460 |
- status = (dhcp_failover_put_message
|
|
|
fad460 |
- (link, link -> outer,
|
|
|
fad460 |
- FTM_UPDREQ, link->xid++,
|
|
|
fad460 |
- (failover_option_t *)0));
|
|
|
fad460 |
+ status = (dhcp_failover_put_message(link, link -> outer, FTM_UPDREQ,
|
|
|
fad460 |
+ link -> xid++, NULL));
|
|
|
fad460 |
|
|
|
fad460 |
- if (status == ISC_R_SUCCESS)
|
|
|
fad460 |
- state -> curUPD = FTM_UPDREQ;
|
|
|
fad460 |
+ state -> curUPD = FTM_UPDREQ;
|
|
|
fad460 |
|
|
|
fad460 |
#if defined (DEBUG_FAILOVER_MESSAGES)
|
|
|
fad460 |
if (status != ISC_R_SUCCESS)
|
|
|
fad460 |
@@ -4886,7 +4937,12 @@ isc_result_t dhcp_failover_send_update_request (dhcp_failover_state_t *state)
|
|
|
fad460 |
log_debug ("%s", obuf);
|
|
|
fad460 |
}
|
|
|
fad460 |
#endif
|
|
|
fad460 |
- log_info ("Sent update request message to %s", state -> name);
|
|
|
fad460 |
+ if (status == ISC_R_SUCCESS) {
|
|
|
fad460 |
+ log_info("Sent update request message to %s", state -> name);
|
|
|
fad460 |
+ } else {
|
|
|
fad460 |
+ log_error("Failed to send update request all message to %s: %s",
|
|
|
fad460 |
+ state -> name, isc_result_totext(status));
|
|
|
fad460 |
+ }
|
|
|
fad460 |
return status;
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
@@ -4913,17 +4969,14 @@ isc_result_t dhcp_failover_send_update_request_all (dhcp_failover_state_t
|
|
|
fad460 |
if (!link -> outer || link -> outer -> type != omapi_type_connection)
|
|
|
fad460 |
return DHCP_R_INVALIDARG;
|
|
|
fad460 |
|
|
|
fad460 |
- /* If there is an UPDREQ in progress, then upgrade to UPDREQALL. */
|
|
|
fad460 |
- if (state -> curUPD && (state -> curUPD != FTM_UPDREQ))
|
|
|
fad460 |
- return ISC_R_ALREADYRUNNING;
|
|
|
fad460 |
+ /* We allow an update to be restarted in case we requested an update
|
|
|
fad460 |
+ * and were interrupted by something.
|
|
|
fad460 |
+ */
|
|
|
fad460 |
|
|
|
fad460 |
- status = (dhcp_failover_put_message
|
|
|
fad460 |
- (link, link -> outer,
|
|
|
fad460 |
- FTM_UPDREQALL, link->xid++,
|
|
|
fad460 |
- (failover_option_t *)0));
|
|
|
fad460 |
+ status = (dhcp_failover_put_message(link, link -> outer, FTM_UPDREQALL,
|
|
|
fad460 |
+ link -> xid++, NULL));
|
|
|
fad460 |
|
|
|
fad460 |
- if (status == ISC_R_SUCCESS)
|
|
|
fad460 |
- state -> curUPD = FTM_UPDREQALL;
|
|
|
fad460 |
+ state -> curUPD = FTM_UPDREQALL;
|
|
|
fad460 |
|
|
|
fad460 |
#if defined (DEBUG_FAILOVER_MESSAGES)
|
|
|
fad460 |
if (status != ISC_R_SUCCESS)
|
|
|
fad460 |
@@ -4933,7 +4986,12 @@ isc_result_t dhcp_failover_send_update_request_all (dhcp_failover_state_t
|
|
|
fad460 |
log_debug ("%s", obuf);
|
|
|
fad460 |
}
|
|
|
fad460 |
#endif
|
|
|
fad460 |
- log_info ("Sent update request all message to %s", state -> name);
|
|
|
fad460 |
+ if (status == ISC_R_SUCCESS) {
|
|
|
fad460 |
+ log_info("Sent update request all message to %s", state -> name);
|
|
|
fad460 |
+ } else {
|
|
|
fad460 |
+ log_error("Failed to send update request all message to %s: %s",
|
|
|
fad460 |
+ state -> name, isc_result_totext(status));
|
|
|
fad460 |
+ }
|
|
|
fad460 |
return status;
|
|
|
fad460 |
}
|
|
|
fad460 |
|