From 19282d6d6cdd6f2150043bf9c2fa5b1c4fde6214 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 15 Feb 2015 11:25:37 +0100 Subject: [PATCH] PPP, moved low level protocol connect init to low level protocol files Low level protocol init machine state does not belong to PPP core, moved those init to respective low level protocol files. --- src/include/netif/ppp/ppp_impl.h | 3 +++ src/netif/ppp/ppp.c | 35 +------------------------------- src/netif/ppp/pppoe.c | 19 +++++++++++++++++ src/netif/ppp/pppol2tp.c | 17 ++++++++++++++++ 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index 01194efe..a1858e2e 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -380,6 +380,9 @@ int ppp_init(void); /* Create a new PPP control block */ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); +/* Set a PPP PCB to its initial state */ +void ppp_clear(ppp_pcb *pcb); + /* Set link callback function */ void ppp_link_set_callbacks(ppp_pcb *pcb, link_command_cb_fn command, link_write_cb_fn write, link_netif_output_cb_fn netif_output); diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 173014df..ce29605a 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -183,7 +183,6 @@ const struct protent* const protocols[] = { }; /* Prototypes for procedures local to this file. */ -static void ppp_clear(ppp_pcb *pcb); static void ppp_do_open(void *arg); static void ppp_stop(ppp_pcb *pcb); static void ppp_hup(ppp_pcb *pcb); @@ -506,7 +505,7 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void } /* Set a PPP PCB to its initial state */ -static void ppp_clear(ppp_pcb *pcb) { +void ppp_clear(ppp_pcb *pcb) { const struct protent *protp; int i; @@ -1608,44 +1607,12 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) { #if PPPOE_SUPPORT static void ppp_over_ethernet_open(ppp_pcb *pcb) { - - lcp_options *wo = &pcb->lcp_wantoptions; - lcp_options *ao = &pcb->lcp_allowoptions; - - ppp_clear(pcb); - - wo->mru = pcb->pppoe_sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; - - ao->mru = pcb->pppoe_sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; - pcb->link_command_cb(pcb->pppoe_sc, PPP_LINK_COMMAND_CONNECT); } #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT static void ppp_over_l2tp_open(ppp_pcb *pcb) { - - lcp_options *wo = &pcb->lcp_wantoptions; - lcp_options *ao = &pcb->lcp_allowoptions; - - ppp_clear(pcb); - - wo->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; - - ao->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; - pcb->link_command_cb(pcb->l2tp_pcb, PPP_LINK_COMMAND_CONNECT); } #endif /* PPPOL2TP_SUPPORT */ diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 9e9fda99..a23cdf99 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -82,6 +82,7 @@ #include "lwip/snmp.h" #include "netif/ppp/ppp_impl.h" +#include "netif/ppp/lcp.h" #include "netif/ppp/pppoe.h" /* Add a 16 bit unsigned value to a buffer pointed to by PTR */ @@ -919,6 +920,9 @@ static int pppoe_connect(struct pppoe_softc *sc) { int err; + ppp_pcb *ppp = sc->pcb; + lcp_options *wo; + lcp_options *ao; if (sc->sc_state != PPPOE_STATE_INITIAL) { return EBUSY; @@ -935,6 +939,21 @@ pppoe_connect(struct pppoe_softc *sc) return 0; } #endif + + ppp_clear(ppp); + + wo = &ppp->lcp_wantoptions; + wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ + wo->neg_asyncmap = 0; + wo->neg_pcompression = 0; + wo->neg_accompression = 0; + + ao = &ppp->lcp_allowoptions; + ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ + ao->neg_asyncmap = 0; + ao->neg_pcompression = 0; + ao->neg_accompression = 0; + /* save state, in case we fail to send PADI */ sc->sc_state = PPPOE_STATE_PADI_SENT; if ((err = pppoe_send_padi(sc)) != 0) { diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index a9f9eb18..98732cfd 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -259,6 +259,9 @@ static err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) { /* Be a LAC, connect to a LNS. */ static err_t pppol2tp_connect(pppol2tp_pcb *l2tp) { err_t err; + ppp_pcb *ppp = l2tp->ppp; + lcp_options *wo; + lcp_options *ao; if (l2tp->phase != PPPOL2TP_STATE_INITIAL) { return ERR_VAL; @@ -266,6 +269,20 @@ static err_t pppol2tp_connect(pppol2tp_pcb *l2tp) { pppol2tp_clear(l2tp); + ppp_clear(ppp); + + wo = &ppp->lcp_wantoptions; + wo->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ + wo->neg_asyncmap = 0; + wo->neg_pcompression = 0; + wo->neg_accompression = 0; + + ao = &ppp->lcp_allowoptions; + ao->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ + ao->neg_asyncmap = 0; + ao->neg_pcompression = 0; + ao->neg_accompression = 0; + /* Listen to a random source port, we need to do that instead of using udp_connect() * because the L2TP LNS might answer with its own random source port (!= 1701) */