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.9 1998/03/24 23:52:37 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, ppp_deflate_draft;
168 struct compressor *ppp_compressors[] = {
180 * STREAMS module entry points.
182 MOD_OPEN(ppp_comp_open)
189 if (q->q_ptr == NULL) {
190 cp = (comp_state_t *) ALLOC_SLEEP(sizeof(comp_state_t));
193 WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
194 bzero((caddr_t)cp, sizeof(comp_state_t));
199 vj_compress_init(&cp->vj_comp, -1);
203 if (!(thread = kernel_thread_w_arg(first_task, ppp_comp_alloc, (void *)cp)))
211 MOD_CLOSE(ppp_comp_close)
216 cp = (comp_state_t *) q->q_ptr;
218 if (cp->xstate != NULL)
219 (*cp->xcomp->comp_free)(cp->xstate);
220 if (cp->rstate != NULL)
221 (*cp->rcomp->decomp_free)(cp->rstate);
224 printf("ppp_comp_close: NULL thread!\n");
226 thread_terminate(cp->thread);
228 FREE(cp, sizeof(comp_state_t));
230 OTHERQ(q)->q_ptr = NULL;
238 /* thread for calling back to a compressor's memory allocator
239 * Needed for Digital UNIX since it's VM can't handle requests
240 * for large amounts of memory without blocking. The thread
241 * provides a context in which we can call a memory allocator
245 ppp_comp_alloc(comp_state_t *cp)
248 unsigned char *compressor_options;
250 void *(*comp_allocator)();
253 #if defined(MAJOR_VERSION) && (MAJOR_VERSION <= 2)
255 /* In 2.x and earlier the argument gets passed
256 * in the thread structure itself. Yuck.
258 thread = current_thread();
259 cp = thread->reply_port;
260 thread->reply_port = PORT_NULL;
265 assert_wait((vm_offset_t)&cp->memreq.thread_status, TRUE);
268 if (thread_should_halt(current_thread()))
270 cmd = cp->memreq.cmd;
271 compressor_options = &cp->memreq.comp_opts[0];
272 len = compressor_options[1];
273 if (cmd == PPPIO_XCOMP) {
274 cp->memreq.returned_mem = cp->xcomp->comp_alloc(compressor_options, len);
275 if (!cp->memreq.returned_mem) {
276 cp->memreq.thread_status = ENOSR;
278 cp->memreq.thread_status = 0;
281 cp->memreq.returned_mem = cp->rcomp->decomp_alloc(compressor_options, len);
282 if (!cp->memreq.returned_mem) {
283 cp->memreq.thread_status = ENOSR;
285 cp->memreq.thread_status = 0;
293 /* here's the deal with memory allocation under Digital UNIX.
294 * Some other may also benefit from this...
295 * We can't ask for huge chunks of memory in a context where
296 * the caller can't be put to sleep (like, here.) The alloc
297 * is likely to fail. Instead we do this: the first time we
298 * get called, kick off a thread to do the allocation. Return
299 * immediately to the caller with EAGAIN, as an indication that
300 * they should send down the ioctl again. By the time the
301 * second call comes in it's likely that the memory allocation
302 * thread will have returned with the requested memory. We will
303 * continue to return EAGAIN however until the thread has completed.
304 * When it has, we return zero (and the memory) if the allocator
305 * was successful and ENOSR otherwise.
307 * Callers of the RCOMP and XCOMP ioctls are encouraged (but not
308 * required) to loop for some number of iterations with a small
309 * delay in the loop body (for instance a 1/10-th second "sleep"
322 struct compressor **comp;
323 struct ppp_stats *psp;
324 struct ppp_comp_stats *csp;
325 unsigned char *opt_data;
326 int nxslots, nrslots;
328 cp = (comp_state_t *) q->q_ptr;
329 switch (mp->b_datap->db_type) {
336 iop = (struct iocblk *) mp->b_rptr;
338 switch (iop->ioc_cmd) {
341 /* set/get CCP state */
342 if (iop->ioc_count != 2 * sizeof(int))
344 if (mp->b_cont == 0) {
345 DPRINT1("ppp_comp_wput/%d: PPPIO_CFLAGS b_cont = 0!\n", cp->unit);
348 flags = ((int *) mp->b_cont->b_rptr)[0];
349 mask = ((int *) mp->b_cont->b_rptr)[1];
350 cp->flags = (cp->flags & ~mask) | (flags & mask);
351 if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
352 if (cp->xstate != NULL) {
353 (*cp->xcomp->comp_free)(cp->xstate);
356 if (cp->rstate != NULL) {
357 (*cp->rcomp->decomp_free)(cp->rstate);
360 cp->flags &= ~CCP_ISUP;
363 iop->ioc_count = sizeof(int);
364 ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
365 mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
370 * Initialize VJ compressor/decompressor
372 if (iop->ioc_count != 2)
374 if (mp->b_cont == 0) {
375 DPRINT1("ppp_comp_wput/%d: PPPIO_VJINIT b_cont = 0!\n", cp->unit);
378 nxslots = mp->b_cont->b_rptr[0] + 1;
379 nrslots = mp->b_cont->b_rptr[1] + 1;
380 if (nxslots > MAX_STATES || nrslots > MAX_STATES)
382 vj_compress_init(&cp->vj_comp, nxslots);
383 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
390 if (iop->ioc_count <= 0)
392 if (mp->b_cont == 0) {
393 DPRINT1("ppp_comp_wput/%d: PPPIO_[XR]COMP b_cont = 0!\n", cp->unit);
396 opt_data = mp->b_cont->b_rptr;
397 len = mp->b_cont->b_wptr - opt_data;
398 if (len > iop->ioc_count)
399 len = iop->ioc_count;
400 if (opt_data[1] < 2 || opt_data[1] > len)
402 for (comp = ppp_compressors; *comp != NULL; ++comp)
403 if ((*comp)->compress_proto == opt_data[0]) {
404 /* here's the handler! */
407 if (iop->ioc_cmd == PPPIO_XCOMP) {
408 /* A previous call may have fetched memory for a compressor
409 * that's now being retired or reset. Free it using it's
410 * mechanism for freeing stuff.
412 if (cp->xstate != NULL) {
413 (*cp->xcomp->comp_free)(cp->xstate);
417 cp->xstate = (*comp)->comp_alloc(opt_data, len);
418 if (cp->xstate == NULL)
421 if (cp->rstate != NULL) {
422 (*cp->rcomp->decomp_free)(cp->rstate);
426 cp->rstate = (*comp)->decomp_alloc(opt_data, len);
427 if (cp->rstate == NULL)
431 if ((error = cp->memreq.thread_status) != EAGAIN)
432 if (iop->ioc_cmd == PPPIO_XCOMP) {
434 (*cp->xcomp->comp_free)(cp->xstate);
437 /* sanity check for compressor options
439 if (sizeof (cp->memreq.comp_opts) < len) {
440 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
442 cp->memreq.thread_status = ENOSR;
443 cp->memreq.returned_mem = 0;
445 /* fill in request for the thread and kick it off
447 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
448 bcopy(opt_data, cp->memreq.comp_opts, len);
449 cp->memreq.cmd = PPPIO_XCOMP;
451 error = cp->memreq.thread_status = EAGAIN;
452 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
454 cp->xstate = cp->memreq.returned_mem;
455 cp->memreq.returned_mem = 0;
456 cp->memreq.thread_status = 0;
460 (*cp->rcomp->decomp_free)(cp->rstate);
463 if (sizeof (cp->memreq.comp_opts) < len) {
464 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
466 cp->memreq.thread_status = ENOSR;
467 cp->memreq.returned_mem = 0;
469 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
470 bcopy(opt_data, cp->memreq.comp_opts, len);
471 cp->memreq.cmd = PPPIO_RCOMP;
473 error = cp->memreq.thread_status = EAGAIN;
474 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
476 cp->rstate = cp->memreq.returned_mem;
477 cp->memreq.returned_mem = 0;
478 cp->memreq.thread_status = 0;
488 if ((cp->flags & LAST_MOD) == 0) {
489 error = -1; /* let the ppp_ahdl module handle it */
492 np = allocb(sizeof(struct ppp_stats), BPRI_HI);
500 psp = (struct ppp_stats *) np->b_wptr;
501 np->b_wptr += sizeof(struct ppp_stats);
502 iop->ioc_count = sizeof(struct ppp_stats);
504 psp->vj = cp->vj_comp.stats;
509 np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
517 csp = (struct ppp_comp_stats *) np->b_wptr;
518 np->b_wptr += sizeof(struct ppp_comp_stats);
519 iop->ioc_count = sizeof(struct ppp_comp_stats);
520 bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
522 (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
524 (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
529 if (iop->ioc_count != sizeof(int))
531 if (mp->b_cont == 0) {
532 DPRINT1("ppp_comp_wput/%d: PPPIO_DEBUG b_cont = 0!\n", cp->unit);
535 n = *(int *)mp->b_cont->b_rptr;
536 if (n == PPPDBG_LOG + PPPDBG_COMP) {
537 DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
547 cp->flags |= LAST_MOD;
558 else if (error == 0) {
559 mp->b_datap->db_type = M_IOCACK;
562 mp->b_datap->db_type = M_IOCNAK;
563 iop->ioc_error = error;
570 switch (*mp->b_rptr) {
572 cp->mtu = ((unsigned short *)mp->b_rptr)[1];
575 cp->mru = ((unsigned short *)mp->b_rptr)[1];
578 cp->unit = mp->b_rptr[1];
593 mblk_t *mp, *cmp = NULL, *np;
595 int len, proto, type, hlen, code;
597 unsigned char *vjhdr, *dp;
599 cp = (comp_state_t *) q->q_ptr;
600 while ((mp = getq(q)) != 0) {
601 /* assert(mp->b_datap->db_type == M_DATA) */
603 if (!bcanputnext(q,mp->b_band)) {
605 if (!canputnext(q)) {
612 * First check the packet length and work out what the protocol is.
615 if (len < PPP_HDRLEN) {
616 DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
618 cp->stats.ppp_oerrors++;
619 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
622 proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
625 * Make sure we've got enough data in the first mblk
626 * and that we are its only user.
628 if (proto == PPP_CCP)
630 else if (proto == PPP_IP)
631 hlen = PPP_HDRLEN + MAX_IPHDR;
636 if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
639 DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
640 cp->stats.ppp_oerrors++;
641 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
647 * Do VJ compression if requested.
649 if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
650 ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
651 if (ip->ip_p == IPPROTO_TCP) {
652 type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
653 (cp->flags & COMP_VJCCID), &vjhdr);
655 case TYPE_UNCOMPRESSED_TCP:
656 mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
658 case TYPE_COMPRESSED_TCP:
659 dp = vjhdr - PPP_HDRLEN;
660 dp[1] = mp->b_rptr[1]; /* copy control field */
661 dp[0] = mp->b_rptr[0]; /* copy address field */
662 dp[2] = 0; /* set protocol field */
663 dp[3] = proto = PPP_VJC_COMP;
671 * Do packet compression if enabled.
673 if (proto == PPP_CCP)
674 ppp_comp_ccp(q, mp, 0);
675 else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
676 && cp->xstate != NULL) {
678 (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
679 (cp->flags & CCP_ISUP? cp->mtu + PPP_HDRLEN: 0));
682 cmp->b_band=mp->b_band;
690 * Do address/control and protocol compression if enabled.
692 if ((cp->flags & COMP_AC)
693 && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
694 mp->b_rptr += 2; /* drop the address & ctrl fields */
695 if (proto < 0x100 && (cp->flags & COMP_PROT))
696 ++mp->b_rptr; /* drop the high protocol byte */
697 } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
698 /* shuffle up the address & ctrl fields */
699 mp->b_rptr[2] = mp->b_rptr[1];
700 mp->b_rptr[1] = mp->b_rptr[0];
704 cp->stats.ppp_opackets++;
705 cp->stats.ppp_obytes += msgdsize(mp);
717 struct ppp_stats *psp;
719 cp = (comp_state_t *) q->q_ptr;
720 switch (mp->b_datap->db_type) {
727 iop = (struct iocblk *) mp->b_rptr;
728 switch (iop->ioc_cmd) {
731 * Catch this on the way back from the ppp_ahdl module
732 * so we can fill in the VJ stats.
734 if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
736 psp = (struct ppp_stats *) mp->b_cont->b_rptr;
737 psp->vj = cp->vj_comp.stats;
744 switch (mp->b_rptr[0]) {
746 ++cp->stats.ppp_ierrors;
749 ++cp->stats.ppp_oerrors;
765 mblk_t *mp, *dmp = NULL, *np;
768 int len, hlen, vjlen;
771 cp = (comp_state_t *) q->q_ptr;
772 while ((mp = getq(q)) != 0) {
773 /* assert(mp->b_datap->db_type == M_DATA) */
774 if (!canputnext(q)) {
780 cp->stats.ppp_ibytes += len;
781 cp->stats.ppp_ipackets++;
784 * First work out the protocol and where the PPP header ends.
787 proto = MSG_BYTE(mp, 0);
788 if (proto == PPP_ALLSTATIONS) {
790 proto = MSG_BYTE(mp, 2);
792 if ((proto & 1) == 0) {
794 proto = (proto << 8) + MSG_BYTE(mp, i);
799 * Now reconstruct a complete, contiguous PPP header at the
800 * start of the packet.
802 if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
803 + ((cp->flags & DECOMP_PROT)? 1: 2)) {
807 if (mp->b_rptr + hlen > mp->b_wptr) {
808 adjmsg(mp, hlen); /* XXX check this call */
811 if (hlen != PPP_HDRLEN) {
813 * We need to put some bytes on the front of the packet
814 * to make a full-length PPP header.
815 * If we can put them in *mp, we do, otherwise we
816 * tack another mblk on the front.
817 * XXX we really shouldn't need to carry around
818 * the address and control at this stage.
820 dp = mp->b_rptr + hlen - PPP_HDRLEN;
821 if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
822 np = allocb(PPP_HDRLEN, BPRI_MED);
829 mp->b_wptr += PPP_HDRLEN;
833 dp[0] = PPP_ALLSTATIONS;
840 * Now see if we have a compressed packet to decompress,
841 * or a CCP packet to take notice of.
843 proto = PPP_PROTOCOL(mp->b_rptr);
844 if (proto == PPP_CCP) {
846 if (mp->b_wptr < mp->b_rptr + len) {
851 ppp_comp_ccp(q, mp, 1);
852 } else if (proto == PPP_COMP) {
853 if ((cp->flags & CCP_ISUP)
854 && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
855 && (cp->flags & CCP_ERR) == 0) {
856 rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
862 /* no error, but no packet returned either. */
867 cp->flags |= CCP_ERROR;
868 ++cp->stats.ppp_ierrors;
869 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
871 case DECOMP_FATALERROR:
872 cp->flags |= CCP_FATALERROR;
873 ++cp->stats.ppp_ierrors;
874 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
878 } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
879 (*cp->rcomp->incomp)(cp->rstate, mp);
883 * Now do VJ decompression.
885 proto = PPP_PROTOCOL(mp->b_rptr);
886 if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
887 len = msgdsize(mp) - PPP_HDRLEN;
888 if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
892 * Advance past the ppp header.
893 * Here we assume that the whole PPP header is in the first mblk.
896 dp = np->b_rptr + PPP_HDRLEN;
897 if (dp >= mp->b_wptr) {
903 * Make sure we have sufficient contiguous data at this point.
905 hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
908 if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
909 PULLUP(mp, hlen + PPP_HDRLEN);
913 dp = np->b_rptr + PPP_HDRLEN;
916 if (proto == PPP_VJC_COMP) {
918 * Decompress VJ-compressed packet.
919 * First reset compressor if an input error has occurred.
921 if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
922 if (cp->flags & DBGLOG)
923 DPRINT1("ppp%d: resetting VJ\n", cp->unit);
924 vj_uncompress_err(&cp->vj_comp);
925 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
928 vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
929 &cp->vj_comp, &iphdr, &iphlen);
931 if (cp->flags & DBGLOG)
932 DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
934 ++cp->vj_last_ierrors; /* so we don't reset next time */
938 /* drop ppp and vj headers off */
943 mp->b_rptr = dp + vjlen;
945 /* allocate a new mblk for the ppp and ip headers */
946 if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
948 dp = np->b_rptr; /* prepend mblk with TCP/IP hdr */
949 dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
953 bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
954 np->b_wptr = dp + iphlen + PPP_HDRLEN;
957 /* XXX there seems to be a bug which causes panics in strread
958 if we make an mbuf with only the IP header in it :-( */
959 if (mp->b_wptr - mp->b_rptr > 4) {
960 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
964 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
965 mp->b_wptr - mp->b_rptr);
966 np->b_wptr += mp->b_wptr - mp->b_rptr;
967 np->b_cont = mp->b_cont;
975 * "Decompress" a VJ-uncompressed packet.
977 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
978 if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
979 if (cp->flags & DBGLOG)
980 DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
982 ++cp->vj_last_ierrors; /* don't need to reset next time */
985 mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
995 cp->stats.ppp_ierrors++;
996 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
1001 * Handle a CCP packet being sent or received.
1002 * Here all the data in the packet is in a single mbuf.
1005 ppp_comp_ccp(q, mp, rcvd)
1015 if (len < PPP_HDRLEN + CCP_HDRLEN)
1018 cp = (comp_state_t *) q->q_ptr;
1019 dp = mp->b_rptr + PPP_HDRLEN;
1021 clen = CCP_LENGTH(dp);
1025 switch (CCP_CODE(dp)) {
1029 cp->flags &= ~CCP_ISUP;
1033 if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
1034 && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
1035 && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
1037 if (cp->xstate != NULL
1038 && (*cp->xcomp->comp_init)
1039 (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1040 cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
1041 cp->flags |= CCP_COMP_RUN;
1043 if (cp->rstate != NULL
1044 && (*cp->rcomp->decomp_init)
1045 (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1046 cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
1047 cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
1053 if (cp->flags & CCP_ISUP) {
1055 if (cp->xstate && (cp->flags & CCP_COMP_RUN))
1056 (*cp->xcomp->comp_reset)(cp->xstate);
1058 if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
1059 (*cp->rcomp->decomp_reset)(cp->rstate);
1060 cp->flags &= ~CCP_ERROR;
1076 DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
1077 DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
1078 DPRINT2(" base=%x lim=%x", db->db_base, db->db_lim);
1079 DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
1090 while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
1094 return mp->b_rptr[i];