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 */ /* passive */
#define PPPOE_STATE_PADO_SENT 1 #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_HEADERLEN sizeof(struct pppoehdr)
#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */ #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 */ #endif /* PPPOS_SUPPORT */
#if PPPOE_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, 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) { ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) {
@ -682,7 +682,7 @@ ppp_close(int pd)
void void
ppp_sighup(int pd) 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); ppp_hup(pd);
} }
@ -709,7 +709,7 @@ ppp_stop(int pd)
static void static void
ppp_hup(int pd) 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); lcp_lowerdown(pd);
link_terminated(pd); link_terminated(pd);
} }
@ -1834,27 +1834,39 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
} }
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
void ppp_over_ethernet_init_failed(int pd) { static void ppp_over_ethernet_link_status_cb(int pd, int state) {
ppp_control* pc; ppp_control *pc = &ppp_control_list[pd];
ppp_hup(pd); switch(state) {
ppp_stop(pd); 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]; /* FIXME: here we can handle the PPPoE persist, in case of DOWN or FAILED, we just have to
pppoe_destroy(&pc->netif); * call pppoe_connect(sc); without setting pc->open_flag to 0.
pc->open_flag = 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) { case PPPOE_CB_STATE_FAILED:
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_PROTOCOL, NULL); 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);
static void ppp_over_ethernet_link_status_cb(int pd, int up) { pc->open_flag = 0;
if(up) { if(pc->link_status_cb) {
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: Connecting\n", pd)); pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_PROTOCOL, NULL);
ppp_start(pd); }
} else { break;
ppp_over_ethernet_init_failed(pd);
} }
} }
#endif /* PPPOE_SUPPORT */ #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 static void
pppoe_linkstatus_up(struct pppoe_softc *sc) 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 */ /* analyze and handle a single received packet while not in session state */
@ -863,8 +863,7 @@ pppoe_do_disconnect(struct pppoe_softc *sc)
#endif #endif
sc->sc_session = 0; 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; 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)); 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_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 */ /* clear connection state */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); 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; sc->sc_state = PPPOE_STATE_INITIAL;
/* notify upper layers */ /* notify upper layers */
sc->sc_linkStatusCB(sc->sc_pd, 0); sc->sc_linkStatusCB(sc->sc_pd, PPPOE_CB_STATE_DOWN);
/* clean up softc */ /* clean up softc */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));