Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists