From 86089be928599c3ff6181ab58b0bcf980aa517c1 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 20 Dec 2024 08:16:25 +0100 Subject: [PATCH] feat(lwip): Hardcode NETIF_API=1 to support POSIX netif API --- components/lwip/CMakeLists.txt | 7 ++----- components/lwip/Kconfig | 8 -------- components/lwip/port/include/lwipopts.h | 9 +-------- components/lwip/port/linux/include/net/if.h | 22 ++++++++++++++++++++- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/components/lwip/CMakeLists.txt b/components/lwip/CMakeLists.txt index 6fb648f5d6..4daec4c224 100644 --- a/components/lwip/CMakeLists.txt +++ b/components/lwip/CMakeLists.txt @@ -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 diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index bbaa605f93..04b20b1702 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -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 diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index 3a7671472d..b3c9df8d86 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -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 diff --git a/components/lwip/port/linux/include/net/if.h b/components/lwip/port/linux/include/net/if.h index e3c24eb941..2d980f6e8b 100644 --- a/components/lwip/port/linux/include/net/if.h +++ b/components/lwip/port/linux/include/net/if.h @@ -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);