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 9 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
 //#define DHCP_DISC_START_TIMEOUT_SEC	4	/* as per PXE spec */
24
 //#define DHCP_DISC_START_TIMEOUT_SEC	4	/* as per PXE spec */
25
 //#define DHCP_DISC_END_TIMEOUT_SEC	32	/* as per PXE spec */
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
  * ProxyDHCP offers are given precedence by continue to wait for them
34
  * ProxyDHCP offers are given precedence by continue to wait for them
29
  * after a valid DHCPOFFER is received.  We'll wait through this
35
  * after a valid DHCPOFFER is received.  We'll wait through this

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

444
 	unsigned long elapsed = ( currticks() - dhcp->start );
444
 	unsigned long elapsed = ( currticks() - dhcp->start );
445
 
445
 
446
 	/* If link is blocked, defer DHCP discovery (and reset timeout) */
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
 		DBGC ( dhcp, "DHCP %p deferring discovery\n", dhcp );
449
 		DBGC ( dhcp, "DHCP %p deferring discovery\n", dhcp );
449
 		dhcp->start = currticks();
450
 		dhcp->start = currticks();
450
 		start_timer_fixed ( &dhcp->timer,
451
 		start_timer_fixed ( &dhcp->timer,
1115
 	 * session state into packet traces.  Useful for extracting
1116
 	 * session state into packet traces.  Useful for extracting
1116
 	 * debug information from non-debug builds.
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
 					( dhcp->offer.s_addr ? 0x02 : 0 ) |
1120
 					( dhcp->offer.s_addr ? 0x02 : 0 ) |
1120
 					( dhcp->proxy_offer ? 0x01 : 0 ) );
1121
 					( dhcp->proxy_offer ? 0x01 : 0 ) );
1121
 
1122
 
1259
 		return;
1260
 		return;
1260
 	}
1261
 	}
1261
 
1262
 
1263
+	/* Increment transmission counter */
1264
+	dhcp->count++;
1265
+
1262
 	/* Handle timer expiry based on current state */
1266
 	/* Handle timer expiry based on current state */
1263
 	dhcp->state->expired ( dhcp );
1267
 	dhcp->state->expired ( dhcp );
1264
 }
1268
 }

Loading…
Cancel
Save