mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 05:06:32 +00:00
Support for IPv6 link-local zones for esp-idf 5.1 (#19469)
This commit is contained in:
parent
1c6db35d96
commit
f4bc7c34c6
@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Berry make mdns compatible with non-IPv6 builds
|
- Berry make mdns compatible with non-IPv6 builds
|
||||||
- ESP32 Shutter migration (#19454)
|
- ESP32 Shutter migration (#19454)
|
||||||
- ESP32 Shutter multi press button events (#19465)
|
- ESP32 Shutter multi press button events (#19465)
|
||||||
|
- Support for IPv6 link-local zones for esp-idf 5.1 (necessary for Matter)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -567,15 +567,6 @@ bool WifiFindIPv6(IPAddress *ip, bool is_local, const char * if_type = "st") {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// add an IPv6 link-local address to all netif
|
|
||||||
void CreateLinkLocalIPv6(void)
|
|
||||||
{
|
|
||||||
#ifdef ESP32
|
|
||||||
for (auto intf = esp_netif_next(NULL); intf != NULL; intf = esp_netif_next(intf)) {
|
|
||||||
esp_netif_create_ip6_linklocal(intf);
|
|
||||||
}
|
|
||||||
#endif // ESP32
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns only IPv6 global address (no loopback and no link-local)
|
// Returns only IPv6 global address (no loopback and no link-local)
|
||||||
@ -1266,11 +1257,32 @@ bool WifiDNSGetIPv6Priority(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WifiHostByName(const char* aHostname, IPAddress& aResult) {
|
bool WifiHostByName(const char* aHostname, IPAddress& aResult) {
|
||||||
|
#ifdef USE_IPV6
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
// try converting directly to IP
|
||||||
|
if (aResult.fromString(aHostname)) {
|
||||||
|
return true; // we're done
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // USE_IPV6
|
||||||
|
|
||||||
uint32_t dns_start = millis();
|
uint32_t dns_start = millis();
|
||||||
bool success = WiFi.hostByName(aHostname, aResult, Settings->dns_timeout);
|
bool success = WiFi.hostByName(aHostname, aResult, Settings->dns_timeout);
|
||||||
uint32_t dns_end = millis();
|
uint32_t dns_end = millis();
|
||||||
if (success) {
|
if (success) {
|
||||||
// Host name resolved
|
// Host name resolved
|
||||||
|
#ifdef USE_IPV6
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
// check if there is a zone-id
|
||||||
|
// look for '%' in string
|
||||||
|
const char *s = aHostname;
|
||||||
|
while (*s && *s != '%') { s++; }
|
||||||
|
if (*s == '%') {
|
||||||
|
// we have a zone id
|
||||||
|
aResult.setZone(netif_name_to_index(s + 1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // USE_IPV6
|
||||||
if (0xFFFFFFFF != (uint32_t)aResult) {
|
if (0xFFFFFFFF != (uint32_t)aResult) {
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_WIFI "DNS resolved '%s' (%s) in %i ms"), aHostname, aResult.toString().c_str(), dns_end - dns_start);
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_WIFI "DNS resolved '%s' (%s) in %i ms"), aHostname, aResult.toString().c_str(), dns_end - dns_start);
|
||||||
return true;
|
return true;
|
||||||
|
@ -75,6 +75,9 @@ public:
|
|||||||
tmpaddr->sin6_family = AF_INET6;
|
tmpaddr->sin6_family = AF_INET6;
|
||||||
memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16);
|
memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16);
|
||||||
tmpaddr->sin6_port = htons(port);
|
tmpaddr->sin6_port = htons(port);
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
tmpaddr->sin6_scope_id = ip.zone();
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr;
|
struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr;
|
||||||
@ -314,7 +317,6 @@ public:
|
|||||||
struct sockaddr_in *s = (struct sockaddr_in *)&local_address;
|
struct sockaddr_in *s = (struct sockaddr_in *)&local_address;
|
||||||
local_port = ntohs(s->sin_port);
|
local_port = ntohs(s->sin_port);
|
||||||
local_addr = IPAddress((uint32_t)(s->sin_addr.s_addr));
|
local_addr = IPAddress((uint32_t)(s->sin_addr.s_addr));
|
||||||
// return IPAddress((uint32_t)(s->sin_addr.s_addr));
|
|
||||||
}
|
}
|
||||||
#ifdef USE_IPV6
|
#ifdef USE_IPV6
|
||||||
// IPv6, but it might be IPv4 mapped address
|
// IPv6, but it might be IPv4 mapped address
|
||||||
@ -323,10 +325,12 @@ public:
|
|||||||
local_port = ntohs(saddr6->sin6_port);
|
local_port = ntohs(saddr6->sin6_port);
|
||||||
if (T_IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) {
|
if (T_IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) {
|
||||||
local_addr = IPAddress(IPv4, (uint8_t*)saddr6->sin6_addr.s6_addr+12);
|
local_addr = IPAddress(IPv4, (uint8_t*)saddr6->sin6_addr.s6_addr+12);
|
||||||
// return IPAddress(IPv4, (uint8_t*)saddr6->sin6_addr.s6_addr+12);
|
|
||||||
} else {
|
} else {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
local_addr = IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr), saddr6->sin6_scope_id);
|
||||||
|
#else
|
||||||
local_addr = IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr));
|
local_addr = IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr));
|
||||||
// return IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr));
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_IPV6
|
#endif // USE_IPV6
|
||||||
|
@ -79,7 +79,7 @@ extern "C" {
|
|||||||
if (!WifiHostByName(host, addr)){
|
if (!WifiHostByName(host, addr)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// AddLog(LOG_LEVEL_DEBUG, "BRY: udp.begin got host '%s'", addr.toString().c_str());
|
// AddLog(LOG_LEVEL_DEBUG, "BRY: be_udp_send_ntv host '%s'", addr.toString().c_str());
|
||||||
if (!udp->beginPacket(addr, port)) { return 0; }
|
if (!udp->beginPacket(addr, port)) { return 0; }
|
||||||
int bw = udp->write(buf, len);
|
int bw = udp->write(buf, len);
|
||||||
if (!bw) { return 0; }
|
if (!bw) { return 0; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user