Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

dhcp hostname issue in 2.4.0

Open dragondaud opened this issue 8 years ago • 32 comments

Basic Infos

Hardware

Hardware: ESP-12/NodeMCU v1.0 Core Version: 2.4.0-github

Description

When using github version of Arduino ESP8266, the dhcp client is not sending hostname in request, resulting in a blank name in the DHCP server, and no DNS entry created. If I recompile with 2.3.0, then the hostname is sent, and assigned as expected.

I noticed blank hostnames previously, but wasn't sure where they came from. It turns out that jumping between 2.3.0 and 2.4.0-github was masking the issue, as once the server has the name set, it maintains it thru renewals, even when the name is not specified subsequently. And something is causing my modules running 2.4.0-github to occasionally lose their lease (localIP() shows 0.0.0.0).

ALSO, the default generated hostname (ESP_xxxx) is invalid, as the underscore character is not allowed in a valid hostname. A valid hostname may only contain letters, numbers and the dash "-", though a valid hostname cannot begin or end with a dash. https://en.wikipedia.org/wiki/Hostname

Settings in IDE

Arduino IDE: 1.8.5 Module: NodeMCU 1.0(ESP-12E) Flash Size: 4M(1M) CPU Frequency: 80 Mhz lwip: v2 Upload Using: Serial

Sketch

#include <ESP8266WiFi.h>

#define HOST "test-hostname"
#define WIFI_SSID "SSID"
#define WIFI_PASS "PASS"

void setup() {
  Serial.begin(115200);
  while (!Serial);
  delay(100);
  Serial.println();
  Serial.print(F("setup: WiFi connecting to "));
  Serial.print(WIFI_SSID);
  Serial.print(F("..."));
  WiFi.hostname(HOST);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(F("."));
    delay(500);
  }
  Serial.println(F(" OK"));
  Serial.print(F("Last reset reason: "));
  Serial.println(ESP.getResetReason());
}

void loop() {
  String ip = WiFi.localIP().toString();
  int heap = ESP.getFreeHeap();
  Serial.printf("%s: %6d %6d \r\n", ip.c_str(), millis(), heap);
  delay(2000);
}

Debug Messages

No related errors or other messages observed, even with full debug enabled.

dragondaud avatar Dec 14 '17 16:12 dragondaud

I think this is related to the dhcp client in lwip2. Can you try with lwip1.4 (select in menu) and report if this is working with it ?

d-a-v avatar Dec 14 '17 16:12 d-a-v

Selecting "v1.4 Prebuilt(gcc)" does indeed fix THIS problem, but as you know I had other troubles using the old lwip in my sketches, specifically with my telnet server. Thanks for the quick response, let me know if you want me to test a fix or anything.

dragondaud avatar Dec 14 '17 22:12 dragondaud

Can you please try to update lwip2 like this:

cd tools/sdk/lwip2
make
cd builder
git checkout master
git pull origin master
cd ..
make install

then retry your sketch and check for hostname set by dhcp client ?

d-a-v avatar Dec 14 '17 23:12 d-a-v

apps/sntp/sntp.c:728:1: error: stray '' in program \n\n\n#if LWIP_UDP\nvoid sntp_force_request (void)\n{\n\tsntp_request(NULL);\n}\n#endif\n ^

On Thu, Dec 14, 2017 at 4:44 PM, david gauchard [email protected] wrote:

Can you please try to update lwip2 like this:

cd tools/sdk/lwip2 make cd builder git checkout master git pull origin master cd .. make install

then retry your sketch and check for hostname set by dhcp client ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/esp8266/Arduino/issues/3970#issuecomment-351870285, or mute the thread https://github.com/notifications/unsubscribe-auth/AZnTPkoWjpnjhhPTbBsxeUtB0OP5nf-rks5tAbL5gaJpZM4RCUGn .

-- david denney dragondaud AT gmail DOT com 719-821-8900

dragondaud avatar Dec 15 '17 00:12 dragondaud

after manually fixing the src error, it compiles and installs fine. And it does fix the dhcp hostname issue. I'll let you know if I see anything else, thanks!

On Thu, Dec 14, 2017 at 5:58 PM, David Denney [email protected] wrote:

apps/sntp/sntp.c:728:1: error: stray '' in program \n\n\n#if LWIP_UDP\nvoid sntp_force_request (void)\n{\n\tsntp_request( NULL);\n}\n#endif\n ^

On Thu, Dec 14, 2017 at 4:44 PM, david gauchard [email protected] wrote:

Can you please try to update lwip2 like this:

cd tools/sdk/lwip2 make cd builder git checkout master git pull origin master cd .. make install

then retry your sketch and check for hostname set by dhcp client ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/esp8266/Arduino/issues/3970#issuecomment-351870285, or mute the thread https://github.com/notifications/unsubscribe-auth/AZnTPkoWjpnjhhPTbBsxeUtB0OP5nf-rks5tAbL5gaJpZM4RCUGn .

-- david denney dragondaud AT gmail DOT com 719-821-8900 <(719)%20821-8900>

-- david denney dragondaud AT gmail DOT com 719-821-8900

dragondaud avatar Dec 15 '17 02:12 dragondaud

@d-a-v this sounds like a simple fix. Will you be making a PR?

devyte avatar Dec 16 '17 20:12 devyte

@devyte will be included in the next lwip2 update

d-a-v avatar Dec 26 '17 22:12 d-a-v

DHCP hostname stopped working, again. Did this change not make it into master? I recently sync'd, but am not sure exactly when it stopped working. I tried the instructions above, again, and it didn't help.

dragondaud avatar Jan 15 '18 18:01 dragondaud

Noticed that dhcp hostname works normally if I enable WiFi debugging in the build. Stops working again when I disable debugging.

dragondaud avatar Jan 15 '18 20:01 dragondaud

It is currently working with master and you sketch above, no debug option enabled. Please double check then open a new issue (or reopen this one and update the title).

d-a-v avatar Jan 15 '18 21:01 d-a-v

I will try to isolate the problem further, but here are some packet captures that demonstrate the problem. The first one is successful, with debugging enabled, and you can see the requested hostname. The second capture, running the same exact code, but with debugging disabled, and it either doesn't have a hostname request, at all, or it is garbage as in this sample. Something is getting overwritten...

15:44:23.280937 60:01:94:34:52:20 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 1, offset 0, flags [none], proto UDP (17), length 336) 0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 60:01:94:34:52:20, length 308, xid 0xfce0d625, Flags [none] (0x0000) Client-Ethernet-Address 60:01:94:34:52:20 Vendor-rfc1048 Extensions Magic Cookie 0x63825363 DHCP-Message Option 53, length 1: Request MSZ Option 57, length 2: 1500 Requested-IP Option 50, length 4: 10.10.10.197 Server-ID Option 54, length 4: 10.10.10.1 Parameter-Request Option 55, length 5: Subnet-Mask, Default-Gateway, BR, Domain-Name-Server NTP Hostname Option 12, length 16: "TankGuard-345220"

15:50:36.939437 60:01:94:34:52:20 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 1, offset 0, flags [none], proto UDP (17), length 336) 0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 60:01:94:34:52:20, length 308, xid 0x2ce43abb, Flags [none] (0x0000) Client-Ethernet-Address 60:01:94:34:52:20 Vendor-rfc1048 Extensions Magic Cookie 0x63825363 DHCP-Message Option 53, length 1: Request MSZ Option 57, length 2: 1500 Requested-IP Option 50, length 4: 10.10.10.197 Server-ID Option 54, length 4: 10.10.10.1 Parameter-Request Option 55, length 5: Subnet-Mask, Default-Gateway, BR, Domain-Name-Server NTP Hostname Option 12, length 5: "G^A0^B^G"

dragondaud avatar Jan 15 '18 22:01 dragondaud

Thanks for this finding!

d-a-v avatar Jan 15 '18 23:01 d-a-v

FYI, switching to lwip1.4 makes the problem disappear. Also of note, lwip2 is sending multiple dhcp requests every boot. Sometimes the first one has the correct hostname, but the second request overwrites it with garbage. I can make traces and upload if you need.

dragondaud avatar Jan 16 '18 00:01 dragondaud

Thanks a lot for highlighting this issue here. Same experience at my end.

I am quite happy with stability of my lwip v2 webinterface by now, but I am desperately missing hostname feature.

Any idea when this is going to be tackled?

caipifrosch avatar Feb 04 '18 11:02 caipifrosch

@caipifrosch @dragondaud So the first dhcp request is always good and the second one (after the delay defined by the dhcp server) can be (or is always) garbage ?

d-a-v avatar Feb 04 '18 14:02 d-a-v

As dragondaud's description perfectly matched my experience, there were no further investigations into this at my end.

Just tested again with lwip 1.4prebuild and V2prebuild MCC=536.... Hostname just wont work on lwipV2. V1.4 hostname seems to be fine, but mobile access with my Android7 is very slow, no matter what browser I use.

Nevertheless, I can not confirm that wifi debug option sets the hostname correctly.

caipifrosch avatar Feb 04 '18 16:02 caipifrosch

So I need help with a live patch to try. Can you

cd tools/sdk/lwip2
make download

edit builder/glue-lwip/lwip-git.c L313 and comment the line out:

//netif->hostname = wifi_station_get_hostname();

then recompile

make install

and relink your sketch (by rebuilding it).

Reason: netif (lwip2) ->hostname used by dhcp client is set twice, one coming from lwip1's netif and the other one above. This may be a mistake. I commented out the one from lwip1 and I had no more hostname in my dhcp requests, so the bug may be coming from this line above. Calling orders sometimes vary and I have not yet been able to control this since they are called from espressif binaries.

I have the DHCP hostname with the commented line above, do you ? @dragondaud @caipifrosch

edit: wifi_station_get_hostname() is null at the time it is executed (in my setup).

d-a-v avatar Feb 04 '18 18:02 d-a-v

OK, tried it without real background knowledge here... no success. Manually downloaded lwip2 from git as make download was not working. Make install then gave another error message.

Any idea how to get around this? A link to a guide how to compile lwip would be highly appreciated.

Error message:

C:\develop\Arduino\hardware\ESP8266com\ESP8266\tools\sdk\lwip2>make install MAKE Version 5.41 Copyright (c) 1987, 2014 Embarcadero Technologies, Inc. make -C builder -f Makefile.arduino install MAKE Version 5.41 Copyright (c) 1987, 2014 Embarcadero Technologies, Inc. Incorrect command line argument: -C

caipifrosch avatar Feb 04 '18 19:02 caipifrosch

Can you replace your liblwip2.a and liblwip2_1460.a with these (link) and verify you get the right name in your dhcp server ? (just select the file and click on the download button)

d-a-v avatar Feb 05 '18 11:02 d-a-v

@caipifrosch you would need to use GNU make and gcc to build, looks like you have a commercial tool in your path. If you install GNU Make, and put it in your path before Embarcadero's then it will work.

@d-a-v I'm testing the change now.

dragondaud avatar Feb 05 '18 13:02 dragondaud