From 42d50eba4e3f49088b00988d911a674a022435d7 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 19 Jun 2016 23:48:08 +0200 Subject: [PATCH] PPP, move protocols initialization from ppp_clear to ppp_new What protocols init functions are meant to is to be called once to set the default configuration before user specific configuration is set. Until now, we reset to the default configuration just before reconnecting, thus without allowing any time frame to let users change it. That was fine until one user asked to be able to do that. This change move protocols init functions calls from ppp_clear to ppp_new, meaning user configuration is not overwritten anymore. --- src/netif/ppp/ccp.c | 2 +- src/netif/ppp/chap-new.c | 2 +- src/netif/ppp/ecp.c | 2 +- src/netif/ppp/ipcp.c | 2 +- src/netif/ppp/ipv6cp.c | 2 +- src/netif/ppp/ppp.c | 21 ++++++++++----------- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/netif/ppp/ccp.c b/src/netif/ppp/ccp.c index 8428dfb7..f8519ebe 100644 --- a/src/netif/ppp/ccp.c +++ b/src/netif/ppp/ccp.c @@ -373,7 +373,7 @@ static void ccp_init(ppp_pcb *pcb) { f->callbacks = &ccp_callbacks; fsm_init(f); -#if 0 /* Not necessary, everything is cleared in ppp_clear() */ +#if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(wo, 0, sizeof(*wo)); memset(go, 0, sizeof(*go)); memset(ao, 0, sizeof(*ao)); diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index 9e7e66c5..485122d2 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -124,7 +124,7 @@ static const struct chap_digest_type* const chap_digests[] = { static void chap_init(ppp_pcb *pcb) { LWIP_UNUSED_ARG(pcb); -#if 0 /* Not necessary, everything is cleared in ppp_clear() */ +#if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(&pcb->chap_client, 0, sizeof(chap_client_state)); #if PPP_SERVER memset(&pcb->chap_server, 0, sizeof(chap_server_state)); diff --git a/src/netif/ppp/ecp.c b/src/netif/ppp/ecp.c index 68e5bcb9..4d84f609 100644 --- a/src/netif/ppp/ecp.c +++ b/src/netif/ppp/ecp.c @@ -166,7 +166,7 @@ ecp_init(unit) f->callbacks = &ecp_callbacks; fsm_init(f); -#if 0 /* Not necessary, everything is cleared in ppp_clear() */ +#if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(&ecp_wantoptions[unit], 0, sizeof(ecp_options)); memset(&ecp_gotoptions[unit], 0, sizeof(ecp_options)); memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options)); diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index c42fdf76..06e1eac3 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -611,7 +611,7 @@ static void ipcp_init(ppp_pcb *pcb) { */ f->maxnakloops = 100; -#if 0 /* Not necessary, everything is cleared in ppp_clear() */ +#if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(wo, 0, sizeof(*wo)); memset(ao, 0, sizeof(*ao)); #endif /* 0 */ diff --git a/src/netif/ppp/ipv6cp.c b/src/netif/ppp/ipv6cp.c index f02558e0..db24305c 100644 --- a/src/netif/ppp/ipv6cp.c +++ b/src/netif/ppp/ipv6cp.c @@ -435,7 +435,7 @@ static void ipv6cp_init(ppp_pcb *pcb) { f->callbacks = &ipv6cp_callbacks; fsm_init(f); -#if 0 /* Not necessary, everything is cleared in ppp_clear() */ +#if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(wo, 0, sizeof(*wo)); memset(ao, 0, sizeof(*ao)); #endif /* 0 */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 16aba02f..95cc22b0 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -613,6 +613,8 @@ int ppp_init(void) */ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { ppp_pcb *pcb; + const struct protent *protp; + int i; /* PPP is single-threaded: without a callback, * there is no way to know when the link is up. */ @@ -686,15 +688,20 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo pcb->link_ctx_cb = link_ctx_cb; pcb->link_status_cb = link_status_cb; pcb->ctx_cb = ctx_cb; + + /* + * Initialize each protocol. + */ + for (i = 0; (protp = protocols[i]) != NULL; ++i) { + (*protp->init)(pcb); + } + new_phase(pcb, PPP_PHASE_DEAD); return pcb; } /* Set a PPP PCB to its initial state */ void ppp_clear(ppp_pcb *pcb) { - const struct protent *protp; - int i; - LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); /* Clean data not taken care by anything else, mostly shared data. */ @@ -706,14 +713,6 @@ void ppp_clear(ppp_pcb *pcb) { memset(&pcb->mppe_comp, 0, sizeof(pcb->mppe_comp)); memset(&pcb->mppe_decomp, 0, sizeof(pcb->mppe_decomp)); #endif /* MPPE_SUPPORT */ - - /* - * Initialize each protocol. - */ - for (i = 0; (protp = protocols[i]) != NULL; ++i) { - (*protp->init)(pcb); - } - #if VJ_SUPPORT && LWIP_TCP vj_compress_init(&pcb->vj_comp); #endif /* VJ_SUPPORT && LWIP_TCP */