mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
Disable IPv6 when config explicitly says false (#5310)
This commit is contained in:
parent
32b24726ed
commit
97dcbe84da
@ -118,10 +118,10 @@ void EthernetComponent::setup() {
|
|||||||
ESPHL_ERROR_CHECK(err, "ETH event handler register error");
|
ESPHL_ERROR_CHECK(err, "ETH event handler register error");
|
||||||
err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetComponent::got_ip_event_handler, nullptr);
|
err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetComponent::got_ip_event_handler, nullptr);
|
||||||
ESPHL_ERROR_CHECK(err, "GOT IP event handler register error");
|
ESPHL_ERROR_CHECK(err, "GOT IP event handler register error");
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
err = esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EthernetComponent::got_ip6_event_handler, nullptr);
|
err = esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EthernetComponent::got_ip6_event_handler, nullptr);
|
||||||
ESPHL_ERROR_CHECK(err, "GOT IP6 event handler register error");
|
ESPHL_ERROR_CHECK(err, "GOT IP6 event handler register error");
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
/* start Ethernet driver state machine */
|
/* start Ethernet driver state machine */
|
||||||
err = esp_eth_start(this->eth_handle_);
|
err = esp_eth_start(this->eth_handle_);
|
||||||
@ -164,7 +164,7 @@ void EthernetComponent::loop() {
|
|||||||
this->state_ = EthernetComponentState::CONNECTING;
|
this->state_ = EthernetComponentState::CONNECTING;
|
||||||
this->start_connect_();
|
this->start_connect_();
|
||||||
}
|
}
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
else if (this->got_ipv6_) {
|
else if (this->got_ipv6_) {
|
||||||
esp_ip6_addr_t ip6_addr;
|
esp_ip6_addr_t ip6_addr;
|
||||||
if (esp_netif_get_ip6_global(this->eth_netif_, &ip6_addr) == 0 &&
|
if (esp_netif_get_ip6_global(this->eth_netif_, &ip6_addr) == 0 &&
|
||||||
@ -177,7 +177,7 @@ void EthernetComponent::loop() {
|
|||||||
|
|
||||||
this->got_ipv6_ = false;
|
this->got_ipv6_ = false;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,14 +272,14 @@ void EthernetComponent::got_ip_event_handler(void *arg, esp_event_base_t event_b
|
|||||||
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP (num=%" PRId32 ")", event_id);
|
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP (num=%" PRId32 ")", event_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
|
void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
|
||||||
void *event_data) {
|
void *event_data) {
|
||||||
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP6 (num=%d)", event_id);
|
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP6 (num=%d)", event_id);
|
||||||
global_eth_component->got_ipv6_ = true;
|
global_eth_component->got_ipv6_ = true;
|
||||||
global_eth_component->ipv6_count_ += 1;
|
global_eth_component->ipv6_count_ += 1;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
void EthernetComponent::start_connect_() {
|
void EthernetComponent::start_connect_() {
|
||||||
this->connect_begin_ = millis();
|
this->connect_begin_ = millis();
|
||||||
@ -343,12 +343,12 @@ void EthernetComponent::start_connect_() {
|
|||||||
if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
|
if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
|
||||||
ESPHL_ERROR_CHECK(err, "DHCPC start error");
|
ESPHL_ERROR_CHECK(err, "DHCPC start error");
|
||||||
}
|
}
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
err = esp_netif_create_ip6_linklocal(this->eth_netif_);
|
err = esp_netif_create_ip6_linklocal(this->eth_netif_);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESPHL_ERROR_CHECK(err, "IPv6 local failed");
|
ESPHL_ERROR_CHECK(err, "IPv6 local failed");
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
}
|
}
|
||||||
|
|
||||||
this->connect_begin_ = millis();
|
this->connect_begin_ = millis();
|
||||||
@ -376,7 +376,7 @@ void EthernetComponent::dump_connect_params_() {
|
|||||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->addr).str().c_str());
|
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->addr).str().c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
if (this->ipv6_count_ > 0) {
|
if (this->ipv6_count_ > 0) {
|
||||||
esp_ip6_addr_t ip6_addr;
|
esp_ip6_addr_t ip6_addr;
|
||||||
esp_netif_get_ip6_linklocal(this->eth_netif_, &ip6_addr);
|
esp_netif_get_ip6_linklocal(this->eth_netif_, &ip6_addr);
|
||||||
@ -387,7 +387,7 @@ void EthernetComponent::dump_connect_params_() {
|
|||||||
ESP_LOGCONFIG(TAG, "IPv6 Addr (Global): " IPV6STR, IPV62STR(ip6_addr));
|
ESP_LOGCONFIG(TAG, "IPv6 Addr (Global): " IPV6STR, IPV62STR(ip6_addr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ CONFIG_SCHEMA = cv.Schema(
|
|||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
if CONF_ENABLE_IPV6 in config:
|
if CONF_ENABLE_IPV6 in config:
|
||||||
|
cg.add_define("ENABLE_IPV6", config[CONF_ENABLE_IPV6])
|
||||||
if CORE.using_esp_idf:
|
if CORE.using_esp_idf:
|
||||||
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", config[CONF_ENABLE_IPV6])
|
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", config[CONF_ENABLE_IPV6])
|
||||||
add_idf_sdkconfig_option(
|
add_idf_sdkconfig_option(
|
||||||
|
@ -447,9 +447,9 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
|
|||||||
buf[it.ssid_len] = '\0';
|
buf[it.ssid_len] = '\0';
|
||||||
ESP_LOGV(TAG, "Event: Connected ssid='%s' bssid=" LOG_SECRET("%s") " channel=%u, authmode=%s", buf,
|
ESP_LOGV(TAG, "Event: Connected ssid='%s' bssid=" LOG_SECRET("%s") " channel=%u, authmode=%s", buf,
|
||||||
format_mac_addr(it.bssid).c_str(), it.channel, get_auth_mode_str(it.authmode));
|
format_mac_addr(it.bssid).c_str(), it.channel, get_auth_mode_str(it.authmode));
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
this->set_timeout(100, [] { WiFi.enableIpV6(); });
|
this->set_timeout(100, [] { WiFi.enableIpV6(); });
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -504,13 +504,13 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
|
|||||||
s_sta_connecting = false;
|
s_sta_connecting = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
case ESPHOME_EVENT_ID_WIFI_STA_GOT_IP6: {
|
case ESPHOME_EVENT_ID_WIFI_STA_GOT_IP6: {
|
||||||
auto it = info.got_ip6.ip6_info;
|
auto it = info.got_ip6.ip6_info;
|
||||||
ESP_LOGV(TAG, "Got IPv6 address=" IPV6STR, IPV62STR(it.ip));
|
ESP_LOGV(TAG, "Got IPv6 address=" IPV6STR, IPV62STR(it.ip));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
case ESPHOME_EVENT_ID_WIFI_STA_LOST_IP: {
|
case ESPHOME_EVENT_ID_WIFI_STA_LOST_IP: {
|
||||||
ESP_LOGV(TAG, "Event: Lost IP");
|
ESP_LOGV(TAG, "Event: Lost IP");
|
||||||
break;
|
break;
|
||||||
|
@ -58,9 +58,9 @@ struct IDFWiFiEvent {
|
|||||||
wifi_event_ap_probe_req_rx_t ap_probe_req_rx;
|
wifi_event_ap_probe_req_rx_t ap_probe_req_rx;
|
||||||
wifi_event_bss_rssi_low_t bss_rssi_low;
|
wifi_event_bss_rssi_low_t bss_rssi_low;
|
||||||
ip_event_got_ip_t ip_got_ip;
|
ip_event_got_ip_t ip_got_ip;
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
ip_event_got_ip6_t ip_got_ip6;
|
ip_event_got_ip6_t ip_got_ip6;
|
||||||
#endif
|
#endif /* ENABLE_IPV6 */
|
||||||
ip_event_ap_staipassigned_t ip_ap_staipassigned;
|
ip_event_ap_staipassigned_t ip_ap_staipassigned;
|
||||||
} data;
|
} data;
|
||||||
};
|
};
|
||||||
@ -84,7 +84,7 @@ void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, voi
|
|||||||
memcpy(&event.data.sta_disconnected, event_data, sizeof(wifi_event_sta_disconnected_t));
|
memcpy(&event.data.sta_disconnected, event_data, sizeof(wifi_event_sta_disconnected_t));
|
||||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||||
memcpy(&event.data.ip_got_ip, event_data, sizeof(ip_event_got_ip_t));
|
memcpy(&event.data.ip_got_ip, event_data, sizeof(ip_event_got_ip_t));
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6) {
|
} else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6) {
|
||||||
memcpy(&event.data.ip_got_ip6, event_data, sizeof(ip_event_got_ip6_t));
|
memcpy(&event.data.ip_got_ip6, event_data, sizeof(ip_event_got_ip6_t));
|
||||||
#endif
|
#endif
|
||||||
@ -645,18 +645,18 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
|||||||
|
|
||||||
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_GOT_IP) {
|
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_GOT_IP) {
|
||||||
const auto &it = data->data.ip_got_ip;
|
const auto &it = data->data.ip_got_ip;
|
||||||
#if LWIP_IPV6_AUTOCONFIG
|
#if ENABLE_IPV6
|
||||||
esp_netif_create_ip6_linklocal(s_sta_netif);
|
esp_netif_create_ip6_linklocal(s_sta_netif);
|
||||||
#endif
|
#endif /* ENABLE_IPV6 */
|
||||||
ESP_LOGV(TAG, "Event: Got IP static_ip=%s gateway=%s", format_ip4_addr(it.ip_info.ip).c_str(),
|
ESP_LOGV(TAG, "Event: Got IP static_ip=%s gateway=%s", format_ip4_addr(it.ip_info.ip).c_str(),
|
||||||
format_ip4_addr(it.ip_info.gw).c_str());
|
format_ip4_addr(it.ip_info.gw).c_str());
|
||||||
s_sta_got_ip = true;
|
s_sta_got_ip = true;
|
||||||
|
|
||||||
#if LWIP_IPV6
|
#if ENABLE_IPV6
|
||||||
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_GOT_IP6) {
|
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_GOT_IP6) {
|
||||||
const auto &it = data->data.ip_got_ip6;
|
const auto &it = data->data.ip_got_ip6;
|
||||||
ESP_LOGV(TAG, "Event: Got IPv6 address=%s", format_ip6_addr(it.ip6_info.ip).c_str());
|
ESP_LOGV(TAG, "Event: Got IPv6 address=%s", format_ip6_addr(it.ip6_info.ip).c_str());
|
||||||
#endif
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_LOST_IP) {
|
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_LOST_IP) {
|
||||||
ESP_LOGV(TAG, "Event: Lost IP");
|
ESP_LOGV(TAG, "Event: Lost IP");
|
||||||
|
Loading…
Reference in New Issue
Block a user