improved PPPoE callback with state values, so that PPP know exactly what is happening on the PPPoE side

This commit is contained in:
Sylvain Rochet 2012-06-06 23:42:20 +02:00
parent ac0a864e14
commit e44aada634
3 changed files with 41 additions and 26 deletions

View File

@ -113,6 +113,10 @@ PACK_STRUCT_END
/* passive */
#define PPPOE_STATE_PADO_SENT 1
#define PPPOE_CB_STATE_UP 0 /* PPPoE link is UP */
#define PPPOE_CB_STATE_DOWN 1 /* PPPoE link is DOWN - normal condition */
#define PPPOE_CB_STATE_FAILED 2 /* Failed to setup PPPoE link */
#define PPPOE_HEADERLEN sizeof(struct pppoehdr)
#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */

View File

@ -580,7 +580,7 @@ void ppp_set_xaccm(int unit, ext_accm *accm) {
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
static void ppp_over_ethernet_link_status_cb(int pd, int up);
static void ppp_over_ethernet_link_status_cb(int pd, int state);
int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const char *concentrator_name,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) {
@ -682,7 +682,7 @@ ppp_close(int pd)
void
ppp_sighup(int pd)
{
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d sig_hup -> ppp_hupCB\n", pd));
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d sig_hup -> ppp_hup\n", pd));
ppp_hup(pd);
}
@ -709,7 +709,7 @@ ppp_stop(int pd)
static void
ppp_hup(int pd)
{
PPPDEBUG(LOG_DEBUG, ("ppp_hupCB: unit %d\n", pd));
PPPDEBUG(LOG_DEBUG, ("ppp_hup: unit %d\n", pd));
lcp_lowerdown(pd);
link_terminated(pd);
}
@ -1834,27 +1834,39 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
}
#if PPPOE_SUPPORT
void ppp_over_ethernet_init_failed(int pd) {
ppp_control* pc;
static void ppp_over_ethernet_link_status_cb(int pd, int state) {
ppp_control *pc = &ppp_control_list[pd];
ppp_hup(pd);
ppp_stop(pd);
switch(state) {
case PPPOE_CB_STATE_UP:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: UP, connecting\n", pd));
ppp_start(pd);
break;
pc = &ppp_control_list[pd];
pppoe_destroy(&pc->netif);
pc->open_flag = 0;
/* FIXME: here we can handle the PPPoE persist, in case of DOWN or FAILED, we just have to
* call pppoe_connect(sc); without setting pc->open_flag to 0.
*/
case PPPOE_CB_STATE_DOWN:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: DOWN, disconnected\n", pd));
ppp_hup(pd);
ppp_stop(pd);
pppoe_destroy(&pc->netif);
pc->open_flag = 0;
if(pc->link_status_cb) {
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_CONNECT, NULL);
}
break;
if(pc->link_status_cb) {
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_PROTOCOL, NULL);
}
}
static void ppp_over_ethernet_link_status_cb(int pd, int up) {
if(up) {
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: Connecting\n", pd));
ppp_start(pd);
} else {
ppp_over_ethernet_init_failed(pd);
case PPPOE_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pd));
ppp_hup(pd);
ppp_stop(pd);
pppoe_destroy(&pc->netif);
pc->open_flag = 0;
if(pc->link_status_cb) {
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_PROTOCOL, NULL);
}
break;
}
}
#endif /* PPPOE_SUPPORT */

View File

@ -277,7 +277,7 @@ pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif)
static void
pppoe_linkstatus_up(struct pppoe_softc *sc)
{
sc->sc_linkStatusCB(sc->sc_pd, 1);
sc->sc_linkStatusCB(sc->sc_pd, PPPOE_CB_STATE_UP);
}
/* analyze and handle a single received packet while not in session state */
@ -863,8 +863,7 @@ pppoe_do_disconnect(struct pppoe_softc *sc)
#endif
sc->sc_session = 0;
sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
sc->sc_linkStatusCB(sc->sc_pd, PPPOE_CB_STATE_DOWN); /* notify upper layers */
return err;
}
@ -875,7 +874,7 @@ pppoe_abort_connect(struct pppoe_softc *sc)
PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
sc->sc_state = PPPOE_STATE_CLOSING;
sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
sc->sc_linkStatusCB(sc->sc_pd, PPPOE_CB_STATE_FAILED); /* notify upper layers */
/* clear connection state */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
@ -1118,7 +1117,7 @@ pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
sc->sc_state = PPPOE_STATE_INITIAL;
/* notify upper layers */
sc->sc_linkStatusCB(sc->sc_pd, 0);
sc->sc_linkStatusCB(sc->sc_pd, PPPOE_CB_STATE_DOWN);
/* clean up softc */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));