From c58c27ed8b118e48a785080b95f1213c02cabe67 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Tue, 24 Jul 2012 22:50:17 +0200 Subject: [PATCH] removed time-based PPP phase state machine hacks from PPPoE dans PPPoL2TP Our PPP phase state machine is now clean, we can safely remove time based hacks in PPPoE dans PPPoL2TP. --- src/include/netif/ppp_oe.h | 1 - src/include/netif/pppol2tp.h | 1 - src/netif/ppp/ppp_oe.c | 27 ++++----------------------- src/netif/ppp/pppol2tp.c | 23 ++++++----------------- 4 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/include/netif/ppp_oe.h b/src/include/netif/ppp_oe.h index 3a5a482c..02006f33 100644 --- a/src/include/netif/ppp_oe.h +++ b/src/include/netif/ppp_oe.h @@ -109,7 +109,6 @@ PACK_STRUCT_END #define PPPOE_STATE_PADI_SENT 1 #define PPPOE_STATE_PADR_SENT 2 #define PPPOE_STATE_SESSION 3 -#define PPPOE_STATE_CLOSING 4 /* passive */ #define PPPOE_STATE_PADO_SENT 1 diff --git a/src/include/netif/pppol2tp.h b/src/include/netif/pppol2tp.h index ddd68e2d..c7beaaae 100644 --- a/src/include/netif/pppol2tp.h +++ b/src/include/netif/pppol2tp.h @@ -154,7 +154,6 @@ #define PPPOL2TP_STATE_ICRQ_SENT 2 #define PPPOL2TP_STATE_ICCN_SENT 3 #define PPPOL2TP_STATE_DATA 4 -#define PPPOL2TP_STATE_CLOSING 5 #define PPPOL2TP_CB_STATE_UP 0 /* PPPoL2TP link is UP */ #define PPPOL2TP_CB_STATE_DOWN 1 /* PPPo2TP link is DOWN - normal condition */ diff --git a/src/netif/ppp/ppp_oe.c b/src/netif/ppp/ppp_oe.c index bd7aa1f7..d61b84bb 100644 --- a/src/netif/ppp/ppp_oe.c +++ b/src/netif/ppp/ppp_oe.c @@ -113,7 +113,6 @@ static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN]; /* management routines */ -static int pppoe_do_disconnect(struct pppoe_softc *); static void pppoe_abort_connect(struct pppoe_softc *); static void pppoe_clear_softc(struct pppoe_softc *, const char *); @@ -780,9 +779,6 @@ pppoe_timeout(void *arg) } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); break; - case PPPOE_STATE_CLOSING: - pppoe_do_disconnect(sc); - break; default: return; /* all done, work in peace */ } @@ -821,31 +817,16 @@ pppoe_connect(struct pppoe_softc *sc) /* disconnect */ void pppoe_disconnect(struct pppoe_softc *sc) -{ - if (sc->sc_state < PPPOE_STATE_SESSION) { - return; - } - /* - * Do not call pppoe_disconnect here, the upper layer state - * machine gets confused by this. We must return from this - * function and defer disconnecting to the timeout handler. - */ - sc->sc_state = PPPOE_STATE_CLOSING; - sys_timeout(20, pppoe_timeout, sc); -} - -static int -pppoe_do_disconnect(struct pppoe_softc *sc) { int err; if (sc->sc_state < PPPOE_STATE_SESSION) { - err = EBUSY; - } else { - PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); - err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); + return EBUSY; } + PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); + err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); + /* cleanup softc */ sc->sc_state = PPPOE_STATE_INITIAL; MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index a197fea8..aa595a82 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -72,7 +72,6 @@ #endif /* PPPOL2TP_AUTH_SUPPORT */ /* Prototypes for procedures local to this file. */ -static void pppol2tp_do_disconnect(pppol2tp_pcb *l2tp); static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port); static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, struct ip_addr *addr, u16_t port, struct pbuf *p, u16_t len, u16_t tunnel_id, u16_t session_id, u16_t ns, u16_t nr); @@ -197,22 +196,12 @@ void pppol2tp_reconnect(pppol2tp_pcb *l2tp) { /* Disconnect */ void pppol2tp_disconnect(pppol2tp_pcb *l2tp) { - if (l2tp->phase == PPPOL2TP_STATE_CLOSING) { + if (l2tp->phase < PPPOL2TP_STATE_DATA) { return; } l2tp->our_ns++; pppol2tp_send_stopccn(l2tp, l2tp->our_ns); - /* - * Do not call pppol2tp_disconnect here, the upper layer state - * machine gets confused by this. We must return from this - * function and defer disconnecting to the timeout handler. - */ - l2tp->phase = PPPOL2TP_STATE_CLOSING; - sys_timeout(20, pppol2tp_timeout, l2tp); -} - -static void pppol2tp_do_disconnect(pppol2tp_pcb *l2tp) { pppol2tp_clear(l2tp); l2tp->link_status_cb(l2tp->ppp, PPPOL2TP_CB_STATE_DOWN); /* notify upper layers */ @@ -410,7 +399,11 @@ static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, struct ip_addr if (l2tp->phase < PPPOL2TP_STATE_DATA) { pppol2tp_abort_connect(l2tp); } else if (l2tp->phase == PPPOL2TP_STATE_DATA) { - pppol2tp_disconnect(l2tp); + /* Don't disconnect here, we let the LCP Echo/Reply find the fact + * that PPP session is down. Asking the PPP stack to end the session + * require strict checking about the PPP phase to prevent endless + * disconnection loops. + */ } return; } @@ -608,10 +601,6 @@ static void pppol2tp_timeout(void *arg) { sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); break; - case PPPOL2TP_STATE_CLOSING: - pppol2tp_do_disconnect(l2tp); - break; - default: return; /* all done, work in peace */ }