Browse Source

[dhcp] Limit maximum number of DHCP discovery deferrals

For switches which remain permanently in the non-forwarding state (or
which erroneously report a non-forwarding state), ensure that iPXE
will eventually give up waiting for the link to become unblocked.

Originally-fixed-by: Wissam Shoukair <wissams@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
ed0d7c4f6f
2 changed files with 12 additions and 2 deletions
  1. 6
    0
      src/config/dhcp.h
  2. 6
    2
      src/net/udp/dhcp.c

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

@@ -24,6 +24,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24 24
 //#define DHCP_DISC_START_TIMEOUT_SEC	4	/* as per PXE spec */
25 25
 //#define DHCP_DISC_END_TIMEOUT_SEC	32	/* as per PXE spec */
26 26
 
27
+/*
28
+ * Maximum number of discovery deferrals due to blocked links
29
+ * (e.g. from non-forwarding STP ports)
30
+ */
31
+#define DHCP_DISC_MAX_DEFERRALS		60
32
+
27 33
 /*
28 34
  * ProxyDHCP offers are given precedence by continue to wait for them
29 35
  * after a valid DHCPOFFER is received.  We'll wait through this

+ 6
- 2
src/net/udp/dhcp.c View File

@@ -444,7 +444,8 @@ static void dhcp_discovery_expired ( struct dhcp_session *dhcp ) {
444 444
 	unsigned long elapsed = ( currticks() - dhcp->start );
445 445
 
446 446
 	/* If link is blocked, defer DHCP discovery (and reset timeout) */
447
-	if ( netdev_link_blocked ( dhcp->netdev ) ) {
447
+	if ( netdev_link_blocked ( dhcp->netdev ) &&
448
+	     ( dhcp->count <= DHCP_DISC_MAX_DEFERRALS ) ) {
448 449
 		DBGC ( dhcp, "DHCP %p deferring discovery\n", dhcp );
449 450
 		dhcp->start = currticks();
450 451
 		start_timer_fixed ( &dhcp->timer,
@@ -1115,7 +1116,7 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
1115 1116
 	 * session state into packet traces.  Useful for extracting
1116 1117
 	 * debug information from non-debug builds.
1117 1118
 	 */
1118
-	dhcppkt.dhcphdr->secs = htons ( ( ++(dhcp->count) << 2 ) |
1119
+	dhcppkt.dhcphdr->secs = htons ( ( dhcp->count << 2 ) |
1119 1120
 					( dhcp->offer.s_addr ? 0x02 : 0 ) |
1120 1121
 					( dhcp->proxy_offer ? 0x01 : 0 ) );
1121 1122
 
@@ -1259,6 +1260,9 @@ static void dhcp_timer_expired ( struct retry_timer *timer, int fail ) {
1259 1260
 		return;
1260 1261
 	}
1261 1262
 
1263
+	/* Increment transmission counter */
1264
+	dhcp->count++;
1265
+
1262 1266
 	/* Handle timer expiry based on current state */
1263 1267
 	dhcp->state->expired ( dhcp );
1264 1268
 }

Loading…
Cancel
Save