2 * Input/Output VJ Compressed packets
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * $Id: vjcomp.c,v 1.24 1999/01/28 01:56:34 brian Exp $
24 #include <sys/param.h>
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
27 #include <netinet/ip.h>
37 #include "slcompress.h"
42 #include "throughput.h"
48 #include "descriptor.h"
56 #define MAX_VJHEADER 16 /* Maximum size of compressed header */
59 vj_SendFrame(struct link *l, struct mbuf * bp, struct bundle *bundle)
63 u_short cproto = bundle->ncp.ipcp.peer_compproto >> 16;
65 log_Printf(LogDEBUG, "vj_SendFrame: COMPPROTO = %x\n",
66 bundle->ncp.ipcp.peer_compproto);
67 if (((struct ip *) MBUF_CTOP(bp))->ip_p == IPPROTO_TCP
68 && cproto == PROTO_VJCOMP) {
69 type = sl_compress_tcp(bp, (struct ip *)MBUF_CTOP(bp),
70 &bundle->ncp.ipcp.vj.cslc,
71 &bundle->ncp.ipcp.vj.slstat,
72 bundle->ncp.ipcp.peer_compproto & 0xff);
73 log_Printf(LogDEBUG, "vj_SendFrame: type = %x\n", type);
78 case TYPE_UNCOMPRESSED_TCP:
79 proto = PROTO_VJUNCOMP;
81 case TYPE_COMPRESSED_TCP:
85 log_Printf(LogALERT, "Unknown frame type %x\n", type);
92 if (!ccp_Compress(&l->ccp, l, PRI_NORMAL, proto, bp))
93 hdlc_Output(l, PRI_NORMAL, proto, bp);
97 VjUncompressTcp(struct ipcp *ipcp, struct mbuf * bp, u_char type)
102 u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
104 olen = len = mbuf_Length(bp);
105 if (type == TYPE_UNCOMPRESSED_TCP) {
108 * Uncompressed packet does NOT change its size, so that we can use mbuf
109 * space for uncompression job.
111 bufp = MBUF_CTOP(bp);
112 len = sl_uncompress_tcp(&bufp, len, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
113 (ipcp->my_compproto >> 8) & 255);
122 * Handle compressed packet. 1) Read upto MAX_VJHEADER bytes into work
123 * space. 2) Try to uncompress it. 3) Compute amount of necesary space. 4)
124 * Copy unread data info there.
126 if (len > MAX_VJHEADER)
129 bufp = work + MAX_HDR;
130 bp = mbuf_Read(bp, bufp, rlen);
131 len = sl_uncompress_tcp(&bufp, olen, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
132 (ipcp->my_compproto >> 8) & 255);
139 nbp = mbuf_Alloc(len, MB_VJCOMP);
140 memcpy(MBUF_CTOP(nbp), bufp, len);
146 vj_Input(struct ipcp *ipcp, struct mbuf *bp, int proto)
150 log_Printf(LogDEBUG, "vj_Input: proto %02x\n", proto);
151 log_DumpBp(LogDEBUG, "Raw packet info:", bp);
155 type = TYPE_COMPRESSED_TCP;
158 type = TYPE_UNCOMPRESSED_TCP;
161 log_Printf(LogWARN, "vj_Input...???\n");
164 bp = VjUncompressTcp(ipcp, bp, type);
169 vj2asc(u_int32_t val)
171 static char asc[50]; /* The return value is used immediately */
174 snprintf(asc, sizeof asc, "%d VJ slots %s slot compression",
175 (int)((val>>8)&15)+1, val & 1 ? "with" : "without");
177 strcpy(asc, "VJ disabled");