Debian Codegraph @

include/linux/ppp-comp.h

raw
1 /*
2 * ppp-comp.h - Definitions for doing PPP packet compression.
3 *
4 * Copyright (c) 1994-2024 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 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
19 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
21 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
23 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
24 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 */
26
27 #ifndef _NET_PPP_COMP_H
28 #define _NET_PPP_COMP_H
29
30 /*
31 * The following symbols control whether we include code for
32 * various compression methods.
33 */
34
35 #ifndef DO_BSD_COMPRESS
36 #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
37 #endif
38 #ifndef DO_DEFLATE
39 #define DO_DEFLATE 1 /* by default, include Deflate */
40 #endif
41 #define DO_PREDICTOR_1 0
42 #define DO_PREDICTOR_2 0
43
44 /*
45 * Structure giving methods for compression/decompression.
46 */
47
48 struct compressor {
49 int compress_proto; /* CCP compression protocol number */
50
51 /* Allocate space for a compressor (transmit side) */
52 void *(*comp_alloc) (unsigned char *options, int opt_len);
53
54 /* Free space used by a compressor */
55 void (*comp_free) (void *state);
56
57 /* Initialize a compressor */
58 int (*comp_init) (void *state, unsigned char *options,
59 int opt_len, int unit, int opthdr, int debug);
60
61 /* Reset a compressor */
62 void (*comp_reset) (void *state);
63
64 /* Compress a packet */
65 int (*compress) (void *state, unsigned char *rptr,
66 unsigned char *obuf, int isize, int osize);
67
68 /* Return compression statistics */
69 void (*comp_stat) (void *state, struct compstat *stats);
70
71 /* Allocate space for a decompressor (receive side) */
72 void *(*decomp_alloc) (unsigned char *options, int opt_len);
73
74 /* Free space used by a decompressor */
75 void (*decomp_free) (void *state);
76
77 /* Initialize a decompressor */
78 int (*decomp_init) (void *state, unsigned char *options,
79 int opt_len, int unit, int opthdr, int mru,
80 int debug);
81
82 /* Reset a decompressor */
83 void (*decomp_reset) (void *state);
84
85 /* Decompress a packet. */
86 int (*decompress) (void *state, unsigned char *ibuf, int isize,
87 unsigned char *obuf, int osize);
88
89 /* Update state for an incompressible packet received */
90 void (*incomp) (void *state, unsigned char *ibuf, int icnt);
91
92 /* Return decompression statistics */
93 void (*decomp_stat) (void *state, struct compstat *stats);
94 };
95
96 /*
97 * The return value from decompress routine is the length of the
98 * decompressed packet if successful, otherwise DECOMP_ERROR
99 * or DECOMP_FATALERROR if an error occurred.
100 *
101 * We need to make this distinction so that we can disable certain
102 * useful functionality, namely sending a CCP reset-request as a result
103 * of an error detected after decompression. This is to avoid infringing
104 * a patent held by Motorola.
105 * Don't you just lurve software patents.
106 */
107
108 #define DECOMP_ERROR -1 /* error detected before decomp. */
109 #define DECOMP_FATALERROR -2 /* error detected after decomp. */
110
111 /*
112 * CCP codes.
113 */
114
115 #define CCP_CONFREQ 1
116 #define CCP_CONFACK 2
117 #define CCP_TERMREQ 5
118 #define CCP_TERMACK 6
119 #define CCP_RESETREQ 14
120 #define CCP_RESETACK 15
121
122 /*
123 * Max # bytes for a CCP option
124 */
125
126 #define CCP_MAX_OPTION_LENGTH 32
127
128 /*
129 * Parts of a CCP packet.
130 */
131
132 #define CCP_CODE(dp) ((dp)[0])
133 #define CCP_ID(dp) ((dp)[1])
134 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
135 #define CCP_HDRLEN 4
136
137 #define CCP_OPT_CODE(dp) ((dp)[0])
138 #define CCP_OPT_LENGTH(dp) ((dp)[1])
139 #define CCP_OPT_MINLEN 2
140
141 /*
142 * Definitions for BSD-Compress.
143 */
144
145 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
146 #define CILEN_BSD_COMPRESS 3 /* length of config. option */
147
148 /* Macros for handling the 3rd byte of the BSD-Compress config option. */
149 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
150 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
151 #define BSD_CURRENT_VERSION 1 /* current version number */
152 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
153
154 #define BSD_MIN_BITS 9 /* smallest code size supported */
155 #define BSD_MAX_BITS 15 /* largest code size supported */
156
157 /*
158 * Definitions for Deflate.
159 */
160
161 #define CI_DEFLATE 26 /* config option for Deflate */
162 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
163 #define CILEN_DEFLATE 4 /* length of its config option */
164
165 #define DEFLATE_MIN_SIZE 8
166 #define DEFLATE_MAX_SIZE 15
167 #define DEFLATE_METHOD_VAL 8
168 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
169 #define DEFLATE_METHOD(x) ((x) & 0x0F)
170 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
171 + DEFLATE_METHOD_VAL)
172 #define DEFLATE_CHK_SEQUENCE 0
173
174 /*
175 * Definitions for MPPE.
176 */
177
178 #define CI_MPPE 18 /* config option for MPPE */
179 #define CILEN_MPPE 6 /* length of config option */
180
181 /*
182 * Definitions for other, as yet unsupported, compression methods.
183 */
184
185 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
186 #define CILEN_PREDICTOR_1 2 /* length of its config option */
187 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
188 #define CILEN_PREDICTOR_2 2 /* length of its config option */
189
190 #endif /* _NET_PPP_COMP_H */