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.
This commit is contained in:
Sylvain Rochet 2015-02-15 11:25:37 +01:00
parent ee85aaccd2
commit 19282d6d6c
4 changed files with 40 additions and 34 deletions

View File

@ -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);

View File

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

View File

@ -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) {

View File

@ -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)
*/