1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Definitions for tcp compression routines. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * $Id: vjcompress.h,v 1.3 1996/05/28 00:55:33 paulus Exp $ 5*7c478bd9Sstevel@tonic-gate * 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 7*7c478bd9Sstevel@tonic-gate * All rights reserved. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Regents of the University of California. 10*7c478bd9Sstevel@tonic-gate * All rights reserved. 11*7c478bd9Sstevel@tonic-gate * 12*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 13*7c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 14*7c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 15*7c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 16*7c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 17*7c478bd9Sstevel@tonic-gate * by the University of California, Berkeley. The name of the 18*7c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 19*7c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 20*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 21*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 22*7c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 23*7c478bd9Sstevel@tonic-gate * 24*7c478bd9Sstevel@tonic-gate * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 25*7c478bd9Sstevel@tonic-gate * - Initial distribution. 26*7c478bd9Sstevel@tonic-gate */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #ifndef _VJCOMPRESS_H_ 29*7c478bd9Sstevel@tonic-gate #define _VJCOMPRESS_H_ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 34*7c478bd9Sstevel@tonic-gate extern "C" { 35*7c478bd9Sstevel@tonic-gate #endif 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define MAX_STATES 16 /* must be > 2 and < 256 */ 38*7c478bd9Sstevel@tonic-gate #define MAX_HDR 128 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * Compressed packet format: 42*7c478bd9Sstevel@tonic-gate * 43*7c478bd9Sstevel@tonic-gate * The first octet contains the packet type (top 3 bits), TCP 44*7c478bd9Sstevel@tonic-gate * 'push' bit, and flags that indicate which of the 4 TCP sequence 45*7c478bd9Sstevel@tonic-gate * numbers have changed (bottom 5 bits). The next octet is a 46*7c478bd9Sstevel@tonic-gate * conversation number that associates a saved IP/TCP header with 47*7c478bd9Sstevel@tonic-gate * the compressed packet. The next two octets are the TCP checksum 48*7c478bd9Sstevel@tonic-gate * from the original datagram. The next 0 to 15 octets are 49*7c478bd9Sstevel@tonic-gate * sequence number changes, one change per bit set in the header 50*7c478bd9Sstevel@tonic-gate * (there may be no changes and there are two special cases where 51*7c478bd9Sstevel@tonic-gate * the receiver implicitly knows what changed -- see below). 52*7c478bd9Sstevel@tonic-gate * 53*7c478bd9Sstevel@tonic-gate * There are 5 numbers which can change (they are always inserted 54*7c478bd9Sstevel@tonic-gate * in the following order): TCP urgent pointer, window, 55*7c478bd9Sstevel@tonic-gate * acknowlegement, sequence number and IP ID. (The urgent pointer 56*7c478bd9Sstevel@tonic-gate * is different from the others in that its value is sent, not the 57*7c478bd9Sstevel@tonic-gate * change in value.) Since typical use of SLIP links is biased 58*7c478bd9Sstevel@tonic-gate * toward small packets (see comments on MTU/MSS below), changes 59*7c478bd9Sstevel@tonic-gate * use a variable length coding with one octet for numbers in the 60*7c478bd9Sstevel@tonic-gate * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 61*7c478bd9Sstevel@tonic-gate * range 256 - 65535 or 0. (If the change in sequence number or 62*7c478bd9Sstevel@tonic-gate * ack is more than 65535, an uncompressed packet is sent.) 63*7c478bd9Sstevel@tonic-gate */ 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* 66*7c478bd9Sstevel@tonic-gate * Packet types (must not conflict with IP protocol version) 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * The top nibble of the first octet is the packet type. There are 69*7c478bd9Sstevel@tonic-gate * three possible types: IP (not proto TCP or tcp with one of the 70*7c478bd9Sstevel@tonic-gate * control flags set); uncompressed TCP (a normal IP/TCP packet but 71*7c478bd9Sstevel@tonic-gate * with the 8-bit protocol field replaced by an 8-bit connection id -- 72*7c478bd9Sstevel@tonic-gate * this type of packet syncs the sender & receiver); and compressed 73*7c478bd9Sstevel@tonic-gate * TCP (described above). 74*7c478bd9Sstevel@tonic-gate * 75*7c478bd9Sstevel@tonic-gate * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 76*7c478bd9Sstevel@tonic-gate * is logically part of the 4-bit "changes" field that follows. Top 77*7c478bd9Sstevel@tonic-gate * three bits are actual packet type. For backward compatibility 78*7c478bd9Sstevel@tonic-gate * and in the interest of conserving bits, numbers are chosen so the 79*7c478bd9Sstevel@tonic-gate * IP protocol version number (4) which normally appears in this nibble 80*7c478bd9Sstevel@tonic-gate * means "IP packet". 81*7c478bd9Sstevel@tonic-gate */ 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate /* packet types */ 84*7c478bd9Sstevel@tonic-gate #define TYPE_IP 0x40 85*7c478bd9Sstevel@tonic-gate #define TYPE_UNCOMPRESSED_TCP 0x70 86*7c478bd9Sstevel@tonic-gate #define TYPE_COMPRESSED_TCP 0x80 87*7c478bd9Sstevel@tonic-gate #define TYPE_ERROR 0x00 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* Bits in first octet of compressed packet */ 90*7c478bd9Sstevel@tonic-gate #define NEW_C 0x40 /* flag bits for what changed in a packet */ 91*7c478bd9Sstevel@tonic-gate #define NEW_I 0x20 92*7c478bd9Sstevel@tonic-gate #define NEW_S 0x08 93*7c478bd9Sstevel@tonic-gate #define NEW_A 0x04 94*7c478bd9Sstevel@tonic-gate #define NEW_W 0x02 95*7c478bd9Sstevel@tonic-gate #define NEW_U 0x01 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* reserved, special-case values of above */ 98*7c478bd9Sstevel@tonic-gate #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 99*7c478bd9Sstevel@tonic-gate #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 100*7c478bd9Sstevel@tonic-gate #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate #define TCP_PUSH_BIT 0x10 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate /* 106*7c478bd9Sstevel@tonic-gate * "state" data for each active tcp conversation on the wire. This is 107*7c478bd9Sstevel@tonic-gate * basically a copy of the entire IP/TCP header from the last packet 108*7c478bd9Sstevel@tonic-gate * we saw from the conversation together with a small identifier 109*7c478bd9Sstevel@tonic-gate * the transmit & receive ends of the line use to locate saved header. 110*7c478bd9Sstevel@tonic-gate */ 111*7c478bd9Sstevel@tonic-gate struct cstate { 112*7c478bd9Sstevel@tonic-gate struct cstate *cs_next; /* next most recently used state (xmit only) */ 113*7c478bd9Sstevel@tonic-gate ushort_t cs_hlen; /* size of hdr (receive only) */ 114*7c478bd9Sstevel@tonic-gate uchar_t cs_id; /* connection # associated with this state */ 115*7c478bd9Sstevel@tonic-gate uchar_t cs_filler; 116*7c478bd9Sstevel@tonic-gate union { 117*7c478bd9Sstevel@tonic-gate char csu_hdr[MAX_HDR]; 118*7c478bd9Sstevel@tonic-gate struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 119*7c478bd9Sstevel@tonic-gate } vjcs_u; 120*7c478bd9Sstevel@tonic-gate }; 121*7c478bd9Sstevel@tonic-gate #define cs_ip vjcs_u.csu_ip 122*7c478bd9Sstevel@tonic-gate #define cs_hdr vjcs_u.csu_hdr 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* 125*7c478bd9Sstevel@tonic-gate * all the state data for one serial line (we need one of these per line). 126*7c478bd9Sstevel@tonic-gate */ 127*7c478bd9Sstevel@tonic-gate struct vjcompress { 128*7c478bd9Sstevel@tonic-gate struct cstate *last_cs; /* most recently used tstate */ 129*7c478bd9Sstevel@tonic-gate uchar_t last_recv; /* last rcvd conn. id */ 130*7c478bd9Sstevel@tonic-gate uchar_t last_xmit; /* last sent conn. id */ 131*7c478bd9Sstevel@tonic-gate ushort_t flags; 132*7c478bd9Sstevel@tonic-gate #ifndef VJ_NO_STATS 133*7c478bd9Sstevel@tonic-gate struct vjstat stats; 134*7c478bd9Sstevel@tonic-gate #endif 135*7c478bd9Sstevel@tonic-gate struct cstate tstate[MAX_STATES]; /* xmit connection states */ 136*7c478bd9Sstevel@tonic-gate struct cstate rstate[MAX_STATES]; /* receive connection states */ 137*7c478bd9Sstevel@tonic-gate }; 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate /* flag values */ 140*7c478bd9Sstevel@tonic-gate #define VJF_TOSS 1 /* tossing rcvd frames because of input err */ 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate extern void vj_compress_init __P((struct vjcompress *comp, int max_state)); 143*7c478bd9Sstevel@tonic-gate extern uint_t vj_compress_tcp __P((struct ip *ip, uint_t mlen, 144*7c478bd9Sstevel@tonic-gate struct vjcompress *comp, int compress_cid_flag, 145*7c478bd9Sstevel@tonic-gate uchar_t **vjhdrp)); 146*7c478bd9Sstevel@tonic-gate extern void vj_uncompress_err __P((struct vjcompress *comp)); 147*7c478bd9Sstevel@tonic-gate extern int vj_uncompress_uncomp __P((uchar_t *buf, int buflen, 148*7c478bd9Sstevel@tonic-gate struct vjcompress *comp)); 149*7c478bd9Sstevel@tonic-gate extern int vj_uncompress_tcp __P((uchar_t *buf, int buflen, int total_len, 150*7c478bd9Sstevel@tonic-gate struct vjcompress *comp, uchar_t **hdrp, 151*7c478bd9Sstevel@tonic-gate uint_t *hlenp)); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate #endif 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate #endif /* _VJCOMPRESS_H_ */ 158