philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.5-failover-potential-conflict.patch

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