Skip to content

Commit 9063a6c

Browse files
committed
Merge branch 'feat/lwip_netif_callbacks' into 'master'
[lwip]: Add support for netif link callback Closes IDFGH-16317 See merge request espressif/esp-idf!42097
2 parents 726a430 + 16b02ae commit 9063a6c

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

components/lwip/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ menu "LWIP"
560560
help
561561
Enable callbacks when the network interface is up/down and addresses are changed.
562562

563+
config LWIP_NETIF_LINK_CALLBACK
564+
bool "Enable link callback for network interfaces"
565+
default n
566+
help
567+
Enable callbacks when the physical network link is up/down.
568+
563569
menuconfig LWIP_NETIF_LOOPBACK
564570
bool "Support per-interface loopback"
565571
default y

components/lwip/port/include/lwipopts.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
6-
* SPDX-FileContributor: 2015-2024 Espressif Systems (Shanghai) CO LTD
6+
* SPDX-FileContributor: 2015-2025 Espressif Systems (Shanghai) CO LTD
77
*/
88
#ifndef LWIP_HDR_ESP_LWIPOPTS_H
99
#define LWIP_HDR_ESP_LWIPOPTS_H
@@ -725,6 +725,16 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
725725
#define LWIP_NETIF_STATUS_CALLBACK 0
726726
#endif
727727

728+
/**
729+
* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
730+
* whenever the link changes its up/down status.
731+
*/
732+
#ifdef CONFIG_LWIP_NETIF_LINK_CALLBACK
733+
#define LWIP_NETIF_LINK_CALLBACK 1
734+
#else
735+
#define LWIP_NETIF_LINK_CALLBACK 0
736+
#endif
737+
728738
/**
729739
* LWIP_NETIF_EXT_STATUS_CALLBACK==1: Support an extended callback function
730740
* for several netif related event that supports multiple subscribers.

docs/en/api-guides/lwip.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ This approach may not work for function-like macros, as there is no guarantee th
507507

508508
Alternatively, you can define your function-like macro in a header file which will be pre-included as an lwIP hook file, see :ref:`lwip-custom-hooks`.
509509

510+
Network Interface Callbacks
511+
---------------------------
512+
513+
- Status Callback (:ref:`CONFIG_LWIP_NETIF_STATUS_CALLBACK`): Enables `netif_set_status_callback()` to notify when an interface comes up/down and when IPv4/IPv6 addresses change.
514+
- Link Callback (:ref:`CONFIG_LWIP_NETIF_LINK_CALLBACK`): Enables `netif_set_link_callback()` to notify when the physical link goes up/down. The callback is triggered by `netif_set_link_up()` / `netif_set_link_down()` calls in drivers or virtual interfaces. Can be used alongside `LWIP_NETIF_EXT_STATUS_CALLBACK` for richer eventing.
515+
510516
.. _lwip-limitations:
511517

512518
Limitations

docs/zh_CN/api-guides/lwip.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ ESP-IDF 提供了其他可覆盖的 lwIP 钩子,例如:
507507

508508
另一种方法是在头文件中定义函数式宏,该头文件将预先包含在 lwIP 钩子文件中,请参考 :ref:`lwip-custom-hooks`。
509509

510+
网络接口回调
511+
-----------------
512+
513+
- 状态回调 (:ref:`CONFIG_LWIP_NETIF_STATUS_CALLBACK`):启用 `netif_set_status_callback()`,在接口上下线以及 IPv4/IPv6 地址发生变化时通知。
514+
- 链路回调 (:ref:`CONFIG_LWIP_NETIF_LINK_CALLBACK`):启用 `netif_set_link_callback()`,在物理链路上下线时通知。该回调由驱动或虚拟接口调用 `netif_set_link_up()` / `netif_set_link_down()` 触发。可与 `LWIP_NETIF_EXT_STATUS_CALLBACK` 配合使用,以获取更丰富的事件通知。
515+
510516
.. _lwip-limitations:
511517

512518
限制

0 commit comments

Comments
 (0)