From 7df5496e7b3f45fc77aedeeb37b362df910f4159 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 19 Jun 2016 23:08:24 +0200 Subject: [PATCH] PPP, rework initial/reconnect cleanup Our previous way of doing it was to clear everything except a small part of the ppp_pcb structure and then populate the structure with default values using protocols init functions. But it means the user is currently not allowed to change the default configuration except the few flags and values that are currently available in the ppp_settings structure. Instead of adding more and more fields to the ppp_settings structure, actually making them duplicate of already existing structure members of ppp_pcb, but unfortunately cleaned, we carefully checked that everything is properly cleaned during protocol lowerdown/close and replaced our giant memset to selective memset of the few ppp_pcb members that are not properly cleaned. --- src/include/netif/ppp/ppp.h | 8 -------- src/netif/ppp/ppp.c | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index ca4a4b81..9ffc8b4e 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -310,7 +310,6 @@ struct ppp_addrs { * PPP interface control block. */ struct ppp_pcb_s { - /* -- below are data that will NOT be cleared between two sessions */ ppp_settings settings; const struct link_callbacks *link_cb; void *link_ctx_cb; @@ -320,13 +319,6 @@ struct ppp_pcb_s { #endif /* PPP_NOTIFY_PHASE */ void *ctx_cb; /* Callbacks optional pointer */ struct netif *netif; /* PPP interface */ - - /* -- below are data that will be cleared between two sessions */ - - /* - * phase must be the first member of cleared members, because it is used to know - * which part must not be cleared. - */ u8_t phase; /* where the link is at */ u8_t err_code; /* Code indicating why interface is down. */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index e9112111..16aba02f 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -697,11 +697,15 @@ void ppp_clear(ppp_pcb *pcb) { 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. */ #if PPP_STATS_SUPPORT link_stats_valid = 0; #endif /* PPP_STATS_SUPPORT */ - - memset(&pcb->phase, 0, sizeof(ppp_pcb) - ( (char*)&((ppp_pcb*)0)->phase - (char*)0 ) ); +#if MPPE_SUPPORT + pcb->mppe_keys_set = 0; + memset(&pcb->mppe_comp, 0, sizeof(pcb->mppe_comp)); + memset(&pcb->mppe_decomp, 0, sizeof(pcb->mppe_decomp)); +#endif /* MPPE_SUPPORT */ /* * Initialize each protocol.