PPP: don't restart LCP closing if termination is already in progress

We say in the PPP documentation that ppp_close() can be called anytime,
as of today, this is not entirely true, there are still conditions that
are not handled properly.

If PPP is already disconnecting, ppp_close() must do nothing and returns
ERR_INPROGRESS instead of messing up the PPP disconnection state.
This commit is contained in:
Sylvain Rochet 2016-08-07 21:04:56 +02:00
parent f185104ac6
commit d15ebc6a4c

View File

@ -336,6 +336,11 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier)
return ERR_OK;
}
/* Already terminating, nothing to do */
if (pcb->phase >= PPP_PHASE_TERMINATE) {
return ERR_INPROGRESS;
}
/*
* Only accept carrier lost signal on the stable running phase in order
* to prevent changing the PPP phase FSM in transition phases.
@ -346,14 +351,14 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier)
if (nocarrier && pcb->phase == PPP_PHASE_RUNNING) {
PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: carrier lost -> lcp_lowerdown\n", pcb->netif->num));
lcp_lowerdown(pcb);
/* forced link termination, this will leave us at PPP_PHASE_DEAD. */
/* forced link termination, this will force link protocol to disconnect. */
link_terminated(pcb);
return ERR_OK;
}
/* Disconnect */
PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: kill_link -> lcp_close\n", pcb->netif->num));
/* LCP close request, this will leave us at PPP_PHASE_DEAD. */
/* LCP soft close request. */
lcp_close(pcb, "User request");
return ERR_OK;
}