Merge branch 'lwip/enable_netif_api' into 'master'

feat(lwip): Hardcode NETIF_API=1 to support POSIX netif API

See merge request espressif/esp-idf!35841
This commit is contained in:
David Čermák 2025-02-11 19:05:17 +08:00
commit e11a918572
6 changed files with 24 additions and 53 deletions

View File

@ -100,11 +100,8 @@ if(CONFIG_LWIP_ENABLE)
"port/hooks/lwip_default_hooks.c"
"port/debug/lwip_debug.c"
"port/sockets_ext.c"
"port/freertos/sys_arch.c")
if(CONFIG_LWIP_NETIF_API)
list(APPEND srcs "port/if_index.c")
endif()
"port/freertos/sys_arch.c"
"port/if_index.c")
if(CONFIG_LWIP_PPP_SUPPORT)
list(APPEND srcs

View File

@ -18,14 +18,6 @@ menu "LWIP"
The default name this device will report to other devices on the network.
Could be updated at runtime with esp_netif_set_hostname()
config LWIP_NETIF_API
bool "Enable usage of standard POSIX APIs in LWIP"
default n
help
If this feature is enabled, standard POSIX APIs: if_indextoname(), if_nametoindex()
could be used to convert network interface index to name
instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name())
config LWIP_TCPIP_TASK_PRIO
int "LWIP TCP/IP Task Priority"
default 18

View File

@ -26,33 +26,6 @@
#include "ping/ping_sock.h"
#include "esp_check.h"
#ifndef CONFIG_LWIP_NETIF_API
// If POSIX NETIF_API not enabled, we need to supply the implementation of if_indextoname()
// using tcpip_api_call()
#include "lwip/priv/tcpip_priv.h"
struct tcpip_netif_name {
struct tcpip_api_call_data call;
u8_t ifindex;
char *ifname;
};
static err_t do_netif_index_to_name(struct tcpip_api_call_data *msg)
{
struct tcpip_netif_name *params = __containerof(msg, struct tcpip_netif_name, call);
return netif_index_to_name(params->ifindex, params->ifname) ? ERR_OK : ERR_IF;
}
char *if_indextoname(unsigned int ifindex, char *ifname)
{
struct tcpip_netif_name params = { .ifindex = ifindex, .ifname = ifname };
if (tcpip_api_call(do_netif_index_to_name, &params.call) != ERR_OK) {
return NULL;
}
return ifname;
}
#endif // CONFIG_LWIP_NETIF_API == 0
const static char *TAG = "ping_sock";
#define PING_TIME_DIFF_MS(_end, _start) ((uint32_t)(((_end).tv_sec - (_start).tv_sec) * 1000 + \

View File

@ -709,18 +709,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
* LWIP_DHCP_DISCOVER_ADD_HOSTNAME==1: include hostname opt in discover packets.
* If the hostname is not set in the DISCOVER packet, then some servers might issue
* an OFFER with hostname configured and consequently reject the REQUEST with any other hostname.
* LWIP_NETIF_API==1: Support netif APIs (if_nametoindex and if_indextoname)
*/
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_DHCP_DISCOVER_ADD_HOSTNAME 1
/**
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
*/
#ifdef CONFIG_LWIP_NETIF_API
#define LWIP_NETIF_API 1
#else
#define LWIP_NETIF_API 0
#endif
/**
* LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface

View File

@ -1,6 +1,26 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
// Need to provide declarations of if_nametoindex and if_indextoname functions
// as we don't want to bring lwip specific defines
// (since we're on linux target and likely using linux tcp/ip stack)
/**
* @brief Get the interface index for the given interface name.
* @param ifname The interface name.
* @return The interface index.
*/
unsigned int if_nametoindex(const char *ifname);
/**
* @brief Get the interface name for the given interface index.
*
* @param ifindex The interface index.
* @param ifname The buffer to store the interface name.
* @return char* The interface name.
*/
char *if_indextoname(unsigned int ifindex, char *ifname);

View File

@ -46,11 +46,7 @@ static void app_multiple_handle(esp_ip4_addr_t *ip4_addr, esp_netif_t *esp_netif
*/
#if CONFIG_EXAMPLE_BIND_SOCKET_TO_NETIF_NAME
struct ifreq ifr;
#if !CONFIG_LWIP_NETIF_API
esp_netif_get_netif_impl_name(esp_netif, ifr.ifr_name);
#else
if_indextoname(esp_netif_get_netif_impl_index(esp_netif), ifr.ifr_name);
#endif
int ret = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(struct ifreq));
if (ret < 0) {
ESP_LOGE(TAG, "\"%s\" Unable to bind socket to specified interface: errno %d", netif_name, errno);