From d15ebc6a4cd62f7637f7b05ed68c4adb98b6977b Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 21:04:56 +0200 Subject: [PATCH] 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. --- src/netif/ppp/ppp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 4c06083c..d5de30b2 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -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; }