17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * spppcomp.c - STREAMS module for kernel-level compression and CCP support.
37c478bd9Sstevel@tonic-gate  *
4f53eecf5SJames Carlson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
6*48bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
97c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
107c478bd9Sstevel@tonic-gate  * notice appears in all copies.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
137c478bd9Sstevel@tonic-gate  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
147c478bd9Sstevel@tonic-gate  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
157c478bd9Sstevel@tonic-gate  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
167c478bd9Sstevel@tonic-gate  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
177c478bd9Sstevel@tonic-gate  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * Copyright (c) 1994 The Australian National University.
207c478bd9Sstevel@tonic-gate  * All rights reserved.
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
237c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
247c478bd9Sstevel@tonic-gate  * notice appears in all copies.  This software is provided without any
257c478bd9Sstevel@tonic-gate  * warranty, express or implied. The Australian National University
267c478bd9Sstevel@tonic-gate  * makes no representations about the suitability of this software for
277c478bd9Sstevel@tonic-gate  * any purpose.
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
307c478bd9Sstevel@tonic-gate  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
317c478bd9Sstevel@tonic-gate  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
327c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
337c478bd9Sstevel@tonic-gate  * OF SUCH DAMAGE.
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
367c478bd9Sstevel@tonic-gate  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
377c478bd9Sstevel@tonic-gate  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
387c478bd9Sstevel@tonic-gate  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
397c478bd9Sstevel@tonic-gate  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
407c478bd9Sstevel@tonic-gate  * OR MODIFICATIONS.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * This module is derived from the original SVR4 STREAMS PPP compression
437c478bd9Sstevel@tonic-gate  * module originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * James Carlson <james.d.carlson@sun.com> and Adi Masputra
467c478bd9Sstevel@tonic-gate  * <adi.masputra@sun.com> rewrote and restructured the code for improved
477c478bd9Sstevel@tonic-gate  * performance and scalability.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	RCSID	"$Id: spppcomp.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
537c478bd9Sstevel@tonic-gate #include <sys/debug.h>
547c478bd9Sstevel@tonic-gate #include <sys/param.h>
557c478bd9Sstevel@tonic-gate #include <sys/stream.h>
567c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
577c478bd9Sstevel@tonic-gate #include <sys/errno.h>
587c478bd9Sstevel@tonic-gate #include <sys/conf.h>
597c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
607c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
617c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
627c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
637c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
647c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
657c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
667c478bd9Sstevel@tonic-gate #include <netinet/in.h>
677c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
687c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
697c478bd9Sstevel@tonic-gate #include <net/pppio.h>
707c478bd9Sstevel@tonic-gate #include <net/vjcompress.h>
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* Defined for platform-neutral include file */
737c478bd9Sstevel@tonic-gate #define	PACKETPTR	mblk_t *
747c478bd9Sstevel@tonic-gate #include <net/ppp-comp.h>
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #include "s_common.h"
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #ifdef DEBUG
797c478bd9Sstevel@tonic-gate #define	SPC_DEBUG
807c478bd9Sstevel@tonic-gate #endif
817c478bd9Sstevel@tonic-gate #include "spppcomp.h"
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * This is used to tag official Solaris sources.  Please do not define
857c478bd9Sstevel@tonic-gate  * "INTERNAL_BUILD" when building this software outside of Sun
867c478bd9Sstevel@tonic-gate  * Microsystems.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #ifdef INTERNAL_BUILD
897c478bd9Sstevel@tonic-gate /* MODINFO is limited to 32 characters. */
90002c70ffScarlsonj const char spppcomp_module_description[] = "PPP 4.0 compression";
917c478bd9Sstevel@tonic-gate #else /* INTERNAL_BUILD */
927c478bd9Sstevel@tonic-gate const char spppcomp_module_description[] =
937c478bd9Sstevel@tonic-gate 	"ANU PPP compression $Revision: 1.16$ ";
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* LINTED */
967c478bd9Sstevel@tonic-gate static const char buildtime[] = "Built " __DATE__ " at " __TIME__
977c478bd9Sstevel@tonic-gate #ifdef DEBUG
987c478bd9Sstevel@tonic-gate " DEBUG"
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate "\n";
1017c478bd9Sstevel@tonic-gate #endif /* INTERNAL_BUILD */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static int	spppcomp_open(queue_t *, dev_t *, int, int, cred_t *);
1047c478bd9Sstevel@tonic-gate static int	spppcomp_close(queue_t *, int, cred_t *);
105f53eecf5SJames Carlson static void	spppcomp_rput(queue_t *, mblk_t *);
106f53eecf5SJames Carlson static void	spppcomp_rsrv(queue_t *);
107f53eecf5SJames Carlson static void	spppcomp_wput(queue_t *, mblk_t *);
108f53eecf5SJames Carlson static void	spppcomp_wsrv(queue_t *);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_MINPSZ	(0)
1117c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_MAXPSZ	(INFPSZ)
1127c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_HIWAT	(PPP_MTU * 20)
1137c478bd9Sstevel@tonic-gate #define	PPPCOMP_MI_LOWAT	(PPP_MTU * 18)
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static struct module_info spppcomp_modinfo = {
1167c478bd9Sstevel@tonic-gate 	COMP_MOD_ID,		/* mi_idnum */
1177c478bd9Sstevel@tonic-gate 	COMP_MOD_NAME,		/* mi_idname */
1187c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_MINPSZ,	/* mi_minpsz */
1197c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_MAXPSZ,	/* mi_maxpsz */
1207c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_HIWAT,	/* mi_hiwat */
1217c478bd9Sstevel@tonic-gate 	PPPCOMP_MI_LOWAT	/* mi_lowat */
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate static struct qinit spppcomp_rinit = {
125f53eecf5SJames Carlson 	(int (*)())spppcomp_rput, /* qi_putp */
126f53eecf5SJames Carlson 	(int (*)())spppcomp_rsrv, /* qi_srvp */
1277c478bd9Sstevel@tonic-gate 	spppcomp_open,		/* qi_qopen */
1287c478bd9Sstevel@tonic-gate 	spppcomp_close,		/* qi_qclose */
1297c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1307c478bd9Sstevel@tonic-gate 	&spppcomp_modinfo,	/* qi_minfo */
1317c478bd9Sstevel@tonic-gate 	NULL			/* qi_mstat */
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate static struct qinit spppcomp_winit = {
135f53eecf5SJames Carlson 	(int (*)())spppcomp_wput, /* qi_putp */
136f53eecf5SJames Carlson 	(int (*)())spppcomp_wsrv, /* qi_srvp */
1377c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qopen */
1387c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qclose */
1397c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1407c478bd9Sstevel@tonic-gate 	&spppcomp_modinfo,	/* qi_minfo */
1417c478bd9Sstevel@tonic-gate 	NULL			/* qi_mstat */
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate struct streamtab spppcomp_tab = {
1457c478bd9Sstevel@tonic-gate 	&spppcomp_rinit,	/* st_rdinit */
1467c478bd9Sstevel@tonic-gate 	&spppcomp_winit,	/* st_wrinit */
1477c478bd9Sstevel@tonic-gate 	NULL,			/* st_muxrinit */
1487c478bd9Sstevel@tonic-gate 	NULL			/* st_muxwinit */
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /* Set non-zero to debug algorithm-specific problems alone. */
1527c478bd9Sstevel@tonic-gate #define	ALG_DEBUG	0
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	MAX_IPHLEN	(0x0f << 2)
1557c478bd9Sstevel@tonic-gate #define	MAX_TCPHLEN	(0x0f << 2)
1567c478bd9Sstevel@tonic-gate #define	MAX_TCPIPHLEN	(MAX_IPHLEN + MAX_TCPHLEN) /* max TCP/IP header size */
1577c478bd9Sstevel@tonic-gate #define	MAX_VJHDR	(20)		/* max VJ compressed header size (?) */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #if 0
1607c478bd9Sstevel@tonic-gate #define	DBGSTART	CE_CONT, COMP_MOD_NAME "%d: "
1617c478bd9Sstevel@tonic-gate #define	CKDEBUG(x)	cmn_err x
1627c478bd9Sstevel@tonic-gate #else
1637c478bd9Sstevel@tonic-gate #define	DBGSTART	COMP_MOD_NAME "%d: "
1647c478bd9Sstevel@tonic-gate #define	CKDEBUG(x)	printf x
1657c478bd9Sstevel@tonic-gate #endif
1667c478bd9Sstevel@tonic-gate #define	CPDEBUG(x)	(IS_CP_KDEBUG(cp) ? CKDEBUG(x) : (void)0)
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * List of compressors we know about.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate #if DO_BSD_COMPRESS
1727c478bd9Sstevel@tonic-gate extern struct compressor ppp_bsd_compress;
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate #if DO_DEFLATE
1757c478bd9Sstevel@tonic-gate extern struct compressor ppp_deflate;
1767c478bd9Sstevel@tonic-gate extern struct compressor ppp_deflate_draft;
1777c478bd9Sstevel@tonic-gate #endif
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate struct compressor *ppp_compressors[] = {
1807c478bd9Sstevel@tonic-gate #if DO_BSD_COMPRESS
1817c478bd9Sstevel@tonic-gate 	&ppp_bsd_compress,
1827c478bd9Sstevel@tonic-gate #endif
1837c478bd9Sstevel@tonic-gate #if DO_DEFLATE
1847c478bd9Sstevel@tonic-gate 	&ppp_deflate,
1857c478bd9Sstevel@tonic-gate 	&ppp_deflate_draft,
1867c478bd9Sstevel@tonic-gate #endif
1877c478bd9Sstevel@tonic-gate 	NULL
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * LCP_USE_DFLT() removed by James Carlson.  RFC 1661 section 6.6 has
1927c478bd9Sstevel@tonic-gate  * this to say on the topic:
1937c478bd9Sstevel@tonic-gate  *
1947c478bd9Sstevel@tonic-gate  *    The Address and Control fields MUST NOT be compressed when sending
1957c478bd9Sstevel@tonic-gate  *    any LCP packet.  This rule guarantees unambiguous recognition of
1967c478bd9Sstevel@tonic-gate  *    LCP packets.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate static void	spppcomp_ioctl(queue_t *, mblk_t *, sppp_comp_t *);
2007c478bd9Sstevel@tonic-gate static int	spppcomp_mctl(queue_t *, mblk_t *);
2017c478bd9Sstevel@tonic-gate static mblk_t	*spppcomp_outpkt(queue_t *, mblk_t *);
2027c478bd9Sstevel@tonic-gate static mblk_t	*spppcomp_inpkt(queue_t *, mblk_t *);
2037c478bd9Sstevel@tonic-gate static int	spppcomp_kstat_update(kstat_t *, int);
2047c478bd9Sstevel@tonic-gate static void	comp_ccp(queue_t *, mblk_t *, sppp_comp_t *, boolean_t);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Values for checking inter-arrival times on interrupt stacks.  These
2087c478bd9Sstevel@tonic-gate  * are used to prevent CPU hogging in interrupt context.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate #define	MIN_ARRIVAL_TIME	5000000	/* interarrival time in nanoseconds */
2117c478bd9Sstevel@tonic-gate #define	MAX_FAST_ARRIVALS	10	/* maximum packet count */
2127c478bd9Sstevel@tonic-gate hrtime_t spppcomp_min_arrival = MIN_ARRIVAL_TIME;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate static const char *kstats_names[] = {
2157c478bd9Sstevel@tonic-gate #ifdef SPCDEBUG_KSTATS_NAMES
2167c478bd9Sstevel@tonic-gate 	SPPPCOMP_KSTATS_NAMES,
2177c478bd9Sstevel@tonic-gate 	SPCDEBUG_KSTATS_NAMES
2187c478bd9Sstevel@tonic-gate #else
2197c478bd9Sstevel@tonic-gate 	SPPPCOMP_KSTATS_NAMES
2207c478bd9Sstevel@tonic-gate #endif
2217c478bd9Sstevel@tonic-gate };
2227c478bd9Sstevel@tonic-gate static const char *kstats64_names[] = { SPPPCOMP_KSTATS64_NAMES };
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * spppcomp_open()
2267c478bd9Sstevel@tonic-gate  *
2277c478bd9Sstevel@tonic-gate  * MT-Perimeters:
2287c478bd9Sstevel@tonic-gate  *    exclusive inner.
2297c478bd9Sstevel@tonic-gate  *
2307c478bd9Sstevel@tonic-gate  * Description:
2317c478bd9Sstevel@tonic-gate  *    Common open procedure for module.
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate /* ARGSUSED */
2347c478bd9Sstevel@tonic-gate static int
2357c478bd9Sstevel@tonic-gate spppcomp_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	sppp_comp_t	*cp;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (q->q_ptr != NULL) {
2407c478bd9Sstevel@tonic-gate 		return (0);
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 	if (sflag != MODOPEN) {
2437c478bd9Sstevel@tonic-gate 		return (EINVAL);
2447c478bd9Sstevel@tonic-gate 	}
245f53eecf5SJames Carlson 	cp = kmem_zalloc(sizeof (sppp_comp_t), KM_SLEEP);
2467c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = (caddr_t)cp;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	cp->cp_mru = PPP_MRU;
2497c478bd9Sstevel@tonic-gate 	cp->cp_mtu = PPP_MTU;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	mutex_init(&cp->cp_pair_lock, NULL, MUTEX_DRIVER, NULL);
2527c478bd9Sstevel@tonic-gate 	vj_compress_init(&cp->cp_vj, -1);
2537c478bd9Sstevel@tonic-gate 	cp->cp_nxslots = -1;
2547c478bd9Sstevel@tonic-gate 	cp->cp_effort = -1;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	qprocson(q);
2577c478bd9Sstevel@tonic-gate 	return (0);
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * spppcomp_close()
2627c478bd9Sstevel@tonic-gate  *
2637c478bd9Sstevel@tonic-gate  * MT-Perimeters:
2647c478bd9Sstevel@tonic-gate  *    exclusive inner.
2657c478bd9Sstevel@tonic-gate  *
2667c478bd9Sstevel@tonic-gate  * Description:
2677c478bd9Sstevel@tonic-gate  *    Common close procedure for module.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate /* ARGSUSED */
2707c478bd9Sstevel@tonic-gate static int
2717c478bd9Sstevel@tonic-gate spppcomp_close(queue_t *q, int flag, cred_t *credp)
2727c478bd9Sstevel@tonic-gate {
273f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	qprocsoff(q);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "close flags=0x%b\n",
2787c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), cp->cp_flags,
2797c478bd9Sstevel@tonic-gate 	    CP_FLAGSSTR));
2807c478bd9Sstevel@tonic-gate 	mutex_destroy(&cp->cp_pair_lock);
2817c478bd9Sstevel@tonic-gate 	if (cp->cp_kstats) {
2827c478bd9Sstevel@tonic-gate 		ASSERT(IS_CP_HASUNIT(cp));
2837c478bd9Sstevel@tonic-gate 		kstat_delete(cp->cp_kstats);
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
2867c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_free)(cp->cp_xstate);
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
2897c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_free)(cp->cp_rstate);
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	kmem_free(cp, sizeof (sppp_comp_t));
2927c478bd9Sstevel@tonic-gate 	q->q_ptr = WR(q)->q_ptr = NULL;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	return (0);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate  * spppcomp_wput()
2997c478bd9Sstevel@tonic-gate  *
3007c478bd9Sstevel@tonic-gate  * MT-Perimeters:
3017c478bd9Sstevel@tonic-gate  *    exclusive inner.
3027c478bd9Sstevel@tonic-gate  *
3037c478bd9Sstevel@tonic-gate  * Description:
3047c478bd9Sstevel@tonic-gate  *    Write-side put procedure.  Packets from above us arrive here.
3057c478bd9Sstevel@tonic-gate  *
3067c478bd9Sstevel@tonic-gate  *	The data handling logic is a little tricky here.  We defer to
3077c478bd9Sstevel@tonic-gate  *	the service routine if q_first isn't NULL (to preserve message
3087c478bd9Sstevel@tonic-gate  *	ordering after deferring a previous message), bcanputnext() is
3097c478bd9Sstevel@tonic-gate  *	FALSE (to handle flow control), or we need a lot of processing
3107c478bd9Sstevel@tonic-gate  *	and we're in an interrupt context (on the theory that we're
3117c478bd9Sstevel@tonic-gate  *	already on a very long call stack at that point).  Since many
3127c478bd9Sstevel@tonic-gate  *	callers will be in a non-interrupt context, this means that
3137c478bd9Sstevel@tonic-gate  *	most processing will be performed here in-line, and deferral
3147c478bd9Sstevel@tonic-gate  *	occurs only when necessary.
3157c478bd9Sstevel@tonic-gate  */
316f53eecf5SJames Carlson static void
3177c478bd9Sstevel@tonic-gate spppcomp_wput(queue_t *q, mblk_t *mp)
3187c478bd9Sstevel@tonic-gate {
319f53eecf5SJames Carlson 	sppp_comp_t *cp = q->q_ptr;
3207c478bd9Sstevel@tonic-gate 	int flag;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
3237c478bd9Sstevel@tonic-gate 	case M_DATA:
3247c478bd9Sstevel@tonic-gate 		if (q->q_first != NULL || !bcanputnext(q, mp->b_band) ||
3257c478bd9Sstevel@tonic-gate 		    ((cp->cp_flags & (COMP_VJC|CCP_COMP_RUN)) &&
326002c70ffScarlsonj 		    servicing_interrupt())) {
3277c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
3287c478bd9Sstevel@tonic-gate 			cp->cp_out_queued++;
3297c478bd9Sstevel@tonic-gate #endif
330f53eecf5SJames Carlson 			if (!putq(q, mp))
331f53eecf5SJames Carlson 				freemsg(mp);
3327c478bd9Sstevel@tonic-gate 		} else {
3337c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
3347c478bd9Sstevel@tonic-gate 			cp->cp_out_handled++;
3357c478bd9Sstevel@tonic-gate #endif
336f53eecf5SJames Carlson 			if ((mp = spppcomp_outpkt(q, mp)) != NULL)
3377c478bd9Sstevel@tonic-gate 				putnext(q, mp);
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 		break;
3407c478bd9Sstevel@tonic-gate 	case M_IOCTL:
3417c478bd9Sstevel@tonic-gate 		spppcomp_ioctl(q, mp, cp);
3427c478bd9Sstevel@tonic-gate 		break;
3437c478bd9Sstevel@tonic-gate 	case M_CTL:
3447c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
3457c478bd9Sstevel@tonic-gate 		flag = spppcomp_mctl(q, mp);
3467c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
3477c478bd9Sstevel@tonic-gate 		if (flag != 0)
3487c478bd9Sstevel@tonic-gate 			putnext(q, mp);
3497c478bd9Sstevel@tonic-gate 		else
3507c478bd9Sstevel@tonic-gate 			freemsg(mp);
3517c478bd9Sstevel@tonic-gate 		break;
3527c478bd9Sstevel@tonic-gate 	case M_FLUSH:
3537c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "wput M_FLUSH (0x%x) flags=0x%b\n",
3547c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
3557c478bd9Sstevel@tonic-gate 		    *mp->b_rptr, cp->cp_flags,	CP_FLAGSSTR));
3567c478bd9Sstevel@tonic-gate 		/*
3577c478bd9Sstevel@tonic-gate 		 * Just discard pending data.  For CCP, any compressor
3587c478bd9Sstevel@tonic-gate 		 * dictionary sequencing problems caused by this will
3597c478bd9Sstevel@tonic-gate 		 * have to be handled by the compression protocol in
3607c478bd9Sstevel@tonic-gate 		 * use.  For VJ, we need to tell the compressor to
3617c478bd9Sstevel@tonic-gate 		 * start over.
3627c478bd9Sstevel@tonic-gate 		 */
3637c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW) {
3647c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
3657c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
3667c478bd9Sstevel@tonic-gate 			vj_compress_init(&cp->cp_vj, cp->cp_nxslots);
3677c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
3687c478bd9Sstevel@tonic-gate 		}
3697c478bd9Sstevel@tonic-gate 		putnext(q, mp);
3707c478bd9Sstevel@tonic-gate 		break;
3717c478bd9Sstevel@tonic-gate 	default:
372f53eecf5SJames Carlson 		if (bcanputnext(q, mp->b_band))
373f53eecf5SJames Carlson 			putnext(q, mp);
374f53eecf5SJames Carlson 		else if (!putq(q, mp))
375f53eecf5SJames Carlson 			freemsg(mp);
3767c478bd9Sstevel@tonic-gate 		break;
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate /*
3817c478bd9Sstevel@tonic-gate  * spppcomp_wsrv()
3827c478bd9Sstevel@tonic-gate  *
3837c478bd9Sstevel@tonic-gate  * MT-Perimeters:
3847c478bd9Sstevel@tonic-gate  *    exclusive inner
3857c478bd9Sstevel@tonic-gate  *
3867c478bd9Sstevel@tonic-gate  * Description:
3877c478bd9Sstevel@tonic-gate  *    Write-side service procedure.
3887c478bd9Sstevel@tonic-gate  */
389f53eecf5SJames Carlson static void
3907c478bd9Sstevel@tonic-gate spppcomp_wsrv(queue_t *q)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
3957c478bd9Sstevel@tonic-gate 		/*
3967c478bd9Sstevel@tonic-gate 		 * If the module below us is flow-controlled, then put
3977c478bd9Sstevel@tonic-gate 		 * this message back on the queue again.
3987c478bd9Sstevel@tonic-gate 		 */
3997c478bd9Sstevel@tonic-gate 		if (!bcanputnext(q, mp->b_band)) {
4007c478bd9Sstevel@tonic-gate 			(void) putbq(q, mp);
4017c478bd9Sstevel@tonic-gate 			break;
4027c478bd9Sstevel@tonic-gate 		}
403f53eecf5SJames Carlson 		if (MTYPE(mp) != M_DATA ||
404f53eecf5SJames Carlson 		    (mp = spppcomp_outpkt(q, mp)) != NULL)
4057c478bd9Sstevel@tonic-gate 			putnext(q, mp);
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate  * spppcomp_outpkt()
4117c478bd9Sstevel@tonic-gate  *
4127c478bd9Sstevel@tonic-gate  * MT-Perimeters:
4137c478bd9Sstevel@tonic-gate  *    exclusive inner
4147c478bd9Sstevel@tonic-gate  *
4157c478bd9Sstevel@tonic-gate  * Description:
4167c478bd9Sstevel@tonic-gate  *    Process outgoing packet.  Returns new mblk_t pointer on success
4177c478bd9Sstevel@tonic-gate  *    (caller should do putnext through q), NULL on failure (packet has
4187c478bd9Sstevel@tonic-gate  *    been discarded).
4197c478bd9Sstevel@tonic-gate  */
4207c478bd9Sstevel@tonic-gate static mblk_t *
4217c478bd9Sstevel@tonic-gate spppcomp_outpkt(queue_t *q, mblk_t *mp)
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate 	mblk_t		*zmp;
4247c478bd9Sstevel@tonic-gate 	int		len;
4257c478bd9Sstevel@tonic-gate 	ushort_t	proto;
426f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	/*
4297c478bd9Sstevel@tonic-gate 	 * If the entire data size of the mblk is less than the length of the
4307c478bd9Sstevel@tonic-gate 	 * PPP header, then free it. We can't do much with such message anyway,
4317c478bd9Sstevel@tonic-gate 	 * since we can't determine what the PPP protocol is.
4327c478bd9Sstevel@tonic-gate 	 */
4337c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
4347c478bd9Sstevel@tonic-gate 	if (MBLKL(mp) < PPP_HDRLEN) {
4357c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
4367c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
4377c478bd9Sstevel@tonic-gate 		cp->cp_omsg_pull++;
4387c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
4397c478bd9Sstevel@tonic-gate #endif
4407c478bd9Sstevel@tonic-gate 		zmp = msgpullup(mp, PPP_HDRLEN);
4417c478bd9Sstevel@tonic-gate 		freemsg(mp);
4427c478bd9Sstevel@tonic-gate 		if ((mp = zmp) == NULL)
4437c478bd9Sstevel@tonic-gate 			goto msg_oerror;
4447c478bd9Sstevel@tonic-gate 	}
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	/*
4497c478bd9Sstevel@tonic-gate 	 * Do VJ compression if requested.
4507c478bd9Sstevel@tonic-gate 	 */
4517c478bd9Sstevel@tonic-gate 	if (proto == PPP_IP && IS_COMP_VJC(cp) &&
4527c478bd9Sstevel@tonic-gate 	    MSG_BYTE(mp, PPP_HDRLEN+offsetof(struct ip, ip_p)) ==
4537c478bd9Sstevel@tonic-gate 	    IPPROTO_TCP) {
4547c478bd9Sstevel@tonic-gate 		uchar_t		*vjhdr;
4557c478bd9Sstevel@tonic-gate 		int		type;
4567c478bd9Sstevel@tonic-gate 		uint32_t	indata[(PPP_HDRLEN+MAX_TCPIPHLEN) /
4577c478bd9Sstevel@tonic-gate 		    sizeof (uint32_t)];
4587c478bd9Sstevel@tonic-gate 		uchar_t		*dp;
4597c478bd9Sstevel@tonic-gate 		int		tocopy, copied;
4607c478bd9Sstevel@tonic-gate 		mblk_t		*fmb;
4617c478bd9Sstevel@tonic-gate 		void		*srcp;
4627c478bd9Sstevel@tonic-gate 		int		thislen;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 		tocopy = copied = MIN(len, sizeof (indata));
4667c478bd9Sstevel@tonic-gate 		/*
4677c478bd9Sstevel@tonic-gate 		 * If we can alter this dblk, and there's enough data
4687c478bd9Sstevel@tonic-gate 		 * here to work with, and it's nicely aligned, then
4697c478bd9Sstevel@tonic-gate 		 * avoid the data copy.
4707c478bd9Sstevel@tonic-gate 		 */
4717c478bd9Sstevel@tonic-gate 		if (DB_REF(mp) == 1 && MBLKL(mp) >= tocopy &&
4727c478bd9Sstevel@tonic-gate 		    ((uintptr_t)mp->b_rptr & 3) == 0) {
4737c478bd9Sstevel@tonic-gate 			/* Save off the address/control */
4747c478bd9Sstevel@tonic-gate 			indata[0] = *(uint32_t *)mp->b_rptr;
4757c478bd9Sstevel@tonic-gate 			srcp = (void *)(mp->b_rptr + PPP_HDRLEN);
4767c478bd9Sstevel@tonic-gate 		} else {
4777c478bd9Sstevel@tonic-gate 			fmb = mp;
4787c478bd9Sstevel@tonic-gate 			dp = (uchar_t *)indata;
4797c478bd9Sstevel@tonic-gate 			while (tocopy > 0) {
4807c478bd9Sstevel@tonic-gate 				thislen = MBLKL(fmb);
4817c478bd9Sstevel@tonic-gate 				if (tocopy > thislen) {
4827c478bd9Sstevel@tonic-gate 					bcopy(fmb->b_rptr, dp, thislen);
4837c478bd9Sstevel@tonic-gate 					dp += thislen;
4847c478bd9Sstevel@tonic-gate 					tocopy -= thislen;
4857c478bd9Sstevel@tonic-gate 					fmb = fmb->b_cont;
4867c478bd9Sstevel@tonic-gate 				} else {
4877c478bd9Sstevel@tonic-gate 					bcopy(fmb->b_rptr, dp, tocopy);
4887c478bd9Sstevel@tonic-gate 					break;
4897c478bd9Sstevel@tonic-gate 				}
4907c478bd9Sstevel@tonic-gate 			}
4917c478bd9Sstevel@tonic-gate 			srcp = (void *)(indata + PPP_HDRLEN/sizeof (*indata));
4927c478bd9Sstevel@tonic-gate 		}
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 		type = vj_compress_tcp((struct ip *)srcp, len - PPP_HDRLEN,
4957c478bd9Sstevel@tonic-gate 		    &cp->cp_vj, IS_COMP_VJCCID(cp), &vjhdr);
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 		/*
4987c478bd9Sstevel@tonic-gate 		 * If we're going to modify this packet, then we can't modify
4997c478bd9Sstevel@tonic-gate 		 * someone else's data.  Copy instead.
5007c478bd9Sstevel@tonic-gate 		 *
5017c478bd9Sstevel@tonic-gate 		 * (It would be nice to be able to avoid this data copy if CCP
5027c478bd9Sstevel@tonic-gate 		 * is also enabled.  That would require extensive
5037c478bd9Sstevel@tonic-gate 		 * modifications to the compression code.  Users should be
5047c478bd9Sstevel@tonic-gate 		 * told to disable VJ compression when using CCP.)
5057c478bd9Sstevel@tonic-gate 		 */
5067c478bd9Sstevel@tonic-gate 		if (type != TYPE_IP && DB_REF(mp) > 1) {
5077c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
5087c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
5097c478bd9Sstevel@tonic-gate 			cp->cp_omsg_dcopy++;
5107c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
5117c478bd9Sstevel@tonic-gate #endif
5127c478bd9Sstevel@tonic-gate 			/* Copy just altered portion. */
5137c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, copied);
5147c478bd9Sstevel@tonic-gate 			freemsg(mp);
5157c478bd9Sstevel@tonic-gate 			if ((mp = zmp) == NULL)
5167c478bd9Sstevel@tonic-gate 				goto msg_oerror;
5177c478bd9Sstevel@tonic-gate 		}
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 		switch (type) {
5207c478bd9Sstevel@tonic-gate 		case TYPE_UNCOMPRESSED_TCP:
5217c478bd9Sstevel@tonic-gate 			mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
5227c478bd9Sstevel@tonic-gate 			/* No need to update if it was done in place. */
5237c478bd9Sstevel@tonic-gate 			if (srcp ==
5247c478bd9Sstevel@tonic-gate 			    (void *)(indata + PPP_HDRLEN / sizeof (*indata))) {
5257c478bd9Sstevel@tonic-gate 				thislen = PPP_HDRLEN +
5267c478bd9Sstevel@tonic-gate 				    offsetof(struct ip, ip_p);
5277c478bd9Sstevel@tonic-gate 				zmp = mp;
5287c478bd9Sstevel@tonic-gate 				while (zmp != NULL) {
5297c478bd9Sstevel@tonic-gate 					if (MBLKL(zmp) > thislen) {
5307c478bd9Sstevel@tonic-gate 						zmp->b_rptr[thislen] =
5317c478bd9Sstevel@tonic-gate 						    ((struct ip *)srcp)->ip_p;
5327c478bd9Sstevel@tonic-gate 						break;
5337c478bd9Sstevel@tonic-gate 					}
5347c478bd9Sstevel@tonic-gate 					thislen -= MBLKL(zmp);
5357c478bd9Sstevel@tonic-gate 					zmp = zmp->b_cont;
5367c478bd9Sstevel@tonic-gate 				}
5377c478bd9Sstevel@tonic-gate 			}
5387c478bd9Sstevel@tonic-gate 			break;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 		case TYPE_COMPRESSED_TCP:
5417c478bd9Sstevel@tonic-gate 			/* Calculate amount to remove from front */
5427c478bd9Sstevel@tonic-gate 			thislen = vjhdr - (uchar_t *)srcp;
5437c478bd9Sstevel@tonic-gate 			ASSERT(thislen >= 0);
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 			/* Try to do a cheap adjmsg by arithmetic first. */
5467c478bd9Sstevel@tonic-gate 			dp = mp->b_rptr + thislen;
5477c478bd9Sstevel@tonic-gate 			if (dp > mp->b_wptr) {
5487c478bd9Sstevel@tonic-gate 				if (!adjmsg(mp, thislen)) {
5497c478bd9Sstevel@tonic-gate 					freemsg(mp);
5507c478bd9Sstevel@tonic-gate 					goto msg_oerror;
5517c478bd9Sstevel@tonic-gate 				}
5527c478bd9Sstevel@tonic-gate 				dp = mp->b_rptr;
5537c478bd9Sstevel@tonic-gate 			}
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 			/*
5567c478bd9Sstevel@tonic-gate 			 * Now make sure first block is big enough to
5577c478bd9Sstevel@tonic-gate 			 * receive modified data.  If we modified in
5587c478bd9Sstevel@tonic-gate 			 * place, then no need to check or copy.
5597c478bd9Sstevel@tonic-gate 			 */
5607c478bd9Sstevel@tonic-gate 			copied -= thislen;
5617c478bd9Sstevel@tonic-gate 			ASSERT(copied >= PPP_HDRLEN);
5627c478bd9Sstevel@tonic-gate 			if (srcp !=
5637c478bd9Sstevel@tonic-gate 			    (void *)(indata + PPP_HDRLEN / sizeof (*indata)))
5647c478bd9Sstevel@tonic-gate 				copied = 0;
5657c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp;
5667c478bd9Sstevel@tonic-gate 			if (MBLKL(mp) < copied) {
5677c478bd9Sstevel@tonic-gate 				zmp = msgpullup(mp, copied);
5687c478bd9Sstevel@tonic-gate 				freemsg(mp);
5697c478bd9Sstevel@tonic-gate 				if ((mp = zmp) == NULL)
5707c478bd9Sstevel@tonic-gate 					goto msg_oerror;
5717c478bd9Sstevel@tonic-gate 				dp = mp->b_rptr;
5727c478bd9Sstevel@tonic-gate 			}
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 			*dp++ = ((uchar_t *)indata)[0];	/* address */
5757c478bd9Sstevel@tonic-gate 			*dp++ = ((uchar_t *)indata)[1];	/* control  */
5767c478bd9Sstevel@tonic-gate 			*dp++ = 0;			/* protocol */
5777c478bd9Sstevel@tonic-gate 			*dp++ = proto = PPP_VJC_COMP;	/* protocol */
5787c478bd9Sstevel@tonic-gate 			copied -= PPP_HDRLEN;
5797c478bd9Sstevel@tonic-gate 			if (copied > 0) {
5807c478bd9Sstevel@tonic-gate 				bcopy(vjhdr, dp, copied);
5817c478bd9Sstevel@tonic-gate 			}
5827c478bd9Sstevel@tonic-gate 			break;
5837c478bd9Sstevel@tonic-gate 		}
5847c478bd9Sstevel@tonic-gate 	}
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	/*
5877c478bd9Sstevel@tonic-gate 	 * Do packet compression if enabled.
5887c478bd9Sstevel@tonic-gate 	 */
5897c478bd9Sstevel@tonic-gate 	if (proto == PPP_CCP) {
5907c478bd9Sstevel@tonic-gate 		/*
5917c478bd9Sstevel@tonic-gate 		 * Handle any negotiation packets by changing compressor
5927c478bd9Sstevel@tonic-gate 		 * state.  Doing this here rather than with an ioctl keeps
5937c478bd9Sstevel@tonic-gate 		 * the negotiation and the data flow in sync.
5947c478bd9Sstevel@tonic-gate 		 */
5957c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
5967c478bd9Sstevel@tonic-gate 		comp_ccp(q, mp, cp, B_FALSE);
5977c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
5987c478bd9Sstevel@tonic-gate 	} else if (proto != PPP_LCP && IS_CCP_COMP_RUN(cp) &&
599002c70ffScarlsonj 	    IS_CCP_ISUP(cp) && cp->cp_xstate != NULL) {
6007c478bd9Sstevel@tonic-gate 		mblk_t	*cmp = NULL;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 		len = msgsize(mp);
6037c478bd9Sstevel@tonic-gate 		len = (*cp->cp_xcomp->compress)(cp->cp_xstate, &cmp, mp, len,
604002c70ffScarlsonj 		    cp->cp_mtu + PPP_HDRLEN);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 		if (cmp != NULL) {
6077c478bd9Sstevel@tonic-gate 			/* Success!  Discard uncompressed version */
6087c478bd9Sstevel@tonic-gate 			cmp->b_band = mp->b_band;
6097c478bd9Sstevel@tonic-gate 			freemsg(mp);
6107c478bd9Sstevel@tonic-gate 			mp = cmp;
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 		if (len < 0) {
6137c478bd9Sstevel@tonic-gate 			/*
6147c478bd9Sstevel@tonic-gate 			 * Compressor failure; must discard this
6157c478bd9Sstevel@tonic-gate 			 * packet because the compressor dictionary is
6167c478bd9Sstevel@tonic-gate 			 * now corrupt.
6177c478bd9Sstevel@tonic-gate 			 */
6187c478bd9Sstevel@tonic-gate 			freemsg(mp);
6197c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
6207c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_oerrors++;
6217c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
6227c478bd9Sstevel@tonic-gate 			(void) putnextctl1(RD(q), M_CTL, PPPCTL_OERROR);
6237c478bd9Sstevel@tonic-gate 			return (NULL);
6247c478bd9Sstevel@tonic-gate 		}
6257c478bd9Sstevel@tonic-gate 	}
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	/*
6287c478bd9Sstevel@tonic-gate 	 * If either address and control field compression or protocol field
6297c478bd9Sstevel@tonic-gate 	 * compression is enabled, then we'll need a writable packet.  Copy if
6307c478bd9Sstevel@tonic-gate 	 * necessary.
6317c478bd9Sstevel@tonic-gate 	 */
6327c478bd9Sstevel@tonic-gate 	if ((cp->cp_flags & (COMP_AC|COMP_PROT)) && DB_REF(mp) > 1) {
6337c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
6347c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
6357c478bd9Sstevel@tonic-gate 		cp->cp_omsg_dcopy++;
6367c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
6377c478bd9Sstevel@tonic-gate #endif
6387c478bd9Sstevel@tonic-gate 		zmp = copymsg(mp);
6397c478bd9Sstevel@tonic-gate 		freemsg(mp);
6407c478bd9Sstevel@tonic-gate 		if ((mp = zmp) == NULL)
6417c478bd9Sstevel@tonic-gate 			goto msg_oerror;
6427c478bd9Sstevel@tonic-gate 	}
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	/*
6457c478bd9Sstevel@tonic-gate 	 * Do address/control and protocol compression if enabled.
6467c478bd9Sstevel@tonic-gate 	 */
6477c478bd9Sstevel@tonic-gate 	if (IS_COMP_AC(cp) && (proto != PPP_LCP)) {
6487c478bd9Sstevel@tonic-gate 		mp->b_rptr += 2;	/* drop address & ctrl fields */
6497c478bd9Sstevel@tonic-gate 		/*
6507c478bd9Sstevel@tonic-gate 		 * Protocol field compression omits the first byte if
6517c478bd9Sstevel@tonic-gate 		 * it would be 0x00, thus the check for < 0x100.
6527c478bd9Sstevel@tonic-gate 		 */
6537c478bd9Sstevel@tonic-gate 		if (proto < 0x100 && IS_COMP_PROT(cp)) {
6547c478bd9Sstevel@tonic-gate 			++mp->b_rptr;	/* drop high protocol byte */
6557c478bd9Sstevel@tonic-gate 		}
6567c478bd9Sstevel@tonic-gate 	} else if ((proto < 0x100) && IS_COMP_PROT(cp)) {
6577c478bd9Sstevel@tonic-gate 		/*
6587c478bd9Sstevel@tonic-gate 		 * shuffle up the address & ctrl fields
6597c478bd9Sstevel@tonic-gate 		 */
6607c478bd9Sstevel@tonic-gate 		mp->b_rptr[2] = mp->b_rptr[1];
6617c478bd9Sstevel@tonic-gate 		mp->b_rptr[1] = mp->b_rptr[0];
6627c478bd9Sstevel@tonic-gate 		++mp->b_rptr;
6637c478bd9Sstevel@tonic-gate 	}
6647c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
6657c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_opackets++;
6667c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_obytes += msgsize(mp);
6677c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "send (%ld bytes) flags=0x%b\n",
6707c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), msgsize(mp),
6717c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
6727c478bd9Sstevel@tonic-gate 	return (mp);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate msg_oerror:
6757c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
6767c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_oerrors++;
6777c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
6787c478bd9Sstevel@tonic-gate 	(void) putnextctl1(RD(q), M_CTL, PPPCTL_OERROR);
6797c478bd9Sstevel@tonic-gate 	return (NULL);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate /*
6837c478bd9Sstevel@tonic-gate  * spppcomp_inner_ioctl()
6847c478bd9Sstevel@tonic-gate  *
6857c478bd9Sstevel@tonic-gate  * MT-Perimeters:
6867c478bd9Sstevel@tonic-gate  *    exclusive inner; queue pair lock held.
6877c478bd9Sstevel@tonic-gate  *
6887c478bd9Sstevel@tonic-gate  * Description:
6897c478bd9Sstevel@tonic-gate  *	Called by spppcomp_ioctl to handle state-affecting ioctls.
6907c478bd9Sstevel@tonic-gate  *	Returns -1 if caller should do putnext, 0 for miocack, or >0
6917c478bd9Sstevel@tonic-gate  *	for miocnak.  Must *NOT* do putnext in this routine, since
6927c478bd9Sstevel@tonic-gate  *	lock is held here.
6937c478bd9Sstevel@tonic-gate  */
6947c478bd9Sstevel@tonic-gate static int
6957c478bd9Sstevel@tonic-gate spppcomp_inner_ioctl(queue_t *q, mblk_t *mp)
6967c478bd9Sstevel@tonic-gate {
697f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
6987c478bd9Sstevel@tonic-gate 	int		flags;
6997c478bd9Sstevel@tonic-gate 	int		mask;
7007c478bd9Sstevel@tonic-gate 	int		rc;
7017c478bd9Sstevel@tonic-gate 	int		len;
7027c478bd9Sstevel@tonic-gate 	int		cmd;
7037c478bd9Sstevel@tonic-gate 	int		nxslots;
7047c478bd9Sstevel@tonic-gate 	int		nrslots;
7057c478bd9Sstevel@tonic-gate 	int		val;
7067c478bd9Sstevel@tonic-gate 	uchar_t		*opt_data;
7077c478bd9Sstevel@tonic-gate 	uint32_t	opt_len;
7087c478bd9Sstevel@tonic-gate 	struct compressor **comp;
7097c478bd9Sstevel@tonic-gate 	struct compressor *ccomp;
7107c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
7117c478bd9Sstevel@tonic-gate 	void		*xtemp;
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
7147c478bd9Sstevel@tonic-gate 	rc = EINVAL;
7157c478bd9Sstevel@tonic-gate 	len = 0;
7167c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
7177c478bd9Sstevel@tonic-gate 	case PPPIO_CFLAGS:
7187c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != 2 * sizeof (uint32_t) ||
7197c478bd9Sstevel@tonic-gate 		    mp->b_cont == NULL)
7207c478bd9Sstevel@tonic-gate 			break;
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 		flags = ((uint32_t *)mp->b_cont->b_rptr)[0];
7237c478bd9Sstevel@tonic-gate 		mask = ((uint32_t *)mp->b_cont->b_rptr)[1];
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 		cp->cp_flags = (cp->cp_flags & ~mask) | (flags & mask);
7267c478bd9Sstevel@tonic-gate 
727002c70ffScarlsonj 		if ((mask & CCP_ISOPEN) && !(flags & CCP_ISOPEN)) {
728002c70ffScarlsonj 			cp->cp_flags &= ~CCP_ISUP & ~CCP_COMP_RUN &
729002c70ffScarlsonj 			    ~CCP_DECOMP_RUN;
7307c478bd9Sstevel@tonic-gate 			if (cp->cp_xstate != NULL) {
7317c478bd9Sstevel@tonic-gate 				(*cp->cp_xcomp->comp_free)(cp->cp_xstate);
7327c478bd9Sstevel@tonic-gate 				cp->cp_xstate = NULL;
7337c478bd9Sstevel@tonic-gate 			}
7347c478bd9Sstevel@tonic-gate 			if (cp->cp_rstate != NULL) {
7357c478bd9Sstevel@tonic-gate 				(*cp->cp_rcomp->decomp_free)(cp->cp_rstate);
7367c478bd9Sstevel@tonic-gate 				cp->cp_rstate = NULL;
7377c478bd9Sstevel@tonic-gate 			}
7387c478bd9Sstevel@tonic-gate 		}
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART
7417c478bd9Sstevel@tonic-gate 		    "PPPIO_CFLAGS xflags=0x%b xmask=0x%b flags=0x%b\n",
7427c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
7437c478bd9Sstevel@tonic-gate 		    flags, CP_FLAGSSTR, mask,
7447c478bd9Sstevel@tonic-gate 		    CP_FLAGSSTR, cp->cp_flags, CP_FLAGSSTR));
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 		/* If we're not the last PPP-speaker, then pass along. */
7477c478bd9Sstevel@tonic-gate 		if (!IS_CP_LASTMOD(cp)) {
7487c478bd9Sstevel@tonic-gate 			return (-1);	/* putnext */
7497c478bd9Sstevel@tonic-gate 		}
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 		*(uint32_t *)mp->b_cont->b_rptr = cp->cp_flags;
7527c478bd9Sstevel@tonic-gate 		len = sizeof (uint32_t);
7537c478bd9Sstevel@tonic-gate 		rc = 0;
7547c478bd9Sstevel@tonic-gate 		break;
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	case PPPIO_VJINIT:
7577c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != 2 || mp->b_cont == NULL)
7587c478bd9Sstevel@tonic-gate 			break;
7597c478bd9Sstevel@tonic-gate 		/*
7607c478bd9Sstevel@tonic-gate 		 * Even though it's not passed along, we have to
7617c478bd9Sstevel@tonic-gate 		 * validate nrslots so that we don't agree to
7627c478bd9Sstevel@tonic-gate 		 * decompress anything we cannot.
7637c478bd9Sstevel@tonic-gate 		 */
7647c478bd9Sstevel@tonic-gate 		nxslots = mp->b_cont->b_rptr[0] + 1;
7657c478bd9Sstevel@tonic-gate 		nrslots = mp->b_cont->b_rptr[1] + 1;
7667c478bd9Sstevel@tonic-gate 		if (nxslots > MAX_STATES || nrslots > MAX_STATES)
7677c478bd9Sstevel@tonic-gate 			break;
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 		/* No need to lock here; just reading a word is atomic */
7707c478bd9Sstevel@tonic-gate 		/* mutex_enter(&cp->cp_pair_lock); */
7717c478bd9Sstevel@tonic-gate 		cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
7727c478bd9Sstevel@tonic-gate 		/* mutex_exit(&cp->cp_pair_lock); */
7737c478bd9Sstevel@tonic-gate 		vj_compress_init(&cp->cp_vj, nxslots);
7747c478bd9Sstevel@tonic-gate 		cp->cp_nxslots = nxslots;
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART
7777c478bd9Sstevel@tonic-gate 		    "PPPIO_VJINIT txslots=%d rxslots=%d flags=0x%b\n",
7787c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), nxslots,
7797c478bd9Sstevel@tonic-gate 		    nrslots, cp->cp_flags, CP_FLAGSSTR));
7807c478bd9Sstevel@tonic-gate 		rc = 0;
7817c478bd9Sstevel@tonic-gate 		break;
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 	case PPPIO_XCOMP:
7847c478bd9Sstevel@tonic-gate 	case PPPIO_RCOMP:
7857c478bd9Sstevel@tonic-gate 		if (iop->ioc_count < 2 || mp->b_cont == NULL)
7867c478bd9Sstevel@tonic-gate 			break;
7877c478bd9Sstevel@tonic-gate 		/*
7887c478bd9Sstevel@tonic-gate 		 * The input data here is the raw CCP algorithm option
7897c478bd9Sstevel@tonic-gate 		 * from negotiation.  The format is always one byte of
7907c478bd9Sstevel@tonic-gate 		 * algorithm number, one byte of length, and
7917c478bd9Sstevel@tonic-gate 		 * (length-2) bytes of algorithm-dependent data.  The
7927c478bd9Sstevel@tonic-gate 		 * alloc routine is expected to parse and validate
7937c478bd9Sstevel@tonic-gate 		 * this.
7947c478bd9Sstevel@tonic-gate 		 */
7957c478bd9Sstevel@tonic-gate 		opt_data = mp->b_cont->b_rptr;
7967c478bd9Sstevel@tonic-gate 		opt_len = mp->b_cont->b_wptr - opt_data;
7977c478bd9Sstevel@tonic-gate 		if (opt_len > iop->ioc_count) {
7987c478bd9Sstevel@tonic-gate 			opt_len = iop->ioc_count;
7997c478bd9Sstevel@tonic-gate 		}
8007c478bd9Sstevel@tonic-gate 		len = mp->b_cont->b_rptr[1];
8017c478bd9Sstevel@tonic-gate 		if (len < 2 || len > opt_len)
8027c478bd9Sstevel@tonic-gate 			break;
8037c478bd9Sstevel@tonic-gate 		len = 0;
8047c478bd9Sstevel@tonic-gate 		for (comp = ppp_compressors; *comp != NULL; ++comp) {
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 			if ((*comp)->compress_proto != opt_data[0]) {
8077c478bd9Sstevel@tonic-gate 				continue;
8087c478bd9Sstevel@tonic-gate 			}
8097c478bd9Sstevel@tonic-gate 			rc = 0;
8107c478bd9Sstevel@tonic-gate 			if (iop->ioc_cmd == PPPIO_XCOMP) {
8117c478bd9Sstevel@tonic-gate 				/*
8127c478bd9Sstevel@tonic-gate 				 * A previous call may have fetched
8137c478bd9Sstevel@tonic-gate 				 * memory for a compressor that's now
8147c478bd9Sstevel@tonic-gate 				 * being retired or reset.  Free it
8157c478bd9Sstevel@tonic-gate 				 * using its mechanism for freeing
8167c478bd9Sstevel@tonic-gate 				 * stuff.
8177c478bd9Sstevel@tonic-gate 				 */
8187c478bd9Sstevel@tonic-gate 				if ((xtemp = cp->cp_xstate) != NULL) {
819002c70ffScarlsonj 					cp->cp_flags &= ~CCP_ISUP &
820002c70ffScarlsonj 					    ~CCP_COMP_RUN;
8217c478bd9Sstevel@tonic-gate 					cp->cp_xstate = NULL;
8227c478bd9Sstevel@tonic-gate 					(*cp->cp_xcomp->comp_free)(xtemp);
8237c478bd9Sstevel@tonic-gate 				}
8247c478bd9Sstevel@tonic-gate 				cp->cp_xcomp = *comp;
8257c478bd9Sstevel@tonic-gate 				cp->cp_xstate = (*comp)->comp_alloc(opt_data,
8267c478bd9Sstevel@tonic-gate 				    opt_len);
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate == NULL) {
8297c478bd9Sstevel@tonic-gate 					rc = ENOSR;
8307c478bd9Sstevel@tonic-gate 				}
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 				CPDEBUG((DBGSTART "PPPIO_XCOMP opt_proto=0x%x "
8337c478bd9Sstevel@tonic-gate 				    "opt_len=0x%d flags=0x%b\n",
8347c478bd9Sstevel@tonic-gate 				    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8357c478bd9Sstevel@tonic-gate 				    (uchar_t)opt_data[0], opt_len,
8367c478bd9Sstevel@tonic-gate 				    cp->cp_flags,
8377c478bd9Sstevel@tonic-gate 				    CP_FLAGSSTR));
8387c478bd9Sstevel@tonic-gate 			} else {
8397c478bd9Sstevel@tonic-gate 				if ((xtemp = cp->cp_rstate) != NULL) {
840002c70ffScarlsonj 					cp->cp_flags &= ~CCP_ISUP &
841002c70ffScarlsonj 					    ~CCP_DECOMP_RUN;
8427c478bd9Sstevel@tonic-gate 					cp->cp_rstate = NULL;
8437c478bd9Sstevel@tonic-gate 					(*cp->cp_rcomp->decomp_free)(xtemp);
8447c478bd9Sstevel@tonic-gate 				}
8457c478bd9Sstevel@tonic-gate 				cp->cp_rcomp = *comp;
8467c478bd9Sstevel@tonic-gate 				cp->cp_rstate =
8477c478bd9Sstevel@tonic-gate 				    (*comp)->decomp_alloc(opt_data, opt_len);
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate == NULL) {
8507c478bd9Sstevel@tonic-gate 					rc = ENOSR;
8517c478bd9Sstevel@tonic-gate 				}
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 				CPDEBUG((DBGSTART "PPPIO_RCOMP opt_proto=0x%x "
8547c478bd9Sstevel@tonic-gate 				    "opt_len=0x%d flags=0x%b\n",
8557c478bd9Sstevel@tonic-gate 				    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8567c478bd9Sstevel@tonic-gate 				    (uchar_t)opt_data[0], opt_len,
8577c478bd9Sstevel@tonic-gate 				    cp->cp_flags,
8587c478bd9Sstevel@tonic-gate 				    CP_FLAGSSTR));
8597c478bd9Sstevel@tonic-gate 			}
8607c478bd9Sstevel@tonic-gate 			if (rc == 0 && (*comp)->set_effort != NULL) {
8617c478bd9Sstevel@tonic-gate 				rc = (*(*comp)->set_effort)(cp->
8627c478bd9Sstevel@tonic-gate 				    cp_xcomp == *comp ? cp->cp_xstate : NULL,
8637c478bd9Sstevel@tonic-gate 				    cp->cp_rcomp == *comp ? cp->cp_rstate :
8647c478bd9Sstevel@tonic-gate 				    NULL, cp->cp_effort);
8657c478bd9Sstevel@tonic-gate 				if (rc != 0) {
8667c478bd9Sstevel@tonic-gate 					CKDEBUG((DBGSTART
8677c478bd9Sstevel@tonic-gate 					    "cannot set effort %d",
8687c478bd9Sstevel@tonic-gate 					    cp->cp_unit, cp->cp_effort));
8697c478bd9Sstevel@tonic-gate 					rc = 0;
8707c478bd9Sstevel@tonic-gate 				}
8717c478bd9Sstevel@tonic-gate 			}
8727c478bd9Sstevel@tonic-gate 			break;
8737c478bd9Sstevel@tonic-gate 		}
8747c478bd9Sstevel@tonic-gate 		break;
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	case PPPIO_DEBUG:
8777c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != sizeof (uint32_t) || mp->b_cont == NULL)
8787c478bd9Sstevel@tonic-gate 			break;
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 		cmd = *(uint32_t *)mp->b_cont->b_rptr;
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate 		/* If it's not for us, then pass along. */
8837c478bd9Sstevel@tonic-gate 		if (cmd != PPPDBG_LOG + PPPDBG_COMP) {
8847c478bd9Sstevel@tonic-gate 			return (-1);	/* putnext */
8857c478bd9Sstevel@tonic-gate 		}
8867c478bd9Sstevel@tonic-gate 		cp->cp_flags |= CP_KDEBUG;
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 		CKDEBUG((DBGSTART "PPPIO_DEBUG log enabled flags=0x%b\n",
8897c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8907c478bd9Sstevel@tonic-gate 		    cp->cp_flags, CP_FLAGSSTR));
8917c478bd9Sstevel@tonic-gate 		rc = 0;
8927c478bd9Sstevel@tonic-gate 		break;
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 	case PPPIO_LASTMOD:
8957c478bd9Sstevel@tonic-gate 		cp->cp_flags |= CP_LASTMOD;
8967c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPIO_LASTMOD last module flags=0x%b\n",
8977c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
8987c478bd9Sstevel@tonic-gate 		    cp->cp_flags, CP_FLAGSSTR));
8997c478bd9Sstevel@tonic-gate 		rc = 0;
9007c478bd9Sstevel@tonic-gate 		break;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	case PPPIO_COMPLEV:	/* set compression effort level */
9037c478bd9Sstevel@tonic-gate 		if (iop->ioc_count != sizeof (uint32_t) || mp->b_cont == NULL)
9047c478bd9Sstevel@tonic-gate 			break;
9057c478bd9Sstevel@tonic-gate 		val = *(uint32_t *)mp->b_cont->b_rptr;
9067c478bd9Sstevel@tonic-gate 		cp->cp_effort = val;
9077c478bd9Sstevel@tonic-gate 		/* Silently ignore if compressor doesn't understand this. */
9087c478bd9Sstevel@tonic-gate 		rc = 0;
9097c478bd9Sstevel@tonic-gate 		if ((ccomp = cp->cp_xcomp) != NULL &&
9107c478bd9Sstevel@tonic-gate 		    ccomp->set_effort != NULL) {
9117c478bd9Sstevel@tonic-gate 			rc = (*ccomp->set_effort)(cp->cp_xstate,
9127c478bd9Sstevel@tonic-gate 			    ccomp == cp->cp_rcomp ? cp->cp_rstate : NULL, val);
9137c478bd9Sstevel@tonic-gate 			if (rc != 0)
9147c478bd9Sstevel@tonic-gate 				break;
9157c478bd9Sstevel@tonic-gate 		}
9167c478bd9Sstevel@tonic-gate 		if ((ccomp = cp->cp_rcomp) != NULL && ccomp != cp->cp_xcomp &&
9177c478bd9Sstevel@tonic-gate 		    ccomp->set_effort != NULL)
9187c478bd9Sstevel@tonic-gate 			rc = (*ccomp->set_effort)(NULL, cp->cp_rstate, val);
9197c478bd9Sstevel@tonic-gate 		break;
9207c478bd9Sstevel@tonic-gate 	}
9217c478bd9Sstevel@tonic-gate 	if (rc == 0 && mp->b_cont != NULL)
9227c478bd9Sstevel@tonic-gate 		mp->b_cont->b_wptr = mp->b_cont->b_rptr + len;
9237c478bd9Sstevel@tonic-gate 	return (rc);
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate /*
9277c478bd9Sstevel@tonic-gate  * spppcomp_getcstat()
9287c478bd9Sstevel@tonic-gate  *
9297c478bd9Sstevel@tonic-gate  * MT-Perimeters:
9307c478bd9Sstevel@tonic-gate  *    exclusive inner.
9317c478bd9Sstevel@tonic-gate  *
9327c478bd9Sstevel@tonic-gate  * Description:
9337c478bd9Sstevel@tonic-gate  *    Called by spppcomp_ioctl as the result of receiving a PPPIO_GETCSTAT.
9347c478bd9Sstevel@tonic-gate  */
9357c478bd9Sstevel@tonic-gate static void
9367c478bd9Sstevel@tonic-gate spppcomp_getcstat(queue_t *q, mblk_t *mp, sppp_comp_t *cp)
9377c478bd9Sstevel@tonic-gate {
9387c478bd9Sstevel@tonic-gate 	mblk_t		*mpnext;
9397c478bd9Sstevel@tonic-gate 	struct ppp_comp_stats	*csp;
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate 	ASSERT(cp != NULL);
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 	mpnext = allocb(sizeof (struct ppp_comp_stats), BPRI_MED);
9447c478bd9Sstevel@tonic-gate 	if (mpnext == NULL) {
9457c478bd9Sstevel@tonic-gate 		miocnak(q, mp, 0, ENOSR);
9467c478bd9Sstevel@tonic-gate 		return;
9477c478bd9Sstevel@tonic-gate 	}
9487c478bd9Sstevel@tonic-gate 	if (mp->b_cont != NULL) {
9497c478bd9Sstevel@tonic-gate 		freemsg(mp->b_cont);
9507c478bd9Sstevel@tonic-gate 	}
9517c478bd9Sstevel@tonic-gate 	mp->b_cont = mpnext;
9527c478bd9Sstevel@tonic-gate 	csp = (struct ppp_comp_stats *)mpnext->b_wptr;
9537c478bd9Sstevel@tonic-gate 	mpnext->b_wptr += sizeof (struct ppp_comp_stats);
9547c478bd9Sstevel@tonic-gate 	bzero((caddr_t)csp, sizeof (struct ppp_comp_stats));
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
9577c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_stat)(cp->cp_xstate, &csp->c);
9587c478bd9Sstevel@tonic-gate 	}
9597c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
9607c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_stat)(cp->cp_rstate, &csp->d);
9617c478bd9Sstevel@tonic-gate 	}
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	miocack(q, mp, sizeof (struct ppp_comp_stats), 0);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate /*
9677c478bd9Sstevel@tonic-gate  * spppcomp_ioctl()
9687c478bd9Sstevel@tonic-gate  *
9697c478bd9Sstevel@tonic-gate  * MT-Perimeters:
9707c478bd9Sstevel@tonic-gate  *    exclusive inner.
9717c478bd9Sstevel@tonic-gate  *
9727c478bd9Sstevel@tonic-gate  * Description:
9737c478bd9Sstevel@tonic-gate  *    Called by spppcomp_wput as the result of receiving an M_IOCTL
9747c478bd9Sstevel@tonic-gate  *    command.
9757c478bd9Sstevel@tonic-gate  */
9767c478bd9Sstevel@tonic-gate static void
9777c478bd9Sstevel@tonic-gate spppcomp_ioctl(queue_t *q, mblk_t *mp, sppp_comp_t *cp)
9787c478bd9Sstevel@tonic-gate {
9797c478bd9Sstevel@tonic-gate 	struct iocblk	*iop;
9807c478bd9Sstevel@tonic-gate 	int flag;
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 	ASSERT(cp != NULL);
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 	iop = (struct iocblk *)mp->b_rptr;
9857c478bd9Sstevel@tonic-gate 	switch (iop->ioc_cmd) {
9867c478bd9Sstevel@tonic-gate 	case PPPIO_CFLAGS:
9877c478bd9Sstevel@tonic-gate 	case PPPIO_VJINIT:
9887c478bd9Sstevel@tonic-gate 	case PPPIO_XCOMP:
9897c478bd9Sstevel@tonic-gate 	case PPPIO_RCOMP:
9907c478bd9Sstevel@tonic-gate 	case PPPIO_DEBUG:
9917c478bd9Sstevel@tonic-gate 	case PPPIO_LASTMOD:
9927c478bd9Sstevel@tonic-gate 	case PPPIO_COMPLEV:
9937c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
9947c478bd9Sstevel@tonic-gate 		flag = spppcomp_inner_ioctl(q, mp);
9957c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
9967c478bd9Sstevel@tonic-gate 		if (flag == -1) {
9977c478bd9Sstevel@tonic-gate 			putnext(q, mp);
9987c478bd9Sstevel@tonic-gate 		} else if (flag == 0) {
9997c478bd9Sstevel@tonic-gate 			miocack(q, mp,
10007c478bd9Sstevel@tonic-gate 			    mp->b_cont == NULL ? 0 : MBLKL(mp->b_cont), 0);
10017c478bd9Sstevel@tonic-gate 		} else {
10027c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, flag);
10037c478bd9Sstevel@tonic-gate 		}
10047c478bd9Sstevel@tonic-gate 		break;
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate 	case PPPIO_GETCSTAT:
10077c478bd9Sstevel@tonic-gate 		spppcomp_getcstat(q, mp, cp);
10087c478bd9Sstevel@tonic-gate 		break;
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate 	case PPPIO_GTYPE:	/* get existing driver type */
10117c478bd9Sstevel@tonic-gate 		if (!IS_CP_LASTMOD(cp)) {
10127c478bd9Sstevel@tonic-gate 			putnext(q, mp);
10137c478bd9Sstevel@tonic-gate 			break;
10147c478bd9Sstevel@tonic-gate 		}
10157c478bd9Sstevel@tonic-gate 		freemsg(mp->b_next);
10167c478bd9Sstevel@tonic-gate 		mp->b_next = allocb(sizeof (uint32_t), BPRI_MED);
10177c478bd9Sstevel@tonic-gate 		if (mp->b_next == NULL) {
10187c478bd9Sstevel@tonic-gate 			miocnak(q, mp, 0, ENOSR);
10197c478bd9Sstevel@tonic-gate 		} else {
10207c478bd9Sstevel@tonic-gate 			*(uint32_t *)mp->b_cont->b_wptr = PPPTYP_HC;
10217c478bd9Sstevel@tonic-gate 			mp->b_cont->b_wptr += sizeof (uint32_t);
10227c478bd9Sstevel@tonic-gate 			miocack(q, mp, sizeof (uint32_t), 0);
10237c478bd9Sstevel@tonic-gate 		}
10247c478bd9Sstevel@tonic-gate 		break;
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 	default:
10277c478bd9Sstevel@tonic-gate 		putnext(q, mp);
10287c478bd9Sstevel@tonic-gate 		break;
10297c478bd9Sstevel@tonic-gate 	}
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate /*
10337c478bd9Sstevel@tonic-gate  * spppcomp_mctl()
10347c478bd9Sstevel@tonic-gate  *
10357c478bd9Sstevel@tonic-gate  * MT-Perimeters:
10367c478bd9Sstevel@tonic-gate  *    exclusive inner; queue pair lock held.
10377c478bd9Sstevel@tonic-gate  *
10387c478bd9Sstevel@tonic-gate  * Description:
10397c478bd9Sstevel@tonic-gate  *	Called by spppcomp_wput as the result of receiving an M_CTL
10407c478bd9Sstevel@tonic-gate  *	message from another STREAMS module, and returns non-zero if
10417c478bd9Sstevel@tonic-gate  *	caller should do putnext or zero for freemsg.  Must *NOT* do
10427c478bd9Sstevel@tonic-gate  *	putnext in this routine, since lock is held here.
10437c478bd9Sstevel@tonic-gate  */
10447c478bd9Sstevel@tonic-gate static int
10457c478bd9Sstevel@tonic-gate spppcomp_mctl(queue_t *q, mblk_t *mp)
10467c478bd9Sstevel@tonic-gate {
1047f53eecf5SJames Carlson 	sppp_comp_t		*cp = q->q_ptr;
10487c478bd9Sstevel@tonic-gate 	kstat_t			*ksp;
10497c478bd9Sstevel@tonic-gate 	char			unit[32];
10507c478bd9Sstevel@tonic-gate 	const char **cpp;
10517c478bd9Sstevel@tonic-gate 	kstat_named_t *knt;
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate 	switch (*mp->b_rptr) {
10547c478bd9Sstevel@tonic-gate 	case PPPCTL_MTU:
10557c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 4) {
10567c478bd9Sstevel@tonic-gate 			break;
10577c478bd9Sstevel@tonic-gate 		}
10587c478bd9Sstevel@tonic-gate 		cp->cp_mtu = ((ushort_t *)mp->b_rptr)[1];
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPCTL_MTU (%d) flags=0x%b\n",
10617c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
10627c478bd9Sstevel@tonic-gate 		    cp->cp_mtu, cp->cp_flags, CP_FLAGSSTR));
10637c478bd9Sstevel@tonic-gate 		break;
10647c478bd9Sstevel@tonic-gate 	case PPPCTL_MRU:
10657c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 4) {
10667c478bd9Sstevel@tonic-gate 			break;
10677c478bd9Sstevel@tonic-gate 		}
10687c478bd9Sstevel@tonic-gate 		cp->cp_mru = ((ushort_t *)mp->b_rptr)[1];
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "PPPCTL_MRU (%d) flags=0x%b\n",
10717c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
10727c478bd9Sstevel@tonic-gate 		    cp->cp_mru, cp->cp_flags, CP_FLAGSSTR));
10737c478bd9Sstevel@tonic-gate 		break;
10747c478bd9Sstevel@tonic-gate 	case PPPCTL_UNIT:
10757c478bd9Sstevel@tonic-gate 		if (MBLKL(mp) < 8) {
10767c478bd9Sstevel@tonic-gate 			break;
10777c478bd9Sstevel@tonic-gate 		}
10787c478bd9Sstevel@tonic-gate 		/* If PPPCTL_UNIT has already been issued, then ignore. */
10797c478bd9Sstevel@tonic-gate 		if (IS_CP_HASUNIT(cp)) {
10807c478bd9Sstevel@tonic-gate 			break;
10817c478bd9Sstevel@tonic-gate 		}
10827c478bd9Sstevel@tonic-gate 		ASSERT(cp->cp_kstats == NULL);
10837c478bd9Sstevel@tonic-gate 		cp->cp_unit = ((uint32_t *)mp->b_rptr)[1];
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 		/* Create kstats for this unit. */
1086002c70ffScarlsonj 		(void) sprintf(unit, "%s" "%d", COMP_MOD_NAME, cp->cp_unit);
10877c478bd9Sstevel@tonic-gate 		ksp = kstat_create(COMP_MOD_NAME, cp->cp_unit, unit, "net",
1088002c70ffScarlsonj 		    KSTAT_TYPE_NAMED, sizeof (spppcomp_kstats_t) /
1089002c70ffScarlsonj 		    sizeof (kstat_named_t), 0);
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 		if (ksp != NULL) {
10927c478bd9Sstevel@tonic-gate 			cp->cp_flags |= CP_HASUNIT;
10937c478bd9Sstevel@tonic-gate 			cp->cp_kstats = ksp;
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate 			knt = (kstat_named_t *)ksp->ks_data;
10967c478bd9Sstevel@tonic-gate 			for (cpp = kstats_names;
10977c478bd9Sstevel@tonic-gate 			    cpp < kstats_names + Dim(kstats_names); cpp++) {
1098d624471bSelowe 				kstat_named_init(knt, *cpp,
10997c478bd9Sstevel@tonic-gate 				    KSTAT_DATA_UINT32);
11007c478bd9Sstevel@tonic-gate 				knt++;
11017c478bd9Sstevel@tonic-gate 			}
11027c478bd9Sstevel@tonic-gate 			for (cpp = kstats64_names;
11037c478bd9Sstevel@tonic-gate 			    cpp < kstats64_names + Dim(kstats64_names); cpp++) {
1104d624471bSelowe 				kstat_named_init(knt, *cpp,
11057c478bd9Sstevel@tonic-gate 				    KSTAT_DATA_UINT64);
11067c478bd9Sstevel@tonic-gate 				knt++;
11077c478bd9Sstevel@tonic-gate 			}
11087c478bd9Sstevel@tonic-gate 			ksp->ks_update = spppcomp_kstat_update;
11097c478bd9Sstevel@tonic-gate 			ksp->ks_private = (void *)cp;
11107c478bd9Sstevel@tonic-gate 			kstat_install(ksp);
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 			CPDEBUG((DBGSTART "PPPCTL_UNIT flags=0x%b\n",
11137c478bd9Sstevel@tonic-gate 			    cp->cp_unit, cp->cp_flags, CP_FLAGSSTR));
11147c478bd9Sstevel@tonic-gate 		}
11157c478bd9Sstevel@tonic-gate 		break;
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate 	default:
11187c478bd9Sstevel@tonic-gate 		/* Forward unknown M_CTL messages along */
11197c478bd9Sstevel@tonic-gate 		return (1);
11207c478bd9Sstevel@tonic-gate 	}
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 	/*
11237c478bd9Sstevel@tonic-gate 	 * For known PPP M_CTL messages, forward along only if we're not the
11247c478bd9Sstevel@tonic-gate 	 * last PPP-aware module.
11257c478bd9Sstevel@tonic-gate 	 */
11267c478bd9Sstevel@tonic-gate 	if (IS_CP_LASTMOD(cp))
11277c478bd9Sstevel@tonic-gate 		return (0);
11287c478bd9Sstevel@tonic-gate 	return (1);
11297c478bd9Sstevel@tonic-gate }
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate /*
11327c478bd9Sstevel@tonic-gate  * spppcomp_rput()
11337c478bd9Sstevel@tonic-gate  *
11347c478bd9Sstevel@tonic-gate  * MT-Perimeters:
11357c478bd9Sstevel@tonic-gate  *    exclusive inner.
11367c478bd9Sstevel@tonic-gate  *
11377c478bd9Sstevel@tonic-gate  * Description:
11387c478bd9Sstevel@tonic-gate  *    Upper read-side put procedure.  Messages get here from below.
11397c478bd9Sstevel@tonic-gate  *
11407c478bd9Sstevel@tonic-gate  *	The data handling logic is a little more tricky here.  We
11417c478bd9Sstevel@tonic-gate  *	defer to the service routine if q_first isn't NULL (to
11427c478bd9Sstevel@tonic-gate  *	preserve message ordering after deferring a previous message),
11437c478bd9Sstevel@tonic-gate  *	bcanputnext() is FALSE (to handle flow control), or we have
11447c478bd9Sstevel@tonic-gate  *	done a lot of processing recently and we're about to do a lot
11457c478bd9Sstevel@tonic-gate  *	more and we're in an interrupt context (on the theory that
11467c478bd9Sstevel@tonic-gate  *	we're hogging the CPU in this case).
11477c478bd9Sstevel@tonic-gate  */
1148f53eecf5SJames Carlson static void
11497c478bd9Sstevel@tonic-gate spppcomp_rput(queue_t *q, mblk_t *mp)
11507c478bd9Sstevel@tonic-gate {
1151f53eecf5SJames Carlson 	sppp_comp_t		*cp = q->q_ptr;
11527c478bd9Sstevel@tonic-gate 	struct iocblk		*iop;
11537c478bd9Sstevel@tonic-gate 	struct ppp_stats64	*psp;
11547c478bd9Sstevel@tonic-gate 	boolean_t		inter;
11557c478bd9Sstevel@tonic-gate 	hrtime_t		curtime;
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate 	switch (MTYPE(mp)) {
11587c478bd9Sstevel@tonic-gate 	case M_DATA:
11597c478bd9Sstevel@tonic-gate 		inter = servicing_interrupt();
11607c478bd9Sstevel@tonic-gate 		if (inter) {
11617c478bd9Sstevel@tonic-gate 			curtime = gethrtime();
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 			/*
11647c478bd9Sstevel@tonic-gate 			 * If little time has passed since last
11657c478bd9Sstevel@tonic-gate 			 * arrival, then bump the counter.
11667c478bd9Sstevel@tonic-gate 			 */
11677c478bd9Sstevel@tonic-gate 			if (curtime - cp->cp_lastfinish < spppcomp_min_arrival)
11687c478bd9Sstevel@tonic-gate 				cp->cp_fastin++;
11697c478bd9Sstevel@tonic-gate 			else
11707c478bd9Sstevel@tonic-gate 				cp->cp_fastin >>= 1;	/* a guess */
11717c478bd9Sstevel@tonic-gate 		}
11727c478bd9Sstevel@tonic-gate 		/*
11737c478bd9Sstevel@tonic-gate 		 * If we're not decompressing, then we'll be fast, so
11747c478bd9Sstevel@tonic-gate 		 * we don't have to worry about hogging here.  If we
11757c478bd9Sstevel@tonic-gate 		 * are decompressing, then we have to check the
11767c478bd9Sstevel@tonic-gate 		 * cp_fastin count.
11777c478bd9Sstevel@tonic-gate 		 */
11787c478bd9Sstevel@tonic-gate 		if ((!(cp->cp_flags & (CCP_DECOMP_RUN | DECOMP_VJC)) ||
11797c478bd9Sstevel@tonic-gate 		    cp->cp_fastin < MAX_FAST_ARRIVALS) &&
11807c478bd9Sstevel@tonic-gate 		    q->q_first == NULL && bcanputnext(q, mp->b_band)) {
11817c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
11827c478bd9Sstevel@tonic-gate 			cp->cp_in_handled++;
11837c478bd9Sstevel@tonic-gate #endif
11847c478bd9Sstevel@tonic-gate 			if ((mp = spppcomp_inpkt(q, mp)) != NULL)
11857c478bd9Sstevel@tonic-gate 				putnext(q, mp);
11867c478bd9Sstevel@tonic-gate 			if (inter) {
11877c478bd9Sstevel@tonic-gate 				cp->cp_lastfinish = gethrtime();
11887c478bd9Sstevel@tonic-gate 			}
11897c478bd9Sstevel@tonic-gate 		} else {
1190*48bbca81SDaniel Hoffman 			/* Deferring; provide a clean slate */
11917c478bd9Sstevel@tonic-gate 			cp->cp_fastin = 0;
11927c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
11937c478bd9Sstevel@tonic-gate 			cp->cp_in_queued++;
11947c478bd9Sstevel@tonic-gate #endif
1195f53eecf5SJames Carlson 			if (!putq(q, mp))
1196f53eecf5SJames Carlson 				freemsg(mp);
11977c478bd9Sstevel@tonic-gate 		}
11987c478bd9Sstevel@tonic-gate 		break;
11997c478bd9Sstevel@tonic-gate 	case M_IOCACK:
12007c478bd9Sstevel@tonic-gate 		iop = (struct iocblk *)mp->b_rptr;
12017c478bd9Sstevel@tonic-gate 		/*
12027c478bd9Sstevel@tonic-gate 		 * Bundled with pppstats; no need to handle PPPIO_GETSTAT
12037c478bd9Sstevel@tonic-gate 		 * here since we'll never see it.
12047c478bd9Sstevel@tonic-gate 		 */
12057c478bd9Sstevel@tonic-gate 		if (iop->ioc_cmd == PPPIO_GETSTAT64 &&
12067c478bd9Sstevel@tonic-gate 		    iop->ioc_count == sizeof (struct ppp_stats64) &&
12077c478bd9Sstevel@tonic-gate 		    mp->b_cont != NULL) {
12087c478bd9Sstevel@tonic-gate 			/*
12097c478bd9Sstevel@tonic-gate 			 * This crock is to handle a badly-designed
12107c478bd9Sstevel@tonic-gate 			 * but well-known ioctl for ANU PPP.  Both
12117c478bd9Sstevel@tonic-gate 			 * link statistics and VJ statistics are
12127c478bd9Sstevel@tonic-gate 			 * requested together.
12137c478bd9Sstevel@tonic-gate 			 *
12147c478bd9Sstevel@tonic-gate 			 * Catch this on the way back from the
12157c478bd9Sstevel@tonic-gate 			 * spppasyn module so we can fill in the VJ
12167c478bd9Sstevel@tonic-gate 			 * stats.  This happens only when we have
12177c478bd9Sstevel@tonic-gate 			 * PPP-aware modules beneath us.
12187c478bd9Sstevel@tonic-gate 			 */
12197c478bd9Sstevel@tonic-gate 			psp = (struct ppp_stats64 *)mp->b_cont->b_rptr;
12207c478bd9Sstevel@tonic-gate 			psp->vj = cp->cp_vj.stats;
12217c478bd9Sstevel@tonic-gate 			CPDEBUG((DBGSTART
12227c478bd9Sstevel@tonic-gate 			    "PPPIO_GETSTAT64 (VJ filled) flags=0x%b\n",
12237c478bd9Sstevel@tonic-gate 			    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
12247c478bd9Sstevel@tonic-gate 			    cp->cp_flags, CP_FLAGSSTR));
12257c478bd9Sstevel@tonic-gate 		}
12267c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12277c478bd9Sstevel@tonic-gate 		break;
12287c478bd9Sstevel@tonic-gate 	case M_CTL:
12297c478bd9Sstevel@tonic-gate 		/* Increase our statistics and forward it upstream. */
12307c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
12317c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr == PPPCTL_IERROR) {
12327c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_ierrors++;
12337c478bd9Sstevel@tonic-gate 			cp->cp_ierr_low++;
12347c478bd9Sstevel@tonic-gate 		} else if (*mp->b_rptr == PPPCTL_OERROR) {
12357c478bd9Sstevel@tonic-gate 			cp->cp_stats.ppp_oerrors++;
12367c478bd9Sstevel@tonic-gate 			cp->cp_oerr_low++;
12377c478bd9Sstevel@tonic-gate 		}
12387c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
12397c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12407c478bd9Sstevel@tonic-gate 		break;
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate 	case M_FLUSH:
12437c478bd9Sstevel@tonic-gate 		CPDEBUG((DBGSTART "rput M_FLUSH (0x%x) flags=0x%b\n",
12447c478bd9Sstevel@tonic-gate 		    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1),
12457c478bd9Sstevel@tonic-gate 		    *mp->b_rptr, cp->cp_flags,	CP_FLAGSSTR));
12467c478bd9Sstevel@tonic-gate 		/*
12477c478bd9Sstevel@tonic-gate 		 * Just discard pending data.  For CCP, any
12487c478bd9Sstevel@tonic-gate 		 * decompressor dictionary sequencing problems caused
12497c478bd9Sstevel@tonic-gate 		 * by this will have to be handled by the compression
12507c478bd9Sstevel@tonic-gate 		 * protocol in use.  For VJ, we need to give the
12517c478bd9Sstevel@tonic-gate 		 * decompressor a heads-up.
12527c478bd9Sstevel@tonic-gate 		 */
12537c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR) {
12547c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
12557c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
12567c478bd9Sstevel@tonic-gate 			cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
12577c478bd9Sstevel@tonic-gate 			vj_uncompress_err(&cp->cp_vj);
12587c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
12597c478bd9Sstevel@tonic-gate 		}
12607c478bd9Sstevel@tonic-gate 		putnext(q, mp);
12617c478bd9Sstevel@tonic-gate 		break;
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 	default:
1264f53eecf5SJames Carlson 		if (bcanputnext(q, mp->b_band))
1265f53eecf5SJames Carlson 			putnext(q, mp);
1266f53eecf5SJames Carlson 		else if (!putq(q, mp))
1267f53eecf5SJames Carlson 			freemsg(mp);
12687c478bd9Sstevel@tonic-gate 		break;
12697c478bd9Sstevel@tonic-gate 	}
12707c478bd9Sstevel@tonic-gate }
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate /*
12737c478bd9Sstevel@tonic-gate  * spppcomp_rsrv()
12747c478bd9Sstevel@tonic-gate  *
12757c478bd9Sstevel@tonic-gate  * MT-Perimeters:
12767c478bd9Sstevel@tonic-gate  *    exclusive inner.
12777c478bd9Sstevel@tonic-gate  *
12787c478bd9Sstevel@tonic-gate  * Description:
12797c478bd9Sstevel@tonic-gate  *    Upper read-side service procedure.  We handle data deferred from
12807c478bd9Sstevel@tonic-gate  *    spppcomp_rput here.
12817c478bd9Sstevel@tonic-gate  *
12827c478bd9Sstevel@tonic-gate  *	The data on the queue are always compressed (unprocessed).
12837c478bd9Sstevel@tonic-gate  *	The rput procedure tries to do decompression, but if it can't,
12847c478bd9Sstevel@tonic-gate  *	it will put the unprocessed data on the queue for later
12857c478bd9Sstevel@tonic-gate  *	handling.
12867c478bd9Sstevel@tonic-gate  */
1287f53eecf5SJames Carlson static void
12887c478bd9Sstevel@tonic-gate spppcomp_rsrv(queue_t *q)
12897c478bd9Sstevel@tonic-gate {
12907c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 	while ((mp = getq(q)) != NULL) {
12937c478bd9Sstevel@tonic-gate 		/*
12947c478bd9Sstevel@tonic-gate 		 * If the module above us is flow-controlled, then put
12957c478bd9Sstevel@tonic-gate 		 * this message back on the queue again.
12967c478bd9Sstevel@tonic-gate 		 */
12977c478bd9Sstevel@tonic-gate 		if (!bcanputnext(q, mp->b_band)) {
12987c478bd9Sstevel@tonic-gate 			(void) putbq(q, mp);
12997c478bd9Sstevel@tonic-gate 			break;
13007c478bd9Sstevel@tonic-gate 		}
1301f53eecf5SJames Carlson 		if (MTYPE(mp) != M_DATA ||
1302f53eecf5SJames Carlson 		    (mp = spppcomp_inpkt(q, mp)) != NULL)
13037c478bd9Sstevel@tonic-gate 			putnext(q, mp);
13047c478bd9Sstevel@tonic-gate 	}
13057c478bd9Sstevel@tonic-gate }
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate /*
13087c478bd9Sstevel@tonic-gate  * spppcomp_inpkt()
13097c478bd9Sstevel@tonic-gate  *
13107c478bd9Sstevel@tonic-gate  * MT-Perimeters:
13117c478bd9Sstevel@tonic-gate  *    exclusive inner
13127c478bd9Sstevel@tonic-gate  *
13137c478bd9Sstevel@tonic-gate  * Description:
13147c478bd9Sstevel@tonic-gate  *    Process incoming packet.
13157c478bd9Sstevel@tonic-gate  */
13167c478bd9Sstevel@tonic-gate static mblk_t *
13177c478bd9Sstevel@tonic-gate spppcomp_inpkt(queue_t *q, mblk_t *mp)
13187c478bd9Sstevel@tonic-gate {
13197c478bd9Sstevel@tonic-gate 	ushort_t	proto;
13207c478bd9Sstevel@tonic-gate 	int		i;
13217c478bd9Sstevel@tonic-gate 	mblk_t		*zmp;
13227c478bd9Sstevel@tonic-gate 	mblk_t		*np;
13237c478bd9Sstevel@tonic-gate 	uchar_t		*dp;
13247c478bd9Sstevel@tonic-gate 	int		len;
13257c478bd9Sstevel@tonic-gate 	int		hlen;
1326f53eecf5SJames Carlson 	sppp_comp_t	*cp = q->q_ptr;
13277c478bd9Sstevel@tonic-gate 
13287c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
13297c478bd9Sstevel@tonic-gate 
13307c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
13317c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ibytes += len;
13327c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ipackets++;
13337c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
13347c478bd9Sstevel@tonic-gate 	/*
13357c478bd9Sstevel@tonic-gate 	 * First work out the protocol and where the PPP header ends.
13367c478bd9Sstevel@tonic-gate 	 */
13377c478bd9Sstevel@tonic-gate 	i = 0;
13387c478bd9Sstevel@tonic-gate 	proto = MSG_BYTE(mp, 0);
13397c478bd9Sstevel@tonic-gate 	if (proto == PPP_ALLSTATIONS) {
13407c478bd9Sstevel@tonic-gate 		i = 2;
13417c478bd9Sstevel@tonic-gate 		proto = MSG_BYTE(mp, 2);
13427c478bd9Sstevel@tonic-gate 	}
13437c478bd9Sstevel@tonic-gate 	if ((proto & 1) == 0) {
13447c478bd9Sstevel@tonic-gate 		++i;
13457c478bd9Sstevel@tonic-gate 		proto = (proto << 8) + MSG_BYTE(mp, i);
13467c478bd9Sstevel@tonic-gate 	}
13477c478bd9Sstevel@tonic-gate 	hlen = i + 1;
13487c478bd9Sstevel@tonic-gate 	/*
13497c478bd9Sstevel@tonic-gate 	 * Now reconstruct a complete, contiguous PPP header at the
13507c478bd9Sstevel@tonic-gate 	 * start of the packet.
13517c478bd9Sstevel@tonic-gate 	 */
13527c478bd9Sstevel@tonic-gate 	if (hlen < (IS_DECOMP_AC(cp) ? 0 : 2) + (IS_DECOMP_PROT(cp) ? 1 : 2)) {
13537c478bd9Sstevel@tonic-gate 		/* count these? */
13547c478bd9Sstevel@tonic-gate 		goto bad;
13557c478bd9Sstevel@tonic-gate 	}
13567c478bd9Sstevel@tonic-gate 	if (mp->b_rptr + hlen > mp->b_wptr) {
13577c478bd9Sstevel@tonic-gate 		/*
13587c478bd9Sstevel@tonic-gate 		 * Header is known to be intact here; so adjmsg will do the
13597c478bd9Sstevel@tonic-gate 		 * right thing here.
13607c478bd9Sstevel@tonic-gate 		 */
13617c478bd9Sstevel@tonic-gate 		if (!adjmsg(mp, hlen)) {
13627c478bd9Sstevel@tonic-gate 			goto bad;
13637c478bd9Sstevel@tonic-gate 		}
13647c478bd9Sstevel@tonic-gate 		hlen = 0;
13657c478bd9Sstevel@tonic-gate 	}
13667c478bd9Sstevel@tonic-gate 	if (hlen != PPP_HDRLEN) {
13677c478bd9Sstevel@tonic-gate 		/*
13687c478bd9Sstevel@tonic-gate 		 * We need to put some bytes on the front of the packet
13697c478bd9Sstevel@tonic-gate 		 * to make a full-length PPP header. If we can put them
13707c478bd9Sstevel@tonic-gate 		 * in mp, we do, otherwise we tack another mblk on the
13717c478bd9Sstevel@tonic-gate 		 * front.
13727c478bd9Sstevel@tonic-gate 		 *
13737c478bd9Sstevel@tonic-gate 		 * XXX we really shouldn't need to carry around the address
13747c478bd9Sstevel@tonic-gate 		 * and control at this stage.  ACFC and PFC need to be
13757c478bd9Sstevel@tonic-gate 		 * reworked.
13767c478bd9Sstevel@tonic-gate 		 */
13777c478bd9Sstevel@tonic-gate 		dp = mp->b_rptr + hlen - PPP_HDRLEN;
13787c478bd9Sstevel@tonic-gate 		if ((dp < mp->b_datap->db_base) || (DB_REF(mp) > 1)) {
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate 			np = allocb(PPP_HDRLEN, BPRI_MED);
13817c478bd9Sstevel@tonic-gate 			if (np == 0) {
13827c478bd9Sstevel@tonic-gate 				goto bad;
13837c478bd9Sstevel@tonic-gate 			}
13847c478bd9Sstevel@tonic-gate 			np->b_cont = mp;
13857c478bd9Sstevel@tonic-gate 			mp->b_rptr += hlen;
13867c478bd9Sstevel@tonic-gate 			mp = np;
13877c478bd9Sstevel@tonic-gate 			dp = mp->b_wptr;
13887c478bd9Sstevel@tonic-gate 			mp->b_wptr += PPP_HDRLEN;
13897c478bd9Sstevel@tonic-gate 		} else {
13907c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp;
13917c478bd9Sstevel@tonic-gate 		}
13927c478bd9Sstevel@tonic-gate 		dp[0] = PPP_ALLSTATIONS;
13937c478bd9Sstevel@tonic-gate 		dp[1] = PPP_UI;
13947c478bd9Sstevel@tonic-gate 		dp[2] = (proto >> 8) & 0xff;
13957c478bd9Sstevel@tonic-gate 		dp[3] = proto & 0xff;
13967c478bd9Sstevel@tonic-gate 	}
13977c478bd9Sstevel@tonic-gate 	/*
13987c478bd9Sstevel@tonic-gate 	 * Now see if we have a compressed packet to decompress, or a
13997c478bd9Sstevel@tonic-gate 	 * CCP negotiation packet to take notice of.  It's guaranteed
14007c478bd9Sstevel@tonic-gate 	 * that at least PPP_HDRLEN bytes are contiguous in the first
14017c478bd9Sstevel@tonic-gate 	 * block now.
14027c478bd9Sstevel@tonic-gate 	 */
14037c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
14047c478bd9Sstevel@tonic-gate 	if (proto == PPP_CCP) {
14057c478bd9Sstevel@tonic-gate 		len = msgsize(mp);
14067c478bd9Sstevel@tonic-gate 		if (mp->b_wptr < mp->b_rptr + len) {
14077c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
14087c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
14097c478bd9Sstevel@tonic-gate 			cp->cp_imsg_ccp_pull++;
14107c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
14117c478bd9Sstevel@tonic-gate #endif
14127c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, len);
14137c478bd9Sstevel@tonic-gate 			freemsg(mp);
14147c478bd9Sstevel@tonic-gate 			mp = zmp;
14157c478bd9Sstevel@tonic-gate 			if (mp == 0) {
14167c478bd9Sstevel@tonic-gate 				goto bad;
14177c478bd9Sstevel@tonic-gate 			}
14187c478bd9Sstevel@tonic-gate 		}
14197c478bd9Sstevel@tonic-gate 		mutex_enter(&cp->cp_pair_lock);
14207c478bd9Sstevel@tonic-gate 		comp_ccp(q, mp, cp, B_TRUE);
14217c478bd9Sstevel@tonic-gate 		mutex_exit(&cp->cp_pair_lock);
14227c478bd9Sstevel@tonic-gate 	} else if ((cp->cp_flags & (CCP_ISUP | CCP_DECOMP_RUN | CCP_ERR)) ==
14237c478bd9Sstevel@tonic-gate 	    (CCP_ISUP | CCP_DECOMP_RUN) && cp->cp_rstate != NULL) {
14247c478bd9Sstevel@tonic-gate 		int	rv;
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate 		if ((proto == PPP_COMP) || (proto == PPP_COMPFRAG)) {
14277c478bd9Sstevel@tonic-gate 			rv = (*cp->cp_rcomp->decompress)(cp->cp_rstate, &mp);
14287c478bd9Sstevel@tonic-gate 			switch (rv) {
14297c478bd9Sstevel@tonic-gate 			case DECOMP_OK:
14307c478bd9Sstevel@tonic-gate 				break;
14317c478bd9Sstevel@tonic-gate 			case DECOMP_ERROR:
14327c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_ERROR;
14337c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14347c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14357c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14367c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14377c478bd9Sstevel@tonic-gate 				break;
14387c478bd9Sstevel@tonic-gate 			case DECOMP_FATALERROR:
14397c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_FATALERROR;
14407c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14417c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14427c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14437c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14447c478bd9Sstevel@tonic-gate 				break;
14457c478bd9Sstevel@tonic-gate 			}
14467c478bd9Sstevel@tonic-gate 			if (mp == NULL) {
14477c478bd9Sstevel@tonic-gate 				/* Decompress failed; data are gone. */
14487c478bd9Sstevel@tonic-gate 				return (NULL);
14497c478bd9Sstevel@tonic-gate 			}
14507c478bd9Sstevel@tonic-gate 		} else {
14517c478bd9Sstevel@tonic-gate 			/*
14527c478bd9Sstevel@tonic-gate 			 * For RFCs 1977 and 1979 (BSD Compress and Deflate),
14537c478bd9Sstevel@tonic-gate 			 * the compressor should send incompressible data
14547c478bd9Sstevel@tonic-gate 			 * without encapsulation and the receiver must update
14557c478bd9Sstevel@tonic-gate 			 * its decompression dictionary as though this data
14567c478bd9Sstevel@tonic-gate 			 * were received and decompressed.  This keeps the
14577c478bd9Sstevel@tonic-gate 			 * dictionaries in sync.
14587c478bd9Sstevel@tonic-gate 			 */
14597c478bd9Sstevel@tonic-gate 			rv = (*cp->cp_rcomp->incomp)(cp->cp_rstate, mp);
14607c478bd9Sstevel@tonic-gate 			if (rv < 0) {
14617c478bd9Sstevel@tonic-gate 				cp->cp_flags |= CCP_FATALERROR;
14627c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
14637c478bd9Sstevel@tonic-gate 				++cp->cp_stats.ppp_ierrors;
14647c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
14657c478bd9Sstevel@tonic-gate 				(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
14667c478bd9Sstevel@tonic-gate 			}
14677c478bd9Sstevel@tonic-gate 		}
14687c478bd9Sstevel@tonic-gate 	}
14697c478bd9Sstevel@tonic-gate 	/*
14707c478bd9Sstevel@tonic-gate 	 * Now do VJ decompression.
14717c478bd9Sstevel@tonic-gate 	 */
14727c478bd9Sstevel@tonic-gate 	proto = PPP_PROTOCOL(mp->b_rptr);
14737c478bd9Sstevel@tonic-gate 	if ((proto == PPP_VJC_COMP) || (proto == PPP_VJC_UNCOMP)) {
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate 		len = msgsize(mp) - PPP_HDRLEN;
14767c478bd9Sstevel@tonic-gate 
14777c478bd9Sstevel@tonic-gate 		if (!IS_DECOMP_VJC(cp) || (len <= 0)) {
14787c478bd9Sstevel@tonic-gate 			goto bad;
14797c478bd9Sstevel@tonic-gate 		}
14807c478bd9Sstevel@tonic-gate 		/*
14817c478bd9Sstevel@tonic-gate 		 * Advance past the ppp header.  Here we assume that the whole
14827c478bd9Sstevel@tonic-gate 		 * PPP header is in the first mblk.  (This should be true
14837c478bd9Sstevel@tonic-gate 		 * because the above code does pull-ups as necessary on raw
14847c478bd9Sstevel@tonic-gate 		 * data, and the decompressor engines all produce large blocks
14857c478bd9Sstevel@tonic-gate 		 * on output.)
14867c478bd9Sstevel@tonic-gate 		 */
14877c478bd9Sstevel@tonic-gate 		np = mp;
14887c478bd9Sstevel@tonic-gate 		dp = np->b_rptr + PPP_HDRLEN;
14897c478bd9Sstevel@tonic-gate 		if (dp >= mp->b_wptr) {
14907c478bd9Sstevel@tonic-gate 			np = np->b_cont;
14917c478bd9Sstevel@tonic-gate 			dp = np->b_rptr;
14927c478bd9Sstevel@tonic-gate 		}
14937c478bd9Sstevel@tonic-gate 		/*
14947c478bd9Sstevel@tonic-gate 		 * Make sure we have sufficient contiguous data at this point,
14957c478bd9Sstevel@tonic-gate 		 * which in most cases we will always do.
14967c478bd9Sstevel@tonic-gate 		 */
14977c478bd9Sstevel@tonic-gate 		hlen = (proto == PPP_VJC_COMP) ? MAX_VJHDR : MAX_TCPIPHLEN;
14987c478bd9Sstevel@tonic-gate 		if (hlen > len) {
14997c478bd9Sstevel@tonic-gate 			hlen = len;
15007c478bd9Sstevel@tonic-gate 		}
15017c478bd9Sstevel@tonic-gate 		if ((np->b_wptr < dp + hlen) || DB_REF(np) > 1) {
15027c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
15037c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
15047c478bd9Sstevel@tonic-gate 			cp->cp_imsg_vj_pull++;
15057c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
15067c478bd9Sstevel@tonic-gate #endif
15077c478bd9Sstevel@tonic-gate 			zmp = msgpullup(mp, hlen + PPP_HDRLEN);
15087c478bd9Sstevel@tonic-gate 			freemsg(mp);
15097c478bd9Sstevel@tonic-gate 			mp = zmp;
15107c478bd9Sstevel@tonic-gate 			if (mp == NULL) {
15117c478bd9Sstevel@tonic-gate 				goto bad;
15127c478bd9Sstevel@tonic-gate 			}
15137c478bd9Sstevel@tonic-gate 			np = mp;
15147c478bd9Sstevel@tonic-gate 			dp = np->b_rptr + PPP_HDRLEN;
15157c478bd9Sstevel@tonic-gate 		}
15167c478bd9Sstevel@tonic-gate 
15177c478bd9Sstevel@tonic-gate 		if (proto == PPP_VJC_COMP) {
15187c478bd9Sstevel@tonic-gate 			uchar_t		*iphdr;
15197c478bd9Sstevel@tonic-gate 			int		vjlen;
15207c478bd9Sstevel@tonic-gate 			uint_t		iphlen;
15217c478bd9Sstevel@tonic-gate 			int		errcnt;
15227c478bd9Sstevel@tonic-gate 
15237c478bd9Sstevel@tonic-gate 			/*
15247c478bd9Sstevel@tonic-gate 			 * Decompress VJ-compressed packet.  First
15257c478bd9Sstevel@tonic-gate 			 * reset compressor if an input error has
15267c478bd9Sstevel@tonic-gate 			 * occurred.  (No need to lock statistics
15277c478bd9Sstevel@tonic-gate 			 * structure for read of a single word.)
15287c478bd9Sstevel@tonic-gate 			 */
15297c478bd9Sstevel@tonic-gate 			errcnt = cp->cp_stats.ppp_ierrors;
15307c478bd9Sstevel@tonic-gate 			if (errcnt != cp->cp_vj_last_ierrors) {
15317c478bd9Sstevel@tonic-gate 				cp->cp_vj_last_ierrors = errcnt;
15327c478bd9Sstevel@tonic-gate 				vj_uncompress_err(&cp->cp_vj);
15337c478bd9Sstevel@tonic-gate 			}
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate 			vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
1536002c70ffScarlsonj 			    &cp->cp_vj, &iphdr, &iphlen);
15377c478bd9Sstevel@tonic-gate 
15387c478bd9Sstevel@tonic-gate 			if (vjlen < 0 || iphlen == 0) {
15397c478bd9Sstevel@tonic-gate 				/*
15407c478bd9Sstevel@tonic-gate 				 * so we don't reset next time
15417c478bd9Sstevel@tonic-gate 				 */
15427c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
15437c478bd9Sstevel@tonic-gate 				++cp->cp_vj_last_ierrors;
15447c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
15457c478bd9Sstevel@tonic-gate 				goto bad;
15467c478bd9Sstevel@tonic-gate 			}
15477c478bd9Sstevel@tonic-gate 			/*
15487c478bd9Sstevel@tonic-gate 			 * drop ppp and vj headers off
15497c478bd9Sstevel@tonic-gate 			 */
15507c478bd9Sstevel@tonic-gate 			if (mp != np) {
15517c478bd9Sstevel@tonic-gate 				freeb(mp);
15527c478bd9Sstevel@tonic-gate 				mp = np;
15537c478bd9Sstevel@tonic-gate 			}
15547c478bd9Sstevel@tonic-gate 			mp->b_rptr = dp + vjlen;
15557c478bd9Sstevel@tonic-gate 			/*
15567c478bd9Sstevel@tonic-gate 			 * allocate a new mblk for the ppp and
15577c478bd9Sstevel@tonic-gate 			 * ip headers
15587c478bd9Sstevel@tonic-gate 			 */
15597c478bd9Sstevel@tonic-gate 			np = allocb(iphlen + PPP_HDRLEN, BPRI_MED);
15607c478bd9Sstevel@tonic-gate 			if (np == NULL)
15617c478bd9Sstevel@tonic-gate 				goto bad;
15627c478bd9Sstevel@tonic-gate 			dp = np->b_rptr;
15637c478bd9Sstevel@tonic-gate 			/*
15647c478bd9Sstevel@tonic-gate 			 * reconstruct PPP header
15657c478bd9Sstevel@tonic-gate 			 */
15667c478bd9Sstevel@tonic-gate 			dp[0] = PPP_ALLSTATIONS;
15677c478bd9Sstevel@tonic-gate 			dp[1] = PPP_UI;
15687c478bd9Sstevel@tonic-gate 			dp[2] = PPP_IP >> 8;
15697c478bd9Sstevel@tonic-gate 			dp[3] = PPP_IP;
15707c478bd9Sstevel@tonic-gate 			/*
15717c478bd9Sstevel@tonic-gate 			 * prepend mblk with reconstructed TCP/IP header.
15727c478bd9Sstevel@tonic-gate 			 */
15737c478bd9Sstevel@tonic-gate 			bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
15747c478bd9Sstevel@tonic-gate 			np->b_wptr = dp + iphlen + PPP_HDRLEN;
15757c478bd9Sstevel@tonic-gate 			np->b_cont = mp;
15767c478bd9Sstevel@tonic-gate 			mp = np;
15777c478bd9Sstevel@tonic-gate 		} else {
15787c478bd9Sstevel@tonic-gate 			/*
15797c478bd9Sstevel@tonic-gate 			 * "Decompress" a VJ-uncompressed packet.
15807c478bd9Sstevel@tonic-gate 			 */
15817c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->cp_pair_lock);
15827c478bd9Sstevel@tonic-gate 			cp->cp_vj_last_ierrors = cp->cp_stats.ppp_ierrors;
15837c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->cp_pair_lock);
15847c478bd9Sstevel@tonic-gate 			if (!vj_uncompress_uncomp(dp, hlen, &cp->cp_vj)) {
15857c478bd9Sstevel@tonic-gate 				/*
15867c478bd9Sstevel@tonic-gate 				 * don't need to reset next time
15877c478bd9Sstevel@tonic-gate 				 */
15887c478bd9Sstevel@tonic-gate 				mutex_enter(&cp->cp_pair_lock);
15897c478bd9Sstevel@tonic-gate 				++cp->cp_vj_last_ierrors;
15907c478bd9Sstevel@tonic-gate 				mutex_exit(&cp->cp_pair_lock);
15917c478bd9Sstevel@tonic-gate 				goto bad;
15927c478bd9Sstevel@tonic-gate 			}
15937c478bd9Sstevel@tonic-gate 			/*
15947c478bd9Sstevel@tonic-gate 			 * fix up the PPP protocol field
15957c478bd9Sstevel@tonic-gate 			 */
15967c478bd9Sstevel@tonic-gate 			mp->b_rptr[3] = PPP_IP;
15977c478bd9Sstevel@tonic-gate 		}
15987c478bd9Sstevel@tonic-gate 	}
15997c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "recv (%ld bytes) flags=0x%b\n",
16007c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), msgsize(mp),
16017c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
16027c478bd9Sstevel@tonic-gate 	return (mp);
16037c478bd9Sstevel@tonic-gate 
16047c478bd9Sstevel@tonic-gate bad:
16057c478bd9Sstevel@tonic-gate 	if (mp != 0) {
16067c478bd9Sstevel@tonic-gate 		freemsg(mp);
16077c478bd9Sstevel@tonic-gate 	}
16087c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
16097c478bd9Sstevel@tonic-gate 	cp->cp_stats.ppp_ierrors++;
16107c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
16117c478bd9Sstevel@tonic-gate 	(void) putnextctl1(q, M_CTL, PPPCTL_IERROR);
16127c478bd9Sstevel@tonic-gate 	return (NULL);
16137c478bd9Sstevel@tonic-gate }
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate /*
16167c478bd9Sstevel@tonic-gate  * comp_ccp()
16177c478bd9Sstevel@tonic-gate  *
16187c478bd9Sstevel@tonic-gate  * Description:
16197c478bd9Sstevel@tonic-gate  *    Called by spppcomp_outpkt and spppcomp_inpkt to handle a CCP
16207c478bd9Sstevel@tonic-gate  *    negotiation packet being sent or received.  Here all the data in
16217c478bd9Sstevel@tonic-gate  *    the packet is in a single mbuf.
16227c478bd9Sstevel@tonic-gate  *
16237c478bd9Sstevel@tonic-gate  *	Global state is updated.  Must be called with mutex held.
16247c478bd9Sstevel@tonic-gate  */
16257c478bd9Sstevel@tonic-gate /* ARGSUSED */
16267c478bd9Sstevel@tonic-gate static void
16277c478bd9Sstevel@tonic-gate comp_ccp(queue_t *q, mblk_t *mp, sppp_comp_t *cp, boolean_t rcvd)
16287c478bd9Sstevel@tonic-gate {
16297c478bd9Sstevel@tonic-gate 	int	len;
16307c478bd9Sstevel@tonic-gate 	int	clen;
16317c478bd9Sstevel@tonic-gate 	uchar_t	*dp;
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 	len = msgsize(mp);
16347c478bd9Sstevel@tonic-gate 	if (len < PPP_HDRLEN + CCP_HDRLEN) {
16357c478bd9Sstevel@tonic-gate 		return;
16367c478bd9Sstevel@tonic-gate 	}
16377c478bd9Sstevel@tonic-gate 	dp = mp->b_rptr + PPP_HDRLEN;
16387c478bd9Sstevel@tonic-gate 
16397c478bd9Sstevel@tonic-gate 	len -= PPP_HDRLEN;
16407c478bd9Sstevel@tonic-gate 	clen = CCP_LENGTH(dp);
16417c478bd9Sstevel@tonic-gate 	if (clen > len) {
16427c478bd9Sstevel@tonic-gate 		return;
16437c478bd9Sstevel@tonic-gate 	}
16447c478bd9Sstevel@tonic-gate 
16457c478bd9Sstevel@tonic-gate 	CPDEBUG((DBGSTART "CCP code=%d flags=0x%b\n",
16467c478bd9Sstevel@tonic-gate 	    (IS_CP_HASUNIT(cp) ? cp->cp_unit : -1), CCP_CODE(dp),
16477c478bd9Sstevel@tonic-gate 	    cp->cp_flags, CP_FLAGSSTR));
16487c478bd9Sstevel@tonic-gate 	switch (CCP_CODE(dp)) {
16497c478bd9Sstevel@tonic-gate 	case CCP_CONFREQ:
16507c478bd9Sstevel@tonic-gate 	case CCP_TERMREQ:
16517c478bd9Sstevel@tonic-gate 	case CCP_TERMACK:
16527c478bd9Sstevel@tonic-gate 		cp->cp_flags &= ~CCP_ISUP;
16537c478bd9Sstevel@tonic-gate 		break;
16547c478bd9Sstevel@tonic-gate 	case CCP_CONFACK:
16557c478bd9Sstevel@tonic-gate 		if ((cp->cp_flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN &&
1656002c70ffScarlsonj 		    clen >= CCP_HDRLEN + CCP_OPT_MINLEN &&
1657002c70ffScarlsonj 		    clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
16587c478bd9Sstevel@tonic-gate 
16597c478bd9Sstevel@tonic-gate 			int	rc;
16607c478bd9Sstevel@tonic-gate 
16617c478bd9Sstevel@tonic-gate 			if (!rcvd) {
16627c478bd9Sstevel@tonic-gate 				rc = (*cp->cp_xcomp->comp_init)(cp->cp_xstate,
16637c478bd9Sstevel@tonic-gate 				    dp + CCP_HDRLEN, clen - CCP_HDRLEN,
16647c478bd9Sstevel@tonic-gate 				    cp->cp_unit, 0,
16657c478bd9Sstevel@tonic-gate 				    IS_CP_KDEBUG(cp) | ALG_DEBUG);
16667c478bd9Sstevel@tonic-gate 
16677c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate != NULL && rc != 0) {
16687c478bd9Sstevel@tonic-gate 					cp->cp_flags |= CCP_COMP_RUN;
16697c478bd9Sstevel@tonic-gate 				}
16707c478bd9Sstevel@tonic-gate 			} else {
16717c478bd9Sstevel@tonic-gate 				rc = (*cp->cp_rcomp->decomp_init)(cp->
16727c478bd9Sstevel@tonic-gate 				    cp_rstate, dp + CCP_HDRLEN,
16737c478bd9Sstevel@tonic-gate 				    clen - CCP_HDRLEN, cp->cp_unit, 0,
16747c478bd9Sstevel@tonic-gate 				    cp->cp_mru,
16757c478bd9Sstevel@tonic-gate 				    IS_CP_KDEBUG(cp) | ALG_DEBUG);
16767c478bd9Sstevel@tonic-gate 
16777c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate != NULL && rc != 0) {
16787c478bd9Sstevel@tonic-gate 					cp->cp_flags &= ~CCP_ERR;
16797c478bd9Sstevel@tonic-gate 					cp->cp_flags |= CCP_DECOMP_RUN;
16807c478bd9Sstevel@tonic-gate 				}
16817c478bd9Sstevel@tonic-gate 			}
16827c478bd9Sstevel@tonic-gate 		}
16837c478bd9Sstevel@tonic-gate 		break;
16847c478bd9Sstevel@tonic-gate 	case CCP_RESETACK:
16857c478bd9Sstevel@tonic-gate 		if (IS_CCP_ISUP(cp)) {
16867c478bd9Sstevel@tonic-gate 			if (!rcvd) {
16877c478bd9Sstevel@tonic-gate 				if (cp->cp_xstate != NULL &&
16887c478bd9Sstevel@tonic-gate 				    IS_CCP_COMP_RUN(cp)) {
16897c478bd9Sstevel@tonic-gate 					(*cp->cp_xcomp->comp_reset)(cp->
16907c478bd9Sstevel@tonic-gate 					    cp_xstate);
16917c478bd9Sstevel@tonic-gate 				}
16927c478bd9Sstevel@tonic-gate 			} else {
16937c478bd9Sstevel@tonic-gate 				if (cp->cp_rstate != NULL &&
16947c478bd9Sstevel@tonic-gate 				    IS_CCP_DECOMP_RUN(cp)) {
16957c478bd9Sstevel@tonic-gate 					(*cp->cp_rcomp->decomp_reset)(cp->
16967c478bd9Sstevel@tonic-gate 					    cp_rstate);
16977c478bd9Sstevel@tonic-gate 					cp->cp_flags &= ~CCP_ERROR;
16987c478bd9Sstevel@tonic-gate 				}
16997c478bd9Sstevel@tonic-gate 			}
17007c478bd9Sstevel@tonic-gate 		}
17017c478bd9Sstevel@tonic-gate 		break;
17027c478bd9Sstevel@tonic-gate 	}
17037c478bd9Sstevel@tonic-gate }
17047c478bd9Sstevel@tonic-gate 
17057c478bd9Sstevel@tonic-gate /*
17067c478bd9Sstevel@tonic-gate  * spppcomp_kstat_update()
17077c478bd9Sstevel@tonic-gate  *
17087c478bd9Sstevel@tonic-gate  * Description:
17097c478bd9Sstevel@tonic-gate  *    Update per-unit kstat statistics.
17107c478bd9Sstevel@tonic-gate  */
17117c478bd9Sstevel@tonic-gate static int
17127c478bd9Sstevel@tonic-gate spppcomp_kstat_update(kstat_t *ksp, int rw)
17137c478bd9Sstevel@tonic-gate {
1714f53eecf5SJames Carlson 	sppp_comp_t		*cp = ksp->ks_private;
1715f53eecf5SJames Carlson 	spppcomp_kstats_t	*cpkp;
1716f53eecf5SJames Carlson 	struct vjstat		*sp;
1717f53eecf5SJames Carlson 	struct pppstat64	*psp;
17187c478bd9Sstevel@tonic-gate 	struct ppp_comp_stats		csp;
17197c478bd9Sstevel@tonic-gate 
17207c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE) {
17217c478bd9Sstevel@tonic-gate 		return (EACCES);
17227c478bd9Sstevel@tonic-gate 	}
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate 	cpkp = (spppcomp_kstats_t *)ksp->ks_data;
17257c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&csp, sizeof (struct ppp_comp_stats));
17267c478bd9Sstevel@tonic-gate 
17277c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->cp_pair_lock);
17287c478bd9Sstevel@tonic-gate 
17297c478bd9Sstevel@tonic-gate 	if (cp->cp_xstate != NULL) {
17307c478bd9Sstevel@tonic-gate 		(*cp->cp_xcomp->comp_stat)(cp->cp_xstate, &csp.c);
17317c478bd9Sstevel@tonic-gate 	}
17327c478bd9Sstevel@tonic-gate 	if (cp->cp_rstate != NULL) {
17337c478bd9Sstevel@tonic-gate 		(*cp->cp_rcomp->decomp_stat)(cp->cp_rstate, &csp.d);
17347c478bd9Sstevel@tonic-gate 	}
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate 	sp = &cp->cp_vj.stats;
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	cpkp->vj_out_pkts.value.ui32		= sp->vjs_packets;
17397c478bd9Sstevel@tonic-gate 	cpkp->vj_out_pkts_comp.value.ui32	= sp->vjs_compressed;
17407c478bd9Sstevel@tonic-gate 	cpkp->vj_cs_searches.value.ui32		= sp->vjs_searches;
17417c478bd9Sstevel@tonic-gate 	cpkp->vj_cs_misses.value.ui32		= sp->vjs_misses;
17427c478bd9Sstevel@tonic-gate 	cpkp->vj_in_pkts_uncomp.value.ui32	= sp->vjs_uncompressedin;
17437c478bd9Sstevel@tonic-gate 	cpkp->vj_in_pkts_comp.value.ui32	= sp->vjs_compressedin;
17447c478bd9Sstevel@tonic-gate 	cpkp->vj_in_error.value.ui32		= sp->vjs_errorin;
17457c478bd9Sstevel@tonic-gate 	cpkp->vj_in_tossed.value.ui32		= sp->vjs_tossed;
17467c478bd9Sstevel@tonic-gate 
17477c478bd9Sstevel@tonic-gate 	psp = &cp->cp_stats;
17487c478bd9Sstevel@tonic-gate 
17497c478bd9Sstevel@tonic-gate 	cpkp->out_bytes.value.ui64		= psp->ppp_obytes;
17507c478bd9Sstevel@tonic-gate 	cpkp->out_pkts.value.ui64		= psp->ppp_opackets;
17517c478bd9Sstevel@tonic-gate 	cpkp->out_errors.value.ui64		= psp->ppp_oerrors;
17527c478bd9Sstevel@tonic-gate 	cpkp->out_errors_low.value.ui32		= cp->cp_oerr_low;
17537c478bd9Sstevel@tonic-gate 	cpkp->out_uncomp_bytes.value.ui32	= csp.c.unc_bytes;
17547c478bd9Sstevel@tonic-gate 	cpkp->out_uncomp_pkts.value.ui32	= csp.c.unc_packets;
17557c478bd9Sstevel@tonic-gate 	cpkp->out_comp_bytes.value.ui32		= csp.c.comp_bytes;
17567c478bd9Sstevel@tonic-gate 	cpkp->out_comp_pkts.value.ui32		= csp.c.comp_packets;
17577c478bd9Sstevel@tonic-gate 	cpkp->out_incomp_bytes.value.ui32	= csp.c.inc_bytes;
17587c478bd9Sstevel@tonic-gate 	cpkp->out_incomp_pkts.value.ui32	= csp.c.inc_packets;
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate 	cpkp->in_bytes.value.ui64		= psp->ppp_ibytes;
17617c478bd9Sstevel@tonic-gate 	cpkp->in_pkts.value.ui64		= psp->ppp_ipackets;
17627c478bd9Sstevel@tonic-gate 	cpkp->in_errors.value.ui64		= psp->ppp_ierrors;
17637c478bd9Sstevel@tonic-gate 	cpkp->in_errors_low.value.ui32		= cp->cp_ierr_low;
17647c478bd9Sstevel@tonic-gate 	cpkp->in_uncomp_bytes.value.ui32	= csp.d.unc_bytes;
17657c478bd9Sstevel@tonic-gate 	cpkp->in_uncomp_pkts.value.ui32		= csp.d.unc_packets;
17667c478bd9Sstevel@tonic-gate 	cpkp->in_comp_bytes.value.ui32		= csp.d.comp_bytes;
17677c478bd9Sstevel@tonic-gate 	cpkp->in_comp_pkts.value.ui32		= csp.d.comp_packets;
17687c478bd9Sstevel@tonic-gate 	cpkp->in_incomp_bytes.value.ui32	= csp.d.inc_bytes;
17697c478bd9Sstevel@tonic-gate 	cpkp->in_incomp_pkts.value.ui32		= csp.d.inc_packets;
17707c478bd9Sstevel@tonic-gate #ifdef SPC_DEBUG
17717c478bd9Sstevel@tonic-gate 	cpkp->in_msg_ccp_pulledup.value.ui32	= cp->cp_imsg_ccp_pull;
17727c478bd9Sstevel@tonic-gate 	cpkp->in_msg_vj_pulledup.value.ui32	= cp->cp_imsg_vj_pull;
17737c478bd9Sstevel@tonic-gate 	cpkp->out_msg_pulledup.value.ui32	= cp->cp_omsg_pull;
17747c478bd9Sstevel@tonic-gate 	cpkp->out_msg_copied.value.ui32		= cp->cp_omsg_dcopy;
17757c478bd9Sstevel@tonic-gate 	cpkp->out_queued.value.ui32		= cp->cp_out_queued;
17767c478bd9Sstevel@tonic-gate 	cpkp->out_handled.value.ui32		= cp->cp_out_handled;
17777c478bd9Sstevel@tonic-gate 	cpkp->in_queued.value.ui32		= cp->cp_in_queued;
17787c478bd9Sstevel@tonic-gate 	cpkp->in_handled.value.ui32		= cp->cp_in_handled;
17797c478bd9Sstevel@tonic-gate #endif
17807c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->cp_pair_lock);
17817c478bd9Sstevel@tonic-gate 	return (0);
17827c478bd9Sstevel@tonic-gate }
1783