mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_set_dhcp_server_poll_fail_issue' into 'master'
fix(dhcp server):fix set dhcp server poll fail issue See merge request espressif/esp-idf!25626
This commit is contained in:
commit
41ee651e82
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -2229,34 +2229,43 @@ esp_err_t esp_netif_dhcps_option_api(esp_netif_api_msg_t *msg)
|
||||
}
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
memcpy(opt_info, opt->val, opt->len);
|
||||
|
@ -1178,7 +1178,7 @@ static void dhcps_poll_set(dhcps_t *dhcps, 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*/
|
||||
@ -1211,6 +1211,7 @@ static void dhcps_poll_set(dhcps_t *dhcps, 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user