/*
* spppcomp.c - STREAMS module for kernel-level compression and CCP support.
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies.
*
* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* This module is derived from the original SVR4 STREAMS PPP compression
* module originally written by Paul Mackerras <paul.mackerras@cs.anu.edu.au>.
*
* James Carlson <james.d.carlson@sun.com> and Adi Masputra
* <adi.masputra@sun.com> rewrote and restructured the code for improved
* performance and scalability.
*/
#include <sys/sysmacros.h>
#include <net/ppp_defs.h>
#include <net/vjcompress.h>
/* Defined for platform-neutral include file */
#include <net/ppp-comp.h>
#include "s_common.h"
#ifdef DEBUG
#define SPC_DEBUG
#endif
#include "spppcomp.h"
/*
* This is used to tag official Solaris sources. Please do not define
* "INTERNAL_BUILD" when building this software outside of Sun
* Microsystems.
*/
#ifdef INTERNAL_BUILD
/* MODINFO is limited to 32 characters. */
#else /* INTERNAL_BUILD */
const char spppcomp_module_description[] =
"ANU PPP compression $Revision: 1.16$ ";
/* LINTED */
#ifdef DEBUG
" DEBUG"
#endif
"\n";
#endif /* INTERNAL_BUILD */
static void spppcomp_rsrv(queue_t *);
static void spppcomp_wsrv(queue_t *);
#define PPPCOMP_MI_MINPSZ (0)
COMP_MOD_ID, /* mi_idnum */
COMP_MOD_NAME, /* mi_idname */
PPPCOMP_MI_MINPSZ, /* mi_minpsz */
PPPCOMP_MI_MAXPSZ, /* mi_maxpsz */
PPPCOMP_MI_HIWAT, /* mi_hiwat */
PPPCOMP_MI_LOWAT /* mi_lowat */
};
(int (*)())spppcomp_rput, /* qi_putp */
(int (*)())spppcomp_rsrv, /* qi_srvp */
spppcomp_open, /* qi_qopen */
spppcomp_close, /* qi_qclose */
NULL, /* qi_qadmin */
&spppcomp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
(int (*)())spppcomp_wput, /* qi_putp */
(int (*)())spppcomp_wsrv, /* qi_srvp */
NULL, /* qi_qopen */
NULL, /* qi_qclose */
NULL, /* qi_qadmin */
&spppcomp_modinfo, /* qi_minfo */
NULL /* qi_mstat */
};
&spppcomp_rinit, /* st_rdinit */
&spppcomp_winit, /* st_wrinit */
NULL, /* st_muxrinit */
NULL /* st_muxwinit */
};
/* Set non-zero to debug algorithm-specific problems alone. */
#define ALG_DEBUG 0
#if 0
#else
#endif
/*
* List of compressors we know about.
*/
#if DO_BSD_COMPRESS
extern struct compressor ppp_bsd_compress;
#endif
#if DO_DEFLATE
extern struct compressor ppp_deflate;
extern struct compressor ppp_deflate_draft;
#endif
#if DO_BSD_COMPRESS
#endif
#if DO_DEFLATE
#endif
};
/*
* LCP_USE_DFLT() removed by James Carlson. RFC 1661 section 6.6 has
* this to say on the topic:
*
* The Address and Control fields MUST NOT be compressed when sending
* any LCP packet. This rule guarantees unambiguous recognition of
* LCP packets.
*/
static int spppcomp_kstat_update(kstat_t *, int);
/*
* Values for checking inter-arrival times on interrupt stacks. These
* are used to prevent CPU hogging in interrupt context.
*/
static const char *kstats_names[] = {
#ifdef SPCDEBUG_KSTATS_NAMES
#else
#endif
};
/*
* spppcomp_open()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Common open procedure for module.
*/
/* ARGSUSED */
static int
{
return (0);
}
return (EINVAL);
}
qprocson(q);
return (0);
}
/*
* spppcomp_close()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Common close procedure for module.
*/
/* ARGSUSED */
static int
{
qprocsoff(q);
CP_FLAGSSTR));
}
}
}
return (0);
}
/*
* spppcomp_wput()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Write-side put procedure. Packets from above us arrive here.
*
* The data handling logic is a little tricky here. We defer to
* the service routine if q_first isn't NULL (to preserve message
* ordering after deferring a previous message), bcanputnext() is
* FALSE (to handle flow control), or we need a lot of processing
* and we're in an interrupt context (on the theory that we're
* already on a very long call stack at that point). Since many
* callers will be in a non-interrupt context, this means that
* most processing will be performed here in-line, and deferral
* occurs only when necessary.
*/
static void
{
int flag;
case M_DATA:
servicing_interrupt())) {
#ifdef SPC_DEBUG
cp->cp_out_queued++;
#endif
} else {
#ifdef SPC_DEBUG
cp->cp_out_handled++;
#endif
}
break;
case M_IOCTL:
break;
case M_CTL:
if (flag != 0)
else
break;
case M_FLUSH:
/*
* Just discard pending data. For CCP, any compressor
* dictionary sequencing problems caused by this will
* have to be handled by the compression protocol in
* use. For VJ, we need to tell the compressor to
* start over.
*/
}
break;
default:
break;
}
}
/*
* spppcomp_wsrv()
*
* MT-Perimeters:
* exclusive inner
*
* Description:
* Write-side service procedure.
*/
static void
{
/*
* If the module below us is flow-controlled, then put
* this message back on the queue again.
*/
break;
}
}
}
/*
* spppcomp_outpkt()
*
* MT-Perimeters:
* exclusive inner
*
* Description:
* Process outgoing packet. Returns new mblk_t pointer on success
* (caller should do putnext through q), NULL on failure (packet has
* been discarded).
*/
static mblk_t *
{
int len;
/*
* If the entire data size of the mblk is less than the length of the
* PPP header, then free it. We can't do much with such message anyway,
* since we can't determine what the PPP protocol is.
*/
#ifdef SPC_DEBUG
cp->cp_omsg_pull++;
#endif
goto msg_oerror;
}
/*
* Do VJ compression if requested.
*/
IPPROTO_TCP) {
int type;
sizeof (uint32_t)];
void *srcp;
int thislen;
/*
* If we can alter this dblk, and there's enough data
* here to work with, and it's nicely aligned, then
* avoid the data copy.
*/
} else {
while (tocopy > 0) {
} else {
break;
}
}
}
/*
* If we're going to modify this packet, then we can't modify
* someone else's data. Copy instead.
*
* (It would be nice to be able to avoid this data copy if CCP
* is also enabled. That would require extensive
* modifications to the compression code. Users should be
* told to disable VJ compression when using CCP.)
*/
#ifdef SPC_DEBUG
cp->cp_omsg_dcopy++;
#endif
/* Copy just altered portion. */
goto msg_oerror;
}
switch (type) {
case TYPE_UNCOMPRESSED_TCP:
/* No need to update if it was done in place. */
if (srcp ==
thislen = PPP_HDRLEN +
break;
}
}
}
break;
case TYPE_COMPRESSED_TCP:
/* Calculate amount to remove from front */
/* Try to do a cheap adjmsg by arithmetic first. */
goto msg_oerror;
}
}
/*
* Now make sure first block is big enough to
* receive modified data. If we modified in
* place, then no need to check or copy.
*/
if (srcp !=
copied = 0;
goto msg_oerror;
}
*dp++ = 0; /* protocol */
copied -= PPP_HDRLEN;
if (copied > 0) {
}
break;
}
}
/*
* Do packet compression if enabled.
*/
/*
* Handle any negotiation packets by changing compressor
* state. Doing this here rather than with an ioctl keeps
* the negotiation and the data flow in sync.
*/
/* Success! Discard uncompressed version */
}
if (len < 0) {
/*
* Compressor failure; must discard this
* packet because the compressor dictionary is
* now corrupt.
*/
return (NULL);
}
}
/*
* If either address and control field compression or protocol field
* compression is enabled, then we'll need a writable packet. Copy if
* necessary.
*/
#ifdef SPC_DEBUG
cp->cp_omsg_dcopy++;
#endif
goto msg_oerror;
}
/*
*/
/*
* Protocol field compression omits the first byte if
* it would be 0x00, thus the check for < 0x100.
*/
}
/*
* shuffle up the address & ctrl fields
*/
}
return (mp);
return (NULL);
}
/*
* spppcomp_inner_ioctl()
*
* MT-Perimeters:
* exclusive inner; queue pair lock held.
*
* Description:
* Called by spppcomp_ioctl to handle state-affecting ioctls.
* Returns -1 if caller should do putnext, 0 for miocack, or >0
* for miocnak. Must *NOT* do putnext in this routine, since
* lock is held here.
*/
static int
{
int flags;
int mask;
int rc;
int len;
int cmd;
int nxslots;
int nrslots;
int val;
void *xtemp;
len = 0;
case PPPIO_CFLAGS:
break;
}
}
}
"PPPIO_CFLAGS xflags=0x%b xmask=0x%b flags=0x%b\n",
/* If we're not the last PPP-speaker, then pass along. */
if (!IS_CP_LASTMOD(cp)) {
return (-1); /* putnext */
}
rc = 0;
break;
case PPPIO_VJINIT:
break;
/*
* Even though it's not passed along, we have to
* validate nrslots so that we don't agree to
* decompress anything we cannot.
*/
break;
/* No need to lock here; just reading a word is atomic */
/* mutex_enter(&cp->cp_pair_lock); */
/* mutex_exit(&cp->cp_pair_lock); */
"PPPIO_VJINIT txslots=%d rxslots=%d flags=0x%b\n",
rc = 0;
break;
case PPPIO_XCOMP:
case PPPIO_RCOMP:
break;
/*
* The input data here is the raw CCP algorithm option
* from negotiation. The format is always one byte of
* algorithm number, one byte of length, and
* (length-2) bytes of algorithm-dependent data. The
* alloc routine is expected to parse and validate
* this.
*/
}
break;
len = 0;
continue;
}
rc = 0;
/*
* A previous call may have fetched
* memory for a compressor that's now
* being retired or reset. Free it
* using its mechanism for freeing
* stuff.
*/
}
opt_len);
}
"opt_len=0x%d flags=0x%b\n",
CP_FLAGSSTR));
} else {
}
}
"opt_len=0x%d flags=0x%b\n",
CP_FLAGSSTR));
}
if (rc != 0) {
"cannot set effort %d",
rc = 0;
}
}
break;
}
break;
case PPPIO_DEBUG:
break;
/* If it's not for us, then pass along. */
return (-1); /* putnext */
}
rc = 0;
break;
case PPPIO_LASTMOD:
rc = 0;
break;
case PPPIO_COMPLEV: /* set compression effort level */
break;
/* Silently ignore if compressor doesn't understand this. */
rc = 0;
if (rc != 0)
break;
}
break;
}
return (rc);
}
/*
* spppcomp_getcstat()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Called by spppcomp_ioctl as the result of receiving a PPPIO_GETCSTAT.
*/
static void
{
return;
}
}
}
}
}
/*
* spppcomp_ioctl()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Called by spppcomp_wput as the result of receiving an M_IOCTL
* command.
*/
static void
{
int flag;
case PPPIO_CFLAGS:
case PPPIO_VJINIT:
case PPPIO_XCOMP:
case PPPIO_RCOMP:
case PPPIO_DEBUG:
case PPPIO_LASTMOD:
case PPPIO_COMPLEV:
if (flag == -1) {
} else if (flag == 0) {
} else {
}
break;
case PPPIO_GETCSTAT:
break;
case PPPIO_GTYPE: /* get existing driver type */
if (!IS_CP_LASTMOD(cp)) {
break;
}
} else {
}
break;
default:
break;
}
}
/*
* spppcomp_mctl()
*
* MT-Perimeters:
* exclusive inner; queue pair lock held.
*
* Description:
* Called by spppcomp_wput as the result of receiving an M_CTL
* message from another STREAMS module, and returns non-zero if
* caller should do putnext or zero for freemsg. Must *NOT* do
* putnext in this routine, since lock is held here.
*/
static int
{
const char **cpp;
case PPPCTL_MTU:
break;
}
break;
case PPPCTL_MRU:
break;
}
break;
case PPPCTL_UNIT:
break;
}
/* If PPPCTL_UNIT has already been issued, then ignore. */
if (IS_CP_HASUNIT(cp)) {
break;
}
/* Create kstats for this unit. */
KSTAT_TYPE_NAMED, sizeof (spppcomp_kstats_t) /
sizeof (kstat_named_t), 0);
for (cpp = kstats_names;
knt++;
}
for (cpp = kstats64_names;
knt++;
}
}
break;
default:
/* Forward unknown M_CTL messages along */
return (1);
}
/*
* For known PPP M_CTL messages, forward along only if we're not the
* last PPP-aware module.
*/
if (IS_CP_LASTMOD(cp))
return (0);
return (1);
}
/*
* spppcomp_rput()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Upper read-side put procedure. Messages get here from below.
*
* The data handling logic is a little more tricky here. We
* defer to the service routine if q_first isn't NULL (to
* preserve message ordering after deferring a previous message),
* bcanputnext() is FALSE (to handle flow control), or we have
* done a lot of processing recently and we're about to do a lot
* more and we're in an interrupt context (on the theory that
* we're hogging the CPU in this case).
*/
static void
{
case M_DATA:
inter = servicing_interrupt();
if (inter) {
/*
* If little time has passed since last
* arrival, then bump the counter.
*/
else
}
/*
* If we're not decompressing, then we'll be fast, so
* we don't have to worry about hogging here. If we
* are decompressing, then we have to check the
* cp_fastin count.
*/
#ifdef SPC_DEBUG
cp->cp_in_handled++;
#endif
if (inter) {
}
} else {
/* Deferring; give him a clean slate */
#ifdef SPC_DEBUG
cp->cp_in_queued++;
#endif
}
break;
case M_IOCACK:
/*
* Bundled with pppstats; no need to handle PPPIO_GETSTAT
* here since we'll never see it.
*/
/*
* This crock is to handle a badly-designed
* but well-known ioctl for ANU PPP. Both
* link statistics and VJ statistics are
* requested together.
*
* Catch this on the way back from the
* spppasyn module so we can fill in the VJ
* stats. This happens only when we have
* PPP-aware modules beneath us.
*/
"PPPIO_GETSTAT64 (VJ filled) flags=0x%b\n",
}
break;
case M_CTL:
/* Increase our statistics and forward it upstream. */
cp->cp_ierr_low++;
cp->cp_oerr_low++;
}
break;
case M_FLUSH:
/*
* Just discard pending data. For CCP, any
* decompressor dictionary sequencing problems caused
* by this will have to be handled by the compression
* protocol in use. For VJ, we need to give the
* decompressor a heads-up.
*/
}
break;
default:
break;
}
}
/*
* spppcomp_rsrv()
*
* MT-Perimeters:
* exclusive inner.
*
* Description:
* Upper read-side service procedure. We handle data deferred from
* spppcomp_rput here.
*
* The data on the queue are always compressed (unprocessed).
* The rput procedure tries to do decompression, but if it can't,
* it will put the unprocessed data on the queue for later
* handling.
*/
static void
{
/*
* If the module above us is flow-controlled, then put
* this message back on the queue again.
*/
break;
}
}
}
/*
* spppcomp_inpkt()
*
* MT-Perimeters:
* exclusive inner
*
* Description:
* Process incoming packet.
*/
static mblk_t *
{
int i;
int len;
int hlen;
/*
* First work out the protocol and where the PPP header ends.
*/
i = 0;
if (proto == PPP_ALLSTATIONS) {
i = 2;
}
if ((proto & 1) == 0) {
++i;
}
hlen = i + 1;
/*
* Now reconstruct a complete, contiguous PPP header at the
* start of the packet.
*/
/* count these? */
goto bad;
}
/*
* Header is known to be intact here; so adjmsg will do the
* right thing here.
*/
goto bad;
}
hlen = 0;
}
if (hlen != PPP_HDRLEN) {
/*
* We need to put some bytes on the front of the packet
* to make a full-length PPP header. If we can put them
* in mp, we do, otherwise we tack another mblk on the
* front.
*
* XXX we really shouldn't need to carry around the address
* and control at this stage. ACFC and PFC need to be
* reworked.
*/
if (np == 0) {
goto bad;
}
} else {
}
dp[0] = PPP_ALLSTATIONS;
}
/*
* Now see if we have a compressed packet to decompress, or a
* CCP negotiation packet to take notice of. It's guaranteed
* that at least PPP_HDRLEN bytes are contiguous in the first
* block now.
*/
#ifdef SPC_DEBUG
cp->cp_imsg_ccp_pull++;
#endif
if (mp == 0) {
goto bad;
}
}
int rv;
switch (rv) {
case DECOMP_OK:
break;
case DECOMP_ERROR:
break;
case DECOMP_FATALERROR:
break;
}
/* Decompress failed; data are gone. */
return (NULL);
}
} else {
/*
* For RFCs 1977 and 1979 (BSD Compress and Deflate),
* the compressor should send incompressible data
* without encapsulation and the receiver must update
* its decompression dictionary as though this data
* were received and decompressed. This keeps the
* dictionaries in sync.
*/
if (rv < 0) {
}
}
}
/*
* Now do VJ decompression.
*/
goto bad;
}
/*
* Advance past the ppp header. Here we assume that the whole
* PPP header is in the first mblk. (This should be true
* because the above code does pull-ups as necessary on raw
* data, and the decompressor engines all produce large blocks
* on output.)
*/
}
/*
* Make sure we have sufficient contiguous data at this point,
* which in most cases we will always do.
*/
}
#ifdef SPC_DEBUG
cp->cp_imsg_vj_pull++;
#endif
goto bad;
}
}
if (proto == PPP_VJC_COMP) {
int vjlen;
int errcnt;
/*
* Decompress VJ-compressed packet. First
* reset compressor if an input error has
* occurred. (No need to lock statistics
* structure for read of a single word.)
*/
}
/*
* so we don't reset next time
*/
++cp->cp_vj_last_ierrors;
goto bad;
}
/*
* drop ppp and vj headers off
*/
}
/*
* allocate a new mblk for the ppp and
* ip headers
*/
goto bad;
/*
* reconstruct PPP header
*/
dp[0] = PPP_ALLSTATIONS;
/*
*/
} else {
/*
* "Decompress" a VJ-uncompressed packet.
*/
/*
* don't need to reset next time
*/
++cp->cp_vj_last_ierrors;
goto bad;
}
/*
* fix up the PPP protocol field
*/
}
}
return (mp);
bad:
if (mp != 0) {
}
return (NULL);
}
/*
* comp_ccp()
*
* Description:
* Called by spppcomp_outpkt and spppcomp_inpkt to handle a CCP
* negotiation packet being sent or received. Here all the data in
* the packet is in a single mbuf.
*
* Global state is updated. Must be called with mutex held.
*/
/* ARGSUSED */
static void
{
int len;
int clen;
return;
}
len -= PPP_HDRLEN;
return;
}
case CCP_CONFREQ:
case CCP_TERMREQ:
case CCP_TERMACK:
break;
case CCP_CONFACK:
int rc;
if (!rcvd) {
}
} else {
}
}
}
break;
case CCP_RESETACK:
if (IS_CCP_ISUP(cp)) {
if (!rcvd) {
IS_CCP_COMP_RUN(cp)) {
}
} else {
IS_CCP_DECOMP_RUN(cp)) {
}
}
}
break;
}
}
/*
* spppcomp_kstat_update()
*
* Description:
* Update per-unit kstat statistics.
*/
static int
{
if (rw == KSTAT_WRITE) {
return (EACCES);
}
}
}
#ifdef SPC_DEBUG
#endif
return (0);
}