2 * ppp-comp.h - Definitions for doing PPP packet compression.
4 * Copyright (c) 1984 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.
35 * $Id: ppp-comp.h,v 1.13 2002/12/06 09:49:15 paulus Exp $
38 #ifndef _NET_PPP_COMP_H
39 #define _NET_PPP_COMP_H
42 * The following symbols control whether we include code for
43 * various compression methods.
45 #ifndef DO_BSD_COMPRESS
46 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
49 #define DO_DEFLATE 1 /* by default, include Deflate */
51 #define DO_PREDICTOR_1 0
52 #define DO_PREDICTOR_2 0
55 * Structure giving methods for compression/decompression.
59 int compress_proto; /* CCP compression protocol number */
61 /* Allocate space for a compressor (transmit side) */
62 void *(*comp_alloc) __P((u_char *options, int opt_len));
63 /* Free space used by a compressor */
64 void (*comp_free) __P((void *state));
65 /* Initialize a compressor */
66 int (*comp_init) __P((void *state, u_char *options, int opt_len,
67 int unit, int hdrlen, int debug));
68 /* Reset a compressor */
69 void (*comp_reset) __P((void *state));
70 /* Compress a packet */
71 int (*compress) __P((void *state, PACKETPTR *mret,
72 PACKETPTR mp, int orig_len, int max_len));
73 /* Return compression statistics */
74 void (*comp_stat) __P((void *state, struct compstat *stats));
76 /* Allocate space for a decompressor (receive side) */
77 void *(*decomp_alloc) __P((u_char *options, int opt_len));
78 /* Free space used by a decompressor */
79 void (*decomp_free) __P((void *state));
80 /* Initialize a decompressor */
81 int (*decomp_init) __P((void *state, u_char *options, int opt_len,
82 int unit, int hdrlen, int mru, int debug));
83 /* Reset a decompressor */
84 void (*decomp_reset) __P((void *state));
85 /* Decompress a packet. */
86 int (*decompress) __P((void *state, PACKETPTR mp,
88 /* Update state for an incompressible packet received */
89 void (*incomp) __P((void *state, PACKETPTR mp));
90 /* Return decompression statistics */
91 void (*decomp_stat) __P((void *state, struct compstat *stats));
93 #endif /* PACKETPTR */
96 * Return values for decompress routine.
97 * We need to make these distinctions so that we can disable certain
98 * useful functionality, namely sending a CCP reset-request as a result
99 * of an error detected after decompression. This is to avoid infringing
100 * a patent held by Motorola.
101 * Don't you just lurve software patents.
103 #define DECOMP_OK 0 /* everything went OK */
104 #define DECOMP_ERROR 1 /* error detected before decomp. */
105 #define DECOMP_FATALERROR 2 /* error detected after decomp. */
110 #define CCP_CONFREQ 1
111 #define CCP_CONFACK 2
112 #define CCP_TERMREQ 5
113 #define CCP_TERMACK 6
114 #define CCP_RESETREQ 14
115 #define CCP_RESETACK 15
118 * Max # bytes for a CCP option
120 #define CCP_MAX_OPTION_LENGTH 32
123 * Parts of a CCP packet.
125 #define CCP_CODE(dp) ((dp)[0])
126 #define CCP_ID(dp) ((dp)[1])
127 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
130 #define CCP_OPT_CODE(dp) ((dp)[0])
131 #define CCP_OPT_LENGTH(dp) ((dp)[1])
132 #define CCP_OPT_MINLEN 2
135 * Definitions for BSD-Compress.
137 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
138 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
140 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
141 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
142 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
143 #define BSD_CURRENT_VERSION 1 /* current version number */
144 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
146 #define BSD_MIN_BITS 9 /* smallest code size supported */
147 #define BSD_MAX_BITS 15 /* largest code size supported */
150 * Definitions for Deflate.
152 #define CI_DEFLATE 26 /* config option for Deflate */
153 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
154 #define CILEN_DEFLATE 4 /* length of its config option */
156 #define DEFLATE_MIN_SIZE 8
157 #define DEFLATE_MAX_SIZE 15
158 #define DEFLATE_METHOD_VAL 8
159 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
160 #define DEFLATE_METHOD(x) ((x) & 0x0F)
161 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
162 + DEFLATE_METHOD_VAL)
163 #define DEFLATE_CHK_SEQUENCE 0
166 * Definitions for MPPE.
168 #define CI_MPPE 18 /* config option for MPPE */
169 #define CILEN_MPPE 6 /* length of config option */
171 #define MPPE_PAD 4 /* MPPE growth per frame */
172 #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
174 /* option bits for ccp_options.mppe */
175 #define MPPE_OPT_40 0x01 /* 40 bit */
176 #define MPPE_OPT_128 0x02 /* 128 bit */
177 #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
178 /* unsupported opts */
179 #define MPPE_OPT_56 0x08 /* 56 bit */
180 #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
181 #define MPPE_OPT_D 0x20 /* Unknown */
182 #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
183 #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
186 * This is not nice ... the alternative is a bitfield struct though.
187 * And unfortunately, we cannot share the same bits for the option
188 * names above since C and H are the same bit. We could do a u_int32
189 * but then we have to do a htonl() all the time and/or we still need
190 * to know which octet is which.
192 #define MPPE_C_BIT 0x01 /* MPPC */
193 #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
194 #define MPPE_L_BIT 0x20 /* 40-bit */
195 #define MPPE_S_BIT 0x40 /* 128-bit */
196 #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
197 #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
199 /* Does not include H bit; used for least significant octet only. */
200 #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
202 /* Build a CI from mppe opts (see RFC 3078) */
203 #define MPPE_OPTS_TO_CI(opts, ci) \
205 u_char *ptr = ci; /* u_char[4] */ \
208 if (opts & MPPE_OPT_STATEFUL) \
211 *ptr++ = MPPE_H_BIT; \
217 if (opts & MPPE_OPT_128) \
218 *ptr |= MPPE_S_BIT; \
219 if (opts & MPPE_OPT_40) \
220 *ptr |= MPPE_L_BIT; \
221 /* M,D,C bits not supported */ \
222 } while (/* CONSTCOND */ 0)
224 /* The reverse of the above */
225 #define MPPE_CI_TO_OPTS(ci, opts) \
227 u_char *ptr = ci; /* u_char[4] */ \
232 if (!(ptr[0] & MPPE_H_BIT)) \
233 opts |= MPPE_OPT_STATEFUL; \
236 if (ptr[3] & MPPE_S_BIT) \
237 opts |= MPPE_OPT_128; \
238 if (ptr[3] & MPPE_L_BIT) \
239 opts |= MPPE_OPT_40; \
242 if (ptr[3] & MPPE_M_BIT) \
243 opts |= MPPE_OPT_56; \
244 if (ptr[3] & MPPE_D_BIT) \
245 opts |= MPPE_OPT_D; \
246 if (ptr[3] & MPPE_C_BIT) \
247 opts |= MPPE_OPT_MPPC; \
250 if (ptr[0] & ~MPPE_H_BIT) \
251 opts |= MPPE_OPT_UNKNOWN; \
252 if (ptr[1] || ptr[2]) \
253 opts |= MPPE_OPT_UNKNOWN; \
254 if (ptr[3] & ~MPPE_ALL_BITS) \
255 opts |= MPPE_OPT_UNKNOWN; \
256 } while (/* CONSTCOND */ 0)
259 * Definitions for other, as yet unsupported, compression methods.
261 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
262 #define CILEN_PREDICTOR_1 2 /* length of its config option */
263 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
264 #define CILEN_PREDICTOR_2 2 /* length of its config option */
266 #endif /* _NET_PPP_COMP_H */