Subversion Repositories SvarDOS

Rev

Rev 616 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*!\file netinet/ip6.h
2
 * IPv6 definitions.
3
 */
4
 
5
/*      $FreeBSD: src/sys/netinet/ip6.h,v 1.5 2001/06/11 12:39:00 ume Exp $     */
6
/*      $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $    */
7
 
8
/*
9
 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
10
 * All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. Neither the name of the project nor the names of its contributors
21
 *    may be used to endorse or promote products derived from this software
22
 *    without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
25
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
28
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
 * SUCH DAMAGE.
35
 */
36
 
37
/*
38
 * Copyright (c) 1982, 1986, 1993
39
 *      The Regents of the University of California.  All rights reserved.
40
 *
41
 * Redistribution and use in source and binary forms, with or without
42
 * modification, are permitted provided that the following conditions
43
 * are met:
44
 * 1. Redistributions of source code must retain the above copyright
45
 *    notice, this list of conditions and the following disclaimer.
46
 * 2. Redistributions in binary form must reproduce the above copyright
47
 *    notice, this list of conditions and the following disclaimer in the
48
 *    documentation and/or other materials provided with the distribution.
49
 * 3. All advertising materials mentioning features or use of this software
50
 *    must display the following acknowledgement:
51
 *      This product includes software developed by the University of
52
 *      California, Berkeley and its contributors.
53
 * 4. Neither the name of the University nor the names of its contributors
54
 *    may be used to endorse or promote products derived from this software
55
 *    without specific prior written permission.
56
 *
57
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67
 * SUCH DAMAGE.
68
 *
69
 *      @(#)ip.h        8.1 (Berkeley) 6/10/93
70
 */
71
 
72
#ifndef _NETINET_IP6_H_
73
#define _NETINET_IP6_H_
74
 
75
/*
76
 * Definition for internet protocol version 6.
77
 * RFC 2460
78
 */
79
 
80
#ifndef __SYS_WTYPES_H
81
#include <sys/wtypes.h>
82
#endif
83
 
84
#include <sys/packon.h>
85
 
86
struct ip6_hdr {
87
       union {
88
         struct ip6_hdrctl {
89
           u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
90
           u_int16_t ip6_un1_plen; /* payload length */
91
           u_int8_t  ip6_un1_nxt;  /* next header */
92
           u_int8_t  ip6_un1_hlim; /* hop limit */
93
         } ip6_un1;
94
         u_int8_t    ip6_un2_vfc;  /* 4 bits version, top 4 bits class */
95
       } ip6_ctlun;
96
       struct in6_addr ip6_src;    /* source address */
97
       struct in6_addr ip6_dst;    /* destination address */
98
     };
99
 
100
#define ip6_vfc         ip6_ctlun.ip6_un2_vfc
101
#define ip6_flow        ip6_ctlun.ip6_un1.ip6_un1_flow
102
#define ip6_plen        ip6_ctlun.ip6_un1.ip6_un1_plen
103
#define ip6_nxt         ip6_ctlun.ip6_un1.ip6_un1_nxt
104
#define ip6_hlim        ip6_ctlun.ip6_un1.ip6_un1_hlim
105
#define ip6_hops        ip6_ctlun.ip6_un1.ip6_un1_hlim
106
 
107
#define IPV6_VERSION            0x60
108
#define IPV6_VERSION_MASK       0xf0
109
 
110
#if BYTE_ORDER == BIG_ENDIAN
111
#define IPV6_FLOWINFO_MASK      0x0fffffff      /* flow info (28 bits) */
112
#define IPV6_FLOWLABEL_MASK     0x000fffff      /* flow label (20 bits) */
113
#else
114
#if BYTE_ORDER == LITTLE_ENDIAN
115
#define IPV6_FLOWINFO_MASK      0xffffff0f      /* flow info (28 bits) */
116
#define IPV6_FLOWLABEL_MASK     0xffff0f00      /* flow label (20 bits) */
117
#endif /* LITTLE_ENDIAN */
118
#endif
119
 
120
#if 1
121
/* ECN bits proposed by Sally Floyd */
122
#define IP6TOS_CE               0x01    /* congestion experienced */
123
#define IP6TOS_ECT              0x02    /* ECN-capable transport */
124
#endif
125
 
126
/*
127
 * Extension Headers
128
 */
129
 
130
struct ip6_ext {
131
       u_int8_t ip6e_nxt;
132
       u_int8_t ip6e_len;
133
     };
134
 
135
/* Hop-by-Hop options header */
136
/* XXX should we pad it to force alignment on an 8-byte boundary? */
137
struct ip6_hbh {
138
       u_int8_t ip6h_nxt;      /* next header */
139
       u_int8_t ip6h_len;      /* length in units of 8 octets */
140
       /* followed by options */
141
     };
142
 
143
/* Destination options header */
144
/* XXX should we pad it to force alignment on an 8-byte boundary? */
145
struct ip6_dest {
146
       u_int8_t ip6d_nxt;      /* next header */
147
       u_int8_t ip6d_len;      /* length in units of 8 octets */
148
       /* followed by options */
149
     };
150
 
151
/* Option types and related macros */
152
#define IP6OPT_PAD1             0x00    /* 00 0 00000 */
153
#define IP6OPT_PADN             0x01    /* 00 0 00001 */
154
#define IP6OPT_JUMBO            0xC2    /* 11 0 00010 = 194 */
155
#define IP6OPT_NSAP_ADDR        0xC3    /* 11 0 00011 */
156
#define IP6OPT_TUNNEL_LIMIT     0x04    /* 00 0 00100 */
157
#define IP6OPT_RTALERT          0x05    /* 00 0 00101 (KAME definition) */
158
 
159
#define IP6OPT_RTALERT_LEN      4
160
#define IP6OPT_RTALERT_MLD      0       /* Datagram contains an MLD message */
161
#define IP6OPT_RTALERT_RSVP     1       /* Datagram contains an RSVP message */
162
#define IP6OPT_RTALERT_ACTNET   2       /* contains an Active Networks msg */
163
#define IP6OPT_MINLEN           2
164
 
165
#define IP6OPT_BINDING_UPDATE   0xc6    /* 11 0 00110 */
166
#define IP6OPT_BINDING_ACK      0x07    /* 00 0 00111 */
167
#define IP6OPT_BINDING_REQ      0x08    /* 00 0 01000 */
168
#define IP6OPT_HOME_ADDRESS     0xc9    /* 11 0 01001 */
169
#define IP6OPT_EID              0x8a    /* 10 0 01010 */
170
 
171
#define IP6OPT_TYPE(o)          ((o) & 0xC0)
172
#define IP6OPT_TYPE_SKIP        0x00
173
#define IP6OPT_TYPE_DISCARD     0x40
174
#define IP6OPT_TYPE_FORCEICMP   0x80
175
#define IP6OPT_TYPE_ICMP        0xC0
176
 
177
#define IP6OPT_MUTABLE          0x20
178
 
179
#define IP6OPT_JUMBO_LEN        6
180
 
181
/* Routing header */
182
struct ip6_rthdr {
183
       u_int8_t  ip6r_nxt;     /* next header */
184
       u_int8_t  ip6r_len;     /* length in units of 8 octets */
185
       u_int8_t  ip6r_type;    /* routing type */
186
       u_int8_t  ip6r_segleft; /* segments left */
187
       /* followed by routing type specific data */
188
     };
189
 
190
/* Type 0 Routing header */
191
struct ip6_rthdr0 {
192
       u_int8_t  ip6r0_nxt;            /* next header */
193
       u_int8_t  ip6r0_len;            /* length in units of 8 octets */
194
       u_int8_t  ip6r0_type;           /* always zero */
195
       u_int8_t  ip6r0_segleft;        /* segments left */
196
       u_int8_t  ip6r0_reserved;       /* reserved field */
197
       u_int8_t  ip6r0_slmap[3];       /* strict/loose bit map */
198
       struct in6_addr  ip6r0_addr[1]; /* up to 23 addresses */
199
     };
200
 
201
/* Fragment header */
202
struct ip6_frag {
203
       u_int8_t  ip6f_nxt;             /* next header */
204
       u_int8_t  ip6f_reserved;        /* reserved field */
205
       u_int16_t ip6f_offlg;           /* offset, reserved, and flag */
206
       u_int32_t ip6f_ident;           /* identification */
207
     };
208
 
209
#include <sys/packoff.h>
210
 
211
#if BYTE_ORDER == BIG_ENDIAN
212
#define IP6F_OFF_MASK           0xfff8  /* mask out offset from _offlg */
213
#define IP6F_RESERVED_MASK      0x0006  /* reserved bits in ip6f_offlg */
214
#define IP6F_MORE_FRAG          0x0001  /* more-fragments flag */
215
#else /* BYTE_ORDER == LITTLE_ENDIAN */
216
#define IP6F_OFF_MASK           0xf8ff  /* mask out offset from _offlg */
217
#define IP6F_RESERVED_MASK      0x0600  /* reserved bits in ip6f_offlg */
218
#define IP6F_MORE_FRAG          0x0100  /* more-fragments flag */
219
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
220
 
221
/*
222
 * Internet implementation parameters.
223
 */
224
#define IPV6_MAXHLIM    255     /* maximun hoplimit */
225
#define IPV6_DEFHLIM    64      /* default hlim */
226
#define IPV6_FRAGTTL    120     /* ttl for fragment packets, in slowtimo tick */
227
#define IPV6_HLIMDEC    1       /* subtracted when forwaeding */
228
 
229
#define IPV6_MMTU       1280    /* minimal MTU and reassembly. 1024 + 256 */
230
#define IPV6_MAXPACKET  65535   /* ip6 max packet size without Jumbo payload*/
231
 
232
#ifdef _KERNEL
233
/*
234
 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
235
 * target header (including IPv6 itself, extension headers and
236
 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
237
 * to store incoming data into one internal mbuf or one or more external
238
 * mbufs(never into two or more internal mbufs). Thus, the third case is
239
 * supposed to never be matched but is prepared just in case.
240
 */
241
 
242
#define IP6_EXTHDR_CHECK(m, off, hlen, ret)                             \
243
do {                                                                    \
244
    if ((m)->m_next != NULL) {                                          \
245
        if (((m)->m_flags & M_LOOP) &&                                  \
246
            ((m)->m_len < (off) + (hlen)) &&                            \
247
            (((m) = m_pullup((m), (off) + (hlen))) == NULL)) {          \
248
                ip6stat.ip6s_exthdrtoolong++;                           \
249
                return ret;                                             \
250
        } else if ((m)->m_flags & M_EXT) {                              \
251
                if ((m)->m_len < (off) + (hlen)) {                      \
252
                        ip6stat.ip6s_exthdrtoolong++;                   \
253
                        m_freem(m);                                     \
254
                        return ret;                                     \
255
                }                                                       \
256
        } else {                                                        \
257
                if ((m)->m_len < (off) + (hlen)) {                      \
258
                        ip6stat.ip6s_exthdrtoolong++;                   \
259
                        m_freem(m);                                     \
260
                        return ret;                                     \
261
                }                                                       \
262
        }                                                               \
263
    } else {                                                            \
264
        if ((m)->m_len < (off) + (hlen)) {                              \
265
                ip6stat.ip6s_tooshort++;                                \
266
                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);   \
267
                m_freem(m);                                             \
268
                return ret;                                             \
269
        }                                                               \
270
    }                                                                   \
271
} while (0)
272
 
273
/*
274
 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
275
 * "len") is located in single mbuf, on contiguous memory region.
276
 * The pointer to the region will be returned to pointer variable "val",
277
 * with type "typ".
278
 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
279
 * very top of mbuf.  GET0 is likely to make memory copy than GET.
280
 *
281
 * XXX we're now testing this, needs m_pulldown()
282
 */
283
#define IP6_EXTHDR_GET(val, typ, m, off, len) \
284
do {                                                                    \
285
        struct mbuf *t;                                                 \
286
        int tmp;                                                        \
287
        if ((m)->m_len >= (off) + (len))                                \
288
                (val) = (typ)(mtod((m), caddr_t) + (off));              \
289
        else {                                                          \
290
                t = m_pulldown((m), (off), (len), &tmp);                \
291
                if (t) {                                                \
292
                        if (t->m_len < tmp + (len))                     \
293
                                panic("m_pulldown malfunction");        \
294
                        (val) = (typ)(mtod(t, caddr_t) + tmp);          \
295
                } else {                                                \
296
                        (val) = (typ)NULL;                              \
297
                        (m) = NULL;                                     \
298
                }                                                       \
299
        }                                                               \
300
} while (0)
301
 
302
#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
303
do {                                                                    \
304
        struct mbuf *t;                                                 \
305
        if ((off) == 0)                                                 \
306
                (val) = (typ)mtod(m, caddr_t);                          \
307
        else {                                                          \
308
                t = m_pulldown((m), (off), (len), NULL);                \
309
                if (t) {                                                \
310
                        if (t->m_len < (len))                           \
311
                                panic("m_pulldown malfunction");        \
312
                        (val) = (typ)mtod(t, caddr_t);                  \
313
                } else {                                                \
314
                        (val) = (typ)NULL;                              \
315
                        (m) = NULL;                                     \
316
                }                                                       \
317
        }                                                               \
318
} while (0)
319
#endif /*_KERNEL*/
320
 
321
#endif /* not _NETINET_IP6_H_ */