blob: b09ef710fc39533a4fa8673d14ea33ed205dc68e [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * ppp-comp.h - Definitions for doing PPP packet compression.
3 *
4 * Copyright (c) 1984 Paul Mackerras. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
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
16 * distribution.
17 *
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.
21 *
22 * 4. Redistributions of any form whatsoever must retain the following
23 * acknowledgment:
24 * "This product includes software developed by Paul Mackerras
25 * <paulus@samba.org>".
26 *
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.
34 *
xf.li84027492024-04-09 00:17:51 -070035 * $Id: ppp-comp.h,v 1.13 2002/12/06 09:49:15 paulus Exp $
lh9ed821d2023-04-07 01:36:19 -070036 */
37
38#ifndef _NET_PPP_COMP_H
39#define _NET_PPP_COMP_H
40
41/*
42 * The following symbols control whether we include code for
43 * various compression methods.
44 */
45#ifndef DO_BSD_COMPRESS
46#define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
47#endif
48#ifndef DO_DEFLATE
49#define DO_DEFLATE 1 /* by default, include Deflate */
50#endif
51#define DO_PREDICTOR_1 0
52#define DO_PREDICTOR_2 0
53
54/*
55 * Structure giving methods for compression/decompression.
56 */
57#ifdef PACKETPTR
58struct compressor {
59 int compress_proto; /* CCP compression protocol number */
60
61 /* Allocate space for a compressor (transmit side) */
xf.li84027492024-04-09 00:17:51 -070062 void *(*comp_alloc)(u_char *options, int opt_len);
lh9ed821d2023-04-07 01:36:19 -070063 /* Free space used by a compressor */
xf.li84027492024-04-09 00:17:51 -070064 void (*comp_free)(void *state);
lh9ed821d2023-04-07 01:36:19 -070065 /* Initialize a compressor */
xf.li84027492024-04-09 00:17:51 -070066 int (*comp_init)(void *state, u_char *options, int opt_len,
67 int unit, int hdrlen, int debug);
lh9ed821d2023-04-07 01:36:19 -070068 /* Reset a compressor */
xf.li84027492024-04-09 00:17:51 -070069 void (*comp_reset)(void *state);
lh9ed821d2023-04-07 01:36:19 -070070 /* Compress a packet */
xf.li84027492024-04-09 00:17:51 -070071 int (*compress)(void *state, PACKETPTR *mret,
72 PACKETPTR mp, int orig_len, int max_len);
lh9ed821d2023-04-07 01:36:19 -070073 /* Return compression statistics */
xf.li84027492024-04-09 00:17:51 -070074 void (*comp_stat)(void *state, struct compstat *stats);
lh9ed821d2023-04-07 01:36:19 -070075
76 /* Allocate space for a decompressor (receive side) */
xf.li84027492024-04-09 00:17:51 -070077 void *(*decomp_alloc)(u_char *options, int opt_len);
lh9ed821d2023-04-07 01:36:19 -070078 /* Free space used by a decompressor */
xf.li84027492024-04-09 00:17:51 -070079 void (*decomp_free)(void *state);
lh9ed821d2023-04-07 01:36:19 -070080 /* Initialize a decompressor */
xf.li84027492024-04-09 00:17:51 -070081 int (*decomp_init)(void *state, u_char *options, int opt_len,
82 int unit, int hdrlen, int mru, int debug);
lh9ed821d2023-04-07 01:36:19 -070083 /* Reset a decompressor */
xf.li84027492024-04-09 00:17:51 -070084 void (*decomp_reset)(void *state);
lh9ed821d2023-04-07 01:36:19 -070085 /* Decompress a packet. */
xf.li84027492024-04-09 00:17:51 -070086 int (*decompress)(void *state, PACKETPTR mp,
87 PACKETPTR *dmpp);
lh9ed821d2023-04-07 01:36:19 -070088 /* Update state for an incompressible packet received */
xf.li84027492024-04-09 00:17:51 -070089 void (*incomp)(void *state, PACKETPTR mp);
lh9ed821d2023-04-07 01:36:19 -070090 /* Return decompression statistics */
xf.li84027492024-04-09 00:17:51 -070091 void (*decomp_stat)(void *state, struct compstat *stats);
lh9ed821d2023-04-07 01:36:19 -070092};
93#endif /* PACKETPTR */
94
95/*
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.
102 */
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. */
106
107/*
108 * CCP codes.
109 */
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
116
117/*
118 * Max # bytes for a CCP option
119 */
120#define CCP_MAX_OPTION_LENGTH 32
121
122/*
123 * Parts of a CCP packet.
124 */
125#define CCP_CODE(dp) ((dp)[0])
126#define CCP_ID(dp) ((dp)[1])
127#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
128#define CCP_HDRLEN 4
129
130#define CCP_OPT_CODE(dp) ((dp)[0])
131#define CCP_OPT_LENGTH(dp) ((dp)[1])
132#define CCP_OPT_MINLEN 2
133
134/*
135 * Definitions for BSD-Compress.
136 */
137#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
138#define CILEN_BSD_COMPRESS 3 /* length of config. option */
139
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))
145
146#define BSD_MIN_BITS 9 /* smallest code size supported */
147#define BSD_MAX_BITS 15 /* largest code size supported */
148
149/*
150 * Definitions for Deflate.
151 */
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 */
155
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
164
165/*
166 * Definitions for MPPE.
167 */
168#define CI_MPPE 18 /* config option for MPPE */
169#define CILEN_MPPE 6 /* length of config option */
170
171/*
172 * Definitions for other, as yet unsupported, compression methods.
173 */
174#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
175#define CILEN_PREDICTOR_1 2 /* length of its config option */
176#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
177#define CILEN_PREDICTOR_2 2 /* length of its config option */
178
179#endif /* _NET_PPP_COMP_H */