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

inappropriate IPv4 address offered by DHCP server (IDFGH-8574) #10024

Closed
3 tasks done
sergioaiello opened this issue Oct 21, 2022 · 19 comments
Closed
3 tasks done

inappropriate IPv4 address offered by DHCP server (IDFGH-8574) #10024

sergioaiello opened this issue Oct 21, 2022 · 19 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@sergioaiello
Copy link

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.

General issue report

Hope this problem has not been previously flagged.

Based on AP networking configuration
IP4_ADDR(&ipInfo.ip, 192,168,200,9);
IP4_ADDR(&ipInfo.gw, 192,168,200,9);
IP4_ADDR(&ipInfo.netmask, 255,255,255,248);
the addresses 192.168.200.8 and 192.168.200.15 should be reserved
Vice versa the HDCP server of the ESP32 AP tried to assign it. The STA does not answer and does not associate.
Note that only three IP addresses has been assigned on 5 available:

  • 192.168.200.12
  • 13
  • 14

I (743059) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.200.15
D (743059) event: no handlers have been registered for event IP_EVENT:2 posted to loop 0x3ffbdc18
D (744349) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffbeb44
D (744489) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffbeb44
I (744489) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.200.15
D (744499) event: no handlers have been registered for event IP_EVENT:2 posted to loop 0x3ffbdc18
D (745739) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffbeb44
D (745929) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffbeb44

I can't clarify the reason why the AP's DHCP svr does not consider the two addresses 192.168.200.10 and .11 (usually they are assigned as expected)

The wireshark trace reports, similarly to lwip's log. a DHCP offer of the 192.168.200.15 address. The STA does not answer to AP's HDCP MSGs

@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 21, 2022
@github-actions github-actions bot changed the title inappropriate IPv4 address offered by DHCP server inappropriate IPv4 address offered by DHCP server (IDFGH-8574) Oct 21, 2022
@xueyunfei998
Copy link

image

@xueyunfei998
Copy link

xueyunfei998 commented Oct 24, 2022

image

I can receive 10 addresses for the test here, and you can modify the address configuration here.

location:esp-idf/components/esp_netif/esp_netif_defaults.c

@sergioaiello
Copy link
Author

@xueyunfei998 / "I can receive 10 addresses for the test here"
Are you saying the DHCP server does offer the IP address to 10 STAs?
If so, I think it is an error since only 8 IP addresses can be used in a /29 subnet. And on top of 8 IP addresses, the DHCP server can offer to STAs only 5.
Please, clarify
Thank you

@xueyunfei998
Copy link

hi @sergioaiello

I mean: according to your configuration, softap can be allocated from the address of 192.168.200.10, not to 10 stas.
image

@sergioaiello
Copy link
Author

sergioaiello commented Oct 25, 2022

hi xueyunfei998,
ok, clear. Thank you.
Have you checked to IPv4 address range?
I experienced that AP does not stop after .14. It offers also .15. That's a bug to me. Isn't it?

@xueyunfei998
Copy link

hi @sergioaiello

Yes, the subnet mask you set has no effect on idf.

@sergioaiello
Copy link
Author

@xueyunfei998
is a /29 mask allowed? will a patch be released?
thank you

@xueyunfei998
Copy link

@sergioaiello
Copy link
Author

Hi xueyunfei998,
thank you for the patch. I see my "dhcpserver.c" is different (I'm using IDF release 4.4)
Please, see here below an excerpt with the "dhcps_poll_set" function.
How can apply your patch?
Thank you.

static void dhcps_poll_set(u32_t ip)
{
u32_t softap_ip = 0, local_ip = 0;
u32_t start_ip = 0;
u32_t end_ip = 0;

if (dhcps_poll.enable == true) {
    softap_ip = htonl(ip);
    start_ip = htonl(dhcps_poll.start_ip.addr);
    end_ip = htonl(dhcps_poll.end_ip.addr);

    /*config ip information can't contain local ip*/
    if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) {
        dhcps_poll.enable = false;
    } else {
        /*config ip information must be in the same segment as the local ip*/
        softap_ip >>= 8;

        if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip))
                || (end_ip - start_ip > DHCPS_MAX_LEASE)) {
            dhcps_poll.enable = false;
        }
    }
}

if (dhcps_poll.enable == false) {
    local_ip = softap_ip = htonl(ip);
    softap_ip &= 0xFFFFFF00;
    local_ip &= 0xFF;

    if (local_ip >= 0x80) {
        local_ip -= DHCPS_MAX_LEASE;
    } else {
        local_ip ++;
    }

    bzero(&dhcps_poll, sizeof(dhcps_poll));
    dhcps_poll.start_ip.addr = softap_ip | local_ip;
    dhcps_poll.end_ip.addr = softap_ip | (local_ip + DHCPS_MAX_LEASE - 1);
    dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr);
    dhcps_poll.end_ip.addr = htonl(dhcps_poll.end_ip.addr);
}

}

@sergioaiello
Copy link
Author

sorry, to enter even though your question was @xueyunfei998, but I'm on hold waiting for a support to test the fix (please, see comment on Nov 19th. Thank you.

@sergioaiello
Copy link
Author

Hi, just loaded ESP-IDF 5.0 I'll test the patch soon.
Thank you.

@sergioaiello
Copy link
Author

Hi, the issue is still there :(
In the "C:\Users\sergi\esp\esp-idf\components\lwip\apps\dhcpserver" folder I edited the file "dhcpserver.c"/"dhcps_poll_set" as follows:
"
....
static void dhcps_poll_set(dhcps_t *dhcps, u32_t ip)
{
u32_t softap_ip = 0, local_ip = 0, temp_local_ip = 0; // u32_t softap_ip = 0, local_ip = 0;
u32_t start_ip = 0;
u32_t end_ip = 0;
dhcps_lease_t *dhcps_poll = &dhcps->dhcps_poll;
if (dhcps_poll->enable == true) {
softap_ip = htonl(ip);
start_ip = htonl(dhcps_poll->start_ip.addr);
end_ip = htonl(dhcps_poll->end_ip.addr);

    /*config ip information can't contain local ip*/
    if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) {
        dhcps_poll->enable = false;
    } else {
        /*config ip information must be in the same segment as the local ip*/
        softap_ip >>= 8;

        if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip))
                || (end_ip - start_ip > DHCPS_MAX_LEASE)) {
            dhcps_poll->enable = false;
        }
    }
}

if (dhcps_poll->enable == false) {
    local_ip = softap_ip = htonl(ip);
    softap_ip &= 0xFFFFFF00;
    temp_local_ip = local_ip &= 0xFF; // local_ip &= 0xFF;

    if (local_ip >= 0x80) {
        local_ip -= DHCPS_MAX_LEASE;
    } else {
        local_ip ++;
    }

    bzero(dhcps_poll, sizeof(*dhcps_poll));
    dhcps_poll->start_ip.addr = softap_ip | local_ip;
    dhcps_poll->end_ip.addr = softap_ip | (temp_local_ip + 0xFFFFFFFF- htonl(dhcps->dhcps_mask.addr) - 1); // dhcps_poll->end_ip.addr = softap_ip | (local_ip + DHCPS_MAX_LEASE - 1);
    dhcps_poll->start_ip.addr = htonl(dhcps_poll->start_ip.addr);
    dhcps_poll->end_ip.addr = htonl(dhcps_poll->end_ip.addr);
}

}
......
"
Is that correct?
If not, please, provide me a document that explains how-to test patches.
Thank you.

@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally and removed Status: Opened Issue is new labels Jan 30, 2023
@AxelLin
Copy link
Contributor

AxelLin commented Feb 22, 2023

@xueyunfei998
Any update? This issue was marked as "Resolution: Done" 3 weeks ago, but I still cannot find the fix in any branch.

@xueyunfei998
Copy link

dhcpserver.txt
hi @sergioaiello

Sorry for not replying in time.

The above is a complete pacth based on version 4.4.

@sergioaiello
Copy link
Author

Please, let me know what to test in IDF v5.0
My last test (about one month ago) was not successful (the patch did not solve the issue ... on the opposite I found an other problem that I did not investigate since not relevant with this case and limited time)

Is the file dhcpserver.txt also relevant for IDF v5.0?
Should it be tested?
Thank you

espressif-bot pushed a commit that referenced this issue Mar 17, 2023
@AxelLin
Copy link
Contributor

AxelLin commented Mar 17, 2023

@xueyunfei998 This bug is also in v4.3: cab17c7, please backport the fix for v4.3.

@AxelLin
Copy link
Contributor

AxelLin commented Mar 27, 2023

@xueyunfei998 v4.3.5 still has this bug.

espressif-bot pushed a commit that referenced this issue Apr 8, 2023
@xueyunfei998
Copy link

hi @sergioaiello

The dhcp address pool allocation algorithm has been revised again. Please use the master version to test it.

hi @AxelLin

dhcp server's new memory pool allocation algorithm has been backport to 4.3.please test

@AxelLin
Copy link
Contributor

AxelLin commented Jul 26, 2023

@xueyunfei998 @mhdong

I have a question regarding the change in espressif/esp-lwip@4f24c9b ,
the commit log tells nothing about what was fixed.

Does this commit fix any issue?
If yes, why not mention it in commit log? and what was actually fixed?
If no, what is the reason to lower the retry backoff time?

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
Projects
None yet
Development

No branches or pull requests

4 participants