ppp-comp.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * ppp-comp.h - Definitions for doing PPP packet compression.
  3. *
  4. * Copyright (c) 1994 The Australian National University.
  5. * All rights reserved.
  6. *
  7. * Permission to use, copy, modify, and distribute this software and its
  8. * documentation is hereby granted, provided that the above copyright
  9. * notice appears in all copies. This software is provided without any
  10. * warranty, express or implied. The Australian National University
  11. * makes no representations about the suitability of this software for
  12. * any purpose.
  13. *
  14. * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
  15. * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  16. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  17. * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
  18. * OF SUCH DAMAGE.
  19. *
  20. * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  21. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  23. * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
  24. * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
  25. * OR MODIFICATIONS.
  26. *
  27. * $Id: ppp-comp.h,v 1.6 1997/11/27 06:04:44 paulus Exp $
  28. */
  29. /*
  30. * ==FILEVERSION 980319==
  31. *
  32. * NOTE TO MAINTAINERS:
  33. * If you modify this file at all, please set the above date.
  34. * ppp-comp.h is shipped with a PPP distribution as well as with the kernel;
  35. * if everyone increases the FILEVERSION number above, then scripts
  36. * can do the right thing when deciding whether to install a new ppp-comp.h
  37. * file. Don't change the format of that line otherwise, so the
  38. * installation script can recognize it.
  39. */
  40. #ifndef _NET_PPP_COMP_H
  41. #define _NET_PPP_COMP_H
  42. struct module;
  43. /*
  44. * The following symbols control whether we include code for
  45. * various compression methods.
  46. */
  47. #ifndef DO_BSD_COMPRESS
  48. #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
  49. #endif
  50. #ifndef DO_DEFLATE
  51. #define DO_DEFLATE 1 /* by default, include Deflate */
  52. #endif
  53. #define DO_PREDICTOR_1 0
  54. #define DO_PREDICTOR_2 0
  55. /*
  56. * Structure giving methods for compression/decompression.
  57. */
  58. struct compressor {
  59. int compress_proto; /* CCP compression protocol number */
  60. /* Allocate space for a compressor (transmit side) */
  61. void *(*comp_alloc) (unsigned char *options, int opt_len);
  62. /* Free space used by a compressor */
  63. void (*comp_free) (void *state);
  64. /* Initialize a compressor */
  65. int (*comp_init) (void *state, unsigned char *options,
  66. int opt_len, int unit, int opthdr, int debug);
  67. /* Reset a compressor */
  68. void (*comp_reset) (void *state);
  69. /* Compress a packet */
  70. int (*compress) (void *state, unsigned char *rptr,
  71. unsigned char *obuf, int isize, int osize);
  72. /* Return compression statistics */
  73. void (*comp_stat) (void *state, struct compstat *stats);
  74. /* Allocate space for a decompressor (receive side) */
  75. void *(*decomp_alloc) (unsigned char *options, int opt_len);
  76. /* Free space used by a decompressor */
  77. void (*decomp_free) (void *state);
  78. /* Initialize a decompressor */
  79. int (*decomp_init) (void *state, unsigned char *options,
  80. int opt_len, int unit, int opthdr, int mru,
  81. int debug);
  82. /* Reset a decompressor */
  83. void (*decomp_reset) (void *state);
  84. /* Decompress a packet. */
  85. int (*decompress) (void *state, unsigned char *ibuf, int isize,
  86. unsigned char *obuf, int osize);
  87. /* Update state for an incompressible packet received */
  88. void (*incomp) (void *state, unsigned char *ibuf, int icnt);
  89. /* Return decompression statistics */
  90. void (*decomp_stat) (void *state, struct compstat *stats);
  91. /* Used in locking compressor modules */
  92. struct module *owner;
  93. };
  94. /*
  95. * The return value from decompress routine is the length of the
  96. * decompressed packet if successful, otherwise DECOMP_ERROR
  97. * or DECOMP_FATALERROR if an error occurred.
  98. *
  99. * We need to make this distinction so that we can disable certain
  100. * useful functionality, namely sending a CCP reset-request as a result
  101. * of an error detected after decompression. This is to avoid infringing
  102. * a patent held by Motorola.
  103. * Don't you just lurve software patents.
  104. */
  105. #define DECOMP_ERROR -1 /* error detected before decomp. */
  106. #define DECOMP_FATALERROR -2 /* error detected after decomp. */
  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. * Max # bytes for a CCP option
  118. */
  119. #define CCP_MAX_OPTION_LENGTH 32
  120. /*
  121. * Parts of a CCP packet.
  122. */
  123. #define CCP_CODE(dp) ((dp)[0])
  124. #define CCP_ID(dp) ((dp)[1])
  125. #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
  126. #define CCP_HDRLEN 4
  127. #define CCP_OPT_CODE(dp) ((dp)[0])
  128. #define CCP_OPT_LENGTH(dp) ((dp)[1])
  129. #define CCP_OPT_MINLEN 2
  130. /*
  131. * Definitions for BSD-Compress.
  132. */
  133. #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
  134. #define CILEN_BSD_COMPRESS 3 /* length of config. option */
  135. /* Macros for handling the 3rd byte of the BSD-Compress config option. */
  136. #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
  137. #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
  138. #define BSD_CURRENT_VERSION 1 /* current version number */
  139. #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
  140. #define BSD_MIN_BITS 9 /* smallest code size supported */
  141. #define BSD_MAX_BITS 15 /* largest code size supported */
  142. /*
  143. * Definitions for Deflate.
  144. */
  145. #define CI_DEFLATE 26 /* config option for Deflate */
  146. #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
  147. #define CILEN_DEFLATE 4 /* length of its config option */
  148. #define DEFLATE_MIN_SIZE 9
  149. #define DEFLATE_MAX_SIZE 15
  150. #define DEFLATE_METHOD_VAL 8
  151. #define DEFLATE_SIZE(x) (((x) >> 4) + 8)
  152. #define DEFLATE_METHOD(x) ((x) & 0x0F)
  153. #define DEFLATE_MAKE_OPT(w) ((((w) - 8) << 4) + DEFLATE_METHOD_VAL)
  154. #define DEFLATE_CHK_SEQUENCE 0
  155. /*
  156. * Definitions for other, as yet unsupported, compression methods.
  157. */
  158. #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
  159. #define CILEN_PREDICTOR_1 2 /* length of its config option */
  160. #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
  161. #define CILEN_PREDICTOR_2 2 /* length of its config option */
  162. #ifdef __KERNEL__
  163. extern int ppp_register_compressor(struct compressor *);
  164. extern void ppp_unregister_compressor(struct compressor *);
  165. #endif /* __KERNEL__ */
  166. #endif /* _NET_PPP_COMP_H */