From 89ba9ebde1e9cafb592752cffa0315685b7cd751 Mon Sep 17 00:00:00 2001 From: xueyunfei Date: Tue, 21 Nov 2023 11:18:43 +0800 Subject: [PATCH] fix(dhcp server):fix set dhcp server poll fail issue --- components/esp_netif/lwip/esp_netif_lwip.c | 24 ++++++++++++++------ components/lwip/apps/dhcpserver/dhcpserver.c | 3 ++- components/lwip/lwip | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 2c046875d7..ca9fd8fe02 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1879,32 +1879,42 @@ esp_err_t esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_m } case REQUESTED_IP_ADDRESS: { esp_netif_ip_info_t info; - uint32_t softap_ip = 0; + uint32_t server_ip = 0; uint32_t start_ip = 0; uint32_t end_ip = 0; + uint32_t range_start_ip = 0; + uint32_t range_end_ip = 0; dhcps_lease_t *poll = opt_val; if (poll->enable) { memset(&info, 0x00, sizeof(esp_netif_ip_info_t)); esp_netif_get_ip_info(esp_netif, &info); - softap_ip = htonl(info.ip.addr); + server_ip = htonl(info.ip.addr); + range_start_ip = server_ip & htonl(info.netmask.addr); + range_end_ip = range_start_ip | ~htonl(info.netmask.addr); + if (server_ip == range_start_ip || server_ip == range_end_ip) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } start_ip = htonl(poll->start_ip.addr); end_ip = htonl(poll->end_ip.addr); /*config ip information can't contain local ip*/ - if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) { + if ((server_ip >= start_ip) && (server_ip <= end_ip)) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } /*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)) { + if (start_ip <= range_start_ip || start_ip >= range_end_ip) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } - if (end_ip - start_ip > DHCPS_MAX_LEASE) { + if (end_ip <= range_start_ip || end_ip >= range_end_ip) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } + + /*The number of configured ip is less than DHCPS_MAX_LEASE*/ + if ((end_ip - start_ip + 1 > DHCPS_MAX_LEASE) || (start_ip >= end_ip)) { return ESP_ERR_ESP_NETIF_INVALID_PARAMS; } } diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 82ddf80e0d..ca7c575a15 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -1116,7 +1116,7 @@ static void dhcps_poll_set(u32_t ip) end_ip = htonl(dhcps_poll.end_ip.addr); /*config ip information can't contain local ip*/ - if ((start_ip <= server_ip) && (server_ip <= end_ip)) { + if ((server_ip >= start_ip) && (server_ip <= end_ip)) { dhcps_poll.enable = false; } else { /*config ip information must be in the same segment as the local ip*/ @@ -1148,6 +1148,7 @@ static void dhcps_poll_set(u32_t ip) dhcps_poll.end_ip.addr = range_end_ip; dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr); dhcps_poll.end_ip.addr = htonl(dhcps_poll.end_ip.addr); + dhcps_poll.enable = true; } } diff --git a/components/lwip/lwip b/components/lwip/lwip index 5d8bf71c84..d3c89e938a 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 5d8bf71c843f52de280b10d9d6e2e0eadc49e126 +Subproject commit d3c89e938aac62c5cd2032628b05900787de5cc8