1 1.16 cube /* $NetBSD: ppp-comp.h,v 1.16 2008/11/29 23:15:20 cube 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.15 cube #include <sys/queue.h> 66 1.15 cube 67 1.1 paulus struct compressor { 68 1.1 paulus int compress_proto; /* CCP compression protocol number */ 69 1.1 paulus 70 1.1 paulus /* Allocate space for a compressor (transmit side) */ 71 1.13 thorpej void *(*comp_alloc)(u_char *, int); 72 1.1 paulus /* Free space used by a compressor */ 73 1.13 thorpej void (*comp_free)(void *); 74 1.1 paulus /* Initialize a compressor */ 75 1.13 thorpej int (*comp_init)(void *, u_char *, int, int, int, int); 76 1.1 paulus /* Reset a compressor */ 77 1.13 thorpej void (*comp_reset)(void *); 78 1.1 paulus /* Compress a packet */ 79 1.13 thorpej int (*compress)(void *, PACKETPTR *, PACKETPTR, int, int); 80 1.1 paulus /* Return compression statistics */ 81 1.13 thorpej void (*comp_stat)(void *, struct compstat *); 82 1.1 paulus 83 1.1 paulus /* Allocate space for a decompressor (receive side) */ 84 1.13 thorpej void *(*decomp_alloc)(u_char *, int); 85 1.1 paulus /* Free space used by a decompressor */ 86 1.13 thorpej void (*decomp_free)(void *); 87 1.1 paulus /* Initialize a decompressor */ 88 1.13 thorpej int (*decomp_init)(void *, u_char *, int, int, int, int, int); 89 1.1 paulus /* Reset a decompressor */ 90 1.13 thorpej void (*decomp_reset)(void *); 91 1.1 paulus /* Decompress a packet. */ 92 1.13 thorpej int (*decompress)(void *, PACKETPTR, PACKETPTR *); 93 1.1 paulus /* Update state for an incompressible packet received */ 94 1.13 thorpej void (*incomp)(void *, PACKETPTR); 95 1.1 paulus /* Return decompression statistics */ 96 1.13 thorpej void (*decomp_stat)(void *, struct compstat *); 97 1.15 cube 98 1.15 cube LIST_ENTRY(compressor) comp_list; 99 1.16 cube unsigned int comp_refcnt; 100 1.1 paulus }; 101 1.1 paulus #endif /* PACKETPTR */ 102 1.1 paulus 103 1.1 paulus /* 104 1.1 paulus * Return values for decompress routine. 105 1.1 paulus * We need to make these distinctions so that we can disable certain 106 1.1 paulus * useful functionality, namely sending a CCP reset-request as a result 107 1.1 paulus * of an error detected after decompression. This is to avoid infringing 108 1.1 paulus * a patent held by Motorola. 109 1.1 paulus * Don't you just lurve software patents. 110 1.1 paulus */ 111 1.1 paulus #define DECOMP_OK 0 /* everything went OK */ 112 1.1 paulus #define DECOMP_ERROR 1 /* error detected before decomp. */ 113 1.1 paulus #define DECOMP_FATALERROR 2 /* error detected after decomp. */ 114 1.1 paulus 115 1.1 paulus /* 116 1.1 paulus * CCP codes. 117 1.1 paulus */ 118 1.1 paulus #define CCP_CONFREQ 1 119 1.1 paulus #define CCP_CONFACK 2 120 1.6 christos #define CCP_CONFNAK 3 121 1.6 christos #define CCP_CONFREJ 4 122 1.1 paulus #define CCP_TERMREQ 5 123 1.1 paulus #define CCP_TERMACK 6 124 1.1 paulus #define CCP_RESETREQ 14 125 1.1 paulus #define CCP_RESETACK 15 126 1.1 paulus 127 1.1 paulus /* 128 1.1 paulus * Max # bytes for a CCP option 129 1.1 paulus */ 130 1.5 christos #define CCP_MAX_OPTION_LENGTH 64 131 1.1 paulus 132 1.1 paulus /* 133 1.1 paulus * Parts of a CCP packet. 134 1.1 paulus */ 135 1.1 paulus #define CCP_CODE(dp) ((dp)[0]) 136 1.1 paulus #define CCP_ID(dp) ((dp)[1]) 137 1.1 paulus #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3]) 138 1.1 paulus #define CCP_HDRLEN 4 139 1.1 paulus 140 1.1 paulus #define CCP_OPT_CODE(dp) ((dp)[0]) 141 1.1 paulus #define CCP_OPT_LENGTH(dp) ((dp)[1]) 142 1.1 paulus #define CCP_OPT_MINLEN 2 143 1.1 paulus 144 1.1 paulus /* 145 1.1 paulus * Definitions for BSD-Compress. 146 1.1 paulus */ 147 1.1 paulus #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */ 148 1.1 paulus #define CILEN_BSD_COMPRESS 3 /* length of config. option */ 149 1.1 paulus 150 1.1 paulus /* Macros for handling the 3rd byte of the BSD-Compress config option. */ 151 1.1 paulus #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */ 152 1.1 paulus #define BSD_VERSION(x) ((x) >> 5) /* version of option format */ 153 1.1 paulus #define BSD_CURRENT_VERSION 1 /* current version number */ 154 1.1 paulus #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n)) 155 1.1 paulus 156 1.1 paulus #define BSD_MIN_BITS 9 /* smallest code size supported */ 157 1.1 paulus #define BSD_MAX_BITS 15 /* largest code size supported */ 158 1.2 paulus 159 1.2 paulus /* 160 1.3 christos * Definitions for Deflate. 161 1.2 paulus */ 162 1.4 christos #define CI_DEFLATE 26 /* config option for Deflate */ 163 1.4 christos #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */ 164 1.4 christos 165 1.2 paulus #define CILEN_DEFLATE 4 /* length of its config option */ 166 1.2 paulus 167 1.2 paulus #define DEFLATE_MIN_SIZE 8 168 1.2 paulus #define DEFLATE_MAX_SIZE 15 169 1.2 paulus #define DEFLATE_METHOD_VAL 8 170 1.2 paulus #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE) 171 1.2 paulus #define DEFLATE_METHOD(x) ((x) & 0x0F) 172 1.2 paulus #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \ 173 1.2 paulus + DEFLATE_METHOD_VAL) 174 1.2 paulus #define DEFLATE_CHK_SEQUENCE 0 175 1.3 christos 176 1.3 christos /* 177 1.11 cube * Definitions for MPPE. 178 1.11 cube */ 179 1.11 cube #define CI_MPPE 18 /* config option for MPPE */ 180 1.11 cube #define CILEN_MPPE 6 /* length of config option */ 181 1.11 cube 182 1.11 cube #define MPPE_PAD 4 /* MPPE growth per frame */ 183 1.11 cube #define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ 184 1.11 cube 185 1.11 cube /* option bits for ccp_options.mppe */ 186 1.11 cube #define MPPE_OPT_40 0x01 /* 40 bit */ 187 1.11 cube #define MPPE_OPT_128 0x02 /* 128 bit */ 188 1.11 cube #define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ 189 1.11 cube /* unsupported opts */ 190 1.11 cube #define MPPE_OPT_56 0x08 /* 56 bit */ 191 1.11 cube #define MPPE_OPT_MPPC 0x10 /* MPPC compression */ 192 1.11 cube #define MPPE_OPT_D 0x20 /* Unknown */ 193 1.11 cube #define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) 194 1.11 cube #define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ 195 1.11 cube 196 1.11 cube /* 197 1.11 cube * This is not nice ... the alternative is a bitfield struct though. 198 1.11 cube * And unfortunately, we cannot share the same bits for the option 199 1.14 matt * names above since C and H are the same bit. We could do a uint32_t 200 1.11 cube * but then we have to do a htonl() all the time and/or we still need 201 1.11 cube * to know which octet is which. 202 1.11 cube */ 203 1.11 cube #define MPPE_C_BIT 0x01 /* MPPC */ 204 1.11 cube #define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ 205 1.11 cube #define MPPE_L_BIT 0x20 /* 40-bit */ 206 1.11 cube #define MPPE_S_BIT 0x40 /* 128-bit */ 207 1.11 cube #define MPPE_M_BIT 0x80 /* 56-bit, not supported */ 208 1.11 cube #define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ 209 1.11 cube 210 1.11 cube /* Does not include H bit; used for least significant octet only. */ 211 1.11 cube #define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) 212 1.11 cube 213 1.11 cube /* Build a CI from mppe opts (see RFC 3078) */ 214 1.11 cube #define MPPE_OPTS_TO_CI(opts, ci) \ 215 1.11 cube do { \ 216 1.11 cube u_char *ptr = ci; /* u_char[4] */ \ 217 1.11 cube \ 218 1.11 cube /* H bit */ \ 219 1.11 cube if (opts & MPPE_OPT_STATEFUL) \ 220 1.11 cube *ptr++ = 0x0; \ 221 1.11 cube else \ 222 1.11 cube *ptr++ = MPPE_H_BIT; \ 223 1.11 cube *ptr++ = 0; \ 224 1.11 cube *ptr++ = 0; \ 225 1.11 cube \ 226 1.11 cube /* S,L bits */ \ 227 1.11 cube *ptr = 0; \ 228 1.11 cube if (opts & MPPE_OPT_128) \ 229 1.11 cube *ptr |= MPPE_S_BIT; \ 230 1.11 cube if (opts & MPPE_OPT_40) \ 231 1.11 cube *ptr |= MPPE_L_BIT; \ 232 1.11 cube /* M,D,C bits not supported */ \ 233 1.11 cube } while (/* CONSTCOND */ 0) 234 1.11 cube 235 1.11 cube /* The reverse of the above */ 236 1.11 cube #define MPPE_CI_TO_OPTS(ci, opts) \ 237 1.11 cube do { \ 238 1.11 cube u_char *ptr = ci; /* u_char[4] */ \ 239 1.11 cube \ 240 1.11 cube opts = 0; \ 241 1.11 cube \ 242 1.11 cube /* H bit */ \ 243 1.11 cube if (!(ptr[0] & MPPE_H_BIT)) \ 244 1.11 cube opts |= MPPE_OPT_STATEFUL; \ 245 1.11 cube \ 246 1.11 cube /* S,L bits */ \ 247 1.11 cube if (ptr[3] & MPPE_S_BIT) \ 248 1.11 cube opts |= MPPE_OPT_128; \ 249 1.11 cube if (ptr[3] & MPPE_L_BIT) \ 250 1.11 cube opts |= MPPE_OPT_40; \ 251 1.11 cube \ 252 1.11 cube /* M,D,C bits */ \ 253 1.11 cube if (ptr[3] & MPPE_M_BIT) \ 254 1.11 cube opts |= MPPE_OPT_56; \ 255 1.11 cube if (ptr[3] & MPPE_D_BIT) \ 256 1.11 cube opts |= MPPE_OPT_D; \ 257 1.11 cube if (ptr[3] & MPPE_C_BIT) \ 258 1.11 cube opts |= MPPE_OPT_MPPC; \ 259 1.11 cube \ 260 1.11 cube /* Other bits */ \ 261 1.11 cube if (ptr[0] & ~MPPE_H_BIT) \ 262 1.11 cube opts |= MPPE_OPT_UNKNOWN; \ 263 1.11 cube if (ptr[1] || ptr[2]) \ 264 1.11 cube opts |= MPPE_OPT_UNKNOWN; \ 265 1.11 cube if (ptr[3] & ~MPPE_ALL_BITS) \ 266 1.11 cube opts |= MPPE_OPT_UNKNOWN; \ 267 1.11 cube } while (/* CONSTCOND */ 0) 268 1.11 cube 269 1.11 cube /* 270 1.3 christos * Definitions for other, as yet unsupported, compression methods. 271 1.3 christos */ 272 1.3 christos #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */ 273 1.3 christos #define CILEN_PREDICTOR_1 2 /* length of its config option */ 274 1.3 christos #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ 275 1.3 christos #define CILEN_PREDICTOR_2 2 /* length of its config option */ 276 1.1 paulus 277 1.12 elad #endif /* !_NET_PPP_COMP_H_ */ 278