Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

[FreeRTOS+TCP] FreeRTOS_DHCP.c dhcpGATEWAY_OPTION_CODE

Posted by flandroid on May 30, 2016

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


[FreeRTOS+TCP] FreeRTOS_DHCP.c dhcpGATEWAY_OPTION_CODE

Posted by heinbali01 on June 2, 2016

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS