]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - server/failover.c
- A new failover configuration parameter has been introduced for those
[thirdparty/dhcp.git] / server / failover.c
index 773f1e7a0b8ef24e553011644d7aaa76dfd12bde..795f896a66a331c332341eb1f0f42156d5d367c5 100644 (file)
@@ -1797,6 +1797,12 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
     if (new_state != startup && saved_state == startup)
        cancel_timeout (dhcp_failover_startup_timeout, state);
 
+    /*
+     * If the state changes for any reason, cancel 'delayed auto state
+     * changes' (currently there is just the one).
+     */
+    cancel_timeout(dhcp_failover_auto_partner_down, state);
+
     /* Set our service state. */
     dhcp_failover_set_service_state (state);
 
@@ -1805,6 +1811,29 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
            dhcp_failover_send_state (state);
 
     switch (new_state) {
+         case communications_interrupted:
+           /*
+            * There is an optional feature to automatically enter partner
+            * down after a timer expires, upon entering comms-interrupted.
+            * This feature is generally not safe except in specific
+            * circumstances.
+            *
+            * A zero value (also the default) disables it.
+            */
+           if (state->auto_partner_down == 0)
+               break;
+
+#if defined (DEBUG_FAILOVER_TIMING)
+           log_info("add_timeout +%ul dhcp_failover_auto_partner_down",
+                     (unsigned long)state->auto_partner_down);
+#endif
+           tv.tv_sec = cur_time + state->auto_partner_down;
+           tv.tv_usec = 0;
+           add_timeout(&tv, dhcp_failover_auto_partner_down, state,
+                       (tvref_t)omapi_object_reference,
+                       (tvunref_t)omapi_object_dereference);
+           break;
+
          case normal:
            /* Upon entering normal state, the server is expected to retransmit
             * all pending binding updates.  This is a good opportunity to
@@ -1820,12 +1849,12 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *state,
            }
 
            break;
-           
+
          case potential_conflict:
            if (state -> i_am == primary)
                    dhcp_failover_send_update_request (state);
            break;
-           
+
          case startup:
 #if defined (DEBUG_FAILOVER_TIMING)
            log_info ("add_timeout +15 %s",
@@ -3066,6 +3095,18 @@ void dhcp_failover_listener_restart (void *vs)
        }
 }
 
+void
+dhcp_failover_auto_partner_down(void *vs)
+{
+       dhcp_failover_state_t *state = vs;
+
+#if defined (DEBUG_FAILOVER_TIMING)
+       log_info("dhcp_failover_auto_partner_down");
+#endif
+
+       dhcp_failover_set_state(state, partner_down);
+}
+
 isc_result_t dhcp_failover_state_get_value (omapi_object_t *h,
                                            omapi_object_t *id,
                                            omapi_data_string_t *name,