diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index c6f16fc3..8b1abed9 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -165,6 +165,8 @@ struct link_callbacks { void (*vj_config)(ppp_pcb *pcb, void *ctx, int vjcomp, int cidcomp, int maxcid); /* Get and set parameters for the given connection. */ int (*ioctl)(ppp_pcb *pcb, void *ctx, int cmd, void *arg); + /* Pass the processed input packet to the appropriate handler. */ + err_t (*netif_input)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u16_t protocol); }; /* diff --git a/src/include/netif/ppp/pppos.h b/src/include/netif/ppp/pppos.h index 9cc52474..26fd2578 100644 --- a/src/include/netif/ppp/pppos.h +++ b/src/include/netif/ppp/pppos.h @@ -96,14 +96,5 @@ ppp_pcb *pppos_create(struct netif *pppif, sio_fd_t fd, /* PPP over Serial: this is the input function to be called for received data. */ void pppos_input(ppp_pcb *ppp, u_char* data, int len); - -/* - * Functions called from PPP CORE - * - * You may use them if you REALLY know what you are doing. - */ -int pppos_vjc_comp(pppos_pcb *pppos, struct pbuf *pb); -int pppos_vjc_uncomp(pppos_pcb *pppos, struct pbuf *pb); - #endif /* PPPOS_H */ #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index eb901d91..5bd548e2 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -691,26 +691,8 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { goto drop; } - /* FIXME: should we write protent to do that ? */ - switch(protocol) { -#if VJ_SUPPORT - case PPP_VJC_COMP: /* VJ compressed TCP */ - /* VJ is only enabled on PPPoS interfaces */ - if (pcb->vj_enabled && pppos_vjc_comp((pppos_pcb*)pcb->link_ctx_cb, pb) >= 0) { - return; - } - break; - - case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ - /* VJ is only enabled on PPPoS interfaces */ - if (pcb->vj_enabled && pppos_vjc_uncomp((pppos_pcb*)pcb->link_ctx_cb, pb) >= 0) { - return; - } - break; -#endif /* VJ_SUPPORT */ - case PPP_IP: /* Internet Protocol */ PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->num, pb->len)); ip_input(pb, pcb->netif); @@ -724,9 +706,14 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { #endif /* PPP_IPV6_SUPPORT */ default: { - int i; const struct protent *protp; + + /* If callback set, try to pass the input packet to low level protocol */ + if (pcb->link_cb->netif_input && pcb->link_cb->netif_input(pcb, pcb->link_ctx_cb, pb, protocol) == ERR_OK) { + return; + } + /* * Upcall the proper protocol input routine. */ diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 8dce7ae5..811583ee 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -157,6 +157,7 @@ static const struct link_callbacks pppoe_callbacks = { NULL, NULL, NULL, + NULL, NULL }; diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index 4f086650..390ef8c9 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -106,6 +106,7 @@ static const struct link_callbacks pppol2tp_callbacks = { NULL, NULL, NULL, + NULL, NULL }; diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 358fe6db..4c4d087f 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -92,6 +92,7 @@ static void pppos_recv_config(ppp_pcb *ppp, void *ctx, u32_t accm); static int pppos_ioctl(ppp_pcb *pcb, void *ctx, int cmd, void *arg); #if VJ_SUPPORT static void pppos_vjc_config(ppp_pcb *ppp, void *ctx, int vjcomp, int cidcomp, int maxcid); +err_t pppos_netif_input(ppp_pcb *ppp, void *ctx, struct pbuf *p, u16_t protocol); #endif /* VJ_SUPPORT */ /* Prototypes for procedures local to this file. */ @@ -117,7 +118,12 @@ static const struct link_callbacks pppos_callbacks = { #else /* VJ_SUPPORT */ NULL, #endif /* VJ_SUPPORT */ - pppos_ioctl + pppos_ioctl, +#if VJ_SUPPORT + pppos_netif_input +#else /* VJ_SUPPORT */ + NULL +#endif /* VJ_SUPPORT */ }; /* PPP's Asynchronous-Control-Character-Map. The mask array is used @@ -845,48 +851,52 @@ pppos_vjc_config(ppp_pcb *ppp, void *ctx, int vjcomp, int cidcomp, int maxcid) ppp->num, vjcomp, cidcomp, maxcid)); } -int -pppos_vjc_comp(pppos_pcb *pppos, struct pbuf *pb) -{ - ppp_pcb *ppp = pppos->ppp; +err_t pppos_netif_input(ppp_pcb *ppp, void *ctx, struct pbuf *p, u16_t protocol) { int ret; - PPPDEBUG(LOG_INFO, ("pppos_vjc_comp[%d]: vj_comp in pbuf len=%d\n", ppp->num, pb->len)); + pppos_pcb *pppos = (pppos_pcb *)ctx; - /* - * Clip off the VJ header and prepend the rebuilt TCP/IP header and - * pass the result to IP. - */ - ret = vj_uncompress_tcp(&pb, &pppos->vj_comp); - if (ret >= 0) { - ip_input(pb, ppp->netif); - return ret; + switch(protocol) { + case PPP_VJC_COMP: /* VJ compressed TCP */ + if (!ppp->vj_enabled) { + break; + } + /* + * Clip off the VJ header and prepend the rebuilt TCP/IP header and + * pass the result to IP. + */ + PPPDEBUG(LOG_INFO, ("pppos_vjc_comp[%d]: vj_comp in pbuf len=%d\n", ppp->num, p->len)); + ret = vj_uncompress_tcp(&p, &pppos->vj_comp); + if (ret >= 0) { + ip_input(p, pppos->ppp->netif); + return ERR_OK; + } + /* Something's wrong so drop it. */ + PPPDEBUG(LOG_WARNING, ("pppos_vjc_comp[%d]: Dropping VJ compressed\n", ppp->num)); + break; + + case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ + if (!ppp->vj_enabled) { + break; + } + /* + * Process the TCP/IP header for VJ header compression and then pass + * the packet to IP. + */ + PPPDEBUG(LOG_INFO, ("pppos_vjc_uncomp[%d]: vj_un in pbuf len=%d\n", ppp->num, p->len)); + ret = vj_uncompress_uncomp(p, &pppos->vj_comp); + if (ret >= 0) { + ip_input(p, pppos->ppp->netif); + return ERR_OK; + } + /* Something's wrong so drop it. */ + PPPDEBUG(LOG_WARNING, ("pppos_vjc_uncomp[%d]: Dropping VJ uncompressed\n", ppp->num)); + break; + + /* Pass the packet to other handlers */ + default: ; } - /* Something's wrong so drop it. */ - PPPDEBUG(LOG_WARNING, ("pppos_vjc_comp[%d]: Dropping VJ compressed\n", ppp->num)); - return -1; -} - -int -pppos_vjc_uncomp(pppos_pcb *pppos, struct pbuf *pb) -{ - ppp_pcb *ppp = pppos->ppp; - int ret; - PPPDEBUG(LOG_INFO, ("pppos_vjc_uncomp[%d]: vj_un in pbuf len=%d\n", ppp->num, pb->len)); - - /* - * Process the TCP/IP header for VJ header compression and then pass - * the packet to IP. - */ - ret = vj_uncompress_uncomp(pb, &pppos->vj_comp); - if (ret >= 0) { - ip_input(pb, ppp->netif); - return ret; - } - - /* Something's wrong so drop it. */ - PPPDEBUG(LOG_WARNING, ("pppos_vjc_uncomp[%d]: Dropping VJ uncompressed\n", ppp->num)); - return -1; + return ERR_VAL; } #endif /* VJ_SUPPORT */