lwIP DHCP with static IP fallback

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
datenwolf
Posts: 11
Joined: Mon Mar 25, 2013 11:12 pm

lwIP DHCP with static IP fallback

Post by datenwolf »

Okay, this is not so much a ChibiOS and much more a lwIP related question. OTOH I'd like to use ChibiOS primitives (events, messages, etc.) if such is accounted for. Unfortunately lwIP documentation is between far and few and it's really hard to distill how things are to be done from the lwIP sources alone. I figured there is some substancial lwIP experience in this forum, so…

I'd like to add an configuration option to my device that in case DHCP fails it either falls back to AutoIP or to a manually configured static IP address. Furthermore I'd like it to go through this every time the link goes up.

All the lwIP examples out there go through DHCP configuration at device initialization and then no longer care about it. So my first idea was to put a dhcp_start in the link status callback. The problem is then: How do I detect if DHCP was successfull (all the examples I found use the IP address configuration as a side channel). So DHCP fails… Wait a moment, how do I decide that DHCP failed at all? And if so, what then? With LWIP_DHCP_AUTOIP_COOP will it automatically start autoip or do I have to do that manually?

Does anybody have some insight into this?
datenwolf
Posts: 11
Joined: Mon Mar 25, 2013 11:12 pm

Re: lwIP DHCP with static IP fallback

Post by datenwolf »

Okay, after spending an afternoon diving into the lwIP sources I got this thing done. As it turns out it's the easiest to place the static IP fallback logic into the lwIP DHCP client code itself; since there's a tight interaction between DHCP and AutoIP code in lwIP it's the only sane way to do, anyway.

I'll prepare a patch to pass to lwIP upstream next week. Unfortunately a collaborator on our little project took the local copy of the lwIP sources in the project tree out of source control (because we're only going to use vanilla… yeah :? ) so I'll have to do that first before preparing a patch.
Post Reply