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.12 1999/09/15 23:49:06 masputra 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 bzero((caddr_t)cp, sizeof(comp_state_t));
194 WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
199 vj_compress_init(&cp->vj_comp, -1);
201 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;
330 DPRINT("cp == 0 in ppp_comp_wput\n");
335 switch (mp->b_datap->db_type) {
342 iop = (struct iocblk *) mp->b_rptr;
344 switch (iop->ioc_cmd) {
347 /* set/get CCP state */
348 if (iop->ioc_count != 2 * sizeof(int))
350 if (mp->b_cont == 0) {
351 DPRINT1("ppp_comp_wput/%d: PPPIO_CFLAGS b_cont = 0!\n", cp->unit);
354 flags = ((int *) mp->b_cont->b_rptr)[0];
355 mask = ((int *) mp->b_cont->b_rptr)[1];
356 cp->flags = (cp->flags & ~mask) | (flags & mask);
357 if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
358 if (cp->xstate != NULL) {
359 (*cp->xcomp->comp_free)(cp->xstate);
362 if (cp->rstate != NULL) {
363 (*cp->rcomp->decomp_free)(cp->rstate);
366 cp->flags &= ~CCP_ISUP;
369 iop->ioc_count = sizeof(int);
370 ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
371 mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
376 * Initialize VJ compressor/decompressor
378 if (iop->ioc_count != 2)
380 if (mp->b_cont == 0) {
381 DPRINT1("ppp_comp_wput/%d: PPPIO_VJINIT b_cont = 0!\n", cp->unit);
384 nxslots = mp->b_cont->b_rptr[0] + 1;
385 nrslots = mp->b_cont->b_rptr[1] + 1;
386 if (nxslots > MAX_STATES || nrslots > MAX_STATES)
388 vj_compress_init(&cp->vj_comp, nxslots);
389 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
396 if (iop->ioc_count <= 0)
398 if (mp->b_cont == 0) {
399 DPRINT1("ppp_comp_wput/%d: PPPIO_[XR]COMP b_cont = 0!\n", cp->unit);
402 opt_data = mp->b_cont->b_rptr;
403 len = mp->b_cont->b_wptr - opt_data;
404 if (len > iop->ioc_count)
405 len = iop->ioc_count;
406 if (opt_data[1] < 2 || opt_data[1] > len)
408 for (comp = ppp_compressors; *comp != NULL; ++comp)
409 if ((*comp)->compress_proto == opt_data[0]) {
410 /* here's the handler! */
413 if (iop->ioc_cmd == PPPIO_XCOMP) {
414 /* A previous call may have fetched memory for a compressor
415 * that's now being retired or reset. Free it using it's
416 * mechanism for freeing stuff.
418 if (cp->xstate != NULL) {
419 (*cp->xcomp->comp_free)(cp->xstate);
423 cp->xstate = (*comp)->comp_alloc(opt_data, len);
424 if (cp->xstate == NULL)
427 if (cp->rstate != NULL) {
428 (*cp->rcomp->decomp_free)(cp->rstate);
432 cp->rstate = (*comp)->decomp_alloc(opt_data, len);
433 if (cp->rstate == NULL)
437 if ((error = cp->memreq.thread_status) != EAGAIN)
438 if (iop->ioc_cmd == PPPIO_XCOMP) {
440 (*cp->xcomp->comp_free)(cp->xstate);
443 /* sanity check for compressor options
445 if (sizeof (cp->memreq.comp_opts) < len) {
446 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
448 cp->memreq.thread_status = ENOSR;
449 cp->memreq.returned_mem = 0;
451 /* fill in request for the thread and kick it off
453 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
454 bcopy(opt_data, cp->memreq.comp_opts, len);
455 cp->memreq.cmd = PPPIO_XCOMP;
457 error = cp->memreq.thread_status = EAGAIN;
458 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
460 cp->xstate = cp->memreq.returned_mem;
461 cp->memreq.returned_mem = 0;
462 cp->memreq.thread_status = 0;
466 (*cp->rcomp->decomp_free)(cp->rstate);
469 if (sizeof (cp->memreq.comp_opts) < len) {
470 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
472 cp->memreq.thread_status = ENOSR;
473 cp->memreq.returned_mem = 0;
475 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
476 bcopy(opt_data, cp->memreq.comp_opts, len);
477 cp->memreq.cmd = PPPIO_RCOMP;
479 error = cp->memreq.thread_status = EAGAIN;
480 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
482 cp->rstate = cp->memreq.returned_mem;
483 cp->memreq.returned_mem = 0;
484 cp->memreq.thread_status = 0;
494 if ((cp->flags & LAST_MOD) == 0) {
495 error = -1; /* let the ppp_ahdl module handle it */
498 np = allocb(sizeof(struct ppp_stats), BPRI_HI);
506 psp = (struct ppp_stats *) np->b_wptr;
507 np->b_wptr += sizeof(struct ppp_stats);
508 iop->ioc_count = sizeof(struct ppp_stats);
510 psp->vj = cp->vj_comp.stats;
515 np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
523 csp = (struct ppp_comp_stats *) np->b_wptr;
524 np->b_wptr += sizeof(struct ppp_comp_stats);
525 iop->ioc_count = sizeof(struct ppp_comp_stats);
526 bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
528 (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
530 (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
535 if (iop->ioc_count != sizeof(int))
537 if (mp->b_cont == 0) {
538 DPRINT1("ppp_comp_wput/%d: PPPIO_DEBUG b_cont = 0!\n", cp->unit);
541 n = *(int *)mp->b_cont->b_rptr;
542 if (n == PPPDBG_LOG + PPPDBG_COMP) {
543 DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
553 cp->flags |= LAST_MOD;
564 else if (error == 0) {
565 mp->b_datap->db_type = M_IOCACK;
568 mp->b_datap->db_type = M_IOCNAK;
569 iop->ioc_error = error;
576 switch (*mp->b_rptr) {
578 cp->mtu = ((unsigned short *)mp->b_rptr)[1];
581 cp->mru = ((unsigned short *)mp->b_rptr)[1];
584 cp->unit = mp->b_rptr[1];
601 mblk_t *mp, *cmp = NULL;
603 int len, proto, type, hlen, code;
605 unsigned char *vjhdr, *dp;
607 cp = (comp_state_t *) q->q_ptr;
609 DPRINT("cp == 0 in ppp_comp_wsrv\n");
613 while ((mp = getq(q)) != 0) {
614 /* assert(mp->b_datap->db_type == M_DATA) */
616 if (!bcanputnext(q,mp->b_band))
626 * First check the packet length and work out what the protocol is.
629 if (len < PPP_HDRLEN) {
630 DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
632 cp->stats.ppp_oerrors++;
633 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
636 proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
639 * Make sure we've got enough data in the first mblk
640 * and that we are its only user.
642 if (proto == PPP_CCP)
644 else if (proto == PPP_IP)
645 hlen = PPP_HDRLEN + MAX_IPHDR;
650 if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
653 DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
654 cp->stats.ppp_oerrors++;
655 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
661 * Do VJ compression if requested.
663 if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
664 ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
665 if (ip->ip_p == IPPROTO_TCP) {
666 type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
667 (cp->flags & COMP_VJCCID), &vjhdr);
669 case TYPE_UNCOMPRESSED_TCP:
670 mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
672 case TYPE_COMPRESSED_TCP:
673 dp = vjhdr - PPP_HDRLEN;
674 dp[1] = mp->b_rptr[1]; /* copy control field */
675 dp[0] = mp->b_rptr[0]; /* copy address field */
676 dp[2] = 0; /* set protocol field */
677 dp[3] = proto = PPP_VJC_COMP;
685 * Do packet compression if enabled.
687 if (proto == PPP_CCP)
688 ppp_comp_ccp(q, mp, 0);
689 else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
690 && cp->xstate != NULL) {
692 (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
693 (cp->flags & CCP_ISUP? cp->mtu + PPP_HDRLEN: 0));
696 cmp->b_band=mp->b_band;
704 * Do address/control and protocol compression if enabled.
706 if ((cp->flags & COMP_AC)
707 && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
708 mp->b_rptr += 2; /* drop the address & ctrl fields */
709 if (proto < 0x100 && (cp->flags & COMP_PROT))
710 ++mp->b_rptr; /* drop the high protocol byte */
711 } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
712 /* shuffle up the address & ctrl fields */
713 mp->b_rptr[2] = mp->b_rptr[1];
714 mp->b_rptr[1] = mp->b_rptr[0];
718 cp->stats.ppp_opackets++;
719 cp->stats.ppp_obytes += msgdsize(mp);
733 struct ppp_stats *psp;
735 cp = (comp_state_t *) q->q_ptr;
737 DPRINT("cp == 0 in ppp_comp_rput\n");
742 switch (mp->b_datap->db_type) {
749 iop = (struct iocblk *) mp->b_rptr;
750 switch (iop->ioc_cmd) {
753 * Catch this on the way back from the ppp_ahdl module
754 * so we can fill in the VJ stats.
756 if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
758 psp = (struct ppp_stats *) mp->b_cont->b_rptr;
759 psp->vj = cp->vj_comp.stats;
766 switch (mp->b_rptr[0]) {
768 ++cp->stats.ppp_ierrors;
771 ++cp->stats.ppp_oerrors;
789 mblk_t *mp, *dmp = NULL, *np;
792 int len, hlen, vjlen;
795 cp = (comp_state_t *) q->q_ptr;
797 DPRINT("cp == 0 in ppp_comp_rsrv\n");
801 while ((mp = getq(q)) != 0) {
802 /* assert(mp->b_datap->db_type == M_DATA) */
803 if (!canputnext(q)) {
809 cp->stats.ppp_ibytes += len;
810 cp->stats.ppp_ipackets++;
813 * First work out the protocol and where the PPP header ends.
816 proto = MSG_BYTE(mp, 0);
817 if (proto == PPP_ALLSTATIONS) {
819 proto = MSG_BYTE(mp, 2);
821 if ((proto & 1) == 0) {
823 proto = (proto << 8) + MSG_BYTE(mp, i);
828 * Now reconstruct a complete, contiguous PPP header at the
829 * start of the packet.
831 if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
832 + ((cp->flags & DECOMP_PROT)? 1: 2)) {
836 if (mp->b_rptr + hlen > mp->b_wptr) {
837 adjmsg(mp, hlen); /* XXX check this call */
840 if (hlen != PPP_HDRLEN) {
842 * We need to put some bytes on the front of the packet
843 * to make a full-length PPP header.
844 * If we can put them in *mp, we do, otherwise we
845 * tack another mblk on the front.
846 * XXX we really shouldn't need to carry around
847 * the address and control at this stage.
849 dp = mp->b_rptr + hlen - PPP_HDRLEN;
850 if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
851 np = allocb(PPP_HDRLEN, BPRI_MED);
858 mp->b_wptr += PPP_HDRLEN;
862 dp[0] = PPP_ALLSTATIONS;
869 * Now see if we have a compressed packet to decompress,
870 * or a CCP packet to take notice of.
872 proto = PPP_PROTOCOL(mp->b_rptr);
873 if (proto == PPP_CCP) {
875 if (mp->b_wptr < mp->b_rptr + len) {
880 ppp_comp_ccp(q, mp, 1);
881 } else if (proto == PPP_COMP) {
882 if ((cp->flags & CCP_ISUP)
883 && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
884 && (cp->flags & CCP_ERR) == 0) {
885 rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
891 /* no error, but no packet returned either. */
896 cp->flags |= CCP_ERROR;
897 ++cp->stats.ppp_ierrors;
898 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
900 case DECOMP_FATALERROR:
901 cp->flags |= CCP_FATALERROR;
902 ++cp->stats.ppp_ierrors;
903 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
907 } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
908 (*cp->rcomp->incomp)(cp->rstate, mp);
912 * Now do VJ decompression.
914 proto = PPP_PROTOCOL(mp->b_rptr);
915 if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
916 len = msgdsize(mp) - PPP_HDRLEN;
917 if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
921 * Advance past the ppp header.
922 * Here we assume that the whole PPP header is in the first mblk.
925 dp = np->b_rptr + PPP_HDRLEN;
926 if (dp >= mp->b_wptr) {
932 * Make sure we have sufficient contiguous data at this point.
934 hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
937 if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
938 PULLUP(mp, hlen + PPP_HDRLEN);
942 dp = np->b_rptr + PPP_HDRLEN;
945 if (proto == PPP_VJC_COMP) {
947 * Decompress VJ-compressed packet.
948 * First reset compressor if an input error has occurred.
950 if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
951 if (cp->flags & DBGLOG)
952 DPRINT1("ppp%d: resetting VJ\n", cp->unit);
953 vj_uncompress_err(&cp->vj_comp);
954 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
957 vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
958 &cp->vj_comp, &iphdr, &iphlen);
960 if (cp->flags & DBGLOG)
961 DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
963 ++cp->vj_last_ierrors; /* so we don't reset next time */
967 /* drop ppp and vj headers off */
972 mp->b_rptr = dp + vjlen;
974 /* allocate a new mblk for the ppp and ip headers */
975 if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
977 dp = np->b_rptr; /* prepend mblk with TCP/IP hdr */
978 dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
982 bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
983 np->b_wptr = dp + iphlen + PPP_HDRLEN;
986 /* XXX there seems to be a bug which causes panics in strread
987 if we make an mbuf with only the IP header in it :-( */
988 if (mp->b_wptr - mp->b_rptr > 4) {
989 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
993 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
994 mp->b_wptr - mp->b_rptr);
995 np->b_wptr += mp->b_wptr - mp->b_rptr;
996 np->b_cont = mp->b_cont;
1004 * "Decompress" a VJ-uncompressed packet.
1006 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
1007 if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
1008 if (cp->flags & DBGLOG)
1009 DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
1011 ++cp->vj_last_ierrors; /* don't need to reset next time */
1014 mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
1024 cp->stats.ppp_ierrors++;
1025 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
1032 * Handle a CCP packet being sent or received.
1033 * Here all the data in the packet is in a single mbuf.
1036 ppp_comp_ccp(q, mp, rcvd)
1046 if (len < PPP_HDRLEN + CCP_HDRLEN)
1049 cp = (comp_state_t *) q->q_ptr;
1050 dp = mp->b_rptr + PPP_HDRLEN;
1052 clen = CCP_LENGTH(dp);
1056 switch (CCP_CODE(dp)) {
1060 cp->flags &= ~CCP_ISUP;
1064 if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
1065 && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
1066 && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
1068 if (cp->xstate != NULL
1069 && (*cp->xcomp->comp_init)
1070 (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1071 cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
1072 cp->flags |= CCP_COMP_RUN;
1074 if (cp->rstate != NULL
1075 && (*cp->rcomp->decomp_init)
1076 (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1077 cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
1078 cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
1084 if (cp->flags & CCP_ISUP) {
1086 if (cp->xstate && (cp->flags & CCP_COMP_RUN))
1087 (*cp->xcomp->comp_reset)(cp->xstate);
1089 if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
1090 (*cp->rcomp->decomp_reset)(cp->rstate);
1091 cp->flags &= ~CCP_ERROR;
1107 DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
1108 DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
1109 DPRINT2(" base=%x lim=%x", db->db_base, db->db_lim);
1110 DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
1121 while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
1125 return mp->b_rptr[i];