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

4.104.114.84.95
Last change on this file since ef0b69d1 was ef0b69d1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/29/07 at 14:28:49

2007-03-29 Ralf Corsépius <ralf.corsepius@…>

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