Annotation of kernel/bsd/net/slcompress.h, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.