philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.0-dhclient-decline-backoff.patch

45d60a
diff -up dhcp-4.2.0/client/dhclient.c.backoff dhcp-4.2.0/client/dhclient.c
45d60a
--- dhcp-4.2.0/client/dhclient.c.backoff	2010-07-21 13:37:03.000000000 +0200
45d60a
+++ dhcp-4.2.0/client/dhclient.c	2010-07-21 13:38:31.000000000 +0200
45d60a
@@ -1208,6 +1208,8 @@ void state_init (cpp)
45d60a
 	void *cpp;
45d60a
 {
45d60a
 	struct client_state *client = cpp;
45d60a
+	enum dhcp_state init_state = client->state;
45d60a
+	struct timeval tv;
45d60a
 
45d60a
 	ASSERT_STATE(state, S_INIT);
45d60a
 
45d60a
@@ -1220,9 +1222,18 @@ void state_init (cpp)
45d60a
 	client -> first_sending = cur_time;
45d60a
 	client -> interval = client -> config -> initial_interval;
45d60a
 
45d60a
-	/* Add an immediate timeout to cause the first DHCPDISCOVER packet
45d60a
-	   to go out. */
45d60a
-	send_discover (client);
45d60a
+	if (init_state != S_DECLINED) {
45d60a
+		/* Add an immediate timeout to cause the first DHCPDISCOVER packet
45d60a
+		   to go out. */
45d60a
+		send_discover(client);
45d60a
+	} else {
45d60a
+		/* We've received an OFFER and it has been DECLINEd by dhclient-script.
45d60a
+		 * wait for a random time between 1 and backoff_cutoff seconds before
45d60a
+		 * trying again. */
45d60a
+		tv . tv_sec = cur_time + ((1 + (random() >> 2)) %  client->config->backoff_cutoff);
45d60a
+		tv . tv_usec = 0;
45d60a
+		add_timeout(&tv, send_discover, client, 0, 0);
45d60a
+	}
45d60a
 }
45d60a
 
45d60a
 /*
45d60a
@@ -1501,6 +1512,7 @@ void bind_lease (client)
45d60a
 		send_decline (client);
45d60a
 		destroy_client_lease (client -> new);
45d60a
 		client -> new = (struct client_lease *)0;
45d60a
+		client -> state = S_DECLINED;
45d60a
 		state_init (client);
45d60a
 		return;
45d60a
 	}
45d60a
@@ -3711,6 +3723,7 @@ void client_location_changed ()
45d60a
 			      case S_INIT:
45d60a
 			      case S_REBINDING:
45d60a
 			      case S_STOPPED:
45d60a
+			      case S_DECLINED:
45d60a
 				break;
45d60a
 			}
45d60a
 			client -> state = S_INIT;
45d60a
diff -up dhcp-4.2.0/includes/dhcpd.h.backoff dhcp-4.2.0/includes/dhcpd.h
45d60a
--- dhcp-4.2.0/includes/dhcpd.h.backoff	2010-07-21 13:29:05.000000000 +0200
45d60a
+++ dhcp-4.2.0/includes/dhcpd.h	2010-07-21 13:38:31.000000000 +0200
45d60a
@@ -1056,7 +1056,8 @@ enum dhcp_state {
45d60a
 	S_BOUND = 5,
45d60a
 	S_RENEWING = 6,
45d60a
 	S_REBINDING = 7,
45d60a
-	S_STOPPED = 8
45d60a
+	S_STOPPED = 8,
45d60a
+	S_DECLINED = 9
45d60a
 };
45d60a
 
45d60a
 /* Authentication and BOOTP policy possibilities (not all values work