1 /* $NetBSD: ppp-comp.h,v 1.9 2003/03/27 17:50:28 christos Exp $ */ 2 3 /* 4 * ppp-comp.h - Definitions for doing PPP packet compression. 5 * 6 * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The name(s) of the authors of this software must not be used to 21 * endorse or promote products derived from this software without 22 * prior written permission. 23 * 24 * 4. Redistributions of any form whatsoever must retain the following 25 * acknowledgment: 26 * "This product includes software developed by Paul Mackerras 27 * <paulus@samba.org>". 28 * 29 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 30 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 31 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 32 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 33 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 34 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 35 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 36 */ 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 * How many entries to make available in the compressors table 56 */ 57 #ifndef PPP_COMPRESSORS_MAX 58 #define PPP_COMPRESSORS_MAX 8 59 #endif 60 61 /* 62 * Structure giving methods for compression/decompression. 63 */ 64 #ifdef PACKETPTR 65 struct compressor { 66 int compress_proto; /* CCP compression protocol number */ 67 68 /* Allocate space for a compressor (transmit side) */ 69 void *(*comp_alloc) __P((u_char *options, int opt_len)); 70 /* Free space used by a compressor */ 71 void (*comp_free) __P((void *state)); 72 /* Initialize a compressor */ 73 int (*comp_init) __P((void *state, u_char *options, int opt_len, 74 int unit, int hdrlen, int debug)); 75 /* Reset a compressor */ 76 void (*comp_reset) __P((void *state)); 77 /* Compress a packet */ 78 int (*compress) __P((void *state, PACKETPTR *mret, 79 PACKETPTR mp, int orig_len, int max_len)); 80 /* Return compression statistics */ 81 void (*comp_stat) __P((void *state, struct compstat *stats)); 82 83 /* Allocate space for a decompressor (receive side) */ 84 void *(*decomp_alloc) __P((u_char *options, int opt_len)); 85 /* Free space used by a decompressor */ 86 void (*decomp_free) __P((void *state)); 87 /* Initialize a decompressor */ 88 int (*decomp_init) __P((void *state, u_char *options, int opt_len, 89 int unit, int hdrlen, int mru, int debug)); 90 /* Reset a decompressor */ 91 void (*decomp_reset) __P((void *state)); 92 /* Decompress a packet. */ 93 int (*decompress) __P((void *state, PACKETPTR mp, 94 PACKETPTR *dmpp)); 95 /* Update state for an incompressible packet received */ 96 void (*incomp) __P((void *state, PACKETPTR mp)); 97 /* Return decompression statistics */ 98 void (*decomp_stat) __P((void *state, struct compstat *stats)); 99 }; 100 #endif /* PACKETPTR */ 101 102 /* 103 * Return values for decompress routine. 104 * We need to make these distinctions so that we can disable certain 105 * useful functionality, namely sending a CCP reset-request as a result 106 * of an error detected after decompression. This is to avoid infringing 107 * a patent held by Motorola. 108 * Don't you just lurve software patents. 109 */ 110 #define DECOMP_OK 0 /* everything went OK */ 111 #define DECOMP_ERROR 1 /* error detected before decomp. */ 112 #define DECOMP_FATALERROR 2 /* error detected after decomp. */ 113 114 /* 115 * CCP codes. 116 */ 117 #define CCP_CONFREQ 1 118 #define CCP_CONFACK 2 119 #define CCP_CONFNAK 3 120 #define CCP_CONFREJ 4 121 #define CCP_TERMREQ 5 122 #define CCP_TERMACK 6 123 #define CCP_RESETREQ 14 124 #define CCP_RESETACK 15 125 126 /* 127 * Max # bytes for a CCP option 128 */ 129 #define CCP_MAX_OPTION_LENGTH 64 130 131 /* 132 * Parts of a CCP packet. 133 */ 134 #define CCP_CODE(dp) ((dp)[0]) 135 #define CCP_ID(dp) ((dp)[1]) 136 #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3]) 137 #define CCP_HDRLEN 4 138 139 #define CCP_OPT_CODE(dp) ((dp)[0]) 140 #define CCP_OPT_LENGTH(dp) ((dp)[1]) 141 #define CCP_OPT_MINLEN 2 142 143 /* 144 * Definitions for BSD-Compress. 145 */ 146 #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */ 147 #define CILEN_BSD_COMPRESS 3 /* length of config. option */ 148 149 /* Macros for handling the 3rd byte of the BSD-Compress config option. */ 150 #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */ 151 #define BSD_VERSION(x) ((x) >> 5) /* version of option format */ 152 #define BSD_CURRENT_VERSION 1 /* current version number */ 153 #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n)) 154 155 #define BSD_MIN_BITS 9 /* smallest code size supported */ 156 #define BSD_MAX_BITS 15 /* largest code size supported */ 157 158 /* 159 * Definitions for Deflate. 160 */ 161 #define CI_DEFLATE 26 /* config option for Deflate */ 162 #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */ 163 164 #define CILEN_DEFLATE 4 /* length of its config option */ 165 166 #define DEFLATE_MIN_SIZE 8 167 #define DEFLATE_MAX_SIZE 15 168 #define DEFLATE_METHOD_VAL 8 169 #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE) 170 #define DEFLATE_METHOD(x) ((x) & 0x0F) 171 #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \ 172 + DEFLATE_METHOD_VAL) 173 #define DEFLATE_CHK_SEQUENCE 0 174 175 /* 176 * Definitions for other, as yet unsupported, compression methods. 177 */ 178 #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */ 179 #define CILEN_PREDICTOR_1 2 /* length of its config option */ 180 #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ 181 #define CILEN_PREDICTOR_2 2 /* length of its config option */ 182 183 #endif /* _NET_PPP_COMP_H */ 184