2 * ppp_comp.c - STREAMS module for kernel-level compression and CCP support.
4 * Copyright (c) 1994 Paul Mackerras. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name(s) of the authors of this software must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission.
22 * 4. Redistributions of any form whatsoever must retain the following
24 * "This product includes software developed by Paul Mackerras
25 * <paulus@samba.org>".
27 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 * This file is used under SVR4, Solaris 2, SunOS 4, and Digital UNIX.
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/errno.h>
43 #include <sys/stream.h>
47 #include <sys/cmn_err.h>
52 #include <sys/cmn_err.h>
56 #include <net/ppp_defs.h>
57 #include <net/pppio.h>
62 #include <sys/protosw.h>
65 #include <netinet/in.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/ip.h>
68 #include <net/vjcompress.h>
70 #define PACKETPTR mblk_t *
71 #include <net/ppp-comp.h>
73 MOD_OPEN_DECL(ppp_comp_open);
74 MOD_CLOSE_DECL(ppp_comp_close);
75 static int ppp_comp_rput(queue_t *, mblk_t *);
76 static int ppp_comp_rsrv(queue_t *);
77 static int ppp_comp_wput(queue_t *, mblk_t *);
78 static int ppp_comp_wsrv(queue_t *);
79 static void ppp_comp_ccp(queue_t *, mblk_t *, int);
80 static int msg_byte(mblk_t *, unsigned int);
82 /* Extract byte i of message mp. */
83 #define MSG_BYTE(mp, i) ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
86 /* Is this LCP packet one we have to transmit using LCP defaults? */
87 #define LCP_USE_DFLT(mp) (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
89 #define PPP_COMP_ID 0xbadf
90 static struct module_info minfo = {
92 PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16512, 16384,
94 PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16384, 4096,
98 static struct qinit r_init = {
99 ppp_comp_rput, ppp_comp_rsrv, ppp_comp_open, ppp_comp_close,
103 static struct qinit w_init = {
104 ppp_comp_wput, ppp_comp_wsrv, NULL, NULL, NULL, &minfo, NULL
107 #if defined(SVR4) && !defined(SOL2)
109 #define ppp_compinfo pcmpinfo
111 struct streamtab ppp_compinfo = {
112 &r_init, &w_init, NULL, NULL
115 int ppp_comp_count; /* number of module instances in use */
119 static void ppp_comp_alloc(comp_state_t *);
120 typedef struct memreq {
121 unsigned char comp_opts[20];
129 typedef struct comp_state {
134 struct compressor *xcomp;
136 struct compressor *rcomp;
138 struct vjcompress vj_comp;
140 struct pppstat stats;
149 extern task_t first_task;
152 /* Bits in flags are as defined in pppio.h. */
153 #define CCP_ERR (CCP_ERROR | CCP_FATALERROR)
154 #define LAST_MOD 0x1000000 /* no ppp modules below us */
155 #define DBGLOG 0x2000000 /* log debugging stuff */
157 #define MAX_IPHDR 128 /* max TCP/IP header size */
158 #define MAX_VJHDR 20 /* max VJ compressed header size (?) */
160 #undef MIN /* just in case */
161 #define MIN(a, b) ((a) < (b)? (a): (b))
164 * List of compressors we know about.
168 extern struct compressor ppp_bsd_compress;
171 extern struct compressor ppp_deflate, ppp_deflate_draft;
174 struct compressor *ppp_compressors[] = {
186 * STREAMS module entry points.
188 MOD_OPEN(ppp_comp_open)
195 if (q->q_ptr == NULL) {
196 cp = (comp_state_t *) ALLOC_SLEEP(sizeof(comp_state_t));
199 bzero((caddr_t)cp, sizeof(comp_state_t));
200 WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
205 vj_compress_init(&cp->vj_comp, -1);
207 if (!(thread = kernel_thread_w_arg(first_task, ppp_comp_alloc, (void *)cp)))
217 MOD_CLOSE(ppp_comp_close)
222 cp = (comp_state_t *) q->q_ptr;
224 if (cp->xstate != NULL)
225 (*cp->xcomp->comp_free)(cp->xstate);
226 if (cp->rstate != NULL)
227 (*cp->rcomp->decomp_free)(cp->rstate);
230 printf("ppp_comp_close: NULL thread!\n");
232 thread_terminate(cp->thread);
234 FREE(cp, sizeof(comp_state_t));
236 OTHERQ(q)->q_ptr = NULL;
244 /* thread for calling back to a compressor's memory allocator
245 * Needed for Digital UNIX since it's VM can't handle requests
246 * for large amounts of memory without blocking. The thread
247 * provides a context in which we can call a memory allocator
251 ppp_comp_alloc(comp_state_t *cp)
254 unsigned char *compressor_options;
256 void *(*comp_allocator)();
259 #if defined(MAJOR_VERSION) && (MAJOR_VERSION <= 2)
261 /* In 2.x and earlier the argument gets passed
262 * in the thread structure itself. Yuck.
264 thread = current_thread();
265 cp = thread->reply_port;
266 thread->reply_port = PORT_NULL;
271 assert_wait((vm_offset_t)&cp->memreq.thread_status, TRUE);
274 if (thread_should_halt(current_thread()))
276 cmd = cp->memreq.cmd;
277 compressor_options = &cp->memreq.comp_opts[0];
278 len = compressor_options[1];
279 if (cmd == PPPIO_XCOMP) {
280 cp->memreq.returned_mem = cp->xcomp->comp_alloc(compressor_options, len);
281 if (!cp->memreq.returned_mem) {
282 cp->memreq.thread_status = ENOSR;
284 cp->memreq.thread_status = 0;
287 cp->memreq.returned_mem = cp->rcomp->decomp_alloc(compressor_options, len);
288 if (!cp->memreq.returned_mem) {
289 cp->memreq.thread_status = ENOSR;
291 cp->memreq.thread_status = 0;
299 /* here's the deal with memory allocation under Digital UNIX.
300 * Some other may also benefit from this...
301 * We can't ask for huge chunks of memory in a context where
302 * the caller can't be put to sleep (like, here.) The alloc
303 * is likely to fail. Instead we do this: the first time we
304 * get called, kick off a thread to do the allocation. Return
305 * immediately to the caller with EAGAIN, as an indication that
306 * they should send down the ioctl again. By the time the
307 * second call comes in it's likely that the memory allocation
308 * thread will have returned with the requested memory. We will
309 * continue to return EAGAIN however until the thread has completed.
310 * When it has, we return zero (and the memory) if the allocator
311 * was successful and ENOSR otherwise.
313 * Callers of the RCOMP and XCOMP ioctls are encouraged (but not
314 * required) to loop for some number of iterations with a small
315 * delay in the loop body (for instance a 1/10-th second "sleep"
328 struct compressor **comp;
329 struct ppp_stats *psp;
330 struct ppp_comp_stats *csp;
331 unsigned char *opt_data;
332 int nxslots, nrslots;
334 cp = (comp_state_t *) q->q_ptr;
336 DPRINT("cp == 0 in ppp_comp_wput\n");
341 switch (mp->b_datap->db_type) {
348 iop = (struct iocblk *) mp->b_rptr;
350 switch (iop->ioc_cmd) {
353 /* set/get CCP state */
354 if (iop->ioc_count != 2 * sizeof(int))
356 if (mp->b_cont == 0) {
357 DPRINT1("ppp_comp_wput/%d: PPPIO_CFLAGS b_cont = 0!\n", cp->unit);
360 flags = ((int *) mp->b_cont->b_rptr)[0];
361 mask = ((int *) mp->b_cont->b_rptr)[1];
362 cp->flags = (cp->flags & ~mask) | (flags & mask);
363 if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
364 if (cp->xstate != NULL) {
365 (*cp->xcomp->comp_free)(cp->xstate);
368 if (cp->rstate != NULL) {
369 (*cp->rcomp->decomp_free)(cp->rstate);
372 cp->flags &= ~CCP_ISUP;
375 iop->ioc_count = sizeof(int);
376 ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
377 mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
382 * Initialize VJ compressor/decompressor
384 if (iop->ioc_count != 2)
386 if (mp->b_cont == 0) {
387 DPRINT1("ppp_comp_wput/%d: PPPIO_VJINIT b_cont = 0!\n", cp->unit);
390 nxslots = mp->b_cont->b_rptr[0] + 1;
391 nrslots = mp->b_cont->b_rptr[1] + 1;
392 if (nxslots > MAX_STATES || nrslots > MAX_STATES)
394 vj_compress_init(&cp->vj_comp, nxslots);
395 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
402 if (iop->ioc_count <= 0)
404 if (mp->b_cont == 0) {
405 DPRINT1("ppp_comp_wput/%d: PPPIO_[XR]COMP b_cont = 0!\n", cp->unit);
408 opt_data = mp->b_cont->b_rptr;
409 len = mp->b_cont->b_wptr - opt_data;
410 if (len > iop->ioc_count)
411 len = iop->ioc_count;
412 if (opt_data[1] < 2 || opt_data[1] > len)
414 for (comp = ppp_compressors; *comp != NULL; ++comp)
415 if ((*comp)->compress_proto == opt_data[0]) {
416 /* here's the handler! */
419 if (iop->ioc_cmd == PPPIO_XCOMP) {
420 /* A previous call may have fetched memory for a compressor
421 * that's now being retired or reset. Free it using it's
422 * mechanism for freeing stuff.
424 if (cp->xstate != NULL) {
425 (*cp->xcomp->comp_free)(cp->xstate);
429 cp->xstate = (*comp)->comp_alloc(opt_data, len);
430 if (cp->xstate == NULL)
433 if (cp->rstate != NULL) {
434 (*cp->rcomp->decomp_free)(cp->rstate);
438 cp->rstate = (*comp)->decomp_alloc(opt_data, len);
439 if (cp->rstate == NULL)
443 if ((error = cp->memreq.thread_status) != EAGAIN)
444 if (iop->ioc_cmd == PPPIO_XCOMP) {
446 (*cp->xcomp->comp_free)(cp->xstate);
449 /* sanity check for compressor options
451 if (sizeof (cp->memreq.comp_opts) < len) {
452 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
454 cp->memreq.thread_status = ENOSR;
455 cp->memreq.returned_mem = 0;
457 /* fill in request for the thread and kick it off
459 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
460 bcopy(opt_data, cp->memreq.comp_opts, len);
461 cp->memreq.cmd = PPPIO_XCOMP;
463 error = cp->memreq.thread_status = EAGAIN;
464 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
466 cp->xstate = cp->memreq.returned_mem;
467 cp->memreq.returned_mem = 0;
468 cp->memreq.thread_status = 0;
472 (*cp->rcomp->decomp_free)(cp->rstate);
475 if (sizeof (cp->memreq.comp_opts) < len) {
476 printf("can't handle options for compressor %d (%d)\n", opt_data[0],
478 cp->memreq.thread_status = ENOSR;
479 cp->memreq.returned_mem = 0;
481 if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
482 bcopy(opt_data, cp->memreq.comp_opts, len);
483 cp->memreq.cmd = PPPIO_RCOMP;
485 error = cp->memreq.thread_status = EAGAIN;
486 thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
488 cp->rstate = cp->memreq.returned_mem;
489 cp->memreq.returned_mem = 0;
490 cp->memreq.thread_status = 0;
500 if ((cp->flags & LAST_MOD) == 0) {
501 error = -1; /* let the ppp_ahdl module handle it */
504 np = allocb(sizeof(struct ppp_stats), BPRI_HI);
512 psp = (struct ppp_stats *) np->b_wptr;
513 np->b_wptr += sizeof(struct ppp_stats);
514 iop->ioc_count = sizeof(struct ppp_stats);
516 psp->vj = cp->vj_comp.stats;
521 np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
529 csp = (struct ppp_comp_stats *) np->b_wptr;
530 np->b_wptr += sizeof(struct ppp_comp_stats);
531 iop->ioc_count = sizeof(struct ppp_comp_stats);
532 bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
534 (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
536 (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
541 if (iop->ioc_count != sizeof(int))
543 if (mp->b_cont == 0) {
544 DPRINT1("ppp_comp_wput/%d: PPPIO_DEBUG b_cont = 0!\n", cp->unit);
547 n = *(int *)mp->b_cont->b_rptr;
548 if (n == PPPDBG_LOG + PPPDBG_COMP) {
549 DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
559 cp->flags |= LAST_MOD;
570 else if (error == 0) {
571 mp->b_datap->db_type = M_IOCACK;
574 mp->b_datap->db_type = M_IOCNAK;
575 iop->ioc_error = error;
582 switch (*mp->b_rptr) {
584 cp->mtu = ((unsigned short *)mp->b_rptr)[1];
587 cp->mru = ((unsigned short *)mp->b_rptr)[1];
590 cp->unit = mp->b_rptr[1];
607 mblk_t *mp, *cmp = NULL;
609 int len, proto, type, hlen, code;
611 unsigned char *vjhdr, *dp;
613 cp = (comp_state_t *) q->q_ptr;
615 DPRINT("cp == 0 in ppp_comp_wsrv\n");
619 while ((mp = getq(q)) != 0) {
620 /* assert(mp->b_datap->db_type == M_DATA) */
622 if (!bcanputnext(q,mp->b_band))
632 * First check the packet length and work out what the protocol is.
635 if (len < PPP_HDRLEN) {
636 DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
638 cp->stats.ppp_oerrors++;
639 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
642 proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
645 * Make sure we've got enough data in the first mblk
646 * and that we are its only user.
648 if (proto == PPP_CCP)
650 else if (proto == PPP_IP)
651 hlen = PPP_HDRLEN + MAX_IPHDR;
656 if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
659 DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
660 cp->stats.ppp_oerrors++;
661 putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
667 * Do VJ compression if requested.
669 if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
670 ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
671 if (ip->ip_p == IPPROTO_TCP) {
672 type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
673 (cp->flags & COMP_VJCCID), &vjhdr);
675 case TYPE_UNCOMPRESSED_TCP:
676 mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
678 case TYPE_COMPRESSED_TCP:
679 dp = vjhdr - PPP_HDRLEN;
680 dp[1] = mp->b_rptr[1]; /* copy control field */
681 dp[0] = mp->b_rptr[0]; /* copy address field */
682 dp[2] = 0; /* set protocol field */
683 dp[3] = proto = PPP_VJC_COMP;
691 * Do packet compression if enabled.
693 if (proto == PPP_CCP)
694 ppp_comp_ccp(q, mp, 0);
695 else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
696 && cp->xstate != NULL) {
698 (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
699 (cp->flags & CCP_ISUP? cp->mtu + PPP_HDRLEN: 0));
702 cmp->b_band=mp->b_band;
710 * Do address/control and protocol compression if enabled.
712 if ((cp->flags & COMP_AC)
713 && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
714 mp->b_rptr += 2; /* drop the address & ctrl fields */
715 if (proto < 0x100 && (cp->flags & COMP_PROT))
716 ++mp->b_rptr; /* drop the high protocol byte */
717 } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
718 /* shuffle up the address & ctrl fields */
719 mp->b_rptr[2] = mp->b_rptr[1];
720 mp->b_rptr[1] = mp->b_rptr[0];
724 cp->stats.ppp_opackets++;
725 cp->stats.ppp_obytes += msgdsize(mp);
739 struct ppp_stats *psp;
741 cp = (comp_state_t *) q->q_ptr;
743 DPRINT("cp == 0 in ppp_comp_rput\n");
748 switch (mp->b_datap->db_type) {
755 iop = (struct iocblk *) mp->b_rptr;
756 switch (iop->ioc_cmd) {
759 * Catch this on the way back from the ppp_ahdl module
760 * so we can fill in the VJ stats.
762 if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
764 psp = (struct ppp_stats *) mp->b_cont->b_rptr;
765 psp->vj = cp->vj_comp.stats;
772 switch (mp->b_rptr[0]) {
774 ++cp->stats.ppp_ierrors;
777 ++cp->stats.ppp_oerrors;
795 mblk_t *mp, *dmp = NULL, *np;
798 int len, hlen, vjlen;
801 cp = (comp_state_t *) q->q_ptr;
803 DPRINT("cp == 0 in ppp_comp_rsrv\n");
807 while ((mp = getq(q)) != 0) {
808 /* assert(mp->b_datap->db_type == M_DATA) */
809 if (!canputnext(q)) {
815 cp->stats.ppp_ibytes += len;
816 cp->stats.ppp_ipackets++;
819 * First work out the protocol and where the PPP header ends.
822 proto = MSG_BYTE(mp, 0);
823 if (proto == PPP_ALLSTATIONS) {
825 proto = MSG_BYTE(mp, 2);
827 if ((proto & 1) == 0) {
829 proto = (proto << 8) + MSG_BYTE(mp, i);
834 * Now reconstruct a complete, contiguous PPP header at the
835 * start of the packet.
837 if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
838 + ((cp->flags & DECOMP_PROT)? 1: 2)) {
842 if (mp->b_rptr + hlen > mp->b_wptr) {
843 adjmsg(mp, hlen); /* XXX check this call */
846 if (hlen != PPP_HDRLEN) {
848 * We need to put some bytes on the front of the packet
849 * to make a full-length PPP header.
850 * If we can put them in *mp, we do, otherwise we
851 * tack another mblk on the front.
852 * XXX we really shouldn't need to carry around
853 * the address and control at this stage.
855 dp = mp->b_rptr + hlen - PPP_HDRLEN;
856 if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
857 np = allocb(PPP_HDRLEN, BPRI_MED);
864 mp->b_wptr += PPP_HDRLEN;
868 dp[0] = PPP_ALLSTATIONS;
875 * Now see if we have a compressed packet to decompress,
876 * or a CCP packet to take notice of.
878 proto = PPP_PROTOCOL(mp->b_rptr);
879 if (proto == PPP_CCP) {
881 if (mp->b_wptr < mp->b_rptr + len) {
886 ppp_comp_ccp(q, mp, 1);
887 } else if (proto == PPP_COMP) {
888 if ((cp->flags & CCP_ISUP)
889 && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
890 && (cp->flags & CCP_ERR) == 0) {
891 rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
897 /* no error, but no packet returned either. */
902 cp->flags |= CCP_ERROR;
903 ++cp->stats.ppp_ierrors;
904 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
906 case DECOMP_FATALERROR:
907 cp->flags |= CCP_FATALERROR;
908 ++cp->stats.ppp_ierrors;
909 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
913 } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
914 (*cp->rcomp->incomp)(cp->rstate, mp);
918 * Now do VJ decompression.
920 proto = PPP_PROTOCOL(mp->b_rptr);
921 if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
922 len = msgdsize(mp) - PPP_HDRLEN;
923 if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
927 * Advance past the ppp header.
928 * Here we assume that the whole PPP header is in the first mblk.
931 dp = np->b_rptr + PPP_HDRLEN;
932 if (dp >= mp->b_wptr) {
938 * Make sure we have sufficient contiguous data at this point.
940 hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
943 if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
944 PULLUP(mp, hlen + PPP_HDRLEN);
948 dp = np->b_rptr + PPP_HDRLEN;
951 if (proto == PPP_VJC_COMP) {
953 * Decompress VJ-compressed packet.
954 * First reset compressor if an input error has occurred.
956 if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
957 if (cp->flags & DBGLOG)
958 DPRINT1("ppp%d: resetting VJ\n", cp->unit);
959 vj_uncompress_err(&cp->vj_comp);
960 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
963 vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
964 &cp->vj_comp, &iphdr, &iphlen);
966 if (cp->flags & DBGLOG)
967 DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
969 ++cp->vj_last_ierrors; /* so we don't reset next time */
973 /* drop ppp and vj headers off */
978 mp->b_rptr = dp + vjlen;
980 /* allocate a new mblk for the ppp and ip headers */
981 if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
983 dp = np->b_rptr; /* prepend mblk with TCP/IP hdr */
984 dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
988 bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
989 np->b_wptr = dp + iphlen + PPP_HDRLEN;
992 /* XXX there seems to be a bug which causes panics in strread
993 if we make an mbuf with only the IP header in it :-( */
994 if (mp->b_wptr - mp->b_rptr > 4) {
995 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
999 bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
1000 mp->b_wptr - mp->b_rptr);
1001 np->b_wptr += mp->b_wptr - mp->b_rptr;
1002 np->b_cont = mp->b_cont;
1010 * "Decompress" a VJ-uncompressed packet.
1012 cp->vj_last_ierrors = cp->stats.ppp_ierrors;
1013 if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
1014 if (cp->flags & DBGLOG)
1015 DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
1017 ++cp->vj_last_ierrors; /* don't need to reset next time */
1020 mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
1030 cp->stats.ppp_ierrors++;
1031 putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
1038 * Handle a CCP packet being sent or received.
1039 * Here all the data in the packet is in a single mbuf.
1042 ppp_comp_ccp(q, mp, rcvd)
1052 if (len < PPP_HDRLEN + CCP_HDRLEN)
1055 cp = (comp_state_t *) q->q_ptr;
1056 dp = mp->b_rptr + PPP_HDRLEN;
1058 clen = CCP_LENGTH(dp);
1062 switch (CCP_CODE(dp)) {
1066 cp->flags &= ~CCP_ISUP;
1070 if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
1071 && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
1072 && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
1074 if (cp->xstate != NULL
1075 && (*cp->xcomp->comp_init)
1076 (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1077 cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
1078 cp->flags |= CCP_COMP_RUN;
1080 if (cp->rstate != NULL
1081 && (*cp->rcomp->decomp_init)
1082 (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
1083 cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
1084 cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
1090 if (cp->flags & CCP_ISUP) {
1092 if (cp->xstate && (cp->flags & CCP_COMP_RUN))
1093 (*cp->xcomp->comp_reset)(cp->xstate);
1095 if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
1096 (*cp->rcomp->decomp_reset)(cp->rstate);
1097 cp->flags &= ~CCP_ERROR;
1113 DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
1114 DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
1115 DPRINT2(" base=%x lim=%x", db->db_base, db->db_lim);
1116 DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
1127 while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
1131 return mp->b_rptr[i];