Procházet zdrojové kódy

[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 před 9 roky
rodič
revize
47aebc24d3
3 změnil soubory, kde provedl 106 přidání a 23 odebrání
  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 Zobrazit soubor

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 Zobrazit soubor

639
  */
639
  */
640
 #define DHCP_MIN_LEN 552
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
 /** Settings block name used for DHCP responses */
642
 /** Settings block name used for DHCP responses */
653
 #define DHCP_SETTINGS_NAME "dhcp"
643
 #define DHCP_SETTINGS_NAME "dhcp"
654
 
644
 

+ 19
- 13
src/net/udp/dhcp.c Zobrazit soubor

44
 #include <ipxe/dhcppkt.h>
44
 #include <ipxe/dhcppkt.h>
45
 #include <ipxe/dhcp_arch.h>
45
 #include <ipxe/dhcp_arch.h>
46
 #include <ipxe/features.h>
46
 #include <ipxe/features.h>
47
+#include <config/dhcp.h>
47
 
48
 
48
 /** @file
49
 /** @file
49
  *
50
  *
171
 	void ( * expired ) ( struct dhcp_session *dhcp );
172
 	void ( * expired ) ( struct dhcp_session *dhcp );
172
 	/** Transmitted message type */
173
 	/** Transmitted message type */
173
 	uint8_t tx_msgtype;
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
 static struct dhcp_session_state dhcp_state_discover;
180
 static struct dhcp_session_state dhcp_state_discover;
272
 	dhcp->state = state;
274
 	dhcp->state = state;
273
 	dhcp->start = currticks();
275
 	dhcp->start = currticks();
274
 	stop_timer ( &dhcp->timer );
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
 	start_timer_nodelay ( &dhcp->timer );
279
 	start_timer_nodelay ( &dhcp->timer );
279
 }
280
 }
280
 
281
 
415
 	/* If we can't yet transition to DHCPREQUEST, do nothing */
416
 	/* If we can't yet transition to DHCPREQUEST, do nothing */
416
 	elapsed = ( currticks() - dhcp->start );
417
 	elapsed = ( currticks() - dhcp->start );
417
 	if ( ! ( dhcp->no_pxedhcp || dhcp->proxy_offer ||
418
 	if ( ! ( dhcp->no_pxedhcp || dhcp->proxy_offer ||
418
-		 ( elapsed > PROXYDHCP_MAX_TIMEOUT ) ) )
419
+		 ( elapsed > DHCP_DISC_PROXY_TIMEOUT_SEC * TICKS_PER_SEC ) ) )
419
 		return;
420
 		return;
420
 
421
 
421
 	/* Transition to DHCPREQUEST */
422
 	/* Transition to DHCPREQUEST */
431
 	unsigned long elapsed = ( currticks() - dhcp->start );
432
 	unsigned long elapsed = ( currticks() - dhcp->start );
432
 
433
 
433
 	/* Give up waiting for ProxyDHCP before we reach the failure point */
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
 		dhcp_set_state ( dhcp, &dhcp_state_request );
437
 		dhcp_set_state ( dhcp, &dhcp_state_request );
436
 		return;
438
 		return;
437
 	}
439
 	}
447
 	.rx			= dhcp_discovery_rx,
449
 	.rx			= dhcp_discovery_rx,
448
 	.expired		= dhcp_discovery_expired,
450
 	.expired		= dhcp_discovery_expired,
449
 	.tx_msgtype		= DHCPDISCOVER,
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
 	.rx			= dhcp_request_rx,
587
 	.rx			= dhcp_request_rx,
585
 	.expired		= dhcp_request_expired,
588
 	.expired		= dhcp_request_expired,
586
 	.tx_msgtype		= DHCPREQUEST,
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
 	unsigned long elapsed = ( currticks() - dhcp->start );
673
 	unsigned long elapsed = ( currticks() - dhcp->start );
670
 
674
 
671
 	/* Give up waiting for ProxyDHCP before we reach the failure point */
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
 		dhcp_finished ( dhcp, 0 );
677
 		dhcp_finished ( dhcp, 0 );
674
 		return;
678
 		return;
675
 	}
679
 	}
685
 	.rx			= dhcp_proxy_rx,
689
 	.rx			= dhcp_proxy_rx,
686
 	.expired		= dhcp_proxy_expired,
690
 	.expired		= dhcp_proxy_expired,
687
 	.tx_msgtype		= DHCPREQUEST,
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
 	/* Give up waiting before we reach the failure point, and fail
815
 	/* Give up waiting before we reach the failure point, and fail
811
 	 * over to the next server in the attempt list
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
 		dhcp->pxe_attempt++;
819
 		dhcp->pxe_attempt++;
815
 		if ( dhcp->pxe_attempt->s_addr ) {
820
 		if ( dhcp->pxe_attempt->s_addr ) {
816
 			dhcp_set_state ( dhcp, &dhcp_state_pxebs );
821
 			dhcp_set_state ( dhcp, &dhcp_state_pxebs );
832
 	.rx			= dhcp_pxebs_rx,
837
 	.rx			= dhcp_pxebs_rx,
833
 	.expired		= dhcp_pxebs_expired,
838
 	.expired		= dhcp_pxebs_expired,
834
 	.tx_msgtype		= DHCPREQUEST,
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
 /****************************************************************************

Načítá se…
Zrušit
Uložit