From f98f2890f32d079a551aab0551d7559d81c4c71f Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Mon, 16 Feb 2015 22:44:23 +0100 Subject: [PATCH] PPP, PPPoS, check if PPPoS configuration functions are used on PPPoS We don't have callbacks which can be set or cleared for PPPoS configuration, there is too much callbacks to create and PPPoS must be kept light, therefore PPPoS functions can be called when PPP core configure a PPPoE or PPPoL2TP interface, this is very unlikely to happens because protocols not supported by PPPoE or PPPoL2TP are disabled at LCP/IPCP negotiation but being safe is still better. Check if passed PPP pointer to PPPoS configuration functions is a PPPoS interface by using a linked list of exiting PPPoS interfaces. --- src/include/netif/ppp/pppos.h | 1 + src/netif/ppp/pppos.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/include/netif/ppp/pppos.h b/src/include/netif/ppp/pppos.h index 7c0ef93b..b7d56526 100644 --- a/src/include/netif/ppp/pppos.h +++ b/src/include/netif/ppp/pppos.h @@ -45,6 +45,7 @@ */ typedef struct pppos_pcb_s pppos_pcb; struct pppos_pcb_s { + pppos_pcb *next; ppp_pcb *ppp; /* PPP PCB */ sio_fd_t fd; /* File device ID of port. */ #if VJ_SUPPORT diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 6c034f7f..116d2243 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -55,6 +55,7 @@ static int pppos_link_write_callback(void *pcb, struct pbuf *p); static err_t pppos_link_netif_output_callback(void *pcb, struct pbuf *pb, u_short protocol); /* Prototypes for procedures local to this file. */ +static u8_t pppos_exist(pppos_pcb *pppos); static void pppos_connect(pppos_pcb *pppos); static void pppos_disconnect(pppos_pcb *pppos); static err_t pppos_destroy(pppos_pcb *pppos); @@ -133,6 +134,9 @@ ppp_get_fcs(u8_t byte) #define PPP_INITFCS 0xffff /* Initial FCS value */ #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ +/* linked list of created PPPoS interfaces */ +static pppos_pcb *pppos_pcb_list; + /* @@ -161,6 +165,10 @@ ppp_over_serial_create(struct netif *pppif, sio_fd_t fd, return NULL; } + /* put the new interface at the head of the list */ + pppos->next = pppos_pcb_list; + pppos_pcb_list = pppos; + pppos->ppp = ppp; pppos->fd = fd; ppp_link_set_callbacks(ppp, pppos_link_command_callback, pppos_link_write_callback, pppos_link_netif_output_callback, pppos); @@ -375,6 +383,18 @@ pppos_link_netif_output_callback(void *pcb, struct pbuf *pb, u_short protocol) return ERR_OK; } +static u8_t +pppos_exist(pppos_pcb *pppos) +{ + pppos_pcb *test; + for (test = pppos_pcb_list; test != NULL; test = test->next) { + if (test == pppos) { + return 1; + } + } + return 0; +} + static void pppos_connect(pppos_pcb *pppos) { @@ -434,6 +454,15 @@ static err_t pppos_destroy(pppos_pcb *pppos) { ppp_pcb *ppp = pppos->ppp; + pppos_pcb **copp, *freep; + + /* remove interface from list */ + for (copp = &pppos_pcb_list; (freep = *copp); copp = &freep->next) { + if (freep == pppos) { + *copp = freep->next; + break; + } + } /* input pbuf left ? */ pppos_free_current_input_packet(&ppp->rx); @@ -718,6 +747,9 @@ void pppos_vjc_config(ppp_pcb *ppp, int vjcomp, int cidcomp, int maxcid) { pppos_pcb *pppos = (pppos_pcb *)ppp->link_ctx_cb; + if (!pppos_exist(pppos)) { + return; + } ppp->vj_enabled = vjcomp; pppos->vj_comp.compressSlot = cidcomp; pppos->vj_comp.maxSlotIndex = maxcid;