X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=svr4%2Fppp_comp.c;h=34eda2428ef1203f96d813941938f5a7948faff5;hp=4a33591503f6e484df04f70ee5eaf311acd3ed14;hb=a44a616baa968a263dc273bc06ed79c475b7deec;hpb=3d07235754b30ee9187f041a126d72dbeeac14d8 diff --git a/svr4/ppp_comp.c b/svr4/ppp_comp.c index 4a33591..34eda24 100644 --- a/svr4/ppp_comp.c +++ b/svr4/ppp_comp.c @@ -24,11 +24,11 @@ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, * OR MODIFICATIONS. * - * $Id: ppp_comp.c,v 1.3 1995/05/29 06:43:50 paulus Exp $ + * $Id: ppp_comp.c,v 1.5 1995/10/27 03:56:19 paulus Exp $ */ /* - * This file is used under Solaris 2. + * This file is used under SVR4 and Solaris 2. */ #include @@ -78,7 +78,7 @@ static struct streamtab ppp_compinfo = { &r_init, &w_init, NULL, NULL }; -#ifdef sun +#if defined(sun) && defined(svr4) /* Solaris 2 */ static struct fmodsw fsw = { "ppp_comp", &ppp_compinfo, @@ -124,6 +124,28 @@ typedef struct comp_state { #undef MIN /* just in case */ #define MIN(a, b) ((a) < (b)? (a): (b)) +#ifdef D_MP +/* Use msgpullup if we have other multithreading support. */ +#define PULLUP(mp, len) \ + do { \ + mblk_t *np = msgpullup((mp), (len)); \ + freemsg(mp); \ + mp = np; \ + } while (0) + +#else +/* Use pullupmsg if we don't have any multithreading support. */ +#define PULLUP(mp, len) \ + do { \ + if (!pullupmsg((mp), (len))) { \ + freemsg(mp); \ + mp = 0; \ + } \ + } while (0) + +#endif + + /* * List of compressors we know about. */ @@ -164,6 +186,7 @@ _info(mip) #ifndef sun # define qprocson(q) # define qprocsoff(q) +#define canputnext(q) canput((q)->q_next) #endif /* @@ -406,7 +429,7 @@ static int ppp_comp_wsrv(q) queue_t *q; { - mblk_t *mp, *cmp, *np; + mblk_t *mp, *cmp = NULL, *np; comp_state_t *cp; int len, proto, type; struct ip *ip; @@ -429,17 +452,15 @@ ppp_comp_wsrv(q) if (len > PPP_HDRLEN + MAX_IPHDR) len = PPP_HDRLEN + MAX_IPHDR; if (mp->b_wptr < mp->b_rptr + len || mp->b_datap->db_ref > 1) { - np = msgpullup(mp, len); - freemsg(mp); - if (np == 0) { + PULLUP(mp, len); + if (mp == 0) { #if DEBUG - cmn_err(CE_CONT, "ppp_comp_wsrv: msgpullup failed\n"); + cmn_err(CE_CONT, "ppp_comp_wsrv: pullup failed\n"); #endif cp->stats.ppp_oerrors++; putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR); continue; } - mp = np; } proto = PPP_PROTOCOL(mp->b_rptr); @@ -558,7 +579,7 @@ ppp_comp_rsrv(q) queue_t *q; { int proto, rv, i; - mblk_t *mp, *dmp, *np; + mblk_t *mp, *dmp = NULL, *np; uchar_t *dp, *iphdr; comp_state_t *cp; int len, hlen, vjlen, iphlen; @@ -580,11 +601,9 @@ ppp_comp_rsrv(q) */ hlen = MIN(len, PPP_HDRLEN); if (mp->b_wptr < mp->b_rptr + hlen) { - np = msgpullup(mp, hlen); - if (np == 0) + PULLUP(mp, hlen); + if (mp == 0) goto bad; - freemsg(mp); - mp = np; } dp = mp->b_rptr; if (PPP_ADDRESS(dp) == PPP_ALLSTATIONS @@ -644,26 +663,25 @@ ppp_comp_rsrv(q) && (cp->flags & CCP_DECOMP_RUN) && cp->rstate && (cp->flags & CCP_ERR) == 0) { rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp); - if (dmp != NULL) { + switch (rv) { + case DECOMP_OK: freemsg(mp); mp = dmp; - } else { - switch (rv) { - case DECOMP_OK: - /* no error, but no packet returned */ - freemsg(mp); + if (mp == NULL) { + /* no error, but no packet returned either. */ continue; - case DECOMP_ERROR: - cp->flags |= CCP_ERROR; - ++cp->stats.ppp_ierrors; - putctl1(q->q_next, M_CTL, PPPCTL_IERROR); - break; - case DECOMP_FATALERROR: - cp->flags |= CCP_FATALERROR; - ++cp->stats.ppp_ierrors; - putctl1(q->q_next, M_CTL, PPPCTL_IERROR); - break; } + break; + case DECOMP_ERROR: + cp->flags |= CCP_ERROR; + ++cp->stats.ppp_ierrors; + putctl1(q->q_next, M_CTL, PPPCTL_IERROR); + break; + case DECOMP_FATALERROR: + cp->flags |= CCP_FATALERROR; + ++cp->stats.ppp_ierrors; + putctl1(q->q_next, M_CTL, PPPCTL_IERROR); + break; } } } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) { @@ -693,11 +711,10 @@ ppp_comp_rsrv(q) if (proto == PPP_VJC_COMP) { hlen = MIN(len, MAX_VJHDR); if (np->b_wptr < dp + hlen) { - np = msgpullup(mp, hlen + PPP_HDRLEN); - if (np == 0) + PULLUP(mp, hlen + PPP_HDRLEN); + if (mp == 0) goto bad; - freemsg(mp); - mp = np; + np = mp; dp = np->b_rptr + PPP_HDRLEN; } @@ -749,11 +766,10 @@ ppp_comp_rsrv(q) hlen = MIN(len, MAX_IPHDR); if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1 || mp->b_datap->db_ref > 1) { - np = msgpullup(mp, hlen + PPP_HDRLEN); - if (np == 0) + PULLUP(mp, hlen + PPP_HDRLEN); + if (mp == 0) goto bad; - freemsg(mp); - mp = np; + np = mp; dp = np->b_rptr + PPP_HDRLEN; } @@ -792,13 +808,14 @@ ppp_comp_ccp(q, mp, rcvd) if (len < PPP_HDRLEN + CCP_HDRLEN) return; if (mp->b_wptr < mp->b_rptr + len) { - np = msgpullup(mp, len); - if (np == 0) { - cmn_err(CE_CONT, "ppp_comp_ccp: msgpullup failed\n"); + /* XXX this isn't right, because it may free mp */ + PULLUP(mp, len); + if (mp == 0) { + cmn_err(CE_CONT, "ppp_comp_ccp: pullup failed\n"); return; } - } else - np = mp; + } + np = mp; cp = (comp_state_t *) q->q_ptr; dp = mp->b_rptr + PPP_HDRLEN;