Skip to content

Commit c0d4feb

Browse files
committed
Initial
1 parent 0ab46d1 commit c0d4feb

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

source/FreeRTOS_DHCP.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
pxIterator = NULL;
258258
}
259259

260-
if( pxIterator != NULL )
260+
if(( pxIterator != NULL ) && ( pxIterator->xDHCPData.eDHCPState == pxIterator->xDHCPData.eExpectedState ) )
261261
{
262262
/* The second parameter pdTRUE tells to check for a UDP message. */
263263
vDHCPProcessEndPoint( pdFALSE, pdTRUE, pxIterator );
@@ -269,15 +269,23 @@
269269
}
270270
else
271271
{
272-
/* Target not found, fetch the message and delete it. */
272+
/* Target not found or there is a state mismatch, fetch the message and delete it. */
273273
/* PAss the address of a pointer pucUDPPayload, because zero-copy is used. */
274274
lBytes = FreeRTOS_recvfrom( EP_DHCPData.xDHCPSocket, &( pucUDPPayload ), 0, FREERTOS_ZERO_COPY, NULL, NULL );
275275

276276
if( ( lBytes > 0 ) && ( pucUDPPayload != NULL ) )
277277
{
278278
/* Remove it now, destination not found. */
279279
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayload );
280-
FreeRTOS_printf( ( "vDHCPProcess: Removed a %d-byte message: target not found\n", ( int ) lBytes ) );
280+
if( pxIterator == NULL )
281+
{
282+
FreeRTOS_printf( ( "vDHCPProcess: Removed a %d-byte message: target not found\n", ( int ) lBytes ) );
283+
}
284+
else
285+
{
286+
FreeRTOS_printf( ( "vDHCPProcess: Wrong state: expected: %d got: %d : ignore\n",
287+
pxIterator->xDHCPData.eExpectedState, pxIterator->xDHCPData.eDHCPState ) );
288+
}
281289
}
282290
}
283291
}
@@ -489,6 +497,10 @@
489497
{
490498
/* Give up, start again. */
491499
EP_DHCPData.eDHCPState = eInitialWait;
500+
/* Reset expected state so that DHCP packets from
501+
different DHCP servers if available already in the DHCP socket can
502+
be processed */
503+
EP_DHCPData.eExpectedState = eInitialWait;
492504
}
493505
}
494506
}
@@ -992,6 +1004,10 @@
9921004
{
9931005
/* Start again. */
9941006
EP_DHCPData.eDHCPState = eInitialWait;
1007+
/* Reset expected state so that DHCP packets from
1008+
different DHCP servers if available already in the DHCP socket can
1009+
be processed */
1010+
EP_DHCPData.eExpectedState = eInitialWait;
9951011
}
9961012
}
9971013

0 commit comments

Comments
 (0)