ppp-comp.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * ppp-comp.h - Definitions for doing PPP packet compression.
  3. *
  4. * Copyright 1994-1998 Paul Mackerras.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. */
  10. #ifndef _NET_PPP_COMP_H
  11. #define _NET_PPP_COMP_H
  12. struct module;
  13. /*
  14. * The following symbols control whether we include code for
  15. * various compression methods.
  16. */
  17. #ifndef DO_BSD_COMPRESS
  18. #define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */
  19. #endif
  20. #ifndef DO_DEFLATE
  21. #define DO_DEFLATE 1 /* by default, include Deflate */
  22. #endif
  23. #define DO_PREDICTOR_1 0
  24. #define DO_PREDICTOR_2 0
  25. /*
  26. * Structure giving methods for compression/decompression.
  27. */
  28. struct compressor {
  29. int compress_proto; /* CCP compression protocol number */
  30. /* Allocate space for a compressor (transmit side) */
  31. void *(*comp_alloc) (unsigned char *options, int opt_len);
  32. /* Free space used by a compressor */
  33. void (*comp_free) (void *state);
  34. /* Initialize a compressor */
  35. int (*comp_init) (void *state, unsigned char *options,
  36. int opt_len, int unit, int opthdr, int debug);
  37. /* Reset a compressor */
  38. void (*comp_reset) (void *state);
  39. /* Compress a packet */
  40. int (*compress) (void *state, unsigned char *rptr,
  41. unsigned char *obuf, int isize, int osize);
  42. /* Return compression statistics */
  43. void (*comp_stat) (void *state, struct compstat *stats);
  44. /* Allocate space for a decompressor (receive side) */
  45. void *(*decomp_alloc) (unsigned char *options, int opt_len);
  46. /* Free space used by a decompressor */
  47. void (*decomp_free) (void *state);
  48. /* Initialize a decompressor */
  49. int (*decomp_init) (void *state, unsigned char *options,
  50. int opt_len, int unit, int opthdr, int mru,
  51. int debug);
  52. /* Reset a decompressor */
  53. void (*decomp_reset) (void *state);
  54. /* Decompress a packet. */
  55. int (*decompress) (void *state, unsigned char *ibuf, int isize,
  56. unsigned char *obuf, int osize);
  57. /* Update state for an incompressible packet received */
  58. void (*incomp) (void *state, unsigned char *ibuf, int icnt);
  59. /* Return decompression statistics */
  60. void (*decomp_stat) (void *state, struct compstat *stats);
  61. /* Used in locking compressor modules */
  62. struct module *owner;
  63. /* Extra skb space needed by the compressor algorithm */
  64. unsigned int comp_extra;
  65. };
  66. /*
  67. * The return value from decompress routine is the length of the
  68. * decompressed packet if successful, otherwise DECOMP_ERROR
  69. * or DECOMP_FATALERROR if an error occurred.
  70. *
  71. * We need to make this distinction so that we can disable certain
  72. * useful functionality, namely sending a CCP reset-request as a result
  73. * of an error detected after decompression. This is to avoid infringing
  74. * a patent held by Motorola.
  75. * Don't you just lurve software patents.
  76. */
  77. #define DECOMP_ERROR -1 /* error detected before decomp. */
  78. #define DECOMP_FATALERROR -2 /* error detected after decomp. */
  79. /*
  80. * CCP codes.
  81. */
  82. #define CCP_CONFREQ 1
  83. #define CCP_CONFACK 2
  84. #define CCP_TERMREQ 5
  85. #define CCP_TERMACK 6
  86. #define CCP_RESETREQ 14
  87. #define CCP_RESETACK 15
  88. /*
  89. * Max # bytes for a CCP option
  90. */
  91. #define CCP_MAX_OPTION_LENGTH 32
  92. /*
  93. * Parts of a CCP packet.
  94. */
  95. #define CCP_CODE(dp) ((dp)[0])
  96. #define CCP_ID(dp) ((dp)[1])
  97. #define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3])
  98. #define CCP_HDRLEN 4
  99. #define CCP_OPT_CODE(dp) ((dp)[0])
  100. #define CCP_OPT_LENGTH(dp) ((dp)[1])
  101. #define CCP_OPT_MINLEN 2
  102. /*
  103. * Definitions for BSD-Compress.
  104. */
  105. #define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */
  106. #define CILEN_BSD_COMPRESS 3 /* length of config. option */
  107. /* Macros for handling the 3rd byte of the BSD-Compress config option. */
  108. #define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */
  109. #define BSD_VERSION(x) ((x) >> 5) /* version of option format */
  110. #define BSD_CURRENT_VERSION 1 /* current version number */
  111. #define BSD_MAKE_OPT(v, n) (((v) << 5) | (n))
  112. #define BSD_MIN_BITS 9 /* smallest code size supported */
  113. #define BSD_MAX_BITS 15 /* largest code size supported */
  114. /*
  115. * Definitions for Deflate.
  116. */
  117. #define CI_DEFLATE 26 /* config option for Deflate */
  118. #define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */
  119. #define CILEN_DEFLATE 4 /* length of its config option */
  120. #define DEFLATE_MIN_SIZE 9
  121. #define DEFLATE_MAX_SIZE 15
  122. #define DEFLATE_METHOD_VAL 8
  123. #define DEFLATE_SIZE(x) (((x) >> 4) + 8)
  124. #define DEFLATE_METHOD(x) ((x) & 0x0F)
  125. #define DEFLATE_MAKE_OPT(w) ((((w) - 8) << 4) + DEFLATE_METHOD_VAL)
  126. #define DEFLATE_CHK_SEQUENCE 0
  127. /*
  128. * Definitions for MPPE.
  129. */
  130. #define CI_MPPE 18 /* config option for MPPE */
  131. #define CILEN_MPPE 6 /* length of config option */
  132. /*
  133. * Definitions for other, as yet unsupported, compression methods.
  134. */
  135. #define CI_PREDICTOR_1 1 /* config option for Predictor-1 */
  136. #define CILEN_PREDICTOR_1 2 /* length of its config option */
  137. #define CI_PREDICTOR_2 2 /* config option for Predictor-2 */
  138. #define CILEN_PREDICTOR_2 2 /* length of its config option */
  139. #ifdef __KERNEL__
  140. extern int ppp_register_compressor(struct compressor *);
  141. extern void ppp_unregister_compressor(struct compressor *);
  142. #endif /* __KERNEL__ */
  143. #endif /* _NET_PPP_COMP_H */