From 443b2551c7cfe6970c88a6c32430749adbf149f0 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 14 Feb 2015 22:47:38 +0100 Subject: [PATCH] PPP: moved duplicated init code from ppp_over_X_create() to ppp_new() Some init code were duplicated for all low-level PPP protocols, moved uselessly duplicated code to ppp_new(). --- src/netif/ppp/ppp.c | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 6ac49710..f2d5de1e 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -183,7 +183,7 @@ const struct protent* const protocols[] = { }; /* Prototypes for procedures local to this file. */ -static ppp_pcb *ppp_new(struct netif *pppif); +static ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); static void ppp_clear(ppp_pcb *pcb); static void ppp_do_open(void *arg); static void ppp_start(ppp_pcb *pcb); /** Initiate LCP open request */ @@ -229,20 +229,12 @@ static int ppp_write_over_l2tp(ppp_pcb *pcb, struct pbuf *p); ppp_pcb *ppp_over_serial_create(struct netif *pppif, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { ppp_pcb *pcb; - /* PPP is single-threaded: without a callback, - * there is no way to know when the link is up. */ - if (link_status_cb == NULL) { - return NULL; - } - - pcb = ppp_new(pppif); + pcb = ppp_new(pppif, link_status_cb, ctx_cb); if (pppif == NULL) { return NULL; } pcb->fd = fd; - pcb->link_status_cb = link_status_cb; - pcb->ctx_cb = ctx_cb; return pcb; } @@ -270,20 +262,11 @@ ppp_pcb *ppp_over_ethernet_create(struct netif *pppif, struct netif *ethif, cons LWIP_UNUSED_ARG(service_name); LWIP_UNUSED_ARG(concentrator_name); - /* PPP is single-threaded: without a callback, - * there is no way to know when the link is up. */ - if (link_status_cb == NULL) { - return NULL; - } - - pcb = ppp_new(pppif); + pcb = ppp_new(pppif, link_status_cb, ctx_cb); if (pppif == NULL) { return NULL; } - pcb->link_status_cb = link_status_cb; - pcb->ctx_cb = ctx_cb; - if (pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) { ppp_free(pcb); return NULL; @@ -301,20 +284,11 @@ ppp_pcb *ppp_over_l2tp_create(struct netif *pppif, struct netif *netif, ip_addr_ ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { ppp_pcb *pcb; - /* PPP is single-threaded: without a callback, - * there is no way to know when the link is up. */ - if (link_status_cb == NULL) { - return NULL; - } - - pcb = ppp_new(pppif); + pcb = ppp_new(pppif, link_status_cb, ctx_cb); if (pppif == NULL) { return NULL; } - pcb->link_status_cb = link_status_cb; - pcb->ctx_cb = ctx_cb; - if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, netif, ipaddr, port, secret, secret_len) != ERR_OK) { ppp_free(pcb); return NULL; @@ -531,9 +505,15 @@ int ppp_init(void) { * Return a new PPP connection control block pointer * on success or a null pointer on failure. */ -static ppp_pcb *ppp_new(struct netif *pppif) { +static ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { ppp_pcb *pcb; + /* PPP is single-threaded: without a callback, + * there is no way to know when the link is up. */ + if (link_status_cb == NULL) { + return NULL; + } + pcb = (ppp_pcb*)memp_malloc(MEMP_PPP_PCB); if (pcb == NULL) { return NULL; @@ -589,6 +569,8 @@ static ppp_pcb *ppp_new(struct netif *pppif) { return NULL; } + pcb->link_status_cb = link_status_cb; + pcb->ctx_cb = ctx_cb; new_phase(pcb, PPP_PHASE_DEAD); return pcb; }