Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak/deadlock in netif_loop_output if tcpip_try_callback fails #67

Open
wants to merge 1 commit into
base: 2.1.2-esp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/core/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ netif_add(struct netif *netif,
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
netif->loop_cnt_current = 0;
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
#if ENABLE_LOOPBACK && LWIP_NETIF_LOOPBACK_MULTITHREADING
netif->reschedule_poll = 0;
#endif /* ENABLE_LOOPBACK && LWIP_NETIF_LOOPBACK_MULTITHREADING */

#if ESP_LWIP
#if IP_NAPT
Expand Down Expand Up @@ -1089,11 +1092,12 @@ netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callb
/**
* @ingroup netif
* Send an IP packet to be received on the same netif (loopif-like).
* The pbuf is simply copied and handed back to netif->input.
* In multithreaded mode, this is done directly since netif->input must put
* the packet on a queue.
* In callback mode, the packet is put on an internal queue and is fed to
* The pbuf is copied and added to an internal queue which is fed to
* netif->input by netif_poll().
* In multithreaded mode, the call to netif_poll() is queued to be done on the
* TCP/IP thread.
* In callback mode, the user has the responsibility to call netif_poll() in
* the main loop of their application.
*
* @param netif the lwip network interface structure
* @param p the (IP) packet to 'send'
Expand Down Expand Up @@ -1170,6 +1174,12 @@ netif_loop_output(struct netif *netif, struct pbuf *p)
LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
netif->loop_last->next = r;
netif->loop_last = last;
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
if (netif->reschedule_poll) {
schedule_poll = 1;
netif->reschedule_poll = 0;
}
#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
} else {
netif->loop_first = r;
netif->loop_last = last;
Expand All @@ -1187,7 +1197,11 @@ netif_loop_output(struct netif *netif, struct pbuf *p)
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
/* For multithreading environment, schedule a call to netif_poll */
if (schedule_poll) {
tcpip_try_callback((tcpip_callback_fn)netif_poll, netif);
if (tcpip_try_callback((tcpip_callback_fn)netif_poll, netif) != ERR_OK) {
SYS_ARCH_PROTECT(lev);
netif->reschedule_poll = 1;
SYS_ARCH_UNPROTECT(lev);
}
}
#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */

Expand Down
4 changes: 4 additions & 0 deletions src/include/lwip/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ struct netif {
#if LWIP_LOOPBACK_MAX_PBUFS
u16_t loop_cnt_current;
#endif /* LWIP_LOOPBACK_MAX_PBUFS */
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
/* Used if the original scheduling failed. */
u8_t reschedule_poll;
#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
#endif /* ENABLE_LOOPBACK */
#if ESP_PBUF
void (*l2_buffer_free_notify)(struct netif *lwip_netif, void *user_buf); /* Allows LWIP to notify driver when a L2-supplied pbuf can be freed */
Expand Down