mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 21:54:33 +02:00
Merge branch 'fix_ot_src_addr_select_v5.4' into 'release/v5.4'
Fix ot src addr select (v5.4) See merge request espressif/esp-idf!40874
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -153,21 +153,29 @@ static err_t openthread_netif_init(struct netif *netif)
|
|||||||
|
|
||||||
const ip_addr_t *lwip_hook_ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest)
|
const ip_addr_t *lwip_hook_ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest)
|
||||||
{
|
{
|
||||||
const ip6_addr_t *cur_addr;
|
ip6_addr_t cand_addr = { 0 };
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
|
otError err = OT_ERROR_NONE;
|
||||||
// Only process with ot netif.
|
// Only process with ot netif.
|
||||||
if (!(netif->name[0] == 'o' && netif->name[1] == 't')) {
|
if (!(netif->name[0] == 'o' && netif->name[1] == 't')) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Currently, prefer the address with the same prefix of the destination address.
|
otMessageInfo message_info = { 0 };
|
||||||
// If no address found, return NULL for selection source address using the default algorithm.
|
memcpy(message_info.mPeerAddr.mFields.m32, dest->addr, sizeof(message_info.mPeerAddr.mFields.m32));
|
||||||
for (idx = 0; idx < LWIP_IPV6_NUM_ADDRESSES; idx++) {
|
otInstance *instance = esp_openthread_get_instance();
|
||||||
if (!ip6_addr_isvalid(netif_ip6_addr_state(netif, idx))) {
|
esp_openthread_task_switching_lock_acquire(portMAX_DELAY);
|
||||||
continue;
|
err = otIp6SelectSourceAddress(instance, &message_info);
|
||||||
}
|
esp_openthread_task_switching_lock_release();
|
||||||
cur_addr = netif_ip6_addr(netif, idx);
|
if (err == OT_ERROR_NONE) {
|
||||||
if (ip6_addr_netcmp_zoneless(cur_addr, dest)) {
|
// If a Src address was selected by the OT stack, use this address.
|
||||||
return netif_ip_addr6(netif, idx);
|
memcpy(cand_addr.addr, message_info.mSockAddr.mFields.m32, sizeof(cand_addr.addr));
|
||||||
|
for (idx = 0; idx < LWIP_IPV6_NUM_ADDRESSES; idx++) {
|
||||||
|
if (!ip6_addr_isvalid(netif_ip6_addr_state(netif, idx))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ip6_addr_zoneless_eq(netif_ip6_addr(netif, idx), &cand_addr)) {
|
||||||
|
return netif_ip_addr6(netif, idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -106,9 +106,13 @@ static void process_thread_address(const otIp6AddressInfo *address_info, bool is
|
|||||||
} else {
|
} else {
|
||||||
ip_event_add_ip6_t add_addr;
|
ip_event_add_ip6_t add_addr;
|
||||||
add_addr.addr = addr;
|
add_addr.addr = addr;
|
||||||
// if an address is not mesh local or link local, we set preferred for this address.
|
// Only mark the address as preferred if
|
||||||
add_addr.preferred =
|
// it is marked preferred by OpenThread and it is neither a mesh-local nor a link-local address.
|
||||||
is_mesh_local_addr(address_info->mAddress) || is_link_local_addr(address_info->mAddress) ? 0 : 1;
|
if (address_info->mPreferred == 0 || is_mesh_local_addr(address_info->mAddress) || is_link_local_addr(address_info->mAddress)) {
|
||||||
|
add_addr.preferred = 0;
|
||||||
|
} else {
|
||||||
|
add_addr.preferred = 1;
|
||||||
|
}
|
||||||
if (esp_event_post(OPENTHREAD_EVENT, OPENTHREAD_EVENT_GOT_IP6, &add_addr, sizeof(add_addr), 0) != ESP_OK) {
|
if (esp_event_post(OPENTHREAD_EVENT, OPENTHREAD_EVENT_GOT_IP6, &add_addr, sizeof(add_addr), 0) != ESP_OK) {
|
||||||
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to post OpenThread got ip6 address event");
|
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to post OpenThread got ip6 address event");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user