Skip to content

Commit b46b3d1

Browse files
david-cermakDavid Čermák
authored andcommitted
fix(lwip): Fix potential data-race in ping tcpip callback
Need to use tcpip_api_call() instead of tcpip_callback(), since the former waits for the tcpip task to complete and thus prevents potential data races with subsequent TCP/IP tasks.
1 parent d30e4d9 commit b46b3d1

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

components/lwip/apps/ping/ping_sock.c

Lines changed: 7 additions & 9 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
*/
@@ -27,28 +27,26 @@
2727
#include "esp_check.h"
2828

2929
#ifndef CONFIG_LWIP_NETIF_API
30-
31-
#include "lwip/priv/tcpip_priv.h"
3230
// If POSIX NETIF_API not enabled, we need to supply the implementation of if_indextoname()
33-
// using tcpip_callback()
31+
// using tcpip_api_call()
32+
#include "lwip/priv/tcpip_priv.h"
3433

3534
struct tcpip_netif_name {
3635
struct tcpip_api_call_data call;
3736
u8_t ifindex;
3837
char *ifname;
39-
err_t err;
4038
};
4139

42-
static void do_netif_index_to_name(void *ctx)
40+
static err_t do_netif_index_to_name(struct tcpip_api_call_data *msg)
4341
{
44-
struct tcpip_netif_name *params = ctx;
45-
params->err = netif_index_to_name(params->ifindex, params->ifname) ? ERR_OK : ERR_IF;
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;
4644
}
4745

4846
char *if_indextoname(unsigned int ifindex, char *ifname)
4947
{
5048
struct tcpip_netif_name params = { .ifindex = ifindex, .ifname = ifname };
51-
if (tcpip_callback(do_netif_index_to_name, &params) != ERR_OK || params.err != ERR_OK) {
49+
if (tcpip_api_call(do_netif_index_to_name, &params.call) != ERR_OK) {
5250
return NULL;
5351
}
5452
return ifname;

0 commit comments

Comments
 (0)