mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'openthread/disable_ipv4' into 'master'
openthread: Fix errors after disabling IPv4 in LwIP See merge request espressif/esp-idf!22658
This commit is contained in:
commit
e995db71c1
@ -129,6 +129,11 @@ if(CONFIG_OPENTHREAD_ENABLED)
|
||||
-Wno-maybe-uninitialized)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_OPENTHREAD_DNS64_CLIENT)
|
||||
list(APPEND exclude_srcs
|
||||
"port/esp_openthread_dns64.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_OPENTHREAD_FTD)
|
||||
set(device_type "OPENTHREAD_FTD=1")
|
||||
elseif(CONFIG_OPENTHREAD_MTD)
|
||||
|
@ -152,7 +152,7 @@ menu "OpenThread"
|
||||
|
||||
config OPENTHREAD_DNS64_CLIENT
|
||||
bool "Use dns64 client"
|
||||
depends on OPENTHREAD_ENABLED
|
||||
depends on OPENTHREAD_ENABLED && LWIP_IPV4
|
||||
default n
|
||||
help
|
||||
Select this option to acquire NAT64 address from dns servers.
|
||||
|
@ -134,7 +134,9 @@ static err_t openthread_netif_init(struct netif *netif)
|
||||
memset(netif->hwaddr, 0, sizeof(netif->hwaddr));
|
||||
netif->mtu = OPENTHREAD_IP6_MTU;
|
||||
netif->flags = NETIF_FLAG_BROADCAST;
|
||||
#if CONFIG_LWIP_IPV4
|
||||
netif->output = NULL;
|
||||
#endif
|
||||
netif->output_ip6 = openthread_output_ip6;
|
||||
netif->mld_mac_filter = openthread_netif_multicast_handler;
|
||||
netif_set_link_up(netif);
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
#include "esp_check.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_netif.h"
|
||||
@ -15,8 +17,6 @@
|
||||
#include "esp_openthread_lock.h"
|
||||
#include "esp_openthread_netif_glue.h"
|
||||
#include "esp_openthread_task_queue.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "lwip/ip6.h"
|
||||
@ -88,6 +88,7 @@ static ip_addr_t map_openthread_addr_to_lwip_addr(const otIp6Address *address)
|
||||
ip_addr_t addr;
|
||||
|
||||
memcpy(ip_2_ip6(&addr)->addr, address->mFields.m8, sizeof(ip_2_ip6(&addr)->addr));
|
||||
#if CONFIG_LWIP_IPV4
|
||||
if (ip6_addr_isipv4mappedipv6(ip_2_ip6(&addr))) {
|
||||
unmap_ipv4_mapped_ipv6(ip_2_ip4(&addr), ip_2_ip6(&addr));
|
||||
addr.type = IPADDR_TYPE_V4;
|
||||
@ -95,8 +96,13 @@ static ip_addr_t map_openthread_addr_to_lwip_addr(const otIp6Address *address)
|
||||
addr.type = IPADDR_TYPE_V6;
|
||||
#if LWIP_IPV6_SCOPES
|
||||
addr.u_addr.ip6.zone = IP6_NO_ZONE;
|
||||
#endif
|
||||
#endif // LWIP_IPV6_SCOPES
|
||||
}
|
||||
#else
|
||||
#if LWIP_IPV6_SCOPES
|
||||
addr.zone = IP6_NO_ZONE;
|
||||
#endif // LWIP_IPV6_SCOPES
|
||||
#endif // CONFIG_LWIP_IPV4
|
||||
return addr;
|
||||
}
|
||||
|
||||
@ -106,7 +112,7 @@ static void udp_recv_task(void *ctx)
|
||||
|
||||
otMessageInfo message_info;
|
||||
otMessage *message = NULL;
|
||||
otMessageSettings msg_settings = {.mLinkSecurityEnabled = false, .mPriority = OT_MESSAGE_PRIORITY_NORMAL};
|
||||
otMessageSettings msg_settings = { .mLinkSecurityEnabled = false, .mPriority = OT_MESSAGE_PRIORITY_NORMAL };
|
||||
struct pbuf *recv_buf = task->recv_buf;
|
||||
uint8_t *data_buf = (uint8_t *)recv_buf->payload;
|
||||
uint8_t *data_buf_to_free = NULL;
|
||||
@ -115,9 +121,11 @@ static void udp_recv_task(void *ctx)
|
||||
memset(&message_info.mSockAddr, 0, sizeof(message_info.mSockAddr));
|
||||
message_info.mHopLimit = task->hop_limit;
|
||||
message_info.mPeerPort = task->port;
|
||||
#if CONFIG_LWIP_IPV4
|
||||
if (task->addr.type == IPADDR_TYPE_V4) {
|
||||
ip4_2_ipv4_mapped_ipv6(ip_2_ip6(&task->addr), ip_2_ip4(&task->addr));
|
||||
}
|
||||
#endif
|
||||
memcpy(&message_info.mPeerAddr, ip_2_ip6(&task->addr)->addr, sizeof(message_info.mPeerAddr));
|
||||
|
||||
if (recv_buf->next != NULL) {
|
||||
@ -150,7 +158,9 @@ static void handle_udp_recv(void *ctx, struct udp_pcb *pcb, struct pbuf *p, cons
|
||||
{
|
||||
udp_recv_task_t *task = (udp_recv_task_t *)malloc(sizeof(udp_recv_task_t));
|
||||
const struct ip6_hdr *ip6_hdr = ip6_current_header();
|
||||
#if CONFIG_LWIP_IPV4
|
||||
const struct ip_hdr *ip4_hdr = ip4_current_header();
|
||||
#endif
|
||||
struct netif *source_netif = ip_current_netif();
|
||||
|
||||
if (task == NULL) {
|
||||
@ -160,7 +170,11 @@ static void handle_udp_recv(void *ctx, struct udp_pcb *pcb, struct pbuf *p, cons
|
||||
task->recv_buf = p;
|
||||
task->addr = *addr;
|
||||
task->port = port;
|
||||
#if CONFIG_LWIP_IPV4
|
||||
task->hop_limit = (addr->type == IPADDR_TYPE_V6) ? IP6H_HOPLIM(ip6_hdr) : IPH_TTL(ip4_hdr);
|
||||
#else
|
||||
task->hop_limit = IP6H_HOPLIM(ip6_hdr);
|
||||
#endif
|
||||
task->is_host_interface =
|
||||
(netif_get_index(source_netif) == esp_netif_get_netif_impl_index(esp_openthread_get_backbone_netif()));
|
||||
|
||||
@ -182,7 +196,7 @@ otError otPlatUdpSocket(otUdpSocket *udp_socket)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
udp_new_task_t task = {.source_task = xTaskGetCurrentTaskHandle(), .socket = udp_socket};
|
||||
udp_new_task_t task = { .source_task = xTaskGetCurrentTaskHandle(), .socket = udp_socket };
|
||||
tcpip_callback(udp_new_task, &task);
|
||||
wait_for_task_notification();
|
||||
VerifyOrExit(task.pcb_ret != NULL, error = OT_ERROR_FAILED);
|
||||
@ -227,7 +241,9 @@ otError otPlatUdpBind(otUdpSocket *udp_socket)
|
||||
};
|
||||
ESP_LOGI(OT_PLAT_LOG_TAG, "Platform UDP bound to port %d", udp_socket->mSockName.mPort);
|
||||
|
||||
#if CONFIG_LWIP_IPV4
|
||||
task.addr.type = IPADDR_TYPE_ANY;
|
||||
#endif
|
||||
memcpy(ip_2_ip6(&task.addr)->addr, udp_socket->mSockName.mAddress.mFields.m8, sizeof(ip_2_ip6(&task.addr)->addr));
|
||||
tcpip_callback(udp_bind_task, &task);
|
||||
wait_for_task_notification();
|
||||
@ -313,10 +329,16 @@ static void udp_send_task(void *ctx)
|
||||
task->pcb->ttl = task->hop_limit;
|
||||
task->pcb->netif_idx = task->netif_index;
|
||||
#if LWIP_IPV6_SCOPES
|
||||
if (task->peer_addr.type == IPADDR_TYPE_V6) {
|
||||
#if CONFIG_LWIP_IPV4
|
||||
if (task->peer_addr.type == IPADDR_TYPE_V6)
|
||||
#endif
|
||||
{
|
||||
ip_2_ip6(&task->peer_addr)->zone = task->netif_index;
|
||||
}
|
||||
if (task->source_addr.type == IPADDR_TYPE_V6) {
|
||||
#if CONFIG_LWIP_IPV4
|
||||
if (task->source_addr.type == IPADDR_TYPE_V6)
|
||||
#endif
|
||||
{
|
||||
ip_2_ip6(&task->source_addr)->zone = task->netif_index;
|
||||
}
|
||||
#endif
|
||||
@ -343,8 +365,11 @@ exit:
|
||||
|
||||
static inline bool is_addr_ip6_any(const ip_addr_t *addr)
|
||||
{
|
||||
return addr->type == IPADDR_TYPE_V6 && addr->u_addr.ip6.addr[0] == 0 && addr->u_addr.ip6.addr[1] == 0 &&
|
||||
addr->u_addr.ip6.addr[2] == 0 && addr->u_addr.ip6.addr[3] == 0;
|
||||
return ip_2_ip6(addr)->addr[0] == 0 && ip_2_ip6(addr)->addr[1] == 0 && ip_2_ip6(addr)->addr[2] == 0 && ip_2_ip6(addr)->addr[3] == 0
|
||||
#if CONFIG_LWIP_IPV4
|
||||
&& addr->type == IPADDR_TYPE_V6
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
otError otPlatUdpSend(otUdpSocket *udp_socket, otMessage *message, const otMessageInfo *message_info)
|
||||
@ -362,9 +387,11 @@ otError otPlatUdpSend(otUdpSocket *udp_socket, otMessage *message, const otMessa
|
||||
task->netif_index = NETIF_NO_INDEX;
|
||||
task->source_addr = map_openthread_addr_to_lwip_addr(&message_info->mSockAddr);
|
||||
task->peer_addr = map_openthread_addr_to_lwip_addr(&message_info->mPeerAddr);
|
||||
#if CONFIG_LWIP_IPV4
|
||||
if (task->peer_addr.type == IPADDR_TYPE_V4 && is_addr_ip6_any(&task->source_addr)) {
|
||||
task->source_addr.type = IPADDR_TYPE_ANY;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_link_local(&message_info->mPeerAddr) || is_multicast(&message_info->mPeerAddr)) {
|
||||
task->netif_index = get_netif_index(message_info->mIsHostInterface ? OT_NETIF_BACKBONE : OT_NETIF_THREAD);
|
||||
|
Loading…
Reference in New Issue
Block a user