Annotation of qemu/slirp/ip.h, revision 1.1.1.9

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986, 1993
                      3:  *     The Regents of the University of California.  All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
1.1.1.4   root       13:  * 3. Neither the name of the University nor the names of its contributors
1.1       root       14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  *
                     29:  *     @(#)ip.h        8.1 (Berkeley) 6/10/93
                     30:  * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
                     31:  */
                     32: 
                     33: #ifndef _IP_H_
                     34: #define _IP_H_
                     35: 
1.1.1.6   root       36: #ifdef HOST_WORDS_BIGENDIAN
1.1.1.9 ! root       37: # undef NTOHL
        !            38: # undef NTOHS
        !            39: # undef HTONL
        !            40: # undef HTONS
        !            41: # define NTOHL(d)
        !            42: # define NTOHS(d)
        !            43: # define HTONL(d)
        !            44: # define HTONS(d)
1.1       root       45: #else
                     46: # ifndef NTOHL
                     47: #  define NTOHL(d) ((d) = ntohl((d)))
                     48: # endif
                     49: # ifndef NTOHS
1.1.1.7   root       50: #  define NTOHS(d) ((d) = ntohs((uint16_t)(d)))
1.1       root       51: # endif
                     52: # ifndef HTONL
                     53: #  define HTONL(d) ((d) = htonl((d)))
                     54: # endif
                     55: # ifndef HTONS
1.1.1.7   root       56: #  define HTONS(d) ((d) = htons((uint16_t)(d)))
1.1       root       57: # endif
                     58: #endif
                     59: 
1.1.1.7   root       60: typedef uint32_t n_long;                 /* long as received from the net */
1.1       root       61: 
                     62: /*
                     63:  * Definitions for internet protocol version 4.
                     64:  * Per RFC 791, September 1981.
                     65:  */
                     66: #define        IPVERSION       4
                     67: 
                     68: /*
                     69:  * Structure of an internet header, naked of options.
                     70:  */
                     71: struct ip {
1.1.1.6   root       72: #ifdef HOST_WORDS_BIGENDIAN
1.1.1.8   root       73:        uint8_t ip_v:4,                 /* version */
1.1       root       74:                ip_hl:4;                /* header length */
                     75: #else
1.1.1.8   root       76:        uint8_t ip_hl:4,                /* header length */
1.1       root       77:                ip_v:4;                 /* version */
                     78: #endif
1.1.1.7   root       79:        uint8_t         ip_tos;                 /* type of service */
                     80:        uint16_t        ip_len;                 /* total length */
                     81:        uint16_t        ip_id;                  /* identification */
                     82:        uint16_t        ip_off;                 /* fragment offset field */
1.1       root       83: #define        IP_DF 0x4000                    /* don't fragment flag */
                     84: #define        IP_MF 0x2000                    /* more fragments flag */
                     85: #define        IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
1.1.1.7   root       86:        uint8_t ip_ttl;                 /* time to live */
                     87:        uint8_t ip_p;                   /* protocol */
                     88:        uint16_t        ip_sum;                 /* checksum */
1.1       root       89:        struct  in_addr ip_src,ip_dst;  /* source and dest address */
1.1.1.8   root       90: } QEMU_PACKED;
1.1       root       91: 
                     92: #define        IP_MAXPACKET    65535           /* maximum packet size */
                     93: 
                     94: /*
                     95:  * Definitions for IP type of service (ip_tos)
                     96:  */
                     97: #define        IPTOS_LOWDELAY          0x10
                     98: #define        IPTOS_THROUGHPUT        0x08
                     99: #define        IPTOS_RELIABILITY       0x04
                    100: 
                    101: /*
                    102:  * Definitions for options.
                    103:  */
                    104: #define        IPOPT_COPIED(o)         ((o)&0x80)
                    105: #define        IPOPT_CLASS(o)          ((o)&0x60)
                    106: #define        IPOPT_NUMBER(o)         ((o)&0x1f)
                    107: 
                    108: #define        IPOPT_CONTROL           0x00
                    109: #define        IPOPT_RESERVED1         0x20
                    110: #define        IPOPT_DEBMEAS           0x40
                    111: #define        IPOPT_RESERVED2         0x60
                    112: 
                    113: #define        IPOPT_EOL               0               /* end of option list */
                    114: #define        IPOPT_NOP               1               /* no operation */
                    115: 
                    116: #define        IPOPT_RR                7               /* record packet route */
                    117: #define        IPOPT_TS                68              /* timestamp */
                    118: #define        IPOPT_SECURITY          130             /* provide s,c,h,tcc */
                    119: #define        IPOPT_LSRR              131             /* loose source route */
                    120: #define        IPOPT_SATID             136             /* satnet id */
                    121: #define        IPOPT_SSRR              137             /* strict source route */
                    122: 
                    123: /*
                    124:  * Offsets to fields in options other than EOL and NOP.
                    125:  */
                    126: #define        IPOPT_OPTVAL            0               /* option ID */
                    127: #define        IPOPT_OLEN              1               /* option length */
                    128: #define IPOPT_OFFSET           2               /* offset within option */
                    129: #define        IPOPT_MINOFF            4               /* min value of above */
                    130: 
                    131: /*
                    132:  * Time stamp option structure.
                    133:  */
                    134: struct ip_timestamp {
1.1.1.7   root      135:        uint8_t ipt_code;               /* IPOPT_TS */
                    136:        uint8_t ipt_len;                /* size of structure (variable) */
                    137:        uint8_t ipt_ptr;                /* index of current entry */
1.1.1.6   root      138: #ifdef HOST_WORDS_BIGENDIAN
1.1.1.8   root      139:        uint8_t ipt_oflw:4,             /* overflow counter */
1.1       root      140:                ipt_flg:4;              /* flags, see below */
                    141: #else
1.1.1.8   root      142:        uint8_t ipt_flg:4,              /* flags, see below */
1.1       root      143:                ipt_oflw:4;             /* overflow counter */
                    144: #endif
                    145:        union ipt_timestamp {
                    146:                n_long  ipt_time[1];
                    147:                struct  ipt_ta {
                    148:                        struct in_addr ipt_addr;
                    149:                        n_long ipt_time;
                    150:                } ipt_ta[1];
                    151:        } ipt_timestamp;
1.1.1.8   root      152: } QEMU_PACKED;
1.1       root      153: 
                    154: /* flag bits for ipt_flg */
                    155: #define        IPOPT_TS_TSONLY         0               /* timestamps only */
                    156: #define        IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
                    157: #define        IPOPT_TS_PRESPEC        3               /* specified modules only */
                    158: 
                    159: /* bits for security (not byte swapped) */
                    160: #define        IPOPT_SECUR_UNCLASS     0x0000
                    161: #define        IPOPT_SECUR_CONFID      0xf135
                    162: #define        IPOPT_SECUR_EFTO        0x789a
                    163: #define        IPOPT_SECUR_MMMM        0xbc4d
                    164: #define        IPOPT_SECUR_RESTR       0xaf13
                    165: #define        IPOPT_SECUR_SECRET      0xd788
                    166: #define        IPOPT_SECUR_TOPSECRET   0x6bc5
                    167: 
                    168: /*
                    169:  * Internet implementation parameters.
                    170:  */
                    171: #define        MAXTTL          255             /* maximum time to live (seconds) */
                    172: #define        IPDEFTTL        64              /* default ttl, from RFC 1340 */
                    173: #define        IPFRAGTTL       60              /* time to live for frags, slowhz */
                    174: #define        IPTTLDEC        1               /* subtracted when forwarding */
                    175: 
                    176: #define        IP_MSS          576             /* default maximum segment size */
                    177: 
                    178: #if SIZEOF_CHAR_P == 4
1.1.1.4   root      179: struct mbuf_ptr {
                    180:        struct mbuf *mptr;
                    181:        uint32_t dummy;
1.1.1.8   root      182: } QEMU_PACKED;
1.1       root      183: #else
1.1.1.4   root      184: struct mbuf_ptr {
                    185:        struct mbuf *mptr;
1.1.1.8   root      186: } QEMU_PACKED;
1.1       root      187: #endif
1.1.1.4   root      188: struct qlink {
                    189:        void *next, *prev;
                    190: };
1.1       root      191: 
                    192: /*
                    193:  * Overlay for ip header used by other protocols (tcp, udp).
                    194:  */
                    195: struct ipovly {
1.1.1.4   root      196:        struct mbuf_ptr ih_mbuf;        /* backpointer to mbuf */
1.1.1.7   root      197:        uint8_t ih_x1;                  /* (unused) */
                    198:        uint8_t ih_pr;                  /* protocol */
                    199:        uint16_t        ih_len;                 /* protocol length */
1.1       root      200:        struct  in_addr ih_src;         /* source internet address */
                    201:        struct  in_addr ih_dst;         /* destination internet address */
1.1.1.8   root      202: } QEMU_PACKED;
1.1       root      203: 
                    204: /*
                    205:  * Ip reassembly queue structure.  Each fragment
                    206:  * being reassembled is attached to one of these structures.
                    207:  * They are timed out after ipq_ttl drops to 0, and may also
                    208:  * be reclaimed if memory becomes tight.
                    209:  * size 28 bytes
                    210:  */
                    211: struct ipq {
1.1.1.4   root      212:         struct qlink frag_link;                        /* to ip headers of fragments */
                    213:        struct qlink ip_link;                           /* to other reass headers */
1.1.1.7   root      214:        uint8_t ipq_ttl;                /* time for reass q to live */
                    215:        uint8_t ipq_p;                  /* protocol of this fragment */
                    216:        uint16_t        ipq_id;                 /* sequence id for reassembly */
1.1       root      217:        struct  in_addr ipq_src,ipq_dst;
1.1.1.8   root      218: } QEMU_PACKED;
1.1       root      219: 
                    220: /*
                    221:  * Ip header, when holding a fragment.
                    222:  *
1.1.1.4   root      223:  * Note: ipf_link must be at same offset as frag_link above
1.1       root      224:  */
                    225: struct ipasfrag {
1.1.1.4   root      226:        struct qlink ipf_link;
                    227:        struct ip ipf_ip;
1.1.1.8   root      228: } QEMU_PACKED;
1.1       root      229: 
1.1.1.4   root      230: #define ipf_off      ipf_ip.ip_off
                    231: #define ipf_tos      ipf_ip.ip_tos
                    232: #define ipf_len      ipf_ip.ip_len
                    233: #define ipf_next     ipf_link.next
1.1.1.7   root      234: #define ipf_prev     ipf_link.prev
1.1.1.4   root      235: 
1.1       root      236: /*
                    237:  * Structure stored in mbuf in inpcb.ip_options
                    238:  * and passed to ip_output when ip options are in use.
                    239:  * The actual length of the options (including ipopt_dst)
                    240:  * is in m_len.
                    241:  */
                    242: #define MAX_IPOPTLEN   40
                    243: 
                    244: struct ipoption {
                    245:        struct  in_addr ipopt_dst;      /* first-hop dst if source routed */
                    246:        int8_t  ipopt_list[MAX_IPOPTLEN];       /* options proper */
1.1.1.8   root      247: } QEMU_PACKED;
1.1       root      248: 
                    249: #endif

unix.superglobalmegacorp.com