Skip to content

esp32/network_ppp: Bugfixes for deadlocks and crashes when disconnecting. #17656

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

Open
wants to merge 3 commits into
base: master
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
27 changes: 15 additions & 12 deletions extmod/network_ppp_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ typedef struct _network_ppp_obj_t {

const mp_obj_type_t mp_network_ppp_lwip_type;

static mp_obj_t network_ppp___del__(mp_obj_t self_in);

static void network_ppp_stream_uart_irq_disable(network_ppp_obj_t *self) {
if (self->stream == mp_const_none) {
return;
Expand All @@ -88,8 +86,12 @@ static void network_ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
// only need to free the PPP PCB, not close it.
self->state = STATE_ACTIVE;
}
network_ppp_stream_uart_irq_disable(self);
// Clean up the PPP PCB.
network_ppp___del__(MP_OBJ_FROM_PTR(self));
if (ppp_free(pcb) == ERR_OK) {
self->state = STATE_INACTIVE;
self->pcb = NULL;
}
break;
default:
self->state = STATE_ERROR;
Expand Down Expand Up @@ -117,17 +119,18 @@ static mp_obj_t network_ppp_make_new(const mp_obj_type_t *type, size_t n_args, s

static mp_obj_t network_ppp___del__(mp_obj_t self_in) {
network_ppp_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->state >= STATE_ACTIVE) {
if (self->state >= STATE_ERROR) {
// Still connected over the stream.
// Force the connection to close, with nocarrier=1.
self->state = STATE_INACTIVE;
ppp_close(self->pcb, 1);
}
network_ppp_stream_uart_irq_disable(self);

network_ppp_stream_uart_irq_disable(self);
if (self->state >= STATE_ERROR) {
// Still connected over the stream.
// Force the connection to close, with nocarrier=1.
ppp_close(self->pcb, 1);
} else if (self->state >= STATE_ACTIVE) {
// Free PPP PCB and reset state.
if (ppp_free(self->pcb) != ERR_OK) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ppp_free failed"));
}
self->state = STATE_INACTIVE;
ppp_free(self->pcb);
self->pcb = NULL;
}
return mp_const_none;
Expand Down
31 changes: 18 additions & 13 deletions ports/esp32/network_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ typedef struct _network_ppp_obj_t {

const mp_obj_type_t esp_network_ppp_lwip_type;

static mp_obj_t network_ppp___del__(mp_obj_t self_in);

static void network_ppp_stream_uart_irq_disable(network_ppp_obj_t *self) {
if (self->stream == mp_const_none) {
return;
Expand All @@ -94,8 +92,15 @@ static void network_ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
// only need to free the PPP PCB, not close it.
self->state = STATE_ACTIVE;
}
network_ppp_stream_uart_irq_disable(self);
// Clean up the PPP PCB.
network_ppp___del__(MP_OBJ_FROM_PTR(self));
// Note: Because we use pppapi_close instead of ppp_close, this
// callback will run on the lwIP tcpip_thread, thus to prevent a
// deadlock we must use the non-threadsafe function here.
if (ppp_free(pcb) == ERR_OK) {
self->state = STATE_INACTIVE;
self->pcb = NULL;
}
break;
default:
self->state = STATE_ERROR;
Expand Down Expand Up @@ -123,17 +128,17 @@ static mp_obj_t network_ppp_make_new(const mp_obj_type_t *type, size_t n_args, s

static mp_obj_t network_ppp___del__(mp_obj_t self_in) {
network_ppp_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->state >= STATE_ACTIVE) {
if (self->state >= STATE_ERROR) {
// Still connected over the stream.
// Force the connection to close, with nocarrier=1.
self->state = STATE_INACTIVE;
pppapi_close(self->pcb, 1);
}
network_ppp_stream_uart_irq_disable(self);
network_ppp_stream_uart_irq_disable(self);
if (self->state >= STATE_ERROR) {
// Still connected over the stream.
// Force the connection to close, with nocarrier=1.
pppapi_close(self->pcb, 1);
} else if (self->state >= STATE_ACTIVE) {
// Free PPP PCB and reset state.
if (pppapi_free(self->pcb) != ERR_OK) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("pppapi_free failed"));
}
self->state = STATE_INACTIVE;
pppapi_free(self->pcb);
self->pcb = NULL;
}
return mp_const_none;
Expand Down Expand Up @@ -163,7 +168,7 @@ static mp_obj_t network_ppp_poll(size_t n_args, const mp_obj_t *args) {
}
mp_printf(&mp_plat_print, ")\n");
#endif
pppos_input(self->pcb, (u8_t *)buf, len);
pppos_input_tcpip(self->pcb, (u8_t *)buf, len);
total_len += len;
}

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy