LWIP & DHCP/Static addressing

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

LWIP & DHCP/Static addressing

Post by steved »

I've been looking at the LWIP interface, mostly using gallegojm's example from viewtopic.php?f=4&t=2602.
I've also compared what happens in lwipthread.c with the documentation at http://lwip.wikia.com/wiki/Network_inte ... management, and it doesn't look quite right.

Firstly, the LWIP_DHCP option determines whether DHCP capability is available to the programmer; however as coded it also sets DHCP mode regardless.
I would expect the choice of DHCP/static address to be a run-time option, potentially changeable on the fly.
Also the initialisation sequence doesn't look right; according to the documentation either dhcp_start() or netif_set_up() (or autoip_start(), for autoip) should be called - not more than one.

My initial thought is to extend the lwipthread_opts structure with an enum for dhcp/static/autoip addressing, and modify the startup sequence in lwip_thread() appropriately.

I've got to look at this in more detail before proposing a specific change, but thought I'd seek any comments from those who've previously used the code to check whether I've missed something.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: LWIP & DHCP/Static addressing

Post by Giovanni »

Please feel free to propose changes to that layer, I am not very expert of lwIP so probably there is a lot that could be improved there.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

Giovanni wrote:I am not very expert of lwIP

Nor am I ;)

But I Have used other network stacks a bit.
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

Progress so far attached.

1. I've updated the lwip configuration block to allow specification of DHCP/static/autoip, and the flow in LWIP thread to take account of it.

At present the code has to be restarted to change the address, which in practice I've found to be a very satisfactory way of doing it. To change address/mode on the fly would require stopping the old mode, then starting the new.

2. I found the default stack allocation to be too small, so have increased it a little.
The requirement is somewhat dependent on the options selected, so debatable whether there should be a default at all, and its value.

3. I've updated some of the comments and defaults in lwipopts.h

4. I've supported the use of SNMP - it requires larger stacks, and the defaults are now increased when SNMP is enabled.
It also requires additional files to be linked in; at present I've done this by selecting an alternative make file. Can a make file test a #define from the code? If so, that would be a better way to go.

5. LWIP internally creates a thread which appeared in the thread list with no name. This is because Chibi doesn't support setting the thread name when the thread is created; it has to be done within the thread.
I've added a kludge (which you will probably detest and ignore!) in sys_arch.c to set the thread name.

The ability to set the thread name at creation time is something you might consider adding; looks pretty simple to do.


One thing I've noticed with the Chibistudio plugin (preview 10) is that it reports an obviously wrong value for unused stack space for the thread mentioned in item 5. That thread is created on the heap; the only one which is, AFAIK. May be relevant, since not noticed this before.
A stack size of 1024 generates a total thread working area of 1400. Immediately after creating the thread, unused stack is reported as 1260.
Attachments
lwip.zip
Proposed LWIP changes
(30.13 KiB) Downloaded 452 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: LWIP & DHCP/Static addressing

Post by Giovanni »

Hi,

Is stack filling enabled? without that the measurement can go wrong.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

Giovanni wrote:Is stack filling enabled? without that the measurement can go wrong.

Yes, it is.
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

Seeing that you're looking at LWIP, thought I'd better say that I've seen no need to change the code I proposed earlier to support SHCP?static address selection (other than to take account of mods you've done so far - will try and look at that next week).
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: LWIP & DHCP/Static addressing

Post by Giovanni »

Thanks, I wish to finish it before 3.0 if possible.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP & DHCP/Static addressing

Post by steved »

I've added the recent lwip initialisation changes to my working project, and all seems to be OK. Updated files attached.

As I've added to the comment, various bits need to be initialised before calling lwipInit(), especially if using SNMP.

Most users will have to call lwipInit() with some parameters set; it may be clearer to add that to the example:

Code: Select all

const uint8_t localMACAddress[6] = {0x00, 0x0E, 0x32, 0x00, 0x00, 0x01 };

struct lwipthread_opts netOptions = { (uint8_t *)localMACAddress,
                                      IP4_ADDR_VALUE(192, 168, 143, 25),
                                      IP4_ADDR_VALUE(255, 255, 255, 0),
                                      IP4_ADDR_VALUE(192, 168, 143, 220),
                                      NET_ADDRESS_STATIC
//                                      NET_ADDRESS_DHCP
};

// To initialise:
   lwipInit(&netOptions);


Hence the addition of the IP4_ADDR_VALUE() macro


As a side issue, the addition of chRegSetThreadNameX() isn't mentioned in the readme.txt, which perhaps it could be.

Also, on the description of chThdSuspendS(), it could be pointed out that the actual thread reference variable whose pointer is passed must be NULL on entry.
Attachments
lwip_bindings.zip
LWIP selectable Static/DHCP addressing
(14.66 KiB) Downloaded 564 times
wildsun
Posts: 4
Joined: Tue Mar 18, 2014 2:55 pm

Re: LWIP & DHCP/Static addressing

Post by wildsun »

hello:
Can you support IPv6 communications, the latest code with LWIP。thanks,
Post Reply