ppp-comp.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  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. *
  35. * $Id: ppp-comp.h,v 1.13 2002/12/06 09:49:15 paulus Exp $
  36. */
  37. #ifndef _NET_PPP_COMP_H
  38. #define _NET_PPP_COMP_H
  39. /*
  40. * The following symbols control whether we include code for
  41. * various compression methods.
  42. */
  43. #ifndef DO_BSD_COMPRESS
  44. #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
  45. #endif
  46. #ifndef DO_DEFLATE
  47. #define DO_DEFLATE 1 /* by default, include Deflate */
  48. #endif
  49. #define DO_PREDICTOR_1 0
  50. #define DO_PREDICTOR_2 0
  51. /*
  52. * Structure giving methods for compression/decompression.
  53. */
  54. #ifdef PACKETPTR
  55. struct compressor {
  56. int compress_proto; /* CCP compression protocol number */
  57. /* Allocate space for a compressor (transmit side) */
  58. void *(*comp_alloc) __P((u_char *options, int opt_len));
  59. /* Free space used by a compressor */
  60. void (*comp_free) __P((void *state));
  61. /* Initialize a compressor */
  62. int (*comp_init) __P((void *state, u_char *options, int opt_len,
  63. int unit, int hdrlen, int debug));
  64. /* Reset a compressor */
  65. void (*comp_reset) __P((void *state));
  66. /* Compress a packet */
  67. int (*compress) __P((void *state, PACKETPTR *mret,
  68. PACKETPTR mp, int orig_len, int max_len));
  69. /* Return compression statistics */
  70. void (*comp_stat) __P((void *state, struct compstat *stats));
  71. /* Allocate space for a decompressor (receive side) */
  72. void *(*decomp_alloc) __P((u_char *options, int opt_len));
  73. /* Free space used by a decompressor */
  74. void (*decomp_free) __P((void *state));
  75. /* Initialize a decompressor */
  76. int (*decomp_init) __P((void *state, u_char *options, int opt_len,
  77. int unit, int hdrlen, int mru, int debug));
  78. /* Reset a decompressor */
  79. void (*decomp_reset) __P((void *state));
  80. /* Decompress a packet. */
  81. int (*decompress) __P((void *state, PACKETPTR mp,
  82. PACKETPTR *dmpp));
  83. /* Update state for an incompressible packet received */
  84. void (*incomp) __P((void *state, PACKETPTR mp));
  85. /* Return decompression statistics */
  86. void (*decomp_stat) __P((void *state, struct compstat *stats));
  87. };
  88. #endif /* PACKETPTR */
  89. /*
  90. * Return values for decompress routine.
  91. * We need to make these distinctions so that we can disable certain
  92. * useful functionality, namely sending a CCP reset-request as a result
  93. * of an error detected after decompression. This is to avoid infringing
  94. * a patent held by Motorola.
  95. * Don't you just lurve software patents.
  96. */
  97. #define DECOMP_OK 0 /* everything went OK */
  98. #define DECOMP_ERROR 1 /* error detected before decomp. */
  99. #define DECOMP_FATALERROR 2 /* error detected after decomp. */
  100. /*
  101. * CCP codes.
  102. */
  103. #define CCP_CONFREQ 1
  104. #define CCP_CONFACK 2
  105. #define CCP_TERMREQ 5
  106. #define CCP_TERMACK 6
  107. #define CCP_RESETREQ 14
  108. #define CCP_RESETACK 15
  109. /*
  110. * Max # bytes for a CCP option
  111. */
  112. #define CCP_MAX_OPTION_LENGTH 32
  113. /*
  114. * Parts of a CCP packet.
  115. */
  116. #define CCP_CODE(dp) ((dp)[0])
  117. #define CCP_ID(dp) ((dp)[1])
  118. #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
  119. #define CCP_HDRLEN 4
  120. #define CCP_OPT_CODE(dp) ((dp)[0])
  121. #define CCP_OPT_LENGTH(dp) ((dp)[1])
  122. #define CCP_OPT_MINLEN 2
  123. /*
  124. * Definitions for BSD-Compress.
  125. */
  126. #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
  127. #define CILEN_BSD_COMPRESS 3 /* length of config. option */
  128. /* Macros for handling the 3rd byte of the BSD-Compress config option. */
  129. #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
  130. #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
  131. #define BSD_CURRENT_VERSION 1 /* current version number */
  132. #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
  133. #define BSD_MIN_BITS 9 /* smallest code size supported */
  134. #define BSD_MAX_BITS 15 /* largest code size supported */
  135. /*
  136. * Definitions for Deflate.
  137. */
  138. #define CI_DEFLATE 26 /* config option for Deflate */
  139. #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
  140. #define CILEN_DEFLATE 4 /* length of its config option */
  141. #define DEFLATE_MIN_SIZE 8
  142. #define DEFLATE_MAX_SIZE 15
  143. #define DEFLATE_METHOD_VAL 8
  144. #define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE)
  145. #define DEFLATE_METHOD(x) ((x) & 0x0F)
  146. #define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \
  147. + DEFLATE_METHOD_VAL)
  148. #define DEFLATE_CHK_SEQUENCE 0
  149. /*
  150. * Definitions for MPPE.
  151. */
  152. #define CI_MPPE 18 /* config option for MPPE */
  153. #define CILEN_MPPE 6 /* length of config option */
  154. /*
  155. * Definitions for other, as yet unsupported, compression methods.
  156. */
  157. #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
  158. #define CILEN_PREDICTOR_1 2 /* length of its config option */
  159. #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
  160. #define CILEN_PREDICTOR_2 2 /* length of its config option */
  161. #endif /* _NET_PPP_COMP_H */