From e6465a6f4473647c71499fb44796da05ccfca77d Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Mon, 16 Feb 2015 00:24:17 +0100 Subject: [PATCH] PPP, PPPoS, moved VJ from PPP core to PPPoS VJ is only available for PPPoS, moved VJ from PPP CORE to PPPoS. --- src/include/netif/ppp/ppp.h | 7 +-- src/include/netif/ppp/pppos.h | 9 +++ src/netif/ppp/ppp.c | 35 +++-------- src/netif/ppp/pppoe.c | 35 +++++++---- src/netif/ppp/pppol2tp.c | 36 ++++++++---- src/netif/ppp/pppos.c | 106 ++++++++++++++++++++++++++++++---- 6 files changed, 161 insertions(+), 67 deletions(-) diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 9fd88e68..1d00ff6b 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -391,11 +391,11 @@ struct ppp_pcb_s { #endif /* PPP_IPV6_SUPPORT */ unsigned int ask_for_local :1; /* request our address from peer */ unsigned int lcp_echo_timer_running :1; /* set if a timer is running */ -#if PPPOS_SUPPORT && VJ_SUPPORT +#if VJ_SUPPORT unsigned int vj_enabled :1; /* Flag indicating VJ compression enabled. */ #else unsigned int :1; /* 1 bit of padding */ -#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ +#endif /* VJ_SUPPORT */ unsigned int :5; /* 5 bits of padding to round out to 16 bits */ #if PPPOS_SUPPORT @@ -403,9 +403,6 @@ struct ppp_pcb_s { ext_accm out_accm; /* Async-Ctl-Char-Map for output. */ ext_accm xmit_accm; /* extended transmit ACCM */ ppp_pcb_rx rx; -#if VJ_SUPPORT - struct vjcompress vj_comp; /* Van Jacobson compression header. */ -#endif /* VJ_SUPPORT */ #endif /* PPPOS_SUPPORT */ u32_t last_xmit; /* Time of last transmission. */ diff --git a/src/include/netif/ppp/pppos.h b/src/include/netif/ppp/pppos.h index cdef3c2f..232e92bc 100644 --- a/src/include/netif/ppp/pppos.h +++ b/src/include/netif/ppp/pppos.h @@ -38,6 +38,7 @@ #define PPPOS_H #include "ppp.h" +#include "vj.h" /* * PPPoS interface control block. @@ -46,6 +47,9 @@ typedef struct pppos_pcb_s pppos_pcb; struct pppos_pcb_s { ppp_pcb *ppp; /* PPP PCB */ sio_fd_t fd; /* File device ID of port. */ +#if VJ_SUPPORT + struct vjcompress vj_comp; /* Van Jacobson compression header. */ +#endif /* VJ_SUPPORT */ }; /* Create a new PPPoS session. */ @@ -55,5 +59,10 @@ ppp_pcb *ppp_over_serial_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 *pcb, u_char* data, int len); + +void pppos_vjc_config(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid); +int pppos_vjc_comp(ppp_pcb *pcb, struct pbuf *pb); +int pppos_vjc_uncomp(ppp_pcb *pcb, 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 f808f4fa..0fec0774 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -93,6 +93,7 @@ #include "lwip/ip.h" /* for ip_input() */ #include "netif/ppp/ppp_impl.h" +#include "netif/ppp/pppos.h" #include "netif/ppp/fsm.h" #include "netif/ppp/lcp.h" @@ -581,31 +582,15 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { #if VJ_SUPPORT case PPP_VJC_COMP: /* VJ compressed TCP */ - PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_comp in pbuf len=%d\n", pcb->num, pb->len)); - /* - * Clip off the VJ header and prepend the rebuilt TCP/IP header and - * pass the result to IP. - */ - if (vj_uncompress_tcp(&pb, &pcb->vj_comp) >= 0) { - ip_input(pb, pcb->netif); + if (pppos_vjc_comp(pcb, pb) >= 0) { return; } - /* Something's wrong so drop it. */ - PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ compressed\n", pcb->num)); break; case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ - PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_un in pbuf len=%d\n", pcb->num, pb->len)); - /* - * Process the TCP/IP header for VJ header compression and then pass - * the packet to IP. - */ - if (vj_uncompress_uncomp(pb, &pcb->vj_comp) >= 0) { - ip_input(pb, pcb->netif); + if (pppos_vjc_uncomp(pcb, pb) >= 0) { return; } - /* Something's wrong so drop it. */ - PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ uncompressed\n", pcb->num)); break; #endif /* VJ_SUPPORT */ @@ -1199,20 +1184,14 @@ int cifproxyarp(ppp_pcb *pcb, u32_t his_adr) { * sifvjcomp - config tcp header compression */ int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) { - -#if PPPOS_SUPPORT && VJ_SUPPORT - pcb->vj_enabled = vjcomp; - pcb->vj_comp.compressSlot = cidcomp; - pcb->vj_comp.maxSlotIndex = maxcid; - PPPDEBUG(LOG_INFO, ("sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n", - vjcomp, cidcomp, maxcid)); -#else /* PPPOS_SUPPORT && VJ_SUPPORT */ +#if VJ_SUPPORT + pppos_vjc_config(pcb, vjcomp, cidcomp, maxcid); +#else /* VJ_SUPPORT */ LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(vjcomp); LWIP_UNUSED_ARG(cidcomp); LWIP_UNUSED_ARG(maxcid); -#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ - +#endif /* VJ_SUPPORT */ return 0; } diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 8cc51129..d64d05e6 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -83,6 +83,7 @@ #include "netif/ppp/ppp_impl.h" #include "netif/ppp/lcp.h" +#include "netif/ppp/ipcp.h" #include "netif/ppp/pppoe.h" /* Add a 16 bit unsigned value to a buffer pointed to by PTR */ @@ -920,8 +921,10 @@ pppoe_connect(struct pppoe_softc *sc) { int err; ppp_pcb *ppp = sc->pcb; - lcp_options *wo; - lcp_options *ao; + lcp_options *lcp_wo; + lcp_options *lcp_ao; + ipcp_options *ipcp_wo; + ipcp_options *ipcp_ao; if (sc->sc_state != PPPOE_STATE_INITIAL) { return EBUSY; @@ -941,17 +944,25 @@ pppoe_connect(struct pppoe_softc *sc) ppp_clear(ppp); - wo = &ppp->lcp_wantoptions; - wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; + lcp_wo = &ppp->lcp_wantoptions; + lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ + lcp_wo->neg_asyncmap = 0; + lcp_wo->neg_pcompression = 0; + lcp_wo->neg_accompression = 0; - ao = &ppp->lcp_allowoptions; - ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; + lcp_ao = &ppp->lcp_allowoptions; + lcp_ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ + lcp_ao->neg_asyncmap = 0; + lcp_ao->neg_pcompression = 0; + lcp_ao->neg_accompression = 0; + + ipcp_wo = &ppp->ipcp_wantoptions; + ipcp_wo->neg_vj = 0; + ipcp_wo->old_vj = 0; + + ipcp_ao = &ppp->ipcp_allowoptions; + ipcp_ao->neg_vj = 0; + ipcp_ao->old_vj = 0; /* save state, in case we fail to send PADI */ sc->sc_state = PPPOE_STATE_PADI_SENT; diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index d3dc182f..948ff31b 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -60,6 +60,8 @@ #include "lwip/snmp.h" #include "netif/ppp/ppp_impl.h" +#include "netif/ppp/lcp.h" +#include "netif/ppp/ipcp.h" #include "netif/ppp/pppol2tp.h" #include "netif/ppp/magic.h" @@ -259,8 +261,10 @@ static err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) { static err_t pppol2tp_connect(pppol2tp_pcb *l2tp) { err_t err; ppp_pcb *ppp = l2tp->ppp; - lcp_options *wo; - lcp_options *ao; + lcp_options *lcp_wo; + lcp_options *lcp_ao; + ipcp_options *ipcp_wo; + ipcp_options *ipcp_ao; if (l2tp->phase != PPPOL2TP_STATE_INITIAL) { return ERR_VAL; @@ -270,17 +274,25 @@ static err_t pppol2tp_connect(pppol2tp_pcb *l2tp) { ppp_clear(ppp); - wo = &ppp->lcp_wantoptions; - wo->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - wo->neg_asyncmap = 0; - wo->neg_pcompression = 0; - wo->neg_accompression = 0; + lcp_wo = &ppp->lcp_wantoptions; + lcp_wo->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ + lcp_wo->neg_asyncmap = 0; + lcp_wo->neg_pcompression = 0; + lcp_wo->neg_accompression = 0; - ao = &ppp->lcp_allowoptions; - ao->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ - ao->neg_asyncmap = 0; - ao->neg_pcompression = 0; - ao->neg_accompression = 0; + lcp_ao = &ppp->lcp_allowoptions; + lcp_ao->mru = 1500; /* FIXME: MTU depends if we support IP fragmentation or not */ + lcp_ao->neg_asyncmap = 0; + lcp_ao->neg_pcompression = 0; + lcp_ao->neg_accompression = 0; + + ipcp_wo = &ppp->ipcp_wantoptions; + ipcp_wo->neg_vj = 0; + ipcp_wo->old_vj = 0; + + ipcp_ao = &ppp->ipcp_allowoptions; + ipcp_ao->neg_vj = 0; + ipcp_ao->old_vj = 0; /* Listen to a random source port, we need to do that instead of using udp_connect() * because the L2TP LNS might answer with its own random source port (!= 1701) diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 78f339de..1ed856f0 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -64,7 +64,7 @@ static void pppos_input_callback(void *arg); static void pppos_xmit(pppos_pcb *sc, struct pbuf *nb); static void pppos_free_current_input_packet(ppp_pcb_rx *pcrx); static struct pbuf *pppos_append(u_char c, struct pbuf *nb, ext_accm *out_accm); -static void pppos_drop(ppp_pcb_rx *pcrx); +static void pppos_drop(pppos_pcb *pcrx); /* PPP's Asynchronous-Control-Character-Map. The mask array is used * to select the specific bit for a character. */ @@ -236,7 +236,7 @@ pppos_link_netif_output_callback(void *pcb, struct pbuf *pb, u_short protocol) * this is an IP packet. */ if (protocol == PPP_IP && ppp->vj_enabled) { - switch (vj_compress_tcp(&ppp->vj_comp, pb)) { + switch (vj_compress_tcp(&sc->vj_comp, pb)) { case TYPE_IP: /* No change... protocol = PPP_IP_PROTOCOL; */ @@ -329,6 +329,10 @@ static void pppos_connect(pppos_pcb *pcb) { ppp_pcb *ppp = pcb->ppp; +#if !VJ_SUPPORT + ipcp_options *ipcp_wo; + ipcp_options *ipcp_ao; +#endif /* !VJ_SUPPORT */ /* input pbuf left over from last session? */ pppos_free_current_input_packet(&ppp->rx); @@ -339,7 +343,16 @@ pppos_connect(pppos_pcb *pcb) ppp->rx.fd = pcb->fd; #if VJ_SUPPORT - vj_compress_init(&ppp->vj_comp); + vj_compress_init(&pcb->vj_comp); +#else /* VJ_SUPPORT */ + /* Don't even try to negotiate VJ if VJ is disabled */ + ipcp_wo = &ppp->ipcp_wantoptions; + ipcp_wo->neg_vj = 0; + ipcp_wo->old_vj = 0; + + ipcp_ao = &ppp->ipcp_allowoptions; + ipcp_ao->neg_vj = 0; + ipcp_ao->old_vj = 0; #endif /* VJ_SUPPORT */ /* @@ -406,6 +419,7 @@ void pppos_input(ppp_pcb *pcb, u_char *s, int l) { ppp_pcb_rx *pcrx = &pcb->rx; + pppos_pcb *sc = (pppos_pcb *)pcb->link_ctx_cb; struct pbuf *next_pbuf; u_char cur_char; u_char escaped; @@ -438,7 +452,7 @@ pppos_input(ppp_pcb *pcb, u_char *s, int l) ("pppos_input[%d]: Dropping incomplete packet %d\n", pcb->num, pcrx->in_state)); LINK_STATS_INC(link.lenerr); - pppos_drop(pcrx); + pppos_drop(sc); /* If the fcs is invalid, drop the packet. */ } else if (pcrx->in_fcs != PPP_GOODFCS) { PPPDEBUG(LOG_INFO, @@ -446,7 +460,7 @@ pppos_input(ppp_pcb *pcb, u_char *s, int l) pcb->num, pcrx->in_fcs, pcrx->in_protocol)); /* Note: If you get lots of these, check for UART frame errors or try different baud rate */ LINK_STATS_INC(link.chkerr); - pppos_drop(pcrx); + pppos_drop(sc); /* Otherwise it's a good packet so pass it on. */ } else { struct pbuf *inp; @@ -592,7 +606,7 @@ pppos_input(ppp_pcb *pcb, u_char *s, int l) * the received pbuf chain in case a new packet starts. */ PPPDEBUG(LOG_ERR, ("pppos_input[%d]: NO FREE PBUFS!\n", pcb->num)); LINK_STATS_INC(link.memerr); - pppos_drop(pcrx); + pppos_drop(sc); pcrx->in_state = PDSTART; /* Wait for flag sequence. */ break; } @@ -649,6 +663,77 @@ drop: } #endif /* PPP_INPROC_MULTITHREADED */ +#if VJ_SUPPORT +void +pppos_vjc_config(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) +{ + pppos_pcb *sc = (pppos_pcb *)pcb->link_ctx_cb; + pcb->vj_enabled = vjcomp; + sc->vj_comp.compressSlot = cidcomp; + sc->vj_comp.maxSlotIndex = maxcid; + PPPDEBUG(LOG_INFO, ("pppos_vjc_config: VJ compress enable=%d slot=%d max slot=%d\n", + vjcomp, cidcomp, maxcid)); +} + +int +pppos_vjc_comp(ppp_pcb *pcb, struct pbuf *pb) +{ + pppos_pcb *sc; + int ret; + PPPDEBUG(LOG_INFO, ("pppos_vjc_comp[%d]: vj_comp in pbuf len=%d\n", pcb->num, pb->len)); + + /* VJ is only enabled on PPPoS interfaces */ + if (!pcb->vj_enabled) { + goto drop; + } + sc = (pppos_pcb *)pcb->link_ctx_cb; + + /* + * Clip off the VJ header and prepend the rebuilt TCP/IP header and + * pass the result to IP. + */ + ret = vj_uncompress_tcp(&pb, &sc->vj_comp); + if (ret >= 0) { + ip_input(pb, pcb->netif); + return ret; + } + +drop: + /* Something's wrong so drop it. */ + PPPDEBUG(LOG_WARNING, ("pppos_vjc_comp[%d]: Dropping VJ compressed\n", pcb->num)); + return -1; +} + +int +pppos_vjc_uncomp(ppp_pcb *pcb, struct pbuf *pb) +{ + pppos_pcb *sc; + int ret; + PPPDEBUG(LOG_INFO, ("pppos_vjc_uncomp[%d]: vj_un in pbuf len=%d\n", pcb->num, pb->len)); + + /* VJ is only enabled on PPPoS interfaces */ + if (!pcb->vj_enabled) { + goto drop; + } + sc = (pppos_pcb *)pcb->link_ctx_cb; + + /* + * Process the TCP/IP header for VJ header compression and then pass + * the packet to IP. + */ + ret = vj_uncompress_uncomp(pb, &sc->vj_comp); + if (ret >= 0) { + ip_input(pb, pcb->netif); + return ret; + } + +drop: + /* Something's wrong so drop it. */ + PPPDEBUG(LOG_WARNING, ("pppos_vjc_uncomp[%d]: Dropping VJ uncompressed\n", pcb->num)); + return -1; +} +#endif /* VJ_SUPPORT */ + static void pppos_xmit(pppos_pcb *sc, struct pbuf *nb) { @@ -784,10 +869,11 @@ pppos_append(u_char c, struct pbuf *nb, ext_accm *out_accm) * Drop the input packet and increase error counters. */ static void -pppos_drop(ppp_pcb_rx *pcrx) +pppos_drop(pppos_pcb *sc) { -#if LWIP_SNMP || VJ_SUPPORT - ppp_pcb *pcb = (ppp_pcb*)pcrx->pcb; + ppp_pcb_rx *pcrx = &sc->ppp->rx; +#if LWIP_SNMP + ppp_pcb *pcb = sc->ppp; #endif /* LWIP_SNMP || VJ_SUPPORT */ if (pcrx->in_head != NULL) { #if 0 @@ -797,7 +883,7 @@ pppos_drop(ppp_pcb_rx *pcrx) } pppos_free_current_input_packet(pcrx); #if VJ_SUPPORT - vj_uncompress_err(&pcb->vj_comp); + vj_uncompress_err(&sc->vj_comp); #endif /* VJ_SUPPORT */ LINK_STATS_INC(link.drop);