PPP, reorder initialisation of low level protocols to call ppp_link_set_callbacks() just after PPP control block allocation

This commit is contained in:
Sylvain Rochet 2015-09-13 18:21:14 +02:00
parent 5b07569eb9
commit 46204a9f86
3 changed files with 22 additions and 25 deletions

View File

@ -174,29 +174,26 @@ ppp_pcb *pppoe_create(struct netif *pppif,
LWIP_UNUSED_ARG(service_name);
LWIP_UNUSED_ARG(concentrator_name);
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
return NULL;
}
sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF);
if (sc == NULL) {
ppp_free(ppp);
return NULL;
}
memset(sc, 0, sizeof(struct pppoe_softc));
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
memp_free(MEMP_PPPOE_IF, sc);
return NULL;
}
ppp_link_set_callbacks(ppp, &pppoe_callbacks, sc);
memset(sc, 0, sizeof(struct pppoe_softc));
/* changed to real address later */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
sc->pcb = ppp;
sc->sc_ethif = ethif;
/* put the new interface at the head of the list */
sc->next = pppoe_softc_list;
pppoe_softc_list = sc;
ppp_link_set_callbacks(ppp, &pppoe_callbacks, sc);
return ppp;
}

View File

@ -124,16 +124,17 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
goto ipaddr_check_failed;
}
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
goto ppp_new_failed;
}
l2tp = (pppol2tp_pcb *)memp_malloc(MEMP_PPPOL2TP_PCB);
if (l2tp == NULL) {
goto memp_malloc_l2tp_failed;
}
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
goto ppp_new_failed;
}
ppp_link_set_callbacks(ppp, &pppol2tp_callbacks, l2tp);
#if LWIP_IPV6
if (IP_IS_V6_VAL(*ipaddr)) {
udp = udp_new_ip6();
@ -157,14 +158,13 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
l2tp->secret_len = secret_len;
#endif /* PPPOL2TP_AUTH_SUPPORT */
ppp_link_set_callbacks(ppp, &pppol2tp_callbacks, l2tp);
return ppp;
udp_new_failed:
memp_free(MEMP_PPPOL2TP_PCB, l2tp);
memp_malloc_l2tp_failed:
ppp_free(ppp);
ppp_new_failed:
memp_free(MEMP_PPPOL2TP_PCB, l2tp);
memp_malloc_l2tp_failed:
ipaddr_check_failed:
return NULL;
}

View File

@ -173,20 +173,20 @@ ppp_pcb *pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
pppos_pcb *pppos;
ppp_pcb *ppp;
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
pppos = (pppos_pcb *)memp_malloc(MEMP_PPPOS_PCB);
if (pppos == NULL) {
return NULL;
}
pppos = (pppos_pcb *)memp_malloc(MEMP_PPPOS_PCB);
if (pppos == NULL) {
ppp_free(ppp);
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
if (ppp == NULL) {
memp_free(MEMP_PPPOS_PCB, pppos);
return NULL;
}
ppp_link_set_callbacks(ppp, &pppos_callbacks, pppos);
pppos->ppp = ppp;
pppos->output_cb = output_cb;
ppp_link_set_callbacks(ppp, &pppos_callbacks, pppos);
return ppp;
}