OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [bsd_tcpip/] [v2_0/] [include/] [netinet/] [ip6.h] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      include/netinet/ip6.h
4
//
5
//==========================================================================
6
//####BSDCOPYRIGHTBEGIN####
7
//
8
// -------------------------------------------
9
//
10
// Portions of this software may have been derived from OpenBSD, 
11
// FreeBSD or other sources, and are covered by the appropriate
12
// copyright disclaimers included herein.
13
//
14
// Portions created by Red Hat are
15
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
16
//
17
// -------------------------------------------
18
//
19
//####BSDCOPYRIGHTEND####
20
//==========================================================================
21
 
22
/*      $KAME: ip6.h,v 1.25 2001/11/29 04:38:37 keiichi Exp $   */
23
 
24
/*
25
 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
26
 * All rights reserved.
27
 *
28
 * Redistribution and use in source and binary forms, with or without
29
 * modification, are permitted provided that the following conditions
30
 * are met:
31
 * 1. Redistributions of source code must retain the above copyright
32
 *    notice, this list of conditions and the following disclaimer.
33
 * 2. Redistributions in binary form must reproduce the above copyright
34
 *    notice, this list of conditions and the following disclaimer in the
35
 *    documentation and/or other materials provided with the distribution.
36
 * 3. Neither the name of the project nor the names of its contributors
37
 *    may be used to endorse or promote products derived from this software
38
 *    without specific prior written permission.
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
41
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
44
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
 * SUCH DAMAGE.
51
 */
52
 
53
/*
54
 * Copyright (c) 1982, 1986, 1993
55
 *      The Regents of the University of California.  All rights reserved.
56
 *
57
 * Redistribution and use in source and binary forms, with or without
58
 * modification, are permitted provided that the following conditions
59
 * are met:
60
 * 1. Redistributions of source code must retain the above copyright
61
 *    notice, this list of conditions and the following disclaimer.
62
 * 2. Redistributions in binary form must reproduce the above copyright
63
 *    notice, this list of conditions and the following disclaimer in the
64
 *    documentation and/or other materials provided with the distribution.
65
 * 3. All advertising materials mentioning features or use of this software
66
 *    must display the following acknowledgement:
67
 *      This product includes software developed by the University of
68
 *      California, Berkeley and its contributors.
69
 * 4. Neither the name of the University nor the names of its contributors
70
 *    may be used to endorse or promote products derived from this software
71
 *    without specific prior written permission.
72
 *
73
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
74
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
77
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
78
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
79
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
80
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
81
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
82
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
83
 * SUCH DAMAGE.
84
 *
85
 *      @(#)ip.h        8.1 (Berkeley) 6/10/93
86
 */
87
 
88
#ifndef _NETINET_IP6_H_
89
#define _NETINET_IP6_H_
90
 
91
/*
92
 * Definition for internet protocol version 6.
93
 * RFC 2460
94
 */
95
 
96
struct ip6_hdr {
97
        union {
98
                struct ip6_hdrctl {
99
                        u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
100
                        u_int16_t ip6_un1_plen; /* payload length */
101
                        u_int8_t  ip6_un1_nxt;  /* next header */
102
                        u_int8_t  ip6_un1_hlim; /* hop limit */
103
                } ip6_un1;
104
                u_int8_t ip6_un2_vfc;   /* 4 bits version, top 4 bits class */
105
        } ip6_ctlun;
106
        struct in6_addr ip6_src;        /* source address */
107
        struct in6_addr ip6_dst;        /* destination address */
108
} __attribute__ ((aligned(1), packed));
109
 
110
#define ip6_vfc         ip6_ctlun.ip6_un2_vfc
111
#define ip6_flow        ip6_ctlun.ip6_un1.ip6_un1_flow
112
#define ip6_plen        ip6_ctlun.ip6_un1.ip6_un1_plen
113
#define ip6_nxt         ip6_ctlun.ip6_un1.ip6_un1_nxt
114
#define ip6_hlim        ip6_ctlun.ip6_un1.ip6_un1_hlim
115
#define ip6_hops        ip6_ctlun.ip6_un1.ip6_un1_hlim
116
 
117
#define IPV6_VERSION            0x60
118
#define IPV6_VERSION_MASK       0xf0
119
 
120
#if BYTE_ORDER == BIG_ENDIAN
121
#define IPV6_FLOWINFO_MASK      0x0fffffff      /* flow info (28 bits) */
122
#define IPV6_FLOWLABEL_MASK     0x000fffff      /* flow label (20 bits) */
123
#else
124
#if BYTE_ORDER == LITTLE_ENDIAN
125
#define IPV6_FLOWINFO_MASK      0xffffff0f      /* flow info (28 bits) */
126
#define IPV6_FLOWLABEL_MASK     0xffff0f00      /* flow label (20 bits) */
127
#endif /* LITTLE_ENDIAN */
128
#endif
129
#if 1
130
/* ECN bits proposed by Sally Floyd */
131
#define IP6TOS_CE               0x01    /* congestion experienced */
132
#define IP6TOS_ECT              0x02    /* ECN-capable transport */
133
#endif
134
 
135
/*
136
 * Extension Headers
137
 */
138
 
139
struct  ip6_ext {
140
        u_int8_t ip6e_nxt;
141
        u_int8_t ip6e_len;
142
} __attribute__ ((aligned(1), packed));
143
 
144
/* Hop-by-Hop options header */
145
/* XXX should we pad it to force alignment on an 8-byte boundary? */
146
struct ip6_hbh {
147
        u_int8_t ip6h_nxt;      /* next header */
148
        u_int8_t ip6h_len;      /* length in units of 8 octets */
149
        /* followed by options */
150
} __attribute__ ((aligned(1), packed));
151
 
152
/* Destination options header */
153
/* XXX should we pad it to force alignment on an 8-byte boundary? */
154
struct ip6_dest {
155
        u_int8_t ip6d_nxt;      /* next header */
156
        u_int8_t ip6d_len;      /* length in units of 8 octets */
157
        /* followed by options */
158
} __attribute__ ((aligned(1), packed));
159
 
160
/* Option types and related macros */
161
#define IP6OPT_PAD1             0x00    /* 00 0 00000 */
162
#define IP6OPT_PADN             0x01    /* 00 0 00001 */
163
#define IP6OPT_JUMBO            0xC2    /* 11 0 00010 = 194 */
164
#define IP6OPT_NSAP_ADDR        0xC3    /* 11 0 00011 */
165
#define IP6OPT_TUNNEL_LIMIT     0x04    /* 00 0 00100 */
166
#define IP6OPT_RTALERT          0x05    /* 00 0 00101 (KAME definition) */
167
#define IP6OPT_ROUTER_ALERT     0x05    /* (2292bis def, recommended) */
168
 
169
#define IP6OPT_RTALERT_LEN      4
170
#define IP6OPT_RTALERT_MLD      0        /* Datagram contains an MLD message */
171
#define IP6OPT_RTALERT_RSVP     1       /* Datagram contains an RSVP message */
172
#define IP6OPT_RTALERT_ACTNET   2       /* contains an Active Networks msg */
173
#define IP6OPT_MINLEN           2
174
 
175
#define IP6OPT_BINDING_UPDATE   0xc6    /* 11 0 00110 */
176
#define IP6OPT_BINDING_ACK      0x07    /* 00 0 00111 */
177
#define IP6OPT_BINDING_REQ      0x08    /* 00 0 01000 */
178
#define IP6OPT_HOME_ADDRESS     0xc9    /* 11 0 01001 */
179
#define IP6OPT_EID              0x8a    /* 10 0 01010 */
180
 
181
#define IP6OPT_TYPE(o)          ((o) & 0xC0)
182
#define IP6OPT_TYPE_SKIP        0x00
183
#define IP6OPT_TYPE_DISCARD     0x40
184
#define IP6OPT_TYPE_FORCEICMP   0x80
185
#define IP6OPT_TYPE_ICMP        0xC0
186
 
187
#define IP6OPT_MUTABLE          0x20
188
 
189
/* IPv6 options: common part */
190
struct ip6_opt {
191
        u_int8_t ip6o_type;
192
        u_int8_t ip6o_len;
193
} __attribute__ ((aligned(1), packed));
194
 
195
/* Jumbo Payload Option */
196
struct ip6_opt_jumbo {
197
        u_int8_t ip6oj_type;
198
        u_int8_t ip6oj_len;
199
        u_int8_t ip6oj_jumbo_len[4];
200
} __attribute__ ((aligned(1), packed));
201
#define IP6OPT_JUMBO_LEN 6
202
 
203
/* NSAP Address Option */
204
struct ip6_opt_nsap {
205
        u_int8_t ip6on_type;
206
        u_int8_t ip6on_len;
207
        u_int8_t ip6on_src_nsap_len;
208
        u_int8_t ip6on_dst_nsap_len;
209
        /* followed by source NSAP */
210
        /* followed by destination NSAP */
211
} __attribute__ ((aligned(1), packed));
212
 
213
/* Tunnel Limit Option */
214
struct ip6_opt_tunnel {
215
        u_int8_t ip6ot_type;
216
        u_int8_t ip6ot_len;
217
        u_int8_t ip6ot_encap_limit;
218
} __attribute__ ((aligned(1), packed));
219
 
220
/* Router Alert Option */
221
struct ip6_opt_router {
222
        u_int8_t ip6or_type;
223
        u_int8_t ip6or_len;
224
        u_int8_t ip6or_value[2];
225
} __attribute__ ((aligned(1), packed));
226
/* Router alert values (in network byte order) */
227
#if BYTE_ORDER == BIG_ENDIAN
228
#define IP6_ALERT_MLD   0x0000
229
#define IP6_ALERT_RSVP  0x0001
230
#define IP6_ALERT_AN    0x0002
231
#else
232
#if BYTE_ORDER == LITTLE_ENDIAN
233
#define IP6_ALERT_MLD   0x0000
234
#define IP6_ALERT_RSVP  0x0100
235
#define IP6_ALERT_AN    0x0200
236
#endif /* LITTLE_ENDIAN */
237
#endif
238
 
239
/* Binding Update Option */
240
struct ip6_opt_binding_update {
241
        u_int8_t ip6ou_type;
242
        u_int8_t ip6ou_len;
243
#ifdef MIP6_DRAFT13
244
        u_int8_t ip6ou_flags;
245
        u_int8_t ip6ou_prefixlen;
246
        u_int16_t ip6ou_seqno;
247
#else
248
        u_int8_t ip6ou_flags;
249
        u_int8_t ip6ou_reserved[2];
250
        u_int8_t ip6ou_seqno;
251
#endif /* MIP6_DRAFT13 */
252
        u_int8_t ip6ou_lifetime[4];
253
        /* followed by sub-options */
254
} __attribute__ ((aligned(1), packed));
255
 
256
/* Binding Update Flags */
257
#define IP6_BUF_ACK     0x80    /* Request a binding ack */
258
#define IP6_BUF_HOME    0x40    /* Home Registration */
259
#ifdef MIP6_DRAFT13
260
#define IP6_BUF_ROUTER  0x20    /* Sending mobile node is a router */
261
#else
262
#define IP6_BUF_SINGLE  0x20    /* Update the specified address only */
263
#endif /* MIP6_DRAFT13 */
264
#define IP6_BUF_DAD     0x10    /* Perform Duplicate Address Detection */
265
 
266
/* Binding Ack Option */
267
struct ip6_opt_binding_ack {
268
        u_int8_t ip6oa_type;
269
        u_int8_t ip6oa_len;
270
        u_int8_t ip6oa_status;
271
#ifdef MIP6_DRAFT13
272
        u_int16_t ip6oa_seqno;
273
#else
274
        u_int8_t ip6oa_reserved;
275
        u_int8_t ip6oa_seqno;
276
#endif /* MIP6_DRAFT13 */
277
        u_int8_t ip6oa_lifetime[4];
278
        u_int8_t ip6oa_refresh[4];
279
        /* followed by sub-options */
280
} __attribute__ ((aligned(1), packed));
281
 
282
/* Binding Request Option */
283
struct ip6_opt_binding_request {
284
        u_int8_t ip6or_type;
285
        u_int8_t ip6or_len;
286
        /* followed by sub-options */
287
} __attribute__ ((aligned(1), packed));
288
 
289
/* Home Address Option */
290
struct ip6_opt_home_address {
291
        u_int8_t ip6oh_type;
292
        u_int8_t ip6oh_len;
293
        u_int8_t ip6oh_addr[16];/* Home Address */
294
        /* followed by sub-options */
295
} __attribute__ ((aligned(1), packed));
296
 
297
/* Routing header */
298
struct ip6_rthdr {
299
        u_int8_t  ip6r_nxt;     /* next header */
300
        u_int8_t  ip6r_len;     /* length in units of 8 octets */
301
        u_int8_t  ip6r_type;    /* routing type */
302
        u_int8_t  ip6r_segleft; /* segments left */
303
        /* followed by routing type specific data */
304
} __attribute__ ((aligned(1), packed));
305
 
306
/* Type 0 Routing header */
307
struct ip6_rthdr0 {
308
        u_int8_t  ip6r0_nxt;            /* next header */
309
        u_int8_t  ip6r0_len;            /* length in units of 8 octets */
310
        u_int8_t  ip6r0_type;           /* always zero */
311
        u_int8_t  ip6r0_segleft;        /* segments left */
312
        u_int32_t  ip6r0_reserved;      /* reserved field */
313
        /* followed by up to 127 struct in6_addr */
314
} __attribute__ ((aligned(1), packed));
315
 
316
/* Fragment header */
317
struct ip6_frag {
318
        u_int8_t  ip6f_nxt;             /* next header */
319
        u_int8_t  ip6f_reserved;        /* reserved field */
320
        u_int16_t ip6f_offlg;           /* offset, reserved, and flag */
321
        u_int32_t ip6f_ident;           /* identification */
322
} __attribute__ ((aligned(1), packed));
323
 
324
#if BYTE_ORDER == BIG_ENDIAN
325
#define IP6F_OFF_MASK           0xfff8  /* mask out offset from _offlg */
326
#define IP6F_RESERVED_MASK      0x0006  /* reserved bits in ip6f_offlg */
327
#define IP6F_MORE_FRAG          0x0001  /* more-fragments flag */
328
#else /* BYTE_ORDER == LITTLE_ENDIAN */
329
#define IP6F_OFF_MASK           0xf8ff  /* mask out offset from _offlg */
330
#define IP6F_RESERVED_MASK      0x0600  /* reserved bits in ip6f_offlg */
331
#define IP6F_MORE_FRAG          0x0100  /* more-fragments flag */
332
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
333
 
334
/*
335
 * Internet implementation parameters.
336
 */
337
#define IPV6_MAXHLIM    255     /* maximun hoplimit */
338
#define IPV6_DEFHLIM    64      /* default hlim */
339
#define IPV6_FRAGTTL    120     /* ttl for fragment packets, in slowtimo tick */
340
#define IPV6_HLIMDEC    1       /* subtracted when forwaeding */
341
 
342
#define IPV6_MMTU       1280    /* minimal MTU and reassembly. 1024 + 256 */
343
#define IPV6_MAXPACKET  65535   /* ip6 max packet size without Jumbo payload*/
344
 
345
#ifdef _KERNEL
346
/*
347
 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
348
 * target header (including IPv6 itself, extension headers and
349
 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
350
 * to store incoming data into one internal mbuf or one or more external
351
 * mbufs(never into two or more internal mbufs). Thus, the third case is
352
 * supposed to never be matched but is prepared just in case.
353
 */
354
 
355
#define IP6_EXTHDR_CHECK(m, off, hlen, ret)                             \
356
do {                                                                    \
357
    if ((m)->m_next != NULL) {                                          \
358
        if ((m)->m_flags & M_EXT) {                                     \
359
                if ((m)->m_len < (off) + (hlen)) {                      \
360
                        ip6stat.ip6s_exthdrtoolong++;                   \
361
                        m_freem(m);                                     \
362
                        return ret;                                     \
363
                }                                                       \
364
        } else {                                                        \
365
                if ((m)->m_len < (off) + (hlen)) {                      \
366
                        ip6stat.ip6s_exthdrtoolong++;                   \
367
                        m_freem(m);                                     \
368
                        return ret;                                     \
369
                }                                                       \
370
        }                                                               \
371
    } else {                                                            \
372
        if ((m)->m_len < (off) + (hlen)) {                              \
373
                ip6stat.ip6s_tooshort++;                                \
374
                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);   \
375
                m_freem(m);                                             \
376
                return ret;                                             \
377
        }                                                               \
378
    }                                                                   \
379
} while (0)
380
 
381
#ifdef PULLDOWN_STAT
382
#define IP6_EXTHDR_STAT(x)      x
383
#else
384
#define IP6_EXTHDR_STAT(x)
385
#endif
386
 
387
/*
388
 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
389
 * "len") is located in single mbuf, on contiguous memory region.
390
 * The pointer to the region will be returned to pointer variable "val",
391
 * with type "typ".
392
 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
393
 * very top of mbuf.  GET0 is likely to make memory copy than GET.
394
 *
395
 * XXX we're now testing this, needs m_pulldown()
396
 */
397
#define IP6_EXTHDR_GET(val, typ, m, off, len) \
398
do {                                                                    \
399
        struct mbuf *t;                                                 \
400
        int tmp;                                                        \
401
        IP6_EXTHDR_STAT(mbstat.m_exthdrget++);                          \
402
        if ((m)->m_len >= (off) + (len))                                \
403
                (val) = (typ)(mtod((m), caddr_t) + (off));              \
404
        else {                                                          \
405
                t = m_pulldown((m), (off), (len), &tmp);                \
406
                if (t) {                                                \
407
                        if (t->m_len < tmp + (len))                     \
408
                                panic("m_pulldown malfunction");        \
409
                        (val) = (typ)(mtod(t, caddr_t) + tmp);          \
410
                } else {                                                \
411
                        (val) = (typ)NULL;                              \
412
                        (m) = NULL;                                     \
413
                }                                                       \
414
        }                                                               \
415
} while (0)
416
 
417
#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
418
do {                                                                    \
419
        struct mbuf *t;                                                 \
420
        IP6_EXTHDR_STAT(mbstat.m_exthdrget0++);                         \
421
        if ((off) == 0 && (m)->m_len >= len)                             \
422
                (val) = (typ)mtod((m), caddr_t);                        \
423
        else {                                                          \
424
                t = m_pulldown((m), (off), (len), NULL);                \
425
                if (t) {                                                \
426
                        if (t->m_len < (len))                           \
427
                                panic("m_pulldown malfunction");        \
428
                        (val) = (typ)mtod(t, caddr_t);                  \
429
                } else {                                                \
430
                        (val) = (typ)NULL;                              \
431
                        (m) = NULL;                                     \
432
                }                                                       \
433
        }                                                               \
434
} while (0)
435
#endif /*_KERNEL*/
436
 
437
#endif /* not _NETINET_IP6_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.