diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-12-07 17:45:24 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-12-07 17:45:24 +0300 |
commit | fd792ed4e723508d829497ba3c89218407f83d17 (patch) | |
tree | 142c2db9ab7e6df3650bace88e9c0b6d60e38315 /src | |
parent | 27ef732453f21abacd3a8dd8a0f6407a58586e12 (diff) |
Fixes for call to conn_accept with null PCB
Diffstat (limited to 'src')
-rw-r--r-- | src/Networking/LwipEthernet/Lwip/lwipopts.h | 2 | ||||
-rw-r--r-- | src/Networking/LwipEthernet/LwipEthernetInterface.cpp | 59 |
2 files changed, 47 insertions, 14 deletions
diff --git a/src/Networking/LwipEthernet/Lwip/lwipopts.h b/src/Networking/LwipEthernet/Lwip/lwipopts.h index ee093678..acc23f00 100644 --- a/src/Networking/LwipEthernet/Lwip/lwipopts.h +++ b/src/Networking/LwipEthernet/Lwip/lwipopts.h @@ -121,7 +121,7 @@ * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. * (requires the LWIP_TCP option) */ -#define MEMP_NUM_TCP_PCB_LISTEN 4 +#define MEMP_NUM_TCP_PCB_LISTEN 7 /** * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. diff --git a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp index 07c47311..935ed9ef 100644 --- a/src/Networking/LwipEthernet/LwipEthernetInterface.cpp +++ b/src/Networking/LwipEthernet/LwipEthernetInterface.cpp @@ -63,18 +63,22 @@ extern "C" } // Callback functions for LWIP (may be called from ISR) + // This occasionally seems to get called with a null pcb argument, so check for that here static err_t conn_accept(void *arg, tcp_pcb *pcb, err_t err) { LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(err); - if (ethernetInterface->ConnectionEstablished(pcb)) + if (pcb != nullptr) { - // A socket has accepted this connection and will deal with it - return ERR_OK; - } + if (ethernetInterface->ConnectionEstablished(pcb)) + { + // A socket has accepted this connection and will deal with it + return ERR_OK; + } - tcp_abort(pcb); + tcp_abort(pcb); + } return ERR_ABRT; } @@ -201,9 +205,24 @@ void LwipEthernetInterface::StartProtocol(NetworkProtocol protocol) noexcept if (listeningPcbs[protocol] == nullptr) { tcp_pcb *pcb = tcp_new(); - tcp_bind(pcb, IP_ADDR_ANY, portNumbers[protocol]); - listeningPcbs[protocol] = tcp_listen(pcb); - tcp_accept(listeningPcbs[protocol], conn_accept); + if (pcb == nullptr) + { + platform.Message(ErrorMessage, "unable to allocate a pcb\n"); + } + else + { + tcp_bind(pcb, IP_ADDR_ANY, portNumbers[protocol]); + pcb = tcp_listen(pcb); + if (pcb == nullptr) + { + platform.Message(ErrorMessage, "tcp_listen call failed\n"); + } + else + { + listeningPcbs[protocol] = pcb; + tcp_accept(listeningPcbs[protocol], conn_accept); + } + } } switch(protocol) @@ -591,11 +610,25 @@ void LwipEthernetInterface::OpenDataPort(TcpPort port) noexcept } tcp_pcb *pcb = tcp_new(); - tcp_bind(pcb, IP_ADDR_ANY, port); - listeningPcbs[NumProtocols] = tcp_listen(pcb); - tcp_accept(listeningPcbs[NumProtocols], conn_accept); - - sockets[FtpDataSocketNumber]->Init(FtpDataSocketNumber, port, FtpDataProtocol); + if (pcb == nullptr) + { + platform.Message(ErrorMessage, "unable to allocate a pcb\n"); + } + else + { + tcp_bind(pcb, IP_ADDR_ANY, port); + pcb = tcp_listen(pcb); + if (pcb == nullptr) + { + platform.Message(ErrorMessage, "tcp_listen call failed\n"); + } + else + { + listeningPcbs[NumProtocols] = pcb; + tcp_accept(listeningPcbs[NumProtocols], conn_accept); + sockets[FtpDataSocketNumber]->Init(FtpDataSocketNumber, port, FtpDataProtocol); + } + } } // Close FTP data port and purge associated resources |