Browse Source

[dhcp] Extract timing parameters out to config/dhcp.h

iPXE uses DHCP timeouts loosely based on values recommended by the
specification, but often abbreviated to reduce timeouts for reliable
and/or simple network topologies.  Extract the DHCP timing parameters
to config/dhcp.h and document them.  The resulting default iPXE
behavior is exactly the same, but downstreams are now afforded the
opportunity to implement spec-compliant behavior via config file
overrides.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Alex Williamson 9 years ago
parent
commit
47aebc24d3
3 changed files with 106 additions and 23 deletions
  1. 87
    0
      src/config/dhcp.h
  2. 0
    10
      src/include/ipxe/dhcp.h
  3. 19
    13
      src/net/udp/dhcp.c

+ 87
- 0
src/config/dhcp.h View File

@@ -0,0 +1,87 @@
1
+#ifndef CONFIG_DHCP_H
2
+#define CONFIG_DHCP_H
3
+
4
+/** @file
5
+ *
6
+ * DHCP configuration
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <config/defaults.h>
13
+
14
+/*
15
+ * DHCP and PXE Boot Server timeout parameters
16
+ *
17
+ * Initial and final timeout for DHCP discovery
18
+ *
19
+ * The PXE spec indicates discover request are sent 4 times, with
20
+ * timeouts of 4, 8, 16, 32 seconds.  iPXE by default uses 1, 2, 4, 8.
21
+ */
22
+#define DHCP_DISC_START_TIMEOUT_SEC	1
23
+#define DHCP_DISC_END_TIMEOUT_SEC	10
24
+//#define DHCP_DISC_START_TIMEOUT_SEC	4	/* as per PXE spec */
25
+//#define DHCP_DISC_END_TIMEOUT_SEC	32	/* as per PXE spec */
26
+
27
+/*
28
+ * ProxyDHCP offers are given precedence by continue to wait for them
29
+ * after a valid DHCPOFFER is received.  We'll wait through this
30
+ * timeout for it.  The PXE spec indicates waiting through the 4 & 8
31
+ * second timeouts, iPXE by default stops after 2.
32
+ */
33
+#define DHCP_DISC_PROXY_TIMEOUT_SEC	2
34
+//#define DHCP_DISC_PROXY_TIMEOUT_SEC	11	/* as per PXE spec */
35
+
36
+/*
37
+ * Per the PXE spec, requests are also tried 4 times, but at timeout
38
+ * intervals of 1, 2, 3, 4 seconds.  To adapt this to an exponential
39
+ * backoff timer, we can either do 1, 2, 4, 8, ie. 4 retires with a
40
+ * longer interval or start at 0 (0.25s) for 0.25, 0.5, 1, 2, 4,
41
+ * ie. one extra try and shorter initial timeouts.  iPXE by default
42
+ * does a combination of both, starting at 0 and going through the 8
43
+ * second timeout.
44
+ */
45
+#define DHCP_REQ_START_TIMEOUT_SEC	0
46
+#define DHCP_REQ_END_TIMEOUT_SEC	10
47
+//#define DHCP_REQ_END_TIMEOUT_SEC	4	/* as per PXE spec */
48
+
49
+/*
50
+ * A ProxyDHCP offer without PXE options also goes through a request
51
+ * phase using these same parameters, but note the early break below.
52
+ */
53
+#define DHCP_PROXY_START_TIMEOUT_SEC	0
54
+#define DHCP_PROXY_END_TIMEOUT_SEC	10
55
+//#define DHCP_PROXY_END_TIMEOUT_SEC	8	/* as per PXE spec */
56
+
57
+/*
58
+ * A ProxyDHCP request timeout should not induce a failure condition,
59
+ * so we always want to break before the above set of timers expire.
60
+ * The iPXE default value of 2 breaks at the first timeout after 2
61
+ * seconds, which will be after the 2 second timeout.
62
+ */
63
+#define DHCP_REQ_PROXY_TIMEOUT_SEC	2
64
+//#define DHCP_REQ_PROXY_TIMEOUT_SEC	7	/* as per PXE spec */
65
+
66
+/*
67
+ * Per the PXE spec, a PXE boot server request is also be retried 4
68
+ * times at timeouts of 1, 2, 3, 4.  iPXE uses the same timeouts as
69
+ * discovery, 1, 2, 4, 8, but will move on to the next server if
70
+ * available after an elapsed time greater than 3 seconds, therefore
71
+ * effectively only sending 3 tries at timeouts of 1, 2, 4.
72
+ */
73
+#define PXEBS_START_TIMEOUT_SEC		1
74
+#define PXEBS_END_TIMEOUT_SEC		10
75
+//#define PXEBS_START_TIMEOUT_SEC	0	/* as per PXE spec */
76
+//#define PXEBS_END_TIMEOUT_SEC		8	/* as per PXE spec */
77
+
78
+/*
79
+ * Increment to the next PXE Boot server, if available, after this
80
+ * this much time has elapsed.
81
+ */
82
+#define PXEBS_MAX_TIMEOUT_SEC		3
83
+//#define PXEBS_MAX_TIMEOUT_SEC		7	/* as per PXE spec */
84
+
85
+#include <config/local/dhcp.h>
86
+
87
+#endif /* CONFIG_DHCP_H */

+ 0
- 10
src/include/ipxe/dhcp.h View File

@@ -639,16 +639,6 @@ struct dhcphdr {
639 639
  */
640 640
 #define DHCP_MIN_LEN 552
641 641
 
642
-/** Timeouts for sending DHCP packets */
643
-#define DHCP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
644
-#define DHCP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
645
-
646
-/** Maximum time that we will wait for ProxyDHCP responses */
647
-#define PROXYDHCP_MAX_TIMEOUT ( 2 * TICKS_PER_SEC )
648
-
649
-/** Maximum time that we will wait for Boot Server responses */
650
-#define PXEBS_MAX_TIMEOUT ( 3 * TICKS_PER_SEC )
651
-
652 642
 /** Settings block name used for DHCP responses */
653 643
 #define DHCP_SETTINGS_NAME "dhcp"
654 644
 

+ 19
- 13
src/net/udp/dhcp.c View File

@@ -44,6 +44,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
44 44
 #include <ipxe/dhcppkt.h>
45 45
 #include <ipxe/dhcp_arch.h>
46 46
 #include <ipxe/features.h>
47
+#include <config/dhcp.h>
47 48
 
48 49
 /** @file
49 50
  *
@@ -171,8 +172,9 @@ struct dhcp_session_state {
171 172
 	void ( * expired ) ( struct dhcp_session *dhcp );
172 173
 	/** Transmitted message type */
173 174
 	uint8_t tx_msgtype;
174
-	/** Apply minimum timeout */
175
-	uint8_t apply_min_timeout;
175
+	/** Timeout parameters */
176
+	uint8_t min_timeout_sec;
177
+	uint8_t max_timeout_sec;
176 178
 };
177 179
 
178 180
 static struct dhcp_session_state dhcp_state_discover;
@@ -272,9 +274,8 @@ static void dhcp_set_state ( struct dhcp_session *dhcp,
272 274
 	dhcp->state = state;
273 275
 	dhcp->start = currticks();
274 276
 	stop_timer ( &dhcp->timer );
275
-	dhcp->timer.min_timeout =
276
-		( state->apply_min_timeout ? DHCP_MIN_TIMEOUT : 0 );
277
-	dhcp->timer.max_timeout = DHCP_MAX_TIMEOUT;
277
+	dhcp->timer.min_timeout = state->min_timeout_sec * TICKS_PER_SEC;
278
+	dhcp->timer.max_timeout = state->max_timeout_sec * TICKS_PER_SEC;
278 279
 	start_timer_nodelay ( &dhcp->timer );
279 280
 }
280 281
 
@@ -415,7 +416,7 @@ static void dhcp_discovery_rx ( struct dhcp_session *dhcp,
415 416
 	/* If we can't yet transition to DHCPREQUEST, do nothing */
416 417
 	elapsed = ( currticks() - dhcp->start );
417 418
 	if ( ! ( dhcp->no_pxedhcp || dhcp->proxy_offer ||
418
-		 ( elapsed > PROXYDHCP_MAX_TIMEOUT ) ) )
419
+		 ( elapsed > DHCP_DISC_PROXY_TIMEOUT_SEC * TICKS_PER_SEC ) ) )
419 420
 		return;
420 421
 
421 422
 	/* Transition to DHCPREQUEST */
@@ -431,7 +432,8 @@ static void dhcp_discovery_expired ( struct dhcp_session *dhcp ) {
431 432
 	unsigned long elapsed = ( currticks() - dhcp->start );
432 433
 
433 434
 	/* Give up waiting for ProxyDHCP before we reach the failure point */
434
-	if ( dhcp->offer.s_addr && ( elapsed > PROXYDHCP_MAX_TIMEOUT ) ) {
435
+	if ( dhcp->offer.s_addr &&
436
+	     ( elapsed > DHCP_DISC_PROXY_TIMEOUT_SEC * TICKS_PER_SEC ) ) {
435 437
 		dhcp_set_state ( dhcp, &dhcp_state_request );
436 438
 		return;
437 439
 	}
@@ -447,7 +449,8 @@ static struct dhcp_session_state dhcp_state_discover = {
447 449
 	.rx			= dhcp_discovery_rx,
448 450
 	.expired		= dhcp_discovery_expired,
449 451
 	.tx_msgtype		= DHCPDISCOVER,
450
-	.apply_min_timeout	= 1,
452
+	.min_timeout_sec	= DHCP_DISC_START_TIMEOUT_SEC,
453
+	.max_timeout_sec	= DHCP_DISC_END_TIMEOUT_SEC,
451 454
 };
452 455
 
453 456
 /**
@@ -584,7 +587,8 @@ static struct dhcp_session_state dhcp_state_request = {
584 587
 	.rx			= dhcp_request_rx,
585 588
 	.expired		= dhcp_request_expired,
586 589
 	.tx_msgtype		= DHCPREQUEST,
587
-	.apply_min_timeout	= 0,
590
+	.min_timeout_sec	= DHCP_REQ_START_TIMEOUT_SEC,
591
+	.max_timeout_sec	= DHCP_REQ_END_TIMEOUT_SEC,
588 592
 };
589 593
 
590 594
 /**
@@ -669,7 +673,7 @@ static void dhcp_proxy_expired ( struct dhcp_session *dhcp ) {
669 673
 	unsigned long elapsed = ( currticks() - dhcp->start );
670 674
 
671 675
 	/* Give up waiting for ProxyDHCP before we reach the failure point */
672
-	if ( elapsed > PROXYDHCP_MAX_TIMEOUT ) {
676
+	if ( elapsed > DHCP_REQ_PROXY_TIMEOUT_SEC * TICKS_PER_SEC ) {
673 677
 		dhcp_finished ( dhcp, 0 );
674 678
 		return;
675 679
 	}
@@ -685,7 +689,8 @@ static struct dhcp_session_state dhcp_state_proxy = {
685 689
 	.rx			= dhcp_proxy_rx,
686 690
 	.expired		= dhcp_proxy_expired,
687 691
 	.tx_msgtype		= DHCPREQUEST,
688
-	.apply_min_timeout	= 0,
692
+	.min_timeout_sec	= DHCP_PROXY_START_TIMEOUT_SEC,
693
+	.max_timeout_sec	= DHCP_PROXY_END_TIMEOUT_SEC,
689 694
 };
690 695
 
691 696
 /**
@@ -810,7 +815,7 @@ static void dhcp_pxebs_expired ( struct dhcp_session *dhcp ) {
810 815
 	/* Give up waiting before we reach the failure point, and fail
811 816
 	 * over to the next server in the attempt list
812 817
 	 */
813
-	if ( elapsed > PXEBS_MAX_TIMEOUT ) {
818
+	if ( elapsed > PXEBS_MAX_TIMEOUT_SEC * TICKS_PER_SEC ) {
814 819
 		dhcp->pxe_attempt++;
815 820
 		if ( dhcp->pxe_attempt->s_addr ) {
816 821
 			dhcp_set_state ( dhcp, &dhcp_state_pxebs );
@@ -832,7 +837,8 @@ static struct dhcp_session_state dhcp_state_pxebs = {
832 837
 	.rx			= dhcp_pxebs_rx,
833 838
 	.expired		= dhcp_pxebs_expired,
834 839
 	.tx_msgtype		= DHCPREQUEST,
835
-	.apply_min_timeout	= 1,
840
+	.min_timeout_sec	= PXEBS_START_TIMEOUT_SEC,
841
+	.max_timeout_sec	= PXEBS_END_TIMEOUT_SEC,
836 842
 };
837 843
 
838 844
 /****************************************************************************

Loading…
Cancel
Save