Home | History | Annotate | Download | only in netinet
      1 /*
      2  * Copyright (c) 1982, 1986, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * Portions copyright (c) 1999, 2000
      6  * Intel Corporation.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  *
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  *
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *
     23  *    This product includes software developed by the University of
     24  *    California, Berkeley, Intel Corporation, and its contributors.
     25  *
     26  * 4. Neither the name of University, Intel Corporation, or their respective
     27  *    contributors may be used to endorse or promote products derived from
     28  *    this software without specific prior written permission.
     29  *
     30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
     31  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
     32  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     33  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS,
     34  * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     35  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     36  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     40  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     41  *
     42  *	@(#)ip.h	8.2 (Berkeley) 6/1/94
     43  *	$Id: ip.h,v 1.1.1.1 2006/05/30 06:12:48 hhzhou Exp $
     44  */
     45 
     46 #ifndef _NETINET_IP_H_
     47 #define _NETINET_IP_H_
     48 
     49 #ifndef _ORG_FREEBSD_
     50 #define _IP_VHL
     51 #endif
     52 
     53 /*
     54  * Definitions for internet protocol version 4.
     55  * Per RFC 791, September 1981.
     56  */
     57 #define	IPVERSION	4
     58 
     59 /*
     60  * Structure of an internet header, naked of options.
     61  */
     62 struct ip {
     63 #ifdef _IP_VHL
     64 	u_char	ip_vhl;			/* version << 4 | header length >> 2 */
     65 #else
     66 #if BYTE_ORDER == LITTLE_ENDIAN
     67 	u_int	ip_hl:4,		/* header length */
     68 		ip_v:4;			/* version */
     69 #endif
     70 #if BYTE_ORDER == BIG_ENDIAN
     71 	u_int	ip_v:4,			/* version */
     72 		ip_hl:4;		/* header length */
     73 #endif
     74 #endif /* not _IP_VHL */
     75 	u_char	ip_tos;			/* type of service */
     76 	u_short	ip_len;			/* total length */
     77 	u_short	ip_id;			/* identification */
     78 	u_short	ip_off;			/* fragment offset field */
     79 #define	IP_RF 0x8000			/* reserved fragment flag */
     80 #define	IP_DF 0x4000			/* dont fragment flag */
     81 #define	IP_MF 0x2000			/* more fragments flag */
     82 #define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
     83 	u_char	ip_ttl;			/* time to live */
     84 	u_char	ip_p;			/* protocol */
     85 	u_short	ip_sum;			/* checksum */
     86 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
     87 };
     88 
     89 #ifdef _IP_VHL
     90 #define	IP_MAKE_VHL(v, hl)	((v) << 4 | (hl))
     91 #define	IP_VHL_HL(vhl)		((vhl) & 0x0f)
     92 #define	IP_VHL_V(vhl)		((vhl) >> 4)
     93 #define	IP_VHL_BORING		0x45
     94 #endif
     95 
     96 #define	IP_MAXPACKET	65535		/* maximum packet size */
     97 
     98 /*
     99  * Definitions for IP type of service (ip_tos)
    100  */
    101 #define	IPTOS_LOWDELAY		0x10
    102 #define	IPTOS_THROUGHPUT	0x08
    103 #define	IPTOS_RELIABILITY	0x04
    104 #define	IPTOS_MINCOST		0x02
    105 
    106 /*
    107  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
    108  */
    109 #define	IPTOS_PREC_NETCONTROL		0xe0
    110 #define	IPTOS_PREC_INTERNETCONTROL	0xc0
    111 #define	IPTOS_PREC_CRITIC_ECP		0xa0
    112 #define	IPTOS_PREC_FLASHOVERRIDE	0x80
    113 #define	IPTOS_PREC_FLASH		0x60
    114 #define	IPTOS_PREC_IMMEDIATE		0x40
    115 #define	IPTOS_PREC_PRIORITY		0x20
    116 #define	IPTOS_PREC_ROUTINE		0x00
    117 
    118 /*
    119  * Definitions for options.
    120  */
    121 #define	IPOPT_COPIED(o)		((o)&0x80)
    122 #define	IPOPT_CLASS(o)		((o)&0x60)
    123 #define	IPOPT_NUMBER(o)		((o)&0x1f)
    124 
    125 #define	IPOPT_CONTROL		0x00
    126 #define	IPOPT_RESERVED1		0x20
    127 #define	IPOPT_DEBMEAS		0x40
    128 #define	IPOPT_RESERVED2		0x60
    129 
    130 #define	IPOPT_EOL		0		/* end of option list */
    131 #define	IPOPT_NOP		1		/* no operation */
    132 
    133 #define	IPOPT_RR		7		/* record packet route */
    134 #define	IPOPT_TS		68		/* timestamp */
    135 #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
    136 #define	IPOPT_LSRR		131		/* loose source route */
    137 #define	IPOPT_SATID		136		/* satnet id */
    138 #define	IPOPT_SSRR		137		/* strict source route */
    139 #define	IPOPT_RA		148		/* router alert */
    140 
    141 /*
    142  * Offsets to fields in options other than EOL and NOP.
    143  */
    144 #define	IPOPT_OPTVAL		0		/* option ID */
    145 #define	IPOPT_OLEN		1		/* option length */
    146 #define IPOPT_OFFSET		2		/* offset within option */
    147 #define	IPOPT_MINOFF		4		/* min value of above */
    148 
    149 /*
    150  * Time stamp option structure.
    151  */
    152 struct	ip_timestamp {
    153 	u_char	ipt_code;		/* IPOPT_TS */
    154 	u_char	ipt_len;		/* size of structure (variable) */
    155 	u_char	ipt_ptr;		/* index of current entry */
    156 #if BYTE_ORDER == LITTLE_ENDIAN
    157 	u_int	ipt_flg:4,		/* flags, see below */
    158 		ipt_oflw:4;		/* overflow counter */
    159 #endif
    160 #if BYTE_ORDER == BIG_ENDIAN
    161 	u_int	ipt_oflw:4,		/* overflow counter */
    162 		ipt_flg:4;		/* flags, see below */
    163 #endif
    164 	union ipt_timestamp {
    165 		n_long	ipt_time[1];
    166 		struct	ipt_ta {
    167 			struct in_addr ipt_addr;
    168 			n_long ipt_time;
    169 		} ipt_ta[1];
    170 	} ipt_timestamp;
    171 };
    172 
    173 /* flag bits for ipt_flg */
    174 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
    175 #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
    176 #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
    177 
    178 /* bits for security (not byte swapped) */
    179 #define	IPOPT_SECUR_UNCLASS	0x0000
    180 #define	IPOPT_SECUR_CONFID	0xf135
    181 #define	IPOPT_SECUR_EFTO	0x789a
    182 #define	IPOPT_SECUR_MMMM	0xbc4d
    183 #define	IPOPT_SECUR_RESTR	0xaf13
    184 #define	IPOPT_SECUR_SECRET	0xd788
    185 #define	IPOPT_SECUR_TOPSECRET	0x6bc5
    186 
    187 /*
    188  * Internet implementation parameters.
    189  */
    190 #define	MAXTTL		255		/* maximum time to live (seconds) */
    191 #define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
    192 #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
    193 #define	IPTTLDEC	1		/* subtracted when forwarding */
    194 
    195 #define	IP_MSS		576		/* default maximum segment size */
    196 
    197 #endif
    198