Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_dhcp_subnet_option_api_dos_not_work_issue_5.…
Browse files Browse the repository at this point in the history
…1' into 'release/v5.1'

Fix(dhcps):fix dhcp subnet option api dos not work issue 5.1

See merge request espressif/esp-idf!27675
  • Loading branch information
jack0c committed Dec 7, 2023
2 parents 977098e + 97b9c24 commit 493ecf5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions components/esp_netif/lwip/esp_netif_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,23 @@ esp_err_t esp_netif_dhcps_option_api(esp_netif_api_msg_t *msg)
break;
}
case ESP_NETIF_SUBNET_MASK: {
esp_netif_ip_info_t *default_ip = esp_netif->ip_info;
ip4_addr_t *config_netmask = (ip4_addr_t *)opt->val;
if (!memcmp(&default_ip->netmask, config_netmask, sizeof(struct ip4_addr))) {
ESP_LOGE(TAG, "Please use esp_netif_set_ip_info interface to configure subnet mask");
/*
* This API directly changes the subnet mask of dhcp server
* but the subnet mask of the network interface has not changed
* If you need to change the subnet mask of dhcp server
* you need to change the subnet mask of the network interface first.
* If the subnet mask of dhcp server is changed
* and the subnet mask of network interface is inconsistent
* with the subnet mask of dhcp sever, it may lead to the failure of sending packets.
* If want to configure the subnet mask of dhcp server
* please use esp_netif_set_ip_info to change the subnet mask of network interface first.
*/
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
}
memcpy(opt_info, opt->val, opt->len);
break;
}
Expand Down Expand Up @@ -2263,10 +2280,7 @@ esp_err_t esp_netif_dhcps_option_api(esp_netif_api_msg_t *msg)
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);
break;
}
Expand Down

0 comments on commit 493ecf5

Please sign in to comment.