Skip to content

Commit e11a918

Browse files
author
David Čermák
committed
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
2 parents 9342b3f + 42d2a13 commit e11a918

File tree

6 files changed

+24
-53
lines changed

6 files changed

+24
-53
lines changed

components/lwip/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,8 @@ if(CONFIG_LWIP_ENABLE)
100100
"port/hooks/lwip_default_hooks.c"
101101
"port/debug/lwip_debug.c"
102102
"port/sockets_ext.c"
103-
"port/freertos/sys_arch.c")
104-
105-
if(CONFIG_LWIP_NETIF_API)
106-
list(APPEND srcs "port/if_index.c")
107-
endif()
103+
"port/freertos/sys_arch.c"
104+
"port/if_index.c")
108105

109106
if(CONFIG_LWIP_PPP_SUPPORT)
110107
list(APPEND srcs

components/lwip/Kconfig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ menu "LWIP"
1818
The default name this device will report to other devices on the network.
1919
Could be updated at runtime with esp_netif_set_hostname()
2020

21-
config LWIP_NETIF_API
22-
bool "Enable usage of standard POSIX APIs in LWIP"
23-
default n
24-
help
25-
If this feature is enabled, standard POSIX APIs: if_indextoname(), if_nametoindex()
26-
could be used to convert network interface index to name
27-
instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name())
28-
2921
config LWIP_TCPIP_TASK_PRIO
3022
int "LWIP TCP/IP Task Priority"
3123
default 18

components/lwip/apps/ping/ping_sock.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,6 @@
2626
#include "ping/ping_sock.h"
2727
#include "esp_check.h"
2828

29-
#ifndef CONFIG_LWIP_NETIF_API
30-
// If POSIX NETIF_API not enabled, we need to supply the implementation of if_indextoname()
31-
// using tcpip_api_call()
32-
#include "lwip/priv/tcpip_priv.h"
33-
34-
struct tcpip_netif_name {
35-
struct tcpip_api_call_data call;
36-
u8_t ifindex;
37-
char *ifname;
38-
};
39-
40-
static err_t do_netif_index_to_name(struct tcpip_api_call_data *msg)
41-
{
42-
struct tcpip_netif_name *params = __containerof(msg, struct tcpip_netif_name, call);
43-
return netif_index_to_name(params->ifindex, params->ifname) ? ERR_OK : ERR_IF;
44-
}
45-
46-
char *if_indextoname(unsigned int ifindex, char *ifname)
47-
{
48-
struct tcpip_netif_name params = { .ifindex = ifindex, .ifname = ifname };
49-
if (tcpip_api_call(do_netif_index_to_name, &params.call) != ERR_OK) {
50-
return NULL;
51-
}
52-
return ifname;
53-
}
54-
#endif // CONFIG_LWIP_NETIF_API == 0
55-
5629
const static char *TAG = "ping_sock";
5730

5831
#define PING_TIME_DIFF_MS(_end, _start) ((uint32_t)(((_end).tv_sec - (_start).tv_sec) * 1000 + \

components/lwip/port/include/lwipopts.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,18 +709,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
709709
* LWIP_DHCP_DISCOVER_ADD_HOSTNAME==1: include hostname opt in discover packets.
710710
* If the hostname is not set in the DISCOVER packet, then some servers might issue
711711
* an OFFER with hostname configured and consequently reject the REQUEST with any other hostname.
712+
* LWIP_NETIF_API==1: Support netif APIs (if_nametoindex and if_indextoname)
712713
*/
713714
#define LWIP_NETIF_HOSTNAME 1
714715
#define LWIP_DHCP_DISCOVER_ADD_HOSTNAME 1
715-
716-
/**
717-
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
718-
*/
719-
#ifdef CONFIG_LWIP_NETIF_API
720716
#define LWIP_NETIF_API 1
721-
#else
722-
#define LWIP_NETIF_API 0
723-
#endif
724717

725718
/**
726719
* LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#pragma once
7+
8+
// Need to provide declarations of if_nametoindex and if_indextoname functions
9+
// as we don't want to bring lwip specific defines
10+
// (since we're on linux target and likely using linux tcp/ip stack)
11+
12+
/**
13+
* @brief Get the interface index for the given interface name.
14+
* @param ifname The interface name.
15+
* @return The interface index.
16+
*/
17+
unsigned int if_nametoindex(const char *ifname);
18+
19+
/**
20+
* @brief Get the interface name for the given interface index.
21+
*
22+
* @param ifindex The interface index.
23+
* @param ifname The buffer to store the interface name.
24+
* @return char* The interface name.
25+
*/
26+
char *if_indextoname(unsigned int ifindex, char *ifname);

examples/protocols/sockets/tcp_client_multi_net/main/tcp_client_multiple.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ static void app_multiple_handle(esp_ip4_addr_t *ip4_addr, esp_netif_t *esp_netif
4646
*/
4747
#if CONFIG_EXAMPLE_BIND_SOCKET_TO_NETIF_NAME
4848
struct ifreq ifr;
49-
#if !CONFIG_LWIP_NETIF_API
50-
esp_netif_get_netif_impl_name(esp_netif, ifr.ifr_name);
51-
#else
5249
if_indextoname(esp_netif_get_netif_impl_index(esp_netif), ifr.ifr_name);
53-
#endif
5450
int ret = setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(struct ifreq));
5551
if (ret < 0) {
5652
ESP_LOGE(TAG, "\"%s\" Unable to bind socket to specified interface: errno %d", netif_name, errno);

0 commit comments

Comments
 (0)