philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

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

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