tcp: centralize freeing tcp pcbs to memp_free

This should make it easier to add debugging messages or other hooks
to the point where tcp pcbs are deallocated.

Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
goldsimon 2018-01-24 15:17:01 +01:00
parent ce79811bce
commit ebe782ba16
3 changed files with 28 additions and 11 deletions

View File

@ -202,6 +202,22 @@ tcp_init(void)
#endif /* LWIP_RAND */ #endif /* LWIP_RAND */
} }
/** Free a tcp pcb */
void
tcp_free(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN);
memp_free(MEMP_TCP_PCB, pcb);
}
/** Free a tcp listen pcb */
static void
tcp_free_listen(struct tcp_pcb *pcb)
{
LWIP_ASSERT("tcp_free_listen: !LISTEN", pcb->state != LISTEN);
memp_free(MEMP_TCP_PCB_LISTEN, pcb);
}
/** /**
* Called periodically to dispatch TCP timers. * Called periodically to dispatch TCP timers.
*/ */
@ -337,7 +353,7 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
/* prevent using a deallocated pcb: free it from tcp_input later */ /* prevent using a deallocated pcb: free it from tcp_input later */
tcp_trigger_input_pcb_close(); tcp_trigger_input_pcb_close();
} else { } else {
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
} }
return ERR_OK; return ERR_OK;
} }
@ -357,16 +373,16 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
if (pcb->local_port != 0) { if (pcb->local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb); TCP_RMV(&tcp_bound_pcbs, pcb);
} }
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
break; break;
case LISTEN: case LISTEN:
tcp_listen_closed(pcb); tcp_listen_closed(pcb);
tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb); tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);
memp_free(MEMP_TCP_PCB_LISTEN, pcb); tcp_free_listen(pcb);
break; break;
case SYN_SENT: case SYN_SENT:
TCP_PCB_REMOVE_ACTIVE(pcb); TCP_PCB_REMOVE_ACTIVE(pcb);
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
MIB2_STATS_INC(mib2.tcpattemptfails); MIB2_STATS_INC(mib2.tcpattemptfails);
break; break;
default: default:
@ -541,7 +557,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
the PCB with a NULL argument, and send an RST to the remote end. */ the PCB with a NULL argument, and send an RST to the remote end. */
if (pcb->state == TIME_WAIT) { if (pcb->state == TIME_WAIT) {
tcp_pcb_remove(&tcp_tw_pcbs, pcb); tcp_pcb_remove(&tcp_tw_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
} else { } else {
int send_rst = 0; int send_rst = 0;
enum tcp_state last_state; enum tcp_state last_state;
@ -577,7 +593,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
tcp_rst(pcb, seqno, ackno, &pcb->local_ip, &pcb->remote_ip, pcb->local_port, pcb->remote_port); tcp_rst(pcb, seqno, ackno, &pcb->local_ip, &pcb->remote_ip, pcb->local_port, pcb->remote_port);
} }
last_state = pcb->state; last_state = pcb->state;
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
TCP_EVENT_ERR(last_state, errf, errf_arg, ERR_ABRT); TCP_EVENT_ERR(last_state, errf, errf_arg, ERR_ABRT);
} }
} }
@ -850,7 +866,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
if (pcb->local_port != 0) { if (pcb->local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb); TCP_RMV(&tcp_bound_pcbs, pcb);
} }
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
#if LWIP_CALLBACK_API #if LWIP_CALLBACK_API
lpcb->accept = tcp_accept_null; lpcb->accept = tcp_accept_null;
#endif /* LWIP_CALLBACK_API */ #endif /* LWIP_CALLBACK_API */
@ -1346,7 +1362,7 @@ tcp_slowtmr_start:
last_state = pcb->state; last_state = pcb->state;
pcb2 = pcb; pcb2 = pcb;
pcb = pcb->next; pcb = pcb->next;
memp_free(MEMP_TCP_PCB, pcb2); tcp_free(pcb2);
tcp_active_pcbs_changed = 0; tcp_active_pcbs_changed = 0;
TCP_EVENT_ERR(last_state, err_fn, err_arg, ERR_ABRT); TCP_EVENT_ERR(last_state, err_fn, err_arg, ERR_ABRT);
@ -1404,7 +1420,7 @@ tcp_slowtmr_start:
} }
pcb2 = pcb; pcb2 = pcb;
pcb = pcb->next; pcb = pcb->next;
memp_free(MEMP_TCP_PCB, pcb2); tcp_free(pcb2);
} else { } else {
prev = pcb; prev = pcb;
pcb = pcb->next; pcb = pcb->next;

View File

@ -422,7 +422,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
deallocate the PCB. */ deallocate the PCB. */
TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_RST); TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_RST);
tcp_pcb_remove(&tcp_active_pcbs, pcb); tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
} else { } else {
err = ERR_OK; err = ERR_OK;
/* If the application has registered a "sent" function to be /* If the application has registered a "sent" function to be
@ -585,7 +585,7 @@ tcp_input_delayed_close(struct tcp_pcb *pcb)
TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_CLSD); TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_CLSD);
} }
tcp_pcb_remove(&tcp_active_pcbs, pcb); tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb); tcp_free(pcb);
return 1; return 1;
} }
return 0; return 0;

View File

@ -77,6 +77,7 @@ void tcp_txnow (void);
void tcp_input (struct pbuf *p, struct netif *inp); void tcp_input (struct pbuf *p, struct netif *inp);
/* Used within the TCP code only: */ /* Used within the TCP code only: */
struct tcp_pcb * tcp_alloc (u8_t prio); struct tcp_pcb * tcp_alloc (u8_t prio);
void tcp_free (struct tcp_pcb *pcb);
void tcp_abandon (struct tcp_pcb *pcb, int reset); void tcp_abandon (struct tcp_pcb *pcb, int reset);
err_t tcp_send_empty_ack(struct tcp_pcb *pcb); err_t tcp_send_empty_ack(struct tcp_pcb *pcb);
err_t tcp_rexmit (struct tcp_pcb *pcb); err_t tcp_rexmit (struct tcp_pcb *pcb);