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