Add additional sanity checks, remove unused arguments to vm_page_startup().
[dragonfly.git] / sys / netinet / icmp6.h
1 /*      $FreeBSD: src/sys/netinet/icmp6.h,v 1.2.2.5 2002/06/29 18:31:11 ume Exp $       */
2 /*      $DragonFly: src/sys/netinet/icmp6.h,v 1.6 2005/02/01 16:09:37 hrs Exp $ */
3 /*      $KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $  */
4
5 /*
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 /*
35  * Copyright (c) 1982, 1986, 1993
36  *      The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *      This product includes software developed by the University of
49  *      California, Berkeley and its contributors.
50  * 4. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *      @(#)ip_icmp.h   8.1 (Berkeley) 6/10/93
67  */
68
69 #ifndef _NETINET_ICMP6_H_
70 #define _NETINET_ICMP6_H_
71
72 #define ICMPV6_PLD_MAXLEN       1232    /* IPV6_MMTU - sizeof(struct ip6_hdr)
73                                            - sizeof(struct icmp6_hdr) */
74
75 struct icmp6_hdr {
76         u_int8_t        icmp6_type;     /* type field */
77         u_int8_t        icmp6_code;     /* code field */
78         u_int16_t       icmp6_cksum;    /* checksum field */
79         union {
80                 u_int32_t       icmp6_un_data32[1]; /* type-specific field */
81                 u_int16_t       icmp6_un_data16[2]; /* type-specific field */
82                 u_int8_t        icmp6_un_data8[4];  /* type-specific field */
83         } icmp6_dataun;
84 } __attribute__((__packed__));
85
86 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
87 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
88 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
89 #define icmp6_pptr      icmp6_data32[0]         /* parameter prob */
90 #define icmp6_mtu       icmp6_data32[0]         /* packet too big */
91 #define icmp6_id        icmp6_data16[0]         /* echo request/reply */
92 #define icmp6_seq       icmp6_data16[1]         /* echo request/reply */
93 #define icmp6_maxdelay  icmp6_data16[0]         /* mcast group membership */
94
95 #define ICMP6_DST_UNREACH               1       /* dest unreachable, codes: */
96 #define ICMP6_PACKET_TOO_BIG            2       /* packet too big */
97 #define ICMP6_TIME_EXCEEDED             3       /* time exceeded, code: */
98 #define ICMP6_PARAM_PROB                4       /* ip6 header bad */
99
100 #define ICMP6_ECHO_REQUEST              128     /* echo service */
101 #define ICMP6_ECHO_REPLY                129     /* echo reply */
102 #define ICMP6_MEMBERSHIP_QUERY          130     /* group membership query */
103 #define MLD_LISTENER_QUERY              130     /* multicast listener query */
104 #define ICMP6_MEMBERSHIP_REPORT         131     /* group membership report */
105 #define MLD_LISTENER_REPORT             131     /* multicast listener report */
106 #define ICMP6_MEMBERSHIP_REDUCTION      132     /* group membership termination */
107 #define MLD_LISTENER_DONE               132     /* multicast listener done */
108
109 #ifndef _KERNEL
110 /* the followings are for backward compatibility to old KAME apps. */
111 #define MLD6_LISTENER_QUERY     MLD_LISTENER_QUERY
112 #define MLD6_LISTENER_REPORT    MLD_LISTENER_REPORT
113 #define MLD6_LISTENER_DONE      MLD_LISTENER_DONE
114 #endif
115
116 #define ND_ROUTER_SOLICIT               133     /* router solicitation */
117 #define ND_ROUTER_ADVERT                134     /* router advertisment */
118 #define ND_NEIGHBOR_SOLICIT             135     /* neighbor solicitation */
119 #define ND_NEIGHBOR_ADVERT              136     /* neighbor advertisment */
120 #define ND_REDIRECT                     137     /* redirect */
121
122 #define ICMP6_ROUTER_RENUMBERING        138     /* router renumbering */
123
124 #define ICMP6_WRUREQUEST                139     /* who are you request */
125 #define ICMP6_WRUREPLY                  140     /* who are you reply */
126 #define ICMP6_FQDN_QUERY                139     /* FQDN query */
127 #define ICMP6_FQDN_REPLY                140     /* FQDN reply */
128 #define ICMP6_NI_QUERY                  139     /* node information request */
129 #define ICMP6_NI_REPLY                  140     /* node information reply */
130
131 /* The definitions below are experimental. TBA */
132 #define MLD_MTRACE_RESP                 200     /* mtrace resp (to sender) */
133 #define MLD_MTRACE                      201     /* mtrace messages */
134
135 #define ICMP6_HADISCOV_REQUEST          202     /* XXX To be defined */
136 #define ICMP6_HADISCOV_REPLY            203     /* XXX To be defined */
137  
138 #ifndef _KERNEL
139 #define MLD6_MTRACE_RESP        MLD_MTRACE_RESP
140 #define MLD6_MTRACE             MLD_MTRACE
141 #endif
142
143 #define ICMP6_MAXTYPE                   203
144
145 #define ICMP6_DST_UNREACH_NOROUTE       0       /* no route to destination */
146 #define ICMP6_DST_UNREACH_ADMIN         1       /* administratively prohibited */
147 #define ICMP6_DST_UNREACH_NOTNEIGHBOR   2       /* not a neighbor(obsolete) */
148 #define ICMP6_DST_UNREACH_BEYONDSCOPE   2       /* beyond scope of source address */
149 #define ICMP6_DST_UNREACH_ADDR          3       /* address unreachable */
150 #define ICMP6_DST_UNREACH_NOPORT        4       /* port unreachable */
151
152 #define ICMP6_TIME_EXCEED_TRANSIT       0       /* ttl==0 in transit */
153 #define ICMP6_TIME_EXCEED_REASSEMBLY    1       /* ttl==0 in reass */
154
155 #define ICMP6_PARAMPROB_HEADER          0       /* erroneous header field */
156 #define ICMP6_PARAMPROB_NEXTHEADER      1       /* unrecognized next header */
157 #define ICMP6_PARAMPROB_OPTION          2       /* unrecognized option */
158
159 #define ICMP6_INFOMSG_MASK              0x80    /* all informational messages */
160
161 #define ICMP6_NI_SUBJ_IPV6      0       /* Query Subject is an IPv6 address */
162 #define ICMP6_NI_SUBJ_FQDN      1       /* Query Subject is a Domain name */
163 #define ICMP6_NI_SUBJ_IPV4      2       /* Query Subject is an IPv4 address */
164
165 #define ICMP6_NI_SUCCESS        0       /* node information successful reply */
166 #define ICMP6_NI_REFUSED        1       /* node information request is refused */
167 #define ICMP6_NI_UNKNOWN        2       /* unknown Qtype */
168
169 #define ICMP6_ROUTER_RENUMBERING_COMMAND  0     /* rr command */
170 #define ICMP6_ROUTER_RENUMBERING_RESULT   1     /* rr result */
171 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255     /* rr seq num reset */
172
173 /* Used in kernel only */
174 #define ND_REDIRECT_ONLINK      0       /* redirect to an on-link node */
175 #define ND_REDIRECT_ROUTER      1       /* redirect to a better router */
176
177 /*
178  * Multicast Listener Discovery
179  */
180 struct mld_hdr {
181         struct icmp6_hdr        mld_icmp6_hdr;
182         struct in6_addr         mld_addr; /* multicast address */
183 } __attribute__((__packed__));
184
185 /* definitions to provide backward compatibility to old KAME applications */
186 #ifndef _KERNEL
187 #define mld6_hdr        mld_hdr
188 #define mld6_type       mld_type
189 #define mld6_code       mld_code
190 #define mld6_cksum      mld_cksum
191 #define mld6_maxdelay   mld_maxdelay
192 #define mld6_reserved   mld_reserved
193 #define mld6_addr       mld_addr
194 #endif
195
196 /* shortcut macro definitions */
197 #define mld_type        mld_icmp6_hdr.icmp6_type
198 #define mld_code        mld_icmp6_hdr.icmp6_code
199 #define mld_cksum       mld_icmp6_hdr.icmp6_cksum
200 #define mld_maxdelay    mld_icmp6_hdr.icmp6_data16[0]
201 #define mld_reserved    mld_icmp6_hdr.icmp6_data16[1]
202
203 /*
204  * Neighbor Discovery
205  */
206
207 struct nd_router_solicit {      /* router solicitation */
208         struct icmp6_hdr        nd_rs_hdr;
209         /* could be followed by options */
210 } __attribute__((__packed__));
211
212 #define nd_rs_type      nd_rs_hdr.icmp6_type
213 #define nd_rs_code      nd_rs_hdr.icmp6_code
214 #define nd_rs_cksum     nd_rs_hdr.icmp6_cksum
215 #define nd_rs_reserved  nd_rs_hdr.icmp6_data32[0]
216
217 struct nd_router_advert {       /* router advertisement */
218         struct icmp6_hdr        nd_ra_hdr;
219         u_int32_t               nd_ra_reachable;        /* reachable time */
220         u_int32_t               nd_ra_retransmit;       /* retransmit timer */
221         /* could be followed by options */
222 } __attribute__((__packed__));
223
224 #define nd_ra_type              nd_ra_hdr.icmp6_type
225 #define nd_ra_code              nd_ra_hdr.icmp6_code
226 #define nd_ra_cksum             nd_ra_hdr.icmp6_cksum
227 #define nd_ra_curhoplimit       nd_ra_hdr.icmp6_data8[0]
228 #define nd_ra_flags_reserved    nd_ra_hdr.icmp6_data8[1]
229 #define ND_RA_FLAG_MANAGED      0x80
230 #define ND_RA_FLAG_OTHER        0x40
231 #define ND_RA_FLAG_HA           0x20
232
233 /*
234  * Router preference values based on draft-draves-ipngwg-router-selection-01.
235  * These are non-standard definitions.
236  */
237 #define ND_RA_FLAG_RTPREF_MASK  0x18 /* 00011000 */
238
239 #define ND_RA_FLAG_RTPREF_HIGH  0x08 /* 00001000 */
240 #define ND_RA_FLAG_RTPREF_MEDIUM        0x00 /* 00000000 */
241 #define ND_RA_FLAG_RTPREF_LOW   0x18 /* 00011000 */
242 #define ND_RA_FLAG_RTPREF_RSV   0x10 /* 00010000 */
243
244 #define nd_ra_router_lifetime   nd_ra_hdr.icmp6_data16[1]
245
246 struct nd_neighbor_solicit {    /* neighbor solicitation */
247         struct icmp6_hdr        nd_ns_hdr;
248         struct in6_addr         nd_ns_target;   /*target address */
249         /* could be followed by options */
250 } __attribute__((__packed__));
251
252 #define nd_ns_type              nd_ns_hdr.icmp6_type
253 #define nd_ns_code              nd_ns_hdr.icmp6_code
254 #define nd_ns_cksum             nd_ns_hdr.icmp6_cksum
255 #define nd_ns_reserved          nd_ns_hdr.icmp6_data32[0]
256
257 struct nd_neighbor_advert {     /* neighbor advertisement */
258         struct icmp6_hdr        nd_na_hdr;
259         struct in6_addr         nd_na_target;   /* target address */
260         /* could be followed by options */
261 } __attribute__((__packed__));
262
263 #define nd_na_type              nd_na_hdr.icmp6_type
264 #define nd_na_code              nd_na_hdr.icmp6_code
265 #define nd_na_cksum             nd_na_hdr.icmp6_cksum
266 #define nd_na_flags_reserved    nd_na_hdr.icmp6_data32[0]
267 #if _BYTE_ORDER == _BIG_ENDIAN
268 #define ND_NA_FLAG_ROUTER               0x80000000
269 #define ND_NA_FLAG_SOLICITED            0x40000000
270 #define ND_NA_FLAG_OVERRIDE             0x20000000
271 #elif _BYTE_ORDER == _LITTLE_ENDIAN
272 #define ND_NA_FLAG_ROUTER               0x80
273 #define ND_NA_FLAG_SOLICITED            0x40
274 #define ND_NA_FLAG_OVERRIDE             0x20
275 #else
276 #error "Byte order not implemented"
277 #endif
278
279 struct nd_redirect {            /* redirect */
280         struct icmp6_hdr        nd_rd_hdr;
281         struct in6_addr         nd_rd_target;   /* target address */
282         struct in6_addr         nd_rd_dst;      /* destination address */
283         /* could be followed by options */
284 } __attribute__((__packed__));
285
286 #define nd_rd_type              nd_rd_hdr.icmp6_type
287 #define nd_rd_code              nd_rd_hdr.icmp6_code
288 #define nd_rd_cksum             nd_rd_hdr.icmp6_cksum
289 #define nd_rd_reserved          nd_rd_hdr.icmp6_data32[0]
290
291 struct nd_opt_hdr {             /* Neighbor discovery option header */
292         u_int8_t        nd_opt_type;
293         u_int8_t        nd_opt_len;
294         /* followed by option specific data*/
295 } __attribute__((__packed__));
296
297 #define ND_OPT_SOURCE_LINKADDR          1
298 #define ND_OPT_TARGET_LINKADDR          2
299 #define ND_OPT_PREFIX_INFORMATION       3
300 #define ND_OPT_REDIRECTED_HEADER        4
301 #define ND_OPT_MTU                      5
302
303 #define ND_OPT_ROUTE_INFO               200     /* draft-ietf-ipngwg-router-preference, not officially assigned yet */
304
305 struct nd_opt_prefix_info {     /* prefix information */
306         u_int8_t        nd_opt_pi_type;
307         u_int8_t        nd_opt_pi_len;
308         u_int8_t        nd_opt_pi_prefix_len;
309         u_int8_t        nd_opt_pi_flags_reserved;
310         u_int32_t       nd_opt_pi_valid_time;
311         u_int32_t       nd_opt_pi_preferred_time;
312         u_int32_t       nd_opt_pi_reserved2;
313         struct in6_addr nd_opt_pi_prefix;
314 } __attribute__((__packed__));
315
316 #define ND_OPT_PI_FLAG_ONLINK           0x80
317 #define ND_OPT_PI_FLAG_AUTO             0x40
318
319 struct nd_opt_rd_hdr {          /* redirected header */
320         u_int8_t        nd_opt_rh_type;
321         u_int8_t        nd_opt_rh_len;
322         u_int16_t       nd_opt_rh_reserved1;
323         u_int32_t       nd_opt_rh_reserved2;
324         /* followed by IP header and data */
325 } __attribute__((__packed__));
326
327 struct nd_opt_mtu {             /* MTU option */
328         u_int8_t        nd_opt_mtu_type;
329         u_int8_t        nd_opt_mtu_len;
330         u_int16_t       nd_opt_mtu_reserved;
331         u_int32_t       nd_opt_mtu_mtu;
332 } __attribute__((__packed__));
333
334 struct nd_opt_route_info {      /* route info */
335         u_int8_t        nd_opt_rti_type;
336         u_int8_t        nd_opt_rti_len;
337         u_int8_t        nd_opt_rti_prefixlen;
338         u_int8_t        nd_opt_rti_flags;
339         u_int32_t       nd_opt_rti_lifetime;
340         /* prefix follows */
341 } __attribute__((__packed__));
342
343 /*
344  * icmp6 namelookup
345  */
346
347 struct icmp6_namelookup {
348         struct icmp6_hdr        icmp6_nl_hdr;
349         u_int8_t        icmp6_nl_nonce[8];
350         int32_t         icmp6_nl_ttl;
351 #if 0
352         u_int8_t        icmp6_nl_len;
353         u_int8_t        icmp6_nl_name[3];
354 #endif
355         /* could be followed by options */
356 } __attribute__((__packed__));
357
358 /*
359  * icmp6 node information
360  */
361 struct icmp6_nodeinfo {
362         struct icmp6_hdr icmp6_ni_hdr;
363         u_int8_t icmp6_ni_nonce[8];
364         /* could be followed by reply data */
365 } __attribute__((__packed__));
366
367 #define ni_type         icmp6_ni_hdr.icmp6_type
368 #define ni_code         icmp6_ni_hdr.icmp6_code
369 #define ni_cksum        icmp6_ni_hdr.icmp6_cksum
370 #define ni_qtype        icmp6_ni_hdr.icmp6_data16[0]
371 #define ni_flags        icmp6_ni_hdr.icmp6_data16[1]
372
373 #define NI_QTYPE_NOOP           0 /* NOOP  */
374 #define NI_QTYPE_SUPTYPES       1 /* Supported Qtypes */
375 #define NI_QTYPE_FQDN           2 /* FQDN (draft 04) */
376 #define NI_QTYPE_DNSNAME        2 /* DNS Name */
377 #define NI_QTYPE_NODEADDR       3 /* Node Addresses */
378 #define NI_QTYPE_IPV4ADDR       4 /* IPv4 Addresses */
379
380 #if _BYTE_ORDER == _BIG_ENDIAN
381 #define NI_SUPTYPE_FLAG_COMPRESS        0x1
382 #define NI_FQDN_FLAG_VALIDTTL           0x1
383 #elif _BYTE_ORDER == _LITTLE_ENDIAN
384 #define NI_SUPTYPE_FLAG_COMPRESS        0x0100
385 #define NI_FQDN_FLAG_VALIDTTL           0x0100
386 #else
387 #error "Byte order not implemented"
388 #endif
389
390 #ifdef NAME_LOOKUPS_04
391 #if _BYTE_ORDER == _BIG_ENDIAN
392 #define NI_NODEADDR_FLAG_LINKLOCAL      0x1
393 #define NI_NODEADDR_FLAG_SITELOCAL      0x2
394 #define NI_NODEADDR_FLAG_GLOBAL         0x4
395 #define NI_NODEADDR_FLAG_ALL            0x8
396 #define NI_NODEADDR_FLAG_TRUNCATE       0x10
397 #define NI_NODEADDR_FLAG_ANYCAST        0x20 /* just experimental. not in spec */
398 #elif _BYTE_ORDER == _LITTLE_ENDIAN
399 #define NI_NODEADDR_FLAG_LINKLOCAL      0x0100
400 #define NI_NODEADDR_FLAG_SITELOCAL      0x0200
401 #define NI_NODEADDR_FLAG_GLOBAL         0x0400
402 #define NI_NODEADDR_FLAG_ALL            0x0800
403 #define NI_NODEADDR_FLAG_TRUNCATE       0x1000
404 #define NI_NODEADDR_FLAG_ANYCAST        0x2000 /* just experimental. not in spec */
405 #else
406 #error "Byte order not implemented"
407 #endif
408 #else  /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
409 #if _BYTE_ORDER == _BIG_ENDIAN
410 #define NI_NODEADDR_FLAG_TRUNCATE       0x1
411 #define NI_NODEADDR_FLAG_ALL            0x2
412 #define NI_NODEADDR_FLAG_COMPAT         0x4
413 #define NI_NODEADDR_FLAG_LINKLOCAL      0x8
414 #define NI_NODEADDR_FLAG_SITELOCAL      0x10
415 #define NI_NODEADDR_FLAG_GLOBAL         0x20
416 #define NI_NODEADDR_FLAG_ANYCAST        0x40 /* just experimental. not in spec */
417 #elif _BYTE_ORDER == _LITTLE_ENDIAN
418 #define NI_NODEADDR_FLAG_TRUNCATE       0x0100
419 #define NI_NODEADDR_FLAG_ALL            0x0200
420 #define NI_NODEADDR_FLAG_COMPAT         0x0400
421 #define NI_NODEADDR_FLAG_LINKLOCAL      0x0800
422 #define NI_NODEADDR_FLAG_SITELOCAL      0x1000
423 #define NI_NODEADDR_FLAG_GLOBAL         0x2000
424 #define NI_NODEADDR_FLAG_ANYCAST        0x4000 /* just experimental. not in spec */
425 #else
426 #error "Byte order not implemented"
427 #endif
428 #endif
429
430 struct ni_reply_fqdn {
431         u_int32_t ni_fqdn_ttl;  /* TTL */
432         u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
433         u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
434 } __attribute__((__packed__));
435
436 /*
437  * Router Renumbering. as router-renum-08.txt
438  */
439 struct icmp6_router_renum {     /* router renumbering header */
440         struct icmp6_hdr        rr_hdr;
441         u_int8_t        rr_segnum;
442         u_int8_t        rr_flags;
443         u_int16_t       rr_maxdelay;
444         u_int32_t       rr_reserved;
445 } __attribute__((__packed__));
446
447 #define ICMP6_RR_FLAGS_TEST             0x80
448 #define ICMP6_RR_FLAGS_REQRESULT        0x40
449 #define ICMP6_RR_FLAGS_FORCEAPPLY       0x20
450 #define ICMP6_RR_FLAGS_SPECSITE         0x10
451 #define ICMP6_RR_FLAGS_PREVDONE         0x08
452
453 #define rr_type         rr_hdr.icmp6_type
454 #define rr_code         rr_hdr.icmp6_code
455 #define rr_cksum        rr_hdr.icmp6_cksum
456 #define rr_seqnum       rr_hdr.icmp6_data32[0]
457
458 struct rr_pco_match {           /* match prefix part */
459         u_int8_t        rpm_code;
460         u_int8_t        rpm_len;
461         u_int8_t        rpm_ordinal;
462         u_int8_t        rpm_matchlen;
463         u_int8_t        rpm_minlen;
464         u_int8_t        rpm_maxlen;
465         u_int16_t       rpm_reserved;
466         struct  in6_addr        rpm_prefix;
467 } __attribute__((__packed__));
468
469 #define RPM_PCO_ADD             1
470 #define RPM_PCO_CHANGE          2
471 #define RPM_PCO_SETGLOBAL       3
472 #define RPM_PCO_MAX             4
473
474 struct rr_pco_use {             /* use prefix part */
475         u_int8_t        rpu_uselen;
476         u_int8_t        rpu_keeplen;
477         u_int8_t        rpu_ramask;
478         u_int8_t        rpu_raflags;
479         u_int32_t       rpu_vltime;
480         u_int32_t       rpu_pltime;
481         u_int32_t       rpu_flags;
482         struct  in6_addr rpu_prefix;
483 } __attribute__((__packed__));
484 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK  0x80
485 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO    0x40
486
487 #if _BYTE_ORDER == _BIG_ENDIAN
488 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80000000
489 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40000000
490 #elif _BYTE_ORDER == _LITTLE_ENDIAN
491 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME     0x80
492 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME     0x40
493 #else
494 #error "Byte order not implemented"
495 #endif
496
497 struct rr_result {              /* router renumbering result message */
498         u_int16_t       rrr_flags;
499         u_int8_t        rrr_ordinal;
500         u_int8_t        rrr_matchedlen;
501         u_int32_t       rrr_ifid;
502         struct  in6_addr rrr_prefix;
503 } __attribute__((__packed__));
504 #if _BYTE_ORDER == _BIG_ENDIAN
505 #define ICMP6_RR_RESULT_FLAGS_OOB               0x0002
506 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN         0x0001
507 #elif _BYTE_ORDER == _LITTLE_ENDIAN
508 #define ICMP6_RR_RESULT_FLAGS_OOB               0x0200
509 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN         0x0100
510 #else
511 #error "Byte order not implemented"
512 #endif
513
514 /*
515  * icmp6 filter structures.
516  */
517
518 struct icmp6_filter {
519         u_int32_t icmp6_filt[8];
520 };
521
522 #ifdef _KERNEL
523 #define ICMP6_FILTER_SETPASSALL(filterp) \
524 do {                                                            \
525         int i; u_char *p;                                       \
526         p = (u_char *)filterp;                                  \
527         for (i = 0; i < sizeof(struct icmp6_filter); i++)       \
528                 p[i] = 0xff;                                    \
529 } while (0)
530 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
531         bzero(filterp, sizeof(struct icmp6_filter))
532 #else /* _KERNEL */
533 #define ICMP6_FILTER_SETPASSALL(filterp) \
534         memset(filterp, 0xff, sizeof(struct icmp6_filter))
535 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
536         memset(filterp, 0x00, sizeof(struct icmp6_filter))
537 #endif /* _KERNEL */
538
539 #define ICMP6_FILTER_SETPASS(type, filterp) \
540         (((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
541 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
542         (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
543 #define ICMP6_FILTER_WILLPASS(type, filterp) \
544         ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
545 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
546         ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
547
548 /*
549  * Variables related to this implementation
550  * of the internet control message protocol version 6.
551  */
552 struct icmp6errstat {
553         u_quad_t icp6errs_dst_unreach_noroute;
554         u_quad_t icp6errs_dst_unreach_admin;
555         u_quad_t icp6errs_dst_unreach_beyondscope;
556         u_quad_t icp6errs_dst_unreach_addr;
557         u_quad_t icp6errs_dst_unreach_noport;
558         u_quad_t icp6errs_packet_too_big;
559         u_quad_t icp6errs_time_exceed_transit;
560         u_quad_t icp6errs_time_exceed_reassembly;
561         u_quad_t icp6errs_paramprob_header;
562         u_quad_t icp6errs_paramprob_nextheader;
563         u_quad_t icp6errs_paramprob_option;
564         u_quad_t icp6errs_redirect; /* we regard redirect as an error here */
565         u_quad_t icp6errs_unknown;
566 };
567
568 struct icmp6stat {
569 /* statistics related to icmp6 packets generated */
570         u_quad_t icp6s_error;           /* # of calls to icmp6_error */
571         u_quad_t icp6s_canterror;       /* no error 'cuz old was icmp */
572         u_quad_t icp6s_toofreq;         /* no error 'cuz rate limitation */
573         u_quad_t icp6s_outhist[256];
574 /* statistics related to input message processed */
575         u_quad_t icp6s_badcode;         /* icmp6_code out of range */
576         u_quad_t icp6s_tooshort;        /* packet < sizeof(struct icmp6_hdr) */
577         u_quad_t icp6s_checksum;        /* bad checksum */
578         u_quad_t icp6s_badlen;          /* calculated bound mismatch */
579         /*
580          * number of responses: this member is inherited from netinet code, but
581          * for netinet6 code, it is already available in icp6s_outhist[].
582          */
583         u_quad_t icp6s_reflect;
584         u_quad_t icp6s_inhist[256];     
585         u_quad_t icp6s_nd_toomanyopt;   /* too many ND options */
586         struct icmp6errstat icp6s_outerrhist;
587 #define icp6s_odst_unreach_noroute \
588         icp6s_outerrhist.icp6errs_dst_unreach_noroute
589 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
590 #define icp6s_odst_unreach_beyondscope \
591         icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
592 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
593 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
594 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
595 #define icp6s_otime_exceed_transit \
596         icp6s_outerrhist.icp6errs_time_exceed_transit
597 #define icp6s_otime_exceed_reassembly \
598         icp6s_outerrhist.icp6errs_time_exceed_reassembly
599 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
600 #define icp6s_oparamprob_nextheader \
601         icp6s_outerrhist.icp6errs_paramprob_nextheader
602 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
603 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
604 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
605         u_quad_t icp6s_pmtuchg;         /* path MTU changes */
606         u_quad_t icp6s_nd_badopt;       /* bad ND options */
607         u_quad_t icp6s_badns;           /* bad neighbor solicitation */
608         u_quad_t icp6s_badna;           /* bad neighbor advertisement */
609         u_quad_t icp6s_badrs;           /* bad router advertisement */
610         u_quad_t icp6s_badra;           /* bad router advertisement */
611         u_quad_t icp6s_badredirect;     /* bad redirect message */
612 };
613
614 /*
615  * Names for ICMP sysctl objects
616  */
617 #define ICMPV6CTL_STATS         1
618 #define ICMPV6CTL_REDIRACCEPT   2       /* accept/process redirects */
619 #define ICMPV6CTL_REDIRTIMEOUT  3       /* redirect cache time */
620 #if 0   /*obsoleted*/
621 #define ICMPV6CTL_ERRRATELIMIT  5       /* ICMPv6 error rate limitation */
622 #endif
623 #define ICMPV6CTL_ND6_PRUNE     6
624 #define ICMPV6CTL_ND6_DELAY     8
625 #define ICMPV6CTL_ND6_UMAXTRIES 9
626 #define ICMPV6CTL_ND6_MMAXTRIES         10
627 #define ICMPV6CTL_ND6_USELOOPBACK       11
628 /*#define ICMPV6CTL_ND6_PROXYALL        12      obsoleted, do not reuse here */
629 #define ICMPV6CTL_NODEINFO      13
630 #define ICMPV6CTL_ERRPPSLIMIT   14      /* ICMPv6 error pps limitation */
631 #define ICMPV6CTL_ND6_MAXNUDHINT        15
632 #define ICMPV6CTL_MTUDISC_HIWAT 16
633 #define ICMPV6CTL_MTUDISC_LOWAT 17
634 #define ICMPV6CTL_ND6_DEBUG     18
635 #define ICMPV6CTL_ND6_DRLIST    19
636 #define ICMPV6CTL_ND6_PRLIST    20
637 #define ICMPV6CTL_MAXID         21
638
639 #define ICMPV6CTL_NAMES { \
640         { 0, 0 }, \
641         { 0, 0 }, \
642         { "rediraccept", CTLTYPE_INT }, \
643         { "redirtimeout", CTLTYPE_INT }, \
644         { 0, 0 }, \
645         { 0, 0 }, \
646         { "nd6_prune", CTLTYPE_INT }, \
647         { 0, 0 }, \
648         { "nd6_delay", CTLTYPE_INT }, \
649         { "nd6_umaxtries", CTLTYPE_INT }, \
650         { "nd6_mmaxtries", CTLTYPE_INT }, \
651         { "nd6_useloopback", CTLTYPE_INT }, \
652         { 0, 0 }, \
653         { "nodeinfo", CTLTYPE_INT }, \
654         { "errppslimit", CTLTYPE_INT }, \
655         { "nd6_maxnudhint", CTLTYPE_INT }, \
656         { "mtudisc_hiwat", CTLTYPE_INT }, \
657         { "mtudisc_lowat", CTLTYPE_INT }, \
658         { "nd6_debug", CTLTYPE_INT }, \
659         { 0, 0 }, \
660         { 0, 0 }, \
661 }
662
663 #define RTF_PROBEMTU    RTF_PROTO1
664
665 #ifdef _KERNEL
666 # ifdef __STDC__
667 struct  rtentry;
668 struct  rttimer;
669 struct  in6_multi;
670 # endif
671 void    icmp6_init (void);
672 void    icmp6_paramerror (struct mbuf *, int);
673 void    icmp6_error (struct mbuf *, int, int, int);
674 int     icmp6_input (struct mbuf **, int *, int);
675 void    icmp6_fasttimo (void);
676 void    icmp6_reflect (struct mbuf *, size_t);
677 void    icmp6_prepare (struct mbuf *);
678 void    icmp6_redirect_input (struct mbuf *, int);
679 void    icmp6_redirect_output (struct mbuf *, struct rtentry *);
680
681 struct  ip6ctlparam;
682 void    icmp6_mtudisc_update (struct ip6ctlparam *, int);
683
684 /* XXX: is this the right place for these macros? */
685 #define icmp6_ifstat_inc(ifp, tag) \
686 do {                                                            \
687         if (ifp)                                                \
688                 ((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat->tag++; \
689 } while (0)
690
691 #define icmp6_ifoutstat_inc(ifp, type, code) \
692 do { \
693                 icmp6_ifstat_inc(ifp, ifs6_out_msg); \
694                 if (type < ICMP6_INFOMSG_MASK) \
695                         icmp6_ifstat_inc(ifp, ifs6_out_error); \
696                 switch (type) { \
697                  case ICMP6_DST_UNREACH: \
698                          icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
699                          if (code == ICMP6_DST_UNREACH_ADMIN) \
700                                  icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
701                          break; \
702                  case ICMP6_PACKET_TOO_BIG: \
703                          icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
704                          break; \
705                  case ICMP6_TIME_EXCEEDED: \
706                          icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
707                          break; \
708                  case ICMP6_PARAM_PROB: \
709                          icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
710                          break; \
711                  case ICMP6_ECHO_REQUEST: \
712                          icmp6_ifstat_inc(ifp, ifs6_out_echo); \
713                          break; \
714                  case ICMP6_ECHO_REPLY: \
715                          icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
716                          break; \
717                  case MLD_LISTENER_QUERY: \
718                          icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
719                          break; \
720                  case MLD_LISTENER_REPORT: \
721                          icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
722                          break; \
723                  case MLD_LISTENER_DONE: \
724                          icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
725                          break; \
726                  case ND_ROUTER_SOLICIT: \
727                          icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
728                          break; \
729                  case ND_ROUTER_ADVERT: \
730                          icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
731                          break; \
732                  case ND_NEIGHBOR_SOLICIT: \
733                          icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
734                          break; \
735                  case ND_NEIGHBOR_ADVERT: \
736                          icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
737                          break; \
738                  case ND_REDIRECT: \
739                          icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
740                          break; \
741                 } \
742 } while (0)
743
744 extern int      icmp6_rediraccept;      /* accept/process redirects */
745 extern int      icmp6_redirtimeout;     /* cache time for redirect routes */
746 #endif /* _KERNEL */
747
748 #endif /* not _NETINET_ICMP6_H_ */