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.
This commit is contained in:
Sylvain Rochet 2015-02-16 22:44:23 +01:00
parent d93c21349f
commit f98f2890f3
2 changed files with 33 additions and 0 deletions

View File

@ -45,6 +45,7 @@
*/ */
typedef struct pppos_pcb_s pppos_pcb; typedef struct pppos_pcb_s pppos_pcb;
struct pppos_pcb_s { struct pppos_pcb_s {
pppos_pcb *next;
ppp_pcb *ppp; /* PPP PCB */ ppp_pcb *ppp; /* PPP PCB */
sio_fd_t fd; /* File device ID of port. */ sio_fd_t fd; /* File device ID of port. */
#if VJ_SUPPORT #if VJ_SUPPORT

View File

@ -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); static err_t pppos_link_netif_output_callback(void *pcb, struct pbuf *pb, u_short protocol);
/* Prototypes for procedures local to this file. */ /* 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_connect(pppos_pcb *pppos);
static void pppos_disconnect(pppos_pcb *pppos); static void pppos_disconnect(pppos_pcb *pppos);
static err_t pppos_destroy(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_INITFCS 0xffff /* Initial FCS value */
#define PPP_GOODFCS 0xf0b8 /* Good final 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; 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->ppp = ppp;
pppos->fd = fd; pppos->fd = fd;
ppp_link_set_callbacks(ppp, pppos_link_command_callback, pppos_link_write_callback, pppos_link_netif_output_callback, pppos); 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; 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 static void
pppos_connect(pppos_pcb *pppos) pppos_connect(pppos_pcb *pppos)
{ {
@ -434,6 +454,15 @@ static err_t
pppos_destroy(pppos_pcb *pppos) pppos_destroy(pppos_pcb *pppos)
{ {
ppp_pcb *ppp = pppos->ppp; 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 ? */ /* input pbuf left ? */
pppos_free_current_input_packet(&ppp->rx); 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_vjc_config(ppp_pcb *ppp, int vjcomp, int cidcomp, int maxcid)
{ {
pppos_pcb *pppos = (pppos_pcb *)ppp->link_ctx_cb; pppos_pcb *pppos = (pppos_pcb *)ppp->link_ctx_cb;
if (!pppos_exist(pppos)) {
return;
}
ppp->vj_enabled = vjcomp; ppp->vj_enabled = vjcomp;
pppos->vj_comp.compressSlot = cidcomp; pppos->vj_comp.compressSlot = cidcomp;
pppos->vj_comp.maxSlotIndex = maxcid; pppos->vj_comp.maxSlotIndex = maxcid;