Skip to content

Commit a786676

Browse files
committed
Merge branch 'bugfix/esp_netif_ppp_set_dns' into 'master'
esp_netif: Allow set_dns_info() for PPP netifs Closes IDFGH-7031 See merge request espressif/esp-idf!21863
2 parents bcc307c + d16c422 commit a786676

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

components/esp_netif/lwip/esp_netif_lwip.c

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,23 +1692,7 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
16921692
esp_netif_dns_type_t type = dns_param->dns_type;
16931693
esp_netif_dns_info_t *dns = dns_param->dns_info;
16941694

1695-
ESP_LOGD(TAG, "%s esp_netif:%p", __func__, esp_netif);
1696-
1697-
if (esp_netif == NULL) {
1698-
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1699-
}
1700-
1701-
if (!dns) {
1702-
ESP_LOGD(TAG, "set dns null dns");
1703-
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1704-
}
1705-
1706-
if (ip4_addr_isany_val(dns->ip.u_addr.ip4)) {
1707-
ESP_LOGD(TAG, "set dns invalid dns");
1708-
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1709-
}
1710-
1711-
ESP_LOGD(TAG, "set dns if=%p type=%d dns=%x", esp_netif, type, dns->ip.u_addr.ip4.addr);
1695+
ESP_LOGD(TAG, "esp_netif_set_dns_info: if=%p type=%d dns=%x", esp_netif, type, dns->ip.u_addr.ip4.addr);
17121696

17131697
ip_addr_t *lwip_ip = (ip_addr_t*)&dns->ip;
17141698
#if CONFIG_LWIP_IPV6 && LWIP_IPV4
@@ -1737,9 +1721,20 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
17371721

17381722
esp_err_t esp_netif_set_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns)
17391723
{
1740-
if (_IS_NETIF_ANY_POINT2POINT_TYPE(esp_netif)) {
1741-
return ESP_ERR_NOT_SUPPORTED;
1724+
if (esp_netif == NULL) {
1725+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1726+
}
1727+
1728+
if (dns == NULL) {
1729+
ESP_LOGD(TAG, "set dns null dns");
1730+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
17421731
}
1732+
1733+
if (ip4_addr_isany_val(dns->ip.u_addr.ip4)) {
1734+
ESP_LOGD(TAG, "set dns invalid dns");
1735+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1736+
}
1737+
17431738
esp_netif_dns_param_t dns_param = {
17441739
.dns_type = type,
17451740
.dns_info = dns
@@ -1754,18 +1749,14 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
17541749
esp_netif_dns_type_t type = dns_param->dns_type;
17551750
esp_netif_dns_info_t *dns = dns_param->dns_info;
17561751

1757-
ESP_LOGD(TAG, "%s esp_netif:%p", __func__, esp_netif);
1758-
1759-
if (!dns) {
1760-
ESP_LOGE(TAG, "%s: dns_info cannot be NULL", __func__);
1761-
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1762-
}
1752+
ESP_LOGD(TAG, "esp_netif_get_dns_info: esp_netif=%p type=%d", esp_netif, type);
17631753

17641754
if (esp_netif->flags & ESP_NETIF_DHCP_SERVER) {
17651755
#if ESP_DHCPS
17661756
ip4_addr_t dns_ip;
17671757
dhcps_dns_getserver(esp_netif->dhcps, &dns_ip);
17681758
memcpy(&dns->ip.u_addr.ip4, &dns_ip, sizeof(ip4_addr_t));
1759+
dns->ip.type = ESP_IPADDR_TYPE_V4;
17691760
#else
17701761
LOG_NETIF_DISABLED_AND_DO("DHCP Server", return ESP_ERR_NOT_SUPPORTED);
17711762
#endif
@@ -1782,17 +1773,13 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
17821773

17831774
esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns)
17841775
{
1785-
if (_IS_NETIF_ANY_POINT2POINT_TYPE(esp_netif)) {
1786-
const ip_addr_t *dns_ip = dns_getserver(type);
1787-
if (dns_ip == IP_ADDR_ANY) {
1788-
return ESP_ERR_ESP_NETIF_DNS_NOT_CONFIGURED;
1789-
}
1790-
#if CONFIG_LWIP_IPV6
1791-
memcpy(&dns->ip.u_addr.ip4, &dns_ip->u_addr.ip4, sizeof(ip4_addr_t));
1792-
#else
1793-
memcpy(&dns->ip.u_addr.ip4, &dns_ip->addr, sizeof(ip4_addr_t));
1794-
#endif
1795-
return ESP_OK;
1776+
if (esp_netif == NULL) {
1777+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
1778+
}
1779+
1780+
if (dns == NULL) {
1781+
ESP_LOGE(TAG, "%s: dns_info cannot be NULL", __func__);
1782+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
17961783
}
17971784

17981785
esp_netif_dns_param_t dns_param = {

0 commit comments

Comments
 (0)