Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESP32S3] v4.4 DHCP Server failing to reuse port (IDFGH-9389) #10762

Closed
3 tasks done
KonssnoK opened this issue Feb 14, 2023 · 8 comments
Closed
3 tasks done

[ESP32S3] v4.4 DHCP Server failing to reuse port (IDFGH-9389) #10762

KonssnoK opened this issue Feb 14, 2023 · 8 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@KonssnoK
Copy link
Contributor

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v4.4.4-116-g00bb43ff24

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

PowerShell

Development Kit.

ESP32S3-WROOM N8R2

Power Supply used.

USB

What is the expected behavior?

DHCP Server to work correctly upon multiple switch on/off.

This scenario happens in a mesh environment where a node can become ROOT and has to provide IP address multiple times to other nodes

What is the actual behavior?

DHCP Server will fail on udp_bind because port 67 was already used.

Steps to reproduce.

  1. Start DHCPS
  2. Stop
  3. Start DHCPS
    ...

Debug Logs.

No response

More Information.

No response

@KonssnoK KonssnoK added the Type: Bug bugs in IDF label Feb 14, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 14, 2023
@github-actions github-actions bot changed the title [ESP32S3] v4.4 DHCP Server failing to reuse port [ESP32S3] v4.4 DHCP Server failing to reuse port (IDFGH-9389) Feb 14, 2023
@KonssnoK
Copy link
Contributor Author

KonssnoK commented Feb 14, 2023

about DHCP Server, the error is the following

D (406106) lwip: udp_bind: local port 67 already bound by another pcb

I have no idea why this is treated as a debugging message when it's a clear error.

the bug is in the DHCP Server

    udp_bind(pcb_dhcps, &netif->ip_addr, DHCPS_SERVER_PORT);
    udp_recv(pcb_dhcps, handle_dhcp, NULL);

Proposed change to DHCPs code

    ip_set_option(pcb_dhcps, SOF_REUSEADDR);

    udp_bind(pcb_dhcps, &netif->ip_addr, DHCPS_SERVER_PORT);

image

@KonssnoK
Copy link
Contributor Author

Reference commit with fix:
1f027d3

@xueyunfei998
Copy link

hi @KonssnoK

I saw your reappearance steps.
1 Start DHCPS
2 Stop
3 Start DHCPS

You should not execute dhcps_stop when you stop.

@KonssnoK
Copy link
Contributor Author

KonssnoK commented Feb 15, 2023

hi @xueyunfei998 ,
what do you mean?
how do i stop using the dhcps if i don't stop it?
Consider that the device will become a mesh node, which does not require dhcps, but only dhcp, and there will be another device with an active dhcps.
Also, according to your in-code documentation
* - To propagate the DNS info to client, please stop the DHCP server before using this API.

@xueyunfei998
Copy link

hi @KonssnoK

D (406106) lwip: udp_bind: local port 67 already bound by another pcb

The reason why this log appears is that the dhcps_start function is called, and the problem will appear when dhcps_start is called without closing dhcps_stop.

I have a question.

Your reproduction steps are as follows.

1 Start DHCPS
2 Stop
3 Start DHCPS

Which function did you stop calling in the second step?

What's wrong now is that the function you called at the time of stop in the second step did not close dhcps.

@KonssnoK
Copy link
Contributor Author

KonssnoK commented Feb 15, 2023

This is the code:

static esp_err_t set_dhcps_dns(esp_netif_t *netif, uint32_t addr)
{
    esp_netif_dns_info_t dns;
    dns.ip.u_addr.ip4.addr = addr;
    dns.ip.type = IPADDR_TYPE_V4;
    dhcps_offer_t dhcps_dns_value = OFFER_DNS;
    // From netif doc: *   - To propagate the DNS info to client, please stop the DHCP server before using this API.
    ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_stop(netif));
    ESP_ERROR_CHECK(esp_netif_dhcps_option(netif, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value)));
    ESP_ERROR_CHECK(esp_netif_set_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns));
    ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_start(netif));
    return ESP_OK;
}

you can find it here :
https://github.com/KonssnoK/esp-idf/tree/bug/mesh_wifi/examples/mesh/ip_internal_network

Please consider also that the dhcp server start does a disconnect + close of the udp pcb, so in theory it should work even without a stop (if the issue was not closing correctly)

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Feb 21, 2023
@xueyunfei998
Copy link

hi @KonssnoK

There is something wrong with this function set_dhcps_dns , and I will fix this bug later.

@KonssnoK
Copy link
Contributor Author

@xueyunfei998 ok thanks, keep us updated. Meanwhile, we continue to use the reuseaddr as workaround!

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Mar 24, 2023
espressif-bot pushed a commit that referenced this issue Apr 8, 2023
espressif-bot pushed a commit that referenced this issue Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants