^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #ifndef _SLHC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #define _SLHC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Definitions for tcp compression routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 1989 Regents of the University of California.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Redistribution and use in source and binary forms are permitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * provided that the above copyright notice and this paragraph are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * duplicated in all such forms and that any documentation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * advertising materials, and other materials related to such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * distribution and use acknowledge that the software was developed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * by the University of California, Berkeley. The name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * University may not be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * - Initial distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * modified for KA9Q Internet Software Package by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Katie Stevens (dkstevens@ucdavis.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * University of California, Davis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Computing Services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * - 01-31-90 initial adaptation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * - Feb 1991 Bill_Simpson@um.cc.umich.edu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * variable number of conversation slots
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * allow zero or one slots
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * separate routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * status display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Compressed packet format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * The first octet contains the packet type (top 3 bits), TCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * 'push' bit, and flags that indicate which of the 4 TCP sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * numbers have changed (bottom 5 bits). The next octet is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * conversation number that associates a saved IP/TCP header with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * the compressed packet. The next two octets are the TCP checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * from the original datagram. The next 0 to 15 octets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * sequence number changes, one change per bit set in the header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * (there may be no changes and there are two special cases where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * the receiver implicitly knows what changed -- see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * There are 5 numbers which can change (they are always inserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * in the following order): TCP urgent pointer, window,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * acknowledgment, sequence number and IP ID. (The urgent pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * is different from the others in that its value is sent, not the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * change in value.) Since typical use of SLIP links is biased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * toward small packets (see comments on MTU/MSS below), changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * use a variable length coding with one octet for numbers in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * range 256 - 65535 or 0. (If the change in sequence number or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * ack is more than 65535, an uncompressed packet is sent.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * Packet types (must not conflict with IP protocol version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * The top nibble of the first octet is the packet type. There are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * three possible types: IP (not proto TCP or tcp with one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * control flags set); uncompressed TCP (a normal IP/TCP packet but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * with the 8-bit protocol field replaced by an 8-bit connection id --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * this type of packet syncs the sender & receiver); and compressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * TCP (described above).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * is logically part of the 4-bit "changes" field that follows. Top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * three bits are actual packet type. For backward compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * and in the interest of conserving bits, numbers are chosen so the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * IP protocol version number (4) which normally appears in this nibble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * means "IP packet".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* SLIP compression masks for len/vers byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define SL_TYPE_IP 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define SL_TYPE_UNCOMPRESSED_TCP 0x70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define SL_TYPE_COMPRESSED_TCP 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define SL_TYPE_ERROR 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* Bits in first octet of compressed packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define NEW_C 0x40 /* flag bits for what changed in a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define NEW_I 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define NEW_S 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define NEW_A 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define NEW_W 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define NEW_U 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* reserved, special-case values of above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define TCP_PUSH_BIT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * data type and sizes conversion assumptions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * VJ code KA9Q style generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * u_char byte_t unsigned char 8 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * u_short int16 unsigned short 16 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * u_int int16 unsigned short 16 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * u_long unsigned long unsigned long 32 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * int int32 long 32 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) typedef __u8 byte_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) typedef __u32 int32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * "state" data for each active tcp conversation on the wire. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * basically a copy of the entire IP/TCP header from the last packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * we saw from the conversation together with a small identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * the transmit & receive ends of the line use to locate saved header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct cstate {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) byte_t cs_this; /* connection id number (xmit) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) bool initialized; /* true if initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct cstate *next; /* next in ring (xmit) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct iphdr cs_ip; /* ip/tcp hdr from most recent packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct tcphdr cs_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned char cs_ipopt[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned char cs_tcpopt[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int cs_hsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define NULLSLSTATE (struct cstate *)0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * all the state data for one serial line (we need one of these per line).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct slcompress {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct cstate *tstate; /* transmit connection states (array)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct cstate *rstate; /* receive connection states (array)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) byte_t tslot_limit; /* highest transmit slot id (0-l)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) byte_t rslot_limit; /* highest receive slot id (0-l)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) byte_t xmit_oldest; /* oldest xmit in ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) byte_t xmit_current; /* most recent xmit id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) byte_t recv_current; /* most recent rcvd id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) byte_t flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define SLF_TOSS 0x01 /* tossing rcvd frames until id received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int32 sls_o_nontcp; /* outbound non-TCP packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int32 sls_o_tcp; /* outbound TCP packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int32 sls_o_uncompressed; /* outbound uncompressed packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int32 sls_o_compressed; /* outbound compressed packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int32 sls_o_searches; /* searches for connection state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int32 sls_o_misses; /* times couldn't find conn. state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int32 sls_i_uncompressed; /* inbound uncompressed packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int32 sls_i_compressed; /* inbound compressed packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int32 sls_i_error; /* inbound error packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int32 sls_i_tossed; /* inbound packets tossed because of error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int32 sls_i_runt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int32 sls_i_badcheck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define NULLSLCOMPR (struct slcompress *)0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* In slhc.c: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct slcompress *slhc_init(int rslots, int tslots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) void slhc_free(struct slcompress *comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned char *ocp, unsigned char **cpp, int compress_cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int slhc_remember(struct slcompress *comp, unsigned char *icp, int isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int slhc_toss(struct slcompress *comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #endif /* _SLHC_H */