Skip to content

Commit c9c3e4e

Browse files
committed
fix(esp_netif): Remove deprecated APIs
1 parent 34f658a commit c9c3e4e

File tree

4 files changed

+134
-28
lines changed

4 files changed

+134
-28
lines changed

components/esp_netif/esp_netif_objects.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -71,13 +71,6 @@ size_t esp_netif_get_nr_of_ifs(void)
7171
return s_esp_netif_counter;
7272
}
7373

74-
// This API is inherently unsafe
75-
// suggest that users call from esp_netif_tcpip_exec()
76-
esp_netif_t* esp_netif_next(esp_netif_t* netif)
77-
{
78-
return esp_netif_next_unsafe(netif);
79-
}
80-
8174
esp_netif_t* esp_netif_next_unsafe(esp_netif_t* netif)
8275
{
8376
ESP_LOGV(TAG, "%s %p", __func__, netif);

components/esp_netif/include/esp_netif.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -981,25 +981,6 @@ int esp_netif_set_route_prio(esp_netif_t *esp_netif, int route_prio);
981981
int32_t esp_netif_get_event_id(esp_netif_t *esp_netif, esp_netif_ip_event_type_t event_type);
982982

983983

984-
/**
985-
* @brief Iterates over list of interfaces. Returns first netif if NULL given as parameter
986-
*
987-
* @note This API doesn't lock the list, nor the TCPIP context, as this it's usually required
988-
* to get atomic access between iteration steps rather that within a single iteration.
989-
* Therefore it is recommended to iterate over the interfaces inside esp_netif_tcpip_exec()
990-
*
991-
* @note This API is deprecated. Please use esp_netif_next_unsafe() directly if all the system
992-
* interfaces are under your control and you can safely iterate over them.
993-
* Otherwise, iterate over interfaces using esp_netif_tcpip_exec(), or use esp_netif_find_if()
994-
* to search in the list of netifs with defined predicate.
995-
*
996-
* @param[in] esp_netif Handle to esp-netif instance
997-
*
998-
* @return First netif from the list if supplied parameter is NULL, next one otherwise
999-
*/
1000-
esp_netif_t *esp_netif_next(esp_netif_t *esp_netif)
1001-
__attribute__((deprecated("use esp_netif_next_unsafe() either directly or via esp_netif_tcpip_exec")));
1002-
1003984
/**
1004985
* @brief Iterates over list of interfaces without list locking. Returns first netif if NULL given as parameter
1005986
*

docs/en/migration-guides/release-6.x/6.0/networking.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,69 @@ Removed the following RMII clock Kconfig options from `components/esp_eth`. Cloc
4242
4343
**Impact**: Applications using ``ETH_ESP32_EMAC_DEFAULT_CONFIG()`` continue to work. Custom clock configurations must be set explicitly in the EMAC config structure or use the `Ethernet Init component <https://components.espressif.com/components/espressif/ethernet_init>`_.
4444

45+
46+
ESP-NETIF
47+
*********
48+
49+
Removal of deprecated :cpp:func:`esp_netif_next`
50+
------------------------------------------------
51+
52+
The deprecated iteration helper :cpp:func:`esp_netif_next` has been removed from :doc:`/api-reference/network/esp_netif`. This API was inherently unsafe because it did not lock the interface list or the TCP/IP context during iteration.
53+
54+
Use one of the following alternatives:
55+
56+
- Directly call :cpp:func:`esp_netif_next_unsafe` only in contexts you fully control, or inside :cpp:func:`esp_netif_tcpip_exec` for safe execution within the TCP/IP context.
57+
- Use :cpp:func:`esp_netif_find_if` with a predicate to search for specific interfaces without manual iteration.
58+
59+
Migration
60+
~~~~~~~~~
61+
62+
Before:
63+
64+
.. code-block:: c
65+
66+
esp_netif_t *it = NULL;
67+
while ((it = esp_netif_next(it)) != NULL) {
68+
// use "it"
69+
}
70+
71+
After (iterate unsafely in a controlled context):
72+
73+
.. code-block:: c
74+
75+
esp_netif_t *it = NULL;
76+
while ((it = esp_netif_next_unsafe(it)) != NULL) {
77+
// use "it"
78+
}
79+
80+
Recommended (iterate within TCP/IP context):
81+
82+
.. code-block:: c
83+
84+
static esp_err_t iterate_netifs(void *ctx)
85+
{
86+
esp_netif_t *it = NULL;
87+
while ((it = esp_netif_next_unsafe(it)) != NULL) {
88+
// use "it"
89+
}
90+
return ESP_OK;
91+
}
92+
93+
// Execute iteration safely in TCP/IP context
94+
ESP_ERROR_CHECK(esp_netif_tcpip_exec(iterate_netifs, NULL));
95+
96+
Alternative (find with predicate):
97+
98+
.. code-block:: c
99+
100+
static bool match_by_key(void *ctx, esp_netif_t *netif)
101+
{
102+
const char *wanted = (const char *)ctx;
103+
const char *key = esp_netif_get_ifkey(netif);
104+
return key && strcmp(key, wanted) == 0;
105+
}
106+
107+
esp_netif_t *target = esp_netif_find_if(match_by_key, (void *)"WIFI_STA_DEF");
108+
if (target) {
109+
// use "target"
110+
}

docs/zh_CN/migration-guides/release-6.x/6.0/networking.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,69 @@
4242
4343
**影响**:使用 ``ETH_ESP32_EMAC_DEFAULT_CONFIG()`` 的应用程序可继续正常工作。自定义时钟配置需在 EMAC 配置结构体中显式设置,或使用 `Ethernet Init 组件 <https://components.espressif.com/components/espressif/ethernet_init>`_。
4444

45+
46+
ESP-NETIF
47+
*********
48+
49+
移除弃用的 :cpp:func:`esp_netif_next`
50+
-------------------------------------
51+
52+
已从 :doc:`/api-reference/network/esp_netif` 中移除弃用的迭代辅助函数 :cpp:func:`esp_netif_next`。该 API 在迭代过程中不会对接口列表或 TCP/IP 上下文进行加锁,因而并不安全。
53+
54+
请使用以下替代方案:
55+
56+
- 仅在完全可控的上下文中直接调用 :cpp:func:`esp_netif_next_unsafe`,或在 :cpp:func:`esp_netif_tcpip_exec` 中执行以保证在 TCP/IP 上下文内安全运行。
57+
- 使用 :cpp:func:`esp_netif_find_if` 并配合谓词查找特定接口,从而避免手动迭代。
58+
59+
迁移方式
60+
~~~~~~~~~
61+
62+
之前:
63+
64+
.. code-block:: c
65+
66+
esp_netif_t *it = NULL;
67+
while ((it = esp_netif_next(it)) != NULL) {
68+
// 使用 "it"
69+
}
70+
71+
之后(在可控上下文中进行不加锁迭代):
72+
73+
.. code-block:: c
74+
75+
esp_netif_t *it = NULL;
76+
while ((it = esp_netif_next_unsafe(it)) != NULL) {
77+
// 使用 "it"
78+
}
79+
80+
推荐方式(在 TCP/IP 上下文中迭代):
81+
82+
.. code-block:: c
83+
84+
static esp_err_t iterate_netifs(void *ctx)
85+
{
86+
esp_netif_t *it = NULL;
87+
while ((it = esp_netif_next_unsafe(it)) != NULL) {
88+
// 使用 "it"
89+
}
90+
return ESP_OK;
91+
}
92+
93+
// 在 TCP/IP 上下文中安全执行迭代
94+
ESP_ERROR_CHECK(esp_netif_tcpip_exec(iterate_netifs, NULL));
95+
96+
替代方式(使用谓词查找):
97+
98+
.. code-block:: c
99+
100+
static bool match_by_key(void *ctx, esp_netif_t *netif)
101+
{
102+
const char *wanted = (const char *)ctx;
103+
const char *key = esp_netif_get_ifkey(netif);
104+
return key && strcmp(key, wanted) == 0;
105+
}
106+
107+
esp_netif_t *target = esp_netif_find_if(match_by_key, (void *)"WIFI_STA_DEF");
108+
if (target) {
109+
// 使用 "target"
110+
}

0 commit comments

Comments
 (0)