* 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 <sys/types.h>
&r_init, &w_init, NULL, NULL
};
-#ifdef sun
+#if defined(sun) && defined(svr4) /* Solaris 2 */
static struct fmodsw fsw = {
"ppp_comp",
&ppp_compinfo,
#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.
*/
#ifndef sun
# define qprocson(q)
# define qprocsoff(q)
+#define canputnext(q) canput((q)->q_next)
#endif
/*
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;
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);
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;
*/
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
&& (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)) {
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;
}
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;
}
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;