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:
Sylvain Rochet 2015-02-22 14:25:36 +01:00
parent b040ace4c2
commit 4be7fccad3
5 changed files with 38 additions and 76 deletions

View File

@ -256,7 +256,8 @@ ppp_set_default(ppp);
* Initiate PPP negotiation, without waiting (holdoff=0), can only be called
* if PPP session is in the dead state (i.e. disconnected).
*/
ppp_open(ppp, 0);
u16_t holdoff = 0;
ppp_open(ppp, holdoff);
/*
@ -264,8 +265,13 @@ ppp_open(ppp, 0);
* ======================
*/
/* You can call this function anytime */
ppp_close(ppp);
/*
* Initiate the end of the PPP session, without carrier lost signal
* (nocarrier=0), meaning a clean shutdown of PPP protocols.
* You can call this function at anytime.
*/
u8_t nocarrier = 0;
ppp_close(ppp, nocarrier);
/*
* Then you must wait your status_cb() to be called, it may takes from a few
* seconds to several tens of seconds depending on the current PPP state.
@ -354,3 +360,6 @@ from previous lwIP version is pretty easy:
* If you used tcpip_callback_with_block() on ppp_ functions you may wish to use
the PPPAPI API instead.
* ppp_sighup and ppp_close functions were merged using an optional argument
"nocarrier" on ppp_close.

View File

@ -267,7 +267,7 @@ pppapi_open(ppp_pcb *pcb, u16_t holdoff)
static void
pppapi_do_ppp_close(struct pppapi_msg_msg *msg)
{
msg->err = ppp_close(msg->ppp);
msg->err = ppp_close(msg->ppp, msg->msg.close.nocarrier);
TCPIP_PPPAPI_ACK(msg);
}
@ -276,40 +276,17 @@ pppapi_do_ppp_close(struct pppapi_msg_msg *msg)
* tcpip_thread context.
*/
err_t
pppapi_close(ppp_pcb *pcb)
pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
{
struct pppapi_msg msg;
msg.function = pppapi_do_ppp_close;
msg.msg.ppp = pcb;
msg.msg.msg.close.nocarrier = nocarrier;
TCPIP_PPPAPI(&msg);
return msg.msg.err;
}
/**
* Call ppp_sighup() inside the tcpip_thread context.
*/
static void
pppapi_do_ppp_sighup(struct pppapi_msg_msg *msg)
{
ppp_sighup(msg->ppp);
TCPIP_PPPAPI_ACK(msg);
}
/**
* Call ppp_sighup() in a thread-safe way by running that function inside the
* tcpip_thread context.
*/
void
pppapi_sighup(ppp_pcb *pcb)
{
struct pppapi_msg msg;
msg.function = pppapi_do_ppp_sighup;
msg.msg.ppp = pcb;
TCPIP_PPPAPI(&msg);
}
/**
* Call ppp_free() inside the tcpip_thread context.
*/

View File

@ -92,6 +92,9 @@ struct pppapi_msg_msg {
struct {
u16_t holdoff;
} open;
struct {
u8_t nocarrier;
} close;
struct {
u8_t cmd;
void *arg;
@ -134,8 +137,7 @@ ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_add
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOL2TP_SUPPORT */
err_t pppapi_open(ppp_pcb *pcb, u16_t holdoff);
err_t pppapi_close(ppp_pcb *pcb);
void pppapi_sighup(ppp_pcb *pcb);
err_t pppapi_close(ppp_pcb *pcb, u8_t nocarrier);
err_t pppapi_free(ppp_pcb *pcb);
err_t pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg);
#if LWIP_NETIF_STATUS_CALLBACK

View File

@ -467,13 +467,13 @@ err_t ppp_open(ppp_pcb *pcb, u16_t holdoff);
* Initiate the end of a PPP connection.
* Any outstanding packets in the queues are dropped.
* Return 0 on success, an error code on failure.
*
* Setting nocarrier to 1 close the PPP connection without initiating the
* shutdown procedure. Always using nocarrier = 0 is still recommended,
* this is going to take a little longer time if your link is down, but
* is a safer choice for the PPP state machine.
*/
err_t ppp_close(ppp_pcb *pcb);
/*
* Indicate to the PPP stack that the line has disconnected.
*/
void ppp_sighup(ppp_pcb *pcb);
err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier);
/*
* Release the control block.

View File

@ -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;
}
/*