slcompress.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Definitions for tcp compression routines.
  3. */
  4. /*-
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. *
  7. * Copyright (c) 1989, 1993
  8. * The Regents of the University of California. All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  35. * - Initial distribution.
  36. */
  37. #ifndef _NET_SLCOMPRESS_H_
  38. #define _NET_SLCOMPRESS_H_
  39. #define MAX_STATES 16 /* must be > 2 and < 256 */
  40. #define MAX_HDR 128
  41. /*
  42. * Compressed packet format:
  43. *
  44. * The first octet contains the packet type (top 3 bits), TCP
  45. * 'push' bit, and flags that indicate which of the 4 TCP sequence
  46. * numbers have changed (bottom 5 bits). The next octet is a
  47. * conversation number that associates a saved IP/TCP header with
  48. * the compressed packet. The next two octets are the TCP checksum
  49. * from the original datagram. The next 0 to 15 octets are
  50. * sequence number changes, one change per bit set in the header
  51. * (there may be no changes and there are two special cases where
  52. * the receiver implicitly knows what changed -- see below).
  53. *
  54. * There are 5 numbers which can change (they are always inserted
  55. * in the following order): TCP urgent pointer, window,
  56. * acknowledgement, sequence number and IP ID. (The urgent pointer
  57. * is different from the others in that its value is sent, not the
  58. * change in value.) Since typical use of SLIP links is biased
  59. * toward small packets (see comments on MTU/MSS below), changes
  60. * use a variable length coding with one octet for numbers in the
  61. * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  62. * range 256 - 65535 or 0. (If the change in sequence number or
  63. * ack is more than 65535, an uncompressed packet is sent.)
  64. */
  65. /*
  66. * Packet types (must not conflict with IP protocol version)
  67. *
  68. * The top nibble of the first octet is the packet type. There are
  69. * three possible types: IP (not proto TCP or tcp with one of the
  70. * control flags set); uncompressed TCP (a normal IP/TCP packet but
  71. * with the 8-bit protocol field replaced by an 8-bit connection id --
  72. * this type of packet syncs the sender & receiver); and compressed
  73. * TCP (described above).
  74. *
  75. * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  76. * is logically part of the 4-bit "changes" field that follows. Top
  77. * three bits are actual packet type. For backward compatibility
  78. * and in the interest of conserving bits, numbers are chosen so the
  79. * IP protocol version number (4) which normally appears in this nibble
  80. * means "IP packet".
  81. */
  82. /* packet types */
  83. #define TYPE_IP 0x40
  84. #define TYPE_UNCOMPRESSED_TCP 0x70
  85. #define TYPE_COMPRESSED_TCP 0x80
  86. #define TYPE_ERROR 0x00
  87. /* Bits in first octet of compressed packet */
  88. #define NEW_C 0x40 /* flag bits for what changed in a packet */
  89. #define NEW_I 0x20
  90. #define NEW_S 0x08
  91. #define NEW_A 0x04
  92. #define NEW_W 0x02
  93. #define NEW_U 0x01
  94. /* reserved, special-case values of above */
  95. #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
  96. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
  97. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  98. #define TCP_PUSH_BIT 0x10
  99. /*
  100. * "state" data for each active tcp conversation on the wire. This is
  101. * basically a copy of the entire IP/TCP header from the last packet
  102. * we saw from the conversation together with a small identifier
  103. * the transmit & receive ends of the line use to locate saved header.
  104. */
  105. struct cstate {
  106. struct cstate *cs_next; /* next most recently used cstate (xmit only) */
  107. u_int16_t cs_hlen; /* size of hdr (receive only) */
  108. u_char cs_id; /* connection # associated with this state */
  109. u_char cs_filler;
  110. union {
  111. char csu_hdr[MAX_HDR];
  112. struct ip csu_ip; /* ip/tcp hdr from most recent packet */
  113. } slcs_u;
  114. };
  115. #define cs_ip slcs_u.csu_ip
  116. #define cs_hdr slcs_u.csu_hdr
  117. /*
  118. * all the state data for one serial line (we need one of these
  119. * per line).
  120. */
  121. struct slcompress {
  122. struct cstate *last_cs; /* most recently used tstate */
  123. u_char last_recv; /* last rcvd conn. id */
  124. u_char last_xmit; /* last sent conn. id */
  125. u_int16_t flags;
  126. #ifndef SL_NO_STATS
  127. int sls_packets; /* outbound packets */
  128. int sls_compressed; /* outbound compressed packets */
  129. int sls_searches; /* searches for connection state */
  130. int sls_misses; /* times couldn't find conn. state */
  131. int sls_uncompressedin; /* inbound uncompressed packets */
  132. int sls_compressedin; /* inbound compressed packets */
  133. int sls_errorin; /* inbound unknown type packets */
  134. int sls_tossed; /* inbound packets tossed because of error */
  135. #endif
  136. struct cstate tstate[MAX_STATES]; /* xmit connection states */
  137. struct cstate rstate[MAX_STATES]; /* receive connection states */
  138. };
  139. /* flag values */
  140. #define SLF_TOSS 1 /* tossing rcvd frames because of input err */
  141. void sl_compress_init(struct slcompress *, int);
  142. u_int sl_compress_tcp(struct mbuf *, struct ip *, struct slcompress *, int);
  143. int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *);
  144. int sl_uncompress_tcp_core(u_char *, int, int, u_int,
  145. struct slcompress *, u_char **, u_int *);
  146. #endif /* !_NET_SLCOMPRESS_H_ */