ppp-comp.h revision 1.14 1 1.14 matt /* $NetBSD: ppp-comp.h,v 1.14 2008/02/20 17:05:53 matt Exp $ */
2 1.1 paulus
3 1.1 paulus /*
4 1.1 paulus * ppp-comp.h - Definitions for doing PPP packet compression.
5 1.1 paulus *
6 1.8 itojun * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
7 1.1 paulus *
8 1.8 itojun * Redistribution and use in source and binary forms, with or without
9 1.8 itojun * modification, are permitted provided that the following conditions
10 1.8 itojun * are met:
11 1.8 itojun *
12 1.8 itojun * 1. Redistributions of source code must retain the above copyright
13 1.8 itojun * notice, this list of conditions and the following disclaimer.
14 1.8 itojun *
15 1.8 itojun * 2. Redistributions in binary form must reproduce the above copyright
16 1.8 itojun * notice, this list of conditions and the following disclaimer in
17 1.8 itojun * the documentation and/or other materials provided with the
18 1.8 itojun * distribution.
19 1.8 itojun *
20 1.8 itojun * 3. The name(s) of the authors of this software must not be used to
21 1.8 itojun * endorse or promote products derived from this software without
22 1.8 itojun * prior written permission.
23 1.8 itojun *
24 1.8 itojun * 4. Redistributions of any form whatsoever must retain the following
25 1.8 itojun * acknowledgment:
26 1.8 itojun * "This product includes software developed by Paul Mackerras
27 1.8 itojun * <paulus (at) samba.org>".
28 1.8 itojun *
29 1.8 itojun * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
30 1.8 itojun * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31 1.8 itojun * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
32 1.8 itojun * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
33 1.8 itojun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
34 1.8 itojun * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
35 1.8 itojun * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36 1.1 paulus */
37 1.1 paulus
38 1.12 elad #ifndef _NET_PPP_COMP_H_
39 1.12 elad #define _NET_PPP_COMP_H_
40 1.1 paulus
41 1.1 paulus /*
42 1.1 paulus * The following symbols control whether we include code for
43 1.1 paulus * various compression methods.
44 1.1 paulus */
45 1.1 paulus #ifndef DO_BSD_COMPRESS
46 1.1 paulus #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
47 1.1 paulus #endif
48 1.2 paulus #ifndef DO_DEFLATE
49 1.2 paulus #define DO_DEFLATE 1 /* by default, include Deflate */
50 1.2 paulus #endif
51 1.2 paulus #define DO_PREDICTOR_1 0
52 1.2 paulus #define DO_PREDICTOR_2 0
53 1.9 christos
54 1.9 christos /*
55 1.9 christos * How many entries to make available in the compressors table
56 1.9 christos */
57 1.9 christos #ifndef PPP_COMPRESSORS_MAX
58 1.9 christos #define PPP_COMPRESSORS_MAX 8
59 1.9 christos #endif
60 1.1 paulus
61 1.1 paulus /*
62 1.1 paulus * Structure giving methods for compression/decompression.
63 1.1 paulus */
64 1.1 paulus #ifdef PACKETPTR
65 1.1 paulus struct compressor {
66 1.1 paulus int compress_proto; /* CCP compression protocol number */
67 1.1 paulus
68 1.1 paulus /* Allocate space for a compressor (transmit side) */
69 1.13 thorpej void *(*comp_alloc)(u_char *, int);
70 1.1 paulus /* Free space used by a compressor */
71 1.13 thorpej void (*comp_free)(void *);
72 1.1 paulus /* Initialize a compressor */
73 1.13 thorpej int (*comp_init)(void *, u_char *, int, int, int, int);
74 1.1 paulus /* Reset a compressor */
75 1.13 thorpej void (*comp_reset)(void *);
76 1.1 paulus /* Compress a packet */
77 1.13 thorpej int (*compress)(void *, PACKETPTR *, PACKETPTR, int, int);
78 1.1 paulus /* Return compression statistics */
79 1.13 thorpej void (*comp_stat)(void *, struct compstat *);
80 1.1 paulus
81 1.1 paulus /* Allocate space for a decompressor (receive side) */
82 1.13 thorpej void *(*decomp_alloc)(u_char *, int);
83 1.1 paulus /* Free space used by a decompressor */
84 1.13 thorpej void (*decomp_free)(void *);
85 1.1 paulus /* Initialize a decompressor */
86 1.13 thorpej int (*decomp_init)(void *, u_char *, int, int, int, int, int);
87 1.1 paulus /* Reset a decompressor */
88 1.13 thorpej void (*decomp_reset)(void *);
89 1.1 paulus /* Decompress a packet. */
90 1.13 thorpej int (*decompress)(void *, PACKETPTR, PACKETPTR *);
91 1.1 paulus /* Update state for an incompressible packet received */
92 1.13 thorpej void (*incomp)(void *, PACKETPTR);
93 1.1 paulus /* Return decompression statistics */
94 1.13 thorpej void (*decomp_stat)(void *, struct compstat *);
95 1.1 paulus };
96 1.1 paulus #endif /* PACKETPTR */
97 1.1 paulus
98 1.1 paulus /*
99 1.1 paulus * Return values for decompress routine.
100 1.1 paulus * We need to make these distinctions so that we can disable certain
101 1.1 paulus * useful functionality, namely sending a CCP reset-request as a result
102 1.1 paulus * of an error detected after decompression. This is to avoid infringing
103 1.1 paulus * a patent held by Motorola.
104 1.1 paulus * Don't you just lurve software patents.
105 1.1 paulus */
106 1.1 paulus #define DECOMP_OK 0 /* everything went OK */
107 1.1 paulus #define DECOMP_ERROR 1 /* error detected before decomp. */
108 1.1 paulus #define DECOMP_FATALERROR 2 /* error detected after decomp. */
109 1.1 paulus
110 1.1 paulus /*
111 1.1 paulus * CCP codes.
112 1.1 paulus */
113 1.1 paulus #define CCP_CONFREQ 1
114 1.1 paulus #define CCP_CONFACK 2
115 1.6 christos #define CCP_CONFNAK 3
116 1.6 christos #define CCP_CONFREJ 4
117 1.1 paulus #define CCP_TERMREQ 5
118 1.1 paulus #define CCP_TERMACK 6
119 1.1 paulus #define CCP_RESETREQ 14
120 1.1 paulus #define CCP_RESETACK 15
121 1.1 paulus
122 1.1 paulus /*
123 1.1 paulus * Max # bytes for a CCP option
124 1.1 paulus */
125 1.5 christos #define CCP_MAX_OPTION_LENGTH 64
126 1.1 paulus
127 1.1 paulus /*
128 1.1 paulus * Parts of a CCP packet.
129 1.1 paulus */
130 1.1 paulus #define CCP_CODE(dp) ((dp)[0])
131 1.1 paulus #define CCP_ID(dp) ((dp)[1])
132 1.1 paulus #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
133 1.1 paulus #define CCP_HDRLEN 4
134 1.1 paulus
135 1.1 paulus #define CCP_OPT_CODE(dp) ((dp)[0])
136 1.1 paulus #define CCP_OPT_LENGTH(dp) ((dp)[1])
137 1.1 paulus #define CCP_OPT_MINLEN 2
138 1.1 paulus
139 1.1 paulus /*
140 1.1 paulus * Definitions for BSD-Compress.
141 1.1 paulus */
142 1.1 paulus #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
143 1.1 paulus #define CILEN_BSD_COMPRESS 3 /* length of config. option */
144 1.1 paulus
145 1.1 paulus /* Macros for handling the 3rd byte of the BSD-Compress config option. */
146 1.1 paulus #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
147 1.1 paulus #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
148 1.1 paulus #define BSD_CURRENT_VERSION 1 /* current version number */
149 1.1 paulus #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
150 1.1 paulus
151 1.1 paulus #define BSD_MIN_BITS 9 /* smallest code size supported */
152 1.1 paulus #define BSD_MAX_BITS 15 /* largest code size supported */
153 1.2 paulus
154 1.2 paulus /*
155 1.3 christos * Definitions for Deflate.
156 1.2 paulus */
157 1.4 christos #define CI_DEFLATE 26 /* config option for Deflate */
158 1.4 christos #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
159 1.4 christos
160 1.2 paulus #define CILEN_DEFLATE 4 /* length of its config option */
161 1.2 paulus
162 1.2 paulus #define DEFLATE_MIN_SIZE 8
163 1.2 paulus #define DEFLATE_MAX_SIZE 15
164 1.2 paulus #define DEFLATE_METHOD_VAL 8
165 1.2 paulus #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
166 1.2 paulus #define DEFLATE_METHOD(x) ((x) & 0x0F)
167 1.2 paulus #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
168 1.2 paulus + DEFLATE_METHOD_VAL)
169 1.2 paulus #define DEFLATE_CHK_SEQUENCE 0
170 1.3 christos
171 1.3 christos /*
172 1.11 cube * Definitions for MPPE.
173 1.11 cube */
174 1.11 cube #define CI_MPPE 18 /* config option for MPPE */
175 1.11 cube #define CILEN_MPPE 6 /* length of config option */
176 1.11 cube
177 1.11 cube #define MPPE_PAD 4 /* MPPE growth per frame */
178 1.11 cube #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */
179 1.11 cube
180 1.11 cube /* option bits for ccp_options.mppe */
181 1.11 cube #define MPPE_OPT_40 0x01 /* 40 bit */
182 1.11 cube #define MPPE_OPT_128 0x02 /* 128 bit */
183 1.11 cube #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */
184 1.11 cube /* unsupported opts */
185 1.11 cube #define MPPE_OPT_56 0x08 /* 56 bit */
186 1.11 cube #define MPPE_OPT_MPPC 0x10 /* MPPC compression */
187 1.11 cube #define MPPE_OPT_D 0x20 /* Unknown */
188 1.11 cube #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D)
189 1.11 cube #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */
190 1.11 cube
191 1.11 cube /*
192 1.11 cube * This is not nice ... the alternative is a bitfield struct though.
193 1.11 cube * And unfortunately, we cannot share the same bits for the option
194 1.14 matt * names above since C and H are the same bit. We could do a uint32_t
195 1.11 cube * but then we have to do a htonl() all the time and/or we still need
196 1.11 cube * to know which octet is which.
197 1.11 cube */
198 1.11 cube #define MPPE_C_BIT 0x01 /* MPPC */
199 1.11 cube #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */
200 1.11 cube #define MPPE_L_BIT 0x20 /* 40-bit */
201 1.11 cube #define MPPE_S_BIT 0x40 /* 128-bit */
202 1.11 cube #define MPPE_M_BIT 0x80 /* 56-bit, not supported */
203 1.11 cube #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */
204 1.11 cube
205 1.11 cube /* Does not include H bit; used for least significant octet only. */
206 1.11 cube #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT)
207 1.11 cube
208 1.11 cube /* Build a CI from mppe opts (see RFC 3078) */
209 1.11 cube #define MPPE_OPTS_TO_CI(opts, ci) \
210 1.11 cube do { \
211 1.11 cube u_char *ptr = ci; /* u_char[4] */ \
212 1.11 cube \
213 1.11 cube /* H bit */ \
214 1.11 cube if (opts & MPPE_OPT_STATEFUL) \
215 1.11 cube *ptr++ = 0x0; \
216 1.11 cube else \
217 1.11 cube *ptr++ = MPPE_H_BIT; \
218 1.11 cube *ptr++ = 0; \
219 1.11 cube *ptr++ = 0; \
220 1.11 cube \
221 1.11 cube /* S,L bits */ \
222 1.11 cube *ptr = 0; \
223 1.11 cube if (opts & MPPE_OPT_128) \
224 1.11 cube *ptr |= MPPE_S_BIT; \
225 1.11 cube if (opts & MPPE_OPT_40) \
226 1.11 cube *ptr |= MPPE_L_BIT; \
227 1.11 cube /* M,D,C bits not supported */ \
228 1.11 cube } while (/* CONSTCOND */ 0)
229 1.11 cube
230 1.11 cube /* The reverse of the above */
231 1.11 cube #define MPPE_CI_TO_OPTS(ci, opts) \
232 1.11 cube do { \
233 1.11 cube u_char *ptr = ci; /* u_char[4] */ \
234 1.11 cube \
235 1.11 cube opts = 0; \
236 1.11 cube \
237 1.11 cube /* H bit */ \
238 1.11 cube if (!(ptr[0] & MPPE_H_BIT)) \
239 1.11 cube opts |= MPPE_OPT_STATEFUL; \
240 1.11 cube \
241 1.11 cube /* S,L bits */ \
242 1.11 cube if (ptr[3] & MPPE_S_BIT) \
243 1.11 cube opts |= MPPE_OPT_128; \
244 1.11 cube if (ptr[3] & MPPE_L_BIT) \
245 1.11 cube opts |= MPPE_OPT_40; \
246 1.11 cube \
247 1.11 cube /* M,D,C bits */ \
248 1.11 cube if (ptr[3] & MPPE_M_BIT) \
249 1.11 cube opts |= MPPE_OPT_56; \
250 1.11 cube if (ptr[3] & MPPE_D_BIT) \
251 1.11 cube opts |= MPPE_OPT_D; \
252 1.11 cube if (ptr[3] & MPPE_C_BIT) \
253 1.11 cube opts |= MPPE_OPT_MPPC; \
254 1.11 cube \
255 1.11 cube /* Other bits */ \
256 1.11 cube if (ptr[0] & ~MPPE_H_BIT) \
257 1.11 cube opts |= MPPE_OPT_UNKNOWN; \
258 1.11 cube if (ptr[1] || ptr[2]) \
259 1.11 cube opts |= MPPE_OPT_UNKNOWN; \
260 1.11 cube if (ptr[3] & ~MPPE_ALL_BITS) \
261 1.11 cube opts |= MPPE_OPT_UNKNOWN; \
262 1.11 cube } while (/* CONSTCOND */ 0)
263 1.11 cube
264 1.11 cube /*
265 1.3 christos * Definitions for other, as yet unsupported, compression methods.
266 1.3 christos */
267 1.3 christos #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
268 1.3 christos #define CILEN_PREDICTOR_1 2 /* length of its config option */
269 1.3 christos #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
270 1.3 christos #define CILEN_PREDICTOR_2 2 /* length of its config option */
271 1.1 paulus
272 1.12 elad #endif /* !_NET_PPP_COMP_H_ */
273