source: rtems/cpukit/libnetworking/netinet/ip.h @ c7d0d86

4.115
Last change on this file since c7d0d86 was c7d0d86, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/11/11 at 14:35:03

Make self-contained.

  • Property mode set to 100644
File size: 7.2 KB
Line 
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.
13 * 4. Neither the name of the University nor the names of its contributors
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.2 (Berkeley) 6/1/94
30 * $FreeBSD: src/sys/netinet/ip.h,v 1.29 2005/01/07 01:45:44 imp Exp $
31 */
32
33/*
34 *      $Id$
35 */
36
37#ifndef _NETINET_IP_H_
38#define _NETINET_IP_H_
39
40#include <sys/cdefs.h>
41#include <netinet/in.h> /* struct in_addr */
42#include <netinet/in_systm.h> /* n_long */
43
44/*
45 * Definitions for internet protocol version 4.
46 * Per RFC 791, September 1981.
47 */
48#define IPVERSION       4
49
50#ifndef __packed
51#if defined(__GNUC__)
52#define __packed __attribute__((packed))
53#define __aligned(x) __attribute__((aligned(x)))
54#else
55#define __packed
56#define __aligned(x)
57#endif
58#endif
59
60/*
61 * Structure of an internet header, naked of options.
62 */
63struct ip {
64#ifdef _IP_VHL
65        u_char  ip_vhl;                 /* version << 4 | header length >> 2 */
66#else
67#if BYTE_ORDER == LITTLE_ENDIAN
68        u_int   ip_hl:4,                /* header length */
69                ip_v:4;                 /* version */
70#endif
71#if BYTE_ORDER == BIG_ENDIAN
72        u_int   ip_v:4,                 /* version */
73                ip_hl:4;                /* header length */
74#endif
75#endif /* not _IP_VHL */
76        u_char  ip_tos;                 /* type of service */
77        u_short ip_len;                 /* total length */
78        u_short ip_id;                  /* identification */
79        u_short ip_off;                 /* fragment offset field */
80#define IP_RF 0x8000                    /* reserved fragment flag */
81#define IP_DF 0x4000                    /* dont fragment flag */
82#define IP_MF 0x2000                    /* more fragments flag */
83#define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
84        u_char  ip_ttl;                 /* time to live */
85        u_char  ip_p;                   /* protocol */
86        u_short ip_sum;                 /* checksum */
87        struct  in_addr ip_src,ip_dst;  /* source and dest address */
88} __packed __aligned(4);
89
90#ifdef _IP_VHL
91#define IP_MAKE_VHL(v, hl)      ((v) << 4 | (hl))
92#define IP_VHL_HL(vhl)          ((vhl) & 0x0f)
93#define IP_VHL_V(vhl)           ((vhl) >> 4)
94#define IP_VHL_BORING           0x45
95#endif
96
97#ifdef CTASSERT
98CTASSERT(sizeof (struct ip) == 20);
99#endif
100
101#define IP_MAXPACKET    65535L          /* maximum packet size */
102
103/*
104 * Definitions for IP type of service (ip_tos)
105 */
106#define IPTOS_LOWDELAY          0x10
107#define IPTOS_THROUGHPUT        0x08
108#define IPTOS_RELIABILITY       0x04
109#define IPTOS_MINCOST           0x02
110#if 1
111/* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */
112#define IPTOS_CE                0x01
113#define IPTOS_ECT               0x02
114#endif
115
116/*
117 * Definitions for IP precedence (also in ip_tos) (hopefully unused)
118 */
119#define IPTOS_PREC_NETCONTROL           0xe0
120#define IPTOS_PREC_INTERNETCONTROL      0xc0
121#define IPTOS_PREC_CRITIC_ECP           0xa0
122#define IPTOS_PREC_FLASHOVERRIDE        0x80
123#define IPTOS_PREC_FLASH                0x60
124#define IPTOS_PREC_IMMEDIATE            0x40
125#define IPTOS_PREC_PRIORITY             0x20
126#define IPTOS_PREC_ROUTINE              0x00
127
128/*
129 * ECN (Explicit Congestion Notification) codepoints in RFC3168
130 * mapped to the lower 2 bits of the TOS field.
131 */
132#define IPTOS_ECN_NOTECT        0x00    /* not-ECT */
133#define IPTOS_ECN_ECT1          0x01    /* ECN-capable transport (1) */
134#define IPTOS_ECN_ECT0          0x02    /* ECN-capable transport (0) */
135#define IPTOS_ECN_CE            0x03    /* congestion experienced */
136#define IPTOS_ECN_MASK          0x03    /* ECN field mask */
137
138/*
139 * Definitions for options.
140 */
141#define IPOPT_COPIED(o)         ((o)&0x80)
142#define IPOPT_CLASS(o)          ((o)&0x60)
143#define IPOPT_NUMBER(o)         ((o)&0x1f)
144
145#define IPOPT_CONTROL           0x00
146#define IPOPT_RESERVED1         0x20
147#define IPOPT_DEBMEAS           0x40
148#define IPOPT_RESERVED2         0x60
149
150#define IPOPT_EOL               0               /* end of option list */
151#define IPOPT_NOP               1               /* no operation */
152
153#define IPOPT_RR                7               /* record packet route */
154#define IPOPT_TS                68              /* timestamp */
155#define IPOPT_SECURITY          130             /* provide s,c,h,tcc */
156#define IPOPT_LSRR              131             /* loose source route */
157#define IPOPT_ESO               133             /* extended security */
158#define IPOPT_CIPSO             134             /* commerical security */
159#define IPOPT_SATID             136             /* satnet id */
160#define IPOPT_SSRR              137             /* strict source route */
161#define IPOPT_RA                148             /* router alert */
162
163/*
164 * Offsets to fields in options other than EOL and NOP.
165 */
166#define IPOPT_OPTVAL            0               /* option ID */
167#define IPOPT_OLEN              1               /* option length */
168#define IPOPT_OFFSET            2               /* offset within option */
169#define IPOPT_MINOFF            4               /* min value of above */
170
171/*
172 * Time stamp option structure.
173 */
174struct  ip_timestamp {
175        u_char  ipt_code;               /* IPOPT_TS */
176        u_char  ipt_len;                /* size of structure (variable) */
177        u_char  ipt_ptr;                /* index of current entry */
178#if BYTE_ORDER == LITTLE_ENDIAN
179        u_int   ipt_flg:4,              /* flags, see below */
180                ipt_oflw:4;             /* overflow counter */
181#endif
182#if BYTE_ORDER == BIG_ENDIAN
183        u_int   ipt_oflw:4,             /* overflow counter */
184                ipt_flg:4;              /* flags, see below */
185#endif
186        union ipt_timestamp {
187                n_long  ipt_time[1];
188                struct  ipt_ta {
189                        struct in_addr ipt_addr;
190                        n_long ipt_time;
191                } ipt_ta[1];
192        } ipt_timestamp;
193};
194
195#include <machine/in_cksum.h>
196
197/* flag bits for ipt_flg */
198#define IPOPT_TS_TSONLY         0               /* timestamps only */
199#define IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
200#define IPOPT_TS_PRESPEC        3               /* specified modules only */
201
202/* bits for security (not byte swapped) */
203#define IPOPT_SECUR_UNCLASS     0x0000
204#define IPOPT_SECUR_CONFID      0xf135
205#define IPOPT_SECUR_EFTO        0x789a
206#define IPOPT_SECUR_MMMM        0xbc4d
207#define IPOPT_SECUR_RESTR       0xaf13
208#define IPOPT_SECUR_SECRET      0xd788
209#define IPOPT_SECUR_TOPSECRET   0x6bc5
210
211/*
212 * Internet implementation parameters.
213 */
214#define MAXTTL          255             /* maximum time to live (seconds) */
215#define IPDEFTTL        64              /* default ttl, from RFC 1340 */
216#define IPFRAGTTL       60              /* time to live for frags, slowhz */
217#define IPTTLDEC        1               /* subtracted when forwarding */
218
219#define IP_MSS          576             /* default maximum segment size */
220
221/*
222 * This is the real IPv4 pseudo header, used for computing the TCP and UDP
223 * checksums. For the Internet checksum, struct ipovly can be used instead.
224 * For stronger checksums, the real thing must be used.
225 */
226struct ippseudo {
227        struct  in_addr ippseudo_src;   /* source internet address */
228        struct  in_addr ippseudo_dst;   /* destination internet address */
229        u_char          ippseudo_pad;   /* pad, must be zero */
230        u_char          ippseudo_p;     /* protocol */
231        u_short         ippseudo_len;   /* protocol length */
232};
233#endif
Note: See TracBrowser for help on using the repository browser.