2 * ppp_comp.c - STREAMS module for kernel-level compression and CCP support.
4 * Copyright (c) 1994 The Australian National University.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation is hereby granted, provided that the above copyright
9 * notice appears in all copies. This software is provided without any
10 * warranty, express or implied. The Australian National University
11 * makes no representations about the suitability of this software for
14 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
15 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
17 * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
20 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
24 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27 * $Id: ppp_comp.c,v 1.8 1997/04/30 05:45:15 paulus Exp $
31 * This file is used under SVR4, Solaris 2, SunOS 4, and Digital UNIX.
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/errno.h>
37 #include <sys/stream.h>
41 #include <sys/cmn_err.h>
46 #include <sys/cmn_err.h>
50 #include <net/ppp_defs.h>
51 #include <net/pppio.h>
56 #include <sys/protosw.h>
59 #include <netinet/in.h>
60 #include <netinet/in_systm.h>
61 #include <netinet/ip.h>
62 #include <net/vjcompress.h>
64 #define PACKETPTR mblk_t *
65 #include <net/ppp-comp.h>
67 MOD_OPEN_DECL(ppp_comp_open);
68 MOD_CLOSE_DECL(ppp_comp_close);
69 static int ppp_comp_rput __P((queue_t *, mblk_t *));
70 static int ppp_comp_rsrv __P((queue_t *));
71 static int ppp_comp_wput __P((queue_t *, mblk_t *));
72 static int ppp_comp_wsrv __P((queue_t *));
73 static void ppp_comp_ccp __P((queue_t *, mblk_t *, int));
74 static int msg_byte __P((mblk_t *, unsigned int));
76 /* Extract byte i of message mp. */
77 #define MSG_BYTE(mp, i) ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
80 /* Is this LCP packet one we have to transmit using LCP defaults? */
81 #define LCP_USE_DFLT(mp) (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
83 #define PPP_COMP_ID 0xbadf
84 static struct module_info minfo = {
86 PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16512, 16384,
88 PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16384, 4096,
92 static struct qinit r_init = {
93 ppp_comp_rput, ppp_comp_rsrv, ppp_comp_open, ppp_comp_close,
97 static struct qinit w_init = {
98 ppp_comp_wput, ppp_comp_wsrv, NULL, NULL, NULL, &minfo, NULL
101 #if defined(SVR4) && !defined(SOL2)
103 #define ppp_compinfo pcmpinfo
105 struct streamtab ppp_compinfo = {
106 &r_init, &w_init, NULL, NULL
109 int ppp_comp_count; /* number of module instances in use */
113 static void ppp_comp_alloc __P((comp_state_t *));
114 typedef struct memreq {
115 unsigned char comp_opts[20];
123 typedef struct comp_state {
128 struct compressor *xcomp;
130 struct compressor *rcomp;
132 struct vjcompress vj_comp;
134 struct pppstat stats;
143 extern task_t first_task;
146 /* Bits in flags are as defined in pppio.h. */
147 #define CCP_ERR (CCP_ERROR | CCP_FATALERROR)
148 #define LAST_MOD 0x1000000 /* no ppp modules below us */
149 #define DBGLOG 0x2000000 /* log debugging stuff */
151 #define MAX_IPHDR 128 /* max TCP/IP header size */
152 #define MAX_VJHDR 20 /* max VJ compressed header size (?) */
154 #undef MIN /* just in case */
155 #define MIN(a, b) ((a) < (b)? (a): (b))
158 * List of compressors we know about.
162 extern struct compressor ppp_bsd_compress;
165 extern struct compressor ppp_deflate;
168 struct compressor *ppp_compressors[] = {
179 * STREAMS module entry points.
181 MOD_OPEN(ppp_comp_open)
188 if (q->q_ptr == NULL) {
189 cp = (comp_state_t *) ALLOC_SLEEP(sizeof(comp_state_t));
192 WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
193 bzero((caddr_t)cp, sizeof(comp_state_t));
198 vj_compress_init(&cp->vj_comp, -1);
202 if (!(thread = kernel_thread_w_arg(first_task, ppp_comp_alloc, (void *)cp)))
210 MOD_CLOSE(ppp_comp_close)
215 cp = (comp_state_t *) q->q_ptr;
217 if (cp->xstate != NULL)
218 (*cp->xcomp->comp_free)(cp->xstate);
219 if (cp->rstate != NULL)
220 (*cp->rcomp->decomp_free)(cp->rstate);
223 printf("ppp_comp_close: NULL thread!\n");
225 thread_terminate(cp->thread);
227 FREE(cp, sizeof(comp_state_t));
229 OTHERQ(q)->q_ptr = NULL;
237 /* thread for calling back to a compressor's memory allocator
238 * Needed for Digital UNIX since it's VM can't handle requests
239 * for large amounts of memory without blocking. The thread
240 * provides a context in which we can call a memory allocator
244 ppp_comp_alloc(comp_state_t *cp)
247 unsigned char *compressor_options;
249 void *(*comp_allocator)();
252 #if defined(MAJOR_VERSION) && (MAJOR_VERSION <= 2)
254 /* In 2.x and earlier the argument gets passed
255 * in the thread structure itself. Yuck.
257 thread = current_thread();
258 cp = thread->reply_port;
259 thread->reply_port = PORT_NULL;
264 assert_wait((vm_offset_t)&cp->memreq.thread_status, TRUE);
267 if (thread_should_halt(current_thread()))
269 cmd = cp->memreq.cmd;
270 compressor_options = &cp->memreq.comp_opts[0];
271 len = compressor_options[1];
272 if (cmd == PPPIO_XCOMP) {
273 cp->memreq.returned_mem = cp->xcomp->comp_alloc(compressor_options, len);
274 if (!cp->memreq.returned_mem) {
275 cp->memreq.thread_status = ENOSR;
277 cp->memreq.thread_status = 0;
280 cp->memreq.returned_mem = cp->rcomp->decomp_alloc(compressor_options, len);
281 if (!cp->memreq.returned_mem) {
282 cp->memreq.thread_status = ENOSR;
284 cp->memreq.thread_status = 0;
292 /* here's the deal with memory allocation under Digital UNIX.
293 * Some other may also benefit from this...
294 * We can't ask for huge chunks of memory in a context where
295 * the caller can't be put to sleep (like, here.) The alloc
296 * is likely to fail. Instead we do this: the first time we
297 * get called, kick off a thread to do the allocation. Return
298 * immediately to the caller with EAGAIN, as an indication that
299 * they should send down the ioctl again. By the time the
300 * second call comes in it's likely that the memory allocation
301 * thread will have returned with the requested memory. We will
302 * continue to return EAGAIN however until the thread has completed.
303 * When it has, we return zero (and the memory) if the allocator
304 * was successful and ENOSR otherwise.
306 * Callers of the RCOMP and XCOMP ioctls are encouraged (but not
307 * required) to loop for some number of iterations with a small
308 * delay in the loop body (for instance a 1/10-th second "sleep"
321 struct compressor **comp;
322 struct ppp_stats *psp;
323 struct ppp_comp_stats *csp;
324 unsigned char *opt_data;
325 int nxslots, nrslots;
327 cp = (comp_state_t *) q->q_ptr;
328 switch (mp->b_datap->db_type) {
335 iop = (struct iocblk *) mp->b_rptr;
337 switch (iop->ioc_cmd) {
340 /* set/get CCP state */
341 if (iop->ioc_count != 2 * sizeof(int))
343 flags = ((int *) mp->b_cont->b_rptr)[0];
344 mask = ((int *) mp->b_cont->b_rptr)[1];
345 cp->flags = (cp->flags & ~mask) | (flags & mask);
346 if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
347 if (cp->xstate != NULL) {
348 (*cp->xcomp->comp_free)(cp->xstate);
351 if (cp->rstate != NULL) {
352 (*cp->rcomp->decomp_free)(cp->rstate);
355 cp->flags &= ~CCP_ISUP;
358 iop->ioc_count = sizeof(int);
359 ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
360 mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
365 * Initialize VJ compressor/decompressor
367 if (iop->ioc_count != 2)
369 nxslots = mp->b_cont->b_rptr[0] + 1;
370 nrslots = mp->b_cont->b_rptr[1] + 1;
371 if (nxslots > MAX_STATES || nrslots > MAX_STATES)
373 vj_compress_init(&cp->vj_comp, nxslots);
374 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
381 if (iop->ioc_count <= 0)
383 opt_data = mp->b_cont->b_rptr;
384 len = mp->b_cont->b_wptr - opt_data;
385 if (len > iop->ioc_count)
386 len = iop->ioc_count;
387 if (opt_data[1] < 2 || opt_data[1] > len)
389 for (comp = ppp_compressors; *comp != NULL; ++comp)
390 if ((*comp)->compress_proto == opt_data[0]) {
391 /* here's the handler! */
394 if (iop->ioc_cmd == PPPIO_XCOMP) {
395 /* A previous call may have fetched memory for a compressor
396 * that's now being retired or reset. Free it using it's
397 * mechanism for freeing stuff.
399 if (cp->xstate != NULL) {
400 (*cp->xcomp->comp_free)(cp->xstate);
404 cp->xstate = (*comp)->comp_alloc(opt_data, len);
405 if (cp->xstate == NULL)
408 if (cp->rstate != NULL) {
409 (*cp->rcomp->decomp_free)(cp->rstate);
413 cp->rstate = (*comp)->decomp_alloc(opt_data, len);
414 if (cp->rstate == NULL)
418 if ((error = cp->memreq.thread_status) != EAGAIN)
419 if (iop->ioc_cmd == PPPIO_XCOMP) {
421 (*cp->xcomp->comp_free)(cp->xstate);
424 /* sanity check for compressor options
426 if (sizeof (cp->memreq.comp_opts) < len) {
427 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
429 cp->memreq.thread_status = ENOSR;
430 cp->memreq.returned_mem = 0;
432 /* fill in request for the thread and kick it off
434 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
435 bcopy(opt_data, cp->memreq.comp_opts, len);
436 cp->memreq.cmd = PPPIO_XCOMP;
438 error = cp->memreq.thread_status = EAGAIN;
439 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
441 cp->xstate = cp->memreq.returned_mem;
442 cp->memreq.returned_mem = 0;
443 cp->memreq.thread_status = 0;
447 (*cp->rcomp->decomp_free)(cp->rstate);
450 if (sizeof (cp->memreq.comp_opts) < len) {
451 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
453 cp->memreq.thread_status = ENOSR;
454 cp->memreq.returned_mem = 0;
456 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
457 bcopy(opt_data, cp->memreq.comp_opts, len);
458 cp->memreq.cmd = PPPIO_RCOMP;
460 error = cp->memreq.thread_status = EAGAIN;
461 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
463 cp->rstate = cp->memreq.returned_mem;
464 cp->memreq.returned_mem = 0;
465 cp->memreq.thread_status = 0;
475 if ((cp->flags & LAST_MOD) == 0) {
476 error = -1; /* let the ppp_ahdl module handle it */
479 np = allocb(sizeof(struct ppp_stats), BPRI_HI);
487 psp = (struct ppp_stats *) np->b_wptr;
488 np->b_wptr += sizeof(struct ppp_stats);
489 iop->ioc_count = sizeof(struct ppp_stats);
491 psp->vj = cp->vj_comp.stats;
496 np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
504 csp = (struct ppp_comp_stats *) np->b_wptr;
505 np->b_wptr += sizeof(struct ppp_comp_stats);
506 iop->ioc_count = sizeof(struct ppp_comp_stats);
507 bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
509 (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
511 (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
516 if (iop->ioc_count != sizeof(int))
518 n = *(int *)mp->b_cont->b_rptr;
519 if (n == PPPDBG_LOG + PPPDBG_COMP) {
520 DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
530 cp->flags |= LAST_MOD;
541 else if (error == 0) {
542 mp->b_datap->db_type = M_IOCACK;
545 mp->b_datap->db_type = M_IOCNAK;
546 iop->ioc_error = error;
553 switch (*mp->b_rptr) {
555 cp->mtu = ((unsigned short *)mp->b_rptr)[1];
558 cp->mru = ((unsigned short *)mp->b_rptr)[1];
561 cp->unit = mp->b_rptr[1];
576 mblk_t *mp, *cmp = NULL, *np;
578 int len, proto, type, hlen, code;
580 unsigned char *vjhdr, *dp;
582 cp = (comp_state_t *) q->q_ptr;
583 while ((mp = getq(q)) != 0) {
584 /* assert(mp->b_datap->db_type == M_DATA) */
586 if (!bcanputnext(q,mp->b_band)) {
588 if (!canputnext(q)) {
595 * First check the packet length and work out what the protocol is.
598 if (len < PPP_HDRLEN) {
599 DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
601 cp->stats.ppp_oerrors++;
602 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
605 proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
608 * Make sure we've got enough data in the first mblk
609 * and that we are its only user.
611 if (proto == PPP_CCP)
613 else if (proto == PPP_IP)
614 hlen = PPP_HDRLEN + MAX_IPHDR;
619 if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
622 DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
623 cp->stats.ppp_oerrors++;
624 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
630 * Do VJ compression if requested.
632 if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
633 ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
634 if (ip->ip_p == IPPROTO_TCP) {
635 type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
636 (cp->flags & COMP_VJCCID), &vjhdr);
638 case TYPE_UNCOMPRESSED_TCP:
639 mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
641 case TYPE_COMPRESSED_TCP:
642 dp = vjhdr - PPP_HDRLEN;
643 dp[1] = mp->b_rptr[1]; /* copy control field */
644 dp[0] = mp->b_rptr[0]; /* copy address field */
645 dp[2] = 0; /* set protocol field */
646 dp[3] = proto = PPP_VJC_COMP;
654 * Do packet compression if enabled.
656 if (proto == PPP_CCP)
657 ppp_comp_ccp(q, mp, 0);
658 else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
659 && cp->xstate != NULL) {
661 (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
662 (cp->flags & CCP_ISUP? cp->mtu: 0));
665 cmp->b_band=mp->b_band;
673 * Do address/control and protocol compression if enabled.
675 if ((cp->flags & COMP_AC)
676 && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
677 mp->b_rptr += 2; /* drop the address & ctrl fields */
678 if (proto < 0x100 && (cp->flags & COMP_PROT))
679 ++mp->b_rptr; /* drop the high protocol byte */
680 } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
681 /* shuffle up the address & ctrl fields */
682 mp->b_rptr[2] = mp->b_rptr[1];
683 mp->b_rptr[1] = mp->b_rptr[0];
687 cp->stats.ppp_opackets++;
688 cp->stats.ppp_obytes += msgdsize(mp);
700 struct ppp_stats *psp;
702 cp = (comp_state_t *) q->q_ptr;
703 switch (mp->b_datap->db_type) {
710 iop = (struct iocblk *) mp->b_rptr;
711 switch (iop->ioc_cmd) {
714 * Catch this on the way back from the ppp_ahdl module
715 * so we can fill in the VJ stats.
717 if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
719 psp = (struct ppp_stats *) mp->b_cont->b_rptr;
720 psp->vj = cp->vj_comp.stats;
727 switch (mp->b_rptr[0]) {
729 ++cp->stats.ppp_ierrors;
732 ++cp->stats.ppp_oerrors;
748 mblk_t *mp, *dmp = NULL, *np;
751 int len, hlen, vjlen;
754 cp = (comp_state_t *) q->q_ptr;
755 while ((mp = getq(q)) != 0) {
756 /* assert(mp->b_datap->db_type == M_DATA) */
757 if (!canputnext(q)) {
763 cp->stats.ppp_ibytes += len;
764 cp->stats.ppp_ipackets++;
767 * First work out the protocol and where the PPP header ends.
770 proto = MSG_BYTE(mp, 0);
771 if (proto == PPP_ALLSTATIONS) {
773 proto = MSG_BYTE(mp, 2);
775 if ((proto & 1) == 0) {
777 proto = (proto << 8) + MSG_BYTE(mp, i);
782 * Now reconstruct a complete, contiguous PPP header at the
783 * start of the packet.
785 if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
786 + ((cp->flags & DECOMP_PROT)? 1: 2)) {
790 if (mp->b_rptr + hlen > mp->b_wptr) {
791 adjmsg(mp, hlen); /* XXX check this call */
794 if (hlen != PPP_HDRLEN) {
796 * We need to put some bytes on the front of the packet
797 * to make a full-length PPP header.
798 * If we can put them in *mp, we do, otherwise we
799 * tack another mblk on the front.
800 * XXX we really shouldn't need to carry around
801 * the address and control at this stage.
803 dp = mp->b_rptr + hlen - PPP_HDRLEN;
804 if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
805 np = allocb(PPP_HDRLEN, BPRI_MED);
812 mp->b_wptr += PPP_HDRLEN;
816 dp[0] = PPP_ALLSTATIONS;
823 * Now see if we have a compressed packet to decompress,
824 * or a CCP packet to take notice of.
826 proto = PPP_PROTOCOL(mp->b_rptr);
827 if (proto == PPP_CCP) {
829 if (mp->b_wptr < mp->b_rptr + len) {
834 ppp_comp_ccp(q, mp, 1);
835 } else if (proto == PPP_COMP) {
836 if ((cp->flags & CCP_ISUP)
837 && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
838 && (cp->flags & CCP_ERR) == 0) {
839 rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
845 /* no error, but no packet returned either. */
850 cp->flags |= CCP_ERROR;
851 ++cp->stats.ppp_ierrors;
852 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
854 case DECOMP_FATALERROR:
855 cp->flags |= CCP_FATALERROR;
856 ++cp->stats.ppp_ierrors;
857 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
861 } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
862 (*cp->rcomp->incomp)(cp->rstate, mp);
866 * Now do VJ decompression.
868 proto = PPP_PROTOCOL(mp->b_rptr);
869 if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
870 len = msgdsize(mp) - PPP_HDRLEN;
871 if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
875 * Advance past the ppp header.
876 * Here we assume that the whole PPP header is in the first mblk.
879 dp = np->b_rptr + PPP_HDRLEN;
880 if (dp >= mp->b_wptr) {
886 * Make sure we have sufficient contiguous data at this point.
888 hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
891 if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
892 PULLUP(mp, hlen + PPP_HDRLEN);
896 dp = np->b_rptr + PPP_HDRLEN;
899 if (proto == PPP_VJC_COMP) {
901 * Decompress VJ-compressed packet.
902 * First reset compressor if an input error has occurred.
904 if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
905 if (cp->flags & DBGLOG)
906 DPRINT1("ppp%d: resetting VJ\n", cp->unit);
907 vj_uncompress_err(&cp->vj_comp);
908 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
911 vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
912 &cp->vj_comp, &iphdr, &iphlen);
914 if (cp->flags & DBGLOG)
915 DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
917 ++cp->vj_last_ierrors; /* so we don't reset next time */
921 /* drop ppp and vj headers off */
926 mp->b_rptr = dp + vjlen;
928 /* allocate a new mblk for the ppp and ip headers */
929 if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
931 dp = np->b_rptr; /* prepend mblk with TCP/IP hdr */
932 dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
936 bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
937 np->b_wptr = dp + iphlen + PPP_HDRLEN;
940 /* XXX there seems to be a bug which causes panics in strread
941 if we make an mbuf with only the IP header in it :-( */
942 if (mp->b_wptr - mp->b_rptr > 4) {
943 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
947 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
948 mp->b_wptr - mp->b_rptr);
949 np->b_wptr += mp->b_wptr - mp->b_rptr;
950 np->b_cont = mp->b_cont;
958 * "Decompress" a VJ-uncompressed packet.
960 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
961 if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
962 if (cp->flags & DBGLOG)
963 DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
965 ++cp->vj_last_ierrors; /* don't need to reset next time */
968 mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
978 cp->stats.ppp_ierrors++;
979 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
984 * Handle a CCP packet being sent or received.
985 * Here all the data in the packet is in a single mbuf.
988 ppp_comp_ccp(q, mp, rcvd)
998 if (len < PPP_HDRLEN + CCP_HDRLEN)
1001 cp = (comp_state_t *) q->q_ptr;
1002 dp = mp->b_rptr + PPP_HDRLEN;
1004 clen = CCP_LENGTH(dp);
1008 switch (CCP_CODE(dp)) {
1012 cp->flags &= ~CCP_ISUP;
1016 if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
1017 && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
1018 && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
1020 if (cp->xstate != NULL
1021 && (*cp->xcomp->comp_init)
1022 (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1023 cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
1024 cp->flags |= CCP_COMP_RUN;
1026 if (cp->rstate != NULL
1027 && (*cp->rcomp->decomp_init)
1028 (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1029 cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
1030 cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
1036 if (cp->flags & CCP_ISUP) {
1038 if (cp->xstate && (cp->flags & CCP_COMP_RUN))
1039 (*cp->xcomp->comp_reset)(cp->xstate);
1041 if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
1042 (*cp->rcomp->decomp_reset)(cp->rstate);
1043 cp->flags &= ~CCP_ERROR;
1059 DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
1060 DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
1061 DPRINT2(" base=%x lim=%x", db->db_base, db->db_lim);
1062 DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
1073 while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
1077 return mp->b_rptr[i];