Improve dualstack and IPv6 support (#5449)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Jimmy Hedman
2024-02-27 09:16:20 +01:00
committed by GitHub
parent 5e04914a11
commit f73518dbeb
26 changed files with 300 additions and 140 deletions
+4 -1
View File
@@ -5,6 +5,7 @@ from esphome.components.esp32 import add_idf_sdkconfig_option
from esphome.const import (
CONF_ENABLE_IPV6,
CONF_MIN_IPV6_ADDR_COUNT,
)
CODEOWNERS = ["@esphome/core"]
@@ -16,12 +17,14 @@ IPAddress = network_ns.class_("IPAddress")
CONFIG_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE_IPV6, default=False): cv.boolean,
cv.Optional(CONF_MIN_IPV6_ADDR_COUNT, default=0): cv.positive_int,
}
)
async def to_code(config):
cg.add_define("ENABLE_IPV6", config[CONF_ENABLE_IPV6])
cg.add_define("USE_NETWORK_IPV6", config[CONF_ENABLE_IPV6])
cg.add_define("USE_NETWORK_MIN_IPV6_ADDR_COUNT", config[CONF_MIN_IPV6_ADDR_COUNT])
if CORE.using_esp_idf:
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", config[CONF_ENABLE_IPV6])
add_idf_sdkconfig_option(
+9
View File
@@ -77,6 +77,13 @@ struct IPAddress {
}
#endif /* LWIP_IPV6 */
IPAddress(esp_ip4_addr_t *other_ip) { memcpy((void *) &ip_addr_, (void *) other_ip, sizeof(esp_ip4_addr_t)); }
IPAddress(esp_ip_addr_t *other_ip) {
#if LWIP_IPV6
memcpy((void *) &ip_addr_, (void *) other_ip, sizeof(ip_addr_));
#else
memcpy((void *) &ip_addr_, (void *) &other_ip->u_addr.ip4, sizeof(ip_addr_));
#endif
}
operator esp_ip_addr_t() const {
esp_ip_addr_t tmp;
#if LWIP_IPV6
@@ -128,5 +135,7 @@ struct IPAddress {
ip_addr_t ip_addr_;
};
using IPAddresses = std::array<IPAddress, 5>;
} // namespace network
} // namespace esphome
+3 -3
View File
@@ -37,14 +37,14 @@ bool is_disabled() {
return false;
}
network::IPAddress get_ip_address() {
network::IPAddresses get_ip_addresses() {
#ifdef USE_ETHERNET
if (ethernet::global_eth_component != nullptr)
return ethernet::global_eth_component->get_ip_address();
return ethernet::global_eth_component->get_ip_addresses();
#endif
#ifdef USE_WIFI
if (wifi::global_wifi_component != nullptr)
return wifi::global_wifi_component->get_ip_address();
return wifi::global_wifi_component->get_ip_addresses();
#endif
return {};
}
+1 -1
View File
@@ -12,7 +12,7 @@ bool is_connected();
bool is_disabled();
/// Get the active network hostname
std::string get_use_address();
IPAddress get_ip_address();
IPAddresses get_ip_addresses();
} // namespace network
} // namespace esphome