Unable to start DHCP server on ethernet port

MikeMyhre
Posts: 54
Joined: Sat Nov 05, 2022 3:32 am

Unable to start DHCP server on ethernet port

Postby MikeMyhre » Sun Aug 18, 2024 2:25 pm

I am using IDF version 5.2.1 and an ESP32-WROOM module.
I have a KSZ8863 3 port switch that provides two Ethernet ports (using 2 port mode). Everything is working well sending packets through the TAP interfaces. ARP, ICMP, UDP packet flow all as expected.
Now I want to take one port and make it an isolated port that provides a DHCP Server to devices connected to that port. The other port can be a static or DHCP client port as configured by the user.
When I try to enable the DHCP server on one or both ports, I get errors.
I have set the appropriate flags in the esp_netif_inherent_config_t structure:

Code: Select all

esp_netif_config.flags &= ~ESP_NETIF_DHCP_CLIENT;
esp_netif_config.flags |= ESP_NETIF_DHCP_SERVER;
esp_netif_config.flags |= ESP_NETIF_AUTOUP;
When I run the code I get the message:
dhcps_start(): could not obtain pcb and
esp_netif_lwip: DHCP server cannot be started.
Looking at the framework code:

Code: Select all

dhcps->dhcps_pcb = udp_new();

if( dhcps->dhcps_pcb == NULL || ip4_addr_isany_val(ip)) {
  DHCPS_LOG("dhcps_start(): could not obtain pcb\n");
  return ERR_ARG;
}
it looks like the two reasons for this would be udp_new() didn't return a valid object for dhcps_pcb (whatever that is), or more likely that the ip4_addr_isany_val(ip) function returned true (guessing it doesn't want the default IP in esp_netif->ip_info to have a value).
Is there some other condition I need to satisfy before bringing up the interface? If the DHCP server is starting, it seems like it would need to have an IP set so it can act as a DHCP server.
Any thoughts?
Thanks!
Mike

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: Unable to start DHCP server on ethernet port

Postby ESP_ondrej » Mon Aug 19, 2024 12:59 pm

Here https://github.com/espressif/esp-eth-dr ... rver.c#L48 is example how to configure DHCP Server. Please don't use `ESP_NETIF_AUTOUP`. That's reserved for WiFi AP mode.

MikeMyhre
Posts: 54
Joined: Sat Nov 05, 2022 3:32 am

Re: Unable to start DHCP server on ethernet port

Postby MikeMyhre » Tue Aug 20, 2024 1:07 am

Awesome.
That worked. Thank you.
If I wanted to take an existing port after being initialized as a non server port, is there a way I can reinitialize it as a DHCP Server port without rebooting?
I can stop the state machine (down the port) but I don't see a way to unattach the glue and do a new config.
Any idea how I would do that?
Thanks,
Mike

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: Unable to start DHCP server on ethernet port

Postby ESP_ondrej » Tue Aug 27, 2024 9:43 am

Sorry for late and short answer. However, I'm super busy with other tasks... Try to go over ESP-NETIF documentation or go over examples. If you don't find anything, I think stopping and starting the netif with different configuration should work. Here is example https://github.com/espressif/esp-idf/bl ... ain.c#L124

Who is online

Users browsing this forum: No registered users and 163 guests