Update.
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / netinet / ip.h
1 /* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #ifndef __NETINET_IP_H
20 #define __NETINET_IP_H 1
21
22 #include <sys/cdefs.h>
23 #include <sys/types.h>
24
25 #include <netinet/in.h>
26
27 __BEGIN_DECLS
28
29 struct timestamp
30   {
31     u_int8_t len;
32     u_int8_t ptr;
33 #if __BYTE_ORDER == __LITTLE_ENDIAN
34     unsigned int flags:4;
35     unsigned int overflow:4;
36 #elif __BYTE_ORDER == __BIG_ENDIAN
37     unsigned int overflow:4;
38     unsigned int flags:4;
39 #else
40 # error "Please fix <bits/endian.h>"
41 #endif
42     u_int32_t data[9];
43   };
44
45 struct ip_options
46   {
47     u_int32_t faddr;            /* Saved first hop address */
48     u_int8_t optlen;
49     u_int8_t srr;
50     u_int8_t rr;
51     u_int8_t ts;
52     unsigned int is_setbyuser:1;   /* Set by setsockopt?                  */
53     unsigned int is_data:1;        /* Options in __data, rather than skb  */
54     unsigned int is_strictroute:1; /* Strict source route                 */
55     unsigned int srr_is_hit:1;     /* Packet destination addr was our one */
56     unsigned int is_changed:1;     /* IP checksum more not valid          */
57     unsigned int rr_needaddr:1;    /* Need to record addr of outgoing dev */
58     unsigned int ts_needtime:1;    /* Need to record timestamp            */
59     unsigned int ts_needaddr:1;    /* Need to record addr of outgoing dev */
60     u_int8_t router_alert;
61     u_int8_t __pad1;
62     u_int8_t __pad2;
63     u_int8_t __data[0];
64   };
65
66 struct iphdr
67   {
68 #if __BYTE_ORDER == __LITTLE_ENDIAN
69     unsigned int ihl:4;
70     unsigned int version:4;
71 #elif __BYTE_ORDER == __BIG_ENDIAN
72     unsigned int version:4;
73     unsigned int ihl:4;
74 #else
75 # error "Please fix <bits/endian.h>"
76 #endif
77     u_int8_t tos;
78     u_int16_t tot_len;
79     u_int16_t id;
80     u_int16_t frag_off;
81     u_int8_t ttl;
82     u_int8_t protocol;
83     u_int16_t check;
84     u_int32_t saddr;
85     u_int32_t daddr;
86     /*The options start here. */
87   };
88
89 #ifdef __USE_BSD
90 /*
91  * Copyright (c) 1982, 1986, 1993
92  *      The Regents of the University of California.  All rights reserved.
93  *
94  * Redistribution and use in source and binary forms, with or without
95  * modification, are permitted provided that the following conditions
96  * are met:
97  * 1. Redistributions of source code must retain the above copyright
98  *    notice, this list of conditions and the following disclaimer.
99  * 2. Redistributions in binary form must reproduce the above copyright
100  *    notice, this list of conditions and the following disclaimer in the
101  *    documentation and/or other materials provided with the distribution.
102  * 3. All advertising materials mentioning features or use of this software
103  *    must display the following acknowledgement:
104  *      This product includes software developed by the University of
105  *      California, Berkeley and its contributors.
106  * 4. Neither the name of the University nor the names of its contributors
107  *    may be used to endorse or promote products derived from this software
108  *    without specific prior written permission.
109  *
110  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
111  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
113  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
114  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
115  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
116  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
117  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
118  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
119  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
120  * SUCH DAMAGE.
121  *
122  *      @(#)ip.h        8.1 (Berkeley) 6/10/93
123  */
124
125 /*
126  * Definitions for internet protocol version 4.
127  * Per RFC 791, September 1981.
128  */
129
130 /*
131  * Structure of an internet header, naked of options.
132  */
133 struct ip
134   {
135 #if __BYTE_ORDER == __LITTLE_ENDIAN
136     unsigned int ip_hl:4;               /* header length */
137     unsigned int ip_v:4;                /* version */
138 #endif
139 #if __BYTE_ORDER == __BIG_ENDIAN
140     unsigned int ip_v:4;                /* version */
141     unsigned int ip_hl:4;               /* header length */
142 #endif
143     u_int8_t ip_tos;                    /* type of service */
144     u_short ip_len;                     /* total length */
145     u_short ip_id;                      /* identification */
146     u_short ip_off;                     /* fragment offset field */
147 #define IP_RF 0x8000                    /* reserved fragment flag */
148 #define IP_DF 0x4000                    /* dont fragment flag */
149 #define IP_MF 0x2000                    /* more fragments flag */
150 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
151     u_int8_t ip_ttl;                    /* time to live */
152     u_int8_t ip_p;                      /* protocol */
153     u_short ip_sum;                     /* checksum */
154     struct in_addr ip_src, ip_dst;      /* source and dest address */
155   };
156
157 /*
158  * Time stamp option structure.
159  */
160 struct ip_timestamp
161   {
162     u_int8_t ipt_code;                  /* IPOPT_TS */
163     u_int8_t ipt_len;                   /* size of structure (variable) */
164     u_int8_t ipt_ptr;                   /* index of current entry */
165 #if __BYTE_ORDER == __LITTLE_ENDIAN
166     unsigned int ipt_flg:4;             /* flags, see below */
167     unsigned int ipt_oflw:4;            /* overflow counter */
168 #endif
169 #if __BYTE_ORDER == __BIG_ENDIAN
170     unsigned int ipt_oflw:4;            /* overflow counter */
171     unsigned int ipt_flg:4;             /* flags, see below */
172 #endif
173     u_int32_t data[9];
174   };
175 #endif /* __USE_BSD */
176
177 #define IPVERSION       4               /* IP version number */
178 #define IP_MAXPACKET    65535           /* maximum packet size */
179
180 /*
181  * Definitions for IP type of service (ip_tos)
182  */
183 #define IPTOS_TOS_MASK          0x1E
184 #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
185 #define IPTOS_LOWDELAY          0x10
186 #define IPTOS_THROUGHPUT        0x08
187 #define IPTOS_RELIABILITY       0x04
188 #define IPTOS_LOWCOST           0x02
189 #define IPTOS_MINCOST           IPTOS_LOWCOST
190
191 /*
192  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
193  */
194 #define IPTOS_PREC_MASK                 0xe0
195 #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
196 #define IPTOS_PREC_NETCONTROL           0xe0
197 #define IPTOS_PREC_INTERNETCONTROL      0xc0
198 #define IPTOS_PREC_CRITIC_ECP           0xa0
199 #define IPTOS_PREC_FLASHOVERRIDE        0x80
200 #define IPTOS_PREC_FLASH                0x60
201 #define IPTOS_PREC_IMMEDIATE            0x40
202 #define IPTOS_PREC_PRIORITY             0x20
203 #define IPTOS_PREC_ROUTINE              0x00
204
205 /*
206  * Definitions for options.
207  */
208 #define IPOPT_COPY              0x80
209 #define IPOPT_CLASS_MASK        0x60
210 #define IPOPT_NUMBER_MASK       0x1f
211
212 #define IPOPT_COPIED(o)         ((o) & IPOPT_COPY)
213 #define IPOPT_CLASS(o)          ((o) & IPOPT_CLASS_MASK)
214 #define IPOPT_NUMBER(o)         ((o) & IPOPT_NUMBER_MASK)
215
216 #define IPOPT_CONTROL           0x00
217 #define IPOPT_RESERVED1         0x20
218 #define IPOPT_DEBMEAS           0x40
219 #define IPOPT_MEASUREMENT       IPOPT_DEBMEAS
220 #define IPOPT_RESERVED2         0x60
221
222 #define IPOPT_EOL               0               /* end of option list */
223 #define IPOPT_END               IPOPT_EOL
224 #define IPOPT_NOP               1               /* no operation */
225 #define IPOPT_NOOP              IP_NOP
226
227 #define IPOPT_RR                7               /* record packet route */
228 #define IPOPT_TS                68              /* timestamp */
229 #define IPOPT_TIMESTAMP         IPOPT_TS
230 #define IPOPT_SECURITY          130             /* provide s,c,h,tcc */
231 #define IPOPT_SEC               IPOPT_SECURITY
232 #define IPOPT_LSRR              131             /* loose source route */
233 #define IPOPT_SATID             136             /* satnet id */
234 #define IPOPT_SID               IPOPT_SATID
235 #define IPOPT_SSRR              137             /* strict source route */
236 #define IPOPT_RA                148             /* router alert */
237
238 /*
239  * Offsets to fields in options other than EOL and NOP.
240  */
241 #define IPOPT_OPTVAL            0               /* option ID */
242 #define IPOPT_OLEN              1               /* option length */
243 #define IPOPT_OFFSET            2               /* offset within option */
244 #define IPOPT_MINOFF            4               /* min value of above */
245
246 #define MAX_IPOPTLEN            40
247
248 /* flag bits for ipt_flg */
249 #define IPOPT_TS_TSONLY         0               /* timestamps only */
250 #define IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
251 #define IPOPT_TS_PRESPEC        3               /* specified modules only */
252
253 /* bits for security (not byte swapped) */
254 #define IPOPT_SECUR_UNCLASS     0x0000
255 #define IPOPT_SECUR_CONFID      0xf135
256 #define IPOPT_SECUR_EFTO        0x789a
257 #define IPOPT_SECUR_MMMM        0xbc4d
258 #define IPOPT_SECUR_RESTR       0xaf13
259 #define IPOPT_SECUR_SECRET      0xd788
260 #define IPOPT_SECUR_TOPSECRET   0x6bc5
261
262 /*
263  * Internet implementation parameters.
264  */
265 #define MAXTTL          255             /* maximum time to live (seconds) */
266 #define IPDEFTTL        64              /* default ttl, from RFC 1340 */
267 #define IPFRAGTTL       60              /* time to live for frags, slowhz */
268 #define IPTTLDEC        1               /* subtracted when forwarding */
269
270 #define IP_MSS          576             /* default maximum segment size */
271
272 __END_DECLS
273
274 #endif /* netinet/ip.h */