-
Notifications
You must be signed in to change notification settings - Fork 145
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
[examples]: Make multi-netif example working with DNS_PER_DEFAULT_NETIF #609
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
|
@@ -23,9 +23,9 @@ | |
#include "nvs_flash.h" | ||
#include "iface_info.h" | ||
|
||
iface_info_t *eth_init(int prio); | ||
iface_info_t *wifi_init(int prio); | ||
iface_info_t *ppp_init(int prio); | ||
iface_info_t *example_eth_init(int prio); | ||
iface_info_t *example_wifi_init(int prio); | ||
iface_info_t *example_ppp_init(int prio); | ||
esp_err_t check_connectivity(const char *host); | ||
|
||
#define HOST "www.espressif.com" | ||
|
@@ -69,13 +69,15 @@ void app_main(void) | |
|
||
// all interfaces | ||
iface_info_t *ifaces[] = { | ||
eth_init(ETH_PRIO), | ||
wifi_init(WIFI_PRIO), | ||
ppp_init(PPP_PRIO), | ||
example_eth_init(ETH_PRIO), | ||
example_wifi_init(WIFI_PRIO), | ||
example_ppp_init(PPP_PRIO), | ||
}; | ||
size_t num_of_ifaces = sizeof(ifaces) / sizeof(ifaces[0]); | ||
|
||
while (true) { | ||
// For demonstration purposes we clear DNS table every iteration to exercise | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we try to move this out of a loop and have it set twice only? One with the regular expected way users would do and after that we clean and do as demo? We could consider keep the loop as is as long as we have once the expected way clearly stated. |
||
// a condition of DNS servers being misconfigured | ||
dns_clear_cache(); | ||
vTaskDelay(pdMS_TO_TICKS(2000)); | ||
ssize_t i = get_default(ifaces, num_of_ifaces); | ||
|
@@ -91,7 +93,9 @@ void app_main(void) | |
continue; | ||
} | ||
if (connect_status == ESP_ERR_NOT_FOUND) { | ||
#ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF | ||
// set the default DNS info to global DNS server list | ||
// manually if DNS_PER_DEFAULT_NETIF if OFF or not-supported | ||
for (int j = 0; j < 2; ++j) { | ||
esp_netif_dns_info_t dns_info; | ||
esp_netif_get_dns_info(ifaces[i]->netif, j, &dns_info); | ||
|
@@ -102,6 +106,12 @@ void app_main(void) | |
ESP_LOGI(TAG, "Reconfigured DNS%i=" IPSTR, j, IP2STR(&ifaces[i]->dns[j].ip.u_addr.ip4)); | ||
} | ||
} | ||
#else | ||
// simulate that the (default) netif is brought UP | ||
// this is only needed, since we explicitly clear DNS servers every iteration using dns_clear_cache() | ||
// (for demonstration purpose only, won't be needed in your project, unless you delete DNS info for some reasons) | ||
esp_netif_action_connected(ifaces[i]->netif, NULL, 0, NULL); | ||
#endif | ||
} | ||
if (connect_status == ESP_FAIL) { | ||
ESP_LOGE(TAG, "No connection via the default netif!"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# You can use CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect this to be the default for users? If so, we should enable it here and point in README how to disable. |
||
# to perform DNS server updates automatically in esp_netif layers | ||
# instead of manually as it is demonstrated in this example | ||
CONFIG_LWIP_PPP_SUPPORT=y | ||
CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth to add a subsection for the DNS part to improve reading.