FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [May 2016 Threads]
Hello,
I am actually reading the FreeRTOS DHCP implementation and I found something that bother me.
In FreeRTOS_DHCP.c, line "~693" you have :
~~~
case dhcpGATEWAYOPTIONCODE :
if( ucLength == sizeof( uint32_t ) )
{
/* ulProcessed is not incremented in this case
because the gateway is not essential. */
xNetworkAddressing.ulGatewayAddress = ulParameter;
}
break;
~~~
In the code, if we receive the dhcpGATEWAYOPTIONCODE (=3), and the size of the parameter (ucLength) is 4 bytes, we take the parameter and use it as the gateway address.
In the RFC 2132 (https://tools.ietf.org/html/rfc2132) which defines the DHCP option format, you can read :
***3.5. Router Option
The router option specifies a list of IP addresses for routers on the
client's subnet. Routers SHOULD be listed in order of preference.
The code for the router option is 3. The minimum length for the
router option is 4 octets, and the length MUST always be a multiple
of 4.
Code Len Address 1Address 2
+-----+-----+-----+-----+-----+-----+-----+-----+--
| 3 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
+-----+-----+-----+-----+-----+-----+-----+-----+--*
As you can see the lenght can be different from 4.
In your implementation, in the case (probably a very rare one) where the router option contains more than one IP address, it should be more "clever" to take at least the first one ?
Without the gateway address, the device will not be able to connect to internet.
Thank for your time.
PS : Sorry for my bad English
Hi Florian,
Three days ago I answered to your post, but I forgot to check if Sourceforge had received my answer. Sorry about that.
Yes you are right, and thanks for reporting it. A DHCP server can send a list (an array) of gateway addresses.
So lets change the code to :
case dhcpGATEWAYOPTIONCODE :
~~~~
if( ucLength >= sizeof( uint32_t ) )
{
/* ulProcessed is not incremented in this case
because the gateway is not essential. */
xNetworkAddressing.ulGatewayAddress = ulParameter;
}
break;
~~~~
The bug went unnoticed because the routers that I played with only reported a single GW address.
Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.