mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-10 01:23:48 +08:00
PPP, CORE, ppp_close() and ppp_sighup() ended up sharing almost everything, merged
Merged ppp_sighup() to ppp_close() using an optional argument "nocarrier" on ppp_close().
This commit is contained in:
@@ -278,7 +278,7 @@ err_t ppp_open(ppp_pcb *pcb, u16_t holdoff) {
|
||||
* Return 0 on success, an error code on failure.
|
||||
*/
|
||||
err_t
|
||||
ppp_close(ppp_pcb *pcb)
|
||||
ppp_close(ppp_pcb *pcb, u8_t nocarrier)
|
||||
{
|
||||
pcb->err_code = PPPERR_USER;
|
||||
|
||||
@@ -296,52 +296,26 @@ ppp_close(ppp_pcb *pcb)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* Disconnect */
|
||||
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> lcp_close\n", pcb->netif->num));
|
||||
/* LCP close request, this will leave us at PPP_PHASE_DEAD. */
|
||||
lcp_close(pcb, "User request");
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* This function is called when carrier is lost on the PPP channel. */
|
||||
void
|
||||
ppp_sighup(ppp_pcb *pcb)
|
||||
{
|
||||
pcb->err_code = PPPERR_PEERDEAD;
|
||||
|
||||
/* dead phase, nothing to do, call the status callback to be consistent */
|
||||
if (pcb->phase == PPP_PHASE_DEAD) {
|
||||
pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
|
||||
return;
|
||||
}
|
||||
|
||||
/* holdoff phase, cancel the reconnection and call the status callback */
|
||||
if (pcb->phase == PPP_PHASE_HOLDOFF) {
|
||||
sys_untimeout(ppp_do_open, pcb);
|
||||
pcb->phase = PPP_PHASE_DEAD;
|
||||
pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only accept carrier lost signal on the stable running phase in order
|
||||
* to prevent changing the PPP phase FSM in transition phases.
|
||||
*
|
||||
* Always calling ppp_close() instead is still recommended, this is going to
|
||||
* Always using nocarrier = 0 is still recommended, this is going to
|
||||
* take a little longer time, but is a safer choice from FSM point of view.
|
||||
*/
|
||||
if (pcb->phase != PPP_PHASE_RUNNING) {
|
||||
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d -> lcp_close\n", pcb->netif->num));
|
||||
lcp_close(pcb, "Carrier lost");
|
||||
return;
|
||||
if (nocarrier && pcb->phase == PPP_PHASE_RUNNING) {
|
||||
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d -> lcp_lowerdown\n", pcb->netif->num));
|
||||
lcp_lowerdown(pcb);
|
||||
/* forced link termination, this will leave us at PPP_PHASE_DEAD. */
|
||||
link_terminated(pcb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d -> lcp_lowerdown\n", pcb->netif->num));
|
||||
lcp_lowerdown(pcb);
|
||||
/* forced link termination, this will leave us at PPP_PHASE_DEAD. */
|
||||
link_terminated(pcb);
|
||||
return;
|
||||
/* Disconnect */
|
||||
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> lcp_close\n", pcb->netif->num));
|
||||
/* LCP close request, this will leave us at PPP_PHASE_DEAD. */
|
||||
lcp_close(pcb, "User request");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user