summaryrefslogtreecommitdiffstats
path: root/src/net/udp
diff options
context:
space:
mode:
authorMichael Brown2009-01-21 02:28:18 +0100
committerMichael Brown2009-01-21 02:31:52 +0100
commit7be5fa82e375119c01717275b7e54aa7fa6199fd (patch)
tree9f1f38bf21fbc3305bb4e374301c22f20bcccd62 /src/net/udp
parent[dhcp] Allow for missing server ID in ProxyDHCPACK (diff)
downloadipxe-7be5fa82e375119c01717275b7e54aa7fa6199fd.tar.gz
ipxe-7be5fa82e375119c01717275b7e54aa7fa6199fd.tar.xz
ipxe-7be5fa82e375119c01717275b7e54aa7fa6199fd.zip
[dhcp] Centralise DHCP successful state transitions
Move all the DHCP state transition logic into a single function dhcp_next_state(). This will make it easier to add support for PXE Boot Servers, since it abstracts away the difference between "mark DHCP as complete" and "transition to boot server discovery".
Diffstat (limited to 'src/net/udp')
-rw-r--r--src/net/udp/dhcp.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c
index 40670232..dd3763b4 100644
--- a/src/net/udp/dhcp.c
+++ b/src/net/udp/dhcp.c
@@ -640,10 +640,38 @@ static void dhcp_set_state ( struct dhcp_session *dhcp,
dhcp, dhcp_state_name ( state ) );
dhcp->state = state;
dhcp->start = currticks();
+ dhcp->timer.min_timeout = 0;
start_timer_nodelay ( &dhcp->timer );
}
/**
+ * Transition to next DHCP state
+ *
+ * @v dhcp DHCP session
+ */
+static void dhcp_next_state ( struct dhcp_session *dhcp ) {
+
+ switch ( dhcp->state ) {
+ case DHCP_STATE_DISCOVER:
+ dhcp_set_state ( dhcp, DHCP_STATE_REQUEST );
+ break;
+ case DHCP_STATE_REQUEST:
+ if ( dhcp->proxydhcpoffer ) {
+ dhcp_set_state ( dhcp, DHCP_STATE_PROXYREQUEST );
+ break;
+ }
+ /* Fall through */
+ case DHCP_STATE_PROXYREQUEST:
+ dhcp_finished ( dhcp, 0 );
+ break;
+ default:
+ assert ( 0 );
+ return;
+ }
+
+}
+
+/**
* Store received DHCPOFFER
*
* @v dhcp DHCP session
@@ -759,7 +787,7 @@ static void dhcp_rx_dhcpoffer ( struct dhcp_session *dhcp,
return;
/* Transition to DHCPREQUEST */
- dhcp_set_state ( dhcp, DHCP_STATE_REQUEST );
+ dhcp_next_state ( dhcp );
}
/**
@@ -822,15 +850,8 @@ static void dhcp_rx_dhcpack ( struct dhcp_session *dhcp,
if ( ( rc = dhcp_store_dhcpack ( dhcp, dhcpack, parent ) ) !=0 )
return;
- /* If we have a ProxyDHCPOFFER, transition to PROXYDHCPREQUEST */
- if ( dhcp->proxydhcpoffer ) {
- dhcp->timer.min_timeout = 0;
- dhcp_set_state ( dhcp, DHCP_STATE_PROXYREQUEST );
- return;
- }
-
- /* Terminate DHCP */
- dhcp_finished ( dhcp, 0 );
+ /* Transition to next state */
+ dhcp_next_state ( dhcp );
}
/**
@@ -868,8 +889,8 @@ static void dhcp_rx_proxydhcpack ( struct dhcp_session *dhcp,
if ( ( rc = dhcp_store_dhcpack ( dhcp, proxydhcpack, NULL ) ) != 0 )
return;
- /* Terminate DHCP */
- dhcp_finished ( dhcp, 0 );
+ /* Transition to next state */
+ dhcp_next_state ( dhcp );
}
/**
@@ -991,13 +1012,8 @@ static void dhcp_timer_expired ( struct retry_timer *timer, int fail ) {
/* Give up waiting for ProxyDHCP before we reach the failure point */
if ( dhcp->dhcpoffer && ( elapsed > PROXYDHCP_WAIT_TIME ) ) {
- if ( dhcp->state == DHCP_STATE_DISCOVER ) {
- dhcp_set_state ( dhcp, DHCP_STATE_REQUEST );
- return;
- } else if ( dhcp->state == DHCP_STATE_PROXYREQUEST ) {
- dhcp_finished ( dhcp, 0 );
- return;
- }
+ dhcp_next_state ( dhcp );
+ return;
}
/* Otherwise, retransmit current packet */