ssahani / rpms / dhcp

Forked from rpms/dhcp 6 years ago
Clone
d3e04df
diff -up dhcp-4.1.1/client/dhclient.c.backoff dhcp-4.1.1/client/dhclient.c
545bbd8
--- dhcp-4.1.1/client/dhclient.c.backoff	2010-02-08 16:41:52.000000000 +0100
545bbd8
+++ dhcp-4.1.1/client/dhclient.c	2010-02-08 16:43:56.000000000 +0100
545bbd8
@@ -1187,6 +1187,8 @@ void state_init (cpp)
8273327
 	void *cpp;
8273327
 {
8273327
 	struct client_state *client = cpp;
8273327
+	enum dhcp_state init_state = client->state;
545bbd8
+	struct timeval tv;
8273327
 
8273327
 	ASSERT_STATE(state, S_INIT);
8273327
 
545bbd8
@@ -1199,9 +1201,18 @@ void state_init (cpp)
8273327
 	client -> first_sending = cur_time;
8273327
 	client -> interval = client -> config -> initial_interval;
8273327
 
8273327
-	/* Add an immediate timeout to cause the first DHCPDISCOVER packet
8273327
-	   to go out. */
8273327
-	send_discover (client);
8273327
+	if (init_state != S_DECLINED) {
8273327
+		/* Add an immediate timeout to cause the first DHCPDISCOVER packet
8273327
+		   to go out. */
8273327
+		send_discover(client);
8273327
+	} else {
8273327
+		/* We've received an OFFER and it has been DECLINEd by dhclient-script.
8273327
+		 * wait for a random time between 1 and backoff_cutoff seconds before
8273327
+		 * trying again. */
545bbd8
+		tv . tv_sec = cur_time + ((1 + (random() >> 2)) %  client->config->backoff_cutoff);
545bbd8
+		tv . tv_usec = 0;
545bbd8
+		add_timeout(&tv, send_discover, client, 0, 0);
8273327
+	}
8273327
 }
8273327
 
3161ff3
 /*
545bbd8
@@ -1480,6 +1491,7 @@ void bind_lease (client)
8273327
 		send_decline (client);
8273327
 		destroy_client_lease (client -> new);
8273327
 		client -> new = (struct client_lease *)0;
8273327
+		client -> state = S_DECLINED;
8273327
 		state_init (client);
8273327
 		return;
8273327
 	}
545bbd8
@@ -3689,6 +3701,7 @@ void client_location_changed ()
8273327
 			      case S_INIT:
8273327
 			      case S_REBINDING:
8273327
 			      case S_STOPPED:
8273327
+			      case S_DECLINED:
8273327
 				break;
8273327
 			}
8273327
 			client -> state = S_INIT;
d3e04df
diff -up dhcp-4.1.1/includes/dhcpd.h.backoff dhcp-4.1.1/includes/dhcpd.h
545bbd8
--- dhcp-4.1.1/includes/dhcpd.h.backoff	2010-02-08 16:41:52.000000000 +0100
545bbd8
+++ dhcp-4.1.1/includes/dhcpd.h	2010-02-08 16:41:52.000000000 +0100
d3e04df
@@ -1017,7 +1017,8 @@ enum dhcp_state {
8273327
 	S_BOUND = 5,
8273327
 	S_RENEWING = 6,
8273327
 	S_REBINDING = 7,
8273327
-	S_STOPPED = 8
8273327
+	S_STOPPED = 8,
8273327
+	S_DECLINED = 9
8273327
 };
8273327
 
8273327
 /* Authentication and BOOTP policy possibilities (not all values work